From 5ec4ab3113dcc813b6040d7ded38e297df99dc0e Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Thu, 28 Nov 2013 21:06:15 -0600 Subject: Add xgetpwnam() to lib/xwrap.c. --- lib/lib.h | 1 + lib/xwrap.c | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/lib.h b/lib/lib.h index e5d4a1d3..2d3e2734 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -113,6 +113,7 @@ void xmkpath(char *path, int mode); void xsetuid(uid_t uid); struct passwd *xgetpwuid(uid_t uid); struct group *xgetgrgid(gid_t gid); +struct passwd *xgetpwnam(char *name); char *xreadlink(char *name); long xparsetime(char *arg, long units, long *fraction); void xpidfile(char *name); diff --git a/lib/xwrap.c b/lib/xwrap.c index 71ea9209..c0c8a44b 100644 --- a/lib/xwrap.c +++ b/lib/xwrap.c @@ -402,17 +402,24 @@ void xsetuid(uid_t uid) struct passwd *xgetpwuid(uid_t uid) { struct passwd *pwd = getpwuid(uid); - if (!pwd) error_exit(NULL); + if (!pwd) error_exit("bad uid %ld", (long)uid); return pwd; } struct group *xgetgrgid(gid_t gid) { struct group *group = getgrgid(gid); - if (!group) error_exit(NULL); + if (!group) error_exit("bad gid %ld", (long)gid); return group; } +struct passwd *xgetpwnam(char *name) +{ + struct passwd *up = getpwnam(name); + if (!up) error_exit("bad user '%s'", name); + return up; +} + // This can return null (meaning file not found). It just won't return null // for memory allocation reasons. char *xreadlink(char *name) -- cgit v1.2.3