#endif /* not lint */
#include <sys/param.h>
-#include <sys/resource.h>
-#include <sys/time.h>
#include <sys/types.h>
#include <ctype.h>
errx(EX_UNAVAILABLE, "out of memory");
tmp = strrchr(dirs, '/');
- if (tmp == NULL)
+ if (tmp == NULL) {
+ free(dirs);
return;
+ }
tmp[0] = '\0';
/*
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");
if (arg1 == NULL)
errx(EX_DATAERR, "username or id required");
- if (arg1[strspn(arg1, "0123456789")] == '\0')
- id = pw_checkid(arg1, UID_MAX);
- 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);
}
}
if (!reject) {
while (*ch) {
- if (strchr(badchars, *ch) != NULL || *ch < ' ' ||
+ if (strchr(badchars, *ch) != NULL ||
+ (!gecos && *ch < ' ') ||
*ch == 127) {
reject = 1;
break;
bool quiet = false;
uid_t next;
- while ((ch = getopt(argc, argv, "Cq")) != -1) {
+ while ((ch = getopt(argc, argv, "C:q")) != -1) {
switch (ch) {
case 'C':
cfg = optarg;
}
}
- if (id > 0 && pwd->pw_uid != id) {
+ if (id >= 0 && pwd->pw_uid != id) {
pwd->pw_uid = id;
edited = true;
if (pwd->pw_uid != 0 && strcmp(pwd->pw_name, "root") == 0)