From 83edf3e43e86781872a07d8eb53084f59ad7384c Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 21 Sep 2009 02:42:35 +0200 Subject: [PATCH] s3:winbindd: avoid writing to a closed connection and generate SIGPIPE metze --- source3/winbindd/winbindd.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/source3/winbindd/winbindd.c b/source3/winbindd/winbindd.c index 9d4676f9b597..f0160fcb78fb 100644 --- a/source3/winbindd/winbindd.c +++ b/source3/winbindd/winbindd.c @@ -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 */ -- 2.34.1