messaging4: Pass fds to messaging handlers
authorVolker Lendecke <vl@samba.org>
Wed, 18 Sep 2019 16:19:37 +0000 (09:19 -0700)
committerJeremy Allison <jra@samba.org>
Wed, 18 Sep 2019 20:10:24 +0000 (20:10 +0000)
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>
source3/winbindd/winbindd_util.c
source4/dsdb/repl/drepl_ridalloc.c
source4/lib/messaging/messaging.c
source4/lib/messaging/messaging.h
source4/lib/messaging/messaging_handlers.c
source4/lib/messaging/pymessaging.c
source4/lib/messaging/tests/messaging.c
source4/ntvfs/common/notify.c
source4/ntvfs/posix/pvfs_oplock.c
source4/ntvfs/posix/pvfs_wait.c
source4/smbd/server.c

index cc4c3f7391ae62f30ad435e4f81d417eccbf6b5c..ebe283ec71235c0c080957b6b77ac97083301dae 100644 (file)
@@ -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();
index 3615859ed9b38c372b1cb14817396f1151ae9f5b..1e7d937b9a80cd4d617f646a640f700f4c6bebe2 100644 (file)
@@ -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);
 }
index 1f27cf74e17a205714fcbf16821876f7f14db148..6cfa4bbd4f14e9118be8c27c656ed1ca3e0af4a1 100644 (file)
@@ -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;
 
index 8eb195dfb2e72788682e5c61d629d26f71af95e1..3fd788d1e4209e335792c2721bbb4c3a75818155 100644 (file)
@@ -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);
index 342157d5b4a080b842326e036d47157d6055e1d4..57e3e1c8f1b5a40fdfd37a69eba3e55ff607c811 100644 (file)
@@ -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));
index e506d94f4742ecb2b5c6896842865f7ca24d19f5..e6b9c770dfdf24b08d21642b4baf6962f18f872f 100644 (file)
@@ -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;
index 2f29ae3b64071e16570612518519f171e2b51923..dcbbc19a3886d735eb70393a2cd1279e4d392e4b 100644 (file)
 
 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.");
index 61da0b8291d1090adfcb201f3cffab6fbee36ca4..a434fab998c1bd90f42507bbfe562706566eb163 100644 (file)
@@ -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;
        }
index 5b9f3a318c82649c05210ae9cc72cd0a4e5b4f6d..ba5d25dfdee47d3847af5710571722400f302aff 100644 (file)
@@ -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
index 89b0cee2f15bb05fa814ac77d343d972504abbdf..460c2f7d9c5985b8e2eed18930613d70734b89d8 100644 (file)
@@ -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.
         */
index eb43f28e6b86f414f854e10ae4665723e59cb5a8..0fc9125cbbab240e50758cfe3ace0c9d2abac527 100644 (file)
@@ -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),