summaryrefslogtreecommitdiff
path: root/src/udev/udev-node.c
diff options
context:
space:
mode:
authorKay Sievers <kay@vrfy.org>2013-10-08 01:59:10 +0200
committerKay Sievers <kay@vrfy.org>2013-10-08 02:23:24 +0200
commitc26547d612733371494330e26c7d3604a5dba3d9 (patch)
tree2a89eb3090316bd0c91f3c10aa2b66adc11065dd /src/udev/udev-node.c
parent8b197c3a8a57c3f7c231b39e5660856fd9580c80 (diff)
udev: support custom Linux Security Module labels for device nodes
Diffstat (limited to 'src/udev/udev-node.c')
-rw-r--r--src/udev/udev-node.c40
1 files changed, 35 insertions, 5 deletions
diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c
index 1148a1529c..6c9bef331e 100644
--- a/src/udev/udev-node.c
+++ b/src/udev/udev-node.c
@@ -28,6 +28,9 @@
#include <sys/time.h>
#include <sys/stat.h>
#include <sys/types.h>
+#ifdef HAVE_XATTR
+#include <attr/xattr.h>
+#endif
#include "udev.h"
@@ -252,11 +255,13 @@ void udev_node_update_old_links(struct udev_device *dev, struct udev_device *dev
}
}
-static int node_permissions_apply(struct udev_device *dev, bool apply, mode_t mode, uid_t uid, gid_t gid)
-{
+static int node_permissions_apply(struct udev_device *dev, bool apply,
+ mode_t mode, uid_t uid, gid_t gid,
+ struct udev_list *seclabel_list) {
const char *devnode = udev_device_get_devnode(dev);
dev_t devnum = udev_device_get_devnum(dev);
struct stat stats;
+ struct udev_list_entry *entry;
int err = 0;
if (streq(udev_device_get_subsystem(dev), "block"))
@@ -285,7 +290,31 @@ static int node_permissions_apply(struct udev_device *dev, bool apply, mode_t mo
} else {
log_debug("preserve permissions %s, %#o, uid=%u, gid=%u\n", devnode, mode, uid, gid);
}
+
label_fix(devnode, true, false);
+
+ /* apply SECLABEL{$module}=$label */
+ udev_list_entry_foreach(entry, udev_list_get_entry(seclabel_list)) {
+ const char *name, *label;
+
+ name = udev_list_entry_get_name(entry);
+ label = udev_list_entry_get_value(entry);
+
+ if (streq(name, "selinux")) {
+ /* FIXME: hook up libselinux */
+ log_error("SECLABEL: failed to set selinux label '%s'", label);
+
+ } else if (streq(name, "smack")) {
+#ifdef HAVE_XATTR
+ if (lsetxattr(devnode, "security.SMACK64", label, strlen(label), 0) < 0)
+ log_error("SECLABEL: failed to set SMACK label '%s'", label);
+ else
+ log_debug("SECLABEL: set SMACK label '%s'", label);
+#endif
+
+ } else
+ log_error("SECLABEL: unknown subsystem, ignoring '%s'='%s'", name, label);
+ }
}
/* always update timestamp when we re-use the node, like on media change events */
@@ -294,15 +323,16 @@ out:
return err;
}
-void udev_node_add(struct udev_device *dev, bool apply, mode_t mode, uid_t uid, gid_t gid)
-{
+void udev_node_add(struct udev_device *dev, bool apply,
+ mode_t mode, uid_t uid, gid_t gid,
+ struct udev_list *seclabel_list) {
char filename[UTIL_PATH_SIZE];
struct udev_list_entry *list_entry;
log_debug("handling device node '%s', devnum=%s, mode=%#o, uid=%d, gid=%d\n",
udev_device_get_devnode(dev), udev_device_get_id_filename(dev), mode, uid, gid);
- if (node_permissions_apply(dev, apply, mode, uid, gid) < 0)
+ if (node_permissions_apply(dev, apply, mode, uid, gid, seclabel_list) < 0)
return;
/* always add /dev/{block,char}/$major:$minor */