. Correct order of checking name and id for --uid and --gid.

This commit is contained in:
Emil Mikulic 2003-11-27 05:18:00 +00:00
parent 7ef872fd6a
commit 45ac8883e0

View File

@ -982,14 +982,11 @@ static void parse_commandline(const int argc, char *argv[])
struct passwd *p; struct passwd *p;
int num; int num;
if (++i >= argc) errx(1, "missing uid after --uid"); if (++i >= argc) errx(1, "missing uid after --uid");
if (!str_to_num(argv[i], &num))
p = getpwnam(argv[i]); p = getpwnam(argv[i]);
else if ((p == NULL) && (str_to_num(argv[i], &num)))
p = getpwuid( (uid_t)num ); p = getpwuid( (uid_t)num );
if (p == NULL) if (p == NULL) errx(1, "no such uid: `%s'", argv[i]);
errx(1, "no such uid: `%s'", argv[i]);
else
drop_uid = p->pw_uid; drop_uid = p->pw_uid;
} }
else if (strcmp(argv[i], "--gid") == 0) else if (strcmp(argv[i], "--gid") == 0)
@ -997,14 +994,11 @@ static void parse_commandline(const int argc, char *argv[])
struct group *g; struct group *g;
int num; int num;
if (++i >= argc) errx(1, "missing gid after --gid"); if (++i >= argc) errx(1, "missing gid after --gid");
if (!str_to_num(argv[i], &num))
g = getgrnam(argv[i]); g = getgrnam(argv[i]);
else if ((g == NULL) && (str_to_num(argv[i], &num)))
g = getgrgid( (gid_t)num ); g = getgrgid( (gid_t)num );
if (g == NULL) if (g == NULL) errx(1, "no such gid: `%s'", argv[i]);
errx(1, "no such gid: `%s'", argv[i]);
else
drop_gid = g->gr_gid; drop_gid = g->gr_gid;
} }
else else