# HG changeset patch # User Jim Meyering # Date 880885478 0 # Node ID 22a1ad770d563a64256e551d534991e038c90f97 # Parent 2c9059ccc457e5556ca360d586129a22b3832e4b (getuidbyname, getgidbyname): Names can now be NULL in cache. This change merely fixes ifdeffed-out code. diff --git a/lib/idcache.c b/lib/idcache.c --- a/lib/idcache.c +++ b/lib/idcache.c @@ -55,10 +55,13 @@ struct userid *next; }; +/* The members of this list have already been looked up. + If a name is NULL, the corresponding id is not in the password file. */ static struct userid *user_alist; #ifdef NOT_USED -/* The members of this list have names not in the local passwd file. */ +/* The members of this list are names not in the local passwd file; + their names are always not NULL, and their ids are irrelevant. */ static struct userid *nouser_alist; #endif /* NOT_USED */ @@ -82,7 +85,7 @@ tail->id.u = uid; tail->name = (pwent ? xstrdup (pwent->pw_name) : NULL); - /* Add to the head of the list, so most recently used is first. */ + /* Add to the head of the list, so most recently added is first. */ tail->next = user_alist; user_alist = tail; return tail->name; @@ -104,7 +107,7 @@ for (tail = user_alist; tail; tail = tail->next) /* Avoid a function call for the most common case. */ - if (*tail->name == *user && !strcmp (tail->name, user)) + if (tail->name && *tail->name == *user && !strcmp (tail->name, user)) return &tail->id.u; for (tail = nouser_alist; tail; tail = tail->next) @@ -117,7 +120,7 @@ tail = (struct userid *) xmalloc (sizeof (struct userid)); tail->name = xstrdup (user); - /* Add to the head of the list, so most recently used is first. */ + /* Add to the head of the list, so most recently added is first. */ if (pwent) { tail->id.u = pwent->pw_uid; @@ -139,8 +142,8 @@ static struct userid *nogroup_alist; #endif -/* Translate GID to a group name or a stringified number, - with cache. */ +/* Translate GID to a group name, with cache. + Return NULL if the group has no name. */ char * getgroup (gid) @@ -180,7 +183,7 @@ for (tail = group_alist; tail; tail = tail->next) /* Avoid a function call for the most common case. */ - if (*tail->name == *group && !strcmp (tail->name, group)) + if (tail->name && *tail->name == *group && !strcmp (tail->name, group)) return &tail->id.g; for (tail = nogroup_alist; tail; tail = tail->next)