From 3a020a85da768808a03f1574b001d1d06d55ae07 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Sun, 20 Aug 2006 18:25:57 +0200 Subject: remove built-in /etc/passwd /etc/group parser --- udev_utils.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'udev_utils.c') diff --git a/udev_utils.c b/udev_utils.c index 003d7bded9..b198892c01 100644 --- a/udev_utils.c +++ b/udev_utils.c @@ -28,6 +28,9 @@ #include #include #include +#include +#include +#include #include #include "udev.h" @@ -161,3 +164,40 @@ int add_matching_files(struct list_head *name_list, const char *dirname, const c closedir(dir); return 0; } + +uid_t lookup_user(const char *user) +{ + struct passwd *pw; + uid_t uid = 0; + + errno = 0; + pw = getpwnam(user); + if (pw == NULL) { + if (errno == 0 || errno == ENOENT || errno == ESRCH) + err("specified user unknown '%s'", user); + else + err("error resolving user '%s': %s", user, strerror(errno)); + } else + uid = pw->pw_uid; + + return uid; +} + +extern gid_t lookup_group(const char *group) +{ + struct group *gr; + gid_t gid = 0; + + errno = 0; + gr = getgrnam(group); + if (gr == NULL) { + if (errno == 0 || errno == ENOENT || errno == ESRCH) + err("specified group unknown '%s'", group); + else + err("error resolving group '%s': %s", group, strerror(errno)); + } else + gid = gr->gr_gid; + + return gid; +} + -- cgit v1.2.3-54-g00ecf