From ed5d57202ebab0e923eb8e9d967a9f97792a6e8f Mon Sep 17 00:00:00 2001 From: Peter Avalos Date: Sun, 21 Dec 2008 21:24:07 -0500 Subject: [PATCH] Add nsswitch support. The nsswitch.conf(5) manual page has a description of nsswitch. Curiously, we already had this manual page, even though we didn't support it. /etc/host.conf is removed from src/, but if host.conf exists and nsswitch.conf does not, nsswitch.conf will be created using its contents. Included in this commit is a framework for nsswitch caching, nscd(8), but it relies on a few upcoming changes to our libc before it will work. For now, it's turned off. Also this commit includes hesiod support which is not compiled by default. Add WANT_HESIOD=true to make.conf to get it working. Obtained-from: FreeBSD --- Makefile.inc1 | 2 +- etc/Makefile | 4 +- etc/defaults/make.conf | 7 + etc/defaults/rc.conf | 1 + etc/host.conf | 8 - etc/hosts | 4 +- etc/nscd.conf | 12 + etc/rc.d/Makefile | 3 +- etc/rc.d/nscd | 52 + etc/rc.d/nsswitch | 165 ++ include/Makefile | 6 +- include/dlfcn.h | 31 +- include/grp.h | 33 +- include/hesiod.h | 98 + include/netdb.h | 10 - include/nss.h | 57 + include/nsswitch.h | 250 ++ include/pwd.h | 80 +- include/rpc/rpcent.h | 12 +- include/stdlib.h | 2 - lib/libc/Makefile.inc | 7 + lib/libc/gen/Makefile.inc | 8 +- lib/libc/gen/dlfunc.c | 29 + lib/libc/gen/dlopen.3 | 2 + lib/libc/gen/getgrent.3 | 150 +- lib/libc/gen/getgrent.c | 1817 +++++++++--- lib/libc/gen/getgrouplist.c | 52 +- lib/libc/gen/getpwent.3 | 153 +- lib/libc/gen/getpwent.c | 2487 ++++++++++++----- lib/libc/gen/getusershell.3 | 14 +- lib/libc/gen/getusershell.c | 231 +- {usr.sbin/pwd_mkdb => lib/libc/gen}/pw_scan.c | 102 +- {usr.sbin/pwd_mkdb => lib/libc/gen}/pw_scan.h | 14 +- lib/libc/gen/pwcache.3 | 19 +- lib/libc/gen/pwcache.c | 8 +- lib/libc/include/namespace.h | 6 + lib/libc/include/nscache.h | 197 ++ lib/libc/include/nscachedcli.h | 107 + lib/libc/include/nss_tls.h | 80 + lib/libc/include/un-namespace.h | 2 + lib/libc/net/Makefile.inc | 28 +- lib/libc/net/getaddrinfo.c | 607 ++-- lib/libc/net/gethostbydns.c | 69 +- lib/libc/net/gethostbyht.c | 31 +- lib/libc/net/gethostbyname.3 | 17 +- lib/libc/net/gethostbynis.c | 63 +- lib/libc/net/gethostnamadr.c | 456 ++- lib/libc/net/getipnodebyname.3 | 5 +- lib/libc/net/getnetbydns.c | 49 +- lib/libc/net/getnetbyht.c | 24 +- lib/libc/net/getnetbynis.c | 50 +- lib/libc/net/getnetent.3 | 20 +- lib/libc/net/getnetnamadr.c | 170 +- lib/libc/net/getproto.c | 108 +- lib/libc/net/getprotoent.c | 498 +++- lib/libc/net/getprotoname.c | 113 +- lib/libc/net/getservbyname.c | 73 - lib/libc/net/getservent.c | 1272 +++++++-- lib/libc/net/hesiod.3 | 176 ++ lib/libc/net/hesiod.c | 560 ++++ lib/libc/net/name6.c | 545 +++- lib/libc/net/netdb_private.h | 145 + lib/libc/net/nscache.c | 436 +++ lib/libc/net/nscachedcli.c | 574 ++++ lib/libc/net/nsdispatch.3 | 258 ++ lib/libc/net/nsdispatch.c | 744 +++++ lib/libc/net/nslexer.l | 115 + lib/libc/net/nsparser.y | 182 ++ lib/libc/net/{getproto.c => nss_backends.h} | 50 +- lib/libc/net/nss_compat.c | 278 ++ lib/libc/rpc/getrpcent.c | 1154 ++++++-- share/man/man5/Makefile | 4 + share/man/man5/group.5 | 45 +- share/man/man5/hesiod.conf.5 | 80 + share/man/man5/hosts.5 | 12 +- share/man/man5/make.conf.5 | 11 + share/man/man5/nsswitch.conf.5 | 174 +- share/man/man5/passwd.5 | 912 ++---- share/man/man8/yp.8 | 35 +- usr.bin/Makefile | 4 + usr.bin/chpass/chpass.c | 2 +- usr.bin/chpass/edit.c | 2 +- usr.bin/chpass/pw_copy.c | 2 +- usr.bin/hesinfo/Makefile | 5 + usr.bin/hesinfo/hesinfo.1 | 198 ++ usr.bin/hesinfo/hesinfo.c | 106 + usr.bin/passwd/Makefile | 6 +- usr.sbin/Makefile | 5 + usr.sbin/nscd/Makefile | 17 + usr.sbin/nscd/agent.c | 124 + usr.sbin/nscd/agent.h | 72 + usr.sbin/nscd/agents/Makefile.inc | 3 + usr.sbin/nscd/agents/group.c | 257 ++ .../nscd/agents/group.h | 35 +- usr.sbin/nscd/agents/passwd.c | 264 ++ .../nscd/agents/passwd.h | 35 +- usr.sbin/nscd/agents/services.c | 278 ++ .../nscd/agents/services.h | 35 +- usr.sbin/nscd/cachelib.c | 1216 ++++++++ usr.sbin/nscd/cachelib.h | 281 ++ usr.sbin/nscd/cacheplcs.c | 584 ++++ usr.sbin/nscd/cacheplcs.h | 137 + usr.sbin/nscd/config.c | 577 ++++ usr.sbin/nscd/config.h | 156 ++ usr.sbin/nscd/debug.c | 147 + usr.sbin/nscd/debug.h | 67 + usr.sbin/nscd/hashtable.h | 216 ++ usr.sbin/nscd/log.c | 76 + .../net/getproto.c => usr.sbin/nscd/log.h | 42 +- usr.sbin/nscd/mp_rs_query.c | 533 ++++ .../getproto.c => usr.sbin/nscd/mp_rs_query.h | 35 +- usr.sbin/nscd/mp_ws_query.c | 543 ++++ .../getproto.c => usr.sbin/nscd/mp_ws_query.h | 37 +- usr.sbin/nscd/nscd.8 | 165 ++ usr.sbin/nscd/nscd.c | 867 ++++++ usr.sbin/nscd/nscd.conf.5 | 148 + usr.sbin/nscd/nscdcli.c | 281 ++ .../{pwd_mkdb/pw_scan.h => nscd/nscdcli.h} | 50 +- usr.sbin/nscd/parser.c | 472 ++++ .../getservbyport.c => usr.sbin/nscd/parser.h | 52 +- usr.sbin/nscd/protocol.c | 548 ++++ usr.sbin/nscd/protocol.h | 265 ++ usr.sbin/nscd/query.c | 1266 +++++++++ usr.sbin/nscd/query.h | 108 + .../getproto.c => usr.sbin/nscd/singletons.c | 37 +- .../getproto.c => usr.sbin/nscd/singletons.h | 46 +- usr.sbin/pwd_mkdb/Makefile | 11 +- usr.sbin/pwd_mkdb/pwd_mkdb.8 | 41 +- usr.sbin/pwd_mkdb/pwd_mkdb.c | 297 +- usr.sbin/rarpd/Makefile | 2 - usr.sbin/rarpd/rarpd.8 | 21 +- usr.sbin/rarpd/rarpd.c | 351 +-- usr.sbin/ypserv/ypserv.8 | 4 +- 133 files changed, 23677 insertions(+), 3917 deletions(-) delete mode 100644 etc/host.conf create mode 100644 etc/nscd.conf create mode 100644 etc/rc.d/nscd create mode 100644 etc/rc.d/nsswitch create mode 100644 include/hesiod.h create mode 100644 include/nss.h create mode 100644 include/nsswitch.h create mode 100644 lib/libc/gen/dlfunc.c rename {usr.sbin/pwd_mkdb => lib/libc/gen}/pw_scan.c (65%) copy {usr.sbin/pwd_mkdb => lib/libc/gen}/pw_scan.h (78%) create mode 100644 lib/libc/include/nscache.h create mode 100644 lib/libc/include/nscachedcli.h create mode 100644 lib/libc/include/nss_tls.h delete mode 100644 lib/libc/net/getservbyname.c create mode 100644 lib/libc/net/hesiod.3 create mode 100644 lib/libc/net/hesiod.c create mode 100644 lib/libc/net/netdb_private.h create mode 100644 lib/libc/net/nscache.c create mode 100644 lib/libc/net/nscachedcli.c create mode 100644 lib/libc/net/nsdispatch.3 create mode 100644 lib/libc/net/nsdispatch.c create mode 100644 lib/libc/net/nslexer.l create mode 100644 lib/libc/net/nsparser.y copy lib/libc/net/{getproto.c => nss_backends.h} (54%) create mode 100644 lib/libc/net/nss_compat.c create mode 100644 share/man/man5/hesiod.conf.5 create mode 100644 usr.bin/hesinfo/Makefile create mode 100644 usr.bin/hesinfo/hesinfo.1 create mode 100644 usr.bin/hesinfo/hesinfo.c create mode 100644 usr.sbin/nscd/Makefile create mode 100644 usr.sbin/nscd/agent.c create mode 100644 usr.sbin/nscd/agent.h create mode 100644 usr.sbin/nscd/agents/Makefile.inc create mode 100644 usr.sbin/nscd/agents/group.c copy lib/libc/net/getproto.c => usr.sbin/nscd/agents/group.h (57%) create mode 100644 usr.sbin/nscd/agents/passwd.c copy lib/libc/net/getproto.c => usr.sbin/nscd/agents/passwd.h (57%) create mode 100644 usr.sbin/nscd/agents/services.c copy lib/libc/net/getproto.c => usr.sbin/nscd/agents/services.h (57%) create mode 100644 usr.sbin/nscd/cachelib.c create mode 100644 usr.sbin/nscd/cachelib.h create mode 100644 usr.sbin/nscd/cacheplcs.c create mode 100644 usr.sbin/nscd/cacheplcs.h create mode 100644 usr.sbin/nscd/config.c create mode 100644 usr.sbin/nscd/config.h create mode 100644 usr.sbin/nscd/debug.c create mode 100644 usr.sbin/nscd/debug.h create mode 100644 usr.sbin/nscd/hashtable.h create mode 100644 usr.sbin/nscd/log.c copy lib/libc/net/getproto.c => usr.sbin/nscd/log.h (54%) create mode 100644 usr.sbin/nscd/mp_rs_query.c copy lib/libc/net/getproto.c => usr.sbin/nscd/mp_rs_query.h (57%) create mode 100644 usr.sbin/nscd/mp_ws_query.c copy lib/libc/net/getproto.c => usr.sbin/nscd/mp_ws_query.h (57%) create mode 100644 usr.sbin/nscd/nscd.8 create mode 100644 usr.sbin/nscd/nscd.c create mode 100644 usr.sbin/nscd/nscd.conf.5 create mode 100644 usr.sbin/nscd/nscdcli.c rename usr.sbin/{pwd_mkdb/pw_scan.h => nscd/nscdcli.h} (52%) create mode 100644 usr.sbin/nscd/parser.c rename lib/libc/net/getservbyport.c => usr.sbin/nscd/parser.h (50%) create mode 100644 usr.sbin/nscd/protocol.c create mode 100644 usr.sbin/nscd/protocol.h create mode 100644 usr.sbin/nscd/query.c create mode 100644 usr.sbin/nscd/query.h copy lib/libc/net/getproto.c => usr.sbin/nscd/singletons.c (57%) copy lib/libc/net/getproto.c => usr.sbin/nscd/singletons.h (57%) diff --git a/Makefile.inc1 b/Makefile.inc1 index 0e35c04fab..57996893b2 100644 --- a/Makefile.inc1 +++ b/Makefile.inc1 @@ -762,7 +762,7 @@ bootstrap-tools: usr.bin/cmp usr.bin/xargs usr.bin/id usr.bin/env usr.bin/dirname \ usr.bin/tail \ usr.sbin/chown usr.sbin/mtree usr.sbin/config \ - usr.sbin/btxld usr.sbin/pwd_mkdb usr.sbin/zic usr.sbin/makewhatis \ + usr.sbin/btxld usr.sbin/zic usr.sbin/makewhatis \ gnu/usr.bin/texinfo gnu/usr.bin/grep gnu/usr.bin/sort \ usr.bin/gzip usr.bin/bzip2 usr.bin/mkcsmapper usr.bin/mkesdb ${ECHODIR} "===> ${_tool} (bootstrap-tools)"; \ diff --git a/etc/Makefile b/etc/Makefile index d0b07c2107..30d1010e05 100644 --- a/etc/Makefile +++ b/etc/Makefile @@ -28,10 +28,10 @@ BIN1= amd.map auth.conf \ crontab csh.cshrc csh.login csh.logout \ devd.conf devices.conf dhclient.conf dm.conf dntpd.conf \ ftpusers group \ - hosts hosts.allow host.conf hosts.equiv hosts.lpd \ + hosts hosts.allow hosts.equiv hosts.lpd \ inetd.conf login.access login.conf \ motd modems netconfig networks newsyslog.conf \ - pf.conf phones printcap profile \ + nscd.conf pf.conf phones printcap profile \ remote sensorsd.conf \ shells sysctl.conf syslog.conf usbd.conf \ etc.${MACHINE_ARCH}/ttys diff --git a/etc/defaults/make.conf b/etc/defaults/make.conf index af0cce9831..29f8d5fc4a 100644 --- a/etc/defaults/make.conf +++ b/etc/defaults/make.conf @@ -95,6 +95,13 @@ THREAD_LIB?= thread_xu # To use GNU cpio as the standard cpio. The default is bsdcpio. #WITH_GCPIO= true # +# To enable Hesiod support in libc +#WANT_HESIOD= true +# +# To disable name caching in the nsswitch subsystem. The generic caching +# daemon, nscd(8), will not be built either if this option is set. +#NO_NS_CACHING= true +# # To avoid building various parts of the base system: #NO_BIND= true # do not build BIND #NO_CRYPT= true # do not build crypto code diff --git a/etc/defaults/rc.conf b/etc/defaults/rc.conf index a7ad2aefe2..0f7895baea 100644 --- a/etc/defaults/rc.conf +++ b/etc/defaults/rc.conf @@ -404,6 +404,7 @@ cron_flags="" # Which options to pass to the cron daemon. lpd_enable="NO" # Run the line printer daemon. lpd_program="/usr/sbin/lpd" # path to lpd, if you want a different one. lpd_flags="" # Flags to lpd (if enabled). +nscd_enable="NO" # Run the nsswitch caching daemon. usbd_enable="NO" # Run the usbd daemon. usbd_flags="" # Flags to usbd (if enabled). devd_enable="NO" # Rund devd(8) daemon. diff --git a/etc/host.conf b/etc/host.conf deleted file mode 100644 index eed1658cf2..0000000000 --- a/etc/host.conf +++ /dev/null @@ -1,8 +0,0 @@ -# $FreeBSD: src/etc/host.conf,v 1.6 1999/08/27 23:23:41 peter Exp $ -# $DragonFly: src/etc/host.conf,v 1.2 2003/06/17 04:24:45 dillon Exp $ -# First try the /etc/hosts file -hosts -# Now try the nameserver next. -bind -# If you have YP/NIS configured, uncomment the next line -# nis diff --git a/etc/hosts b/etc/hosts index 9e01843a11..a36591bfe8 100644 --- a/etc/hosts +++ b/etc/hosts @@ -1,4 +1,4 @@ -# $FreeBSD: src/etc/hosts,v 1.11.2.4 2003/02/06 20:36:58 dbaker Exp $ +# $FreeBSD: src/etc/hosts,v 1.16 2003/01/28 21:29:23 dbaker Exp $ # $DragonFly: src/etc/hosts,v 1.2 2003/06/17 04:24:45 dillon Exp $ # # Host Database @@ -8,7 +8,7 @@ # machine. # # In the presence of the domain name service or NIS, this file may -# not be consulted at all; see /etc/host.conf for the resolution order. +# not be consulted at all; see /etc/nsswitch.conf for the resolution order. # # ::1 localhost localhost.my.domain diff --git a/etc/nscd.conf b/etc/nscd.conf new file mode 100644 index 0000000000..8706c212b4 --- /dev/null +++ b/etc/nscd.conf @@ -0,0 +1,12 @@ +# +# Default caching daemon configuration file +# $FreeBSD: src/etc/nscd.conf,v 1.2 2007/10/18 08:26:20 bushman Exp $ +# + +enable-cache passwd yes +enable-cache group yes +enable-cache hosts yes +enable-cache services yes +enable-cache protocols yes +enable-cache rpc yes +enable-cache networks yes diff --git a/etc/rc.d/Makefile b/etc/rc.d/Makefile index 37100d75e3..7a0f6d41f3 100644 --- a/etc/rc.d/Makefile +++ b/etc/rc.d/Makefile @@ -18,13 +18,14 @@ FILES= DAEMON LOGIN NETWORKING SERVERS abi accounting addswap adjkerntz \ mixer motd mountcritlocal mountcritremote \ mountd moused mroute6d mrouted msgs \ named netif netoptions newsyslog \ - network_ipv6 nfsclient nfsd nfsserver nisdomain \ + network_ipv6 nfsclient nfsd nfsserver nisdomain nscd nsswitch \ dntpd othermta pf pflog ppp ppp-user pppoed pwcheck \ quota random rarpd rcconf.sh resident rndcontrol root route6d routed \ routing rpcbind rtadvd rtsold rwho sysdb savecore sdpd securelevel \ sendmail sensorsd serial sppp sshd statd swap1 syscons sysctl syslogd \ timed ttys usbd varsym vinum virecover watchdogd wpa_supplicant \ ypbind yppasswdd ypserv ypset ypupdated ypxfrd + FILESDIR= /etc/rc.d FILESMODE= ${BINMODE} diff --git a/etc/rc.d/nscd b/etc/rc.d/nscd new file mode 100644 index 0000000000..13bbd851c8 --- /dev/null +++ b/etc/rc.d/nscd @@ -0,0 +1,52 @@ +#!/bin/sh +# +# $FreeBSD: src/etc/rc.d/nscd,v 1.7 2008/07/16 19:50:29 dougb Exp $ +# + +# PROVIDE: nscd +# REQUIRE: DAEMON +# BEFORE: LOGIN +# KEYWORD: shutdown + +# +# Add the following lines to /etc/rc.conf to enable nscd: +# +# nscd_enable="YES" +# +# See nscd(8) for flags +# + +. /etc/rc.subr + +name=nscd +rcvar=`set_rcvar` + +command=/usr/sbin/nscd +extra_commands="flush" +flush_cmd="${command} -I all" + +# usage: _nscd_set_option