s3:winbindd Split helper functions to allow s3compat to call them
authorAndrew Bartlett <abartlet@samba.org>
Tue, 11 May 2010 11:31:18 +0000 (21:31 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 13 May 2010 00:12:27 +0000 (10:12 +1000)
This provides a more useful entry point for s3compat.

Andrew Bartlett

source3/winbindd/winbindd.c
source3/winbindd/winbindd_proto.h

index 948e9ec93ab116b1c8c70a6e950888e12ebc8f63..186b0d852b8d5ad674216a47417b605716de59f7 100644 (file)
@@ -763,40 +763,23 @@ void request_ok(struct winbindd_cli_state *state)
 
 /* Process a new connection by adding it to the client connection list */
 
-static void new_connection(int listen_sock, bool privileged)
+void winbindd_accepted_new_connection(int accepted_sock, bool privileged)
 {
-       struct sockaddr_un sunaddr;
        struct winbindd_cli_state *state;
        struct tevent_req *req;
-       socklen_t len;
-       int sock;
-
-       /* Accept connection */
-
-       len = sizeof(sunaddr);
-
-       do {
-               sock = accept(listen_sock, (struct sockaddr *)(void *)&sunaddr,
-                             &len);
-       } while (sock == -1 && errno == EINTR);
-
-       if (sock == -1)
-               return;
-
-       DEBUG(6,("accepted socket %d\n", sock));
 
        /* Create new connection structure */
 
        if ((state = TALLOC_ZERO_P(NULL, struct winbindd_cli_state)) == NULL) {
-               close(sock);
+               close(accepted_sock);
                return;
        }
 
-       state->sock = sock;
+       state->sock = accepted_sock;
 
        state->out_queue = tevent_queue_create(state, "winbind client reply");
        if (state->out_queue == NULL) {
-               close(sock);
+               close(accepted_sock);
                TALLOC_FREE(state);
                return;
        }
@@ -809,16 +792,40 @@ static void new_connection(int listen_sock, bool privileged)
                               WINBINDD_MAX_EXTRA_DATA);
        if (req == NULL) {
                TALLOC_FREE(state);
-               close(sock);
+               close(accepted_sock);
                return;
        }
        tevent_req_set_callback(req, winbind_client_request_read, state);
 
        /* Add to connection list */
 
+       /* Once the client is added here, we can be sure something will close it eventually */
        winbindd_add_client(state);
 }
 
+static void new_connection(int listen_sock, bool privileged)
+{
+       struct sockaddr_un sunaddr;
+       socklen_t len;
+       int sock;
+
+       /* Accept connection */
+
+       len = sizeof(sunaddr);
+
+       do {
+               sock = accept(listen_sock, (struct sockaddr *)(void *)&sunaddr,
+                             &len);
+       } while (sock == -1 && errno == EINTR);
+
+       if (sock == -1)
+               return;
+
+       DEBUG(6,("accepted socket %d\n", sock));
+
+       winbindd_accepted_new_connection(sock, privileged);
+}
+
 static void winbind_client_request_read(struct tevent_req *req)
 {
        struct winbindd_cli_state *state = tevent_req_callback_data(
index a449f424523b5862bf9eb6adfd0868a94eac85c8..123fefc5fc9d3326847d17331b1d904a35a7fb94 100644 (file)
@@ -44,6 +44,7 @@ void debug_unix_user_token(int dbg_class, int dbg_lev, uid_t uid, gid_t gid,
 struct event_context *winbind_event_context(void);
 
 /* The following definitions come from winbindd/winbindd.c  */
+void winbindd_accepted_new_connection(int accepted_sock, bool privileged);
 struct messaging_context *winbind_messaging_context(void);
 void request_error(struct winbindd_cli_state *state);
 void request_ok(struct winbindd_cli_state *state);