Netgroups.
[profile.git] / src / netgroups.c
diff --git a/src/netgroups.c b/src/netgroups.c
new file mode 100644 (file)
index 0000000..0a3dd77
--- /dev/null
@@ -0,0 +1,27 @@
+#include <netdb.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char **argv) {
+  char *group, *host, *hostp, *userp, *domainp;
+
+  if (argc == 1) {
+    fprintf(stderr, "Usage: netgroups <netgroup> [<hostname>]\n");
+    exit(1);
+  }
+
+  /* What group do we want? */
+  group = argv[1];
+  if (*group == '@') group++;
+
+  /* Do we want to match a host? */
+  host = argv[2];
+
+  if (host) exit(! innetgr(group, host, 0, 0));
+
+  setnetgrent(group);
+  while (getnetgrent(&hostp, &userp, &domainp)) printf("%s\n", hostp);
+  endnetgrent();
+
+  exit(0);
+}