diff options
author | Stefan Metzmacher <metze@samba.org> | 2014-06-23 17:16:32 +0200 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2014-09-24 08:44:11 +0200 |
commit | c689547c9370967b3eecf0ea88252ad86f0234bf (patch) | |
tree | 0f1eac207860eff097a6afbf240061994f9386fa /source3/lib | |
parent | af573af0ff2fed6a9ce6f3cbd27e32c62d5884eb (diff) | |
download | samba-c689547c9370967b3eecf0ea88252ad86f0234bf.tar.gz samba-c689547c9370967b3eecf0ea88252ad86f0234bf.tar.xz samba-c689547c9370967b3eecf0ea88252ad86f0234bf.zip |
s3:unix_msg: pass the fd array to the unix_msg recv_callback function
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/messages_dgm.c | 9 | ||||
-rw-r--r-- | source3/lib/unix_msg/test_drain.c | 2 | ||||
-rw-r--r-- | source3/lib/unix_msg/tests.c | 2 | ||||
-rw-r--r-- | source3/lib/unix_msg/unix_msg.c | 14 | ||||
-rw-r--r-- | source3/lib/unix_msg/unix_msg.h | 1 |
5 files changed, 23 insertions, 5 deletions
diff --git a/source3/lib/messages_dgm.c b/source3/lib/messages_dgm.c index 471aed464c..cadcb4be72 100644 --- a/source3/lib/messages_dgm.c +++ b/source3/lib/messages_dgm.c @@ -54,6 +54,7 @@ static struct messaging_dgm_context *global_dgm_context; static void messaging_dgm_recv(struct unix_msg_ctx *ctx, uint8_t *msg, size_t msg_len, + int *fds, size_t num_fds, void *private_data); static int messaging_dgm_lockfile_name(struct sun_path_buf *buf, @@ -324,10 +325,18 @@ int messaging_dgm_send(pid_t pid, const struct iovec *iov, int iovlen) static void messaging_dgm_recv(struct unix_msg_ctx *ctx, uint8_t *msg, size_t msg_len, + int *fds, size_t num_fds, void *private_data) { struct messaging_dgm_context *dgm_ctx = talloc_get_type_abort( private_data, struct messaging_dgm_context); + size_t i; + + /* for now we ignore passed file descriptors */ + for (i = 0; i < num_fds; i++) { + close(fds[i]); + fds[i] = -1; + } dgm_ctx->recv_cb(msg, msg_len, dgm_ctx->recv_cb_private_data); } diff --git a/source3/lib/unix_msg/test_drain.c b/source3/lib/unix_msg/test_drain.c index abaf5ef3c8..5b6a9304ce 100644 --- a/source3/lib/unix_msg/test_drain.c +++ b/source3/lib/unix_msg/test_drain.c @@ -12,6 +12,7 @@ struct cb_state { static void recv_cb(struct unix_msg_ctx *ctx, uint8_t *msg, size_t msg_len, + int *fds, size_t num_fds, void *private_data); int main(int argc, const char *argv[]) @@ -64,6 +65,7 @@ int main(int argc, const char *argv[]) static void recv_cb(struct unix_msg_ctx *ctx, uint8_t *msg, size_t msg_len, + int *fds, size_t num_fds, void *private_data) { unsigned num; diff --git a/source3/lib/unix_msg/tests.c b/source3/lib/unix_msg/tests.c index 37ff3040a4..a213cc22a6 100644 --- a/source3/lib/unix_msg/tests.c +++ b/source3/lib/unix_msg/tests.c @@ -11,6 +11,7 @@ struct cb_state { static void recv_cb(struct unix_msg_ctx *ctx, uint8_t *msg, size_t msg_len, + int *fds, size_t num_fds, void *private_data); static void expect_messages(struct tevent_context *ev, struct cb_state *state, @@ -225,6 +226,7 @@ int main(void) static void recv_cb(struct unix_msg_ctx *ctx, uint8_t *msg, size_t msg_len, + int *fds, size_t num_fds, void *private_data) { struct cb_state *state = (struct cb_state *)private_data; diff --git a/source3/lib/unix_msg/unix_msg.c b/source3/lib/unix_msg/unix_msg.c index 3a9ce09282..e32a4d80bc 100644 --- a/source3/lib/unix_msg/unix_msg.c +++ b/source3/lib/unix_msg/unix_msg.c @@ -802,6 +802,7 @@ struct unix_msg_ctx { void (*recv_callback)(struct unix_msg_ctx *ctx, uint8_t *msg, size_t msg_len, + int *fds, size_t num_fds, void *private_data); void *private_data; @@ -818,6 +819,7 @@ int unix_msg_init(const struct sockaddr_un *addr, size_t fragment_len, uint64_t cookie, void (*recv_callback)(struct unix_msg_ctx *ctx, uint8_t *msg, size_t msg_len, + int *fds, size_t num_fds, void *private_data), void *private_data, struct unix_msg_ctx **result) @@ -960,10 +962,8 @@ static void unix_msg_recv(struct unix_dgram_ctx *dgram_ctx, size_t space; uint64_t cookie; - /* for now we ignore passed file descriptors */ - close_fd_array(fds, num_fds); - if (buflen < sizeof(cookie)) { + close_fd_array(fds, num_fds); return; } memcpy(&cookie, buf, sizeof(cookie)); @@ -972,11 +972,12 @@ static void unix_msg_recv(struct unix_dgram_ctx *dgram_ctx, buflen -= sizeof(cookie); if (cookie == 0) { - ctx->recv_callback(ctx, buf, buflen, ctx->private_data); + ctx->recv_callback(ctx, buf, buflen, fds, num_fds, ctx->private_data); return; } if (buflen < sizeof(hdr)) { + close_fd_array(fds, num_fds); return; } memcpy(&hdr, buf, sizeof(hdr)); @@ -1000,6 +1001,7 @@ static void unix_msg_recv(struct unix_dgram_ctx *dgram_ctx, if (msg == NULL) { msg = malloc(offsetof(struct unix_msg, buf) + hdr.msglen); if (msg == NULL) { + close_fd_array(fds, num_fds); return; } *msg = (struct unix_msg) { @@ -1013,6 +1015,7 @@ static void unix_msg_recv(struct unix_dgram_ctx *dgram_ctx, space = msg->msglen - msg->received; if (buflen > space) { + close_fd_array(fds, num_fds); return; } @@ -1020,11 +1023,12 @@ static void unix_msg_recv(struct unix_dgram_ctx *dgram_ctx, msg->received += buflen; if (msg->received < msg->msglen) { + close_fd_array(fds, num_fds); return; } DLIST_REMOVE(ctx->msgs, msg); - ctx->recv_callback(ctx, msg->buf, msg->msglen, ctx->private_data); + ctx->recv_callback(ctx, msg->buf, msg->msglen, fds, num_fds, ctx->private_data); free(msg); } diff --git a/source3/lib/unix_msg/unix_msg.h b/source3/lib/unix_msg/unix_msg.h index a712a8f1ee..16c7c83aaa 100644 --- a/source3/lib/unix_msg/unix_msg.h +++ b/source3/lib/unix_msg/unix_msg.h @@ -81,6 +81,7 @@ int unix_msg_init(const struct sockaddr_un *addr, size_t fragment_size, uint64_t cookie, void (*recv_callback)(struct unix_msg_ctx *ctx, uint8_t *msg, size_t msg_len, + int *fds, size_t num_fds, void *private_data), void *private_data, struct unix_msg_ctx **result); |