LCOV - code coverage report
Current view: top level - source4/lib/messaging - messaging_handlers.c (source / functions) Hit Total Coverage
Test: coverage report for master 469b22b8 Lines: 14 37 37.8 %
Date: 2024-06-10 12:05:21 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    Handers for non core Samba internal messages
       5             : 
       6             :    Handlers for messages that are only included in developer and self test
       7             :    builds.
       8             : 
       9             :    Copyright (C) Andrew Bartlett <abartlet@samba.org> 2018
      10             : 
      11             :    This program is free software; you can redistribute it and/or modify
      12             :    it under the terms of the GNU General Public License as published by
      13             :    the Free Software Foundation; either version 3 of the License, or
      14             :    (at your option) any later version.
      15             : 
      16             :    This program is distributed in the hope that it will be useful,
      17             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      18             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19             :    GNU General Public License for more details.
      20             : 
      21             :    You should have received a copy of the GNU General Public License
      22             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      23             : */
      24             : 
      25             : #include "includes.h"
      26             : #include "lib/util/server_id.h"
      27             : #include "messaging/messaging.h"
      28             : #include "messaging/messaging_internal.h"
      29             : 
      30             : #if defined(DEVELOPER) || defined(ENABLE_SELFTEST)
      31             : 
      32             : /*
      33             :  * Inject a fault into the currently running process
      34             :  */
      35           0 : static void do_inject_fault(struct imessaging_context *msg,
      36             :                             void *private_data,
      37             :                             uint32_t msg_type,
      38             :                             struct server_id src,
      39             :                             size_t num_fds,
      40             :                             int *fds,
      41             :                             DATA_BLOB *data)
      42             : {
      43           0 :         int sig;
      44           0 :         struct server_id_buf tmp;
      45             : 
      46           0 :         if (num_fds != 0) {
      47           0 :                 DBG_WARNING("Received %zu fds, ignoring message\n", num_fds);
      48           0 :                 return;
      49             :         }
      50             : 
      51           0 :         if (data->length != sizeof(sig)) {
      52           0 :                 DBG_ERR("Process %s sent bogus signal injection request\n",
      53             :                         server_id_str_buf(src, &tmp));
      54           0 :                 return;
      55             :         }
      56             : 
      57           0 :         sig = *(int *)data->data;
      58           0 :         if (sig == -1) {
      59           0 :                 DBG_ERR("Process %s requested an iternal failure, "
      60             :                         "calling exit(1)\n",
      61             :                         server_id_str_buf(src, &tmp));
      62           0 :                 exit(1);
      63             :         }
      64             : 
      65             : #if HAVE_STRSIGNAL
      66           0 :         DBG_ERR("Process %s requested injection of signal %d (%s)\n",
      67             :                 server_id_str_buf(src, &tmp),
      68             :                 sig,
      69             :                 strsignal(sig));
      70             : #else
      71             :         DBG_ERR("Process %s requested injection of signal %d\n",
      72             :                 server_id_str_buf(src, &tmp),
      73             :                 sig);
      74             : #endif
      75             : 
      76           0 :         kill(getpid(), sig);
      77             : }
      78             : 
      79             : /*
      80             :  * Cause the current process to sleep for a specified number of seconds
      81             :  */
      82           2 : static void do_sleep(struct imessaging_context *msg,
      83             :                      void *private_data,
      84             :                      uint32_t msg_type,
      85             :                      struct server_id src,
      86             :                      size_t num_fds,
      87             :                      int *fds,
      88             :                      DATA_BLOB *data)
      89             : {
      90           0 :         unsigned int seconds;
      91           0 :         struct server_id_buf tmp;
      92             : 
      93           2 :         if (num_fds != 0) {
      94           0 :                 DBG_WARNING("Received %zu fds, ignoring message\n", num_fds);
      95           0 :                 return;
      96             :         }
      97             : 
      98           2 :         if (data->length != sizeof(seconds)) {
      99           0 :                 DBG_ERR("Process %s sent bogus sleep request\n",
     100             :                         server_id_str_buf(src, &tmp));
     101           0 :                 return;
     102             :         }
     103             : 
     104           2 :         seconds = *(unsigned int *)data->data;
     105           2 :         DBG_ERR("Process %s requested a sleep of %u seconds\n",
     106             :                 server_id_str_buf(src, &tmp),
     107             :                 seconds);
     108           2 :         sleep(seconds);
     109           2 :         DBG_ERR("Restarting after %u second sleep requested by process %s\n",
     110             :                 seconds,
     111             :                 server_id_str_buf(src, &tmp));
     112             : }
     113             : 
     114             : /*
     115             :  * Register the extra messaging handlers
     116             :  */
     117      413078 : NTSTATUS imessaging_register_extra_handlers(struct imessaging_context *msg)
     118             : {
     119       17235 :         NTSTATUS status;
     120             : 
     121      413078 :         status = imessaging_register(
     122             :             msg, NULL, MSG_SMB_INJECT_FAULT, do_inject_fault);
     123      413078 :         if (!NT_STATUS_IS_OK(status)) {
     124           0 :                 return status;
     125             :         }
     126             : 
     127      413078 :         status = imessaging_register(msg, NULL, MSG_SMB_SLEEP, do_sleep);
     128      413078 :         if (!NT_STATUS_IS_OK(status)) {
     129           0 :                 return status;
     130             :         }
     131             : 
     132      413078 :         return NT_STATUS_OK;
     133             : }
     134             : 
     135             : #endif /* defined(DEVELOPER) || defined(ENABLE_SELFTEST) */

Generated by: LCOV version 1.14