* 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 <sys/types.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
+#define _NETGROUP_PRIVATE
#include <netgroup.h>
#include <assert.h>
#include "str.h"
#include "util.h"
+#define DEBUG_NG
+
#define NEW(a) (a *) emalloc(sizeof(a))
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 *));
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)
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;
/* 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);
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;
{
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: