4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
24 * Copyright (c) 1996, by Sun Microsystems, Inc.
25 * All rights reserved.
28 #ident "%Z%%M% %I% %E% SMI" /* SMI4.1 1.5 */
37 #define MAXGROUPLEN 1024
40 * Stolen mostly, from getnetgrent.c
42 * my_getgroup() performs the same function as _getgroup(), but operates
43 * on /etc/netgroup directly, rather than doing yp lookups.
45 * /etc/netgroup must first loaded into a hash table so the matching
46 * function can look up lines quickly.
50 /* To check for cycles in netgroups */
57 extern stringtable ngtable
; /* stored info from /etc/netgroup */
59 static struct grouplist
*grouplist
; /* stores a list of users in a group */
64 static void freegrouplist();
74 for (gl
= grouplist
; gl
!= NULL
; gl
= gl
->gl_nxt
) {
91 doit(group
, (struct list
*) NULL
);
100 * recursive function to find the members of netgroup "group". "list" is
101 * the path followed through the netgroups so far, to check for cycles.
108 register char *p
, *q
;
109 register struct list
*ls
;
112 struct grouplist
*gpls
;
116 * check for non-existing groups
118 if ((val
= match(group
)) == NULL
) {
126 for (ls
= list
; ls
!= NULL
; ls
= ls
->nxt
) {
127 if (strcmp(ls
->name
, group
) == 0) {
128 (void) fprintf(stderr
,
129 "Cycle detected in /etc/netgroup: %s.\n",
143 while (*p
== ' ' || *p
== '\t')
145 if (*p
== EOS
|| *p
== '#')
148 gpls
= MALLOC(struct grouplist
);
151 if (!(p
= fill(p
, &gpls
->gl_machine
, ','))) {
154 if (!(p
= fill(p
, &gpls
->gl_name
, ','))) {
157 if (!(p
= fill(p
, &gpls
->gl_domain
, ')'))) {
160 gpls
->gl_nxt
= grouplist
;
163 q
= any(p
, " \t\n#");
175 (void) fprintf(stderr
, "syntax error in /etc/netgroup\n");
176 (void) fprintf(stderr
, "--- %s %s\n", group
, val
);
183 * Fill a buffer "target" selectively from buffer "start".
184 * "termchar" terminates the information in start, and preceding
185 * or trailing white space is ignored. If the buffer "start" is
186 * empty, "target" is filled with "*". The location just after the
187 * terminating character is returned.
190 fill(start
, target
, termchar
)
200 for (p
= start
; *p
== ' ' || *p
== '\t'; p
++)
202 r
= strchr(p
, termchar
);
203 if (r
== (char *)NULL
) {
204 return ((char *)NULL
);
209 for (q
= r
-1; *q
== ' ' || *q
== '\t'; q
--)
212 STRNCPY(*target
, p
, size
);
219 * scans cp, looking for a match with any character
220 * in match. Returns pointer to place in cp that matched
221 * (or NULL if no match)
228 register char *mp
, c
;
231 for (mp
= match
; *mp
; mp
++)
242 * The equivalent of yp_match. Returns the match, or NULL if there is none.
248 return (lookup(ngtable
, group
));