Restore contexts when doing mkdierhier in libtar

Do a restore of loaded file contexts to /data/media directory. This will help denials to be prevented when internal storage is wiped.

Change-Id: Ie49bbfa48d2f3ee4f08376d9c1877b92c051017c
This commit is contained in:
bigbiff bigbiff
2014-02-06 19:56:25 -05:00
parent 6c694b6f0b
commit 6b600f9644
5 changed files with 54 additions and 10 deletions
+32 -1
View File
@@ -74,18 +74,48 @@ int fixPermissions::fixDataDataContexts(void) {
struct selinux_opt selinux_options[] = {
{ SELABEL_OPT_PATH, "/file_contexts" }
};
selinux_handle = selabel_open(SELABEL_CTX_FILE, selinux_options, 1);
if (!selinux_handle)
printf("No file contexts for SELinux\n");
else
printf("SELinux contexts loaded from /file_contexts\n");
d = opendir("/data/data");
while (( de = readdir(d)) != NULL) {
stat(de->d_name, &sb);
string f = "/data/data/";
f = f + de->d_name;
restorecon(f, &sb);
}
closedir(d);
return 0;
}
int fixPermissions::fixDataInternalContexts(void) {
DIR *d;
struct dirent *de;
struct stat sb;
string dir;
if (TWFunc::Path_Exists("/data/media")) {
dir = "/data/media";
}
else {
dir = "/data/media/0";
}
LOGINFO("Fixing %s contexts\n", dir.c_str());
d = opendir(dir.c_str());
while (( de = readdir(d)) != NULL) {
stat(de->d_name, &sb);
string f;
f = dir + de->d_name;
restorecon(f, &sb);
}
closedir(d);
return 0;
}
#endif
@@ -173,8 +203,9 @@ int fixPermissions::fixPerms(bool enable_debug, bool remove_data_for_missing_app
}
}
#ifdef HAVE_SELINUX
gui_print("Fixing /data/data contexts.\n");
gui_print("Fixing /data/data/ contexts.\n");
fixDataDataContexts();
fixDataInternalContexts();
#endif
gui_print("Done fixing permissions.\n");
return 0;