------------------------------------------------------------
revno: 634
revision-id: [EMAIL PROTECTED]
parent: [EMAIL PROTECTED]
committer: Andrew Tridgell <[EMAIL PROTECTED]>
branch nick: s3-ctdb-tridge
timestamp: Tue 2007-09-25 14:52:20 +1000
message:
  merge from volker
modified:
  source/nsswitch/wb_common.c    wb_common.c-20070210173807-1wjifrbwaz6xnmgl-719
=== modified file 'source/nsswitch/wb_common.c'
--- a/source/nsswitch/wb_common.c       2007-09-11 05:25:56 +0000
+++ b/source/nsswitch/wb_common.c       2007-09-25 04:52:20 +0000
@@ -34,7 +34,15 @@
 
 int winbindd_fd = -1;           /* fd for winbindd socket */
 static int is_privileged = 0;
-static char *priv_directory;
+
+/*
+ * Location of the winbind privileged directory
+ *
+ * This is used for two purposes: First, this being != NULL is an indication
+ * that winbind is around and we should retry hard on failure. Second, this
+ * saves the child smbd some round-trips to winbind
+ */
+static char *priv_directory = NULL;
 
 /* Free a response structure */
 
@@ -241,6 +249,14 @@
                int connect_errno = 0;
                socklen_t errnosize;
 
+               if (priv_directory == NULL) {
+                       /*
+                        * Our first connection attempt to winbind at all
+                        * failed, so directly bail out.
+                        */
+                       goto error_out;
+               }
+
                if (wait_time >= CONNECT_TIMEOUT)
                        goto error_out;
 
@@ -268,6 +284,7 @@
                                slept = CONNECT_TIMEOUT;
                                break;
                        case EAGAIN:
+                       case ECONNREFUSED:
                                slept = rand() % 3 + 1;
                                sleep(slept);
                                break;
@@ -295,6 +312,7 @@
        static pid_t our_pid;
        struct winbindd_request request;
        struct winbindd_response response;
+       NSS_STATUS result;
        ZERO_STRUCT(request);
        ZERO_STRUCT(response);
 
@@ -342,21 +360,27 @@
                return -1;
        }
 
-       if (need_priv == 0) {
-               return winbindd_fd;
-       }
-
        /* try and get priv pipe */
 
        request.flags = WBFLAG_RECURSE;
-       if (winbindd_request_response(WINBINDD_PRIV_PIPE_DIR, &request, 
&response) == NSS_STATUS_SUCCESS) {
+
+       result = winbindd_request_response(WINBINDD_PRIV_PIPE_DIR, &request,
+                                          &response);
+
+       if (result == NSS_STATUS_SUCCESS) {
                int fd;
-               if ((fd = winbind_named_pipe_sock((char 
*)response.extra_data.data)) != -1) {
+               priv_directory = (char *)response.extra_data.data;
+
+               if (need_priv == 0) {
+                       return winbindd_fd;
+               }
+
+               fd = winbind_named_pipe_sock((char *)response.extra_data.data);
+
+               if (fd != -1) {
                        close(winbindd_fd);
                        winbindd_fd = fd;
                        is_privileged = 1;
-                       priv_directory = strdup(
-                               (char *)response.extra_data.data);
                }
        }
 
@@ -364,8 +388,6 @@
                return -1;
        }
 
-       SAFE_FREE(response.extra_data.data);
-
        return winbindd_fd;
 #else
        return -1;
@@ -651,6 +673,14 @@
                            && (request->flags & WBFLAG_RECURSE)) {
                                return status;
                        }
+                       if (priv_directory == NULL) {
+                               /*
+                                * Our first connection attempt to winbind
+                                * failed, so directly bail out.
+                                */
+                               return status;
+                       }
+                               
                        /*
                         * Something might have failed in the previous
                         * iteration which caused the filehandle to be closed
@@ -685,6 +715,13 @@
                            && (request->flags & WBFLAG_RECURSE)) {
                                return status;
                        }
+                       if (priv_directory == NULL) {
+                               /*
+                                * Our first connection attempt to winbind
+                                * failed, so directly bail out.
+                                */
+                               return status;
+                       }
                        /*
                         * Something might have failed in the previous
                         * iteration which caused the filehandle to be closed

Reply via email to