Consistent creation/destruction of user data.
Preparing and destroying users currently needs to be split across
installd, system_server, and vold, since no single party has all the
required SELinux permissions.
Start passing down flags so we only prepare/destroy storage areas
that have keys currently installed.
Add delete_dir_contents_and_dir() argument to ignore ENOENT, since
all we care about is the directory being gone.
Bug: 27896918
Change-Id: Ia1cccc9b35e6ff09e3ca50effeab676157b856e8
diff --git a/cmds/installd/utils.cpp b/cmds/installd/utils.cpp
index 5c2ad2d..90d2a9e 100644
--- a/cmds/installd/utils.cpp
+++ b/cmds/installd/utils.cpp
@@ -193,6 +193,10 @@
return StringPrintf("%s/media/%u", create_data_path(volume_uuid).c_str(), userid);
}
+std::string create_data_misc_legacy_path(userid_t userid) {
+ return StringPrintf("%s/misc/user/%u", create_data_path(nullptr).c_str(), userid);
+}
+
std::string create_data_user_profiles_path(userid_t userid) {
return StringPrintf("%s/cur/%u", android_profiles_dir.path, userid);
}
@@ -239,17 +243,6 @@
return users;
}
-/**
- * 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,
@@ -1219,19 +1212,13 @@
}
int ensure_config_user_dirs(userid_t userid) {
- char config_user_path[PATH_MAX];
-
// writable by system, readable by any app within the same user
const int uid = multiuser_get_uid(userid, AID_SYSTEM);
const int gid = multiuser_get_uid(userid, 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;
+ auto path = create_data_misc_legacy_path(userid);
+ return fs_prepare_dir(path.c_str(), 0750, uid, gid);
}
int wait_child(pid_t pid)