aboutsummaryrefslogtreecommitdiff
path: root/nss/tst-nss-test1.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2010-08-11 07:25:02 -0700
committerUlrich Drepper <drepper@redhat.com>2010-08-11 07:25:02 -0700
commitc3e2f19bb995a0281f4cc56ad81bd67a5404dde6 (patch)
tree5bdbd8e1cb8119cd07cb48c60ef4f383c6b2d875 /nss/tst-nss-test1.c
parentf15ce4d8dc139523fe0c273580b604b2453acba6 (diff)
downloadglibc-c3e2f19bb995a0281f4cc56ad81bd67a5404dde6.tar
glibc-c3e2f19bb995a0281f4cc56ad81bd67a5404dde6.tar.gz
glibc-c3e2f19bb995a0281f4cc56ad81bd67a5404dde6.tar.bz2
glibc-c3e2f19bb995a0281f4cc56ad81bd67a5404dde6.zip
Add self-contained test for NSS.
While at it fix interaction between __nss_configure_lookup and nscd. Otherwise the test fails if nscd is runnung.
Diffstat (limited to 'nss/tst-nss-test1.c')
-rw-r--r--nss/tst-nss-test1.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/nss/tst-nss-test1.c b/nss/tst-nss-test1.c
new file mode 100644
index 0000000000..4e443d4539
--- /dev/null
+++ b/nss/tst-nss-test1.c
@@ -0,0 +1,72 @@
+#include <nss.h>
+#include <pwd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+static int
+do_test (void)
+{
+ int retval = 0;
+
+ __nss_configure_lookup ("passwd", "test1");
+
+ static const unsigned int pwdids[] = { 100, 30, 200, 60, 20000 };
+#define npwdids (sizeof (pwdids) / sizeof (pwdids[0]))
+ setpwent ();
+
+ const unsigned int *np = pwdids;
+ for (struct passwd *p = getpwent (); p != NULL; ++np, p = getpwent ())
+ if (p->pw_uid != *np || strncmp (p->pw_name, "name", 4) != 0
+ || atol (p->pw_name + 4) != *np)
+ {
+ printf ("passwd entry %ju wrong (%s, %u)\n",
+ np - pwdids, p->pw_name, p->pw_uid);
+ retval = 1;
+ break;
+ }
+
+ endpwent ();
+
+ for (int i = npwdids - 1; i >= 0; --i)
+ {
+ char buf[30];
+ snprintf (buf, sizeof (buf), "name%u", pwdids[i]);
+
+ struct passwd *p = getpwnam (buf);
+ if (p == NULL || p->pw_uid != pwdids[i] || strcmp (buf, p->pw_name) != 0)
+ {
+ printf ("passwd entry \"%s\" wrong\n", buf);
+ retval = 1;
+ }
+
+ p = getpwuid (pwdids[i]);
+ if (p == NULL || p->pw_uid != pwdids[i] || strcmp (buf, p->pw_name) != 0)
+ {
+ printf ("passwd entry %u wrong\n", pwdids[i]);
+ retval = 1;
+ }
+
+ snprintf (buf, sizeof (buf), "name%u", pwdids[i] + 1);
+
+ p = getpwnam (buf);
+ if (p != NULL)
+ {
+ printf ("passwd entry \"%s\" wrong\n", buf);
+ retval = 1;
+ }
+
+ p = getpwuid (pwdids[i] + 1);
+ if (p != NULL)
+ {
+ printf ("passwd entry %u wrong\n", pwdids[i] + 1);
+ retval = 1;
+ }
+ }
+
+ return retval;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"