Old bug in pwcache functions. Calling setpassent(1) to keep the passwd
database open is a surprising abstraction violation for the caller of
user_from_uid. Now it has a file descriptor it must close before exec by
calling endpwent(), but this fact is not mentioned. (find is affected by this,
for example.)
Simplest fix is to just leave the database closed. The point of the cache is
to avoid calling getpwuid() at all, so we shouldn't worry about the
performance of that call so much. Now, the cache is rather stupid, and we can
fix that too, but first fix the real bug.
Index: gen/pwcache.c
===================================================================
RCS file: /cvs/src/lib/libc/gen/pwcache.c,v
retrieving revision 1.9
diff -u -p -r1.9 pwcache.c
--- gen/pwcache.c 8 Aug 2005 08:05:34 -0000 1.9
+++ gen/pwcache.c 26 Oct 2015 13:41:52 -0000
@@ -45,17 +45,12 @@ user_from_uid(uid_t uid, int nouser)
uid_t uid;
char name[_PW_NAME_LEN + 1];
} c_uid[NCACHE];
- static int pwopen;
static char nbuf[15]; /* 32 bits == 10 digits */
struct passwd *pw;
struct ncache *cp;
cp = c_uid + (uid & MASK);
if (cp->uid != uid || !*cp->name) {
- if (pwopen == 0) {
- setpassent(1);
- pwopen = 1;
- }
if ((pw = getpwuid(uid)) == NULL) {
if (nouser)
return (NULL);
@@ -75,17 +70,12 @@ group_from_gid(gid_t gid, int nogroup)
gid_t gid;
char name[_PW_NAME_LEN + 1];
} c_gid[NCACHE];
- static int gropen;
static char nbuf[15]; /* 32 bits == 10 digits */
struct group *gr;
struct ncache *cp;
cp = c_gid + (gid & MASK);
if (cp->gid != gid || !*cp->name) {
- if (gropen == 0) {
- setgroupent(1);
- gropen = 1;
- }
if ((gr = getgrgid(gid)) == NULL) {
if (nogroup)
return (NULL);