ypserv.c revision 1.9 1 1.9 abs /* $NetBSD: ypserv.c,v 1.9 1999/02/18 06:03:47 abs 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.9 abs __RCSID("$NetBSD: ypserv.c,v 1.9 1999/02/18 06:03:47 abs 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.1 thorpej #include <netinet/in.h>
44 1.1 thorpej
45 1.5 thorpej #include <err.h>
46 1.1 thorpej #include <netdb.h>
47 1.1 thorpej #include <signal.h>
48 1.1 thorpej #include <stdio.h>
49 1.1 thorpej #include <stdlib.h>
50 1.1 thorpej #include <string.h>
51 1.5 thorpej #include <syslog.h>
52 1.5 thorpej #include <unistd.h>
53 1.1 thorpej
54 1.1 thorpej #include <rpc/rpc.h>
55 1.1 thorpej #include <rpc/xdr.h>
56 1.1 thorpej #include <rpc/pmap_clnt.h>
57 1.1 thorpej
58 1.1 thorpej #include <rpcsvc/yp_prot.h>
59 1.1 thorpej
60 1.1 thorpej #include "ypdef.h"
61 1.1 thorpej #include "ypserv.h"
62 1.1 thorpej
63 1.8 thorpej #ifdef LIBWRAP
64 1.8 thorpej #include <tcpd.h>
65 1.8 thorpej
66 1.8 thorpej int allow_severity = LOG_DAEMON | LOG_INFO;
67 1.8 thorpej int deny_severity = LOG_DAEMON | LOG_WARNING;
68 1.8 thorpej
69 1.8 thorpej /* XXX For ypserv_proc.c -- NOT THREAD SAFE! (like any of this code is) */
70 1.8 thorpej const char *clientstr;
71 1.8 thorpej const char *svcname;
72 1.8 thorpej #endif /* LIBWRAP */
73 1.8 thorpej
74 1.1 thorpej #ifdef __STDC__
75 1.1 thorpej #define SIG_PF void(*)(int)
76 1.1 thorpej #endif
77 1.1 thorpej
78 1.1 thorpej #define _RPCSVC_CLOSEDOWN 120
79 1.1 thorpej static int _rpcpmstart; /* Started by a port monitor ? */
80 1.1 thorpej static int _rpcfdtype; /* Whether Stream or Datagram ? */
81 1.1 thorpej static int _rpcsvcdirty; /* Still serving ? */
82 1.1 thorpej
83 1.1 thorpej int usedns;
84 1.9 abs #ifdef DEBUG
85 1.9 abs int foreground = 1;
86 1.9 abs #else
87 1.9 abs int foreground;
88 1.9 abs #endif
89 1.9 abs
90 1.8 thorpej #ifdef LIBWRAP
91 1.8 thorpej int lflag;
92 1.8 thorpej #endif
93 1.1 thorpej
94 1.1 thorpej extern char *__progname; /* from crt0.s */
95 1.1 thorpej
96 1.5 thorpej int main __P((int, char *[]));
97 1.1 thorpej void usage __P((void));
98 1.1 thorpej
99 1.5 thorpej void sighandler __P((int));
100 1.5 thorpej
101 1.5 thorpej static void closedown __P((void));
102 1.1 thorpej
103 1.1 thorpej static
104 1.1 thorpej void _msgout(char* msg)
105 1.1 thorpej {
106 1.9 abs if (foreground && ! _rpcpmstart)
107 1.9 abs warnx("%s", msg);
108 1.9 abs else
109 1.9 abs syslog(LOG_ERR, msg);
110 1.1 thorpej }
111 1.1 thorpej
112 1.1 thorpej static void
113 1.1 thorpej closedown()
114 1.1 thorpej {
115 1.1 thorpej if (_rpcsvcdirty == 0) {
116 1.1 thorpej extern fd_set svc_fdset;
117 1.1 thorpej static int size;
118 1.1 thorpej int i, openfd;
119 1.1 thorpej
120 1.1 thorpej if (_rpcfdtype == SOCK_DGRAM)
121 1.1 thorpej exit(0);
122 1.1 thorpej if (size == 0) {
123 1.1 thorpej size = getdtablesize();
124 1.1 thorpej }
125 1.1 thorpej for (i = 0, openfd = 0; i < size && openfd < 2; i++)
126 1.1 thorpej if (FD_ISSET(i, &svc_fdset))
127 1.1 thorpej openfd++;
128 1.1 thorpej if (openfd <= (_rpcpmstart?0:1))
129 1.1 thorpej exit(0);
130 1.1 thorpej }
131 1.1 thorpej (void) alarm(_RPCSVC_CLOSEDOWN);
132 1.1 thorpej }
133 1.1 thorpej
134 1.1 thorpej static void
135 1.6 lukem ypprog_2(struct svc_req *rqstp, SVCXPRT *transp)
136 1.1 thorpej {
137 1.1 thorpej union {
138 1.1 thorpej char * ypproc_domain_2_arg;
139 1.1 thorpej char * ypproc_domain_nonack_2_arg;
140 1.1 thorpej struct ypreq_key ypproc_match_2_arg;
141 1.1 thorpej struct ypreq_nokey ypproc_first_2_arg;
142 1.1 thorpej struct ypreq_key ypproc_next_2_arg;
143 1.1 thorpej struct ypreq_xfr ypproc_xfr_2_arg;
144 1.1 thorpej struct ypreq_nokey ypproc_all_2_arg;
145 1.1 thorpej struct ypreq_nokey ypproc_master_2_arg;
146 1.1 thorpej struct ypreq_nokey ypproc_order_2_arg;
147 1.1 thorpej char * ypproc_maplist_2_arg;
148 1.1 thorpej } argument;
149 1.1 thorpej char *result;
150 1.1 thorpej xdrproc_t xdr_argument, xdr_result;
151 1.1 thorpej void *(*local) __P((void *, struct svc_req *));
152 1.8 thorpej #ifdef LIBWRAP
153 1.8 thorpej struct request_info req;
154 1.8 thorpej struct sockaddr_in *caller;
155 1.8 thorpej #define SVCNAME(x) svcname = x
156 1.8 thorpej #else
157 1.8 thorpej #define SVCNAME(x) /* nothing */
158 1.8 thorpej #endif
159 1.1 thorpej
160 1.1 thorpej _rpcsvcdirty = 1;
161 1.8 thorpej
162 1.8 thorpej #ifdef LIBWRAP
163 1.8 thorpej caller = svc_getcaller(transp);
164 1.8 thorpej request_init(&req, RQ_DAEMON, __progname, RQ_CLIENT_SIN, caller, NULL);
165 1.8 thorpej sock_methods(&req);
166 1.8 thorpej #endif
167 1.8 thorpej
168 1.1 thorpej switch (rqstp->rq_proc) {
169 1.1 thorpej case YPPROC_NULL:
170 1.1 thorpej xdr_argument = xdr_void;
171 1.1 thorpej xdr_result = xdr_void;
172 1.1 thorpej local = ypproc_null_2_svc;
173 1.8 thorpej SVCNAME("null_2");
174 1.1 thorpej break;
175 1.1 thorpej
176 1.1 thorpej case YPPROC_DOMAIN:
177 1.1 thorpej xdr_argument = xdr_ypdomain_wrap_string;
178 1.1 thorpej xdr_result = xdr_bool;
179 1.1 thorpej local = ypproc_domain_2_svc;
180 1.8 thorpej SVCNAME("domain_2");
181 1.1 thorpej break;
182 1.1 thorpej
183 1.1 thorpej case YPPROC_DOMAIN_NONACK:
184 1.1 thorpej xdr_argument = xdr_ypdomain_wrap_string;
185 1.1 thorpej xdr_result = xdr_bool;
186 1.1 thorpej local = ypproc_domain_nonack_2_svc;
187 1.8 thorpej SVCNAME("domain_nonack_2");
188 1.1 thorpej break;
189 1.1 thorpej
190 1.1 thorpej case YPPROC_MATCH:
191 1.1 thorpej xdr_argument = xdr_ypreq_key;
192 1.1 thorpej xdr_result = xdr_ypresp_val;
193 1.1 thorpej local = ypproc_match_2_svc;
194 1.8 thorpej SVCNAME("match_2");
195 1.1 thorpej break;
196 1.1 thorpej
197 1.1 thorpej case YPPROC_FIRST:
198 1.1 thorpej xdr_argument = xdr_ypreq_nokey;
199 1.1 thorpej xdr_result = xdr_ypresp_key_val;
200 1.1 thorpej local = ypproc_first_2_svc;
201 1.8 thorpej SVCNAME("first_2");
202 1.1 thorpej break;
203 1.1 thorpej
204 1.1 thorpej case YPPROC_NEXT:
205 1.1 thorpej xdr_argument = xdr_ypreq_key;
206 1.1 thorpej xdr_result = xdr_ypresp_key_val;
207 1.1 thorpej local = ypproc_next_2_svc;
208 1.8 thorpej SVCNAME("next_2");
209 1.1 thorpej break;
210 1.1 thorpej
211 1.1 thorpej case YPPROC_XFR:
212 1.1 thorpej xdr_argument = xdr_ypreq_xfr;
213 1.1 thorpej xdr_result = xdr_ypresp_xfr;
214 1.1 thorpej local = ypproc_xfr_2_svc;
215 1.8 thorpej SVCNAME("xfer_2");
216 1.1 thorpej break;
217 1.1 thorpej
218 1.1 thorpej case YPPROC_CLEAR:
219 1.1 thorpej xdr_argument = xdr_void;
220 1.1 thorpej xdr_result = xdr_void;
221 1.1 thorpej local = ypproc_clear_2_svc;
222 1.8 thorpej SVCNAME("clear_2");
223 1.1 thorpej break;
224 1.1 thorpej
225 1.1 thorpej case YPPROC_ALL:
226 1.1 thorpej xdr_argument = xdr_ypreq_nokey;
227 1.1 thorpej xdr_result = xdr_ypresp_all;
228 1.1 thorpej local = ypproc_all_2_svc;
229 1.8 thorpej SVCNAME("all_2");
230 1.1 thorpej break;
231 1.1 thorpej
232 1.1 thorpej case YPPROC_MASTER:
233 1.1 thorpej xdr_argument = xdr_ypreq_nokey;
234 1.1 thorpej xdr_result = xdr_ypresp_master;
235 1.1 thorpej local = ypproc_master_2_svc;
236 1.8 thorpej SVCNAME("master_2");
237 1.1 thorpej break;
238 1.1 thorpej
239 1.1 thorpej case YPPROC_ORDER:
240 1.1 thorpej xdr_argument = xdr_ypreq_nokey;
241 1.1 thorpej xdr_result = xdr_ypresp_order;
242 1.1 thorpej local = ypproc_order_2_svc;
243 1.8 thorpej SVCNAME("order_2");
244 1.1 thorpej break;
245 1.1 thorpej
246 1.1 thorpej case YPPROC_MAPLIST:
247 1.1 thorpej xdr_argument = xdr_ypdomain_wrap_string;
248 1.1 thorpej xdr_result = xdr_ypresp_maplist;
249 1.1 thorpej local = ypproc_maplist_2_svc;
250 1.8 thorpej SVCNAME("maplist_2");
251 1.1 thorpej break;
252 1.1 thorpej
253 1.1 thorpej default:
254 1.1 thorpej svcerr_noproc(transp);
255 1.1 thorpej _rpcsvcdirty = 0;
256 1.1 thorpej return;
257 1.1 thorpej }
258 1.8 thorpej
259 1.8 thorpej #ifdef LIBWRAP
260 1.8 thorpej clientstr = eval_client(&req);
261 1.8 thorpej
262 1.8 thorpej if (hosts_access(&req) == 0) {
263 1.8 thorpej syslog(deny_severity,
264 1.8 thorpej "%s: refused request from %.500s", svcname, clientstr);
265 1.8 thorpej svcerr_auth(transp, AUTH_FAILED);
266 1.8 thorpej _rpcsvcdirty = 0;
267 1.8 thorpej return;
268 1.8 thorpej }
269 1.8 thorpej #endif
270 1.8 thorpej
271 1.1 thorpej (void) memset((char *)&argument, 0, sizeof (argument));
272 1.1 thorpej if (!svc_getargs(transp, xdr_argument, (caddr_t) &argument)) {
273 1.1 thorpej svcerr_decode(transp);
274 1.1 thorpej _rpcsvcdirty = 0;
275 1.1 thorpej return;
276 1.1 thorpej }
277 1.1 thorpej result = (*local)(&argument, rqstp);
278 1.1 thorpej if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
279 1.1 thorpej svcerr_systemerr(transp);
280 1.1 thorpej }
281 1.1 thorpej if (!svc_freeargs(transp, xdr_argument, (caddr_t) &argument)) {
282 1.1 thorpej _msgout("unable to free arguments");
283 1.1 thorpej exit(1);
284 1.1 thorpej }
285 1.1 thorpej _rpcsvcdirty = 0;
286 1.1 thorpej return;
287 1.1 thorpej }
288 1.1 thorpej
289 1.4 christos /*
290 1.4 christos * limited NIS version 1 support: the null, domain, and domain_nonack
291 1.4 christos * request/reply format is identical between v1 and v2. SunOS4's ypbind
292 1.4 christos * makes v1 domain_nonack calls.
293 1.4 christos */
294 1.4 christos static void
295 1.6 lukem ypprog_1(struct svc_req *rqstp, SVCXPRT *transp)
296 1.4 christos {
297 1.4 christos switch (rqstp->rq_proc) {
298 1.4 christos case YPPROC_NULL:
299 1.4 christos case YPPROC_DOMAIN:
300 1.4 christos case YPPROC_DOMAIN_NONACK:
301 1.4 christos ypprog_2(rqstp, transp);
302 1.4 christos return;
303 1.4 christos
304 1.4 christos default:
305 1.4 christos svcerr_noproc(transp);
306 1.4 christos _rpcsvcdirty = 0;
307 1.4 christos return;
308 1.4 christos }
309 1.4 christos }
310 1.4 christos
311 1.1 thorpej int
312 1.1 thorpej main(argc, argv)
313 1.1 thorpej int argc;
314 1.5 thorpej char *argv[];
315 1.1 thorpej {
316 1.6 lukem SVCXPRT *transp;
317 1.1 thorpej int sock, proto;
318 1.5 thorpej struct sigaction sa;
319 1.2 ws int ch;
320 1.5 thorpej
321 1.5 thorpej transp = NULL; /* XXX gcc -Wuninitialized */
322 1.5 thorpej proto = 0; /* XXX gcc -Wuninitialized */
323 1.5 thorpej
324 1.8 thorpej #ifdef LIBWRAP
325 1.9 abs #define GETOPTSTR "dfl"
326 1.8 thorpej #else
327 1.9 abs #define GETOPTSTR "df"
328 1.8 thorpej #endif
329 1.8 thorpej
330 1.8 thorpej while ((ch = getopt(argc, argv, GETOPTSTR)) != -1) {
331 1.1 thorpej switch (ch) {
332 1.1 thorpej case 'd':
333 1.1 thorpej usedns = 1;
334 1.1 thorpej break;
335 1.9 abs case 'f':
336 1.9 abs foreground = 1;
337 1.9 abs break;
338 1.1 thorpej
339 1.8 thorpej #ifdef LIBWRAP
340 1.8 thorpej case 'l':
341 1.8 thorpej lflag = 1;
342 1.1 thorpej break;
343 1.8 thorpej #endif
344 1.1 thorpej default:
345 1.1 thorpej usage();
346 1.1 thorpej }
347 1.1 thorpej }
348 1.1 thorpej
349 1.8 thorpej #undef GETOPTSTR
350 1.8 thorpej
351 1.1 thorpej /* This program must be run by root. */
352 1.1 thorpej if (geteuid() != 0)
353 1.1 thorpej errx(1, "must run as root");
354 1.1 thorpej
355 1.9 abs if (!foreground && daemon(0, 0))
356 1.3 mikel err(1, "can't detach");
357 1.3 mikel
358 1.8 thorpej openlog(__progname, LOG_PID, LOG_DAEMON);
359 1.8 thorpej syslog(LOG_INFO, "starting");
360 1.8 thorpej
361 1.1 thorpej {
362 1.1 thorpej FILE *pidfile = fopen(YPSERV_PID_PATH, "w");
363 1.1 thorpej
364 1.1 thorpej if (pidfile != NULL) {
365 1.1 thorpej fprintf(pidfile, "%d\n", getpid());
366 1.1 thorpej fclose(pidfile);
367 1.8 thorpej } else {
368 1.8 thorpej _msgout("can't write PID file: %m");
369 1.8 thorpej exit(1);
370 1.8 thorpej }
371 1.1 thorpej }
372 1.1 thorpej
373 1.1 thorpej sock = RPC_ANYSOCK;
374 1.1 thorpej (void) pmap_unset(YPPROG, YPVERS);
375 1.4 christos (void) pmap_unset(YPPROG, YPVERS_ORIG);
376 1.1 thorpej
377 1.1 thorpej ypdb_init(); /* init db stuff */
378 1.1 thorpej
379 1.5 thorpej sa.sa_handler = sighandler;
380 1.5 thorpej sa.sa_flags = 0;
381 1.8 thorpej if (sigemptyset(&sa.sa_mask)) {
382 1.8 thorpej _msgout("sigemptyset: %m");
383 1.8 thorpej exit(1);
384 1.8 thorpej }
385 1.8 thorpej if (sigaction(SIGCHLD, &sa, NULL)) {
386 1.8 thorpej _msgout("sigaction: %m");
387 1.8 thorpej exit(1);
388 1.8 thorpej }
389 1.1 thorpej
390 1.1 thorpej if ((_rpcfdtype == 0) || (_rpcfdtype == SOCK_DGRAM)) {
391 1.1 thorpej transp = svcudp_create(sock);
392 1.1 thorpej if (transp == NULL) {
393 1.1 thorpej _msgout("cannot create udp service.");
394 1.1 thorpej exit(1);
395 1.1 thorpej }
396 1.6 lukem if (transp->xp_port >= IPPORT_RESERVED) {
397 1.6 lukem _msgout("udp service not bound to a privileged port.");
398 1.6 lukem exit(1);
399 1.6 lukem }
400 1.1 thorpej if (!_rpcpmstart)
401 1.1 thorpej proto = IPPROTO_UDP;
402 1.6 lukem if (!svc_register(transp, YPPROG, YPVERS_ORIG, ypprog_1,
403 1.6 lukem proto)) {
404 1.6 lukem _msgout(
405 1.6 lukem "unable to register (YPPROG, YPVERS_ORIG, udp).");
406 1.4 christos exit(1);
407 1.4 christos }
408 1.1 thorpej if (!svc_register(transp, YPPROG, YPVERS, ypprog_2, proto)) {
409 1.1 thorpej _msgout("unable to register (YPPROG, YPVERS, udp).");
410 1.1 thorpej exit(1);
411 1.1 thorpej }
412 1.1 thorpej }
413 1.1 thorpej
414 1.1 thorpej if ((_rpcfdtype == 0) || (_rpcfdtype == SOCK_STREAM)) {
415 1.1 thorpej if (_rpcpmstart)
416 1.1 thorpej transp = svcfd_create(sock, 0, 0);
417 1.1 thorpej else
418 1.1 thorpej transp = svctcp_create(sock, 0, 0);
419 1.1 thorpej if (transp == NULL) {
420 1.1 thorpej _msgout("cannot create tcp service.");
421 1.1 thorpej exit(1);
422 1.1 thorpej }
423 1.6 lukem if (transp->xp_port >= IPPORT_RESERVED) {
424 1.6 lukem _msgout("tcp service not bound to a privileged port.");
425 1.6 lukem exit(1);
426 1.6 lukem }
427 1.1 thorpej if (!_rpcpmstart)
428 1.1 thorpej proto = IPPROTO_TCP;
429 1.6 lukem if (!svc_register(transp, YPPROG, YPVERS_ORIG, ypprog_1,
430 1.6 lukem proto)) {
431 1.6 lukem _msgout(
432 1.6 lukem "unable to register (YPPROG, YPVERS_ORIG, tcp).");
433 1.4 christos exit(1);
434 1.4 christos }
435 1.1 thorpej if (!svc_register(transp, YPPROG, YPVERS, ypprog_2, proto)) {
436 1.1 thorpej _msgout("unable to register (YPPROG, YPVERS, tcp).");
437 1.1 thorpej exit(1);
438 1.1 thorpej }
439 1.1 thorpej }
440 1.1 thorpej
441 1.1 thorpej if (transp == (SVCXPRT *)NULL) {
442 1.1 thorpej _msgout("could not create a handle");
443 1.1 thorpej exit(1);
444 1.1 thorpej }
445 1.1 thorpej if (_rpcpmstart) {
446 1.1 thorpej (void) signal(SIGALRM, (SIG_PF) closedown);
447 1.1 thorpej (void) alarm(_RPCSVC_CLOSEDOWN);
448 1.1 thorpej }
449 1.1 thorpej svc_run();
450 1.1 thorpej _msgout("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.8 thorpej fprintf(stderr, USAGESTR, __progname);
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 /*
482 1.7 lukem * _yp_invalid_map: check if given map name isn't legal.
483 1.7 lukem * returns non-zero if invalid
484 1.7 lukem *
485 1.7 lukem * XXX: this probably should be in libc/yp/yplib.c
486 1.7 lukem */
487 1.7 lukem int
488 1.7 lukem _yp_invalid_map(map)
489 1.7 lukem const char *map;
490 1.7 lukem {
491 1.7 lukem if (map == NULL || *map == '\0')
492 1.7 lukem return 1;
493 1.7 lukem
494 1.7 lukem if (strlen(map) > YPMAXMAP)
495 1.7 lukem return 1;
496 1.7 lukem
497 1.7 lukem if (strchr(map, '/') != NULL)
498 1.7 lukem return 1;
499 1.7 lukem
500 1.7 lukem return 0;
501 1.1 thorpej }
502