LCOV - code coverage report
Current view: top level - source4/torture/rpc - alter_context.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 41 51 80.4 %
Date: 2021-09-23 10:06:22 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    test suite for dcerpc alter_context operations
       5             : 
       6             :    Copyright (C) Andrew Tridgell 2005
       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 "librpc/gen_ndr/ndr_lsa.h"
      24             : #include "librpc/gen_ndr/ndr_dssetup.h"
      25             : #include "torture/rpc/torture_rpc.h"
      26             : 
      27          15 : bool torture_rpc_alter_context(struct torture_context *torture)
      28             : {
      29             :         NTSTATUS status;
      30             :         struct dcerpc_pipe *p, *p2, *p3;
      31             :         struct policy_handle *handle;
      32             :         struct ndr_interface_table tmptbl;
      33          15 :         bool ret = true;
      34             : 
      35          15 :         torture_comment(torture, "opening LSA connection\n");
      36          15 :         status = torture_rpc_connection(torture, &p, &ndr_table_lsarpc);
      37          15 :         torture_assert_ntstatus_ok(torture, status, "connecting");
      38             : 
      39          15 :         torture_comment(torture, "Testing change of primary context\n");
      40          15 :         status = dcerpc_alter_context(p, torture, &p->syntax, &p->transfer_syntax);
      41          15 :         torture_assert_ntstatus_ok(torture, status, "dcerpc_alter_context failed");
      42             : 
      43          15 :         if (!test_lsa_OpenPolicy2(p->binding_handle, torture, &handle)) {
      44           0 :                 ret = false;
      45             :         }
      46             : 
      47          15 :         torture_comment(torture, "Testing change of primary context\n");
      48          15 :         status = dcerpc_alter_context(p, torture, &p->syntax, &p->transfer_syntax);
      49          15 :         torture_assert_ntstatus_ok(torture, status, "dcerpc_alter_context failed");
      50             : 
      51          15 :         torture_comment(torture, "Opening secondary DSSETUP context\n");
      52          15 :         status = dcerpc_secondary_context(p, &p2, &ndr_table_dssetup);
      53          15 :         torture_assert_ntstatus_ok(torture, status, "dcerpc_alter_context failed");
      54             : 
      55          15 :         torture_comment(torture, "Testing change of primary context\n");
      56          15 :         status = dcerpc_alter_context(p2, torture, &p2->syntax, &p2->transfer_syntax);
      57          15 :         torture_assert_ntstatus_ok(torture, status, "dcerpc_alter_context failed");
      58             : 
      59          15 :         tmptbl = ndr_table_dssetup;
      60          15 :         tmptbl.syntax_id.if_version += 100;
      61          15 :         torture_comment(torture, "Opening bad secondary connection\n");
      62          15 :         status = dcerpc_secondary_context(p, &p3, &tmptbl);
      63          15 :         torture_assert_ntstatus_equal(torture, status, NT_STATUS_RPC_UNSUPPORTED_NAME_SYNTAX,
      64             :                                       "dcerpc_alter_context with wrong version should fail");
      65             : 
      66          15 :         torture_comment(torture, "Testing DSSETUP pipe operations\n");
      67          15 :         ret &= test_DsRoleGetPrimaryDomainInformation(torture, p2);
      68             : 
      69          15 :         if (handle) {
      70          15 :                 ret &= test_lsa_Close(p->binding_handle, torture, handle);
      71             :         }
      72             : 
      73          15 :         torture_comment(torture, "Testing change of primary context\n");
      74          15 :         status = dcerpc_alter_context(p, torture, &p->syntax, &p->transfer_syntax);
      75          15 :         torture_assert_ntstatus_ok(torture, status, "dcerpc_alter_context failed");
      76             : 
      77          15 :         ret &= test_lsa_OpenPolicy2(p->binding_handle, torture, &handle);
      78             : 
      79          15 :         if (handle) {
      80          15 :                 ret &= test_lsa_Close(p->binding_handle, torture, handle);
      81             :         }
      82             : 
      83          15 :         torture_comment(torture, "Testing change of primary context\n");
      84          15 :         status = dcerpc_alter_context(p, torture, &p2->syntax, &p2->transfer_syntax);
      85          15 :         if (NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTOCOL_ERROR)) {
      86             : 
      87          18 :                 ret &= test_lsa_OpenPolicy2_ex(p->binding_handle, torture, &handle,
      88          15 :                                                NT_STATUS_CONNECTION_DISCONNECTED,
      89          15 :                                                NT_STATUS_CONNECTION_RESET);
      90             : 
      91          15 :                 torture_assert(torture, !dcerpc_binding_handle_is_connected(p->binding_handle),
      92             :                                "dcerpc disonnected");
      93             : 
      94          12 :                 return ret;
      95             :         }
      96           0 :         torture_assert_ntstatus_ok(torture, status, "dcerpc_alter_context failed");
      97             : 
      98           0 :         torture_comment(torture, "Testing DSSETUP pipe operations - should fault\n");
      99           0 :         ret &= test_DsRoleGetPrimaryDomainInformation_ext(torture, p, NT_STATUS_RPC_BAD_STUB_DATA);
     100             : 
     101           0 :         ret &= test_lsa_OpenPolicy2(p->binding_handle, torture, &handle);
     102             : 
     103           0 :         if (handle) {
     104           0 :                 ret &= test_lsa_Close(p->binding_handle, torture, handle);
     105             :         }
     106             : 
     107           0 :         torture_comment(torture, "Testing DSSETUP pipe operations\n");
     108             : 
     109           0 :         ret &= test_DsRoleGetPrimaryDomainInformation(torture, p2);
     110             : 
     111           0 :         return ret;
     112             : }

Generated by: LCOV version 1.13