diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 17:20:00 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 17:20:00 +0000 |
commit | 8daa83a594a2e98f39d764422bfbdbc62c9efd44 (patch) | |
tree | 4099e8021376c7d8c05bdf8503093d80e9c7bad0 /testsuite/nsswitch/initgroups.c | |
parent | Initial commit. (diff) | |
download | samba-8daa83a594a2e98f39d764422bfbdbc62c9efd44.tar.xz samba-8daa83a594a2e98f39d764422bfbdbc62c9efd44.zip |
Adding upstream version 2:4.20.0+dfsg.upstream/2%4.20.0+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testsuite/nsswitch/initgroups.c')
-rw-r--r-- | testsuite/nsswitch/initgroups.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/testsuite/nsswitch/initgroups.c b/testsuite/nsswitch/initgroups.c new file mode 100644 index 0000000..b7d9c50 --- /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; +} |