]>
git.saurik.com Git - apple/libinfo.git/blob - nis.subproj/getnetgrent.c
2 * Copyright (c) 1999-2015 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
24 #if !defined(lint) && defined(SCCSIDS)
25 static char sccsid
[] = "@(#)getnetgrent.c 1.2 90/07/20 4.1NFSSRC; from 1.22 88/02/08 Copyr 1985 Sun Micro";
29 * Copyright (c) 1985 by Sun Microsystems, Inc.
36 #include <rpcsvc/ypclnt.h>
38 #define MAXGROUPLEN 1024
41 * access members of a netgroup
44 static struct grouplist
{ /* also used by pwlib */
48 struct grouplist
*gl_nxt
;
52 struct list
{ /* list of names to check for loops */
63 char *NETGROUP
= "netgroup";
65 * recursive function to find the members of netgroup "group". "list" is
66 * the path followed through the netgroups so far, to check for cycles.
74 register struct list
*ls
;
75 struct list this_group
;
77 struct grouplist
*gpls
;
80 * check for non-existing groups
82 if ((val
= match(group
)) == NULL
)
88 for (ls
= list
; ls
!= NULL
; ls
= ls
->nxt
)
89 if (strcmp(ls
->name
, group
) == 0) {
90 (void) fprintf(stderr
,
91 "Cycle detected in /etc/netgroup: %s.\n", group
);
102 while (*p
== ' ' || *p
== '\t')
104 if (*p
== 0 || *p
=='#')
107 gpls
= (struct grouplist
*)
108 malloc(sizeof(struct grouplist
));
109 if (gpls
== NULL
) return;
111 if (!(p
= fill(p
,&gpls
->gl_machine
,',')))
113 if (!(p
= fill(p
,&gpls
->gl_name
,',')))
115 if (!(p
= fill(p
,&gpls
->gl_domain
,')')))
117 gpls
->gl_nxt
= grouplist
;
120 q
= strpbrk(p
, " \t\n#");
121 if (q
== NULL
|| *q
== '#')
127 p
= strpbrk(p
, " \t");
133 (void) fprintf(stderr
,"syntax error in /etc/netgroup\n");
134 (void) fprintf(stderr
,"--- %s\n",val
);
139 * Fill a buffer "target" selectively from buffer "start".
140 * "termchar" terminates the information in start, and preceding
141 * or trailing white space is ignored. The location just after the
142 * terminating character is returned.
145 fill(start
,target
,termchar
)
146 char *start
, **target
, termchar
;
148 register char *p
, *q
;
152 for (p
= start
; *p
== ' ' || *p
== '\t'; p
++)
154 r
= index(p
, termchar
);
160 for (q
= r
-1; *q
== ' ' || *q
== '\t'; q
--)
163 *target
= malloc(size
+1);
164 if (*target
== NULL
) return NULL
;
165 (void) strncpy(*target
,p
,(int) size
);
179 (void) yp_get_default_domain(&domain
);
180 if (yp_match(domain
, NETGROUP
, group
, strlen(group
), &val
, &vallen
))