summaryrefslogtreecommitdiff
path: root/usr.bin/fstat
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2018-09-16 02:44:08 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2018-09-16 02:44:08 +0000
commitb5def64de55a2a39374221bb2c618e52880a6339 (patch)
tree682253c002d50f19b6913e6b7944f4c3a5b78206 /usr.bin/fstat
parent9c8f73324a0075fd194fa0cdfe30ea838752d595 (diff)
Use uid_from_user(3) and gid_from_group(3) in utilities that
do repeated lookups. OK tb@
Diffstat (limited to 'usr.bin/fstat')
-rw-r--r--usr.bin/fstat/fstat.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/usr.bin/fstat/fstat.c b/usr.bin/fstat/fstat.c
index 783fda718d5..3671baa863a 100644
--- a/usr.bin/fstat/fstat.c
+++ b/usr.bin/fstat/fstat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fstat.c,v 1.94 2018/09/13 15:23:32 millert Exp $ */
+/* $OpenBSD: fstat.c,v 1.95 2018/09/16 02:44:06 millert Exp $ */
/*
* Copyright (c) 2009 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -159,6 +159,9 @@ main(int argc, char *argv[])
optstr = "fnop:su:vN:M:";
}
+ /* Keep passwd file open for faster lookups. */
+ setpassent(1);
+
/*
* fuser and fstat share three flags: -f, -s and -u. In both cases
* -f is a boolean, but for -u fstat wants an argument while fuser
@@ -217,15 +220,17 @@ main(int argc, char *argv[])
if (uflg++)
usage();
if (!fuser) {
- if (!(passwd = getpwnam(optarg))) {
- arg = strtonum(optarg, 0, UID_MAX,
+ uid_t uid;
+
+ if (uid_from_user(optarg, &uid) == -1) {
+ uid = strtonum(optarg, 0, UID_MAX,
&errstr);
if (errstr != NULL) {
errx(1, "%s: unknown uid",
optarg);
}
- } else
- arg = passwd->pw_uid;
+ }
+ arg = uid;
what = KERN_FILE_BYUID;
}
break;