f = __nscd_query(req, key, groupbuf, sizeof groupbuf, &swap);
if (!f) { rv = errno; goto done; }
- if (f == (FILE*)-1) { rv = 0; goto done; }
if (!groupbuf[GRFOUND]) { rv = 0; goto cleanup_f; }
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)) {
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)
f = __nscd_query(req, key, passwdbuf, sizeof passwdbuf, (int[]){0});
if (!f) { rv = errno; goto done; }
- if (f == (FILE*)-1) { rv = 0; goto done; }
if(!passwdbuf[PWFOUND]) { rv = 0; goto cleanup_f; }
.msg_iovlen = 2
};
- if (strlen(key) > INT32_MAX - 1) {
- return (FILE*)-1;
- }
-
*swap = 0;
retry:
+ memset(buf, 0, len);
+ buf[0] = NSCDVERSION;
fd = socket(PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
if (fd < 0) return NULL;
+ if(!(f = fdopen(fd, "r"))) {
+ close(fd);
+ return 0;
+ }
+
+ if (strlen(key) > INT32_MAX - 1)
+ return f;
+
if (connect(fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
/* If there isn't a running nscd we return -1 to indicate that
* that is precisely what happened
*/
- if (errno == EACCES || errno == ECONNREFUSED || errno == ENOENT) {
- close(fd);
- return (FILE *)-1;
- }
+ if (errno == EACCES || errno == ECONNREFUSED || errno == ENOENT)
+ return f;
goto error;
}
if (sendmsg(fd, &msg, MSG_NOSIGNAL) < 0)
goto error;
- if(!(f = fdopen(fd, "r"))) goto error;
-
if (!fread(buf, len, 1, f)) {
/* If the VERSION entry mismatches nscd will disconnect. The
* most likely cause is that the endianness mismatched. So, we
return f;
error:
- if (f) fclose(f); else close(fd);
+ fclose(f);
return 0;
}