summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2010-04-06 14:04:33 +0200
committerKarolin Seeger <kseeger@samba.org>2010-05-06 14:08:35 +0200
commit9c056c0afbc824f179fdb3dbbac6babed9130e63 (patch)
tree333e5792606b4204bc4ef971c24d43b3e5c7f76f
parent5069a5792e56bb845b4bcacae7c68075a72cdf57 (diff)
downloadsamba-9c056c0afbc824f179fdb3dbbac6babed9130e63.tar.gz
s3:rpc_client: close the socket when pipe is broken
Signed-off-by: Bo Yang <boyang@samba.org> (similar to commit aa70e44cd0576e5280e24cf35000369a47dd958f) Signed-off-by: Stefan Metzmacher <metze@samba.org> (cherry picked from commit 407b9577febff6dfbe29106d783d64c41d6fe4e4)
-rw-r--r--source3/rpc_client/rpc_transport_sock.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/source3/rpc_client/rpc_transport_sock.c b/source3/rpc_client/rpc_transport_sock.c
index 7115dc4c928..0e9706d74e4 100644
--- a/source3/rpc_client/rpc_transport_sock.c
+++ b/source3/rpc_client/rpc_transport_sock.c
@@ -36,6 +36,7 @@ static int rpc_transport_sock_state_destructor(struct rpc_transport_sock_state *
}
struct rpc_sock_read_state {
+ struct rpc_transport_sock_state *transp;
ssize_t received;
};
@@ -56,7 +57,13 @@ static struct async_req *rpc_sock_read_send(TALLOC_CTX *mem_ctx,
struct rpc_sock_read_state)) {
return NULL;
}
-
+ if (sock_transp->fd == -1) {
+ if (!async_post_ntstatus(result, ev, NT_STATUS_CONNECTION_INVALID)) {
+ goto fail;
+ }
+ return result;
+ }
+ state->transp = sock_transp;
subreq = async_recv_send(state, ev, sock_transp->fd, data, size, 0);
if (subreq == NULL) {
goto fail;
@@ -82,6 +89,10 @@ static void rpc_sock_read_done(struct tevent_req *subreq)
state->received = async_recv_recv(subreq, &err);
if (state->received == -1) {
+ if (err == EPIPE) {
+ close(state->transp->fd);
+ state->transp->fd = -1;
+ }
TALLOC_FREE(subreq);
async_req_nterror(req, map_nt_error_from_unix(err));
return;
@@ -104,6 +115,7 @@ static NTSTATUS rpc_sock_read_recv(struct async_req *req, ssize_t *preceived)
}
struct rpc_sock_write_state {
+ struct rpc_transport_sock_state *transp;
ssize_t sent;
};
@@ -124,6 +136,13 @@ static struct async_req *rpc_sock_write_send(TALLOC_CTX *mem_ctx,
struct rpc_sock_write_state)) {
return NULL;
}
+ if (sock_transp->fd == -1) {
+ if (!async_post_ntstatus(result, ev, NT_STATUS_CONNECTION_INVALID)) {
+ goto fail;
+ }
+ return result;
+ }
+ state->transp = sock_transp;
subreq = async_send_send(state, ev, sock_transp->fd, data, size, 0);
if (subreq == NULL) {
goto fail;
@@ -149,6 +168,10 @@ static void rpc_sock_write_done(struct tevent_req *subreq)
state->sent = async_send_recv(subreq, &err);
if (state->sent == -1) {
+ if (err == EPIPE) {
+ close(state->transp->fd);
+ state->transp->fd = -1;
+ }
TALLOC_FREE(subreq);
async_req_nterror(req, map_nt_error_from_unix(err));
return;