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