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