diff options
Diffstat (limited to 'usr.sbin/rpc.ypxfrd')
| -rw-r--r-- | usr.sbin/rpc.ypxfrd/Makefile | 35 | ||||
| -rw-r--r-- | usr.sbin/rpc.ypxfrd/Makefile.depend | 19 | ||||
| -rw-r--r-- | usr.sbin/rpc.ypxfrd/rpc.ypxfrd.8 | 151 | ||||
| -rw-r--r-- | usr.sbin/rpc.ypxfrd/ypxfrd_extern.h | 50 | ||||
| -rw-r--r-- | usr.sbin/rpc.ypxfrd/ypxfrd_main.c | 303 | ||||
| -rw-r--r-- | usr.sbin/rpc.ypxfrd/ypxfrd_server.c | 145 |
6 files changed, 703 insertions, 0 deletions
diff --git a/usr.sbin/rpc.ypxfrd/Makefile b/usr.sbin/rpc.ypxfrd/Makefile new file mode 100644 index 000000000000..2e0decd7a763 --- /dev/null +++ b/usr.sbin/rpc.ypxfrd/Makefile @@ -0,0 +1,35 @@ +.PATH: ${SRCTOP}/usr.sbin/ypserv + +PACKAGE=yp +PROG= rpc.ypxfrd +MAN= rpc.ypxfrd.8 +SRCS= ypxfrd_svc.c ypxfrd.h ypxfrd_server.c yp_error.c \ + yp_access.c ypxfrd_main.c + +CFLAGS+= -I. -DXFRBLOCKSIZE=65535 + +WARNS?= 2 + +LIBADD= rpcsvc + +CLEANFILES= ypxfrd_svc.c ypxfrd.h + +RPCDIR= ${SRCTOP}/include/rpcsvc +RPCGEN= RPCGEN_CPP=${CPP:Q} rpcgen -I -C + +# We need to remove the 'static' keyword from _rpcsvcstate so that +# ypxfrd_main.c can see it. +ypxfrd_svc.c: ${RPCDIR}/ypxfrd.x + rm -f ${.TARGET} + ${RPCGEN} -m ${.ALLSRC} | \ + sed s/"static int _rpcsvcstate"/"int _rpcsvcstate"/g > ${.TARGET} + +# ypxfrd_xdr.c: ${RPCDIR}/ypxfrd.x +# rm -f ${.TARGET} +# ${RPCGEN} -c -o ${.TARGET} ${RPCDIR}/ypxfrd.x + +ypxfrd.h: ${RPCDIR}/ypxfrd.x + rm -f ${.TARGET} + ${RPCGEN} -h -o ${.TARGET} ${.ALLSRC} + +.include <bsd.prog.mk> diff --git a/usr.sbin/rpc.ypxfrd/Makefile.depend b/usr.sbin/rpc.ypxfrd/Makefile.depend new file mode 100644 index 000000000000..210baeaabfd6 --- /dev/null +++ b/usr.sbin/rpc.ypxfrd/Makefile.depend @@ -0,0 +1,19 @@ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + include \ + include/arpa \ + include/rpc \ + include/rpcsvc \ + include/xlocale \ + lib/${CSU_DIR} \ + lib/libc \ + lib/libcompiler_rt \ + lib/librpcsvc \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/usr.sbin/rpc.ypxfrd/rpc.ypxfrd.8 b/usr.sbin/rpc.ypxfrd/rpc.ypxfrd.8 new file mode 100644 index 000000000000..7b2573421159 --- /dev/null +++ b/usr.sbin/rpc.ypxfrd/rpc.ypxfrd.8 @@ -0,0 +1,151 @@ +.\" Copyright (c) 1995, 1996 +.\" Bill Paul <wpaul@ctr.columbia.edu>. 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 Bill Paul. +.\" 4. Neither the name of the author nor the names of contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY Bill Paul 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 Bill Paul 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. +.\" +.Dd June 2, 1996 +.Dt RPC.YPXFRD 8 +.Os +.Sh NAME +.Nm rpc.ypxfrd +.Nd "NIS map transfer server" +.Sh SYNOPSIS +.Nm +.Op Fl p Ar path +.Sh DESCRIPTION +The +.Nm +utility is used to speed up the distribution of very large NIS maps +from NIS master to NIS slave servers. +The normal method for transferring +maps involves several steps: +.Bl -bullet -offset indent +.It +The master server calls +.Xr yppush 8 +to inform the slave servers to start a transfer. +.It +The slave servers invoke +.Xr ypxfr 8 , +which reads the entire contents of a map from the master server +using the yp_all() function. +.It +The +.Xr ypxfr 8 +program then creates a new map database file by using the +.Xr db 3 +library hash method to store the data that it receives from the server. +.It +When all the data has been retrieved, +.Xr ypxfr 8 +moves the new file into place and sends +.Xr ypserv 8 +on the local machine a YPPROC_CLEAR to tell it to refresh its +database handles. +.El +.Pp +This process can take several minutes when there are very large +maps involved. +For example: a passwd database with several tens of +thousands of entries can consume several megabytes of disk space, +and it can take the +.Xr db 3 +library package a long time to sort and store all the records +in a hash database. +Consider also that there are two sets of map +files: +.Pa master.passwd.by{name,uid} +and +.Pa passwd.by{name,uid} . +.Pp +The +.Nm +utility speeds up the transfer process by allowing NIS slave servers to +simply copy the master server's map files rather than building their +own from scratch. +Simply put, +.Nm +implements an RPC-based file transfer protocol. +Transferring even +a multi-megabyte file in this fashion takes only a few seconds compared +to the several minutes it would take even a reasonably fast slave server +to build a new map from scratch. +.Pp +The +.Nm +utility uses the same access restriction mechanism as +.Xr ypserv 8 . +This means that slave servers will only be permitted to transfer +files if the rules in the +.Pa securenets +database permit it (see +.Xr ypserv 8 +for more information on +.Pa securenets ) . +Furthermore, only slave servers using reserved +ports will be allowed to transfer the +.Pa master.passwd +maps. +.Sh OPTIONS +The following option is available: +.Bl -tag -width indent +.It Fl p Ar path +This option can be used to override the default path to +the location of the NIS +map databases. +The compiled-in default path is +.Pa /var/yp . +.El +.Sh FILES +.Bl -tag -width Pa -compact +.It Pa /var/yp/[domainname]/[maps] +The NIS maps for a particular NIS domain. +.El +.Sh SEE ALSO +.Xr yp 8 , +.Xr yppush 8 , +.Xr ypserv 8 , +.Xr ypxfr 8 +.Sh AUTHORS +.An Bill Paul Aq Mt wpaul@ctr.columbia.edu +.Sh BUGS +The +.Fx +.Nm ypxfrd +protocol is not compatible with that used by SunOS. +This is unfortunate +but unavoidable: Sun's protocol is not freely available, and even if it +were it would probably not be useful since the SunOS NIS v2 implementation +uses the original ndbm package for its map databases whereas the +.Fx +implementation uses Berkeley DB. +These two packages use vastly different +file formats. +Furthermore, ndbm is byte-order sensitive and not very +smart about it, meaning that am ndbm database created on a big endian +system cannot be read on a little endian system. diff --git a/usr.sbin/rpc.ypxfrd/ypxfrd_extern.h b/usr.sbin/rpc.ypxfrd/ypxfrd_extern.h new file mode 100644 index 000000000000..efe5b3ff2cec --- /dev/null +++ b/usr.sbin/rpc.ypxfrd/ypxfrd_extern.h @@ -0,0 +1,50 @@ +/*- + * SPDX-License-Identifier: BSD-4-Clause + * + * Copyright (c) 1995, 1996 + * Bill Paul <wpaul@ctr.columbia.edu>. 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 Bill Paul. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Bill Paul 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 Bill Paul 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. + */ + +#ifndef MAX_CHILDREN +#define MAX_CHILDREN 20 +#endif + +#ifndef XFRBLOCKSIZE +#define XFRBLOCKSIZE YPXFRBLOCK +#endif + +extern int forked; +extern int children; +extern void load_securenets(void); +extern void yp_error(const char *, ...); +extern int yp_access(const char *, const struct svc_req *); +extern int yp_validdomain(const char *); +extern char *yp_dir; +extern void ypxfrd_freebsd_prog_1(struct svc_req *, register SVCXPRT *); diff --git a/usr.sbin/rpc.ypxfrd/ypxfrd_main.c b/usr.sbin/rpc.ypxfrd/ypxfrd_main.c new file mode 100644 index 000000000000..5498535930f1 --- /dev/null +++ b/usr.sbin/rpc.ypxfrd/ypxfrd_main.c @@ -0,0 +1,303 @@ +/*- + * SPDX-License-Identifier: BSD-4-Clause + * + * Copyright (c) 1995, 1996 + * Bill Paul <wpaul@ctr.columbia.edu>. 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 Bill Paul. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Bill Paul 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 Bill Paul 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 <sys/cdefs.h> +#include "ypxfrd.h" +#include <err.h> +#include <fcntl.h> +#include <paths.h> +#include <stdio.h> +#include <stdlib.h> /* getenv, exit */ +#include <unistd.h> +#include <rpc/pmap_clnt.h> /* for pmap_unset */ +#include <rpc/rpc_com.h> +#include <string.h> /* strcmp */ +#include <signal.h> +#include <sys/ttycom.h> /* TIOCNOTTY */ +#ifdef __cplusplus +#include <sysent.h> /* getdtablesize, open */ +#endif /* __cplusplus */ +#include <memory.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <syslog.h> +#include "ypxfrd_extern.h" +#include <sys/wait.h> +#include <errno.h> + +#ifndef SIG_PF +#define SIG_PF void(*)(int) +#endif + +#ifdef DEBUG +#define RPC_SVC_FG +#endif + +#define _RPCSVC_CLOSEDOWN 120 +int _rpcpmstart; /* Started by a port monitor ? */ +static int _rpcfdtype; + /* Whether Stream or Datagram ? */ + /* States a server can be in wrt request */ + +#define _IDLE 0 +#define _SERVED 1 +#define _SERVING 2 + +extern int _rpcsvcstate; /* Set when a request is serviced */ + +int debug; + +char *progname = "rpc.ypxfrd"; +char *yp_dir = "/var/yp/"; + +static void +_msgout(char *msg) +{ +#ifdef RPC_SVC_FG + if (_rpcpmstart) + syslog(LOG_ERR, "%s", msg); + else + warnx("%s", msg); +#else + syslog(LOG_ERR, "%s", msg); +#endif +} + +static void +closedown(int sig) +{ + if (_rpcsvcstate == _IDLE) { + extern fd_set svc_fdset; + static int size; + int i, openfd; + + if (_rpcfdtype == SOCK_DGRAM) + exit(0); + if (size == 0) { + size = getdtablesize(); + } + for (i = 0, openfd = 0; i < size && openfd < 2; i++) + if (FD_ISSET(i, &svc_fdset)) + openfd++; + if (openfd <= 1) + exit(0); + } + if (_rpcsvcstate == _SERVED) + _rpcsvcstate = _IDLE; + + (void) signal(SIGALRM, (SIG_PF) closedown); + (void) alarm(_RPCSVC_CLOSEDOWN/2); +} + + +static void +ypxfrd_svc_run(void) +{ +#ifdef FD_SETSIZE + fd_set readfds; +#else + int readfds; +#endif /* def FD_SETSIZE */ + extern int forked; + int pid; + int fd_setsize = _rpc_dtablesize(); + + /* Establish the identity of the parent ypserv process. */ + pid = getpid(); + + for (;;) { +#ifdef FD_SETSIZE + readfds = svc_fdset; +#else + readfds = svc_fds; +#endif /* def FD_SETSIZE */ + switch (select(fd_setsize, &readfds, NULL, NULL, + (struct timeval *)0)) { + case -1: + if (errno == EINTR) { + continue; + } + warn("svc_run: - select failed"); + return; + case 0: + continue; + default: + svc_getreqset(&readfds); + if (forked && pid != getpid()) + exit(0); + } + } +} + +static void reaper(int sig) +{ + int status; + int saved_errno; + + saved_errno = errno; + + if (sig == SIGHUP) { + load_securenets(); + errno = saved_errno; + return; + } + + if (sig == SIGCHLD) { + while (wait3(&status, WNOHANG, NULL) > 0) + children--; + } else { + (void) pmap_unset(YPXFRD_FREEBSD_PROG, YPXFRD_FREEBSD_VERS); + exit(0); + } + + errno = saved_errno; +} + +void +usage(void) +{ + fprintf(stderr, "usage: rpc.ypxfrd [-p path]\n"); + exit(0); +} + +int +main(int argc, char *argv[]) +{ + register SVCXPRT *transp = NULL; + int sock; + int proto = 0; + struct sockaddr_in saddr; + int asize = sizeof (saddr); + int ch; + + while ((ch = getopt(argc, argv, "p:h")) != -1) { + switch (ch) { + case 'p': + yp_dir = optarg; + break; + default: + usage(); + break; + } + } + + load_securenets(); + + if (getsockname(0, (struct sockaddr *)&saddr, &asize) == 0) { + int ssize = sizeof (int); + + if (saddr.sin_family != AF_INET) + exit(1); + if (getsockopt(0, SOL_SOCKET, SO_TYPE, + (char *)&_rpcfdtype, &ssize) == -1) + exit(1); + sock = 0; + _rpcpmstart = 1; + proto = 0; + openlog("rpc.ypxfrd", LOG_PID, LOG_DAEMON); + } else { +#ifndef RPC_SVC_FG + int size; + int pid, i; + + pid = fork(); + if (pid < 0) + err(1, "fork"); + if (pid) + exit(0); + size = getdtablesize(); + for (i = 0; i < size; i++) + (void) close(i); + i = open(_PATH_CONSOLE, 2); + (void) dup2(i, 1); + (void) dup2(i, 2); + i = open(_PATH_TTY, 2); + if (i >= 0) { + (void) ioctl(i, TIOCNOTTY, (char *)NULL); + (void) close(i); + } + openlog("rpc.ypxfrd", LOG_PID, LOG_DAEMON); +#endif + sock = RPC_ANYSOCK; + (void) pmap_unset(YPXFRD_FREEBSD_PROG, YPXFRD_FREEBSD_VERS); + } + + if ((_rpcfdtype == 0) || (_rpcfdtype == SOCK_DGRAM)) { + transp = svcudp_create(sock); + if (transp == NULL) { + _msgout("cannot create udp service."); + exit(1); + } + if (!_rpcpmstart) + proto = IPPROTO_UDP; + if (!svc_register(transp, YPXFRD_FREEBSD_PROG, YPXFRD_FREEBSD_VERS, ypxfrd_freebsd_prog_1, proto)) { + _msgout("unable to register (YPXFRD_FREEBSD_PROG, YPXFRD_FREEBSD_VERS, udp)."); + exit(1); + } + } + + if ((_rpcfdtype == 0) || (_rpcfdtype == SOCK_STREAM)) { + transp = svctcp_create(sock, 0, 0); + if (transp == NULL) { + _msgout("cannot create tcp service."); + exit(1); + } + if (!_rpcpmstart) + proto = IPPROTO_TCP; + if (!svc_register(transp, YPXFRD_FREEBSD_PROG, YPXFRD_FREEBSD_VERS, ypxfrd_freebsd_prog_1, proto)) { + _msgout("unable to register (YPXFRD_FREEBSD_PROG, YPXFRD_FREEBSD_VERS, tcp)."); + exit(1); + } + } + + if (transp == (SVCXPRT *)NULL) { + _msgout("could not create a handle"); + exit(1); + } + if (_rpcpmstart) { + (void) signal(SIGALRM, (SIG_PF) closedown); + (void) alarm(_RPCSVC_CLOSEDOWN/2); + } + + (void) signal(SIGPIPE, SIG_IGN); + (void) signal(SIGCHLD, (SIG_PF) reaper); + (void) signal(SIGTERM, (SIG_PF) reaper); + (void) signal(SIGINT, (SIG_PF) reaper); + (void) signal(SIGHUP, (SIG_PF) reaper); + + ypxfrd_svc_run(); + _msgout("svc_run returned"); + exit(1); + /* NOTREACHED */ +} diff --git a/usr.sbin/rpc.ypxfrd/ypxfrd_server.c b/usr.sbin/rpc.ypxfrd/ypxfrd_server.c new file mode 100644 index 000000000000..f012fbaf50d3 --- /dev/null +++ b/usr.sbin/rpc.ypxfrd/ypxfrd_server.c @@ -0,0 +1,145 @@ +/*- + * SPDX-License-Identifier: BSD-4-Clause + * + * Copyright (c) 1995, 1996 + * Bill Paul <wpaul@ctr.columbia.edu>. 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 Bill Paul. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Bill Paul 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 Bill Paul 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 <sys/cdefs.h> +#include "ypxfrd.h" + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <errno.h> +#include <sys/types.h> +#include <sys/param.h> +#include <sys/uio.h> +#include <sys/fcntl.h> +#include <machine/endian.h> +#include "ypxfrd_extern.h" + +int forked = 0; +int children = 0; +int fp = 0; + +static bool_t +xdr_my_xfr(register XDR *xdrs, xfr *objp) +{ + unsigned char buf[XFRBLOCKSIZE]; + + while (1) { + if ((objp->xfr_u.xfrblock_buf.xfrblock_buf_len = + read(fp, &buf, XFRBLOCKSIZE)) != -1) { + objp->ok = TRUE; + objp->xfr_u.xfrblock_buf.xfrblock_buf_val = (char *)&buf; + } else { + objp->ok = FALSE; + objp->xfr_u.xfrstat = XFR_READ_ERR; + yp_error("read error: %s", strerror(errno)); + } + + /* Serialize */ + if (!xdr_xfr(xdrs, objp)) + return(FALSE); + if (objp->ok == FALSE) + return(TRUE); + if (objp->xfr_u.xfrblock_buf.xfrblock_buf_len < XFRBLOCKSIZE) { + objp->ok = FALSE; + objp->xfr_u.xfrstat = XFR_DONE; + if (!xdr_xfr(xdrs, objp)) + return(FALSE); + return(TRUE); + } + } +} + +struct xfr * +ypxfrd_getmap_1_svc(ypxfr_mapname *argp, struct svc_req *rqstp) +{ + static struct xfr result; + char buf[MAXPATHLEN]; + + result.ok = FALSE; + result.xfr_u.xfrstat = XFR_DENIED; + + if (yp_validdomain(argp->xfrdomain)) { + return(&result); + } + + if (yp_access(argp->xfrmap, (struct svc_req *)rqstp)) { + return(&result); + } + + snprintf (buf, sizeof(buf), "%s/%s/%s", yp_dir, argp->xfrdomain, + argp->xfrmap); + if (access(buf, R_OK) == -1) { + result.xfr_u.xfrstat = XFR_ACCESS; + return(&result); + } + + if (argp->xfr_db_type != XFR_DB_BSD_HASH && + argp->xfr_db_type != XFR_DB_ANY) { + result.xfr_u.xfrstat = XFR_DB_TYPE_MISMATCH; + return(&result); + } + +#if BYTE_ORDER == LITTLE_ENDIAN + if (argp->xfr_byte_order == XFR_ENDIAN_BIG) { +#else + if (argp->xfr_byte_order == XFR_ENDIAN_LITTLE) { +#endif + result.xfr_u.xfrstat = XFR_DB_ENDIAN_MISMATCH; + return(&result); + } + +#ifndef DEBUG + if (children < MAX_CHILDREN && fork()) { + children++; + forked = 0; + return (NULL); + } else { + forked++; + } +#endif + if ((fp = open(buf, O_RDONLY)) == -1) { + result.xfr_u.xfrstat = XFR_READ_ERR; + return(&result); + } + + /* Start sending the file. */ + + svc_sendreply(rqstp->rq_xprt, (xdrproc_t)xdr_my_xfr, &result); + + close(fp); + + return (NULL); +} |
