Print this page
*** NO COMMENTS ***
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/ypcmd/revnetgroup/getgroup.c
+++ new/usr/src/cmd/ypcmd/revnetgroup/getgroup.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
16 16 * If applicable, add the following below this CDDL HEADER, with the
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 19 *
20 20 * CDDL HEADER END
21 21 */
22 22
23 23 /*
24 24 * Copyright (c) 1996, by Sun Microsystems, Inc.
25 25 * All rights reserved.
26 + *
27 + * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
26 28 */
27 -
28 -#ident "%Z%%M% %I% %E% SMI" /* SMI4.1 1.5 */
29 29
30 +#include <stdlib.h>
30 31 #include <stdio.h>
31 32 #include <ctype.h>
32 33 #include <string.h>
33 34 #include "table.h"
34 35 #include "util.h"
35 36 #include "getgroup.h"
36 37
37 -#define MAXGROUPLEN 1024
38 -
39 38 /*
40 39 * Stolen mostly, from getnetgrent.c
41 40 *
42 41 * my_getgroup() performs the same function as _getgroup(), but operates
43 42 * on /etc/netgroup directly, rather than doing yp lookups.
44 43 *
45 44 * /etc/netgroup must first loaded into a hash table so the matching
46 45 * function can look up lines quickly.
47 46 */
48 47
49 48
50 49 /* To check for cycles in netgroups */
51 50 struct list {
52 51 char *name;
53 52 struct list *nxt;
54 53 };
55 54
56 -
57 -extern stringtable ngtable; /* stored info from /etc/netgroup */
58 -
59 -static struct grouplist *grouplist; /* stores a list of users in a group */
60 -
61 55 static char *any();
62 56 static char *match();
63 57 static char *fill();
64 -static void freegrouplist();
65 -static void doit();
66 58
67 59
68 -
69 -static void
70 -freegrouplist()
60 +void
61 +freegrouplist(revhandle_t *hdl)
71 62 {
72 - struct grouplist *gl;
63 + struct grouplist *gl, *next;
73 64
74 - for (gl = grouplist; gl != NULL; gl = gl->gl_nxt) {
65 + for (gl = hdl->grouplist; gl != NULL; gl = next) {
66 + next = gl->gl_nxt;
67 +
75 68 FREE(gl->gl_name);
76 69 FREE(gl->gl_domain);
77 70 FREE(gl->gl_machine);
78 71 FREE(gl);
79 72 }
80 - grouplist = NULL;
73 + hdl->grouplist = NULL;
81 74 }
82 75
83 76
84 77
85 -
86 -struct grouplist *
87 -my_getgroup(group)
88 - char *group;
89 -{
90 - freegrouplist();
91 - doit(group, (struct list *) NULL);
92 - return (grouplist);
93 -}
94 -
95 -
96 -
97 -
98 -
99 78 /*
100 79 * recursive function to find the members of netgroup "group". "list" is
101 80 * the path followed through the netgroups so far, to check for cycles.
102 81 */
103 -static void
104 -doit(group, list)
105 - char *group;
106 - struct list *list;
82 +void
83 +doit(char *group, struct list *list, revhandle_t *hdl)
107 84 {
108 85 register char *p, *q;
109 86 register struct list *ls;
110 87 struct list tmplist;
111 88 char *val;
112 89 struct grouplist *gpls;
113 90
114 91
115 92 /*
116 93 * check for non-existing groups
117 94 */
118 - if ((val = match(group)) == NULL) {
95 + if ((val = match(group, hdl)) == NULL) {
119 96 return;
120 97 }
121 98
122 99
123 100 /*
124 101 * check for cycles
125 102 */
126 103 for (ls = list; ls != NULL; ls = ls->nxt) {
127 104 if (strcmp(ls->name, group) == 0) {
128 105 (void) fprintf(stderr,
129 - "Cycle detected in /etc/netgroup: %s.\n",
130 - group);
106 + "Cycle detected in /etc/netgroup: %s.\n",
107 + group);
131 108 return;
132 109 }
133 110 }
134 111
135 112
136 113 ls = &tmplist;
137 114 ls->name = group;
138 115 ls->nxt = list;
139 116 list = ls;
140 117
141 118 p = val;
142 119 while (p != NULL) {
143 120 while (*p == ' ' || *p == '\t')
144 121 p++;
145 122 if (*p == EOS || *p == '#')
146 123 break;
147 124 if (*p == '(') {
148 125 gpls = MALLOC(struct grouplist);
149 126 p++;
↓ open down ↓ |
9 lines elided |
↑ open up ↑ |
150 127
151 128 if (!(p = fill(p, &gpls->gl_machine, ','))) {
152 129 goto syntax_error;
153 130 }
154 131 if (!(p = fill(p, &gpls->gl_name, ','))) {
155 132 goto syntax_error;
156 133 }
157 134 if (!(p = fill(p, &gpls->gl_domain, ')'))) {
158 135 goto syntax_error;
159 136 }
160 - gpls->gl_nxt = grouplist;
161 - grouplist = gpls;
137 + gpls->gl_nxt = hdl->grouplist;
138 + hdl->grouplist = gpls;
162 139 } else {
163 140 q = any(p, " \t\n#");
164 141 if (q && *q == '#')
165 142 break;
166 143 *q = EOS;
167 - doit(p, list);
144 + doit(p, list, hdl);
168 145 *q = ' ';
169 146 }
170 147 p = any(p, " \t");
171 148 }
172 149 return;
173 150
174 151 syntax_error:
175 152 (void) fprintf(stderr, "syntax error in /etc/netgroup\n");
176 153 (void) fprintf(stderr, "--- %s %s\n", group, val);
177 154 }
178 155
179 156
180 157
181 158
182 159 /*
183 160 * Fill a buffer "target" selectively from buffer "start".
184 161 * "termchar" terminates the information in start, and preceding
185 162 * or trailing white space is ignored. If the buffer "start" is
186 163 * empty, "target" is filled with "*". The location just after the
187 164 * terminating character is returned.
188 165 */
189 166 static char *
190 167 fill(start, target, termchar)
191 168 char *start;
192 169 char **target;
193 170 char termchar;
194 171 {
195 172 register char *p;
196 173 register char *q;
197 174 register char *r;
198 175 int size;
199 176
200 177 for (p = start; *p == ' ' || *p == '\t'; p++)
201 178 ;
202 179 r = strchr(p, termchar);
203 180 if (r == (char *)NULL) {
204 181 return ((char *)NULL);
205 182 }
206 183 if (p == r) {
207 184 *target = NULL;
208 185 } else {
209 186 for (q = r-1; *q == ' ' || *q == '\t'; q--)
210 187 ;
211 188 size = q-p+1;
212 189 STRNCPY(*target, p, size);
213 190 }
214 191 return (r+1);
215 192 }
216 193
217 194
218 195 /*
219 196 * scans cp, looking for a match with any character
220 197 * in match. Returns pointer to place in cp that matched
221 198 * (or NULL if no match)
222 199 */
223 200 static char *
224 201 any(cp, match)
225 202 register char *cp;
226 203 char *match;
227 204 {
228 205 register char *mp, c;
229 206
230 207 while (c = *cp) {
231 208 for (mp = match; *mp; mp++)
232 209 if (*mp == c)
233 210 return (cp);
234 211 cp++;
↓ open down ↓ |
57 lines elided |
↑ open up ↑ |
235 212 }
236 213 return (NULL);
237 214 }
238 215
239 216
240 217
241 218 /*
242 219 * The equivalent of yp_match. Returns the match, or NULL if there is none.
243 220 */
244 221 static char *
245 -match(group)
246 - char *group;
222 +match(char *group, revhandle_t *hdl)
247 223 {
248 - return (lookup(ngtable, group));
224 + return (lookup(hdl->ngtable, group));
249 225 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX