/* * addgroup(): Recursively add all the members of the netgroup to this group */ static void addgroup(char *ypdom, struct stringlist *sl, char *grp) { char *line, *p; struct netgroup *ng; char *name; #ifdef DEBUG_NG (void) fprintf(stderr, "addgroup(%s)\n", grp); #endif /* check for cycles */ if (_ng_sl_find(sl, grp) != NULL) { _warnx("netgroup: Cycle in group `%s'", grp); free(grp); return; } if (_ng_sl_add(sl, grp) == -1) { free(grp); return; } /* Lookup this netgroup */ if (!lookup(ypdom, grp, &line, _NG_KEYBYNAME)) return; p = line; for (;;) { switch (_ng_parse(&p, &name, &ng)) { case _NG_NONE: /* Done with the line */ free(line); return; case _NG_GROUP: /* new netgroup */ /* add to the list */ ng->ng_next = _nglist; _nglist = ng; break; case _NG_NAME: /* netgroup name */ addgroup(ypdom, sl, name); break; case _NG_ERROR: return; } } }
/* * in_find(): Find a match for the host, user, domain spec */ static int in_find(char *ypdom, struct stringlist *sl, char *grp, const char *host, const char *user, const char *domain) { char *line, *p; int i; struct netgroup *ng; char *name; #ifdef DEBUG_NG (void) fprintf(stderr, "in_find(%s)\n", grp); #endif /* check for cycles */ if (_ng_sl_find(sl, grp) != NULL) { _warnx("netgroup: Cycle in group `%s'", grp); free(grp); return 0; } if (_ng_sl_add(sl, grp) == -1) { free(grp); return 0; } /* Lookup this netgroup */ if (!lookup(ypdom, grp, &line, _NG_KEYBYNAME)) return 0; p = line; for (;;) { switch (_ng_parse(&p, &name, &ng)) { case _NG_NONE: /* Done with the line */ free(line); return 0; case _NG_GROUP: /* new netgroup */ i = in_check(host, user, domain, ng); if (ng->ng_host != NULL) free(ng->ng_host); if (ng->ng_user != NULL) free(ng->ng_user); if (ng->ng_domain != NULL) free(ng->ng_domain); free(ng); if (i) { free(line); return 1; } break; case _NG_NAME: /* netgroup name */ if (in_find(ypdom, sl, name, host, user, domain)) { free(line); return 1; } break; case _NG_ERROR: free(line); return 0; } } }
extern char * getbsize(int *headerlenp, long *blocksizep) { static char header[20]; long n, max, mul, blocksize; char *ep, *p = getenv("BLOCKSIZE"), *form = ""; #define KB (1024) #define MB (1024 * 1024) #define GB (1024 * 1024 * 1024) #define MAXB GB /* No tera, peta, nor exa. */ if (p != NULL && *p != '\0') { if ((n = strtol(p, &ep, 10)) < 0) goto underflow; if (n == 0) n = 1; if (*ep && ep[1]) goto fmterr; switch (*ep) { case 'G': case 'g': form = "G"; max = MAXB / GB; mul = GB; break; case 'K': case 'k': form = "K"; max = MAXB / KB; mul = KB; break; case 'M': case 'm': form = "M"; max = MAXB / MB; mul = MB; break; case '\0': max = MAXB; mul = 1; break; default: fmterr: _warnx("%s: unknown blocksize", p); n = 512; max = MAXB; mul = 1; break; } if (n > max) { _warnx("maximum blocksize is %dG", MAXB / GB); n = max; } if ((blocksize = n * mul) < 512) { underflow: _warnx("%s: minimum blocksize is 512", p); form = ""; blocksize = n = 512; } } else blocksize = n = 512; *headerlenp = snprintf(header, sizeof(header), "%ld%s-blocks", n, form); if ((size_t)*headerlenp >= sizeof(header)) *headerlenp = sizeof(header) - 1; *blocksizep = blocksize; return (header); }