]>
git.saurik.com Git - apple/libinfo.git/blob - nis.subproj/getnetgrent.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 #if !defined(lint) && defined(SCCSIDS)
26 static char sccsid
[] = "@(#)getnetgrent.c 1.2 90/07/20 4.1NFSSRC; from 1.22 88/02/08 Copyr 1985 Sun Micro";
30 * Copyright (c) 1985 by Sun Microsystems, Inc.
37 #include <rpcsvc/ypclnt.h>
39 #define MAXGROUPLEN 1024
42 * access members of a netgroup
45 static struct grouplist
{ /* also used by pwlib */
49 struct grouplist
*gl_nxt
;
50 } *grouplist
, *grlist
;
53 struct list
{ /* list of names to check for loops */
65 char *NETGROUP
= "netgroup";
67 void _old_endnetgrent(void);
68 void _old_setnetgrent(char *);
70 void _old_setnetgrent(grp
)
75 oldgrp
= (char *)calloc(1,256);
76 if (strcmp(oldgrp
, grp
) == 0)
79 if (grouplist
!= NULL
)
81 doit(grp
, (struct list
*) NULL
);
83 (void) strcpy(oldgrp
, grp
);
87 void _old_endnetgrent()
89 register struct grouplist
*gl
;
91 for (gl
= grouplist
; gl
!= NULL
; gl
= gl
->gl_nxt
) {
108 int _old_getnetgrent(machinep
, namep
, domainp
)
109 char **machinep
, **namep
, **domainp
;
114 *machinep
= grlist
->gl_machine
;
115 *namep
= grlist
->gl_name
;
116 *domainp
= grlist
->gl_domain
;
117 grlist
= grlist
->gl_nxt
;
122 * recursive function to find the members of netgroup "group". "list" is
123 * the path followed through the netgroups so far, to check for cycles.
130 register char *p
, *q
;
131 register struct list
*ls
;
132 struct list this_group
;
134 struct grouplist
*gpls
;
137 * check for non-existing groups
139 if ((val
= match(group
)) == NULL
)
145 for (ls
= list
; ls
!= NULL
; ls
= ls
->nxt
)
146 if (strcmp(ls
->name
, group
) == 0) {
147 (void) fprintf(stderr
,
148 "Cycle detected in /etc/netgroup: %s.\n", group
);
159 while (*p
== ' ' || *p
== '\t')
161 if (*p
== 0 || *p
=='#')
164 gpls
= (struct grouplist
*)
165 malloc(sizeof(struct grouplist
));
167 if (!(p
= fill(p
,&gpls
->gl_machine
,',')))
169 if (!(p
= fill(p
,&gpls
->gl_name
,',')))
171 if (!(p
= fill(p
,&gpls
->gl_domain
,')')))
173 gpls
->gl_nxt
= grouplist
;
176 q
= strpbrk(p
, " \t\n#");
183 p
= strpbrk(p
, " \t");
188 (void) fprintf(stderr
,"syntax error in /etc/netgroup\n");
189 (void) fprintf(stderr
,"--- %s\n",val
);
194 * Fill a buffer "target" selectively from buffer "start".
195 * "termchar" terminates the information in start, and preceding
196 * or trailing white space is ignored. The location just after the
197 * terminating character is returned.
200 fill(start
,target
,termchar
)
201 char *start
, **target
, termchar
;
203 register char *p
, *q
;
207 for (p
= start
; *p
== ' ' || *p
== '\t'; p
++)
209 r
= index(p
, termchar
);
215 for (q
= r
-1; *q
== ' ' || *q
== '\t'; q
--)
218 *target
= malloc(size
+1);
219 (void) strncpy(*target
,p
,(int) size
);
233 (void) yp_get_default_domain(&domain
);
234 if (yp_match(domain
, NETGROUP
, group
, strlen(group
), &val
, &vallen
))