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