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