Deleted Added
full compact
getnetgrent.c (8870) getnetgrent.c (9287)
1/*
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Rick Macklem at The University of Guelph.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 178 unchanged lines hidden (view full) ---

187 */
188int
189innetgr(group, host, user, dom)
190 char *group, *host, *user, *dom;
191{
192 char *hst, *usr, *dm;
193
194 /* Sanity check */
1/*
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Rick Macklem at The University of Guelph.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 178 unchanged lines hidden (view full) ---

187 */
188int
189innetgr(group, host, user, dom)
190 char *group, *host, *user, *dom;
191{
192 char *hst, *usr, *dm;
193
194 /* Sanity check */
195
195
196 if (group == NULL || !strlen(group))
197 return (0);
198
199 setnetgrent(group);
200 while (getnetgrent(&hst, &usr, &dm))
201 if ((host == (char *)0 || !strcmp(host, hst)) &&
202 (user == (char *)0 || !strcmp(user, usr)) &&
203 (dom == (char *)0 || !strcmp(dom, dm))) {

--- 8 unchanged lines hidden (view full) ---

212 * Parse the netgroup file setting up the linked lists.
213 */
214static int
215parse_netgrp(group)
216 char *group;
217{
218 register char *spos, *epos;
219 register int len, strpos;
196 if (group == NULL || !strlen(group))
197 return (0);
198
199 setnetgrent(group);
200 while (getnetgrent(&hst, &usr, &dm))
201 if ((host == (char *)0 || !strcmp(host, hst)) &&
202 (user == (char *)0 || !strcmp(user, usr)) &&
203 (dom == (char *)0 || !strcmp(dom, dm))) {

--- 8 unchanged lines hidden (view full) ---

212 * Parse the netgroup file setting up the linked lists.
213 */
214static int
215parse_netgrp(group)
216 char *group;
217{
218 register char *spos, *epos;
219 register int len, strpos;
220#ifdef DEBUG
221 register int fields;
222#endif
220 char *pos, *gpos;
221 struct netgrp *grp;
222 struct linelist *lp = linehead;
223
224 /*
225 * First, see if the line has already been read in.
226 */
227 while (lp) {
228 if (!strcmp(group, lp->l_groupname))
229 break;
230 lp = lp->l_next;
231 }
232 if (lp == (struct linelist *)0 &&
233 (lp = read_for_group(group)) == (struct linelist *)0)
234 return (1);
235 if (lp->l_parsed) {
223 char *pos, *gpos;
224 struct netgrp *grp;
225 struct linelist *lp = linehead;
226
227 /*
228 * First, see if the line has already been read in.
229 */
230 while (lp) {
231 if (!strcmp(group, lp->l_groupname))
232 break;
233 lp = lp->l_next;
234 }
235 if (lp == (struct linelist *)0 &&
236 (lp = read_for_group(group)) == (struct linelist *)0)
237 return (1);
238 if (lp->l_parsed) {
239#ifdef DEBUG
240 /*
241 * This error message is largely superflous since the
242 * code handles the error condition sucessfully, and
243 * spewing it out from inside libc can actually hose
244 * certain programs.
245 */
236 fprintf(stderr, "Cycle in netgroup %s\n", lp->l_groupname);
246 fprintf(stderr, "Cycle in netgroup %s\n", lp->l_groupname);
247#endif
237 return (1);
238 } else
239 lp->l_parsed = 1;
240 pos = lp->l_line;
241 /* Watch for null pointer dereferences, dammit! */
242 while (pos != NULL && *pos != '\0') {
243 if (*pos == '(') {
244 grp = (struct netgrp *)malloc(sizeof (struct netgrp));
245 bzero((char *)grp, sizeof (struct netgrp));
246 grp->ng_next = grouphead.gr;
247 grouphead.gr = grp;
248 pos++;
249 gpos = strsep(&pos, ")");
248 return (1);
249 } else
250 lp->l_parsed = 1;
251 pos = lp->l_line;
252 /* Watch for null pointer dereferences, dammit! */
253 while (pos != NULL && *pos != '\0') {
254 if (*pos == '(') {
255 grp = (struct netgrp *)malloc(sizeof (struct netgrp));
256 bzero((char *)grp, sizeof (struct netgrp));
257 grp->ng_next = grouphead.gr;
258 grouphead.gr = grp;
259 pos++;
260 gpos = strsep(&pos, ")");
261#ifdef DEBUG
262 fields = 0;
263#endif
250 for (strpos = 0; strpos < 3; strpos++) {
251 if (spos = strsep(&gpos, ",")) {
264 for (strpos = 0; strpos < 3; strpos++) {
265 if (spos = strsep(&gpos, ",")) {
266#ifdef DEBUG
267 fields++;
268#endif
252 while (*spos == ' ' || *spos == '\t')
253 spos++;
254 if (epos = strpbrk(spos, " \t")) {
255 *epos = '\0';
256 len = epos - spos;
257 } else
258 len = strlen(spos);
259 if (len > 0) {
260 grp->ng_str[strpos] = (char *)
261 malloc(len + 1);
262 bcopy(spos, grp->ng_str[strpos],
263 len + 1);
264 }
269 while (*spos == ' ' || *spos == '\t')
270 spos++;
271 if (epos = strpbrk(spos, " \t")) {
272 *epos = '\0';
273 len = epos - spos;
274 } else
275 len = strlen(spos);
276 if (len > 0) {
277 grp->ng_str[strpos] = (char *)
278 malloc(len + 1);
279 bcopy(spos, grp->ng_str[strpos],
280 len + 1);
281 }
265 } else
266 goto errout;
282 } else {
283 /*
284 * All other systems I've tested
285 * return NULL for empty netgroup
286 * fields. It's up to user programs
287 * to handle the NULLs appropriately.
288 */
289 grp->ng_str[strpos] = NULL;
290 }
267 }
291 }
292#ifdef DEBUG
293 /*
294 * Note: on other platforms, malformed netgroup
295 * entries are not normally flagged. While we
296 * can catch bad entries and report them, we should
297 * stay silent by default for compatibility's sake.
298 */
299 if (fields < 3)
300 fprintf(stderr, "Bad entry (%s%s%s%s%s) in netgroup \"%s\"\n",
301 grp->ng_str[NG_HOST] == NULL ? "" : grp->ng_str[NG_HOST],
302 grp->ng_str[NG_USER] == NULL ? "" : ",",
303 grp->ng_str[NG_USER] == NULL ? "" : grp->ng_str[NG_USER],
304 grp->ng_str[NG_DOM] == NULL ? "" : ",",
305 grp->ng_str[NG_DOM] == NULL ? "" : grp->ng_str[NG_DOM],
306 lp->l_groupname);
307#endif
268 } else {
269 spos = strsep(&pos, ", \t");
270 if (parse_netgrp(spos))
271 continue;
272 }
273 /* Watch for null pointer dereferences, dammit! */
274 if (pos != NULL)
275 while (*pos == ' ' || *pos == ',' || *pos == '\t')
276 pos++;
277 }
278 return (0);
308 } else {
309 spos = strsep(&pos, ", \t");
310 if (parse_netgrp(spos))
311 continue;
312 }
313 /* Watch for null pointer dereferences, dammit! */
314 if (pos != NULL)
315 while (*pos == ' ' || *pos == ',' || *pos == '\t')
316 pos++;
317 }
318 return (0);
279errout:
280 fprintf(stderr, "Bad netgroup %s at ..%s\n", lp->l_groupname,
281 spos);
282 return (1);
283}
284
285/*
286 * Read the netgroup file and save lines until the line for the netgroup
287 * is found. Return 1 if eof is encountered.
288 */
289static struct linelist *
290read_for_group(group)

--- 102 unchanged lines hidden ---
319}
320
321/*
322 * Read the netgroup file and save lines until the line for the netgroup
323 * is found. Return 1 if eof is encountered.
324 */
325static struct linelist *
326read_for_group(group)

--- 102 unchanged lines hidden ---