summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2008-10-22 23:59:53 +0200
committerKay Sievers <kay.sievers@vrfy.org>2008-10-22 23:59:53 +0200
commita391f49d7f5433e6204f35331b81391c2d110309 (patch)
tree9fe8437fa187fc974148267c80b578eb56c3d318
parentaaff3d023f89522f56f7cd345b6849e1251a6a74 (diff)
handle numerical owner/group string in lookup_user/group()
-rw-r--r--udev/udev-util.c57
1 files changed, 32 insertions, 25 deletions
diff --git a/udev/udev-util.c b/udev/udev-util.c
index 76d7270f66..2620d9a994 100644
--- a/udev/udev-util.c
+++ b/udev/udev-util.c
@@ -126,48 +126,55 @@ int util_unlink_secure(struct udev *udev, const char *filename)
uid_t util_lookup_user(struct udev *udev, const char *user)
{
+ char *endptr;
int buflen = sysconf(_SC_GETPW_R_SIZE_MAX);
char buf[buflen];
struct passwd pwbuf;
struct passwd *pw;
- uid_t uid = 0;
+ uid_t uid;
if (strcmp(user, "root") == 0)
return 0;
- errno = 0;
- getpwnam_r(user, &pwbuf, buf, buflen, &pw);
- if (pw == NULL) {
+ uid = strtoul(user, &endptr, 10);
+ if (endptr[0] == '\0')
+ return uid;
+
+ errno = 0;
+ getpwnam_r(user, &pwbuf, buf, buflen, &pw);
+ if (pw != NULL)
+ return pw->pw_uid;
if (errno == 0 || errno == ENOENT || errno == ESRCH)
err(udev, "specified user '%s' unknown\n", user);
else
err(udev, "error resolving user '%s': %m\n", user);
- } else
- uid = pw->pw_uid;
-
- return uid;
-}
+ return 0;
+ }
-extern gid_t util_lookup_group(struct udev *udev, const char *group)
-{
- int buflen = sysconf(_SC_GETGR_R_SIZE_MAX);
- char buf[buflen];
- struct group grbuf;
- struct group *gr;
- gid_t gid = 0;
+ extern gid_t util_lookup_group(struct udev *udev, const char *group)
+ {
+ char *endptr;
+ int buflen = sysconf(_SC_GETGR_R_SIZE_MAX);
+ char buf[buflen];
+ struct group grbuf;
+ struct group *gr;
+ gid_t gid = 0;
- if (strcmp(group, "root") == 0)
- return 0;
- errno = 0;
- getgrnam_r(group, &grbuf, buf, buflen, &gr);
- if (gr == NULL) {
+ if (strcmp(group, "root") == 0)
+ return 0;
+ gid = strtoul(group, &endptr, 10);
+ if (endptr[0] == '\0')
+ return gid;
+
+ errno = 0;
+ getgrnam_r(group, &grbuf, buf, buflen, &gr);
+ if (gr != NULL)
+ return gr->gr_gid;
if (errno == 0 || errno == ENOENT || errno == ESRCH)
err(udev, "specified group '%s' unknown\n", group);
else
err(udev, "error resolving group '%s': %m\n", group);
- } else
- gid = gr->gr_gid;
- return gid;
-}
+ return 0;
+ }
/* handle "[<SUBSYSTEM>/<KERNEL>]<attribute>" format */
int util_resolve_subsys_kernel(struct udev *udev, const char *string,