Home | History | Annotate | Line # | Download | only in ypserv
ypserv.c revision 1.8
      1  1.8   thorpej /*	$NetBSD: ypserv.c,v 1.8 1999/01/22 02:36:13 thorpej Exp $	*/
      2  1.1   thorpej 
      3  1.1   thorpej /*
      4  1.1   thorpej  * Copyright (c) 1994 Mats O Jansson <moj (at) stacken.kth.se>
      5  1.1   thorpej  * All rights reserved.
      6  1.1   thorpej  *
      7  1.1   thorpej  * Redistribution and use in source and binary forms, with or without
      8  1.1   thorpej  * modification, are permitted provided that the following conditions
      9  1.1   thorpej  * are met:
     10  1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     11  1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     12  1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     14  1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     15  1.1   thorpej  * 3. All advertising materials mentioning features or use of this software
     16  1.1   thorpej  *    must display the following acknowledgement:
     17  1.1   thorpej  *	This product includes software developed by Mats O Jansson
     18  1.1   thorpej  * 4. The name of the author may not be used to endorse or promote products
     19  1.1   thorpej  *    derived from this software without specific prior written permission.
     20  1.1   thorpej  *
     21  1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     22  1.1   thorpej  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     23  1.1   thorpej  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  1.1   thorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
     25  1.1   thorpej  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  1.1   thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27  1.1   thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28  1.1   thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29  1.1   thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  1.1   thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  1.1   thorpej  * SUCH DAMAGE.
     32  1.1   thorpej  */
     33  1.1   thorpej 
     34  1.7     lukem #include <sys/cdefs.h>
     35  1.7     lukem #ifndef lint
     36  1.8   thorpej __RCSID("$NetBSD: ypserv.c,v 1.8 1999/01/22 02:36:13 thorpej Exp $");
     37  1.7     lukem #endif
     38  1.7     lukem 
     39  1.1   thorpej #include <sys/types.h>
     40  1.1   thorpej #include <sys/socket.h>
     41  1.1   thorpej #include <sys/wait.h>
     42  1.1   thorpej 
     43  1.1   thorpej #include <netinet/in.h>
     44  1.1   thorpej 
     45  1.5   thorpej #include <err.h>
     46  1.1   thorpej #include <netdb.h>
     47  1.1   thorpej #include <signal.h>
     48  1.1   thorpej #include <stdio.h>
     49  1.1   thorpej #include <stdlib.h>
     50  1.1   thorpej #include <string.h>
     51  1.5   thorpej #include <syslog.h>
     52  1.5   thorpej #include <unistd.h>
     53  1.1   thorpej 
     54  1.1   thorpej #include <rpc/rpc.h>
     55  1.1   thorpej #include <rpc/xdr.h>
     56  1.1   thorpej #include <rpc/pmap_clnt.h>
     57  1.1   thorpej 
     58  1.1   thorpej #include <rpcsvc/yp_prot.h>
     59  1.1   thorpej 
     60  1.1   thorpej #include "ypdef.h"
     61  1.1   thorpej #include "ypserv.h"
     62  1.1   thorpej 
     63  1.8   thorpej #ifdef LIBWRAP
     64  1.8   thorpej #include <tcpd.h>
     65  1.8   thorpej 
     66  1.8   thorpej int allow_severity = LOG_DAEMON | LOG_INFO;
     67  1.8   thorpej int deny_severity = LOG_DAEMON | LOG_WARNING;
     68  1.8   thorpej 
     69  1.8   thorpej /* XXX For ypserv_proc.c -- NOT THREAD SAFE!  (like any of this code is) */
     70  1.8   thorpej const char *clientstr;
     71  1.8   thorpej const char *svcname;
     72  1.8   thorpej #endif /* LIBWRAP */
     73  1.8   thorpej 
     74  1.1   thorpej #ifdef __STDC__
     75  1.1   thorpej #define SIG_PF void(*)(int)
     76  1.1   thorpej #endif
     77  1.1   thorpej 
     78  1.1   thorpej #ifdef DEBUG
     79  1.1   thorpej #define RPC_SVC_FG
     80  1.1   thorpej #endif
     81  1.1   thorpej 
     82  1.1   thorpej #define _RPCSVC_CLOSEDOWN 120
     83  1.1   thorpej static int _rpcpmstart;		/* Started by a port monitor ? */
     84  1.1   thorpej static int _rpcfdtype;		/* Whether Stream or Datagram ? */
     85  1.1   thorpej static int _rpcsvcdirty;	/* Still serving ? */
     86  1.1   thorpej 
     87  1.1   thorpej int	usedns;
     88  1.8   thorpej #ifdef LIBWRAP
     89  1.8   thorpej int	lflag;
     90  1.8   thorpej #endif
     91  1.1   thorpej 
     92  1.1   thorpej extern	char *__progname;	/* from crt0.s */
     93  1.1   thorpej 
     94  1.5   thorpej int	main __P((int, char *[]));
     95  1.1   thorpej void	usage __P((void));
     96  1.1   thorpej 
     97  1.5   thorpej void	sighandler __P((int));
     98  1.5   thorpej 
     99  1.5   thorpej static	void closedown __P((void));
    100  1.1   thorpej 
    101  1.1   thorpej static
    102  1.1   thorpej void _msgout(char* msg)
    103  1.1   thorpej {
    104  1.1   thorpej #ifdef RPC_SVC_FG
    105  1.1   thorpej 	if (_rpcpmstart)
    106  1.1   thorpej 		syslog(LOG_ERR, msg);
    107  1.1   thorpej 	else
    108  1.1   thorpej 		warnx("%s", msg);
    109  1.1   thorpej #else
    110  1.1   thorpej 	syslog(LOG_ERR, msg);
    111  1.1   thorpej #endif
    112  1.1   thorpej }
    113  1.1   thorpej 
    114  1.1   thorpej static void
    115  1.1   thorpej closedown()
    116  1.1   thorpej {
    117  1.1   thorpej 	if (_rpcsvcdirty == 0) {
    118  1.1   thorpej 		extern fd_set svc_fdset;
    119  1.1   thorpej 		static int size;
    120  1.1   thorpej 		int i, openfd;
    121  1.1   thorpej 
    122  1.1   thorpej 		if (_rpcfdtype == SOCK_DGRAM)
    123  1.1   thorpej 			exit(0);
    124  1.1   thorpej 		if (size == 0) {
    125  1.1   thorpej 			size = getdtablesize();
    126  1.1   thorpej 		}
    127  1.1   thorpej 		for (i = 0, openfd = 0; i < size && openfd < 2; i++)
    128  1.1   thorpej 			if (FD_ISSET(i, &svc_fdset))
    129  1.1   thorpej 				openfd++;
    130  1.1   thorpej 		if (openfd <= (_rpcpmstart?0:1))
    131  1.1   thorpej 			exit(0);
    132  1.1   thorpej 	}
    133  1.1   thorpej 	(void) alarm(_RPCSVC_CLOSEDOWN);
    134  1.1   thorpej }
    135  1.1   thorpej 
    136  1.1   thorpej static void
    137  1.6     lukem ypprog_2(struct svc_req *rqstp, SVCXPRT *transp)
    138  1.1   thorpej {
    139  1.1   thorpej 	union {
    140  1.1   thorpej 		char * ypproc_domain_2_arg;
    141  1.1   thorpej 		char * ypproc_domain_nonack_2_arg;
    142  1.1   thorpej 		struct ypreq_key ypproc_match_2_arg;
    143  1.1   thorpej 		struct ypreq_nokey ypproc_first_2_arg;
    144  1.1   thorpej 		struct ypreq_key ypproc_next_2_arg;
    145  1.1   thorpej 		struct ypreq_xfr ypproc_xfr_2_arg;
    146  1.1   thorpej 		struct ypreq_nokey ypproc_all_2_arg;
    147  1.1   thorpej 		struct ypreq_nokey ypproc_master_2_arg;
    148  1.1   thorpej 		struct ypreq_nokey ypproc_order_2_arg;
    149  1.1   thorpej 		char * ypproc_maplist_2_arg;
    150  1.1   thorpej 	} argument;
    151  1.1   thorpej 	char *result;
    152  1.1   thorpej 	xdrproc_t xdr_argument, xdr_result;
    153  1.1   thorpej 	void *(*local) __P((void *, struct svc_req *));
    154  1.8   thorpej #ifdef LIBWRAP
    155  1.8   thorpej 	struct request_info req;
    156  1.8   thorpej 	struct sockaddr_in *caller;
    157  1.8   thorpej #define	SVCNAME(x)	svcname = x
    158  1.8   thorpej #else
    159  1.8   thorpej #define	SVCNAME(x)	/* nothing */
    160  1.8   thorpej #endif
    161  1.1   thorpej 
    162  1.1   thorpej 	_rpcsvcdirty = 1;
    163  1.8   thorpej 
    164  1.8   thorpej #ifdef LIBWRAP
    165  1.8   thorpej 	caller = svc_getcaller(transp);
    166  1.8   thorpej 	request_init(&req, RQ_DAEMON, __progname, RQ_CLIENT_SIN, caller, NULL);
    167  1.8   thorpej 	sock_methods(&req);
    168  1.8   thorpej #endif
    169  1.8   thorpej 
    170  1.1   thorpej 	switch (rqstp->rq_proc) {
    171  1.1   thorpej 	case YPPROC_NULL:
    172  1.1   thorpej 		xdr_argument = xdr_void;
    173  1.1   thorpej 		xdr_result = xdr_void;
    174  1.1   thorpej 		local = ypproc_null_2_svc;
    175  1.8   thorpej 		SVCNAME("null_2");
    176  1.1   thorpej 		break;
    177  1.1   thorpej 
    178  1.1   thorpej 	case YPPROC_DOMAIN:
    179  1.1   thorpej 		xdr_argument = xdr_ypdomain_wrap_string;
    180  1.1   thorpej 		xdr_result = xdr_bool;
    181  1.1   thorpej 		local = ypproc_domain_2_svc;
    182  1.8   thorpej 		SVCNAME("domain_2");
    183  1.1   thorpej 		break;
    184  1.1   thorpej 
    185  1.1   thorpej 	case YPPROC_DOMAIN_NONACK:
    186  1.1   thorpej 		xdr_argument = xdr_ypdomain_wrap_string;
    187  1.1   thorpej 		xdr_result = xdr_bool;
    188  1.1   thorpej 		local = ypproc_domain_nonack_2_svc;
    189  1.8   thorpej 		SVCNAME("domain_nonack_2");
    190  1.1   thorpej 		break;
    191  1.1   thorpej 
    192  1.1   thorpej 	case YPPROC_MATCH:
    193  1.1   thorpej 		xdr_argument = xdr_ypreq_key;
    194  1.1   thorpej 		xdr_result = xdr_ypresp_val;
    195  1.1   thorpej 		local = ypproc_match_2_svc;
    196  1.8   thorpej 		SVCNAME("match_2");
    197  1.1   thorpej 		break;
    198  1.1   thorpej 
    199  1.1   thorpej 	case YPPROC_FIRST:
    200  1.1   thorpej 		xdr_argument = xdr_ypreq_nokey;
    201  1.1   thorpej 		xdr_result = xdr_ypresp_key_val;
    202  1.1   thorpej 		local = ypproc_first_2_svc;
    203  1.8   thorpej 		SVCNAME("first_2");
    204  1.1   thorpej 		break;
    205  1.1   thorpej 
    206  1.1   thorpej 	case YPPROC_NEXT:
    207  1.1   thorpej 		xdr_argument = xdr_ypreq_key;
    208  1.1   thorpej 		xdr_result = xdr_ypresp_key_val;
    209  1.1   thorpej 		local = ypproc_next_2_svc;
    210  1.8   thorpej 		SVCNAME("next_2");
    211  1.1   thorpej 		break;
    212  1.1   thorpej 
    213  1.1   thorpej 	case YPPROC_XFR:
    214  1.1   thorpej 		xdr_argument = xdr_ypreq_xfr;
    215  1.1   thorpej 		xdr_result = xdr_ypresp_xfr;
    216  1.1   thorpej 		local = ypproc_xfr_2_svc;
    217  1.8   thorpej 		SVCNAME("xfer_2");
    218  1.1   thorpej 		break;
    219  1.1   thorpej 
    220  1.1   thorpej 	case YPPROC_CLEAR:
    221  1.1   thorpej 		xdr_argument = xdr_void;
    222  1.1   thorpej 		xdr_result = xdr_void;
    223  1.1   thorpej 		local = ypproc_clear_2_svc;
    224  1.8   thorpej 		SVCNAME("clear_2");
    225  1.1   thorpej 		break;
    226  1.1   thorpej 
    227  1.1   thorpej 	case YPPROC_ALL:
    228  1.1   thorpej 		xdr_argument = xdr_ypreq_nokey;
    229  1.1   thorpej 		xdr_result = xdr_ypresp_all;
    230  1.1   thorpej 		local = ypproc_all_2_svc;
    231  1.8   thorpej 		SVCNAME("all_2");
    232  1.1   thorpej 		break;
    233  1.1   thorpej 
    234  1.1   thorpej 	case YPPROC_MASTER:
    235  1.1   thorpej 		xdr_argument = xdr_ypreq_nokey;
    236  1.1   thorpej 		xdr_result = xdr_ypresp_master;
    237  1.1   thorpej 		local = ypproc_master_2_svc;
    238  1.8   thorpej 		SVCNAME("master_2");
    239  1.1   thorpej 		break;
    240  1.1   thorpej 
    241  1.1   thorpej 	case YPPROC_ORDER:
    242  1.1   thorpej 		xdr_argument = xdr_ypreq_nokey;
    243  1.1   thorpej 		xdr_result = xdr_ypresp_order;
    244  1.1   thorpej 		local = ypproc_order_2_svc;
    245  1.8   thorpej 		SVCNAME("order_2");
    246  1.1   thorpej 		break;
    247  1.1   thorpej 
    248  1.1   thorpej 	case YPPROC_MAPLIST:
    249  1.1   thorpej 		xdr_argument = xdr_ypdomain_wrap_string;
    250  1.1   thorpej 		xdr_result = xdr_ypresp_maplist;
    251  1.1   thorpej 		local = ypproc_maplist_2_svc;
    252  1.8   thorpej 		SVCNAME("maplist_2");
    253  1.1   thorpej 		break;
    254  1.1   thorpej 
    255  1.1   thorpej 	default:
    256  1.1   thorpej 		svcerr_noproc(transp);
    257  1.1   thorpej 		_rpcsvcdirty = 0;
    258  1.1   thorpej 		return;
    259  1.1   thorpej 	}
    260  1.8   thorpej 
    261  1.8   thorpej #ifdef LIBWRAP
    262  1.8   thorpej 	clientstr = eval_client(&req);
    263  1.8   thorpej 
    264  1.8   thorpej 	if (hosts_access(&req) == 0) {
    265  1.8   thorpej 		syslog(deny_severity,
    266  1.8   thorpej 		    "%s: refused request from %.500s", svcname, clientstr);
    267  1.8   thorpej 		svcerr_auth(transp, AUTH_FAILED);
    268  1.8   thorpej 		_rpcsvcdirty = 0;
    269  1.8   thorpej 		return;
    270  1.8   thorpej 	}
    271  1.8   thorpej #endif
    272  1.8   thorpej 
    273  1.1   thorpej 	(void) memset((char *)&argument, 0, sizeof (argument));
    274  1.1   thorpej 	if (!svc_getargs(transp, xdr_argument, (caddr_t) &argument)) {
    275  1.1   thorpej 		svcerr_decode(transp);
    276  1.1   thorpej 		_rpcsvcdirty = 0;
    277  1.1   thorpej 		return;
    278  1.1   thorpej 	}
    279  1.1   thorpej 	result = (*local)(&argument, rqstp);
    280  1.1   thorpej 	if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
    281  1.1   thorpej 		svcerr_systemerr(transp);
    282  1.1   thorpej 	}
    283  1.1   thorpej 	if (!svc_freeargs(transp, xdr_argument, (caddr_t) &argument)) {
    284  1.1   thorpej 		_msgout("unable to free arguments");
    285  1.1   thorpej 		exit(1);
    286  1.1   thorpej 	}
    287  1.1   thorpej 	_rpcsvcdirty = 0;
    288  1.1   thorpej 	return;
    289  1.1   thorpej }
    290  1.1   thorpej 
    291  1.4  christos /*
    292  1.4  christos  * limited NIS version 1 support: the null, domain, and domain_nonack
    293  1.4  christos  * request/reply format is identical between v1 and v2.  SunOS4's ypbind
    294  1.4  christos  * makes v1 domain_nonack calls.
    295  1.4  christos  */
    296  1.4  christos static void
    297  1.6     lukem ypprog_1(struct svc_req *rqstp, SVCXPRT *transp)
    298  1.4  christos {
    299  1.4  christos 	switch (rqstp->rq_proc) {
    300  1.4  christos 	case YPPROC_NULL:
    301  1.4  christos 	case YPPROC_DOMAIN:
    302  1.4  christos 	case YPPROC_DOMAIN_NONACK:
    303  1.4  christos 		ypprog_2(rqstp, transp);
    304  1.4  christos 		return;
    305  1.4  christos 
    306  1.4  christos 	default:
    307  1.4  christos 		svcerr_noproc(transp);
    308  1.4  christos 		_rpcsvcdirty = 0;
    309  1.4  christos 		return;
    310  1.4  christos 	}
    311  1.4  christos }
    312  1.4  christos 
    313  1.1   thorpej int
    314  1.1   thorpej main(argc, argv)
    315  1.1   thorpej 	int argc;
    316  1.5   thorpej 	char *argv[];
    317  1.1   thorpej {
    318  1.6     lukem 	SVCXPRT *transp;
    319  1.1   thorpej 	int sock, proto;
    320  1.5   thorpej 	struct sigaction sa;
    321  1.2        ws 	int ch;
    322  1.5   thorpej 
    323  1.5   thorpej 	transp = NULL;		/* XXX gcc -Wuninitialized */
    324  1.5   thorpej 	proto = 0;		/* XXX gcc -Wuninitialized */
    325  1.5   thorpej 
    326  1.8   thorpej #ifdef LIBWRAP
    327  1.8   thorpej #define	GETOPTSTR	"dl"
    328  1.8   thorpej #else
    329  1.8   thorpej #define	GETOPTSTR	"d"
    330  1.8   thorpej #endif
    331  1.8   thorpej 
    332  1.8   thorpej 	while ((ch = getopt(argc, argv, GETOPTSTR)) != -1) {
    333  1.1   thorpej 		switch (ch) {
    334  1.1   thorpej 		case 'd':
    335  1.1   thorpej 			usedns = 1;
    336  1.1   thorpej 			break;
    337  1.1   thorpej 
    338  1.8   thorpej #ifdef LIBWRAP
    339  1.8   thorpej 		case 'l':
    340  1.8   thorpej 			lflag = 1;
    341  1.1   thorpej 			break;
    342  1.8   thorpej #endif
    343  1.1   thorpej 		default:
    344  1.1   thorpej 			usage();
    345  1.1   thorpej 		}
    346  1.1   thorpej 	}
    347  1.1   thorpej 
    348  1.8   thorpej #undef GETOPTSTR
    349  1.8   thorpej 
    350  1.1   thorpej 	/* This program must be run by root. */
    351  1.1   thorpej 	if (geteuid() != 0)
    352  1.1   thorpej 		errx(1, "must run as root");
    353  1.1   thorpej 
    354  1.3     mikel #ifndef RPC_SVC_FG
    355  1.3     mikel 	if (daemon(0, 0))
    356  1.3     mikel 		err(1, "can't detach");
    357  1.3     mikel #endif
    358  1.3     mikel 
    359  1.8   thorpej 	openlog(__progname, LOG_PID, LOG_DAEMON);
    360  1.8   thorpej 	syslog(LOG_INFO, "starting");
    361  1.8   thorpej 
    362  1.1   thorpej 	{
    363  1.1   thorpej 		FILE *pidfile = fopen(YPSERV_PID_PATH, "w");
    364  1.1   thorpej 
    365  1.1   thorpej 		if (pidfile != NULL) {
    366  1.1   thorpej 			fprintf(pidfile, "%d\n", getpid());
    367  1.1   thorpej 			fclose(pidfile);
    368  1.8   thorpej 		} else {
    369  1.8   thorpej 			_msgout("can't write PID file: %m");
    370  1.8   thorpej 			exit(1);
    371  1.8   thorpej 		}
    372  1.1   thorpej 	}
    373  1.1   thorpej 
    374  1.1   thorpej 	sock = RPC_ANYSOCK;
    375  1.1   thorpej 	(void) pmap_unset(YPPROG, YPVERS);
    376  1.4  christos 	(void) pmap_unset(YPPROG, YPVERS_ORIG);
    377  1.1   thorpej 
    378  1.1   thorpej 	ypdb_init();	/* init db stuff */
    379  1.1   thorpej 
    380  1.5   thorpej 	sa.sa_handler = sighandler;
    381  1.5   thorpej 	sa.sa_flags = 0;
    382  1.8   thorpej 	if (sigemptyset(&sa.sa_mask)) {
    383  1.8   thorpej 		_msgout("sigemptyset: %m");
    384  1.8   thorpej 		exit(1);
    385  1.8   thorpej 	}
    386  1.8   thorpej 	if (sigaction(SIGCHLD, &sa, NULL)) {
    387  1.8   thorpej 		_msgout("sigaction: %m");
    388  1.8   thorpej 		exit(1);
    389  1.8   thorpej 	}
    390  1.1   thorpej 
    391  1.1   thorpej 	if ((_rpcfdtype == 0) || (_rpcfdtype == SOCK_DGRAM)) {
    392  1.1   thorpej 		transp = svcudp_create(sock);
    393  1.1   thorpej 		if (transp == NULL) {
    394  1.1   thorpej 			_msgout("cannot create udp service.");
    395  1.1   thorpej 			exit(1);
    396  1.1   thorpej 		}
    397  1.6     lukem 		if (transp->xp_port >= IPPORT_RESERVED) {
    398  1.6     lukem 			_msgout("udp service not bound to a privileged port.");
    399  1.6     lukem 			exit(1);
    400  1.6     lukem 		}
    401  1.1   thorpej 		if (!_rpcpmstart)
    402  1.1   thorpej 			proto = IPPROTO_UDP;
    403  1.6     lukem 		if (!svc_register(transp, YPPROG, YPVERS_ORIG, ypprog_1,
    404  1.6     lukem 		    proto)) {
    405  1.6     lukem 			_msgout(
    406  1.6     lukem 			    "unable to register (YPPROG, YPVERS_ORIG, udp).");
    407  1.4  christos 			exit(1);
    408  1.4  christos 		}
    409  1.1   thorpej 		if (!svc_register(transp, YPPROG, YPVERS, ypprog_2, proto)) {
    410  1.1   thorpej 			_msgout("unable to register (YPPROG, YPVERS, udp).");
    411  1.1   thorpej 			exit(1);
    412  1.1   thorpej 		}
    413  1.1   thorpej 	}
    414  1.1   thorpej 
    415  1.1   thorpej 	if ((_rpcfdtype == 0) || (_rpcfdtype == SOCK_STREAM)) {
    416  1.1   thorpej 		if (_rpcpmstart)
    417  1.1   thorpej 			transp = svcfd_create(sock, 0, 0);
    418  1.1   thorpej 		else
    419  1.1   thorpej 			transp = svctcp_create(sock, 0, 0);
    420  1.1   thorpej 		if (transp == NULL) {
    421  1.1   thorpej 			_msgout("cannot create tcp service.");
    422  1.1   thorpej 			exit(1);
    423  1.1   thorpej 		}
    424  1.6     lukem 		if (transp->xp_port >= IPPORT_RESERVED) {
    425  1.6     lukem 			_msgout("tcp service not bound to a privileged port.");
    426  1.6     lukem 			exit(1);
    427  1.6     lukem 		}
    428  1.1   thorpej 		if (!_rpcpmstart)
    429  1.1   thorpej 			proto = IPPROTO_TCP;
    430  1.6     lukem 		if (!svc_register(transp, YPPROG, YPVERS_ORIG, ypprog_1,
    431  1.6     lukem 		    proto)) {
    432  1.6     lukem 			_msgout(
    433  1.6     lukem 			    "unable to register (YPPROG, YPVERS_ORIG, tcp).");
    434  1.4  christos 			exit(1);
    435  1.4  christos 		}
    436  1.1   thorpej 		if (!svc_register(transp, YPPROG, YPVERS, ypprog_2, proto)) {
    437  1.1   thorpej 			_msgout("unable to register (YPPROG, YPVERS, tcp).");
    438  1.1   thorpej 			exit(1);
    439  1.1   thorpej 		}
    440  1.1   thorpej 	}
    441  1.1   thorpej 
    442  1.1   thorpej 	if (transp == (SVCXPRT *)NULL) {
    443  1.1   thorpej 		_msgout("could not create a handle");
    444  1.1   thorpej 		exit(1);
    445  1.1   thorpej 	}
    446  1.1   thorpej 	if (_rpcpmstart) {
    447  1.1   thorpej 		(void) signal(SIGALRM, (SIG_PF) closedown);
    448  1.1   thorpej 		(void) alarm(_RPCSVC_CLOSEDOWN);
    449  1.1   thorpej 	}
    450  1.1   thorpej 	svc_run();
    451  1.1   thorpej 	_msgout("svc_run returned");
    452  1.1   thorpej 	exit(1);
    453  1.1   thorpej 	/* NOTREACHED */
    454  1.1   thorpej }
    455  1.1   thorpej 
    456  1.1   thorpej void
    457  1.5   thorpej sighandler(sig)
    458  1.5   thorpej 	int sig;
    459  1.1   thorpej {
    460  1.1   thorpej 
    461  1.5   thorpej 	/* SIGCHLD */
    462  1.1   thorpej 	while (wait3((int *)NULL, WNOHANG, (struct rusage *)NULL) > 0);
    463  1.1   thorpej }
    464  1.1   thorpej 
    465  1.1   thorpej void
    466  1.1   thorpej usage()
    467  1.1   thorpej {
    468  1.1   thorpej 
    469  1.8   thorpej #ifdef LIBWRAP
    470  1.8   thorpej #define	USAGESTR	"usage: %s [-d] [-l]\n"
    471  1.8   thorpej #else
    472  1.8   thorpej #define	USAGESTR	"usage: %s [-d]\n"
    473  1.8   thorpej #endif
    474  1.8   thorpej 
    475  1.8   thorpej 	fprintf(stderr, USAGESTR, __progname);
    476  1.1   thorpej 	exit(1);
    477  1.8   thorpej 
    478  1.8   thorpej #undef USAGESTR
    479  1.7     lukem }
    480  1.7     lukem 
    481  1.7     lukem 
    482  1.7     lukem /*
    483  1.7     lukem  * _yp_invalid_map: check if given map name isn't legal.
    484  1.7     lukem  * returns non-zero if invalid
    485  1.7     lukem  *
    486  1.7     lukem  * XXX: this probably should be in libc/yp/yplib.c
    487  1.7     lukem  */
    488  1.7     lukem int
    489  1.7     lukem _yp_invalid_map(map)
    490  1.7     lukem 	const char *map;
    491  1.7     lukem {
    492  1.7     lukem 	if (map == NULL || *map == '\0')
    493  1.7     lukem 		return 1;
    494  1.7     lukem 
    495  1.7     lukem 	if (strlen(map) > YPMAXMAP)
    496  1.7     lukem 		return 1;
    497  1.7     lukem 
    498  1.7     lukem 	if (strchr(map, '/') != NULL)
    499  1.7     lukem 		return 1;
    500  1.7     lukem 
    501  1.7     lukem 	return 0;
    502  1.1   thorpej }
    503