diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 17:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 17:47:29 +0000 |
commit | 4f5791ebd03eaec1c7da0865a383175b05102712 (patch) | |
tree | 8ce7b00f7a76baa386372422adebbe64510812d4 /testsuite/nsswitch/getgrnam.c | |
parent | Initial commit. (diff) | |
download | samba-4f5791ebd03eaec1c7da0865a383175b05102712.tar.xz samba-4f5791ebd03eaec1c7da0865a383175b05102712.zip |
Adding upstream version 2:4.17.12+dfsg.upstream/2%4.17.12+dfsgupstream
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); +} |