Blob Blame History Raw
This file contains the reworked/backported sections from these two
upstream commits:

commit ae5c498d93d049d9574d3f8f18e62cac64cbdf5c
Author: DJ Delorie <dj@delorie.com>
Date:   Mon Jul 17 15:50:43 2017 -0400

    Extend NSS test suite

commit a3fe6a20bf81ef6a97a761dac9050517e7fd7a1f
Author: DJ Delorie <dj@redhat.com>
Date:   Thu Aug 17 17:58:25 2017 -0400

    Update nss tests to new skeleton
 
diff -Nrup a/nss/Makefile b/nss/Makefile
--- a/nss/Makefile	2019-07-29 22:25:16.482170120 -0400
+++ b/nss/Makefile	2019-07-29 22:37:05.675342258 -0400
@@ -38,8 +38,14 @@ install-bin             := getent makedb
 makedb-modules = xmalloc hash-string
 extra-objs		+= $(makedb-modules:=.o)
 
-tests			= test-netdb tst-nss-test1 bug17079 tst-nss-getpwent \
-			 test-digits-dots tst-nss-files-hosts-erange
+tests                  = test-netdb test-digits-dots tst-nss-getpwent bug17079 \
+			 tst-nss-files-hosts-erange \
+                         tst-nss-test1 \
+                         tst-nss-test2 \
+                         tst-nss-test3 \
+                         tst-nss-test4 \
+                         tst-nss-test5
+
 xtests			= bug-erange
 
 include ../Makeconfig
@@ -80,6 +86,8 @@ tests-static		= tst-nss-static
 tests			+= $(tests-static)
 endif
 
+extra-test-objs                += nss_test1.os nss_test2.os
+
 include ../Rules
 
 ifeq (yes,$(have-selinux))
@@ -107,13 +115,28 @@ $(objpfx)makedb: $(makedb-modules:%=$(ob
 $(inst_vardbdir)/Makefile: db-Makefile $(+force)
 	$(do-install)
 
+libnss_test1.so-no-z-defs = 1
+libnss_test2.so-no-z-defs = 1
+
+rtld-tests-LDFLAGS += -Wl,--dynamic-list=nss_test.ver
+
 libof-nss_test1 = extramodules
+libof-nss_test2 = extramodules
 $(objpfx)/libnss_test1.so: $(objpfx)nss_test1.os $(link-libc-deps)
 	$(build-module)
+$(objpfx)/libnss_test2.so: $(objpfx)nss_test2.os $(link-libc-deps)
+	$(build-module)
+$(objpfx)nss_test2.os : nss_test1.c
 ifdef libnss_test1.so-version
 $(objpfx)/libnss_test1.so$(libnss_test1.so-version): $(objpfx)/libnss_test1.so
 	$(make-link)
 endif
-$(objpfx)tst-nss-test1.out: $(objpfx)/libnss_test1.so$(libnss_test1.so-version)
+ifdef libnss_test2.so-version
+$(objpfx)/libnss_test2.so$(libnss_test2.so-version): $(objpfx)/libnss_test2.so
+	$(make-link)
+endif
+$(patsubst %,$(objpfx)%.out,$(tests)) : \
+	$(objpfx)/libnss_test1.so$(libnss_test1.so-version) \
+	$(objpfx)/libnss_test2.so$(libnss_test2.so-version)
 
 $(objpfx)tst-nss-files-hosts-erange: $(libdl)
diff -Nrup a/nss/tst-nss-getpwent.c b/nss/tst-nss-getpwent.c
--- a/nss/tst-nss-getpwent.c	2019-07-29 16:44:37.670904243 -0400
+++ b/nss/tst-nss-getpwent.c	2019-07-29 16:49:58.538313946 -0400
@@ -21,6 +21,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <support/support.h>
+
 int
 do_test (void)
 {
@@ -37,22 +39,12 @@ do_test (void)
     {
       if (first_name == NULL)
 	{
-	  first_name = strdup (pw->pw_name);
-	  if (first_name == NULL)
-	    {
-	      printf ("strdup: %m\n");
-	      return 1;
-	    }
+          first_name = xstrdup (pw->pw_name);
 	  first_uid = pw->pw_uid;
 	}
       
       free (last_name);
-      last_name = strdup (pw->pw_name);
-      if (last_name == NULL)
-	{
-	  printf ("strdup: %m\n");
-	  return 1;
-	}
+      last_name = xstrdup (pw->pw_name);
       last_uid = pw->pw_uid;
       ++count;
     }
@@ -112,5 +104,4 @@ do_test (void)
   return 0;
 }
 
-#define TEST_FUNCTION do_test ()
-#include "../test-skeleton.c"
+#include <support/test-driver.c>
diff -Nrup a/shlib-versions b/shlib-versions
--- a/shlib-versions	2019-07-29 16:50:46.222077613 -0400
+++ b/shlib-versions	2019-07-29 16:53:04.745391058 -0400
@@ -87,6 +87,7 @@ sh.*-.*-linux.*		ld=ld-linux.so.2	GLIBC_
 # Tests for NSS.  They must have the same NSS_SHLIB_REVISION number as
 # the rest.
 .*-.*-.*		libnss_test1=2
+.*-.*-.*                libnss_test2=2
 
 # Version for libnsl with YP and NIS+ functions.
 .*-.*-.*		libnsl=1
diff -Nrup a/nss/tst-nss-test1.c b/nss/tst-nss-test1.c
--- a/nss/tst-nss-test1.c	2019-07-29 16:54:05.824241220 -0400
+++ b/nss/tst-nss-test1.c	2019-07-29 17:13:55.696765720 -0400
@@ -1,9 +1,51 @@
+/* Basic test of passwd database handling.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
 #include <nss.h>
 #include <pwd.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
+#include <support/support.h>
+
+#include "nss_test.h"
+
+static int hook_called = 0;
+
+/* Note: the values chosen here are arbitrary; they need only be
+   unique within the table.  However, they do need to match the
+   "pwdids" array further down.  */
+static struct passwd pwd_table[] = {
+    PWD (100),
+    PWD (30),
+    PWD (200),
+    PWD (60),
+    PWD (20000),
+    PWD_LAST ()
+  };
+
+void
+_nss_test1_init_hook(test_tables *t)
+{
+  hook_called = 1;
+  t->pwd_table = pwd_table;
+}
 
 static int
 do_test (void)
@@ -12,20 +54,26 @@ do_test (void)
 
   __nss_configure_lookup ("passwd", "test1");
 
+  /* This must match the pwd_table above.  */
   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 %td wrong (%s, %u)\n",
-		np - pwdids, p->pw_name, p->pw_uid);
-	retval = 1;
-	break;
-      }
+    {
+      retval += compare_passwds (np-pwdids, p, & pwd_table[np-pwdids]);
+
+      if (p->pw_uid != *np || strncmp (p->pw_name, "name", 4) != 0
+         || atol (p->pw_name + 4) != *np)
+       {
+         printf ("FAIL: passwd entry %td wrong (%s, %u)\n",
+                 np - pwdids, p->pw_name, p->pw_uid);
+         retval = 1;
+         break;
+       }
+    }
 
   endpwent ();
 
@@ -37,14 +85,14 @@ do_test (void)
       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);
+          printf ("FAIL: 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]);
+          printf ("FAIL: passwd entry %u wrong\n", pwdids[i]);
 	  retval = 1;
 	}
 
@@ -53,20 +101,25 @@ do_test (void)
       p = getpwnam (buf);
       if (p != NULL)
 	{
-	  printf ("passwd entry \"%s\" wrong\n", buf);
+          printf ("FAIL: 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);
+          printf ("FAIL: passwd entry %u wrong\n", pwdids[i] + 1);
 	  retval = 1;
 	}
     }
 
+  if (!hook_called)
+    {
+      retval = 1;
+      printf("FAIL: init hook never called\n");
+    }
+
   return retval;
 }
 
-#define TEST_FUNCTION do_test ()
-#include "../test-skeleton.c"
+#include <support/test-driver.c>
diff -Nrup a/nss/test-netdb.c b/nss/test-netdb.c
--- a/nss/test-netdb.c	2019-07-30 15:31:30.468602060 -0400
+++ b/nss/test-netdb.c	2019-07-30 15:37:29.116601115 -0400
@@ -42,6 +42,8 @@
 #include <errno.h>
 #include "nss.h"
 
+#include <support/support.h>
+
 /*
   The following define is necessary for glibc 2.0.6
 */
@@ -179,7 +181,7 @@ test_hosts (void)
   while (gethostname (name, namelen) < 0 && errno == ENAMETOOLONG)
     {
       namelen += 2;		/* tiny increments to test a lot */
-      name = realloc (name, namelen);
+      name = xrealloc (name, namelen);
     }
   if (gethostname (name, namelen) == 0)
     {
@@ -377,5 +379,4 @@ do_test (void)
   return (error_count != 0);
 }
 
-#define TEST_FUNCTION do_test ()
-#include "../test-skeleton.c"
+#include <support/test-driver.c>