LCOV - code coverage report
Current view: top level - source4/torture/rpc - countcalls.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 0 54 0.0 %
Date: 2021-09-23 10:06:22 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    count number of calls on an interface
       5             : 
       6             :    Copyright (C) Andrew Tridgell 2003
       7             :    Copyright (C) Andrew Bartlett <abartlet@samba.org> 2007
       8             :    
       9             :    This program is free software; you can redistribute it and/or modify
      10             :    it under the terms of the GNU General Public License as published by
      11             :    the Free Software Foundation; either version 3 of the License, or
      12             :    (at your option) any later version.
      13             :    
      14             :    This program is distributed in the hope that it will be useful,
      15             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      16             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17             :    GNU General Public License for more details.
      18             :    
      19             :    You should have received a copy of the GNU General Public License
      20             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      21             : */
      22             : 
      23             : #include "includes.h"
      24             : #include "librpc/ndr/libndr.h"
      25             : #include "librpc/ndr/ndr_table.h"
      26             : #include "torture/rpc/torture_rpc.h"
      27             : #include "param/param.h"
      28             : 
      29             : 
      30             :         
      31           0 : bool count_calls(struct torture_context *tctx,
      32             :                  TALLOC_CTX *mem_ctx,
      33             :                  const struct ndr_interface_table *iface,
      34             :         bool all) 
      35             : {
      36             :         struct dcerpc_pipe *p;
      37             :         DATA_BLOB stub_in, stub_out;
      38             :         int i;
      39           0 :         NTSTATUS status = torture_rpc_connection(tctx, &p, iface);
      40           0 :         if (NT_STATUS_EQUAL(NT_STATUS_OBJECT_NAME_NOT_FOUND, status)
      41             :             || NT_STATUS_IS_RPC(status)
      42           0 :             || NT_STATUS_EQUAL(NT_STATUS_PORT_UNREACHABLE, status)
      43           0 :             || NT_STATUS_EQUAL(NT_STATUS_ACCESS_DENIED, status)) {
      44           0 :                 if (all) {
      45             :                         /* Not fatal if looking for all pipes */
      46           0 :                         return true;
      47             :                 } else {
      48           0 :                         printf("Failed to open '%s' to count calls - %s\n", iface->name, nt_errstr(status));
      49           0 :                         return false;
      50             :                 }
      51           0 :         } else if (!NT_STATUS_IS_OK(status)) {
      52           0 :                 printf("Failed to open '%s' to count calls - %s\n", iface->name, nt_errstr(status));
      53           0 :                 return false;
      54             :         }
      55             : 
      56           0 :         stub_in = data_blob_null;
      57             : 
      58           0 :         printf("\nScanning pipe '%s'\n", iface->name);
      59             : 
      60           0 :         for (i=0;i<500;i++) {
      61           0 :                 uint32_t out_flags = 0;
      62             : 
      63           0 :                 status = dcerpc_binding_handle_raw_call(p->binding_handle,
      64             :                                                         NULL, i,
      65             :                                                         0, /* in_flags */
      66           0 :                                                         stub_in.data,
      67             :                                                         stub_in.length,
      68             :                                                         mem_ctx,
      69             :                                                         &stub_out.data,
      70             :                                                         &stub_out.length,
      71             :                                                         &out_flags);
      72           0 :                 if (NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROCNUM_OUT_OF_RANGE)) {
      73           0 :                         i--;
      74           0 :                         break;
      75             :                 }
      76           0 :                 if (NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_DISCONNECTED)) {
      77           0 :                         i--;
      78           0 :                         break;
      79             :                 }
      80           0 :                 if (NT_STATUS_EQUAL(status, NT_STATUS_PIPE_DISCONNECTED)) {
      81           0 :                         i--;
      82           0 :                         break;
      83             :                 }
      84           0 :                 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
      85           0 :                         i--;
      86           0 :                         break;
      87             :                 }
      88           0 :                 if (NT_STATUS_EQUAL(status, NT_STATUS_LOGON_FAILURE)) {
      89           0 :                         i--;
      90           0 :                         break;
      91             :                 }
      92             :         }
      93             :         
      94           0 :         if (i==500) {
      95           0 :                 talloc_free(p);
      96           0 :                 printf("no limit on calls: %s!?\n", nt_errstr(status));
      97           0 :                 return false;
      98             :         }
      99             : 
     100           0 :         printf("Found %d calls\n", i);
     101             : 
     102           0 :         talloc_free(p);
     103             :         
     104           0 :         return true;
     105             : 
     106             : }
     107             : 
     108           0 : bool torture_rpc_countcalls(struct torture_context *torture)
     109             : {
     110             :         const struct ndr_interface_table *iface;
     111             :         const char *iface_name;
     112           0 :         bool ret = true;
     113             :         const struct ndr_interface_list *l;
     114           0 :         iface_name = lpcfg_parm_string(torture->lp_ctx, NULL, "countcalls", "interface");
     115           0 :         if (iface_name != NULL) {
     116           0 :                 iface = ndr_table_by_name(iface_name);
     117           0 :                 if (!iface) {
     118           0 :                         printf("Unknown interface '%s'\n", iface_name);
     119           0 :                         return false;
     120             :                 }
     121           0 :                 return count_calls(torture, torture, iface, false);
     122             :         }
     123             : 
     124           0 :         for (l=ndr_table_list();l;l=l->next) {               
     125             :                 TALLOC_CTX *loop_ctx;
     126           0 :                 loop_ctx = talloc_named(torture, 0, "torture_rpc_councalls loop context");
     127           0 :                 ret &= count_calls(torture, loop_ctx, l->table, true);
     128           0 :                 talloc_free(loop_ctx);
     129             :         }
     130           0 :         return ret;
     131             : }

Generated by: LCOV version 1.13