summaryrefslogtreecommitdiffstats
path: root/init/devices.c
diff options
context:
space:
mode:
Diffstat (limited to 'init/devices.c')
-rw-r--r--init/devices.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/init/devices.c b/init/devices.c
index 02698ef..ea9a4b2 100644
--- a/init/devices.c
+++ b/init/devices.c
@@ -15,6 +15,7 @@
*/
#include <errno.h>
+#include <fnmatch.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
@@ -77,6 +78,7 @@ struct perms_ {
unsigned int uid;
unsigned int gid;
unsigned short prefix;
+ unsigned short wildcard;
};
struct perm_node {
@@ -97,7 +99,8 @@ static list_declare(platform_names);
int add_dev_perms(const char *name, const char *attr,
mode_t perm, unsigned int uid, unsigned int gid,
- unsigned short prefix) {
+ unsigned short prefix,
+ unsigned short wildcard) {
struct perm_node *node = calloc(1, sizeof(*node));
if (!node)
return -ENOMEM;
@@ -116,6 +119,7 @@ int add_dev_perms(const char *name, const char *attr,
node->dp.uid = uid;
node->dp.gid = gid;
node->dp.prefix = prefix;
+ node->dp.wildcard = wildcard;
if (attr)
list_add_tail(&sys_perms, &node->plist);
@@ -140,6 +144,9 @@ void fixup_sys_perms(const char *upath)
if (dp->prefix) {
if (strncmp(upath, dp->name + 4, strlen(dp->name + 4)))
continue;
+ } else if (dp->wildcard) {
+ if (fnmatch(dp->name + 4, upath, FNM_PATHNAME) != 0)
+ continue;
} else {
if (strcmp(upath, dp->name + 4))
continue;
@@ -180,6 +187,9 @@ static mode_t get_device_perm(const char *path, unsigned *uid, unsigned *gid)
if (dp->prefix) {
if (strncmp(path, dp->name, strlen(dp->name)))
continue;
+ } else if (dp->wildcard) {
+ if (fnmatch(dp->name, path, FNM_PATHNAME) != 0)
+ continue;
} else {
if (strcmp(path, dp->name))
continue;