From 49d1e7f93129cdcc2ab0cc91832b8a29ccd1570d Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 15 Mar 2015 23:33:59 -0400 Subject: simplify nscd lookup code for alt passwd/group backends previously, a sentinel value of (FILE *)-1 was used to inform the caller of __nscd_query that nscd is not in use. aside from being an ugly hack, this resulted in duplicate code paths for two logically equivalent cases: no nscd, and "not found" result from nscd. now, __nscd_query simply skips closing the socket and returns a valid FILE pointer when nscd is not in use, and produces a fake "not found" response header. the caller is then responsible for closing the socket just like it would do if it had gotten a real "not found" response. --- src/passwd/getgrouplist.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/passwd/getgrouplist.c') diff --git a/src/passwd/getgrouplist.c b/src/passwd/getgrouplist.c index 0fddc9a1..43e51824 100644 --- a/src/passwd/getgrouplist.c +++ b/src/passwd/getgrouplist.c @@ -28,7 +28,7 @@ int getgrouplist(const char *user, gid_t gid, gid_t *groups, int *ngroups) f = __nscd_query(GETINITGR, user, resp, sizeof resp, &swap); if (!f) goto cleanup; - if (f != (FILE*)-1 && resp[INITGRFOUND]) { + if (resp[INITGRFOUND]) { nscdbuf = calloc(resp[INITGRNGRPS], sizeof(uint32_t)); if (!nscdbuf) goto cleanup; if (!fread(nscdbuf, sizeof(*nscdbuf)*resp[INITGRNGRPS], 1, f)) { @@ -40,7 +40,7 @@ int getgrouplist(const char *user, gid_t gid, gid_t *groups, int *ngroups) nscdbuf[i] = bswap_32(nscdbuf[i]); } } - if (f != (FILE*)-1) fclose(f); + fclose(f); f = fopen("/etc/group", "rbe"); if (!f && errno != ENOENT && errno != ENOTDIR) -- cgit v1.2.1