#include "libudev.h"
#include "libudev-private.h"
-int util_create_path(struct udev *udev, const char *path)
+static int create_path(struct udev *udev, const char *path, bool selinux)
{
char p[UTIL_PATH_SIZE];
char *pos;
return err;
dbg(udev, "mkdir '%s'\n", p);
- udev_selinux_setfscreatecon(udev, p, S_IFDIR|0755);
+ if (selinux)
+ udev_selinux_setfscreatecon(udev, p, S_IFDIR|0755);
err = mkdir(p, 0755);
if (err != 0) {
err = -errno;
err = -ENOTDIR;
}
}
- udev_selinux_resetfscreatecon(udev);
+ if (selinux)
+ udev_selinux_resetfscreatecon(udev);
return err;
}
+int util_create_path(struct udev *udev, const char *path)
+{
+ return create_path(udev, path, false);
+}
+
+int util_create_path_selinux(struct udev *udev, const char *path)
+{
+ return create_path(udev, path, true);
+}
+
int util_delete_path(struct udev *udev, const char *path)
{
char p[UTIL_PATH_SIZE];
} else {
info(udev, "mknod '%s' %u:%u %#o\n", file, major(devnum), minor(devnum), mode);
do {
- err = util_create_path(udev, file);
+ err = util_create_path_selinux(udev, file);
if (err != 0 && err != -ENOENT)
break;
udev_selinux_setfscreatecon(udev, file, mode);
} else {
info(udev, "creating symlink '%s' to '%s'\n", slink, target);
do {
- err = util_create_path(udev, slink);
+ err = util_create_path_selinux(udev, slink);
if (err != 0 && err != -ENOENT)
break;
udev_selinux_setfscreatecon(udev, slink, S_IFLNK);
util_strscpyl(slink_tmp, sizeof(slink_tmp), slink, TMP_FILE_EXT, NULL);
unlink(slink_tmp);
do {
- err = util_create_path(udev, slink_tmp);
+ err = util_create_path_selinux(udev, slink_tmp);
if (err != 0 && err != -ENOENT)
break;
udev_selinux_setfscreatecon(udev, slink_tmp, S_IFLNK);
continue;
util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/", devname, NULL);
- util_create_path(udev, filename);
+ util_create_path_selinux(udev, filename);
udev_selinux_setfscreatecon(udev, filename, mode);
info(udev, "mknod '%s' %c%u:%u\n", filename, type, maj, min);
if (mknod(filename, mode, makedev(maj, min)) < 0 && errno == EEXIST)
fclose(f);
}
-static int copy_dir(struct udev *udev, DIR *dir_from, DIR *dir_to, int maxdepth)
+static int copy_dev_dir(struct udev *udev, DIR *dir_from, DIR *dir_to, int maxdepth)
{
struct dirent *dent;
continue;
}
- copy_dir(udev, dir2_from, dir2_to, maxdepth-1);
+ copy_dev_dir(udev, dir2_from, dir2_to, maxdepth-1);
closedir(dir2_to);
closedir(dir2_from);
dir_from = opendir(LIBEXECDIR "/devices");
if (dir_from == NULL)
return;
- copy_dir(udev, dir_from, dir, 8);
+ copy_dev_dir(udev, dir_from, dir, 8);
closedir(dir_from);
}
/* make sure we do not get here again */
util_create_path(udev, filename);
- udev_selinux_setfscreatecon(udev, udev_get_run_path(udev), S_IFDIR|0755);
mkdir(filename, 0755);
- udev_selinux_resetfscreatecon(udev);
/* old database */
util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/.udev/db", NULL);
/* make sure, that our runtime dir exists and is writable */
if (utimensat(AT_FDCWD, udev_get_run_config_path(udev), NULL, 0) < 0) {
/* try to create our own subdirectory, do not create parent directories */
- udev_selinux_setfscreatecon(udev, udev_get_run_config_path(udev), S_IFDIR|0755);
mkdir(udev_get_run_config_path(udev), 0755);
- udev_selinux_resetfscreatecon(udev);
if (utimensat(AT_FDCWD, udev_get_run_config_path(udev), NULL, 0) >= 0) {
/* directory seems writable now */
util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/.udev", NULL);
if (udev_set_run_path(udev, filename) == NULL)
goto exit;
+ mkdir(udev_get_run_path(udev), 0755);
}
}
+ /* relabel runtime dir only if it resides below /dev */
+ if (strncmp(udev_get_run_path(udev), udev_get_dev_path(udev), strlen(udev_get_dev_path(udev))) == 0)
+ udev_selinux_lsetfilecon(udev, udev_get_run_path(udev), 0755);
info(udev, "runtime dir '%s'\n", udev_get_run_path(udev));
for (;;) {
util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/rules.d", NULL);
if (stat(filename, &statbuf) != 0) {
util_create_path(udev, filename);
- udev_selinux_setfscreatecon(udev, filename, S_IFDIR|0755);
mkdir(filename, 0755);
- udev_selinux_resetfscreatecon(udev);
}
inotify_add_watch(pfd[FD_INOTIFY].fd, filename,
IN_DELETE | IN_MOVE | IN_CLOSE_WRITE);