s3: Add wbinfo --ccache-save
[ira/wip.git] / source3 / winbindd / winbindd.c
index b29c646631ad901b98ed1d2500290387b7e9b787..c0b42b811d7bf9044819caee649993275e4a9547 100644 (file)
@@ -438,11 +438,6 @@ static struct winbindd_dispatch_table {
        { WINBINDD_LIST_TRUSTDOM, winbindd_list_trusted_domains,
          "LIST_TRUSTDOM" },
 
-       /* Lookup related functions */
-
-       { WINBINDD_REMOVE_MAPPING, winbindd_remove_mapping, "REMOVE_MAPPING" },
-       { WINBINDD_SET_HWM, winbindd_set_hwm, "SET_HWMS" },
-
        /* Miscellaneous */
 
        { WINBINDD_INFO, winbindd_info, "INFO" },
@@ -456,6 +451,7 @@ static struct winbindd_dispatch_table {
 
        /* Credential cache access */
        { WINBINDD_CCACHE_NTLMAUTH, winbindd_ccache_ntlm_auth, "NTLMAUTH" },
+       { WINBINDD_CCACHE_SAVE, winbindd_ccache_save, "CCACHE_SAVE" },
 
        /* WINS functions */
 
@@ -537,6 +533,8 @@ static struct winbindd_async_dispatch_table async_nonpriv_table[] = {
          winbindd_list_groups_send, winbindd_list_groups_recv },
        { WINBINDD_CHECK_MACHACC, "CHECK_MACHACC",
          winbindd_check_machine_acct_send, winbindd_check_machine_acct_recv },
+       { WINBINDD_PING_DC, "PING_DC",
+         winbindd_ping_dc_send, winbindd_ping_dc_recv },
 
        { 0, NULL, NULL, NULL }
 };
@@ -548,6 +546,12 @@ static struct winbindd_async_dispatch_table async_priv_table[] = {
          winbindd_allocate_gid_send, winbindd_allocate_gid_recv },
        { WINBINDD_SET_MAPPING, "SET_MAPPING",
          winbindd_set_mapping_send, winbindd_set_mapping_recv },
+       { WINBINDD_REMOVE_MAPPING, "SET_MAPPING",
+         winbindd_remove_mapping_send, winbindd_remove_mapping_recv },
+       { WINBINDD_SET_HWM, "SET_HWM",
+         winbindd_set_hwm_send, winbindd_set_hwm_recv },
+       { WINBINDD_CHANGE_MACHACC, "CHANGE_MACHACC",
+         winbindd_change_machine_acct_send, winbindd_change_machine_acct_recv },
 
        { 0, NULL, NULL, NULL }
 };
@@ -693,6 +697,8 @@ static void winbind_client_response_written(struct tevent_req *req)
        ret = wb_resp_write_recv(req, &err);
        TALLOC_FREE(req);
        if (ret == -1) {
+               close(state->sock);
+               state->sock = -1;
                DEBUG(2, ("Could not write response to client: %s\n",
                          strerror(err)));
                remove_client(state);
@@ -793,8 +799,15 @@ static void winbind_client_request_read(struct tevent_req *req)
        ret = wb_req_read_recv(req, state, &state->request, &err);
        TALLOC_FREE(req);
        if (ret == -1) {
-               DEBUG(2, ("Could not read client request: %s\n",
-                         strerror(err)));
+               if (err == EPIPE) {
+                       DEBUG(6, ("closing socket %d, client exited\n",
+                                 state->sock));
+               } else {
+                       DEBUG(2, ("Could not read client request from fd %d: "
+                                 "%s\n", state->sock, strerror(err)));
+               }
+               close(state->sock);
+               state->sock = -1;
                remove_client(state);
                return;
        }
@@ -814,26 +827,19 @@ static void remove_client(struct winbindd_cli_state *state)
                return;
        }
 
-       /* tell client, we are closing ... */
-       nwritten = write(state->sock, &c, sizeof(c));
-       if (nwritten == -1) {
-               /* 
-                * ignore EPIPE error here, because the other end might
-                * have already closed the socket.
-                */
-               if (errno != EPIPE) {
+       if (state->sock != -1) {
+               /* tell client, we are closing ... */
+               nwritten = write(state->sock, &c, sizeof(c));
+               if (nwritten == -1) {
                        DEBUG(2, ("final write to client failed: %s\n",
-                               strerror(errno)));
+                               strerror(errno)));
                }
-       }
-
-       /* Close socket */
 
-       close(state->sock);
+               /* Close socket */
 
-       /* Free any getent state */
-
-       free_getent_state(state->getgrent_state);
+               close(state->sock);
+               state->sock = -1;
+       }
 
        TALLOC_FREE(state->mem_ctx);
 
@@ -853,7 +859,7 @@ static bool remove_idle_client(void)
 
        for (state = winbindd_client_list(); state; state = state->next) {
                if (state->response == NULL &&
-                   !state->pwent_state && !state->getgrent_state) {
+                   !state->pwent_state && !state->grent_state) {
                        nidle++;
                        if (!last_access || state->last_access < last_access) {
                                last_access = state->last_access;