diff options
author | Ulrich Drepper <drepper@redhat.com> | 2009-04-23 18:29:30 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2009-04-23 18:29:30 +0000 |
commit | 829fea46179b8d5cf25f8eae0b78550e3539ad60 (patch) | |
tree | 6f89526d907c86329565d6ebc825aaf7a32fa1d1 /gshadow/tst-gshadow.c | |
parent | 5497de87c94539c327c8341f3633b99d5b2dd674 (diff) | |
download | glibc-829fea46179b8d5cf25f8eae0b78550e3539ad60.tar.gz glibc-829fea46179b8d5cf25f8eae0b78550e3539ad60.tar.xz glibc-829fea46179b8d5cf25f8eae0b78550e3539ad60.zip |
[BZ #9955]
2009-04-23 Ulrich Drepper <drepper@redhat.com> [BZ #9955] * gshadow/Makefile: New file. * gshadow/Versions: New file. * gshadow/fgetsgent.c: New file. * gshadow/fgetsgent_r.c: New file. * gshadow/getsgent.c: New file. * gshadow/getsgent_r.c: New file. * gshadow/getsgnam.c: New file. * gshadow/getsgnam_r.c: New file. * gshadow/gshadow.h: New file. * gshadow/putsgent.c: New file. * gshadow/sgetsgent.c: New file. * gshadow/sgetsgent_r.c: New file. * gshadow/tst-gshadow.c: New file. * include/gshadow.h: New file. * Makeconfig (all-subdirs): Add gshadow. * Makefile (installed-headers): Add gshadow/gshadow.h. * nss/Makefile (databases): Add sgrp. * nss/Versions: Add gshadow functions as private exports. * nss/nsswitch.conf: Add gshadow entry. * nss/sgrp-lookup.c: New file. * nss/nss_files/files-parse.c: Add STRING_LIST macro. Rewrite parse_list to handle STRING_LIST and TRAILING_LIST_PARSER. * nss/nss_files/files-sgrp.c: New file. * sysdeps/generic/paths.h: Add _PATH_GSHADOW. * sysdeps/unix/sysv/linux/paths.h: Likewise.
Diffstat (limited to 'gshadow/tst-gshadow.c')
-rw-r--r-- | gshadow/tst-gshadow.c | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/gshadow/tst-gshadow.c b/gshadow/tst-gshadow.c new file mode 100644 index 0000000000..8c26a486a7 --- /dev/null +++ b/gshadow/tst-gshadow.c @@ -0,0 +1,138 @@ +#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])) + + +int +main (void) +{ + FILE *fp = fopen ("/tmp/aaa", "w+");//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; +} |