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/getgrnam.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/getgrnam.c')
-rw-r--r-- | testsuite/nsswitch/getgrnam.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/testsuite/nsswitch/getgrnam.c b/testsuite/nsswitch/getgrnam.c new file mode 100644 index 0000000..8ab4046 --- /dev/null +++ b/testsuite/nsswitch/getgrnam.c @@ -0,0 +1,51 @@ +/* + * Lookup a group by name + */ + +#include <stdio.h> +#include <grp.h> +#include <sys/types.h> + +int main(int argc, char **argv) +{ + struct group *gr; + + /* Check args */ + + if (argc != 2) { + printf("ERROR: no arg specified\n"); + exit(1); + } + + /* Do getgrnam() */ + + if ((gr = getgrnam(argv[1])) == NULL) { + printf("FAIL: group %s does not exist\n", argv[1]); + exit(1); + } + + /* Print group info */ + + printf("PASS: group %s exists\n", argv[1]); + printf("gr_name = %s\n", gr->gr_name); + printf("gr_passwd = %s\n", gr->gr_passwd); + printf("gr_gid = %d\n", gr->gr_gid); + + /* Group membership */ + + if (gr->gr_mem != NULL) { + int i = 0; + + printf("gr_mem = "); + while(gr->gr_mem[i] != NULL) { + printf("%s", gr->gr_mem[i]); + i++; + if (gr->gr_mem != NULL) { + printf(","); + } + } + printf("\n"); + } + + exit(0); +} |