1
0
mirror of https://github.com/samba-team/samba.git synced 2025-08-04 08:22:08 +03:00

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>
This commit is contained in:
Stefan Metzmacher
2014-06-23 17:16:32 +02:00
committed by Michael Adam
parent af573af0ff
commit c689547c93
5 changed files with 23 additions and 5 deletions

View File

@ -54,6 +54,7 @@ static struct messaging_dgm_context *global_dgm_context;
static void messaging_dgm_recv(struct unix_msg_ctx *ctx, static void messaging_dgm_recv(struct unix_msg_ctx *ctx,
uint8_t *msg, size_t msg_len, uint8_t *msg, size_t msg_len,
int *fds, size_t num_fds,
void *private_data); void *private_data);
static int messaging_dgm_lockfile_name(struct sun_path_buf *buf, 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, static void messaging_dgm_recv(struct unix_msg_ctx *ctx,
uint8_t *msg, size_t msg_len, uint8_t *msg, size_t msg_len,
int *fds, size_t num_fds,
void *private_data) void *private_data)
{ {
struct messaging_dgm_context *dgm_ctx = talloc_get_type_abort( struct messaging_dgm_context *dgm_ctx = talloc_get_type_abort(
private_data, struct messaging_dgm_context); 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); dgm_ctx->recv_cb(msg, msg_len, dgm_ctx->recv_cb_private_data);
} }

View File

@ -12,6 +12,7 @@ struct cb_state {
static void recv_cb(struct unix_msg_ctx *ctx, static void recv_cb(struct unix_msg_ctx *ctx,
uint8_t *msg, size_t msg_len, uint8_t *msg, size_t msg_len,
int *fds, size_t num_fds,
void *private_data); void *private_data);
int main(int argc, const char *argv[]) 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, static void recv_cb(struct unix_msg_ctx *ctx,
uint8_t *msg, size_t msg_len, uint8_t *msg, size_t msg_len,
int *fds, size_t num_fds,
void *private_data) void *private_data)
{ {
unsigned num; unsigned num;

View File

@ -11,6 +11,7 @@ struct cb_state {
static void recv_cb(struct unix_msg_ctx *ctx, static void recv_cb(struct unix_msg_ctx *ctx,
uint8_t *msg, size_t msg_len, uint8_t *msg, size_t msg_len,
int *fds, size_t num_fds,
void *private_data); void *private_data);
static void expect_messages(struct tevent_context *ev, struct cb_state *state, 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, static void recv_cb(struct unix_msg_ctx *ctx,
uint8_t *msg, size_t msg_len, uint8_t *msg, size_t msg_len,
int *fds, size_t num_fds,
void *private_data) void *private_data)
{ {
struct cb_state *state = (struct cb_state *)private_data; struct cb_state *state = (struct cb_state *)private_data;

View File

@ -802,6 +802,7 @@ struct unix_msg_ctx {
void (*recv_callback)(struct unix_msg_ctx *ctx, void (*recv_callback)(struct unix_msg_ctx *ctx,
uint8_t *msg, size_t msg_len, uint8_t *msg, size_t msg_len,
int *fds, size_t num_fds,
void *private_data); void *private_data);
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, size_t fragment_len, uint64_t cookie,
void (*recv_callback)(struct unix_msg_ctx *ctx, void (*recv_callback)(struct unix_msg_ctx *ctx,
uint8_t *msg, size_t msg_len, uint8_t *msg, size_t msg_len,
int *fds, size_t num_fds,
void *private_data), void *private_data),
void *private_data, void *private_data,
struct unix_msg_ctx **result) struct unix_msg_ctx **result)
@ -960,10 +962,8 @@ static void unix_msg_recv(struct unix_dgram_ctx *dgram_ctx,
size_t space; size_t space;
uint64_t cookie; uint64_t cookie;
/* for now we ignore passed file descriptors */
close_fd_array(fds, num_fds);
if (buflen < sizeof(cookie)) { if (buflen < sizeof(cookie)) {
close_fd_array(fds, num_fds);
return; return;
} }
memcpy(&cookie, buf, sizeof(cookie)); memcpy(&cookie, buf, sizeof(cookie));
@ -972,11 +972,12 @@ static void unix_msg_recv(struct unix_dgram_ctx *dgram_ctx,
buflen -= sizeof(cookie); buflen -= sizeof(cookie);
if (cookie == 0) { 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; return;
} }
if (buflen < sizeof(hdr)) { if (buflen < sizeof(hdr)) {
close_fd_array(fds, num_fds);
return; return;
} }
memcpy(&hdr, buf, sizeof(hdr)); memcpy(&hdr, buf, sizeof(hdr));
@ -1000,6 +1001,7 @@ static void unix_msg_recv(struct unix_dgram_ctx *dgram_ctx,
if (msg == NULL) { if (msg == NULL) {
msg = malloc(offsetof(struct unix_msg, buf) + hdr.msglen); msg = malloc(offsetof(struct unix_msg, buf) + hdr.msglen);
if (msg == NULL) { if (msg == NULL) {
close_fd_array(fds, num_fds);
return; return;
} }
*msg = (struct unix_msg) { *msg = (struct unix_msg) {
@ -1013,6 +1015,7 @@ static void unix_msg_recv(struct unix_dgram_ctx *dgram_ctx,
space = msg->msglen - msg->received; space = msg->msglen - msg->received;
if (buflen > space) { if (buflen > space) {
close_fd_array(fds, num_fds);
return; return;
} }
@ -1020,11 +1023,12 @@ static void unix_msg_recv(struct unix_dgram_ctx *dgram_ctx,
msg->received += buflen; msg->received += buflen;
if (msg->received < msg->msglen) { if (msg->received < msg->msglen) {
close_fd_array(fds, num_fds);
return; return;
} }
DLIST_REMOVE(ctx->msgs, msg); 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); free(msg);
} }

View File

@ -81,6 +81,7 @@ int unix_msg_init(const struct sockaddr_un *addr,
size_t fragment_size, uint64_t cookie, size_t fragment_size, uint64_t cookie,
void (*recv_callback)(struct unix_msg_ctx *ctx, void (*recv_callback)(struct unix_msg_ctx *ctx,
uint8_t *msg, size_t msg_len, uint8_t *msg, size_t msg_len,
int *fds, size_t num_fds,
void *private_data), void *private_data),
void *private_data, void *private_data,
struct unix_msg_ctx **result); struct unix_msg_ctx **result);