s4-messaging: split up messaging into a smaller library for send only
authorAndrew Bartlett <abartlet@samba.org>
Fri, 24 Mar 2017 02:11:35 +0000 (15:11 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 29 Mar 2017 00:37:27 +0000 (02:37 +0200)
This will help avoid a dep loop when the low-level auth code relies on the message
code to deliver authentication messages

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
auth/wscript_build
source4/lib/messaging/messaging.c
source4/lib/messaging/messaging_send.c [new file with mode: 0644]
source4/lib/messaging/wscript_build

index 30f8bf9e1fb6c85fa8d6dd34e75f2c11d9f567ca..e0c694642369e42457b7ca3d571cfad385311760 100644 (file)
@@ -2,7 +2,7 @@
 
 bld.SAMBA_LIBRARY('common_auth',
                   source='auth_sam_reply.c wbc_auth_util.c auth_log.c',
-                  deps='talloc samba-security samba-util util_str_escape LIBTSOCKET jansson',
+                  deps='talloc samba-security samba-util util_str_escape LIBTSOCKET jansson MESSAGING_SEND server_id_db',
                   private_library=True
                   )
 
index 4d75f0976dcba1b5ad18a19d953d976db703a524..80ef597ed48d951a6d298482403103a206111acc 100644 (file)
@@ -230,68 +230,6 @@ void imessaging_deregister(struct imessaging_context *msg, uint32_t msg_type, vo
        }
 }
 
-/*
-  Send a message to a particular server
-*/
-NTSTATUS imessaging_send(struct imessaging_context *msg, struct server_id server,
-                       uint32_t msg_type, const DATA_BLOB *data)
-{
-       uint8_t hdr[MESSAGE_HDR_LENGTH];
-       struct iovec iov[2];
-       int num_iov, ret;
-       pid_t pid;
-       void *priv;
-
-       if (!cluster_node_equal(&msg->server_id, &server)) {
-               /* No cluster in source4... */
-               return NT_STATUS_OK;
-       }
-
-       message_hdr_put(hdr, msg_type, msg->server_id, server);
-
-       iov[0] = (struct iovec) { .iov_base = &hdr, .iov_len = sizeof(hdr) };
-       num_iov = 1;
-
-       if (data != NULL) {
-               iov[1] = (struct iovec) { .iov_base = data->data,
-                                         .iov_len = data->length };
-               num_iov += 1;
-       }
-
-       pid = server.pid;
-       if (pid == 0) {
-               pid = getpid();
-       }
-
-       ret = messaging_dgm_send(pid, iov, num_iov, NULL, 0);
-
-       if (ret == EACCES) {
-               priv = root_privileges();
-               ret = messaging_dgm_send(pid, iov, num_iov, NULL, 0);
-               TALLOC_FREE(priv);
-       }
-
-       if (ret != 0) {
-               return map_nt_error_from_unix_common(ret);
-       }
-       return NT_STATUS_OK;
-}
-
-/*
-  Send a message to a particular server, with the message containing a single pointer
-*/
-NTSTATUS imessaging_send_ptr(struct imessaging_context *msg, struct server_id server,
-                           uint32_t msg_type, void *ptr)
-{
-       DATA_BLOB blob;
-
-       blob.data = (uint8_t *)&ptr;
-       blob.length = sizeof(void *);
-
-       return imessaging_send(msg, server, msg_type, &blob);
-}
-
-
 /*
 */
 int imessaging_cleanup(struct imessaging_context *msg)
@@ -778,24 +716,6 @@ NTSTATUS irpc_add_name(struct imessaging_context *msg_ctx, const char *name)
        return NT_STATUS_OK;
 }
 
-/*
-  return a list of server ids for a server name
-*/
-NTSTATUS irpc_servers_byname(struct imessaging_context *msg_ctx,
-                            TALLOC_CTX *mem_ctx, const char *name,
-                            unsigned *num_servers,
-                            struct server_id **servers)
-{
-       int ret;
-
-       ret = server_id_db_lookup(msg_ctx->names, name, mem_ctx,
-                                 num_servers, servers);
-       if (ret != 0) {
-               return map_nt_error_from_unix_common(ret);
-       }
-       return NT_STATUS_OK;
-}
-
 static int all_servers_func(const char *name, unsigned num_servers,
                            const struct server_id *servers,
                            void *private_data)
diff --git a/source4/lib/messaging/messaging_send.c b/source4/lib/messaging/messaging_send.c
new file mode 100644 (file)
index 0000000..a4f8281
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+   Unix SMB/CIFS implementation.
+
+   Samba internal messaging functions (send).
+
+   Copyright (C) Andrew Tridgell 2004
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "messaging/messaging.h"
+#include "messaging/irpc.h"
+#include "../source3/lib/messages_dgm.h"
+#include "../source3/lib/messages_dgm_ref.h"
+#include "../source3/lib/messages_util.h"
+#include "messaging/messaging_internal.h"
+#include "lib/util/server_id_db.h"
+#include "cluster/cluster.h"
+#include "../lib/util/unix_privs.h"
+
+/*
+ * This file is for functions that can be called from auth_log without
+ * depending on all of dcerpc and so cause dep loops.
+ */
+
+/*
+  return a list of server ids for a server name
+*/
+NTSTATUS irpc_servers_byname(struct imessaging_context *msg_ctx,
+                            TALLOC_CTX *mem_ctx, const char *name,
+                            unsigned *num_servers,
+                            struct server_id **servers)
+{
+       int ret;
+
+       ret = server_id_db_lookup(msg_ctx->names, name, mem_ctx,
+                                 num_servers, servers);
+       if (ret != 0) {
+               return map_nt_error_from_unix_common(ret);
+       }
+       return NT_STATUS_OK;
+}
+
+/*
+  Send a message to a particular server
+*/
+NTSTATUS imessaging_send(struct imessaging_context *msg, struct server_id server,
+                       uint32_t msg_type, const DATA_BLOB *data)
+{
+       uint8_t hdr[MESSAGE_HDR_LENGTH];
+       struct iovec iov[2];
+       int num_iov, ret;
+       pid_t pid;
+       void *priv;
+
+       if (!cluster_node_equal(&msg->server_id, &server)) {
+               /* No cluster in source4... */
+               return NT_STATUS_OK;
+       }
+
+       message_hdr_put(hdr, msg_type, msg->server_id, server);
+
+       iov[0] = (struct iovec) { .iov_base = &hdr, .iov_len = sizeof(hdr) };
+       num_iov = 1;
+
+       if (data != NULL) {
+               iov[1] = (struct iovec) { .iov_base = data->data,
+                                         .iov_len = data->length };
+               num_iov += 1;
+       }
+
+       pid = server.pid;
+       if (pid == 0) {
+               pid = getpid();
+       }
+
+       ret = messaging_dgm_send(pid, iov, num_iov, NULL, 0);
+
+       if (ret == EACCES) {
+               priv = root_privileges();
+               ret = messaging_dgm_send(pid, iov, num_iov, NULL, 0);
+               TALLOC_FREE(priv);
+       }
+
+       if (ret != 0) {
+               return map_nt_error_from_unix_common(ret);
+       }
+       return NT_STATUS_OK;
+}
+
+/*
+  Send a message to a particular server, with the message containing a single pointer
+*/
+NTSTATUS imessaging_send_ptr(struct imessaging_context *msg, struct server_id server,
+                           uint32_t msg_type, void *ptr)
+{
+       DATA_BLOB blob;
+
+       blob.data = (uint8_t *)&ptr;
+       blob.length = sizeof(void *);
+
+       return imessaging_send(msg, server, msg_type, &blob);
+}
index 86877af8441a9500fbe3b3c86bd01581cd92c544..2b6cf81885c0de3061049c1f562d5dcf2685f573 100644 (file)
@@ -1,6 +1,12 @@
 #!/usr/bin/env python
 
 
+bld.SAMBA_LIBRARY('MESSAGING_SEND',
+       source='messaging_send.c',
+       public_deps='messages_util messages_dgm UNIX_PRIVS cluster server_id_db',
+       private_library=True
+       )
+
 bld.SAMBA_LIBRARY('MESSAGING',
        source='messaging.c',
        public_deps='samba-util NDR_IRPC UNIX_PRIVS cluster ndr dcerpc messages_util server_id_db talloc_report',