diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2018-09-16 02:44:08 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2018-09-16 02:44:08 +0000 |
commit | b5def64de55a2a39374221bb2c618e52880a6339 (patch) | |
tree | 682253c002d50f19b6913e6b7944f4c3a5b78206 /sbin | |
parent | 9c8f73324a0075fd194fa0cdfe30ea838752d595 (diff) |
Use uid_from_user(3) and gid_from_group(3) in utilities that
do repeated lookups. OK tb@
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/fsdb/fsdb.c | 7 | ||||
-rw-r--r-- | sbin/pfctl/parse.y | 14 |
2 files changed, 9 insertions, 12 deletions
diff --git a/sbin/fsdb/fsdb.c b/sbin/fsdb/fsdb.c index c82fc676bf4..49128eae52f 100644 --- a/sbin/fsdb/fsdb.c +++ b/sbin/fsdb/fsdb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fsdb.c,v 1.31 2016/09/09 15:37:14 tb Exp $ */ +/* $OpenBSD: fsdb.c,v 1.32 2018/09/16 02:44:06 millert Exp $ */ /* $NetBSD: fsdb.c,v 1.7 1997/01/11 06:50:53 lukem Exp $ */ /*- @@ -760,7 +760,6 @@ CMDFUNCSTART(chowner) int rval = 1; uid_t uid; char *cp; - struct passwd *pwd; if (!checkactive()) return 1; @@ -768,9 +767,7 @@ CMDFUNCSTART(chowner) uid = strtoul(argv[1], &cp, 0); if (cp == argv[1] || *cp != '\0' ) { /* try looking up name */ - if ((pwd = getpwnam(argv[1]))) { - uid = pwd->pw_uid; - } else { + if (uid_from_user(argv[1], &uid) == -1) { warnx("bad uid `%s'", argv[1]); return 1; } diff --git a/sbin/pfctl/parse.y b/sbin/pfctl/parse.y index 9c1a6293709..0791c9c01d7 100644 --- a/sbin/pfctl/parse.y +++ b/sbin/pfctl/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.683 2018/09/06 15:07:33 kn Exp $ */ +/* $OpenBSD: parse.y,v 1.684 2018/09/16 02:44:06 millert Exp $ */ /* * Copyright (c) 2001 Markus Friedl. All rights reserved. @@ -2965,14 +2965,14 @@ uid : STRING { if (!strcmp($1, "unknown")) $$ = UID_MAX; else { - struct passwd *pw; + uid_t uid; - if ((pw = getpwnam($1)) == NULL) { + if (uid_from_user($1, &uid) == -1) { yyerror("unknown user %s", $1); free($1); YYERROR; } - $$ = pw->pw_uid; + $$ = uid; } free($1); } @@ -3043,14 +3043,14 @@ gid : STRING { if (!strcmp($1, "unknown")) $$ = GID_MAX; else { - struct group *grp; + gid_t gid; - if ((grp = getgrnam($1)) == NULL) { + if (gid_from_group($1, &gid) == -1) { yyerror("unknown group %s", $1); free($1); YYERROR; } - $$ = grp->gr_gid; + $$ = gid; } free($1); } |