summaryrefslogtreecommitdiff
path: root/testsuite/nsswitch/initgroups.c
diff options
context:
space:
mode:
authorTim Potter <tpot@samba.org>2001-05-09 04:59:49 +0000
committerTim Potter <tpot@samba.org>2001-05-09 04:59:49 +0000
commitdcc39ea43984fe9f9c683e48423794793a923e28 (patch)
treecfccda702e3f50fa6da408c42937f1007abee49e /testsuite/nsswitch/initgroups.c
parent9de17c5c3892930d6d1d349df63e2c4206787ceb (diff)
downloadsamba-dcc39ea43984fe9f9c683e48423794793a923e28.tar.gz
samba-dcc39ea43984fe9f9c683e48423794793a923e28.tar.bz2
samba-dcc39ea43984fe9f9c683e48423794793a923e28.zip
Cleaned up bitrot in nsswitch testsuite. Merged tests across from TNG
branch. (This used to be commit acef477383e5739292e764c17cef87822a09f13b)
Diffstat (limited to 'testsuite/nsswitch/initgroups.c')
-rw-r--r--testsuite/nsswitch/initgroups.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/testsuite/nsswitch/initgroups.c b/testsuite/nsswitch/initgroups.c
new file mode 100644
index 0000000000..b7d9c50eaa
--- /dev/null
+++ b/testsuite/nsswitch/initgroups.c
@@ -0,0 +1,42 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <grp.h>
+#include <pwd.h>
+#include <sys/types.h>
+
+int main(int argc, char **argv)
+{
+ int result, ngroups, i;
+ gid_t *groups;
+ struct passwd *pw;
+
+ if (!(pw = getpwnam(argv[1]))) {
+ printf("FAIL: no passwd entry for %s\n", argv[1]);
+ return 1;
+ }
+
+ result = initgroups(argv[1], pw->pw_gid);
+
+ if (result == -1) {
+ printf("FAIL");
+ return 1;
+ }
+
+ ngroups = getgroups(0, NULL);
+
+ groups = (gid_t *)malloc(sizeof(gid_t) * ngroups);
+ ngroups = getgroups(ngroups, groups);
+
+ printf("%s is a member of groups:\n", argv[1]);
+
+ for (i = 0; i < ngroups; i++) {
+ struct group *grp;
+
+ grp = getgrgid(groups[i]);
+
+ printf("%d (%s)\n", groups[i], grp ? grp->gr_name : "?");
+ }
+
+ printf("PASS\n");
+ return 0;
+}