summaryrefslogtreecommitdiff
path: root/src/udev/udev-node.c
diff options
context:
space:
mode:
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 */