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