summaryrefslogtreecommitdiffstats
path: root/usr.sbin/pw/pw_user.c
diff options
context:
space:
mode:
authorbapt <bapt@FreeBSD.org>2015-12-02 22:01:37 +0000
committerbapt <bapt@FreeBSD.org>2015-12-02 22:01:37 +0000
commit5df8300abf919431bbeedfbabfa605cf95f01080 (patch)
treeee4e56dbad51f43e7716b1e8c0a6b2fee58a8bc9 /usr.sbin/pw/pw_user.c
parent7a42e48a348675fc0e24e99944651befad40fc65 (diff)
downloadFreeBSD-src-5df8300abf919431bbeedfbabfa605cf95f01080.zip
FreeBSD-src-5df8300abf919431bbeedfbabfa605cf95f01080.tar.gz
Fix handling of numeric-only names with pw lock
Add a regression test about it PR: 204968 MFC after: 1 week
Diffstat (limited to 'usr.sbin/pw/pw_user.c')
-rw-r--r--usr.sbin/pw/pw_user.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/usr.sbin/pw/pw_user.c b/usr.sbin/pw/pw_user.c
index 5c168ab..61c2440 100644
--- a/usr.sbin/pw/pw_user.c
+++ b/usr.sbin/pw/pw_user.c
@@ -274,7 +274,7 @@ pw_userlock(char *arg1, int mode)
char *passtmp = NULL;
char *name;
bool locked = false;
- uid_t id;
+ uid_t id = (uid_t)-1;
if (geteuid() != 0)
errx(EX_NOPERM, "you must be root");
@@ -282,16 +282,19 @@ pw_userlock(char *arg1, int mode)
if (arg1 == NULL)
errx(EX_DATAERR, "username or id required");
- if (arg1[strspn(arg1, "0123456789")] == '\0') {
- id = pw_checkid(arg1, UID_MAX);
- name = NULL;
- } else
- name = arg1;
+ name = arg1;
+ if (arg1[strspn(name, "0123456789")] == '\0')
+ id = pw_checkid(name, UID_MAX);
- pwd = (name != NULL) ? GETPWNAM(pw_checkname(name, 0)) : GETPWUID(id);
+ pwd = GETPWNAM(pw_checkname(name, 0));
+ if (pwd == NULL && id != (uid_t)-1) {
+ pwd = GETPWUID(id);
+ if (pwd != NULL)
+ name = pwd->pw_name;
+ }
if (pwd == NULL) {
- if (name == NULL)
- errx(EX_NOUSER, "no such uid `%ju'", (uintmax_t) id);
+ if (id == (uid_t)-1)
+ errx(EX_NOUSER, "no such name or uid `%ju'", (uintmax_t) id);
errx(EX_NOUSER, "no such user `%s'", name);
}
OpenPOWER on IntegriCloud