diff --git a/INSTALL b/INSTALL
index 62e78725f5..3f5575e23e 100644
--- a/INSTALL
+++ b/INSTALL
@@ -227,15 +227,6 @@ if 'CFLAGS' is specified it must enable optimization. For example:
colon-separated list in a single environment variable
'GLIBC_TUNABLES'.
-'--enable-obsolete-nsl'
- By default, libnsl is only built as shared library for backward
- compatibility and the NSS modules libnss_compat, libnss_nis and
- libnss_nisplus are not built at all. Use this option to enable
- libnsl with all depending NSS modules and header files. For
- architectures and ABIs that have been added after version 2.28 of
- the GNU C Library this option is not available, and the libnsl
- compatibility library is not built.
-
'--disable-crypt'
Do not install the passphrase-hashing library 'libcrypt' or the
header file 'crypt.h'. 'unistd.h' will still declare the function
diff --git a/NEWS b/NEWS
index d7282b4ad5..f0782d6096 100644
--- a/NEWS
+++ b/NEWS
@@ -69,6 +69,16 @@ Major new features:
Deprecated and removed features, and other changes affecting compatibility:
+* Remove configure option --enable-obsolete-nsl. libnsl is only built
+ as shared library for backward compatibility and the NSS modules "nis"
+ and "nisplus" are not built at all and libnsl's headers aren't
+ installed. This compatibility is kept only for architectures and ABIs
+ that have been added in or before version 2.28. Replacement
+ implementations based on TI-RPC, which additionally support IPv6, are
+ available from . This change does not
+ affect the "compat" NSS module, which does not depended on libnsl
+ since 2.27 and thus can be used without NIS.
+
* The deprecated header and the sysctl function have been
removed. To support old binaries, the sysctl function continues to
exist as a compatibility symbol (on those architectures which had it),
@@ -104,11 +114,11 @@ Deprecated and removed features, and other changes affecting compatibility:
or contents might be overwritten on subsequent calls in the same thread or
if the thread is terminated. It makes strerror MT-safe.
-* The "files", "nis" and "nisplus" NSS modules no longer supports the
- "key" database (used for secure RPC). The contents of the
- /etc/publickey file will be ignored, regardless of the settings in
- /etc/nsswitch.conf. (This method of storing RPC keys only supported
- the obsolete and insecure AUTH_DES flavor of secure RPC.)
+* The "files" NSS module no longer supports the "key" database (used for
+ secure RPC). The contents of the /etc/publickey file will be ignored,
+ regardless of the settings in /etc/nsswitch.conf. (This method of
+ storing RPC keys only supported the obsolete and insecure AUTH_DES
+ flavor of secure RPC.)
Changes to build and runtime requirements:
diff --git a/config.h.in b/config.h.in
index 831eca2fe1..9eb71a81b7 100644
--- a/config.h.in
+++ b/config.h.in
@@ -161,10 +161,6 @@
to link against. */
#undef LINK_OBSOLETE_RPC
-/* Define if obsolete libnsl code should be made available for user-level
- code to link against. */
-#undef LINK_OBSOLETE_NSL
-
/* Define if Systemtap probes should be defined. */
#undef USE_STAP_PROBE
diff --git a/config.make.in b/config.make.in
index 2fed3da773..cefb6d4a90 100644
--- a/config.make.in
+++ b/config.make.in
@@ -97,7 +97,6 @@ build-static-nss = @static_nss@
cross-compiling = @cross_compiling@
force-install = @force_install@
link-obsolete-rpc = @link_obsolete_rpc@
-build-obsolete-nsl = @build_obsolete_nsl@
build-crypt = @build_crypt@
build-nscd = @build_nscd@
use-nscd = @use_nscd@
diff --git a/configure b/configure
index b8ef8c7a51..793c0068cc 100755
--- a/configure
+++ b/configure
@@ -673,7 +673,6 @@ base_machine
have_tunables
build_pt_chown
build_nscd
-build_obsolete_nsl
link_obsolete_rpc
libc_cv_static_nss_crypt
libc_cv_nss_crypt
@@ -786,7 +785,6 @@ enable_experimental_malloc
enable_crypt
enable_nss_crypt
enable_obsolete_rpc
-enable_obsolete_nsl
enable_systemtap
enable_build_nscd
enable_nscd
@@ -1459,8 +1457,6 @@ Optional Features:
--enable-nss-crypt enable libcrypt to use nss
--enable-obsolete-rpc build and install the obsolete RPC code for
link-time usage
- --enable-obsolete-nsl build and install the obsolete libnsl library and
- depending NSS modules
--enable-systemtap enable systemtap static probe points [default=no]
--disable-build-nscd disable building and installing the nscd daemon
--disable-nscd library functions will not contact the nscd daemon
@@ -3654,20 +3650,6 @@ if test "$link_obsolete_rpc" = yes; then
fi
-# Check whether --enable-obsolete-nsl was given.
-if test "${enable_obsolete_nsl+set}" = set; then :
- enableval=$enable_obsolete_nsl; build_obsolete_nsl=$enableval
-else
- build_obsolete_nsl=no
-fi
-
-
-
-if test "$build_obsolete_nsl" = yes; then
- $as_echo "#define LINK_OBSOLETE_NSL 1" >>confdefs.h
-
-fi
-
# Check whether --enable-systemtap was given.
if test "${enable_systemtap+set}" = set; then :
enableval=$enable_systemtap; systemtap=$enableval
@@ -3785,7 +3767,7 @@ main ()
{
#ifndef __CET__
-#error no CET compiler support
+# error no CET compiler support
#endif
;
return 0;
diff --git a/configure.ac b/configure.ac
index ff00591fd4..33a1189804 100644
--- a/configure.ac
+++ b/configure.ac
@@ -387,17 +387,6 @@ if test "$link_obsolete_rpc" = yes; then
AC_DEFINE(LINK_OBSOLETE_RPC)
fi
-AC_ARG_ENABLE([obsolete-nsl],
- AC_HELP_STRING([--enable-obsolete-nsl],
- [build and install the obsolete libnsl library and depending NSS modules]),
- [build_obsolete_nsl=$enableval],
- [build_obsolete_nsl=no])
-AC_SUBST(build_obsolete_nsl)
-
-if test "$build_obsolete_nsl" = yes; then
- AC_DEFINE(LINK_OBSOLETE_NSL)
-fi
-
AC_ARG_ENABLE([systemtap],
[AS_HELP_STRING([--enable-systemtap],
[enable systemtap static probe points @<:@default=no@:>@])],
diff --git a/grp/initgroups.c b/grp/initgroups.c
index f4c4e986e9..0c17141117 100644
--- a/grp/initgroups.c
+++ b/grp/initgroups.c
@@ -31,12 +31,6 @@
#include "../nscd/nscd-client.h"
#include "../nscd/nscd_proto.h"
-#ifdef LINK_OBSOLETE_NSL
-# define DEFAULT_CONFIG "compat [NOTFOUND=return] files"
-#else
-# define DEFAULT_CONFIG "files"
-#endif
-
/* Type of the lookup function. */
typedef enum nss_status (*initgroups_dyn_function) (const char *, gid_t,
long int *, long int *,
@@ -83,7 +77,7 @@ internal_getgrouplist (const char *user, gid_t group, long int *size,
&__nss_initgroups_database) < 0)
{
if (__nss_group_database == NULL)
- no_more = __nss_database_lookup2 ("group", NULL, DEFAULT_CONFIG,
+ no_more = __nss_database_lookup2 ("group", NULL, "files",
&__nss_group_database);
__nss_initgroups_database = __nss_group_database;
diff --git a/include/aliases.h b/include/aliases.h
index 11b81d4d24..db82588630 100644
--- a/include/aliases.h
+++ b/include/aliases.h
@@ -33,8 +33,6 @@ extern enum nss_status _nss_ ## service ## _getaliasbyname_r \
DECLARE_NSS_PROTOTYPES (files)
-DECLARE_NSS_PROTOTYPES (nis)
-DECLARE_NSS_PROTOTYPES (nisplus)
#undef DECLARE_NSS_PROTOTYPES
# endif /* !_ISOMAC */
diff --git a/include/dlfcn.h b/include/dlfcn.h
index 93dd369ab1..a1816e4991 100644
--- a/include/dlfcn.h
+++ b/include/dlfcn.h
@@ -39,10 +39,11 @@ extern char **__libc_argv attribute_hidden;
__libgcc_s_init because unwinding is already in progress, so libgcc_s.so
has already been loaded if its unwinder is used (Bug 22636).
2. It allows us to provide robust fallback code at dlopen time for
- incorrectly configured systems that mix old libnss_* modules with newly
- installed libraries e.g. old libnss_nis.so.2 with new libnsl.so.1. Using
- RTLD_LAZY here causes a failure at the time the symbol is called and at
- that point it is much harder to safely return an error (Bug 22766).
+ incorrectly configured systems that mix old libnss_* modules
+ with newly installed libraries e.g. old libnss_dns.so.2 with new
+ libresolv.so.2. Using RTLD_LAZY here causes a failure at the
+ time the symbol is called and at that point it is much harder to
+ safely return an error (Bug 22766).
The use of RTLD_NOW also impacts gconv module loading, backtracing
(where the unwinder form libgcc_s.so is used), and IDNA functions
diff --git a/include/grp.h b/include/grp.h
index 871701adbe..58f7b4d233 100644
--- a/include/grp.h
+++ b/include/grp.h
@@ -56,8 +56,6 @@ extern enum nss_status _nss_ ## service ##_initgroups_dyn \
DECLARE_NSS_PROTOTYPES (compat)
DECLARE_NSS_PROTOTYPES (files)
DECLARE_NSS_PROTOTYPES (hesiod)
-DECLARE_NSS_PROTOTYPES (nis)
-DECLARE_NSS_PROTOTYPES (nisplus)
#undef DECLARE_NSS_PROTOTYPES
#endif
diff --git a/include/libc-symbols.h b/include/libc-symbols.h
index b2f36bc44b..29483779fe 100644
--- a/include/libc-symbols.h
+++ b/include/libc-symbols.h
@@ -833,13 +833,7 @@ for linking")
# define libnsl_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
# define libnsl_hidden_tls_proto(name, attrs...) \
hidden_tls_proto (name, ##attrs)
-# ifdef LINK_OBSOLETE_NSL
- /* libnsl_hidden_nolink should only get used in libnsl code. */
-# define libnsl_hidden_nolink_def(name, version) libnsl_hidden_def (name)
-# else
-# define libnsl_hidden_nolink_def(name, version) hidden_nolink (name, libnsl, version)
-# endif
-# define libnsl_hidden_def(name) hidden_def (name)
+# define libnsl_hidden_nolink_def(name, version) hidden_nolink (name, libnsl, version)
# define libnsl_hidden_weak(name) hidden_weak (name)
# define libnsl_hidden_ver(local, name) hidden_ver (local, name)
# define libnsl_hidden_data_def(name) hidden_data_def (name)
@@ -849,7 +843,6 @@ for linking")
#else
# define libnsl_hidden_proto(name, attrs...)
# define libnsl_hidden_tls_proto(name, attrs...)
-# define libnsl_hidden_def(name)
# define libnsl_hidden_weak(name)
# define libnsl_hidden_ver(local, name)
# define libnsl_hidden_data_def(name)
@@ -858,52 +851,6 @@ for linking")
# define libnsl_hidden_data_ver(local, name)
#endif
-#if IS_IN (libnss_nis)
-# define libnss_nis_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
-# define libnss_nis_hidden_tls_proto(name, attrs...) \
- hidden_tls_proto (name, ##attrs)
-# define libnss_nis_hidden_def(name) hidden_def (name)
-# define libnss_nis_hidden_weak(name) hidden_weak (name)
-# define libnss_nis_hidden_ver(local, name) hidden_ver (local, name)
-# define libnss_nis_hidden_data_def(name) hidden_data_def (name)
-# define libnss_nis_hidden_tls_def(name) hidden_tls_def (name)
-# define libnss_nis_hidden_data_weak(name) hidden_data_weak (name)
-# define libnss_nis_hidden_data_ver(local, name) hidden_data_ver (local, name)
-#else
-# define libnss_nis_hidden_proto(name, attrs...)
-# define libnss_nis_hidden_tls_proto(name, attrs...)
-# define libnss_nis_hidden_def(name)
-# define libnss_nis_hidden_weak(name)
-# define libnss_nis_hidden_ver(local, name)
-# define libnss_nis_hidden_data_def(name)
-# define libnss_nis_hidden_tls_def(name)
-# define libnss_nis_hidden_data_weak(name)
-# define libnss_nis_hidden_data_ver(local, name)
-#endif
-
-#if IS_IN (libnss_nisplus)
-# define libnss_nisplus_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
-# define libnss_nisplus_hidden_tls_proto(name, attrs...) \
- hidden_tls_proto (name, ##attrs)
-# define libnss_nisplus_hidden_def(name) hidden_def (name)
-# define libnss_nisplus_hidden_weak(name) hidden_weak (name)
-# define libnss_nisplus_hidden_ver(local, name) hidden_ver (local, name)
-# define libnss_nisplus_hidden_data_def(name) hidden_data_def (name)
-# define libnss_nisplus_hidden_tls_def(name) hidden_tls_def (name)
-# define libnss_nisplus_hidden_data_weak(name) hidden_data_weak (name)
-# define libnss_nisplus_hidden_data_ver(local, name) hidden_data_ver (local, name)
-#else
-# define libnss_nisplus_hidden_proto(name, attrs...)
-# define libnss_nisplus_hidden_tls_proto(name, attrs...)
-# define libnss_nisplus_hidden_def(name)
-# define libnss_nisplus_hidden_weak(name)
-# define libnss_nisplus_hidden_ver(local, name)
-# define libnss_nisplus_hidden_data_def(name)
-# define libnss_nisplus_hidden_tls_def(name)
-# define libnss_nisplus_hidden_data_weak(name)
-# define libnss_nisplus_hidden_data_ver(local, name)
-#endif
-
#define libc_hidden_builtin_proto(name, attrs...) libc_hidden_proto (name, ##attrs)
#define libc_hidden_builtin_def(name) libc_hidden_def (name)
#define libc_hidden_builtin_weak(name) libc_hidden_weak (name)
diff --git a/include/netdb.h b/include/netdb.h
index 3c78da60c5..6b431350df 100644
--- a/include/netdb.h
+++ b/include/netdb.h
@@ -286,15 +286,9 @@ DECLARE_NSS_PROTOTYPES (compat)
DECLARE_NSS_PROTOTYPES (dns)
DECLARE_NSS_PROTOTYPES (files)
DECLARE_NSS_PROTOTYPES (hesiod)
-DECLARE_NSS_PROTOTYPES (nis)
-DECLARE_NSS_PROTOTYPES (nisplus)
#undef DECLARE_NSS_PROTOTYPES
-libnss_nis_hidden_proto (_nss_nis_endhostent)
-libnss_nis_hidden_proto (_nss_nis_endnetent)
-libnss_nis_hidden_proto (_nss_nis_endspent)
-
#endif
#endif /* !_NETDB_H */
diff --git a/include/netinet/ether.h b/include/netinet/ether.h
index 8bfe7e03ad..8fd05f8193 100644
--- a/include/netinet/ether.h
+++ b/include/netinet/ether.h
@@ -36,8 +36,6 @@ extern enum nss_status _nss_ ## service ## _getntohost_r \
char *buffer, size_t buflen, int *errnop);
DECLARE_NSS_PROTOTYPES (files)
-DECLARE_NSS_PROTOTYPES (nis)
-DECLARE_NSS_PROTOTYPES (nisplus)
#undef DECLARE_NSS_PROTOTYPES
diff --git a/include/pwd.h b/include/pwd.h
index fc995065d9..fd23fe9d6b 100644
--- a/include/pwd.h
+++ b/include/pwd.h
@@ -48,8 +48,6 @@ extern enum nss_status _nss_ ## service ##_getpwent_r \
DECLARE_NSS_PROTOTYPES (compat)
DECLARE_NSS_PROTOTYPES (files)
DECLARE_NSS_PROTOTYPES (hesiod)
-DECLARE_NSS_PROTOTYPES (nis)
-DECLARE_NSS_PROTOTYPES (nisplus)
#undef DECLARE_NSS_PROTOTYPES
#endif
diff --git a/include/rpc/auth.h b/include/rpc/auth.h
index 2e55cce11d..86cbd77196 100644
--- a/include/rpc/auth.h
+++ b/include/rpc/auth.h
@@ -13,17 +13,6 @@ libc_hidden_proto (key_gendes)
struct key_netstarg;
extern int key_setnet (struct key_netstarg *arg);
-#define DECLARE_NSS_PROTOTYPES(service) \
-extern enum nss_status _nss_ ##service ## _netname2user \
- (char netname[MAXNETNAMELEN + 1], uid_t *uidp, \
- gid_t *gidp, int *gidlenp, gid_t *gidlist, \
- int *errnop);
-
-DECLARE_NSS_PROTOTYPES (nis)
-DECLARE_NSS_PROTOTYPES (nisplus)
-
-#undef DECLARE_NSS_PROTOTYPES
-
libc_hidden_proto (key_encryptsession_pk)
libc_hidden_proto (key_decryptsession_pk)
diff --git a/include/rpc/auth_des.h b/include/rpc/auth_des.h
index 6afed56b71..31e0742096 100644
--- a/include/rpc/auth_des.h
+++ b/include/rpc/auth_des.h
@@ -17,19 +17,6 @@ extern enum auth_stat _svcauth_des (struct svc_req *rqst,
struct rpc_msg *msg);
-#define DECLARE_NSS_PROTOTYPES(service) \
-extern enum nss_status _nss_ ## service ## _getpublickey \
- (const char *netname, char *pkey, int *errnop); \
-extern enum nss_status _nss_ ## service ## _getsecretkey \
- (const char *netname, char *skey, char *passwd, \
- int *errnop);
-
-DECLARE_NSS_PROTOTYPES (files)
-DECLARE_NSS_PROTOTYPES (nis)
-DECLARE_NSS_PROTOTYPES (nisplus)
-
-#undef DECLARE_NSS_PROTOTYPES
-
libc_hidden_proto (authdes_getucred)
libc_hidden_proto (xdr_authdes_cred)
libc_hidden_proto (xdr_authdes_verf)
diff --git a/include/rpc/netdb.h b/include/rpc/netdb.h
index eb75f3f58c..dc0d0e26b9 100644
--- a/include/rpc/netdb.h
+++ b/include/rpc/netdb.h
@@ -45,8 +45,6 @@ extern enum nss_status _nss_ ## service ## _getrpcbynumber_r \
DECLARE_NSS_PROTOTYPES (files)
-DECLARE_NSS_PROTOTYPES (nis)
-DECLARE_NSS_PROTOTYPES (nisplus)
#undef DECLARE_NSS_PROTOTYPES
diff --git a/include/rpcsvc/yp_prot.h b/include/rpcsvc/yp_prot.h
deleted file mode 100644
index ab1ca10a28..0000000000
--- a/include/rpcsvc/yp_prot.h
+++ /dev/null
@@ -1 +0,0 @@
-#include
diff --git a/include/shadow.h b/include/shadow.h
index 366ea83482..5168d8d4a3 100644
--- a/include/shadow.h
+++ b/include/shadow.h
@@ -44,8 +44,6 @@ extern enum nss_status _nss_ ## service ## _getspnam_r \
DECLARE_NSS_PROTOTYPES (compat)
DECLARE_NSS_PROTOTYPES (files)
DECLARE_NSS_PROTOTYPES (hesiod)
-DECLARE_NSS_PROTOTYPES (nis)
-DECLARE_NSS_PROTOTYPES (nisplus)
#undef DECLARE_NSS_PROTOTYPES
diff --git a/manual/install.texi b/manual/install.texi
index c1e49a94fe..ea0059a4ec 100644
--- a/manual/install.texi
+++ b/manual/install.texi
@@ -257,16 +257,6 @@ This frontend allows users to specify tunables as a colon-separated list in a
single environment variable @env{GLIBC_TUNABLES}.
@end table
-@item --enable-obsolete-nsl
-By default, libnsl is only built as shared library for backward
-compatibility and the NSS modules libnss_compat, libnss_nis and
-libnss_nisplus are not built at all.
-Use this option to enable libnsl with all depending NSS modules and
-header files.
-For architectures and ABIs that have been added after version 2.28 of
-@theglibc{} this option is not available, and the libnsl compatibility
-library is not built.
-
@item --disable-crypt
Do not install the passphrase-hashing library @file{libcrypt} or the
header file @file{crypt.h}. @file{unistd.h} will still declare the
diff --git a/manual/nss.texi b/manual/nss.texi
index 821469a78a..80e730768e 100644
--- a/manual/nss.texi
+++ b/manual/nss.texi
@@ -328,17 +328,12 @@ For the @code{hosts} and @code{networks} databases the default value is
the DNS service not to be available but if it is available the answer it
returns is definitive.
-The @code{passwd}, @code{group}, and @code{shadow} databases are
+The @code{passwd}, @code{group}, and @code{shadow} databases was
traditionally handled in a special way. The appropriate files in the
-@file{/etc} directory are read but if an entry with a name starting
-with a @code{+} character is found NIS is used. This kind of lookup
-remains possible if @theglibc{} was configured with the
-@code{--enable-obsolete-nsl} option and the special lookup service
-@code{compat} is used. If @theglibc{} was configured with the
-@code{--enable-obsolete-nsl} option the default value for the three
-databases above is @code{compat [NOTFOUND=return] files}. If the
-@code{--enable-obsolete-nsl} option was not used the default value
-for the services is @code{files}.
+@file{/etc} directory were read but if an entry with a name starting
+with a @code{+} character was found NIS was used. This kind of lookup
+was removed and now the default value for the services is @code{files}.
+libnss_compat no longer depends on libnsl and can be used without NIS.
For all other databases the default value is @code{files} unless
@theglibc{} was configured with @code{--enable-obsolete-rpc} option, in
diff --git a/manual/nsswitch.texi b/manual/nsswitch.texi
index 62e7f607d1..a6ff3bed74 100644
--- a/manual/nsswitch.texi
+++ b/manual/nsswitch.texi
@@ -3,14 +3,14 @@
# Name Service Switch configuration file.
#
-passwd: db files nis
+passwd: db files
shadow: files
-group: db files nis
+group: db files
-hosts: files nisplus nis dns
-networks: nisplus [NOTFOUND=return] files
+hosts: files dns
+networks: files
-ethers: nisplus [NOTFOUND=return] db files
-protocols: nisplus [NOTFOUND=return] db files
-rpc: nisplus [NOTFOUND=return] db files
-services: nisplus [NOTFOUND=return] db files
+ethers: db files
+protocols: db files
+rpc: db files
+services: db files
diff --git a/nis/Makefile b/nis/Makefile
index 9ad5e1db7a..2d3c586890 100644
--- a/nis/Makefile
+++ b/nis/Makefile
@@ -22,40 +22,13 @@ subdir := nis
include ../Makeconfig
-ifndef have-GLIBC_2.28
-
-ifeq ($(build-obsolete-nsl),yes)
-$(error --enabe-obsolete-nsl is not available)
-endif
-
-else
-
-ifeq ($(build-obsolete-nsl),yes)
-headers := $(wildcard rpcsvc/*.[hx])
-
-# These are the databases available for the nis (and perhaps later nisplus)
-# service. This must be a superset of the services in nss.
-databases = proto service hosts network grp pwd rpc ethers \
- spwd netgrp alias
-
-# Specify rules for the nss_* modules.
-services := nis nisplus
-endif
+ifdef have-GLIBC_2.28
extra-libs = libnsl
-ifeq ($(build-obsolete-nsl),yes)
-extra-libs += $(services:%=libnss_%)
-endif
# These libraries will be built in the `others' pass rather than
# the `lib' pass, because they depend on libc.so being built already.
extra-libs-others = $(extra-libs)
-ifeq ($(build-obsolete-nsl),yes)
-# The sources are found in the appropriate subdir.
-subdir-dirs = $(services:%=nss_%)
-vpath %.c $(subdir-dirs)
-endif
-
libnsl-routines = yp_xdr ypclnt ypupdate_xdr \
nis_subr nis_local_names nis_free nis_file \
nis_print nis_error nis_call nis_lookup\
@@ -68,17 +41,6 @@ libnsl-routines = yp_xdr ypclnt ypupdate_xdr \
nis_findserv nis_callback nis_clone_dir nis_clone_obj\
nis_clone_res
-ifeq ($(build-obsolete-nsl),yes)
-libnsl-routines += nss-default
-libnss_nis-routines := $(addprefix nis-,$(databases)) nis-initgroups \
- nss-nis
-libnss_nis-inhibit-o = $(filter-out .os,$(object-suffixes))
-
-libnss_nisplus-routines := $(addprefix nisplus-,$(databases)) nisplus-parser \
- nss-nisplus nisplus-initgroups
-libnss_nisplus-inhibit-o = $(filter-out .os,$(object-suffixes))
-
-else # not $(build-obsolete-nsl)
# Pretend that libnsl.so is a linker script, so that the symbolic link
# is not installed.
install-lib-ldscripts = libnsl.so
@@ -86,31 +48,18 @@ $(inst_libdir)/libnsl.so:
# Build only shared libnsl.
libnsl-inhibit-o = $(filter-out .os,$(object-suffixes))
-endif # not $(build-obsolete-nsl)
-
endif # have-GLIBC_2.28
include ../Rules
-ifeq ($(build-obsolete-nsl),yes)
-$(objpfx)libnss_nis.so: $(objpfx)libnsl.so$(libnsl.so-version) \
- $(common-objpfx)nss/libnss_files.so
-$(objpfx)libnss_nisplus.so: $(objpfx)libnsl.so$(libnsl.so-version)
-endif
-
libnsl-libc = $(common-objpfx)linkobj/libc.so
# Target-specific variable setting to link objects using deprecated
# RPC interfaces with the version of libc.so that makes them available
# for new links:
-$(services:%=$(objpfx)libnss_%.so) $(objpfx)libnsl.so: \
- libc-for-link = $(libnsl-libc)
+$(objpfx)libnsl.so: libc-for-link = $(libnsl-libc)
ifeq ($(build-shared),yes)
$(others:%=$(objpfx)%): $(objpfx)libnsl.so$(libnsl.so-version)
-else
-ifeq ($(build-obsolete-nsl),yes)
-$(others:%=$(objpfx)%): $(objpfx)libnsl.a
-endif
endif
diff --git a/nis/Versions b/nis/Versions
index 90d3d9dfaa..9f8285fd05 100644
--- a/nis/Versions
+++ b/nis/Versions
@@ -58,63 +58,7 @@ libnsl {
xdr_ypall;
}
GLIBC_PRIVATE {
- _nsl_default_nss; __prepare_niscall; __follow_path; __do_niscall3;
+ __prepare_niscall; __follow_path; __do_niscall3;
__create_ib_request; _xdr_ib_request; _xdr_nis_result;
}
}
-
-libnss_nis {
- GLIBC_PRIVATE {
- _nss_nis_endaliasent; _nss_nis_endetherent; _nss_nis_endgrent;
- _nss_nis_endhostent; _nss_nis_endnetent; _nss_nis_endnetgrent;
- _nss_nis_endprotoent; _nss_nis_endpwent; _nss_nis_endrpcent;
- _nss_nis_endservent; _nss_nis_endspent; _nss_nis_getaliasbyname_r;
- _nss_nis_getaliasent_r; _nss_nis_getetherent_r; _nss_nis_getgrent_r;
- _nss_nis_getgrgid_r; _nss_nis_getgrnam_r; _nss_nis_gethostbyaddr_r;
- _nss_nis_gethostbyname2_r; _nss_nis_gethostbyname_r; _nss_nis_gethostent_r;
- _nss_nis_gethostton_r; _nss_nis_getnetbyaddr_r; _nss_nis_getnetbyname_r;
- _nss_nis_getnetent_r; _nss_nis_getnetgrent_r; _nss_nis_getntohost_r;
- _nss_nis_getprotobyname_r; _nss_nis_getprotobynumber_r;
- _nss_nis_getprotoent_r; _nss_nis_getpublickey; _nss_nis_getpwent_r;
- _nss_nis_getpwnam_r; _nss_nis_getpwuid_r; _nss_nis_getrpcbyname_r;
- _nss_nis_getrpcbynumber_r; _nss_nis_getrpcent_r; _nss_nis_getsecretkey;
- _nss_nis_getservbyname_r; _nss_nis_getservbyport_r; _nss_nis_getservent_r;
- _nss_nis_getspent_r; _nss_nis_getspnam_r;
- _nss_nis_netname2user; _nss_nis_setaliasent; _nss_nis_setetherent;
- _nss_nis_setgrent; _nss_nis_sethostent; _nss_nis_setnetent;
- _nss_nis_setnetgrent; _nss_nis_setprotoent; _nss_nis_setpwent;
- _nss_nis_setrpcent; _nss_nis_setservent; _nss_nis_setspent;
- _nss_nis_initgroups_dyn; _nss_nis_gethostbyname4_r;
- }
-}
-
-libnss_nisplus {
- GLIBC_PRIVATE {
- _nss_nisplus_endaliasent; _nss_nisplus_endetherent; _nss_nisplus_endgrent;
- _nss_nisplus_endhostent; _nss_nisplus_endnetent; _nss_nisplus_endnetgrent;
- _nss_nisplus_endprotoent; _nss_nisplus_endpwent; _nss_nisplus_endrpcent;
- _nss_nisplus_endservent; _nss_nisplus_endspent;
- _nss_nisplus_getaliasbyname_r; _nss_nisplus_getaliasent_r;
- _nss_nisplus_getetherent_r; _nss_nisplus_getgrent_r;
- _nss_nisplus_getgrgid_r; _nss_nisplus_getgrnam_r;
- _nss_nisplus_gethostbyaddr_r; _nss_nisplus_gethostbyname2_r;
- _nss_nisplus_gethostbyname_r; _nss_nisplus_gethostent_r;
- _nss_nisplus_gethostton_r; _nss_nisplus_getnetbyaddr_r;
- _nss_nisplus_getnetbyname_r; _nss_nisplus_getnetent_r;
- _nss_nisplus_getnetgrent_r; _nss_nisplus_getntohost_r;
- _nss_nisplus_getprotobyname_r; _nss_nisplus_getprotobynumber_r;
- _nss_nisplus_getprotoent_r; _nss_nisplus_getpublickey;
- _nss_nisplus_getpwent_r; _nss_nisplus_getpwnam_r; _nss_nisplus_getpwuid_r;
- _nss_nisplus_getrpcbyname_r; _nss_nisplus_getrpcbynumber_r;
- _nss_nisplus_getrpcent_r; _nss_nisplus_getsecretkey;
- _nss_nisplus_getservbyname_r; _nss_nisplus_getservbynumber_r;
- _nss_nisplus_getservent_r; _nss_nisplus_getspent_r;
- _nss_nisplus_getspnam_r; _nss_nisplus_netname2user;
- _nss_nisplus_setaliasent;
- _nss_nisplus_setetherent; _nss_nisplus_setgrent; _nss_nisplus_sethostent;
- _nss_nisplus_setnetent; _nss_nisplus_setnetgrent; _nss_nisplus_setprotoent;
- _nss_nisplus_setpwent; _nss_nisplus_setrpcent; _nss_nisplus_setservent;
- _nss_nisplus_setspent; _nss_nisplus_initgroups_dyn;
- _nss_nisplus_gethostbyname4_r;
- }
-}
diff --git a/nis/libnsl.h b/nis/libnsl.h
index 3c88c6ac73..64ca262579 100644
--- a/nis/libnsl.h
+++ b/nis/libnsl.h
@@ -23,9 +23,6 @@
#define NSS_FLAG_ADJUNCT_AS_SHADOW 8
-/* Get current set of default flags. */
-extern int _nsl_default_nss (void);
-
/* Set up everything for a call to __do_niscall3. */
extern nis_error __prepare_niscall (const_nis_name name, directory_obj **dirp,
dir_binding *bptrp, unsigned int flags);
diff --git a/nis/nisplus-parser.h b/nis/nisplus-parser.h
deleted file mode 100644
index 89bc901841..0000000000
--- a/nis/nisplus-parser.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/* Copyright (C) 1997-2020 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Thorsten Kukuk , 1997.
-
- 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
- . */
-
-#ifndef __NISPLUS_PARSER_H
-#define __NISPLUS_PARSER_H 1
-
-#include
-#include
-#include
-
-extern int _nss_nisplus_parse_pwent (nis_result *result, struct passwd *pw,
- char *buffer, size_t buflen, int *errnop);
-
-extern int _nss_nisplus_parse_grent (nis_result *result, struct group *gr,
- char *buffer, size_t buflen, int *errnop);
-
-extern int _nss_nisplus_parse_spent (nis_result *result, struct spwd *sp,
- char *buffer, size_t buflen, int *errnop);
-
-#endif
diff --git a/nis/nss-default.c b/nis/nss-default.c
deleted file mode 100644
index 7fb06461cd..0000000000
--- a/nis/nss-default.c
+++ /dev/null
@@ -1,127 +0,0 @@
-/* Copyright (C) 1996-2020 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
- . */
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include
-
-
-/* Path of the file. */
-static const char default_nss[] = "/etc/default/nss";
-
-/* Flags once read from the file. */
-static int default_nss_flags;
-
-/* Code to make sure we call 'init' once. */
-__libc_once_define (static, once);
-
-/* Table of the recognized variables. */
-static const struct
-{
- char name[23];
- unsigned int len;
- int flag;
-} vars[] =
- {
-#define STRNLEN(s) s, sizeof (s) - 1
- { STRNLEN ("NETID_AUTHORITATIVE"), NSS_FLAG_NETID_AUTHORITATIVE },
- { STRNLEN ("SERVICES_AUTHORITATIVE"), NSS_FLAG_SERVICES_AUTHORITATIVE },
- { STRNLEN ("SETENT_BATCH_READ"), NSS_FLAG_SETENT_BATCH_READ },
- { STRNLEN ("ADJUNCT_AS_SHADOW"), NSS_FLAG_ADJUNCT_AS_SHADOW },
- };
-#define nvars (sizeof (vars) / sizeof (vars[0]))
-
-
-static void
-init (void)
-{
- int saved_errno = errno;
- FILE *fp = fopen (default_nss, "rce");
- if (fp != NULL)
- {
- char *line = NULL;
- size_t linelen = 0;
-
- __fsetlocking (fp, FSETLOCKING_BYCALLER);
-
- while (!feof_unlocked (fp))
- {
- ssize_t n = getline (&line, &linelen, fp);
- if (n <= 0)
- break;
-
- /* Recognize only
-
- = TRUE
-
- with arbitrary white spaces. */
- char *cp = line;
- while (isspace (*cp))
- ++cp;
-
- /* Recognize comment lines. */
- if (*cp == '#')
- continue;
-
- int idx;
- for (idx = 0; idx < nvars; ++idx)
- if (strncmp (cp, vars[idx].name, vars[idx].len) == 0)
- break;
- if (idx == nvars)
- continue;
-
- cp += vars[idx].len;
- while (isspace (*cp))
- ++cp;
- if (*cp++ != '=')
- continue;
- while (isspace (*cp))
- ++cp;
-
- if (strncmp (cp, "TRUE", 4) != 0)
- continue;
- cp += 4;
-
- while (isspace (*cp))
- ++cp;
-
- if (*cp == '\0')
- default_nss_flags |= vars[idx].flag;
- }
-
- free (line);
-
- fclose (fp);
- }
- __set_errno (saved_errno);
-}
-
-
-int
-_nsl_default_nss (void)
-{
- /* If we have not yet read the file yet do it now. */
- __libc_once (once, init);
-
- return default_nss_flags;
-}
diff --git a/nis/nss-nis.c b/nis/nss-nis.c
deleted file mode 100644
index f496017a27..0000000000
--- a/nis/nss-nis.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/* Copyright (C) 1996-2020 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
- . */
-
-#include "nss-nis.h"
-#include "nsswitch.h"
-
-
-/* Convert YP error number to NSS error number. */
-const enum nss_status __yperr2nss_tab[] =
-{
- [YPERR_SUCCESS] = NSS_STATUS_SUCCESS,
- [YPERR_BADARGS] = NSS_STATUS_UNAVAIL,
- [YPERR_RPC] = NSS_STATUS_UNAVAIL,
- [YPERR_DOMAIN] = NSS_STATUS_UNAVAIL,
- [YPERR_MAP] = NSS_STATUS_UNAVAIL,
- [YPERR_KEY] = NSS_STATUS_NOTFOUND,
- [YPERR_YPERR] = NSS_STATUS_UNAVAIL,
- [YPERR_RESRC] = NSS_STATUS_TRYAGAIN,
- [YPERR_NOMORE] = NSS_STATUS_NOTFOUND,
- [YPERR_PMAP] = NSS_STATUS_UNAVAIL,
- [YPERR_YPBIND] = NSS_STATUS_UNAVAIL,
- [YPERR_YPSERV] = NSS_STATUS_UNAVAIL,
- [YPERR_NODOM] = NSS_STATUS_UNAVAIL,
- [YPERR_BADDB] = NSS_STATUS_UNAVAIL,
- [YPERR_VERS] = NSS_STATUS_UNAVAIL,
- [YPERR_ACCESS] = NSS_STATUS_UNAVAIL,
- [YPERR_BUSY] = NSS_STATUS_TRYAGAIN
-};
-const unsigned int __yperr2nss_count = (sizeof (__yperr2nss_tab)
- / sizeof (__yperr2nss_tab[0]));
diff --git a/nis/nss-nis.h b/nis/nss-nis.h
deleted file mode 100644
index 7c009d7e87..0000000000
--- a/nis/nss-nis.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/* Copyright (C) 1996-2020 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
- . */
-
-#ifndef _NIS_NSS_NIS_H
-#define _NIS_NSS_NIS_H 1
-
-#include
-
-#include "nsswitch.h"
-
-NSS_DECLARE_MODULE_FUNCTIONS (nis)
-
-/* Convert YP error number to NSS error number. */
-extern const enum nss_status __yperr2nss_tab[] attribute_hidden;
-extern const unsigned int __yperr2nss_count attribute_hidden;
-
-static inline enum nss_status
-yperr2nss (int errval)
-{
- if ((unsigned int) errval >= __yperr2nss_count)
- return NSS_STATUS_UNAVAIL;
- return __yperr2nss_tab[(unsigned int) errval];
-}
-
-
-struct response_t
-{
- struct response_t *next;
- size_t size;
- char mem[0];
-};
-
-typedef struct intern_t
-{
- struct response_t *start;
- struct response_t *next;
- size_t offset;
-} intern_t;
-
-
-extern int _nis_saveit (int instatus, char *inkey, int inkeylen, char *inval,
- int invallen, char *indata) attribute_hidden;
-
-
-#endif /* nis/nss-nis.h */
diff --git a/nis/nss-nisplus.c b/nis/nss-nisplus.c
deleted file mode 100644
index 70cc7b939e..0000000000
--- a/nis/nss-nisplus.c
+++ /dev/null
@@ -1,78 +0,0 @@
-/* Copyright (C) 1997-2020 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Thorsten Kukuk , 1997.
-
- 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
- . */
-
-#include
-
-#include "nss-nisplus.h"
-#include "nsswitch.h"
-
-
-/* Convert NIS+ error number to NSS error number. */
-const enum nss_status __niserr2nss_tab[] =
-{
- [NIS_SUCCESS] = NSS_STATUS_SUCCESS,
- [NIS_S_SUCCESS] = NSS_STATUS_SUCCESS,
- [NIS_NOTFOUND] = NSS_STATUS_NOTFOUND,
- [NIS_S_NOTFOUND] = NSS_STATUS_NOTFOUND,
- [NIS_CACHEEXPIRED] = NSS_STATUS_UNAVAIL,
- [NIS_NAMEUNREACHABLE] = NSS_STATUS_UNAVAIL,
- [NIS_UNKNOWNOBJ] = NSS_STATUS_NOTFOUND,
- [NIS_TRYAGAIN] = NSS_STATUS_TRYAGAIN,
- [NIS_SYSTEMERROR] = NSS_STATUS_UNAVAIL,
- [NIS_CHAINBROKEN] = NSS_STATUS_UNAVAIL,
- [NIS_PERMISSION] = NSS_STATUS_UNAVAIL,
- [NIS_NOTOWNER] = NSS_STATUS_UNAVAIL,
- [NIS_NOT_ME] = NSS_STATUS_UNAVAIL,
- [NIS_NOMEMORY] = NSS_STATUS_TRYAGAIN,
- [NIS_NAMEEXISTS] = NSS_STATUS_UNAVAIL,
- [NIS_NOTMASTER] = NSS_STATUS_UNAVAIL,
- [NIS_INVALIDOBJ] = NSS_STATUS_UNAVAIL,
- [NIS_BADNAME] = NSS_STATUS_UNAVAIL,
- [NIS_NOCALLBACK] = NSS_STATUS_UNAVAIL,
- [NIS_CBRESULTS] = NSS_STATUS_UNAVAIL,
- [NIS_NOSUCHNAME] = NSS_STATUS_NOTFOUND,
- [NIS_NOTUNIQUE] = NSS_STATUS_UNAVAIL,
- [NIS_IBMODERROR] = NSS_STATUS_UNAVAIL,
- [NIS_NOSUCHTABLE] = NSS_STATUS_UNAVAIL,
- [NIS_TYPEMISMATCH] = NSS_STATUS_UNAVAIL,
- [NIS_LINKNAMEERROR] = NSS_STATUS_UNAVAIL,
- [NIS_PARTIAL] = NSS_STATUS_NOTFOUND,
- [NIS_TOOMANYATTRS] = NSS_STATUS_UNAVAIL,
- [NIS_RPCERROR] = NSS_STATUS_UNAVAIL,
- [NIS_BADATTRIBUTE] = NSS_STATUS_UNAVAIL,
- [NIS_NOTSEARCHABLE] = NSS_STATUS_UNAVAIL,
- [NIS_CBERROR] = NSS_STATUS_UNAVAIL,
- [NIS_FOREIGNNS] = NSS_STATUS_UNAVAIL,
- [NIS_BADOBJECT] = NSS_STATUS_UNAVAIL,
- [NIS_NOTSAMEOBJ] = NSS_STATUS_UNAVAIL,
- [NIS_MODFAIL] = NSS_STATUS_UNAVAIL,
- [NIS_BADREQUEST] = NSS_STATUS_UNAVAIL,
- [NIS_NOTEMPTY] = NSS_STATUS_UNAVAIL,
- [NIS_COLDSTART_ERR] = NSS_STATUS_UNAVAIL,
- [NIS_RESYNC] = NSS_STATUS_UNAVAIL,
- [NIS_FAIL] = NSS_STATUS_UNAVAIL,
- [NIS_UNAVAIL] = NSS_STATUS_UNAVAIL,
- [NIS_RES2BIG] = NSS_STATUS_UNAVAIL,
- [NIS_SRVAUTH] = NSS_STATUS_UNAVAIL,
- [NIS_CLNTAUTH] = NSS_STATUS_UNAVAIL,
- [NIS_NOFILESPACE] = NSS_STATUS_UNAVAIL,
- [NIS_NOPROC] = NSS_STATUS_UNAVAIL,
- [NIS_DUMPLATER] = NSS_STATUS_UNAVAIL
-};
-const unsigned int __niserr2nss_count = (sizeof (__niserr2nss_tab)
- / sizeof (__niserr2nss_tab[0]));
diff --git a/nis/nss-nisplus.h b/nis/nss-nisplus.h
deleted file mode 100644
index 92c67880b9..0000000000
--- a/nis/nss-nisplus.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/* Copyright (C) 1997-2020 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Thorsten Kukuk , 1997.
-
- 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
- . */
-
-#ifndef _NIS_NSS_NISPLUS_H
-#define _NIS_NSS_NISPLUS_H 1
-
-#include
-
-#include "nsswitch.h"
-
-NSS_DECLARE_MODULE_FUNCTIONS (nisplus)
-
-/* Convert NIS+ error number to NSS error number. */
-extern const enum nss_status __niserr2nss_tab[] attribute_hidden;
-extern const unsigned int __niserr2nss_count attribute_hidden;
-
-static enum nss_status
-__attribute__ ((unused))
-niserr2nss (int errval)
-{
- if ((unsigned int) errval >= __niserr2nss_count)
- return NSS_STATUS_UNAVAIL;
- return __niserr2nss_tab[(unsigned int) errval];
-}
-
-#endif /* nis/nss-nisplus.h */
diff --git a/nis/nss_nis/nis-alias.c b/nis/nss_nis/nis-alias.c
deleted file mode 100644
index b8f83b94b7..0000000000
--- a/nis/nss_nis/nis-alias.c
+++ /dev/null
@@ -1,281 +0,0 @@
-/* Copyright (C) 1996-2020 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Thorsten Kukuk , 1996.
-
- 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
- . */
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "nss-nis.h"
-
-__libc_lock_define_initialized (static, lock)
-
-static bool_t new_start = 1;
-static char *oldkey;
-static int oldkeylen;
-
-static int
-_nss_nis_parse_aliasent (const char *key, char *alias, struct aliasent *result,
- char *buffer, size_t buflen, int *errnop)
-{
- char *first_unused = buffer + strlen (alias) + 1;
- size_t room_left =
- buflen - (buflen % __alignof__ (char *)) - strlen (alias) - 2;
- char *line;
- char *cp;
-
- result->alias_members_len = 0;
- *first_unused = '\0';
- first_unused++;
- strcpy (first_unused, key);
-
- if (first_unused[room_left - 1] != '\0')
- {
- /* The line is too long for our buffer. */
- no_more_room:
- *errnop = ERANGE;
- return -1;
- }
-
- result->alias_name = first_unused;
-
- /* Terminate the line for any case. */
- cp = strpbrk (alias, "#\n");
- if (cp != NULL)
- *cp = '\0';
-
- first_unused += strlen (result->alias_name) + 1;
- /* Adjust the pointer so it is aligned for
- storing pointers. */
- first_unused += __alignof__ (char *) - 1;
- first_unused -= ((first_unused - (char *) 0) % __alignof__ (char *));
- result->alias_members = (char **) first_unused;
-
- line = alias;
-
- while (*line != '\0')
- {
- /* Skip leading blanks. */
- while (isspace (*line))
- line++;
-
- if (*line == '\0')
- break;
-
- if (room_left < sizeof (char *))
- goto no_more_room;
- room_left -= sizeof (char *);
- result->alias_members[result->alias_members_len] = line;
-
- while (*line != '\0' && *line != ',')
- line++;
-
- if (line != result->alias_members[result->alias_members_len])
- {
- *line = '\0';
- line++;
- result->alias_members_len++;
- }
- }
- return result->alias_members_len == 0 ? 0 : 1;
-}
-
-enum nss_status
-_nss_nis_setaliasent (void)
-{
- __libc_lock_lock (lock);
-
- new_start = 1;
- if (oldkey != NULL)
- {
- free (oldkey);
- oldkey = NULL;
- oldkeylen = 0;
- }
-
- __libc_lock_unlock (lock);
-
- return NSS_STATUS_SUCCESS;
-}
-/* The 'endaliasent' function is identical. */
-strong_alias (_nss_nis_setaliasent, _nss_nis_endaliasent)
-
-static enum nss_status
-internal_nis_getaliasent_r (struct aliasent *alias, char *buffer,
- size_t buflen, int *errnop)
-{
- char *domain;
-
- if (__glibc_unlikely (yp_get_default_domain (&domain)))
- return NSS_STATUS_UNAVAIL;
-
- alias->alias_local = 0;
-
- /* Get the next entry until we found a correct one. */
- int parse_res;
- do
- {
- char *result;
- int len;
- char *outkey;
- int keylen;
- int yperr;
-
- if (new_start)
- yperr = yp_first (domain, "mail.aliases", &outkey, &keylen, &result,
- &len);
- else
- yperr = yp_next (domain, "mail.aliases", oldkey, oldkeylen, &outkey,
- &keylen, &result, &len);
-
- if (__glibc_unlikely (yperr != YPERR_SUCCESS))
- {
- enum nss_status retval = yperr2nss (yperr);
-
- if (retval == NSS_STATUS_TRYAGAIN)
- *errnop = errno;
- return retval;
- }
-
- if (__glibc_unlikely ((size_t) (len + 1) > buflen))
- {
- free (result);
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
- char *p = strncpy (buffer, result, len);
- buffer[len] = '\0';
- while (isspace (*p))
- ++p;
- free (result);
-
- parse_res = _nss_nis_parse_aliasent (outkey, p, alias, buffer,
- buflen, errnop);
- if (__glibc_unlikely (parse_res == -1))
- {
- free (outkey);
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- free (oldkey);
- oldkey = outkey;
- oldkeylen = keylen;
- new_start = 0;
- }
- while (!parse_res);
-
- return NSS_STATUS_SUCCESS;
-}
-
-enum nss_status
-_nss_nis_getaliasent_r (struct aliasent *alias, char *buffer, size_t buflen,
- int *errnop)
-{
- enum nss_status status;
-
- __libc_lock_lock (lock);
-
- status = internal_nis_getaliasent_r (alias, buffer, buflen, errnop);
-
- __libc_lock_unlock (lock);
-
- return status;
-}
-
-enum nss_status
-_nss_nis_getaliasbyname_r (const char *name, struct aliasent *alias,
- char *buffer, size_t buflen, int *errnop)
-{
- if (name == NULL)
- {
- *errnop = EINVAL;
- return NSS_STATUS_UNAVAIL;
- }
-
- char *domain;
- if (__glibc_unlikely (yp_get_default_domain (&domain)))
- return NSS_STATUS_UNAVAIL;
-
- size_t namlen = strlen (name);
- char *name2;
- int use_alloca = __libc_use_alloca (namlen + 1);
- if (use_alloca)
- name2 = __alloca (namlen + 1);
- else
- {
- name2 = malloc (namlen + 1);
- if (name2 == NULL)
- {
- *errnop = ENOMEM;
- return NSS_STATUS_TRYAGAIN;
- }
- }
-
- /* Convert name to lowercase. */
- size_t i;
- for (i = 0; i < namlen; ++i)
- name2[i] = _tolower (name[i]);
- name2[i] = '\0';
-
- char *result;
- int len;
- int yperr = yp_match (domain, "mail.aliases", name2, namlen, &result, &len);
-
- if (!use_alloca)
- free (name2);
-
- if (__glibc_unlikely (yperr != YPERR_SUCCESS))
- {
- enum nss_status retval = yperr2nss (yperr);
-
- if (retval == NSS_STATUS_TRYAGAIN)
- *errnop = errno;
- return retval;
- }
-
- if (__glibc_unlikely ((size_t) (len + 1) > buflen))
- {
- free (result);
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- char *p = strncpy (buffer, result, len);
- buffer[len] = '\0';
- while (isspace (*p))
- ++p;
- free (result);
-
- alias->alias_local = 0;
- int parse_res = _nss_nis_parse_aliasent (name, p, alias, buffer, buflen,
- errnop);
- if (__glibc_unlikely (parse_res < 1))
- {
- if (parse_res == -1)
- return NSS_STATUS_TRYAGAIN;
- else
- return NSS_STATUS_NOTFOUND;
- }
-
- return NSS_STATUS_SUCCESS;
-}
diff --git a/nis/nss_nis/nis-ethers.c b/nis/nss_nis/nis-ethers.c
deleted file mode 100644
index c7441ff6b5..0000000000
--- a/nis/nss_nis/nis-ethers.c
+++ /dev/null
@@ -1,292 +0,0 @@
-/* Copyright (C) 1996-2020 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Thorsten Kukuk , 1996.
-
- 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
- . */
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "nss-nis.h"
-
-/* Protect global state against multiple changers */
-__libc_lock_define_initialized (static, lock)
-
-/* Get the declaration of the parser function. */
-#define ENTNAME etherent
-#define STRUCTURE etherent
-#define EXTERN_PARSER
-#include
-
-struct response
-{
- struct response *next;
- char val[0];
-};
-
-static struct response *start;
-static struct response *next;
-
-static int
-saveit (int instatus, char *inkey, int inkeylen, char *inval,
- int invallen, char *indata)
-{
- if (instatus != YP_TRUE)
- return 1;
-
- if (inkey && inkeylen > 0 && inval && invallen > 0)
- {
- struct response *newp = malloc (sizeof (struct response) + invallen + 1);
- if (newp == NULL)
- return 1; /* We have no error code for out of memory */
-
- if (start == NULL)
- start = newp;
- else
- next->next = newp;
- next = newp;
-
- newp->next = NULL;
- *((char *) mempcpy (newp->val, inval, invallen)) = '\0';
- }
-
- return 0;
-}
-
-static void
-internal_nis_endetherent (void)
-{
- while (start != NULL)
- {
- next = start;
- start = start->next;
- free (next);
- }
-}
-
-enum nss_status
-_nss_nis_endetherent (void)
-{
- __libc_lock_lock (lock);
-
- internal_nis_endetherent ();
- next = NULL;
-
- __libc_lock_unlock (lock);
-
- return NSS_STATUS_SUCCESS;
-}
-
-static enum nss_status
-internal_nis_setetherent (void)
-{
- char *domainname;
- struct ypall_callback ypcb;
- enum nss_status status;
-
- yp_get_default_domain (&domainname);
-
- internal_nis_endetherent ();
-
- ypcb.foreach = saveit;
- ypcb.data = NULL;
- status = yperr2nss (yp_all (domainname, "ethers.byname", &ypcb));
- next = start;
-
- return status;
-}
-
-enum nss_status
-_nss_nis_setetherent (int stayopen)
-{
- enum nss_status result;
-
- __libc_lock_lock (lock);
-
- result = internal_nis_setetherent ();
-
- __libc_lock_unlock (lock);
-
- return result;
-}
-
-static enum nss_status
-internal_nis_getetherent_r (struct etherent *eth, char *buffer, size_t buflen,
- int *errnop)
-{
- struct parser_data *data = (void *) buffer;
- int parse_res;
-
- if (start == NULL)
- internal_nis_setetherent ();
-
- /* Get the next entry until we found a correct one. */
- do
- {
- char *p;
-
- if (next == NULL)
- return NSS_STATUS_NOTFOUND;
-
- p = strncpy (buffer, next->val, buflen);
-
- while (isspace (*p))
- ++p;
-
- parse_res = _nss_files_parse_etherent (p, eth, data, buflen, errnop);
- if (parse_res == -1)
- return NSS_STATUS_TRYAGAIN;
- next = next->next;
- }
- while (!parse_res);
-
- return NSS_STATUS_SUCCESS;
-}
-
-enum nss_status
-_nss_nis_getetherent_r (struct etherent *result, char *buffer, size_t buflen,
- int *errnop)
-{
- int status;
-
- __libc_lock_lock (lock);
-
- status = internal_nis_getetherent_r (result, buffer, buflen, errnop);
-
- __libc_lock_unlock (lock);
-
- return status;
-}
-
-enum nss_status
-_nss_nis_gethostton_r (const char *name, struct etherent *eth,
- char *buffer, size_t buflen, int *errnop)
-{
- if (name == NULL)
- {
- *errnop = EINVAL;
- return NSS_STATUS_UNAVAIL;
- }
-
- char *domain;
- if (__glibc_unlikely (yp_get_default_domain (&domain)))
- return NSS_STATUS_UNAVAIL;
-
- char *result;
- int len;
- int yperr = yp_match (domain, "ethers.byname", name, strlen (name), &result,
- &len);
-
- if (__glibc_unlikely (yperr != YPERR_SUCCESS))
- {
- enum nss_status retval = yperr2nss (yperr);
-
- if (retval == NSS_STATUS_TRYAGAIN)
- *errnop = errno;
- return retval;
- }
-
- if (__glibc_unlikely ((size_t) (len + 1) > buflen))
- {
- free (result);
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- char *p = strncpy (buffer, result, len);
- buffer[len] = '\0';
- while (isspace (*p))
- ++p;
- free (result);
-
- int parse_res = _nss_files_parse_etherent (p, eth, (void *) buffer, buflen,
- errnop);
- if (__glibc_unlikely (parse_res < 1))
- {
- if (parse_res == -1)
- return NSS_STATUS_TRYAGAIN;
- else
- return NSS_STATUS_NOTFOUND;
- }
- return NSS_STATUS_SUCCESS;
-}
-
-enum nss_status
-_nss_nis_getntohost_r (const struct ether_addr *addr, struct etherent *eth,
- char *buffer, size_t buflen, int *errnop)
-{
- if (addr == NULL)
- {
- *errnop = EINVAL;
- return NSS_STATUS_UNAVAIL;
- }
-
- char *domain;
- if (__glibc_unlikely (yp_get_default_domain (&domain)))
- return NSS_STATUS_UNAVAIL;
-
- char buf[33];
- int nlen = snprintf (buf, sizeof (buf), "%x:%x:%x:%x:%x:%x",
- (int) addr->ether_addr_octet[0],
- (int) addr->ether_addr_octet[1],
- (int) addr->ether_addr_octet[2],
- (int) addr->ether_addr_octet[3],
- (int) addr->ether_addr_octet[4],
- (int) addr->ether_addr_octet[5]);
-
- char *result;
- int len;
- int yperr = yp_match (domain, "ethers.byaddr", buf, nlen, &result, &len);
-
- if (__glibc_unlikely (yperr != YPERR_SUCCESS))
- {
- enum nss_status retval = yperr2nss (yperr);
-
- if (retval == NSS_STATUS_TRYAGAIN)
- *errnop = errno;
- return retval;
- }
-
- if (__glibc_unlikely ((size_t) (len + 1) > buflen))
- {
- free (result);
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- char *p = strncpy (buffer, result, len);
- buffer[len] = '\0';
- while (isspace (*p))
- ++p;
- free (result);
-
- int parse_res = _nss_files_parse_etherent (p, eth, (void *) buffer, buflen,
- errnop);
- if (__glibc_unlikely (parse_res < 1))
- {
- if (parse_res == -1)
- return NSS_STATUS_TRYAGAIN;
- else
- return NSS_STATUS_NOTFOUND;
- }
- return NSS_STATUS_SUCCESS;
-}
diff --git a/nis/nss_nis/nis-grp.c b/nis/nss_nis/nis-grp.c
deleted file mode 100644
index 74a8f82f9a..0000000000
--- a/nis/nss_nis/nis-grp.c
+++ /dev/null
@@ -1,359 +0,0 @@
-/* Copyright (C) 1996-2020 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Thorsten Kukuk , 1996.
-
- 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
- . */
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "nss-nis.h"
-#include
-
-/* Get the declaration of the parser function. */
-#define ENTNAME grent
-#define STRUCTURE group
-#define EXTERN_PARSER
-#include
-
-/* Protect global state against multiple changers */
-__libc_lock_define_initialized (static, lock)
-
-static bool_t new_start = 1;
-static char *oldkey;
-static int oldkeylen;
-static intern_t intern;
-
-
-static void
-internal_nis_endgrent (void)
-{
- new_start = 1;
- if (oldkey != NULL)
- {
- free (oldkey);
- oldkey = NULL;
- oldkeylen = 0;
- }
-
- struct response_t *curr = intern.start;
-
- while (curr != NULL)
- {
- struct response_t *last = curr;
- curr = curr->next;
- free (last);
- }
-
- intern.next = intern.start = NULL;
-}
-
-
-enum nss_status
-_nss_nis_endgrent (void)
-{
- __libc_lock_lock (lock);
-
- internal_nis_endgrent ();
-
- __libc_lock_unlock (lock);
-
- return NSS_STATUS_SUCCESS;
-}
-
-
-enum nss_status
-internal_nis_setgrent (void)
-{
- /* We have to read all the data now. */
- char *domain;
- if (__glibc_unlikely (yp_get_default_domain (&domain)))
- return NSS_STATUS_UNAVAIL;
-
- struct ypall_callback ypcb;
-
- ypcb.foreach = _nis_saveit;
- ypcb.data = (char *) &intern;
- enum nss_status status = yperr2nss (yp_all (domain, "group.byname", &ypcb));
-
-
- /* Mark the last buffer as full. */
- if (intern.next != NULL)
- intern.next->size = intern.offset;
-
- intern.next = intern.start;
- intern.offset = 0;
-
- return status;
-}
-
-
-enum nss_status
-_nss_nis_setgrent (int stayopen)
-{
- enum nss_status result = NSS_STATUS_SUCCESS;
-
- __libc_lock_lock (lock);
-
- internal_nis_endgrent ();
-
- if (_nsl_default_nss () & NSS_FLAG_SETENT_BATCH_READ)
- result = internal_nis_setgrent ();
-
- __libc_lock_unlock (lock);
-
- return result;
-}
-
-
-static enum nss_status
-internal_nis_getgrent_r (struct group *grp, char *buffer, size_t buflen,
- int *errnop)
-{
- /* If we read the entire database at setpwent time we just iterate
- over the data we have in memory. */
- bool batch_read = intern.start != NULL;
-
- char *domain = NULL;
- if (!batch_read && __builtin_expect (yp_get_default_domain (&domain), 0))
- return NSS_STATUS_UNAVAIL;
-
- /* Get the next entry until we found a correct one. */
- int parse_res;
- do
- {
- char *result;
- char *outkey;
- int len;
- int keylen;
-
- if (batch_read)
- {
- struct response_t *bucket;
-
- handle_batch_read:
- bucket = intern.next;
-
- if (__glibc_unlikely (intern.offset >= bucket->size))
- {
- if (bucket->next == NULL)
- return NSS_STATUS_NOTFOUND;
-
- /* We look at all the content in the current bucket. Go on
- to the next. */
- bucket = intern.next = bucket->next;
- intern.offset = 0;
- }
-
- for (result = &bucket->mem[intern.offset]; isspace (*result);
- ++result)
- ++intern.offset;
-
- len = strlen (result);
- }
- else
- {
- int yperr;
-
- if (new_start)
- {
- /* Maybe we should read the database in one piece. */
- if ((_nsl_default_nss () & NSS_FLAG_SETENT_BATCH_READ)
- && internal_nis_setgrent () == NSS_STATUS_SUCCESS
- && intern.start != NULL)
- {
- batch_read = true;
- goto handle_batch_read;
- }
-
- yperr = yp_first (domain, "group.byname", &outkey, &keylen,
- &result, &len);
- }
- else
- yperr = yp_next (domain, "group.byname", oldkey, oldkeylen,
- &outkey, &keylen, &result, &len);
-
- if (__glibc_unlikely (yperr != YPERR_SUCCESS))
- {
- enum nss_status retval = yperr2nss (yperr);
-
- if (retval == NSS_STATUS_TRYAGAIN)
- *errnop = errno;
- return retval;
- }
- }
-
- if (__glibc_unlikely ((size_t) (len + 1) > buflen))
- {
- if (!batch_read)
- free (result);
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- char *p = strncpy (buffer, result, len);
- buffer[len] = '\0';
- while (isspace (*p))
- ++p;
- if (!batch_read)
- free (result);
-
- parse_res = _nss_files_parse_grent (p, grp, (void *) buffer, buflen,
- errnop);
- if (__glibc_unlikely (parse_res == -1))
- {
- if (!batch_read)
- free (outkey);
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- if (batch_read)
- intern.offset += len + 1;
- else
- {
- free (oldkey);
- oldkey = outkey;
- oldkeylen = keylen;
- new_start = 0;
- }
- }
- while (parse_res < 1);
-
- return NSS_STATUS_SUCCESS;
-}
-
-enum nss_status
-_nss_nis_getgrent_r (struct group *result, char *buffer, size_t buflen,
- int *errnop)
-{
- int status;
-
- __libc_lock_lock (lock);
-
- status = internal_nis_getgrent_r (result, buffer, buflen, errnop);
-
- __libc_lock_unlock (lock);
-
- return status;
-}
-
-enum nss_status
-_nss_nis_getgrnam_r (const char *name, struct group *grp,
- char *buffer, size_t buflen, int *errnop)
-{
- if (name == NULL)
- {
- *errnop = EINVAL;
- return NSS_STATUS_UNAVAIL;
- }
-
- char *domain;
- if (__glibc_unlikely (yp_get_default_domain (&domain)))
- return NSS_STATUS_UNAVAIL;
-
- char *result;
- int len;
- int yperr = yp_match (domain, "group.byname", name, strlen (name), &result,
- &len);
-
- if (__glibc_unlikely (yperr != YPERR_SUCCESS))
- {
- enum nss_status retval = yperr2nss (yperr);
-
- if (retval == NSS_STATUS_TRYAGAIN)
- *errnop = errno;
- return retval;
- }
-
- if (__glibc_unlikely ((size_t) (len + 1) > buflen))
- {
- free (result);
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- char *p = strncpy (buffer, result, len);
- buffer[len] = '\0';
- while (isspace (*p))
- ++p;
- free (result);
-
- int parse_res = _nss_files_parse_grent (p, grp, (void *) buffer, buflen,
- errnop);
- if (__builtin_expect (parse_res < 1, 0))
- {
- if (parse_res == -1)
- return NSS_STATUS_TRYAGAIN;
- else
- return NSS_STATUS_NOTFOUND;
- }
- return NSS_STATUS_SUCCESS;
-}
-
-enum nss_status
-_nss_nis_getgrgid_r (gid_t gid, struct group *grp,
- char *buffer, size_t buflen, int *errnop)
-{
- char *domain;
- if (__glibc_unlikely (yp_get_default_domain (&domain)))
- return NSS_STATUS_UNAVAIL;
-
- char buf[32];
- int nlen = sprintf (buf, "%lu", (unsigned long int) gid);
-
- char *result;
- int len;
- int yperr = yp_match (domain, "group.bygid", buf, nlen, &result, &len);
-
- if (__glibc_unlikely (yperr != YPERR_SUCCESS))
- {
- enum nss_status retval = yperr2nss (yperr);
-
- if (retval == NSS_STATUS_TRYAGAIN)
- *errnop = errno;
- return retval;
- }
-
- if (__glibc_unlikely ((size_t) (len + 1) > buflen))
- {
- free (result);
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- char *p = strncpy (buffer, result, len);
- buffer[len] = '\0';
- while (isspace (*p))
- ++p;
- free (result);
-
- int parse_res = _nss_files_parse_grent (p, grp, (void *) buffer, buflen,
- errnop);
- if (__glibc_unlikely (parse_res < 1))
- {
- if (parse_res == -1)
- return NSS_STATUS_TRYAGAIN;
- else
- return NSS_STATUS_NOTFOUND;
- }
- return NSS_STATUS_SUCCESS;
-}
diff --git a/nis/nss_nis/nis-hosts.c b/nis/nss_nis/nis-hosts.c
deleted file mode 100644
index eb074783f7..0000000000
--- a/nis/nss_nis/nis-hosts.c
+++ /dev/null
@@ -1,535 +0,0 @@
-/* Copyright (C) 1996-2020 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Thorsten Kukuk , 1996.
-
- 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
- . */
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "nss-nis.h"
-
-#define ENTNAME hostent
-#define DATABASE "hosts"
-#define NEED_H_ERRNO
-
-#define EXTRA_ARGS , af
-#define EXTRA_ARGS_DECL , int af
-
-#define ENTDATA hostent_data
-struct hostent_data
- {
- unsigned char host_addr[16]; /* IPv4 or IPv6 address. */
- char *h_addr_ptrs[2]; /* Points to that and null terminator. */
- };
-
-#define TRAILING_LIST_MEMBER h_aliases
-#define TRAILING_LIST_SEPARATOR_P isspace
-#include
-LINE_PARSER
-("#",
- {
- char *addr;
-
- STRING_FIELD (addr, isspace, 1);
-
- assert (af == AF_INET || af == AF_INET6 || af == AF_UNSPEC);
-
- /* Parse address. */
- if (af != AF_INET6 && inet_pton (AF_INET, addr, entdata->host_addr) > 0)
- {
- result->h_addrtype = AF_INET;
- result->h_length = INADDRSZ;
- }
- else if (af != AF_INET
- && inet_pton (AF_INET6, addr, entdata->host_addr) > 0)
- {
- result->h_addrtype = AF_INET6;
- result->h_length = IN6ADDRSZ;
- }
- else
- /* Illegal address: ignore line. */
- return 0;
-
- /* Store a pointer to the address in the expected form. */
- entdata->h_addr_ptrs[0] = (char *) entdata->host_addr;
- entdata->h_addr_ptrs[1] = NULL;
- result->h_addr_list = entdata->h_addr_ptrs;
-
- STRING_FIELD (result->h_name, isspace, 1);
- })
-
-
-__libc_lock_define_initialized (static, lock)
-
-static bool_t new_start = 1;
-static char *oldkey = NULL;
-static int oldkeylen = 0;
-
-enum nss_status
-_nss_nis_sethostent (int stayopen)
-{
- return _nss_nis_endhostent ();
-}
-
-enum nss_status
-_nss_nis_endhostent (void)
-{
- __libc_lock_lock (lock);
-
- new_start = 1;
- if (oldkey != NULL)
- {
- free (oldkey);
- oldkey = NULL;
- oldkeylen = 0;
- }
-
- __libc_lock_unlock (lock);
-
- return NSS_STATUS_SUCCESS;
-}
-libnss_nis_hidden_def (_nss_nis_endhostent)
-
-/* The calling function always need to get a lock first. */
-static enum nss_status
-internal_nis_gethostent_r (struct hostent *host, char *buffer,
- size_t buflen, int *errnop, int *h_errnop,
- int af)
-{
- char *domain;
- if (__glibc_unlikely (yp_get_default_domain (&domain)))
- return NSS_STATUS_UNAVAIL;
-
- uintptr_t pad = -(uintptr_t) buffer % __alignof__ (struct parser_data);
- buffer += pad;
-
- struct parser_data *data = (void *) buffer;
- if (__glibc_unlikely (buflen < sizeof *data + 1 + pad))
- {
- *errnop = ERANGE;
- *h_errnop = NETDB_INTERNAL;
- return NSS_STATUS_TRYAGAIN;
- }
- buflen -= pad;
-
- /* Get the next entry until we found a correct one. */
- const size_t linebuflen = buffer + buflen - data->linebuffer;
- int parse_res;
- do
- {
- char *result;
- int len;
- char *outkey;
- int keylen;
- int yperr;
- if (new_start)
- yperr = yp_first (domain, "hosts.byname", &outkey, &keylen, &result,
- &len);
- else
- yperr = yp_next (domain, "hosts.byname", oldkey, oldkeylen, &outkey,
- &keylen, &result, &len);
-
- if (__glibc_unlikely (yperr != YPERR_SUCCESS))
- {
- enum nss_status retval = yperr2nss (yperr);
-
- switch (retval)
- {
- case NSS_STATUS_TRYAGAIN:
- *errnop = errno;
- *h_errnop = TRY_AGAIN;
- break;
- case NSS_STATUS_NOTFOUND:
- *h_errnop = HOST_NOT_FOUND;
- break;
- default:
- *h_errnop = NO_RECOVERY;
- break;
- }
- return retval;
- }
-
- if (__glibc_unlikely ((size_t) (len + 1) > linebuflen))
- {
- free (result);
- *h_errnop = NETDB_INTERNAL;
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- char *p = strncpy (data->linebuffer, result, len);
- data->linebuffer[len] = '\0';
- while (isspace (*p))
- ++p;
- free (result);
-
- parse_res = parse_line (p, host, data, buflen, errnop, af);
- if (__glibc_unlikely (parse_res == -1))
- {
- free (outkey);
- *h_errnop = NETDB_INTERNAL;
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
- free (oldkey);
- oldkey = outkey;
- oldkeylen = keylen;
- new_start = 0;
- }
- while (!parse_res);
-
- *h_errnop = NETDB_SUCCESS;
- return NSS_STATUS_SUCCESS;
-}
-
-
-enum nss_status
-_nss_nis_gethostent_r (struct hostent *host, char *buffer, size_t buflen,
- int *errnop, int *h_errnop)
-{
- enum nss_status status;
-
- __libc_lock_lock (lock);
-
- status = internal_nis_gethostent_r (host, buffer, buflen, errnop, h_errnop,
- AF_INET);
-
- __libc_lock_unlock (lock);
-
- return status;
-}
-
-
-static enum nss_status
-internal_gethostbyname2_r (const char *name, int af, struct hostent *host,
- char *buffer, size_t buflen, int *errnop,
- int *h_errnop)
-{
- uintptr_t pad = -(uintptr_t) buffer % __alignof__ (struct parser_data);
- buffer += pad;
-
- struct parser_data *data = (void *) buffer;
-
- if (name == NULL)
- {
- *errnop = EINVAL;
- return NSS_STATUS_UNAVAIL;
- }
-
- char *domain;
- if (yp_get_default_domain (&domain))
- return NSS_STATUS_UNAVAIL;
-
- if (buflen < sizeof *data + 1 + pad)
- {
- *h_errnop = NETDB_INTERNAL;
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
- buflen -= pad;
-
- /* Convert name to lowercase. */
- size_t namlen = strlen (name);
- /* Limit name length to the maximum size of an RPC packet. */
- if (namlen > UDPMSGSIZE)
- {
- *errnop = ERANGE;
- return NSS_STATUS_UNAVAIL;
- }
-
- char name2[namlen + 1];
- size_t i;
-
- for (i = 0; i < namlen; ++i)
- name2[i] = tolower (name[i]);
- name2[i] = '\0';
-
- char *result;
- int len;
- int yperr = yp_match (domain, "hosts.byname", name2, namlen, &result, &len);
-
- if (__glibc_unlikely (yperr != YPERR_SUCCESS))
- {
- enum nss_status retval = yperr2nss (yperr);
-
- if (retval == NSS_STATUS_TRYAGAIN)
- {
- *h_errnop = TRY_AGAIN;
- *errnop = errno;
- }
- if (retval == NSS_STATUS_NOTFOUND)
- *h_errnop = HOST_NOT_FOUND;
- return retval;
- }
-
- const size_t linebuflen = buffer + buflen - data->linebuffer;
- if (__glibc_unlikely ((size_t) (len + 1) > linebuflen))
- {
- free (result);
- *h_errnop = NETDB_INTERNAL;
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- char *p = strncpy (data->linebuffer, result, len);
- data->linebuffer[len] = '\0';
- while (isspace (*p))
- ++p;
- free (result);
-
- int parse_res = parse_line (p, host, data, buflen, errnop, af);
-
- if (__glibc_unlikely (parse_res < 1 || host->h_addrtype != af))
- {
- if (parse_res == -1)
- {
- *h_errnop = NETDB_INTERNAL;
- return NSS_STATUS_TRYAGAIN;
- }
- else
- {
- *h_errnop = HOST_NOT_FOUND;
- return NSS_STATUS_NOTFOUND;
- }
- }
-
- *h_errnop = NETDB_SUCCESS;
- return NSS_STATUS_SUCCESS;
-}
-
-
-enum nss_status
-_nss_nis_gethostbyname2_r (const char *name, int af, struct hostent *host,
- char *buffer, size_t buflen, int *errnop,
- int *h_errnop)
-{
- if (af != AF_INET && af != AF_INET6)
- {
- *h_errnop = HOST_NOT_FOUND;
- return NSS_STATUS_NOTFOUND;
- }
-
- return internal_gethostbyname2_r (name, af, host, buffer, buflen, errnop,
- h_errnop);
-}
-
-
-enum nss_status
-_nss_nis_gethostbyname_r (const char *name, struct hostent *host, char *buffer,
- size_t buflen, int *errnop, int *h_errnop)
-{
- return internal_gethostbyname2_r (name, AF_INET, host, buffer, buflen,
- errnop, h_errnop);
-}
-
-
-enum nss_status
-_nss_nis_gethostbyaddr_r (const void *addr, socklen_t addrlen, int af,
- struct hostent *host, char *buffer, size_t buflen,
- int *errnop, int *h_errnop)
-{
- char *domain;
- if (__glibc_unlikely (yp_get_default_domain (&domain)))
- return NSS_STATUS_UNAVAIL;
-
- uintptr_t pad = -(uintptr_t) buffer % __alignof__ (struct parser_data);
- buffer += pad;
-
- struct parser_data *data = (void *) buffer;
- if (__glibc_unlikely (buflen < sizeof *data + 1 + pad))
- {
- *errnop = ERANGE;
- *h_errnop = NETDB_INTERNAL;
- return NSS_STATUS_TRYAGAIN;
- }
- buflen -= pad;
-
- char *buf = inet_ntoa (*(const struct in_addr *) addr);
-
- char *result;
- int len;
- int yperr = yp_match (domain, "hosts.byaddr", buf, strlen (buf), &result,
- &len);
-
- if (__glibc_unlikely (yperr != YPERR_SUCCESS))
- {
- enum nss_status retval = yperr2nss (yperr);
-
- if (retval == NSS_STATUS_TRYAGAIN)
- {
- *h_errnop = TRY_AGAIN;
- *errnop = errno;
- }
- else if (retval == NSS_STATUS_NOTFOUND)
- *h_errnop = HOST_NOT_FOUND;
-
- return retval;
- }
-
- const size_t linebuflen = buffer + buflen - data->linebuffer;
- if (__glibc_unlikely ((size_t) (len + 1) > linebuflen))
- {
- free (result);
- *errnop = ERANGE;
- *h_errnop = NETDB_INTERNAL;
- return NSS_STATUS_TRYAGAIN;
- }
-
- char *p = strncpy (data->linebuffer, result, len);
- data->linebuffer[len] = '\0';
- while (isspace (*p))
- ++p;
- free (result);
-
- int parse_res = parse_line (p, host, data, buflen, errnop, af);
- if (__glibc_unlikely (parse_res < 1))
- {
- if (parse_res == -1)
- {
- *h_errnop = NETDB_INTERNAL;
- return NSS_STATUS_TRYAGAIN;
- }
- else
- {
- *h_errnop = HOST_NOT_FOUND;
- return NSS_STATUS_NOTFOUND;
- }
- }
-
- *h_errnop = NETDB_SUCCESS;
- return NSS_STATUS_SUCCESS;
-}
-
-
-enum nss_status
-_nss_nis_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
- char *buffer, size_t buflen, int *errnop,
- int *herrnop, int32_t *ttlp)
-{
- char *domain;
- if (yp_get_default_domain (&domain))
- {
- *herrnop = NO_DATA;
- return NSS_STATUS_UNAVAIL;
- }
-
- /* Convert name to lowercase. */
- size_t namlen = strlen (name);
- /* Limit name length to the maximum size of an RPC packet. */
- if (namlen > UDPMSGSIZE)
- {
- *errnop = ERANGE;
- return NSS_STATUS_UNAVAIL;
- }
-
- char name2[namlen + 1];
- size_t i;
-
- for (i = 0; i < namlen; ++i)
- name2[i] = tolower (name[i]);
- name2[i] = '\0';
-
- char *result;
- int len;
- int yperr = yp_match (domain, "hosts.byname", name2, namlen, &result, &len);
-
- if (__glibc_unlikely (yperr != YPERR_SUCCESS))
- {
- enum nss_status retval = yperr2nss (yperr);
-
- if (retval == NSS_STATUS_TRYAGAIN)
- {
- *herrnop = TRY_AGAIN;
- *errnop = errno;
- }
- if (retval == NSS_STATUS_NOTFOUND)
- *herrnop = HOST_NOT_FOUND;
- return retval;
- }
-
- if (*pat == NULL)
- {
- uintptr_t pad = (-(uintptr_t) buffer
- % __alignof__ (struct gaih_addrtuple));
- buffer += pad;
- buflen = buflen > pad ? buflen - pad : 0;
-
- if (__glibc_unlikely (buflen < sizeof (struct gaih_addrtuple)))
- {
- erange:
- free (result);
- *errnop = ERANGE;
- *herrnop = NETDB_INTERNAL;
- return NSS_STATUS_TRYAGAIN;
- }
-
- *pat = (struct gaih_addrtuple *) buffer;
- buffer += sizeof (struct gaih_addrtuple);
- buflen -= sizeof (struct gaih_addrtuple);
- }
-
- uintptr_t pad = -(uintptr_t) buffer % __alignof__ (struct parser_data);
- buffer += pad;
-
- struct parser_data *data = (void *) buffer;
-
- if (__glibc_unlikely (buflen < sizeof *data + 1 + pad))
- goto erange;
- buflen -= pad;
-
- struct hostent host;
- int parse_res = parse_line (result, &host, data, buflen, errnop, AF_UNSPEC);
- if (__glibc_unlikely (parse_res < 1))
- {
- if (parse_res == -1)
- {
- *herrnop = NETDB_INTERNAL;
- return NSS_STATUS_TRYAGAIN;
- }
- else
- {
- *herrnop = HOST_NOT_FOUND;
- return NSS_STATUS_NOTFOUND;
- }
- }
-
- (*pat)->next = NULL;
- (*pat)->family = host.h_addrtype;
- memcpy ((*pat)->addr, host.h_addr_list[0], host.h_length);
- (*pat)->scopeid = 0;
- assert (host.h_addr_list[1] == NULL);
-
- /* Undo the alignment for parser_data. */
- buffer -= pad;
- buflen += pad;
-
- size_t h_name_len = strlen (host.h_name) + 1;
- if (h_name_len >= buflen)
- goto erange;
- (*pat)->name = memcpy (buffer, host.h_name, h_name_len);
-
- free (result);
-
- return NSS_STATUS_SUCCESS;
-}
diff --git a/nis/nss_nis/nis-initgroups.c b/nis/nss_nis/nis-initgroups.c
deleted file mode 100644
index 9dc945a1bc..0000000000
--- a/nis/nss_nis/nis-initgroups.c
+++ /dev/null
@@ -1,343 +0,0 @@
-/* Copyright (C) 1998-2020 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Thorsten Kukuk , 1998.
-
- 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
- . */
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "nss-nis.h"
-#include
-
-/* Get the declaration of the parser function. */
-#define ENTNAME grent
-#define STRUCTURE group
-#define EXTERN_PARSER
-#include
-
-
-static enum nss_status
-internal_setgrent (char *domainname, intern_t *intern)
-{
- struct ypall_callback ypcb;
- enum nss_status status;
-
- ypcb.foreach = _nis_saveit;
- ypcb.data = (char *) intern;
- status = yperr2nss (yp_all (domainname, "group.byname", &ypcb));
-
- /* Mark the last buffer as full. */
- if (intern->next != NULL)
- intern->next->size = intern->offset;
-
- intern->next = intern->start;
- intern->offset = 0;
-
- return status;
-}
-
-
-static enum nss_status
-internal_getgrent_r (struct group *grp, char *buffer, size_t buflen,
- int *errnop, intern_t *intern)
-{
- if (intern->start == NULL)
- return NSS_STATUS_NOTFOUND;
-
- /* Get the next entry until we found a correct one. */
- int parse_res;
- do
- {
- struct response_t *bucket = intern->next;
-
- if (__glibc_unlikely (intern->offset >= bucket->size))
- {
- if (bucket->next == NULL)
- return NSS_STATUS_NOTFOUND;
-
- /* We look at all the content in the current bucket. Go on
- to the next. */
- bucket = intern->next = bucket->next;
- intern->offset = 0;
- }
-
- char *p;
- for (p = &bucket->mem[intern->offset]; isspace (*p); ++p)
- ++intern->offset;
-
- size_t len = strlen (p) + 1;
- if (__glibc_unlikely (len > buflen))
- {
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- /* We unfortunately have to copy the data in the user-provided
- buffer because that buffer might be around for a very long
- time and the servent structure must remain valid. If we would
- rely on the BUCKET memory the next 'setservent' or 'endservent'
- call would destroy it.
-
- The important thing is that it is a single NUL-terminated
- string. This is what the parsing routine expects. */
- p = memcpy (buffer, &bucket->mem[intern->offset], len);
-
- parse_res = _nss_files_parse_grent (p, grp, (void *) buffer, buflen,
- errnop);
- if (__glibc_unlikely (parse_res == -1))
- return NSS_STATUS_TRYAGAIN;
-
- intern->offset += len;
- }
- while (!parse_res);
-
- return NSS_STATUS_SUCCESS;
-}
-
-
-static int
-get_uid (const char *user, uid_t *uidp)
-{
- struct scratch_buffer tmpbuf;
- scratch_buffer_init (&tmpbuf);
-
- while (1)
- {
- struct passwd result;
- struct passwd *resp;
-
- int r = getpwnam_r (user, &result, tmpbuf.data, tmpbuf.length, &resp);
- if (r == 0 && resp != NULL)
- {
- *uidp = resp->pw_uid;
- scratch_buffer_free (&tmpbuf);
- return 0;
- }
-
- if (r != ERANGE)
- break;
-
- if (!scratch_buffer_grow (&tmpbuf))
- return 1;
- }
-
- scratch_buffer_free (&tmpbuf);
- return 1;
-}
-
-
-static enum nss_status
-initgroups_netid (uid_t uid, gid_t group, long int *start, long int *size,
- gid_t **groupsp, long int limit, int *errnop,
- const char *domainname)
-{
- /* Limit domainname length to the maximum size of an RPC packet. */
- if (strlen (domainname) > UDPMSGSIZE)
- {
- *errnop = ERANGE;
- return NSS_STATUS_UNAVAIL;
- }
-
- /* Prepare the key. The form is "unix.UID@DOMAIN" with the UID and
- DOMAIN field filled in appropriately. */
- char key[sizeof ("unix.@") + sizeof (uid_t) * 3 + strlen (domainname)];
- ssize_t keylen = snprintf (key, sizeof (key), "unix.%lu@%s",
- (unsigned long int) uid, domainname);
-
- char *result;
- int reslen;
- int yperr = yp_match (domainname, "netid.byname", key, keylen, &result,
- &reslen);
- if (__glibc_unlikely (yperr != YPERR_SUCCESS))
- return yperr2nss (yperr);
-
- /* Parse the result: following the colon is a comma separated list of
- group IDs. */
- char *cp = strchr (result, ':');
- if (cp == NULL)
- {
- errout:
- free (result);
- return NSS_STATUS_NOTFOUND;
- }
- /* Skip the colon. */
- ++cp;
-
- gid_t *groups = *groupsp;
- while (*cp != '\0')
- {
- char *endp;
- unsigned long int gid = strtoul (cp, &endp, 0);
- if (cp == endp)
- goto errout;
- if (*endp == ',')
- ++endp;
- else if (*endp != '\0')
- goto errout;
- cp = endp;
-
- if (gid == group)
- /* We do not need this group again. */
- continue;
-
- /* Insert this group. */
- if (*start == *size)
- {
- /* Need a bigger buffer. */
- long int newsize;
-
- if (limit > 0 && *size == limit)
- /* We reached the maximum. */
- break;
-
- if (limit <= 0)
- newsize = 2 * *size;
- else
- newsize = MIN (limit, 2 * *size);
-
- gid_t *newgroups = realloc (groups, newsize * sizeof (*groups));
- if (newgroups == NULL)
- goto errout;
- *groupsp = groups = newgroups;
- *size = newsize;
- }
-
- groups[*start] = gid;
- *start += 1;
- }
-
- free (result);
-
- return NSS_STATUS_SUCCESS;
-}
-
-
-enum nss_status
-_nss_nis_initgroups_dyn (const char *user, gid_t group, long int *start,
- long int *size, gid_t **groupsp, long int limit,
- int *errnop)
-{
- /* We always need the domain name. */
- char *domainname;
- if (yp_get_default_domain (&domainname))
- return NSS_STATUS_UNAVAIL;
-
- /* Check whether we are supposed to use the netid.byname map. */
- if (_nsl_default_nss () & NSS_FLAG_NETID_AUTHORITATIVE)
- {
- /* We need the user ID. */
- uid_t uid;
-
- if (get_uid (user, &uid) == 0
- && initgroups_netid (uid, group, start, size, groupsp, limit,
- errnop, domainname) == NSS_STATUS_SUCCESS)
- return NSS_STATUS_SUCCESS;
- }
-
- struct group grpbuf, *g;
- enum nss_status status;
- intern_t intern = { NULL, NULL, 0 };
- gid_t *groups = *groupsp;
-
- status = internal_setgrent (domainname, &intern);
- if (status != NSS_STATUS_SUCCESS)
- return status;
-
- struct scratch_buffer tmpbuf;
- scratch_buffer_init (&tmpbuf);
-
- while (1)
- {
- while ((status =
- internal_getgrent_r (&grpbuf, tmpbuf.data, tmpbuf.length, errnop,
- &intern)) == NSS_STATUS_TRYAGAIN
- && *errnop == ERANGE)
- if (!scratch_buffer_grow (&tmpbuf))
- {
- status = NSS_STATUS_TRYAGAIN;
- goto done;
- }
-
- if (status != NSS_STATUS_SUCCESS)
- {
- if (status == NSS_STATUS_NOTFOUND)
- status = NSS_STATUS_SUCCESS;
- goto done;
- }
-
- g = &grpbuf;
- if (g->gr_gid != group)
- {
- char **m;
-
- for (m = g->gr_mem; *m != NULL; ++m)
- if (strcmp (*m, user) == 0)
- {
- /* Matches user. Insert this group. */
- if (*start == *size)
- {
- /* Need a bigger buffer. */
- gid_t *newgroups;
- long int newsize;
-
- if (limit > 0 && *size == limit)
- /* We reached the maximum. */
- goto done;
-
- if (limit <= 0)
- newsize = 2 * *size;
- else
- newsize = MIN (limit, 2 * *size);
-
- newgroups = realloc (groups, newsize * sizeof (*groups));
- if (newgroups == NULL)
- {
- status = NSS_STATUS_TRYAGAIN;
- *errnop = errno;
- goto done;
- }
- *groupsp = groups = newgroups;
- *size = newsize;
- }
-
- groups[*start] = g->gr_gid;
- *start += 1;
-
- break;
- }
- }
- }
-
-done:
- while (intern.start != NULL)
- {
- intern.next = intern.start;
- intern.start = intern.start->next;
- free (intern.next);
- }
- scratch_buffer_free (&tmpbuf);
-
- return status;
-}
diff --git a/nis/nss_nis/nis-netgrp.c b/nis/nss_nis/nis-netgrp.c
deleted file mode 100644
index 41b530a979..0000000000
--- a/nis/nss_nis/nis-netgrp.c
+++ /dev/null
@@ -1,98 +0,0 @@
-/* Copyright (C) 1996-2020 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Thorsten Kukuk , 1996.
-
- 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
- . */
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "nss-nis.h"
-
-extern enum nss_status
-_nss_netgroup_parseline (char **cursor, struct __netgrent *netgrp,
- char *buffer, size_t buflen, int *errnop);
-
-
-static void
-internal_nis_endnetgrent (struct __netgrent *netgrp)
-{
- free (netgrp->data);
- netgrp->data = NULL;
- netgrp->data_size = 0;
- netgrp->cursor = NULL;
-}
-
-
-enum nss_status
-_nss_nis_setnetgrent (const char *group, struct __netgrent *netgrp)
-{
- int len;
- enum nss_status status;
-
- status = NSS_STATUS_SUCCESS;
-
- if (__glibc_unlikely (group == NULL || group[0] == '\0'))
- return NSS_STATUS_UNAVAIL;
-
- char *domain;
- if (__glibc_unlikely (yp_get_default_domain (&domain)))
- return NSS_STATUS_UNAVAIL;
-
- status = yperr2nss (yp_match (domain, "netgroup", group, strlen (group),
- &netgrp->data, &len));
- if (__glibc_likely (status == NSS_STATUS_SUCCESS))
- {
- /* Our implementation of yp_match already allocates a buffer
- which is one byte larger than the value in LEN specifies
- and the last byte is filled with NUL. So we can simply
- use that buffer. */
- assert (len >= 0);
- assert (netgrp->data[len] == '\0');
-
- netgrp->data_size = len;
- netgrp->cursor = netgrp->data;
- }
-
- return status;
-}
-
-
-enum nss_status
-_nss_nis_endnetgrent (struct __netgrent *netgrp)
-{
- internal_nis_endnetgrent (netgrp);
-
- return NSS_STATUS_SUCCESS;
-}
-
-
-enum nss_status
-_nss_nis_getnetgrent_r (struct __netgrent *result, char *buffer, size_t buflen,
- int *errnop)
-{
- return _nss_netgroup_parseline (&result->cursor, result, buffer, buflen,
- errnop);
-}
diff --git a/nis/nss_nis/nis-network.c b/nis/nss_nis/nis-network.c
deleted file mode 100644
index 8d87c69d8e..0000000000
--- a/nis/nss_nis/nis-network.c
+++ /dev/null
@@ -1,314 +0,0 @@
-/* Copyright (C) 1996-2020 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Thorsten Kukuk , 1996.
-
- 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
- . */
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "nss-nis.h"
-
-/* Get the declaration of the parser function. */
-#define ENTNAME netent
-#define EXTERN_PARSER
-#include
-
-__libc_lock_define_initialized (static, lock)
-
-static bool_t new_start = 1;
-static char *oldkey;
-static int oldkeylen;
-
-enum nss_status
-_nss_nis_setnetent (int stayopen)
-{
- return _nss_nis_endnetent ();
-}
-
-enum nss_status
-_nss_nis_endnetent (void)
-{
-__libc_lock_lock (lock);
-
- new_start = 1;
- if (oldkey != NULL)
- {
- free (oldkey);
- oldkey = NULL;
- oldkeylen = 0;
- }
-
- __libc_lock_unlock (lock);
-
- return NSS_STATUS_SUCCESS;
-}
-libnss_nis_hidden_def (_nss_nis_endnetent)
-
-static enum nss_status
-internal_nis_getnetent_r (struct netent *net, char *buffer, size_t buflen,
- int *errnop, int *herrnop)
-{
- struct parser_data *data = (void *) buffer;
-
- char *domain;
- if (__glibc_unlikely (yp_get_default_domain (&domain)))
- return NSS_STATUS_UNAVAIL;
-
- /* Get the next entry until we found a correct one. */
- int parse_res;
- do
- {
- char *result;
- char *outkey;
- int len;
- int keylen;
- int yperr;
-
- if (new_start)
- yperr = yp_first (domain, "networks.byname", &outkey, &keylen, &result,
- &len);
- else
- yperr = yp_next (domain, "networks.byname", oldkey, oldkeylen, &outkey,
- &keylen, &result, &len);
-
- if (__glibc_unlikely (yperr != YPERR_SUCCESS))
- {
- enum nss_status retval = yperr2nss (yperr);
-
- if (retval == NSS_STATUS_TRYAGAIN)
- {
- *herrnop = NETDB_INTERNAL;
- *errnop = errno;
- }
- return retval;
- }
-
- if (__glibc_unlikely ((size_t) (len + 1) > buflen))
- {
- free (result);
- *errnop = ERANGE;
- *herrnop = NETDB_INTERNAL;
- return NSS_STATUS_TRYAGAIN;
- }
-
- char *p = strncpy (buffer, result, len);
- buffer[len] = '\0';
- while (isspace (*p))
- ++p;
- free (result);
-
- parse_res = _nss_files_parse_netent (p, net, data, buflen, errnop);
- if (__glibc_unlikely (parse_res == -1))
- {
- free (outkey);
- *herrnop = NETDB_INTERNAL;
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- free (oldkey);
- oldkey = outkey;
- oldkeylen = keylen;
- new_start = 0;
- }
- while (!parse_res);
-
- return NSS_STATUS_SUCCESS;
-}
-
-enum nss_status
-_nss_nis_getnetent_r (struct netent *net, char *buffer, size_t buflen,
- int *errnop, int *herrnop)
-{
- enum nss_status status;
-
- __libc_lock_lock (lock);
-
- status = internal_nis_getnetent_r (net, buffer, buflen, errnop, herrnop);
-
- __libc_lock_unlock (lock);
-
- return status;
-}
-
-enum nss_status
-_nss_nis_getnetbyname_r (const char *name, struct netent *net, char *buffer,
- size_t buflen, int *errnop, int *herrnop)
-{
- if (name == NULL)
- {
- *errnop = EINVAL;
- *herrnop = NETDB_INTERNAL;
- return NSS_STATUS_UNAVAIL;
- }
-
- char *domain;
- if (__glibc_unlikely (yp_get_default_domain (&domain)))
- return NSS_STATUS_UNAVAIL;
-
- struct parser_data *data = (void *) buffer;
- if (buflen < sizeof *data + 1)
- {
- *herrnop = NETDB_INTERNAL;
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- /* Convert name to lowercase. */
- size_t namlen = strlen (name);
- /* Limit name length to the maximum size of an RPC packet. */
- if (namlen > UDPMSGSIZE)
- {
- *errnop = ERANGE;
- return NSS_STATUS_UNAVAIL;
- }
-
- char name2[namlen + 1];
- size_t i;
-
- for (i = 0; i < namlen; ++i)
- name2[i] = _tolower (name[i]);
- name2[i] = '\0';
-
- char *result;
- int len;
- int yperr = yp_match (domain, "networks.byname", name2, namlen, &result,
- &len);
-
- if (__glibc_unlikely (yperr != YPERR_SUCCESS))
- {
- enum nss_status retval = yperr2nss (yperr);
-
- if (retval == NSS_STATUS_TRYAGAIN)
- {
- *errnop = errno;
- *herrnop = NETDB_INTERNAL;
- }
- return retval;
- }
-
- if (__glibc_unlikely ((size_t) (len + 1) > buflen))
- {
- free (result);
- *errnop = ERANGE;
- *herrnop = NETDB_INTERNAL;
- return NSS_STATUS_TRYAGAIN;
- }
-
- char *p = strncpy (buffer, result, len);
- buffer[len] = '\0';
- while (isspace (*p))
- ++p;
- free (result);
-
- int parse_res = _nss_files_parse_netent (p, net, data, buflen, errnop);
-
- if (__glibc_unlikely (parse_res < 1))
- {
- *herrnop = NETDB_INTERNAL;
- if (parse_res == -1)
- return NSS_STATUS_TRYAGAIN;
- else
- return NSS_STATUS_NOTFOUND;
- }
- else
- return NSS_STATUS_SUCCESS;
-}
-
-enum nss_status
-_nss_nis_getnetbyaddr_r (uint32_t addr, int type, struct netent *net,
- char *buffer, size_t buflen, int *errnop,
- int *herrnop)
-{
- char *domain;
- if (__glibc_unlikely (yp_get_default_domain (&domain)))
- return NSS_STATUS_UNAVAIL;
-
- struct in_addr in = { .s_addr = htonl (addr) };
- char *buf = inet_ntoa (in);
- size_t blen = strlen (buf);
-
- while (1)
- {
- char *result;
- int len;
-
- int yperr = yp_match (domain, "networks.byaddr", buf, blen, &result,
- &len);
-
- if (__glibc_unlikely (yperr != YPERR_SUCCESS))
- {
- enum nss_status retval = yperr2nss (yperr);
-
- if (retval == NSS_STATUS_NOTFOUND)
- {
- if (buf[blen - 2] == '.' && buf[blen - 1] == '0')
- {
- /* Try again, but with trailing dot(s)
- removed (one by one) */
- buf[blen - 2] = '\0';
- blen -= 2;
- continue;
- }
- else
- return NSS_STATUS_NOTFOUND;
- }
- else
- {
- if (retval == NSS_STATUS_TRYAGAIN)
- *errnop = errno;
- return retval;
- }
- }
-
- if (__glibc_unlikely ((size_t) (len + 1) > buflen))
- {
- free (result);
- *errnop = ERANGE;
- *herrnop = NETDB_INTERNAL;
- return NSS_STATUS_TRYAGAIN;
- }
-
- char *p = strncpy (buffer, result, len);
- buffer[len] = '\0';
- while (isspace (*p))
- ++p;
- free (result);
-
- int parse_res = _nss_files_parse_netent (p, net, (void *) buffer,
- buflen, errnop);
-
- if (__glibc_unlikely (parse_res < 1))
- {
- *herrnop = NETDB_INTERNAL;
- if (parse_res == -1)
- return NSS_STATUS_TRYAGAIN;
- else
- return NSS_STATUS_NOTFOUND;
- }
- else
- return NSS_STATUS_SUCCESS;
- }
-}
diff --git a/nis/nss_nis/nis-proto.c b/nis/nss_nis/nis-proto.c
deleted file mode 100644
index 9aa698e96a..0000000000
--- a/nis/nss_nis/nis-proto.c
+++ /dev/null
@@ -1,278 +0,0 @@
-/* Copyright (C) 1996-2020 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Thorsten Kukuk , 1996.
-
- 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
- . */
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "nss-nis.h"
-
-/* Get the declaration of the parser function. */
-#define ENTNAME protoent
-#define EXTERN_PARSER
-#include
-
-__libc_lock_define_initialized (static, lock)
-
-struct response
-{
- struct response *next;
- char val[0];
-};
-
-static struct response *start;
-static struct response *next;
-
-static int
-saveit (int instatus, char *inkey, int inkeylen, char *inval,
- int invallen, char *indata)
-{
- if (instatus != YP_TRUE)
- return 1;
-
- if (inkey && inkeylen > 0 && inval && invallen > 0)
- {
- struct response *newp = malloc (sizeof (struct response) + invallen + 1);
- if (newp == NULL)
- return 1; /* We have no error code for out of memory */
-
- if (start == NULL)
- start = newp;
- else
- next->next = newp;
- next = newp;
-
- newp->next = NULL;
- *((char *) mempcpy (newp->val, inval, invallen)) = '\0';
- }
-
- return 0;
-}
-
-static void
-internal_nis_endprotoent (void)
-{
- while (start != NULL)
- {
- next = start;
- start = start->next;
- free (next);
- }
-}
-
-static enum nss_status
-internal_nis_setprotoent (void)
-{
- char *domainname;
- struct ypall_callback ypcb;
- enum nss_status status;
-
- yp_get_default_domain (&domainname);
-
- internal_nis_endprotoent ();
-
- ypcb.foreach = saveit;
- ypcb.data = NULL;
- status = yperr2nss (yp_all (domainname, "protocols.bynumber", &ypcb));
- next = start;
-
- return status;
-}
-
-enum nss_status
-_nss_nis_setprotoent (int stayopen)
-{
- enum nss_status status;
-
- __libc_lock_lock (lock);
-
- status = internal_nis_setprotoent ();
-
- __libc_lock_unlock (lock);
-
- return status;
-}
-
-enum nss_status
-_nss_nis_endprotoent (void)
-{
- __libc_lock_lock (lock);
-
- internal_nis_endprotoent ();
- next = NULL;
-
- __libc_lock_unlock (lock);
-
- return NSS_STATUS_SUCCESS;
-}
-
-static enum nss_status
-internal_nis_getprotoent_r (struct protoent *proto,
- char *buffer, size_t buflen, int *errnop)
-{
- struct parser_data *data = (void *) buffer;
- int parse_res;
-
- if (start == NULL)
- internal_nis_setprotoent ();
-
- /* Get the next entry until we found a correct one. */
- do
- {
- char *p;
-
- if (next == NULL)
- return NSS_STATUS_NOTFOUND;
-
- p = strncpy (buffer, next->val, buflen);
-
- while (isspace (*p))
- ++p;
-
- parse_res = _nss_files_parse_protoent (p, proto, data, buflen, errnop);
- if (parse_res == -1)
- return NSS_STATUS_TRYAGAIN;
- next = next->next;
- }
- while (!parse_res);
-
- return NSS_STATUS_SUCCESS;
-}
-
-enum nss_status
-_nss_nis_getprotoent_r (struct protoent *proto, char *buffer, size_t buflen,
- int *errnop)
-{
- enum nss_status status;
-
- __libc_lock_lock (lock);
-
- status = internal_nis_getprotoent_r (proto, buffer, buflen, errnop);
-
- __libc_lock_unlock (lock);
-
- return status;
-}
-
-enum nss_status
-_nss_nis_getprotobyname_r (const char *name, struct protoent *proto,
- char *buffer, size_t buflen, int *errnop)
-{
- if (name == NULL)
- {
- *errnop = EINVAL;
- return NSS_STATUS_UNAVAIL;
- }
-
- char *domain;
- if (__glibc_unlikely (yp_get_default_domain (&domain)))
- return NSS_STATUS_UNAVAIL;
-
- char *result;
- int len;
- int yperr = yp_match (domain, "protocols.byname", name, strlen (name),
- &result, &len);
-
- if (__glibc_unlikely (yperr != YPERR_SUCCESS))
- {
- enum nss_status retval = yperr2nss (yperr);
-
- if (retval == NSS_STATUS_TRYAGAIN)
- *errnop = errno;
- return retval;
- }
-
- if (__glibc_unlikely ((size_t) (len + 1) > buflen))
- {
- free (result);
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- char *p = strncpy (buffer, result, len);
- buffer[len] = '\0';
- while (isspace (*p))
- ++p;
- free (result);
-
- int parse_res = _nss_files_parse_protoent (p, proto, (void *) buffer, buflen,
- errnop);
- if (__glibc_unlikely (parse_res < 1))
- {
- if (parse_res == -1)
- return NSS_STATUS_TRYAGAIN;
- else
- return NSS_STATUS_NOTFOUND;
- }
- return NSS_STATUS_SUCCESS;
-}
-
-enum nss_status
-_nss_nis_getprotobynumber_r (int number, struct protoent *proto,
- char *buffer, size_t buflen, int *errnop)
-{
- char *domain;
- if (__glibc_unlikely (yp_get_default_domain (&domain)))
- return NSS_STATUS_UNAVAIL;
-
- char buf[32];
- int nlen = snprintf (buf, sizeof (buf), "%d", number);
-
- char *result;
- int len;
- int yperr = yp_match (domain, "protocols.bynumber", buf, nlen, &result,
- &len);
-
- if (__glibc_unlikely (yperr != YPERR_SUCCESS))
- {
- enum nss_status retval = yperr2nss (yperr);
-
- if (retval == NSS_STATUS_TRYAGAIN)
- *errnop = errno;
- return retval;
- }
-
- if (__glibc_unlikely ((size_t) (len + 1) > buflen))
- {
- free (result);
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- char *p = strncpy (buffer, result, len);
- buffer[len] = '\0';
- while (isspace (*p))
- ++p;
- free (result);
-
- int parse_res = _nss_files_parse_protoent (p, proto, (void *) buffer, buflen,
- errnop);
- if (__glibc_unlikely (parse_res < 1))
- {
- if (parse_res == -1)
- return NSS_STATUS_TRYAGAIN;
- else
- return NSS_STATUS_NOTFOUND;
- }
- return NSS_STATUS_SUCCESS;
-}
diff --git a/nis/nss_nis/nis-pwd.c b/nis/nss_nis/nis-pwd.c
deleted file mode 100644
index 00dcda41e5..0000000000
--- a/nis/nss_nis/nis-pwd.c
+++ /dev/null
@@ -1,581 +0,0 @@
-/* Copyright (C) 1996-2020 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Thorsten Kukuk , 1996.
-
- 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
- . */
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "nss-nis.h"
-#include
-
-/* Get the declaration of the parser function. */
-#define ENTNAME pwent
-#define STRUCTURE passwd
-#define EXTERN_PARSER
-#include
-
-/* Protect global state against multiple changers */
-__libc_lock_define_initialized (static, lock)
-
-static bool new_start = true;
-static char *oldkey;
-static int oldkeylen;
-static intern_t intern;
-
-
-int
-_nis_saveit (int instatus, char *inkey, int inkeylen, char *inval,
- int invallen, char *indata)
-{
- intern_t *intern = (intern_t *) indata;
-
- if (instatus != YP_TRUE)
- return 1;
-
- if (inkey && inkeylen > 0 && inval && invallen > 0)
- {
- struct response_t *bucket = intern->next;
-
- if (__glibc_unlikely (bucket == NULL))
- {
-#define MINSIZE 4096 - 4 * sizeof (void *)
- const size_t minsize = MAX (MINSIZE, 2 * (invallen + 1));
- bucket = malloc (sizeof (struct response_t) + minsize);
- if (bucket == NULL)
- /* We have no error code for out of memory. */
- return 1;
-
- bucket->next = NULL;
- bucket->size = minsize;
- intern->start = intern->next = bucket;
- intern->offset = 0;
- }
- else if (__builtin_expect (invallen + 1 > bucket->size - intern->offset,
- 0))
- {
- /* We need a new (larger) buffer. */
- const size_t newsize = 2 * MAX (bucket->size, invallen + 1);
- struct response_t *newp = malloc (sizeof (struct response_t)
- + newsize);
- if (newp == NULL)
- /* We have no error code for out of memory. */
- return 1;
-
- /* Mark the old bucket as full. */
- bucket->size = intern->offset;
-
- newp->next = NULL;
- newp->size = newsize;
- bucket = intern->next = bucket->next = newp;
- intern->offset = 0;
- }
-
- char *p = mempcpy (&bucket->mem[intern->offset], inval, invallen);
- if (__glibc_unlikely (p[-1] != '\0'))
- {
- *p = '\0';
- ++invallen;
- }
- intern->offset += invallen;
- }
-
- return 0;
-}
-
-
-static void
-internal_nis_endpwent (void)
-{
- new_start = true;
- free (oldkey);
- oldkey = NULL;
- oldkeylen = 0;
-
- struct response_t *curr = intern.start;
-
- while (curr != NULL)
- {
- struct response_t *last = curr;
- curr = curr->next;
- free (last);
- }
-
- intern.next = intern.start = NULL;
-}
-
-
-enum nss_status
-_nss_nis_endpwent (void)
-{
- __libc_lock_lock (lock);
-
- internal_nis_endpwent ();
-
- __libc_lock_unlock (lock);
-
- return NSS_STATUS_SUCCESS;
-}
-
-
-enum nss_status
-internal_nis_setpwent (void)
-{
- /* We have to read all the data now. */
- char *domain;
- if (__glibc_unlikely (yp_get_default_domain (&domain)))
- return NSS_STATUS_UNAVAIL;
-
- struct ypall_callback ypcb;
-
- ypcb.foreach = _nis_saveit;
- ypcb.data = (char *) &intern;
- enum nss_status status = yperr2nss (yp_all (domain, "passwd.byname", &ypcb));
-
-
- /* Mark the last buffer as full. */
- if (intern.next != NULL)
- intern.next->size = intern.offset;
-
- intern.next = intern.start;
- intern.offset = 0;
-
- return status;
-}
-
-
-enum nss_status
-_nss_nis_setpwent (int stayopen)
-{
- enum nss_status result = NSS_STATUS_SUCCESS;
-
- __libc_lock_lock (lock);
-
- internal_nis_endpwent ();
-
- if (_nsl_default_nss () & NSS_FLAG_SETENT_BATCH_READ)
- result = internal_nis_setpwent ();
-
- __libc_lock_unlock (lock);
-
- return result;
-}
-
-
-static enum nss_status
-internal_nis_getpwent_r (struct passwd *pwd, char *buffer, size_t buflen,
- int *errnop)
-{
- /* If we read the entire database at setpwent time we just iterate
- over the data we have in memory. */
- bool batch_read = intern.start != NULL;
-
- char *domain = NULL;
- if (!batch_read && __builtin_expect (yp_get_default_domain (&domain), 0))
- return NSS_STATUS_UNAVAIL;
-
- /* Get the next entry until we found a correct one. */
- int parse_res;
- do
- {
- char *result;
- char *outkey;
- int len;
- int keylen;
-
- if (batch_read)
- {
- struct response_t *bucket;
-
- handle_batch_read:
- bucket = intern.next;
-
- if (__glibc_unlikely (intern.offset >= bucket->size))
- {
- if (bucket->next == NULL)
- return NSS_STATUS_NOTFOUND;
-
- /* We look at all the content in the current bucket. Go on
- to the next. */
- bucket = intern.next = bucket->next;
- intern.offset = 0;
- }
-
- for (result = &bucket->mem[intern.offset]; isspace (*result);
- ++result)
- ++intern.offset;
-
- len = strlen (result);
- }
- else
- {
- int yperr;
-
- if (new_start)
- {
- /* Maybe we should read the database in one piece. */
- if ((_nsl_default_nss () & NSS_FLAG_SETENT_BATCH_READ)
- && internal_nis_setpwent () == NSS_STATUS_SUCCESS
- && intern.start != NULL)
- {
- batch_read = true;
- goto handle_batch_read;
- }
-
- yperr = yp_first (domain, "passwd.byname", &outkey, &keylen,
- &result, &len);
- }
- else
- yperr = yp_next (domain, "passwd.byname", oldkey, oldkeylen,
- &outkey, &keylen, &result, &len);
-
- if (__glibc_unlikely (yperr != YPERR_SUCCESS))
- {
- enum nss_status retval = yperr2nss (yperr);
-
- if (retval == NSS_STATUS_TRYAGAIN)
- *errnop = errno;
- return retval;
- }
- }
-
- /* Check for adjunct style secret passwords. They can be
- recognized by a password starting with "##". We do not use
- it if the passwd.adjunct.byname table is supposed to be used
- as a shadow.byname replacement. */
- char *p = strchr (result, ':');
- size_t namelen;
- char *result2;
- int len2;
- if ((_nsl_default_nss () & NSS_FLAG_ADJUNCT_AS_SHADOW) == 0
- && p != NULL /* This better should be true in all cases. */
- && p[1] == '#' && p[2] == '#'
- && (namelen = p - result,
- yp_match (domain, "passwd.adjunct.byname", result, namelen,
- &result2, &len2)) == YPERR_SUCCESS)
- {
- /* We found a passwd.adjunct.byname entry. Merge encrypted
- password therein into original result. */
- char *encrypted = strchr (result2, ':');
- char *endp;
- size_t restlen;
-
- if (encrypted == NULL
- || (endp = strchr (++encrypted, ':')) == NULL
- || (p = strchr (p + 1, ':')) == NULL)
- {
- /* Invalid format of the entry. This never should happen
- unless the data from which the NIS table is generated is
- wrong. We simply ignore it. */
- free (result2);
- goto non_adjunct;
- }
-
- restlen = len - (p - result);
- if (__builtin_expect ((size_t) (namelen + (endp - encrypted)
- + restlen + 2) > buflen, 0))
- {
- free (result2);
- free (result);
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- mempcpy (mempcpy (mempcpy (mempcpy (buffer, result, namelen),
- ":", 1),
- encrypted, endp - encrypted),
- p, restlen + 1);
- p = buffer;
-
- free (result2);
- }
- else
- {
- non_adjunct:
- if (__glibc_unlikely ((size_t) (len + 1) > buflen))
- {
- free (result);
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- p = buffer;
- *((char *) mempcpy (buffer, result, len)) = '\0';
- }
-
- while (isspace (*p))
- ++p;
- if (!batch_read)
- free (result);
-
- parse_res = _nss_files_parse_pwent (p, pwd, (void *) buffer, buflen,
- errnop);
- if (__glibc_unlikely (parse_res == -1))
- {
- if (!batch_read)
- free (outkey);
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- if (batch_read)
- intern.offset += len + 1;
- else
- {
- free (oldkey);
- oldkey = outkey;
- oldkeylen = keylen;
- new_start = false;
- }
- }
- while (parse_res < 1);
-
- return NSS_STATUS_SUCCESS;
-}
-
-enum nss_status
-_nss_nis_getpwent_r (struct passwd *result, char *buffer, size_t buflen,
- int *errnop)
-{
- int status;
-
- __libc_lock_lock (lock);
-
- status = internal_nis_getpwent_r (result, buffer, buflen, errnop);
-
- __libc_lock_unlock (lock);
-
- return status;
-}
-
-enum nss_status
-_nss_nis_getpwnam_r (const char *name, struct passwd *pwd,
- char *buffer, size_t buflen, int *errnop)
-{
- if (name == NULL)
- {
- *errnop = EINVAL;
- return NSS_STATUS_UNAVAIL;
- }
-
- char *domain;
- if (__glibc_unlikely (yp_get_default_domain (&domain)))
- return NSS_STATUS_UNAVAIL;
-
- size_t namelen = strlen (name);
-
- char *result;
- int len;
- int yperr = yp_match (domain, "passwd.byname", name, namelen, &result, &len);
-
- if (__glibc_unlikely (yperr != YPERR_SUCCESS))
- {
- enum nss_status retval = yperr2nss (yperr);
-
- if (retval == NSS_STATUS_TRYAGAIN)
- *errnop = errno;
- return retval;
- }
-
- /* Check for adjunct style secret passwords. They can be recognized
- by a password starting with "##". We do not use it if the
- passwd.adjunct.byname table is supposed to be used as a shadow.byname
- replacement. */
- char *result2;
- int len2;
- char *p = strchr (result, ':');
- if ((_nsl_default_nss () & NSS_FLAG_ADJUNCT_AS_SHADOW) == 0
- && p != NULL /* This better should be true in all cases. */
- && p[1] == '#' && p[2] == '#'
- && yp_match (domain, "passwd.adjunct.byname", name, namelen,
- &result2, &len2) == YPERR_SUCCESS)
- {
- /* We found a passwd.adjunct.byname entry. Merge encrypted password
- therein into original result. */
- char *encrypted = strchr (result2, ':');
- char *endp;
-
- if (encrypted == NULL
- || (endp = strchr (++encrypted, ':')) == NULL
- || (p = strchr (p + 1, ':')) == NULL)
- {
- /* Invalid format of the entry. This never should happen
- unless the data from which the NIS table is generated is
- wrong. We simply ignore it. */
- free (result2);
- goto non_adjunct;
- }
-
- size_t restlen = len - (p - result);
- if (__builtin_expect ((size_t) (namelen + (endp - encrypted)
- + restlen + 2) > buflen, 0))
- {
- free (result2);
- free (result);
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- __mempcpy (__mempcpy (__mempcpy (__mempcpy (buffer, name, namelen),
- ":", 1),
- encrypted, endp - encrypted),
- p, restlen + 1);
- p = buffer;
-
- free (result2);
- }
- else
- {
- non_adjunct:
- if (__glibc_unlikely ((size_t) (len + 1) > buflen))
- {
- free (result);
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- p = strncpy (buffer, result, len);
- buffer[len] = '\0';
- }
-
- while (isspace (*p))
- ++p;
- free (result);
-
- int parse_res = _nss_files_parse_pwent (p, pwd, (void *) buffer, buflen,
- errnop);
- if (__glibc_unlikely (parse_res < 1))
- {
- if (parse_res == -1)
- return NSS_STATUS_TRYAGAIN;
- else
- return NSS_STATUS_NOTFOUND;
- }
- else
- return NSS_STATUS_SUCCESS;
-}
-
-enum nss_status
-_nss_nis_getpwuid_r (uid_t uid, struct passwd *pwd,
- char *buffer, size_t buflen, int *errnop)
-{
- char *domain;
- if (__glibc_unlikely (yp_get_default_domain (&domain)))
- return NSS_STATUS_UNAVAIL;
-
- char buf[32];
- int nlen = snprintf (buf, sizeof (buf), "%lu", (unsigned long int) uid);
-
- char *result;
- int len;
- int yperr = yp_match (domain, "passwd.byuid", buf, nlen, &result, &len);
-
- if (__glibc_unlikely (yperr != YPERR_SUCCESS))
- {
- enum nss_status retval = yperr2nss (yperr);
-
- if (retval == NSS_STATUS_TRYAGAIN)
- *errnop = errno;
- return retval;
- }
-
- /* Check for adjunct style secret passwords. They can be recognized
- by a password starting with "##". We do not use it if the
- passwd.adjunct.byname table is supposed to be used as a shadow.byname
- replacement. */
- char *result2;
- int len2;
- size_t namelen;
- char *p = strchr (result, ':');
- if ((_nsl_default_nss () & NSS_FLAG_ADJUNCT_AS_SHADOW) == 0
- && p != NULL /* This better should be true in all cases. */
- && p[1] == '#' && p[2] == '#'
- && (namelen = p - result,
- yp_match (domain, "passwd.adjunct.byname", result, namelen,
- &result2, &len2)) == YPERR_SUCCESS)
- {
- /* We found a passwd.adjunct.byname entry. Merge encrypted password
- therein into original result. */
- char *encrypted = strchr (result2, ':');
- char *endp;
- size_t restlen;
-
- if (encrypted == NULL
- || (endp = strchr (++encrypted, ':')) == NULL
- || (p = strchr (p + 1, ':')) == NULL)
- {
- /* Invalid format of the entry. This never should happen
- unless the data from which the NIS table is generated is
- wrong. We simply ignore it. */
- free (result2);
- goto non_adjunct;
- }
-
- restlen = len - (p - result);
- if (__builtin_expect ((size_t) (namelen + (endp - encrypted)
- + restlen + 2) > buflen, 0))
- {
- free (result2);
- free (result);
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- __mempcpy (__mempcpy (__mempcpy (__mempcpy (buffer, result, namelen),
- ":", 1),
- encrypted, endp - encrypted),
- p, restlen + 1);
- p = buffer;
-
- free (result2);
- }
- else
- {
- non_adjunct:
- if (__glibc_unlikely ((size_t) (len + 1) > buflen))
- {
- free (result);
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- p = strncpy (buffer, result, len);
- buffer[len] = '\0';
- }
-
- while (isspace (*p))
- ++p;
- free (result);
-
- int parse_res = _nss_files_parse_pwent (p, pwd, (void *) buffer, buflen,
- errnop);
- if (__glibc_unlikely (parse_res < 1))
- {
- if (parse_res == -1)
- return NSS_STATUS_TRYAGAIN;
- else
- return NSS_STATUS_NOTFOUND;
- }
- else
- return NSS_STATUS_SUCCESS;
-}
diff --git a/nis/nss_nis/nis-rpc.c b/nis/nss_nis/nis-rpc.c
deleted file mode 100644
index b118e1b01c..0000000000
--- a/nis/nss_nis/nis-rpc.c
+++ /dev/null
@@ -1,279 +0,0 @@
-/* Copyright (C) 1996-2020 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Thorsten Kukuk , 1996.
-
- 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
- . */
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "nss-nis.h"
-
-/* Get the declaration of the parser function. */
-#define ENTNAME rpcent
-#define EXTERN_PARSER
-#include
-
-__libc_lock_define_initialized (static, lock)
-
-static intern_t intern;
-
-
-static void
-internal_nis_endrpcent (intern_t *intern)
-{
- struct response_t *curr = intern->next;
-
- while (curr != NULL)
- {
- struct response_t *last = curr;
- curr = curr->next;
- free (last);
- }
-
- intern->next = intern->start = NULL;
-}
-
-static enum nss_status
-internal_nis_setrpcent (intern_t *intern)
-{
- char *domainname;
- struct ypall_callback ypcb;
- enum nss_status status;
-
- if (yp_get_default_domain (&domainname))
- return NSS_STATUS_UNAVAIL;
-
- internal_nis_endrpcent (intern);
-
- ypcb.foreach = _nis_saveit;
- ypcb.data = (char *) intern;
- status = yperr2nss (yp_all (domainname, "rpc.bynumber", &ypcb));
-
- /* Mark the last buffer as full. */
- if (intern->next != NULL)
- intern->next->size = intern->offset;
-
- intern->next = intern->start;
- intern->offset = 0;
-
- return status;
-}
-
-enum nss_status
-_nss_nis_setrpcent (int stayopen)
-{
- enum nss_status status;
-
- __libc_lock_lock (lock);
-
- status = internal_nis_setrpcent (&intern);
-
- __libc_lock_unlock (lock);
-
- return status;
-}
-
-enum nss_status
-_nss_nis_endrpcent (void)
-{
- __libc_lock_lock (lock);
-
- internal_nis_endrpcent (&intern);
-
- __libc_lock_unlock (lock);
-
- return NSS_STATUS_SUCCESS;
-}
-
-static enum nss_status
-internal_nis_getrpcent_r (struct rpcent *rpc, char *buffer, size_t buflen,
- int *errnop, intern_t *intern)
-{
- struct parser_data *pdata = (void *) buffer;
- int parse_res;
- char *p;
-
- if (intern->start == NULL)
- internal_nis_setrpcent (intern);
-
- if (intern->next == NULL)
- /* Not one entry in the map. */
- return NSS_STATUS_NOTFOUND;
-
- /* Get the next entry until we found a correct one. */
- do
- {
- struct response_t *bucket = intern->next;
-
- if (__glibc_unlikely (intern->offset >= bucket->size))
- {
- if (bucket->next == NULL)
- return NSS_STATUS_NOTFOUND;
-
- /* We look at all the content in the current bucket. Go on
- to the next. */
- bucket = intern->next = bucket->next;
- intern->offset = 0;
- }
-
- for (p = &bucket->mem[intern->offset]; isspace (*p); ++p)
- ++intern->offset;
-
- size_t len = strlen (p) + 1;
- if (__glibc_unlikely (len > buflen))
- {
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- /* We unfortunately have to copy the data in the user-provided
- buffer because that buffer might be around for a very long
- time and the servent structure must remain valid. If we would
- rely on the BUCKET memory the next 'setservent' or 'endservent'
- call would destroy it.
-
- The important thing is that it is a single NUL-terminated
- string. This is what the parsing routine expects. */
- p = memcpy (buffer, &bucket->mem[intern->offset], len);
-
- parse_res = _nss_files_parse_rpcent (p, rpc, pdata, buflen, errnop);
- if (__glibc_unlikely (parse_res == -1))
- return NSS_STATUS_TRYAGAIN;
-
- intern->offset += len;
- }
- while (!parse_res);
-
- return NSS_STATUS_SUCCESS;
-}
-
-enum nss_status
-_nss_nis_getrpcent_r (struct rpcent *rpc, char *buffer, size_t buflen,
- int *errnop)
-{
- enum nss_status status;
-
- __libc_lock_lock (lock);
-
- status = internal_nis_getrpcent_r (rpc, buffer, buflen, errnop, &intern);
-
- __libc_lock_unlock (lock);
-
- return status;
-}
-
-enum nss_status
-_nss_nis_getrpcbyname_r (const char *name, struct rpcent *rpc,
- char *buffer, size_t buflen, int *errnop)
-{
- if (name == NULL)
- {
- *errnop = EINVAL;
- return NSS_STATUS_UNAVAIL;
- }
-
- intern_t data = { NULL, NULL, 0 };
- enum nss_status status = internal_nis_setrpcent (&data);
- if (__glibc_unlikely (status != NSS_STATUS_SUCCESS))
- return status;
-
- int found = 0;
- while (!found
- && ((status = internal_nis_getrpcent_r (rpc, buffer, buflen, errnop,
- &data)) == NSS_STATUS_SUCCESS))
- {
- if (strcmp (rpc->r_name, name) == 0)
- found = 1;
- else
- {
- int i = 0;
-
- while (rpc->r_aliases[i] != NULL)
- {
- if (strcmp (rpc->r_aliases[i], name) == 0)
- {
- found = 1;
- break;
- }
- else
- ++i;
- }
- }
- }
-
- internal_nis_endrpcent (&data);
-
- if (__glibc_unlikely (!found && status == NSS_STATUS_SUCCESS))
- return NSS_STATUS_NOTFOUND;
-
- return status;
-}
-
-enum nss_status
-_nss_nis_getrpcbynumber_r (int number, struct rpcent *rpc,
- char *buffer, size_t buflen, int *errnop)
-{
- char *domain;
- if (__glibc_unlikely (yp_get_default_domain (&domain)))
- return NSS_STATUS_UNAVAIL;
-
- char buf[32];
- int nlen = snprintf (buf, sizeof (buf), "%d", number);
-
- char *result;
- int len;
- int yperr = yp_match (domain, "rpc.bynumber", buf, nlen, &result, &len);
-
- if (__glibc_unlikely (yperr != YPERR_SUCCESS))
- {
- enum nss_status retval = yperr2nss (yperr);
-
- if (retval == NSS_STATUS_TRYAGAIN)
- *errnop = errno;
- return retval;
- }
-
- if (__glibc_unlikely ((size_t) (len + 1) > buflen))
- {
- free (result);
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- char *p = strncpy (buffer, result, len);
- buffer[len] = '\0';
- while (isspace (*p))
- ++p;
- free (result);
-
- int parse_res = _nss_files_parse_rpcent (p, rpc, (void *) buffer, buflen,
- errnop);
- if (__glibc_unlikely (parse_res < 1))
- {
- if (parse_res == -1)
- return NSS_STATUS_TRYAGAIN;
- else
- return NSS_STATUS_NOTFOUND;
- }
- else
- return NSS_STATUS_SUCCESS;
-}
diff --git a/nis/nss_nis/nis-service.c b/nis/nss_nis/nis-service.c
deleted file mode 100644
index 61a8ff5f46..0000000000
--- a/nis/nss_nis/nis-service.c
+++ /dev/null
@@ -1,438 +0,0 @@
-/* Copyright (C) 1996-2020 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Thorsten Kukuk , 1996.
-
- 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
- . */
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "nss-nis.h"
-#include
-
-
-/* Get the declaration of the parser function. */
-#define ENTNAME servent
-#define EXTERN_PARSER
-#include
-
-__libc_lock_define_initialized (static, lock)
-
-static intern_t intern;
-
-struct search_t
-{
- const char *name;
- const char *proto;
- int port;
- enum nss_status status;
- struct servent *serv;
- char *buffer;
- size_t buflen;
- int *errnop;
-};
-
-static int
-dosearch (int instatus, char *inkey, int inkeylen, char *inval,
- int invallen, char *indata)
-{
- struct search_t *req = (struct search_t *) indata;
-
- if (__glibc_unlikely (instatus != YP_TRUE))
- return 1;
-
- if (inkey && inkeylen > 0 && inval && invallen > 0)
- {
- if (__glibc_unlikely ((size_t) (invallen + 1) > req->buflen))
- {
- *req->errnop = ERANGE;
- req->status = NSS_STATUS_TRYAGAIN;
- return 1;
- }
-
- char *p = strncpy (req->buffer, inval, invallen);
- req->buffer[invallen] = '\0';
- while (isspace (*p))
- ++p;
-
- int parse_res = _nss_files_parse_servent (p, req->serv,
- (void *) req->buffer,
- req->buflen, req->errnop);
- if (parse_res == -1)
- {
- req->status = NSS_STATUS_TRYAGAIN;
- return 1;
- }
-
- if (!parse_res)
- return 0;
-
- if (req->proto != NULL && strcmp (req->serv->s_proto, req->proto) != 0)
- return 0;
-
- if (req->port != -1 && req->serv->s_port != req->port)
- return 0;
-
- if (req->name != NULL && strcmp (req->serv->s_name, req->name) != 0)
- {
- char **cp;
- for (cp = req->serv->s_aliases; *cp; cp++)
- if (strcmp (req->name, *cp) == 0)
- break;
-
- if (*cp == NULL)
- return 0;
- }
-
- req->status = NSS_STATUS_SUCCESS;
- return 1;
- }
-
- return 0;
-}
-
-static void
-internal_nis_endservent (void)
-{
- struct response_t *curr = intern.next;
-
- while (curr != NULL)
- {
- struct response_t *last = curr;
- curr = curr->next;
- free (last);
- }
-
- intern.next = intern.start = NULL;
-}
-
-enum nss_status
-_nss_nis_endservent (void)
-{
- __libc_lock_lock (lock);
-
- internal_nis_endservent ();
-
- __libc_lock_unlock (lock);
-
- return NSS_STATUS_SUCCESS;
-}
-
-static enum nss_status
-internal_nis_setservent (void)
-{
- char *domainname;
- struct ypall_callback ypcb;
- enum nss_status status;
-
- if (yp_get_default_domain (&domainname))
- return NSS_STATUS_UNAVAIL;
-
- internal_nis_endservent ();
-
- ypcb.foreach = _nis_saveit;
- ypcb.data = (char *) &intern;
- status = yperr2nss (yp_all (domainname, "services.byname", &ypcb));
-
- /* Mark the last buffer as full. */
- if (intern.next != NULL)
- intern.next->size = intern.offset;
-
- intern.next = intern.start;
- intern.offset = 0;
-
- return status;
-}
-
-enum nss_status
-_nss_nis_setservent (int stayopen)
-{
- enum nss_status status;
-
- __libc_lock_lock (lock);
-
- status = internal_nis_setservent ();
-
- __libc_lock_unlock (lock);
-
- return status;
-}
-
-static enum nss_status
-internal_nis_getservent_r (struct servent *serv, char *buffer,
- size_t buflen, int *errnop)
-{
- struct parser_data *pdata = (void *) buffer;
- int parse_res;
- char *p;
-
- if (intern.start == NULL)
- internal_nis_setservent ();
-
- if (intern.next == NULL)
- /* Not one entry in the map. */
- return NSS_STATUS_NOTFOUND;
-
- /* Get the next entry until we found a correct one. */
- do
- {
- struct response_t *bucket = intern.next;
-
- if (__glibc_unlikely (intern.offset >= bucket->size))
- {
- if (bucket->next == NULL)
- return NSS_STATUS_NOTFOUND;
-
- /* We look at all the content in the current bucket. Go on
- to the next. */
- bucket = intern.next = bucket->next;
- intern.offset = 0;
- }
-
- for (p = &bucket->mem[intern.offset]; isspace (*p); ++p)
- ++intern.offset;
-
- size_t len = strlen (p) + 1;
- if (__glibc_unlikely (len > buflen))
- {
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- /* We unfortunately have to copy the data in the user-provided
- buffer because that buffer might be around for a very long
- time and the servent structure must remain valid. If we would
- rely on the BUCKET memory the next 'setservent' or 'endservent'
- call would destroy it.
-
- The important thing is that it is a single NUL-terminated
- string. This is what the parsing routine expects. */
- p = memcpy (buffer, &bucket->mem[intern.offset], len);
-
- parse_res = _nss_files_parse_servent (p, serv, pdata, buflen, errnop);
- if (__glibc_unlikely (parse_res == -1))
- return NSS_STATUS_TRYAGAIN;
-
- intern.offset += len;
- }
- while (!parse_res);
-
- return NSS_STATUS_SUCCESS;
-}
-
-enum nss_status
-_nss_nis_getservent_r (struct servent *serv, char *buffer, size_t buflen,
- int *errnop)
-{
- enum nss_status status;
-
- __libc_lock_lock (lock);
-
- status = internal_nis_getservent_r (serv, buffer, buflen, errnop);
-
- __libc_lock_unlock (lock);
-
- return status;
-}
-
-enum nss_status
-_nss_nis_getservbyname_r (const char *name, const char *protocol,
- struct servent *serv, char *buffer, size_t buflen,
- int *errnop)
-{
- if (name == NULL)
- {
- *errnop = EINVAL;
- return NSS_STATUS_UNAVAIL;
- }
-
- char *domain;
- if (__glibc_unlikely (yp_get_default_domain (&domain)))
- return NSS_STATUS_UNAVAIL;
-
- /* If the protocol is given, we could try if our NIS server knows
- about services.byservicename map. If yes, we only need one query. */
- size_t keylen = strlen (name) + (protocol ? 1 + strlen (protocol) : 0);
- /* Limit key length to the maximum size of an RPC packet. */
- if (keylen > UDPMSGSIZE)
- {
- *errnop = ERANGE;
- return NSS_STATUS_UNAVAIL;
- }
-
- char key[keylen + 1];
-
- /* key is: "name/proto" */
- char *cp = stpcpy (key, name);
- if (protocol != NULL)
- {
- *cp++ = '/';
- strcpy (cp, protocol);
- }
-
- char *result;
- int int_len;
- int status = yp_match (domain, "services.byservicename", key,
- keylen, &result, &int_len);
- size_t len = int_len;
-
- /* If we found the key, it's ok and parse the result. If not,
- fall through and parse the complete table. */
- if (__glibc_likely (status == YPERR_SUCCESS))
- {
- if (__glibc_unlikely ((size_t) (len + 1) > buflen))
- {
- free (result);
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- char *p = strncpy (buffer, result, len);
- buffer[len] = '\0';
- while (isspace (*p))
- ++p;
- free (result);
-
- int parse_res = _nss_files_parse_servent (p, serv, (void *) buffer,
- buflen, errnop);
- if (__glibc_unlikely (parse_res < 0))
- {
- if (parse_res == -1)
- return NSS_STATUS_TRYAGAIN;
- else
- return NSS_STATUS_NOTFOUND;
- }
- else
- return NSS_STATUS_SUCCESS;
- }
-
- /* Check if it is safe to rely on services.byservicename. */
- if (_nsl_default_nss () & NSS_FLAG_SERVICES_AUTHORITATIVE)
- return yperr2nss (status);
-
- struct ypall_callback ypcb;
- struct search_t req;
-
- ypcb.foreach = dosearch;
- ypcb.data = (char *) &req;
- req.name = name;
- req.proto = protocol;
- req.port = -1;
- req.serv = serv;
- req.buffer = buffer;
- req.buflen = buflen;
- req.errnop = errnop;
- req.status = NSS_STATUS_NOTFOUND;
- status = yp_all (domain, "services.byname", &ypcb);
-
- if (__glibc_unlikely (status != YPERR_SUCCESS))
- return yperr2nss (status);
-
- return req.status;
-}
-
-enum nss_status
-_nss_nis_getservbyport_r (int port, const char *protocol,
- struct servent *serv, char *buffer,
- size_t buflen, int *errnop)
-{
- char *domain;
- if (__glibc_unlikely (yp_get_default_domain (&domain)))
- return NSS_STATUS_UNAVAIL;
-
- /* If the protocol is given, we only need one query.
- Otherwise try first port/tcp, then port/udp and then fallback
- to sequential scanning of services.byname. */
- const char *proto = protocol != NULL ? protocol : "tcp";
- /* Limit protocol name length to the maximum size of an RPC packet. */
- if (strlen (proto) > UDPMSGSIZE)
- {
- *errnop = ERANGE;
- return NSS_STATUS_UNAVAIL;
- }
-
- do
- {
- /* key is: "port/proto" */
- char key[sizeof (int) * 3 + strlen (proto) + 2];
- size_t keylen = snprintf (key, sizeof (key), "%d/%s", ntohs (port),
- proto);
-
- char *result;
- int int_len;
- int status = yp_match (domain, "services.byname", key, keylen, &result,
- &int_len);
- size_t len = int_len;
-
- /* If we found the key, it's ok and parse the result. If not,
- fall through and parse the complete table. */
- if (__glibc_likely (status == YPERR_SUCCESS))
- {
- if (__glibc_unlikely ((size_t) (len + 1) > buflen))
- {
- free (result);
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- char *p = strncpy (buffer, result, len);
- buffer[len] = '\0';
- while (isspace (*p))
- ++p;
- free (result);
- int parse_res = _nss_files_parse_servent (p, serv, (void *) buffer,
- buflen, errnop);
- if (__glibc_unlikely (parse_res < 0))
- {
- if (parse_res == -1)
- return NSS_STATUS_TRYAGAIN;
- else
- return NSS_STATUS_NOTFOUND;
- }
-
- return NSS_STATUS_SUCCESS;
- }
- }
- while (protocol == NULL && (proto[0] == 't' ? (proto = "udp") : NULL));
-
- if (port == -1)
- return NSS_STATUS_NOTFOUND;
-
- struct ypall_callback ypcb;
- struct search_t req;
-
- ypcb.foreach = dosearch;
- ypcb.data = (char *) &req;
- req.name = NULL;
- req.proto = protocol;
- req.port = port;
- req.serv = serv;
- req.buffer = buffer;
- req.buflen = buflen;
- req.errnop = errnop;
- req.status = NSS_STATUS_NOTFOUND;
- int status = yp_all (domain, "services.byname", &ypcb);
-
- if (__glibc_unlikely (status != YPERR_SUCCESS))
- return yperr2nss (status);
-
- return req.status;
-}
diff --git a/nis/nss_nis/nis-spwd.c b/nis/nss_nis/nis-spwd.c
deleted file mode 100644
index 9790dd4104..0000000000
--- a/nis/nss_nis/nis-spwd.c
+++ /dev/null
@@ -1,235 +0,0 @@
-/* Copyright (C) 1996-2020 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Thorsten Kukuk , 1996.
-
- 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
- . */
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "nss-nis.h"
-#include
-
-/* Get the declaration of the parser function. */
-#define ENTNAME spent
-#define STRUCTURE spwd
-#define EXTERN_PARSER
-#include
-
-/* Protect global state against multiple changers */
-__libc_lock_define_initialized (static, lock)
-
-static bool new_start = true;
-static bool ent_adjunct_used;
-static char *oldkey;
-static int oldkeylen;
-
-enum nss_status
-_nss_nis_setspent (int stayopen)
-{
- return _nss_nis_endspent ();
-}
-
-enum nss_status
-_nss_nis_endspent (void)
-{
- __libc_lock_lock (lock);
-
- new_start = true;
- ent_adjunct_used = false;
- free (oldkey);
- oldkey = NULL;
- oldkeylen = 0;
-
- __libc_lock_unlock (lock);
-
- return NSS_STATUS_SUCCESS;
-}
-libnss_nis_hidden_def (_nss_nis_endspent)
-
-static enum nss_status
-internal_nis_getspent_r (struct spwd *sp, char *buffer, size_t buflen,
- int *errnop)
-{
- char *domain;
- if (__glibc_unlikely (yp_get_default_domain (&domain)))
- return NSS_STATUS_UNAVAIL;
-
- /* Get the next entry until we found a correct one. */
- int parse_res;
- do
- {
- char *result;
- char *outkey;
- int len;
- int keylen;
- int yperr;
-
- if (new_start)
- {
- yperr = yp_first (domain, "shadow.byname", &outkey, &keylen, &result,
- &len);
- if (__builtin_expect (yperr == YPERR_MAP, 0)
- && (_nsl_default_nss () & NSS_FLAG_ADJUNCT_AS_SHADOW))
- {
- free (result);
- yperr = yp_first (domain, "passwd.adjunct.byname", &outkey,
- &keylen, &result, &len);
- ent_adjunct_used = true;
- }
- }
- else
- yperr = yp_next (domain, (ent_adjunct_used
- ? "passwd.adjunct.byname" : "shadow.byname"),
- oldkey, oldkeylen, &outkey, &keylen, &result, &len);
-
- if (__glibc_unlikely (yperr != YPERR_SUCCESS))
- {
- enum nss_status retval = yperr2nss (yperr);
-
- if (retval == NSS_STATUS_TRYAGAIN)
- *errnop = errno;
- return retval;
- }
-
- if (__builtin_expect ((size_t) (len + (ent_adjunct_used ? 3 : 1))
- > buflen, 0))
- {
- free (result);
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- char *p = strncpy (buffer, result, len);
- if (ent_adjunct_used)
- /* This is an ugly trick. The format of passwd.adjunct.byname almost
- matches the shadow.byname format except that the last two fields
- are missing. Synthesize them by marking them empty. */
- strcpy (&buffer[len], "::");
- else
- buffer[len] = '\0';
- while (isspace (*p))
- ++p;
- free (result);
-
- parse_res = _nss_files_parse_spent (p, sp, (void *) buffer, buflen,
- errnop);
- if (__builtin_expect (parse_res == -1, 0))
- {
- free (outkey);
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- free (oldkey);
- oldkey = outkey;
- oldkeylen = keylen;
- new_start = false;
- }
- while (!parse_res);
-
- return NSS_STATUS_SUCCESS;
-}
-
-enum nss_status
-_nss_nis_getspent_r (struct spwd *result, char *buffer, size_t buflen,
- int *errnop)
-{
- int status;
-
- __libc_lock_lock (lock);
-
- status = internal_nis_getspent_r (result, buffer, buflen, errnop);
-
- __libc_lock_unlock (lock);
-
- return status;
-}
-
-enum nss_status
-_nss_nis_getspnam_r (const char *name, struct spwd *sp,
- char *buffer, size_t buflen, int *errnop)
-{
- if (name == NULL)
- {
- *errnop = EINVAL;
- return NSS_STATUS_UNAVAIL;
- }
- const size_t name_len = strlen (name);
-
- char *domain;
- if (__glibc_unlikely (yp_get_default_domain (&domain)))
- return NSS_STATUS_UNAVAIL;
-
- bool adjunct_used = false;
- char *result;
- int len;
- int yperr = yp_match (domain, "shadow.byname", name, name_len, &result,
- &len);
- if (__builtin_expect (yperr == YPERR_MAP, 0)
- && (_nsl_default_nss () & NSS_FLAG_ADJUNCT_AS_SHADOW))
- {
- free (result);
- yperr = yp_match (domain, "passwd.adjunct.byname", name, name_len,
- &result, &len);
- adjunct_used = true;
- }
-
- if (__glibc_unlikely (yperr != YPERR_SUCCESS))
- {
- enum nss_status retval = yperr2nss (yperr);
-
- if (retval == NSS_STATUS_TRYAGAIN)
- *errnop = errno;
- return retval;
- }
-
- if (__glibc_unlikely ((size_t) (len + (adjunct_used ? 3 : 1)) > buflen))
- {
- free (result);
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- char *p = strncpy (buffer, result, len);
- if (__builtin_expect (adjunct_used, false))
- /* This is an ugly trick. The format of passwd.adjunct.byname almost
- matches the shadow.byname format except that the last two fields
- are missing. Synthesize them by marking them empty. */
- strcpy (&buffer[len], "::");
- else
- buffer[len] = '\0';
- while (isspace (*p))
- ++p;
- free (result);
-
- int parse_res = _nss_files_parse_spent (p, sp, (void *) buffer, buflen,
- errnop);
- if (__glibc_unlikely (parse_res < 1))
- {
- if (parse_res == -1)
- return NSS_STATUS_TRYAGAIN;
- else
- return NSS_STATUS_NOTFOUND;
- }
- return NSS_STATUS_SUCCESS;
-}
diff --git a/nis/nss_nisplus/nisplus-alias.c b/nis/nss_nisplus/nisplus-alias.c
deleted file mode 100644
index d938763ac9..0000000000
--- a/nis/nss_nisplus/nisplus-alias.c
+++ /dev/null
@@ -1,337 +0,0 @@
-/* Copyright (C) 1997-2020 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Thorsten Kukuk , 1997.
-
- 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
- . */
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "nss-nisplus.h"
-
-__libc_lock_define_initialized (static, lock)
-
-static nis_result *result;
-static u_long next_entry;
-static nis_name tablename_val;
-static size_t tablename_len;
-
-#define NISENTRYVAL(idx, col, res) \
- (NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_val)
-
-#define NISENTRYLEN(idx, col, res) \
- (NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len)
-
-static enum nss_status
-_nss_create_tablename (int *errnop)
-{
- if (tablename_val == NULL)
- {
- const char *local_dir = nis_local_directory ();
- size_t local_dir_len = strlen (local_dir);
- static const char prefix[] = "mail_aliases.org_dir.";
-
- char *p = malloc (sizeof (prefix) + local_dir_len);
- if (p == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
-
- memcpy (__stpcpy (p, prefix), local_dir, local_dir_len + 1);
-
- tablename_len = sizeof (prefix) - 1 + local_dir_len;
-
- atomic_write_barrier ();
-
- tablename_val = p;
- }
-
- return NSS_STATUS_SUCCESS;
-}
-
-static int
-_nss_nisplus_parse_aliasent (nis_result *result, unsigned long entry,
- struct aliasent *alias, char *buffer,
- size_t buflen, int *errnop)
-{
- if (result == NULL)
- return 0;
-
- if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS)
- || __type_of (&NIS_RES_OBJECT (result)[entry]) != NIS_ENTRY_OBJ
- || strcmp (NIS_RES_OBJECT (result)[entry].EN_data.en_type,
- "mail_aliases") != 0
- || NIS_RES_OBJECT (result)[entry].EN_data.en_cols.en_cols_len < 2)
- return 0;
-
- if (NISENTRYLEN (entry, 1, result) >= buflen)
- {
- /* The line is too long for our buffer. */
- no_more_room:
- *errnop = ERANGE;
- return -1;
- }
-
- char *cp = __stpncpy (buffer, NISENTRYVAL (entry, 1, result),
- NISENTRYLEN (entry, 1, result));
- *cp = '\0';
-
- char *first_unused = cp + 1;
- size_t room_left = buflen - (first_unused - buffer);
-
- alias->alias_local = 0;
- alias->alias_members_len = 0;
-
- if (NISENTRYLEN (entry, 0, result) >= room_left)
- goto no_more_room;
-
- cp = __stpncpy (first_unused, NISENTRYVAL (entry, 0, result),
- NISENTRYLEN (entry, 0, result));
- *cp = '\0';
- alias->alias_name = first_unused;
-
- /* Terminate the line for any case. */
- cp = strpbrk (alias->alias_name, "#\n");
- if (cp != NULL)
- *cp = '\0';
-
- size_t len = strlen (alias->alias_name) + 1;
- first_unused += len;
- room_left -= len;
-
- /* Adjust the pointer so it is aligned for
- storing pointers. */
- size_t adjust = ((__alignof__ (char *)
- - (first_unused - (char *) 0) % __alignof__ (char *))
- % __alignof__ (char *));
- if (room_left < adjust)
- goto no_more_room;
- first_unused += adjust;
- room_left -= adjust;
-
- alias->alias_members = (char **) first_unused;
-
- char *line = buffer;
- while (*line != '\0')
- {
- /* Skip leading blanks. */
- while (isspace (*line))
- ++line;
-
- if (*line == '\0')
- break;
-
- if (room_left < sizeof (char *))
- goto no_more_room;
- room_left -= sizeof (char *);
- alias->alias_members[alias->alias_members_len] = line;
-
- while (*line != '\0' && *line != ',')
- ++line;
-
- if (line != alias->alias_members[alias->alias_members_len])
- {
- *line++ = '\0';
- ++alias->alias_members_len;
- }
- else if (*line == ',')
- ++line;
- }
-
- return alias->alias_members_len == 0 ? 0 : 1;
-}
-
-static enum nss_status
-internal_setaliasent (void)
-{
- enum nss_status status;
- int err;
-
- if (result != NULL)
- {
- nis_freeresult (result);
- result = NULL;
- }
-
- if (_nss_create_tablename (&err) != NSS_STATUS_SUCCESS)
- return NSS_STATUS_UNAVAIL;
-
- next_entry = 0;
- result = nis_list (tablename_val, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
- if (result == NULL)
- {
- status = NSS_STATUS_TRYAGAIN;
- __set_errno (ENOMEM);
- }
- else
- {
- status = niserr2nss (result->status);
- if (status != NSS_STATUS_SUCCESS)
- {
- nis_freeresult (result);
- result = NULL;
- }
- }
- return status;
-}
-
-enum nss_status
-_nss_nisplus_setaliasent (void)
-{
- enum nss_status status;
-
- __libc_lock_lock (lock);
-
- status = internal_setaliasent ();
-
- __libc_lock_unlock (lock);
-
- return status;
-}
-
-enum nss_status
-_nss_nisplus_endaliasent (void)
-{
- __libc_lock_lock (lock);
-
- if (result != NULL)
- {
- nis_freeresult (result);
- result = NULL;
- }
- next_entry = 0;
-
- __libc_lock_unlock (lock);
-
- return NSS_STATUS_SUCCESS;
-}
-
-static enum nss_status
-internal_nisplus_getaliasent_r (struct aliasent *alias,
- char *buffer, size_t buflen, int *errnop)
-{
- int parse_res;
-
- if (result == NULL)
- {
- enum nss_status status;
-
- status = internal_setaliasent ();
- if (result == NULL || status != NSS_STATUS_SUCCESS)
- return status;
- }
-
- /* Get the next entry until we found a correct one. */
- do
- {
- if (next_entry >= result->objects.objects_len)
- return NSS_STATUS_NOTFOUND;
-
- parse_res = _nss_nisplus_parse_aliasent (result, next_entry, alias,
- buffer, buflen, errnop);
- if (parse_res == -1)
- return NSS_STATUS_TRYAGAIN;
-
- ++next_entry;
- }
- while (!parse_res);
-
- return NSS_STATUS_SUCCESS;
-}
-
-enum nss_status
-_nss_nisplus_getaliasent_r (struct aliasent *result, char *buffer,
- size_t buflen, int *errnop)
-{
- int status;
-
- __libc_lock_lock (lock);
-
- status = internal_nisplus_getaliasent_r (result, buffer, buflen, errnop);
-
- __libc_lock_unlock (lock);
-
- return status;
-}
-
-enum nss_status
-_nss_nisplus_getaliasbyname_r (const char *name, struct aliasent *alias,
- char *buffer, size_t buflen, int *errnop)
-{
- int parse_res;
-
- if (tablename_val == NULL)
- {
- __libc_lock_lock (lock);
-
- enum nss_status status = _nss_create_tablename (errnop);
-
- __libc_lock_unlock (lock);
-
- if (status != NSS_STATUS_SUCCESS)
- return status;
- }
-
- if (name == NULL)
- {
- *errnop = EINVAL;
- return NSS_STATUS_UNAVAIL;
- }
-
- char buf[strlen (name) + 9 + tablename_len];
- int olderr = errno;
-
- snprintf (buf, sizeof (buf), "[name=%s],%s", name, tablename_val);
-
- nis_result *result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
-
- if (result == NULL)
- {
- *errnop = ENOMEM;
- return NSS_STATUS_TRYAGAIN;
- }
-
- if (__glibc_unlikely (niserr2nss (result->status) != NSS_STATUS_SUCCESS))
- {
- enum nss_status status = niserr2nss (result->status);
- nis_freeresult (result);
- return status;
- }
-
- parse_res = _nss_nisplus_parse_aliasent (result, 0, alias,
- buffer, buflen, errnop);
-
- /* We do not need the lookup result anymore. */
- nis_freeresult (result);
-
- if (__glibc_unlikely (parse_res < 1))
- {
- __set_errno (olderr);
-
- if (parse_res == -1)
- return NSS_STATUS_TRYAGAIN;
- else
- return NSS_STATUS_NOTFOUND;
- }
-
- return NSS_STATUS_SUCCESS;
-}
diff --git a/nis/nss_nisplus/nisplus-ethers.c b/nis/nss_nisplus/nisplus-ethers.c
deleted file mode 100644
index 51aa6a6e83..0000000000
--- a/nis/nss_nisplus/nisplus-ethers.c
+++ /dev/null
@@ -1,356 +0,0 @@
-/* Copyright (C) 1997-2020 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Thorsten Kukuk , 1997.
-
- 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
- . */
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "nss-nisplus.h"
-
-__libc_lock_define_initialized (static, lock)
-
-static nis_result *result;
-static nis_name tablename_val;
-static u_long tablename_len;
-
-
-#define NISENTRYVAL(idx, col, res) \
- (NIS_RES_OBJECT (res)[idx].zo_data.objdata_u.en_data.en_cols.en_cols_val[col].ec_value.ec_value_val)
-
-#define NISENTRYLEN(idx, col, res) \
- (NIS_RES_OBJECT (res)[idx].zo_data.objdata_u.en_data.en_cols.en_cols_val[col].ec_value.ec_value_len)
-
-static int
-_nss_nisplus_parse_etherent (nis_result *result, struct etherent *ether,
- char *buffer, size_t buflen, int *errnop)
-{
- char *p = buffer;
- size_t room_left = buflen;
-
- if (result == NULL)
- return 0;
-
- if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS)
- || NIS_RES_NUMOBJ (result) != 1
- || __type_of (NIS_RES_OBJECT (result)) != NIS_ENTRY_OBJ
- || strcmp (NIS_RES_OBJECT (result)->EN_data.en_type,
- "ethers_tbl") != 0
- || NIS_RES_OBJECT (result)->EN_data.en_cols.en_cols_len < 2)
- return 0;
-
- /* Generate the ether entry format and use the normal parser */
- if (NISENTRYLEN (0, 0, result) + 1 > room_left)
- {
- *errnop = ERANGE;
- return -1;
- }
- char *cp = __stpncpy (p, NISENTRYVAL (0, 0, result),
- NISENTRYLEN (0, 0, result));
- *cp = '\0';
- room_left -= NISENTRYLEN (0, 0, result) + 1;
- ether->e_name = p;
-
- struct ether_addr *ea = ether_aton (NISENTRYVAL (0, 1, result));
- if (ea == NULL)
- {
- *errnop = EINVAL;
- return -2;
- }
-
- ether->e_addr = *ea;
-
- return 1;
-}
-
-static enum nss_status
-_nss_create_tablename (int *errnop)
-{
- if (tablename_val == NULL)
- {
- const char *local_dir = nis_local_directory ();
- size_t local_dir_len = strlen (local_dir);
- static const char prefix[] = "ethers.org_dir.";
-
- char *p = malloc (sizeof (prefix) + local_dir_len);
- if (p == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
-
- memcpy (__stpcpy (p, prefix), local_dir, local_dir_len + 1);
-
- tablename_len = sizeof (prefix) - 1 + local_dir_len;
-
- atomic_write_barrier ();
-
- tablename_val = p;
- }
- return NSS_STATUS_SUCCESS;
-}
-
-
-enum nss_status
-_nss_nisplus_setetherent (int stayopen)
-{
- enum nss_status status;
- int err;
-
- status = NSS_STATUS_SUCCESS;
-
- __libc_lock_lock (lock);
-
- if (result != NULL)
- {
- nis_freeresult (result);
- result = NULL;
- }
-
- if (_nss_create_tablename (&err) != NSS_STATUS_SUCCESS)
- status = NSS_STATUS_UNAVAIL;
-
- __libc_lock_unlock (lock);
-
- return status;
-}
-
-enum nss_status
-_nss_nisplus_endetherent (void)
-{
- __libc_lock_lock (lock);
-
- if (result != NULL)
- {
- nis_freeresult (result);
- result = NULL;
- }
-
- __libc_lock_unlock (lock);
-
- return NSS_STATUS_SUCCESS;
-}
-
-static enum nss_status
-internal_nisplus_getetherent_r (struct etherent *ether, char *buffer,
- size_t buflen, int *errnop)
-{
- if (tablename_val == NULL)
- {
- enum nss_status status = _nss_create_tablename (errnop);
-
- if (status != NSS_STATUS_SUCCESS)
- return status;
- }
-
- /* Get the next entry until we found a correct one. */
- int parse_res;
- do
- {
- nis_result *saved_result;
-
- if (result == NULL)
- {
- saved_result = NULL;
- result = nis_first_entry (tablename_val);
- if (result == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
- if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
- return niserr2nss (result->status);
- }
- else
- {
- saved_result = result;
- result = nis_next_entry (tablename_val, &result->cookie);
- if (result == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
- if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
- {
- nis_freeresult (saved_result);
- return niserr2nss (result->status);
- }
- }
-
- parse_res = _nss_nisplus_parse_etherent (result, ether, buffer,
- buflen, errnop);
- if (parse_res == -1)
- {
- nis_freeresult (result);
- result = saved_result;
- return NSS_STATUS_TRYAGAIN;
- }
-
- if (saved_result != NULL)
- nis_freeresult (saved_result);
-
- }
- while (!parse_res);
-
- return NSS_STATUS_SUCCESS;
-}
-
-enum nss_status
-_nss_nisplus_getetherent_r (struct etherent *result, char *buffer,
- size_t buflen, int *errnop)
-{
- int status;
-
- __libc_lock_lock (lock);
-
- status = internal_nisplus_getetherent_r (result, buffer, buflen, errnop);
-
- __libc_lock_unlock (lock);
-
- return status;
-}
-
-enum nss_status
-_nss_nisplus_gethostton_r (const char *name, struct etherent *eth,
- char *buffer, size_t buflen, int *errnop)
-{
- if (tablename_val == NULL)
- {
- enum nss_status status = _nss_create_tablename (errnop);
-
- if (status != NSS_STATUS_SUCCESS)
- return status;
- }
-
- if (name == NULL)
- {
- *errnop = EINVAL;
- return NSS_STATUS_UNAVAIL;
- }
-
- char buf[strlen (name) + 9 + tablename_len];
- int olderr = errno;
-
- snprintf (buf, sizeof (buf), "[name=%s],%s", name, tablename_val);
-
- nis_result *result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS | USE_DGRAM,
- NULL, NULL);
-
- if (result == NULL)
- {
- *errnop = ENOMEM;
- return NSS_STATUS_TRYAGAIN;
- }
-
- if (__glibc_unlikely (niserr2nss (result->status) != NSS_STATUS_SUCCESS))
- {
- enum nss_status status = niserr2nss (result->status);
- nis_freeresult (result);
- return status;
- }
-
- int parse_res = _nss_nisplus_parse_etherent (result, eth, buffer,
- buflen, errnop);
-
- /* We do not need the lookup result anymore. */
- nis_freeresult (result);
-
- if (__glibc_unlikely (parse_res < 1))
- {
- __set_errno (olderr);
-
- if (parse_res == -1)
- return NSS_STATUS_TRYAGAIN;
-
- return NSS_STATUS_NOTFOUND;
- }
-
- return NSS_STATUS_SUCCESS;
-}
-
-enum nss_status
-_nss_nisplus_getntohost_r (const struct ether_addr *addr, struct etherent *eth,
- char *buffer, size_t buflen, int *errnop)
-{
- if (tablename_val == NULL)
- {
- __libc_lock_lock (lock);
-
- enum nss_status status = _nss_create_tablename (errnop);
-
- __libc_lock_unlock (lock);
-
- if (status != NSS_STATUS_SUCCESS)
- return status;
- }
-
- if (addr == NULL)
- {
- *errnop = EINVAL;
- return NSS_STATUS_UNAVAIL;
- }
-
- char buf[26 + tablename_len];
-
- snprintf (buf, sizeof (buf),
- "[addr=%" PRIx8 ":%" PRIx8 ":%" PRIx8 ":%" PRIx8 ":%" PRIx8
- ":%" PRIx8 "],%s",
- addr->ether_addr_octet[0], addr->ether_addr_octet[1],
- addr->ether_addr_octet[2], addr->ether_addr_octet[3],
- addr->ether_addr_octet[4], addr->ether_addr_octet[5],
- tablename_val);
-
- nis_result *result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS | USE_DGRAM,
- NULL, NULL);
-
- if (result == NULL)
- {
- *errnop = ENOMEM;
- return NSS_STATUS_TRYAGAIN;
- }
-
- if (__glibc_unlikely (niserr2nss (result->status) != NSS_STATUS_SUCCESS))
- {
- enum nss_status status = niserr2nss (result->status);
- nis_freeresult (result);
- return status;
- }
-
- int parse_res = _nss_nisplus_parse_etherent (result, eth, buffer,
- buflen, errnop);
-
- /* We do not need the lookup result anymore. */
- nis_freeresult (result);
-
- if (__glibc_unlikely (parse_res < 1))
- {
- if (parse_res == -1)
- return NSS_STATUS_TRYAGAIN;
-
- return NSS_STATUS_NOTFOUND;
- }
-
- return NSS_STATUS_SUCCESS;
-}
diff --git a/nis/nss_nisplus/nisplus-grp.c b/nis/nss_nisplus/nisplus-grp.c
deleted file mode 100644
index 8223c37bb9..0000000000
--- a/nis/nss_nisplus/nisplus-grp.c
+++ /dev/null
@@ -1,401 +0,0 @@
-/* Copyright (C) 1997-2020 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Thorsten Kukuk , 1997.
-
- 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
- . */
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "nss-nisplus.h"
-#include "nisplus-parser.h"
-#include
-#include
-#include
-
-
-__libc_lock_define_initialized (static, lock);
-
-/* Connection information. */
-static ib_request *ibreq;
-static directory_obj *dir;
-static dir_binding bptr;
-static char *tablepath;
-static char *tableptr;
-/* Cursor. */
-static netobj cursor;
-
-
-nis_name grp_tablename_val attribute_hidden;
-size_t grp_tablename_len attribute_hidden;
-
-enum nss_status
-_nss_grp_create_tablename (int *errnop)
-{
- if (grp_tablename_val == NULL)
- {
- const char *local_dir = nis_local_directory ();
- size_t local_dir_len = strlen (local_dir);
- static const char prefix[] = "group.org_dir.";
-
- char *p = malloc (sizeof (prefix) + local_dir_len);
- if (p == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
-
- memcpy (__stpcpy (p, prefix), local_dir, local_dir_len + 1);
-
- grp_tablename_len = sizeof (prefix) - 1 + local_dir_len;
-
- atomic_write_barrier ();
-
- if (atomic_compare_and_exchange_bool_acq (&grp_tablename_val, p, NULL))
- {
- /* Another thread already installed the value. */
- free (p);
- grp_tablename_len = strlen (grp_tablename_val);
- }
- }
-
- return NSS_STATUS_SUCCESS;
-}
-
-
-static void
-internal_endgrent (void)
-{
- __nisbind_destroy (&bptr);
- memset (&bptr, '\0', sizeof (bptr));
-
- nis_free_directory (dir);
- dir = NULL;
-
- nis_free_request (ibreq);
- ibreq = NULL;
-
- xdr_free ((xdrproc_t) xdr_netobj, (char *) &cursor);
- memset (&cursor, '\0', sizeof (cursor));
-
- free (tablepath);
- tableptr = tablepath = NULL;
-}
-
-
-static enum nss_status
-internal_setgrent (int *errnop)
-{
- enum nss_status status = NSS_STATUS_SUCCESS;
-
- if (grp_tablename_val == NULL)
- status = _nss_grp_create_tablename (errnop);
-
- if (status == NSS_STATUS_SUCCESS)
- {
- ibreq = __create_ib_request (grp_tablename_val, 0);
- if (ibreq == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
-
- nis_error retcode = __prepare_niscall (grp_tablename_val, &dir, &bptr, 0);
- if (retcode != NIS_SUCCESS)
- {
- nis_free_request (ibreq);
- ibreq = NULL;
- status = niserr2nss (retcode);
- }
- }
-
- return status;
-}
-
-
-enum nss_status
-_nss_nisplus_setgrent (int stayopen)
-{
- enum nss_status status;
-
- __libc_lock_lock (lock);
-
- internal_endgrent ();
-
- // XXX We need to be able to set errno. Pass in new parameter.
- int err;
- status = internal_setgrent (&err);
-
- __libc_lock_unlock (lock);
-
- return status;
-}
-
-
-enum nss_status
-_nss_nisplus_endgrent (void)
-{
- __libc_lock_lock (lock);
-
- internal_endgrent ();
-
- __libc_lock_unlock (lock);
-
- return NSS_STATUS_SUCCESS;
-}
-
-
-static enum nss_status
-internal_nisplus_getgrent_r (struct group *gr, char *buffer, size_t buflen,
- int *errnop)
-{
- int parse_res = -1;
- enum nss_status retval = NSS_STATUS_SUCCESS;
-
- /* Get the next entry until we found a correct one. */
- do
- {
- nis_error status;
- nis_result result;
- memset (&result, '\0', sizeof (result));
-
- if (cursor.n_bytes == NULL)
- {
- if (ibreq == NULL)
- {
- retval = internal_setgrent (errnop);
- if (retval != NSS_STATUS_SUCCESS)
- return retval;
- }
-
- status = __do_niscall3 (&bptr, NIS_IBFIRST,
- (xdrproc_t) _xdr_ib_request,
- (caddr_t) ibreq,
- (xdrproc_t) _xdr_nis_result,
- (caddr_t) &result,
- 0, NULL);
- }
- else
- {
- ibreq->ibr_cookie.n_bytes = cursor.n_bytes;
- ibreq->ibr_cookie.n_len = cursor.n_len;
-
- status = __do_niscall3 (&bptr, NIS_IBNEXT,
- (xdrproc_t) _xdr_ib_request,
- (caddr_t) ibreq,
- (xdrproc_t) _xdr_nis_result,
- (caddr_t) &result,
- 0, NULL);
-
- ibreq->ibr_cookie.n_bytes = NULL;
- ibreq->ibr_cookie.n_len = 0;
- }
-
- if (status != NIS_SUCCESS)
- return niserr2nss (status);
-
- if (NIS_RES_STATUS (&result) == NIS_NOTFOUND)
- {
- /* No more entries on this server. This means we have to go
- to the next server on the path. */
- status = __follow_path (&tablepath, &tableptr, ibreq, &bptr);
- if (status != NIS_SUCCESS)
- return niserr2nss (status);
-
- directory_obj *newdir = NULL;
- dir_binding newbptr;
- status = __prepare_niscall (ibreq->ibr_name, &newdir, &newbptr, 0);
- if (status != NIS_SUCCESS)
- return niserr2nss (status);
-
- nis_free_directory (dir);
- dir = newdir;
- __nisbind_destroy (&bptr);
- bptr = newbptr;
-
- xdr_free ((xdrproc_t) xdr_netobj, (char *) &result.cookie);
- result.cookie.n_bytes = NULL;
- result.cookie.n_len = 0;
- parse_res = 0;
- goto next;
- }
- else if (NIS_RES_STATUS (&result) != NIS_SUCCESS)
- return niserr2nss (NIS_RES_STATUS (&result));
-
- parse_res = _nss_nisplus_parse_grent (&result, gr,
- buffer, buflen, errnop);
- if (__glibc_unlikely (parse_res == -1))
- {
- *errnop = ERANGE;
- retval = NSS_STATUS_TRYAGAIN;
- goto freeres;
- }
-
- next:
- /* Free the old cursor. */
- xdr_free ((xdrproc_t) xdr_netobj, (char *) &cursor);
- /* Remember the new one. */
- cursor.n_bytes = result.cookie.n_bytes;
- cursor.n_len = result.cookie.n_len;
- /* Free the result structure. NB: we do not remove the cookie. */
- result.cookie.n_bytes = NULL;
- result.cookie.n_len = 0;
- freeres:
- xdr_free ((xdrproc_t) _xdr_nis_result, (char *) &result);
- memset (&result, '\0', sizeof (result));
- }
- while (!parse_res);
-
- return retval;
-}
-
-enum nss_status
-_nss_nisplus_getgrent_r (struct group *result, char *buffer, size_t buflen,
- int *errnop)
-{
- int status;
-
- __libc_lock_lock (lock);
-
- status = internal_nisplus_getgrent_r (result, buffer, buflen, errnop);
-
- __libc_lock_unlock (lock);
-
- return status;
-}
-
-enum nss_status
-_nss_nisplus_getgrnam_r (const char *name, struct group *gr,
- char *buffer, size_t buflen, int *errnop)
-{
- int parse_res;
-
- if (grp_tablename_val == NULL)
- {
- enum nss_status status = _nss_grp_create_tablename (errnop);
-
- if (status != NSS_STATUS_SUCCESS)
- return status;
- }
-
- if (name == NULL)
- {
- *errnop = EINVAL;
- return NSS_STATUS_NOTFOUND;
- }
-
- nis_result *result;
- char buf[strlen (name) + 9 + grp_tablename_len];
- int olderr = errno;
-
- snprintf (buf, sizeof (buf), "[name=%s],%s", name, grp_tablename_val);
-
- result = nis_list (buf, FOLLOW_LINKS | FOLLOW_PATH, NULL, NULL);
-
- if (result == NULL)
- {
- *errnop = ENOMEM;
- return NSS_STATUS_TRYAGAIN;
- }
-
- if (__glibc_unlikely (niserr2nss (result->status) != NSS_STATUS_SUCCESS))
- {
- enum nss_status status = niserr2nss (result->status);
-
- nis_freeresult (result);
- return status;
- }
-
- parse_res = _nss_nisplus_parse_grent (result, gr, buffer, buflen, errnop);
- nis_freeresult (result);
- if (__glibc_unlikely (parse_res < 1))
- {
- if (parse_res == -1)
- {
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
- else
- {
- __set_errno (olderr);
- return NSS_STATUS_NOTFOUND;
- }
- }
-
- return NSS_STATUS_SUCCESS;
-}
-
-enum nss_status
-_nss_nisplus_getgrgid_r (const gid_t gid, struct group *gr,
- char *buffer, size_t buflen, int *errnop)
-{
- if (grp_tablename_val == NULL)
- {
- enum nss_status status = _nss_grp_create_tablename (errnop);
-
- if (status != NSS_STATUS_SUCCESS)
- return status;
- }
-
- int parse_res;
- nis_result *result;
- char buf[8 + 3 * sizeof (unsigned long int) + grp_tablename_len];
- int olderr = errno;
-
- snprintf (buf, sizeof (buf), "[gid=%lu],%s",
- (unsigned long int) gid, grp_tablename_val);
-
- result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
-
- if (result == NULL)
- {
- *errnop = ENOMEM;
- return NSS_STATUS_TRYAGAIN;
- }
-
- if (__glibc_unlikely (niserr2nss (result->status) != NSS_STATUS_SUCCESS))
- {
- enum nss_status status = niserr2nss (result->status);
-
- __set_errno (olderr);
-
- nis_freeresult (result);
- return status;
- }
-
- parse_res = _nss_nisplus_parse_grent (result, gr, buffer, buflen, errnop);
-
- nis_freeresult (result);
- if (__glibc_unlikely (parse_res < 1))
- {
- __set_errno (olderr);
-
- if (parse_res == -1)
- {
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
- else
- return NSS_STATUS_NOTFOUND;
- }
-
- return NSS_STATUS_SUCCESS;
-}
diff --git a/nis/nss_nisplus/nisplus-hosts.c b/nis/nss_nisplus/nisplus-hosts.c
deleted file mode 100644
index 1e66e4ff92..0000000000
--- a/nis/nss_nisplus/nisplus-hosts.c
+++ /dev/null
@@ -1,584 +0,0 @@
-/* Copyright (C) 1997-2020 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Thorsten Kukuk , 1997.
-
- 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
- . */
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "nss-nisplus.h"
-
-__libc_lock_define_initialized (static, lock)
-
-static nis_result *result;
-static nis_name tablename_val;
-static u_long tablename_len;
-
-#define NISENTRYVAL(idx, col, res) \
- (NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_val)
-
-#define NISENTRYLEN(idx, col, res) \
- (NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len)
-
-static int
-_nss_nisplus_parse_hostent (nis_result *result, int af, struct hostent *host,
- char *buffer, size_t buflen, int *errnop)
-{
- unsigned int i;
- char *first_unused = buffer;
- size_t room_left = buflen;
-
- if (result == NULL)
- return 0;
-
- if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS)
- || __type_of (NIS_RES_OBJECT (result)) != NIS_ENTRY_OBJ
- || strcmp (NIS_RES_OBJECT (result)[0].EN_data.en_type, "hosts_tbl") != 0
- || NIS_RES_OBJECT (result)[0].EN_data.en_cols.en_cols_len < 4)
- return 0;
-
- char *data = first_unused;
-
- if (room_left < (af != AF_INET ? IN6ADDRSZ : INADDRSZ))
- {
- no_more_room:
- *errnop = ERANGE;
- return -1;
- }
-
- /* Parse address. */
- if (af != AF_INET6
- && inet_pton (AF_INET, NISENTRYVAL (0, 2, result), data) > 0)
- {
- host->h_addrtype = AF_INET;
- host->h_length = INADDRSZ;
- }
- else if (af != AF_INET
- && inet_pton (AF_INET6, NISENTRYVAL (0, 2, result), data) > 0)
- {
- host->h_addrtype = AF_INET6;
- host->h_length = IN6ADDRSZ;
- }
- else
- /* Illegal address: ignore line. */
- return 0;
-
- first_unused += host->h_length;
- room_left -= host->h_length;
-
- if (NISENTRYLEN (0, 0, result) + 1 > room_left)
- goto no_more_room;
-
- host->h_name = first_unused;
- first_unused = __stpncpy (first_unused, NISENTRYVAL (0, 0, result),
- NISENTRYLEN (0, 0, result));
- *first_unused++ = '\0';
-
- room_left -= NISENTRYLEN (0, 0, result) + 1;
- char *line = first_unused;
-
- /* When this is a call to gethostbyname4_r we do not need the aliases. */
- if (af != AF_UNSPEC)
- {
- /* XXX Rewrite at some point to allocate the array first and then
- copy the strings. It is wasteful to first concatenate the strings
- to just split them again later. */
- for (i = 0; i < NIS_RES_NUMOBJ (result); ++i)
- {
- if (strcmp (NISENTRYVAL (i, 1, result), host->h_name) != 0)
- {
- if (NISENTRYLEN (i, 1, result) + 2 > room_left)
- goto no_more_room;
-
- *first_unused++ = ' ';
- first_unused = __stpncpy (first_unused,
- NISENTRYVAL (i, 1, result),
- NISENTRYLEN (i, 1, result));
- *first_unused = '\0';
- room_left -= NISENTRYLEN (i, 1, result) + 1;
- }
- }
- *first_unused++ = '\0';
- }
-
- /* Adjust the pointer so it is aligned for
- storing pointers. */
- size_t adjust = ((__alignof__ (char *)
- - (first_unused - (char *) 0) % __alignof__ (char *))
- % __alignof__ (char *));
- if (room_left < adjust + 3 * sizeof (char *))
- goto no_more_room;
- first_unused += adjust;
- room_left -= adjust;
- host->h_addr_list = (char **) first_unused;
-
- room_left -= 3 * sizeof (char *);
- host->h_addr_list[0] = data;
- host->h_addr_list[1] = NULL;
- host->h_aliases = &host->h_addr_list[2];
-
- /* When this is a call to gethostbyname4_r we do not need the aliases. */
- if (af != AF_UNSPEC)
- {
- i = 0;
- while (*line != '\0')
- {
- /* Skip leading blanks. */
- while (isspace (*line))
- ++line;
-
- if (*line == '\0')
- break;
-
- if (room_left < sizeof (char *))
- goto no_more_room;
-
- room_left -= sizeof (char *);
- host->h_aliases[i++] = line;
-
- while (*line != '\0' && *line != ' ')
- ++line;
-
- if (*line == ' ')
- *line++ = '\0';
- }
-
- host->h_aliases[i] = NULL;
- }
-
- return 1;
-}
-
-
-static enum nss_status
-_nss_create_tablename (int *errnop)
-{
- if (tablename_val == NULL)
- {
- const char *local_dir = nis_local_directory ();
- size_t local_dir_len = strlen (local_dir);
- static const char prefix[] = "hosts.org_dir.";
-
- char *p = malloc (sizeof (prefix) + local_dir_len);
- if (p == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
-
- memcpy (__stpcpy (p, prefix), local_dir, local_dir_len + 1);
-
- tablename_len = sizeof (prefix) - 1 + local_dir_len;
-
- atomic_write_barrier ();
-
- tablename_val = p;
- }
-
- return NSS_STATUS_SUCCESS;
-}
-
-
-enum nss_status
-_nss_nisplus_sethostent (int stayopen)
-{
- enum nss_status status = NSS_STATUS_SUCCESS;
- int err;
-
- __libc_lock_lock (lock);
-
- if (result != NULL)
- {
- nis_freeresult (result);
- result = NULL;
- }
-
- if (tablename_val == NULL)
- status = _nss_create_tablename (&err);
-
- __libc_lock_unlock (lock);
-
- return status;
-}
-
-
-enum nss_status
-_nss_nisplus_endhostent (void)
-{
- __libc_lock_lock (lock);
-
- if (result != NULL)
- {
- nis_freeresult (result);
- result = NULL;
- }
-
- __libc_lock_unlock (lock);
-
- return NSS_STATUS_SUCCESS;
-}
-
-
-static enum nss_status
-internal_nisplus_gethostent_r (struct hostent *host, char *buffer,
- size_t buflen, int *errnop, int *herrnop)
-{
- int parse_res;
-
- /* Get the next entry until we found a correct one. */
- do
- {
- nis_result *saved_res;
-
- if (result == NULL)
- {
- saved_res = NULL;
- if (tablename_val == NULL)
- {
- enum nss_status status = _nss_create_tablename (errnop);
-
- if (status != NSS_STATUS_SUCCESS)
- return status;
- }
-
- result = nis_first_entry (tablename_val);
- if (result == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
- if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
- {
- enum nss_status retval = niserr2nss (result->status);
- if (retval == NSS_STATUS_TRYAGAIN)
- {
- *herrnop = NETDB_INTERNAL;
- *errnop = errno;
- }
- return retval;
- }
-
- }
- else
- {
- saved_res = result;
- result = nis_next_entry (tablename_val, &result->cookie);
- if (result == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
- if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
- {
- enum nss_status retval= niserr2nss (result->status);
-
- nis_freeresult (result);
- result = saved_res;
- if (retval == NSS_STATUS_TRYAGAIN)
- {
- *herrnop = NETDB_INTERNAL;
- *errnop = errno;
- }
- return retval;
- }
- }
-
- parse_res = _nss_nisplus_parse_hostent (result, AF_INET, host, buffer,
- buflen, errnop);
-
- if (parse_res == -1)
- {
- nis_freeresult (result);
- result = saved_res;
- *herrnop = NETDB_INTERNAL;
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
- if (saved_res != NULL)
- nis_freeresult (saved_res);
-
- } while (!parse_res);
-
- return NSS_STATUS_SUCCESS;
-}
-
-
-enum nss_status
-_nss_nisplus_gethostent_r (struct hostent *result, char *buffer,
- size_t buflen, int *errnop, int *herrnop)
-{
- int status;
-
- __libc_lock_lock (lock);
-
- status = internal_nisplus_gethostent_r (result, buffer, buflen, errnop,
- herrnop);
-
- __libc_lock_unlock (lock);
-
- return status;
-}
-
-
-static enum nss_status
-get_tablename (int *herrnop)
-{
- __libc_lock_lock (lock);
-
- enum nss_status status = _nss_create_tablename (herrnop);
-
- __libc_lock_unlock (lock);
-
- if (status != NSS_STATUS_SUCCESS)
- *herrnop = NETDB_INTERNAL;
-
- return status;
-}
-
-
-static enum nss_status
-internal_gethostbyname2_r (const char *name, int af, struct hostent *host,
- char *buffer, size_t buflen, int *errnop,
- int *herrnop)
-{
- if (tablename_val == NULL)
- {
- enum nss_status status = get_tablename (herrnop);
- if (status != NSS_STATUS_SUCCESS)
- return status;
- }
-
- if (name == NULL)
- {
- *errnop = EINVAL;
- *herrnop = NETDB_INTERNAL;
- return NSS_STATUS_NOTFOUND;
- }
-
- char buf[strlen (name) + 10 + tablename_len];
- int olderr = errno;
-
- /* Search at first in the alias list, and use the correct name
- for the next search. */
- snprintf (buf, sizeof (buf), "[name=%s],%s", name, tablename_val);
- nis_result *result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
-
- if (result != NULL)
- {
- /* If we did not find it, try it as original name. But if the
- database is correct, we should find it in the first case, too. */
- char *bufptr = buf;
- size_t buflen = sizeof (buf);
-
- if ((result->status == NIS_SUCCESS || result->status == NIS_S_SUCCESS)
- && __type_of (result->objects.objects_val) == NIS_ENTRY_OBJ
- && strcmp (result->objects.objects_val->EN_data.en_type,
- "hosts_tbl") == 0
- && result->objects.objects_val->EN_data.en_cols.en_cols_len >= 3)
- {
- /* We need to allocate a new buffer since there is no
- guarantee the returned alias name has a length limit. */
- name = NISENTRYVAL(0, 0, result);
- size_t buflen = strlen (name) + 10 + tablename_len;
- bufptr = alloca (buflen);
- }
-
- snprintf (bufptr, buflen, "[cname=%s],%s", name, tablename_val);
-
- nis_freeresult (result);
- result = nis_list (bufptr, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
- }
-
- if (result == NULL)
- {
- *errnop = ENOMEM;
- *herrnop = NETDB_INTERNAL;
- return NSS_STATUS_TRYAGAIN;
- }
-
- int retval = niserr2nss (result->status);
- if (__glibc_unlikely (retval != NSS_STATUS_SUCCESS))
- {
- if (retval == NSS_STATUS_TRYAGAIN)
- {
- *errnop = errno;
- *herrnop = TRY_AGAIN;
- }
- else
- {
- __set_errno (olderr);
- *herrnop = NETDB_INTERNAL;
- }
- nis_freeresult (result);
- return retval;
- }
-
- int parse_res = _nss_nisplus_parse_hostent (result, af, host, buffer,
- buflen, errnop);
-
- nis_freeresult (result);
-
- if (parse_res > 0)
- return NSS_STATUS_SUCCESS;
-
- *herrnop = NETDB_INTERNAL;
- if (parse_res == -1)
- {
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- __set_errno (olderr);
- return NSS_STATUS_NOTFOUND;
-}
-
-
-enum nss_status
-_nss_nisplus_gethostbyname2_r (const char *name, int af, struct hostent *host,
- char *buffer, size_t buflen, int *errnop,
- int *herrnop)
-{
- if (af != AF_INET && af != AF_INET6)
- {
- *herrnop = HOST_NOT_FOUND;
- return NSS_STATUS_NOTFOUND;
- }
-
- return internal_gethostbyname2_r (name, af, host, buffer, buflen, errnop,
- herrnop);
-}
-
-
-enum nss_status
-_nss_nisplus_gethostbyname_r (const char *name, struct hostent *host,
- char *buffer, size_t buflen, int *errnop,
- int *h_errnop)
-{
- return internal_gethostbyname2_r (name, AF_INET, host, buffer,
- buflen, errnop, h_errnop);
-}
-
-
-enum nss_status
-_nss_nisplus_gethostbyaddr_r (const void *addr, socklen_t addrlen, int af,
- struct hostent *host, char *buffer,
- size_t buflen, int *errnop, int *herrnop)
-{
- if (tablename_val == NULL)
- {
- enum nss_status status = get_tablename (herrnop);
- if (status != NSS_STATUS_SUCCESS)
- return status;
- }
-
- if (addr == NULL)
- return NSS_STATUS_NOTFOUND;
-
- char buf[24 + tablename_len];
- int retval, parse_res;
- int olderr = errno;
-
- snprintf (buf, sizeof (buf), "[addr=%s],%s",
- inet_ntoa (*(const struct in_addr *) addr), tablename_val);
- nis_result *result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
-
- if (result == NULL)
- {
- __set_errno (ENOMEM);
- return NSS_STATUS_TRYAGAIN;
- }
-
- retval = niserr2nss (result->status);
- if (__glibc_unlikely (retval != NSS_STATUS_SUCCESS))
- {
- if (retval == NSS_STATUS_TRYAGAIN)
- {
- *errnop = errno;
- *herrnop = NETDB_INTERNAL;
- }
- else
- __set_errno (olderr);
- nis_freeresult (result);
- return retval;
- }
-
- parse_res = _nss_nisplus_parse_hostent (result, af, host,
- buffer, buflen, errnop);
- nis_freeresult (result);
-
- if (parse_res > 0)
- return NSS_STATUS_SUCCESS;
-
- *herrnop = NETDB_INTERNAL;
- if (parse_res == -1)
- {
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- __set_errno (olderr);
- return NSS_STATUS_NOTFOUND;
-}
-
-
-enum nss_status
-_nss_nisplus_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
- char *buffer, size_t buflen, int *errnop,
- int *herrnop, int32_t *ttlp)
-{
- struct hostent host;
-
- enum nss_status status = internal_gethostbyname2_r (name, AF_UNSPEC, &host,
- buffer, buflen,
- errnop, herrnop);
- if (__glibc_likely (status == NSS_STATUS_SUCCESS))
- {
- if (*pat == NULL)
- {
- uintptr_t pad = (-(uintptr_t) buffer
- % __alignof__ (struct gaih_addrtuple));
- buffer += pad;
- buflen = buflen > pad ? buflen - pad : 0;
-
- if (__glibc_unlikely (buflen < sizeof (struct gaih_addrtuple)))
- {
- free (result);
- *errnop = ERANGE;
- *herrnop = NETDB_INTERNAL;
- return NSS_STATUS_TRYAGAIN;
- }
- }
-
- (*pat)->next = NULL;
- (*pat)->name = host.h_name;
- (*pat)->family = host.h_addrtype;
-
- memcpy ((*pat)->addr, host.h_addr_list[0], host.h_length);
- (*pat)->scopeid = 0;
- assert (host.h_addr_list[1] == NULL);
- }
-
- return status;
-}
diff --git a/nis/nss_nisplus/nisplus-initgroups.c b/nis/nss_nisplus/nisplus-initgroups.c
deleted file mode 100644
index 9a6ee5cf9e..0000000000
--- a/nis/nss_nisplus/nisplus-initgroups.c
+++ /dev/null
@@ -1,148 +0,0 @@
-/* Copyright (C) 1997-2020 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
- . */
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "nss-nisplus.h"
-#include "nisplus-parser.h"
-#include
-#include
-#include
-
-#define NISOBJVAL(col, obj) \
- ((obj)->EN_data.en_cols.en_cols_val[col].ec_value.ec_value_val)
-
-#define NISOBJLEN(col, obj) \
- ((obj)->EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len)
-
-extern nis_name grp_tablename_val attribute_hidden;
-extern size_t grp_tablename_len attribute_hidden;
-extern enum nss_status _nss_grp_create_tablename (int *errnop);
-
-
-enum nss_status
-_nss_nisplus_initgroups_dyn (const char *user, gid_t group, long int *start,
- long int *size, gid_t **groupsp, long int limit,
- int *errnop)
-{
- if (grp_tablename_val == NULL)
- {
- enum nss_status status = _nss_grp_create_tablename (errnop);
-
- if (status != NSS_STATUS_SUCCESS)
- return status;
- }
-
- nis_result *result;
- char buf[strlen (user) + 12 + grp_tablename_len];
-
- snprintf (buf, sizeof (buf), "[members=%s],%s", user, grp_tablename_val);
-
- result = nis_list (buf, FOLLOW_LINKS | FOLLOW_PATH | ALL_RESULTS, NULL, NULL);
-
- if (result == NULL)
- {
- *errnop = ENOMEM;
- return NSS_STATUS_TRYAGAIN;
- }
-
- if (__glibc_unlikely (niserr2nss (result->status) != NSS_STATUS_SUCCESS))
- {
- enum nss_status status = niserr2nss (result->status);
-
- nis_freeresult (result);
- return status;
- }
-
- if (NIS_RES_NUMOBJ (result) == 0)
- {
- errout:
- nis_freeresult (result);
- return NSS_STATUS_NOTFOUND;
- }
-
- gid_t *groups = *groupsp;
- nis_object *obj = NIS_RES_OBJECT (result);
- for (unsigned int cnt = 0; cnt < NIS_RES_NUMOBJ (result); ++cnt, ++obj)
- {
- if (__type_of (obj) != NIS_ENTRY_OBJ
- || strcmp (obj->EN_data.en_type, "group_tbl") != 0
- || obj->EN_data.en_cols.en_cols_len < 4)
- continue;
-
- char *numstr = NISOBJVAL (2, obj);
- size_t len = NISOBJLEN (2, obj);
- if (len == 0 || numstr[0] == '\0')
- continue;
-
- gid_t gid;
- char *endp;
- if (__glibc_unlikely (numstr[len - 1] != '\0'))
- {
- char numstrbuf[len + 1];
- memcpy (numstrbuf, numstr, len);
- numstrbuf[len] = '\0';
- gid = strtoul (numstrbuf, &endp, 10);
- if (*endp)
- continue;
- }
- else
- {
- gid = strtoul (numstr, &endp, 10);
- if (*endp)
- continue;
- }
-
- if (gid == group)
- continue;
-
- /* Insert this group. */
- if (*start == *size)
- {
- /* Need a bigger buffer. */
- long int newsize;
-
- if (limit > 0 && *size == limit)
- /* We reached the maximum. */
- break;
-
- if (limit <= 0)
- newsize = 2 * *size;
- else
- newsize = MIN (limit, 2 * *size);
-
- gid_t *newgroups = realloc (groups, newsize * sizeof (*groups));
- if (newgroups == NULL)
- goto errout;
- *groupsp = groups = newgroups;
- *size = newsize;
- }
-
- groups[*start] = gid;
- *start += 1;
- }
-
- nis_freeresult (result);
- return NSS_STATUS_SUCCESS;
-}
diff --git a/nis/nss_nisplus/nisplus-netgrp.c b/nis/nss_nisplus/nisplus-netgrp.c
deleted file mode 100644
index d8512b35ce..0000000000
--- a/nis/nss_nisplus/nisplus-netgrp.c
+++ /dev/null
@@ -1,191 +0,0 @@
-/* Copyright (C) 1997-2020 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Thorsten Kukuk , 1997.
-
- 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
- . */
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "nss-nisplus.h"
-
-#define NISENTRYVAL(idx, col, res) \
- (NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_val)
-
-#define NISENTRYLEN(idx, col, res) \
- (NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len)
-
-enum nss_status
-_nss_nisplus_getnetgrent_r (struct __netgrent *result, char *buffer,
- size_t buflen, int *errnop)
-{
- enum nss_status status;
-
- /* Some sanity checks. */
- if (result->data == NULL || result->data_size == 0)
- return NSS_STATUS_NOTFOUND;
-
- if (result->position == result->data_size)
- return result->first ? NSS_STATUS_NOTFOUND : NSS_STATUS_RETURN;
-
- unsigned int entrylen
- = NISENTRYLEN (result->position, 1, (nis_result *) result->data);
- if (entrylen > 0)
- {
- /* We have a list of other netgroups. */
-
- result->type = group_val;
- if (entrylen >= buflen)
- {
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
- strncpy (buffer, NISENTRYVAL (result->position, 1,
- (nis_result *) result->data),
- entrylen);
- buffer[entrylen] = '\0';
- result->val.group = buffer;
- ++result->position;
- result->first = 0;
-
- return NSS_STATUS_SUCCESS;
- }
-
- /* Before we can copy the entry to the private buffer we have to make
- sure it is big enough. */
- unsigned int hostlen
- = NISENTRYLEN (result->position, 2, (nis_result *) result->data);
- unsigned int userlen
- = NISENTRYLEN (result->position, 3, (nis_result *) result->data);
- unsigned int domainlen
- = NISENTRYLEN (result->position, 4, (nis_result *) result->data);
- if (hostlen + userlen + domainlen + 6 > buflen)
- {
- *errnop = ERANGE;
- status = NSS_STATUS_TRYAGAIN;
- }
- else
- {
- char *cp = buffer;
-
- result->type = triple_val;
-
- if (hostlen == 0
- || NISENTRYVAL (result->position, 2,
- (nis_result *) result->data)[0] == '\0')
- result->val.triple.host = NULL;
- else
- {
- result->val.triple.host = cp;
- cp = __stpncpy (cp, NISENTRYVAL (result->position, 2,
- (nis_result *) result->data),
- hostlen);
- *cp++ = '\0';
- }
-
- if (userlen == 0
- || NISENTRYVAL (result->position, 3,
- (nis_result *) result->data)[0] == '\0')
- result->val.triple.user = NULL;
- else
- {
- result->val.triple.user = cp;
- cp = __stpncpy (cp, NISENTRYVAL (result->position, 3,
- (nis_result *) result->data),
- userlen);
- *cp++ = '\0';
- }
-
- if (domainlen == 0
- || NISENTRYVAL (result->position, 4,
- (nis_result *) result->data)[0] == '\0')
- result->val.triple.domain = NULL;
- else
- {
- result->val.triple.domain = cp;
- cp = __stpncpy (cp, NISENTRYVAL (result->position, 4,
- (nis_result *) result->data),
- domainlen);
- *cp = '\0';
- }
-
- status = NSS_STATUS_SUCCESS;
-
- /* Remember where we stopped reading. */
- ++result->position;
-
- result->first = 0;
- }
-
- return status;
-}
-
-static void
-internal_endnetgrent (struct __netgrent *netgrp)
-{
- nis_freeresult ((nis_result *) netgrp->data);
- netgrp->data = NULL;
- netgrp->data_size = 0;
- netgrp->position = 0;
-}
-
-enum nss_status
-_nss_nisplus_setnetgrent (const char *group, struct __netgrent *netgrp)
-{
- char buf[strlen (group) + 25];
-
- if (group == NULL || group[0] == '\0')
- return NSS_STATUS_UNAVAIL;
-
- enum nss_status status = NSS_STATUS_SUCCESS;
-
- snprintf (buf, sizeof (buf), "[name=%s],netgroup.org_dir", group);
-
- netgrp->data = (char *) nis_list (buf, EXPAND_NAME, NULL, NULL);
-
- if (netgrp->data == NULL)
- {
- __set_errno (ENOMEM);
- status = NSS_STATUS_TRYAGAIN;
- }
- else if (niserr2nss (((nis_result *) netgrp->data)->status)
- != NSS_STATUS_SUCCESS)
- {
- status = niserr2nss (((nis_result *) netgrp->data)->status);
-
- internal_endnetgrent (netgrp);
- }
- else
- {
- netgrp->data_size = ((nis_result *) netgrp->data)->objects.objects_len;
- netgrp->position = 0;
- netgrp->first = 1;
- }
-
- return status;
-}
-
-enum nss_status
-_nss_nisplus_endnetgrent (struct __netgrent *netgrp)
-{
- internal_endnetgrent (netgrp);
-
- return NSS_STATUS_SUCCESS;
-}
diff --git a/nis/nss_nisplus/nisplus-network.c b/nis/nss_nisplus/nisplus-network.c
deleted file mode 100644
index a731ed7e8b..0000000000
--- a/nis/nss_nisplus/nisplus-network.c
+++ /dev/null
@@ -1,494 +0,0 @@
-/* Copyright (C) 1997-2020 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Thorsten Kukuk , 1997.
-
- 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
- . */
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "nss-nisplus.h"
-
-__libc_lock_define_initialized (static, lock)
-
-static nis_result *result;
-static nis_name tablename_val;
-static u_long tablename_len;
-
-#define NISENTRYVAL(idx, col, res) \
- (NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_val)
-
-#define NISENTRYLEN(idx, col, res) \
- (NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len)
-
-
-static int
-_nss_nisplus_parse_netent (nis_result *result, struct netent *network,
- char *buffer, size_t buflen, int *errnop)
-{
- char *first_unused = buffer;
- size_t room_left = buflen;
-
- if (result == NULL)
- return 0;
-
- if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS)
- || __type_of (NIS_RES_OBJECT (result)) != NIS_ENTRY_OBJ
- || strcmp (NIS_RES_OBJECT (result)[0].EN_data.en_type,
- "networks_tbl") != 0
- || NIS_RES_OBJECT (result)[0].EN_data.en_cols.en_cols_len < 3)
- return 0;
-
- if (NISENTRYLEN (0, 0, result) >= room_left)
- {
- /* The line is too long for our buffer. */
- no_more_room:
- *errnop = ERANGE;
- return -1;
- }
-
- strncpy (first_unused, NISENTRYVAL (0, 0, result),
- NISENTRYLEN (0, 0, result));
- first_unused[NISENTRYLEN (0, 0, result)] = '\0';
- network->n_name = first_unused;
- size_t len = strlen (first_unused) + 1;
- room_left -= len;
- first_unused += len;
-
- network->n_addrtype = 0;
- network->n_net = inet_network (NISENTRYVAL (0, 2, result));
-
- /* XXX Rewrite at some point to allocate the array first and then
- copy the strings. It wasteful to first concatenate the strings
- to just split them again later. */
- char *line = first_unused;
- for (unsigned int i = 0; i < NIS_RES_NUMOBJ (result); ++i)
- {
- if (strcmp (NISENTRYVAL (i, 1, result), network->n_name) != 0)
- {
- if (NISENTRYLEN (i, 1, result) + 2 > room_left)
- goto no_more_room;
-
- *first_unused++ = ' ';
- first_unused = __stpncpy (first_unused, NISENTRYVAL (i, 1, result),
- NISENTRYLEN (i, 1, result));
- room_left -= (NISENTRYLEN (i, 1, result) + 1);
- }
- }
- *first_unused++ = '\0';
-
- /* Adjust the pointer so it is aligned for
- storing pointers. */
- size_t adjust = ((__alignof__ (char *)
- - (first_unused - (char *) 0) % __alignof__ (char *))
- % __alignof__ (char *));
- if (room_left < adjust + sizeof (char *))
- goto no_more_room;
- first_unused += adjust;
- room_left -= adjust;
- network->n_aliases = (char **) first_unused;
-
- /* For the terminating NULL pointer. */
- room_left -= sizeof (char *);
-
- unsigned int i = 0;
- while (*line != '\0')
- {
- /* Skip leading blanks. */
- while (isspace (*line))
- ++line;
-
- if (*line == '\0')
- break;
-
- if (room_left < sizeof (char *))
- goto no_more_room;
-
- room_left -= sizeof (char *);
- network->n_aliases[i++] = line;
-
- while (*line != '\0' && *line != ' ')
- ++line;
-
- if (*line == ' ')
- *line++ = '\0';
- }
- network->n_aliases[i] = NULL;
-
- return 1;
-}
-
-
-static enum nss_status
-_nss_create_tablename (int *errnop)
-{
- if (tablename_val == NULL)
- {
- const char *local_dir = nis_local_directory ();
- size_t local_dir_len = strlen (local_dir);
- static const char prefix[] = "networks.org_dir.";
-
- char *p = malloc (sizeof (prefix) + local_dir_len);
- if (p == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
-
- memcpy (__stpcpy (p, prefix), local_dir, local_dir_len + 1);
-
- tablename_len = sizeof (prefix) - 1 + local_dir_len;
-
- atomic_write_barrier ();
-
- tablename_val = p;
- }
-
- return NSS_STATUS_SUCCESS;
-}
-
-enum nss_status
-_nss_nisplus_setnetent (int stayopen)
-{
- enum nss_status status = NSS_STATUS_SUCCESS;
-
- __libc_lock_lock (lock);
-
- if (result != NULL)
- {
- nis_freeresult (result);
- result = NULL;
- }
-
- if (tablename_val == NULL)
- {
- int err;
- status = _nss_create_tablename (&err);
- }
-
- __libc_lock_unlock (lock);
-
- return status;
-}
-
-enum nss_status
-_nss_nisplus_endnetent (void)
-{
- __libc_lock_lock (lock);
-
- if (result != NULL)
- {
- nis_freeresult (result);
- result = NULL;
- }
-
- __libc_lock_unlock (lock);
-
- return NSS_STATUS_SUCCESS;
-}
-
-static enum nss_status
-internal_nisplus_getnetent_r (struct netent *network, char *buffer,
- size_t buflen, int *errnop, int *herrnop)
-{
- int parse_res;
-
- /* Get the next entry until we found a correct one. */
- do
- {
- nis_result *saved_res;
-
- if (result == NULL)
- {
- saved_res = NULL;
-
- if (tablename_val == NULL)
- {
- enum nss_status status = _nss_create_tablename (errnop);
-
- if (status != NSS_STATUS_SUCCESS)
- return status;
- }
-
- result = nis_first_entry (tablename_val);
- if (result == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
- if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
- {
- int retval = niserr2nss (result->status);
- nis_freeresult (result);
- result = NULL;
- if (retval == NSS_STATUS_TRYAGAIN)
- {
- *herrnop = NETDB_INTERNAL;
- *errnop = errno;
- return retval;
- }
- else
- return retval;
- }
- }
- else
- {
- saved_res = result;
- result = nis_next_entry (tablename_val, &result->cookie);
- if (result == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
- if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
- {
- int retval = niserr2nss (result->status);
- nis_freeresult (result);
- result = saved_res;
- if (retval == NSS_STATUS_TRYAGAIN)
- {
- *herrnop = NETDB_INTERNAL;
- *errnop = errno;
- }
- return retval;
- }
- }
-
- parse_res = _nss_nisplus_parse_netent (result, network, buffer,
- buflen, errnop);
- if (parse_res == -1)
- {
- *herrnop = NETDB_INTERNAL;
- return NSS_STATUS_TRYAGAIN;
- }
-
- }
- while (!parse_res);
-
- return NSS_STATUS_SUCCESS;
-}
-
-enum nss_status
-_nss_nisplus_getnetent_r (struct netent *result, char *buffer,
- size_t buflen, int *errnop, int *herrnop)
-{
- int status;
-
- __libc_lock_lock (lock);
-
- status = internal_nisplus_getnetent_r (result, buffer, buflen, errnop,
- herrnop);
-
- __libc_lock_unlock (lock);
-
- return status;
-}
-
-enum nss_status
-_nss_nisplus_getnetbyname_r (const char *name, struct netent *network,
- char *buffer, size_t buflen, int *errnop,
- int *herrnop)
-{
- int parse_res, retval;
-
- if (tablename_val == NULL)
- {
- __libc_lock_lock (lock);
-
- enum nss_status status = _nss_create_tablename (errnop);
-
- __libc_lock_unlock (lock);
-
- if (status != NSS_STATUS_SUCCESS)
- return status;
- }
-
- if (name == NULL)
- {
- *errnop = EINVAL;
- *herrnop = NETDB_INTERNAL;
- return NSS_STATUS_UNAVAIL;
- }
-
- nis_result *result;
- char buf[strlen (name) + 10 + tablename_len];
- int olderr = errno;
-
- /* Search at first in the alias list, and use the correct name
- for the next search */
- snprintf (buf, sizeof (buf), "[name=%s],%s", name, tablename_val);
- result = nis_list (buf, FOLLOW_LINKS | FOLLOW_PATH | USE_DGRAM, NULL, NULL);
-
- if (result != NULL)
- {
- char *bufptr = buf;
-
- /* If we do not find it, try it as original name. But if the
- database is correct, we should find it in the first case, too */
- if ((result->status != NIS_SUCCESS
- && result->status != NIS_S_SUCCESS)
- || __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ
- || strcmp (result->objects.objects_val[0].EN_data.en_type,
- "networks_tbl") != 0
- || (result->objects.objects_val[0].EN_data.en_cols.en_cols_len
- < 3))
- snprintf (buf, sizeof (buf), "[cname=%s],%s", name, tablename_val);
- else
- {
- /* We need to allocate a new buffer since there is no
- guarantee the returned name has a length limit. */
- const char *entryval = NISENTRYVAL (0, 0, result);
- size_t buflen = strlen (entryval) + 10 + tablename_len;
- bufptr = alloca (buflen);
- snprintf (bufptr, buflen, "[cname=%s],%s",
- entryval, tablename_val);
- }
-
- nis_freeresult (result);
- result = nis_list (bufptr, FOLLOW_LINKS | FOLLOW_PATH | USE_DGRAM,
- NULL, NULL);
- }
-
- if (result == NULL)
- {
- __set_errno (ENOMEM);
- return NSS_STATUS_TRYAGAIN;
- }
-
- retval = niserr2nss (result->status);
- if (__glibc_unlikely (retval != NSS_STATUS_SUCCESS))
- {
- if (retval == NSS_STATUS_TRYAGAIN)
- {
- *errnop = errno;
- *herrnop = NETDB_INTERNAL;
- }
- else
- __set_errno (olderr);
- nis_freeresult (result);
- return retval;
- }
-
- parse_res = _nss_nisplus_parse_netent (result, network, buffer, buflen,
- errnop);
-
- nis_freeresult (result);
-
- if (parse_res > 0)
- return NSS_STATUS_SUCCESS;
-
- *herrnop = NETDB_INTERNAL;
- if (parse_res == -1)
- {
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- __set_errno (olderr);
- return NSS_STATUS_NOTFOUND;
-}
-
-/* XXX type is ignored, SUN's NIS+ table doesn't support it */
-enum nss_status
-_nss_nisplus_getnetbyaddr_r (uint32_t addr, const int type,
- struct netent *network, char *buffer,
- size_t buflen, int *errnop, int *herrnop)
-{
- if (tablename_val == NULL)
- {
- __libc_lock_lock (lock);
-
- enum nss_status status = _nss_create_tablename (errnop);
-
- __libc_lock_unlock (lock);
-
- if (status != NSS_STATUS_SUCCESS)
- return status;
- }
-
- {
- char buf[27 + tablename_len];
- char buf2[18];
- int olderr = errno;
-
- struct in_addr in = { .s_addr = htonl (addr) };
- strcpy (buf2, inet_ntoa (in));
- size_t b2len = strlen (buf2);
-
- while (1)
- {
- snprintf (buf, sizeof (buf), "[addr=%s],%s", buf2, tablename_val);
- nis_result *result = nis_list (buf, EXPAND_NAME | USE_DGRAM,
- NULL, NULL);
-
- if (result == NULL)
- {
- __set_errno (ENOMEM);
- return NSS_STATUS_TRYAGAIN;
- }
- enum nss_status retval = niserr2nss (result->status);
- if (__glibc_unlikely (retval != NSS_STATUS_SUCCESS))
- {
- if (b2len > 2 && buf2[b2len - 2] == '.' && buf2[b2len - 1] == '0')
- {
- /* Try again, but with trailing dot(s)
- removed (one by one) */
- buf2[b2len - 2] = '\0';
- b2len -= 2;
- nis_freeresult (result);
- continue;
- }
-
- if (retval == NSS_STATUS_TRYAGAIN)
- {
- *errnop = errno;
- *herrnop = NETDB_INTERNAL;
- }
- else
- __set_errno (olderr);
- nis_freeresult (result);
- return retval;
- }
-
- int parse_res = _nss_nisplus_parse_netent (result, network, buffer,
- buflen, errnop);
-
- nis_freeresult (result);
-
- if (parse_res > 0)
- return NSS_STATUS_SUCCESS;
-
- *herrnop = NETDB_INTERNAL;
- if (parse_res == -1)
- {
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
- else
- {
- __set_errno (olderr);
- return NSS_STATUS_NOTFOUND;
- }
- }
- }
-}
diff --git a/nis/nss_nisplus/nisplus-parser.c b/nis/nss_nisplus/nisplus-parser.c
deleted file mode 100644
index 175b9cbf42..0000000000
--- a/nis/nss_nisplus/nisplus-parser.c
+++ /dev/null
@@ -1,375 +0,0 @@
-/* Copyright (C) 1997-2020 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Thorsten Kukuk , 1997.
-
- 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
- . */
-
-#include
-#include
-#include
-#include
-#include
-
-#include "nisplus-parser.h"
-
-#define NISENTRYVAL(idx, col, res) \
- (NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_val)
-
-#define NISENTRYLEN(idx, col, res) \
- (NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len)
-
-#define NISOBJVAL(col, obj) \
- ((obj)->EN_data.en_cols.en_cols_val[col].ec_value.ec_value_val)
-
-#define NISOBJLEN(col, obj) \
- ((obj)->EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len)
-
-
-int
-_nss_nisplus_parse_pwent (nis_result *result, struct passwd *pw,
- char *buffer, size_t buflen, int *errnop)
-{
- if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS)
- || NIS_RES_NUMOBJ (result) != 1
- || __type_of (NIS_RES_OBJECT (result)) != NIS_ENTRY_OBJ
- || strcmp (NIS_RES_OBJECT (result)->EN_data.en_type, "passwd_tbl") != 0
- || NIS_RES_OBJECT (result)->EN_data.en_cols.en_cols_len < 7)
- return 0;
-
- nis_object *obj = NIS_RES_OBJECT (result);
- char *first_unused = buffer;
- size_t room_left = buflen;
- size_t len;
-
- if (NISOBJLEN (0, obj) >= room_left)
- {
- /* The line is too long for our buffer. */
- no_more_room:
- *errnop = ERANGE;
- return -1;
- }
-
- strncpy (first_unused, NISOBJVAL (0, obj), NISOBJLEN (0, obj));
- first_unused[NISOBJLEN (0, obj)] = '\0';
- len = strlen (first_unused);
- if (len == 0) /* No name ? Should never happen, database is corrupt */
- return 0;
- pw->pw_name = first_unused;
- room_left -= len + 1;
- first_unused += len + 1;
-
- if (NISOBJLEN (1, obj) >= room_left)
- goto no_more_room;
-
- strncpy (first_unused, NISOBJVAL (1, obj), NISOBJLEN (1, obj));
- first_unused[NISOBJLEN (1, obj)] = '\0';
- pw->pw_passwd = first_unused;
- len = strlen (first_unused);
- room_left -= len + 1;
- first_unused += len + 1;
-
- char *numstr = NISOBJVAL (2, obj);
- len = NISOBJLEN (2, obj);
- if (len == 0 || numstr[len - 1] != '\0')
- {
- if (len >= room_left)
- goto no_more_room;
-
- strncpy (first_unused, numstr, len);
- first_unused[len] = '\0';
- numstr = first_unused;
- }
- if (numstr[0] == '\0')
- /* If we don't have a uid, it's an invalid shadow entry. */
- return 0;
- pw->pw_uid = strtoul (numstr, NULL, 10);
-
- numstr = NISOBJVAL (3, obj);
- len = NISOBJLEN (3, obj);
- if (len == 0 || numstr[len - 1] != '\0')
- {
- if (len >= room_left)
- goto no_more_room;
-
- strncpy (first_unused, numstr, len);
- first_unused[len] = '\0';
- numstr = first_unused;
- }
- if (numstr[0] == '\0')
- /* If we don't have a gid, it's an invalid shadow entry. */
- return 0;
- pw->pw_gid = strtoul (numstr, NULL, 10);
-
- if (NISOBJLEN(4, obj) >= room_left)
- goto no_more_room;
-
- strncpy (first_unused, NISOBJVAL (4, obj), NISOBJLEN (4, obj));
- first_unused[NISOBJLEN (4, obj)] = '\0';
- pw->pw_gecos = first_unused;
- len = strlen (first_unused);
- room_left -= len + 1;
- first_unused += len + 1;
-
- if (NISOBJLEN (5, obj) >= room_left)
- goto no_more_room;
-
- strncpy (first_unused, NISOBJVAL (5, obj), NISOBJLEN (5, obj));
- first_unused[NISOBJLEN (5, obj)] = '\0';
- pw->pw_dir = first_unused;
- len = strlen (first_unused);
- room_left -= len + 1;
- first_unused += len + 1;
-
- if (NISOBJLEN (6, obj) >= room_left)
- goto no_more_room;
-
- strncpy (first_unused, NISOBJVAL (6, obj), NISOBJLEN (6, obj));
- first_unused[NISOBJLEN (6, obj)] = '\0';
- pw->pw_shell = first_unused;
- len = strlen (first_unused);
- room_left -= len + 1;
- first_unused += len + 1;
-
- return 1;
-}
-
-
-int
-_nss_nisplus_parse_grent (nis_result *result, struct group *gr,
- char *buffer, size_t buflen, int *errnop)
-{
- if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS)
- || __type_of(NIS_RES_OBJECT (result)) != NIS_ENTRY_OBJ
- || strcmp (NIS_RES_OBJECT (result)[0].EN_data.en_type, "group_tbl") != 0
- || NIS_RES_OBJECT (result)[0].EN_data.en_cols.en_cols_len < 4)
- return 0;
-
- nis_object *obj = NIS_RES_OBJECT (result);
- char *first_unused = buffer;
- size_t room_left = buflen;
- char *line;
- int count;
- size_t len;
-
- if (NISOBJLEN (0, obj) >= room_left)
- {
- /* The line is too long for our buffer. */
- no_more_room:
- *errnop = ERANGE;
- return -1;
- }
-
- strncpy (first_unused, NISOBJVAL (0, obj), NISOBJLEN (0, obj));
- first_unused[NISOBJLEN (0, obj)] = '\0';
- len = strlen (first_unused);
- if (len == 0) /* group table is corrupt */
- return 0;
- gr->gr_name = first_unused;
- room_left -= len + 1;
- first_unused += len + 1;
-
- if (NISOBJLEN (1, obj) >= room_left)
- goto no_more_room;
-
- strncpy (first_unused, NISOBJVAL (1, obj), NISOBJLEN (1, obj));
- first_unused[NISOBJLEN (1, obj)] = '\0';
- gr->gr_passwd = first_unused;
- len = strlen (first_unused);
- room_left -= len + 1;
- first_unused += len + 1;
-
- char *numstr = NISOBJVAL (2, obj);
- len = NISOBJLEN (2, obj);
- if (len == 0 || numstr[len - 1] != '\0')
- {
- if (len >= room_left)
- goto no_more_room;
-
- strncpy (first_unused, numstr, len);
- first_unused[len] = '\0';
- numstr = first_unused;
- }
- if (numstr[0] == '\0')
- /* We should always have a gid. */
- return 0;
- gr->gr_gid = strtoul (numstr, NULL, 10);
-
- if (NISOBJLEN (3, obj) >= room_left)
- goto no_more_room;
-
- strncpy (first_unused, NISOBJVAL (3, obj), NISOBJLEN (3, obj));
- first_unused[NISOBJLEN (3, obj)] = '\0';
- line = first_unused;
- len = strlen (line);
- room_left -= len + 1;
- first_unused += len + 1;
- /* Adjust the pointer so it is aligned for
- storing pointers. */
- size_t adjust = ((__alignof__ (char *)
- - (first_unused - (char *) 0) % __alignof__ (char *))
- % __alignof__ (char *));
- if (room_left < adjust)
- goto no_more_room;
- first_unused += adjust;
- room_left -= adjust;
- gr->gr_mem = (char **) first_unused;
-
- count = 0;
- while (*line != '\0')
- {
- /* Skip leading blanks. */
- while (isspace (*line))
- ++line;
-
- if (*line == '\0')
- break;
-
- if (room_left < sizeof (char *))
- goto no_more_room;
- room_left -= sizeof (char *);
- gr->gr_mem[count++] = line;
-
- while (*line != '\0' && *line != ',' && !isspace (*line))
- ++line;
-
- if (*line == ',' || isspace (*line))
- {
- int is = isspace (*line);
-
- *line++ = '\0';
- if (is)
- while (*line != '\0' && (*line == ',' || isspace (*line)))
- ++line;
- }
- }
- if (room_left < sizeof (char *))
- goto no_more_room;
- room_left -= sizeof (char *);
- gr->gr_mem[count] = NULL;
-
- return 1;
-}
-
-
-int
-_nss_nisplus_parse_spent (nis_result *result, struct spwd *sp,
- char *buffer, size_t buflen, int *errnop)
-{
- char *first_unused = buffer;
- size_t room_left = buflen;
- size_t len;
-
- if (result == NULL)
- return 0;
-
- if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS)
- || NIS_RES_NUMOBJ (result) != 1
- || __type_of(NIS_RES_OBJECT (result)) != NIS_ENTRY_OBJ
- || strcmp (NIS_RES_OBJECT (result)->EN_data.en_type, "passwd_tbl") != 0
- || NIS_RES_OBJECT (result)->EN_data.en_cols.en_cols_len < 8)
- return 0;
-
- if (NISENTRYLEN (0, 0, result) >= room_left)
- {
- /* The line is too long for our buffer. */
- no_more_room:
- *errnop = ERANGE;
- return -1;
- }
-
- strncpy (first_unused, NISENTRYVAL (0, 0, result),
- NISENTRYLEN (0, 0, result));
- first_unused[NISENTRYLEN (0, 0, result)] = '\0';
- len = strlen (first_unused);
- if (len == 0)
- return 0;
- sp->sp_namp = first_unused;
- room_left -= len + 1;
- first_unused += len + 1;
-
- if (NISENTRYLEN (0, 1, result) >= room_left)
- goto no_more_room;
-
- strncpy (first_unused, NISENTRYVAL (0, 1, result),
- NISENTRYLEN (0, 1, result));
- first_unused[NISENTRYLEN (0, 1, result)] = '\0';
- sp->sp_pwdp = first_unused;
- len = strlen (first_unused);
- room_left -= len + 1;
- first_unused += len + 1;
-
- sp->sp_lstchg = sp->sp_min = sp->sp_max = sp->sp_warn = sp->sp_inact =
- sp->sp_expire = -1;
- sp->sp_flag = ~0ul;
-
- if (NISENTRYLEN (0, 7, result) > 0)
- {
- char *line = NISENTRYVAL (0, 7, result);
- char *cp = strchr (line, ':');
- if (cp == NULL)
- return 1;
- *cp++ = '\0';
- if (*line)
- sp->sp_lstchg = atol (line);
-
- line = cp;
- cp = strchr (line, ':');
- if (cp == NULL)
- return 1;
- *cp++ = '\0';
- if (*line)
- sp->sp_min = atol (line);
-
- line = cp;
- cp = strchr (line, ':');
- if (cp == NULL)
- return 1;
- *cp++ = '\0';
- if (*line)
- sp->sp_max = atol (line);
-
- line = cp;
- cp = strchr (line, ':');
- if (cp == NULL)
- return 1;
- *cp++ = '\0';
- if (*line)
- sp->sp_warn = atol (line);
-
- line = cp;
- cp = strchr (line, ':');
- if (cp == NULL)
- return 1;
- *cp++ = '\0';
- if (*line)
- sp->sp_inact = atol (line);
-
- line = cp;
- cp = strchr (line, ':');
- if (cp == NULL)
- return 1;
- *cp++ = '\0';
- if (*line)
- sp->sp_expire = atol (line);
-
- line = cp;
- if (line == NULL)
- return 1;
- if (*line)
- sp->sp_flag = atol (line);
- }
-
- return 1;
-}
diff --git a/nis/nss_nisplus/nisplus-proto.c b/nis/nss_nisplus/nisplus-proto.c
deleted file mode 100644
index fc1ac2e9d7..0000000000
--- a/nis/nss_nisplus/nisplus-proto.c
+++ /dev/null
@@ -1,441 +0,0 @@
-/* Copyright (C) 1997-2020 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Thorsten Kukuk , 1997.
-
- 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
- . */
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "nss-nisplus.h"
-
-__libc_lock_define_initialized (static, lock)
-
-static nis_result *result;
-static nis_name tablename_val;
-static u_long tablename_len;
-
-#define NISENTRYVAL(idx, col, res) \
- (NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_val)
-
-#define NISENTRYLEN(idx, col, res) \
- (NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len)
-
-
-static int
-_nss_nisplus_parse_protoent (nis_result *result, struct protoent *proto,
- char *buffer, size_t buflen, int *errnop)
-{
- char *first_unused = buffer;
- size_t room_left = buflen;
- unsigned int i;
-
- if (result == NULL)
- return 0;
-
- if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS)
- || __type_of (NIS_RES_OBJECT (result)) != NIS_ENTRY_OBJ
- || strcmp (NIS_RES_OBJECT (result)->EN_data.en_type,
- "protocols_tbl") != 0
- || NIS_RES_OBJECT (result)->EN_data.en_cols.en_cols_len < 3)
- return 0;
-
- /* Generate the protocols entry format and use the normal parser */
- if (NISENTRYLEN (0, 0, result) + 1 > room_left)
- {
- no_more_room:
- *errnop = ERANGE;
- return -1;
- }
- strncpy (first_unused, NISENTRYVAL (0, 0, result),
- NISENTRYLEN (0, 0, result));
- first_unused[NISENTRYLEN (0, 0, result)] = '\0';
- proto->p_name = first_unused;
- size_t len = strlen (first_unused) + 1;
- room_left -= len;
- first_unused += len;
-
-
- proto->p_proto = atoi (NISENTRYVAL (0, 2, result));
-
- /* XXX Rewrite at some point to allocate the array first and then
- copy the strings. It wasteful to first concatenate the strings
- to just split them again later. */
- char *line = first_unused;
- for (i = 0; i < NIS_RES_NUMOBJ (result); ++i)
- {
- if (strcmp (NISENTRYVAL (i, 1, result), proto->p_name) != 0)
- {
- if (NISENTRYLEN (i, 1, result) + 2 > room_left)
- goto no_more_room;
- *first_unused++ = ' ';
- first_unused = __stpncpy (first_unused, NISENTRYVAL (i, 1, result),
- NISENTRYLEN (i, 1, result));
- room_left -= NISENTRYLEN (i, 1, result) + 1;
- }
- }
- *first_unused++ = '\0';
-
- /* Adjust the pointer so it is aligned for
- storing pointers. */
- size_t adjust = ((__alignof__ (char *)
- - (first_unused - (char *) 0) % __alignof__ (char *))
- % __alignof__ (char *));
- if (room_left < adjust + sizeof (char *))
- goto no_more_room;
- first_unused += adjust;
- room_left -= adjust;
- proto->p_aliases = (char **) first_unused;
-
- /* For the terminating NULL pointer. */
- room_left -= sizeof (char *);
-
- i = 0;
- while (*line != '\0')
- {
- /* Skip leading blanks. */
- while (isspace (*line))
- line++;
- if (*line == '\0')
- break;
-
- if (room_left < sizeof (char *))
- goto no_more_room;
-
- room_left -= sizeof (char *);
- proto->p_aliases[i++] = line;
-
- while (*line != '\0' && *line != ' ')
- ++line;
-
- if (*line == ' ')
- *line++ = '\0';
- }
- proto->p_aliases[i] = NULL;
-
- return 1;
-}
-
-static enum nss_status
-_nss_create_tablename (int *errnop)
-{
- if (tablename_val == NULL)
- {
- const char *local_dir = nis_local_directory ();
- size_t local_dir_len = strlen (local_dir);
- static const char prefix[] = "protocols.org_dir.";
-
- char *p = malloc (sizeof (prefix) + local_dir_len);
- if (p == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
-
- memcpy (__stpcpy (p, prefix), local_dir, local_dir_len + 1);
-
- tablename_len = sizeof (prefix) - 1 + local_dir_len;
-
- atomic_write_barrier ();
-
- tablename_val = p;
- }
-
- return NSS_STATUS_SUCCESS;
-}
-
-enum nss_status
-_nss_nisplus_setprotoent (int stayopen)
-{
- enum nss_status status = NSS_STATUS_SUCCESS;
-
- __libc_lock_lock (lock);
-
- if (result != NULL)
- {
- nis_freeresult (result);
- result = NULL;
- }
-
- if (tablename_val == NULL)
- {
- int err;
- status = _nss_create_tablename (&err);
- }
-
- __libc_lock_unlock (lock);
-
- return status;
-}
-
-enum nss_status
-_nss_nisplus_endprotoent (void)
-{
- __libc_lock_lock (lock);
-
- if (result != NULL)
- {
- nis_freeresult (result);
- result = NULL;
- }
-
- __libc_lock_unlock (lock);
-
- return NSS_STATUS_SUCCESS;
-}
-
-static enum nss_status
-internal_nisplus_getprotoent_r (struct protoent *proto, char *buffer,
- size_t buflen, int *errnop)
-{
- int parse_res;
-
- /* Get the next entry until we found a correct one. */
- do
- {
- nis_result *saved_res;
-
- if (result == NULL)
- {
- saved_res = NULL;
- if (tablename_val == NULL)
- {
- enum nss_status status = _nss_create_tablename (errnop);
-
- if (status != NSS_STATUS_SUCCESS)
- return status;
- }
-
- result = nis_first_entry (tablename_val);
- if (result == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
- if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
- return niserr2nss (result->status);
- }
- else
- {
- saved_res = result;
- result = nis_next_entry (tablename_val, &result->cookie);
- if (result == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
- if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
- {
- nis_freeresult (saved_res);
- return niserr2nss (result->status);
- }
- }
-
- parse_res = _nss_nisplus_parse_protoent (result, proto, buffer,
- buflen, errnop);
- if (parse_res == -1)
- {
- nis_freeresult (result);
- result = saved_res;
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
- else
- {
- if (saved_res)
- nis_freeresult (saved_res);
- }
- }
- while (!parse_res);
-
- return NSS_STATUS_SUCCESS;
-}
-
-enum nss_status
-_nss_nisplus_getprotoent_r (struct protoent *result, char *buffer,
- size_t buflen, int *errnop)
-{
- int status;
-
- __libc_lock_lock (lock);
-
- status = internal_nisplus_getprotoent_r (result, buffer, buflen, errnop);
-
- __libc_lock_unlock (lock);
-
- return status;
-}
-
-enum nss_status
-_nss_nisplus_getprotobyname_r (const char *name, struct protoent *proto,
- char *buffer, size_t buflen, int *errnop)
-{
- int parse_res;
-
- if (tablename_val == NULL)
- {
- __libc_lock_lock (lock);
-
- enum nss_status status = _nss_create_tablename (errnop);
-
- __libc_lock_unlock (lock);
-
- if (status != NSS_STATUS_SUCCESS)
- return status;
- }
-
- if (name == NULL)
- return NSS_STATUS_NOTFOUND;
-
- char buf[strlen (name) + 10 + tablename_len];
- int olderr = errno;
-
- /* Search at first in the alias list, and use the correct name
- for the next search */
- snprintf (buf, sizeof (buf), "[name=%s],%s", name, tablename_val);
- nis_result *result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
-
- if (result != NULL)
- {
- char *bufptr = buf;
-
- /* If we did not find it, try it as original name. But if the
- database is correct, we should find it in the first case, too */
- if ((result->status != NIS_SUCCESS
- && result->status != NIS_S_SUCCESS)
- || __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ
- || strcmp (result->objects.objects_val->EN_data.en_type,
- "protocols_tbl") != 0
- || result->objects.objects_val->EN_data.en_cols.en_cols_len < 3)
- snprintf (buf, sizeof (buf), "[cname=%s],%s", name, tablename_val);
- else
- {
- /* We need to allocate a new buffer since there is no
- guarantee the returned name has a length limit. */
- const char *entryval = NISENTRYVAL (0, 0, result);
- size_t buflen = strlen (entryval) + 10 + tablename_len;
- bufptr = alloca (buflen);
- snprintf (bufptr, buflen, "[cname=%s],%s",
- entryval, tablename_val);
- }
-
- nis_freeresult (result);
- result = nis_list (bufptr, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
- }
-
- if (result == NULL)
- {
- __set_errno (ENOMEM);
- return NSS_STATUS_TRYAGAIN;
- }
-
- if (__glibc_unlikely (niserr2nss (result->status) != NSS_STATUS_SUCCESS))
- {
- enum nss_status status = niserr2nss (result->status);
-
- __set_errno (olderr);
-
- nis_freeresult (result);
- return status;
- }
-
- parse_res = _nss_nisplus_parse_protoent (result, proto, buffer, buflen,
- errnop);
-
- nis_freeresult (result);
-
- if (parse_res < 1)
- {
- if (parse_res == -1)
- {
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
- else
- {
- __set_errno (olderr);
- return NSS_STATUS_NOTFOUND;
- }
- }
-
- return NSS_STATUS_SUCCESS;
-}
-
-enum nss_status
-_nss_nisplus_getprotobynumber_r (const int number, struct protoent *proto,
- char *buffer, size_t buflen, int *errnop)
-{
- if (tablename_val == NULL)
- {
- __libc_lock_lock (lock);
-
- enum nss_status status = _nss_create_tablename (errnop);
-
- __libc_lock_unlock (lock);
-
- if (status != NSS_STATUS_SUCCESS)
- return status;
- }
-
- char buf[12 + 3 * sizeof (number) + tablename_len];
- int olderr = errno;
-
- snprintf (buf, sizeof (buf), "[number=%d],%s", number, tablename_val);
-
- nis_result *result = nis_list (buf, FOLLOW_LINKS | FOLLOW_PATH, NULL, NULL);
-
- if (result == NULL)
- {
- __set_errno (ENOMEM);
- return NSS_STATUS_TRYAGAIN;
- }
-
- if (__glibc_unlikely (niserr2nss (result->status) != NSS_STATUS_SUCCESS))
- {
- enum nss_status status = niserr2nss (result->status);
-
- __set_errno (olderr);
-
- nis_freeresult (result);
- return status;
- }
-
- int parse_res = _nss_nisplus_parse_protoent (result, proto, buffer, buflen,
- errnop);
-
- nis_freeresult (result);
-
- if (parse_res < 1)
- {
- if (parse_res == -1)
- {
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
- else
- {
- __set_errno (olderr);
- return NSS_STATUS_NOTFOUND;
- }
- }
-
- return NSS_STATUS_SUCCESS;
-}
diff --git a/nis/nss_nisplus/nisplus-pwd.c b/nis/nss_nisplus/nisplus-pwd.c
deleted file mode 100644
index b1834609a8..0000000000
--- a/nis/nss_nisplus/nisplus-pwd.c
+++ /dev/null
@@ -1,408 +0,0 @@
-/* Copyright (C) 1997-2020 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Thorsten Kukuk , 1997.
-
- 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
- . */
-
-#include
-#include
-#include
-#include
-#include