diff options
author | robert <robert@FreeBSD.org> | 2003-03-19 14:17:24 +0000 |
---|---|---|
committer | robert <robert@FreeBSD.org> | 2003-03-19 14:17:24 +0000 |
commit | 72ab05df5afd6bc404e885df41d81fbfa657e267 (patch) | |
tree | cbed38239e802b42954c7634573486cce5cabb84 /lib/libc/gen/getusershell.c | |
parent | 5464c702e31c7e2006f96b3b6d523b1e68641ad0 (diff) | |
download | FreeBSD-src-72ab05df5afd6bc404e885df41d81fbfa657e267.zip FreeBSD-src-72ab05df5afd6bc404e885df41d81fbfa657e267.tar.gz |
- Revamp the function _nis_initshells() to make getusershell() backed
by NIS work, like nsswitch.conf(5) promises to be able to.
(These modifications will be fed back to NetBSD, of course)
- In endusershell(), do not set `sl' to NULL if we know it already has
that value.
Diffstat (limited to 'lib/libc/gen/getusershell.c')
-rw-r--r-- | lib/libc/gen/getusershell.c | 65 |
1 files changed, 30 insertions, 35 deletions
diff --git a/lib/libc/gen/getusershell.c b/lib/libc/gen/getusershell.c index 2372ec6..2a218cf 100644 --- a/lib/libc/gen/getusershell.c +++ b/lib/libc/gen/getusershell.c @@ -91,9 +91,10 @@ getusershell(void) void endusershell(void) { - if (sl) + if (sl) { sl_free(sl, 1); - sl = NULL; + sl = NULL; + } curshell = NULL; } @@ -196,6 +197,10 @@ _nis_initshells(rv, cb_data, ap) va_list ap; { static char *ypdomain; + char *key, *data; + char *lastkey; + int keylen, datalen; + int r; if (sl) sl_free(sl, 1); @@ -212,42 +217,32 @@ _nis_initshells(rv, cb_data, ap) } } - for (;;) { - char *ypcur = NULL; - int ypcurlen = 0; /* XXX: GCC */ - char *key, *data; - int keylen, datalen; - int r; - - key = data = NULL; - if (ypcur) { - r = yp_next(ypdomain, "shells", ypcur, ypcurlen, - &key, &keylen, &data, &datalen); - free(ypcur); - switch (r) { - case 0: - break; - case YPERR_NOMORE: - free(key); - free(data); - return NS_SUCCESS; - default: - free(key); - free(data); - return NS_UNAVAIL; - } - ypcur = key; - ypcurlen = keylen; - } else { - if (yp_first(ypdomain, "shells", &ypcur, - &ypcurlen, &data, &datalen)) { - free(data); - return NS_UNAVAIL; - } - } + /* + * `key' and `data' point to strings dynamically allocated by + * the yp_... functions. + * `data' is directly put into the stringlist of shells. + */ + key = data = NULL; + if (yp_first(ypdomain, "shells", &key, &keylen, &data, &datalen)) + return NS_UNAVAIL; + do { data[datalen] = '\0'; /* clear trailing \n */ sl_add(sl, data); + + lastkey = key; + r = yp_next(ypdomain, "shells", lastkey, keylen, + &key, &keylen, &data, &datalen); + free(lastkey); + } while (r == 0); + + if (r == YPERR_NOMORE) { + /* + * `data' and `key' ought to be NULL - do not try to free them. + */ + return NS_SUCCESS; } + + return NS_UNAVAIL; } #endif /* YP */ |