From beb33055127ea50e533404a4cb2c04a8ffc70e97 Mon Sep 17 00:00:00 2001 From: downsj Date: Sat, 25 Jan 1997 04:59:42 +0000 Subject: [PATCH] sync with NetBSD, changes from PR#3114, Michael.Eriksson@era-t.ericsson.se --- lib/libc/gen/getgrent.c | 49 +++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/lib/libc/gen/getgrent.c b/lib/libc/gen/getgrent.c index cc67b8196e9..f7b9b7805c3 100644 --- a/lib/libc/gen/getgrent.c +++ b/lib/libc/gen/getgrent.c @@ -33,7 +33,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: getgrent.c,v 1.5 1996/09/15 10:09:10 tholo Exp $"; +static char rcsid[] = "$OpenBSD: getgrent.c,v 1.6 1997/01/25 04:59:42 downsj Exp $"; #endif /* LIBC_SCCS and not lint */ #include @@ -163,15 +163,15 @@ grscan(search, gid, name) register char *cp, **m; char *bp; #ifdef YP + char *key, *data; + int keylen, datalen; + int r; char *grname = (char *)NULL; #endif for (;;) { #ifdef YP if(__ypmode != YPMODE_NONE) { - char *key, *data; - int keylen, datalen; - int r; if(!__ypdomain) { if(yp_get_default_domain(&__ypdomain)) { @@ -256,16 +256,50 @@ grscan(search, gid, name) case '\0': case '\n': if(_yp_check(NULL)) { - __ypmode = YPMODE_FULL; - continue; + if (!search) { + __ypmode = YPMODE_FULL; + continue; + } + if(!__ypdomain && + yp_get_default_domain(&__ypdomain)) + continue; + if (name) { + r = yp_match(__ypdomain, + "group.byname", + name, strlen(name), + &data, &datalen); + } else { + char buf[20]; + sprintf(buf, "%d", gid); + r = yp_match(__ypdomain, + "group.bygid", + buf, strlen(buf), + &data, &datalen); + } + if (r != 0) + continue; + bcopy(data, line, datalen); + free(data); + line[datalen] = '\0'; + bp = line; + _gr_group.gr_name = strsep(&bp, ":\n"); + _gr_group.gr_passwd = + strsep(&bp, ":\n"); + if (!(cp = strsep(&bp, ":\n"))) + continue; + _gr_group.gr_gid = + name ? atoi(cp) : gid; + goto found_it; } break; default: if(_yp_check(NULL)) { register char *tptr; - __ypmode = YPMODE_NAME; tptr = strsep(&bp, ":\n"); + if (search && name && strcmp(tptr, name)) + continue; + __ypmode = YPMODE_NAME; grname = strdup(tptr + 1); continue; } @@ -283,6 +317,7 @@ parse: _gr_group.gr_gid = atoi(cp); if (search && name == NULL && _gr_group.gr_gid != gid) continue; + found_it: cp = NULL; if (bp == NULL) continue; -- 2.20.1