summaryrefslogtreecommitdiff
path: root/src/udev
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-09-17 20:07:21 -0400
committerAnthony G. Basile <blueness@gentoo.org>2014-09-17 20:07:21 -0400
commit5216331b7d3b14362c2ddc4af6520011120475e4 (patch)
tree8c3012e7a4250914382beae507d5aa0ff5035c73 /src/udev
parent136e0eef04563f7d739c1db104c1cab673af85f3 (diff)
libudev: drop util_lookup_{user,group}
Use shared versions instead. Difference is with overwriting of repeated user/group name, and lack of logging. Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src/udev')
-rw-r--r--src/udev/udev-rules.c46
1 files changed, 40 insertions, 6 deletions
diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c
index 0dcd41734b..364e41b763 100644
--- a/src/udev/udev-rules.c
+++ b/src/udev/udev-rules.c
@@ -464,8 +464,9 @@ static int add_token(struct udev_rules *rules, struct token *token) {
static uid_t add_uid(struct udev_rules *rules, const char *owner) {
unsigned int i;
- uid_t uid;
+ uid_t uid = 0;
unsigned int off;
+ int r;
/* lookup, if we know it already */
for (i = 0; i < rules->uids_cur; i++) {
@@ -475,7 +476,13 @@ static uid_t add_uid(struct udev_rules *rules, const char *owner) {
return uid;
}
}
- uid = util_lookup_user(rules->udev, owner);
+ r = get_user_creds(&owner, &uid, NULL, NULL, NULL);
+ if (r < 0) {
+ if (r == -ENOENT || r == -ESRCH)
+ udev_err(rules->udev, "specified user '%s' unknown\n", owner);
+ else
+ udev_err(rules->udev, "error resolving user '%s': %s\n", owner, strerror(-r));
+ }
/* grow buffer if needed */
if (rules->uids_cur+1 >= rules->uids_max) {
@@ -504,8 +511,9 @@ static uid_t add_uid(struct udev_rules *rules, const char *owner) {
static gid_t add_gid(struct udev_rules *rules, const char *group) {
unsigned int i;
- gid_t gid;
+ gid_t gid = 0;
unsigned int off;
+ int r;
/* lookup, if we know it already */
for (i = 0; i < rules->gids_cur; i++) {
@@ -515,7 +523,13 @@ static gid_t add_gid(struct udev_rules *rules, const char *group) {
return gid;
}
}
- gid = util_lookup_group(rules->udev, group);
+ r = get_group_creds(&group, &gid);
+ if (r < 0) {
+ if (r == -ENOENT || r == -ESRCH)
+ udev_err(rules->udev, "specified group '%s' unknown\n", group);
+ else
+ udev_err(rules->udev, "error resolving group '%s': %s\n", group, strerror(-r));
+ }
/* grow buffer if needed */
if (rules->gids_cur+1 >= rules->gids_max) {
@@ -2310,6 +2324,8 @@ int udev_rules_apply_to_event(struct udev_rules *rules,
break;
case TK_A_OWNER: {
char owner[UTIL_NAME_SIZE];
+ const char *ow = owner;
+ int r;
if (event->owner_final)
break;
@@ -2317,7 +2333,15 @@ int udev_rules_apply_to_event(struct udev_rules *rules,
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);
+ r = get_user_creds(&ow, &event->uid, NULL, NULL, NULL);
+ if (r < 0) {
+ if (r == -ENOENT || r == -ESRCH)
+ udev_err(event->udev, "specified user '%s' unknown\n", owner);
+ else
+ udev_err(event->udev, "error resolving user '%s': %s\n", owner, strerror(-r));
+
+ event->uid = 0;
+ }
log_debug("OWNER %u %s:%u",
event->uid,
rules_str(rules, rule->rule.filename_off),
@@ -2326,6 +2350,8 @@ int udev_rules_apply_to_event(struct udev_rules *rules,
}
case TK_A_GROUP: {
char group[UTIL_NAME_SIZE];
+ const char *gr = group;
+ int r;
if (event->group_final)
break;
@@ -2333,7 +2359,15 @@ int udev_rules_apply_to_event(struct udev_rules *rules,
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);
+ r = get_group_creds(&gr, &event->gid);
+ if (r < 0) {
+ if (r == -ENOENT || r == -ESRCH)
+ udev_err(event->udev, "specified group '%s' unknown\n", group);
+ else
+ udev_err(event->udev, "error resolving group '%s': %s\n", group, strerror(-r));
+
+ event->gid = 0;
+ }
log_debug("GROUP %u %s:%u",
event->gid,
rules_str(rules, rule->rule.filename_off),