X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fudev%2Fudev-node.c;h=200e24fb412c11060702f72f493392be657ce899;hp=c5d629d1ce1793127e845e0c96fb3202a3a4fb15;hb=d13394a88334441bf3092cf93804ba0f9c56d8e0;hpb=d682b3a7e7c7c2941a4d3e193f1e330dbc9fae89 diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c index c5d629d1c..200e24fb4 100644 --- a/src/udev/udev-node.c +++ b/src/udev/udev-node.c @@ -28,12 +28,9 @@ #include #include #include -#ifdef HAVE_XATTR -#include -#endif -#include "smack-util.h" #include "udev.h" +#include "smack-util.h" static int node_symlink(struct udev_device *dev, const char *node, const char *slink) { @@ -69,7 +66,7 @@ static int node_symlink(struct udev_device *dev, const char *node, const char *s /* preserve link with correct target, do not replace node of other device */ if (lstat(slink, &stats) == 0) { if (S_ISBLK(stats.st_mode) || S_ISCHR(stats.st_mode)) { - log_error("conflicting device node '%s' found, link to '%s' will not be created\n", slink, node); + log_error("conflicting device node '%s' found, link to '%s' will not be created", slink, node); goto exit; } else if (S_ISLNK(stats.st_mode)) { char buf[UTIL_PATH_SIZE]; @@ -79,7 +76,7 @@ static int node_symlink(struct udev_device *dev, const char *node, const char *s if (len > 0 && len < (int)sizeof(buf)) { buf[len] = '\0'; if (streq(target, buf)) { - log_debug("preserve already existing symlink '%s' to '%s'\n", slink, target); + log_debug("preserve already existing symlink '%s' to '%s'", slink, target); label_fix(slink, true, false); utimensat(AT_FDCWD, slink, NULL, AT_SYMLINK_NOFOLLOW); goto exit; @@ -87,7 +84,7 @@ static int node_symlink(struct udev_device *dev, const char *node, const char *s } } } else { - log_debug("creating symlink '%s' to '%s'\n", slink, target); + log_debug("creating symlink '%s' to '%s'", slink, target); do { err = mkdir_parents_label(slink, 0755); if (err != 0 && err != -ENOENT) @@ -102,7 +99,7 @@ static int node_symlink(struct udev_device *dev, const char *node, const char *s goto exit; } - log_debug("atomically replace '%s'\n", slink); + log_debug("atomically replace '%s'", slink); strscpyl(slink_tmp, sizeof(slink_tmp), slink, ".tmp-", udev_device_get_id_filename(dev), NULL); unlink(slink_tmp); do { @@ -116,12 +113,12 @@ static int node_symlink(struct udev_device *dev, const char *node, const char *s label_context_clear(); } while (err == -ENOENT); if (err != 0) { - log_error("symlink '%s' '%s' failed: %m\n", target, slink_tmp); + log_error("symlink '%s' '%s' failed: %m", target, slink_tmp); goto exit; } err = rename(slink_tmp, slink); if (err != 0) { - log_error("rename '%s' '%s' failed: %m\n", slink_tmp, slink); + log_error("rename '%s' '%s' failed: %m", slink_tmp, slink); unlink(slink_tmp); } exit: @@ -155,7 +152,7 @@ static const char *link_find_prioritized(struct udev_device *dev, bool add, cons if (dent->d_name[0] == '.') continue; - log_debug("found '%s' claiming '%s'\n", dent->d_name, stackdir); + log_debug("found '%s' claiming '%s'", dent->d_name, stackdir); /* did we find ourself? */ if (streq(dent->d_name, udev_device_get_id_filename(dev))) @@ -168,7 +165,7 @@ static const char *link_find_prioritized(struct udev_device *dev, bool add, cons devnode = udev_device_get_devnode(dev_db); if (devnode != NULL) { if (target == NULL || udev_device_get_devlink_priority(dev_db) > priority) { - log_debug("'%s' claims priority %i for '%s'\n", + log_debug("'%s' claims priority %i for '%s'", udev_device_get_syspath(dev_db), udev_device_get_devlink_priority(dev_db), stackdir); priority = udev_device_get_devlink_priority(dev_db); strscpy(buf, bufsize, devnode); @@ -201,11 +198,11 @@ static void link_update(struct udev_device *dev, const char *slink, bool add) target = link_find_prioritized(dev, add, dirname, buf, sizeof(buf)); if (target == NULL) { - log_debug("no reference left, remove '%s'\n", slink); + log_debug("no reference left, remove '%s'", slink); if (unlink(slink) == 0) util_delete_path(udev, slink); } else { - log_debug("creating link '%s' to '%s'\n", slink, target); + log_debug("creating link '%s' to '%s'", slink, target); node_symlink(dev, target, slink); } @@ -250,7 +247,7 @@ void udev_node_update_old_links(struct udev_device *dev, struct udev_device *dev if (found) continue; - log_debug("update old name, '%s' no longer belonging to '%s'\n", + log_debug("update old name, '%s' no longer belonging to '%s'", name, udev_device_get_devpath(dev)); link_update(dev, name, false); } @@ -272,29 +269,27 @@ static int node_permissions_apply(struct udev_device *dev, bool apply, if (lstat(devnode, &stats) != 0) { err = -errno; - log_debug("can not stat() node '%s' (%m)\n", devnode); + log_debug("can not stat() node '%s' (%m)", devnode); goto out; } if (((stats.st_mode & S_IFMT) != (mode & S_IFMT)) || (stats.st_rdev != devnum)) { err = -EEXIST; - log_debug("found node '%s' with non-matching devnum %s, skip handling\n", + log_debug("found node '%s' with non-matching devnum %s, skip handling", udev_device_get_devnode(dev), udev_device_get_id_filename(dev)); goto out; } if (apply) { bool selinux = false; -#ifdef HAVE_SMACK bool smack = false; -#endif if ((stats.st_mode & 0777) != (mode & 0777) || stats.st_uid != uid || stats.st_gid != gid) { - log_debug("set permissions %s, %#o, uid=%u, gid=%u\n", devnode, mode, uid, gid); + log_debug("set permissions %s, %#o, uid=%u, gid=%u", devnode, mode, uid, gid); chmod(devnode, mode); chown(devnode, uid, gid); } else { - log_debug("preserve permissions %s, %#o, uid=%u, gid=%u\n", devnode, mode, uid, gid); + log_debug("preserve permissions %s, %#o, uid=%u, gid=%u", devnode, mode, uid, gid); } /* apply SECLABEL{$module}=$label */ @@ -311,14 +306,12 @@ static int node_permissions_apply(struct udev_device *dev, bool apply, else log_debug("SECLABEL: set SELinux label '%s'", label); -#ifdef HAVE_SMACK - } else if (streq(name, "smack") && use_smack()) { + } else if (streq(name, "smack")) { smack = true; - if (lsetxattr(devnode, "security.SMACK64", label, strlen(label), 0) < 0) + if (smack_label_path(devnode, label) < 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); @@ -327,10 +320,8 @@ static int node_permissions_apply(struct udev_device *dev, bool apply, /* set the defaults */ if (!selinux) label_fix(devnode, true, false); -#ifdef HAVE_SMACK - if (!smack && use_smack()) - lremovexattr(devnode, "security.SMACK64"); -#endif + if (!smack) + smack_label_path(devnode, NULL); } /* always update timestamp when we re-use the node, like on media change events */ @@ -345,7 +336,7 @@ void udev_node_add(struct udev_device *dev, bool apply, 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", + log_debug("handling device node '%s', devnum=%s, mode=%#o, uid=%d, gid=%d", udev_device_get_devnode(dev), udev_device_get_id_filename(dev), mode, uid, gid); if (node_permissions_apply(dev, apply, mode, uid, gid, seclabel_list) < 0)