yplib.c (54167) | yplib.c (55837) |
---|---|
1/* 2 * Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca> 3 * Copyright (c) 1998 Bill Paul <wpaul@ctr.columbia.edu> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 15 unchanged lines hidden (view full) --- 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31#ifndef LINT | 1/* 2 * Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca> 3 * Copyright (c) 1998 Bill Paul <wpaul@ctr.columbia.edu> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 15 unchanged lines hidden (view full) --- 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31#ifndef LINT |
32static char *rcsid = "$FreeBSD: head/lib/libc/yp/yplib.c 54167 1999-12-05 21:02:41Z kris $"; | 32static char *rcsid = "$FreeBSD: head/lib/libc/yp/yplib.c 55837 2000-01-12 09:23:48Z jasone $"; |
33#endif 34 35#include <sys/param.h> 36#include <sys/types.h> 37#include <sys/socket.h> 38#include <sys/file.h> 39#include <sys/uio.h> 40#include <errno.h> --- 304 unchanged lines hidden (view full) --- 345 346 sock = ysd->dom_socket; 347 save = dup(ysd->dom_socket); 348 if (ysd->dom_client != NULL) 349 clnt_destroy(ysd->dom_client); 350 ysd->dom_vers = 0; 351 ysd->dom_client = NULL; 352 sock = dup2(save, sock); | 33#endif 34 35#include <sys/param.h> 36#include <sys/types.h> 37#include <sys/socket.h> 38#include <sys/file.h> 39#include <sys/uio.h> 40#include <errno.h> --- 304 unchanged lines hidden (view full) --- 345 346 sock = ysd->dom_socket; 347 save = dup(ysd->dom_socket); 348 if (ysd->dom_client != NULL) 349 clnt_destroy(ysd->dom_client); 350 ysd->dom_vers = 0; 351 ysd->dom_client = NULL; 352 sock = dup2(save, sock); |
353 close(save); | 353 _libc_close(save); |
354 } 355 } 356 357again: 358 retries++; 359 if (retries > MAX_RETRIES) { 360 if (new) 361 free(ysd); --- 6 unchanged lines hidden (view full) --- 368 * existing handle now (if any). 369 */ 370 if(ysd->dom_client != NULL) { 371 clnt_destroy(ysd->dom_client); 372 ysd->dom_client = NULL; 373 ysd->dom_socket = -1; 374 } 375 snprintf(path, sizeof(path), "%s/%s.%d", BINDINGDIR, dom, 2); | 354 } 355 } 356 357again: 358 retries++; 359 if (retries > MAX_RETRIES) { 360 if (new) 361 free(ysd); --- 6 unchanged lines hidden (view full) --- 368 * existing handle now (if any). 369 */ 370 if(ysd->dom_client != NULL) { 371 clnt_destroy(ysd->dom_client); 372 ysd->dom_client = NULL; 373 ysd->dom_socket = -1; 374 } 375 snprintf(path, sizeof(path), "%s/%s.%d", BINDINGDIR, dom, 2); |
376 if( (fd=open(path, O_RDONLY)) == -1) { | 376 if((fd = _libc_open(path, O_RDONLY)) == -1) { |
377 /* no binding file, YP is dead. */ 378 /* Try to bring it back to life. */ | 377 /* no binding file, YP is dead. */ 378 /* Try to bring it back to life. */ |
379 close(fd); | 379 _libc_close(fd); |
380 goto skipit; 381 } 382 if( flock(fd, LOCK_EX|LOCK_NB) == -1 && errno==EWOULDBLOCK) { 383 struct iovec iov[2]; 384 struct ypbind_resp ybr; 385 u_short ypb_port; 386 387 iov[0].iov_base = (caddr_t)&ypb_port; 388 iov[0].iov_len = sizeof ypb_port; 389 iov[1].iov_base = (caddr_t)&ybr; 390 iov[1].iov_len = sizeof ybr; 391 392 r = readv(fd, iov, 2); 393 if(r != iov[0].iov_len + iov[1].iov_len) { | 380 goto skipit; 381 } 382 if( flock(fd, LOCK_EX|LOCK_NB) == -1 && errno==EWOULDBLOCK) { 383 struct iovec iov[2]; 384 struct ypbind_resp ybr; 385 u_short ypb_port; 386 387 iov[0].iov_base = (caddr_t)&ypb_port; 388 iov[0].iov_len = sizeof ypb_port; 389 iov[1].iov_base = (caddr_t)&ybr; 390 iov[1].iov_len = sizeof ybr; 391 392 r = readv(fd, iov, 2); 393 if(r != iov[0].iov_len + iov[1].iov_len) { |
394 close(fd); | 394 _libc_close(fd); |
395 ysd->dom_vers = -1; 396 goto again; 397 } 398 399 bzero(&ysd->dom_server_addr, sizeof ysd->dom_server_addr); 400 ysd->dom_server_addr.sin_family = AF_INET; 401 ysd->dom_server_addr.sin_len = sizeof(struct sockaddr_in); 402 ysd->dom_server_addr.sin_addr.s_addr = 403 *(u_long *)&ybr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr; 404 ysd->dom_server_addr.sin_port = 405 *(u_short *)&ybr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port; 406 407 ysd->dom_server_port = ysd->dom_server_addr.sin_port; | 395 ysd->dom_vers = -1; 396 goto again; 397 } 398 399 bzero(&ysd->dom_server_addr, sizeof ysd->dom_server_addr); 400 ysd->dom_server_addr.sin_family = AF_INET; 401 ysd->dom_server_addr.sin_len = sizeof(struct sockaddr_in); 402 ysd->dom_server_addr.sin_addr.s_addr = 403 *(u_long *)&ybr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr; 404 ysd->dom_server_addr.sin_port = 405 *(u_short *)&ybr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port; 406 407 ysd->dom_server_port = ysd->dom_server_addr.sin_port; |
408 close(fd); | 408 _libc_close(fd); |
409 goto gotit; 410 } else { 411 /* no lock on binding file, YP is dead. */ 412 /* Try to bring it back to life. */ | 409 goto gotit; 410 } else { 411 /* no lock on binding file, YP is dead. */ 412 /* Try to bring it back to life. */ |
413 close(fd); | 413 _libc_close(fd); |
414 goto skipit; 415 } 416 } 417skipit: 418#endif 419 if(ysd->dom_vers==-1 || ysd->dom_vers==0) { 420 /* 421 * We're trying to make a new binding: zorch the --- 53 unchanged lines hidden (view full) --- 475 } 476 fprintf(stderr, 477 "YP: server for domain %s not responding, retrying\n", dom); 478 goto again; 479 } else { 480 if (ypbr.ypbind_status != YPBIND_SUCC_VAL) { 481 clnt_destroy(client); 482 ysd->dom_vers = -1; | 414 goto skipit; 415 } 416 } 417skipit: 418#endif 419 if(ysd->dom_vers==-1 || ysd->dom_vers==0) { 420 /* 421 * We're trying to make a new binding: zorch the --- 53 unchanged lines hidden (view full) --- 475 } 476 fprintf(stderr, 477 "YP: server for domain %s not responding, retrying\n", dom); 478 goto again; 479 } else { 480 if (ypbr.ypbind_status != YPBIND_SUCC_VAL) { 481 clnt_destroy(client); 482 ysd->dom_vers = -1; |
483 sleep(_yplib_timeout/2); | 483 _libc_sleep(_yplib_timeout/2); |
484 goto again; 485 } 486 } 487 clnt_destroy(client); 488 489 bzero((char *)&ysd->dom_server_addr, sizeof ysd->dom_server_addr); 490 ysd->dom_server_addr.sin_family = AF_INET; 491 ysd->dom_server_addr.sin_port = --- 21 unchanged lines hidden (view full) --- 513 ysd->dom_socket = RPC_ANYSOCK; 514 ysd->dom_client = clntudp_bufcreate(&ysd->dom_server_addr, 515 YPPROG, YPVERS, tv, &ysd->dom_socket, 1280, 2304); 516 if(ysd->dom_client==NULL) { 517 clnt_pcreateerror("clntudp_create"); 518 ysd->dom_vers = -1; 519 goto again; 520 } | 484 goto again; 485 } 486 } 487 clnt_destroy(client); 488 489 bzero((char *)&ysd->dom_server_addr, sizeof ysd->dom_server_addr); 490 ysd->dom_server_addr.sin_family = AF_INET; 491 ysd->dom_server_addr.sin_port = --- 21 unchanged lines hidden (view full) --- 513 ysd->dom_socket = RPC_ANYSOCK; 514 ysd->dom_client = clntudp_bufcreate(&ysd->dom_server_addr, 515 YPPROG, YPVERS, tv, &ysd->dom_socket, 1280, 2304); 516 if(ysd->dom_client==NULL) { 517 clnt_pcreateerror("clntudp_create"); 518 ysd->dom_vers = -1; 519 goto again; 520 } |
521 if( fcntl(ysd->dom_socket, F_SETFD, 1) == -1) | 521 if(_libc_fcntl(ysd->dom_socket, F_SETFD, 1) == -1) |
522 perror("fcntl: F_SETFD"); 523 /* 524 * We want a port number associated with this socket 525 * so that we can check its authenticity later. 526 */ 527 checklen = sizeof(struct sockaddr_in); 528 bzero((char *)&check, checklen); 529 bind(ysd->dom_socket, (struct sockaddr *)&check, checklen); --- 32 unchanged lines hidden (view full) --- 562 &checklen) == -1 || check.sin_family != AF_INET || 563 check.sin_port != ypb->dom_local_port) { 564 int save, sock; 565 566 sock = ypb->dom_socket; 567 save = dup(ypb->dom_socket); 568 clnt_destroy(ypb->dom_client); 569 sock = dup2(save, sock); | 522 perror("fcntl: F_SETFD"); 523 /* 524 * We want a port number associated with this socket 525 * so that we can check its authenticity later. 526 */ 527 checklen = sizeof(struct sockaddr_in); 528 bzero((char *)&check, checklen); 529 bind(ysd->dom_socket, (struct sockaddr *)&check, checklen); --- 32 unchanged lines hidden (view full) --- 562 &checklen) == -1 || check.sin_family != AF_INET || 563 check.sin_port != ypb->dom_local_port) { 564 int save, sock; 565 566 sock = ypb->dom_socket; 567 save = dup(ypb->dom_socket); 568 clnt_destroy(ypb->dom_client); 569 sock = dup2(save, sock); |
570 close(save); | 570 _libc_close(save); |
571 } else 572 clnt_destroy(ypb->dom_client); 573 } 574 575 ypb->dom_client = NULL; 576 ypb->dom_socket = -1; 577 ypb->dom_vers = -1; 578#ifdef YPMATCHCACHE --- 537 unchanged lines hidden --- | 571 } else 572 clnt_destroy(ypb->dom_client); 573 } 574 575 ypb->dom_client = NULL; 576 ypb->dom_socket = -1; 577 ypb->dom_vers = -1; 578#ifdef YPMATCHCACHE --- 537 unchanged lines hidden --- |