summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon J. Gerraty <sjg@FreeBSD.org>2013-09-05 20:18:59 +0000
committerSimon J. Gerraty <sjg@FreeBSD.org>2013-09-05 20:18:59 +0000
commit8613eacaa6abc1e5753f4c76020271b754142a8c (patch)
tree6053875a824db1a3674c454823309c169228ec1c
parentc218245f22206c1d67139e4c2b0dd95a65e19937 (diff)
parent091bc8dbca13a216899b00b61a856dc1bd345900 (diff)
downloadgetent-darwin-8613eacaa6abc1e5753f4c76020271b754142a8c.tar.gz
getent-darwin-8613eacaa6abc1e5753f4c76020271b754142a8c.tar.zst
getent-darwin-8613eacaa6abc1e5753f4c76020271b754142a8c.zip
Merge from head
-rw-r--r--getent.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/getent.c b/getent.c
index 7424577..89c58a2 100644
--- 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, },
@@ -571,6 +573,47 @@ shells(int argc, char *argv[])
}
/*
+ * 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
*/