From: deraadt Date: Wed, 1 May 1996 13:32:21 +0000 (+0000) Subject: from netbsd: X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=1b9b1e5032ccd76ac84069df3bbe8ff0882eb015;p=openbsd from netbsd: - Fixed core-dump when key has no netgroups - added -d flag for debugging. - moved external functions to netgroup.h --- diff --git a/usr.sbin/netgroup_mkdb/netgroup_mkdb.c b/usr.sbin/netgroup_mkdb/netgroup_mkdb.c index 7bbdffeff83..c48c92c47cc 100644 --- a/usr.sbin/netgroup_mkdb/netgroup_mkdb.c +++ b/usr.sbin/netgroup_mkdb/netgroup_mkdb.c @@ -29,7 +29,7 @@ * SUCH DAMAGE. */ #ifndef lint -static char *rcsid = "$Id: netgroup_mkdb.c,v 1.1.1.1 1995/10/18 08:47:57 deraadt Exp $"; +static char *rcsid = "$Id: netgroup_mkdb.c,v 1.2 1996/05/01 13:32:21 deraadt Exp $"; #endif #include @@ -44,12 +44,15 @@ static char *rcsid = "$Id: netgroup_mkdb.c,v 1.1.1.1 1995/10/18 08:47:57 deraadt #include #include #include +#define _NETGROUP_PRIVATE #include #include #include "str.h" #include "util.h" +#define DEBUG_NG + #define NEW(a) (a *) emalloc(sizeof(a)) struct nentry { @@ -65,17 +68,6 @@ struct nentry { }; -struct stringlist; - -extern struct stringlist - *_ng_sl_init __P((void)); -extern void _ng_sl_add __P((struct stringlist *, char *)); -extern void _ng_sl_free __P((struct stringlist *, int)); -extern char *_ng_sl_find __P((struct stringlist *, char *)); - -extern char *_ng_makekey __P((const char *, const char *, size_t)); -extern int _ng_parse __P((char **, char **, struct netgroup **)); - static DB *ng_insert __P((DB *, const char *)); static void ng_reventry __P((DB *, DB *, struct nentry *, char *, size_t, struct stringlist *)); @@ -90,10 +82,12 @@ static void usage __P((void)); static void cleanup __P((void)); #ifdef DEBUG_NG +static int debug = 0; static void ng_dump __P((DB *)); static void ng_rdump __P((DB *)); #endif /* DEBUG_NG */ + static const char ng_empty[] = ""; #define NG_EMPTY(a) ((a) ? (a) : ng_empty) @@ -110,8 +104,13 @@ main(argc, argv) char *fname = _PATH_NETGROUP; - while ((ch = getopt(argc, argv, "o:")) != EOF) + while ((ch = getopt(argc, argv, "do:")) != EOF) switch (ch) { +#ifdef DEBUG_NG + case 'd': + debug++; + break; +#endif case 'o': dbname = optarg; break; @@ -135,22 +134,28 @@ main(argc, argv) /* Read and parse the netgroup file */ ndb = ng_load(fname); #ifdef DEBUG_NG - (void) fprintf(stderr, "#### Database\n"); - ng_dump(ndb); + if (debug) { + (void) fprintf(stderr, "#### Database\n"); + ng_dump(ndb); + } #endif /* Reverse the database by host */ hdb = ng_reverse(ndb, offsetof(struct netgroup, ng_host)); #ifdef DEBUG_NG - (void) fprintf(stderr, "#### Reverse by host\n"); - ng_rdump(hdb); + if (debug) { + (void) fprintf(stderr, "#### Reverse by host\n"); + ng_rdump(hdb); + } #endif /* Reverse the database by user */ udb = ng_reverse(ndb, offsetof(struct netgroup, ng_user)); #ifdef DEBUG_NG - (void) fprintf(stderr, "#### Reverse by user\n"); - ng_rdump(udb); + if (debug) { + (void) fprintf(stderr, "#### Reverse by user\n"); + ng_rdump(udb); + } #endif (void) snprintf(buf, sizeof(buf), "%s.tmp", dbname); @@ -264,8 +269,11 @@ ng_load(fname) break; case _NG_GROUP: - if (tail == NULL) - errx(1, "no netgroup key"); + if (tail == NULL) { + char fmt[BUFSIZ]; + _ng_print(fmt, sizeof(fmt), ng); + errx(1, "no netgroup key for %s", fmt); + } else { e = NEW(struct nentry); e->n_type = _NG_GROUP; @@ -470,6 +478,11 @@ ng_print(e, str) { char *ptr = emalloc(e->n_size); + if (e->n_next == NULL) { + str_append(str, "", ' '); + return; + } + for (e = e->n_next; e != NULL; e = e->n_next) { switch (e->n_type) { case _NG_NAME: