]> git.cameronkatri.com Git - getent-darwin.git/commitdiff
Add support for netgroup, based on patch in the PR but made consistent
authorGuy Helmer <ghelmer@FreeBSD.org>
Thu, 23 May 2013 20:52:30 +0000 (20:52 +0000)
committerGuy Helmer <ghelmer@FreeBSD.org>
Thu, 23 May 2013 20:52:30 +0000 (20:52 +0000)
with existing style.

PR: bin/132692

getent.c

index 74245773d69f6a553767477e5bc360b2b3763f64..89c58a280c1673695677a96f80a1ba96eaacbd19 100644 (file)
--- a/getent.c
+++ b/getent.c
@@ -61,6 +61,7 @@ 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 *[]);
@@ -89,6 +90,7 @@ static struct getentdb {
        {       "rpc",          rpc,            },
        {       "services",     services,       },
        {       "shells",       shells,         },
+       {       "netgroup",     netgroup,       },
        {       "utmpx",        utmpx,          },
 
        {       NULL,           NULL,           },
@@ -570,6 +572,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
  */