Change legacy "persona" references to userid_t.

Offers stronger typing with no functional change.

Change-Id: I09f0262470feec5cfdf26658f998c20550af84d4
This commit is contained in:
Jeff Sharkey 2013-07-10 16:55:46 -07:00
parent 883140d0bf
commit abe4fe5b46
5 changed files with 65 additions and 67 deletions

View File

@ -108,11 +108,11 @@ int install(const char *pkgname, uid_t uid, gid_t gid, const char *seinfo)
return 0; return 0;
} }
int uninstall(const char *pkgname, uid_t persona) int uninstall(const char *pkgname, userid_t userid)
{ {
char pkgdir[PKG_PATH_MAX]; char pkgdir[PKG_PATH_MAX];
if (create_pkg_path(pkgdir, pkgname, PKG_DIR_POSTFIX, persona)) if (create_pkg_path(pkgdir, pkgname, PKG_DIR_POSTFIX, userid))
return -1; return -1;
/* delete contents AND directory, no exceptions */ /* delete contents AND directory, no exceptions */
@ -173,18 +173,18 @@ int fix_uid(const char *pkgname, uid_t uid, gid_t gid)
return 0; return 0;
} }
int delete_user_data(const char *pkgname, uid_t persona) int delete_user_data(const char *pkgname, userid_t userid)
{ {
char pkgdir[PKG_PATH_MAX]; char pkgdir[PKG_PATH_MAX];
if (create_pkg_path(pkgdir, pkgname, PKG_DIR_POSTFIX, persona)) if (create_pkg_path(pkgdir, pkgname, PKG_DIR_POSTFIX, userid))
return -1; return -1;
/* delete contents, excluding "lib", but not the directory itself */ /* delete contents, excluding "lib", but not the directory itself */
return delete_dir_contents(pkgdir, 0, "lib"); return delete_dir_contents(pkgdir, 0, "lib");
} }
int make_user_data(const char *pkgname, uid_t uid, uid_t persona) int make_user_data(const char *pkgname, uid_t uid, userid_t userid)
{ {
char pkgdir[PKG_PATH_MAX]; char pkgdir[PKG_PATH_MAX];
char applibdir[PKG_PATH_MAX]; char applibdir[PKG_PATH_MAX];
@ -192,10 +192,10 @@ int make_user_data(const char *pkgname, uid_t uid, uid_t persona)
struct stat libStat; struct stat libStat;
// Create the data dir for the package // Create the data dir for the package
if (create_pkg_path(pkgdir, pkgname, PKG_DIR_POSTFIX, persona)) { if (create_pkg_path(pkgdir, pkgname, PKG_DIR_POSTFIX, userid)) {
return -1; return -1;
} }
if (create_pkg_path(libsymlink, pkgname, PKG_LIB_POSTFIX, persona)) { if (create_pkg_path(libsymlink, pkgname, PKG_LIB_POSTFIX, userid)) {
ALOGE("cannot create package lib symlink origin path\n"); ALOGE("cannot create package lib symlink origin path\n");
return -1; return -1;
} }
@ -262,10 +262,10 @@ int make_user_data(const char *pkgname, uid_t uid, uid_t persona)
return 0; return 0;
} }
int delete_persona(uid_t persona) int delete_user(userid_t userid)
{ {
char data_path[PKG_PATH_MAX]; char data_path[PKG_PATH_MAX];
if (create_persona_path(data_path, persona)) { if (create_user_path(data_path, userid)) {
return -1; return -1;
} }
if (delete_dir_contents(data_path, 1, NULL)) { if (delete_dir_contents(data_path, 1, NULL)) {
@ -273,7 +273,7 @@ int delete_persona(uid_t persona)
} }
char media_path[PATH_MAX]; char media_path[PATH_MAX];
if (create_persona_media_path(media_path, (userid_t) persona) == -1) { if (create_user_media_path(media_path, userid) == -1) {
return -1; return -1;
} }
if (delete_dir_contents(media_path, 1, NULL) == -1) { if (delete_dir_contents(media_path, 1, NULL) == -1) {
@ -283,11 +283,11 @@ int delete_persona(uid_t persona)
return 0; return 0;
} }
int delete_cache(const char *pkgname, uid_t persona) int delete_cache(const char *pkgname, userid_t userid)
{ {
char cachedir[PKG_PATH_MAX]; char cachedir[PKG_PATH_MAX];
if (create_pkg_path(cachedir, pkgname, CACHE_DIR_POSTFIX, persona)) if (create_pkg_path(cachedir, pkgname, CACHE_DIR_POSTFIX, userid))
return -1; return -1;
/* delete contents, not the directory, no exceptions */ /* delete contents, not the directory, no exceptions */
@ -319,7 +319,7 @@ int free_cache(int64_t free_size)
cache = start_cache_collection(); cache = start_cache_collection();
// Collect cache files for primary user. // Collect cache files for primary user.
if (create_persona_path(tmpdir, 0) == 0) { if (create_user_path(tmpdir, 0) == 0) {
//ALOGI("adding cache files from %s\n", tmpdir); //ALOGI("adding cache files from %s\n", tmpdir);
add_cache_files(cache, tmpdir, "cache"); add_cache_files(cache, tmpdir, "cache");
} }
@ -420,7 +420,7 @@ int rm_dex(const char *path)
} }
} }
int get_size(const char *pkgname, int persona, const char *apkpath, int get_size(const char *pkgname, userid_t userid, const char *apkpath,
const char *libdirpath, const char *fwdlock_apkpath, const char *asecpath, const char *libdirpath, const char *fwdlock_apkpath, const char *asecpath,
int64_t *_codesize, int64_t *_datasize, int64_t *_cachesize, int64_t *_codesize, int64_t *_datasize, int64_t *_cachesize,
int64_t* _asecsize) int64_t* _asecsize)
@ -477,7 +477,7 @@ int get_size(const char *pkgname, int persona, const char *apkpath,
} }
} }
if (create_pkg_path(path, pkgname, PKG_DIR_POSTFIX, persona)) { if (create_pkg_path(path, pkgname, PKG_DIR_POSTFIX, userid)) {
goto done; goto done;
} }

View File

@ -83,7 +83,7 @@ static int do_get_size(char **arg, char reply[REPLY_MAX])
int64_t asecsize = 0; int64_t asecsize = 0;
int res = 0; int res = 0;
/* pkgdir, persona, apkpath */ /* pkgdir, userid, apkpath */
res = get_size(arg[0], atoi(arg[1]), arg[2], arg[3], arg[4], arg[5], res = get_size(arg[0], atoi(arg[1]), arg[2], arg[3], arg[4], arg[5],
&codesize, &datasize, &cachesize, &asecsize); &codesize, &datasize, &cachesize, &asecsize);
@ -108,7 +108,7 @@ static int do_mk_user_data(char **arg, char reply[REPLY_MAX])
static int do_rm_user(char **arg, char reply[REPLY_MAX]) static int do_rm_user(char **arg, char reply[REPLY_MAX])
{ {
return delete_persona(atoi(arg[0])); /* userid */ return delete_user(atoi(arg[0])); /* userid */
} }
static int do_movefiles(char **arg, char reply[REPLY_MAX]) static int do_movefiles(char **arg, char reply[REPLY_MAX])

View File

@ -78,9 +78,6 @@
#define PKG_NAME_MAX 128 /* largest allowed package name */ #define PKG_NAME_MAX 128 /* largest allowed package name */
#define PKG_PATH_MAX 256 /* max size of any path we use */ #define PKG_PATH_MAX 256 /* max size of any path we use */
#define PER_USER_RANGE ((uid_t)100000) /* range of uids per user
uid = persona * PER_USER_RANGE + appid */
/* data structures */ /* data structures */
typedef struct { typedef struct {
@ -138,17 +135,17 @@ int create_pkg_path_in_dir(char path[PKG_PATH_MAX],
int create_pkg_path(char path[PKG_PATH_MAX], int create_pkg_path(char path[PKG_PATH_MAX],
const char *pkgname, const char *pkgname,
const char *postfix, const char *postfix,
uid_t persona); userid_t userid);
int create_persona_path(char path[PKG_PATH_MAX], int create_user_path(char path[PKG_PATH_MAX],
uid_t persona); userid_t userid);
int create_persona_media_path(char path[PKG_PATH_MAX], userid_t userid); int create_user_media_path(char path[PKG_PATH_MAX], userid_t userid);
int create_move_path(char path[PKG_PATH_MAX], int create_move_path(char path[PKG_PATH_MAX],
const char* pkgname, const char* pkgname,
const char* leaf, const char* leaf,
uid_t persona); userid_t userid);
int is_valid_package_name(const char* pkgname); int is_valid_package_name(const char* pkgname);
@ -193,17 +190,17 @@ int ensure_media_user_dirs(userid_t userid);
/* commands.c */ /* commands.c */
int install(const char *pkgname, uid_t uid, gid_t gid, const char *seinfo); int install(const char *pkgname, uid_t uid, gid_t gid, const char *seinfo);
int uninstall(const char *pkgname, uid_t persona); int uninstall(const char *pkgname, userid_t userid);
int renamepkg(const char *oldpkgname, const char *newpkgname); int renamepkg(const char *oldpkgname, const char *newpkgname);
int fix_uid(const char *pkgname, uid_t uid, gid_t gid); int fix_uid(const char *pkgname, uid_t uid, gid_t gid);
int delete_user_data(const char *pkgname, uid_t persona); int delete_user_data(const char *pkgname, userid_t userid);
int make_user_data(const char *pkgname, uid_t uid, uid_t persona); int make_user_data(const char *pkgname, uid_t uid, userid_t userid);
int delete_persona(uid_t persona); int delete_user(userid_t userid);
int delete_cache(const char *pkgname, uid_t persona); int delete_cache(const char *pkgname, userid_t userid);
int move_dex(const char *src, const char *dst); int move_dex(const char *src, const char *dst);
int rm_dex(const char *path); int rm_dex(const char *path);
int protect(char *pkgname, gid_t gid); int protect(char *pkgname, gid_t gid);
int get_size(const char *pkgname, int persona, const char *apkpath, const char *libdirpath, int get_size(const char *pkgname, userid_t userid, const char *apkpath, const char *libdirpath,
const char *fwdlock_apkpath, const char *asecpath, int64_t *codesize, const char *fwdlock_apkpath, const char *asecpath, int64_t *codesize,
int64_t *datasize, int64_t *cachesize, int64_t *asecsize); int64_t *datasize, int64_t *cachesize, int64_t *asecsize);
int free_cache(int64_t free_size); int free_cache(int64_t free_size);

View File

@ -340,7 +340,7 @@ TEST_F(UtilsTest, CreatePkgPathInDir_ProtectedDir) {
TEST_F(UtilsTest, CreatePersonaPath_Primary) { TEST_F(UtilsTest, CreatePersonaPath_Primary) {
char path[PKG_PATH_MAX]; char path[PKG_PATH_MAX];
EXPECT_EQ(0, create_persona_path(path, 0)) EXPECT_EQ(0, create_user_path(path, 0))
<< "Should successfully build primary user path."; << "Should successfully build primary user path.";
EXPECT_STREQ("/data/data/", path) EXPECT_STREQ("/data/data/", path)
@ -350,7 +350,7 @@ TEST_F(UtilsTest, CreatePersonaPath_Primary) {
TEST_F(UtilsTest, CreatePersonaPath_Secondary) { TEST_F(UtilsTest, CreatePersonaPath_Secondary) {
char path[PKG_PATH_MAX]; char path[PKG_PATH_MAX];
EXPECT_EQ(0, create_persona_path(path, 1)) EXPECT_EQ(0, create_user_path(path, 1))
<< "Should successfully build primary user path."; << "Should successfully build primary user path.";
EXPECT_STREQ("/data/user/1/", path) EXPECT_STREQ("/data/user/1/", path)

View File

@ -53,38 +53,39 @@ int create_pkg_path_in_dir(char path[PKG_PATH_MAX],
/** /**
* Create the package path name for a given package name with a postfix for * Create the package path name for a given package name with a postfix for
* a certain persona. Returns 0 on success, and -1 on failure. * a certain userid. Returns 0 on success, and -1 on failure.
*/ */
int create_pkg_path(char path[PKG_PATH_MAX], int create_pkg_path(char path[PKG_PATH_MAX],
const char *pkgname, const char *pkgname,
const char *postfix, const char *postfix,
uid_t persona) userid_t userid)
{ {
size_t uid_len; size_t userid_len;
char* persona_prefix; char* userid_prefix;
if (persona == 0) { if (userid == 0) {
persona_prefix = PRIMARY_USER_PREFIX; userid_prefix = PRIMARY_USER_PREFIX;
uid_len = 0; userid_len = 0;
} else { } else {
persona_prefix = SECONDARY_USER_PREFIX; userid_prefix = SECONDARY_USER_PREFIX;
uid_len = snprintf(NULL, 0, "%d", persona); userid_len = snprintf(NULL, 0, "%d", userid);
} }
const size_t prefix_len = android_data_dir.len + strlen(persona_prefix) + uid_len + 1 /*slash*/; const size_t prefix_len = android_data_dir.len + strlen(userid_prefix)
+ userid_len + 1 /*slash*/;
char prefix[prefix_len + 1]; char prefix[prefix_len + 1];
char *dst = prefix; char *dst = prefix;
size_t dst_size = sizeof(prefix); size_t dst_size = sizeof(prefix);
if (append_and_increment(&dst, android_data_dir.path, &dst_size) < 0 if (append_and_increment(&dst, android_data_dir.path, &dst_size) < 0
|| append_and_increment(&dst, persona_prefix, &dst_size) < 0) { || append_and_increment(&dst, userid_prefix, &dst_size) < 0) {
ALOGE("Error building prefix for APK path"); ALOGE("Error building prefix for APK path");
return -1; return -1;
} }
if (persona != 0) { if (userid != 0) {
int ret = snprintf(dst, dst_size, "%d/", persona); int ret = snprintf(dst, dst_size, "%d/", userid);
if (ret < 0 || (size_t) ret != uid_len + 1) { if (ret < 0 || (size_t) ret != userid_len + 1) {
ALOGW("Error appending UID to APK path"); ALOGW("Error appending UID to APK path");
return -1; return -1;
} }
@ -98,39 +99,39 @@ int create_pkg_path(char path[PKG_PATH_MAX],
} }
/** /**
* Create the path name for user data for a certain persona. * Create the path name for user data for a certain userid.
* Returns 0 on success, and -1 on failure. * Returns 0 on success, and -1 on failure.
*/ */
int create_persona_path(char path[PKG_PATH_MAX], int create_user_path(char path[PKG_PATH_MAX],
uid_t persona) userid_t userid)
{ {
size_t uid_len; size_t userid_len;
char* persona_prefix; char* userid_prefix;
if (persona == 0) { if (userid == 0) {
persona_prefix = PRIMARY_USER_PREFIX; userid_prefix = PRIMARY_USER_PREFIX;
uid_len = 0; userid_len = 0;
} else { } else {
persona_prefix = SECONDARY_USER_PREFIX; userid_prefix = SECONDARY_USER_PREFIX;
uid_len = snprintf(NULL, 0, "%d/", persona); userid_len = snprintf(NULL, 0, "%d/", userid);
} }
char *dst = path; char *dst = path;
size_t dst_size = PKG_PATH_MAX; size_t dst_size = PKG_PATH_MAX;
if (append_and_increment(&dst, android_data_dir.path, &dst_size) < 0 if (append_and_increment(&dst, android_data_dir.path, &dst_size) < 0
|| append_and_increment(&dst, persona_prefix, &dst_size) < 0) { || append_and_increment(&dst, userid_prefix, &dst_size) < 0) {
ALOGE("Error building prefix for user path"); ALOGE("Error building prefix for user path");
return -1; return -1;
} }
if (persona != 0) { if (userid != 0) {
if (dst_size < uid_len + 1) { if (dst_size < userid_len + 1) {
ALOGE("Error building user path"); ALOGE("Error building user path");
return -1; return -1;
} }
int ret = snprintf(dst, dst_size, "%d/", persona); int ret = snprintf(dst, dst_size, "%d/", userid);
if (ret < 0 || (size_t) ret != uid_len) { if (ret < 0 || (size_t) ret != userid_len) {
ALOGE("Error appending persona id to path"); ALOGE("Error appending userid to path");
return -1; return -1;
} }
} }
@ -138,10 +139,10 @@ int create_persona_path(char path[PKG_PATH_MAX],
} }
/** /**
* Create the path name for media for a certain persona. * Create the path name for media for a certain userid.
* Returns 0 on success, and -1 on failure. * Returns 0 on success, and -1 on failure.
*/ */
int create_persona_media_path(char path[PATH_MAX], userid_t userid) { int create_user_media_path(char path[PATH_MAX], userid_t userid) {
if (snprintf(path, PATH_MAX, "%s%d", android_media_dir.path, userid) > PATH_MAX) { if (snprintf(path, PATH_MAX, "%s%d", android_media_dir.path, userid) > PATH_MAX) {
return -1; return -1;
} }
@ -151,7 +152,7 @@ int create_persona_media_path(char path[PATH_MAX], userid_t userid) {
int create_move_path(char path[PKG_PATH_MAX], int create_move_path(char path[PKG_PATH_MAX],
const char* pkgname, const char* pkgname,
const char* leaf, const char* leaf,
uid_t persona) userid_t userid)
{ {
if ((android_data_dir.len + strlen(PRIMARY_USER_PREFIX) + strlen(pkgname) + strlen(leaf) + 1) if ((android_data_dir.len + strlen(PRIMARY_USER_PREFIX) + strlen(pkgname) + strlen(leaf) + 1)
>= PKG_PATH_MAX) { >= PKG_PATH_MAX) {
@ -997,7 +998,7 @@ int ensure_media_user_dirs(userid_t userid) {
char path[PATH_MAX]; char path[PATH_MAX];
// Ensure /data/media/<userid> exists // Ensure /data/media/<userid> exists
create_persona_media_path(media_user_path, userid); create_user_media_path(media_user_path, userid);
if (fs_prepare_dir(media_user_path, 0770, AID_MEDIA_RW, AID_MEDIA_RW) == -1) { if (fs_prepare_dir(media_user_path, 0770, AID_MEDIA_RW, AID_MEDIA_RW) == -1) {
return -1; return -1;
} }