s3:winbindd: avoid writing to a closed connection and generate SIGPIPE
authorStefan Metzmacher <metze@samba.org>
Mon, 21 Sep 2009 00:42:35 +0000 (02:42 +0200)
committerStefan Metzmacher <metze@samba.org>
Mon, 21 Sep 2009 04:05:43 +0000 (06:05 +0200)
metze

source3/winbindd/winbindd.c

index 9d4676f9b5976a9b22ca9656adb63eab6689127e..f0160fcb78fbd95a54b49cf1b5321429f11912c7 100644 (file)
@@ -692,6 +692,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);
@@ -792,6 +794,8 @@ 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) {
+               close(state->sock);
+               state->sock = -1;
                DEBUG(2, ("Could not read client request: %s\n",
                          strerror(err)));
                remove_client(state);
@@ -813,22 +817,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 socket */
 
-       close(state->sock);
+               close(state->sock);
+               state->sock = -1;
+       }
 
        /* Free any getent state */