From 3084928383cdeafc53b2154f458464d9174faff2 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 18 Sep 2019 09:19:37 -0700 Subject: messaging4: Pass fds to messaging handlers Boiler-plate replacement moving the (num_fds!=0) check down Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- source4/lib/messaging/messaging.c | 87 ++++++++++++++++++++++++------ source4/lib/messaging/messaging.h | 11 ++-- source4/lib/messaging/messaging_handlers.c | 14 +++++ source4/lib/messaging/pymessaging.c | 16 ++++-- source4/lib/messaging/tests/messaging.c | 79 ++++++++++++++++++++++++--- 5 files changed, 179 insertions(+), 28 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c index 1f27cf74e17..6cfa4bbd4f1 100644 --- a/source4/lib/messaging/messaging.c +++ b/source4/lib/messaging/messaging.c @@ -67,29 +67,54 @@ struct dispatch_fn { /* an individual message */ -static void irpc_handler(struct imessaging_context *, void *, - uint32_t, struct server_id, DATA_BLOB *); +static void irpc_handler(struct imessaging_context *, + void *, + uint32_t, + struct server_id, + size_t, + int *, + DATA_BLOB *); /* A useful function for testing the message system. */ -static void ping_message(struct imessaging_context *msg, void *private_data, - uint32_t msg_type, struct server_id src, DATA_BLOB *data) +static void ping_message(struct imessaging_context *msg, + void *private_data, + uint32_t msg_type, + struct server_id src, + size_t num_fds, + int *fds, + DATA_BLOB *data) { struct server_id_buf idbuf; + + if (num_fds != 0) { + DBG_WARNING("Received %zu fds, ignoring message\n", num_fds); + return; + } + DEBUG(1,("INFO: Received PING message from server %s [%.*s]\n", server_id_str_buf(src, &idbuf), (int)data->length, data->data?(const char *)data->data:"")); imessaging_send(msg, src, MSG_PONG, data); } -static void pool_message(struct imessaging_context *msg, void *private_data, - uint32_t msg_type, struct server_id src, +static void pool_message(struct imessaging_context *msg, + void *private_data, + uint32_t msg_type, + struct server_id src, + size_t num_fds, + int *fds, DATA_BLOB *data) { char *report; + if (num_fds != 0) { + DBG_WARNING("Received %zu fds, ignoring message\n", num_fds); + return; + } + report = talloc_report_str(msg, NULL); if (report != NULL) { @@ -104,12 +129,19 @@ static void ringbuf_log_msg(struct imessaging_context *msg, void *private_data, uint32_t msg_type, struct server_id src, + size_t num_fds, + int *fds, DATA_BLOB *data) { char *log = debug_get_ringbuf(); size_t logsize = debug_get_ringbuf_size(); DATA_BLOB blob; + if (num_fds != 0) { + DBG_WARNING("Received %zu fds, ignoring message\n", num_fds); + return; + } + if (log == NULL) { log = discard_const_p(char, "*disabled*\n"); logsize = strlen(log) + 1; @@ -129,6 +161,8 @@ static void debug_imessage(struct imessaging_context *msg_ctx, void *private_data, uint32_t msg_type, struct server_id src, + size_t num_fds, + int *fds, DATA_BLOB *data) { const char *params_str = (const char *)data->data; @@ -136,6 +170,11 @@ static void debug_imessage(struct imessaging_context *msg_ctx, struct server_id dst = imessaging_get_server_id(msg_ctx); struct server_id_buf dst_buf; + if (num_fds != 0) { + DBG_WARNING("Received %zu fds, ignoring message\n", num_fds); + return; + } + /* Check, it's a proper string! */ if (params_str[(data->length)-1] != '\0') { DBG_ERR("Invalid debug message from pid %s to pid %s\n", @@ -160,6 +199,8 @@ static void debuglevel_imessage(struct imessaging_context *msg_ctx, void *private_data, uint32_t msg_type, struct server_id src, + size_t num_fds, + int *fds, DATA_BLOB *data) { char *message = debug_list_class_names_and_levels(); @@ -168,6 +209,11 @@ static void debuglevel_imessage(struct imessaging_context *msg_ctx, struct server_id dst = imessaging_get_server_id(msg_ctx); struct server_id_buf dst_buf; + if (num_fds != 0) { + DBG_WARNING("Received %zu fds, ignoring message\n", num_fds); + return; + } + DBG_DEBUG("Received REQ_DEBUGLEVEL message (pid %s from pid %s)\n", server_id_str_buf(dst, &dst_buf), server_id_str_buf(src, &src_buf)); @@ -651,13 +697,6 @@ static void imessaging_dgm_recv(struct tevent_context *ev, return; } - if (num_fds != 0) { - /* - * Source4 based messaging does not expect fd's yet - */ - return; - } - if (ev != msg->ev) { int ret; ret = imessaging_post_self(msg, buf, buf_len); @@ -687,7 +726,13 @@ static void imessaging_dgm_recv(struct tevent_context *ev, for (; d; d = next) { next = d->next; - d->fn(msg, d->private_data, d->msg_type, src, &data); + d->fn(msg, + d->private_data, + d->msg_type, + src, + num_fds, + fds, + &data); } } else { DEBUG(10, ("%s: Ignoring type=0x%x dst %s, I am %s, \n", @@ -882,12 +927,22 @@ failed: /* handle an incoming irpc message */ -static void irpc_handler(struct imessaging_context *msg_ctx, void *private_data, - uint32_t msg_type, struct server_id src, DATA_BLOB *packet) +static void irpc_handler(struct imessaging_context *msg_ctx, + void *private_data, + uint32_t msg_type, + struct server_id src, + size_t num_fds, + int *fds, + DATA_BLOB *packet) { struct irpc_message *m; enum ndr_err_code ndr_err; + if (num_fds != 0) { + DBG_WARNING("Received %zu fds, ignoring message\n", num_fds); + return; + } + m = talloc(msg_ctx, struct irpc_message); if (m == NULL) goto failed; diff --git a/source4/lib/messaging/messaging.h b/source4/lib/messaging/messaging.h index 8eb195dfb2e..3fd788d1e42 100644 --- a/source4/lib/messaging/messaging.h +++ b/source4/lib/messaging/messaging.h @@ -29,9 +29,14 @@ struct imessaging_context; /* taskid for messaging of parent process */ #define SAMBA_PARENT_TASKID 0 -typedef void (*msg_callback_t)(struct imessaging_context *msg, void *private_data, - uint32_t msg_type, - struct server_id server_id, DATA_BLOB *data); +typedef void (*msg_callback_t)( + struct imessaging_context *msg, + void *private_data, + uint32_t msg_type, + struct server_id server_id, + size_t num_fds, + int *fds, + DATA_BLOB *data); NTSTATUS imessaging_send(struct imessaging_context *msg, struct server_id server, uint32_t msg_type, const DATA_BLOB *data); diff --git a/source4/lib/messaging/messaging_handlers.c b/source4/lib/messaging/messaging_handlers.c index 342157d5b4a..57e3e1c8f1b 100644 --- a/source4/lib/messaging/messaging_handlers.c +++ b/source4/lib/messaging/messaging_handlers.c @@ -36,11 +36,18 @@ static void do_inject_fault(struct imessaging_context *msg, void *private_data, uint32_t msg_type, struct server_id src, + size_t num_fds, + int *fds, DATA_BLOB *data) { int sig; struct server_id_buf tmp; + if (num_fds != 0) { + DBG_WARNING("Received %zu fds, ignoring message\n", num_fds); + return; + } + if (data->length != sizeof(sig)) { DBG_ERR("Process %s sent bogus signal injection request\n", server_id_str_buf(src, &tmp)); @@ -76,11 +83,18 @@ static void do_sleep(struct imessaging_context *msg, void *private_data, uint32_t msg_type, struct server_id src, + size_t num_fds, + int *fds, DATA_BLOB *data) { unsigned int seconds; struct server_id_buf tmp; + if (num_fds != 0) { + DBG_WARNING("Received %zu fds, ignoring message\n", num_fds); + return; + } + if (data->length != sizeof(seconds)) { DBG_ERR("Process %s sent bogus sleep request\n", server_id_str_buf(src, &tmp)); diff --git a/source4/lib/messaging/pymessaging.c b/source4/lib/messaging/pymessaging.c index e506d94f474..e6b9c770dfd 100644 --- a/source4/lib/messaging/pymessaging.c +++ b/source4/lib/messaging/pymessaging.c @@ -177,14 +177,24 @@ static PyObject *py_imessaging_send(PyObject *self, PyObject *args, PyObject *kw Py_RETURN_NONE; } -static void py_msg_callback_wrapper(struct imessaging_context *msg, void *private_data, - uint32_t msg_type, - struct server_id server_id, DATA_BLOB *data) +static void py_msg_callback_wrapper(struct imessaging_context *msg, + void *private_data, + uint32_t msg_type, + struct server_id server_id, + size_t num_fds, + int *fds, + DATA_BLOB *data) { PyObject *py_server_id, *callback_and_tuple = (PyObject *)private_data; PyObject *callback, *py_private; struct server_id *p_server_id = talloc(NULL, struct server_id); + + if (num_fds != 0) { + DBG_WARNING("Received %zu fds, ignoring message\n", num_fds); + return; + } + if (!p_server_id) { PyErr_NoMemory(); return; diff --git a/source4/lib/messaging/tests/messaging.c b/source4/lib/messaging/tests/messaging.c index 2f29ae3b640..dcbbc19a388 100644 --- a/source4/lib/messaging/tests/messaging.c +++ b/source4/lib/messaging/tests/messaging.c @@ -34,26 +34,58 @@ static uint32_t msg_pong; -static void ping_message(struct imessaging_context *msg, void *private_data, - uint32_t msg_type, struct server_id src, DATA_BLOB *data) +static void ping_message(struct imessaging_context *msg, + void *private_data, + uint32_t msg_type, + struct server_id src, + size_t num_fds, + int *fds, + DATA_BLOB *data) { NTSTATUS status; + + if (num_fds != 0) { + DBG_WARNING("Received %zu fds, ignoring message\n", num_fds); + return; + } + status = imessaging_send(msg, src, msg_pong, data); if (!NT_STATUS_IS_OK(status)) { printf("pong failed - %s\n", nt_errstr(status)); } } -static void pong_message(struct imessaging_context *msg, void *private_data, - uint32_t msg_type, struct server_id src, DATA_BLOB *data) +static void pong_message(struct imessaging_context *msg, + void *private_data, + uint32_t msg_type, + struct server_id src, + size_t num_fds, + int *fds, + DATA_BLOB *data) { int *count = (int *)private_data; + + if (num_fds != 0) { + DBG_WARNING("Received %zu fds, ignoring message\n", num_fds); + return; + } + (*count)++; } -static void exit_message(struct imessaging_context *msg, void *private_data, - uint32_t msg_type, struct server_id src, DATA_BLOB *data) +static void exit_message(struct imessaging_context *msg, + void *private_data, + uint32_t msg_type, + struct server_id src, + size_t num_fds, + int *fds, + DATA_BLOB *data) { + if (num_fds != 0) { + DBG_WARNING("Received %zu fds, ignoring message\n", num_fds); + return; + } + talloc_free(private_data); exit(0); } @@ -223,10 +255,17 @@ static void overflow_md5_child_handler(struct imessaging_context *msg, void *private_data, uint32_t msg_type, struct server_id server_id, + size_t num_fds, + int *fds, DATA_BLOB *data) { struct overflow_parent_child *state = private_data; + if (num_fds != 0) { + DBG_WARNING("Received %zu fds, ignoring message\n", num_fds); + return; + } + if (data->length == 0) { state->done = true; return; @@ -244,10 +283,17 @@ static void overflow_md5_parent_handler(struct imessaging_context *msg_ctx, void *private_data, uint32_t msg_type, struct server_id server_id, + size_t num_fds, + int *fds, DATA_BLOB *data) { struct overflow_child_parent *state = private_data; + if (num_fds != 0) { + DBG_WARNING("Received %zu fds, ignoring message\n", num_fds); + return; + } + if (data->length != sizeof(state->final)) { memset(state->final, 0, sizeof(state->final)); state->done = true; @@ -410,11 +456,18 @@ static void multi_ctx_server_handler(struct imessaging_context *msg, void *private_data, uint32_t msg_type, struct server_id server_id, + size_t num_fds, + int *fds, DATA_BLOB *data) { struct test_multi_ctx *state = private_data; char *str = NULL; + if (num_fds != 0) { + DBG_WARNING("Received %zu fds, ignoring message\n", num_fds); + return; + } + torture_assert_goto(state->tctx, state->num_missing >= 1, state->ok, fail, "num_missing should be at least 1."); @@ -443,11 +496,18 @@ static void multi_ctx_client_0_1_handler(struct imessaging_context *msg, void *private_data, uint32_t msg_type, struct server_id server_id, + size_t num_fds, + int *fds, DATA_BLOB *data) { struct test_multi_ctx *state = private_data; char *str = NULL; + if (num_fds != 0) { + DBG_WARNING("Received %zu fds, ignoring message\n", num_fds); + return; + } + torture_assert_goto(state->tctx, state->num_missing >= 2, state->ok, fail, "num_missing should be at least 2."); @@ -481,11 +541,18 @@ static void multi_ctx_client_2_3_handler(struct imessaging_context *msg, void *private_data, uint32_t msg_type, struct server_id server_id, + size_t num_fds, + int *fds, DATA_BLOB *data) { struct test_multi_ctx *state = private_data; char *str = NULL; + if (num_fds != 0) { + DBG_WARNING("Received %zu fds, ignoring message\n", num_fds); + return; + } + torture_assert_goto(state->tctx, state->num_missing >= 2, state->ok, fail, "num_missing should be at least 2."); -- cgit v1.2.1