aboutsummaryrefslogtreecommitdiff
path: root/lib/xwrap.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/xwrap.c')
-rw-r--r--lib/xwrap.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/xwrap.c b/lib/xwrap.c
index 44cd1684..54f2cbb5 100644
--- a/lib/xwrap.c
+++ b/lib/xwrap.c
@@ -477,6 +477,38 @@ struct group *xgetgrgid(gid_t gid)
return group;
}
+struct passwd *xgetpwnamid(char *user)
+{
+ struct passwd *up = getpwnam(user);
+ uid_t uid;
+
+ if (!up) {
+ char *s = 0;
+
+ uid = estrtol(user, &s, 10);
+ if (!errno && s && !*s) up = getpwuid(uid);
+ }
+ if (!up) perror_exit("user '%s'", user);
+
+ return up;
+}
+
+struct group *xgetgrnamid(char *group)
+{
+ struct group *gr = getgrnam(group);
+ gid_t gid;
+
+ if (!gr) {
+ char *s = 0;
+
+ gid = estrtol(group, &s, 10);
+ if (!errno && s && !*s) gr = getgrgid(gid);
+ }
+ if (!gr) perror_exit("group '%s'", group);
+
+ return gr;
+}
+
struct passwd *xgetpwnam(char *name)
{
struct passwd *up = getpwnam(name);