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