about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog39
-rw-r--r--NEWS9
-rw-r--r--config.h.in3
-rw-r--r--config.make.in1
-rwxr-xr-xconfigure20
-rw-r--r--configure.in14
-rw-r--r--grp/Makefile6
-rw-r--r--inet/Makefile8
-rw-r--r--inet/getnetgrent_r.c41
-rw-r--r--nscd/Makefile6
-rw-r--r--nscd/nscd.c2
-rw-r--r--nss/nss_db/db-init.c4
-rw-r--r--nss/nss_files/files-init.c6
-rw-r--r--nss/nsswitch.c10
-rw-r--r--posix/Makefile2
-rw-r--r--pwd/Makefile2
-rw-r--r--sysdeps/unix/sysv/linux/check_pf.c38
17 files changed, 163 insertions, 48 deletions
diff --git a/ChangeLog b/ChangeLog
index 8e64d803d2..291a57b867 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,42 @@
+2012-08-22  Roland McGrath  <roland@hack.frob.com>
+
+	[BZ# 13696]
+	* configure.in (use_nscd): New substituted variable, set by
+	--disable-nscd.  If enabled, define USE_NSCD.
+	* configure: Regenerated.
+	* config.h.in: Add USE_NSCD.
+	* config.make.in (use-nscd): New substituted variable.
+	* inet/Makefile (CFLAGS-gethstbyad_r.c): Likewise.
+	(CFLAGS-gethstbynm_r.c, CFLAGS-gethstbynm2_r.c): Likewise.
+	(CFLAGS-getsrvbynm_r.c, CFLAGS-getsrvbypt_r.c): Variables removed.
+	* grp/Makefile (CFLAGS-getgrgid_r.c): Remove -DUSE_NSCD.
+	(CFLAGS-getgrnam_r.c): Likewise.
+	(CFLAGS-initgroups.c): Likewise.
+	* posix/Makefile (CFLAGS-getaddrinfo.c): Remove -DUSE_NSCD.
+	* pwd/Makefile (CFLAGS-getpwuid_r.c, CFLAGS-getpwnam_r.c):
+	Variables removed.
+	* inet/getnetgrent_r.c
+	(nscd_setnetgrent): New function, broken out of ...
+	(setnetgrent): ... here.  Call it.
+	(innetgr): Conditionalize nscd bits on [USE_NSCD].
+	(nscd_getnetgrent): Conditionalize on [USE_NSCD].
+	(__internal_getnetgrent_r): Conditionalize its use on [USE_NSCD].
+	* nscd/Makefile (routines, aux): Move definitions after include of
+	Makeconfig.  Conditionalize on [$(use-nscd) != no].
+	* nss/nsswitch.c (nss_load_all_libraries, __nss_disable_nscd):
+	Conditionalize on [USE_NSCD].
+	(is_nscd, nscd_init_cb): Likewise.
+	(nss_load_library): Conditionalize init callback on [USE_NSCD].
+	* nss/nss_files/files-init.c: Conditionalize body on [USE_NSCD].
+	* nss/nss_db/db-init.c: Likewise.
+	* nscd/nscd.c (main): Conditionalize __nss_disable_nscd call on
+	[USE_NSCD].
+	* sysdeps/unix/sysv/linux/check_pf.c (get_nl_timestamp): New function.
+	(make_request): Use it.
+	(cache_valid_p): New function.
+	(__check_pf): Use it.
+	* NEWS: Add item for --disable-nscd.
+
 2012-08-22  Dmitry V. Levin  <ldv@altlinux.org>
 
 	* configure.in (SED): Update AC_CHECK_PROG_VER's version extract regexp
diff --git a/NEWS b/NEWS
index ff9174cbde..63768398f6 100644
--- a/NEWS
+++ b/NEWS
@@ -9,9 +9,9 @@ Version 2.17
 
 * The following bugs are resolved with this release:
 
-  6778, 6808, 9685, 11607, 13717, 13939, 14042, 14090, 14166, 14150, 14151,
-  14154, 14157, 14166, 14173, 14195, 14252, 14283, 14298, 14303, 14307,
-  14328, 14331, 14336, 14337, 14347, 14349, 14505
+  6778, 6808, 9685, 11607, 13717, 13696, 13939, 14042, 14090, 14166, 14150,
+  14151, 14154, 14157, 14166, 14173, 14195, 14252, 14283, 14298, 14303,
+  14307, 14328, 14331, 14336, 14337, 14347, 14349, 14505
 
 * Support for STT_GNU_IFUNC symbols added for s390 and s390x.
   Optimized versions of memcpy, memset, and memcmp added for System z10 and
@@ -34,6 +34,9 @@ Version 2.17
 * Optimizations of string functions memchr, wcschr, wcscpy, and wcsrchr for
   powerpc POWER7.  Implemented by Will Schmidt.
 
+* New configure option --disable-nscd builds the C library such that it
+  never attempts to contact the Name Service Caching Daemon (nscd).
+
 
 Version 2.16
 
diff --git a/config.h.in b/config.h.in
index e27e86d428..10a9925767 100644
--- a/config.h.in
+++ b/config.h.in
@@ -174,6 +174,9 @@
 /* Define if Systemtap <sys/sdt.h> probes should be defined.  */
 #undef USE_STAP_PROBE
 
+/* Define if library functions should try to contact the nscd daemon.  */
+#undef USE_NSCD
+
 /*
  */
 
diff --git a/config.make.in b/config.make.in
index c511554334..bbb5caca37 100644
--- a/config.make.in
+++ b/config.make.in
@@ -100,6 +100,7 @@ sysdeps-add-ons = @sysdeps_add_ons@
 cross-compiling = @cross_compiling@
 force-install = @force_install@
 link-obsolete-rpc = @link_obsolete_rpc@
+use-nscd = @use_nscd@
 
 # Build tools.
 CC = @CC@
diff --git a/configure b/configure
index a573bfec00..6301a1b3d9 100755
--- a/configure
+++ b/configure
@@ -597,6 +597,7 @@ libc_cv_sysconfdir
 libc_cv_localedir
 libc_cv_slibdir
 old_glibc_headers
+use_nscd
 libc_cv_gcc_unwind_find_fde
 libc_extra_cflags
 CPPUNDEFS
@@ -750,6 +751,7 @@ enable_multi_arch
 enable_nss_crypt
 enable_obsolete_rpc
 enable_systemtap
+enable_nscd
 with_cpu
 '
       ac_precious_vars='build_alias
@@ -1408,6 +1410,7 @@ Optional Features:
   --enable-obsolete-rpc   build and install the obsolete RPC code for
                           link-time usage
   --enable-systemtap      enable systemtap static probe points [default=no]
+  --disable-nscd          library functions will not contact the nscd daemon
 
 Optional Packages:
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
@@ -3753,6 +3756,15 @@ See \`config.log' for more details" "$LINENO" 5; }
   fi
 fi
 
+# Note the use of $use_nscd is near the bottom of the file.
+# Check whether --enable-nscd was given.
+if test "${enable_nscd+set}" = set; then :
+  enableval=$enable_nscd; use_nscd=$enableval
+else
+  use_nscd=yes
+fi
+
+
 # The way shlib-versions is used to generate soversions.mk uses a
 # fairly simplistic model for name recognition that can't distinguish
 # i486-pc-linux-gnu fully from i486-pc-gnu.  So we mutate a $host_os
@@ -7404,6 +7416,14 @@ if test x$libc_cv_gcc_unwind_find_fde = xyes; then
 fi
 
 
+# This is far from the AC_ARG_ENABLE that sets it so that a sysdeps
+# configure fragment can override the value to prevent this AC_DEFINE.
+
+if test "x$use_nscd" != xno; then
+  $as_echo "#define USE_NSCD 1" >>confdefs.h
+
+fi
+
 # Test for old glibc 2.0.x headers so that they can be removed properly
 # Search only in includedir.
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for old glibc 2.0.x headers" >&5
diff --git a/configure.in b/configure.in
index 1b05c87233..a5ce139de4 100644
--- a/configure.in
+++ b/configure.in
@@ -293,6 +293,13 @@ void foo (int i, void *p)
   fi
 fi
 
+# Note the use of $use_nscd is near the bottom of the file.
+AC_ARG_ENABLE([nscd],
+	      [AS_HELP_STRING([--disable-nscd],
+	       [library functions will not contact the nscd daemon])],
+	      [use_nscd=$enableval],
+	      [use_nscd=yes])
+
 # The way shlib-versions is used to generate soversions.mk uses a
 # fairly simplistic model for name recognition that can't distinguish
 # i486-pc-linux-gnu fully from i486-pc-gnu.  So we mutate a $host_os
@@ -2099,6 +2106,13 @@ if test x$libc_cv_gcc_unwind_find_fde = xyes; then
 fi
 AC_SUBST(libc_cv_gcc_unwind_find_fde)
 
+# This is far from the AC_ARG_ENABLE that sets it so that a sysdeps
+# configure fragment can override the value to prevent this AC_DEFINE.
+AC_SUBST(use_nscd)
+if test "x$use_nscd" != xno; then
+  AC_DEFINE([USE_NSCD])
+fi
+
 # Test for old glibc 2.0.x headers so that they can be removed properly
 # Search only in includedir.
 AC_MSG_CHECKING(for old glibc 2.0.x headers)
diff --git a/grp/Makefile b/grp/Makefile
index 384faa062f..ca620603f2 100644
--- a/grp/Makefile
+++ b/grp/Makefile
@@ -38,14 +38,14 @@ include ../Rules
 
 ifeq ($(have-thread-library),yes)
 
-CFLAGS-getgrgid_r.c = -DUSE_NSCD=1 -fexceptions
-CFLAGS-getgrnam_r.c = -DUSE_NSCD=1 -fexceptions
+CFLAGS-getgrgid_r.c = -fexceptions
+CFLAGS-getgrnam_r.c = -fexceptions
 CFLAGS-getgrent_r.c = -fexceptions
 CFLAGS-getgrent.c = -fexceptions
 CFLAGS-fgetgrent.c = -fexceptions
 CFLAGS-fgetgrent_r.c = -fexceptions $(libio-mtsafe)
 CFLAGS-putgrent.c = -fexceptions $(libio-mtsafe)
-CFLAGS-initgroups.c = -DUSE_NSCD=1 -fexceptions
+CFLAGS-initgroups.c = -fexceptions
 CFLAGS-getgrgid.c = -fexceptions
 
 endif
diff --git a/inet/Makefile b/inet/Makefile
index 80e2d7ab2e..1af5dc70d1 100644
--- a/inet/Makefile
+++ b/inet/Makefile
@@ -56,11 +56,11 @@ include ../Rules
 
 ifeq ($(have-thread-library),yes)
 
-CFLAGS-gethstbyad_r.c = -DUSE_NSCD=1 -fexceptions
+CFLAGS-gethstbyad_r.c = -fexceptions
 CFLAGS-gethstbyad.c = -fexceptions
-CFLAGS-gethstbynm_r.c = -DUSE_NSCD=1 -fexceptions
+CFLAGS-gethstbynm_r.c = -fexceptions
 CFLAGS-gethstbynm.c = -fexceptions
-CFLAGS-gethstbynm2_r.c = -DUSE_NSCD=1 -fexceptions
+CFLAGS-gethstbynm2_r.c = -fexceptions
 CFLAGS-gethstbynm2.c = -fexceptions
 CFLAGS-gethstent_r.c = -fexceptions
 CFLAGS-gethstent.c = -fexceptions
@@ -77,8 +77,6 @@ CFLAGS-getrpcent_r.c = -fexceptions
 CFLAGS-getrpcent.c = -fexceptions
 CFLAGS-getservent_r.c = -fexceptions
 CFLAGS-getservent.c = -fexceptions
-CFLAGS-getsrvbynm_r.c = -DUSE_NSCD=1
-CFLAGS-getsrvbypt_r.c = -DUSE_NSCD=1
 CFLAGS-getprtent_r.c = -fexceptions
 CFLAGS-getprtent.c = -fexceptions
 CFLAGS-either_ntoh.c = -fexceptions
diff --git a/inet/getnetgrent_r.c b/inet/getnetgrent_r.c
index c57e7de178..8e69ec7b11 100644
--- a/inet/getnetgrent_r.c
+++ b/inet/getnetgrent_r.c
@@ -182,28 +182,32 @@ __internal_setnetgrent (const char *group, struct __netgrent *datap)
 }
 libc_hidden_def (__internal_setnetgrent)
 
-int
-setnetgrent (const char *group)
+static int
+nscd_setnetgrent (const char *group)
 {
-  int result;
-
-  __libc_lock_lock (lock);
-
+#ifdef USE_NSCD
   if (__nss_not_use_nscd_netgroup > 0
       && ++__nss_not_use_nscd_netgroup > NSS_NSCD_RETRY)
     __nss_not_use_nscd_netgroup = 0;
 
   if (!__nss_not_use_nscd_netgroup
       && !__nss_database_custom[NSS_DBSIDX_netgroup])
-    {
-      result = __nscd_setnetgrent (group, &dataset);
-      if (result >= 0)
-	goto out;
-    }
+    return __nscd_setnetgrent (group, &dataset);
+#endif
+  return -1;
+}
 
-  result = __internal_setnetgrent (group, &dataset);
+int
+setnetgrent (const char *group)
+{
+  int result;
+
+  __libc_lock_lock (lock);
+
+  result = nscd_setnetgrent (group);
+  if (result < 0)
+    result = __internal_setnetgrent (group, &dataset);
 
- out:
   __libc_lock_unlock (lock);
 
   return result;
@@ -230,7 +234,7 @@ endnetgrent (void)
   __libc_lock_unlock (lock);
 }
 
-
+#ifdef USE_NSCD
 static enum nss_status
 nscd_getnetgrent (struct __netgrent *datap, char *buffer, size_t buflen,
 		  int *errnop)
@@ -248,7 +252,7 @@ nscd_getnetgrent (struct __netgrent *datap, char *buffer, size_t buflen,
 
   return NSS_STATUS_SUCCESS;
 }
-
+#endif
 
 int
 internal_function
@@ -267,9 +271,14 @@ __internal_getnetgrent_r (char **hostp, char **userp, char **domainp,
   int no_more = datap->nip == NULL;
   if (! no_more)
     {
+#ifdef USE_NSCD
+      /* This bogus function pointer is a special marker left by
+         __nscd_setnetgrent to tell us to use the data it left
+         before considering any modules.  */
       if (datap->nip == (service_user *) -1l)
 	fct = nscd_getnetgrent;
       else
+#endif
 	{
 	  fct = __nss_lookup_function (datap->nip, "getnetgrent_r");
 	  no_more = fct == NULL;
@@ -375,6 +384,7 @@ int
 innetgr (const char *netgroup, const char *host, const char *user,
 	 const char *domain)
 {
+#ifdef USE_NSCD
   if (__nss_not_use_nscd_netgroup > 0
       && ++__nss_not_use_nscd_netgroup > NSS_NSCD_RETRY)
     __nss_not_use_nscd_netgroup = 0;
@@ -386,6 +396,7 @@ innetgr (const char *netgroup, const char *host, const char *user,
       if (result >= 0)
 	return result;
     }
+#endif
 
   union
   {
diff --git a/nscd/Makefile b/nscd/Makefile
index ba052eb9de..de26f06c05 100644
--- a/nscd/Makefile
+++ b/nscd/Makefile
@@ -20,11 +20,13 @@
 #
 subdir	:= nscd
 
+include ../Makeconfig
+
+ifneq ($(use-nscd),no)
 routines := nscd_getpw_r nscd_getgr_r nscd_gethst_r nscd_getai \
 	    nscd_initgroups nscd_getserv_r nscd_netgroup
 aux	:= nscd_helper
-
-include ../Makeconfig
+endif
 
 # To find xmalloc.c
 vpath %.c ../locale/programs
diff --git a/nscd/nscd.c b/nscd/nscd.c
index 79fb32f327..bee9ed49ff 100644
--- a/nscd/nscd.c
+++ b/nscd/nscd.c
@@ -305,8 +305,10 @@ main (int argc, char **argv)
 # endif
 #endif
 
+#ifdef USE_NSCD
   /* Make sure we do not get recursive calls.  */
   __nss_disable_nscd (register_traced_file);
+#endif
 
   /* Init databases.  */
   nscd_init ();
diff --git a/nss/nss_db/db-init.c b/nss/nss_db/db-init.c
index d23e8f81d6..26508c2ca9 100644
--- a/nss/nss_db/db-init.c
+++ b/nss/nss_db/db-init.c
@@ -16,6 +16,8 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifdef USE_NSCD
+
 #include <paths.h>
 #include <nscd/nscd.h>
 #include <string.h>
@@ -51,3 +53,5 @@ _nss_db_init (void (*cb) (size_t, struct traced_file *))
   strcpy (serv_traced_file.file.fname, _PATH_VARDB "services.db");
   cb (servdb, &serv_traced_file.file);
 }
+
+#endif
diff --git a/nss/nss_files/files-init.c b/nss/nss_files/files-init.c
index 18757cb25b..d58bd82239 100644
--- a/nss/nss_files/files-init.c
+++ b/nss/nss_files/files-init.c
@@ -1,5 +1,5 @@
 /* Initialization in nss_files module.
-   Copyright (C) 2011 Free Software Foundation, Inc.
+   Copyright (C) 2011-2012 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
@@ -16,6 +16,8 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifdef USE_NSCD
+
 #include <nscd/nscd.h>
 
 
@@ -55,3 +57,5 @@ _nss_files_init (void (*cb) (size_t, struct traced_file *))
 
   cb (netgrdb, &netgr_traced_file.file);
 }
+
+#endif
diff --git a/nss/nsswitch.c b/nss/nsswitch.c
index a2628c747c..750cd02ab0 100644
--- a/nss/nsswitch.c
+++ b/nss/nsswitch.c
@@ -92,10 +92,12 @@ static name_database *service_table;
 static name_database_entry *defconfig_entries;
 
 
+#ifdef USE_NSCD
 /* Nonzero if this is the nscd process.  */
 static bool is_nscd;
 /* The callback passed to the init functions when nscd is used.  */
 static void (*nscd_init_cb) (size_t, struct traced_file *);
+#endif
 
 
 /* -1 == database not found
@@ -358,6 +360,7 @@ nss_load_library (service_user *ni)
 	  ni->library->lib_handle = (void *) -1l;
 	  __set_errno (saved_errno);
 	}
+# ifdef USE_NSCD
       else if (is_nscd)
 	{
 	  /* Call the init function when nscd is used.  */
@@ -377,12 +380,13 @@ nss_load_library (service_user *ni)
 	  if (ifct != NULL)
 	    {
 	      void (*cb) (size_t, struct traced_file *) = nscd_init_cb;
-# ifdef PTR_DEMANGLE
+#  ifdef PTR_DEMANGLE
 	      PTR_DEMANGLE (cb);
-# endif
+#  endif
 	      ifct (cb);
 	    }
 	}
+# endif
     }
 
   return 0;
@@ -808,7 +812,7 @@ nss_new_service (name_database *database, const char *name)
 }
 
 
-#ifdef SHARED
+#if defined SHARED && defined USE_NSCD
 /* Load all libraries for the service.  */
 static void
 nss_load_all_libraries (const char *service, const char *def)
diff --git a/posix/Makefile b/posix/Makefile
index 922f9c0884..3560bb2c30 100644
--- a/posix/Makefile
+++ b/posix/Makefile
@@ -134,7 +134,7 @@ $(objpfx)config-name.h: $(..)scripts/config-uname.sh $(common-objpfx)config.make
 	mv -f $@.new $@
 
 CFLAGS-regex.c = -Wno-strict-prototypes
-CFLAGS-getaddrinfo.c = -DRESOLVER -fexceptions -DUSE_NSCD
+CFLAGS-getaddrinfo.c = -DRESOLVER -fexceptions
 CFLAGS-pread.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-pread64.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-pwrite.c = -fexceptions -fasynchronous-unwind-tables
diff --git a/pwd/Makefile b/pwd/Makefile
index 52a917f55d..ec06c8e94d 100644
--- a/pwd/Makefile
+++ b/pwd/Makefile
@@ -31,8 +31,6 @@ include ../Rules
 
 ifeq ($(have-thread-library),yes)
 
-CFLAGS-getpwuid_r.c = -DUSE_NSCD=1
-CFLAGS-getpwnam_r.c = -DUSE_NSCD=1
 CFLAGS-getpwent_r.c = -fexceptions
 CFLAGS-getpwent.c = -fexceptions
 CFLAGS-getpw.c = -fexceptions
diff --git a/sysdeps/unix/sysv/linux/check_pf.c b/sysdeps/unix/sysv/linux/check_pf.c
index 950498acd4..eebb3a4839 100644
--- a/sysdeps/unix/sysv/linux/check_pf.c
+++ b/sysdeps/unix/sysv/linux/check_pf.c
@@ -78,6 +78,29 @@ __bump_nl_timestamp (void)
 }
 #endif
 
+static inline uint32_t
+get_nl_timestamp (void)
+{
+#ifdef IS_IN_nscd
+  return nl_timestamp;
+#elif defined USE_NSCD
+  return __nscd_get_nl_timestamp ();
+#else
+  return 0;
+#endif
+}
+
+static inline bool
+cache_valid_p (void)
+{
+  if (cache != NULL)
+    {
+      uint32_t timestamp = get_nl_timestamp ();
+      return timestamp != 0 && cache->timestamp == timestamp;
+    }
+  return false;
+}
+
 
 static struct cached_data *
 make_request (int fd, pid_t pid)
@@ -253,11 +276,7 @@ make_request (int fd, pid_t pid)
       if (result == NULL)
 	goto out_fail;
 
-#ifdef IS_IN_nscd
-      result->timestamp = nl_timestamp;
-#else
-      result->timestamp = __nscd_get_nl_timestamp ();
-#endif
+      result->timestamp = get_nl_timestamp ();
       result->usecnt = 2;
       result->seen_ipv4 = seen_ipv4;
       result->seen_ipv6 = true;
@@ -302,14 +321,7 @@ __check_pf (bool *seen_ipv4, bool *seen_ipv6,
 
   __libc_lock_lock (lock);
 
-#ifdef IS_IN_nscd
-# define cache_valid() nl_timestamp != 0 && cache->timestamp == nl_timestamp
-#else
-# define cache_valid() \
-      ({ uint32_t val = __nscd_get_nl_timestamp ();			      \
-	 val != 0 && cache->timestamp == val; })
-#endif
-  if (cache != NULL && cache_valid ())
+  if (cache_valid_p ())
     {
       data = cache;
       atomic_increment (&cache->usecnt);