Changeset 740 for vendor/current/nsswitch/wb_common.c
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/nsswitch/wb_common.c
r591 r740 23 23 */ 24 24 25 #include "replace.h" 26 #include "system/select.h" 25 27 #include "winbind_client.h" 26 28 … … 42 44 /* Initialise a request structure */ 43 45 44 void winbindd_init_request(struct winbindd_request *request, int request_type) 46 static void winbindd_init_request(struct winbindd_request *request, 47 int request_type) 45 48 { 46 49 request->length = sizeof(struct winbindd_request); … … 65 68 __attribute__((destructor)) 66 69 #endif 67 void winbind_close_sock(void)70 static void winbind_close_sock(void) 68 71 { 69 72 if (winbindd_fd != -1) { … … 233 236 for (wait_time = 0; connect(fd, (struct sockaddr *)&sunaddr, sizeof(sunaddr)) == -1; 234 237 wait_time += slept) { 235 struct timeval tv; 236 fd_set w_fds; 238 struct pollfd pfd; 237 239 int ret; 238 240 int connect_errno = 0; … … 244 246 switch (errno) { 245 247 case EINPROGRESS: 246 FD_ZERO(&w_fds); 247 if (fd < 0 || fd >= FD_SETSIZE) { 248 errno = EBADF; 249 goto error_out; 250 } 251 FD_SET(fd, &w_fds); 252 tv.tv_sec = CONNECT_TIMEOUT - wait_time; 253 tv.tv_usec = 0; 254 255 ret = select(fd + 1, NULL, &w_fds, NULL, &tv); 248 pfd.fd = fd; 249 pfd.events = POLLOUT; 250 251 ret = poll(&pfd, 1, (CONNECT_TIMEOUT - wait_time) * 1000); 256 252 257 253 if (ret > 0) { … … 371 367 /* Write data to winbindd socket */ 372 368 373 int winbind_write_sock(void *buffer, int count, int recursing, int need_priv) 369 static int winbind_write_sock(void *buffer, int count, int recursing, 370 int need_priv) 374 371 { 375 372 int result, nwritten; … … 389 386 390 387 while(nwritten < count) { 391 struct timeval tv;392 fd_set r_fds;388 struct pollfd pfd; 389 int ret; 393 390 394 391 /* Catch pipe close on other end by checking if a read() 395 call would not block by calling select(). */ 396 397 FD_ZERO(&r_fds); 398 if (winbindd_fd < 0 || winbindd_fd >= FD_SETSIZE) { 399 errno = EBADF; 392 call would not block by calling poll(). */ 393 394 pfd.fd = winbindd_fd; 395 pfd.events = POLLIN|POLLHUP; 396 397 ret = poll(&pfd, 1, 0); 398 if (ret == -1) { 399 winbind_close_sock(); 400 return -1; /* poll error */ 401 } 402 403 /* Write should be OK if fd not available for reading */ 404 405 if ((ret == 1) && (pfd.revents & (POLLIN|POLLHUP|POLLERR))) { 406 407 /* Pipe has closed on remote end */ 408 409 winbind_close_sock(); 410 goto restart; 411 } 412 413 /* Do the write */ 414 415 result = write(winbindd_fd, 416 (char *)buffer + nwritten, 417 count - nwritten); 418 419 if ((result == -1) || (result == 0)) { 420 421 /* Write failed */ 422 400 423 winbind_close_sock(); 401 424 return -1; 402 425 } 403 FD_SET(winbindd_fd, &r_fds); 404 ZERO_STRUCT(tv); 405 406 if (select(winbindd_fd + 1, &r_fds, NULL, NULL, &tv) == -1) { 407 winbind_close_sock(); 408 return -1; /* Select error */ 409 } 410 411 /* Write should be OK if fd not available for reading */ 412 413 if (!FD_ISSET(winbindd_fd, &r_fds)) { 414 415 /* Do the write */ 416 417 result = write(winbindd_fd, 418 (char *)buffer + nwritten, 419 count - nwritten); 420 421 if ((result == -1) || (result == 0)) { 422 423 /* Write failed */ 424 425 winbind_close_sock(); 426 return -1; 427 } 428 429 nwritten += result; 430 431 } else { 432 433 /* Pipe has closed on remote end */ 434 435 winbind_close_sock(); 436 goto restart; 437 } 426 427 nwritten += result; 438 428 } 439 429 … … 443 433 /* Read data from winbindd socket */ 444 434 445 int winbind_read_sock(void *buffer, int count)435 static int winbind_read_sock(void *buffer, int count) 446 436 { 447 437 int nread = 0; 448 int total_time = 0 , selret;438 int total_time = 0; 449 439 450 440 if (winbindd_fd == -1) { … … 454 444 /* Read data from socket */ 455 445 while(nread < count) { 456 struct timeval tv;457 fd_set r_fds;446 struct pollfd pfd; 447 int ret; 458 448 459 449 /* Catch pipe close on other end by checking if a read() 460 call would not block by calling select(). */ 461 462 FD_ZERO(&r_fds); 463 if (winbindd_fd < 0 || winbindd_fd >= FD_SETSIZE) { 464 errno = EBADF; 450 call would not block by calling poll(). */ 451 452 pfd.fd = winbindd_fd; 453 pfd.events = POLLIN|POLLHUP; 454 455 /* Wait for 5 seconds for a reply. May need to parameterise this... */ 456 457 ret = poll(&pfd, 1, 5000); 458 if (ret == -1) { 465 459 winbind_close_sock(); 466 return -1; 467 } 468 FD_SET(winbindd_fd, &r_fds); 469 ZERO_STRUCT(tv); 470 /* Wait for 5 seconds for a reply. May need to parameterise this... */ 471 tv.tv_sec = 5; 472 473 if ((selret = select(winbindd_fd + 1, &r_fds, NULL, NULL, &tv)) == -1) { 474 winbind_close_sock(); 475 return -1; /* Select error */ 476 } 477 478 if (selret == 0) { 460 return -1; /* poll error */ 461 } 462 463 if (ret == 0) { 479 464 /* Not ready for read yet... */ 480 465 if (total_time >= 30) { … … 487 472 } 488 473 489 if ( FD_ISSET(winbindd_fd, &r_fds)) {474 if ((ret == 1) && (pfd.revents & (POLLIN|POLLHUP|POLLERR))) { 490 475 491 476 /* Do the Read */ … … 514 499 /* Read reply */ 515 500 516 int winbindd_read_reply(struct winbindd_response *response)501 static int winbindd_read_reply(struct winbindd_response *response) 517 502 { 518 503 int result1, result2 = 0; … … 527 512 sizeof(struct winbindd_response)); 528 513 if (result1 == -1) { 514 return -1; 515 } 516 517 if (response->length < sizeof(struct winbindd_response)) { 529 518 return -1; 530 519 } … … 683 672 return status; 684 673 } 685 686 /*************************************************************************687 ************************************************************************/688 689 const char *nss_err_str(NSS_STATUS ret)690 {691 switch (ret) {692 case NSS_STATUS_TRYAGAIN:693 return "NSS_STATUS_TRYAGAIN";694 case NSS_STATUS_SUCCESS:695 return "NSS_STATUS_SUCCESS";696 case NSS_STATUS_NOTFOUND:697 return "NSS_STATUS_NOTFOUND";698 case NSS_STATUS_UNAVAIL:699 return "NSS_STATUS_UNAVAIL";700 #ifdef NSS_STATUS_RETURN701 case NSS_STATUS_RETURN:702 return "NSS_STATUS_RETURN";703 #endif704 default:705 return "UNKNOWN RETURN CODE!!!!!!!";706 }707 }
Note:
See TracChangeset
for help on using the changeset viewer.