Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/tests/testgr.c
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2006-10-11 15:34:15 +0200
committerArthur de Jong <arthur@arthurdejong.org>2006-10-11 15:34:15 +0200
commit6f17403298cf33747a45fb5ecbe78bf7632531f9 (patch)
treea5fc4cfdc3b091a0ee86f3c5c8d5e0ea8fc2c564 /tests/testgr.c
import release 251 of nss-ldap
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss_ldap-251@1 ef36b2f9-881f-0410-afb5-c4e39611909c
Diffstat (limited to 'tests/testgr.c')
-rw-r--r--tests/testgr.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/testgr.c b/tests/testgr.c
new file mode 100644
index 0000000..4907238
--- /dev/null
+++ b/tests/testgr.c
@@ -0,0 +1,71 @@
+#include <stdio.h>
+#include <grp.h>
+#include <signal.h>
+
+void
+main (int argc, char **argv)
+{
+#if 0
+ struct group
+ { /* see getgrent(3) */
+ char *gr_name;
+ char *gr_passwd;
+ gid_t gr_gid;
+ char **gr_mem;
+ };
+#endif
+
+ scan_group ();
+ exit (0);
+}
+
+void
+dump (struct group *g)
+{
+ char mem[2048];
+ char **p;
+
+ int doit = (g->gr_mem && *(g->gr_mem));
+ p = g->gr_mem;
+ strcpy (mem, "");
+ while (doit)
+ {
+ if (p != g->gr_mem)
+ strcat (mem, ",");
+ strcat (mem, *p);
+ if (*(++p) == NULL)
+ break;
+ }
+ printf ("%s:%s:%d:%s\n", g->gr_name, g->gr_passwd, g->gr_gid, mem);
+
+}
+
+scan_group ()
+{
+ struct group *g;
+
+ signal(SIGPIPE, SIG_IGN);
+
+ setgrent ();
+
+ while ((g = getgrent ()) != NULL)
+ {
+ dump (g);
+ }
+
+ endgrent ();
+
+ sleep(10);
+
+ printf ("==> getgrnam(qmail)\n");
+ g = getgrnam ("qmail");
+ if (g != NULL)
+ dump (g);
+#if 0
+ printf ("==> getgrnam(testgroup)\n");
+ g = getgrnam ("testgroup");
+ if (g != NULL)
+ dump (g);
+#endif
+
+}