Tue Jun 25 02:59:11 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu> cvs/libc-960625
authorRoland McGrath <roland@gnu.org>
Tue, 25 Jun 1996 08:56:57 +0000 (08:56 +0000)
committerRoland McGrath <roland@gnu.org>
Tue, 25 Jun 1996 08:56:57 +0000 (08:56 +0000)
* malloc/malloc.h: Declare malloc_object_allocated_size, malloc_walk.
* malloc/Makefile (dist-routines): Add malloc-size, malloc-walk.
* malloc/malloc-size.c: New file.
* malloc/malloc-walk.c: New file.

* malloc/malloc-find.c (malloc_find_object_address): Return null if
PTR is outside the heap.

* elf/dl-load.c (_dl_map_object): If the requested name matches the
  soname of a loaded object, use that object.

Mon Jun 24 19:57:01 1996  Roland McGrath  <roland@delasyd.gnu.ai.mit.edu>

* Makefile (subdirs): Add nss.

* inet/Makefile (routines): Add getrpcent, getrpcbyname,
getrpcbynumber, getrpcent_r, getrpcbyname_r, getrpcbynumber_r.
* inet/getrpcbynumber_r.c: New file.
* inet/getrpcbynumber.c: New file.
* inet/getrpcbyname.c: New file.
* inet/getrpcbyname_r.c: New file.
* inet/getrpcent_r.c: New file.
* inet/getrpcent.c: New file.
* nss/rpc-lookup.c: New file.
* nss/nss_files/files-rpc.c: New file.
* nss/Makefile (routines): Add rpc-lookup.
(libnss_files-routines): Add files-rpc.
* sunrpc/Makefile (routines): Remove getrpcent.
* sunrpc/getrpcent.c: File removed.

* nss/getXXent_r.c (REENTRANT_GETNAME): Clear NO_MORE when NIP is
non-null on entry.

* Makeconfig (rpath-link): Add $(nssobjdir).
(nssobjdir): New variable.

* Makerules: Move shared library building before objects rules, so
versions are known before extra-lib.mk gets included.
* extra-lib.mk (lib-noranlib): Depend on the shared object too.

* pwd/getpwuid.c: Rewritten using nss.
* pwd/getpwnam.c: Likewise.
* pwd/getpwent.c: Likewise.
* grp/getgrnam.c: Likewise.
* grp/getgrgid.c: Likewise.
* grp/getgrent.c: Likewise.
* pwd/Makefile (routines): Add getpwent_r, getpwnam_r, getpwuid_r.
* pwd/getpwent_r.c: New file.
* pwd/getpwnam_r.c: New file.
* pwd/getpwuid_r.c: New file.
* grp/Makefile (routines): Add getgrent_r, getgrgid_r, getgrnam_r.
* grp/getgrnam_r.c: New file.
* grp/getgrgid_r.c: New file.
* grp/getgrent_r.c: New file.
* grp/Makefile (routines): Remove grpopen, grpread.
* pwd/Makefile (routines): Remove pwdopen, pwdread.
* grp/grpopen.c, grp/grpread.c, pwd/pwdopen.c, pwd/pwdread.c: Removed.

* pwd/fgetpwent.c: Rewritten using files-parse.c.
* grp/fgetgrent.c: Likewise.

* nss/Makefile (routines): Add grp-lookup and pwd-lookup.
* nss/pwd-lookup.c, nss/grp-lookup.c: New files.
* nss/nss_files/files-grp.c: New file.
* nss/nss_files/files-pwd.c: New file.

* nss/Makefile (subdir-dirs): New variable; use it in vpath.

* nss/nss_files/files-parse.c: New file.
* nss/nss_files/files-XXX.c: New file.
* nss/nss_files/files-hosts.c, nss/nss_files/files-proto.c,
nss/nss_files/files-service.c, nss/nss_files/files-network.c:
Rewritten using them.

* nss/Makefile (libnss_files-routines): Remove files-host.
Add files-hosts, files-grp, files-pwd.

* nss/nss_dns/dns-network.c: Don't include <pthread.h>.

Mon Jun 24 22:39:12 1996  Richard Henderson  <rth@tamu.edu>

* sysdeps/alpha/dl-machine.h (ELF_MACHINE_RUNTIME_TRAMPOLINE):
A .plt entry now loads the .rela.plt offset directly rather
than making us calculate it.

Sun Jun 23 15:24:05 1996  Roland McGrath  <roland@delasyd.gnu.ai.mit.edu>

* time/Makefile ($(installed-localtime-file) rule): Do
$(make-target-directory) first.

* resolv.h: Fix wrapper for resolv/resolv.h.

* configure.in (ld --no-whole-archive check): Use AC_TRY_COMMAND.
Compile dummy file and pass -nostdlib -nostartfiles so as not to
require installed libraries.

* shlib-versions (*-*-*): Set libresolv=2, libnss_files=1,
libnss_dns=1.

Sun Jun 23 19:42:05 1996  Ulrich Drepper  <drepper@cygnus.com>

* resolv/netdb.h (_PATH_NSSWITCH_CONF): New macro.

* inet/herrno.c: New file.

* resolv/res_init.c: Remove res_hconf calls.

* nss/Makefile, nss/XXX-lookup.c, nss/file-lookup.c,
nss/getXXbyYY.c, nss/getXXbyYY_r.c, nss/getXXent.c,
nss/getXXent_r.c, nss/host-lookup.c, nss/network-lookup.c,
nss/nsswitch.c, nss/nsswitch.h, nss/proto-lookup.c,
nss/service-lookup.c: New files.  Implementation of name
service switch, following the approach in Solaris.
Interface specification and general structure inspired by Peter
Eriksson <pen@lysator.liu.se>.
* nss/nss_files/files-host.c, nss/nss_files/files-network.c,
nss/nss_files/files-proto.c, nss/nss_files/files-service.c:
Implementation of libnss_files.so module for file based databases
in NSS service.
* nss/nss_dns/dns-host.c, nss/nss_dns/dns-network.c: Implementation
        if libnss_dns.so module for DNS name lookup in NSS service.

* inet/getproto.c, inet/getprtent.c, inet/getprtname.c,
inet/getservent.c, inet/getsrvbynm.c, inet/getsrvbypt.c:
Changed to serve as interface to NSS.
* inet/gethstbyad.c, inet/gethstbyad_r.c, inet/gethstbynm.c,
inet/gethstbynm2.c, inet/gethstbynm2_r.c, inet/gethstbynm_r.c,
inet/gethstent.c, inet/gethstent_r.c, inet/getnetbynm.c,
inet/getnetbynm_r.c, inet/getnetbypt.c, inet/getnetbypt_r.c,
inet/getnetent.c, inet/getnetent_r.c, inet/getproto_r.c,
inet/getprtent_r.c, inet/getprtname_r.c, inet/getservent_r.c,
inet/getsrvbynm_r.c, inet/getsrvbypt_r.c: New files.  Implement
interfaces to NSS, including reentrant functions.

* resolv/getnetbyaddr.c, resolv/getnetbyname.c, resolv/getnetent.c,
resolv/sethostent.c: Removed:  Obsoleted by NSS.

* resolv/mapv4v6addr.h, resolv/mapv4v6hostent.h: Extracted from
gethnamaddr.c.  These private functions are now used in more
than one file.

* resolv/inet_pton.c, resolv/gethnamaddr.c: Updated to bind-4.9.4-T5B.

Sat Jun 22 16:49:47 1996  Andreas Schwab  <schwab@issan.informatik.uni-dortmund.de>

* rpm/Makefile ($(config)): Make sure the word list in the for
loop is syntactically non-empty.

107 files changed:
ChangeLog
Makeconfig
Makefile
Makerules
NEWS
configure
configure.in
elf/dl-load.c
extra-lib.mk
grp/Makefile
grp/fgetgrent.c
grp/getgrent.c
grp/getgrent_r.c [new file with mode: 0644]
grp/getgrgid.c
grp/getgrgid_r.c [new file with mode: 0644]
grp/getgrnam.c
grp/getgrnam_r.c [new file with mode: 0644]
grp/grpread.c [deleted file]
inet/Makefile
inet/gethstbyad.c [new file with mode: 0644]
inet/gethstbyad_r.c [new file with mode: 0644]
inet/gethstbynm.c [new file with mode: 0644]
inet/gethstbynm2.c [new file with mode: 0644]
inet/gethstbynm2_r.c [new file with mode: 0644]
inet/gethstbynm_r.c [new file with mode: 0644]
inet/gethstent.c [moved from pwd/pwdopen.c with 67% similarity]
inet/gethstent_r.c [new file with mode: 0644]
inet/getnetbynm.c [new file with mode: 0644]
inet/getnetbynm_r.c [new file with mode: 0644]
inet/getnetbypt.c [new file with mode: 0644]
inet/getnetbypt_r.c [new file with mode: 0644]
inet/getnetent.c [moved from grp/grpopen.c with 67% similarity]
inet/getnetent_r.c [new file with mode: 0644]
inet/getproto.c
inet/getproto_r.c [new file with mode: 0644]
inet/getprtent.c
inet/getprtent_r.c [new file with mode: 0644]
inet/getprtname.c
inet/getprtname_r.c [new file with mode: 0644]
inet/getrpcbyname.c [new file with mode: 0644]
inet/getrpcbyname_r.c [new file with mode: 0644]
inet/getrpcbynumber.c [new file with mode: 0644]
inet/getrpcbynumber_r.c [new file with mode: 0644]
inet/getrpcent.c [new file with mode: 0644]
inet/getrpcent_r.c [new file with mode: 0644]
inet/getservent.c
inet/getservent_r.c [new file with mode: 0644]
inet/getsrvbynm.c
inet/getsrvbynm_r.c [new file with mode: 0644]
inet/getsrvbypt.c
inet/getsrvbypt_r.c [new file with mode: 0644]
inet/herrno.c [new file with mode: 0644]
nss/Makefile [new file with mode: 0644]
nss/XXX-lookup.c [new file with mode: 0644]
nss/file-lookup.c [new file with mode: 0644]
nss/getXXbyYY.c [new file with mode: 0644]
nss/getXXbyYY_r.c [new file with mode: 0644]
nss/getXXent.c [new file with mode: 0644]
nss/getXXent_r.c [new file with mode: 0644]
nss/grp-lookup.c [new file with mode: 0644]
nss/host-lookup.c [new file with mode: 0644]
nss/network-lookup.c [new file with mode: 0644]
nss/nss_dns/dns-host.c [new file with mode: 0644]
nss/nss_dns/dns-network.c [new file with mode: 0644]
nss/nss_files/files-XXX.c [new file with mode: 0644]
nss/nss_files/files-grp.c [new file with mode: 0644]
nss/nss_files/files-hosts.c [new file with mode: 0644]
nss/nss_files/files-network.c [new file with mode: 0644]
nss/nss_files/files-parse.c [new file with mode: 0644]
nss/nss_files/files-proto.c [new file with mode: 0644]
nss/nss_files/files-pwd.c [new file with mode: 0644]
nss/nss_files/files-rpc.c [new file with mode: 0644]
nss/nss_files/files-service.c [new file with mode: 0644]
nss/nsswitch.c [new file with mode: 0644]
nss/nsswitch.h [new file with mode: 0644]
nss/proto-lookup.c [new file with mode: 0644]
nss/pwd-lookup.c [new file with mode: 0644]
nss/rpc-lookup.c [new file with mode: 0644]
nss/service-lookup.c [new file with mode: 0644]
posix/getopt.c
posix/regex.c
pwd/Makefile
pwd/fgetpwent.c
pwd/getpwent.c
pwd/getpwent_r.c [new file with mode: 0644]
pwd/getpwnam.c
pwd/getpwnam_r.c [new file with mode: 0644]
pwd/getpwuid.c
pwd/getpwuid_r.c [new file with mode: 0644]
pwd/pwdread.c [deleted file]
resolv.h
resolv/gethnamaddr.c
resolv/getnetbyaddr.c [deleted file]
resolv/getnetbyname.c [deleted file]
resolv/getnetent.c [deleted file]
resolv/inet_pton.c
resolv/mapv4v6addr.h [new file with mode: 0644]
resolv/mapv4v6hostent.h [new file with mode: 0644]
resolv/netdb.h
resolv/res_init.c
resolv/sethostent.c [deleted file]
rpm/Makefile
shlib-versions
sunrpc/Makefile
sunrpc/getrpcent.c [deleted file]
sysdeps/alpha/dl-machine.h
time/Makefile

index 2459342..2721aa9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,153 @@
+Tue Jun 25 02:59:11 1996  Roland McGrath  <roland@delasyd.gnu.ai.mit.edu>
+
+       * malloc/malloc.h: Declare malloc_object_allocated_size, malloc_walk.
+       * malloc/Makefile (dist-routines): Add malloc-size, malloc-walk.
+       * malloc/malloc-size.c: New file.
+       * malloc/malloc-walk.c: New file.
+
+       * malloc/malloc-find.c (malloc_find_object_address): Return null if
+       PTR is outside the heap.
+
+       * elf/dl-load.c (_dl_map_object): If the requested name matches the
+       soname of a loaded object, use that object.
+
+Mon Jun 24 19:57:01 1996  Roland McGrath  <roland@delasyd.gnu.ai.mit.edu>
+
+       * Makefile (subdirs): Add nss.
+
+       * inet/Makefile (routines): Add getrpcent, getrpcbyname,
+       getrpcbynumber, getrpcent_r, getrpcbyname_r, getrpcbynumber_r.
+       * inet/getrpcbynumber_r.c: New file.
+       * inet/getrpcbynumber.c: New file.
+       * inet/getrpcbyname.c: New file.
+       * inet/getrpcbyname_r.c: New file.
+       * inet/getrpcent_r.c: New file.
+       * inet/getrpcent.c: New file.
+       * nss/rpc-lookup.c: New file.
+       * nss/nss_files/files-rpc.c: New file.
+       * nss/Makefile (routines): Add rpc-lookup.
+       (libnss_files-routines): Add files-rpc.
+       * sunrpc/Makefile (routines): Remove getrpcent.
+       * sunrpc/getrpcent.c: File removed.
+
+       * nss/getXXent_r.c (REENTRANT_GETNAME): Clear NO_MORE when NIP is
+       non-null on entry.
+
+       * Makeconfig (rpath-link): Add $(nssobjdir).
+       (nssobjdir): New variable.
+
+       * Makerules: Move shared library building before objects rules, so
+       versions are known before extra-lib.mk gets included.
+       * extra-lib.mk (lib-noranlib): Depend on the shared object too.
+
+       * pwd/getpwuid.c: Rewritten using nss.
+       * pwd/getpwnam.c: Likewise.
+       * pwd/getpwent.c: Likewise.
+       * grp/getgrnam.c: Likewise.
+       * grp/getgrgid.c: Likewise.
+       * grp/getgrent.c: Likewise.
+       * pwd/Makefile (routines): Add getpwent_r, getpwnam_r, getpwuid_r.
+       * pwd/getpwent_r.c: New file.
+       * pwd/getpwnam_r.c: New file.
+       * pwd/getpwuid_r.c: New file.
+       * grp/Makefile (routines): Add getgrent_r, getgrgid_r, getgrnam_r.
+       * grp/getgrnam_r.c: New file.
+       * grp/getgrgid_r.c: New file.
+       * grp/getgrent_r.c: New file.
+       * grp/Makefile (routines): Remove grpopen, grpread.
+       * pwd/Makefile (routines): Remove pwdopen, pwdread.
+       * grp/grpopen.c, grp/grpread.c, pwd/pwdopen.c, pwd/pwdread.c: Removed.
+
+       * pwd/fgetpwent.c: Rewritten using files-parse.c.
+       * grp/fgetgrent.c: Likewise.
+
+       * nss/Makefile (routines): Add grp-lookup and pwd-lookup.
+       * nss/pwd-lookup.c, nss/grp-lookup.c: New files.
+       * nss/nss_files/files-grp.c: New file.
+       * nss/nss_files/files-pwd.c: New file.
+
+       * nss/Makefile (subdir-dirs): New variable; use it in vpath.
+
+       * nss/nss_files/files-parse.c: New file.
+       * nss/nss_files/files-XXX.c: New file.
+       * nss/nss_files/files-hosts.c, nss/nss_files/files-proto.c,
+       nss/nss_files/files-service.c, nss/nss_files/files-network.c:
+       Rewritten using them.
+
+       * nss/Makefile (libnss_files-routines): Remove files-host.
+       Add files-hosts, files-grp, files-pwd.
+
+       * nss/nss_dns/dns-network.c: Don't include <pthread.h>.
+
+Mon Jun 24 22:39:12 1996  Richard Henderson  <rth@tamu.edu>
+
+       * sysdeps/alpha/dl-machine.h (ELF_MACHINE_RUNTIME_TRAMPOLINE):
+       A .plt entry now loads the .rela.plt offset directly rather
+       than making us calculate it.
+
+Sun Jun 23 15:24:05 1996  Roland McGrath  <roland@delasyd.gnu.ai.mit.edu>
+
+       * time/Makefile ($(installed-localtime-file) rule): Do
+       $(make-target-directory) first.
+
+       * resolv.h: Fix wrapper for resolv/resolv.h.
+
+       * configure.in (ld --no-whole-archive check): Use AC_TRY_COMMAND.
+       Compile dummy file and pass -nostdlib -nostartfiles so as not to
+       require installed libraries.
+
+       * shlib-versions (*-*-*): Set libresolv=2, libnss_files=1,
+       libnss_dns=1.
+
+Sun Jun 23 19:42:05 1996  Ulrich Drepper  <drepper@cygnus.com>
+
+       * resolv/netdb.h (_PATH_NSSWITCH_CONF): New macro.
+
+       * inet/herrno.c: New file.
+
+       * resolv/res_init.c: Remove res_hconf calls.
+
+       * nss/Makefile, nss/XXX-lookup.c, nss/file-lookup.c,
+       nss/getXXbyYY.c, nss/getXXbyYY_r.c, nss/getXXent.c,
+       nss/getXXent_r.c, nss/host-lookup.c, nss/network-lookup.c,
+       nss/nsswitch.c, nss/nsswitch.h, nss/proto-lookup.c,
+       nss/service-lookup.c: New files.  Implementation of name
+       service switch, following the approach in Solaris.
+       Interface specification and general structure inspired by Peter
+       Eriksson <pen@lysator.liu.se>.
+       * nss/nss_files/files-host.c, nss/nss_files/files-network.c,
+       nss/nss_files/files-proto.c, nss/nss_files/files-service.c:
+       Implementation of libnss_files.so module for file based databases
+       in NSS service.
+       * nss/nss_dns/dns-host.c, nss/nss_dns/dns-network.c: Implementation
+        if libnss_dns.so module for DNS name lookup in NSS service.
+
+       * inet/getproto.c, inet/getprtent.c, inet/getprtname.c,
+       inet/getservent.c, inet/getsrvbynm.c, inet/getsrvbypt.c:
+       Changed to serve as interface to NSS.
+       * inet/gethstbyad.c, inet/gethstbyad_r.c, inet/gethstbynm.c,
+       inet/gethstbynm2.c, inet/gethstbynm2_r.c, inet/gethstbynm_r.c,
+       inet/gethstent.c, inet/gethstent_r.c, inet/getnetbynm.c,
+       inet/getnetbynm_r.c, inet/getnetbypt.c, inet/getnetbypt_r.c,
+       inet/getnetent.c, inet/getnetent_r.c, inet/getproto_r.c,
+       inet/getprtent_r.c, inet/getprtname_r.c, inet/getservent_r.c,
+       inet/getsrvbynm_r.c, inet/getsrvbypt_r.c: New files.  Implement
+       interfaces to NSS, including reentrant functions.
+
+       * resolv/getnetbyaddr.c, resolv/getnetbyname.c, resolv/getnetent.c,
+       resolv/sethostent.c: Removed:  Obsoleted by NSS.
+
+       * resolv/mapv4v6addr.h, resolv/mapv4v6hostent.h: Extracted from
+       gethnamaddr.c.  These private functions are now used in more
+       than one file.
+
+       * resolv/inet_pton.c, resolv/gethnamaddr.c: Updated to bind-4.9.4-T5B.
+
+Sat Jun 22 16:49:47 1996  Andreas Schwab  <schwab@issan.informatik.uni-dortmund.de>
+
+       * rpm/Makefile ($(config)): Make sure the word list in the for
+       loop is syntactically non-empty.
+
 Sat Jun 22 21:29:52 1996  Roland McGrath  <roland@delasyd.gnu.ai.mit.edu>
 
        * Version 1.92 test release.
index 3d79890..eeeb9ac 100644 (file)
@@ -324,7 +324,8 @@ else
 default-rpath = $(libdir)
 endif
 # This is how to find at build-time things that will be installed there.
-rpath-link = $(common-objdir):$(elfobjdir)
+rpath-link = $(common-objdir):$(elfobjdir):$(nssobjdir)
+nssobjdir := $(firstword $(objdir) $(patsubst ../$(subdir),.,$(..)nss))
 else
 link-libc = $(common-objpfx)libc.a $(gnulib) $(common-objpfx)libc.a
 endif
index 39c812c..13ca36b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -54,7 +54,7 @@ endif
 subdirs = csu assert ctype db locale intl catgets math setjmp signal stdlib \
          stdio-common $(stdio) malloc string wcsmbs time dirent grp pwd\
          posix io termios resource misc login socket sysvipc gmon gnulib \
-         wctype $(wildcard crypt) manual $(sysdep-subdirs) elf po
+         wctype $(wildcard crypt) manual $(sysdep-subdirs) nss elf po
 export subdirs := $(subdirs)   # Benign, useless in GNU make before 3.63.
 
 # The mach and hurd subdirectories have many generated header files which
index 7f4b5fd..84afdd5 100644 (file)
--- a/Makerules
+++ b/Makerules
@@ -286,6 +286,71 @@ define sed-remove-objpfx
 endef
 endif
 \f
+# Shared library building.
+
+ifeq (yes,$(build-shared))
+
+# Process the shlib-versions file, which tells us what shared library
+# version numbers to use when we install shared objects on this system.
+-include $(common-objpfx)soversions.mk
+$(common-objpfx)soversions.mk: $(..)shlib-versions $(..)Makerules \
+                              $(common-objpfx)config.make
+       sed 's/#.*$$//' $< | while read conf versions; do \
+         test -n "$$versions" || continue; \
+         case '$(config-machine)-$(config-vendor)-$(config-os)' in $$conf)\
+           for v in $$versions; do \
+             lib="$${v%%=*}"; if eval "test -z \"\$$vers_lib$$lib\""; then \
+               eval vers_lib$${lib}=yes; \
+               echo $$lib.so-version=.$${v##$$lib=}; fi; \
+         done ;; esac; done > $@T
+       mv -f $@T $@
+
+# Get $(version) defined with the release version number.
+-include $(common-objpfx)version.mk
+
+
+# Pattern rule to build a shared object from an archive of PIC objects.
+# This must come after the installation rules so Make doesn't try to
+# build shared libraries in place from the installed *_pic.a files.
+# $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
+# on other shared objects.
+lib%.so: lib%_pic.a; $(build-shlib)
+
+ifeq ($(have-no-whole-archive),yes)
+no-whole-archive = -Wl,--no-whole-archive
+else
+no-whole-archive =
+endif
+
+define build-shlib
+$(LINK.o) -shared -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS)  \
+         -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
+         $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
+         -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \
+         -Wl,--whole-archive $^ $(no-whole-archive) \
+         $(LDLIBS-$(@F:lib%.so=%).so)
+endef
+
+# Don't try to use -lc when making libc.so itself.
+# Also omits crti.o and crtn.o, which we do not want
+# since we define our own `.init' section specially.
+LDFLAGS-c.so = -nostdlib -nostartfiles
+# Give libc.so an entry point and make it directly runnable itself.
+LDFLAGS-c.so += -e __libc_main
+# Use our own special initializer and finalizer files for libc.so.
+elfobjdir := $(firstword $(objdir) $(patsubst ../$(subdir),.,$(..)elf))
+$(common-objpfx)libc.so: $(elfobjdir)/soinit.so \
+                        $(common-objpfx)libc_pic.a \
+                        $(elfobjdir)/sofini.so $(elfobjdir)/ld.so
+       $(build-shlib)
+
+ifdef libc.so-version
+$(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
+       rm -f $@
+       ln -s $(<F) $@ || ln $< $@
+endif
+endif
+\f
 # Figure out the source filenames in this directory.
 
 override sources       := $(addsuffix .c,$(filter-out $(elided-routines),\
@@ -452,71 +517,6 @@ $(AR) cru$(verbose) $(@:$(objpfx)%=%) \
 $(RANLIB) $@
 endef
 \f
-# Shared library building.
-
-ifeq (yes,$(build-shared))
-
-# Process the shlib-versions file, which tells us what shared library
-# version numbers to use when we install shared objects on this system.
--include $(common-objpfx)soversions.mk
-$(common-objpfx)soversions.mk: $(..)shlib-versions $(..)Makerules \
-                              $(common-objpfx)config.make
-       sed 's/#.*$$//' $< | while read conf versions; do \
-         test -n "$$versions" || continue; \
-         case '$(config-machine)-$(config-vendor)-$(config-os)' in $$conf)\
-           for v in $$versions; do \
-             lib="$${v%%=*}"; if eval "test -z \"\$$vers_lib$$lib\""; then \
-               eval vers_lib$${lib}=yes; \
-               echo $$lib.so-version=.$${v##$$lib=}; fi; \
-         done ;; esac; done > $@T
-       mv -f $@T $@
-
-# Get $(version) defined with the release version number.
--include $(common-objpfx)version.mk
-
-
-# Pattern rule to build a shared object from an archive of PIC objects.
-# This must come after the installation rules so Make doesn't try to
-# build shared libraries in place from the installed *_pic.a files.
-# $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
-# on other shared objects.
-lib%.so: lib%_pic.a; $(build-shlib)
-
-ifeq ($(have-no-whole-archive),yes)
-no-whole-archive = -Wl,--no-whole-archive
-else
-no-whole-archive =
-endif
-
-define build-shlib
-$(LINK.o) -shared -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS)  \
-         -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
-         $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
-         -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \
-         -Wl,--whole-archive $^ $(no-whole-archive) \
-         $(LDLIBS-$(@F:lib%.so=%).so)
-endef
-
-# Don't try to use -lc when making libc.so itself.
-# Also omits crti.o and crtn.o, which we do not want
-# since we define our own `.init' section specially.
-LDFLAGS-c.so = -nostdlib -nostartfiles
-# Give libc.so an entry point and make it directly runnable itself.
-LDFLAGS-c.so += -e __libc_main
-# Use our own special initializer and finalizer files for libc.so.
-elfobjdir := $(firstword $(objdir) $(patsubst ../$(subdir),.,$(..)elf))
-$(common-objpfx)libc.so: $(elfobjdir)/soinit.so \
-                        $(common-objpfx)libc_pic.a \
-                        $(elfobjdir)/sofini.so $(elfobjdir)/ld.so
-       $(build-shlib)
-
-ifdef libc.so-version
-$(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
-       rm -f $@
-       ln -s $(<F) $@ || ln $< $@
-endif
-endif
-\f
 # Installation.
 
 # $(install-lib) are installed from the object directory into $(libdir);
diff --git a/NEWS b/NEWS
index 1522d60..b82baa6 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,4 @@
-GNU C Library NEWS -- history of user-visible changes.  22 June 1996
+GNU C Library NEWS -- history of user-visible changes.  24 June 1996
 
 Copyright (C) 1992, 93, 94, 95, 96 Free Software Foundation, Inc.
 See the end for copying conditions.
@@ -47,6 +47,15 @@ Version 2.0
   `float' functions.  The math functions now reside in a separate library,
   so programs using them will need to use `-lm' their linking commands.
 
+* Ulrich Drepper has contributed support for an `/etc/nsswitch.conf'
+  mechanism similar to that found in Solaris 2.  This is now used for the
+  group, passwd, hosts, networks, services, protocols, and rpc databases.
+  The `nsswitch.conf' file controls what services are used for each
+  individual database.  This works by loading shared libraries with names
+  specified in `nsswitch.conf', so service modules can be changed or added at
+  any time without even relinking any program.  A future release of the
+  separate NYS package will provide NIS/YP and NIS+ modules for this interface.
+
 * The new functions `strtoq' and `strtouq' parse integer values from
   strings, like `strtol' and `strtoul', but they return `long long int' and
   `unsigned long long int' values, respectively (64-bit quantities).
index 25586ff..aef8058 100755 (executable)
--- a/configure
+++ b/configure
@@ -1541,10 +1541,11 @@ if eval "test \"`echo '$''{'libc_cv_ld_no_whole_archive'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.c <<\EOF
-main () { exit (0); }
+_start () {}
 EOF
-if ${CC-cc} $CFLAGS -Wl,--no-whole-archive \
-           -o conftest conftest.c 2>/dev/null; then
+if { ac_try='${CC-cc} $CFLAGS \
+                           -nostdlib -nostartfiles -Wl,--no-whole-archive \
+                           -o conftest conftest.c'; { (eval echo configure:1549: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; }; then
   libc_cv_ld_no_whole_archive=yes
 else
   libc_cv_ld_no_whole_archive=no
index 610d5e8..46d7317 100644 (file)
@@ -475,10 +475,11 @@ fi
 
 AC_CACHE_CHECK(for ld --no-whole-archive, libc_cv_ld_no_whole_archive, [dnl
 cat > conftest.c <<\EOF
-main () { exit (0); }
+_start () {}
 EOF
-if ${CC-cc} $CFLAGS -Wl,--no-whole-archive \
-           -o conftest conftest.c 2>/dev/null; then
+if AC_TRY_COMMAND([${CC-cc} $CFLAGS \
+                           -nostdlib -nostartfiles -Wl,--no-whole-archive \
+                           -o conftest conftest.c]); then
   libc_cv_ld_no_whole_archive=yes
 else
   libc_cv_ld_no_whole_archive=no
index 1e0db77..7c2f2e3 100644 (file)
@@ -459,7 +459,12 @@ _dl_map_object (struct link_map *loader, const char *name, int type)
 
   /* Look for this name among those already loaded.  */
   for (l = _dl_loaded; l; l = l->l_next)
-    if (! strcmp (name, l->l_libname))
+    if (! strcmp (name, l->l_libname) || /* NAME was requested before.  */
+       /* If the requested name matches the soname of a loaded object,
+          use that object.  */
+       (l->l_info[DT_SONAME] &&
+        ! strcmp (name, (const char *) (l->addr +
+                                        l->l_info[DT_SONAME]->d_un.d_ptr))))
       {
        /* The object is already loaded.
           Just bump its reference count and return it.  */
index 283da06..5368a03 100644 (file)
@@ -27,6 +27,9 @@ alltypes-$(lib) := $(foreach o,$(object-suffixes-$(lib)),\
 
 ifeq (,$($(lib)-no-lib-dep))
 lib-noranlib: $(alltypes-$(lib))
+ifeq (yes,$(build-shared))
+lib-noranlib: $(objpfx)$(lib).so$($(lib).so-version)
+endif
 else
 others: $(alltypes-$(lib))
 endif
index 6444aab..273b7d1 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 1991, 1992 Free Software Foundation, Inc.
+# Copyright (C) 1991, 1992, 1996 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
@@ -21,8 +21,9 @@
 #
 subdir := grp
 
-routines := grpopen grpread fgetgrent getgrent getgrgid getgrnam \
-           initgroups setgroups
+routines := fgetgrent initgroups setgroups \
+           getgrent getgrgid getgrnam \
+           getgrent_r getgrgid_r getgrnam_r
 
 tests := testgrp
 
index bef3e3f..031ccb9 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1996 Free Software Foundation, Inc.
 This file is part of the GNU C Library.
 
 The GNU C Library is free software; you can redistribute it and/or
@@ -16,26 +16,48 @@ License along with the GNU C Library; see the file COPYING.LIB.  If
 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
 Cambridge, MA 02139, USA.  */
 
-#include <ansidecl.h>
-#include <errno.h>
-#include <stddef.h>
 #include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
 #include <grp.h>
 
+/* Define a line parsing function using the common code
+   used in the nss_files module.  */
 
-/* Read a group entry from STREAM.  */
+#define STRUCTURE      group
+#define ENTNAME                grent
+struct grent_data {};
+
+#define TRAILING_LIST_MEMBER           gr_mem
+#define TRAILING_LIST_SEPARATOR_P(c)   ((c) == ',')
+#include "../nss/nss_files/files-parse.c"
+LINE_PARSER
+(
+ STRING_FIELD (result->gr_name, ISCOLON);
+ STRING_FIELD (result->gr_passwd, ISCOLON);
+ INT_FIELD (result->gr_gid, ISCOLON, 10,);
+)
+
+
+/* Read one entry from the given stream.  */
 struct group *
-DEFUN(fgetgrent, (stream), FILE *stream)
+fgetgrent (FILE *stream)
 {
-  static PTR info = NULL;
-  if (info == NULL)
+  static char buffer[BUFSIZ];
+  static struct group result;
+  char *p;
+
+  do
     {
-      info = __grpalloc();
-      if (info == NULL)
+      p = fgets (buffer, sizeof buffer, stream);
+      if (p == NULL)
        return NULL;
-    }
 
-  return __grpread(stream, info);
+      /* Skip leading blanks.  */
+      while (isspace (*p))
+       ++p;
+    } while (*p == '\0' || *p == '#' ||        /* Ignore empty and comment lines.  */
+            /* Parse the line.  If it is invalid, loop to
+               get the next line of the file to parse.  */
+            ! parse_line (p, &result, (void *) buffer, sizeof buffer));
+
+  return &result;
 }
index 105572f..4e14bbc 100644 (file)
@@ -1,5 +1,6 @@
-/* Copyright (C) 1991 Free Software Foundation, Inc.
+/* Copyright (C) 1996 Free Software Foundation, Inc.
 This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
 
 The GNU C Library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Library General Public License as
@@ -13,55 +14,17 @@ Library General Public License for more details.
 
 You should have received a copy of the GNU Library General Public
 License along with the GNU C Library; see the file COPYING.LIB.  If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA.  */
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
-#include <ansidecl.h>
-#include <stddef.h>
-#include <stdio.h>
 #include <grp.h>
 
-static FILE *stream = NULL;
 
-/* Rewind the stream.  */
-void
-DEFUN_VOID(setgrent)
-{
-  if (stream != NULL)
-    rewind(stream);
-}
+#define LOOKUP_TYPE    struct group
+#define SETFUNC_NAME   setgrent
+#define        GETFUNC_NAME    getgrent
+#define        ENDFUNC_NAME    endgrent
+#define DATABASE_NAME  group
+#define BUFLEN         1024
 
-
-/* Close the stream.  */
-void
-DEFUN_VOID(endgrent)
-{
-  if (stream != NULL)
-    {
-      (void) fclose(stream);
-      stream = NULL;
-    }
-}
-
-
-/* Read an entry from the stream.  */
-struct group *
-DEFUN_VOID(getgrent)
-{
-  static PTR info = NULL;
-  if (info == NULL)
-    {
-      info = __grpalloc();
-      if (info == NULL)
-       return(NULL);
-    }
-
-  if (stream == NULL)
-    {
-      stream = __grpopen();
-      if (stream == NULL)
-       return(NULL);
-    }
-
-  return(__grpread(stream, info));
-}
+#include "../nss/getXXent.c"
diff --git a/grp/getgrent_r.c b/grp/getgrent_r.c
new file mode 100644 (file)
index 0000000..db692b2
--- /dev/null
@@ -0,0 +1,30 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <grp.h>
+
+
+#define LOOKUP_TYPE    struct group
+#define SETFUNC_NAME   setgrent
+#define        GETFUNC_NAME    getgrent
+#define        ENDFUNC_NAME    endgrent
+#define DATABASE_NAME  group
+#define BUFLEN         1024
+
+#include "../nss/getXXent_r.c"
index ef3860f..855d31c 100644 (file)
@@ -1,5 +1,6 @@
-/* Copyright (C) 1991, 1995 Free Software Foundation, Inc.
+/* Copyright (C) 1996 Free Software Foundation, Inc.
 This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
 
 The GNU C Library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Library General Public License as
@@ -13,24 +14,17 @@ Library General Public License for more details.
 
 You should have received a copy of the GNU Library General Public
 License along with the GNU C Library; see the file COPYING.LIB.  If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA.  */
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
-#include <ansidecl.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <sys/types.h>
 #include <grp.h>
 
-/* Search for an entry with a matching group ID.  */
-struct group *
-DEFUN(getgrgid, (gid), gid_t gid)
-{
-  int match (struct group *p)
-    {
-      return p->gr_gid == gid;
-    }
-  static void *info;
 
-  return __grpscan (&info, &match);
-}
+#define LOOKUP_TYPE    struct group
+#define FUNCTION_NAME  getgrgid
+#define DATABASE_NAME  group
+#define ADD_PARAMS     gid_t gid
+#define ADD_VARIABLES  gid
+#define BUFLEN         1024
+
+#include "../nss/getXXbyYY.c"
diff --git a/grp/getgrgid_r.c b/grp/getgrgid_r.c
new file mode 100644 (file)
index 0000000..1d5f1a4
--- /dev/null
@@ -0,0 +1,30 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <grp.h>
+
+
+#define LOOKUP_TYPE    struct passwd
+#define FUNCTION_NAME  getgrgid
+#define DATABASE_NAME  group
+#define ADD_PARAMS     gid_t gid
+#define ADD_VARIABLES  gid
+#define BUFLEN         1024
+
+#include "../nss/getXXbyYY_r.c"
index 8416770..2104d87 100644 (file)
@@ -1,5 +1,6 @@
-/* Copyright (C) 1991, 1995 Free Software Foundation, Inc.
+/* Copyright (C) 1996 Free Software Foundation, Inc.
 This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
 
 The GNU C Library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Library General Public License as
@@ -13,24 +14,17 @@ Library General Public License for more details.
 
 You should have received a copy of the GNU Library General Public
 License along with the GNU C Library; see the file COPYING.LIB.  If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA.  */
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
-#include <ansidecl.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <string.h>
 #include <grp.h>
 
-/* Search for an entry with a matching name.  */
-struct group *
-DEFUN(getgrnam, (name), const char *name)
-{
-  int match (struct group *p)
-    {
-      return ! strcmp (name, p->gr_name);
-    }
-  static void *info;
 
-  return __grpscan (&info, &match);
-}
+#define LOOKUP_TYPE    struct group
+#define FUNCTION_NAME  getgrnam
+#define DATABASE_NAME  group
+#define ADD_PARAMS     const char *name
+#define ADD_VARIABLES  name
+#define BUFLEN         1024
+
+#include "../nss/getXXbyYY.c"
diff --git a/grp/getgrnam_r.c b/grp/getgrnam_r.c
new file mode 100644 (file)
index 0000000..c1292bb
--- /dev/null
@@ -0,0 +1,29 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <grp.h>
+
+
+#define LOOKUP_TYPE    struct group
+#define FUNCTION_NAME  getgrnam
+#define DATABASE_NAME  group
+#define ADD_PARAMS     const char *name
+#define ADD_VARIABLES  name
+
+#include "../nss/getXXbyYY_r.c"
diff --git a/grp/grpread.c b/grp/grpread.c
deleted file mode 100644 (file)
index 1fed32f..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-/* Copyright (C) 1991, 1992, 1995 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 Library General Public License as
-published by the Free Software Foundation; either version 2 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
-Library General Public License for more details.
-
-You should have received a copy of the GNU Library General Public
-License along with the GNU C Library; see the file COPYING.LIB.  If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA.  */
-
-#include <ansidecl.h>
-#include <errno.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <grp.h>
-
-/* This is the function that all the others are based on.
-   The format of the group file is known only here.  */
-
-/* Structure containing info kept by each __grpread caller.  */
-typedef struct
-  {
-    char *buf;
-    size_t buflen;
-    size_t max_members;
-    char **members;
-    struct group g;
-  } grpread_info;
-
-
-/* Return a chunk of memory containing a pre-initialized `grpread_info'.  */
-PTR
-DEFUN_VOID(__grpalloc)
-{
-  grpread_info *info = (PTR) malloc (sizeof(grpread_info));
-  if (info == NULL)
-    return NULL;
-
-  info->buf = NULL;
-  info->buflen = 0;
-
-  info->max_members = 5;
-  info->members = (char **) malloc (5 * sizeof(char *));
-  if (info->members == NULL)
-    {
-      free ((PTR) info);
-      return NULL;
-    }
-
-  return info;
-}
-
-/* Read a group entry from STREAM, filling in G.  */
-struct group *
-DEFUN(__grpread, (stream, g), FILE *stream AND PTR CONST g)
-{
-  register grpread_info *CONST info = (grpread_info *) g;
-  char *start, *end;
-  register size_t i;
-
-  /* Idiocy checks.  */
-  if (stream == NULL)
-    {
-      errno = EINVAL;
-      return NULL;
-    }
-
-  do
-    if (__getline (&info->buf, &info->buflen, stream) == -1)
-      return NULL;
-  while (info->buf[0] == '#');
-
-  start = info->buf;
-  end = strchr (start, ':');
-  if (end == NULL)
-    return NULL;
-  *end = '\0';
-  info->g.gr_name = start;
-
-  start = end + 1;
-  end = strchr (start, ':');
-  if (end == NULL)
-    return NULL;
-  *end = '\0';
-  info->g.gr_passwd = start;
-
-  info->g.gr_gid = (gid_t) strtol (end + 1, &end, 10);
-  if (*end != ':')
-    return NULL;
-
-  i = 0;
-  do
-    {
-      start = end + 1;
-      end = strchr (start, ',');
-      if (end == NULL)
-       {
-         end = strchr (start, '\n');
-         if (end == start)
-           break;
-         if (end == NULL)
-           return NULL;
-         *end = '\0';
-         end = NULL;
-       }
-      else
-       *end = '\0';
-
-      if (i == info->max_members - 2)
-       {
-         info->max_members += 5;
-         info->members = (char **)
-           realloc ((PTR) info->members, info->max_members * sizeof (char *));
-         if (info->members == NULL)
-           return NULL;
-       }
-
-      info->members[i++] = start;
-    } while (end != NULL);
-  info->members[i] = NULL;
-  info->g.gr_mem = info->members;
-
-  return &info->g;
-}
-
-
-struct group *
-__grpscan (void **info, int (*selector) (struct group *))
-{
-  FILE *stream;
-  struct group *p;
-
-  if (*info == NULL)
-    {
-      *info = __grpalloc ();
-      if (info == NULL)
-       return NULL;
-    }
-
-  stream = __grpopen ();
-  if (stream == NULL)
-    return NULL;
-
-  p = NULL;
-  while (! feof (stream))
-    {
-      p = __grpread (stream, *info);
-      if (p && (*selector) (p))
-       break;
-      p = NULL;
-    }
-
-  (void) fclose (stream);
-  return p;
-}
index 9389a22..da300c7 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
+# Copyright (C) 1991, 92, 93, 94, 95, 96 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
@@ -25,9 +25,16 @@ headers      := netinet/in.h $(wildcard arpa/*.h protocols/*.h)
 
 routines := ntohl ntohs htonl htons            \
            inet_lnaof inet_mkadr       \
-           inet_netof inet_ntoa inet_net       \
-           getproto getprtent getprtname       \
-           getsrvbynm getsrvbypt getservent    \
+           inet_netof inet_ntoa inet_net herrno \
+           gethstbyad gethstbyad_r gethstbynm gethstbynm2 gethstbynm2_r \
+           gethstbynm_r gethstent gethstent_r \
+           getnetbypt getnetbypt_r getnetbynm getnetent getnetent_r \
+           getnetbynm_r \
+           getproto getproto_r getprtent getprtent_r getprtname getprtname_r \
+           getsrvbynm getsrvbynm_r getsrvbypt getsrvbypt_r getservent \
+           getservent_r        \
+           getrpcent getrpcbyname getrpcbynumber \
+           getrpcent_r getrpcbyname_r getrpcbynumber_r \
            rcmd rexec ruserpass
 
 # No warnings about losing BSD code.
diff --git a/inet/gethstbyad.c b/inet/gethstbyad.c
new file mode 100644 (file)
index 0000000..abc2eab
--- /dev/null
@@ -0,0 +1,31 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE    struct hostent
+#define FUNCTION_NAME  gethostbyaddr
+#define DATABASE_NAME  hosts
+#define ADD_PARAMS     const char *addr, int len, int type
+#define ADD_VARIABLES  addr, len, type
+#define BUFLEN         1024
+#define NEED_H_ERRNO   1
+
+#include "../nss/getXXbyYY.c"
diff --git a/inet/gethstbyad_r.c b/inet/gethstbyad_r.c
new file mode 100644 (file)
index 0000000..7dce440
--- /dev/null
@@ -0,0 +1,31 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE    struct hostent
+#define FUNCTION_NAME  gethostbyaddr
+#define DATABASE_NAME  hosts
+#define ADD_PARAMS     const char *addr, int len, int type
+#define ADD_VARIABLES  addr, len, type
+#define NEED_H_ERRNO   1
+#define NEED__RES      1
+
+#include "../nss/getXXbyYY_r.c"
diff --git a/inet/gethstbynm.c b/inet/gethstbynm.c
new file mode 100644 (file)
index 0000000..0717810
--- /dev/null
@@ -0,0 +1,31 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE    struct hostent
+#define FUNCTION_NAME  gethostbyname
+#define DATABASE_NAME  hosts
+#define ADD_PARAMS     const char *name
+#define ADD_VARIABLES  name
+#define BUFLEN         1024
+#define NEED_H_ERRNO   1
+
+#include "../nss/getXXbyYY.c"
diff --git a/inet/gethstbynm2.c b/inet/gethstbynm2.c
new file mode 100644 (file)
index 0000000..42a01d4
--- /dev/null
@@ -0,0 +1,31 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE    struct hostent
+#define FUNCTION_NAME  gethostbyname2
+#define DATABASE_NAME  hosts
+#define ADD_PARAMS     const char *name, int af
+#define ADD_VARIABLES  name, af
+#define BUFLEN         1024
+#define NEED_H_ERRNO   1
+
+#include "../nss/getXXbyYY.c"
diff --git a/inet/gethstbynm2_r.c b/inet/gethstbynm2_r.c
new file mode 100644 (file)
index 0000000..a2aee54
--- /dev/null
@@ -0,0 +1,30 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE    struct hostent
+#define FUNCTION_NAME  gethostbyname2
+#define DATABASE_NAME  hosts
+#define ADD_PARAMS     const char *name, int af
+#define ADD_VARIABLES  name, af
+#define NEED_H_ERRNO   1
+
+#include "../nss/getXXbyYY_r.c"
diff --git a/inet/gethstbynm_r.c b/inet/gethstbynm_r.c
new file mode 100644 (file)
index 0000000..6bd2920
--- /dev/null
@@ -0,0 +1,31 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE    struct hostent
+#define FUNCTION_NAME  gethostbyname
+#define DATABASE_NAME  hosts
+#define ADD_PARAMS     const char *name
+#define ADD_VARIABLES  name
+#define NEED_H_ERRNO   1
+#define NEED__RES      1
+
+#include "../nss/getXXbyYY_r.c"
similarity index 67%
rename from pwd/pwdopen.c
rename to inet/gethstent.c
index 6d35ab9..5c72936 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991 Free Software Foundation, Inc.
+/* Copyright (C) 1996 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
@@ -13,16 +13,15 @@ Library General Public License for more details.
 
 You should have received a copy of the GNU Library General Public
 License along with the GNU C Library; see the file COPYING.LIB.  If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA.  */
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
-#include <ansidecl.h>
-#include <stdio.h>
-#include <pwd.h>
+#include <netdb.h>
 
-/* Return a new stream open on the password file.  */
-FILE *
-DEFUN_VOID(__pwdopen)
-{
-  return(fopen("/etc/passwd", "r"));
-}
+
+#define LOOKUP_TYPE    struct hostent
+#define        GETFUNC_NAME    gethostent
+#define BUFLEN         1024
+#define NEED_H_ERRNO   1
+
+#include "../nss/getXXent.c"
diff --git a/inet/gethstent_r.c b/inet/gethstent_r.c
new file mode 100644 (file)
index 0000000..f07601d
--- /dev/null
@@ -0,0 +1,32 @@
+/* Copyright (C) 1996 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE    struct hostent
+#define SETFUNC_NAME   sethostent
+#define        GETFUNC_NAME    gethostent
+#define        ENDFUNC_NAME    endhostent
+#define DATABASE_NAME  hosts
+#define STAYOPEN       int stayopen
+#define STAYOPEN_VAR   stayopen
+#define NEED_H_ERRNO   1
+#define NEED__RES      1
+
+#include "../nss/getXXent_r.c"
diff --git a/inet/getnetbynm.c b/inet/getnetbynm.c
new file mode 100644 (file)
index 0000000..db1c7b0
--- /dev/null
@@ -0,0 +1,30 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE    struct netent
+#define FUNCTION_NAME  getnetbyname
+#define DATABASE_NAME  networks
+#define ADD_PARAMS     const char *name
+#define ADD_VARIABLES  name
+#define BUFLEN         1024
+
+#include "../nss/getXXbyYY.c"
diff --git a/inet/getnetbynm_r.c b/inet/getnetbynm_r.c
new file mode 100644 (file)
index 0000000..ba395d6
--- /dev/null
@@ -0,0 +1,30 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE    struct netent
+#define FUNCTION_NAME  getnetbyname
+#define DATABASE_NAME  networks
+#define ADD_PARAMS     const char *name
+#define ADD_VARIABLES  name
+#define NEED__RES      1
+
+#include "../nss/getXXbyYY_r.c"
diff --git a/inet/getnetbypt.c b/inet/getnetbypt.c
new file mode 100644 (file)
index 0000000..960ac0a
--- /dev/null
@@ -0,0 +1,30 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE    struct netent
+#define FUNCTION_NAME  getnetbyport
+#define DATABASE_NAME  networks
+#define ADD_PARAMS     unsigned long int net, int type
+#define ADD_VARIABLES  net, type
+#define BUFLEN         1024
+
+#include "../nss/getXXbyYY.c"
diff --git a/inet/getnetbypt_r.c b/inet/getnetbypt_r.c
new file mode 100644 (file)
index 0000000..a39f26f
--- /dev/null
@@ -0,0 +1,30 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE    struct netent
+#define FUNCTION_NAME  getnetbyport
+#define DATABASE_NAME  networks
+#define ADD_PARAMS     unsigned long int net, int type
+#define ADD_VARIABLES  net, type
+#define NEED__RES      1
+
+#include "../nss/getXXbyYY_r.c"
similarity index 67%
rename from grp/grpopen.c
rename to inet/getnetent.c
index 77d1597..207a70e 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991 Free Software Foundation, Inc.
+/* Copyright (C) 1996 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
@@ -13,16 +13,14 @@ Library General Public License for more details.
 
 You should have received a copy of the GNU Library General Public
 License along with the GNU C Library; see the file COPYING.LIB.  If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA.  */
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
-#include <ansidecl.h>
-#include <stdio.h>
-#include <grp.h>
+#include <netdb.h>
 
-/* Return a new stream open on the group file.  */
-FILE *
-DEFUN_VOID(__grpopen)
-{
-  return fopen("/etc/group", "r");
-}
+
+#define LOOKUP_TYPE    struct netent
+#define        GETFUNC_NAME    getnetent
+#define BUFLEN         1024
+
+#include "../nss/getXXent.c"
diff --git a/inet/getnetent_r.c b/inet/getnetent_r.c
new file mode 100644 (file)
index 0000000..333bb4b
--- /dev/null
@@ -0,0 +1,31 @@
+/* Copyright (C) 1996 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE    struct netent
+#define SETFUNC_NAME   setnetent
+#define        GETFUNC_NAME    getnetent
+#define        ENDFUNC_NAME    endnetent
+#define DATABASE_NAME  networks
+#define STAYOPEN       int stayopen
+#define STAYOPEN_VAR   stayopen
+#define NEED__RES      1
+
+#include "../nss/getXXent_r.c"
index 92f562b..11452c1 100644 (file)
@@ -1,55 +1,30 @@
-/*
- * Copyright (c) 1983, 1993
- *     The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getproto.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
 #include <netdb.h>
 
-extern int _proto_stayopen;
 
-struct protoent *
-getprotobynumber(proto)
-       register int proto;
-{
-       register struct protoent *p;
+#define LOOKUP_TYPE    struct protoent
+#define FUNCTION_NAME  getprotobynumber
+#define DATABASE_NAME  protocols
+#define ADD_PARAMS     int proto
+#define ADD_VARIABLES  proto
+#define BUFLEN         1024
 
-       setprotoent(_proto_stayopen);
-       while (p = getprotoent())
-               if (p->p_proto == proto)
-                       break;
-       if (!_proto_stayopen)
-               endprotoent();
-       return (p);
-}
+#include "../nss/getXXbyYY.c"
diff --git a/inet/getproto_r.c b/inet/getproto_r.c
new file mode 100644 (file)
index 0000000..c915280
--- /dev/null
@@ -0,0 +1,29 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE    struct protoent
+#define FUNCTION_NAME  getprotobynumber
+#define DATABASE_NAME  protocols
+#define ADD_PARAMS     int proto
+#define ADD_VARIABLES  proto
+
+#include "../nss/getXXbyYY_r.c"
index c10ae33..8b55a4d 100644 (file)
-/*
- * Copyright (c) 1983, 1993
- *     The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getprotoent.c      8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
 
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netdb.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#define        MAXALIASES      35
+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
+Library General Public License for more details.
 
-static FILE *protof = NULL;
-static char line[BUFSIZ+1];
-static struct protoent proto;
-static char *proto_aliases[MAXALIASES];
-int _proto_stayopen;
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
-void
-setprotoent(f)
-       int f;
-{
-       if (protof == NULL)
-               protof = fopen(_PATH_PROTOCOLS, "r" );
-       else
-               rewind(protof);
-       _proto_stayopen |= f;
-}
+#include <netdb.h>
 
-void
-endprotoent()
-{
-       if (protof) {
-               fclose(protof);
-               protof = NULL;
-       }
-       _proto_stayopen = 0;
-}
 
-struct protoent *
-getprotoent()
-{
-       char *p;
-       register char *cp, **q;
+#define LOOKUP_TYPE    struct protoent
+#define        GETFUNC_NAME    getprotoent
+#define BUFLEN         1024
 
-       if (protof == NULL && (protof = fopen(_PATH_PROTOCOLS, "r" )) == NULL)
-               return (NULL);
-again:
-       if ((p = fgets(line, BUFSIZ, protof)) == NULL)
-               return (NULL);
-       if (*p == '#')
-               goto again;
-       cp = strpbrk(p, "#\n");
-       if (cp == NULL)
-               goto again;
-       *cp = '\0';
-       proto.p_name = p;
-       cp = strpbrk(p, " \t");
-       if (cp == NULL)
-               goto again;
-       *cp++ = '\0';
-       while (*cp == ' ' || *cp == '\t')
-               cp++;
-       p = strpbrk(cp, " \t");
-       if (p != NULL)
-               *p++ = '\0';
-       proto.p_proto = atoi(cp);
-       q = proto.p_aliases = proto_aliases;
-       if (p != NULL) {
-               cp = p;
-               while (cp && *cp) {
-                       if (*cp == ' ' || *cp == '\t') {
-                               cp++;
-                               continue;
-                       }
-                       if (q < &proto_aliases[MAXALIASES - 1])
-                               *q++ = cp;
-                       cp = strpbrk(cp, " \t");
-                       if (cp != NULL)
-                               *cp++ = '\0';
-               }
-       }
-       *q = NULL;
-       return (&proto);
-}
+#include "../nss/getXXent.c"
diff --git a/inet/getprtent_r.c b/inet/getprtent_r.c
new file mode 100644 (file)
index 0000000..47a2f9e
--- /dev/null
@@ -0,0 +1,30 @@
+/* Copyright (C) 1996 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE    struct protoent
+#define SETFUNC_NAME   setprotoent
+#define        GETFUNC_NAME    getprotoent
+#define        ENDFUNC_NAME    endprotoent
+#define DATABASE_NAME  protocols
+#define STAYOPEN       int stayopen
+#define STAYOPEN_VAR   stayopen
+
+#include "../nss/getXXent_r.c"
index 3ee6754..f291513 100644 (file)
@@ -1,62 +1,30 @@
-/*
- * Copyright (c) 1983, 1993
- *     The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getprotoname.c     8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
 #include <netdb.h>
-#include <string.h>
 
-extern int _proto_stayopen;
 
-struct protoent *
-getprotobyname(name)
-       register const char *name;
-{
-       register struct protoent *p;
-       register char **cp;
+#define LOOKUP_TYPE    struct protoent
+#define FUNCTION_NAME  getprotobyname
+#define DATABASE_NAME  protocols
+#define ADD_PARAMS     const char *name
+#define ADD_VARIABLES  name
+#define BUFLEN         1024
 
-       setprotoent(_proto_stayopen);
-       while (p = getprotoent()) {
-               if (strcmp(p->p_name, name) == 0)
-                       break;
-               for (cp = p->p_aliases; *cp != 0; cp++)
-                       if (strcmp(*cp, name) == 0)
-                               goto found;
-       }
-found:
-       if (!_proto_stayopen)
-               endprotoent();
-       return (p);
-}
+#include "../nss/getXXbyYY.c"
diff --git a/inet/getprtname_r.c b/inet/getprtname_r.c
new file mode 100644 (file)
index 0000000..8de7410
--- /dev/null
@@ -0,0 +1,29 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE    struct protoent
+#define FUNCTION_NAME  getprotobyname
+#define DATABASE_NAME  protocols
+#define ADD_PARAMS     const char *name
+#define ADD_VARIABLES  name
+
+#include "../nss/getXXbyYY_r.c"
diff --git a/inet/getrpcbyname.c b/inet/getrpcbyname.c
new file mode 100644 (file)
index 0000000..be14f71
--- /dev/null
@@ -0,0 +1,30 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <rpc/netdb.h>
+
+
+#define LOOKUP_TYPE    struct rpcent
+#define FUNCTION_NAME  getrpcbyname
+#define DATABASE_NAME  rpc
+#define ADD_PARAMS     const char *name
+#define ADD_VARIABLES  name
+#define BUFLEN         1024
+
+#include "../nss/getXXbyYY.c"
diff --git a/inet/getrpcbyname_r.c b/inet/getrpcbyname_r.c
new file mode 100644 (file)
index 0000000..c8b5eba
--- /dev/null
@@ -0,0 +1,29 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <rpc/netdb.h>
+
+
+#define LOOKUP_TYPE    struct rpcent
+#define FUNCTION_NAME  getrpcbyname
+#define DATABASE_NAME  rpc
+#define ADD_PARAMS     const char *name
+#define ADD_VARIABLES  name
+
+#include "../nss/getXXbyYY_r.c"
diff --git a/inet/getrpcbynumber.c b/inet/getrpcbynumber.c
new file mode 100644 (file)
index 0000000..4b02156
--- /dev/null
@@ -0,0 +1,29 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <rpc/netdb.h>
+
+
+#define LOOKUP_TYPE    struct rpcent
+#define FUNCTION_NAME  getrpcbynumber
+#define DATABASE_NAME  rpc
+#define ADD_PARAMS     int number
+#define ADD_VARIABLES  number
+
+#include "../nss/getXXbyYY_r.c"
diff --git a/inet/getrpcbynumber_r.c b/inet/getrpcbynumber_r.c
new file mode 100644 (file)
index 0000000..4b02156
--- /dev/null
@@ -0,0 +1,29 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <rpc/netdb.h>
+
+
+#define LOOKUP_TYPE    struct rpcent
+#define FUNCTION_NAME  getrpcbynumber
+#define DATABASE_NAME  rpc
+#define ADD_PARAMS     int number
+#define ADD_VARIABLES  number
+
+#include "../nss/getXXbyYY_r.c"
diff --git a/inet/getrpcent.c b/inet/getrpcent.c
new file mode 100644 (file)
index 0000000..5b2274a
--- /dev/null
@@ -0,0 +1,26 @@
+/* Copyright (C) 1996 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <rpc/netdb.h>
+
+
+#define LOOKUP_TYPE    struct rpcent
+#define        GETFUNC_NAME    rpcent
+#define BUFLEN         1024
+
+#include "../nss/getXXent.c"
diff --git a/inet/getrpcent_r.c b/inet/getrpcent_r.c
new file mode 100644 (file)
index 0000000..4c9639f
--- /dev/null
@@ -0,0 +1,26 @@
+/* Copyright (C) 1996 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <rpc/netdb.h>
+
+
+#define LOOKUP_TYPE    struct rpcent
+#define        GETFUNC_NAME    rpcent
+#define BUFLEN         1024
+
+#include "../nss/getXXent_r.c"
index 6bee5d3..bb51a68 100644 (file)
-/*
- * Copyright (c) 1983, 1993
- *     The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getservent.c       8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
 
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netdb.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-#define        MAXALIASES      35
+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
+Library General Public License for more details.
 
-static FILE *servf = NULL;
-static char line[BUFSIZ+1];
-static struct servent serv;
-static char *serv_aliases[MAXALIASES];
-int _serv_stayopen;
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
-void
-setservent(f)
-       int f;
-{
-       if (servf == NULL)
-               servf = fopen(_PATH_SERVICES, "r" );
-       else
-               rewind(servf);
-       _serv_stayopen |= f;
-}
+#include <netdb.h>
 
-void
-endservent()
-{
-       if (servf) {
-               fclose(servf);
-               servf = NULL;
-       }
-       _serv_stayopen = 0;
-}
 
-struct servent *
-getservent()
-{
-       char *p;
-       register char *cp, **q;
+#define LOOKUP_TYPE    struct servent
+#define        GETFUNC_NAME    getservent
+#define BUFLEN         1024
 
-       if (servf == NULL && (servf = fopen(_PATH_SERVICES, "r" )) == NULL)
-               return (NULL);
-again:
-       if ((p = fgets(line, BUFSIZ, servf)) == NULL)
-               return (NULL);
-       if (*p == '#')
-               goto again;
-       cp = strpbrk(p, "#\n");
-       if (cp == NULL)
-               goto again;
-       *cp = '\0';
-       serv.s_name = p;
-       p = strpbrk(p, " \t");
-       if (p == NULL)
-               goto again;
-       *p++ = '\0';
-       while (*p == ' ' || *p == '\t')
-               p++;
-       cp = strpbrk(p, ",/");
-       if (cp == NULL)
-               goto again;
-       *cp++ = '\0';
-       serv.s_port = htons((u_short)atoi(p));
-       serv.s_proto = cp;
-       q = serv.s_aliases = serv_aliases;
-       cp = strpbrk(cp, " \t");
-       if (cp != NULL)
-               *cp++ = '\0';
-       while (cp && *cp) {
-               if (*cp == ' ' || *cp == '\t') {
-                       cp++;
-                       continue;
-               }
-               if (q < &serv_aliases[MAXALIASES - 1])
-                       *q++ = cp;
-               cp = strpbrk(cp, " \t");
-               if (cp != NULL)
-                       *cp++ = '\0';
-       }
-       *q = NULL;
-       return (&serv);
-}
+#include "../nss/getXXent.c"
diff --git a/inet/getservent_r.c b/inet/getservent_r.c
new file mode 100644 (file)
index 0000000..676e3c9
--- /dev/null
@@ -0,0 +1,30 @@
+/* Copyright (C) 1996 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE    struct servent
+#define SETFUNC_NAME   setservent
+#define        GETFUNC_NAME    getservent
+#define        ENDFUNC_NAME    endservent
+#define DATABASE_NAME  services
+#define STAYOPEN       int stayopen
+#define STAYOPEN_VAR   stayopen
+
+#include "../nss/getXXent_r.c"
index 77bf813..863d292 100644 (file)
@@ -1,65 +1,30 @@
-/*
- * Copyright (c) 1983, 1993
- *     The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getservbyname.c    8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
 #include <netdb.h>
-#include <string.h>
 
-extern int _serv_stayopen;
 
-struct servent *
-getservbyname(name, proto)
-       const char *name, *proto;
-{
-       register struct servent *p;
-       register char **cp;
+#define LOOKUP_TYPE    struct servent
+#define FUNCTION_NAME  getservbyname
+#define DATABASE_NAME  services
+#define ADD_PARAMS     const char *name, const char *proto
+#define ADD_VARIABLES  name, proto
+#define BUFLEN         1024
 
-       setservent(_serv_stayopen);
-       while (p = getservent()) {
-               if (strcmp(name, p->s_name) == 0)
-                       goto gotname;
-               for (cp = p->s_aliases; *cp; cp++)
-                       if (strcmp(name, *cp) == 0)
-                               goto gotname;
-               continue;
-gotname:
-               if (proto == 0 || strcmp(p->s_proto, proto) == 0)
-                       break;
-       }
-       if (!_serv_stayopen)
-               endservent();
-       return (p);
-}
+#include "../nss/getXXbyYY.c"
diff --git a/inet/getsrvbynm_r.c b/inet/getsrvbynm_r.c
new file mode 100644 (file)
index 0000000..352c646
--- /dev/null
@@ -0,0 +1,29 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE    struct servent
+#define FUNCTION_NAME  getservbyname
+#define DATABASE_NAME  services
+#define ADD_PARAMS     const char *name, const char *proto
+#define ADD_VARIABLES  name, proto
+
+#include "../nss/getXXbyYY_r.c"
index 0acb31b..c7f3508 100644 (file)
@@ -1,60 +1,30 @@
-/*
- * Copyright (c) 1983, 1993
- *     The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getservbyport.c    8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
 #include <netdb.h>
-#include <string.h>
 
-extern int _serv_stayopen;
 
-struct servent *
-getservbyport(port, proto)
-       int port;
-       const char *proto;
-{
-       register struct servent *p;
+#define LOOKUP_TYPE    struct servent
+#define FUNCTION_NAME  getservbyport
+#define DATABASE_NAME  services
+#define ADD_PARAMS     int port, const char *proto
+#define ADD_VARIABLES  port, proto
+#define BUFLEN         1024
 
-       setservent(_serv_stayopen);
-       while (p = getservent()) {
-               if (p->s_port != port)
-                       continue;
-               if (proto == 0 || strcmp(p->s_proto, proto) == 0)
-                       break;
-       }
-       if (!_serv_stayopen)
-               endservent();
-       return (p);
-}
+#include "../nss/getXXbyYY.c"
diff --git a/inet/getsrvbypt_r.c b/inet/getsrvbypt_r.c
new file mode 100644 (file)
index 0000000..58851ef
--- /dev/null
@@ -0,0 +1,29 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <netdb.h>
+
+
+#define LOOKUP_TYPE    struct servent
+#define FUNCTION_NAME  getservbyport
+#define DATABASE_NAME  services
+#define ADD_PARAMS     int port, const char *proto
+#define ADD_VARIABLES  port, proto
+
+#include "../nss/getXXbyYY_r.c"
diff --git a/inet/herrno.c b/inet/herrno.c
new file mode 100644 (file)
index 0000000..7e413ad
--- /dev/null
@@ -0,0 +1,22 @@
+/* Copyright (C) 1996 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+/* We need to have the error status variable of the resolver
+   accessible in the libc.  */
+int h_errno;
+
diff --git a/nss/Makefile b/nss/Makefile
new file mode 100644 (file)
index 0000000..91c4ef7
--- /dev/null
@@ -0,0 +1,57 @@
+# Copyright (C) 1996 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 Library General Public License as
+# published by the Free Software Foundation; either version 2 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
+# Library General Public License for more details.
+
+# You should have received a copy of the GNU Library General Public
+# License along with the GNU C Library; see the file COPYING.LIB.  If
+# not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+#
+#      Makefile for name service switch.
+#
+subdir := nss
+
+distribute             := nsswitch.h XXX-lookup.c getXXbyYY.c getXXbyYY_r.c \
+                          getXXent.c getXXent_r.c
+
+# This is the trivial part which goes into libc itself.
+routines               := nsswitch \
+                          $(addsuffix -lookup,proto service host network \
+                                              grp pwd rpc)
+
+
+# Specify rules for the nss_* modules.  We have some services.
+services               := files dns
+
+extra-libs             = $(services:%=libnss_%)
+
+# The sources are found in the appropriate subdir.
+subdir-dirs = nss_files nss_dns
+vpath %.c $(subdir-dirs)
+
+
+libnss_files-routines  := files-proto files-service files-network \
+                          files-hosts files-grp files-pwd files-rpc
+distribute             += files-XXX.c files-parse.c
+
+libnss_dns-routines    := dns-host dns-network
+
+libnss_files-inhibit-o = $(filter-out .so,$(object-suffixes))
+libnss_dns-inhibit-o   = $(filter-out .so,$(object-suffixes))
+
+
+include ../Rules
+
+
+resobjdir := $(firstword $(objdir) $(patsubst ../$(subdir),.,$(..)resolv))
+LDLIBS-nss_dns.so = -L$(resobjdir) -Wl,-rpath-link=$(resobjdir) -lresolv
diff --git a/nss/XXX-lookup.c b/nss/XXX-lookup.c
new file mode 100644 (file)
index 0000000..1f8cbbf
--- /dev/null
@@ -0,0 +1,51 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include "nsswitch.h"
+
+/*******************************************************************\
+|* Here we assume one symbol to be defined:                       *|
+|*                                                                *|
+|* DATABASE_NAME - name of the database the function accesses     *|
+|*                (e.g., hosts, servicess, ...)                   *|
+|*                                                                *|
+\*******************************************************************/
+
+#define DB_LOOKUP_FCT CONCAT3_1 (__nss_, DATABASE_NAME, _lookup)
+#define CONCAT3_1(Pre, Name, Post) CONCAT3_2 (Pre, Name, Post)
+#define CONCAT3_2(Pre, Name, Post) Pre##Name##Post
+
+#define DATABASE_NAME_STRING STRINGIFY1 (DATABASE_NAME)
+#define STRINGIFY1(Name) STRINGIFY2 (Name)
+#define STRINGIFY2(Name) #Name
+
+
+static service_user *database = NULL;
+
+int
+DB_LOOKUP_FCT (service_user **ni, const char *fct_name, void **fctp)
+{
+  if (database == NULL
+      && __nss_database_lookup (DATABASE_NAME_STRING, &database) < 0)
+    return -1;
+
+  *ni = database;
+
+  return __nss_lookup (ni, fct_name, fctp);
+}
diff --git a/nss/file-lookup.c b/nss/file-lookup.c
new file mode 100644 (file)
index 0000000..d9f7c67
--- /dev/null
@@ -0,0 +1,22 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#define DATABASE_NAME hosts
+
+#include "XXX-lookup.c"
diff --git a/nss/getXXbyYY.c b/nss/getXXbyYY.c
new file mode 100644 (file)
index 0000000..5eb9ee9
--- /dev/null
@@ -0,0 +1,71 @@
+/* Copyright (C) 1996 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include "../nss/nsswitch.h"
+
+/*******************************************************************\
+|* Here we assume several symbols to be defined:                  *|
+|*                                                                *|
+|* LOOKUP_TYPE   - the return type of the function                *|
+|*                                                                *|
+|* FUNCTION_NAME - name of the non-reentrant function             *|
+|*                                                                *|
+|* DATABASE_NAME - name of the database the function accesses     *|
+|*                (e.g., host, services, ...)                     *|
+|*                                                                *|
+|* ADD_PARAMS    - additional parameter, can vary in number       *|
+|*                                                                *|
+|* ADD_VARIABLES - names of additional parameter                  *|
+|*                                                                *|
+|* BUFLEN       - length of buffer allocated for the non          *|
+|*                reentrant version                               *|
+|*                                                                *|
+|* Optionally the following vars can be defined:                  *|
+|*                                                                *|
+|* NEED_H_ERRNO  - an extra parameter will be passed to point to   *|
+|*                the global `h_errno' variable.                  *|
+|*                                                                *|
+\*******************************************************************/
+
+/* To make the real sources a bit prettier.  */
+#define REENTRANT_NAME APPEND_R (FUNCTION_NAME)
+#define APPEND_R(name) APPEND_R1 (name)
+#define APPEND_R1(name) name##_r
+
+/* Sometimes we need to store error codes in the `h_errno' variable.  */
+#ifdef NEED_H_ERRNO
+# define H_ERRNO_PARM , int *h_errnop
+# define H_ERRNO_VAR , &h_errno
+#else
+# define H_ERRNO_PARM
+# define H_ERRNO_VAR
+#endif
+
+
+/* Prototype for reentrant version we use here.  */
+extern LOOKUP_TYPE *REENTRANT_NAME (ADD_PARAMS, LOOKUP_TYPE *result,
+                                   char *buffer, int buflen H_ERRNO_PARM);
+
+LOOKUP_TYPE *
+FUNCTION_NAME (ADD_PARAMS)
+{
+  static LOOKUP_TYPE result;
+  static char buffer[BUFLEN];
+
+  return REENTRANT_NAME (ADD_VARIABLES, &result, buffer, BUFLEN H_ERRNO_VAR);
+}
diff --git a/nss/getXXbyYY_r.c b/nss/getXXbyYY_r.c
new file mode 100644 (file)
index 0000000..4209236
--- /dev/null
@@ -0,0 +1,129 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include "nsswitch.h"
+
+/*******************************************************************\
+|* Here we assume several symbols to be defined:                  *|
+|*                                                                *|
+|* LOOKUP_TYPE   - the return type of the function                *|
+|*                                                                *|
+|* FUNCTION_NAME - name of the non-reentrant function             *|
+|*                                                                *|
+|* DATABASE_NAME - name of the database the function accesses     *|
+|*                (e.g., host, services, ...)                     *|
+|*                                                                *|
+|* ADD_PARAMS    - additional parameter, can vary in number       *|
+|*                                                                *|
+|* ADD_VARIABLES - names of additional parameter                  *|
+|*                                                                *|
+|* Optionally the following vars can be defined:                  *|
+|*                                                                *|
+|* NEED_H_ERRNO  - an extra parameter will be passed to point to   *|
+|*                the global `h_errno' variable.                  *|
+|*                                                                *|
+|* NEED__RES     - the global _res variable might be used so we           *|
+|*                will have to initialize it if necessary         *|
+|*                                                                *|
+\*******************************************************************/
+
+/* To make the real sources a bit prettier.  */
+#define REENTRANT_NAME APPEND_R (FUNCTION_NAME)
+#define APPEND_R(name) APPEND_R1 (name)
+#define APPEND_R1(name) name##_r
+
+#define FUNCTION_NAME_STRING STRINGIZE (FUNCTION_NAME)
+#define REENTRANT_NAME_STRING STRINGIZE (REENTRANT_NAME)
+#define DATABASE_NAME_STRING STRINGIZE (DATABASE_NAME)
+#define STRINGIZE(name) STRINGIZE1 (name)
+#define STRINGIZE1(name) #name
+
+#define DB_LOOKUP_FCT CONCAT3_1 (__nss_, DATABASE_NAME, _lookup)
+#define CONCAT3_1(Pre, Name, Post) CONCAT3_2 (Pre, Name, Post)
+#define CONCAT3_2(Pre, Name, Post) Pre##Name##Post
+
+/* Sometimes we need to store error codes in the `h_errno' variable.  */
+#ifdef NEED_H_ERRNO
+# define H_ERRNO_PARM , int *h_errnop
+# define H_ERRNO_VAR , h_errnop
+#else
+# define H_ERRNO_PARM
+# define H_ERRNO_VAR
+#endif
+
+
+/* Type of the lookup function we need here.  */
+typedef int (*lookup_function) (ADD_PARAMS, LOOKUP_TYPE *, char *, int
+                               H_ERRNO_PARM);
+
+/* Some usages of this file might use this variable.  */
+extern struct __res_state _res;
+
+/* The lookup function for the first entry of this service.  */
+extern int DB_LOOKUP_FCT (service_user **nip, const char *name, void **fctp);
+
+
+
+LOOKUP_TYPE *
+REENTRANT_NAME (ADD_PARAMS, LOOKUP_TYPE *result, char *buffer, int buflen
+               H_ERRNO_PARM)
+{
+  static service_user *startp = NULL;
+  static lookup_function start_fct;
+  service_user *nip;
+  lookup_function fct;
+  int no_more;
+  enum nss_status status = NSS_STATUS_UNAVAIL;
+
+  if (startp == NULL)
+    {
+      no_more = DB_LOOKUP_FCT (&nip, REENTRANT_NAME_STRING, (void **) &fct);
+      if (no_more)
+       startp = (service_user *) -1;
+      else
+       {
+         startp = nip;
+         start_fct = fct;
+
+#ifdef NEED__RES
+         /* The resolver code will really be used so we have to
+            initialize it.  */
+         if ((_res.options & RES_INIT) == 0 && res_init () == -1)
+           {
+             h_errno = NETDB_INTERNAL;
+             return NULL;
+           }
+#endif /* need _res */
+       }
+    }
+  else
+    {
+      fct = start_fct;
+      no_more = (nip = startp) == (service_user *) -1;
+    }
+
+  while (no_more == 0)
+    {
+      status = (*fct) (ADD_VARIABLES, result, buffer, buflen H_ERRNO_VAR);
+
+      no_more = __nss_next (&nip, REENTRANT_NAME_STRING, &fct, status, 0);
+    }
+
+  return status == NSS_STATUS_SUCCESS ? result : NULL;
+}
diff --git a/nss/getXXent.c b/nss/getXXent.c
new file mode 100644 (file)
index 0000000..da3712c
--- /dev/null
@@ -0,0 +1,63 @@
+/* Copyright (C) 1996 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include "nsswitch.h"
+
+/*******************************************************************\
+|* Here we assume several symbols to be defined:                  *|
+|*                                                                *|
+|* LOOKUP_TYPE   - the return type of the function                *|
+|*                                                                *|
+|* GETFUNC_NAME  - name of the non-reentrant getXXXent function           *|
+|*                                                                *|
+|* BUFLEN       - size of static buffer                           *|
+|*                                                                *|
+|* Optionally the following vars can be defined:                  *|
+|*                                                                *|
+|* NEED_H_ERRNO  - an extra parameter will be passed to point to   *|
+|*                the global `h_errno' variable.                  *|
+|*                                                                *|
+\*******************************************************************/
+
+/* To make the real sources a bit prettier.  */
+#define REENTRANT_GETNAME APPEND_R (GETFUNC_NAME)
+#define APPEND_R(name) APPEND_R1 (name)
+#define APPEND_R1(name) name##_r
+
+/* Sometimes we need to store error codes in the `h_errno' variable.  */
+#ifdef NEED_H_ERRNO
+# define H_ERRNO_PARM , int *h_errnop
+# define H_ERRNO_VAR , &h_errno
+#else
+# define H_ERRNO_PARM
+# define H_ERRNO_VAR
+#endif
+
+/* Prototype of the reentrant version.  */
+LOOKUP_TYPE *REENTRANT_GETNAME (LOOKUP_TYPE *result, char *buffer,
+                               int buflen H_ERRNO_PARM);
+
+
+LOOKUP_TYPE *
+GETFUNC_NAME (void)
+{
+  static char buffer[BUFLEN];
+  LOOKUP_TYPE result;
+
+  return REENTRANT_GETNAME (&result, buffer, BUFLEN H_ERRNO_VAR);
+}
diff --git a/nss/getXXent_r.c b/nss/getXXent_r.c
new file mode 100644 (file)
index 0000000..3d1e959
--- /dev/null
@@ -0,0 +1,222 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <libc-lock.h>
+
+#include "nsswitch.h"
+
+/*******************************************************************\
+|* Here we assume several symbols to be defined:                  *|
+|*                                                                *|
+|* LOOKUP_TYPE   - the return type of the function                *|
+|*                                                                *|
+|* SETFUNC_NAME  - name of the non-reentrant setXXXent function           *|
+|*                                                                *|
+|* GETFUNC_NAME  - name of the non-reentrant getXXXent function           *|
+|*                                                                *|
+|* ENDFUNC_NAME  - name of the non-reentrant endXXXent function           *|
+|*                                                                *|
+|* DATABASE_NAME - name of the database the function accesses     *|
+|*                (e.g., host, services, ...)                     *|
+|*                                                                *|
+|* Optionally the following vars can be defined:                  *|
+|*                                                                *|
+|* STAYOPEN      - variable declaration for setXXXent function    *|
+|*                                                                *|
+|* STAYOPEN_VAR  - variable name for setXXXent function                   *|
+|*                                                                *|
+|* NEED_H_ERRNO  - an extra parameter will be passed to point to   *|
+|*                the global `h_errno' variable.                  *|
+|*                                                                *|
+\*******************************************************************/
+
+/* To make the real sources a bit prettier.  */
+#define REENTRANT_GETNAME APPEND_R (GETFUNC_NAME)
+#define APPEND_R(name) APPEND_R1 (name)
+#define APPEND_R1(name) name##_r
+
+#define SETFUNC_NAME_STRING STRINGIZE (SETFUNC_NAME)
+#define GETFUNC_NAME_STRING STRINGIZE (GETFUNC_NAME)
+#define ENDFUNC_NAME_STRING STRINGIZE (ENDFUNC_NAME)
+#define DATABASE_NAME_STRING STRINGIZE (DATABASE_NAME)
+#define STRINGIZE(name) STRINGIZE1 (name)
+#define STRINGIZE1(name) #name
+
+#define DB_LOOKUP_FCT CONCAT3_1 (__nss_, DATABASE_NAME, _lookup)
+#define CONCAT3_1(Pre, Name, Post) CONCAT3_2 (Pre, Name, Post)
+#define CONCAT3_2(Pre, Name, Post) Pre##Name##Post
+
+/* Sometimes we need to store error codes in the `h_errno' variable.  */
+#ifdef NEED_H_ERRNO
+# define H_ERRNO_PARM , int *h_errnop
+# define H_ERRNO_VAR , &h_errno
+#else
+# define H_ERRNO_PARM
+# define H_ERRNO_VAR
+#endif
+
+/* Some databases take the `stayopen' flag.  */
+#ifndef STAYOPEN
+#define STAYOPEN void
+#define STAYOPEN_VAR
+#endif
+
+/* Prototype for the setXXXent functions we use here.  */
+typedef int (*set_function) (STAYOPEN);
+
+/* Prototype for the endXXXent functions we use here.  */
+typedef int (*end_function) (void);
+
+/* Prototype for the setXXXent functions we use here.  */
+typedef int (*get_function) (LOOKUP_TYPE *, char *, int H_ERRNO_PARM);
+
+
+/* This handle for the NSS data base is shared between all
+   set/get/endXXXent functions.  */
+static service_user *nip;
+/* Remember the first service_entry, it's always the same.  */
+static service_user *startp;
+
+/* Protect above variable against multiple uses at the same time.  */
+__libc_lock_define_initialized (static, lock);
+
+/* The lookup function for the first entry of this service.  */
+extern int DB_LOOKUP_FCT (service_user **nip, const char *name, void **fctp);
+
+
+void
+APPEND_R (SETFUNC_NAME) (STAYOPEN)
+{
+  set_function fct;
+  int no_more;
+
+#ifdef NEED__RES
+  if ((_res.options & RES_INIT) == 0 && res_init () == -1)
+    {
+      h_errno = NETDB_INTERNAL;
+      return NULL;
+    }
+#endif /* need _res */
+
+  __libc_lock_lock (lock);
+
+  if (startp == NULL)
+    {
+      no_more = DB_LOOKUP_FCT (&nip, SETFUNC_NAME_STRING, (void **) &fct);
+      startp = no_more == 0 ? (service_user *) -1 : nip;
+    }
+  else
+    no_more = (nip = startp) != (service_user *) -1;
+
+  /* Cycle through all the services and run their setXXent functions.  */
+  while (! no_more)
+    {
+      /* Ignore status, we force check in __NSS_NEXT.  */
+      (void) (*fct) (STAYOPEN_VAR);
+
+      no_more = __nss_next (&nip, SETFUNC_NAME_STRING, (void **) &fct, 0, 1);
+    }
+
+  __libc_lock_unlock (lock);
+}
+
+
+void
+APPEND_R (ENDFUNC_NAME) (void)
+{
+  end_function fct;
+  int no_more;
+
+#ifdef NEED__RES
+  if ((_res.options & RES_INIT) == 0 && res_init () == -1)
+    {
+      h_errno = NETDB_INTERNAL;
+      return NULL;
+    }
+#endif /* need _res */
+
+  __libc_lock_lock (lock);
+
+  if (startp == NULL)
+    {
+      no_more = DB_LOOKUP_FCT (&nip, SETFUNC_NAME_STRING, (void **) &fct);
+      startp = no_more == 0 ? (service_user *) -1 : nip;
+    }
+  else
+    no_more = (nip = startp) != (service_user *) -1;
+
+  /* Cycle through all the services and run their endXXent functions.  */
+  while (no_more == 0)
+    {
+      /* Ignore status, we force check in __NSS_NEXT.  */
+      (void) (*fct) ();
+
+      no_more = __nss_next (&nip, ENDFUNC_NAME_STRING, (void **) &fct, 0, 1);
+    }
+
+  __libc_lock_unlock (lock);
+}
+
+
+LOOKUP_TYPE *
+REENTRANT_GETNAME (LOOKUP_TYPE *result, char *buffer, int buflen H_ERRNO_PARM)
+{
+  get_function fct;
+  int no_more;
+  enum nss_status status = NSS_STATUS_NOTFOUND;
+
+#ifdef NEED__RES
+  if ((_res.options & RES_INIT) == 0 && res_init () == -1)
+    {
+      h_errno = NETDB_INTERNAL;
+      return NULL;
+    }
+#endif /* need _res */
+
+  __libc_lock_lock (lock);
+
+  if (nip)
+    /* Continuing a walk-through started before.  */
+    no_more = 0;
+  else
+    {
+      if (startp == NULL)
+       {
+         no_more = DB_LOOKUP_FCT (&nip, SETFUNC_NAME_STRING, (void **) &fct);
+         startp = no_more == 0 ? (service_user *) -1 : nip;
+       }
+      else
+       no_more = (nip = startp) != (service_user *) -1;
+
+      if (no_more != 0)
+       status = NSS_STATUS_UNAVAIL;
+    }
+
+  while (no_more == 0)
+    {
+      status = (*fct) (result, buffer, buflen H_ERRNO_VAR);
+
+      no_more = __nss_next (&nip, GETFUNC_NAME_STRING, (void **) &fct,
+                           status, 0);
+    }
+
+  __libc_lock_unlock (lock);
+
+  return status == NSS_STATUS_SUCCESS ? result : NULL;
+}
diff --git a/nss/grp-lookup.c b/nss/grp-lookup.c
new file mode 100644 (file)
index 0000000..ce3753c
--- /dev/null
@@ -0,0 +1,22 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#define DATABASE_NAME group
+
+#include "XXX-lookup.c"
diff --git a/nss/host-lookup.c b/nss/host-lookup.c
new file mode 100644 (file)
index 0000000..d9f7c67
--- /dev/null
@@ -0,0 +1,22 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#define DATABASE_NAME hosts
+
+#include "XXX-lookup.c"
diff --git a/nss/network-lookup.c b/nss/network-lookup.c
new file mode 100644 (file)
index 0000000..ab6e51f
--- /dev/null
@@ -0,0 +1,22 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#define DATABASE_NAME networks
+
+#include "XXX-lookup.c"
diff --git a/nss/nss_dns/dns-host.c b/nss/nss_dns/dns-host.c
new file mode 100644 (file)
index 0000000..eaa9e81
--- /dev/null
@@ -0,0 +1,611 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Extended from original form by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+/* Parts of this file are plain copies of the file `getnetnamadr.c' from
+   the bind package and it has the following copyright.  */
+
+/* Copyright (c) 1993 Carlos Leandro and Rui Salgueiro
+ *      Dep. Matematica Universidade de Coimbra, Portugal, Europe
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ */
+/*
+ * Copyright (c) 1983, 1993
+ *      The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed by the University of
+ *      California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <ctype.h>
+#include <errno.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <string.h>
+#include <sys/syslog.h>
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <resolv.h>
+
+#include "nsswitch.h"
+
+/* Get implementation for some internal functions.  */
+#include "../resolv/mapv4v6addr.h"
+#include "../resolv/mapv4v6hostent.h"
+
+/* Maximum number of aliases we allow.  */
+#define MAX_NR_ALIASES 48
+#define MAX_NR_ADDRS   48
+
+#if PACKETSZ > 1024
+# define MAXPACKET     PACKETSZ
+#else
+# define MAXPACKET     1024
+#endif
+
+static const char AskedForGot[] = "\
+gethostby*.getanswer: asked for \"%s\", got \"%s\"";
+
+
+/* We need this time later.  */
+typedef union querybuf
+{
+  HEADER hdr;
+  u_char buf[MAXPACKET];
+} querybuf;
+
+
+static enum nss_status getanswer_r (const querybuf *answer, int anslen,
+                                   const char *qname, int qtype,
+                                   struct hostent *result,
+                                   char *buffer, int buflen, int *h_errnop);
+
+enum nss_status
+_nss_dns_gethostbyname2_r (const char *name, int af, struct hostent *result,
+                          char *buffer, int buflen, int *h_errnop)
+{
+  struct host_data
+  {
+    char *aliases[MAX_NR_ALIASES];
+    unsigned char host_addr[16];       /* IPv4 or IPv6 */
+    char *h_addr_ptrs[MAX_NR_ADDRS + 1];
+    char linebuffer[0];
+  } *host_data = (struct host_data *) buffer;
+  int linebuflen = buflen - offsetof (struct host_data, linebuffer);
+  querybuf host_buffer;
+  int size, type, n;
+  const char *cp;
+
+  switch (af) {
+  case AF_INET:
+    size = INADDRSZ;
+    type = T_A;
+    break;
+  case AF_INET6:
+    size = IN6ADDRSZ;
+    type = T_AAAA;
+    break;
+  default:
+    *h_errnop = NETDB_INTERNAL;
+    errno = EAFNOSUPPORT;
+    return NSS_STATUS_UNAVAIL;
+  }
+
+  result->h_addrtype = af;
+  result->h_length = size;
+
+  /*
+   * if there aren't any dots, it could be a user-level alias.
+   * this is also done in res_query() since we are not the only
+   * function that looks up host names.
+   */
+  if (strchr (name, '.') == NULL && (cp = __hostalias (name)) != NULL)
+    name = cp;
+
+  /*
+   * disallow names consisting only of digits/dots, unless
+   * they end in a dot.
+   */
+  if (isdigit (name[0]))
+    for (cp = name;; ++cp)
+      {
+       if (*cp == '\0')
+         {
+           char *bp;
+
+           if (*--cp == '.')
+             break;
+           /*
+            * All-numeric, no dot at the end.  Fake up a hostent
+            * as if we'd actually done a lookup.
+            */
+           if (inet_pton (af, name, host_data->host_addr) <= 0)
+             {
+               *h_errnop = HOST_NOT_FOUND;
+               return NSS_STATUS_NOTFOUND;
+             }
+
+           bp = __stpncpy (host_data->linebuffer, name, linebuflen);
+           host_data->linebuffer[linebuflen - 1] = '\0';
+           linebuflen -= bp - host_data->linebuffer;
+
+           result->h_name = host_data->linebuffer;
+           result->h_aliases = host_data->aliases;
+           host_data->aliases[0] = NULL;
+           host_data->h_addr_ptrs[0] = (char *) host_data->host_addr;
+           host_data->h_addr_ptrs[1] = NULL;
+           result->h_addr_list = host_data->h_addr_ptrs;
+
+           if (_res.options & RES_USE_INET6)
+             map_v4v6_hostent (result, &bp, &linebuflen);
+           *h_errnop = NETDB_SUCCESS;
+           return NSS_STATUS_SUCCESS;
+         }
+       if (!isdigit (*cp) && *cp != '.')
+         break;
+      }
+
+  n = res_search (name, C_IN, type, host_buffer.buf, sizeof (host_buffer));
+  if (n < 0)
+    return errno == ECONNREFUSED ? NSS_STATUS_UNAVAIL : NSS_STATUS_NOTFOUND;
+
+  return getanswer_r (&host_buffer, n, name, type, result, buffer, buflen,
+                     h_errnop);
+}
+
+
+enum nss_status
+_nss_dns_gethostbyname_r (const char *name, struct hostent *result,
+                         char *buffer, int buflen, int *h_errnop)
+{
+  enum nss_status status = NSS_STATUS_NOTFOUND;
+
+  if (_res.options & RES_USE_INET6)
+    status = _nss_dns_gethostbyname2_r (name, AF_INET6, result, buffer,
+                                       buflen, h_errnop);
+  if (status == NSS_STATUS_NOTFOUND)
+    status = _nss_dns_gethostbyname2_r (name, AF_INET, result, buffer,
+                                       buflen, h_errnop);
+
+  return status;
+}
+
+
+enum nss_status
+_nss_dns_gethostbyaddr_r (const char *addr, int len, int af,
+                         struct hostent *result, char *buffer, int buflen,
+                         int *h_errnop)
+{
+  static const u_char mapped[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0xff,0xff };
+  static const u_char tunnelled[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 };
+  const u_char *uaddr = (const u_char *)addr;
+  struct host_data
+  {
+    char *aliases[MAX_NR_ALIASES];
+    unsigned char host_addr[16];       /* IPv4 or IPv6 */
+    char *h_addr_ptrs[MAX_NR_ADDRS + 1];
+    char linebuffer[0];
+  } *host_data = (struct host_data *) buffer;
+  querybuf host_buffer;
+  char qbuf[MAXDNAME+1], *qp;
+  int size, n, status;
+
+  if (af == AF_INET6 && len == IN6ADDRSZ &&
+      (bcmp (uaddr, mapped, sizeof mapped) == 0
+       || bcmp (uaddr, tunnelled, sizeof tunnelled) == 0))
+    {
+      /* Unmap. */
+      addr += sizeof mapped;
+      uaddr += sizeof mapped;
+      af = AF_INET;
+      len = INADDRSZ;
+    }
+
+  switch (af)
+    {
+    case AF_INET:
+      size = INADDRSZ;
+      break;
+    case AF_INET6:
+      size = IN6ADDRSZ;
+      break;
+    default:
+      errno = EAFNOSUPPORT;
+      *h_errnop = NETDB_INTERNAL;
+      return NSS_STATUS_UNAVAIL;
+    }
+  if (size != len)
+    {
+      errno = EAFNOSUPPORT;
+      *h_errnop = NETDB_INTERNAL;
+      return NSS_STATUS_UNAVAIL;
+    }
+
+  switch (af)
+    {
+    case AF_INET:
+      sprintf (qbuf, "%u.%u.%u.%u.in-addr.arpa", (uaddr[3] & 0xff),
+              (uaddr[2] & 0xff), (uaddr[1] & 0xff), (uaddr[0] & 0xff));
+      break;
+    case AF_INET6:
+      qp = qbuf;
+      for (n = IN6ADDRSZ - 1; n >= 0; n--)
+       qp += sprintf (qp, "%x.%x.", uaddr[n] & 0xf, (uaddr[n] >> 4) & 0xf);
+      strcpy(qp, "ip6.int");
+      break;
+    default:
+      /* Cannot happen.  */
+    }
+
+  n = res_query (qbuf, C_IN, T_PTR, (u_char *)host_buffer.buf,
+                sizeof host_buffer);
+  if (n < 0)
+    return errno == ECONNREFUSED ? NSS_STATUS_UNAVAIL : NSS_STATUS_NOTFOUND;
+
+  status = getanswer_r (&host_buffer, n, qbuf, T_PTR, result, buffer, buflen,
+                       h_errnop);
+  if (status != NSS_STATUS_SUCCESS)
+    return status;
+
+#ifdef SUNSECURITY
+  This is not implemented because it is not possible to use the current
+  source from bind in a multi-threaded program.
+#endif
+
+  result->h_addrtype = af;
+  result->h_length = len;
+  bcopy (addr, host_data->host_addr, len);
+  host_data->h_addr_ptrs[0] = (char *) host_data->host_addr;
+  host_data->h_addr_ptrs[1] = NULL;
+  if (af == AF_INET && (_res.options & RES_USE_INET6))
+    {
+      map_v4v6_address ((char *) host_data->host_addr,
+                       (char *) host_data->host_addr);
+      result->h_addrtype = AF_INET6;
+      result->h_length = IN6ADDRSZ;
+    }
+  *h_errnop = NETDB_SUCCESS;
+  return NSS_STATUS_SUCCESS;
+}
+
+
+static enum nss_status
+getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
+            struct hostent *result, char *buffer, int buflen, int *h_errnop)
+{
+  struct host_data
+  {
+    char *aliases[MAX_NR_ALIASES];
+    unsigned char host_addr[16];       /* IPv4 or IPv6 */
+    char *h_addr_ptrs[MAX_NR_ADDRS + 1];
+    char linebuffer[0];
+  } *host_data = (struct host_data *) buffer;
+  int linebuflen = buflen - offsetof (struct host_data, linebuffer);
+  register const HEADER *hp;
+  const u_char *end_of_message, *cp;
+  int n, ancount, qdcount;
+  int haveanswer, had_error;
+  char *bp, **ap, **hap;
+  char tbuf[MAXDNAME+1];
+  const char *tname;
+  int (*name_ok) __P ((const char *));
+
+  tname = qname;
+  result->h_name = NULL;
+  end_of_message = answer->buf + anslen;
+  switch (qtype)
+    {
+    case T_A:
+    case T_AAAA:
+      name_ok = res_hnok;
+      break;
+    case T_PTR:
+      name_ok = res_dnok;
+      break;
+    default:
+      return NSS_STATUS_UNAVAIL;  /* XXX should be abort(); */
+    }
+
+  /*
+   * find first satisfactory answer
+   */
+  hp = &answer->hdr;
+  bp = host_data->linebuffer;
+  ancount = ntohs (hp->ancount);
+  qdcount = ntohs (hp->qdcount);
+  cp = answer->buf + HFIXEDSZ;
+  if (qdcount != 1)
+    {
+      *h_errnop = NO_RECOVERY;
+      return NSS_STATUS_UNAVAIL;
+    }
+
+  n = dn_expand (answer->buf, end_of_message, cp, bp, linebuflen);
+  if (n < 0 || (*name_ok) (bp) == 0)
+    {
+      *h_errnop = NO_RECOVERY;
+      return NSS_STATUS_UNAVAIL;
+    }
+  cp += n + QFIXEDSZ;
+
+  if (qtype == T_A || qtype == T_AAAA)
+    {
+      /* res_send() has already verified that the query name is the
+       * same as the one we sent; this just gets the expanded name
+       * (i.e., with the succeeding search-domain tacked on).
+       */
+      n = strlen (bp) + 1;             /* for the \0 */
+      result->h_name = bp;
+      bp += n;
+      linebuflen -= n;
+      /* The qname can be abbreviated, but h_name is now absolute. */
+      qname = result->h_name;
+    }
+
+  ap = host_data->aliases;
+  *ap = NULL;
+  result->h_aliases = host_data->aliases;
+  hap = host_data->h_addr_ptrs;
+  *hap = NULL;
+  result->h_addr_list = host_data->h_addr_ptrs;
+  haveanswer = 0;
+  had_error = 0;
+
+  while (ancount-- > 0 && cp < end_of_message && had_error == 0)
+    {
+      int type, class;
+
+      n = dn_expand (answer->buf, end_of_message, cp, bp, linebuflen);
+      if (n < 0 || (*name_ok) (bp) == 0)
+       {
+         ++had_error;
+         continue;
+       }
+      cp += n;                         /* name */
+      type = _getshort (cp);
+      cp += INT16SZ;                   /* type */
+      class = _getshort(cp);
+      cp += INT16SZ + INT32SZ;         /* class, TTL */
+      n = _getshort(cp);
+      cp += INT16SZ;                   /* len */
+      if (class != C_IN)
+       {
+         /* XXX - debug? syslog? */
+         cp += n;
+         continue;                     /* XXX - had_error++ ? */
+       }
+
+      if ((qtype ==T_A || qtype == T_AAAA) && type == T_CNAME)
+       {
+         if (ap >= &host_data->aliases[MAX_NR_ALIASES - 1])
+           continue;
+         n = dn_expand (answer->buf, end_of_message, cp, tbuf, sizeof tbuf);
+         if (n < 0 || (*name_ok) (tbuf) == 0)
+           {
+             ++had_error;
+             continue;
+           }
+         cp += n;
+         /* Store alias.  */
+         *ap++ = bp;
+         n = strlen (bp) + 1;          /* For the \0.  */
+         bp += n;
+         linebuflen -= n;
+         /* Get canonical name.  */
+         n = strlen (tbuf) + 1;        /* For the \0.  */
+         if (n > buflen)
+           {
+             ++had_error;
+             continue;
+           }
+         strcpy (bp, tbuf);
+         result->h_name = bp;
+         bp += n;
+         linebuflen -= n;
+         continue;
+       }
+
+      if (qtype == T_PTR && type == T_CNAME)
+       {
+         n = dn_expand (answer->buf, end_of_message, cp, tbuf, sizeof tbuf);
+         if (n < 0 || res_hnok (tbuf) == 0)
+           {
+             ++had_error;
+             continue;
+           }
+         cp += n;
+         /* Get canonical name. */
+         n = strlen (tbuf) + 1;   /* For the \0.  */
+         if (n > buflen)
+           {
+             ++had_error;
+             continue;
+           }
+         strcpy (bp, tbuf);
+         tname = bp;
+         bp += n;
+         linebuflen -= n;
+         continue;
+       }
+      if (type != qtype)
+       {
+         syslog (LOG_NOTICE | LOG_AUTH,
+              "gethostby*.getanswer: asked for \"%s %s %s\", got type \"%s\"",
+                 qname, p_class (C_IN), p_type (qtype), p_type (type));
+         cp += n;
+         continue;                     /* XXX - had_error++ ? */
+       }
+
+      switch (type)
+       {
+       case T_PTR:
+         if (strcasecmp (tname, bp) != 0)
+           {
+             syslog (LOG_NOTICE | LOG_AUTH, AskedForGot, qname, bp);
+             cp += n;
+             continue;                 /* XXX - had_error++ ? */
+           }
+         n = dn_expand (answer->buf, end_of_message, cp, bp, linebuflen);
+         if (n < 0 || res_hnok (bp) == 0)
+           {
+             ++had_error;
+             break;
+           }
+#if MULTI_PTRS_ARE_ALIASES
+         cp += n;
+         if (haveanswer == 0)
+           result->h_name = bp;
+         else if (ap < &host_data->aliases[MAXALIASES-1])
+           *ap++ = bp;
+         else
+           n = -1;
+         if (n != -1)
+           {
+             n = strlen (bp) + 1;      /* for the \0 */
+             bp += n;
+             linebuflen -= n;
+           }
+         break;
+#else
+         result->h_name = bp;
+         if (_res.options & RES_USE_INET6)
+           {
+             n = strlen (bp) + 1;      /* for the \0 */
+             bp += n;
+             linebuflen -= n;
+             map_v4v6_hostent (result, &bp, &linebuflen);
+           }
+         *h_errnop = NETDB_SUCCESS;
+         return NSS_STATUS_SUCCESS;
+#endif
+       case T_A:
+       case T_AAAA:
+         if (strcasecmp (result->h_name, bp) != 0)
+           {
+             syslog (LOG_NOTICE | LOG_AUTH, AskedForGot, result->h_name, bp);
+             cp += n;
+             continue;                 /* XXX - had_error++ ? */
+           }
+         if (haveanswer)
+           {
+             if (n != result->h_length)
+               {
+                 cp += n;
+                 continue;
+               }
+           }
+         else
+           {
+             register int nn;
+
+             result->h_name = bp;
+             nn = strlen (bp) + 1;     /* for the \0 */
+             bp += nn;
+             linebuflen -= nn;
+           }
+
+         bp += sizeof (align) - ((u_long) bp % sizeof (align));
+
+         if (n >= linebuflen)
+           {
+             ++had_error;
+             continue;
+           }
+         if (hap >= &host_data->h_addr_ptrs[MAX_NR_ADDRS-1])
+           {
+             cp += n;
+             continue;
+           }
+         bcopy (cp, *hap++ = bp, n);
+         bp += n;
+         cp += n;
+         linebuflen -= n;
+         break;
+       default:
+         abort ();
+       }
+      if (had_error == 0)
+       ++haveanswer;
+    }
+
+  if (haveanswer > 0)
+    {
+      *ap = NULL;
+      *hap = NULL;
+#if defined(RESOLVSORT)
+      /*
+       * Note: we sort even if host can take only one address
+       * in its return structures - should give it the "best"
+       * address in that case, not some random one
+       */
+      if (_res.nsort && haveanswer > 1 && qtype == T_A)
+       addrsort (host_data->h_addr_ptrs, haveanswer);
+#endif /*RESOLVSORT*/
+
+      if (result->h_name == NULL)
+       {
+         n = strlen (qname) + 1;       /* For the \0.  */
+         if (n > linebuflen)
+           goto try_again;
+         strcpy (bp, qname);
+         result->h_name = bp;
+         bp += n;
+         linebuflen -= n;
+       }
+
+      if (_res.options & RES_USE_INET6)
+       map_v4v6_hostent (result, &bp, &linebuflen);
+      *h_errnop = NETDB_SUCCESS;
+      return NSS_STATUS_SUCCESS;
+    }
+try_again:
+  *h_errnop = TRY_AGAIN;
+  return NSS_STATUS_TRYAGAIN;
+}
diff --git a/nss/nss_dns/dns-network.c b/nss/nss_dns/dns-network.c
new file mode 100644 (file)
index 0000000..b714128
--- /dev/null
@@ -0,0 +1,338 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Extended from original form by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+/* Parts of this file are plain copies of the file `getnetnamadr.c' from
+   the bind package and it has the following copyright.  */
+
+/* Copyright (c) 1993 Carlos Leandro and Rui Salgueiro
+ *      Dep. Matematica Universidade de Coimbra, Portugal, Europe
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ */
+/*
+ * Copyright (c) 1983, 1993
+ *      The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed by the University of
+ *      California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <ctype.h>
+#include <errno.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "nsswitch.h"
+#include <arpa/inet.h>
+
+/* Maximum number of aliases we allow.  */
+#define MAX_NR_ALIASES 48
+
+
+#if PACKETSZ > 1024
+#define MAXPACKET       PACKETSZ
+#else
+#define MAXPACKET       1024
+#endif
+
+
+typedef enum
+{
+  BYADDR,
+  BYNAME
+} lookup_method;
+
+
+/* We need this time later.  */
+typedef union querybuf
+{
+  HEADER hdr;
+  u_char buf[MAXPACKET];
+} querybuf;
+
+
+/* Protortypes for local functions.  */
+static int getanswer_r (const querybuf *answer, int anslen,
+                       struct netent *result, char *buffer, int buflen,
+                       lookup_method net_i);
+
+
+int
+_nss_dns_getnetbyname_r (const char *name, struct netent *result,
+                        char *buffer, int buflen)
+{
+  /* Return entry for network with NAME.  */
+  querybuf net_buffer;
+  int anslen;
+  char *qbuf;
+
+  qbuf = strdupa (name);
+  anslen = res_search (qbuf, C_IN, T_PTR, (u_char *) &net_buffer,
+                      sizeof (querybuf));
+  if (anslen < 0)
+    /* Nothing found.  */
+    return errno == ECONNREFUSED ? NSS_STATUS_UNAVAIL : NSS_STATUS_NOTFOUND;
+
+  return getanswer_r (&net_buffer, anslen, result, buffer, buflen, BYNAME);
+}
+
+
+int
+_nss_dns_getnetbyaddr_r (long net, int type, struct netent *result,
+                        char *buffer, int buflen)
+{
+  /* Return entry for network with NAME.  */
+  int status;
+  querybuf net_buffer;
+  unsigned int net_bytes[4];
+  char qbuf[MAXDNAME];
+  int cnt, anslen;
+  u_int32_t net2;
+
+  /* No net address lookup for IPv6 yet.  */
+  if (type != AF_INET)
+    return NSS_STATUS_UNAVAIL;
+
+  net2 = (u_int32_t) net;
+  for (cnt = 4; net2 != 0; net2 >>= 8)
+    net_bytes[--cnt] = net2 & 0xff;
+
+  switch (cnt)
+    {
+    case 3:
+      /* Class A network.  */
+      sprintf (qbuf, "0.0.0.%u.in-addr.arpa", net_bytes[3]);
+      break;
+    case 2:
+      /* Class B network.  */
+      sprintf (qbuf, "0.0.%u.%u.in-addr.arpa", net_bytes[3], net_bytes[2]);
+      break;
+    case 1:
+      /* Class C network.  */
+      sprintf (qbuf, "0.%u.%u.%u.in-addr.arpa", net_bytes[3], net_bytes[2],
+              net_bytes[1]);
+      break;
+    case 0:
+      /* Class D - E network.  */
+      sprintf (qbuf, "%u.%u.%u.%u.in-addr.arpa", net_bytes[3], net_bytes[2],
+              net_bytes[1], net_bytes[0]);
+      break;
+    }
+
+  anslen = res_query (qbuf, C_IN, T_PTR, (u_char *) &net_buffer,
+                     sizeof (querybuf));
+  if (anslen < 0)
+    /* Nothing found.  */
+    return errno == ECONNREFUSED ? NSS_STATUS_UNAVAIL : NSS_STATUS_NOTFOUND;
+
+  status = getanswer_r (&net_buffer, anslen, result, buffer, buflen, BYADDR);
+  if (status == NSS_STATUS_SUCCESS)
+    {
+      /* Strip trailing zeros.  */
+      unsigned int u_net = net;        /* Maybe net should be unsigned?  */
+
+      while ((u_net & 0xff) == 0 && u_net != 0)
+       u_net >>= 8;
+      result->n_net = u_net;
+    }
+
+  return status;
+}
+
+
+#undef offsetof
+#define offsetof(Type, Member) ((size_t) &((Type *) NULL)->Member)
+
+static int
+getanswer_r (const querybuf *answer, int anslen, struct netent *result,
+            char *buffer, int buflen, lookup_method net_i)
+{
+  /*
+   * Find first satisfactory answer
+   *
+   *      answer --> +------------+  ( MESSAGE )
+   *                 |   Header   |
+   *                 +------------+
+   *                 |  Question  | the question for the name server
+   *                 +------------+
+   *                 |   Answer   | RRs answering the question
+   *                 +------------+
+   *                 | Authority  | RRs pointing toward an authority
+   *                 | Additional | RRs holding additional information
+   *                 +------------+
+   */
+  struct net_data
+  {
+    char *aliases[MAX_NR_ALIASES];
+    char linebuffer[0];
+  } *net_data = (struct net_data *) buffer;
+  int linebuflen = buflen - offsetof (struct net_data, linebuffer);
+  const char *end_of_message = &answer->buf[anslen];
+  const HEADER *header_pointer = &answer->hdr;
+  /* #/records in the answer section.  */
+  int answer_count =  ntohs (header_pointer->ancount);
+  /* #/entries in the question section.  */
+  int question_count = ntohs (header_pointer->qdcount);
+  char *bp = net_data->linebuffer;
+  const char *cp = &answer->buf[HFIXEDSZ];
+  char **alias_pointer;
+  int have_answer;
+  char *ans;
+
+  if (question_count == 0)
+    /* FIXME: the Sun version uses for host name lookup an additional
+       parameter for pointing to h_errno.  this is missing here.
+       OSF/1 has a per-thread h_errno variable.  */
+    if (header_pointer->aa != 0)
+      {
+       h_errno = HOST_NOT_FOUND;
+       return NSS_STATUS_NOTFOUND;
+      }
+    else
+      {
+       h_errno = TRY_AGAIN;
+       return NSS_STATUS_TRYAGAIN;
+      }
+
+  /* Skip the question part.  */
+  while (question_count-- > 0)
+    cp += __dn_skipname (cp, end_of_message) + QFIXEDSZ;
+
+  alias_pointer = result->n_aliases = &net_data->aliases[0];
+  *alias_pointer = NULL;
+  have_answer = 0;
+  ans = NULL;
+
+  while (--answer_count >= 0 && cp < end_of_message)
+    {
+      int n = dn_expand (answer->buf, end_of_message, cp, bp, linebuflen);
+      int type, class;
+
+      if (n < 0 || res_dnok (bp) == 0)
+       break;
+      cp += n;
+      ans = strdupa (bp);
+      GETSHORT (type, cp);
+      GETSHORT (class, cp);
+      cp += INT32SZ;           /* TTL */
+      GETSHORT (n, cp);
+
+      if (class == C_IN && type == T_PTR)
+       {
+         n = dn_expand (answer->buf, end_of_message, cp, bp, linebuflen);
+         if (n < 0 || !res_hnok (bp))
+           {
+             /* XXX What does this mean?  The original form from bind
+                returns NULL. Incrementing cp has no effect in any case.
+                What should I return here. ??? */
+             cp += n;
+             return NSS_STATUS_UNAVAIL;
+           }
+         cp += n;
+         *alias_pointer++ = bp;
+         bp += strlen (bp) + 1;
+         result->n_addrtype = class == C_IN ? AF_INET : AF_UNSPEC;
+         ++have_answer;
+       }
+    }
+
+  if (have_answer)
+    {
+      char *tmp;
+      int len;
+      char *in, *cp, *rp, *wp;
+      int cnt, first_flag;
+
+      *alias_pointer = NULL;
+      switch (net_i)
+       {
+       case BYADDR:
+         result->n_name = result->n_aliases[0];
+         result->n_net = 0L;
+         break;
+       case BYNAME:
+         len = strlen (result->n_aliases[0]);
+         tmp = (char *) alloca (len + 1);
+         tmp[len] = 0;
+         wp = &tmp[len - 1];
+
+         rp = in = result->n_aliases[0];
+         result->n_name = ans;
+
+         first_flag = 1;
+         for (cnt = 0; cnt < 4; ++cnt)
+           {
+             char *startp;
+
+             startp = rp;
+             while (*rp != '.')
+               ++rp;
+             if (rp - startp > 1 || *startp != '0' || !first_flag)
+               {
+                 first_flag = 0;
+                 if (cnt > 0)
+                   *wp-- = '.';
+                 cp = rp;
+                 while (cp > startp)
+                   *wp-- = *--cp;
+               }
+             in = rp + 1;
+           }
+
+         result->n_net = inet_network (wp);
+         break;
+       }
+
+      ++result->n_aliases;
+      return NSS_STATUS_SUCCESS;
+    }
+
+  /* XXX Really use global variable??? */
+  h_errno = TRY_AGAIN;
+  return NSS_STATUS_TRYAGAIN;
+}
diff --git a/nss/nss_files/files-XXX.c b/nss/nss_files/files-XXX.c
new file mode 100644 (file)
index 0000000..40bb7df
--- /dev/null
@@ -0,0 +1,221 @@
+/* Common code for file-based databases in nss_files module.
+Copyright (C) 1996 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA.  */
+
+#include <stdio.h>
+#include <ctype.h>
+#include <assert.h>
+#include <libc-lock.h>
+#include "nsswitch.h"
+
+/* These symbols are defined by the including source file:
+
+   ENTNAME -- database name of the structure and functions (hostent, pwent).
+   STRUCTURE -- struct name, define only if not ENTNAME (passwd, group).
+   DATAFILE -- string of the database file's name.
+
+   NEED_H_ERRNO - defined iff an arg `int *herrnop' is used.
+   MIDLINE_COMMENTS - defined iff # before \n terminates a database line.
+*/
+
+#define ENTNAME_r CONCAT(ENTNAME,_r)
+
+#ifdef NEED_H_ERRNO
+#define H_ERRNO_PROTO  , int *herrnop
+#define H_ERRNO_ARG    , herrnop
+#define H_ERRNO_SET(val) (*herrnop = (val))
+#else
+#define H_ERRNO_PROTO
+#define H_ERRNO_ARG
+#define H_ERRNO_SET(val) ((void) 0)
+#endif
+
+/* Locks the static variables in this file.  */
+__libc_lock_define_initialized (static, lock);
+\f
+/* Maintenance of the shared stream open on the database file.  */
+
+static FILE *stream;
+static int keep_stream;
+
+/* Open database file if not already opened.  */
+static int
+internal_setent (int stayopen)
+{
+  int status = NSS_STATUS_SUCCESS;
+
+  if (stream == NULL)
+    {
+      stream = fopen (DATAFILE, "r");
+
+      if (stream == NULL)
+       status = NSS_STATUS_UNAVAIL;
+    }
+  else
+    rewind (stream);
+
+  /* Remember STAYOPEN flag.  */
+  if (stream != NULL)
+    keep_stream |= stayopen;
+
+  return status;
+}
+
+
+/* Thread-safe, exported version of that.  */
+int
+CONCAT(_nss_files_set,ENTNAME) (int stayopen)
+{
+  int status;
+
+  __libc_lock_lock (lock);
+
+  status = internal_setent (stayopen);
+
+  __libc_lock_unlock (lock);
+
+  return status;
+}
+
+
+/* Close the database file.  */
+static void
+internal_endent (void)
+{
+  if (stream != NULL)
+    {
+      fclose (stream);
+      stream = NULL;
+    }
+
+  /* Reset STAYOPEN flag.  */
+  keep_stream = 0;
+}
+
+
+/* Thread-safe, exported version of that.  */
+int
+CONCAT(_nss_files_end,ENTNAME) (void)
+{
+  __libc_lock_lock (lock);
+
+  internal_endent ();
+
+  __libc_lock_unlock (lock);
+
+  return NSS_STATUS_SUCCESS;
+}
+\f
+/* Parsing the database file into `struct STRUCTURE' data structures.  */
+
+static enum nss_status
+internal_getent (struct STRUCTURE *result,
+                char *buffer, int buflen H_ERRNO_PROTO)
+{
+  char *p;
+  struct parser_data *data = (void *) buffer;
+  int linebuflen = buffer + buflen - data->linebuffer;
+
+  /* Someone called internal_setent before calling us, so if the
+     stream is not open now the file could not be opened.  */
+  if (stream == NULL)
+    {
+      H_ERRNO_SET (NETDB_INTERNAL);
+      return NSS_STATUS_UNAVAIL;
+    }
+
+  if (buflen < sizeof *data + 1)
+    {
+      errno = ERANGE;
+      return NSS_STATUS_NOTFOUND;
+    }
+
+  do
+    {
+      p = fgets (data->linebuffer, linebuflen, stream);
+      if (p == NULL)
+       {
+         /* End of file or read error.  */
+         H_ERRNO_SET (HOST_NOT_FOUND);
+         return NSS_STATUS_NOTFOUND;
+       }
+
+      /* Skip leading blanks.  */
+      while (isspace (*p))
+       ++p;
+    } while (*p == '\0' || *p == '#' ||        /* Ignore empty and comment lines.  */
+            /* Parse the line.  If it is invalid, loop to
+               get the next line of the file to parse.  */
+            ! parse_line (p, result, data, buflen));
+
+  /* Filled in RESULT with the next entry from the database file.  */
+  return NSS_STATUS_SUCCESS;
+}
+
+
+/* Return the next entry from the database file, doing locking.  */
+int
+CONCAT(_nss_files_get,ENTNAME_r) (struct STRUCTURE *result,
+                                 char *buffer, int buflen H_ERRNO_PROTO)
+{
+  /* Return next entry in host file.  */
+  int status;
+
+  __libc_lock_lock (lock);
+
+  status = internal_getent (result, buffer, buflen H_ERRNO_ARG);
+
+  __libc_lock_unlock (lock);
+
+  return status;
+}
+\f
+/* Macro for defining lookup functions for this file-based database.
+
+   NAME is the name of the lookup; e.g. `hostbyname'.
+
+   PROTO describes the arguments for the lookup key;
+   e.g. `const char *hostname'.
+
+   BREAK_IF_MATCH is a block of code which compares `struct STRUCTURE *result'
+   to the lookup key arguments and does `break;' if they match.  */
+
+#define DB_LOOKUP(name, break_if_match, proto...)                            \
+enum nss_status                                                                      \
+_nss_files_get##name##_r (proto,                                             \
+                         struct STRUCTURE *result,                           \
+                         char *buffer, int buflen H_ERRNO_PROTO)             \
+{                                                                            \
+  enum nss_status status;                                                    \
+                                                                             \
+  __libc_lock_lock (lock);                                                   \
+                                                                             \
+  /* Reset file pointer to beginning or open file.  */                       \
+  internal_setent (keep_stream);                                             \
+                                                                             \
+  while ((status = internal_getent (result, buffer, buflen H_ERRNO_ARG))      \
+        == NSS_STATUS_SUCCESS)                                               \
+    { break_if_match }                                                       \
+                                                                             \
+  if (! keep_stream)                                                         \
+    internal_endent ();                                                              \
+                                                                             \
+  __libc_lock_unlock (lock);                                                 \
+                                                                             \
+  return status;                                                             \
+}
diff --git a/nss/nss_files/files-grp.c b/nss/nss_files/files-grp.c
new file mode 100644 (file)
index 0000000..6d528a6
--- /dev/null
@@ -0,0 +1,49 @@
+/* Group file parser in nss_files module.
+Copyright (C) 1996 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA.  */
+
+#include <grp.h>
+
+#define STRUCTURE      group
+#define ENTNAME                grent
+#define DATAFILE       "/etc/group"
+struct grent_data {};
+
+#define TRAILING_LIST_MEMBER           gr_mem
+#define TRAILING_LIST_SEPARATOR_P(c)   ((c) == ',')
+#include "files-parse.c"
+LINE_PARSER
+(
+ STRING_FIELD (result->gr_name, ISCOLON, 0);
+ STRING_FIELD (result->gr_passwd, ISCOLON, 0);
+ INT_FIELD (result->gr_gid, ISCOLON, 0, 10,);
+)
+
+#include "files-XXX.c"
+
+DB_LOOKUP (grnam,
+          {
+            if (! strcmp (name, result->gr_name))
+              break;
+          }, const char *name)
+
+DB_LOOKUP (grgid,
+          {
+            if (result->gr_gid == gid)
+              break;
+          }, gid_t gid)
diff --git a/nss/nss_files/files-hosts.c b/nss/nss_files/files-hosts.c
new file mode 100644 (file)
index 0000000..dad818c
--- /dev/null
@@ -0,0 +1,111 @@
+/* Hosts file parser in nss_files module.
+Copyright (C) 1996 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA.  */
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <netdb.h>
+#include <resolv.h>
+
+
+/* Get implementation for some internal functions.  */
+#include "../resolv/mapv4v6addr.h"
+#include "../resolv/mapv4v6hostent.h"
+
+
+#define ENTNAME                hostent
+#define DATAFILE       _PATH_HOSTS
+
+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 "files-parse.c"
+LINE_PARSER
+({
+  char *addr;
+
+  STRING_FIELD (addr, isspace, 1);
+
+  /* Parse address.  */
+  if ((_res.options & RES_USE_INET6)
+      && inet_pton (AF_INET6, addr, entdata->host_addr) > 0)
+    {
+      result->h_addrtype = AF_INET6;
+      result->h_length = IN6ADDRSZ;
+    }
+  else if (inet_pton (AF_INET, addr, entdata->host_addr) > 0)
+    {
+      if (_res.options & RES_USE_INET6)
+       {
+         map_v4v6_address ((char *) entdata->host_addr,
+                           (char *) entdata->host_addr);
+         result->h_addrtype = AF_INET6;
+         result->h_length = IN6ADDRSZ;
+       }
+      else
+       {
+         result->h_addrtype = AF_INET;
+         result->h_length = INADDRSZ;
+       }
+    }
+  else
+    /* Illegal address: ignore line.  */
+    return 0;
+
+  /* Store a pointer to the addressin the expected form.  */
+  entdata->h_addr_ptrs[0] = entdata->host_addr;
+  entdata->h_addr_ptrs[1] = NULL;
+  result->h_addr_list = entdata->h_addr_ptrs;
+
+  /* If we need the host entry in IPv6 form change it now.  */
+  if (_res.options & RES_USE_INET6)
+    {
+      char *bufptr = data->linebuffer;
+      int buflen = (char *) data + datalen - bufptr;
+      map_v4v6_hostent (result, &bufptr, &buflen);
+    }
+
+  STRING_FIELD (result->h_name, isspace, 1);
+})
+
+#include "files-XXX.c"
+
+DB_LOOKUP (hostbyname,
+          {
+            char **ap;
+            if (! strcmp (name, result->h_name))
+              break;
+            for (ap = result->h_aliases; *ap; ++ap)
+              if (! strcmp (name, *ap))
+                break;
+            if (*ap)
+              break;
+          }, const char *name)
+
+DB_LOOKUP (hostbyaddr,
+          {
+            if (result->h_addrtype == type && result->h_length == len &&
+                ! memcmp (addr, result->h_addr_list[0], len))
+              break;
+          }, const char *addr, int len, int type)
diff --git a/nss/nss_files/files-network.c b/nss/nss_files/files-network.c
new file mode 100644 (file)
index 0000000..504c420
--- /dev/null
@@ -0,0 +1,54 @@
+/* Networks file parser in nss_files module.
+Copyright (C) 1996 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA.  */
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+
+#define ENTNAME                netent
+#define DATAFILE       _PATH_NETWORKS
+
+struct netent_data {};
+
+#define TRAILING_LIST_MEMBER           n_aliases
+#define TRAILING_LIST_SEPARATOR_P      isspace
+#include "files-parse.c"
+LINE_PARSER
+({
+  char *addr;
+
+  STRING_FIELD (result->n_name, isspace, 1);
+
+  STRING_FIELD (addr, isspace, 1);
+  result->n_net = inet_network (addr);
+
+})
+
+#include "files-XXX.c"
+
+DB_LOOKUP (netbyname,
+          LOOKUP_NAME (n_name, n_aliases),
+          const char *name)
+
+DB_LOOKUP (netbyaddr,
+          {
+            if (result->n_addrtype == type && result->n_net == net)
+              /* Bingo!  */
+              break;
+          }, int type, unsigned long int net)
diff --git a/nss/nss_files/files-parse.c b/nss/nss_files/files-parse.c
new file mode 100644 (file)
index 0000000..a93bee1
--- /dev/null
@@ -0,0 +1,171 @@
+/* Common code for file-based database parsers in nss_files module.
+Copyright (C) 1996 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA.  */
+
+#include <ctype.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+
+
+#define CONCAT(a,b) CONCAT1(a,b)
+#define CONCAT1(a,b) a##b
+
+#ifndef STRUCTURE
+#define STRUCTURE ENTNAME
+#endif
+
+
+struct parser_data
+  {
+    struct CONCAT(ENTNAME,_data) entdata;
+    char linebuffer[0];
+  };
+
+#define LINE_PARSER(BODY)                                                    \
+static inline int                                                            \
+parse_line (char *line, struct STRUCTURE *result,                            \
+           struct parser_data *data, int datalen)                            \
+{                                                                            \
+  struct CONCAT(ENTNAME,_data) *const entdata __attribute__ ((unused))       \
+    = &data->entdata;                                                        \
+  BODY;                                                                              \
+  TRAILING_LIST_PARSER;                                                              \
+  return 1;                                                                  \
+}
+
+
+/* Comments can come mid-line; trim the line at the first # seen.  */
+#define MIDLINE_COMMENTS                                                     \
+  {                                                                          \
+    char *p = strchr (line, '#');                                            \
+    if (p)                                                                   \
+      *p = '\0';                                                             \
+  }
+
+#define STRING_FIELD(variable, terminator_p, swallow)                        \
+  {                                                                          \
+    variable = line;                                                         \
+    while (!terminator_p (*line))                                            \
+      if (*++line == '\0')                                                   \
+       return 0;                                                             \
+    *line = '\0';                                                            \
+    do                                                                       \
+      ++line;                                                                \
+    while (swallow && terminator_p (*line));                                 \
+  }
+
+#define INT_FIELD(variable, terminator_p, swallow, base, convert)            \
+  {                                                                          \
+    char *endp;                                                                      \
+    variable = convert (strtol (line, &endp, base));                         \
+    if (endp == line)                                                        \
+      return 0;                                                                      \
+    else if (terminator_p (*endp))                                           \
+      do                                                                     \
+       ++endp;                                                               \
+      while (swallow && terminator_p (*endp));                               \
+    else if (*endp != '\0')                                                  \
+      return 0;                                                                      \
+    line = endp;                                                             \
+  }
+
+#define ISCOLON(c) ((c) == ':')
+
+
+#ifndef TRAILING_LIST_MEMBER
+#define TRAILING_LIST_PARSER /* Nothing to do.  */
+#else
+
+#define TRAILING_LIST_PARSER                                                 \
+{                                                                            \
+  char **list = parse_list (line, data, datalen);                            \
+  if (list)                                                                  \
+    result->TRAILING_LIST_MEMBER = list;                                     \
+  else                                                                               \
+    return 0;                                                                \
+}
+
+static inline char **
+parse_list (char *line, struct parser_data *data, int datalen)
+{
+  char *eol, **list, **p;
+
+  /* Find the end of the line buffer.  */
+  eol = strchr (line, '\0');
+  /* Adjust the pointer so it is aligned for storing pointers.  */
+  eol += (eol - (char *) 0) % __alignof__ (char *);
+  /* We will start the storage here for the vector of pointers.  */
+  list = (char **) eol;
+
+  p = list;
+  while (1)
+    {
+      char *elt;
+
+      if ((char *) &p[1] - (char *) data > datalen)
+       {
+         /* We cannot fit another pointer in the buffer.  */
+         errno = ERANGE;
+         return NULL;
+       }
+      if (*line == '\0')
+       break;
+
+      elt = line;
+      while (1)
+       {
+         if (TRAILING_LIST_SEPARATOR_P (*line))
+           {
+             *p++ = elt;
+             *line = '\0';
+             do
+               ++line;
+             while (TRAILING_LIST_SEPARATOR_P (*line));
+           }
+         else if (*line == '\0' || *line == '\n')
+           {
+             /* End of the line.  */
+             if (line > elt)
+               /* Last element.  */
+               *p++ = elt;
+             *line = '\0';
+             break;
+           }
+         else
+           ++line;
+       }
+    }
+  *p = NULL;
+
+  return list;
+}
+
+#define LOOKUP_NAME(nameelt, aliaselt)                                       \
+{                                                                            \
+  char **ap;                                                                 \
+  if (! strcmp (name, result->nameelt))                                              \
+    break;                                                                   \
+  for (ap = result->aliaselt; *ap; ++ap)                                     \
+    if (! strcmp (name, *ap))                                                \
+      break;                                                                 \
+  if (*ap)                                                                   \
+    break;                                                                   \
+}
+
+#endif
diff --git a/nss/nss_files/files-proto.c b/nss/nss_files/files-proto.c
new file mode 100644 (file)
index 0000000..d67f8db
--- /dev/null
@@ -0,0 +1,48 @@
+/* Protocols file parser in nss_files module.
+Copyright (C) 1996 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA.  */
+
+#include <netdb.h>
+
+
+#define ENTNAME                protoent
+#define DATAFILE       _PATH_PROTOCOLS
+
+struct protoent_data {};
+
+#define TRAILING_LIST_MEMBER           p_aliases
+#define TRAILING_LIST_SEPARATOR_P      isspace
+#include "files-parse.c"
+LINE_PARSER
+(
+ MIDLINE_COMMENTS;
+ STRING_FIELD (result->p_name, isspace, 1);
+ INT_FIELD (result->p_proto, isspace, 1, 10,);
+ )
+
+#include "files-XXX.c"
+
+DB_LOOKUP (protobyname,
+          LOOKUP_NAME (p_name, p_aliases),
+          const char *name)
+
+DB_LOOKUP (protobynumber,
+          {
+            if (result->p_proto == proto)
+              break;
+          }, int proto)
diff --git a/nss/nss_files/files-pwd.c b/nss/nss_files/files-pwd.c
new file mode 100644 (file)
index 0000000..4b6a4b7
--- /dev/null
@@ -0,0 +1,54 @@
+/* User file parser in nss_files module.
+Copyright (C) 1996 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA.  */
+
+#include <pwd.h>
+
+#define STRUCTURE      passwd
+#define ENTNAME                pwent
+#define DATAFILE       "/etc/passwd"
+struct pwent_data {};
+
+#include "files-parse.c"
+LINE_PARSER
+({
+  STRING_FIELD (result->pw_name, ISCOLON, 0);
+  STRING_FIELD (result->pw_passwd, ISCOLON, 0);
+  INT_FIELD (result->pw_uid, ISCOLON, 0, 10,);
+  INT_FIELD (result->pw_gid, ISCOLON, 0, 10,);
+  STRING_FIELD (result->pw_gecos, ISCOLON, 0);
+  STRING_FIELD (result->pw_dir, ISCOLON, 0);
+  result->pw_shell = line;
+  line = strchr (line, '\n');
+  if (line)
+    *line = '\0';
+})
+
+#include "files-XXX.c"
+
+DB_LOOKUP (pwnam,
+          {
+            if (! strcmp (name, result->pw_name))
+              break;
+          }, const char *name)
+
+DB_LOOKUP (pwuid,
+          {
+            if (result->pw_uid == uid)
+              break;
+          }, uid_t uid)
diff --git a/nss/nss_files/files-rpc.c b/nss/nss_files/files-rpc.c
new file mode 100644 (file)
index 0000000..fef0ff8
--- /dev/null
@@ -0,0 +1,48 @@
+/* SunRPC program number file parser in nss_files module.
+Copyright (C) 1996 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA.  */
+
+#include <rpc/netdb.h>
+
+
+#define ENTNAME                rpcent
+#define DATAFILE       "/etc/rpc"
+
+struct rpcent_data {};
+
+#define TRAILING_LIST_MEMBER           r_aliases
+#define TRAILING_LIST_SEPARATOR_P      isspace
+#include "files-parse.c"
+LINE_PARSER
+(
+ MIDLINE_COMMENTS;
+ STRING_FIELD (result->r_name, isspace, 1);
+ INT_FIELD (result->r_number, isspace, 1, 10,);
+ )
+
+#include "files-XXX.c"
+
+DB_LOOKUP (rpcbyname,
+          LOOKUP_NAME (r_name, r_aliases),
+          const char *name)
+
+DB_LOOKUP (rpcbynumber,
+          {
+            if (result->r_number == number)
+              break;
+          }, int number)
diff --git a/nss/nss_files/files-service.c b/nss/nss_files/files-service.c
new file mode 100644 (file)
index 0000000..3bcb487
--- /dev/null
@@ -0,0 +1,51 @@
+/* Services file parser in nss_files module.
+Copyright (C) 1996 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA.  */
+
+#include <netinet/in.h>
+#include <netdb.h>
+
+
+#define ENTNAME                servent
+#define DATAFILE       _PATH_SERVICES
+
+struct servent_data {};
+
+#define TRAILING_LIST_MEMBER           s_aliases
+#define TRAILING_LIST_SEPARATOR_P      isspace
+#include "files-parse.c"
+#define ISSLASH(c) ((c) == '/')
+LINE_PARSER
+(
+ MIDLINE_COMMENTS;
+ STRING_FIELD (result->s_name, isspace, 1);
+ INT_FIELD (result->s_port, ISSLASH, 10, 0, htons);
+ STRING_FIELD (result->s_proto, isspace, 1);
+ )
+
+#include "files-XXX.c"
+
+DB_LOOKUP (servbyname,
+          LOOKUP_NAME (s_name, s_aliases),
+          const char *name)
+
+DB_LOOKUP (servbyport,
+          {
+            if (result->s_port == port)
+              break;
+          }, int port)
diff --git a/nss/nsswitch.c b/nss/nsswitch.c
new file mode 100644 (file)
index 0000000..4c2ccf6
--- /dev/null
@@ -0,0 +1,588 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <ctype.h>
+#include <dlfcn.h>
+#include <netdb.h>
+#include <libc-lock.h>
+#include <search.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "nsswitch.h"
+#include "../elf/link.h"       /* We need some help from ld.so.  */
+
+/* Prototypes for the local functions.  */
+static void nss_init (void);
+static void *nss_lookup_function (service_user *ni, const char *fct_name);
+static int nss_find_entry (struct entry **knownp, const char *key,
+                          void **valp);
+static void nss_insert_entry (struct entry **knownp, const char *key,
+                             void *val);
+static name_database *nss_parse_file (const char *fname);
+static name_database_entry *nss_getline (char *line);
+static service_library *nss_new_service (name_database *database,
+                                        const char *name);
+
+
+__libc_lock_define_initialized (static, lock);
+
+
+/* Global variable.  */
+struct __res_state _res;
+
+
+/* Known aliases for service names.  */
+static struct {
+  const char *alias;
+  const char *value;
+} service_alias[] =
+{
+  { "nis+", "nisplus" },
+  { "yp", "nis" }
+};
+
+
+/* Nonzero if the sevices are already initialized.  */
+static int nss_initialized;
+
+
+/* The root of the whole data base.  */
+static name_database *service_table;
+
+
+static void
+nss_init (void)
+{
+  /* Prevent multiple threads to change the service table.  */
+  __libc_lock_lock (lock);
+
+  if (service_table == NULL)
+    service_table = nss_parse_file (_PATH_NSSWITCH_CONF);
+
+  __libc_lock_unlock (lock);
+}
+
+
+/* -1 == database not found
+    0 == database entry pointer stored */
+int
+__nss_database_lookup (const char *database, service_user **ni)
+{
+  /* Return first `service_user' entry for DATABASE.
+     XXX Will use perfect hashing function for known databases.  */
+  name_database_entry *entry;
+
+  /* Test whether configuration data is available.  */
+  if (service_table == NULL)
+    {
+      if (nss_initialized == 0)
+       nss_init ();
+
+      if (service_table == NULL)
+       return -1;
+    }
+
+  /* XXX Could use some faster mechanism here.  But each database is
+     only requested once and so this might not be critical.  */
+  for (entry = service_table->entry; entry != NULL; entry = entry->next)
+    if (strcmp (database, entry->name) == 0)
+      break;
+
+  if (entry == NULL || (*ni = entry->service) == NULL)
+    return -1;
+
+  return 0;
+}
+
+
+/* -1 == not found
+    0 == adjusted for next function */
+int
+__nss_lookup (service_user **ni, const char *fct_name, void **fctp)
+{
+  *fctp = nss_lookup_function (*ni, fct_name);
+
+  while (*fctp == NULL
+        && nss_next_action (*ni, NSS_STATUS_UNAVAIL) == NSS_ACTION_CONTINUE
+        && (*ni)->next != NULL)
+    {
+      *ni = (*ni)->next;
+
+      *fctp = nss_lookup_function (*ni, fct_name);
+    }
+
+  return *fctp != NULL ? 0 : -1;
+}
+
+
+/* -1 == not found
+    0 == adjusted for next function
+    1 == finished */
+int
+__nss_next (service_user **ni, const char *fct_name, void **fctp, int status,
+           int all_values)
+{
+  if (all_values)
+    {
+      if (nss_next_action (*ni, NSS_STATUS_TRYAGAIN) == NSS_ACTION_RETURN
+         && nss_next_action (*ni, NSS_STATUS_UNAVAIL) == NSS_ACTION_RETURN
+         && nss_next_action (*ni, NSS_STATUS_NOTFOUND) == NSS_ACTION_RETURN
+         && nss_next_action (*ni, NSS_STATUS_SUCCESS) == NSS_ACTION_RETURN)
+       return 1;
+    }
+  else
+    {
+      /* This is really only for debugging.  */
+       if (NSS_STATUS_TRYAGAIN > status || status > NSS_STATUS_SUCCESS)
+        __libc_fatal ("illegal status in " __FUNCTION__);
+
+       if (nss_next_action (*ni, status) == NSS_ACTION_RETURN)
+        return 1;
+    }
+
+  if ((*ni)->next == NULL)
+    return -1;
+
+  do
+    {
+      *ni = (*ni)->next;
+
+      *fctp = nss_lookup_function (*ni, fct_name);
+    }
+  while (*fctp == NULL
+        && nss_next_action (*ni, NSS_STATUS_UNAVAIL) == NSS_ACTION_CONTINUE
+        && (*ni)->next != NULL);
+
+  return *fctp != NULL ? 0 : -1;
+}
+
+
+static int
+nss_dlerror_run (void (*operate) (void))
+{
+  const char *last_errstring = NULL;
+  const char *last_object_name = NULL;
+
+  (void) _dl_catch_error (&last_errstring, &last_object_name, operate);
+
+  return last_errstring != NULL;
+}
+
+
+static void *
+nss_lookup_function (service_user *ni, const char *fct_name)
+{
+  void *result;
+
+  /* Determine whether current function is loaded.  */
+  if (nss_find_entry (&ni->known, fct_name, &result) >= 0)
+    return result;
+
+  /* If we failed to allocate the needed data structures for the
+     service return an error.  This should only happen when we are out
+     of memory.  */
+  if (ni->library == NULL)
+    return NULL;
+
+  /* We now modify global data.  Protect it.  */
+  __libc_lock_lock (lock);
+
+  if (ni->library->lib_handle == NULL)
+    {
+      /* Load the shared library.  */
+      size_t shlen = (7 + strlen (ni->library->name) + 3
+                     + sizeof (NSS_SHLIB_REVISION));
+      char shlib_name[shlen];
+
+      void do_open (void)
+       {
+         /* The used function is found in GNU ld.so.  XXX The first
+            argument to _dl_open used to be `_dl_loaded'.  But this
+            does (currently) not work.  */
+         ni->library->lib_handle = _dl_open (shlib_name, RTLD_LAZY);
+       }
+
+      /* Construct name.  */
+      __stpcpy (__stpcpy (__stpcpy (shlib_name, "libnss_"), ni->library->name),
+               ".so" NSS_SHLIB_REVISION);
+
+      if (nss_dlerror_run (do_open) != 0)
+       /* Failed to load the library.  */
+       ni->library->lib_handle = (void *) -1;
+    }
+
+  if (ni->library->lib_handle == (void *) -1)
+    /* Library not found => function not found.  */
+    result = NULL;
+  else
+    {
+      /* Get the desired function.  Again,  GNU ld.so magic ahead.  */
+      size_t namlen = (5 + strlen (ni->library->name) + 1
+                      + strlen (fct_name) + 1);
+      char name[namlen];
+      struct link_map *map = ni->library->lib_handle;
+      Elf32_Addr loadbase;
+      const Elf32_Sym *ref = NULL;
+      void get_sym (void)
+       {
+         struct link_map *scope[2] = { map, NULL };
+         loadbase = _dl_lookup_symbol (name, &ref, scope, map->l_name, 0, 0);
+       }
+
+      __stpcpy (__stpcpy (__stpcpy (__stpcpy (name, "_nss_"),
+                                   ni->library->name),
+                         "_"),
+               fct_name);
+
+      result = (nss_dlerror_run (get_sym)
+               ? NULL : (void *) (loadbase + ref->st_value));
+    }
+
+  /* Remember function pointer for the usage.  */
+  nss_insert_entry (&ni->known, fct_name, result);
+
+  /* Remove the lock.  */
+  __libc_lock_unlock (lock);
+
+  return result;
+}
+
+
+static int
+known_compare (const void *p1, const void *p2)
+{
+  known_function *v1 = (known_function *) p1;
+  known_function *v2 = (known_function *) p2;
+
+  return strcmp (v1->fct_name, v2->fct_name);
+}
+
+
+static int
+nss_find_entry (struct entry **knownp, const char *key, void **valp)
+{
+  known_function looking_for = { fct_name: key };
+  struct entry **found;
+
+  found = __tfind (&looking_for, (const void **) knownp, known_compare);
+
+  if (found == NULL)
+    return -1;
+
+  *valp = ((known_function *) (*found)->key)->fct_ptr;
+
+  return 0;
+}
+
+
+static void
+nss_insert_entry (struct entry **knownp, const char *key, void *val)
+{
+  known_function *to_insert;
+
+  to_insert = (known_function *) malloc (sizeof (known_function));
+  if (to_insert == NULL)
+    return;
+
+  to_insert->fct_name = key;
+  to_insert->fct_ptr = val;
+
+  __tsearch (to_insert, (void **) knownp, known_compare);
+}
+
+
+static name_database *
+nss_parse_file (const char *fname)
+{
+  FILE *fp;
+  name_database *result;
+  name_database_entry *last;
+  char *line;
+  size_t len;
+
+  /* Open the configuration file.  */
+  fp = fopen (fname, "r");
+  if (fp == NULL)
+    return NULL;
+
+  result = (name_database *) malloc (sizeof (name_database));
+  if (result == NULL)
+    return NULL;
+
+  result->entry = NULL;
+  result->library = NULL;
+  last = NULL;
+  line = NULL;
+  len = 0;
+  do
+    {
+      name_database_entry *this;
+      ssize_t n;
+      char *cp;
+
+      n = getline (&line, &len, fp);
+      if (n < 0)
+       break;
+      if (line[n - 1] == '\n')
+       line[n - 1] = '\0';
+
+      /* Because the file format does not know any form of quoting we
+        can search forward for the next '#' character and if found
+        make it terminating the line.  */
+      cp = strchr (line, '#');
+      if (cp != NULL)
+       *cp = '\0';
+
+      /* If the line is blank it is ignored.  */
+      if (line[0] == '\0')
+       continue;
+
+      /* Each line completely specifies the actions for a database.  */
+      this = nss_getline (line);
+      if (this != NULL)
+       {
+         if (last != NULL)
+           last->next = this;
+         else
+           result->entry = this;
+
+         last = this;
+       }
+    }
+  while (!feof (fp));
+
+  /* Free the buffer.  */
+  free (line);
+  /* Close configuration file.  */
+  fclose (fp);
+
+  /* Now create for each service we could use an entry in LIBRARY list.  */
+  for (last = result->entry; last != NULL; last = last->next)
+    {
+      service_user *runp;
+
+      for (runp = last->service; runp != NULL; runp = runp->next)
+       runp->library = nss_new_service (result, runp->name);
+    }
+
+  return result;
+}
+
+
+static name_database_entry *
+nss_getline (char *line)
+{
+  const char *name;
+  name_database_entry *result;
+  service_user *last;
+
+  /* Ignore leading white spaces.  ATTENTION: this is different from
+     what is implemented in Solaris.  The Solaris man page says a line
+     beginning with a white space character is ignored.  We regard
+     this as just another misfeature in Solaris.  */
+  while (isspace (line[0]))
+    ++line;
+
+  /* Recognize `<database> ":"'.  */
+  name = line;
+  while (line[0] != '\0' && !isspace (line[0]) && line[0] != ':')
+    ++line;
+  if (line[0] == '\0' || name == line)
+    /* Syntax error.  */
+    return NULL;
+  *line++ = '\0';
+
+  result = (name_database_entry *) malloc (sizeof (name_database_entry));
+  if (result == NULL)
+    return NULL;
+
+  result->name = strdup (name);
+  if (result->name == NULL)
+    {
+      free (result);
+      return NULL;
+    }
+  result->service = NULL;
+  result->next = NULL;
+  last = NULL;
+
+  /* Read the source names: `<source> ( "[" <status> "=" <action> "]" )*'.  */
+  while (1)
+    {
+      service_user *new_service;
+      size_t n;
+
+      while (isspace (line[0]))
+       ++line;
+      if (line[0] == '\0')
+       /* No source specified.  */
+       return result;
+
+      /* Read <source> identifier.  */
+      name = line;
+      while (line[0] != '\0' && !isspace (line[0]) && line[0] != '[')
+       ++line;
+      if (name == line)
+       return result;
+
+
+      new_service = (service_user *) malloc (sizeof (service_user));
+      if (new_service == NULL)
+       return result;
+
+      /* Test whether the source name is one of the aliases.  */
+      for (n = 0; n < sizeof (service_alias) / sizeof (service_alias[0]); ++n)
+       if (strncmp (service_alias[n].alias, name, line - name) == 0
+           && service_alias[n].alias[line - name] == '\0')
+         break;
+
+      if (n < sizeof (service_alias) / sizeof (service_alias[0]))
+       new_service->name = service_alias[n].value;
+      else
+       {
+         char *source = (char *) malloc (line - name + 1);
+         if (source == NULL)
+           {
+             free (new_service);
+             return result;
+           }
+         memcpy (source, name, line - name);
+         source[line - name] = '\0';
+
+         new_service->name = source;
+       }
+
+      /* Set default actions.  */
+      new_service->actions[2 + NSS_STATUS_TRYAGAIN] = NSS_ACTION_CONTINUE;
+      new_service->actions[2 + NSS_STATUS_UNAVAIL] = NSS_ACTION_CONTINUE;
+      new_service->actions[2 + NSS_STATUS_NOTFOUND] = NSS_ACTION_CONTINUE;
+      new_service->actions[2 + NSS_STATUS_SUCCESS] = NSS_ACTION_RETURN;
+      new_service->library = NULL;
+      new_service->known = NULL;
+      new_service->next = NULL;
+
+      while (isspace (line[0]))
+       ++line;
+
+      if (line[0] == '[')
+       {
+         int status;
+
+         /* Read criterions.  */
+         do
+           ++line;
+         while (line[0] != '\0' && isspace (line[0]));
+
+         do
+           {
+             /* Read status name.  */
+             name = line;
+             while (line[0] != '\0' && !isspace (line[0]) && line[0] != '='
+                    && line[0] != ']')
+               ++line;
+
+             /* Compare with known statii.  */
+             if (line - name == 7)
+               {
+                 if (strncasecmp (name, "SUCCESS", 7) == 0)
+                   status = NSS_STATUS_SUCCESS;
+                 else if (strncasecmp (name, "UNAVAIL", 7) == 0)
+                   status = NSS_STATUS_UNAVAIL;
+                 else
+                   return result;
+               }
+             else if (line - name == 8)
+               {
+                 if (strncasecmp (name, "NOTFOUND", 8) == 0)
+                   status = NSS_STATUS_NOTFOUND;
+                 else if (strncasecmp (name, "TRYAGAIN", 8) == 0)
+                   status = NSS_STATUS_TRYAGAIN;
+                 else
+                   return result;
+               }
+             else
+               return result;
+
+             while (isspace (line[0]))
+               ++line;
+             if (line[0] != '=')
+               return result;
+             do
+               ++line;
+             while (isspace (line[0]));
+
+             name = line;
+             while (line[0] != '\0' && !isspace (line[0]) && line[0] != '='
+                    && line[0] != ']')
+               ++line;
+
+             if (line - name == 6 && strncasecmp (name, "RETURN", 6) == 0)
+               new_service->actions[2 + status] = NSS_ACTION_RETURN;
+             else if (line - name == 8
+                      && strncasecmp (name, "CONTINUE", 8) == 0)
+               new_service->actions[2 + status] = NSS_ACTION_CONTINUE;
+             else
+               return result;
+
+             /* Match white spaces.  */
+             while (isspace (line[0]))
+               ++line;
+           }
+         while (line[0] != ']');
+
+         /* Skip the ']'.  */
+         ++line;
+       }
+
+      if (last == NULL)
+       result->service = new_service;
+      else
+       last->next = new_service;
+      last = new_service;
+    }
+  /* NOTREACHED */
+  return NULL;
+}
+
+
+static service_library *
+nss_new_service (name_database *database, const char *name)
+{
+  service_library **currentp = &database->library;
+
+  while (*currentp != NULL)
+    {
+      if (strcmp ((*currentp)->name, name) == 0)
+       return *currentp;
+      currentp = &(*currentp)->next;
+    }
+
+  /* We have to add the new service.  */
+  *currentp = (service_library *) malloc (sizeof (service_library));
+  if (*currentp == NULL)
+    return NULL;
+
+  (*currentp)->name = name;
+  (*currentp)->lib_handle = NULL;
+  (*currentp)->next = NULL;
+
+  return *currentp;
+}
diff --git a/nss/nsswitch.h b/nss/nsswitch.h
new file mode 100644 (file)
index 0000000..f597a58
--- /dev/null
@@ -0,0 +1,138 @@
+/* Copyright (C) 1996 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#ifndef _NSSWITCH_H
+#define _NSSWITCH_H    1
+
+/* This is an *internal* header.  */
+
+#include <arpa/nameser.h>
+#include <netinet/in.h>
+#include <resolv.h>
+#include <search.h>
+
+
+/* Revision number of NSS interface (must be a string).  */
+#define NSS_SHLIB_REVISION ".1"
+
+
+/* Possible results of lookup using a nss_* function.  */
+enum nss_status
+{
+  NSS_STATUS_TRYAGAIN = -2,
+  NSS_STATUS_UNAVAIL,
+  NSS_STATUS_NOTFOUND,
+  NSS_STATUS_SUCCESS,
+};
+
+
+/* Actions performed after lookup finished.  */
+typedef enum
+{
+  NSS_ACTION_CONTINUE,
+  NSS_ACTION_RETURN
+} lookup_actions;
+
+
+typedef struct service_library
+{
+  /* Name of service (`files', `dns', `nis', ...).  */
+  const char *name;
+  /* Pointer to the loaded shared library.  */
+  void *lib_handle;
+  /* And the link to the next entry.  */
+  struct service_library *next;
+} service_library;
+
+
+/* For mappng a function name to a function pointer.  */
+typedef struct
+{
+  const char *fct_name;
+  void *fct_ptr;
+} known_function;
+
+
+typedef struct service_user
+{
+  /* Name of the service (`files', `dns', `nis', ...).  */
+  const char *name;
+  /* Action according to result.  */
+  lookup_actions actions[4];
+  /* Link to the underlying library object.  */
+  service_library *library;
+  /* Collection of known functions.  */
+  struct entry *known;
+  /* And the link to the next entry.  */
+  struct service_user *next;
+} service_user;
+
+/* To access the action based on the status value use this macro.  */
+#define nss_next_action(ni, status) ((ni)->actions[2 + status])
+
+
+typedef struct name_database_entry
+{
+  /* Name of the database.  */
+  const char *name;
+  /* List of service to be used.  */
+  service_user *service;
+  /* And the link to the next entry.  */
+  struct name_database_entry *next;
+} name_database_entry;
+
+
+typedef struct name_database
+{
+  /* List of all known databases.  */
+  name_database_entry *entry;
+  /* List of libraries with service implementation.  */
+  service_library *library;
+} name_database;
+
+
+/* Interface functions for NSS.  */
+
+/* Get the data structure representing the specified database.  More
+   than one function can use the database.  */
+int __nss_database_lookup (const char *database, service_user **ni);
+
+
+/* Put first function with name FCT_NAME for SERVICE in FCTP.  The
+   position is remembered in NI.  The function returns a value < 0 if
+   an error occured or no such function exists.  */
+int __nss_lookup (service_user **ni, const char *fct_name, void **fctp);
+
+/* Determine the next step in the lookup process according to the
+   result STATUS of the call to the last function returned by
+   `__nss_lookup' or `__nss_next'.  NI specifies the last function
+   examined.  The function return a value > 0 if the process should
+   stop with the last result of the last function call to be the
+   result of the entire lookup.  The returned valie is 0 if there is
+   another function to use and < 0 if an error occured.
+
+   If ALL_VALUES is nonzero, the return value will not be > 0 as long as
+   there is a possibility the lookup process can ever use following
+   services.  In other words, only if all four lookup results have
+   the action RETURN associated the lookup process stops before the
+   natural end.  */
+int __nss_next (service_user **ni, const char *fct_name, void **fctp,
+               int status, int all_values);
+
+
+#endif /* nsswitch.h */
diff --git a/nss/proto-lookup.c b/nss/proto-lookup.c
new file mode 100644 (file)
index 0000000..f27ff59
--- /dev/null
@@ -0,0 +1,22 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#define DATABASE_NAME protocols
+
+#include "XXX-lookup.c"
diff --git a/nss/pwd-lookup.c b/nss/pwd-lookup.c
new file mode 100644 (file)
index 0000000..e792560
--- /dev/null
@@ -0,0 +1,22 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#define DATABASE_NAME passwd
+
+#include "XXX-lookup.c"
diff --git a/nss/rpc-lookup.c b/nss/rpc-lookup.c
new file mode 100644 (file)
index 0000000..f49359a
--- /dev/null
@@ -0,0 +1,22 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#define DATABASE_NAME rpc
+
+#include "XXX-lookup.c"
diff --git a/nss/service-lookup.c b/nss/service-lookup.c
new file mode 100644 (file)
index 0000000..c1a3256
--- /dev/null
@@ -0,0 +1,22 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#define DATABASE_NAME services
+
+#include "XXX-lookup.c"
index e4ae334..4f2d068 100644 (file)
@@ -71,7 +71,7 @@ Cambridge, MA 02139, USA.  */
 #endif
 #endif
 
-#ifdef WIN32
+#if defined (WIN32) && !defined (__CYGWIN32__)
 /* It's not Unix, really.  See?  Capital letters.  */
 #include <windows.h>
 #define getpid() GetCurrentProcessId()
index 85c297b..3dd03b2 100644 (file)
@@ -1011,9 +1011,9 @@ static const char *re_error_msgid[] =
    This is a variable only so users of regex can assign to it; we never
    change it ourselves.  */
 #if defined (MATCH_MAY_ALLOCATE)
-/* 8600 was enough to cause a crash on Ultrix,
+/* 4400 was enough to cause a crash on Alpha OSF/1,
    whose default stack limit is 2mb.  */
-int re_max_failures = 8000;
+int re_max_failures = 4000;
 #else
 int re_max_failures = 2000;
 #endif
index b33700a..ce67d49 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 1991 Free Software Foundation, Inc.
+# Copyright (C) 1991, 1996 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
@@ -21,6 +21,8 @@
 #
 subdir := pwd
 
-routines := pwdopen pwdread fgetpwent getpw getpwent getpwnam getpwuid putpwent
+routines := fgetpwent getpw putpwent \
+           getpwent getpwnam getpwuid \
+           getpwent_r getpwnam_r getpwuid_r
 
 include ../Rules
index 4a21cbb..ba9f834 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1996 Free Software Foundation, Inc.
 This file is part of the GNU C Library.
 
 The GNU C Library is free software; you can redistribute it and/or
@@ -16,25 +16,50 @@ License along with the GNU C Library; see the file COPYING.LIB.  If
 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
 Cambridge, MA 02139, USA.  */
 
-#include <ansidecl.h>
-#include <errno.h>
-#include <limits.h>
-#include <stddef.h>
 #include <stdio.h>
-#include <string.h>
 #include <pwd.h>
 
+/* Define a line parsing function using the common code
+   used in the nss_files module.  */
+
+#define STRUCTURE      passwd
+#define ENTNAME                pwent
+struct pwent_data {};
+
+#include "../nss/nss_files/files-parse.c"
+LINE_PARSER
+(
+ STRING_FIELD (result->pw_name, ISCOLON);
+ STRING_FIELD (result->pw_passwd, ISCOLON);
+ INT_FIELD (result->pw_uid, ISCOLON, 10,);
+ INT_FIELD (result->pw_gid, ISCOLON, 10,);
+ STRING_FIELD (result->pw_gecos, ISCOLON);
+ STRING_FIELD (result->pw_dir, ISCOLON);
+ result->pw_shell = line;
+)
+
+
 /* Read one entry from the given stream.  */
 struct passwd *
-DEFUN(fgetpwent, (stream), FILE *stream)
+fgetpwent (FILE *stream)
 {
-  static PTR info = NULL;
-  if (info == NULL)
+  static char buffer[BUFSIZ];
+  static struct passwd result;
+  char *p;
+
+  do
     {
-      info = __pwdalloc();
-      if (info == NULL)
-       return(NULL);
-    }
+      p = fgets (buffer, sizeof buffer, stream);
+      if (p == NULL)
+       return NULL;
+
+      /* Skip leading blanks.  */
+      while (isspace (*p))
+       ++p;
+    } while (*p == '\0' || *p == '#' ||        /* Ignore empty and comment lines.  */
+            /* Parse the line.  If it is invalid, loop to
+               get the next line of the file to parse.  */
+            ! parse_line (p, &result, (void *) buffer, sizeof buffer));
 
-  return(__pwdread(stream, info));
+  return &result;
 }
index 1c88950..79edbd5 100644 (file)
@@ -1,5 +1,6 @@
-/* Copyright (C) 1991 Free Software Foundation, Inc.
+/* Copyright (C) 1996 Free Software Foundation, Inc.
 This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
 
 The GNU C Library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Library General Public License as
@@ -13,55 +14,17 @@ Library General Public License for more details.
 
 You should have received a copy of the GNU Library General Public
 License along with the GNU C Library; see the file COPYING.LIB.  If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA.  */
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
-#include <ansidecl.h>
-#include <stddef.h>
-#include <stdio.h>
 #include <pwd.h>
 
-static FILE *stream = NULL;
 
-/* Rewind the stream.  */
-void
-DEFUN_VOID(setpwent)
-{
-  if (stream != NULL)
-    rewind(stream);
-}
+#define LOOKUP_TYPE    struct passwd
+#define SETFUNC_NAME   setpwent
+#define        GETFUNC_NAME    getpwent
+#define        ENDFUNC_NAME    endpwent
+#define DATABASE_NAME  passwd
+#define BUFLEN         1024
 
-
-/* Close the stream.  */
-void
-DEFUN_VOID(endpwent)
-{
-  if (stream != NULL)
-    {
-      (void) fclose(stream);
-      stream = NULL;
-    }
-}
-
-
-/* Return one entry from the password file.  */
-struct passwd *
-DEFUN_VOID(getpwent)
-{
-  static PTR info = NULL;
-  if (info == NULL)
-    {
-      info = __pwdalloc();
-      if (info == NULL)
-       return(NULL);
-    }
-
-  if (stream == NULL)
-    {
-      stream = __pwdopen();
-      if (stream == NULL)
-       return(NULL);
-    }
-
-  return(__pwdread(stream, info));
-}
+#include "../nss/getXXent.c"
diff --git a/pwd/getpwent_r.c b/pwd/getpwent_r.c
new file mode 100644 (file)
index 0000000..ced7f8a
--- /dev/null
@@ -0,0 +1,30 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <pwd.h>
+
+
+#define LOOKUP_TYPE    struct passwd
+#define SETFUNC_NAME   setpwent
+#define        GETFUNC_NAME    getpwent
+#define        ENDFUNC_NAME    endpwent
+#define DATABASE_NAME  passwd
+#define BUFLEN         1024
+
+#include "../nss/getXXent_r.c"
index bac8b6b..597b8d1 100644 (file)
@@ -1,5 +1,6 @@
-/* Copyright (C) 1991, 1995 Free Software Foundation, Inc.
+/* Copyright (C) 1996 Free Software Foundation, Inc.
 This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
 
 The GNU C Library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Library General Public License as
@@ -13,24 +14,17 @@ Library General Public License for more details.
 
 You should have received a copy of the GNU Library General Public
 License along with the GNU C Library; see the file COPYING.LIB.  If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA.  */
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
-#include <ansidecl.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <string.h>
 #include <pwd.h>
 
-/* Search for an entry with a matching name.  */
-struct passwd *
-DEFUN(getpwnam, (name), const char *name)
-{
-  int match (struct passwd *p)
-    {
-      return ! strcmp (name, p->pw_name);
-    }
-  static void *info;
 
-  return __pwdscan (&info, &match);
-}
+#define LOOKUP_TYPE    struct passwd
+#define FUNCTION_NAME  getpwnam
+#define DATABASE_NAME  passwd
+#define ADD_PARAMS     const char *name
+#define ADD_VARIABLES  name
+#define BUFLEN         1024
+
+#include "../nss/getXXbyYY.c"
diff --git a/pwd/getpwnam_r.c b/pwd/getpwnam_r.c
new file mode 100644 (file)
index 0000000..c2d1f84
--- /dev/null
@@ -0,0 +1,30 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <pwd.h>
+
+
+#define LOOKUP_TYPE    struct passwd
+#define FUNCTION_NAME  getpwnam
+#define DATABASE_NAME  passwd
+#define ADD_PARAMS     const char *name
+#define ADD_VARIABLES  name
+#define BUFLEN         1024
+
+#include "../nss/getXXbyYY_r.c"
index 5093488..130c251 100644 (file)
@@ -1,5 +1,6 @@
-/* Copyright (C) 1991, 1995 Free Software Foundation, Inc.
+/* Copyright (C) 1996 Free Software Foundation, Inc.
 This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
 
 The GNU C Library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Library General Public License as
@@ -13,24 +14,17 @@ Library General Public License for more details.
 
 You should have received a copy of the GNU Library General Public
 License along with the GNU C Library; see the file COPYING.LIB.  If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA.  */
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
-#include <ansidecl.h>
-#include <stddef.h>
-#include <stdio.h>
 #include <pwd.h>
-#include <sys/types.h>
 
-/* Search for an entry with a matching uid.  */
-struct passwd *
-DEFUN(getpwuid, (uid), uid_t uid)
-{
-  int match (struct passwd *p)
-    {
-      return p->pw_uid == uid;
-    }
-  static void *info;
 
-  return __pwdscan (&info, &match);
-}
+#define LOOKUP_TYPE    struct passwd
+#define FUNCTION_NAME  getpwuid
+#define DATABASE_NAME  passwd
+#define ADD_PARAMS     uid_t uid
+#define ADD_VARIABLES  uid
+#define BUFLEN         1024
+
+#include "../nss/getXXbyYY.c"
diff --git a/pwd/getpwuid_r.c b/pwd/getpwuid_r.c
new file mode 100644 (file)
index 0000000..e3bf757
--- /dev/null
@@ -0,0 +1,30 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#include <pwd.h>
+
+
+#define LOOKUP_TYPE    struct passwd
+#define FUNCTION_NAME  getpwuid
+#define DATABASE_NAME  passwd
+#define ADD_PARAMS     uid_t uid
+#define ADD_VARIABLES  uid
+#define BUFLEN         1024
+
+#include "../nss/getXXbyYY_r.c"
diff --git a/pwd/pwdread.c b/pwd/pwdread.c
deleted file mode 100644 (file)
index 1203236..0000000
+++ /dev/null
@@ -1,147 +0,0 @@
-/* Copyright (C) 1991, 1992, 1995 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 Library General Public License as
-published by the Free Software Foundation; either version 2 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
-Library General Public License for more details.
-
-You should have received a copy of the GNU Library General Public
-License along with the GNU C Library; see the file COPYING.LIB.  If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA.  */
-
-#include <ansidecl.h>
-#include <errno.h>
-#include <limits.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <pwd.h>
-#include <sys/types.h>
-
-
-/* This is the function that all the others are based on.
-   The format of the password file is known only here.  */
-
-/* Structure containing info kept by each __pwdread caller.  */
-typedef struct
-  {
-    char *buf;
-    size_t buflen;
-    struct passwd p;
-  } pwdread_info;
-
-
-/* Return a chunk of memory containing a pre-initialized `pwdread_info'.  */
-PTR
-DEFUN_VOID(__pwdalloc)
-{
-  pwdread_info *info = (PTR) malloc (sizeof(pwdread_info));
-  if (info == NULL)
-    return NULL;
-  info->buf = NULL;
-  info->buflen = 0;
-  return info;
-}
-
-/* Read a password entry from STREAM, filling in P.  */
-struct passwd *
-DEFUN(__pwdread, (stream, p), FILE *stream AND PTR CONST p)
-{
-  register pwdread_info *CONST info = (pwdread_info *) p;
-  char *start, *end;
-
-  /* Idiocy checks.  */
-  if (stream == NULL)
-    {
-      errno = EINVAL;
-      return NULL;
-    }
-
-  do
-    if (__getline (&info->buf, &info->buflen, stream) == -1)
-      return NULL;
-  while (info->buf[0] == '#');
-
-  start = info->buf;
-  end = strchr (start, ':');
-  if (end == NULL)
-    return NULL;
-  *end = '\0';
-  info->p.pw_name = start;
-
-  start = end + 1;
-  end = strchr (start, ':');
-  if (end == NULL)
-    return NULL;
-  *end = '\0';
-  info->p.pw_passwd = start;
-
-  info->p.pw_uid = (uid_t) strtol (end + 1, &end, 10);
-  if (*end != ':')
-    return NULL;
-  info->p.pw_gid = (gid_t) strtol (end + 1, &end, 10);
-  if (*end != ':')
-    return NULL;
-
-  start = end + 1;
-  end = strchr (start, ':');
-  if (end == NULL)
-    return NULL;
-  *end = '\0';
-  info->p.pw_gecos = start;
-
-  start = end + 1;
-  end = strchr (start, ':');
-  if (end == NULL)
-    return NULL;
-  *end = '\0';
-  info->p.pw_dir = start;
-
-  start = end + 1;
-  end = strchr (start, '\n');
-  if (end == NULL)
-    return NULL;
-  *end = '\0';
-  info->p.pw_shell = start;
-
-  return &info->p;
-}
-
-
-struct passwd *
-__pwdscan (void **info, int (*selector) (struct passwd *))
-{
-  FILE *stream;
-  struct passwd *p;
-
-  if (*info == NULL)
-    {
-      *info = __pwdalloc ();
-      if (info == NULL)
-       return NULL;
-    }
-
-  stream = __pwdopen ();
-  if (stream == NULL)
-    return NULL;
-
-  p = NULL;
-  while (! feof (stream))
-    {
-      p = __pwdread (stream, *info);
-      if (p && (*selector) (p))
-       break;
-      p = NULL;
-    }
-
-  (void) fclose (stream);
-  return p;
-}
index fc5650d..95b9eeb 100644 (file)
--- a/resolv.h
+++ b/resolv.h
@@ -1 +1 @@
-#include <inet/resolv.h>
+#include <resolv/resolv.h>
index 161060e..d3c45d0 100644 (file)
@@ -65,16 +65,12 @@ static char rcsid[] = "$Id$";
 #include <arpa/nameser.h>
 
 #include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
 #include <netdb.h>
 #include <resolv.h>
 #include <ctype.h>
 #include <errno.h>
 #include <syslog.h>
 
-#include "res_hconf.h"
-
 #ifndef LOG_AUTH
 # define LOG_AUTH 0
 #endif
@@ -98,7 +94,6 @@ static char rcsid[] = "$Id$";
 
 #define        MAXALIASES      35
 #define        MAXADDRS        35
-#define        MAXADDRBUFSIZE  8192
 
 static const char AskedForGot[] =
                          "gethostby*.getanswer: asked for \"%s\", got \"%s\"";
@@ -108,7 +103,7 @@ static struct hostent *gethostbyname_ipv4 __P((const char *));
 
 static struct hostent host;
 static char *host_aliases[MAXALIASES];
-static char hostbuf[MAXADDRBUFSIZE];
+static char hostbuf[8*1024];
 static u_char host_addr[16];   /* IPv4 or IPv6 */
 static FILE *hostf = NULL;
 static int stayopen = 0;
@@ -435,7 +430,7 @@ gethostbyname2(name, af)
        querybuf buf;
        register const char *cp;
        char *bp;
-       int i, n, size, type, len;
+       int n, size, type, len;
        extern struct hostent *_gethtbyname2();
 
        if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
@@ -506,55 +501,13 @@ gethostbyname2(name, af)
                                break;
                }
 
-       h_errno = HOST_NOT_FOUND;
-       for (i = 0; i < _res_hconf.num_services; ++i) {
-               struct hostent * hp;
-               char * cp = (char *) name;
-
-               if (_res_hconf.num_trimdomains > 0) {
-                       size_t name_len = strlen(name);
-
-                       cp = malloc(name_len + 1);
-                       memcpy(cp, name, name_len + 1);
-                       _res_hconf_trim_domain(cp);
-               }
-
-               hp = NULL;
-               switch (_res_hconf.service[i]) {
-                     case SERVICE_BIND:
-                       if ((n = res_search(cp, C_IN, type,
-                                           buf.buf, sizeof(buf))) < 0)
-                       {
-                               dprintf("res_search failed (%d)\n", n);
-                               break;
-                       }
-                       hp = getanswer(&buf, n, cp, type);
-                       break;
-
-                     case SERVICE_HOSTS:
-                       hp = _gethtbyname2(cp, af);
-                       break;
-#ifdef HAVE_NYS
-                     case SERVICE_NIS:
-                       hp = _getnishost(cp, "hosts.byname");
-                       break;
-#endif
-                     default:
-                       break;
-               }
-               if (cp != name)
-                       free(cp);
-               if (hp) {
-                       if ((_res_hconf.flags & HCONF_FLAG_REORDER)
-                           && hp->h_addr_list[0] && hp->h_addr_list[1])
-                               _res_hconf_reorder_addrs(hp);
-                       _res_hconf_trim_domains(hp);
-                       return hp;
-               }
+       if ((n = res_search(name, C_IN, type, buf.buf, sizeof(buf))) < 0) {
+               dprintf("res_search failed (%d)\n", n);
+               if (errno == ECONNREFUSED)
+                       return (_gethtbyname2(name, af));
+               return (NULL);
        }
-       if (h_errno == NETDB_SUCCESS)
-               h_errno = HOST_NOT_FOUND;
-       return NULL;
+       return (getanswer(&buf, n, name, type));
 }
 
 struct hostent *
@@ -569,11 +522,12 @@ gethostbyaddr(addr, len, af)
        querybuf buf;
        register struct hostent *hp;
        char qbuf[MAXDNAME+1], *qp;
+#ifdef SUNSECURITY
        register struct hostent *rhp;
        char **haddr;
        u_long old_options;
        char hname2[MAXDNAME+1];
-       int i, old_num_trimdomains;
+#endif /*SUNSECURITY*/
        extern struct hostent *_gethtbyaddr();
 
        if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
@@ -606,130 +560,79 @@ gethostbyaddr(addr, len, af)
                h_errno = NETDB_INTERNAL;
                return (NULL);
        }
-
-       h_errno = NETDB_SUCCESS;
-       for (i = 0; i < _res_hconf.num_services; ++i) {
-               hp = NULL;
-               switch (_res_hconf.service[i]) {
-               case SERVICE_BIND:
-                       switch (af) {
-                       case AF_INET:
-                               (void) sprintf(qbuf,
-                                              "%u.%u.%u.%u.in-addr.arpa",
-                                              (uaddr[3] & 0xff),
-                                              (uaddr[2] & 0xff),
-                                              (uaddr[1] & 0xff),
-                                              (uaddr[0] & 0xff));
-                               break;
-                       case AF_INET6:
-                               qp = qbuf;
-                               for (n = IN6ADDRSZ - 1; n >= 0; n--) {
-                                       qp += SPRINTF((qp, "%x.%x.",
-                                                      uaddr[n] & 0xf,
-                                                      (uaddr[n] >> 4) & 0xf));
-                               }
-                               strcpy(qp, "ip6.int");
-                               break;
-                       default:
-                               abort();
-                       }
-                       n = res_query(qbuf, C_IN, T_PTR,
-                                     (u_char *)buf.buf, sizeof buf.buf);
-                       if (n < 0) {
-                               dprintf("res_query failed (%d)\n", n);
-                               break;
-                       }
-                       hp = getanswer(&buf, n, qbuf, T_PTR);
-                       if (!hp)
-                               break;  /* h_errno was set by getanswer() */
-                       if (af == AF_INET
-                           && (_res_hconf.flags & HCONF_FLAG_SPOOF)) {
-                               /*
-                                * Turn off search as the name should
-                                * be absolute, 'localhost' should be
-                                * matched by defnames
-                                */
-                               strncpy(hname2, hp->h_name, MAXDNAME);
-                               hname2[MAXDNAME] = '\0';
-                               old_options = _res.options;
-                               /*
-                                * Also turn off domain trimming to prevent it
-                                * from causing the name comparison to fail.
-                                */
-                               old_num_trimdomains =
-                                       _res_hconf.num_trimdomains;
-                               _res.options &= ~RES_DNSRCH;
-                               _res.options |= RES_DEFNAMES;
-                               rhp = gethostbyname(hname2);
-                               _res.options = old_options;
-                               /* There must be an A record and
-                                  the names must match.  */
-                               if (!rhp || strcmp(hname2, rhp->h_name)) {
-                                       syslog(LOG_NOTICE|LOG_AUTH,
-                                              "gethostbyaddr: No A record for"
-                                              " %s (verifying [%s])",
-                                              hname2,
-                                              inet_ntoa(*((struct in_addr *)
-                                                          addr)));
-                                       h_errno = HOST_NOT_FOUND;
-                                       break;
-                               }
-                               for (haddr = rhp->h_addr_list; *haddr; haddr++)
-                                       if (!memcmp(*haddr, addr, INADDRSZ))
-                                               break;
-                               if (!*haddr) {
-                                       syslog(LOG_NOTICE|LOG_AUTH,
-                                              "gethostbyaddr: A record of %s"
-                                              " != PTR record [%s]",
-                                              hname2,
-                                              inet_ntoa(*((struct in_addr *)
-                                                          addr)));
-                                       h_errno = HOST_NOT_FOUND;
-                                       break;
-                               }
-                       }
-                       hp->h_addrtype = af;
-                       hp->h_length = len;
-                       bcopy(addr, host_addr, len);
-                       h_addr_ptrs[0] = (char *)host_addr;
-                       h_addr_ptrs[1] = NULL;
-                       if (af == AF_INET && (_res.options & RES_USE_INET6)) {
-                               map_v4v6_address((char*)host_addr,
-                                                (char*)host_addr);
-                               hp->h_addrtype = AF_INET6;
-                               hp->h_length = IN6ADDRSZ;
-                       }
-                       h_errno = NETDB_SUCCESS;
-                       break;
-
-               case SERVICE_HOSTS:
-                       hp = _gethtbyaddr(addr, len, af);
-                       break;
-
-#ifdef HAVE_NYS
-               case SERVICE_NIS:
-                       if (af == AF_INET) {
-                               sprintf(qbuf, "%u.%u.%u.%u",
-                                       (unsigned)addr[0] & 0xff,
-                                       (unsigned)addr[1] & 0xff,
-                                       (unsigned)addr[2] & 0xff,
-                                       (unsigned)addr[3] & 0xff);
-                               hp = _getnishost(qbuf, "hosts.byaddr");
-                       }
-                       break;
-#endif
-
-               default:
-                       break;
-               }
-               if (hp) {
-                       _res_hconf_trim_domains(hp);
-                       return hp;
+       switch (af) {
+       case AF_INET:
+               (void) sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa",
+                              (uaddr[3] & 0xff),
+                              (uaddr[2] & 0xff),
+                              (uaddr[1] & 0xff),
+                              (uaddr[0] & 0xff));
+               break;
+       case AF_INET6:
+               qp = qbuf;
+               for (n = IN6ADDRSZ - 1; n >= 0; n--) {
+                       qp += SPRINTF((qp, "%x.%x.",
+                                      uaddr[n] & 0xf,
+                                      (uaddr[n] >> 4) & 0xf));
                }
+               strcpy(qp, "ip6.int");
+               break;
+       default:
+               abort();
+       }
+       n = res_query(qbuf, C_IN, T_PTR, (u_char *)buf.buf, sizeof buf.buf);
+       if (n < 0) {
+               dprintf("res_query failed (%d)\n", n);
+               if (errno == ECONNREFUSED)
+                       return (_gethtbyaddr(addr, len, af));
+               return (NULL);
        }
-       if (h_errno == NETDB_SUCCESS)
+       if (!(hp = getanswer(&buf, n, qbuf, T_PTR)))
+               return (NULL);  /* h_errno was set by getanswer() */
+#ifdef SUNSECURITY
+       if (af == AF_INET) {
+           /*
+            * turn off search as the name should be absolute,
+            * 'localhost' should be matched by defnames
+            */
+           strncpy(hname2, hp->h_name, MAXDNAME);
+           hname2[MAXDNAME] = '\0';
+           old_options = _res.options;
+           _res.options &= ~RES_DNSRCH;
+           _res.options |= RES_DEFNAMES;
+           if (!(rhp = gethostbyname(hname2))) {
+               syslog(LOG_NOTICE|LOG_AUTH,
+                      "gethostbyaddr: No A record for %s (verifying [%s])",
+                      hname2, inet_ntoa(*((struct in_addr *)addr)));
+               _res.options = old_options;
+               h_errno = HOST_NOT_FOUND;
+               return (NULL);
+           }
+           _res.options = old_options;
+           for (haddr = rhp->h_addr_list; *haddr; haddr++)
+               if (!memcmp(*haddr, addr, INADDRSZ))
+                       break;
+           if (!*haddr) {
+               syslog(LOG_NOTICE|LOG_AUTH,
+                      "gethostbyaddr: A record of %s != PTR record [%s]",
+                      hname2, inet_ntoa(*((struct in_addr *)addr)));
                h_errno = HOST_NOT_FOUND;
-       return NULL;
+               return (NULL);
+           }
+       }
+#endif /*SUNSECURITY*/
+       hp->h_addrtype = af;
+       hp->h_length = len;
+       bcopy(addr, host_addr, len);
+       h_addr_ptrs[0] = (char *)host_addr;
+       h_addr_ptrs[1] = NULL;
+       if (af == AF_INET && (_res.options & RES_USE_INET6)) {
+               map_v4v6_address((char*)host_addr, (char*)host_addr);
+               hp->h_addrtype = AF_INET6;
+               hp->h_length = IN6ADDRSZ;
+       }
+       h_errno = NETDB_SUCCESS;
+       return (hp);
 }
 
 void
@@ -824,44 +727,6 @@ _gethtent()
        return (&host);
 }
 
-struct hstorage {
-       char    *name;                          /* canonical name */
-       char ** alp;                            /* address list pointer */
-       char *  abp;                            /* address buffer pointer */
-       char *  addr_list[MAXADDRS + 1];        /* address list storage */
-       char    addr_buf[MAXADDRBUFSIZE];       /* addresses storage */
-};
-
-static void
-append_addr (struct hstorage * hs, struct hostent *p)
-{
-       if (hs->alp < hs->addr_list + MAXADDRS
-           && hs->abp + p->h_length < hs->addr_buf + MAXADDRBUFSIZE)
-       {
-               hs->alp[0] = hs->abp;
-               hs->alp[1] = 0;
-               memcpy(hs->abp, p->h_addr_list[0], p->h_length);
-               hs->abp += p->h_length;
-               ++hs->alp;
-       }
-}
-
-/*
- * Lookup IP address and aliases for host NAME.  If multiaddress mode
- * is enabled, the entire /etc/hosts file is searched and the union of
- * all addresses found for NAME is returned (this may be slow with
- * large /etc/hosts files, but is convenient for smallish sites that
- * don't want to go through the complexity of running named locally).
- * If multiaddress mode is enabled, the address returned in
- * h_addr_list[0] is one that is on the same net as one of the host's
- * local addresses (if such an address exists).  For compatibility
- * with the BIND version of gethostbyname(), the alias field is empty
- * unless the name being looked up is an alias itself.  In the latter
- * case, the name field contains the canonical name and the alias
- * field the name that is being looked up.  A difference from the BIND
- * version is that this is true even if the alias applies only to one
- * of the interfaces on the target host.o
- */
 struct hostent *
 _gethtbyname(name)
        const char *name;
@@ -886,163 +751,14 @@ _gethtbyname2(name, af)
        register char **cp;
 
        _sethtent(0);
-
-       if (_res_hconf.flags & HCONF_FLAG_MULTI) {
-               /*
-                * More statics; not pretty, but it would require
-                * interface changes to make these functions
-                * reentrant.
-                */
-               static char *aliases[2] = {0};
-               static struct hstorage self = {0}, target = {0};
-               static size_t self_name_size = 0; /* Allocated in self.name. */
-               static struct hostent ht;
-               int found;
-
-               if (aliases[0])
-                       free (aliases[0]);      /* Malloced in a prev call.  */
-               aliases[0] = aliases[1] = 0;
-
-               /* Get current host name in a large enough buffer.  */
-               do {
-                          errno = 0;
-
-                          if (self.name)
-                          {
-                                  self_name_size += self_name_size;
-                                  self.name =
-                                          realloc (self.name, self_name_size);
-                          } else {
-                                  self_name_size = 128; /* Initial guess */
-                                  self.name = malloc (self_name_size);
-                          }
-
-                          if (! self.name)
-                          {
-                                  errno = ENOMEM;
-                                  return 0;
-                          }
-                  } while ((gethostname(self.name, self_name_size) == 0
-                            && !memchr (self.name, '\0', self_name_size))
-                           || errno == ENAMETOOLONG);
-               
-               if (errno)
-                       /* gethostname failed, abort.  */
-               {
-                       free (self.name);
-                       self.name = 0;
-               }
-
-               self.alp = self.addr_list;
-               self.abp = self.addr_buf;
-
-               if (target.name)
-                       free (target.name);
-               target.name = strdup (name);
-
-               target.alp = target.addr_list;
-               target.abp = target.addr_buf;
-
-               _sethtent(0);
-               while ((p = _gethtent()) != 0) {
-                       found = 1;
-
-                       if (p->h_addrtype != af)
-                               continue;
-                       if (strcasecmp(p->h_name, name) != 0) {
-                               found = 0;
-                               for (cp = p->h_aliases; *cp; ++cp)
-                                       if (strcasecmp(*cp, name) == 0) {
-                                               found = 1;
-                                               if (!aliases[0]) {
-                                                       aliases[0] =
-                                                         target.name;
-                                                       target.name =
-                                                         strdup (p->h_name);
-                                               }
-                                               break;
-                                       }
-                       }
-                       if (found) {
-                               /* they better be all the same type and length! */
-                               ht.h_addrtype = p->h_addrtype;
-                               ht.h_length = p->h_length;
-                               append_addr(&target, p);
-                               /*
-                                * If the current hostentry is for the target host, we don't
-                                * check for the local host name.  This nicely optimizes the
-                                * case where NAME is a local name since address ordering
-                                * doesn't matter in that case.
-                                */
-                               continue;
-                       }
-                       found = 1;
-                       if (strcasecmp(p->h_name, self.name) != 0) {
-                               found = 0;
-                               for (cp = p->h_aliases; *cp; ++cp)
-                                       if (strcasecmp(*cp, self.name) == 0) {
-                                               found = 1;
-                                               break;
-                                       }
-                       }
-                       if (found) {
-                               append_addr(&self, p);
-                       }
-               }
-               _endhtent();
-
-               if (target.alp == target.addr_list)
-                       return NULL;            /* found nothing */
-
-               ht.h_aliases   = aliases;
-               ht.h_name      = target.name;
-               ht.h_addr_list = target.addr_list;
-               /*
-                * XXX (davidm) Isn't this subsumed by REORDER???
-                *
-                * Finding the `best' address is necessarily address
-                * specific.  For now, we do IPv4 addresses only.
-                */
-               if (af == AF_INET) {
-                       u_int32_t a1, a2, diff, mindiff = ~0;
-                       int i, j, bestaddr = 0;
-
-                       for (i = 0; self.addr_list[i]; ++i) {
-                               for (j = 0; target.addr_list[j]; ++j) {
-                                       memcpy(&a1, self.addr_list[i], 4);
-                                       memcpy(&a2, target.addr_list[j], 4);
-                                       a1 = ntohl(a1);
-                                       a2 = ntohl(a2);
-                                       diff = a1 ^ a2;
-                                       if (diff < mindiff) {
-                                               bestaddr = j;
-                                               mindiff = diff;
-                                       }
-                               }
-                       }
-                       if (bestaddr > 0) {
-                               char * tmp;
-
-                               tmp = target.addr_list[0];
-                               target.addr_list[0] = target.addr_list[bestaddr];
-                               target.addr_list[bestaddr] = tmp;
-                       }
-               } else if (af == AF_INET6) {
-                       /* XXX To do!!! */
-               }
-               ht.h_addr_list = target.addr_list;
-               return &ht;
-       } else {
-               _sethtent(0);
-               while (p = _gethtent()) {
-                       if (p->h_addrtype != af)
-                               continue;
-                       if (strcasecmp(p->h_name, name) == 0)
-                               break;
-                       for (cp = p->h_aliases; *cp != 0; cp++)
-                               if (strcasecmp(*cp, name) == 0)
-                                       goto found;
-               }
+       while (p = _gethtent()) {
+               if (p->h_addrtype != af)
+                       continue;
+               if (strcasecmp(p->h_name, name) == 0)
+                       break;
+               for (cp = p->h_aliases; *cp != 0; cp++)
+                       if (strcasecmp(*cp, name) == 0)
+                               goto found;
        }
  found:
        _endhtent();
@@ -1191,47 +907,7 @@ ht_gethostbyaddr(addr, len, af)
 struct hostent *
 gethostent()
 {
-       struct hostent * hp;
-       int i;
-
-       if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
-               h_errno = NETDB_INTERNAL;
-               return (NULL);
-       }
-
-       /*
-        * This doesn't look quite right.  Shouldn't we read one
-        * service until it returns 0, then move on to the next
-        * service?  If so, it requires adding some state and
-        * initializing that state in sethostent().
-        * (davidm@azstarnet.com)
-        */
-       for (i = 0; i < _res_hconf.num_services; ++i) {
-               hp = NULL;
-               switch (_res_hconf.service[i]) {
-                     case SERVICE_HOSTS:
-                       hp = _gethtent ();
-                       break;
-
-#ifdef HAVE_NYS
-                     case SERVICE_NIS:
-                       hp = _getnishost (NULL, "hosts.byname");
-                       break;
-#endif
-
-                     case SERVICE_BIND:
-                     default:
-                       break;
-               }
-               if (hp) {
-                       if ((_res_hconf.flags & HCONF_FLAG_REORDER)
-                           && hp->h_addr_list[0] && hp->h_addr_list[1])
-                               _res_hconf_reorder_addrs (hp);
-                       return hp;
-               }
-       }
-       h_errno = HOST_NOT_FOUND;
-       return NULL;
+       return (_gethtent());
 }
 
 void
diff --git a/resolv/getnetbyaddr.c b/resolv/getnetbyaddr.c
deleted file mode 100644 (file)
index 32513cc..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (c) 1983 Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getnetbyaddr.c     1.1 (Coimbra) 93/06/02";
-static char rcsid[] = "$Id$";
-#endif /* LIBC_SCCS and not lint */
-
-#include <netdb.h>
-
-extern int _net_stayopen;
-
-struct netent *
-_getnetbyaddr(net, type)
-       register unsigned long net;
-       register int type;
-{
-       register struct netent *p;
-
-       setnetent(_net_stayopen);
-       while (p = getnetent())
-               if (p->n_addrtype == type && p->n_net == net)
-                       break;
-       if (!_net_stayopen)
-               endnetent();
-       return (p);
-}
diff --git a/resolv/getnetbyname.c b/resolv/getnetbyname.c
deleted file mode 100644 (file)
index cc3f281..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (c) 1983, 1993
- *     The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getnetbyname.c     8.1 (Berkeley) 6/4/93";
-static char sccsid_[] = "from getnetbyname.c   1.1 (Coimbra) 93/06/02";
-static char rcsid[] = "$Id$";
-#endif /* LIBC_SCCS and not lint */
-
-#include <netdb.h>
-#include <string.h>
-
-extern int _net_stayopen;
-
-struct netent *
-_getnetbyname(name)
-       register const char *name;
-{
-       register struct netent *p;
-       register char **cp;
-
-       setnetent(_net_stayopen);
-       while (p = getnetent()) {
-               if (strcasecmp(p->n_name, name) == 0)
-                       break;
-               for (cp = p->n_aliases; *cp != 0; cp++)
-                       if (strcasecmp(*cp, name) == 0)
-                               goto found;
-       }
-found:
-       if (!_net_stayopen)
-               endnetent();
-       return (p);
-}
diff --git a/resolv/getnetent.c b/resolv/getnetent.c
deleted file mode 100644 (file)
index 7ec5607..0000000
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * Copyright (c) 1983 Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/* Portions Copyright (c) 1993 Carlos Leandro and Rui Salgueiro
- *     Dep. Matematica Universidade de Coimbra, Portugal, Europe
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * from getnetent.c    1.1 (Coimbra) 93/06/02
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getnetent.c        8.1 (Berkeley) 6/4/93";
-static char rcsid[] = "$Id$";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-
-#include <stdio.h>
-#include <resolv.h>
-#include <netdb.h>
-#include <string.h>
-
-#ifndef _PATH_NETWORKS 
-#define _PATH_NETWORKS  "/etc/networks"
-#endif
-
-#define        MAXALIASES      35
-
-static FILE *netf;
-static char line[BUFSIZ+1];
-static struct netent net;
-static char *net_aliases[MAXALIASES];
-int _net_stayopen;
-
-void _setnetent __P((int));
-void _endnetent __P((void));
-
-void
-setnetent(stayopen)
-       int stayopen;
-{
-
-       sethostent(stayopen);
-       _setnetent(stayopen);
-}
-
-void
-endnetent()
-{
-
-       endhostent();
-       _endnetent();
-}
-
-void
-_setnetent(f)
-       int f;
-{
-
-       if (netf == NULL)
-               netf = fopen(_PATH_NETWORKS, "r" );
-       else
-               rewind(netf);
-       _net_stayopen |= f;
-}
-
-void
-_endnetent()
-{
-
-       if (netf) {
-               fclose(netf);
-               netf = NULL;
-       }
-       _net_stayopen = 0;
-}
-
-struct netent *
-getnetent()
-{
-       char *p;
-       register char *cp, **q;
-
-       if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL)
-               return (NULL);
-again:
-       p = fgets(line, BUFSIZ, netf);
-       if (p == NULL)
-               return (NULL);
-       if (*p == '#')
-               goto again;
-       cp = strpbrk(p, "#\n");
-       if (cp == NULL)
-               goto again;
-       *cp = '\0';
-       net.n_name = p;
-       cp = strpbrk(p, " \t");
-       if (cp == NULL)
-               goto again;
-       *cp++ = '\0';
-       while (*cp == ' ' || *cp == '\t')
-               cp++;
-       p = strpbrk(cp, " \t");
-       if (p != NULL)
-               *p++ = '\0';
-       net.n_net = inet_network(cp);
-       net.n_addrtype = AF_INET;
-       q = net.n_aliases = net_aliases;
-       if (p != NULL) {
-               cp = p;
-               while (cp && *cp) {
-                       if (*cp == ' ' || *cp == '\t') {
-                               cp++;
-                               continue;
-                       }
-                       if (q < &net_aliases[MAXALIASES - 1])
-                               *q++ = cp;
-                       cp = strpbrk(cp, " \t");
-                       if (cp != NULL)
-                               *cp++ = '\0';
-               }
-       }
-       *q = NULL;
-       return (&net);
-}
index cfc069d..d0d45ae 100644 (file)
@@ -59,7 +59,7 @@ inet_pton(af, src, dst)
        case AF_INET6:
                return (inet_pton6(src, dst));
        default:
-               errno = EINVAL;
+               errno = EAFNOSUPPORT;
                return (-1);
        }
        /* NOTREACHED */
diff --git a/resolv/mapv4v6addr.h b/resolv/mapv4v6addr.h
new file mode 100644 (file)
index 0000000..4295398
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * ++Copyright++ 1985, 1988, 1993
+ * -
+ * Copyright (c) 1985, 1988, 1993
+ *    The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed by the University of
+ *      California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+#include <string.h>
+#include <arpa/nameser.h>
+
+static void
+map_v4v6_address (const char *src, char *dst)
+{
+  u_char *p = (u_char *) dst;
+  char tmp[INADDRSZ];
+  int i;
+
+  /* Stash a temporary copy so our caller can update in place. */
+  bcopy (src, tmp, INADDRSZ);
+  /* Mark this ipv6 addr as a mapped ipv4. */
+  for (i = 0; i < 10; i++)
+    *p++ = 0x00;
+  *p++ = 0xff;
+  *p++ = 0xff;
+  /* Retrieve the saved copy and we're done. */
+  bcopy (tmp, (void *) p, INADDRSZ);
+}
diff --git a/resolv/mapv4v6hostent.h b/resolv/mapv4v6hostent.h
new file mode 100644 (file)
index 0000000..c3fb8b5
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * ++Copyright++ 1985, 1988, 1993
+ * -
+ * Copyright (c) 1985, 1988, 1993
+ *    The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed by the University of
+ *      California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
+ */
+
+#include <arpa/nameser.h>
+#include <sys/socket.h>
+
+typedef union {
+    int32_t al;
+    char ac;
+} align;
+
+static void
+map_v4v6_hostent (struct hostent *hp, char **bpp, int *lenp)
+{
+  char **ap;
+
+  if (hp->h_addrtype != AF_INET || hp->h_length != INADDRSZ)
+    return;
+  hp->h_addrtype = AF_INET6;
+  hp->h_length = IN6ADDRSZ;
+  for (ap = hp->h_addr_list; *ap; ap++)
+    {
+      int i = sizeof (align) - ((u_long) *bpp % sizeof (align));
+
+      if (*lenp < (i + IN6ADDRSZ))
+       {
+         /* Out of memory.  Truncate address list here.  XXX */
+         *ap = NULL;
+         return;
+       }
+      *bpp += i;
+      *lenp -= i;
+      map_v4v6_address (*ap, *bpp);
+      *ap = *bpp;
+      *bpp += IN6ADDRSZ;
+      *lenp -= IN6ADDRSZ;
+    }
+}
index fd06e17..38367e3 100644 (file)
 #endif
 #include <sys/cdefs.h>
 
-#define        _PATH_HEQUIV    "/etc/hosts.equiv"
-#define        _PATH_HOSTS     "/etc/hosts"
-#define        _PATH_NETWORKS  "/etc/networks"
-#define        _PATH_PROTOCOLS "/etc/protocols"
-#define        _PATH_SERVICES  "/etc/services"
+#define        _PATH_HEQUIV            "/etc/hosts.equiv"
+#define        _PATH_HOSTS             "/etc/hosts"
+#define        _PATH_NETWORKS          "/etc/networks"
+#define        _PATH_NSSWITCH_CONF     "/etc/nsswitch.conf"
+#define        _PATH_PROTOCOLS         "/etc/protocols"
+#define        _PATH_SERVICES          "/etc/services"
 
 extern int h_errno;
 
index 4e8af68..305dabf 100644 (file)
@@ -76,8 +76,6 @@ static char rcsid[] = "$Id$";
 # include "../conf/portability.h"
 #endif
 
-#include "res_hconf.h"
-
 /*-------------------------------------- info about "sortlist" --------------
  * Marc Majka          1994/04/16
  * Allan Nathanson     1994/10/29 (BIND 4.9.3.x)
@@ -421,8 +419,6 @@ res_init()
        if ((cp = getenv("RES_OPTIONS")) != NULL)
                res_setoptions(cp, "env");
        _res.options |= RES_INIT;
-
-       _res_hconf_init ();
        return (0);
 }
 
diff --git a/resolv/sethostent.c b/resolv/sethostent.c
deleted file mode 100644 (file)
index e7a59dd..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (c) 1985, 1993
- *     The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)sethostent.c       8.1 (Berkeley) 6/4/93";
-static char rcsid[] = "$Id$";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/param.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <netdb.h>
-#include <resolv.h>
-
-void _res_close __P((void));
-
-void
-sethostent(stayopen)
-       int stayopen;
-{
-       if ((_res.options & RES_INIT) == 0 && res_init() == -1)
-               return;
-       if (stayopen)
-               _res.options |= RES_STAYOPEN | RES_USEVC;
-}
-
-void
-endhostent()
-{
-       _res.options &= ~(RES_STAYOPEN | RES_USEVC);
-       _res_close();
-}
index 535e14e..36e91b9 100644 (file)
@@ -64,11 +64,13 @@ $(config): template $(distinfo) Makefile
        rm -f $@.new
        (sed -e 's%@VERSION@%$(version)%g' $<; \
         ($(foreach var,$(instvars),\
-         for f in $(install-$(var)); do \
+         list='$(install-$(var))'; \
+         for f in $$list; do \
            echo $(filter-out /,$($(var)dir)/)$$f; \
          done;\
         )) | sort; \
-        (for f in $(install-sysconf); do \
+        (list='$(install-sysconf)'; \
+         for f in $$list; do \
            echo %config $$f; \
          done) | sort) > $@.new
        mv -f $@.new $@
index 2b92f95..1bf19da 100644 (file)
@@ -30,3 +30,13 @@ alpha-*-linux*               libc=6
 # So far the -lutil interface is the same on all platforms, except for the
 # `struct utmp' format, which depends on libc.
 *-*-*                  libutil=1
+
+# Version number 2 is used on other systems for the BIND 4.9.4 resolver
+# interface.
+*-*-*                  libresolv=2
+
+# Interface revision of nss_* modules.  This must match NSS_SHLIB_REVISION
+# in nss/nsswitch.h, which determines the library names used for service
+# names given in /etc/nsswitch.conf.
+*-*-*                  libnss_files=1
+*-*-*                  libnss_dns=1
index 27c85cf..d7101fe 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 1994, 1995 Free Software Foundation, Inc.
+# Copyright (C) 1994, 1995, 1996 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
@@ -57,7 +57,7 @@ generated = $(rpcsvc:%.x=rpcsvc/%.h) $(rpcsvc:%.x=x%.c)
 
 routines := auth_none auth_unix authuxprot bindrsvprt \
            clnt_gen clnt_perr clnt_raw clnt_simp clnt_tcp \
-           clnt_udp rpc_dtable get_myaddr getrpcent getrpcport \
+           clnt_udp rpc_dtable get_myaddr getrpcport \
            pmap_clnt pm_getmaps pm_getport pmap_prot \
            pmap_prot2 pmap_rmt rpc_prot rpc_common rpc_cmsg \
            svc svc_auth svc_authux svc_raw svc_run svc_simple \
diff --git a/sunrpc/getrpcent.c b/sunrpc/getrpcent.c
deleted file mode 100644 (file)
index 0fc7aff..0000000
+++ /dev/null
@@ -1,217 +0,0 @@
-/* @(#)getrpcent.c     2.2 88/07/29 4.0 RPCSRC */
-#if !defined(lint) && defined(SCCSIDS)
-static  char sccsid[] = "@(#)getrpcent.c 1.9 87/08/11  Copyr 1984 Sun Micro";
-#endif
-
-/*
- * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
- * unrestricted use provided that this legend is included on all tape
- * media and as a part of the software program in whole or part.  Users
- * may copy or modify Sun RPC without charge, but are not authorized
- * to license or distribute it to anyone else except as part of a product or
- * program developed by the user.
- * 
- * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
- * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
- * 
- * Sun RPC is provided with no support and without any obligation on the
- * part of Sun Microsystems, Inc. to assist in its use, correction,
- * modification or enhancement.
- * 
- * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
- * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
- * OR ANY PART THEREOF.
- * 
- * In no event will Sun Microsystems, Inc. be liable for any lost revenue
- * or profits or other special, indirect and consequential damages, even if
- * Sun has been advised of the possibility of such damages.
- * 
- * Sun Microsystems, Inc.
- * 2550 Garcia Avenue
- * Mountain View, California  94043
- */
-
-/*
- * Copyright (c) 1985 by Sun Microsystems, Inc.
- */
-
-#include <stdio.h>
-#include <sys/types.h>
-#include <rpc/rpc.h>
-#include <netdb.h>
-#include <sys/socket.h>
-
-/*
- * Internet version.
- */
-struct rpcdata {
-       FILE    *rpcf;
-       char    *current;
-       int     currentlen;
-       int     stayopen;
-#define        MAXALIASES      35
-       char    *rpc_aliases[MAXALIASES];
-       struct  rpcent rpc;
-       char    line[BUFSIZ+1];
-       char    *domain;
-} *rpcdata, *_rpcdata();
-
-static struct rpcent *interpret();
-struct hostent *gethostent();
-char   *inet_ntoa();
-extern char *index();          /* Changed from static by roland@gnu */
-
-static char RPCDB[] = _PATH_RPC; /* Changed from "/etc/rpc" by roland@gnu */
-
-static struct rpcdata *
-_rpcdata()
-{
-       register struct rpcdata *d = rpcdata;
-
-       if (d == 0) {
-               d = (struct rpcdata *)calloc(1, sizeof (struct rpcdata));
-               rpcdata = d;
-       }
-       return (d);
-}
-
-struct rpcent *
-getrpcbynumber(number)
-       register int number;
-{
-       register struct rpcdata *d = _rpcdata();
-       register struct rpcent *p;
-       int reason;
-       char adrstr[16], *val = NULL;
-       int vallen;
-
-       if (d == 0)
-               return (0);
-       setrpcent(0);
-       while (p = getrpcent()) {
-               if (p->r_number == number)
-                       break;
-       }
-       endrpcent();
-       return (p);
-}
-
-struct rpcent *
-getrpcbyname(name)
-     const char *name;         /* const added by roland@gnu */
-{
-       struct rpcent *rpc;
-       char **rp;
-
-       setrpcent(0);
-       while(rpc = getrpcent()) {
-               if (strcmp(rpc->r_name, name) == 0)
-                       return (rpc);
-               for (rp = rpc->r_aliases; *rp != NULL; rp++) {
-                       if (strcmp(*rp, name) == 0)
-                               return (rpc);
-               }
-       }
-       endrpcent();
-       return (NULL);
-}
-
-setrpcent(f)
-       int f;
-{
-       register struct rpcdata *d = _rpcdata();
-
-       if (d == 0)
-               return;
-       if (d->rpcf == NULL)
-               d->rpcf = fopen(RPCDB, "r");
-       else
-               rewind(d->rpcf);
-       if (d->current)
-               free(d->current);
-       d->current = NULL;
-       d->stayopen |= f;
-}
-
-endrpcent()
-{
-       register struct rpcdata *d = _rpcdata();
-
-       if (d == 0)
-               return;
-       if (d->current && !d->stayopen) {
-               free(d->current);
-               d->current = NULL;
-       }
-       if (d->rpcf && !d->stayopen) {
-               fclose(d->rpcf);
-               d->rpcf = NULL;
-       }
-}
-
-struct rpcent *
-getrpcent()
-{
-       struct rpcent *hp;
-       int reason;
-       char *key = NULL, *val = NULL;
-       int keylen, vallen;
-       register struct rpcdata *d = _rpcdata();
-
-       if (d == 0)
-               return(NULL);
-       if (d->rpcf == NULL && (d->rpcf = fopen(RPCDB, "r")) == NULL)
-               return (NULL);
-       if (fgets(d->line, BUFSIZ, d->rpcf) == NULL)
-               return (NULL);
-       return interpret(d->line, strlen(d->line));
-}
-
-static struct rpcent *
-interpret(val, len)
-       char * val;
-       size_t len;
-{
-       register struct rpcdata *d = _rpcdata();
-       char *p;
-       register char *cp, **q;
-
-       if (d == 0)
-               return;
-       strncpy(d->line, val, len);
-       p = d->line;
-       d->line[len] = '\n';
-       if (*p == '#')
-               return (getrpcent());
-       cp = strpbrk(p, "#\n");
-       if (cp == NULL)
-               return (getrpcent());
-       *cp = '\0';
-       cp = strpbrk(p, " \t");
-       if (cp == NULL)
-               return (getrpcent());
-       *cp++ = '\0';
-       /* THIS STUFF IS INTERNET SPECIFIC */
-       d->rpc.r_name = d->line;
-       while (*cp == ' ' || *cp == '\t')
-               cp++;
-       d->rpc.r_number = atoi(cp);
-       q = d->rpc.r_aliases = d->rpc_aliases;
-       cp = strpbrk(p, " \t");
-       if (cp != NULL)
-               *cp++ = '\0';
-       while (cp && *cp) {
-               if (*cp == ' ' || *cp == '\t') {
-                       cp++;
-                       continue;
-               }
-               if (q < &(d->rpc_aliases[MAXALIASES - 1]))
-                       *q++ = cp;
-               cp = strpbrk(p, " \t");
-               if (cp != NULL)
-                       *cp++ = '\0';
-       }
-       *q = NULL;
-       return (&d->rpc);
-}
index 29c9a1d..f23efe7 100644 (file)
@@ -307,10 +307,8 @@ _dl_runtime_resolve:
        /* Set up the arguments for _dl_runtime_resolve. */
        /* $16 = link_map out of plt0 */
        ldq     $16, 8($27)
-       /* $17 = (($28 - 4) - ($27 + 16)) / 12 * sizeof(Elf_Rela) */
-       subq    $28, $27, $28
-       subq    $28, 20, $28
-       addq    $28, $28, $17
+       /* $17 = offset of reloc entry */
+       mov     $28, $17
        /* Do the fixup */
        bsr     $26, fixup..ng
        /* Move the destination address to a safe place.  */
index f1bf761..d77c6c5 100644 (file)
@@ -119,6 +119,7 @@ target-zone-flavor = $(filter /posix /right, \
 
 ifdef localtime
 $(installed-localtime-file): $(zonedir)/$(localtime) $(objpfx)zic
+       $(make-target-directory)
        if test -r $@; then echo Site timezone NOT reset to Factory.; else \
        ln -s -f $< $@; fi
 endif