am 06023134: am 8022ce1e: Merge "ueventd fixup_sys_perms: fixup SELinux labels unconditionally"

* commit '060231346b9901f28ee8692518bcbc059e5777ca':
  ueventd fixup_sys_perms: fixup SELinux labels unconditionally
This commit is contained in:
Nick Kralevich 2014-07-07 19:59:26 +00:00 committed by Android Git Automerger
commit 7367ecbc48

View file

@ -134,11 +134,10 @@ void fixup_sys_perms(const char *upath)
char buf[512]; char buf[512];
struct listnode *node; struct listnode *node;
struct perms_ *dp; struct perms_ *dp;
char *secontext;
/* upaths omit the "/sys" that paths in this list /* upaths omit the "/sys" that paths in this list
* contain, so we add 4 when comparing... * contain, so we add 4 when comparing...
*/ */
list_for_each(node, &sys_perms) { list_for_each(node, &sys_perms) {
dp = &(node_to_item(node, struct perm_node, plist))->dp; dp = &(node_to_item(node, struct perm_node, plist))->dp;
if (dp->prefix) { if (dp->prefix) {
@ -153,20 +152,23 @@ void fixup_sys_perms(const char *upath)
} }
if ((strlen(upath) + strlen(dp->attr) + 6) > sizeof(buf)) if ((strlen(upath) + strlen(dp->attr) + 6) > sizeof(buf))
return; break;
sprintf(buf,"/sys%s/%s", upath, dp->attr); sprintf(buf,"/sys%s/%s", upath, dp->attr);
INFO("fixup %s %d %d 0%o\n", buf, dp->uid, dp->gid, dp->perm); INFO("fixup %s %d %d 0%o\n", buf, dp->uid, dp->gid, dp->perm);
chown(buf, dp->uid, dp->gid); chown(buf, dp->uid, dp->gid);
chmod(buf, dp->perm); chmod(buf, dp->perm);
if (sehandle) { }
secontext = NULL;
selabel_lookup(sehandle, &secontext, buf, 0); // Now fixup SELinux file labels
if (secontext) { int len = snprintf(buf, sizeof(buf), "/sys%s", upath);
setfilecon(buf, secontext); if ((len < 0) || ((size_t) len >= sizeof(buf))) {
freecon(secontext); // Overflow
} return;
} }
if (access(buf, F_OK) == 0) {
INFO("restorecon_recursive: %s\n", buf);
restorecon_recursive(buf);
} }
} }