diff options
Diffstat (limited to 'lib/libc/gen/getgrent.c')
| -rw-r--r-- | lib/libc/gen/getgrent.c | 87 |
1 files changed, 80 insertions, 7 deletions
diff --git a/lib/libc/gen/getgrent.c b/lib/libc/gen/getgrent.c index 60593c2831fd..18f7079eff30 100644 --- a/lib/libc/gen/getgrent.c +++ b/lib/libc/gen/getgrent.c @@ -32,13 +32,20 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)getgrent.c 5.9 (Berkeley) 4/1/91"; +/* static char *sccsid = "from: @(#)getgrent.c 5.9 (Berkeley) 4/1/91"; */ +static char *rcsid = "$Id: getgrent.c,v 1.3 1994/01/11 19:00:57 nate Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <grp.h> +#ifdef YP +#include <rpc/rpc.h> +#include <rpcsvc/yp_prot.h> +#include <rpcsvc/ypclnt.h> +#endif static FILE *_gr_fp; static struct group _gr_group; @@ -50,6 +57,11 @@ static char *members[MAXGRP]; #define MAXLINELENGTH 1024 static char line[MAXLINELENGTH]; +#ifdef YP +static char *__ypcurrent, *__ypdomain; +static int __ypcurrentlen, __ypmode=0; +#endif + struct group * getgrent() { @@ -90,7 +102,7 @@ getgrgid(gid) return(rval ? &_gr_group : NULL); } -static +static int start_gr() { if (_gr_fp) { @@ -100,10 +112,10 @@ start_gr() return((_gr_fp = fopen(_PATH_GROUP, "r")) ? 1 : 0); } -int +void setgrent() { - return(setgroupent(0)); + (void) setgroupent(0); } int @@ -125,27 +137,88 @@ endgrent() } } -static +static int grscan(search, gid, name) register int search, gid; register char *name; { register char *cp, **m; char *bp; - char *fgets(), *strsep(), *index(); for (;;) { +#ifdef YP + if(__ypmode) { + char *key, *data; + int keylen, datalen; + int r; + + if(!__ypdomain) { + if(yp_get_default_domain(&__ypdomain)) { + __ypmode = 0; + continue; + } + } + if(__ypcurrent) { + r = yp_next(__ypdomain, "group.byname", + __ypcurrent, __ypcurrentlen, + &key, &keylen, &data, &datalen); + free(__ypcurrent); + /*printf("yp_next %d\n", r);*/ + switch(r) { + case 0: + break; + default: + __ypcurrent = NULL; + __ypmode = 0; + free(data); + continue; + } + __ypcurrent = key; + __ypcurrentlen = keylen; + bcopy(data, line, datalen); + free(data); + } else { + r = yp_first(__ypdomain, "group.byname", + &__ypcurrent, &__ypcurrentlen, + &data, &datalen); + /*printf("yp_first %d\n", r);*/ + switch(r) { + case 0: + break; + default: + __ypmode = 0; + free(data); + continue; + } + bcopy(data, line, datalen); + free(data); + } + line[datalen] = '\0'; + /*printf("line = %s\n", line);*/ + bp = line; + goto parse; + } +#endif if (!fgets(line, sizeof(line), _gr_fp)) return(0); bp = line; /* skip lines that are too big */ - if (!index(line, '\n')) { + if (!strchr(line, '\n')) { int ch; while ((ch = getc(_gr_fp)) != '\n' && ch != EOF) ; continue; } +#ifdef YP + if ((strcmp("+\n", line) == 0) || (strncmp("+:*:0:", line, 5) == 0)) { + if(_yp_check(NULL)) { + __ypmode = 1; + continue; + } + } +parse: +#endif _gr_group.gr_name = strsep(&bp, ":\n"); if (search && name && strcmp(_gr_group.gr_name, name)) continue; |
