Home | History | Annotate | Line # | Download | only in ypserv
ypserv.c revision 1.18
      1  1.18       wiz /*	$NetBSD: ypserv.c,v 1.18 2002/07/06 00:42:27 wiz 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.18       wiz __RCSID("$NetBSD: ypserv.c,v 1.18 2002/07/06 00:42:27 wiz 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.5   thorpej #include <err.h>
     44   1.1   thorpej #include <netdb.h>
     45   1.1   thorpej #include <signal.h>
     46   1.1   thorpej #include <stdio.h>
     47   1.1   thorpej #include <stdlib.h>
     48   1.1   thorpej #include <string.h>
     49   1.5   thorpej #include <syslog.h>
     50   1.5   thorpej #include <unistd.h>
     51  1.10   thorpej #include <util.h>
     52   1.1   thorpej 
     53   1.1   thorpej #include <rpc/rpc.h>
     54   1.1   thorpej #include <rpc/xdr.h>
     55   1.1   thorpej #include <rpc/pmap_clnt.h>
     56   1.1   thorpej 
     57   1.1   thorpej #include <rpcsvc/yp_prot.h>
     58   1.1   thorpej 
     59   1.1   thorpej #include "ypdef.h"
     60   1.1   thorpej #include "ypserv.h"
     61   1.1   thorpej 
     62   1.8   thorpej #ifdef LIBWRAP
     63   1.8   thorpej #include <tcpd.h>
     64   1.8   thorpej 
     65   1.8   thorpej int allow_severity = LOG_DAEMON | LOG_INFO;
     66   1.8   thorpej int deny_severity = LOG_DAEMON | LOG_WARNING;
     67   1.8   thorpej 
     68   1.8   thorpej /* XXX For ypserv_proc.c -- NOT THREAD SAFE!  (like any of this code is) */
     69   1.8   thorpej const char *clientstr;
     70   1.8   thorpej const char *svcname;
     71   1.8   thorpej #endif /* LIBWRAP */
     72   1.1   thorpej 
     73   1.1   thorpej int	usedns;
     74   1.9       abs #ifdef DEBUG
     75   1.9       abs int	foreground = 1;
     76   1.9       abs #else
     77   1.9       abs int	foreground;
     78   1.9       abs #endif
     79   1.9       abs 
     80   1.8   thorpej #ifdef LIBWRAP
     81   1.8   thorpej int	lflag;
     82   1.8   thorpej #endif
     83   1.1   thorpej 
     84  1.16       wiz int	main(int, char *[]);
     85  1.16       wiz void	usage(void);
     86   1.1   thorpej 
     87  1.16       wiz void	sighandler(int);
     88   1.5   thorpej 
     89   1.1   thorpej 
     90   1.1   thorpej static
     91  1.12   thorpej void _msgout(int level, const char *msg)
     92   1.1   thorpej {
     93  1.12   thorpej 	if (foreground)
     94   1.9       abs                 warnx("%s", msg);
     95   1.9       abs         else
     96  1.12   thorpej                 syslog(level, "%s", msg);
     97   1.1   thorpej }
     98   1.1   thorpej 
     99   1.1   thorpej static void
    100   1.6     lukem ypprog_2(struct svc_req *rqstp, SVCXPRT *transp)
    101   1.1   thorpej {
    102   1.1   thorpej 	union {
    103   1.1   thorpej 		char * ypproc_domain_2_arg;
    104   1.1   thorpej 		char * ypproc_domain_nonack_2_arg;
    105   1.1   thorpej 		struct ypreq_key ypproc_match_2_arg;
    106   1.1   thorpej 		struct ypreq_nokey ypproc_first_2_arg;
    107   1.1   thorpej 		struct ypreq_key ypproc_next_2_arg;
    108   1.1   thorpej 		struct ypreq_xfr ypproc_xfr_2_arg;
    109   1.1   thorpej 		struct ypreq_nokey ypproc_all_2_arg;
    110   1.1   thorpej 		struct ypreq_nokey ypproc_master_2_arg;
    111   1.1   thorpej 		struct ypreq_nokey ypproc_order_2_arg;
    112   1.1   thorpej 		char * ypproc_maplist_2_arg;
    113   1.1   thorpej 	} argument;
    114   1.1   thorpej 	char *result;
    115   1.1   thorpej 	xdrproc_t xdr_argument, xdr_result;
    116  1.16       wiz 	void *(*local)(void *, struct svc_req *);
    117   1.8   thorpej #ifdef LIBWRAP
    118   1.8   thorpej 	struct request_info req;
    119  1.12   thorpej 	struct sockaddr *caller;
    120   1.8   thorpej #define	SVCNAME(x)	svcname = x
    121   1.8   thorpej #else
    122   1.8   thorpej #define	SVCNAME(x)	/* nothing */
    123   1.8   thorpej #endif
    124   1.1   thorpej 
    125   1.8   thorpej #ifdef LIBWRAP
    126  1.12   thorpej 	caller = svc_getrpccaller(transp)->buf;
    127  1.14       cgd 	request_init(&req, RQ_DAEMON, getprogname(), RQ_CLIENT_SIN, caller,
    128  1.14       cgd 	    NULL);
    129   1.8   thorpej 	sock_methods(&req);
    130   1.8   thorpej #endif
    131   1.8   thorpej 
    132   1.1   thorpej 	switch (rqstp->rq_proc) {
    133   1.1   thorpej 	case YPPROC_NULL:
    134   1.1   thorpej 		xdr_argument = xdr_void;
    135   1.1   thorpej 		xdr_result = xdr_void;
    136   1.1   thorpej 		local = ypproc_null_2_svc;
    137   1.8   thorpej 		SVCNAME("null_2");
    138   1.1   thorpej 		break;
    139   1.1   thorpej 
    140   1.1   thorpej 	case YPPROC_DOMAIN:
    141   1.1   thorpej 		xdr_argument = xdr_ypdomain_wrap_string;
    142   1.1   thorpej 		xdr_result = xdr_bool;
    143   1.1   thorpej 		local = ypproc_domain_2_svc;
    144   1.8   thorpej 		SVCNAME("domain_2");
    145   1.1   thorpej 		break;
    146   1.1   thorpej 
    147   1.1   thorpej 	case YPPROC_DOMAIN_NONACK:
    148   1.1   thorpej 		xdr_argument = xdr_ypdomain_wrap_string;
    149   1.1   thorpej 		xdr_result = xdr_bool;
    150   1.1   thorpej 		local = ypproc_domain_nonack_2_svc;
    151   1.8   thorpej 		SVCNAME("domain_nonack_2");
    152   1.1   thorpej 		break;
    153   1.1   thorpej 
    154   1.1   thorpej 	case YPPROC_MATCH:
    155   1.1   thorpej 		xdr_argument = xdr_ypreq_key;
    156   1.1   thorpej 		xdr_result = xdr_ypresp_val;
    157   1.1   thorpej 		local = ypproc_match_2_svc;
    158   1.8   thorpej 		SVCNAME("match_2");
    159   1.1   thorpej 		break;
    160   1.1   thorpej 
    161   1.1   thorpej 	case YPPROC_FIRST:
    162   1.1   thorpej 		xdr_argument = xdr_ypreq_nokey;
    163   1.1   thorpej 		xdr_result = xdr_ypresp_key_val;
    164   1.1   thorpej 		local = ypproc_first_2_svc;
    165   1.8   thorpej 		SVCNAME("first_2");
    166   1.1   thorpej 		break;
    167   1.1   thorpej 
    168   1.1   thorpej 	case YPPROC_NEXT:
    169   1.1   thorpej 		xdr_argument = xdr_ypreq_key;
    170   1.1   thorpej 		xdr_result = xdr_ypresp_key_val;
    171   1.1   thorpej 		local = ypproc_next_2_svc;
    172   1.8   thorpej 		SVCNAME("next_2");
    173   1.1   thorpej 		break;
    174   1.1   thorpej 
    175   1.1   thorpej 	case YPPROC_XFR:
    176   1.1   thorpej 		xdr_argument = xdr_ypreq_xfr;
    177   1.1   thorpej 		xdr_result = xdr_ypresp_xfr;
    178   1.1   thorpej 		local = ypproc_xfr_2_svc;
    179   1.8   thorpej 		SVCNAME("xfer_2");
    180   1.1   thorpej 		break;
    181   1.1   thorpej 
    182   1.1   thorpej 	case YPPROC_CLEAR:
    183   1.1   thorpej 		xdr_argument = xdr_void;
    184   1.1   thorpej 		xdr_result = xdr_void;
    185   1.1   thorpej 		local = ypproc_clear_2_svc;
    186   1.8   thorpej 		SVCNAME("clear_2");
    187   1.1   thorpej 		break;
    188   1.1   thorpej 
    189   1.1   thorpej 	case YPPROC_ALL:
    190   1.1   thorpej 		xdr_argument = xdr_ypreq_nokey;
    191   1.1   thorpej 		xdr_result = xdr_ypresp_all;
    192   1.1   thorpej 		local = ypproc_all_2_svc;
    193   1.8   thorpej 		SVCNAME("all_2");
    194   1.1   thorpej 		break;
    195   1.1   thorpej 
    196   1.1   thorpej 	case YPPROC_MASTER:
    197   1.1   thorpej 		xdr_argument = xdr_ypreq_nokey;
    198   1.1   thorpej 		xdr_result = xdr_ypresp_master;
    199   1.1   thorpej 		local = ypproc_master_2_svc;
    200   1.8   thorpej 		SVCNAME("master_2");
    201   1.1   thorpej 		break;
    202   1.1   thorpej 
    203   1.1   thorpej 	case YPPROC_ORDER:
    204   1.1   thorpej 		xdr_argument = xdr_ypreq_nokey;
    205   1.1   thorpej 		xdr_result = xdr_ypresp_order;
    206   1.1   thorpej 		local = ypproc_order_2_svc;
    207   1.8   thorpej 		SVCNAME("order_2");
    208   1.1   thorpej 		break;
    209   1.1   thorpej 
    210   1.1   thorpej 	case YPPROC_MAPLIST:
    211   1.1   thorpej 		xdr_argument = xdr_ypdomain_wrap_string;
    212   1.1   thorpej 		xdr_result = xdr_ypresp_maplist;
    213   1.1   thorpej 		local = ypproc_maplist_2_svc;
    214   1.8   thorpej 		SVCNAME("maplist_2");
    215   1.1   thorpej 		break;
    216   1.1   thorpej 
    217   1.1   thorpej 	default:
    218   1.1   thorpej 		svcerr_noproc(transp);
    219   1.1   thorpej 		return;
    220   1.1   thorpej 	}
    221   1.8   thorpej 
    222   1.8   thorpej #ifdef LIBWRAP
    223   1.8   thorpej 	clientstr = eval_client(&req);
    224   1.8   thorpej 
    225   1.8   thorpej 	if (hosts_access(&req) == 0) {
    226   1.8   thorpej 		syslog(deny_severity,
    227   1.8   thorpej 		    "%s: refused request from %.500s", svcname, clientstr);
    228   1.8   thorpej 		svcerr_auth(transp, AUTH_FAILED);
    229   1.8   thorpej 		return;
    230   1.8   thorpej 	}
    231   1.8   thorpej #endif
    232   1.8   thorpej 
    233   1.1   thorpej 	(void) memset((char *)&argument, 0, sizeof (argument));
    234   1.1   thorpej 	if (!svc_getargs(transp, xdr_argument, (caddr_t) &argument)) {
    235   1.1   thorpej 		svcerr_decode(transp);
    236   1.1   thorpej 		return;
    237   1.1   thorpej 	}
    238   1.1   thorpej 	result = (*local)(&argument, rqstp);
    239   1.1   thorpej 	if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
    240   1.1   thorpej 		svcerr_systemerr(transp);
    241   1.1   thorpej 	}
    242   1.1   thorpej 	if (!svc_freeargs(transp, xdr_argument, (caddr_t) &argument)) {
    243  1.12   thorpej 		_msgout(LOG_ERR, "unable to free arguments");
    244   1.1   thorpej 		exit(1);
    245   1.1   thorpej 	}
    246   1.1   thorpej 	return;
    247   1.1   thorpej }
    248   1.1   thorpej 
    249   1.4  christos /*
    250   1.4  christos  * limited NIS version 1 support: the null, domain, and domain_nonack
    251   1.4  christos  * request/reply format is identical between v1 and v2.  SunOS4's ypbind
    252   1.4  christos  * makes v1 domain_nonack calls.
    253   1.4  christos  */
    254   1.4  christos static void
    255   1.6     lukem ypprog_1(struct svc_req *rqstp, SVCXPRT *transp)
    256   1.4  christos {
    257   1.4  christos 	switch (rqstp->rq_proc) {
    258   1.4  christos 	case YPPROC_NULL:
    259   1.4  christos 	case YPPROC_DOMAIN:
    260   1.4  christos 	case YPPROC_DOMAIN_NONACK:
    261   1.4  christos 		ypprog_2(rqstp, transp);
    262   1.4  christos 		return;
    263   1.4  christos 
    264   1.4  christos 	default:
    265   1.4  christos 		svcerr_noproc(transp);
    266   1.4  christos 		return;
    267   1.4  christos 	}
    268   1.4  christos }
    269   1.4  christos 
    270   1.1   thorpej int
    271  1.18       wiz main(int argc, char *argv[])
    272   1.1   thorpej {
    273  1.12   thorpej 	SVCXPRT *udptransp, *tcptransp, *udp6transp, *tcp6transp;
    274  1.12   thorpej 	struct netconfig *udpconf, *tcpconf, *udp6conf, *tcp6conf;
    275  1.12   thorpej 	int udpsock, tcpsock, udp6sock, tcp6sock;
    276   1.5   thorpej 	struct sigaction sa;
    277  1.12   thorpej 	int ch, xcreated = 0, one = 1;
    278   1.5   thorpej 
    279   1.8   thorpej #ifdef LIBWRAP
    280   1.9       abs #define	GETOPTSTR	"dfl"
    281   1.8   thorpej #else
    282   1.9       abs #define	GETOPTSTR	"df"
    283   1.8   thorpej #endif
    284   1.8   thorpej 
    285   1.8   thorpej 	while ((ch = getopt(argc, argv, GETOPTSTR)) != -1) {
    286   1.1   thorpej 		switch (ch) {
    287   1.1   thorpej 		case 'd':
    288   1.1   thorpej 			usedns = 1;
    289   1.1   thorpej 			break;
    290   1.9       abs 		case 'f':
    291   1.9       abs 			foreground = 1;
    292   1.9       abs 			break;
    293   1.1   thorpej 
    294   1.8   thorpej #ifdef LIBWRAP
    295   1.8   thorpej 		case 'l':
    296   1.8   thorpej 			lflag = 1;
    297   1.1   thorpej 			break;
    298   1.8   thorpej #endif
    299   1.1   thorpej 		default:
    300   1.1   thorpej 			usage();
    301   1.1   thorpej 		}
    302   1.1   thorpej 	}
    303   1.1   thorpej 
    304   1.8   thorpej #undef GETOPTSTR
    305   1.8   thorpej 
    306   1.1   thorpej 	/* This program must be run by root. */
    307   1.1   thorpej 	if (geteuid() != 0)
    308   1.1   thorpej 		errx(1, "must run as root");
    309   1.1   thorpej 
    310  1.12   thorpej 	if (foreground == 0 && daemon(0, 0))
    311   1.3     mikel 		err(1, "can't detach");
    312   1.3     mikel 
    313  1.13     lukem 	openlog("ypserv", LOG_PID, LOG_DAEMON);
    314   1.8   thorpej 	syslog(LOG_INFO, "starting");
    315  1.10   thorpej 	pidfile(NULL);
    316   1.1   thorpej 
    317  1.12   thorpej 	(void) rpcb_unset(YPPROG, YPVERS, NULL);
    318  1.12   thorpej 	(void) rpcb_unset(YPPROG, YPVERS_ORIG, NULL);
    319  1.12   thorpej 
    320  1.12   thorpej 	udpsock  = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
    321  1.12   thorpej 	tcpsock  = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    322  1.12   thorpej 	udp6sock = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
    323  1.12   thorpej 	tcp6sock = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
    324  1.12   thorpej 
    325  1.12   thorpej 	/*
    326  1.12   thorpej 	 * We're doing host-based access checks here, so don't allow
    327  1.12   thorpej 	 * v4-in-v6 to confuse things.
    328  1.12   thorpej 	 */
    329  1.12   thorpej 	if (udp6sock != -1 && setsockopt(udp6sock, IPPROTO_IPV6,
    330  1.15    itojun 	    IPV6_V6ONLY, &one, sizeof(one)) < 0) {
    331  1.12   thorpej 		_msgout(LOG_ERR, "can't disable v4-in-v6 on UDP socket");
    332  1.12   thorpej 		exit(1);
    333  1.12   thorpej 	}
    334  1.12   thorpej 	if (tcp6sock != -1 && setsockopt(tcp6sock, IPPROTO_IPV6,
    335  1.15    itojun 	    IPV6_V6ONLY, &one, sizeof(one)) < 0) {
    336  1.12   thorpej 		_msgout(LOG_ERR, "can't disable v4-in-v6 on TCP socket");
    337  1.12   thorpej 		exit(1);
    338  1.12   thorpej 	}
    339   1.1   thorpej 
    340   1.1   thorpej 	ypdb_init();	/* init db stuff */
    341   1.1   thorpej 
    342   1.5   thorpej 	sa.sa_handler = sighandler;
    343   1.5   thorpej 	sa.sa_flags = 0;
    344   1.8   thorpej 	if (sigemptyset(&sa.sa_mask)) {
    345  1.12   thorpej 		_msgout(LOG_ERR, "sigemptyset: %m");
    346   1.8   thorpej 		exit(1);
    347   1.8   thorpej 	}
    348   1.8   thorpej 	if (sigaction(SIGCHLD, &sa, NULL)) {
    349  1.12   thorpej 		_msgout(LOG_ERR, "sigaction: %m");
    350   1.8   thorpej 		exit(1);
    351   1.8   thorpej 	}
    352   1.1   thorpej 
    353  1.12   thorpej 	udpconf  = getnetconfigent("udp");
    354  1.12   thorpej 	tcpconf  = getnetconfigent("tcp");
    355  1.12   thorpej 	udp6conf = getnetconfigent("udp6");
    356  1.12   thorpej 	tcp6conf = getnetconfigent("tcp6");
    357  1.12   thorpej 
    358  1.12   thorpej 	if (udpsock != -1 && udpconf != NULL) {
    359  1.12   thorpej 		if (bindresvport(udpsock, NULL) == 0) {
    360  1.12   thorpej 			udptransp = svc_dg_create(udpsock, 0, 0);
    361  1.12   thorpej 			if (udptransp != NULL) {
    362  1.12   thorpej 				if (svc_reg(udptransp, YPPROG, YPVERS_ORIG,
    363  1.12   thorpej 					    ypprog_1, udpconf) == 0 ||
    364  1.12   thorpej 				    svc_reg(udptransp, YPPROG, YPVERS,
    365  1.12   thorpej 					    ypprog_2, udpconf) == 0)
    366  1.12   thorpej 					_msgout(LOG_WARNING,
    367  1.12   thorpej 					    "unable to register UDP service");
    368  1.12   thorpej 				else
    369  1.12   thorpej 					xcreated++;
    370  1.12   thorpej 			} else
    371  1.12   thorpej 				_msgout(LOG_WARNING,
    372  1.12   thorpej 				    "unable to create UDP service");
    373  1.12   thorpej 		} else
    374  1.12   thorpej 			_msgout(LOG_ERR, "unable to bind reserved UDP port");
    375  1.12   thorpej 		freenetconfigent(udpconf);
    376  1.12   thorpej 	}
    377  1.12   thorpej 
    378  1.12   thorpej 	if (tcpsock != -1 && tcpconf != NULL) {
    379  1.12   thorpej 		if (bindresvport(tcpsock, NULL) == 0) {
    380  1.12   thorpej 			listen(tcpsock, SOMAXCONN);
    381  1.12   thorpej 			tcptransp = svc_vc_create(tcpsock, 0, 0);
    382  1.12   thorpej 			if (tcptransp != NULL) {
    383  1.12   thorpej 				if (svc_reg(tcptransp, YPPROG, YPVERS_ORIG,
    384  1.12   thorpej 					    ypprog_1, tcpconf) == 0 ||
    385  1.12   thorpej 				    svc_reg(tcptransp, YPPROG, YPVERS,
    386  1.12   thorpej 					    ypprog_2, tcpconf) == 0)
    387  1.12   thorpej 					_msgout(LOG_WARNING,
    388  1.12   thorpej 					    "unable to register TCP service");
    389  1.12   thorpej 				else
    390  1.12   thorpej 					xcreated++;
    391  1.12   thorpej 			} else
    392  1.12   thorpej 				_msgout(LOG_WARNING,
    393  1.12   thorpej 				    "unable to create TCP service");
    394  1.12   thorpej 		} else
    395  1.12   thorpej 			_msgout(LOG_ERR, "unable to bind reserved TCP port");
    396  1.12   thorpej 		freenetconfigent(tcpconf);
    397  1.12   thorpej 	}
    398  1.12   thorpej 
    399  1.12   thorpej 	if (udp6sock != -1 && udp6conf != NULL) {
    400  1.12   thorpej 		if (bindresvport(udp6sock, NULL) == 0) {
    401  1.12   thorpej 			udp6transp = svc_dg_create(udp6sock, 0, 0);
    402  1.12   thorpej 			if (udp6transp != NULL) {
    403  1.12   thorpej 				if (svc_reg(udp6transp, YPPROG, YPVERS_ORIG,
    404  1.12   thorpej 					    ypprog_1, udp6conf) == 0 ||
    405  1.12   thorpej 				    svc_reg(udp6transp, YPPROG, YPVERS,
    406  1.12   thorpej 					    ypprog_2, udp6conf) == 0)
    407  1.12   thorpej 					_msgout(LOG_WARNING,
    408  1.12   thorpej 					    "unable to register UDP6 service");
    409  1.12   thorpej 				else
    410  1.12   thorpej 					xcreated++;
    411  1.12   thorpej 			} else
    412  1.12   thorpej 				_msgout(LOG_WARNING,
    413  1.12   thorpej 				    "unable to create UDP6 service");
    414  1.12   thorpej 		} else
    415  1.12   thorpej 			_msgout(LOG_ERR, "unable to bind reserved UDP6 port");
    416  1.12   thorpej 		freenetconfigent(udp6conf);
    417  1.12   thorpej 	}
    418  1.12   thorpej 
    419  1.12   thorpej 	if (tcp6sock != -1 && tcp6conf != NULL) {
    420  1.12   thorpej 		if (bindresvport(tcp6sock, NULL) == 0) {
    421  1.12   thorpej 			listen(tcp6sock, SOMAXCONN);
    422  1.12   thorpej 			tcp6transp = svc_vc_create(tcp6sock, 0, 0);
    423  1.12   thorpej 			if (tcp6transp != NULL) {
    424  1.12   thorpej 				if (svc_reg(tcp6transp, YPPROG, YPVERS_ORIG,
    425  1.12   thorpej 					    ypprog_1, tcp6conf) == 0 ||
    426  1.12   thorpej 				    svc_reg(tcp6transp,  YPPROG, YPVERS,
    427  1.12   thorpej 					    ypprog_2, tcp6conf) == 0)
    428  1.12   thorpej 					_msgout(LOG_WARNING,
    429  1.12   thorpej 					    "unable to register TCP6 service");
    430  1.12   thorpej 				else
    431  1.12   thorpej 					xcreated++;
    432  1.12   thorpej 			} else
    433  1.12   thorpej 				_msgout(LOG_WARNING,
    434  1.12   thorpej 				    "unable to create TCP6 service");
    435  1.12   thorpej 		} else
    436  1.12   thorpej 			_msgout(LOG_ERR, "unable to bind reserved TCP6 port");
    437  1.12   thorpej 		freenetconfigent(tcp6conf);
    438   1.1   thorpej 	}
    439   1.1   thorpej 
    440  1.12   thorpej 	if (xcreated == 0) {
    441  1.12   thorpej 		_msgout(LOG_ERR, "unable to create any services");
    442  1.12   thorpej 		exit(1);
    443   1.1   thorpej 	}
    444   1.1   thorpej 
    445   1.1   thorpej 	svc_run();
    446  1.12   thorpej 	_msgout(LOG_ERR, "svc_run returned");
    447   1.1   thorpej 	exit(1);
    448   1.1   thorpej 	/* NOTREACHED */
    449   1.1   thorpej }
    450   1.1   thorpej 
    451   1.1   thorpej void
    452  1.18       wiz sighandler(int sig)
    453   1.1   thorpej {
    454   1.1   thorpej 
    455   1.5   thorpej 	/* SIGCHLD */
    456   1.1   thorpej 	while (wait3((int *)NULL, WNOHANG, (struct rusage *)NULL) > 0);
    457   1.1   thorpej }
    458   1.1   thorpej 
    459   1.1   thorpej void
    460  1.18       wiz usage(void)
    461   1.1   thorpej {
    462   1.1   thorpej 
    463   1.8   thorpej #ifdef LIBWRAP
    464   1.8   thorpej #define	USAGESTR	"usage: %s [-d] [-l]\n"
    465   1.8   thorpej #else
    466   1.8   thorpej #define	USAGESTR	"usage: %s [-d]\n"
    467   1.8   thorpej #endif
    468   1.8   thorpej 
    469  1.14       cgd 	fprintf(stderr, USAGESTR, getprogname());
    470   1.1   thorpej 	exit(1);
    471   1.8   thorpej 
    472   1.8   thorpej #undef USAGESTR
    473   1.7     lukem }
    474   1.7     lukem 
    475   1.7     lukem /*
    476   1.7     lukem  * _yp_invalid_map: check if given map name isn't legal.
    477   1.7     lukem  * returns non-zero if invalid
    478   1.7     lukem  *
    479   1.7     lukem  * XXX: this probably should be in libc/yp/yplib.c
    480   1.7     lukem  */
    481   1.7     lukem int
    482  1.18       wiz _yp_invalid_map(const char *map)
    483   1.7     lukem {
    484   1.7     lukem 	if (map == NULL || *map == '\0')
    485   1.7     lukem 		return 1;
    486   1.7     lukem 
    487   1.7     lukem 	if (strlen(map) > YPMAXMAP)
    488   1.7     lukem 		return 1;
    489   1.7     lukem 
    490   1.7     lukem 	if (strchr(map, '/') != NULL)
    491   1.7     lukem 		return 1;
    492   1.7     lukem 
    493   1.7     lukem 	return 0;
    494   1.1   thorpej }
    495