]>
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 * 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
;
49 } *grouplist
, *grlist
;
52 struct list
{ /* list of names to check for loops */
64 char *NETGROUP
= "netgroup";
66 void _old_endnetgrent(void);
67 void _old_setnetgrent(char *);
69 void _old_setnetgrent(grp
)
74 oldgrp
= (char *)calloc(1,256);
75 if (strcmp(oldgrp
, grp
) == 0)
78 if (grouplist
!= NULL
)
80 doit(grp
, (struct list
*) NULL
);
82 (void) strcpy(oldgrp
, grp
);
86 void _old_endnetgrent()
88 register struct grouplist
*gl
;
90 for (gl
= grouplist
; gl
!= NULL
; gl
= gl
->gl_nxt
) {
107 int _old_getnetgrent(machinep
, namep
, domainp
)
108 char **machinep
, **namep
, **domainp
;
113 *machinep
= grlist
->gl_machine
;
114 *namep
= grlist
->gl_name
;
115 *domainp
= grlist
->gl_domain
;
116 grlist
= grlist
->gl_nxt
;
121 * recursive function to find the members of netgroup "group". "list" is
122 * the path followed through the netgroups so far, to check for cycles.
129 register char *p
, *q
;
130 register struct list
*ls
;
131 struct list this_group
;
133 struct grouplist
*gpls
;
136 * check for non-existing groups
138 if ((val
= match(group
)) == NULL
)
144 for (ls
= list
; ls
!= NULL
; ls
= ls
->nxt
)
145 if (strcmp(ls
->name
, group
) == 0) {
146 (void) fprintf(stderr
,
147 "Cycle detected in /etc/netgroup: %s.\n", group
);
158 while (*p
== ' ' || *p
== '\t')
160 if (*p
== 0 || *p
=='#')
163 gpls
= (struct grouplist
*)
164 malloc(sizeof(struct grouplist
));
166 if (!(p
= fill(p
,&gpls
->gl_machine
,',')))
168 if (!(p
= fill(p
,&gpls
->gl_name
,',')))
170 if (!(p
= fill(p
,&gpls
->gl_domain
,')')))
172 gpls
->gl_nxt
= grouplist
;
175 q
= strpbrk(p
, " \t\n#");
182 p
= strpbrk(p
, " \t");
187 (void) fprintf(stderr
,"syntax error in /etc/netgroup\n");
188 (void) fprintf(stderr
,"--- %s\n",val
);
193 * Fill a buffer "target" selectively from buffer "start".
194 * "termchar" terminates the information in start, and preceding
195 * or trailing white space is ignored. The location just after the
196 * terminating character is returned.
199 fill(start
,target
,termchar
)
200 char *start
, **target
, termchar
;
202 register char *p
, *q
;
206 for (p
= start
; *p
== ' ' || *p
== '\t'; p
++)
208 r
= index(p
, termchar
);
214 for (q
= r
-1; *q
== ' ' || *q
== '\t'; q
--)
217 *target
= malloc(size
+1);
218 (void) strncpy(*target
,p
,(int) size
);
232 (void) yp_get_default_domain(&domain
);
233 if (yp_match(domain
, NETGROUP
, group
, strlen(group
), &val
, &vallen
))