diff options
author | wpaul <wpaul@FreeBSD.org> | 1996-04-28 04:38:52 +0000 |
---|---|---|
committer | wpaul <wpaul@FreeBSD.org> | 1996-04-28 04:38:52 +0000 |
commit | 0f95e4e2267a1ba84724a850c3e16f8a4797df56 (patch) | |
tree | 8a812c67e9e63f836246125cbbd49d43a685fe54 /usr.sbin/ypserv | |
parent | 7431f827c29811064979692b6ff8740ff529e54b (diff) | |
download | FreeBSD-src-0f95e4e2267a1ba84724a850c3e16f8a4797df56.zip FreeBSD-src-0f95e4e2267a1ba84724a850c3e16f8a4797df56.tar.gz |
Performance enhancements (I hope) and new stuff:
yp_dblookup.c:
- Implement database handle caching. What this means is that instead
of opening and closing map databases for each request, we open a
database and save the handle (and, if requested, the key index)
in an array. This saves a bit of overhead on things like repeated
YPPROC_NEXT calls, such as you'd get from getpwent(). Normally,
each YPPROC_NEXT would require open()ing the database, seeking
to the location supplied by the caller (which is time consuming with
hash databases as the R_CURSOR flag doesn't work), reading the
data, close()ing the database and then shipping the data off to
the caller. The system call overhead is prohibitive, especially
with very large maps. By caching the handle to an open database,
we elimitate at least the open()/close() system calls, as well
as the associated DB setup and tear-down operations, for a large
percentage of the time. This improves performance substantially at
the cost of consuming a little more memory than before.
Note that all the caching support is surrounded by #ifdef DB_CACHE
so that this same source module can still be used by other programs
that don't need it.
- Make yp_open_db() call yp_validdomain(). Doing it here saves cycles
when caching is enabled since a hit on the map cache list by
definition means that the domain being referenced is valid.
- Also make yp_open_db() check for exhaustion of file descriptors,
just in case.
yp_server.c:
- Reorganize things a little to take advantage of the database
handle caching. Add a call to yp_flush_all() in ypproc_clear_2_svc().
- Remove calls to yp_validdomain() from some of the service procedures.
yp_validdomain() is called inside yp_open_db() now, so procedures that
call into the database package don't need to use yp_validdomain()
themselves.
- Fix a bogosity in ypproc_maplist_2_svc(): don't summarily initiallize
the result.maps pointer to NULL. This causes yp_maplist_free()
to fail and leaks memory.
- Make ypproc_master_2_svc() copy the string it gets from the database
package into a private static buffer before trying to NUL terminate it.
This is necessary with the DB handle caching: stuffing a NUL into the
data returned by DB package will goof it up internally.
yp_main.c:
- Stuff for DB handle caching: call yp_init_dbs() to clear the
handle array and add call to yp_flush_all() to the SIGHUP
signal handler.
Makefile.yp:
- Reorganize to deal with database caching. yp_mkdb(8) can now be used
to send a YPPROC_CLEAR signal to ypserv(8). Call it after each map
is created to refresh ypserv's cache.
- Add support for mail.alias map.
Contributed by Mike Murphy (mrm@sceard.com).
- Make default location for the netgroups source file be /var/yp/netgroup
instead of /etc/netgroup.
mkaliases:
- New file: script to generate mail.alias map.
Contributed by Mike Murphy (mrm@sceard.com).
Makefile:
- Install Makefile.yp as /var/yp/Makefile.dist and link it to
/var/yp/Makefile only if /var/yp/Makefile doesn't already exist.
Suggested by Peter Wemm.
- Install new mkaliases script in /usr/libexec along with mknetid.
- Use somewhat saner approach to generating rpcgen-dependent files
as suggested by Garrett Wollman.
Diffstat (limited to 'usr.sbin/ypserv')
-rw-r--r-- | usr.sbin/ypserv/Makefile | 28 | ||||
-rw-r--r-- | usr.sbin/ypserv/Makefile.yp | 184 | ||||
-rw-r--r-- | usr.sbin/ypserv/mkaliases | 10 | ||||
-rw-r--r-- | usr.sbin/ypserv/yp_access.c | 24 | ||||
-rw-r--r-- | usr.sbin/ypserv/yp_dblookup.c | 323 | ||||
-rw-r--r-- | usr.sbin/ypserv/yp_extern.h | 9 | ||||
-rw-r--r-- | usr.sbin/ypserv/yp_main.c | 11 | ||||
-rw-r--r-- | usr.sbin/ypserv/yp_server.c | 185 |
8 files changed, 560 insertions, 214 deletions
diff --git a/usr.sbin/ypserv/Makefile b/usr.sbin/ypserv/Makefile index 6f0ca9b..340a4cc 100644 --- a/usr.sbin/ypserv/Makefile +++ b/usr.sbin/ypserv/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.2 1995/12/16 23:01:04 bde Exp $ +# $Id: Makefile,v 1.3 1995/12/23 21:35:27 wpaul Exp $ PROG= ypserv SRCS= yp_svc.c yp_server.c yp_dblookup.c yp_dnslookup.c \ @@ -6,32 +6,40 @@ SRCS= yp_svc.c yp_server.c yp_dblookup.c yp_dnslookup.c \ MAN8= ypserv.8 -CFLAGS+= -I. +CFLAGS+= -I. -DDB_CACHE CLEANFILES= yp_svc.c ypxfr_clnt.c yp.h -RPCSRC= ${.DESTDIR}/usr/include/rpcsvc/yp.x +RPCDIR= ${.CURDIR}/../../include/rpcsvc +.PATH: ${RPCDIR} + RPCGEN= rpcgen -I -C # We need to remove the 'static' keyword from _rpcsvcstate so that # yp_main.c can see it. -yp_svc.c: ${RPCSRC} yp.h +yp_svc.c: yp.x yp.h rm -f ${.TARGET} - ${RPCGEN} -DYPSERV_ONLY -m ${RPCSRC} | \ + ${RPCGEN} -DYPSERV_ONLY -m ${RPCDIR}/yp.x | \ sed s/"static int _rpcsvcstate"/"int _rpcsvcstate"/g > ${.TARGET} -ypxfr_clnt.c: ${RPCSRC} yp.h - ${RPCGEN} -DYPPUSH_ONLY -l -o ${.TARGET} ${RPCSRC} +ypxfr_clnt.c: yp.x yp.h + ${RPCGEN} -DYPPUSH_ONLY -l -o ${.TARGET} ${RPCDIR}/yp.x -yp.h: ${RPCSRC} - ${RPCGEN} -h -o ${.TARGET} ${RPCSRC} +yp.h: yp.x + ${RPCGEN} -h -o ${.TARGET} ${RPCDIR}/yp.x afterinstall: ${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m 444 \ ${.CURDIR}/Makefile.yp \ - ${DESTDIR}/var/yp/Makefile + ${DESTDIR}/var/yp/Makefile.dist + @if [ ! -f ${DESTDIR}/var/yp/Makefile.dist ]; then \ + ln -s ${DESTDIR}/var/yp/Makefile.dist \ + ${DESTDIR}/var/yp/Makefile; fi ${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \ ${.CURDIR}/mknetid \ ${DESTDIR}/usr/libexec/mknetid + ${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \ + ${.CURDIR}/mkaliases \ + ${DESTDIR}/usr/libexec/mkaliases .include <bsd.prog.mk> diff --git a/usr.sbin/ypserv/Makefile.yp b/usr.sbin/ypserv/Makefile.yp index 198ffb7..bcb06d7 100644 --- a/usr.sbin/ypserv/Makefile.yp +++ b/usr.sbin/ypserv/Makefile.yp @@ -1,7 +1,7 @@ # # Makefile for the NIS databases # -# $Id: Makefile.yp,v 1.2 1996/01/12 07:07:18 wpaul Exp $ +# $Id: Makefile.yp,v 1.2 1996/04/13 21:17:57 wpaul Exp wpaul $ # # This Makefile should only be run on the NIS master server of a domain. # All updated maps will be pushed to all NIS slave servers listed in the @@ -36,11 +36,15 @@ NOPUSH = "True" # AWK = /usr/bin/awk RM = @/bin/rm -f +MV = @/bin/mv -f RCAT = /bin/cat CAT = @$(RCAT) +SED = /usr/bin/sed DBLOAD = /usr/sbin/yp_mkdb -m `hostname` MKNETID = /usr/libexec/mknetid +MKALIASES = /usr/libexec/mkaliases +NEWALIASES = /usr/bin/newaliases YPPUSH = /usr/sbin/yppush .if !defined(UPDATE_DOMAIN) DOMAIN = `/bin/domainname` @@ -48,7 +52,13 @@ DOMAIN = `/bin/domainname` DOMAIN = $(UPDATE_DOMAIN) .endif REVNETGROUP = /usr/libexec/revnetgroup +NFILE = /tmp/ypmake +TMP = `$(RCAT) $(NFILE)` +# It is advisable to create a seperate directory to contain the +# source files used to generate your NIS maps. If you intent to +# support multiple domains, something like /src/dir/$DOMAIN +# would work well. YPSRCDIR = /etc YPDIR = /var/yp YPMAPDIR = $(YPDIR)/$(DOMAIN) @@ -82,7 +92,8 @@ PROTOCOLS = $(YPSRCDIR)/protocols RPC = $(YPSRCDIR)/rpc SERVICES = $(YPSRCDIR)/services GROUP = $(YPSRCDIR)/group -NETGROUP = $(YPSRCDIR)/netgroup +ALIASES = $(YPSRCDIR)/aliases +NETGROUP = $(YPDIR)/netgroup PASSWD = $(YPDIR)/passwd .if !defined(MASTER_PASSWD) MASTER = $(YPDIR)/master.passwd @@ -93,6 +104,7 @@ YPSERVERS = $(YPDIR)/ypservers # List of all NIS servers for a domain PUBLICKEY = $(YPSRCDIR)/publickey target: + @$(RM) $(NFILE) @if [ ! -d $(DOMAIN) ]; then mkdir $(DOMAIN); fi; \ cd $(DOMAIN) ; echo "NIS Map update started on `date` for domain $(DOMAIN)" ; \ make -f ../Makefile all; echo "NIS Map update completed." @@ -104,8 +116,8 @@ target: # on all systems. # -all: master.passwd passwd hosts group networks protocols \ - rpc services servers netid # publickey netgroup ethers bootparam +all: master.passwd passwd hosts group networks protocols rpc \ + services servers netid # aliases publickey netgroup ethers bootparam ethers: ethers.byname ethers.byaddr bootparam: bootparams @@ -120,59 +132,84 @@ netgrp: netgroup netid: netid.byname servers: ypservers publickey: publickey.byname +aliases: mail.aliases master.passwd: master.passwd.byname master.passwd.byuid +mail.aliases: $(ALIASES) + @echo "Updating $@..." + @echo $@.$$$$ > $(NFILE) + $(CAT) $(ALIASES) | \ + $(SED) -e "/^#/d" -e s/#.*$$// -e "/^ *$$/d" |\ + $(MKALIASES) \ + | $(DBLOAD) -i $(ALIASES) -o $(YPMAPDIR)/$@ - $(TMP) + @$(MV) $(TMP) $@ + @$(DBLOAD) -c + @$(NEWALIASES) + @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi + @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi + ypservers: $(YPSERVERS) @echo "Updating $@..." - $(RM) $@ + @echo $@.$$$$ > $(NFILE) $(CAT) $(YPSERVERS) | \ $(AWK) '{ if ($$1 != "" && $$1 != "#") print $$0"\t"$$0 }' $^ \ - | $(DBLOAD) -i $(YPSERVERS) -o $(YPMAPDIR)/$@ - $@ + | $(DBLOAD) -i $(YPSERVERS) -o $(YPMAPDIR)/$@ - $(TMP) + @$(MV) $(TMP) $@ + @$(DBLOAD) -c @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi + ethers.byname: $(ETHERS) @echo "Updating $@..." - $(RM) $@ + @echo $@.$$$$ > $(NFILE) $(CAT) $(ETHERS) | \ $(AWK) '{ if ($$1 != "" && $$1 != "#" && $$1 != "+") \ print $$2"\t"$$0 }' $^ | $(DBLOAD) -i $(ETHERS) \ - -o $(YPMAPDIR)/$@ - $@ + -o $(YPMAPDIR)/$@ - $(TMP) + @$(MV) $(TMP) $@ + @$(DBLOAD) -c @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) -i $(ETHERS) $@; fi @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi ethers.byaddr: $(ETHERS) @echo "Updating $@..." - $(RM) $@ + @echo $@.$$$$ > $(NFILE) $(CAT) $(ETHERS) | \ $(AWK) '{ if ($$1 != "" && $$1 != "#" && $$1 != "+") \ print $$1"\t"$$0 }' $^ | $(DBLOAD) -i $(ETHERS) \ - -o $(YPMAPDIR)/$@ - $@ + -o $(YPMAPDIR)/$@ - $(TMP) + @$(MV) $(TMP) $@ + @$(DBLOAD) -c @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi bootparams: $(BOOTPARAMS) @echo "Updating $@..." - $(RM) $@ + @echo $@.$$$$ > $(NFILE) $(CAT) $(BOOTPARAMS) | \ $(AWK) '{ if ($$1 != "" && $$1 != "#" && $$1 != "+") \ print $$0 }' $^ | $(DBLOAD) -i $(BOOTPARAMS) \ - -o $(YPMAPDIR)/$@ - $@ + -o $(YPMAPDIR)/$@ - $(TMP) + @$(MV) $(TMP) $@ + @$(DBLOAD) -c @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi netgroup: $(NETGROUP) netgroup.byhost netgroup.byuser @echo "Updating $@..." - $(RM) $@ + @echo $@.$$$$ > $(NFILE) $(CAT) $(NETGROUP) | \ $(AWK) '{ if ($$1 != "" && $$1 != "#" && $$1 != "+") \ print $$0 }' $^ | $(DBLOAD) -i $(NETGROUP) \ - -o $(YPMAPDIR)/$@ - $@ + -o $(YPMAPDIR)/$@ - $(TMP) + @$(MV) $(TMP) $@ + @$(DBLOAD) -c @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi @$(MAKE) -f ../Makefile netid @@ -180,43 +217,52 @@ netgroup: $(NETGROUP) netgroup.byhost netgroup.byuser netgroup.byhost: $(NETGROUP) @echo "Updating $@..." - $(RM) $@ + @echo $@.$$$$ > $(NFILE) $(CAT) $(NETGROUP) | $(REVNETGROUP) -h -f $(NETGROUP) | \ $(AWK) '{ if ($$1 != "" && $$1 != "#" && $$1 != "+") \ print $$0 }' $^ | $(DBLOAD) -i $(NETGROUP) \ - -o $(YPMAPDIR)/$@ - $@ + -o $(YPMAPDIR)/$@ - $(TMP) + @$(MV) $(TMP) $@ + @$(DBLOAD) -c @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi netgroup.byuser: $(NETGROUP) @echo "Updating $@..." - $(RM) $@ + @echo $@.$$$$ > $(NFILE) $(CAT) $(NETGROUP) | $(REVNETGROUP) -u -f $(NETGROUP) | \ $(AWK) '{ if ($$1 != "" && $$1 != "#" && $$1 != "+") \ print $$0 }' $^ | $(DBLOAD) -i $(NETGROUP) \ - -o $(YPMAPDIR)/$@ - $@ + -o $(YPMAPDIR)/$@ - $(TMP) + @$(MV) $(TMP) $@ + @$(DBLOAD) -c @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi hosts.byname: $(HOSTS) @echo "Updating $@..." - $(RM) $@ + @echo $@.$$$$ > $(NFILE) $(CAT) $(HOSTS) | \ $(AWK) '/^[0-9]/ { for (n=2; n<=NF && $$n !~ "#"; n++) \ print $$n"\t"$$0 }' $^ | $(DBLOAD) -i $(HOSTS) \ - -o $(YPMAPDIR)/$@ - $@ + -o $(YPMAPDIR)/$@ - $(TMP) + @$(MV) $(TMP) $@ + @$(DBLOAD) -c @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi @$(MAKE) -f ../Makefile netid + hosts.byaddr: $(HOSTS) @echo "Updating $@..." - $(RM) $@ + @echo $@.$$$$ > $(NFILE) $(CAT) $(HOSTS) | \ $(AWK) '$$1 !~ "#" { print $$1"\t"$$0 }' $^ \ - | $(DBLOAD) -i $(HOSTS) -o $(YPMAPDIR)/$@ - $@ + | $(DBLOAD) -i $(HOSTS) -o $(YPMAPDIR)/$@ - $(TMP) + @$(MV) $(TMP) $@ + @$(DBLOAD) -c @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi @$(MAKE) -f ../Makefile netid @@ -224,99 +270,114 @@ hosts.byaddr: $(HOSTS) networks.byname: $(NETWORKS) @echo "Updating $@..." - $(RM) $@ + @echo $@.$$$$ > $(NFILE) $(CAT) $(NETWORKS) | \ $(AWK) \ '$$1 !~ "#" { print $$1"\t"$$0; \ for (n=3; n<=NF && $$n !~ "#"; n++) \ print $$n"\t"$$0 \ - }' $^ | $(DBLOAD) -i $(NETWORKS) -o $(YPMAPDIR)/$@ - $@ + }' $^ | $(DBLOAD) -i $(NETWORKS) -o $(YPMAPDIR)/$@ - $(TMP) + @$(MV) $(TMP) $@ + @$(DBLOAD) -c @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi networks.byaddr: $(NETWORKS) @echo "Updating $@..." - $(RM) $@ + @echo $@.$$$$ > $(NFILE) $(CAT) $(NETWORKS) | \ $(AWK) '$$1 !~ "#" { print $$2"\t"$$0 }' $^ \ - | $(DBLOAD) -i $(NETWORKS) -o $(YPMAPDIR)/$@ - $@ + | $(DBLOAD) -i $(NETWORKS) -o $(YPMAPDIR)/$@ - $(TMP) + @$(MV) $(TMP) $@ + @$(DBLOAD) -c @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi protocols.byname: $(PROTOCOLS) @echo "Updating $@..." - $(RM) $@ + @echo $@.$$$$ > $(NFILE) $(CAT) $(PROTOCOLS) | \ $(AWK) \ '$$1 !~ "#" { print $$1"\t"$$0; \ for (n=3; n<=NF && $$n !~ "#"; n++) \ print $$n"\t"$$0 \ }' $^ | $(DBLOAD) -i $(PROTOCOLS) \ - -o $(YPMAPDIR)/$@ - $@ + -o $(YPMAPDIR)/$@ - $(TMP) + @$(MV) $(TMP) $@ + @$(DBLOAD) -c @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi protocols.bynumber: $(PROTOCOLS) @echo "Updating $@..." - $(RM) $@ + @echo $@.$$$$ > $(NFILE) $(CAT) $(PROTOCOLS) | \ $(AWK) '$$1 !~ "#" { print $$2"\t"$$0 }' $^ \ - | $(DBLOAD) -i $(PROTOCOLS) -o $(YPMAPDIR)/$@ - $@ + | $(DBLOAD) -i $(PROTOCOLS) -o $(YPMAPDIR)/$@ - $(TMP) + @$(MV) $(TMP) $@ + @$(DBLOAD) -c @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi rpc.byname: $(RPC) @echo "Updating $@..." - $(RM) $@ + @echo $@.$$$$ > $(NFILE) $(CAT) $(RPC) | \ $(AWK) \ '$$1 !~ "#" { print $$1"\t"$$0; \ for (n=3; n<=NF && $$n !~ "#"; n++) \ print $$n"\t"$$0 \ - }' $^ | $(DBLOAD) -i $(RPC) -o $(YPMAPDIR)/$@ - $@ + }' $^ | $(DBLOAD) -i $(RPC) -o $(YPMAPDIR)/$@ - $(TMP) + @$(MV) $(TMP) $@ + @$(DBLOAD) -c @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi rpc.bynumber: $(RPC) @echo "Updating $@..." - $(RM) $@ + @echo $@.$$$$ > $(NFILE) $(CAT) $(RPC) | \ $(AWK) '$$1 !~ "#" { print $$2"\t"$$0 }' $^ \ - | $(DBLOAD) -i $(RPC) -o $(YPMAPDIR)/$@ - $@ + | $(DBLOAD) -i $(RPC) -o $(YPMAPDIR)/$@ - $(TMP) + @$(MV) $(TMP) $@ + @$(DBLOAD) -c @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi services.byname: $(SERVICES) @echo "Updating $@..." - $(RM) $@ + @echo $@.$$$$ > $(NFILE) $(CAT) $(SERVICES) | \ $(AWK) \ '$$1 !~ "#" { if (index($$2,"udp")) { printf("%s/udp",$$1) } \ else { printf("%s/tcp",$$1) }; print "\t"$$0 \ - }' $^ | $(DBLOAD) -i $(SERVICES) -o $(YPMAPDIR)/$@ - $@ + }' $^ | $(DBLOAD) -i $(SERVICES) -o $(YPMAPDIR)/$@ - $(TMP) + @$(MV) $(TMP) $@ + @$(DBLOAD) -c @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi publickey.byname: $(PUBLICKEY) @echo "Updating $@..." - $(RM) $@ - $(CAT) $(PUBLICKEY) | \ + @echo $@.$$$$ > $(NFILE) + $(TMP) = `$(RCAT) $(NFILE)` $(AWK) '$$1 !~ "#" { print $$1"\t"$$2 }' $^ \ - | $(DBLOAD) -i $(PUBLICKEY) -o $(YPMAPDIR)/$@ - $@ + | $(DBLOAD) -i $(PUBLICKEY) -o $(YPMAPDIR)/$@ - $(TMP) + @$(MV) $(TMP) $@ + @$(DBLOAD) -c @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi $(PASSWD): $(MASTER) @echo "Creating new $@ file from $(MASTER)..." - $(RM) $@ @if [ ! $(UNSECURE) ]; then \ $(RCAT) $(MASTER) | \ $(AWK) -F: '{if ($$1 != "+") \ @@ -330,19 +391,24 @@ $(PASSWD): $(MASTER) passwd.byname: $(PASSWD) @echo "Updating $@..." - $(RM) $@ + @echo $@.$$$$ > $(NFILE) $(CAT) $(PASSWD) | \ $(AWK) -F: '{ if ($$1 != "+") print $$1"\t"$$0 }' $^ \ - | $(DBLOAD) -i $(PASSWD) -o $(YPMAPDIR)/$@ - $@ + | $(DBLOAD) -i $(PASSWD) -o $(YPMAPDIR)/$@ - $(TMP) + @$(MV) $(TMP) $@ + @$(DBLOAD) -c @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi + passwd.byuid: $(PASSWD) @echo "Updating $@..." - $(RM) $@ + @echo $@.$$$$ > $(NFILE) $(CAT) $(PASSWD) | \ $(AWK) -F: '{ if ($$1 != "+") print $$3"\t"$$0 }' $^ \ - | $(DBLOAD) -i $(PASSWD) -o $(YPMAPDIR)/$@ - $@ + | $(DBLOAD) -i $(PASSWD) -o $(YPMAPDIR)/$@ - $(TMP) + @$(MV) $(TMP) $@ + @$(DBLOAD) -c @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi @$(MAKE) -f ../Makefile netid @@ -350,20 +416,24 @@ passwd.byuid: $(PASSWD) group.byname: $(GROUP) @echo "Updating $@..." - $(RM) $@ + @echo $@.$$$$ > $(NFILE) $(CAT) $(GROUP) | \ $(AWK) -F: '{ if ($$1 != "+") print $$1"\t"$$0 }' $^ \ - | $(DBLOAD) -i $(GROUP) -o $(YPMAPDIR)/$@ - $@ + | $(DBLOAD) -i $(GROUP) -o $(YPMAPDIR)/$@ - $(TMP) + @$(MV) $(TMP) $@ + @$(DBLOAD) -c @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi group.bygid: $(GROUP) @echo "Updating $@..." - $(RM) $@ + @echo $@.$$$$ > $(NFILE) $(CAT) $(GROUP) | \ $(AWK) -F: '{ if ($$1 != "+") print $$3"\t"$$0 }' $^ \ - | $(DBLOAD) -i $(GROUP) -o $(YPMAPDIR)/$@ - $@ + | $(DBLOAD) -i $(GROUP) -o $(YPMAPDIR)/$@ - $(TMP) + @$(MV) $(TMP) $@ + @$(DBLOAD) -c @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi @$(MAKE) -f ../Makefile netid @@ -371,28 +441,34 @@ group.bygid: $(GROUP) netid.byname: $(GROUP) $(PASSWD) @echo "Updating $@..." - $(RM) $@ + @echo $@.$$$$ > $(NFILE) @$(MKNETID) $(PASSWD) $(GROUP) `basename \`pwd\`` \ - | $(DBLOAD) -o $(YPMAPDIR)/$@ - $@ + | $(DBLOAD) -o $(YPMAPDIR)/$@ - $(TMP) + @$(MV) $(TMP) $@ + @$(DBLOAD) -c @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi master.passwd.byname: $(MASTER) @echo "Updating $@..." - $(RM) $@ + @echo $@.$$$$ > $(NFILE) $(CAT) $(MASTER) | \ $(AWK) -F: '{ if ($$1 != "+") print $$1"\t"$$0 }' $^ \ - | $(DBLOAD) -i $(MASTER) -o $(YPMAPDIR)/$@ - $@ + | $(DBLOAD) -i $(MASTER) -o $(YPMAPDIR)/$@ - $(TMP) + @$(MV) $(TMP) $@ + @$(DBLOAD) -c @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi master.passwd.byuid: $(MASTER) @echo "Updating $@..." - $(RM) $@ + @echo $@.$$$$ > $(NFILE) $(CAT) $(MASTER) | \ $(AWK) -F: '{ if ($$1 != "+") print $$3"\t"$$0 }' $^ \ - | $(DBLOAD) -i $(MASTER) -o $(YPMAPDIR)/$@ - $@ + | $(DBLOAD) -i $(MASTER) -o $(YPMAPDIR)/$@ - $(TMP) + @$(MV) $(TMP) $@ + @$(DBLOAD) -c @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi diff --git a/usr.sbin/ypserv/mkaliases b/usr.sbin/ypserv/mkaliases new file mode 100644 index 0000000..6f1ad98 --- /dev/null +++ b/usr.sbin/ypserv/mkaliases @@ -0,0 +1,10 @@ +#!/usr/bin/awk -f +# mkaliases script +# Written by Mike Murphy mrm@Sceard.com +# $Id: mkaliases,v 1.1 1996/04/13 20:22:18 wpaul Exp $ + +BEGIN {l=""} +/^#/ || /^[ \t]*$/ {gsub("[ \t]+","",l);if (length(l)!=0){sub(":"," ",l);print l;l=""};next} +/:[ \t]/ {gsub("[ \t]+","",l);if (length(l)!=0){sub(":"," ",l);print l;l=""}} + { l=l $0 } +END {gsub("[ \t]+","",l);if (length(l)!=0){sub(":"," ",l);print l;l=""}} diff --git a/usr.sbin/ypserv/yp_access.c b/usr.sbin/ypserv/yp_access.c index 1750830..7bd3d32 100644 --- a/usr.sbin/ypserv/yp_access.c +++ b/usr.sbin/ypserv/yp_access.c @@ -36,10 +36,13 @@ #include <rpcsvc/yp.h> #include <rpcsvc/yppasswd.h> #include <sys/types.h> +#include <limits.h> +#include <db.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <sys/stat.h> +#include <sys/fcntl.h> #include <paths.h> #include <errno.h> #include <sys/param.h> @@ -49,7 +52,7 @@ #endif #ifndef lint -static const char rcsid[] = "$Id: yp_access.c,v 1.5 1996/02/26 02:34:23 wpaul Exp $"; +static const char rcsid[] = "$Id: yp_access.c,v 1.1 1996/04/13 07:27:13 wpaul Exp $"; #endif extern int debug; @@ -116,12 +119,10 @@ void load_securenets() * the list; free the existing list before re-reading the * securenets file. */ - if (securenets != NULL) { - while(securenets) { - tmp = securenets->next; - free(securenets); - securenets = tmp; - } + while(securenets) { + tmp = securenets->next; + free(securenets); + securenets = tmp; } snprintf(path, MAXPATHLEN, "%s/securenets", yp_dir); @@ -188,19 +189,19 @@ void load_securenets() * * - The client's IP address is checked against the securenets rules. * There are two kinds of securenets support: the built-in support, - * which is very simple and depends on the presense of a + * which is very simple and depends on the presence of a * /var/yp/securenets file, and tcp-wrapper support, which requires * Wietse Venema's libwrap.a and tcpd.h. (Since the tcp-wrapper * package does not ship with FreeBSD, we use the built-in support - * by default. Users can recompile the server the tcp-wrapper library + * by default. Users can recompile the server with the tcp-wrapper library * if they already have it installed and want to use hosts.allow and - * hosts.deny to control access instead od having a seperate securenets + * hosts.deny to control access instead of having a seperate securenets * file.) * * If no /var/yp/securenets file is present, the host access checks * are bypassed and all hosts are allowed to connect. * - * The yp_validdomain() functions checks the domain specified by the caller + * The yp_validdomain() function checks the domain specified by the caller * to make sure it's actually served by this server. This is more a sanity * check than an a security check, but this seems to be the best place for * it. @@ -286,5 +287,6 @@ int yp_validdomain(domain) if (stat(dompath, &statbuf) < 0 || !S_ISDIR(statbuf.st_mode)) return(1); + return(0); } diff --git a/usr.sbin/ypserv/yp_dblookup.c b/usr.sbin/ypserv/yp_dblookup.c index 3f2415b..0cffdb3 100644 --- a/usr.sbin/ypserv/yp_dblookup.c +++ b/usr.sbin/ypserv/yp_dblookup.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: yp_dblookup.c,v 1.3 1996/02/04 05:39:35 wpaul Exp $ + * $Id: yp_dblookup.c,v 1.7 1996/04/27 17:50:18 wpaul Exp wpaul $ * */ #include <stdio.h> @@ -40,9 +40,10 @@ #include <unistd.h> #include <db.h> #include <sys/stat.h> +#include <sys/param.h> #include <errno.h> #include <paths.h> -#include "yp.h" +#include <rpcsvc/yp.h> #include "yp_extern.h" int ypdb_debug = 0; @@ -52,22 +53,212 @@ int yp_errno = YP_TRUE; HASHINFO openinfo = { 4096, /* bsize */ 32, /* ffactor */ - 256, /* nelem */ - 2048 * 1024, /* cachesize */ + 512, /* nelem */ + 2048 * 512, /* cachesize */ NULL, /* hash */ 0, /* lorder */ }; +#ifdef DB_CACHE +#define MAXDBS 20 +#define LASTDB (MAXDBS - 1) + +struct dbent { + DB *dbp; + char *name; + char *key; + int size; +}; + +static struct dbent *dbs[MAXDBS]; +static int numdbs = 0; + /* - * Open a DB database + * Make sure all the DB entries are NULL to start with. */ -DB *yp_open_db(domain, map) +void yp_init_dbs() +{ + register int i; + + for (i = 0; i < MAXDBS; i++); + dbs[i] = NULL; + return; +} + +static inline void yp_flush(i) + register int i; +{ + (void)(dbs[i]->dbp->close)(dbs[i]->dbp); + dbs[i]->dbp = NULL; + free(dbs[i]->name); + dbs[i]->name = NULL; + dbs[i]->key = NULL; + dbs[i]->size = 0; + free(dbs[i]); + dbs[i] = NULL; + numdbs--; +} + +/* + * Close all databases and erase all database names. + * Don't free the memory allocated for each DB entry though: we + * can just reuse it later. + */ +void yp_flush_all() +{ + register int i; + + for (i = 0; i < MAXDBS; i++) { + if (dbs[i] != NULL && dbs[i]->dbp != NULL) { + yp_flush(i); + } + } +} + + +/* + * Add a DB handle and database name to the cache. We only maintain + * fixed number of entries in the cache, so if we're asked to store + * a new entry when all our slots are already filled, we have to kick + * out the entry in the last slot to make room. + */ +static inline void yp_add_db(dbp, name, size) + DB *dbp; + char *name; + int size; +{ + register int i; + register struct dbent *tmp; + static int count = 0; + + + tmp = dbs[LASTDB]; + + /* Rotate */ + for (i = LASTDB; i > 0; i--) + dbs[i] = dbs[i - 1]; + + dbs[0] = tmp; + + if (dbs[0]) { + if (ypdb_debug) + yp_error("table overflow -- releasing last slot"); + yp_flush(0); + } + + /* + * Add the new entry. We allocate memory for the dbent + * structure if we need it. We shoudly only end up calling + * malloc(2) MAXDB times. Once all the slots are filled, we + * hold onto the memory and recycle it. + */ + if (dbs[0] == NULL) { + count++; + if (ypdb_debug) + yp_error("allocating new DB member (%d)", count); + dbs[0] = (struct dbent *)malloc(sizeof(struct dbent)); + bzero((char *)dbs[0], sizeof(struct dbent)); + } + + numdbs++; + dbs[0]->dbp = dbp; + dbs[0]->name = strdup(name); + dbs[0]->size = size; + return; +} + +/* + * Search the list for a database matching 'name.' If we find it, + * move it to the head of the list and return its DB handle. If + * not, just fail: yp_open_db_cache() will subsequently try to open + * the database itself and call yp_add_db() to add it to the + * list. + * + * The search works like this: + * + * - The caller specifies the name of a database to locate. We try to + * find an entry in our list with a matching name. + * + * - If the caller doesn't specify a key or size, we assume that the + * first entry that we encounter with a matching name is returned. + * This will result in matches regardless of the pointer index. + * + * - If the caller also specifies a key and length, we check name + * matches to see if their saved key indexes and lengths also match. + * This lets us return a DB handle that's already positioned at the + * correct location within a database. + * + * - Once we have a match, it gets migrated to the top of the list + * array so that it will be easier to find if another request for + * the same database comes in later. + */ +static inline DB *yp_find_db(name, key, size) + char *name; + char *key; +{ + register int i, j; + register struct dbent *tmp; + + for (i = 0; i < numdbs; i++) { + if (dbs[i]->name != NULL && !strcmp(dbs[i]->name, name)) { + if (size) { + if (size != dbs[i]->size || + strncmp(dbs[i]->key, key, size)) + continue; + } else { + if (dbs[i]->size) { + continue; + } + } + if (i > 0) { + tmp = dbs[i]; + for (j = i; j > 0; j--) + dbs[j] = dbs[j - 1]; + dbs[0] = tmp; + } + return(dbs[0]->dbp); + } + } + return(NULL); +} + +/* + * Open a DB database and cache the handle for later use. We first + * check the cache to see if the required database is already open. + * If so, we fetch the handle from the cache. If not, we try to open + * the database and save the handle in the cache for later use. + */ +DB *yp_open_db_cache(domain, map, key, size) const char *domain; const char *map; + const char *key; + const int size; { - DB *dbp; - char buf[1025]; + DB *dbp = NULL; + char buf[MAXPATHLEN + 2]; + snprintf(buf, sizeof(buf), "%s/%s", domain, map); + + if ((dbp = yp_find_db((char *)&buf, key, size)) != NULL) { + return(dbp); + } else { + if ((dbp = yp_open_db(domain, map)) != NULL) + yp_add_db(dbp, (char *)&buf, size); + } + + return (dbp); +} +#endif + +/* + * Open a DB database. + */ +DB *yp_open_db(domain, map) + const char *domain; + const char *map; +{ + DB *dbp = NULL; + char buf[MAXPATHLEN + 2]; yp_errno = YP_TRUE; @@ -76,12 +267,32 @@ DB *yp_open_db(domain, map) return (NULL); } +#ifdef DB_CACHE + if (yp_validdomain(domain)) { + yp_errno = YP_NODOM; + return(NULL); + } +#endif snprintf(buf, sizeof(buf), "%s/%s/%s", yp_dir, domain, map); - dbp = dbopen(buf,O_RDONLY|O_EXCL, PERM_SECURE, DB_HASH, NULL); +#ifdef DB_CACHE +again: +#endif + dbp = dbopen(buf,O_RDONLY, PERM_SECURE, DB_HASH, NULL); if (dbp == NULL) { switch(errno) { +#ifdef DB_CACHE + case ENFILE: + /* + * We ran out of file descriptors. Nuke an + * open one and try again. + */ + yp_error("ran out of file descriptors"); + yp_flush(numdbs - 1); + goto again; + break; +#endif case ENOENT: yp_errno = YP_NOMAP; break; @@ -117,7 +328,7 @@ int yp_get_record(domain,map,key,data,allow) int allow; { DB *dbp; - int rval; + int rval = 0; if (ypdb_debug) yp_error("Looking up key [%.*s] in map [%s]", @@ -131,31 +342,47 @@ int yp_get_record(domain,map,key,data,allow) if (!allow && !strncmp(key->data, "YP_", 3)) return(YP_NOKEY); +#ifdef DB_CACHE + if ((dbp = yp_open_db_cache(domain, map, NULL, 0)) == NULL) { +#else if ((dbp = yp_open_db(domain, map)) == NULL) { +#endif return(yp_errno); } - if ((rval = (dbp->get)(dbp,key,data,0)) != 0) { + if ((rval = (dbp->get)(dbp, key, data, 0)) != 0) { +#ifdef DB_CACHE + dbs[0]->size = 0; +#else (void)(dbp->close)(dbp); +#endif if (rval == 1) return(YP_NOKEY); else return(YP_BADDB); } - (void)(dbp->close)(dbp); - if (ypdb_debug) yp_error("Result of lookup: key: [%.*s] data: [%.*s]", key->size, key->data, data->size, data->data); +#ifdef DB_CACHE + if (dbs[0]->size) { + dbs[0]->key = key->data; + dbs[0]->size = key->size; + } +#else + (void)(dbp->close)(dbp); +#endif + return(YP_TRUE); } -int yp_first_record(dbp,key,data) +int yp_first_record(dbp,key,data,allow) const DB *dbp; DBT *key; DBT *data; + int allow; { int rval; @@ -163,6 +390,9 @@ int yp_first_record(dbp,key,data) yp_error("Retrieving first key in map."); if ((rval = (dbp->seq)(dbp,key,data,R_FIRST)) != 0) { +#ifdef DB_CACHE + dbs[0]->size = 0; +#endif if (rval == 1) return(YP_NOKEY); else @@ -170,8 +400,11 @@ int yp_first_record(dbp,key,data) } /* Avoid passing back magic "YP_*" records. */ - while (!strncmp(key->data, "YP_", 3)) { + while (!strncmp(key->data, "YP_", 3) && !allow) { if ((rval = (dbp->seq)(dbp,key,data,R_NEXT)) != 0) { +#ifdef DB_CACHE + dbs[0]->size = 0; +#endif if (rval == 1) return(YP_NOKEY); else @@ -183,20 +416,29 @@ int yp_first_record(dbp,key,data) yp_error("Result of lookup: key: [%.*s] data: [%.*s]", key->size, key->data, data->size, data->data); +#ifdef DB_CACHE + if (dbs[0]->size) { + dbs[0]->key = key->data; + dbs[0]->size = key->size; + } +#endif + return(YP_TRUE); } -int yp_next_record(dbp,key,data,all) +int yp_next_record(dbp,key,data,all,allow) const DB *dbp; DBT *key; DBT *data; int all; + int allow; { - DBT lkey, ldata; + static DBT lkey = { NULL, 0 }; + static DBT ldata = { NULL, 0 }; int rval; if (key == NULL || key->data == NULL) { - rval = yp_first_record(dbp,key,data); + rval = yp_first_record(dbp,key,data,allow); if (rval == YP_NOKEY) return(YP_NOMORE); else @@ -208,29 +450,48 @@ int yp_next_record(dbp,key,data,all) key->size, key->data); if (!all) { - (dbp->seq)(dbp,&lkey,&ldata,R_FIRST); - while(strncmp((char *)key->data,lkey.data,(int)key->size) || - key->size != lkey.size) - (dbp->seq)(dbp,&lkey,&ldata,R_NEXT); +#ifndef DB_CACHE + if (key->size != lkey.size || + strncmp(key->data, lkey.data, key->size)) { +#else + if (!dbs[0]->size) { +#endif + (dbp->seq)(dbp,&lkey,&ldata,R_FIRST); + while(strncmp((char *)key->data,lkey.data, + (int)key->size) || key->size != lkey.size) + (dbp->seq)(dbp,&lkey,&ldata,R_NEXT); + } } - if ((dbp->seq)(dbp,&lkey,&ldata,R_NEXT)) + if ((dbp->seq)(dbp,key,data,R_NEXT)) { +#ifdef DB_CACHE + dbs[0]->size = 0; +#endif return(YP_NOMORE); + } /* Avoid passing back magic "YP_*" records. */ - while (!strncmp(lkey.data, "YP_", 3)) - if ((dbp->seq)(dbp,&lkey,&ldata,R_NEXT)) + while (!strncmp(key->data, "YP_", 3) && !allow) + if ((dbp->seq)(dbp,key,data,R_NEXT)) { +#ifdef DB_CACHE + dbs[0]->size = 0; +#endif return(YP_NOMORE); - - if ((dbp->get)(dbp,&lkey,&ldata,0)) - return(YP_FALSE); - - *key = lkey; - *data = ldata; + } if (ypdb_debug) yp_error("Result of lookup: key: [%.*s] data: [%.*s]", key->size, key->data, data->size, data->data); +#ifdef DB_CACHE + if (dbs[0]->size) { + dbs[0]->key = key->data; + dbs[0]->size = key->size; + } +#else + lkey.data = key->data; + lkey.size = key->size; +#endif + return(YP_TRUE); } diff --git a/usr.sbin/ypserv/yp_extern.h b/usr.sbin/ypserv/yp_extern.h index 9e5a39f..aa7529c 100644 --- a/usr.sbin/ypserv/yp_extern.h +++ b/usr.sbin/ypserv/yp_extern.h @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: yp_extern.h,v 1.2 1995/12/23 21:35:30 wpaul Exp $ + * $Id: yp_extern.h,v 1.2 1996/04/21 21:34:02 wpaul Exp wpaul $ */ #include <stdio.h> #include <string.h> @@ -65,11 +65,14 @@ extern char *yp_dir; extern int yp_errno; extern void yp_error __P((const char *, ...)); extern int yp_get_record __P(( const char *, const char *, const DBT *, DBT *, int)); -extern int yp_first_record __P((const DB *, DBT *, DBT *)); -extern int yp_next_record __P((const DB *, DBT *, DBT *, int)); +extern int yp_first_record __P((const DB *, DBT *, DBT *, int)); +extern int yp_next_record __P((const DB *, DBT *, DBT *, int, int)); extern char *yp_dnsname __P(( char * )); extern char *yp_dnsaddr __P(( const char * )); extern int yp_access __P((const char *, const struct svc_req * )); extern int yp_validdomain __P((const char * )); extern DB *yp_open_db __P(( const char *, const char *)); +extern DB *yp_open_db_cache __P(( const char *, const char *, const char *, int )); +extern void yp_flush_all __P(( void )); +extern void yp_init_dbs __P(( void )); extern void load_securenets __P(( void )); diff --git a/usr.sbin/ypserv/yp_main.c b/usr.sbin/ypserv/yp_main.c index 6b23ab1..c4f9275 100644 --- a/usr.sbin/ypserv/yp_main.c +++ b/usr.sbin/ypserv/yp_main.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: yp_main.c,v 1.1 1996/02/25 19:29:34 wpaul Exp $ + * $Id: yp_main.c,v 1.2 1996/04/21 21:33:40 wpaul Exp $ */ /* @@ -65,7 +65,7 @@ #define _RPCSVC_CLOSEDOWN 120 #ifndef lint -static char rcsid[] = "$Id: yp_main.c,v 1.1 1996/02/25 19:29:34 wpaul Exp $"; +static char rcsid[] = "$Id: yp_main.c,v 1.2 1996/04/21 21:33:40 wpaul Exp $"; #endif /* not lint */ int _rpcpmstart; /* Started by a port monitor ? */ static int _rpcfdtype; @@ -148,6 +148,9 @@ static void reaper(sig) if (sig == SIGHUP) { load_securenets(); +#ifdef DB_CACHE + yp_flush_all(); +#endif return; } @@ -225,7 +228,9 @@ main(argc, argv) } load_securenets(); - +#ifdef DB_CACHE + yp_init_dbs(); +#endif if (getsockname(0, (struct sockaddr *)&saddr, &asize) == 0) { int ssize = sizeof (int); diff --git a/usr.sbin/ypserv/yp_server.c b/usr.sbin/ypserv/yp_server.c index 52e9079..27a1279 100644 --- a/usr.sbin/ypserv/yp_server.c +++ b/usr.sbin/ypserv/yp_server.c @@ -45,12 +45,18 @@ #include <rpc/rpc.h> #ifndef lint -static char rcsid[] = "$Id: yp_server.c,v 1.5 1996/03/01 03:28:31 wpaul Exp $"; +static char rcsid[] = "$Id: yp_server.c,v 1.5 1996/04/26 04:35:53 wpaul Exp wpaul $"; #endif /* not lint */ int forked = 0; int children = 0; DB *spec_dbp = NULL; /* Special global DB handle for ypproc_all. */ +char *master_string = "YP_MASTER_NAME"; +char *order_string = "YP_LAST_MODIFIED"; + +#define YP_ALL_TIMEOUT 10 + +static int yp_all_timed_out = 0; /* * NIS v2 support. This is where most of the action happens. @@ -123,17 +129,11 @@ ypproc_match_2_svc(ypreq_key *argp, struct svc_req *rqstp) return (&result); } - if (yp_validdomain(argp->domain)) { - result.stat = YP_NODOM; - return(&result); - } - key.size = argp->key.keydat_len; key.data = argp->key.keydat_val; - result.stat = yp_get_record(argp->domain, argp->map, &key, &data, 0); - - if (result.stat == YP_TRUE) { + if ((result.stat = yp_get_record(argp->domain, argp->map, + &key, &data, 1)) == YP_TRUE) { result.val.valdat_len = data.size; result.val.valdat_val = data.data; } @@ -212,28 +212,27 @@ ypproc_first_2_svc(ypreq_nokey *argp, struct svc_req *rqstp) return (&result); } - if (yp_validdomain(argp->domain)) { - result.stat = YP_NODOM; - return(&result); - } - +#ifdef DB_CACHE + if ((dbp = yp_open_db_cache(argp->domain, argp->map, NULL, 0)) == NULL) { +#else if ((dbp = yp_open_db(argp->domain, argp->map)) == NULL) { +#endif result.stat = yp_errno; return(&result); } key.data = NULL; key.size = 0; - result.stat = yp_first_record(dbp, &key, &data); - (void)(dbp->close)(dbp); - if (result.stat == YP_TRUE) { + if ((result.stat = yp_first_record(dbp, &key, &data, 0)) == YP_TRUE) { result.key.keydat_len = key.size; result.key.keydat_val = key.data; result.val.valdat_len = data.size; result.val.valdat_val = data.data; } - +#ifndef DB_CACHE + (void)(dbp->close)(dbp); +#endif return (&result); } @@ -246,7 +245,7 @@ ypproc_next_2_svc(ypreq_key *argp, struct svc_req *rqstp) result.val.valdat_val = result.key.keydat_val = ""; result.val.valdat_len = result.key.keydat_len = 0; - + if (yp_access(argp->map, (struct svc_req *)rqstp)) { result.stat = YP_YPERR; return (&result); @@ -257,12 +256,13 @@ ypproc_next_2_svc(ypreq_key *argp, struct svc_req *rqstp) return (&result); } - if (yp_validdomain(argp->domain)) { - result.stat = YP_NODOM; - return(&result); - } - +#ifdef DB_CACHE + if ((dbp = yp_open_db_cache(argp->domain, argp->map, + argp->key.keydat_val, + argp->key.keydat_len)) == NULL) { +#else if ((dbp = yp_open_db(argp->domain, argp->map)) == NULL) { +#endif result.stat = yp_errno; return(&result); } @@ -270,16 +270,15 @@ ypproc_next_2_svc(ypreq_key *argp, struct svc_req *rqstp) key.size = argp->key.keydat_len; key.data = argp->key.keydat_val; - result.stat = yp_next_record(dbp, &key, &data, 0); - (void)(dbp->close)(dbp); - - if (result.stat == YP_TRUE) { + if ((result.stat = yp_next_record(dbp, &key, &data,0,0)) == YP_TRUE) { result.key.keydat_len = key.size; result.key.keydat_val = key.data; result.val.valdat_len = data.size; result.val.valdat_val = data.data; } - +#ifndef DB_CACHE + (void)(dbp->close)(dbp); +#endif return (&result); } @@ -324,6 +323,14 @@ callback handle")); return; } +#define YPXFR_RETURN(CODE) \ + /* Order is important: send regular RPC reply, then callback */ \ + result.xfrstat = CODE; \ + svc_sendreply(rqstp->rq_xprt, xdr_ypresp_xfr, (char *)&result); \ + ypxfr_callback(CODE,rqhost,argp->transid, \ + argp->prog,argp->port); \ + return(NULL); + ypresp_xfr * ypproc_xfr_2_svc(ypreq_xfr *argp, struct svc_req *rqstp) { @@ -334,28 +341,15 @@ ypproc_xfr_2_svc(ypreq_xfr *argp, struct svc_req *rqstp) rqhost = svc_getcaller(rqstp->rq_xprt); if (yp_access(argp->map_parms.map, (struct svc_req *)rqstp)) { - /* Order is important: send regular RPC reply, then callback */ - result.xfrstat = YPXFR_REFUSED; - svc_sendreply(rqstp->rq_xprt, xdr_ypresp_xfr, (char *)&result); - ypxfr_callback(YPXFR_REFUSED,rqhost,argp->transid, - argp->prog,argp->port); - return(NULL); + YPXFR_RETURN(YPXFR_REFUSED); } if (argp->map_parms.domain == NULL) { - result.xfrstat = YPXFR_BADARGS; - svc_sendreply(rqstp->rq_xprt, xdr_ypresp_xfr, (char *)&result); - ypxfr_callback(YPXFR_BADARGS,rqhost,argp->transid, - argp->prog,argp->port); - return(NULL); + YPXFR_RETURN(YPXFR_BADARGS); } if (yp_validdomain(argp->map_parms.domain)) { - result.xfrstat = YPXFR_NODOM; - svc_sendreply(rqstp->rq_xprt, xdr_ypresp_xfr, (char *)&result); - ypxfr_callback(YPXFR_NODOM,rqhost,argp->transid, - argp->prog,argp->port); - return(NULL); + YPXFR_RETURN(YPXFR_NODOM); } switch(fork()) { @@ -388,21 +382,13 @@ ypproc_xfr_2_svc(ypreq_xfr *argp, struct svc_req *rqstp) NULL); } forked++; - result.xfrstat = YPXFR_XFRERR; - yp_error("ypxfr execl(): %s", strerror(errno)); - svc_sendreply(rqstp->rq_xprt, xdr_ypresp_xfr, (char *)&result); - ypxfr_callback(YPXFR_XFRERR,rqhost,argp->transid, - argp->prog,argp->port); - return(NULL); + yp_error("ypxfr execl(%s): %s", ypxfr_command, strerror(errno)); + YPXFR_RETURN(YPXFR_XFRERR); break; } case -1: yp_error("ypxfr fork(): %s", strerror(errno)); - result.xfrstat = YPXFR_XFRERR; - svc_sendreply(rqstp->rq_xprt, xdr_ypresp_xfr, (char *)&result); - ypxfr_callback(YPXFR_XFRERR,rqhost,argp->transid, - argp->prog,argp->port); - return(NULL); + YPXFR_RETURN(YPXFR_XFRERR); break; default: result.xfrstat = YPXFR_SUCC; @@ -413,6 +399,7 @@ ypproc_xfr_2_svc(ypreq_xfr *argp, struct svc_req *rqstp) return (&result); } +#undef YPXFR_RETURN void * ypproc_clear_2_svc(void *argp, struct svc_req *rqstp) @@ -420,14 +407,12 @@ ypproc_clear_2_svc(void *argp, struct svc_req *rqstp) static char * result; static char rval = 0; - /* - * We don't have to do anything for ypproc_clear. Unlike - * the SunOS ypserv, we don't hold our database descriptors - * open forever. - */ if (yp_access(NULL, (struct svc_req *)rqstp)) return (NULL); - +#ifdef DB_CACHE + /* clear out the database cache */ + yp_flush_all(); +#endif /* Re-read the securenets database for the hell of it. */ load_securenets(); @@ -456,15 +441,12 @@ ypproc_clear_2_svc(void *argp, struct svc_req *rqstp) static bool_t xdr_my_ypresp_all(register XDR *xdrs, ypresp_all *objp) { - DBT key, data; + DBT key = { NULL, 0 } , data = { NULL, 0 }; while (1) { /* Get a record. */ - key.size = objp->ypresp_all_u.val.key.keydat_len; - key.data = objp->ypresp_all_u.val.key.keydat_val; - if ((objp->ypresp_all_u.val.stat = - yp_next_record(spec_dbp,&key,&data,1)) == YP_TRUE) { + yp_next_record(spec_dbp,&key,&data,1,0)) == YP_TRUE) { objp->ypresp_all_u.val.val.valdat_len = data.size; objp->ypresp_all_u.val.val.valdat_val = data.data; objp->ypresp_all_u.val.key.keydat_len = key.size; @@ -506,18 +488,12 @@ ypproc_all_2_svc(ypreq_nokey *argp, struct svc_req *rqstp) return (&result); } - if (yp_validdomain(argp->domain)) { - result.ypresp_all_u.val.stat = YP_NODOM; - return(&result); - } - /* * The ypproc_all procedure can take a while to complete. * Best to handle it in a subprocess so the parent doesn't - * block. We fork() here so we don't end up sharing a - * DB file handle with the parent. + * block. (Is there a better way to do this? Maybe with + * async socket I/O?) */ - if (!debug && children < MAX_CHILDREN && fork()) { children++; forked = 0; @@ -526,17 +502,24 @@ ypproc_all_2_svc(ypreq_nokey *argp, struct svc_req *rqstp) forked++; } +#ifndef DB_CACHE if ((spec_dbp = yp_open_db(argp->domain, argp->map)) == NULL) { result.ypresp_all_u.val.stat = yp_errno; return(&result); } +#else + if ((spec_dbp = yp_open_db_cache(argp->domain, argp->map, NULL, 0)) == NULL) { + result.ypresp_all_u.val.stat = yp_errno; + return(&result); + } +#endif /* Kick off the actual data transfer. */ svc_sendreply(rqstp->rq_xprt, xdr_my_ypresp_all, (char *)&result); - /* Close database when done. */ +#ifndef DB_CACHE (void)(spec_dbp->close)(spec_dbp); - +#endif /* * Returning NULL prevents the dispatcher from calling * svc_sendreply() since we already did it. @@ -548,7 +531,8 @@ ypresp_master * ypproc_master_2_svc(ypreq_nokey *argp, struct svc_req *rqstp) { static ypresp_master result; - DBT key,data; + static char ypvalbuf[YPMAXRECORD]; + DBT key, data; result.peer = ""; @@ -561,20 +545,23 @@ ypproc_master_2_svc(ypreq_nokey *argp, struct svc_req *rqstp) result.stat = YP_BADARGS; return (&result); } - - if (yp_validdomain(argp->domain)) { - result.stat = YP_NODOM; - return (&result); - } - - key.data = "YP_MASTER_NAME"; - key.size = sizeof("YP_MASTER_NAME") - 1; - result.stat = yp_get_record(argp->domain, argp->map, &key, &data, 1); + key.data = master_string; + key.size = strlen(master_string); - if (result.stat == YP_TRUE) { - result.peer = (char *)data.data; - result.peer[data.size] = '\0'; + /* + * Note that we copy the data retrieved from the database to + * a private buffer and NUL terminate the buffer rather than + * terminating the data in place. We do this because by stuffing + * a '\0' into data.data, we will actually be corrupting memory + * allocated by the DB package. This is a bad thing now that we + * cache DB handles rather than closing the database immediately. + */ + if ((result.stat = yp_get_record(argp->domain, argp->map, + &key, &data, 1)) == YP_TRUE) { + bcopy((char *)data.data, (char *)&ypvalbuf, data.size); + ypvalbuf[data.size] = '\0'; + result.peer = (char *)&ypvalbuf; } else result.peer = ""; @@ -599,27 +586,23 @@ ypproc_order_2_svc(ypreq_nokey *argp, struct svc_req *rqstp) return (&result); } - if (yp_validdomain(argp->domain)) { - result.stat = YP_NODOM; - return (&result); - } - /* * We could just check the timestamp on the map file, * but that's a hack: we'll only know the last time the file * was touched, not the last time the database contents were * updated. */ - key.data = "YP_LAST_MODIFIED"; - key.size = sizeof("YP_LAST_MODIFIED") - 1; - result.stat = yp_get_record(argp->domain, argp->map, &key, &data, 1); + key.data = order_string; + key.size = strlen(order_string); - if (result.stat == YP_TRUE) + if ((result.stat = yp_get_record(argp->domain, argp->map, + &key, &data, 1)) == YP_TRUE) result.ordernum = atoi((char *)data.data); else result.ordernum = 0; + return (&result); } @@ -689,9 +672,7 @@ static struct ypmaplist *yp_maplist_create(domain) ypresp_maplist * ypproc_maplist_2_svc(domainname *argp, struct svc_req *rqstp) { - static ypresp_maplist result; - - result.maps = NULL; + static ypresp_maplist result = { 0, NULL }; if (yp_access(NULL, (struct svc_req *)rqstp)) { result.stat = YP_YPERR; |