LCOV - code coverage report
Current view: top level - source4/lib/messaging - messaging_send.c (source / functions) Hit Total Coverage
Test: coverage report for master 2b515b7d Lines: 32 37 86.5 %
Date: 2024-02-28 12:06:22 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    Samba internal messaging functions (send).
       5             : 
       6             :    Copyright (C) Andrew Tridgell 2004
       7             : 
       8             :    This program is free software; you can redistribute it and/or modify
       9             :    it under the terms of the GNU General Public License as published by
      10             :    the Free Software Foundation; either version 3 of the License, or
      11             :    (at your option) any later version.
      12             : 
      13             :    This program is distributed in the hope that it will be useful,
      14             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16             :    GNU General Public License for more details.
      17             : 
      18             :    You should have received a copy of the GNU General Public License
      19             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      20             : */
      21             : 
      22             : #include "includes.h"
      23             : #include "messaging/messaging.h"
      24             : #include "messaging/irpc.h"
      25             : #include "lib/messaging/messages_dgm.h"
      26             : #include "lib/messaging/messages_dgm_ref.h"
      27             : #include "../source3/lib/messages_util.h"
      28             : #include "messaging/messaging_internal.h"
      29             : #include "lib/util/server_id_db.h"
      30             : #include "cluster/cluster.h"
      31             : #include "../lib/util/unix_privs.h"
      32             : 
      33             : /*
      34             :  * This file is for functions that can be called from auth_log without
      35             :  * depending on all of dcerpc and so cause dep loops.
      36             :  */
      37             : 
      38             : /*
      39             :   return a list of server ids for a server name
      40             : */
      41      729343 : NTSTATUS irpc_servers_byname(struct imessaging_context *msg_ctx,
      42             :                              TALLOC_CTX *mem_ctx, const char *name,
      43             :                              unsigned *num_servers,
      44             :                              struct server_id **servers)
      45             : {
      46       18253 :         int ret;
      47             : 
      48      729343 :         ret = server_id_db_lookup(msg_ctx->names, name, mem_ctx,
      49             :                                   num_servers, servers);
      50      729343 :         if (ret != 0) {
      51      718101 :                 return map_nt_error_from_unix_common(ret);
      52             :         }
      53       11242 :         return NT_STATUS_OK;
      54             : }
      55             : 
      56             : /*
      57             :   Send a message to a particular server
      58             : */
      59       85690 : NTSTATUS imessaging_send(struct imessaging_context *msg, struct server_id server,
      60             :                         uint32_t msg_type, const DATA_BLOB *data)
      61             : {
      62       63326 :         uint8_t hdr[MESSAGE_HDR_LENGTH];
      63       63326 :         struct iovec iov[2];
      64       63326 :         int num_iov, ret;
      65       63326 :         pid_t pid;
      66       63326 :         void *priv;
      67             : 
      68       85690 :         if (!cluster_node_equal(&msg->server_id, &server)) {
      69             :                 /* No cluster in source4... */
      70           0 :                 return NT_STATUS_OK;
      71             :         }
      72             : 
      73       85690 :         message_hdr_put(hdr, msg_type, msg->server_id, server);
      74             : 
      75       85690 :         iov[0] = (struct iovec) { .iov_base = &hdr, .iov_len = sizeof(hdr) };
      76       85690 :         num_iov = 1;
      77             : 
      78       85690 :         if (data != NULL) {
      79       76621 :                 iov[1] = (struct iovec) { .iov_base = data->data,
      80       76621 :                                           .iov_len = data->length };
      81       76621 :                 num_iov += 1;
      82             :         }
      83             : 
      84       85690 :         pid = server.pid;
      85       85690 :         if (pid == 0) {
      86       61306 :                 pid = getpid();
      87             :         }
      88             : 
      89       85690 :         ret = messaging_dgm_send(pid, iov, num_iov, NULL, 0);
      90             : 
      91       85690 :         if (ret == EACCES) {
      92           0 :                 priv = root_privileges();
      93           0 :                 ret = messaging_dgm_send(pid, iov, num_iov, NULL, 0);
      94           0 :                 TALLOC_FREE(priv);
      95             :         }
      96             : 
      97       85690 :         if (ret != 0) {
      98          24 :                 return map_nt_error_from_unix_common(ret);
      99             :         }
     100       85666 :         return NT_STATUS_OK;
     101             : }
     102             : 
     103             : /*
     104             :   Send a message to a particular server, with the message containing a single pointer
     105             : */
     106         144 : NTSTATUS imessaging_send_ptr(struct imessaging_context *msg, struct server_id server,
     107             :                             uint32_t msg_type, void *ptr)
     108             : {
     109           0 :         DATA_BLOB blob;
     110             : 
     111         144 :         blob.data = (uint8_t *)&ptr;
     112         144 :         blob.length = sizeof(void *);
     113             : 
     114         144 :         return imessaging_send(msg, server, msg_type, &blob);
     115             : }

Generated by: LCOV version 1.14