Deleted Added
sdiff udiff text old ( 46186 ) new ( 46205 )
full compact
1/*
2 * Copyright (c) 1995
3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Bill Paul.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 */
33
34#ifndef lint
35static const char rcsid[] =
36 "$Id: yp_server.c,v 1.27 1999/02/10 16:16:14 wpaul Exp $";
37#endif /* not lint */
38
39#include "yp.h"
40#include "yp_extern.h"
41#include <dirent.h>
42#include <errno.h>
43#include <stdlib.h>
44#include <sys/stat.h>
45#include <sys/param.h>
46#include <sys/types.h>
47#include <sys/socket.h>
48#include <netinet/in.h>
49#include <arpa/inet.h>
50#include <rpc/rpc.h>
51
52int children = 0;
53
54#define MASTER_STRING "YP_MASTER_NAME"
55#define MASTER_SZ sizeof(MASTER_STRING) - 1
56#define ORDER_STRING "YP_LAST_MODIFIED"
57#define ORDER_SZ sizeof(ORDER_STRING) - 1
58
59static pid_t yp_fork()
60{
61 if (yp_pid != getpid()) {
62 yp_error("child %d trying to fork!", getpid());
63 errno = EEXIST;
64 return(-1);
65 }
66
67 return(fork());
68}
69
70/*
71 * NIS v2 support. This is where most of the action happens.
72 */
73
74void *
75ypproc_null_2_svc(void *argp, struct svc_req *rqstp)
76{
77 static char * result;
78 static char rval = 0;
79
80#ifdef DB_CACHE
81 if (yp_access(NULL, NULL, (struct svc_req *)rqstp))
82#else
83 if (yp_access(NULL, (struct svc_req *)rqstp))
84#endif
85 return(NULL);
86
87 result = &rval;
88
89 return((void *) &result);
90}
91
92bool_t *
93ypproc_domain_2_svc(domainname *argp, struct svc_req *rqstp)
94{
95 static bool_t result;
96
97#ifdef DB_CACHE
98 if (yp_access(NULL, NULL, (struct svc_req *)rqstp)) {
99#else
100 if (yp_access(NULL, (struct svc_req *)rqstp)) {
101#endif
102 result = FALSE;
103 return (&result);
104 }
105
106 if (argp == NULL || yp_validdomain(*argp))
107 result = FALSE;
108 else
109 result = TRUE;
110
111 return (&result);
112}
113
114bool_t *
115ypproc_domain_nonack_2_svc(domainname *argp, struct svc_req *rqstp)
116{
117 static bool_t result;
118
119#ifdef DB_CACHE
120 if (yp_access(NULL, NULL, (struct svc_req *)rqstp))
121#else
122 if (yp_access(NULL, (struct svc_req *)rqstp))
123#endif
124 return (NULL);
125
126 if (argp == NULL || yp_validdomain(*argp))
127 return (NULL);
128 else
129 result = TRUE;
130
131 return (&result);
132}
133
134ypresp_val *
135ypproc_match_2_svc(ypreq_key *argp, struct svc_req *rqstp)
136{
137 static ypresp_val result;
138
139 result.val.valdat_val = "";
140 result.val.valdat_len = 0;
141
142#ifdef DB_CACHE
143 if (yp_access(argp->map, argp->domain, (struct svc_req *)rqstp)) {
144#else
145 if (yp_access(argp->map, (struct svc_req *)rqstp)) {
146#endif
147 result.stat = YP_YPERR;
148 return (&result);
149 }
150
151 if (argp->domain == NULL || argp->map == NULL) {
152 result.stat = YP_BADARGS;
153 return (&result);
154 }
155
156 if (yp_select_map(argp->map, argp->domain, NULL, 1) != YP_TRUE) {
157 result.stat = yp_errno;
158 return(&result);
159 }
160
161 result.stat = yp_getbykey(&argp->key, &result.val);
162
163 /*
164 * Do DNS lookups for hosts maps if database lookup failed.
165 */
166
167#ifdef DB_CACHE
168 if (result.stat != YP_TRUE &&
169 (yp_testflag(argp->map, argp->domain, YP_INTERDOMAIN) ||
170 (strstr(argp->map, "hosts") && do_dns))) {
171#else
172 if (do_dns && result.stat != YP_TRUE && strstr(argp->map, "hosts")) {
173#endif
174 char nbuf[YPMAXRECORD];
175
176 /* NUL terminate! NUL terminate!! NUL TERMINATE!!! */
177 bcopy(argp->key.keydat_val, nbuf, argp->key.keydat_len);
178 nbuf[argp->key.keydat_len] = '\0';
179
180 if (debug)
181 yp_error("doing DNS lookup of %s", nbuf);
182
183 if (!strcmp(argp->map, "hosts.byname"))
184 result.stat = yp_async_lookup_name(rqstp, nbuf);
185 else if (!strcmp(argp->map, "hosts.byaddr"))
186 result.stat = yp_async_lookup_addr(rqstp, nbuf);
187
188 if (result.stat == YP_TRUE)
189 return(NULL);
190 }
191
192 return (&result);
193}
194
195ypresp_key_val *
196ypproc_first_2_svc(ypreq_nokey *argp, struct svc_req *rqstp)
197{
198 static ypresp_key_val result;
199
200 result.val.valdat_val = result.key.keydat_val = "";
201 result.val.valdat_len = result.key.keydat_len = 0;
202
203#ifdef DB_CACHE
204 if (yp_access(argp->map, argp->domain, (struct svc_req *)rqstp)) {
205#else
206 if (yp_access(argp->map, (struct svc_req *)rqstp)) {
207#endif
208 result.stat = YP_YPERR;
209 return (&result);
210 }
211
212 if (argp->domain == NULL) {
213 result.stat = YP_BADARGS;
214 return (&result);
215 }
216
217 if (yp_select_map(argp->map, argp->domain, NULL, 0) != YP_TRUE) {
218 result.stat = yp_errno;
219 return(&result);
220 }
221
222 result.stat = yp_firstbykey(&result.key, &result.val);
223
224 return (&result);
225}
226
227ypresp_key_val *
228ypproc_next_2_svc(ypreq_key *argp, struct svc_req *rqstp)
229{
230 static ypresp_key_val result;
231
232 result.val.valdat_val = result.key.keydat_val = "";
233 result.val.valdat_len = result.key.keydat_len = 0;
234
235#ifdef DB_CACHE
236 if (yp_access(argp->map, argp->domain, (struct svc_req *)rqstp)) {
237#else
238 if (yp_access(argp->map, (struct svc_req *)rqstp)) {
239#endif
240 result.stat = YP_YPERR;
241 return (&result);
242 }
243
244 if (argp->domain == NULL || argp->map == NULL) {
245 result.stat = YP_BADARGS;
246 return (&result);
247 }
248
249 if (yp_select_map(argp->map, argp->domain, &argp->key, 0) != YP_TRUE) {
250 result.stat = yp_errno;
251 return(&result);
252 }
253
254 result.key.keydat_len = argp->key.keydat_len;
255 result.key.keydat_val = argp->key.keydat_val;
256
257 result.stat = yp_nextbykey(&result.key, &result.val);
258
259 return (&result);
260}
261
262static void ypxfr_callback(rval,addr,transid,prognum,port)
263 ypxfrstat rval;
264 struct sockaddr_in *addr;
265 unsigned int transid;
266 unsigned int prognum;
267 unsigned long port;
268{
269 CLIENT *clnt;
270 int sock = RPC_ANYSOCK;
271 struct timeval timeout;
272 yppushresp_xfr ypxfr_resp;
273 struct rpc_err err;
274
275 timeout.tv_sec = 5;
276 timeout.tv_usec = 0;
277 addr->sin_port = htons(port);
278
279 if ((clnt = clntudp_create(addr,prognum,1,timeout,&sock)) == NULL) {
280 yp_error("%s: %s", inet_ntoa(addr->sin_addr),
281 clnt_spcreateerror("failed to establish callback handle"));
282 return;
283 }
284
285 ypxfr_resp.status = rval;
286 ypxfr_resp.transid = transid;
287
288 /* Turn the timeout off -- we don't want to block. */
289 timeout.tv_sec = 0;
290 if (clnt_control(clnt, CLSET_TIMEOUT, (char *)&timeout) == FALSE)
291 yp_error("failed to set timeout on ypproc_xfr callback");
292
293 if (yppushproc_xfrresp_1(&ypxfr_resp, clnt) == NULL) {
294 clnt_geterr(clnt, &err);
295 if (err.re_status != RPC_SUCCESS &&
296 err.re_status != RPC_TIMEDOUT)
297 yp_error("%s", clnt_sperror(clnt,
298 "ypxfr callback failed"));
299 }
300
301 clnt_destroy(clnt);
302 return;
303}
304
305#define YPXFR_RETURN(CODE) \
306 /* Order is important: send regular RPC reply, then callback */ \
307 result.xfrstat = CODE; \
308 svc_sendreply(rqstp->rq_xprt, xdr_ypresp_xfr, (char *)&result); \
309 ypxfr_callback(CODE,rqhost,argp->transid, \
310 argp->prog,argp->port); \
311 return(NULL);
312
313ypresp_xfr *
314ypproc_xfr_2_svc(ypreq_xfr *argp, struct svc_req *rqstp)
315{
316 static ypresp_xfr result;
317 struct sockaddr_in *rqhost;
318 ypresp_master *mres;
319 ypreq_nokey mreq;
320
321 result.transid = argp->transid;
322 rqhost = svc_getcaller(rqstp->rq_xprt);
323
324#ifdef DB_CACHE
325 if (yp_access(argp->map_parms.map,
326 argp->map_parms.domain, (struct svc_req *)rqstp)) {
327#else
328 if (yp_access(argp->map_parms.map, (struct svc_req *)rqstp)) {
329#endif
330 YPXFR_RETURN(YPXFR_REFUSED)
331 }
332
333
334 if (argp->map_parms.domain == NULL) {
335 YPXFR_RETURN(YPXFR_BADARGS)
336 }
337
338 if (yp_validdomain(argp->map_parms.domain)) {
339 YPXFR_RETURN(YPXFR_NODOM)
340 }
341
342 /*
343 * Determine the master host ourselves. The caller may
344 * be up to no good. This has the side effect of verifying
345 * that the requested map and domain actually exist.
346 */
347
348 mreq.domain = argp->map_parms.domain;
349 mreq.map = argp->map_parms.map;
350
351 mres = ypproc_master_2_svc(&mreq, rqstp);
352
353 if (mres->stat != YP_TRUE) {
354 yp_error("couldn't find master for map %s@%s",
355 argp->map_parms.map,
356 argp->map_parms.domain);
357 yp_error("host at %s (%s) may be pulling my leg",
358 argp->map_parms.peer,
359 inet_ntoa(rqhost->sin_addr));
360 YPXFR_RETURN(YPXFR_REFUSED)
361 }
362
363 switch(yp_fork()) {
364 case 0:
365 {
366 char g[11], t[11], p[11];
367 char ypxfr_command[MAXPATHLEN + 2];
368
369 sprintf (ypxfr_command, "%sypxfr", _PATH_LIBEXEC);
370 sprintf (t, "%u", argp->transid);
371 sprintf (g, "%u", argp->prog);
372 sprintf (p, "%u", argp->port);
373 if (debug) {
374 close(0); close(1); close(2);
375 }
376 if (strcmp(yp_dir, _PATH_YP)) {
377 execl(ypxfr_command, "ypxfr",
378 "-d", argp->map_parms.domain,
379 "-h", mres->peer,
380 "-p", yp_dir, "-C", t,
381 g, inet_ntoa(rqhost->sin_addr),
382 p, argp->map_parms.map,
383 NULL);
384 } else {
385 execl(ypxfr_command, "ypxfr",
386 "-d", argp->map_parms.domain,
387 "-h", mres->peer,
388 "-C", t,
389 g, inet_ntoa(rqhost->sin_addr),
390 p, argp->map_parms.map,
391 NULL);
392 }
393 yp_error("ypxfr execl(%s): %s", ypxfr_command, strerror(errno));
394 YPXFR_RETURN(YPXFR_XFRERR)
395 break;
396 }
397 case -1:
398 yp_error("ypxfr fork(): %s", strerror(errno));
399 YPXFR_RETURN(YPXFR_XFRERR)
400 break;
401 default:
402 result.xfrstat = YPXFR_SUCC;
403 children++;
404 break;
405 }
406
407 return (&result);
408}
409#undef YPXFR_RETURN
410
411void *
412ypproc_clear_2_svc(void *argp, struct svc_req *rqstp)
413{
414 static char * result;
415 static char rval = 0;
416
417#ifdef DB_CACHE
418 if (yp_access(NULL, NULL, (struct svc_req *)rqstp))
419#else
420 if (yp_access(NULL, (struct svc_req *)rqstp))
421#endif
422 return (NULL);
423#ifdef DB_CACHE
424 /* clear out the database cache */
425 yp_flush_all();
426#endif
427 /* Re-read the securenets database for the hell of it. */
428 load_securenets();
429
430 result = &rval;
431 return((void *) &result);
432}
433
434/*
435 * For ypproc_all, we have to send a stream of ypresp_all structures
436 * via TCP, but the XDR filter generated from the yp.x protocol
437 * definition file only serializes one such structure. This means that
438 * to send the whole stream, you need a wrapper which feeds all the
439 * records into the underlying XDR routine until it hits an 'EOF.'
440 * But to use the wrapper, you have to violate the boundaries between
441 * RPC layers by calling svc_sendreply() directly from the ypproc_all
442 * service routine instead of letting the RPC dispatcher do it.
443 *
444 * Bleah.
445 */
446
447/*
448 * Custom XDR routine for serialzing results of ypproc_all: keep
449 * reading from the database and spew until we run out of records
450 * or encounter an error.
451 */
452static bool_t
453xdr_my_ypresp_all(register XDR *xdrs, ypresp_all *objp)
454{
455 while (1) {
456 /* Get a record. */
457 if ((objp->ypresp_all_u.val.stat =
458 yp_nextbykey(&objp->ypresp_all_u.val.key,
459 &objp->ypresp_all_u.val.val)) == YP_TRUE) {
460 objp->more = TRUE;
461 } else {
462 objp->more = FALSE;
463 }
464
465 /* Serialize. */
466 if (!xdr_ypresp_all(xdrs, objp))
467 return(FALSE);
468 if (objp->more == FALSE)
469 return(TRUE);
470 }
471}
472
473ypresp_all *
474ypproc_all_2_svc(ypreq_nokey *argp, struct svc_req *rqstp)
475{
476 static ypresp_all result;
477
478 /*
479 * Set this here so that the client will be forced to make
480 * at least one attempt to read from us even if all we're
481 * doing is returning an error.
482 */
483 result.more = TRUE;
484 result.ypresp_all_u.val.key.keydat_len = 0;
485 result.ypresp_all_u.val.key.keydat_val = "";
486
487#ifdef DB_CACHE
488 if (yp_access(argp->map, argp->domain, (struct svc_req *)rqstp)) {
489#else
490 if (yp_access(argp->map, (struct svc_req *)rqstp)) {
491#endif
492 result.ypresp_all_u.val.stat = YP_YPERR;
493 return (&result);
494 }
495
496 if (argp->domain == NULL || argp->map == NULL) {
497 result.ypresp_all_u.val.stat = YP_BADARGS;
498 return (&result);
499 }
500
501 /*
502 * XXX If we hit the child limit, fail the request.
503 * If we don't, and the map is large, we could block for
504 * a long time in the parent.
505 */
506 if (children >= MAX_CHILDREN) {
507 result.ypresp_all_u.val.stat = YP_YPERR;
508 return(&result);
509 }
510
511 /*
512 * The ypproc_all procedure can take a while to complete.
513 * Best to handle it in a subprocess so the parent doesn't
514 * block. (Is there a better way to do this? Maybe with
515 * async socket I/O?)
516 */
517 if (!debug) {
518 switch(yp_fork()) {
519 case 0:
520 break;
521 case -1:
522 yp_error("ypall fork(): %s", strerror(errno));
523 result.ypresp_all_u.val.stat = YP_YPERR;
524 return(&result);
525 break;
526 default:
527 children++;
528 return (NULL);
529 break;
530 }
531 }
532
533 if (yp_select_map(argp->map, argp->domain,
534 &result.ypresp_all_u.val.key, 0) != YP_TRUE) {
535 result.ypresp_all_u.val.stat = yp_errno;
536 return(&result);
537 }
538
539 /* Kick off the actual data transfer. */
540 svc_sendreply(rqstp->rq_xprt, xdr_my_ypresp_all, (char *)&result);
541
542 /*
543 * Returning NULL prevents the dispatcher from calling
544 * svc_sendreply() since we already did it.
545 */
546 return (NULL);
547}
548
549ypresp_master *
550ypproc_master_2_svc(ypreq_nokey *argp, struct svc_req *rqstp)
551{
552 static ypresp_master result;
553 static char ypvalbuf[YPMAXRECORD];
554 keydat key = { MASTER_SZ, MASTER_STRING };
555 valdat val;
556
557 result.peer = "";
558
559#ifdef DB_CACHE
560 if (yp_access(argp->map, argp->domain, (struct svc_req *)rqstp)) {
561#else
562 if (yp_access(argp->map, (struct svc_req *)rqstp)) {
563#endif
564 result.stat = YP_YPERR;
565 return(&result);
566 }
567
568 if (argp->domain == NULL) {
569 result.stat = YP_BADARGS;
570 return (&result);
571 }
572
573 if (yp_select_map(argp->map, argp->domain, &key, 1) != YP_TRUE) {
574 result.stat = yp_errno;
575 return(&result);
576 }
577
578 /*
579 * Note that we copy the data retrieved from the database to
580 * a private buffer and NUL terminate the buffer rather than
581 * terminating the data in place. We do this because by stuffing
582 * a '\0' into data.data, we will actually be corrupting memory
583 * allocated by the DB package. This is a bad thing now that we
584 * cache DB handles rather than closing the database immediately.
585 */
586 result.stat = yp_getbykey(&key, &val);
587 if (result.stat == YP_TRUE) {
588 bcopy((char *)val.valdat_val, (char *)&ypvalbuf,
589 val.valdat_len);
590 ypvalbuf[val.valdat_len] = '\0';
591 result.peer = (char *)&ypvalbuf;
592 } else
593 result.peer = "";
594
595 return (&result);
596}
597
598ypresp_order *
599ypproc_order_2_svc(ypreq_nokey *argp, struct svc_req *rqstp)
600{
601 static ypresp_order result;
602 keydat key = { ORDER_SZ, ORDER_STRING };
603 valdat val;
604
605 result.ordernum = 0;
606
607#ifdef DB_CACHE
608 if (yp_access(argp->map, argp->domain, (struct svc_req *)rqstp)) {
609#else
610 if (yp_access(argp->map, (struct svc_req *)rqstp)) {
611#endif
612 result.stat = YP_YPERR;
613 return(&result);
614 }
615
616 if (argp->domain == NULL) {
617 result.stat = YP_BADARGS;
618 return (&result);
619 }
620
621 /*
622 * We could just check the timestamp on the map file,
623 * but that's a hack: we'll only know the last time the file
624 * was touched, not the last time the database contents were
625 * updated.
626 */
627
628 if (yp_select_map(argp->map, argp->domain, &key, 1) != YP_TRUE) {
629 result.stat = yp_errno;
630 return(&result);
631 }
632
633 result.stat = yp_getbykey(&key, &val);
634
635 if (result.stat == YP_TRUE)
636 result.ordernum = atoi((char *)val.valdat_val);
637 else
638 result.ordernum = 0;
639
640 return (&result);
641}
642
643static void yp_maplist_free(yp_maplist)
644 struct ypmaplist *yp_maplist;
645{
646 register struct ypmaplist *next;
647
648 while(yp_maplist) {
649 next = yp_maplist->next;
650 free(yp_maplist->map);
651 free(yp_maplist);
652 yp_maplist = next;
653 }
654 return;
655}
656
657static struct ypmaplist *yp_maplist_create(domain)
658 const char *domain;
659{
660 char yp_mapdir[MAXPATHLEN + 2];
661 char yp_mapname[MAXPATHLEN + 2];
662 struct ypmaplist *cur = NULL;
663 struct ypmaplist *yp_maplist = NULL;
664 DIR *dird;
665 struct dirent *dirp;
666 struct stat statbuf;
667
668 snprintf(yp_mapdir, sizeof(yp_mapdir), "%s/%s", yp_dir, domain);
669
670 if ((dird = opendir(yp_mapdir)) == NULL) {
671 yp_error("opendir(%s) failed: %s", yp_mapdir, strerror(errno));
672 return(NULL);
673 }
674
675 while ((dirp = readdir(dird)) != NULL) {
676 if (strcmp(dirp->d_name, ".") && strcmp(dirp->d_name, "..")) {
677 snprintf(yp_mapname, sizeof(yp_mapname), "%s/%s",
678 yp_mapdir,dirp->d_name);
679 if (stat(yp_mapname, &statbuf) < 0 ||
680 !S_ISREG(statbuf.st_mode))
681 continue;
682 if ((cur = (struct ypmaplist *)
683 malloc(sizeof(struct ypmaplist))) == NULL) {
684 yp_error("malloc() failed");
685 closedir(dird);
686 yp_maplist_free(yp_maplist);
687 return(NULL);
688 }
689 if ((cur->map = (char *)strdup(dirp->d_name)) == NULL) {
690 yp_error("strdup() failed: %s",strerror(errno));
691 closedir(dird);
692 yp_maplist_free(yp_maplist);
693 return(NULL);
694 }
695 cur->next = yp_maplist;
696 yp_maplist = cur;
697 if (debug)
698 yp_error("map: %s", yp_maplist->map);
699 }
700
701 }
702 closedir(dird);
703 return(yp_maplist);
704}
705
706ypresp_maplist *
707ypproc_maplist_2_svc(domainname *argp, struct svc_req *rqstp)
708{
709 static ypresp_maplist result = { 0, NULL };
710
711#ifdef DB_CACHE
712 if (yp_access(NULL, NULL, (struct svc_req *)rqstp)) {
713#else
714 if (yp_access(NULL, (struct svc_req *)rqstp)) {
715#endif
716 result.stat = YP_YPERR;
717 return(&result);
718 }
719
720 if (argp == NULL) {
721 result.stat = YP_BADARGS;
722 return (&result);
723 }
724
725 if (yp_validdomain(*argp)) {
726 result.stat = YP_NODOM;
727 return (&result);
728 }
729
730 /*
731 * We have to construct a linked list for the ypproc_maplist
732 * procedure using dynamically allocated memory. Since the XDR
733 * layer won't free this list for us, we have to deal with it
734 * ourselves. We call yp_maplist_free() first to free any
735 * previously allocated data we may have accumulated to insure
736 * that we have only one linked list in memory at any given
737 * time.
738 */
739
740 yp_maplist_free(result.maps);
741
742 if ((result.maps = yp_maplist_create(*argp)) == NULL) {
743 yp_error("yp_maplist_create failed");
744 result.stat = YP_YPERR;
745 return(&result);
746 } else
747 result.stat = YP_TRUE;
748
749 return (&result);
750}
751
752/*
753 * NIS v1 support. The nullproc, domain and domain_nonack
754 * functions from v1 are identical to those in v2, so all
755 * we have to do is hand off to them.
756 *
757 * The other functions are mostly just wrappers around their v2
758 * counterparts. For example, for the v1 'match' procedure, we
759 * crack open the argument structure, make a request to the v2
760 * 'match' function, repackage the data into a v1 response and
761 * then send it on its way.
762 *
763 * Note that we don't support the pull, push and get procedures.
764 * There's little documentation available to show what they
765 * do, and I suspect they're meant largely for map transfers
766 * between master and slave servers.
767 */
768
769void *
770ypoldproc_null_1_svc(void *argp, struct svc_req *rqstp)
771{
772 return(ypproc_null_2_svc(argp, rqstp));
773}
774
775bool_t *
776ypoldproc_domain_1_svc(domainname *argp, struct svc_req *rqstp)
777{
778 return(ypproc_domain_2_svc(argp, rqstp));
779}
780
781bool_t *
782ypoldproc_domain_nonack_1_svc(domainname *argp, struct svc_req *rqstp)
783{
784 return (ypproc_domain_nonack_2_svc(argp, rqstp));
785}
786
787/*
788 * the 'match' procedure sends a response of type YPRESP_VAL
789 */
790ypresponse *
791ypoldproc_match_1_svc(yprequest *argp, struct svc_req *rqstp)
792{
793 static ypresponse result;
794 ypresp_val *v2_result;
795
796 result.yp_resptype = YPRESP_VAL;
797 result.ypresponse_u.yp_resp_valtype.val.valdat_val = "";
798 result.ypresponse_u.yp_resp_valtype.val.valdat_len = 0;
799
800 if (argp->yp_reqtype != YPREQ_KEY) {
801 result.ypresponse_u.yp_resp_valtype.stat = YP_BADARGS;
802 return(&result);
803 }
804
805 v2_result = ypproc_match_2_svc(&argp->yprequest_u.yp_req_keytype,rqstp);
806 if (v2_result == NULL)
807 return(NULL);
808
809 bcopy((char *)v2_result,
810 (char *)&result.ypresponse_u.yp_resp_valtype,
811 sizeof(ypresp_val));
812
813 return (&result);
814}
815
816/*
817 * the 'first' procedure sends a response of type YPRESP_KEY_VAL
818 */
819ypresponse *
820ypoldproc_first_1_svc(yprequest *argp, struct svc_req *rqstp)
821{
822 static ypresponse result;
823 ypresp_key_val *v2_result;
824
825 result.yp_resptype = YPRESP_KEY_VAL;
826 result.ypresponse_u.yp_resp_key_valtype.val.valdat_val =
827 result.ypresponse_u.yp_resp_key_valtype.key.keydat_val = "";
828 result.ypresponse_u.yp_resp_key_valtype.val.valdat_len =
829 result.ypresponse_u.yp_resp_key_valtype.key.keydat_len = 0;
830
831 if (argp->yp_reqtype != YPREQ_NOKEY) {
832 result.ypresponse_u.yp_resp_key_valtype.stat = YP_BADARGS;
833 return(&result);
834 }
835
836 v2_result = ypproc_first_2_svc(&argp->yprequest_u.yp_req_nokeytype,
837 rqstp);
838 if (v2_result == NULL)
839 return(NULL);
840
841 bcopy((char *)v2_result,
842 (char *)&result.ypresponse_u.yp_resp_key_valtype,
843 sizeof(ypresp_key_val));
844
845 return (&result);
846}
847
848/*
849 * the 'next' procedure sends a response of type YPRESP_KEY_VAL
850 */
851ypresponse *
852ypoldproc_next_1_svc(yprequest *argp, struct svc_req *rqstp)
853{
854 static ypresponse result;
855 ypresp_key_val *v2_result;
856
857 result.yp_resptype = YPRESP_KEY_VAL;
858 result.ypresponse_u.yp_resp_key_valtype.val.valdat_val =
859 result.ypresponse_u.yp_resp_key_valtype.key.keydat_val = "";
860 result.ypresponse_u.yp_resp_key_valtype.val.valdat_len =
861 result.ypresponse_u.yp_resp_key_valtype.key.keydat_len = 0;
862
863 if (argp->yp_reqtype != YPREQ_KEY) {
864 result.ypresponse_u.yp_resp_key_valtype.stat = YP_BADARGS;
865 return(&result);
866 }
867
868 v2_result = ypproc_next_2_svc(&argp->yprequest_u.yp_req_keytype,rqstp);
869 if (v2_result == NULL)
870 return(NULL);
871
872 bcopy((char *)v2_result,
873 (char *)&result.ypresponse_u.yp_resp_key_valtype,
874 sizeof(ypresp_key_val));
875
876 return (&result);
877}
878
879/*
880 * the 'poll' procedure sends a response of type YPRESP_MAP_PARMS
881 */
882ypresponse *
883ypoldproc_poll_1_svc(yprequest *argp, struct svc_req *rqstp)
884{
885 static ypresponse result;
886 ypresp_master *v2_result1;
887 ypresp_order *v2_result2;
888
889 result.yp_resptype = YPRESP_MAP_PARMS;
890 result.ypresponse_u.yp_resp_map_parmstype.domain =
891 argp->yprequest_u.yp_req_nokeytype.domain;
892 result.ypresponse_u.yp_resp_map_parmstype.map =
893 argp->yprequest_u.yp_req_nokeytype.map;
894 /*
895 * Hmm... there is no 'status' value in the
896 * yp_resp_map_parmstype structure, so I have to
897 * guess at what to do to indicate a failure.
898 * I hope this is right.
899 */
900 result.ypresponse_u.yp_resp_map_parmstype.ordernum = 0;
901 result.ypresponse_u.yp_resp_map_parmstype.peer = "";
902
903 if (argp->yp_reqtype != YPREQ_MAP_PARMS) {
904 return(&result);
905 }
906
907 v2_result1 = ypproc_master_2_svc(&argp->yprequest_u.yp_req_nokeytype,
908 rqstp);
909 if (v2_result1 == NULL)
910 return(NULL);
911
912 if (v2_result1->stat != YP_TRUE) {
913 return(&result);
914 }
915
916 v2_result2 = ypproc_order_2_svc(&argp->yprequest_u.yp_req_nokeytype,
917 rqstp);
918 if (v2_result2 == NULL)
919 return(NULL);
920
921 if (v2_result2->stat != YP_TRUE) {
922 return(&result);
923 }
924
925 result.ypresponse_u.yp_resp_map_parmstype.peer =
926 v2_result1->peer;
927 result.ypresponse_u.yp_resp_map_parmstype.ordernum =
928 v2_result2->ordernum;
929
930 return (&result);
931}
932
933ypresponse *
934ypoldproc_push_1_svc(yprequest *argp, struct svc_req *rqstp)
935{
936 static ypresponse result;
937
938 /*
939 * Not implemented.
940 */
941
942 return (&result);
943}
944
945ypresponse *
946ypoldproc_pull_1_svc(yprequest *argp, struct svc_req *rqstp)
947{
948 static ypresponse result;
949
950 /*
951 * Not implemented.
952 */
953
954 return (&result);
955}
956
957ypresponse *
958ypoldproc_get_1_svc(yprequest *argp, struct svc_req *rqstp)
959{
960 static ypresponse result;
961
962 /*
963 * Not implemented.
964 */
965
966 return (&result);
967}