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