diff options
author | Robin Lee <rgl@google.com> | 2014-06-05 17:56:59 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-06-05 17:56:59 +0000 |
commit | 958ad9181a661deeaf95ad83d184cda1fa4171d7 (patch) | |
tree | 8c997cecbf72b45d2c05b7b498bee78cccf9f58d | |
parent | 9afbf0c799c249521a4ba480239c2c39eee76d2c (diff) | |
parent | 53b4926828fae0e78b467d49a6084b324bcbdcb7 (diff) | |
download | frameworks_native-958ad9181a661deeaf95ad83d184cda1fa4171d7.zip frameworks_native-958ad9181a661deeaf95ad83d184cda1fa4171d7.tar.gz frameworks_native-958ad9181a661deeaf95ad83d184cda1fa4171d7.tar.bz2 |
am 53b49268: am 8adb5a82: Merge "Add installd command to create /data/misc user dir"
* commit '53b4926828fae0e78b467d49a6084b324bcbdcb7':
Add installd command to create /data/misc user dir
-rw-r--r-- | cmds/installd/commands.c | 33 | ||||
-rw-r--r-- | cmds/installd/installd.c | 42 | ||||
-rw-r--r-- | cmds/installd/installd.h | 4 | ||||
-rw-r--r-- | cmds/installd/utils.c | 28 |
4 files changed, 97 insertions, 10 deletions
diff --git a/cmds/installd/commands.c b/cmds/installd/commands.c index 886fd3b..34a5353 100644 --- a/cmds/installd/commands.c +++ b/cmds/installd/commands.c @@ -265,25 +265,38 @@ int make_user_data(const char *pkgname, uid_t uid, userid_t userid, const char* return 0; } -int delete_user(userid_t userid) +int create_user(userid_t userid) { - char data_path[PKG_PATH_MAX]; - if (create_user_path(data_path, userid)) { + if (ensure_config_user_dirs(userid) == -1) { return -1; } - if (delete_dir_contents(data_path, 1, NULL)) { - return -1; + + return 0; +} + +int delete_user(userid_t userid) +{ + int status = 0; + + char data_path[PKG_PATH_MAX]; + if ((create_user_path(data_path, userid) != 0) + || (delete_dir_contents(data_path, 1, NULL) != 0)) { + status = -1; } char media_path[PATH_MAX]; - if (create_user_media_path(media_path, userid) == -1) { - return -1; + if ((create_user_media_path(media_path, userid) != 0) + || (delete_dir_contents(media_path, 1, NULL) != 0)) { + status = -1; } - if (delete_dir_contents(media_path, 1, NULL) == -1) { - return -1; + + char config_path[PATH_MAX]; + if ((create_user_config_path(config_path, userid) != 0) + || (delete_dir_contents(config_path, 1, NULL) != 0)) { + status = -1; } - return 0; + return status; } int delete_cache(const char *pkgname, userid_t userid) diff --git a/cmds/installd/installd.c b/cmds/installd/installd.c index 10bf5fa..064ee32 100644 --- a/cmds/installd/installd.c +++ b/cmds/installd/installd.c @@ -109,6 +109,11 @@ static int do_mk_user_data(char **arg, char reply[REPLY_MAX]) /* pkgname, uid, userid, seinfo */ } +static int do_mk_user(char **arg, char reply[REPLY_MAX]) +{ + return create_user(atoi(arg[0])); /* userid */ +} + static int do_rm_user(char **arg, char reply[REPLY_MAX]) { return delete_user(atoi(arg[0])); /* userid */ @@ -157,6 +162,7 @@ struct cmdinfo cmds[] = { { "movefiles", 0, do_movefiles }, { "linklib", 3, do_linklib }, { "mkuserdata", 4, do_mk_user_data }, + { "mkuser", 1, do_mk_user }, { "rmuser", 1, do_rm_user }, { "idmap", 3, do_idmap }, { "restorecondata", 3, do_restorecon_data }, @@ -483,6 +489,42 @@ int initialize_directories() { goto fail; } + if (version == 2) { + ALOGD("Upgrading to /data/misc/user directories"); + + DIR *dir; + struct dirent *dirent; + char user_data_dir[PATH_MAX]; + + dir = opendir(user_data_dir); + if (dir != NULL) { + while ((dirent = readdir(dir))) { + if (dirent->d_type == DT_DIR) { + const char *name = dirent->d_name; + + // skip "." and ".." + if (name[0] == '.') { + if (name[1] == 0) continue; + if ((name[1] == '.') && (name[2] == 0)) continue; + } + + // /data/misc/user/<user_id> + if (ensure_config_user_dirs(atoi(name)) == -1) { + goto fail; + } + } + } + closedir(dir); + } + + version = 3; + } + + if (ensure_config_user_dirs(0) == -1) { + ALOGE("Failed to setup misc for user 0"); + goto fail; + } + // Persist layout version if changed if (version != oldVersion) { if (fs_write_atomic_int(version_path, version) == -1) { diff --git a/cmds/installd/installd.h b/cmds/installd/installd.h index 0f7119d..ff26e49 100644 --- a/cmds/installd/installd.h +++ b/cmds/installd/installd.h @@ -145,6 +145,8 @@ int create_user_path(char path[PKG_PATH_MAX], int create_user_media_path(char path[PKG_PATH_MAX], userid_t userid); +int create_user_config_path(char path[PKG_PATH_MAX], userid_t userid); + int create_move_path(char path[PKG_PATH_MAX], const char* pkgname, const char* leaf, @@ -190,6 +192,7 @@ char *build_string3(char *s1, char *s2, char *s3); int ensure_dir(const char* path, mode_t mode, uid_t uid, gid_t gid); int ensure_media_user_dirs(userid_t userid); +int ensure_config_user_dirs(userid_t userid); int create_profile_file(const char *pkgname, gid_t gid); void remove_profile_file(const char *pkgname); @@ -201,6 +204,7 @@ int renamepkg(const char *oldpkgname, const char *newpkgname); int fix_uid(const char *pkgname, uid_t uid, gid_t gid); int delete_user_data(const char *pkgname, userid_t userid); int make_user_data(const char *pkgname, uid_t uid, userid_t userid, const char* seinfo); +int create_user(userid_t userid); int delete_user(userid_t userid); int delete_cache(const char *pkgname, userid_t userid); int move_dex(const char *src, const char *dst, const char *instruction_set); diff --git a/cmds/installd/utils.c b/cmds/installd/utils.c index 671d031..420ad5e 100644 --- a/cmds/installd/utils.c +++ b/cmds/installd/utils.c @@ -149,6 +149,17 @@ int create_user_media_path(char path[PATH_MAX], userid_t userid) { return 0; } +/** + * Create the path name for config for a certain userid. + * Returns 0 on success, and -1 on failure. + */ +int create_user_config_path(char path[PATH_MAX], userid_t userid) { + if (snprintf(path, PATH_MAX, "%s%d", "/data/misc/user/", userid) > PATH_MAX) { + return -1; + } + return 0; +} + int create_move_path(char path[PKG_PATH_MAX], const char* pkgname, const char* leaf, @@ -1006,6 +1017,23 @@ int ensure_media_user_dirs(userid_t userid) { return 0; } +int ensure_config_user_dirs(userid_t userid) { + char config_user_path[PATH_MAX]; + char path[PATH_MAX]; + + // writable by system, readable by any app within the same user + const int uid = (userid * AID_USER) + AID_SYSTEM; + const int gid = (userid * AID_USER) + AID_EVERYBODY; + + // Ensure /data/misc/user/<userid> exists + create_user_config_path(config_user_path, userid); + if (fs_prepare_dir(config_user_path, 0750, uid, gid) == -1) { + return -1; + } + + return 0; +} + int create_profile_file(const char *pkgname, gid_t gid) { const char *profile_dir = DALVIK_CACHE_PREFIX "profiles"; struct stat profileStat; |