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