djdelorie / rpms / glibc

Forked from rpms/glibc 3 years ago
Clone
cc6e160
commit 64d1e08ea822bf47cb2796ad0f727136227f983c
cc6e160
Author: Andreas Schwab <schwab@suse.de>
cc6e160
Date:   Mon Oct 2 14:30:46 2017 +0200
cc6e160
cc6e160
    Move nss_compat from nis to nss subdir and install it unconditionally
cc6e160
    
cc6e160
    This has been tested that local lookup still works with and
cc6e160
    without an installed libnss_nis, and that NIS lookup works when
cc6e160
    libnss_nis is available.
cc6e160
cc6e160
diff --git a/nis/Makefile b/nis/Makefile
cc6e160
index 991460faa6652413..e536b043e54d90f6 100644
cc6e160
--- a/nis/Makefile
cc6e160
+++ b/nis/Makefile
cc6e160
@@ -34,7 +34,7 @@ databases		= proto service hosts network grp pwd rpc ethers \
cc6e160
 			  spwd netgrp alias publickey
cc6e160
 
cc6e160
 # Specify rules for the nss_* modules.
cc6e160
-services		:= nis nisplus compat
cc6e160
+services		:= nis nisplus
cc6e160
 
cc6e160
 extra-libs		= libnsl $(services:%=libnss_%)
cc6e160
 # These libraries will be built in the `others' pass rather than
cc6e160
@@ -57,9 +57,6 @@ libnsl-routines = yp_xdr ypclnt ypupdate_xdr \
cc6e160
 		  nis_findserv nis_callback nis_clone_dir nis_clone_obj\
cc6e160
 		  nis_clone_res nss-default
cc6e160
 
cc6e160
-libnss_compat-routines	:= $(addprefix compat-,grp pwd spwd initgroups)
cc6e160
-libnss_compat-inhibit-o	= $(filter-out .os,$(object-suffixes))
cc6e160
-
cc6e160
 libnss_nis-routines	:= $(addprefix nis-,$(databases)) nis-initgroups \
cc6e160
 			   nss-nis
cc6e160
 libnss_nis-inhibit-o	= $(filter-out .os,$(object-suffixes))
cc6e160
@@ -71,7 +68,6 @@ libnss_nisplus-inhibit-o = $(filter-out .os,$(object-suffixes))
cc6e160
 include ../Rules
cc6e160
 
cc6e160
 
cc6e160
-$(objpfx)libnss_compat.so: $(objpfx)libnsl.so$(libnsl.so-version)
cc6e160
 $(objpfx)libnss_nis.so: $(objpfx)libnsl.so$(libnsl.so-version) \
cc6e160
 			$(common-objpfx)nss/libnss_files.so
cc6e160
 $(objpfx)libnss_nisplus.so: $(objpfx)libnsl.so$(libnsl.so-version)
cc6e160
diff --git a/nis/Versions b/nis/Versions
cc6e160
index ef9a5124174ec0e8..90d3d9dfaa3d853b 100644
cc6e160
--- a/nis/Versions
cc6e160
+++ b/nis/Versions
cc6e160
@@ -63,17 +63,6 @@ libnsl {
cc6e160
   }
cc6e160
 }
cc6e160
 
cc6e160
-libnss_compat {
cc6e160
-  GLIBC_PRIVATE {
cc6e160
-    _nss_compat_endgrent; _nss_compat_endpwent; _nss_compat_endspent;
cc6e160
-    _nss_compat_getgrent_r; _nss_compat_getgrgid_r; _nss_compat_getgrnam_r;
cc6e160
-    _nss_compat_getpwent_r; _nss_compat_getpwnam_r; _nss_compat_getpwuid_r;
cc6e160
-    _nss_compat_getspent_r; _nss_compat_getspnam_r;
cc6e160
-    _nss_compat_setgrent; _nss_compat_setpwent; _nss_compat_setspent;
cc6e160
-    _nss_compat_initgroups_dyn;
cc6e160
-  }
cc6e160
-}
cc6e160
-
cc6e160
 libnss_nis {
cc6e160
   GLIBC_PRIVATE {
cc6e160
     _nss_nis_endaliasent; _nss_nis_endetherent; _nss_nis_endgrent;
cc6e160
diff --git a/nss/Makefile b/nss/Makefile
cc6e160
index 1f016d99c78a7433..760a52acea20d059 100644
cc6e160
--- a/nss/Makefile
cc6e160
+++ b/nss/Makefile
cc6e160
@@ -55,7 +55,7 @@ tests			= test-netdb tst-nss-test1 test-digits-dots \
cc6e160
 xtests			= bug-erange
cc6e160
 
cc6e160
 # Specify rules for the nss_* modules.  We have some services.
cc6e160
-services		:= files db
cc6e160
+services		:= files db compat
cc6e160
 
cc6e160
 extra-libs		= $(services:%=libnss_%)
cc6e160
 # These libraries will be built in the `others' pass rather than
cc6e160
@@ -78,11 +78,15 @@ libnss_db-routines	:= $(libnss_db-dbs) db-open db-init hash-string
cc6e160
 generated		+= $(filter-out db-alias.c db-netgrp.c, \
cc6e160
 					$(addsuffix .c,$(libnss_db-dbs)))
cc6e160
 
cc6e160
+libnss_compat-routines	:= $(addprefix compat-,grp pwd spwd initgroups) \
cc6e160
+			   nisdomain
cc6e160
+
cc6e160
 install-others		+= $(inst_vardbdir)/Makefile
cc6e160
 
cc6e160
 # Build static module into libc if requested
cc6e160
 libnss_files-inhibit-o	= $(filter-out .os,$(object-suffixes))
cc6e160
 libnss_db-inhibit-o	= $(filter-out .os,$(object-suffixes))
cc6e160
+libnss_compat-inhibit-o	= $(filter-out .os,$(object-suffixes))
cc6e160
 ifeq ($(build-static-nss),yes)
cc6e160
 routines                += $(libnss_files-routines)
cc6e160
 static-only-routines    += $(libnss_files-routines)
cc6e160
diff --git a/nss/Versions b/nss/Versions
cc6e160
index f8ababccc74d1dd2..14c2571468169e4d 100644
cc6e160
--- a/nss/Versions
cc6e160
+++ b/nss/Versions
cc6e160
@@ -160,3 +160,14 @@ libnss_db {
cc6e160
     _nss_db_init;
cc6e160
   }
cc6e160
 }
cc6e160
+
cc6e160
+libnss_compat {
cc6e160
+  GLIBC_PRIVATE {
cc6e160
+    _nss_compat_endgrent; _nss_compat_endpwent; _nss_compat_endspent;
cc6e160
+    _nss_compat_getgrent_r; _nss_compat_getgrgid_r; _nss_compat_getgrnam_r;
cc6e160
+    _nss_compat_getpwent_r; _nss_compat_getpwnam_r; _nss_compat_getpwuid_r;
cc6e160
+    _nss_compat_getspent_r; _nss_compat_getspnam_r;
cc6e160
+    _nss_compat_setgrent; _nss_compat_setpwent; _nss_compat_setspent;
cc6e160
+    _nss_compat_initgroups_dyn;
cc6e160
+  }
cc6e160
+}
cc6e160
diff --git a/nis/nss_compat/compat-grp.c b/nss/nss_compat/compat-grp.c
cc6e160
similarity index 97%
cc6e160
rename from nis/nss_compat/compat-grp.c
cc6e160
rename to nss/nss_compat/compat-grp.c
cc6e160
index 736f1df10a276067..28bef2e3745175da 100644
cc6e160
--- a/nis/nss_compat/compat-grp.c
cc6e160
+++ b/nss/nss_compat/compat-grp.c
cc6e160
@@ -24,7 +24,6 @@
cc6e160
 #include <nsswitch.h>
cc6e160
 #include <stdio_ext.h>
cc6e160
 #include <string.h>
cc6e160
-#include <rpc/types.h>
cc6e160
 #include <libc-lock.h>
cc6e160
 #include <kernel-features.h>
cc6e160
 
cc6e160
@@ -58,14 +57,14 @@ struct blacklist_t
cc6e160
 
cc6e160
 struct ent_t
cc6e160
 {
cc6e160
-  bool_t files;
cc6e160
+  bool files;
cc6e160
   enum nss_status setent_status;
cc6e160
   FILE *stream;
cc6e160
   struct blacklist_t blacklist;
cc6e160
 };
cc6e160
 typedef struct ent_t ent_t;
cc6e160
 
cc6e160
-static ent_t ext_ent = { TRUE, NSS_STATUS_SUCCESS, NULL, { NULL, 0, 0 }};
cc6e160
+static ent_t ext_ent = { true, NSS_STATUS_SUCCESS, NULL, { NULL, 0, 0 }};
cc6e160
 
cc6e160
 /* Protect global state against multiple changers.  */
cc6e160
 __libc_lock_define_initialized (static, lock)
cc6e160
@@ -85,7 +84,7 @@ int __compat_have_cloexec;
cc6e160
 
cc6e160
 /* Prototypes for local functions.  */
cc6e160
 static void blacklist_store_name (const char *, ent_t *);
cc6e160
-static int in_blacklist (const char *, int, ent_t *);
cc6e160
+static bool in_blacklist (const char *, int, ent_t *);
cc6e160
 
cc6e160
 /* Initialize the NSS interface/functions. The calling function must
cc6e160
    hold the lock.  */
cc6e160
@@ -107,7 +106,7 @@ internal_setgrent (ent_t *ent, int stayopen, int needent)
cc6e160
 {
cc6e160
   enum nss_status status = NSS_STATUS_SUCCESS;
cc6e160
 
cc6e160
-  ent->files = TRUE;
cc6e160
+  ent->files = true;
cc6e160
 
cc6e160
   if (ent->blacklist.data != NULL)
cc6e160
     {
cc6e160
@@ -369,7 +368,7 @@ getgrent_next_file (struct group *result, ent_t *ent,
cc6e160
       /* +:... */
cc6e160
       if (result->gr_name[0] == '+' && result->gr_name[1] == '\0')
cc6e160
 	{
cc6e160
-	  ent->files = FALSE;
cc6e160
+	  ent->files = false;
cc6e160
 
cc6e160
 	  return getgrent_next_nss (result, ent, buffer, buflen, errnop);
cc6e160
 	}
cc6e160
@@ -514,7 +513,7 @@ enum nss_status
cc6e160
 _nss_compat_getgrnam_r (const char *name, struct group *grp,
cc6e160
 			char *buffer, size_t buflen, int *errnop)
cc6e160
 {
cc6e160
-  ent_t ent = { TRUE, NSS_STATUS_SUCCESS, NULL, { NULL, 0, 0 }};
cc6e160
+  ent_t ent = { true, NSS_STATUS_SUCCESS, NULL, { NULL, 0, 0 }};
cc6e160
   enum nss_status result;
cc6e160
 
cc6e160
   if (name[0] == '-' || name[0] == '+')
cc6e160
@@ -646,7 +645,7 @@ enum nss_status
cc6e160
 _nss_compat_getgrgid_r (gid_t gid, struct group *grp,
cc6e160
 			char *buffer, size_t buflen, int *errnop)
cc6e160
 {
cc6e160
-  ent_t ent = { TRUE, NSS_STATUS_SUCCESS, NULL, { NULL, 0, 0 }};
cc6e160
+  ent_t ent = { true, NSS_STATUS_SUCCESS, NULL, { NULL, 0, 0 }};
cc6e160
   enum nss_status result;
cc6e160
 
cc6e160
   __libc_lock_lock (lock);
cc6e160
@@ -713,15 +712,15 @@ blacklist_store_name (const char *name, ent_t *ent)
cc6e160
   return;
cc6e160
 }
cc6e160
 
cc6e160
-/* returns TRUE if ent->blacklist contains name, else FALSE */
cc6e160
-static bool_t
cc6e160
+/* Return whether ent->blacklist contains name.  */
cc6e160
+static bool
cc6e160
 in_blacklist (const char *name, int namelen, ent_t *ent)
cc6e160
 {
cc6e160
   char buf[namelen + 3];
cc6e160
   char *cp;
cc6e160
 
cc6e160
   if (ent->blacklist.data == NULL)
cc6e160
-    return FALSE;
cc6e160
+    return false;
cc6e160
 
cc6e160
   buf[0] = '|';
cc6e160
   cp = stpcpy (&buf[1], name);
cc6e160
diff --git a/nis/nss_compat/compat-initgroups.c b/nss/nss_compat/compat-initgroups.c
cc6e160
similarity index 98%
cc6e160
rename from nis/nss_compat/compat-initgroups.c
cc6e160
rename to nss/nss_compat/compat-initgroups.c
cc6e160
index 4843e5c28fe1128d..76117033004cfa97 100644
cc6e160
--- a/nis/nss_compat/compat-initgroups.c
cc6e160
+++ b/nss/nss_compat/compat-initgroups.c
cc6e160
@@ -24,7 +24,6 @@
cc6e160
 #include <stdio_ext.h>
cc6e160
 #include <string.h>
cc6e160
 #include <unistd.h>
cc6e160
-#include <rpc/types.h>
cc6e160
 #include <sys/param.h>
cc6e160
 #include <nsswitch.h>
cc6e160
 #include <libc-lock.h>
cc6e160
@@ -93,7 +92,7 @@ extern int __compat_have_cloexec;
cc6e160
 
cc6e160
 /* Prototypes for local functions.  */
cc6e160
 static void blacklist_store_name (const char *, ent_t *);
cc6e160
-static int in_blacklist (const char *, int, ent_t *);
cc6e160
+static bool in_blacklist (const char *, int, ent_t *);
cc6e160
 
cc6e160
 /* Initialize the NSS interface/functions. The calling function must
cc6e160
    hold the lock.  */
cc6e160
@@ -602,15 +601,15 @@ blacklist_store_name (const char *name, ent_t *ent)
cc6e160
   return;
cc6e160
 }
cc6e160
 
cc6e160
-/* returns TRUE if ent->blacklist contains name, else FALSE */
cc6e160
-static bool_t
cc6e160
+/* Return whether ent->blacklist contains name.  */
cc6e160
+static bool
cc6e160
 in_blacklist (const char *name, int namelen, ent_t *ent)
cc6e160
 {
cc6e160
   char buf[namelen + 3];
cc6e160
   char *cp;
cc6e160
 
cc6e160
   if (ent->blacklist.data == NULL)
cc6e160
-    return FALSE;
cc6e160
+    return false;
cc6e160
 
cc6e160
   buf[0] = '|';
cc6e160
   cp = stpcpy (&buf[1], name);
cc6e160
diff --git a/nis/nss_compat/compat-pwd.c b/nss/nss_compat/compat-pwd.c
cc6e160
similarity index 99%
cc6e160
rename from nis/nss_compat/compat-pwd.c
cc6e160
rename to nss/nss_compat/compat-pwd.c
cc6e160
index 16e9404e2263c4b5..638bfe23212205a6 100644
cc6e160
--- a/nis/nss_compat/compat-pwd.c
cc6e160
+++ b/nss/nss_compat/compat-pwd.c
cc6e160
@@ -25,12 +25,11 @@
cc6e160
 #include <pwd.h>
cc6e160
 #include <stdio_ext.h>
cc6e160
 #include <string.h>
cc6e160
-#include <rpc/types.h>
cc6e160
-#include <rpcsvc/ypclnt.h>
cc6e160
 #include <libc-lock.h>
cc6e160
 #include <kernel-features.h>
cc6e160
 
cc6e160
 #include "netgroup.h"
cc6e160
+#include "nisdomain.h"
cc6e160
 
cc6e160
 static service_user *ni;
cc6e160
 static enum nss_status (*nss_setpwent) (int stayopen);
cc6e160
@@ -95,7 +94,7 @@ extern int __compat_have_cloexec;
cc6e160
 
cc6e160
 /* Prototypes for local functions.  */
cc6e160
 static void blacklist_store_name (const char *, ent_t *);
cc6e160
-static int in_blacklist (const char *, int, ent_t *);
cc6e160
+static bool in_blacklist (const char *, int, ent_t *);
cc6e160
 
cc6e160
 /* Initialize the NSS interface/functions. The calling function must
cc6e160
    hold the lock.  */
cc6e160
@@ -394,7 +393,7 @@ getpwent_next_nss_netgr (const char *name, struct passwd *result, ent_t *ent,
cc6e160
       if (domain != NULL)
cc6e160
 	{
cc6e160
 	  if (curdomain == NULL
cc6e160
-	      && yp_get_default_domain (&curdomain) != YPERR_SUCCESS)
cc6e160
+	      && __nss_get_default_domain (&curdomain) != 0)
cc6e160
 	    {
cc6e160
 	      __internal_endnetgrent (&ent->netgrdata);
cc6e160
 	      ent->netgroup = false;
cc6e160
@@ -1162,15 +1161,15 @@ blacklist_store_name (const char *name, ent_t *ent)
cc6e160
   return;
cc6e160
 }
cc6e160
 
cc6e160
-/* Returns TRUE if ent->blacklist contains name, else FALSE.  */
cc6e160
-static bool_t
cc6e160
+/* Returns whether ent->blacklist contains name.  */
cc6e160
+static bool
cc6e160
 in_blacklist (const char *name, int namelen, ent_t *ent)
cc6e160
 {
cc6e160
   char buf[namelen + 3];
cc6e160
   char *cp;
cc6e160
 
cc6e160
   if (ent->blacklist.data == NULL)
cc6e160
-    return FALSE;
cc6e160
+    return false;
cc6e160
 
cc6e160
   buf[0] = '|';
cc6e160
   cp = stpcpy (&buf[1], name);
cc6e160
diff --git a/nis/nss_compat/compat-spwd.c b/nss/nss_compat/compat-spwd.c
cc6e160
similarity index 98%
cc6e160
rename from nis/nss_compat/compat-spwd.c
cc6e160
rename to nss/nss_compat/compat-spwd.c
cc6e160
index 4db96ef29df8d703..7cdd61b6edec8572 100644
cc6e160
--- a/nis/nss_compat/compat-spwd.c
cc6e160
+++ b/nss/nss_compat/compat-spwd.c
cc6e160
@@ -25,12 +25,11 @@
cc6e160
 #include <shadow.h>
cc6e160
 #include <stdio_ext.h>
cc6e160
 #include <string.h>
cc6e160
-#include <rpc/types.h>
cc6e160
-#include <rpcsvc/ypclnt.h>
cc6e160
 #include <libc-lock.h>
cc6e160
 #include <kernel-features.h>
cc6e160
 
cc6e160
 #include "netgroup.h"
cc6e160
+#include "nisdomain.h"
cc6e160
 
cc6e160
 static service_user *ni;
cc6e160
 static enum nss_status (*nss_setspent) (int stayopen);
cc6e160
@@ -92,7 +91,7 @@ extern int __compat_have_cloexec;
cc6e160
 
cc6e160
 /* Prototypes for local functions.  */
cc6e160
 static void blacklist_store_name (const char *, ent_t *);
cc6e160
-static int in_blacklist (const char *, int, ent_t *);
cc6e160
+static bool in_blacklist (const char *, int, ent_t *);
cc6e160
 
cc6e160
 /* Initialize the NSS interface/functions. The calling function must
cc6e160
    hold the lock.  */
cc6e160
@@ -354,7 +353,7 @@ getspent_next_nss_netgr (const char *name, struct spwd *result, ent_t *ent,
cc6e160
       if (domain != NULL)
cc6e160
 	{
cc6e160
 	  if (curdomain == NULL
cc6e160
-	      && yp_get_default_domain (&curdomain) != YPERR_SUCCESS)
cc6e160
+	      && __nss_get_default_domain (&curdomain) != 0)
cc6e160
 	    {
cc6e160
 	      __internal_endnetgrent (&ent->netgrdata);
cc6e160
 	      ent->netgroup = false;
cc6e160
@@ -888,8 +887,8 @@ blacklist_store_name (const char *name, ent_t *ent)
cc6e160
 }
cc6e160
 
cc6e160
 
cc6e160
-/* Returns TRUE if ent->blacklist contains name, else FALSE.  */
cc6e160
-static bool_t
cc6e160
+/* Returns whether ent->blacklist contains name.  */
cc6e160
+static bool
cc6e160
 in_blacklist (const char *name, int namelen, ent_t *ent)
cc6e160
 {
cc6e160
   char buf[namelen + 3];
cc6e160
diff --git a/nss/nss_compat/nisdomain.c b/nss/nss_compat/nisdomain.c
cc6e160
new file mode 100644
cc6e160
index 0000000000000000..220ae27234705855
cc6e160
--- /dev/null
cc6e160
+++ b/nss/nss_compat/nisdomain.c
cc6e160
@@ -0,0 +1,58 @@
cc6e160
+/* Copyright (C) 2017 Free Software Foundation, Inc.
cc6e160
+   This file is part of the GNU C Library.
cc6e160
+
cc6e160
+   The GNU C Library is free software; you can redistribute it and/or
cc6e160
+   modify it under the terms of the GNU Lesser General Public
cc6e160
+   License as published by the Free Software Foundation; either
cc6e160
+   version 2.1 of the License, or (at your option) any later version.
cc6e160
+
cc6e160
+   The GNU C Library is distributed in the hope that it will be useful,
cc6e160
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
cc6e160
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
cc6e160
+   Lesser General Public License for more details.
cc6e160
+
cc6e160
+   You should have received a copy of the GNU Lesser General Public
cc6e160
+   License along with the GNU C Library; if not, see
cc6e160
+   <http://www.gnu.org/licenses/>.  */
cc6e160
+
cc6e160
+#include <stdlib.h>
cc6e160
+#include <string.h>
cc6e160
+#include <errno.h>
cc6e160
+#include <unistd.h>
cc6e160
+#include <libc-lock.h>
cc6e160
+#include "nisdomain.h"
cc6e160
+
cc6e160
+#define MAXDOMAINNAMELEN 1024
cc6e160
+
cc6e160
+static char domainname[MAXDOMAINNAMELEN];
cc6e160
+
cc6e160
+__libc_lock_define_initialized (static, domainname_lock)
cc6e160
+
cc6e160
+int
cc6e160
+__nss_get_default_domain (char **outdomain)
cc6e160
+{
cc6e160
+  int result = 0;
cc6e160
+  *outdomain = NULL;
cc6e160
+
cc6e160
+  __libc_lock_lock (domainname_lock);
cc6e160
+
cc6e160
+  if (domainname[0] != '\0')
cc6e160
+    {
cc6e160
+      if (getdomainname (domainname, MAXDOMAINNAMELEN) < 0)
cc6e160
+	result = errno;
cc6e160
+      else if (strcmp (domainname, "(none)") == 0)
cc6e160
+	{
cc6e160
+	  /* If domainname is not set, some systems will return "(none)" */
cc6e160
+	  domainname[0] = '\0';
cc6e160
+	  result = ENOENT;
cc6e160
+	}
cc6e160
+      else
cc6e160
+	*outdomain = domainname;
cc6e160
+    }
cc6e160
+  else
cc6e160
+    *outdomain = domainname;
cc6e160
+
cc6e160
+  __libc_lock_unlock (domainname_lock);
cc6e160
+
cc6e160
+  return result;
cc6e160
+}
cc6e160
diff --git a/nss/nss_compat/nisdomain.h b/nss/nss_compat/nisdomain.h
cc6e160
new file mode 100644
cc6e160
index 0000000000000000..314f3f7c069835af
cc6e160
--- /dev/null
cc6e160
+++ b/nss/nss_compat/nisdomain.h
cc6e160
@@ -0,0 +1,20 @@
cc6e160
+/* Copyright (C) 2017 Free Software Foundation, Inc.
cc6e160
+   This file is part of the GNU C Library.
cc6e160
+
cc6e160
+   The GNU C Library is free software; you can redistribute it and/or
cc6e160
+   modify it under the terms of the GNU Lesser General Public
cc6e160
+   License as published by the Free Software Foundation; either
cc6e160
+   version 2.1 of the License, or (at your option) any later version.
cc6e160
+
cc6e160
+   The GNU C Library is distributed in the hope that it will be useful,
cc6e160
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
cc6e160
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
cc6e160
+   Lesser General Public License for more details.
cc6e160
+
cc6e160
+   You should have received a copy of the GNU Lesser General Public
cc6e160
+   License along with the GNU C Library; if not, see
cc6e160
+   <http://www.gnu.org/licenses/>.  */
cc6e160
+
cc6e160
+/* Set OUTDOMAIN to a pointer to the current NIS domain name, or NULL if
cc6e160
+   not set.  Return zero on success, an error number on failure.  */
cc6e160
+extern int __nss_get_default_domain (char **outdomain);