aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2013-11-28 21:06:15 -0600
committerRob Landley <rob@landley.net>2013-11-28 21:06:15 -0600
commit5ec4ab3113dcc813b6040d7ded38e297df99dc0e (patch)
treeafad4e181b9b8ab64496ed7d001c444c245ae429 /toys
parent9e44a5841f0ab9bc03cefb5631c80f3e4e5a60fe (diff)
downloadtoybox-5ec4ab3113dcc813b6040d7ded38e297df99dc0e.tar.gz
Add xgetpwnam() to lib/xwrap.c.
Diffstat (limited to 'toys')
-rw-r--r--toys/lsb/passwd.c12
-rw-r--r--toys/pending/groupadd.c3
-rw-r--r--toys/pending/tftpd.c6
-rw-r--r--toys/posix/id.c6
4 files changed, 9 insertions, 18 deletions
diff --git a/toys/lsb/passwd.c b/toys/lsb/passwd.c
index 1784c049..f3338361 100644
--- a/toys/lsb/passwd.c
+++ b/toys/lsb/passwd.c
@@ -103,17 +103,15 @@ void passwd_main(void)
int ret = -1;
myuid = getuid();
- if ((myuid) && (toys.optflags & (FLAG_l | FLAG_u | FLAG_d)))
- error_exit("You need to be root to do these actions\n");
+ if (myuid && (toys.optflags & (FLAG_l | FLAG_u | FLAG_d)))
+ error_exit("Not root");
- pw = getpwuid(myuid);
- if (!pw) error_exit("Unknown uid '%u'",myuid);
+ pw = xgetpwuid(myuid);
- if (toys.optargs[0]) name = toys.optargs[0];
+ if (*toys.optargs) name = toys.optargs[0];
else name = xstrdup(pw->pw_name);
- pw = getpwnam(name);
- if (!pw) error_exit("Unknown user '%s'",name);
+ pw = xgetpwnam(name);
if (myuid && (myuid != pw->pw_uid))
error_exit("You need to be root to change '%s' password\n", name);
diff --git a/toys/pending/groupadd.c b/toys/pending/groupadd.c
index ab290e54..8ff539eb 100644
--- a/toys/pending/groupadd.c
+++ b/toys/pending/groupadd.c
@@ -79,8 +79,7 @@ void groupadd_main(void)
if (toys.optc == 2) { //add user to group
//toys.optargs[0]- user, toys.optargs[1] - group
- if (!getpwnam(toys.optargs[0]))
- error_exit("user '%s' does not exist", toys.optargs[0]);
+ xgetpwnam(*toys.optargs);
if (!(grp = getgrnam(toys.optargs[1])))
error_exit("group '%s' does not exist", toys.optargs[1]);
if (!grp->gr_mem) entry = xmsprintf("%s", *toys.optargs);
diff --git a/toys/pending/tftpd.c b/toys/pending/tftpd.c
index 3e7264b5..ea8d3eac 100644
--- a/toys/pending/tftpd.c
+++ b/toys/pending/tftpd.c
@@ -249,11 +249,7 @@ void tftpd_main(void)
error_exit(NULL);
}
- if (toys.optflags & FLAG_u) {
- struct passwd *pw = getpwnam(TT.user);
- if (!pw) error_exit("unknown user %s", TT.user);
- TT.pw = pw;
- }
+ if (TT.user) TT.pw = xgetpwnam(TT.user);
if (*toys.optargs) {
if (chroot(*toys.optargs))
perror_exit("can't change root directory to '%s'", *toys.optargs);
diff --git a/toys/posix/id.c b/toys/posix/id.c
index f40f6c1b..8b68d4de 100644
--- a/toys/posix/id.c
+++ b/toys/posix/id.c
@@ -67,12 +67,10 @@ void do_id(char *username)
// check if a username is given
if (username) {
- if (!(pw = getpwnam(username)))
- error_exit("no such user '%s'", username);
+ pw = xgetpwnam(username);
uid = euid = pw->pw_uid;
gid = egid = pw->pw_gid;
- if (cmd_groups)
- printf("%s : ", pw->pw_name);
+ if (cmd_groups) printf("%s : ", pw->pw_name);
}
i = flags & FLAG_r;