diff options
author | Arjun Shankar <arjun@redhat.com> | 2023-10-02 14:55:16 +0200 |
---|---|---|
committer | Arjun Shankar <arjun@redhat.com> | 2023-10-24 12:30:59 +0200 |
commit | 98b107e30848198e7128f80b38b406585f0317d6 (patch) | |
tree | 647f9ea8ec2d63136020411d6dcfef63cdfcf7ca /nss/tst-gshadow.c | |
parent | b121fdc552f392cd86b21f159dd3e3b998de91a3 (diff) | |
download | glibc-98b107e30848198e7128f80b38b406585f0317d6.tar.gz glibc-98b107e30848198e7128f80b38b406585f0317d6.tar.xz glibc-98b107e30848198e7128f80b38b406585f0317d6.zip |
Remove 'gshadow' and merge into 'nss'
The majority of gshadow routines are entry points for nss functionality. This commit removes the 'gshadow' subdirectory and moves all functionality and tests to 'nss'. References to gshadow/ are accordingly changed. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'nss/tst-gshadow.c')
-rw-r--r-- | nss/tst-gshadow.c | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/nss/tst-gshadow.c b/nss/tst-gshadow.c new file mode 100644 index 0000000000..8b469b723d --- /dev/null +++ b/nss/tst-gshadow.c @@ -0,0 +1,141 @@ +#include <gshadow.h> +#include <stdio.h> +#include <string.h> + + +static const struct sgrp data[] = + { + { (char *) "one", (char *) "pwdone", + (char *[]) { (char *) "admoneone", (char *) "admonetwo", + (char *) "admonethree", NULL }, + (char *[]) { (char *) "memoneone", (char *) "memonetwo", + (char *) "memonethree", NULL } }, + { (char *) "two", (char *) "pwdtwo", + (char *[]) { (char *) "admtwoone", (char *) "admtwotwo", NULL }, + (char *[]) { (char *) "memtwoone", (char *) "memtwotwo", + (char *) "memtwothree", NULL } }, + { (char *) "three", (char *) "pwdthree", + (char *[]) { (char *) "admthreeone", (char *) "admthreetwo", NULL }, + (char *[]) { (char *) "memthreeone", (char *) "memthreetwo", NULL } }, + { (char *) "four", (char *) "pwdfour", + (char *[]) { (char *) "admfourone", (char *) "admfourtwo", NULL }, + (char *[]) { NULL } }, + { (char *) "five", (char *) "pwdfive", + (char *[]) { NULL }, + (char *[]) { (char *) "memfiveone", (char *) "memfivetwo", NULL } }, + }; +#define ndata (sizeof (data) / sizeof (data[0])) + + +static int +do_test (void) +{ + FILE *fp = tmpfile (); + if (fp == NULL) + { + puts ("cannot open temporary file"); + return 1; + } + + for (size_t i = 0; i < ndata; ++i) + if (putsgent (&data[i], fp) != 0) + { + printf ("putsgent call %zu failed\n", i + 1); + return 1; + } + + rewind (fp); + + int result = 0; + int seen = -1; + struct sgrp *g; + while ((g = fgetsgent (fp)) != NULL) + { + ++seen; + if (strcmp (g->sg_namp, data[seen].sg_namp) != 0) + { + printf ("sg_namp of entry %d does not match: %s vs %s\n", + seen + 1, g->sg_namp, data[seen].sg_namp); + result = 1; + } + if (strcmp (g->sg_passwd, data[seen].sg_passwd) != 0) + { + printf ("sg_passwd of entry %d does not match: %s vs %s\n", + seen + 1, g->sg_passwd, data[seen].sg_passwd); + result = 1; + } + if (g->sg_adm == NULL) + { + printf ("sg_adm of entry %d is NULL\n", seen + 1); + result = 1; + } + else + { + int i = 1; + char **sp1 = g->sg_adm; + char **sp2 = data[seen].sg_adm; + while (*sp1 != NULL && *sp2 != NULL) + { + if (strcmp (*sp1, *sp2) != 0) + { + printf ("sg_adm[%d] of entry %d does not match: %s vs %s\n", + i, seen + 1, *sp1, *sp2); + result = 1; + } + ++sp1; + ++sp2; + ++i; + } + if (*sp1 == NULL && *sp2 != NULL) + { + printf ("sg_adm of entry %d has too few entries\n", seen + 1); + result = 1; + } + else if (*sp1 != NULL && *sp2 == NULL) + { + printf ("sg_adm of entry %d has too many entries\n", seen + 1); + result = 1; + } + } + if (g->sg_mem == NULL) + { + printf ("sg_mem of entry %d is NULL\n", seen + 1); + result = 1; + } + else + { + int i = 1; + char **sp1 = g->sg_mem; + char **sp2 = data[seen].sg_mem; + while (*sp1 != NULL && *sp2 != NULL) + { + if (strcmp (*sp1, *sp2) != 0) + { + printf ("sg_mem[%d] of entry %d does not match: %s vs %s\n", + i, seen + 1, *sp1, *sp2); + result = 1; + } + ++sp1; + ++sp2; + ++i; + } + if (*sp1 == NULL && *sp2 != NULL) + { + printf ("sg_mem of entry %d has too few entries\n", seen + 1); + result = 1; + } + else if (*sp1 != NULL && *sp2 == NULL) + { + printf ("sg_mem of entry %d has too many entries\n", seen + 1); + result = 1; + } + } + } + + fclose (fp); + + return result; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" |