xref: /onnv-gate/usr/src/lib/libbc/libc/gen/common/getgraent.c (revision 722:636b850d4ee9)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
230Sstevel@tonic-gate  * Copyright 1990 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
27*722Smuffin #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include <stdio.h>
300Sstevel@tonic-gate #include <grp.h>
310Sstevel@tonic-gate #include <grpadj.h>
320Sstevel@tonic-gate #include <rpcsvc/ypclnt.h>
33*722Smuffin #include <string.h>
34*722Smuffin #include <malloc.h>
350Sstevel@tonic-gate 
360Sstevel@tonic-gate extern void rewind();
370Sstevel@tonic-gate extern long strtol();
380Sstevel@tonic-gate extern int fclose();
390Sstevel@tonic-gate 
40*722Smuffin void	setgraent(void);
41*722Smuffin void	endgraent(void);
420Sstevel@tonic-gate 
430Sstevel@tonic-gate static struct gradata {
440Sstevel@tonic-gate 	char	*domain;
450Sstevel@tonic-gate 	FILE	*grfa;
460Sstevel@tonic-gate 	char	*yp;
470Sstevel@tonic-gate 	int	yplen;
480Sstevel@tonic-gate 	char	*oldyp;
490Sstevel@tonic-gate 	int	oldyplen;
500Sstevel@tonic-gate 	struct list {
510Sstevel@tonic-gate 		char *name;
520Sstevel@tonic-gate 		struct list *nxt;
530Sstevel@tonic-gate 	} *minuslist;			/* list of - items */
540Sstevel@tonic-gate 	struct	group_adjunct interpgra;
550Sstevel@tonic-gate 	char	interpline[BUFSIZ+1];
560Sstevel@tonic-gate 	struct	group_adjunct *sv;
57*722Smuffin } *gradata, *_gradata(void);
580Sstevel@tonic-gate 
590Sstevel@tonic-gate static char *GROUPADJ = "/etc/security/group.adjunct";
60*722Smuffin 
61*722Smuffin static struct group_adjunct	*interpret(char *, int);
62*722Smuffin static struct group_adjunct	*interpretwithsave(char *, int,
63*722Smuffin     struct group_adjunct *);
64*722Smuffin static struct group_adjunct	*save(struct group_adjunct *);
65*722Smuffin static struct group_adjunct	*getnamefromyellow(char *,
66*722Smuffin     struct group_adjunct *);
67*722Smuffin static int	onminuslist(struct group_adjunct *);
68*722Smuffin static int	matchname(char [], struct group_adjunct **, char *);
69*722Smuffin static void	freeminuslist(void);
70*722Smuffin static void	getnextfromyellow(void);
71*722Smuffin static void	getfirstfromyellow(void);
72*722Smuffin static void	addtominuslist(char *);
73*722Smuffin 
740Sstevel@tonic-gate 
750Sstevel@tonic-gate static struct gradata *
_gradata(void)76*722Smuffin _gradata(void)
770Sstevel@tonic-gate {
78*722Smuffin 	struct gradata *g = gradata;
790Sstevel@tonic-gate 
800Sstevel@tonic-gate 	if (g == 0) {
810Sstevel@tonic-gate 		g = (struct gradata *)calloc(1, sizeof (struct gradata));
820Sstevel@tonic-gate 		gradata = g;
830Sstevel@tonic-gate 	}
840Sstevel@tonic-gate 	return (g);
850Sstevel@tonic-gate }
860Sstevel@tonic-gate 
870Sstevel@tonic-gate struct group_adjunct *
getgranam(char * name)88*722Smuffin getgranam(char *name)
890Sstevel@tonic-gate {
90*722Smuffin 	struct gradata *g = _gradata();
910Sstevel@tonic-gate 	struct group_adjunct *gra;
920Sstevel@tonic-gate 	char line[BUFSIZ+1];
930Sstevel@tonic-gate 
940Sstevel@tonic-gate 	setgraent();
950Sstevel@tonic-gate 	if (g == 0)
960Sstevel@tonic-gate 		return (0);
970Sstevel@tonic-gate 	if (!g->grfa)
98*722Smuffin 		return (NULL);
990Sstevel@tonic-gate 	while (fgets(line, BUFSIZ, g->grfa) != NULL) {
1000Sstevel@tonic-gate 		if ((gra = interpret(line, strlen(line))) == NULL)
1010Sstevel@tonic-gate 			continue;
1020Sstevel@tonic-gate 		if (matchname(line, &gra, name)) {
1030Sstevel@tonic-gate 			endgraent();
1040Sstevel@tonic-gate 			return (gra);
1050Sstevel@tonic-gate 		}
1060Sstevel@tonic-gate 	}
1070Sstevel@tonic-gate 	endgraent();
1080Sstevel@tonic-gate 	return (NULL);
1090Sstevel@tonic-gate }
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate void
setgraent(void)112*722Smuffin setgraent(void)
1130Sstevel@tonic-gate {
114*722Smuffin 	struct gradata *g = _gradata();
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate 	if (g == NULL)
1170Sstevel@tonic-gate 		return;
1180Sstevel@tonic-gate 	if (g->domain == NULL)
1190Sstevel@tonic-gate 		(void) yp_get_default_domain(&g->domain);
1200Sstevel@tonic-gate 	if (!g->grfa)
1210Sstevel@tonic-gate 		g->grfa = fopen(GROUPADJ, "r");
1220Sstevel@tonic-gate 	else
1230Sstevel@tonic-gate 		rewind(g->grfa);
1240Sstevel@tonic-gate 	if (g->yp)
1250Sstevel@tonic-gate 		free(g->yp);
1260Sstevel@tonic-gate 	g->yp = NULL;
1270Sstevel@tonic-gate 	freeminuslist();
1280Sstevel@tonic-gate }
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate void
endgraent(void)131*722Smuffin endgraent(void)
1320Sstevel@tonic-gate {
133*722Smuffin 	struct gradata *g = _gradata();
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate 	if (g == 0)
1360Sstevel@tonic-gate 		return;
1370Sstevel@tonic-gate 	if (g->grfa) {
1380Sstevel@tonic-gate 		(void) fclose(g->grfa);
1390Sstevel@tonic-gate 		g->grfa = NULL;
1400Sstevel@tonic-gate 	}
1410Sstevel@tonic-gate 	if (g->yp)
1420Sstevel@tonic-gate 		free(g->yp);
1430Sstevel@tonic-gate 	g->yp = NULL;
1440Sstevel@tonic-gate 	freeminuslist();
1450Sstevel@tonic-gate }
1460Sstevel@tonic-gate 
1470Sstevel@tonic-gate struct group_adjunct *
fgetgraent(FILE * f)148*722Smuffin fgetgraent(FILE *f)
1490Sstevel@tonic-gate {
1500Sstevel@tonic-gate 	char line1[BUFSIZ+1];
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate 	if(fgets(line1, BUFSIZ, f) == NULL)
153*722Smuffin 		return (NULL);
1540Sstevel@tonic-gate 	return (interpret(line1, strlen(line1)));
1550Sstevel@tonic-gate }
1560Sstevel@tonic-gate 
1570Sstevel@tonic-gate static char *
grskip(char * p,int c)158*722Smuffin grskip(char *p, int c)
1590Sstevel@tonic-gate {
1600Sstevel@tonic-gate 	while(*p && *p != c && *p != '\n') ++p;
1610Sstevel@tonic-gate 	if (*p == '\n')
1620Sstevel@tonic-gate 		*p = '\0';
1630Sstevel@tonic-gate 	else if (*p != '\0')
1640Sstevel@tonic-gate 		*p++ = '\0';
165*722Smuffin 	return (p);
1660Sstevel@tonic-gate }
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate struct group_adjunct *
getgraent(void)169*722Smuffin getgraent(void)
1700Sstevel@tonic-gate {
171*722Smuffin 	struct gradata *g = _gradata();
1720Sstevel@tonic-gate 	char line1[BUFSIZ+1];
1730Sstevel@tonic-gate 	static struct group_adjunct *savegra;
1740Sstevel@tonic-gate 	struct group_adjunct *gra;
1750Sstevel@tonic-gate 
1760Sstevel@tonic-gate 	if (g == 0)
1770Sstevel@tonic-gate 		return (0);
1780Sstevel@tonic-gate 	if (g->domain == NULL) {
1790Sstevel@tonic-gate 		(void) yp_get_default_domain(&g->domain);
1800Sstevel@tonic-gate 	}
1810Sstevel@tonic-gate 	if(!g->grfa && !(g->grfa = fopen(GROUPADJ, "r")))
182*722Smuffin 		return (NULL);
1830Sstevel@tonic-gate   again:
1840Sstevel@tonic-gate 	if (g->yp) {
1850Sstevel@tonic-gate 		gra = interpretwithsave(g->yp, g->yplen, savegra);
1860Sstevel@tonic-gate 		free(g->yp);
1870Sstevel@tonic-gate 		if (gra == NULL)
188*722Smuffin 			return (NULL);
1890Sstevel@tonic-gate 		getnextfromyellow();
1900Sstevel@tonic-gate 		if (onminuslist(gra))
1910Sstevel@tonic-gate 			goto again;
1920Sstevel@tonic-gate 		else
1930Sstevel@tonic-gate 			return (gra);
1940Sstevel@tonic-gate 	}
1950Sstevel@tonic-gate 	else if (fgets(line1, BUFSIZ, g->grfa) == NULL)
196*722Smuffin 		return (NULL);
1970Sstevel@tonic-gate 	if ((gra = interpret(line1, strlen(line1))) == NULL)
198*722Smuffin 		return (NULL);
1990Sstevel@tonic-gate 	switch(line1[0]) {
2000Sstevel@tonic-gate 		case '+':
2010Sstevel@tonic-gate 			if (strcmp(gra->gra_name, "+") == 0) {
2020Sstevel@tonic-gate 				getfirstfromyellow();
2030Sstevel@tonic-gate 				savegra = save(gra);
2040Sstevel@tonic-gate 				goto again;
2050Sstevel@tonic-gate 			}
2060Sstevel@tonic-gate 			/*
2070Sstevel@tonic-gate 			 * else look up this entry in NIS
2080Sstevel@tonic-gate 			 */
2090Sstevel@tonic-gate 			savegra = save(gra);
2100Sstevel@tonic-gate 			gra = getnamefromyellow(gra->gra_name+1, savegra);
2110Sstevel@tonic-gate 			if (gra == NULL)
2120Sstevel@tonic-gate 				goto again;
2130Sstevel@tonic-gate 			else if (onminuslist(gra))
2140Sstevel@tonic-gate 				goto again;
2150Sstevel@tonic-gate 			else
2160Sstevel@tonic-gate 				return (gra);
2170Sstevel@tonic-gate 			break;
2180Sstevel@tonic-gate 		case '-':
2190Sstevel@tonic-gate 			addtominuslist(gra->gra_name+1);
2200Sstevel@tonic-gate 			goto again;
2210Sstevel@tonic-gate 			break;
2220Sstevel@tonic-gate 		default:
2230Sstevel@tonic-gate 			if (onminuslist(gra))
2240Sstevel@tonic-gate 				goto again;
2250Sstevel@tonic-gate 			return (gra);
2260Sstevel@tonic-gate 			break;
2270Sstevel@tonic-gate 	}
228*722Smuffin 	/* NOTREACHED */
2290Sstevel@tonic-gate }
2300Sstevel@tonic-gate 
2310Sstevel@tonic-gate static struct group_adjunct *
interpret(char * val,int len)232*722Smuffin interpret(char *val, int len)
2330Sstevel@tonic-gate {
234*722Smuffin 	struct gradata *g = _gradata();
235*722Smuffin 	char *p;
2360Sstevel@tonic-gate 
2370Sstevel@tonic-gate 	if (g == 0)
2380Sstevel@tonic-gate 		return (0);
2390Sstevel@tonic-gate 	strncpy(g->interpline, val, len);
2400Sstevel@tonic-gate 	p = g->interpline;
2410Sstevel@tonic-gate 	g->interpline[len] = '\n';
2420Sstevel@tonic-gate 	g->interpline[len+1] = 0;
2430Sstevel@tonic-gate 	g->interpgra.gra_name = p;
2440Sstevel@tonic-gate 	p = grskip(p,':');
2450Sstevel@tonic-gate         if (strcmp(g->interpgra.gra_name, "+") == 0) {
2460Sstevel@tonic-gate                 /* we are going to the NIS - fix the
2470Sstevel@tonic-gate                  * rest of the struct as much as is needed
2480Sstevel@tonic-gate                  */
2490Sstevel@tonic-gate                 g->interpgra.gra_passwd = "";
2500Sstevel@tonic-gate 		return (&g->interpgra);
2510Sstevel@tonic-gate         }
2520Sstevel@tonic-gate 	g->interpgra.gra_passwd = p;
2530Sstevel@tonic-gate         while(*p && *p != '\n') p++;
2540Sstevel@tonic-gate         *p = '\0';
2550Sstevel@tonic-gate 	return (&g->interpgra);
2560Sstevel@tonic-gate }
2570Sstevel@tonic-gate 
258*722Smuffin static void
freeminuslist(void)259*722Smuffin freeminuslist(void)
260*722Smuffin {
261*722Smuffin 	struct gradata *g = _gradata();
2620Sstevel@tonic-gate 	struct list *ls;
2630Sstevel@tonic-gate 
2640Sstevel@tonic-gate 	if (g == 0)
2650Sstevel@tonic-gate 		return;
2660Sstevel@tonic-gate 	for (ls = g->minuslist; ls != NULL; ls = ls->nxt) {
2670Sstevel@tonic-gate 		free(ls->name);
2680Sstevel@tonic-gate 		free(ls);
2690Sstevel@tonic-gate 	}
2700Sstevel@tonic-gate 	g->minuslist = NULL;
2710Sstevel@tonic-gate }
2720Sstevel@tonic-gate 
2730Sstevel@tonic-gate static struct group_adjunct *
interpretwithsave(char * val,int len,struct group_adjunct * savegra)274*722Smuffin interpretwithsave(char *val, int len, struct group_adjunct *savegra)
2750Sstevel@tonic-gate {
276*722Smuffin 	struct gradata *g = _gradata();
2770Sstevel@tonic-gate 	struct group_adjunct *gra;
2780Sstevel@tonic-gate 
2790Sstevel@tonic-gate 	if (g == 0)
2800Sstevel@tonic-gate 		return (0);
2810Sstevel@tonic-gate 	if ((gra = interpret(val, len)) == NULL)
2820Sstevel@tonic-gate 		return (NULL);
2830Sstevel@tonic-gate 	if (savegra->gra_passwd && *savegra->gra_passwd)
2840Sstevel@tonic-gate 		gra->gra_passwd =  savegra->gra_passwd;
2850Sstevel@tonic-gate 	return (gra);
2860Sstevel@tonic-gate }
2870Sstevel@tonic-gate 
288*722Smuffin static int
onminuslist(struct group_adjunct * gra)289*722Smuffin onminuslist(struct group_adjunct *gra)
2900Sstevel@tonic-gate {
291*722Smuffin 	struct gradata *g = _gradata();
2920Sstevel@tonic-gate 	struct list *ls;
293*722Smuffin 	char *nm;
2940Sstevel@tonic-gate 
2950Sstevel@tonic-gate 	if (g == 0)
296*722Smuffin 		return (0);
2970Sstevel@tonic-gate 	nm = gra->gra_name;
2980Sstevel@tonic-gate 	for (ls = g->minuslist; ls != NULL; ls = ls->nxt)
2990Sstevel@tonic-gate 		if (strcmp(ls->name, nm) == 0)
300*722Smuffin 			return (1);
301*722Smuffin 	return (0);
3020Sstevel@tonic-gate }
3030Sstevel@tonic-gate 
304*722Smuffin static void
getnextfromyellow(void)305*722Smuffin getnextfromyellow(void)
3060Sstevel@tonic-gate {
307*722Smuffin 	struct gradata *g = _gradata();
3080Sstevel@tonic-gate 	int reason;
3090Sstevel@tonic-gate 	char *key = NULL;
3100Sstevel@tonic-gate 	int keylen;
3110Sstevel@tonic-gate 
3120Sstevel@tonic-gate 	if (g == 0)
3130Sstevel@tonic-gate 		return;
3140Sstevel@tonic-gate 	if (reason = yp_next(g->domain, "group.adjunct.byname",
3150Sstevel@tonic-gate 	    g->oldyp, g->oldyplen, &key, &keylen,
3160Sstevel@tonic-gate 	    &g->yp, &g->yplen)) {
3170Sstevel@tonic-gate #ifdef DEBUG
3180Sstevel@tonic-gate fprintf(stderr, "reason yp_next failed is %d\n", reason);
3190Sstevel@tonic-gate #endif
3200Sstevel@tonic-gate 		g->yp = NULL;
3210Sstevel@tonic-gate 	}
3220Sstevel@tonic-gate 	if (g->oldyp)
3230Sstevel@tonic-gate 		free(g->oldyp);
3240Sstevel@tonic-gate 	g->oldyp = key;
3250Sstevel@tonic-gate 	g->oldyplen = keylen;
3260Sstevel@tonic-gate }
3270Sstevel@tonic-gate 
328*722Smuffin static void
getfirstfromyellow(void)329*722Smuffin getfirstfromyellow(void)
3300Sstevel@tonic-gate {
331*722Smuffin 	struct gradata *g = _gradata();
3320Sstevel@tonic-gate 	int reason;
3330Sstevel@tonic-gate 	char *key = NULL;
3340Sstevel@tonic-gate 	int keylen;
3350Sstevel@tonic-gate 
3360Sstevel@tonic-gate 	if (g == 0)
3370Sstevel@tonic-gate 		return;
3380Sstevel@tonic-gate 	if (reason =  yp_first(g->domain, "group.adjunct.byname",
3390Sstevel@tonic-gate 	    &key, &keylen, &g->yp, &g->yplen)) {
3400Sstevel@tonic-gate #ifdef DEBUG
3410Sstevel@tonic-gate fprintf(stderr, "reason yp_first failed is %d\n", reason);
3420Sstevel@tonic-gate #endif
3430Sstevel@tonic-gate 		g->yp = NULL;
3440Sstevel@tonic-gate 	}
3450Sstevel@tonic-gate 	if (g->oldyp)
3460Sstevel@tonic-gate 		free(g->oldyp);
3470Sstevel@tonic-gate 	g->oldyp = key;
3480Sstevel@tonic-gate 	g->oldyplen = keylen;
3490Sstevel@tonic-gate }
3500Sstevel@tonic-gate 
3510Sstevel@tonic-gate static struct group_adjunct *
getnamefromyellow(char * name,struct group_adjunct * savegra)352*722Smuffin getnamefromyellow(char *name, struct group_adjunct *savegra)
3530Sstevel@tonic-gate {
354*722Smuffin 	struct gradata *g = _gradata();
3550Sstevel@tonic-gate 	struct group_adjunct *gra;
3560Sstevel@tonic-gate 	int reason;
3570Sstevel@tonic-gate 	char *val;
3580Sstevel@tonic-gate 	int vallen;
3590Sstevel@tonic-gate 
3600Sstevel@tonic-gate 	if (g == 0)
3610Sstevel@tonic-gate 		return (NULL);
3620Sstevel@tonic-gate 	if (reason = yp_match(g->domain, "group.adjunct.byname",
3630Sstevel@tonic-gate 	    name, strlen(name), &val, &vallen)) {
3640Sstevel@tonic-gate #ifdef DEBUG
3650Sstevel@tonic-gate fprintf(stderr, "reason yp_next failed is %d\n", reason);
3660Sstevel@tonic-gate #endif
367*722Smuffin 		return (NULL);
3680Sstevel@tonic-gate 	}
3690Sstevel@tonic-gate 	else {
3700Sstevel@tonic-gate 		gra = interpret(val, vallen);
3710Sstevel@tonic-gate 		free(val);
3720Sstevel@tonic-gate 		if (gra == NULL)
373*722Smuffin 			return (NULL);
3740Sstevel@tonic-gate 		if (savegra->gra_passwd && *savegra->gra_passwd)
3750Sstevel@tonic-gate 			gra->gra_passwd =  savegra->gra_passwd;
376*722Smuffin 		return (gra);
3770Sstevel@tonic-gate 	}
3780Sstevel@tonic-gate }
3790Sstevel@tonic-gate 
380*722Smuffin static void
addtominuslist(char * name)381*722Smuffin addtominuslist(char *name)
3820Sstevel@tonic-gate {
383*722Smuffin 	struct gradata *g = _gradata();
3840Sstevel@tonic-gate 	struct list *ls;
3850Sstevel@tonic-gate 	char *buf;
3860Sstevel@tonic-gate 
3870Sstevel@tonic-gate 	if (g == 0)
3880Sstevel@tonic-gate 		return;
3890Sstevel@tonic-gate 	ls = (struct list *)malloc(sizeof(struct list));
3900Sstevel@tonic-gate 	buf = (char *)malloc(strlen(name) + 1);
3910Sstevel@tonic-gate 	(void) strcpy(buf, name);
3920Sstevel@tonic-gate 	ls->name = buf;
3930Sstevel@tonic-gate 	ls->nxt = g->minuslist;
3940Sstevel@tonic-gate 	g->minuslist = ls;
3950Sstevel@tonic-gate }
3960Sstevel@tonic-gate 
3970Sstevel@tonic-gate /*
3980Sstevel@tonic-gate  * save away psswd field, which is the only
3990Sstevel@tonic-gate  * one which can be specified in a local + entry to override the
4000Sstevel@tonic-gate  * value in the NIS
4010Sstevel@tonic-gate  */
4020Sstevel@tonic-gate static struct group_adjunct *
save(struct group_adjunct * gra)403*722Smuffin save(struct group_adjunct *gra)
4040Sstevel@tonic-gate {
405*722Smuffin 	struct gradata *g = _gradata();
4060Sstevel@tonic-gate 
4070Sstevel@tonic-gate 	if (g == 0)
408*722Smuffin 		return (0);
4090Sstevel@tonic-gate 	/*
4100Sstevel@tonic-gate 	 * free up stuff from last time around
4110Sstevel@tonic-gate 	 */
4120Sstevel@tonic-gate 	if (g->sv) {
4130Sstevel@tonic-gate 		free(g->sv->gra_passwd);
4140Sstevel@tonic-gate 		free(g->sv);
4150Sstevel@tonic-gate 	}
4160Sstevel@tonic-gate 	g->sv = (struct group_adjunct *)calloc(1, sizeof(struct group_adjunct));
4170Sstevel@tonic-gate 	g->sv->gra_passwd = (char *)malloc(strlen(gra->gra_passwd) + 1);
4180Sstevel@tonic-gate 	(void) strcpy(g->sv->gra_passwd, gra->gra_passwd);
419*722Smuffin 	return (g->sv);
4200Sstevel@tonic-gate }
4210Sstevel@tonic-gate 
422*722Smuffin static int
matchname(char line1[],struct group_adjunct ** grap,char * name)423*722Smuffin matchname(char line1[], struct group_adjunct **grap, char *name)
4240Sstevel@tonic-gate {
4250Sstevel@tonic-gate 	struct group_adjunct *savegra;
4260Sstevel@tonic-gate 	struct group_adjunct *gra = *grap;
4270Sstevel@tonic-gate 
428*722Smuffin 	switch (line1[0]) {
4290Sstevel@tonic-gate 		case '+':
4300Sstevel@tonic-gate 			if (strcmp(gra->gra_name, "+") == 0) {
4310Sstevel@tonic-gate 				savegra = save(gra);
4320Sstevel@tonic-gate 				gra = getnamefromyellow(name, savegra);
4330Sstevel@tonic-gate 				if (gra) {
4340Sstevel@tonic-gate 					*grap = gra;
435*722Smuffin 					return (1);
4360Sstevel@tonic-gate 				}
4370Sstevel@tonic-gate 				else
438*722Smuffin 					return (0);
4390Sstevel@tonic-gate 			}
4400Sstevel@tonic-gate 			if (strcmp(gra->gra_name+1, name) == 0) {
4410Sstevel@tonic-gate 				savegra = save(gra);
4420Sstevel@tonic-gate 				gra = getnamefromyellow(gra->gra_name+1, savegra);
4430Sstevel@tonic-gate 				if (gra) {
4440Sstevel@tonic-gate 					*grap = gra;
445*722Smuffin 					return (1);
4460Sstevel@tonic-gate 				}
4470Sstevel@tonic-gate 				else
448*722Smuffin 					return (0);
4490Sstevel@tonic-gate 			}
4500Sstevel@tonic-gate 			break;
4510Sstevel@tonic-gate 		case '-':
4520Sstevel@tonic-gate 			if (strcmp(gra->gra_name+1, name) == 0) {
4530Sstevel@tonic-gate 				*grap = NULL;
454*722Smuffin 				return (1);
4550Sstevel@tonic-gate 			}
4560Sstevel@tonic-gate 			break;
4570Sstevel@tonic-gate 		default:
4580Sstevel@tonic-gate 			if (strcmp(gra->gra_name, name) == 0)
459*722Smuffin 				return (1);
4600Sstevel@tonic-gate 	}
461*722Smuffin 	return (0);
4620Sstevel@tonic-gate }
463