]> git.cameronkatri.com Git - getent-darwin.git/blobdiff - getent.c
Makefile and reorganizing
[getent-darwin.git] / getent.c
index 74245773d69f6a553767477e5bc360b2b3763f64..c8a869a9453bd0c6de226ef5ddf4705475c5a80f 100644 (file)
--- a/getent.c
+++ b/getent.c
@@ -1,6 +1,8 @@
 /*     $NetBSD: getent.c,v 1.7 2005/08/24 14:31:02 ginsbach Exp $      */
 
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
@@ -39,7 +41,6 @@ __FBSDID("$FreeBSD$");
 #include <net/if.h>
 #include <netinet/if_ether.h>
 #include <netinet/in.h>                /* for INET6_ADDRSTRLEN */
-#include <rpc/rpcent.h>
 
 #include <assert.h>
 #include <ctype.h>
@@ -56,11 +57,16 @@ __FBSDID("$FreeBSD$");
 #include <unistd.h>
 #include <utmpx.h>
 
+#include <arpa/nameser_compat.h>
+#include "utmpx-defines.h"
+int setutxdb(int db, const char *file);
+
 static int     usage(void);
 static int     parsenum(const char *, unsigned long *);
 static int     ethers(int, char *[]);
 static int     group(int, char *[]);
 static int     hosts(int, char *[]);
+static int     netgroup(int, char *[]);
 static int     networks(int, char *[]);
 static int     passwd(int, char *[]);
 static int     protocols(int, char *[]);
@@ -83,6 +89,7 @@ static struct getentdb {
        {       "ethers",       ethers,         },
        {       "group",        group,          },
        {       "hosts",        hosts,          },
+       {       "netgroup",     netgroup,       },
        {       "networks",     networks,       },
        {       "passwd",       passwd,         },
        {       "protocols",    protocols,      },
@@ -570,6 +577,47 @@ shells(int argc, char *argv[])
        return rv;
 }
 
+/*
+ * netgroup
+ */
+static int
+netgroup(int argc, char *argv[])
+{
+       char            *host, *user, *domain;
+       int             first;
+       int             rv, i;
+
+       assert(argc > 1);
+       assert(argv != NULL);
+
+#define NETGROUPPRINT(s)       (((s) != NULL) ? (s) : "")
+
+       rv = RV_OK;
+       if (argc == 2) {
+               fprintf(stderr, "Enumeration not supported on netgroup\n");
+               rv = RV_NOENUM;
+       } else {
+               for (i = 2; i < argc; i++) {
+                       setnetgrent(argv[i]);
+                       first = 1;
+                       while (getnetgrent(&host, &user, &domain) != 0) {
+                               if (first) {
+                                       first = 0;
+                                       (void)fputs(argv[i], stdout);
+                               }
+                               (void)printf(" (%s,%s,%s)",
+                                   NETGROUPPRINT(host),
+                                   NETGROUPPRINT(user),
+                                   NETGROUPPRINT(domain));
+                       }
+                       if (!first)
+                               (void)putchar('\n');
+                       endnetgrent();
+               }
+       }
+       return rv;
+}
+
 /*
  * utmpx
  */