Ignore:
Timestamp:
Nov 14, 2012, 12:59:34 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to 3.6.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/nsswitch/wb_common.c

    r591 r740  
    2323*/
    2424
     25#include "replace.h"
     26#include "system/select.h"
    2527#include "winbind_client.h"
    2628
     
    4244/* Initialise a request structure */
    4345
    44 void winbindd_init_request(struct winbindd_request *request, int request_type)
     46static void winbindd_init_request(struct winbindd_request *request,
     47                                  int request_type)
    4548{
    4649        request->length = sizeof(struct winbindd_request);
     
    6568__attribute__((destructor))
    6669#endif
    67 void winbind_close_sock(void)
     70static void winbind_close_sock(void)
    6871{
    6972        if (winbindd_fd != -1) {
     
    233236        for (wait_time = 0; connect(fd, (struct sockaddr *)&sunaddr, sizeof(sunaddr)) == -1;
    234237                        wait_time += slept) {
    235                 struct timeval tv;
    236                 fd_set w_fds;
     238                struct pollfd pfd;
    237239                int ret;
    238240                int connect_errno = 0;
     
    244246                switch (errno) {
    245247                        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);
    256252
    257253                                if (ret > 0) {
     
    371367/* Write data to winbindd socket */
    372368
    373 int winbind_write_sock(void *buffer, int count, int recursing, int need_priv)
     369static int winbind_write_sock(void *buffer, int count, int recursing,
     370                              int need_priv)
    374371{
    375372        int result, nwritten;
     
    389386
    390387        while(nwritten < count) {
    391                 struct timeval tv;
    392                 fd_set r_fds;
     388                struct pollfd pfd;
     389                int ret;
    393390
    394391                /* 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
    400423                        winbind_close_sock();
    401424                        return -1;
    402425                }
    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;
    438428        }
    439429
     
    443433/* Read data from winbindd socket */
    444434
    445 int winbind_read_sock(void *buffer, int count)
     435static int winbind_read_sock(void *buffer, int count)
    446436{
    447437        int nread = 0;
    448         int total_time = 0, selret;
     438        int total_time = 0;
    449439
    450440        if (winbindd_fd == -1) {
     
    454444        /* Read data from socket */
    455445        while(nread < count) {
    456                 struct timeval tv;
    457                 fd_set r_fds;
     446                struct pollfd pfd;
     447                int ret;
    458448
    459449                /* 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) {
    465459                        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) {
    479464                        /* Not ready for read yet... */
    480465                        if (total_time >= 30) {
     
    487472                }
    488473
    489                 if (FD_ISSET(winbindd_fd, &r_fds)) {
     474                if ((ret == 1) && (pfd.revents & (POLLIN|POLLHUP|POLLERR))) {
    490475
    491476                        /* Do the Read */
     
    514499/* Read reply */
    515500
    516 int winbindd_read_reply(struct winbindd_response *response)
     501static int winbindd_read_reply(struct winbindd_response *response)
    517502{
    518503        int result1, result2 = 0;
     
    527512                                    sizeof(struct winbindd_response));
    528513        if (result1 == -1) {
     514                return -1;
     515        }
     516
     517        if (response->length < sizeof(struct winbindd_response)) {
    529518                return -1;
    530519        }
     
    683672        return status;
    684673}
    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_RETURN
    701                 case NSS_STATUS_RETURN:
    702                         return "NSS_STATUS_RETURN";
    703 #endif
    704                 default:
    705                         return "UNKNOWN RETURN CODE!!!!!!!";
    706         }
    707 }
Note: See TracChangeset for help on using the changeset viewer.