mirror of
https://github.com/AuxXxilium/eudev.git
synced 2024-12-28 06:35:34 +07:00
Honor DEVUID, DEVGID in addition to DEVMODE
New behaviour in udev-197 systemd commit 1edefa4f1d7bae6cc19aa4a97238400c5a04f7a4 Author: Kay Sievers <kay@vrfy.org> Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
This commit is contained in:
parent
cc9cf4c078
commit
ab779c8146
@ -60,6 +60,8 @@ struct udev_device {
|
||||
const char *sysnum;
|
||||
char *devnode;
|
||||
mode_t devnode_mode;
|
||||
uid_t devnode_uid;
|
||||
gid_t devnode_gid;
|
||||
char *subsystem;
|
||||
char *devtype;
|
||||
char *driver;
|
||||
@ -323,6 +325,40 @@ static int udev_device_set_devnode_mode(struct udev_device *udev_device, mode_t
|
||||
return 0;
|
||||
}
|
||||
|
||||
uid_t udev_device_get_devnode_uid(struct udev_device *udev_device)
|
||||
{
|
||||
if (!udev_device->info_loaded)
|
||||
udev_device_read_uevent_file(udev_device);
|
||||
return udev_device->devnode_uid;
|
||||
}
|
||||
|
||||
static int udev_device_set_devnode_uid(struct udev_device *udev_device, uid_t uid)
|
||||
{
|
||||
char num[32];
|
||||
|
||||
udev_device->devnode_uid = uid;
|
||||
snprintf(num, sizeof(num), "%u", uid);
|
||||
udev_device_add_property(udev_device, "DEVUID", num);
|
||||
return 0;
|
||||
}
|
||||
|
||||
gid_t udev_device_get_devnode_gid(struct udev_device *udev_device)
|
||||
{
|
||||
if (!udev_device->info_loaded)
|
||||
udev_device_read_uevent_file(udev_device);
|
||||
return udev_device->devnode_gid;
|
||||
}
|
||||
|
||||
static int udev_device_set_devnode_gid(struct udev_device *udev_device, gid_t gid)
|
||||
{
|
||||
char num[32];
|
||||
|
||||
udev_device->devnode_gid = gid;
|
||||
snprintf(num, sizeof(num), "%u", gid);
|
||||
udev_device_add_property(udev_device, "DEVGID", num);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct udev_list_entry *udev_device_add_property(struct udev_device *udev_device, const char *key, const char *value)
|
||||
{
|
||||
udev_device->envp_uptodate = false;
|
||||
@ -430,6 +466,10 @@ void udev_device_add_property_from_string_parse(struct udev_device *udev_device,
|
||||
udev_device_set_ifindex(udev_device, strtoull(&property[8], NULL, 10));
|
||||
} else if (startswith(property, "DEVMODE=")) {
|
||||
udev_device_set_devnode_mode(udev_device, strtoul(&property[8], NULL, 8));
|
||||
} else if (startswith(property, "DEVUID=")) {
|
||||
udev_device_set_devnode_uid(udev_device, strtoul(&property[7], NULL, 10));
|
||||
} else if (startswith(property, "DEVGID=")) {
|
||||
udev_device_set_devnode_gid(udev_device, strtoul(&property[7], NULL, 10));
|
||||
} else {
|
||||
udev_device_add_property_from_string(udev_device, property);
|
||||
}
|
||||
|
@ -56,6 +56,8 @@ struct udev_list_entry *udev_get_properties_list_entry(struct udev *udev);
|
||||
/* libudev-device.c */
|
||||
struct udev_device *udev_device_new(struct udev *udev);
|
||||
mode_t udev_device_get_devnode_mode(struct udev_device *udev_device);
|
||||
uid_t udev_device_get_devnode_uid(struct udev_device *udev_device);
|
||||
gid_t udev_device_get_devnode_gid(struct udev_device *udev_device);
|
||||
int udev_device_set_subsystem(struct udev_device *udev_device, const char *subsystem);
|
||||
int udev_device_set_syspath(struct udev_device *udev_device, const char *syspath);
|
||||
int udev_device_set_devnode(struct udev_device *udev_device, const char *devnode);
|
||||
|
@ -849,6 +849,12 @@ int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules,
|
||||
if (event->dev_db != NULL)
|
||||
udev_node_update_old_links(dev, event->dev_db);
|
||||
|
||||
if (!event->owner_set)
|
||||
event->uid = udev_device_get_devnode_uid(dev);
|
||||
|
||||
if (!event->group_set)
|
||||
event->gid = udev_device_get_devnode_gid(dev);
|
||||
|
||||
if (!event->mode_set) {
|
||||
if (udev_device_get_devnode_mode(dev) > 0) {
|
||||
/* kernel supplied value */
|
||||
|
@ -2244,6 +2244,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event
|
||||
if (cur->key.op == OP_ASSIGN_FINAL)
|
||||
event->owner_final = true;
|
||||
udev_event_apply_format(event, rules_str(rules, cur->key.value_off), owner, sizeof(owner));
|
||||
event->owner_set = true;
|
||||
event->uid = util_lookup_user(event->udev, owner);
|
||||
log_debug("OWNER %u %s:%u\n",
|
||||
event->uid,
|
||||
@ -2259,6 +2260,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event
|
||||
if (cur->key.op == OP_ASSIGN_FINAL)
|
||||
event->group_final = true;
|
||||
udev_event_apply_format(event, rules_str(rules, cur->key.value_off), group, sizeof(group));
|
||||
event->group_set = true;
|
||||
event->gid = util_lookup_group(event->udev, group);
|
||||
log_debug("GROUP %u %s:%u\n",
|
||||
event->gid,
|
||||
@ -2294,6 +2296,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event
|
||||
break;
|
||||
if (cur->key.op == OP_ASSIGN_FINAL)
|
||||
event->owner_final = true;
|
||||
event->owner_set = true;
|
||||
event->uid = cur->key.uid;
|
||||
log_debug("OWNER %u %s:%u\n",
|
||||
event->uid,
|
||||
@ -2305,6 +2308,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event
|
||||
break;
|
||||
if (cur->key.op == OP_ASSIGN_FINAL)
|
||||
event->group_final = true;
|
||||
event->group_set = true;
|
||||
event->gid = cur->key.gid;
|
||||
log_debug("GROUP %u %s:%u\n",
|
||||
event->gid,
|
||||
|
@ -49,7 +49,9 @@ struct udev_event {
|
||||
bool sigterm;
|
||||
bool inotify_watch;
|
||||
bool inotify_watch_final;
|
||||
bool group_set;
|
||||
bool group_final;
|
||||
bool owner_set;
|
||||
bool owner_final;
|
||||
bool mode_set;
|
||||
bool mode_final;
|
||||
|
Loading…
Reference in New Issue
Block a user