Import rpc.ypxfrd.

This server impliments an RPC-based file transfer protocol that allows
an NIS slave server to copy a raw map database file from an NIS master.

The goal here is to speed up the transfer of very large maps. If you
have, for example, an NIS password database with 30,000 records in it,
it can take around 8 to 10 minutes to regenerate it (four hash databases
are created). As it stands now, ypxfr(8) transfers a map by sucking all
the records from ypserv(8) on the master using yp_all() and writing them
to a new database using the db(3) library. This adds up to another 8 to 10
minutes, per slave. With as the number of slaves increases, this latency
becomes prohibitive.

With rpc.ypxfrd, all the slave has to do is copy the already-built
hash database file from the master and move it into place. Even with a
multi-megabyte file, this reduces the master to slave transfer time
to well under a minute. (This is using TCP.)

Access restrictions are applied using the same mechanism as in ypserv:
you can control access using /var/yp/securenets, and the server will
not transmit the master.passwd.* maps unless the transfer request originates
on a reserved port.

Note: this server is based on my hastily contrived protocol and is _NOT_
compatible with Sun's protocol of the same name. It can't be compatible
for a couple of reasons. For one thing, Sun's protocol has not been published
anywhere that I know of. It is not included in any of the SunRPC source
distributions that I've been able to find. Second, Sun's NIS v2 code
uses old style ndbm maps while FreeBSD uses Berkeley DB. The file formats
are incompatible, so being able to transfer maps between FreeBSD and SunOS
hosts wouldn't do any good anyway. (You could always port the FreeBSD NIS
code to SunOS if you really wanted to do it. :)

(There's also the little fact that SunOS/SPARC is big-endian and FreeBSD/i386
is little-endian. Berkeley DB can handle byte ordering differences; ndbm
probably can't.)
This commit is contained in:
Bill Paul 1996-06-05 04:36:55 +00:00
parent c8bb0df5d3
commit 16118c2bcb
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/cvs2svn/branches/WPAUL/dist/; revision=16125
6 changed files with 767 additions and 0 deletions

View File

@ -0,0 +1,36 @@
# $Id: Makefile,v 1.4 1996/06/03 04:48:32 wpaul Exp $
PROG= rpc.ypxfrd
SRCS= ypxfrd_svc.c ypxfrd_server.c yp_error.c \
ypxfrd_xdr.c yp_access.c ypxfrd_main.c
RPCDIR= ${.CURDIR}/../../include/rpcsvc
.PATH: ${.CURDIR}/../../usr.sbin/ypserv
MAN8= rpc.ypxfrd.8
CFLAGS+= -I. -DXFRBLOCKSIZE=65535
LDADD+=-lrpcsvc
CLEANFILES= ypxfrd_svc.c ypxfrd.h
RPCGEN= 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 ypxfrd.h
rm -f ${.TARGET}
${RPCGEN} -m ${RPCDIR}/ypxfrd.x | \
sed s/"static int _rpcsvcstate"/"int _rpcsvcstate"/g > ${.TARGET}
# ypxfrd_xdr.c: ${RPCDIR}/ypxfrd.x ypxfrd.h
# rm -f ${.TARGET}
# ${RPCGEN} -c -o ${.TARGET} ${RPCDIR}/ypxfrd.x
ypxfrd.h: ${RPCDIR}/ypxfrd.x
rm -f ${.TARGET}
${RPCGEN} -h -o ${.TARGET} ${RPCDIR}/ypxfrd.x
.include <bsd.prog.mk>

View File

@ -0,0 +1,139 @@
.\" 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.
.\"
.\" $Id: rpc.ypxfrd.8,v 1.2 1996/06/03 20:17:16 wpaul Exp $
.\"
.Dd June 2, 1996
.Dt RPC.YPXFRD 8
.Os
.Sh NAME
.Nm rpc.ypxfrd
.Nd "NIS map transfer server"
.Sh SYNOPSIS
.Nm rpc.ypxfrd
.Op Fl p Ar path
.Sh DESCRIPTION
The
.Nm rpc.ypxfrd
daemon is used to speed up the distribtion of very large NIS maps
from NIS master to NIS slave servers. The normal method for transfering
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 rpc.ypxfrd
server 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 rpc.ypxfrd
impliments an RPC-based file transfer protocol. Transfering 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 rpc.ypxfrd
server 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
.Xr securenets 5
database permit it. Furthermore, only slave servers using reserved
ports will be allowed to transfer the
.Pa master.passwd
maps.
.Sh OPTIONS
The following options and flags are supported by
.Nm rpc.ypxfrd :
.Bl -tag -width flag
.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 ypserv 8 ,
.Xr yppush 8 ,
.Xr ypxfr 8 ,
.Xr yp 4
.Sh BUGS
The FreeBSD
.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 implimentation
uses the original ndbm package for its map databases whereas the FreeBSD
implimentation 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 can't be read on a little endian system.
.Sh AUTHOR
Bill Paul <wpaul@ctr.columbia.edu>

View File

@ -0,0 +1,117 @@
/*
* 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.
*
* $Id: ypxfrd.x,v 1.8 1996/06/03 20:17:04 wpaul Exp $
*/
/*
* This protocol definition file describes a file transfer
* system used to very quickly move NIS maps from one host to
* another. This is similar to what Sun does with their ypxfrd
* protocol, but it must be stressed that this protocol is _NOT_
* compatible with Sun's. There are a couple of reasons for this:
*
* 1) Sun's protocol is proprietary. The protocol definition is
* not freely available in any of the SunRPC source distributions,
* even though the NIS v2 protocol is.
*
* 2) The idea here is to transfer entire raw files rather than
* sending just the records. Sun uses ndbm for its NIS map files,
* while FreeBSD uses Berkeley DB. Both are hash databases, but the
* formats are incompatible, making it impossible for them to
* use each others' files. Even if FreeBSD adopted ndbm for its
* database format, FreeBSD/i386 is a little-endian OS and
* SunOS/SPARC is big-endian; ndbm is byte-order sensitive and
* not very smart about it, which means an attempt to read a
* database on a little-endian box that was created on a big-endian
* box (or vice-versa) can cause the ndbm code to eat itself.
* Luckily, Berkeley DB is able to deal with this situation in
* a more graceful manner.
*
* While the protocol is incompatible, the idea is the same: we just open
* up a TCP pipe to the client and transfer the raw map database
* from the master server to the slave. This is many times faster than
* the standard yppush/ypxfr transfer method since it saves us from
* having to recreate the map databases via the DB library each time.
* For example: creating a passwd database with 30,000 entries with yp_mkdb
* can take a couple of minutes, but to just copy the file takes only a few
* seconds.
*/
#ifndef RPC_HDR
%#ifndef lint
%static const char rcsid[] = "$Id: ypxfrd.x,v 1.8 1996/06/03 20:17:04 wpaul Exp $";
%#endif /* not lint */
#endif
/* XXX cribbed from yp.x */
const _YPMAXRECORD = 1024;
const _YPMAXDOMAIN = 64;
const _YPMAXMAP = 64;
const _YPMAXPEER = 64;
/* Suggested default -- not necesarrily the one used. */
const YPXFRBLOCK = 32767;
enum xfrstat {
XFR_REQUEST_OK = 1, /* Transfer request granted */
XFR_DENIED = 2, /* Transfer request denied */
XFR_NOFILE = 3, /* Requested map file doesn't exist */
XFR_ACCESS = 4, /* File exists, but I couldn't access it */
XFR_BADDB = 5, /* File is not a hash database */
XFR_READ_OK = 6, /* Block read successfully */
XFR_READ_ERR = 7, /* Read error during transfer */
XFR_DONE = 8 /* Transfer completed */
};
typedef string xfrdomain<_YPMAXDOMAIN>;
typedef string xfrmap<_YPMAXMAP>;
/* Ask the remote ypxfrd for a map using this structure */
struct ypxfr_mapname {
xfrmap xfrmap;
xfrdomain xfrdomain;
};
/* Read response using this structure. */
union xfr switch (bool ok) {
case TRUE:
opaque xfrblock_buf<>;
case FALSE:
enum xfrstat xfrstat;
};
program YPXFRD_FREEBSD_PROG {
version YPXFRD_FREEBSD_VERS {
union xfr
YPXFRD_GETMAP(ypxfr_mapname) = 1;
} = 1;
} = 600100069; /* 100069 + 60000000 -- 100069 is the Sun ypxfrd prog number */

View File

@ -0,0 +1,50 @@
/*
* 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.
*
* $Id: ypxfrd_extern.h,v 1.3 1996/06/02 17:24:20 wpaul Exp $
*/
#ifndef MAX_CHILDREN
#define MAX_CHILDREN 20
#endif
#ifndef XFRBLOCKSIZE
#define XFRBLOCKSIZE YPXFRBLOCK
#endif
extern int forked;
extern int children;
extern void load_securenets __P(( void ));
extern void yp_error __P((const char *, ...));
extern int yp_access __P((const char *, const struct svc_req * ));
extern int yp_validdomain __P((const char * ));
extern char *yp_dir;
extern void ypxfrd_freebsd_prog_1 __P(( struct svc_req *, register SVCXPRT * ));

View File

@ -0,0 +1,295 @@
/*
* 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.
*
* $Id: ypxfrd_main.c,v 1.4 1996/06/04 04:27:47 wpaul Exp $
*/
#include "ypxfrd.h"
#include <stdio.h>
#include <stdlib.h> /* getenv, exit */
#include <rpc/pmap_clnt.h> /* for pmap_unset */
#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
#ifndef lint
static const char rcsid[] = "$Id: ypxfrd_main.c,v 1.4 1996/06/04 04:27:47 wpaul Exp $";
#endif /* not lint */
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 */
char *progname = "rpc.ypxfrd";
char *yp_dir = "/var/yp/";
static
void _msgout(char* msg)
{
#ifdef RPC_SVC_FG
if (_rpcpmstart)
syslog(LOG_ERR, msg);
else
(void) fprintf(stderr, "%s\n", msg);
#else
syslog(LOG_ERR, 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()
{
#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;
}
perror("svc_run: - select failed");
return;
case 0:
continue;
default:
svc_getreqset(&readfds);
if (forked && pid != getpid())
exit(0);
}
}
}
static void reaper(sig)
int sig;
{
int status;
if (sig == SIGHUP) {
load_securenets();
return;
}
if (sig == SIGCHLD) {
while (wait3(&status, WNOHANG, NULL) > 0)
children--;
} else {
(void) pmap_unset(YPXFRD_FREEBSD_PROG, YPXFRD_FREEBSD_VERS);
exit(0);
}
}
void usage()
{
fprintf(stderr, "%s [-p path]\n", progname);
exit(0);
}
main(argc, argv)
int argc;
char *argv[];
{
register SVCXPRT *transp;
int sock;
int proto;
struct sockaddr_in saddr;
int asize = sizeof (saddr);
int ch;
while ((ch = getopt(argc, argv, "p:h")) != EOF) {
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) {
perror("cannot fork");
exit(1);
}
if (pid)
exit(0);
size = getdtablesize();
for (i = 0; i < size; i++)
(void) close(i);
i = open("/dev/console", 2);
(void) dup2(i, 1);
(void) dup2(i, 2);
i = open("/dev/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 */
}

View File

@ -0,0 +1,130 @@
/*
* 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.
*
* $Id: ypxfrd_server.c,v 1.5 1996/06/02 17:34:49 wpaul Exp $
*/
#include "ypxfrd.h"
#ifndef lint
static const char rcsid[] = "$Id: ypxfrd_server.c,v 1.5 1996/06/02 17:34:49 wpaul Exp $";
#endif /* not lint */
#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 "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((char *)&buf, R_OK) == -1) {
result.xfr_u.xfrstat = XFR_ACCESS;
return(&result);
}
#ifndef DEBUG
if (children < MAX_CHILDREN && fork()) {
children++;
forked = 0;
return (NULL);
} else {
forked++;
}
#endif
if ((fp = open((char *)&buf, O_RDONLY)) == -1) {
result.xfr_u.xfrstat = XFR_READ_ERR;
return(&result);
}
/* Start sending the file. */
svc_sendreply(rqstp->rq_xprt, xdr_my_xfr, (char *)&result);
close(fp);
return (NULL);
}