xref: /freebsd/lib/libc/gen/getnetgrent.c (revision 0ffe27f5)
158f0484fSRodney W. Grimes /*
258f0484fSRodney W. Grimes  * Copyright (c) 1992, 1993
358f0484fSRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
458f0484fSRodney W. Grimes  *
558f0484fSRodney W. Grimes  * This code is derived from software contributed to Berkeley by
658f0484fSRodney W. Grimes  * Rick Macklem at The University of Guelph.
758f0484fSRodney W. Grimes  *
858f0484fSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
958f0484fSRodney W. Grimes  * modification, are permitted provided that the following conditions
1058f0484fSRodney W. Grimes  * are met:
1158f0484fSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
1258f0484fSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
1358f0484fSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
1458f0484fSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
1558f0484fSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
1658f0484fSRodney W. Grimes  * 3. All advertising materials mentioning features or use of this software
1758f0484fSRodney W. Grimes  *    must display the following acknowledgement:
1858f0484fSRodney W. Grimes  *	This product includes software developed by the University of
1958f0484fSRodney W. Grimes  *	California, Berkeley and its contributors.
2058f0484fSRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
2158f0484fSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
2258f0484fSRodney W. Grimes  *    without specific prior written permission.
2358f0484fSRodney W. Grimes  *
2458f0484fSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2558f0484fSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2658f0484fSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2758f0484fSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2858f0484fSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2958f0484fSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3058f0484fSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3158f0484fSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3258f0484fSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3358f0484fSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3458f0484fSRodney W. Grimes  * SUCH DAMAGE.
3558f0484fSRodney W. Grimes  */
3658f0484fSRodney W. Grimes 
3758f0484fSRodney W. Grimes #if defined(LIBC_SCCS) && !defined(lint)
3858f0484fSRodney W. Grimes static char sccsid[] = "@(#)getnetgrent.c	8.1 (Berkeley) 6/4/93";
3958f0484fSRodney W. Grimes #endif /* LIBC_SCCS and not lint */
4058f0484fSRodney W. Grimes 
4158f0484fSRodney W. Grimes #include <stdio.h>
4258f0484fSRodney W. Grimes #include <strings.h>
4358f0484fSRodney W. Grimes 
4458f0484fSRodney W. Grimes #define _PATH_NETGROUP "/etc/netgroup"
4558f0484fSRodney W. Grimes 
4658f0484fSRodney W. Grimes /*
4758f0484fSRodney W. Grimes  * Static Variables and functions used by setnetgrent(), getnetgrent() and
4858f0484fSRodney W. Grimes  * endnetgrent().
4958f0484fSRodney W. Grimes  * There are two linked lists:
5058f0484fSRodney W. Grimes  * - linelist is just used by setnetgrent() to parse the net group file via.
5158f0484fSRodney W. Grimes  *   parse_netgrp()
5258f0484fSRodney W. Grimes  * - netgrp is the list of entries for the current netgroup
5358f0484fSRodney W. Grimes  */
5458f0484fSRodney W. Grimes struct linelist {
5558f0484fSRodney W. Grimes 	struct linelist	*l_next;	/* Chain ptr. */
5658f0484fSRodney W. Grimes 	int		l_parsed;	/* Flag for cycles */
5758f0484fSRodney W. Grimes 	char		*l_groupname;	/* Name of netgroup */
5858f0484fSRodney W. Grimes 	char		*l_line;	/* Netgroup entrie(s) to be parsed */
5958f0484fSRodney W. Grimes };
6058f0484fSRodney W. Grimes 
6158f0484fSRodney W. Grimes struct netgrp {
6258f0484fSRodney W. Grimes 	struct netgrp	*ng_next;	/* Chain ptr */
6358f0484fSRodney W. Grimes 	char		*ng_str[3];	/* Field pointers, see below */
6458f0484fSRodney W. Grimes };
6558f0484fSRodney W. Grimes #define NG_HOST		0	/* Host name */
6658f0484fSRodney W. Grimes #define NG_USER		1	/* User name */
6758f0484fSRodney W. Grimes #define NG_DOM		2	/* and Domain name */
6858f0484fSRodney W. Grimes 
6958f0484fSRodney W. Grimes static struct linelist	*linehead = (struct linelist *)0;
7058f0484fSRodney W. Grimes static struct netgrp	*nextgrp = (struct netgrp *)0;
7158f0484fSRodney W. Grimes static struct {
7258f0484fSRodney W. Grimes 	struct netgrp	*gr;
7358f0484fSRodney W. Grimes 	char		*grname;
7458f0484fSRodney W. Grimes } grouphead = {
7558f0484fSRodney W. Grimes 	(struct netgrp *)0,
7658f0484fSRodney W. Grimes 	(char *)0,
7758f0484fSRodney W. Grimes };
7858f0484fSRodney W. Grimes static FILE *netf = (FILE *)0;
7958f0484fSRodney W. Grimes static int parse_netgrp();
808516cd0fSBill Paul #ifdef YP
818516cd0fSBill Paul static int _netgr_yp_enabled;
828516cd0fSBill Paul #endif
8358f0484fSRodney W. Grimes static struct linelist *read_for_group();
8458f0484fSRodney W. Grimes void setnetgrent(), endnetgrent();
8558f0484fSRodney W. Grimes int getnetgrent(), innetgr();
8658f0484fSRodney W. Grimes 
8758f0484fSRodney W. Grimes #define	LINSIZ	1024	/* Length of netgroup file line */
8858f0484fSRodney W. Grimes 
8958f0484fSRodney W. Grimes /*
9058f0484fSRodney W. Grimes  * setnetgrent()
9158f0484fSRodney W. Grimes  * Parse the netgroup file looking for the netgroup and build the list
9258f0484fSRodney W. Grimes  * of netgrp structures. Let parse_netgrp() and read_for_group() do
9358f0484fSRodney W. Grimes  * most of the work.
9458f0484fSRodney W. Grimes  */
9558f0484fSRodney W. Grimes void
9658f0484fSRodney W. Grimes setnetgrent(group)
9758f0484fSRodney W. Grimes 	char *group;
9858f0484fSRodney W. Grimes {
990ffe27f5SBill Paul 	/* Sanity check */
10062a77170SBill Paul 
1010ffe27f5SBill Paul 	if (group == NULL || !strlen(group))
10262a77170SBill Paul 		return;
1030ffe27f5SBill Paul 
10458f0484fSRodney W. Grimes 	if (grouphead.gr == (struct netgrp *)0 ||
10558f0484fSRodney W. Grimes 		strcmp(group, grouphead.grname)) {
10658f0484fSRodney W. Grimes 		endnetgrent();
10758f0484fSRodney W. Grimes 		if (netf = fopen(_PATH_NETGROUP, "r")) {
10858f0484fSRodney W. Grimes 			if (parse_netgrp(group))
10958f0484fSRodney W. Grimes 				endnetgrent();
11058f0484fSRodney W. Grimes 			else {
11158f0484fSRodney W. Grimes 				grouphead.grname = (char *)
11258f0484fSRodney W. Grimes 					malloc(strlen(group) + 1);
11358f0484fSRodney W. Grimes 				strcpy(grouphead.grname, group);
11458f0484fSRodney W. Grimes 			}
11558f0484fSRodney W. Grimes 			fclose(netf);
11658f0484fSRodney W. Grimes 		}
11758f0484fSRodney W. Grimes 	}
11858f0484fSRodney W. Grimes 	nextgrp = grouphead.gr;
11958f0484fSRodney W. Grimes }
12058f0484fSRodney W. Grimes 
12158f0484fSRodney W. Grimes /*
12258f0484fSRodney W. Grimes  * Get the next netgroup off the list.
12358f0484fSRodney W. Grimes  */
12458f0484fSRodney W. Grimes int
12558f0484fSRodney W. Grimes getnetgrent(hostp, userp, domp)
12658f0484fSRodney W. Grimes 	char **hostp, **userp, **domp;
12758f0484fSRodney W. Grimes {
12858f0484fSRodney W. Grimes 
12958f0484fSRodney W. Grimes 	if (nextgrp) {
13058f0484fSRodney W. Grimes 		*hostp = nextgrp->ng_str[NG_HOST];
13158f0484fSRodney W. Grimes 		*userp = nextgrp->ng_str[NG_USER];
13258f0484fSRodney W. Grimes 		*domp = nextgrp->ng_str[NG_DOM];
13358f0484fSRodney W. Grimes 		nextgrp = nextgrp->ng_next;
13458f0484fSRodney W. Grimes 		return (1);
13558f0484fSRodney W. Grimes 	}
13658f0484fSRodney W. Grimes 	return (0);
13758f0484fSRodney W. Grimes }
13858f0484fSRodney W. Grimes 
13958f0484fSRodney W. Grimes /*
14058f0484fSRodney W. Grimes  * endnetgrent() - cleanup
14158f0484fSRodney W. Grimes  */
14258f0484fSRodney W. Grimes void
14358f0484fSRodney W. Grimes endnetgrent()
14458f0484fSRodney W. Grimes {
14558f0484fSRodney W. Grimes 	register struct linelist *lp, *olp;
14658f0484fSRodney W. Grimes 	register struct netgrp *gp, *ogp;
14758f0484fSRodney W. Grimes 
14858f0484fSRodney W. Grimes 	lp = linehead;
14958f0484fSRodney W. Grimes 	while (lp) {
15058f0484fSRodney W. Grimes 		olp = lp;
15158f0484fSRodney W. Grimes 		lp = lp->l_next;
15258f0484fSRodney W. Grimes 		free(olp->l_groupname);
15358f0484fSRodney W. Grimes 		free(olp->l_line);
15458f0484fSRodney W. Grimes 		free((char *)olp);
15558f0484fSRodney W. Grimes 	}
15658f0484fSRodney W. Grimes 	linehead = (struct linelist *)0;
15758f0484fSRodney W. Grimes 	if (grouphead.grname) {
15858f0484fSRodney W. Grimes 		free(grouphead.grname);
15958f0484fSRodney W. Grimes 		grouphead.grname = (char *)0;
16058f0484fSRodney W. Grimes 	}
16158f0484fSRodney W. Grimes 	gp = grouphead.gr;
16258f0484fSRodney W. Grimes 	while (gp) {
16358f0484fSRodney W. Grimes 		ogp = gp;
16458f0484fSRodney W. Grimes 		gp = gp->ng_next;
16558f0484fSRodney W. Grimes 		if (ogp->ng_str[NG_HOST])
16658f0484fSRodney W. Grimes 			free(ogp->ng_str[NG_HOST]);
16758f0484fSRodney W. Grimes 		if (ogp->ng_str[NG_USER])
16858f0484fSRodney W. Grimes 			free(ogp->ng_str[NG_USER]);
16958f0484fSRodney W. Grimes 		if (ogp->ng_str[NG_DOM])
17058f0484fSRodney W. Grimes 			free(ogp->ng_str[NG_DOM]);
17158f0484fSRodney W. Grimes 		free((char *)ogp);
17258f0484fSRodney W. Grimes 	}
17358f0484fSRodney W. Grimes 	grouphead.gr = (struct netgrp *)0;
174409495f6SBill Paul #ifdef YP
1758516cd0fSBill Paul 	_netgr_yp_enabled = 0;
176409495f6SBill Paul #endif
17758f0484fSRodney W. Grimes }
17858f0484fSRodney W. Grimes 
17958f0484fSRodney W. Grimes /*
18058f0484fSRodney W. Grimes  * Search for a match in a netgroup.
18158f0484fSRodney W. Grimes  */
18258f0484fSRodney W. Grimes int
18358f0484fSRodney W. Grimes innetgr(group, host, user, dom)
18458f0484fSRodney W. Grimes 	char *group, *host, *user, *dom;
18558f0484fSRodney W. Grimes {
18658f0484fSRodney W. Grimes 	char *hst, *usr, *dm;
18758f0484fSRodney W. Grimes 
1880ffe27f5SBill Paul 	/* Sanity check */
1890ffe27f5SBill Paul 
1900ffe27f5SBill Paul 	if (group == NULL || !strlen(group))
1910ffe27f5SBill Paul 		return (0);
1920ffe27f5SBill Paul 
19358f0484fSRodney W. Grimes 	setnetgrent(group);
19458f0484fSRodney W. Grimes 	while (getnetgrent(&hst, &usr, &dm))
19558f0484fSRodney W. Grimes 		if ((host == (char *)0 || !strcmp(host, hst)) &&
19658f0484fSRodney W. Grimes 		    (user == (char *)0 || !strcmp(user, usr)) &&
19758f0484fSRodney W. Grimes 		    (dom == (char *)0 || !strcmp(dom, dm))) {
19858f0484fSRodney W. Grimes 			endnetgrent();
19958f0484fSRodney W. Grimes 			return (1);
20058f0484fSRodney W. Grimes 		}
20158f0484fSRodney W. Grimes 	endnetgrent();
20258f0484fSRodney W. Grimes 	return (0);
20358f0484fSRodney W. Grimes }
20458f0484fSRodney W. Grimes 
20558f0484fSRodney W. Grimes /*
20658f0484fSRodney W. Grimes  * Parse the netgroup file setting up the linked lists.
20758f0484fSRodney W. Grimes  */
20858f0484fSRodney W. Grimes static int
20958f0484fSRodney W. Grimes parse_netgrp(group)
21058f0484fSRodney W. Grimes 	char *group;
21158f0484fSRodney W. Grimes {
21258f0484fSRodney W. Grimes 	register char *spos, *epos;
21358f0484fSRodney W. Grimes 	register int len, strpos;
21458f0484fSRodney W. Grimes 	char *pos, *gpos;
21558f0484fSRodney W. Grimes 	struct netgrp *grp;
21658f0484fSRodney W. Grimes 	struct linelist *lp = linehead;
21758f0484fSRodney W. Grimes 
21858f0484fSRodney W. Grimes 	/*
21958f0484fSRodney W. Grimes 	 * First, see if the line has already been read in.
22058f0484fSRodney W. Grimes 	 */
22158f0484fSRodney W. Grimes 	while (lp) {
22258f0484fSRodney W. Grimes 		if (!strcmp(group, lp->l_groupname))
22358f0484fSRodney W. Grimes 			break;
22458f0484fSRodney W. Grimes 		lp = lp->l_next;
22558f0484fSRodney W. Grimes 	}
22658f0484fSRodney W. Grimes 	if (lp == (struct linelist *)0 &&
22758f0484fSRodney W. Grimes 	    (lp = read_for_group(group)) == (struct linelist *)0)
22858f0484fSRodney W. Grimes 		return (1);
22958f0484fSRodney W. Grimes 	if (lp->l_parsed) {
23058f0484fSRodney W. Grimes 		fprintf(stderr, "Cycle in netgroup %s\n", lp->l_groupname);
23158f0484fSRodney W. Grimes 		return (1);
23258f0484fSRodney W. Grimes 	} else
23358f0484fSRodney W. Grimes 		lp->l_parsed = 1;
23458f0484fSRodney W. Grimes 	pos = lp->l_line;
235409495f6SBill Paul 	/* Watch for null pointer dereferences, dammit! */
236409495f6SBill Paul 	while (pos != NULL && *pos != '\0') {
23758f0484fSRodney W. Grimes 		if (*pos == '(') {
23858f0484fSRodney W. Grimes 			grp = (struct netgrp *)malloc(sizeof (struct netgrp));
23958f0484fSRodney W. Grimes 			bzero((char *)grp, sizeof (struct netgrp));
24058f0484fSRodney W. Grimes 			grp->ng_next = grouphead.gr;
24158f0484fSRodney W. Grimes 			grouphead.gr = grp;
24258f0484fSRodney W. Grimes 			pos++;
24358f0484fSRodney W. Grimes 			gpos = strsep(&pos, ")");
24458f0484fSRodney W. Grimes 			for (strpos = 0; strpos < 3; strpos++) {
24558f0484fSRodney W. Grimes 				if (spos = strsep(&gpos, ",")) {
24658f0484fSRodney W. Grimes 					while (*spos == ' ' || *spos == '\t')
24758f0484fSRodney W. Grimes 						spos++;
24858f0484fSRodney W. Grimes 					if (epos = strpbrk(spos, " \t")) {
24958f0484fSRodney W. Grimes 						*epos = '\0';
25058f0484fSRodney W. Grimes 						len = epos - spos;
25158f0484fSRodney W. Grimes 					} else
25258f0484fSRodney W. Grimes 						len = strlen(spos);
25358f0484fSRodney W. Grimes 					if (len > 0) {
25458f0484fSRodney W. Grimes 						grp->ng_str[strpos] =  (char *)
25558f0484fSRodney W. Grimes 							malloc(len + 1);
25658f0484fSRodney W. Grimes 						bcopy(spos, grp->ng_str[strpos],
25758f0484fSRodney W. Grimes 							len + 1);
25858f0484fSRodney W. Grimes 					}
25958f0484fSRodney W. Grimes 				} else
26058f0484fSRodney W. Grimes 					goto errout;
26158f0484fSRodney W. Grimes 			}
26258f0484fSRodney W. Grimes 		} else {
26358f0484fSRodney W. Grimes 			spos = strsep(&pos, ", \t");
26458f0484fSRodney W. Grimes 			if (parse_netgrp(spos))
265e8030794SBill Paul 				continue;
26658f0484fSRodney W. Grimes 		}
267409495f6SBill Paul 		/* Watch for null pointer dereferences, dammit! */
268409495f6SBill Paul 		if (pos != NULL)
26958f0484fSRodney W. Grimes 			while (*pos == ' ' || *pos == ',' || *pos == '\t')
27058f0484fSRodney W. Grimes 				pos++;
27158f0484fSRodney W. Grimes 	}
27258f0484fSRodney W. Grimes 	return (0);
27358f0484fSRodney W. Grimes errout:
27458f0484fSRodney W. Grimes 	fprintf(stderr, "Bad netgroup %s at ..%s\n", lp->l_groupname,
27558f0484fSRodney W. Grimes 		spos);
27658f0484fSRodney W. Grimes 	return (1);
27758f0484fSRodney W. Grimes }
27858f0484fSRodney W. Grimes 
27958f0484fSRodney W. Grimes /*
28058f0484fSRodney W. Grimes  * Read the netgroup file and save lines until the line for the netgroup
28158f0484fSRodney W. Grimes  * is found. Return 1 if eof is encountered.
28258f0484fSRodney W. Grimes  */
28358f0484fSRodney W. Grimes static struct linelist *
28458f0484fSRodney W. Grimes read_for_group(group)
28558f0484fSRodney W. Grimes 	char *group;
28658f0484fSRodney W. Grimes {
28758f0484fSRodney W. Grimes 	register char *pos, *spos, *linep, *olinep;
28858f0484fSRodney W. Grimes 	register int len, olen;
28958f0484fSRodney W. Grimes 	int cont;
29058f0484fSRodney W. Grimes 	struct linelist *lp;
29158f0484fSRodney W. Grimes 	char line[LINSIZ + 1];
292409495f6SBill Paul #ifdef YP
293409495f6SBill Paul 	static char *_netgr_yp_domain;
294409495f6SBill Paul 	char *result;
295409495f6SBill Paul 	int resultlen;
29658f0484fSRodney W. Grimes 
297409495f6SBill Paul 	while (_netgr_yp_enabled || fgets(line, LINSIZ, netf) != NULL) {
298409495f6SBill Paul 		if (_netgr_yp_enabled) {
299409495f6SBill Paul 			if(!_netgr_yp_domain)
3008516cd0fSBill Paul 				if(yp_get_default_domain(&_netgr_yp_domain))
301409495f6SBill Paul 					continue;
3028516cd0fSBill Paul 			if (yp_match(_netgr_yp_domain, "netgroup", group,
3038516cd0fSBill Paul 					strlen(group), &result, &resultlen)) {
3048516cd0fSBill Paul 				free(result);
3058516cd0fSBill Paul 				return ((struct linelist *)0);
306409495f6SBill Paul 			}
3078516cd0fSBill Paul 			sprintf(line, "%s %s", group, result);
308409495f6SBill Paul 			free(result);
309409495f6SBill Paul 		}
310409495f6SBill Paul #else
31158f0484fSRodney W. Grimes 	while (fgets(line, LINSIZ, netf) != NULL) {
312409495f6SBill Paul #endif
313409495f6SBill Paul 		pos = (char *)&line;
314409495f6SBill Paul #ifdef YP
3158516cd0fSBill Paul 		/*
3168516cd0fSBill Paul 		 * Once we default over to NIS, only
3178516cd0fSBill Paul 		 * endnetgrent() can get us out again.
3188516cd0fSBill Paul 		 */
319409495f6SBill Paul 		if (*pos == '+') {
320409495f6SBill Paul 			_netgr_yp_enabled = 1;
321409495f6SBill Paul 			continue;
322409495f6SBill Paul 		}
323409495f6SBill Paul #endif
32458f0484fSRodney W. Grimes 		if (*pos == '#')
32558f0484fSRodney W. Grimes 			continue;
32658f0484fSRodney W. Grimes 		while (*pos == ' ' || *pos == '\t')
32758f0484fSRodney W. Grimes 			pos++;
32858f0484fSRodney W. Grimes 		spos = pos;
32958f0484fSRodney W. Grimes 		while (*pos != ' ' && *pos != '\t' && *pos != '\n' &&
33058f0484fSRodney W. Grimes 			*pos != '\0')
33158f0484fSRodney W. Grimes 			pos++;
33258f0484fSRodney W. Grimes 		len = pos - spos;
33358f0484fSRodney W. Grimes 		while (*pos == ' ' || *pos == '\t')
33458f0484fSRodney W. Grimes 			pos++;
33558f0484fSRodney W. Grimes 		if (*pos != '\n' && *pos != '\0') {
33658f0484fSRodney W. Grimes 			lp = (struct linelist *)malloc(sizeof (*lp));
33758f0484fSRodney W. Grimes 			lp->l_parsed = 0;
33858f0484fSRodney W. Grimes 			lp->l_groupname = (char *)malloc(len + 1);
33958f0484fSRodney W. Grimes 			bcopy(spos, lp->l_groupname, len);
34058f0484fSRodney W. Grimes 			*(lp->l_groupname + len) = '\0';
34158f0484fSRodney W. Grimes 			len = strlen(pos);
34258f0484fSRodney W. Grimes 			olen = 0;
34358f0484fSRodney W. Grimes 
34458f0484fSRodney W. Grimes 			/*
34558f0484fSRodney W. Grimes 			 * Loop around handling line continuations.
34658f0484fSRodney W. Grimes 			 */
34758f0484fSRodney W. Grimes 			do {
34858f0484fSRodney W. Grimes 				if (*(pos + len - 1) == '\n')
34958f0484fSRodney W. Grimes 					len--;
35058f0484fSRodney W. Grimes 				if (*(pos + len - 1) == '\\') {
35158f0484fSRodney W. Grimes 					len--;
35258f0484fSRodney W. Grimes 					cont = 1;
35358f0484fSRodney W. Grimes 				} else
35458f0484fSRodney W. Grimes 					cont = 0;
35558f0484fSRodney W. Grimes 				if (len > 0) {
35658f0484fSRodney W. Grimes 					linep = (char *)malloc(olen + len + 1);
35758f0484fSRodney W. Grimes 					if (olen > 0) {
35858f0484fSRodney W. Grimes 						bcopy(olinep, linep, olen);
35958f0484fSRodney W. Grimes 						free(olinep);
36058f0484fSRodney W. Grimes 					}
36158f0484fSRodney W. Grimes 					bcopy(pos, linep + olen, len);
36258f0484fSRodney W. Grimes 					olen += len;
36358f0484fSRodney W. Grimes 					*(linep + olen) = '\0';
36458f0484fSRodney W. Grimes 					olinep = linep;
36558f0484fSRodney W. Grimes 				}
36658f0484fSRodney W. Grimes 				if (cont) {
36758f0484fSRodney W. Grimes 					if (fgets(line, LINSIZ, netf)) {
36858f0484fSRodney W. Grimes 						pos = line;
36958f0484fSRodney W. Grimes 						len = strlen(pos);
37058f0484fSRodney W. Grimes 					} else
37158f0484fSRodney W. Grimes 						cont = 0;
37258f0484fSRodney W. Grimes 				}
37358f0484fSRodney W. Grimes 			} while (cont);
37458f0484fSRodney W. Grimes 			lp->l_line = linep;
37558f0484fSRodney W. Grimes 			lp->l_next = linehead;
37658f0484fSRodney W. Grimes 			linehead = lp;
37758f0484fSRodney W. Grimes 
37858f0484fSRodney W. Grimes 			/*
37958f0484fSRodney W. Grimes 			 * If this is the one we wanted, we are done.
38058f0484fSRodney W. Grimes 			 */
38158f0484fSRodney W. Grimes 			if (!strcmp(lp->l_groupname, group))
38258f0484fSRodney W. Grimes 				return (lp);
38358f0484fSRodney W. Grimes 		}
38458f0484fSRodney W. Grimes 	}
38558f0484fSRodney W. Grimes 	return ((struct linelist *)0);
38658f0484fSRodney W. Grimes }
387