diff options
author | Volker Lendecke <vl@samba.org> | 2019-09-18 09:19:37 -0700 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2019-09-18 20:10:24 +0000 |
commit | 3084928383cdeafc53b2154f458464d9174faff2 (patch) | |
tree | d37b3b05dd801686a2dfafb35c3816095942914a | |
parent | 3263dd32fedf9e6c104a0c03f035b585c568a8d1 (diff) | |
download | samba-3084928383cdeafc53b2154f458464d9174faff2.tar.gz |
messaging4: Pass fds to messaging handlers
Boiler-plate replacement moving the (num_fds!=0) check down
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
-rw-r--r-- | source3/winbindd/winbindd_util.c | 7 | ||||
-rw-r--r-- | source4/dsdb/repl/drepl_ridalloc.c | 12 | ||||
-rw-r--r-- | source4/lib/messaging/messaging.c | 87 | ||||
-rw-r--r-- | source4/lib/messaging/messaging.h | 11 | ||||
-rw-r--r-- | source4/lib/messaging/messaging_handlers.c | 14 | ||||
-rw-r--r-- | source4/lib/messaging/pymessaging.c | 16 | ||||
-rw-r--r-- | source4/lib/messaging/tests/messaging.c | 79 | ||||
-rw-r--r-- | source4/ntvfs/common/notify.c | 23 | ||||
-rw-r--r-- | source4/ntvfs/posix/pvfs_oplock.c | 13 | ||||
-rw-r--r-- | source4/ntvfs/posix/pvfs_wait.c | 13 | ||||
-rw-r--r-- | source4/smbd/server.c | 7 |
11 files changed, 244 insertions, 38 deletions
diff --git a/source3/winbindd/winbindd_util.c b/source3/winbindd/winbindd_util.c index cc4c3f7391a..ebe283ec712 100644 --- a/source3/winbindd/winbindd_util.c +++ b/source3/winbindd/winbindd_util.c @@ -849,10 +849,17 @@ static void wb_imsg_new_trusted_domain(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) { bool ok; + if (num_fds != 0) { + DBG_WARNING("Received %zu fds, ignoring message\n", num_fds); + return; + } + DBG_NOTICE("Rescanning trusted domains\n"); ok = add_trusted_domains_dc(); diff --git a/source4/dsdb/repl/drepl_ridalloc.c b/source4/dsdb/repl/drepl_ridalloc.c index 3615859ed9b..1e7d937b9a8 100644 --- a/source4/dsdb/repl/drepl_ridalloc.c +++ b/source4/dsdb/repl/drepl_ridalloc.c @@ -248,10 +248,18 @@ WERROR dreplsrv_ridalloc_check_rid_pool(struct dreplsrv_service *service) /* called by the samldb ldb module to tell us to ask for a new RID pool */ -void dreplsrv_allocate_rid(struct imessaging_context *msg, void *private_data, +void dreplsrv_allocate_rid(struct imessaging_context *msg, + void *private_data, uint32_t msg_type, - struct server_id server_id, DATA_BLOB *data) + struct server_id server_id, + size_t num_fds, + int *fds, + DATA_BLOB *data) { struct dreplsrv_service *service = talloc_get_type(private_data, struct dreplsrv_service); + if (num_fds != 0) { + DBG_WARNING("Received %zu fds, ignoring message\n", num_fds); + return; + } dreplsrv_ridalloc_check_rid_pool(service); } 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."); diff --git a/source4/ntvfs/common/notify.c b/source4/ntvfs/common/notify.c index 61da0b8291d..a434fab998c 100644 --- a/source4/ntvfs/common/notify.c +++ b/source4/ntvfs/common/notify.c @@ -62,8 +62,13 @@ struct notify_list { #define NOTIFY_ENABLE_DEFAULT true static NTSTATUS notify_remove_all(struct notify_context *notify); -static void notify_handler(struct imessaging_context *msg_ctx, void *private_data, - uint32_t msg_type, struct server_id server_id, DATA_BLOB *data); +static void notify_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); /* destroy the notify context @@ -236,8 +241,13 @@ static NTSTATUS notify_save(struct notify_context *notify) /* handle incoming notify messages */ -static void notify_handler(struct imessaging_context *msg_ctx, void *private_data, - uint32_t msg_type, struct server_id server_id, DATA_BLOB *data) +static void notify_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 notify_context *notify = talloc_get_type(private_data, struct notify_context); enum ndr_err_code ndr_err; @@ -245,6 +255,11 @@ static void notify_handler(struct imessaging_context *msg_ctx, void *private_dat TALLOC_CTX *tmp_ctx = talloc_new(notify); struct notify_list *listel; + if (num_fds != 0) { + DBG_WARNING("Received %zu fds, ignoring message\n", num_fds); + return; + } + if (tmp_ctx == NULL) { return; } diff --git a/source4/ntvfs/posix/pvfs_oplock.c b/source4/ntvfs/posix/pvfs_oplock.c index 5b9f3a318c8..ba5d25dfdee 100644 --- a/source4/ntvfs/posix/pvfs_oplock.c +++ b/source4/ntvfs/posix/pvfs_oplock.c @@ -159,13 +159,22 @@ static void pvfs_oplock_break(struct pvfs_oplock *opl, uint8_t level) } static void pvfs_oplock_break_dispatch(struct imessaging_context *msg, - void *private_data, uint32_t msg_type, - struct server_id src, DATA_BLOB *data) + void *private_data, + uint32_t msg_type, + struct server_id src, + size_t num_fds, + int *fds, + DATA_BLOB *data) { struct pvfs_oplock *opl = talloc_get_type(private_data, struct pvfs_oplock); struct opendb_oplock_break opb; + if (num_fds != 0) { + DBG_WARNING("Received %zu fds, ignoring message\n", num_fds); + return; + } + ZERO_STRUCT(opb); /* we need to check that this one is for us. See diff --git a/source4/ntvfs/posix/pvfs_wait.c b/source4/ntvfs/posix/pvfs_wait.c index 89b0cee2f15..460c2f7d9c5 100644 --- a/source4/ntvfs/posix/pvfs_wait.c +++ b/source4/ntvfs/posix/pvfs_wait.c @@ -57,14 +57,23 @@ NTSTATUS pvfs_async_setup(struct ntvfs_module_context *ntvfs, receive a completion message for a wait */ static void pvfs_wait_dispatch(struct imessaging_context *msg, - void *private_data, uint32_t msg_type, - struct server_id src, DATA_BLOB *data) + void *private_data, + uint32_t msg_type, + struct server_id src, + size_t num_fds, + int *fds, + DATA_BLOB *data) { struct pvfs_wait *pwait = talloc_get_type(private_data, struct pvfs_wait); struct ntvfs_request *req; void *p = NULL; + if (num_fds != 0) { + DBG_WARNING("Received %zu fds, ignoring message\n", num_fds); + return; + } + /* we need to check that this one is for us. See imessaging_send_ptr() for the other side of this. */ diff --git a/source4/smbd/server.c b/source4/smbd/server.c index eb43f28e6b8..0fc9125cbba 100644 --- a/source4/smbd/server.c +++ b/source4/smbd/server.c @@ -341,6 +341,8 @@ static void samba_parent_shutdown(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_state *state = @@ -350,6 +352,11 @@ static void samba_parent_shutdown(struct imessaging_context *msg, struct server_id dst = imessaging_get_server_id(msg); struct server_id_buf dst_buf; + if (num_fds != 0) { + DBG_WARNING("Received %zu fds, ignoring message\n", num_fds); + return; + } + DBG_ERR("samba_shutdown of %s %s: from %s\n", state->binary_name, server_id_str_buf(dst, &dst_buf), |