yp_server.c (20053) | yp_server.c (20100) |
---|---|
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 --- 29 unchanged lines hidden (view full) --- 38#include <sys/stat.h> 39#include <sys/param.h> 40#include <errno.h> 41#include <sys/types.h> 42#include <sys/socket.h> 43#include <netinet/in.h> 44#include <arpa/inet.h> 45#include <rpc/rpc.h> | 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 --- 29 unchanged lines hidden (view full) --- 38#include <sys/stat.h> 39#include <sys/param.h> 40#include <errno.h> 41#include <sys/types.h> 42#include <sys/socket.h> 43#include <netinet/in.h> 44#include <arpa/inet.h> 45#include <rpc/rpc.h> |
46#include <setjmp.h> | |
47 48#ifndef lint | 46 47#ifndef lint |
49static const char rcsid[] = "$Id: yp_server.c,v 1.10 1996/05/31 16:01:51 wpaul Exp $"; | 48static const char rcsid[] = "$Id: yp_server.c,v 1.12 1996/10/24 18:58:26 wpaul Exp $"; |
50#endif /* not lint */ 51 52int forked = 0; 53int children = 0; 54static DB *spec_dbp = NULL; /* Special global DB handle for ypproc_all. */ | 49#endif /* not lint */ 50 51int forked = 0; 52int children = 0; 53static DB *spec_dbp = NULL; /* Special global DB handle for ypproc_all. */ |
55static SVCXPRT *xprt; /* Special SVCXPRT handle for ypproc_all. */ | |
56static char *master_string = "YP_MASTER_NAME"; 57static char *order_string = "YP_LAST_MODIFIED"; 58static int master_sz = sizeof("YP_MASTER_NAME") - 1; 59static int order_sz = sizeof("YP_LAST_MODIFIED") - 1; | 54static char *master_string = "YP_MASTER_NAME"; 55static char *order_string = "YP_LAST_MODIFIED"; 56static int master_sz = sizeof("YP_MASTER_NAME") - 1; 57static int order_sz = sizeof("YP_LAST_MODIFIED") - 1; |
60static jmp_buf env; | |
61 62/* 63 * NIS v2 support. This is where most of the action happens. 64 */ 65 66void * 67ypproc_null_2_svc(void *argp, struct svc_req *rqstp) 68{ --- 402 unchanged lines hidden (view full) --- 471 * But to use the wrapper, you have to violate the boundaries between 472 * RPC layers by calling svc_sendreply() directly from the ypproc_all 473 * service routine instead of letting the RPC dispatcher do it. 474 * 475 * Bleah. 476 */ 477 478/* | 58 59/* 60 * NIS v2 support. This is where most of the action happens. 61 */ 62 63void * 64ypproc_null_2_svc(void *argp, struct svc_req *rqstp) 65{ --- 402 unchanged lines hidden (view full) --- 468 * But to use the wrapper, you have to violate the boundaries between 469 * RPC layers by calling svc_sendreply() directly from the ypproc_all 470 * service routine instead of letting the RPC dispatcher do it. 471 * 472 * Bleah. 473 */ 474 475/* |
479 * Custom XDR routine for serialzing results of ypproc_all: grab control 480 * of the transport and xdr handle from the RPC library and this request 481 * to the async queue. It will multiplex the record transmission in such 482 * a way that we can service other requests between transmissions and 483 * avoid blocking. (It will also close the DB handle for us when the 484 * request is done.) | 476 * Custom XDR routine for serialzing results of ypproc_all: keep 477 * reading from the database and spew until we run out of records 478 * or encounter an error. |
485 */ 486static bool_t 487xdr_my_ypresp_all(register XDR *xdrs, ypresp_all *objp) 488{ | 479 */ 480static bool_t 481xdr_my_ypresp_all(register XDR *xdrs, ypresp_all *objp) 482{ |
489 if (yp_add_async(xdrs, xprt, spec_dbp) == FALSE) 490 return(FALSE); 491 longjmp(env, 1); /* XXX EVIL!! */ | 483 DBT key = { NULL, 0 } , data = { NULL, 0 }; 484 485 while (1) { 486 /* Get a record. */ 487 if ((objp->ypresp_all_u.val.stat = 488 yp_next_record(spec_dbp,&key,&data,1,0)) == YP_TRUE) { 489 objp->ypresp_all_u.val.val.valdat_len = data.size; 490 objp->ypresp_all_u.val.val.valdat_val = data.data; 491 objp->ypresp_all_u.val.key.keydat_len = key.size; 492 objp->ypresp_all_u.val.key.keydat_val = key.data; 493 objp->more = TRUE; 494 } else { 495 objp->more = FALSE; 496 } 497 498 /* Serialize. */ 499 if (!xdr_ypresp_all(xdrs, objp)) 500 return(FALSE); 501 if (objp->more == FALSE) 502 return(TRUE); 503 } |
492} 493 494ypresp_all * 495ypproc_all_2_svc(ypreq_nokey *argp, struct svc_req *rqstp) 496{ 497 static ypresp_all result; 498 499 /* --- 14 unchanged lines hidden (view full) --- 514 return (&result); 515 } 516 517 if (argp->domain == NULL || argp->map == NULL) { 518 result.ypresp_all_u.val.stat = YP_BADARGS; 519 return (&result); 520 } 521 | 504} 505 506ypresp_all * 507ypproc_all_2_svc(ypreq_nokey *argp, struct svc_req *rqstp) 508{ 509 static ypresp_all result; 510 511 /* --- 14 unchanged lines hidden (view full) --- 526 return (&result); 527 } 528 529 if (argp->domain == NULL || argp->map == NULL) { 530 result.ypresp_all_u.val.stat = YP_BADARGS; 531 return (&result); 532 } 533 |
534 /* 535 * The ypproc_all procedure can take a while to complete. 536 * Best to handle it in a subprocess so the parent doesn't 537 * block. (Is there a better way to do this? Maybe with 538 * async socket I/O?) 539 */ 540 if (!debug && children < MAX_CHILDREN && fork()) { 541 children++; 542 forked = 0; 543 return (NULL); 544 } else { 545 forked++; 546 } 547 548#ifndef DB_CACHE |
|
522 if ((spec_dbp = yp_open_db(argp->domain, argp->map)) == NULL) { 523 result.ypresp_all_u.val.stat = yp_errno; 524 return(&result); 525 } | 549 if ((spec_dbp = yp_open_db(argp->domain, argp->map)) == NULL) { 550 result.ypresp_all_u.val.stat = yp_errno; 551 return(&result); 552 } |
553#else 554 if ((spec_dbp = yp_open_db_cache(argp->domain, argp->map, NULL, 0)) == NULL) { 555 result.ypresp_all_u.val.stat = yp_errno; 556 return(&result); 557 } 558#endif |
|
526 527 /* Kick off the actual data transfer. */ | 559 560 /* Kick off the actual data transfer. */ |
528 xprt = rqstp->rq_xprt; 529 if (!setjmp(env)) /* XXX EVIL!!! */ 530 svc_sendreply(rqstp->rq_xprt, xdr_my_ypresp_all, 531 (char *)&result); | 561 svc_sendreply(rqstp->rq_xprt, xdr_my_ypresp_all, (char *)&result); 562 563#ifndef DB_CACHE 564 (void)(spec_dbp->close)(spec_dbp); 565#endif |
532 /* 533 * Returning NULL prevents the dispatcher from calling 534 * svc_sendreply() since we already did it. 535 */ 536 return (NULL); 537} 538 539ypresp_master * --- 405 unchanged lines hidden --- | 566 /* 567 * Returning NULL prevents the dispatcher from calling 568 * svc_sendreply() since we already did it. 569 */ 570 return (NULL); 571} 572 573ypresp_master * --- 405 unchanged lines hidden --- |