summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKay Sievers <kay@vrfy.org>2013-01-27 21:46:36 +0100
committerKay Sievers <kay@vrfy.org>2013-01-27 21:46:36 +0100
commit22582bb2cbe85b40de5f561589e0468dac769515 (patch)
treeb051535729d9890599dab7d112eea3541748c1ee /src
parentd970bd6d39f808b29a804050747c0883fcc2784b (diff)
udev: set default rules permissions only at "add" events
Diffstat (limited to 'src')
-rw-r--r--src/udev/udev-event.c5
-rw-r--r--src/udev/udev-node.c17
-rw-r--r--src/udev/udev.h2
3 files changed, 9 insertions, 15 deletions
diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c
index 8c8b058df7..ef9fc61c64 100644
--- a/src/udev/udev-event.c
+++ b/src/udev/udev-event.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2010 Kay Sievers <kay@vrfy.org>
+ * Copyright (C) 2003-2013 Kay Sievers <kay@vrfy.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -861,7 +861,8 @@ int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules,
}
}
- udev_node_add(dev, event->mode, event->uid, event->gid);
+ udev_node_add(dev, event->owner_set || event->group_set || event->mode_set,
+ event->mode, event->uid, event->gid);
}
/* preserve old, or get new initialization timestamp */
diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c
index 3eec14021b..bce4cfe433 100644
--- a/src/udev/udev-node.c
+++ b/src/udev/udev-node.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2010 Kay Sievers <kay@vrfy.org>
+ * Copyright (C) 2003-2013 Kay Sievers <kay@vrfy.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -254,7 +254,7 @@ void udev_node_update_old_links(struct udev_device *dev, struct udev_device *dev
}
}
-static int node_fixup(struct udev_device *dev, 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)
{
const char *devnode = udev_device_get_devnode(dev);
dev_t devnum = udev_device_get_devnum(dev);
@@ -279,13 +279,7 @@ static int node_fixup(struct udev_device *dev, mode_t mode, uid_t uid, gid_t gid
goto out;
}
- /*
- * Set permissions and selinux file context only on add events. We always
- * set it on bootup (coldplug) with "trigger --action=add" for all devices
- * and for any newly added devices (hotplug). We don't want to change it
- * later, in case something else has applied custom settings in the meantime.
- */
- if (strcmp(udev_device_get_action(dev), "add") == 0) {
+ if (apply) {
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);
chmod(devnode, mode);
@@ -293,7 +287,6 @@ static int node_fixup(struct udev_device *dev, mode_t mode, uid_t uid, gid_t gid
} else {
log_debug("preserve permissions %s, %#o, uid=%u, gid=%u\n", devnode, mode, uid, gid);
}
-
label_fix(devnode, true, false);
}
@@ -303,7 +296,7 @@ out:
return err;
}
-void udev_node_add(struct udev_device *dev, 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 *udev = udev_device_get_udev(dev);
char filename[UTIL_PATH_SIZE];
@@ -312,7 +305,7 @@ void udev_node_add(struct udev_device *dev, mode_t mode, uid_t uid, gid_t gid)
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_fixup(dev, mode, uid, gid) < 0)
+ if (node_permissions_apply(dev, apply, mode, uid, gid) < 0)
return;
/* always add /dev/{block,char}/$major:$minor */
diff --git a/src/udev/udev.h b/src/udev/udev.h
index 72a7623e34..b54cb58fc3 100644
--- a/src/udev/udev.h
+++ b/src/udev/udev.h
@@ -95,7 +95,7 @@ void udev_watch_end(struct udev *udev, struct udev_device *dev);
struct udev_device *udev_watch_lookup(struct udev *udev, int wd);
/* udev-node.c */
-void udev_node_add(struct udev_device *dev, 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);
void udev_node_remove(struct udev_device *dev);
void udev_node_update_old_links(struct udev_device *dev, struct udev_device *dev_old);