* commit 'ab7e5752b0f02d8a5b6d70b94c41eed9f4068005': ueventd: allow matching symlink names when setting permissions
This commit is contained in:
commit
b18d44e458
1 changed files with 38 additions and 13 deletions
|
|
@ -170,7 +170,24 @@ void fixup_sys_perms(const char *upath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static mode_t get_device_perm(const char *path, unsigned *uid, unsigned *gid)
|
static bool perm_path_matches(const char *path, struct perms_ *dp)
|
||||||
|
{
|
||||||
|
if (dp->prefix) {
|
||||||
|
if (strncmp(path, dp->name, strlen(dp->name)) == 0)
|
||||||
|
return true;
|
||||||
|
} else if (dp->wildcard) {
|
||||||
|
if (fnmatch(dp->name, path, FNM_PATHNAME) == 0)
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
if (strcmp(path, dp->name) == 0)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static mode_t get_device_perm(const char *path, const char **links,
|
||||||
|
unsigned *uid, unsigned *gid)
|
||||||
{
|
{
|
||||||
mode_t perm;
|
mode_t perm;
|
||||||
struct listnode *node;
|
struct listnode *node;
|
||||||
|
|
@ -181,22 +198,30 @@ static mode_t get_device_perm(const char *path, unsigned *uid, unsigned *gid)
|
||||||
* override ueventd.rc
|
* override ueventd.rc
|
||||||
*/
|
*/
|
||||||
list_for_each_reverse(node, &dev_perms) {
|
list_for_each_reverse(node, &dev_perms) {
|
||||||
|
bool match = false;
|
||||||
|
|
||||||
perm_node = node_to_item(node, struct perm_node, plist);
|
perm_node = node_to_item(node, struct perm_node, plist);
|
||||||
dp = &perm_node->dp;
|
dp = &perm_node->dp;
|
||||||
|
|
||||||
if (dp->prefix) {
|
if (perm_path_matches(path, dp)) {
|
||||||
if (strncmp(path, dp->name, strlen(dp->name)))
|
match = true;
|
||||||
continue;
|
|
||||||
} else if (dp->wildcard) {
|
|
||||||
if (fnmatch(dp->name, path, FNM_PATHNAME) != 0)
|
|
||||||
continue;
|
|
||||||
} else {
|
} else {
|
||||||
if (strcmp(path, dp->name))
|
if (links) {
|
||||||
continue;
|
int i;
|
||||||
|
for (i = 0; links[i]; i++) {
|
||||||
|
if (perm_path_matches(links[i], dp)) {
|
||||||
|
match = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (match) {
|
||||||
|
*uid = dp->uid;
|
||||||
|
*gid = dp->gid;
|
||||||
|
return dp->perm;
|
||||||
}
|
}
|
||||||
*uid = dp->uid;
|
|
||||||
*gid = dp->gid;
|
|
||||||
return dp->perm;
|
|
||||||
}
|
}
|
||||||
/* Default if nothing found. */
|
/* Default if nothing found. */
|
||||||
*uid = 0;
|
*uid = 0;
|
||||||
|
|
@ -215,7 +240,7 @@ static void make_device(const char *path,
|
||||||
dev_t dev;
|
dev_t dev;
|
||||||
char *secontext = NULL;
|
char *secontext = NULL;
|
||||||
|
|
||||||
mode = get_device_perm(path, &uid, &gid) | (block ? S_IFBLK : S_IFCHR);
|
mode = get_device_perm(path, links, &uid, &gid) | (block ? S_IFBLK : S_IFCHR);
|
||||||
|
|
||||||
if (sehandle) {
|
if (sehandle) {
|
||||||
selabel_lookup_best_match(sehandle, &secontext, path, links, mode);
|
selabel_lookup_best_match(sehandle, &secontext, path, links, mode);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue