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