yp_server.c (12997) | yp_server.c (13375) |
---|---|
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 --- 31 unchanged lines hidden (view full) --- 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 47#ifndef lint | 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 --- 31 unchanged lines hidden (view full) --- 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 47#ifndef lint |
48static char rcsid[] = "$Id: yp_server.c,v 1.1.1.1 1995/12/16 20:54:17 wpaul Exp $"; | 48static char rcsid[] = "$Id: yp_server.c,v 1.2 1995/12/23 21:35:35 wpaul Exp $"; |
49#endif /* not lint */ 50 51int forked = 0; 52int children = 0; 53DB *spec_dbp = NULL; /* Special global DB handle for ypproc_all. */ 54 55void * 56ypproc_null_2_svc(void *argp, struct svc_req *rqstp) --- 218 unchanged lines hidden (view full) --- 275 unsigned int transid; 276 unsigned int prognum; 277 unsigned long port; 278{ 279 CLIENT *clnt; 280 int sock = RPC_ANYSOCK; 281 struct timeval timeout; 282 yppushresp_xfr ypxfr_resp; | 49#endif /* not lint */ 50 51int forked = 0; 52int children = 0; 53DB *spec_dbp = NULL; /* Special global DB handle for ypproc_all. */ 54 55void * 56ypproc_null_2_svc(void *argp, struct svc_req *rqstp) --- 218 unchanged lines hidden (view full) --- 275 unsigned int transid; 276 unsigned int prognum; 277 unsigned long port; 278{ 279 CLIENT *clnt; 280 int sock = RPC_ANYSOCK; 281 struct timeval timeout; 282 yppushresp_xfr ypxfr_resp; |
283 struct rpc_err err; |
|
283 | 284 |
284 timeout.tv_sec = 20; | 285 timeout.tv_sec = 5; |
285 timeout.tv_usec = 0; 286 addr->sin_port = htons(port); 287 288 if ((clnt = clntudp_create(addr, prognum, 1, timeout, &sock)) == NULL) 289 yp_error("%s", clnt_spcreateerror("failed to establish \ 290callback handle")); 291 292 ypxfr_resp.status = rval; 293 ypxfr_resp.transid = transid; 294 | 286 timeout.tv_usec = 0; 287 addr->sin_port = htons(port); 288 289 if ((clnt = clntudp_create(addr, prognum, 1, timeout, &sock)) == NULL) 290 yp_error("%s", clnt_spcreateerror("failed to establish \ 291callback handle")); 292 293 ypxfr_resp.status = rval; 294 ypxfr_resp.transid = transid; 295 |
295 if (yppushproc_xfrresp_1(&ypxfr_resp, clnt) == NULL) 296 yp_error("%s", clnt_sperror(clnt, "ypxfr callback failed")); | 296 /* Turn the timeout off -- we don't want to block. */ 297 timeout.tv_sec = 0; 298 if (clnt_control(clnt, CLSET_TIMEOUT, (char *)&timeout) == FALSE) 299 yp_error("failed to set timeout on ypproc_xfr callback"); |
297 | 300 |
301 if (yppushproc_xfrresp_1(&ypxfr_resp, clnt) == NULL) { 302 clnt_geterr(clnt, &err); 303 if (err.re_status != RPC_SUCCESS && 304 err.re_status != RPC_TIMEDOUT) 305 yp_error("%s", clnt_sperror(clnt, 306 "ypxfr callback failed")); 307 } 308 |
|
298 clnt_destroy(clnt); 299 return; 300} 301 302ypresp_xfr * 303ypproc_xfr_2_svc(ypreq_xfr *argp, struct svc_req *rqstp) 304{ 305 static ypresp_xfr result; 306 struct sockaddr_in *rqhost; 307 | 309 clnt_destroy(clnt); 310 return; 311} 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 |
319 result.transid = argp->transid; 320 rqhost = svc_getcaller(rqstp->rq_xprt); 321 |
|
308 if (yp_access(argp->map_parms.map, (struct svc_req *)rqstp)) { | 322 if (yp_access(argp->map_parms.map, (struct svc_req *)rqstp)) { |
323 /* Order is important: send regular RPC reply, then callback */ |
|
309 result.xfrstat = YPXFR_REFUSED; | 324 result.xfrstat = YPXFR_REFUSED; |
310 return(&result); | 325 svc_sendreply(rqstp->rq_xprt, xdr_ypresp_xfr, (char *)&result); 326 ypxfr_callback(YPXFR_REFUSED,rqhost,argp->transid, 327 argp->prog,argp->port); 328 return(NULL); |
311 } 312 313 if (argp->map_parms.domain == NULL) { 314 result.xfrstat = YPXFR_BADARGS; | 329 } 330 331 if (argp->map_parms.domain == NULL) { 332 result.xfrstat = YPXFR_BADARGS; |
315 return (&result); | 333 svc_sendreply(rqstp->rq_xprt, xdr_ypresp_xfr, (char *)&result); 334 ypxfr_callback(YPXFR_BADARGS,rqhost,argp->transid, 335 argp->prog,argp->port); 336 return(NULL); |
316 } 317 318 if (yp_validdomain(argp->map_parms.domain)) { 319 result.xfrstat = YPXFR_NODOM; | 337 } 338 339 if (yp_validdomain(argp->map_parms.domain)) { 340 result.xfrstat = YPXFR_NODOM; |
320 return(&result); | 341 svc_sendreply(rqstp->rq_xprt, xdr_ypresp_xfr, (char *)&result); 342 ypxfr_callback(YPXFR_NODOM,rqhost,argp->transid, 343 argp->prog,argp->port); 344 return(NULL); |
321 } 322 | 345 } 346 |
323 rqhost = svc_getcaller(rqstp->rq_xprt); 324 | |
325 switch(fork()) { 326 case 0: 327 { 328 char g[11], t[11], p[11]; 329 char ypxfr_command[MAXPATHLEN + 2]; 330 331 sprintf (ypxfr_command, "%sypxfr", _PATH_LIBEXEC); 332 sprintf (t, "%u", argp->transid); 333 sprintf (g, "%u", argp->prog); 334 sprintf (p, "%u", argp->port); 335 if (debug) 336 close(0); close(1); close(2); 337 if (strcmp(yp_dir, _PATH_YP)) { 338 execl(ypxfr_command, "ypxfr", "-d", argp->map_parms.domain, | 347 switch(fork()) { 348 case 0: 349 { 350 char g[11], t[11], p[11]; 351 char ypxfr_command[MAXPATHLEN + 2]; 352 353 sprintf (ypxfr_command, "%sypxfr", _PATH_LIBEXEC); 354 sprintf (t, "%u", argp->transid); 355 sprintf (g, "%u", argp->prog); 356 sprintf (p, "%u", argp->port); 357 if (debug) 358 close(0); close(1); close(2); 359 if (strcmp(yp_dir, _PATH_YP)) { 360 execl(ypxfr_command, "ypxfr", "-d", argp->map_parms.domain, |
339 "-h", argp->map_parms.peer, "-f", "-p", yp_dir, "-C", t, | 361 "-h", argp->map_parms.peer, "-p", yp_dir, "-C", t, |
340 g, inet_ntoa(rqhost->sin_addr), p, argp->map_parms.map, 341 NULL); 342 } else { 343 execl(ypxfr_command, "ypxfr", "-d", argp->map_parms.domain, | 362 g, inet_ntoa(rqhost->sin_addr), p, argp->map_parms.map, 363 NULL); 364 } else { 365 execl(ypxfr_command, "ypxfr", "-d", argp->map_parms.domain, |
344 "-h", argp->map_parms.peer, "-f", "-C", t, g, | 366 "-h", argp->map_parms.peer, "-C", t, g, |
345 inet_ntoa(rqhost->sin_addr), p, argp->map_parms.map, 346 NULL); 347 } 348 forked++; | 367 inet_ntoa(rqhost->sin_addr), p, argp->map_parms.map, 368 NULL); 369 } 370 forked++; |
371 result.xfrstat = YPXFR_XFRERR; |
|
349 yp_error("ypxfr execl(): %s", strerror(errno)); | 372 yp_error("ypxfr execl(): %s", strerror(errno)); |
373 svc_sendreply(rqstp->rq_xprt, xdr_ypresp_xfr, (char *)&result); |
|
350 ypxfr_callback(YPXFR_XFRERR,rqhost,argp->transid, 351 argp->prog,argp->port); | 374 ypxfr_callback(YPXFR_XFRERR,rqhost,argp->transid, 375 argp->prog,argp->port); |
352 result.xfrstat = YPXFR_XFRERR; 353 return(&result); | 376 return(NULL); |
354 break; 355 } 356 case -1: 357 yp_error("ypxfr fork(): %s", strerror(errno)); | 377 break; 378 } 379 case -1: 380 yp_error("ypxfr fork(): %s", strerror(errno)); |
381 result.xfrstat = YPXFR_XFRERR; 382 svc_sendreply(rqstp->rq_xprt, xdr_ypresp_xfr, (char *)&result); |
|
358 ypxfr_callback(YPXFR_XFRERR,rqhost,argp->transid, 359 argp->prog,argp->port); | 383 ypxfr_callback(YPXFR_XFRERR,rqhost,argp->transid, 384 argp->prog,argp->port); |
360 result.xfrstat = YPXFR_XFRERR; 361 return(&result); | 385 return(NULL); |
362 break; 363 default: | 386 break; 387 default: |
388 result.xfrstat = YPXFR_SUCC; |
|
364 children++; 365 forked = 0; 366 break; 367 } | 389 children++; 390 forked = 0; 391 break; 392 } |
368 /* Don't return anything -- it's up to ypxfr to do that. */ 369 return (NULL); | 393 394 return (&result); |
370} 371 372void * 373ypproc_clear_2_svc(void *argp, struct svc_req *rqstp) 374{ 375 static char * result; 376 static char rval = 0; 377 --- 295 unchanged lines hidden --- | 395} 396 397void * 398ypproc_clear_2_svc(void *argp, struct svc_req *rqstp) 399{ 400 static char * result; 401 static char rval = 0; 402 --- 295 unchanged lines hidden --- |