=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/fstat/fstat.c,v retrieving revision 1.94 retrieving revision 1.95 diff -u -r1.94 -r1.95 --- src/usr.bin/fstat/fstat.c 2018/09/13 15:23:32 1.94 +++ src/usr.bin/fstat/fstat.c 2018/09/16 02:44:06 1.95 @@ -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 @@ -159,6 +159,9 @@ 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 @@ 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;