summaryrefslogtreecommitdiff
path: root/udev_utils.c
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@suse.de>2006-08-20 18:25:57 +0200
committerKay Sievers <kay.sievers@suse.de>2006-08-20 18:25:57 +0200
commit3a020a85da768808a03f1574b001d1d06d55ae07 (patch)
treee17643bf1097ced6d6630a3e0fee1bfb917da6d0 /udev_utils.c
parent5c51e31e0e794d8fcdc1225c65985571c9820949 (diff)
remove built-in /etc/passwd /etc/group parser
Diffstat (limited to 'udev_utils.c')
-rw-r--r--udev_utils.c40
1 files changed, 40 insertions, 0 deletions
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 <ctype.h>
#include <dirent.h>
#include <syslog.h>
+#include <pwd.h>
+#include <grp.h>
+#include <sys/types.h>
#include <sys/utsname.h>
#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;
+}
+