From 8daa83a594a2e98f39d764422bfbdbc62c9efd44 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 19:20:00 +0200 Subject: Adding upstream version 2:4.20.0+dfsg. Signed-off-by: Daniel Baumann --- testsuite/nsswitch/getgrnam.c | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 testsuite/nsswitch/getgrnam.c (limited to 'testsuite/nsswitch/getgrnam.c') 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 +#include +#include + +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); +} -- cgit v1.2.3