]>
git.saurik.com Git - apple/libinfo.git/blob - nis.subproj/innetgr.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
[] = "@(#)innetgr.c 1.2 90/07/20 4.1NFSSRC; from 1.17 88/02/08 SMI Copyr 1985 Sun Micro";
29 * Copyright (c) 1990 by Sun Microsystems, Inc.
36 #include <rpcsvc/ypclnt.h>
39 * innetgr: test whether I'm in /etc/netgroup
49 #define LISTSIZE 200 /* recursion limit */
50 char **listp
; /* pointer into list */
54 static int lookup(char *, char *, char *, char *, char *, int *);
55 static int doit(register struct innetgrdata
*, char *);
56 static void makekey(char *, char *, char *);
58 int _old_innetgr(group
, machine
, name
, domain
)
59 char *group
, *machine
, *name
, *domain
;
62 register struct innetgrdata
*d
;
65 (void) yp_get_default_domain(&thisdomain
);
67 if (name
&& !machine
) {
68 if (lookup(thisdomain
,
69 "netgroup.byuser",group
,name
,domain
,&res
)) {
72 } else if (machine
&& !name
) {
73 if (lookup(thisdomain
,
74 "netgroup.byhost",group
,machine
,domain
,&res
)) {
79 d
= (struct innetgrdata
*)malloc(sizeof (struct innetgrdata
));
85 d
->thisdomain
= thisdomain
;
86 d
->list
= (char **)calloc(LISTSIZE
, sizeof (char *));
99 * calls itself recursively
103 register struct innetgrdata
*d
;
110 register char *p
, *q
;
115 if (d
->listp
> d
->list
+ LISTSIZE
) {
116 (void) fprintf(stderr
, "innetgr: recursive overflow\r\n");
121 keylen
= strlen(group
);
122 err
= yp_match(d
->thisdomain
, "netgroup", key
, keylen
, &val
, &vallen
);
125 if (err
== YPERR_KEY
)
126 (void) fprintf(stderr
,
127 "innetgr: no such netgroup as %s\n", group
);
129 (void) fprintf(stderr
, "innetgr: yp_match, %s\n",yperr_string(err
));
135 * check for recursive loops
137 for (lp
= d
->list
; lp
< d
->listp
-1; lp
++)
138 if (strcmp(*lp
, group
) == 0) {
139 (void) fprintf(stderr
,
140 "innetgr: netgroup %s called recursively\r\n",
151 while (*p
== ' ' || *p
== '\t')
153 if (*p
== 0 || *p
== '#')
157 while (*p
== ' ' || *p
== '\t')
159 r
= q
= index(p
, ',');
161 (void) fprintf(stderr
,
162 "innetgr: syntax error in /etc/netgroup\r\n");
167 if (p
== q
|| d
->machine
== NULL
)
170 while (*(q
-1) == ' ' || *(q
-1) == '\t')
172 if (strncmp(d
->machine
, p
, q
-p
) == 0)
177 while (*p
== ' ' || *p
== '\t')
179 r
= q
= index(p
, ',');
181 (void) fprintf(stderr
,
182 "innetgr: syntax error in /etc/netgroup\r\n");
187 if (p
== q
|| d
->name
== NULL
)
190 while (*(q
-1) == ' ' || *(q
-1) == '\t')
192 if (strncmp(d
->name
, p
, q
-p
) == 0)
197 while (*p
== ' ' || *p
== '\t')
199 r
= q
= index(p
, ')');
201 (void) fprintf(stderr
,
202 "innetgr: syntax error in /etc/netgroup\r\n");
207 if (p
== q
|| d
->domain
== NULL
)
210 while (*(q
-1) == ' ' || *(q
-1) == '\t')
212 if (strncmp(d
->domain
, p
, q
-p
) == 0)
223 q
= strpbrk(p
, " \t\n#");
236 p
= strpbrk(p
, " \t");
244 * return 1 if "what" is in the comma-separated, newline-terminated "d->list"
251 # define TERMINATOR(c) (c == ',' || c == '\n')
259 if (strncmp(what
,p
,len
) == 0 && TERMINATOR(p
[len
])) {
262 while (!TERMINATOR(*p
)) {
274 * Lookup a host or user name in a NIS map. Set result to 1 if group in the
275 * lookup list of groups. Return 1 if the map was found.
278 lookup(thisdomain
,map
,group
,name
,domain
,res
)
293 for (i
= 0; i
< 4; i
++) {
295 case 0: makekey(key
,name
,domain
); break;
296 case 1: makekey(key
,wild
,domain
); break;
297 case 2: makekey(key
,name
,wild
); break;
298 case 3: makekey(key
,wild
,wild
); break;
300 err
= yp_match(thisdomain
,map
,key
,strlen(key
),&val
,&vallen
);
302 *res
= inlist(group
,val
);
309 (void) fprintf(stderr
,
310 "yp_match(%s,%s) failed: %s.\n",map
,key
,yperr_string(err
));
312 if (err
!= YPERR_KEY
) {
324 * Generate a key for a netgroup.byXXXX NIS map
327 makekey(key
,name
,domain
)
330 register char *domain
;
332 while ((*key
++ = *name
++))
335 while ((*key
++ = *domain
++))