]>
git.saurik.com Git - apple/libinfo.git/blob - nis.subproj/innetgr.c
c70d4eaf8db1d39f7e1ed6b7173347cf156c916b
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
[] = "@(#)innetgr.c 1.2 90/07/20 4.1NFSSRC; from 1.17 88/02/08 SMI Copyr 1985 Sun Micro";
30 * Copyright (c) 1990 by Sun Microsystems, Inc.
37 #include <rpcsvc/ypclnt.h>
40 * innetgr: test whether I'm in /etc/netgroup
50 #define LISTSIZE 200 /* recursion limit */
51 char **listp
; /* pointer into list */
55 static int lookup(char *, char *, char *, char *, char *, int *);
56 static int doit(register struct innetgrdata
*, char *);
57 static void makekey(char *, char *, char *);
59 int _old_innetgr(group
, machine
, name
, domain
)
60 char *group
, *machine
, *name
, *domain
;
63 register struct innetgrdata
*d
;
66 (void) yp_get_default_domain(&thisdomain
);
68 if (name
&& !machine
) {
69 if (lookup(thisdomain
,
70 "netgroup.byuser",group
,name
,domain
,&res
)) {
73 } else if (machine
&& !name
) {
74 if (lookup(thisdomain
,
75 "netgroup.byhost",group
,machine
,domain
,&res
)) {
80 d
= (struct innetgrdata
*)malloc(sizeof (struct innetgrdata
));
86 d
->thisdomain
= thisdomain
;
87 d
->list
= (char **)calloc(LISTSIZE
, sizeof (char *));
100 * calls itself recursively
104 register struct innetgrdata
*d
;
111 register char *p
, *q
;
116 if (d
->listp
> d
->list
+ LISTSIZE
) {
117 (void) fprintf(stderr
, "innetgr: recursive overflow\r\n");
122 keylen
= strlen(group
);
123 err
= yp_match(d
->thisdomain
, "netgroup", key
, keylen
, &val
, &vallen
);
126 if (err
== YPERR_KEY
)
127 (void) fprintf(stderr
,
128 "innetgr: no such netgroup as %s\n", group
);
130 (void) fprintf(stderr
, "innetgr: yp_match, %s\n",yperr_string(err
));
136 * check for recursive loops
138 for (lp
= d
->list
; lp
< d
->listp
-1; lp
++)
139 if (strcmp(*lp
, group
) == 0) {
140 (void) fprintf(stderr
,
141 "innetgr: netgroup %s called recursively\r\n",
152 while (*p
== ' ' || *p
== '\t')
154 if (*p
== 0 || *p
== '#')
158 while (*p
== ' ' || *p
== '\t')
160 r
= q
= index(p
, ',');
162 (void) fprintf(stderr
,
163 "innetgr: syntax error in /etc/netgroup\r\n");
168 if (p
== q
|| d
->machine
== NULL
)
171 while (*(q
-1) == ' ' || *(q
-1) == '\t')
173 if (strncmp(d
->machine
, p
, q
-p
) == 0)
178 while (*p
== ' ' || *p
== '\t')
180 r
= q
= index(p
, ',');
182 (void) fprintf(stderr
,
183 "innetgr: syntax error in /etc/netgroup\r\n");
188 if (p
== q
|| d
->name
== NULL
)
191 while (*(q
-1) == ' ' || *(q
-1) == '\t')
193 if (strncmp(d
->name
, p
, q
-p
) == 0)
198 while (*p
== ' ' || *p
== '\t')
200 r
= q
= index(p
, ')');
202 (void) fprintf(stderr
,
203 "innetgr: syntax error in /etc/netgroup\r\n");
208 if (p
== q
|| d
->domain
== NULL
)
211 while (*(q
-1) == ' ' || *(q
-1) == '\t')
213 if (strncmp(d
->domain
, p
, q
-p
) == 0)
224 q
= strpbrk(p
, " \t\n#");
237 p
= strpbrk(p
, " \t");
245 * return 1 if "what" is in the comma-separated, newline-terminated "d->list"
252 # define TERMINATOR(c) (c == ',' || c == '\n')
260 if (strncmp(what
,p
,len
) == 0 && TERMINATOR(p
[len
])) {
263 while (!TERMINATOR(*p
)) {
275 * Lookup a host or user name in a NIS map. Set result to 1 if group in the
276 * lookup list of groups. Return 1 if the map was found.
279 lookup(thisdomain
,map
,group
,name
,domain
,res
)
294 for (i
= 0; i
< 4; i
++) {
296 case 0: makekey(key
,name
,domain
); break;
297 case 1: makekey(key
,wild
,domain
); break;
298 case 2: makekey(key
,name
,wild
); break;
299 case 3: makekey(key
,wild
,wild
); break;
301 err
= yp_match(thisdomain
,map
,key
,strlen(key
),&val
,&vallen
);
303 *res
= inlist(group
,val
);
310 (void) fprintf(stderr
,
311 "yp_match(%s,%s) failed: %s.\n",map
,key
,yperr_string(err
));
313 if (err
!= YPERR_KEY
) {
325 * Generate a key for a netgroup.byXXXX NIS map
328 makekey(key
,name
,domain
)
331 register char *domain
;
333 while ((*key
++ = *name
++))
336 while ((*key
++ = *domain
++))