LCOV - code coverage report
Current view: top level - source4/torture/libnet - domain.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 28 44 63.6 %
Date: 2024-04-21 15:09:00 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    Test suite for libnet calls.
       4             : 
       5             :    Copyright (C) Rafal Szczesniak 2005
       6             : 
       7             :    This program is free software; you can redistribute it and/or modify
       8             :    it under the terms of the GNU General Public License as published by
       9             :    the Free Software Foundation; either version 3 of the License, or
      10             :    (at your option) any later version.
      11             : 
      12             :    This program is distributed in the hope that it will be useful,
      13             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             :    GNU General Public License for more details.
      16             : 
      17             :    You should have received a copy of the GNU General Public License
      18             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      19             : */
      20             : 
      21             : #include "includes.h"
      22             : #include "torture/rpc/torture_rpc.h"
      23             : #include "libnet/libnet.h"
      24             : #include "librpc/gen_ndr/ndr_samr_c.h"
      25             : #include "param/param.h"
      26             : #include "torture/libnet/proto.h"
      27             : 
      28           1 : static bool test_domainopen(struct torture_context *tctx,
      29             :                             struct libnet_context *net_ctx, TALLOC_CTX *mem_ctx,
      30             :                             struct lsa_String *domname,
      31             :                             struct policy_handle *domain_handle)
      32             : {
      33           0 :         NTSTATUS status;
      34           0 :         struct libnet_DomainOpen io;
      35             : 
      36           1 :         ZERO_STRUCT(io);
      37             : 
      38           1 :         torture_comment(tctx, "opening domain\n");
      39             : 
      40           1 :         io.in.domain_name  = talloc_strdup(mem_ctx, domname->string);
      41           1 :         io.in.access_mask  = SEC_FLAG_MAXIMUM_ALLOWED;
      42             : 
      43           1 :         status = libnet_DomainOpen(net_ctx, mem_ctx, &io);
      44           1 :         if (!NT_STATUS_IS_OK(status)) {
      45           0 :                 torture_comment(tctx, "Composite domain open failed for domain '%s' - %s\n",
      46             :                                 domname->string, nt_errstr(status));
      47           0 :                 return false;
      48             :         }
      49             : 
      50           1 :         *domain_handle = io.out.domain_handle;
      51           1 :         return true;
      52             : }
      53             : 
      54             : 
      55           1 : static bool test_cleanup(struct torture_context *tctx,
      56             :                          struct dcerpc_binding_handle *b, TALLOC_CTX *mem_ctx,
      57             :                          struct policy_handle *domain_handle)
      58             : {
      59           0 :         struct samr_Close r;
      60           0 :         struct policy_handle handle;
      61             : 
      62           1 :         r.in.handle   = domain_handle;
      63           1 :         r.out.handle  = &handle;
      64             : 
      65           1 :         torture_comment(tctx, "closing domain handle\n");
      66             : 
      67           1 :         torture_assert_ntstatus_ok(tctx,
      68             :                 dcerpc_samr_Close_r(b, mem_ctx, &r),
      69             :                 "Close failed");
      70           1 :         torture_assert_ntstatus_ok(tctx, r.out.result,
      71             :                 "Close failed");
      72             : 
      73           1 :         return true;
      74             : }
      75             : 
      76             : 
      77           1 : bool torture_domainopen(struct torture_context *torture)
      78             : {
      79           0 :         NTSTATUS status;
      80           0 :         struct libnet_context *net_ctx;
      81           0 :         TALLOC_CTX *mem_ctx;
      82           1 :         bool ret = true;
      83           0 :         struct policy_handle h;
      84           0 :         struct lsa_String name;
      85             : 
      86           1 :         mem_ctx = talloc_init("test_domain_open");
      87             : 
      88           1 :         net_ctx = libnet_context_init(torture->ev, torture->lp_ctx);
      89             : 
      90           1 :         status = torture_rpc_connection(torture,
      91             :                                         &net_ctx->samr.pipe,
      92             :                                         &ndr_table_samr);
      93             : 
      94           1 :         if (!NT_STATUS_IS_OK(status)) {
      95           0 :                 return false;
      96             :         }
      97             : 
      98           1 :         name.string = lpcfg_workgroup(torture->lp_ctx);
      99             : 
     100             :         /*
     101             :          * Testing synchronous version
     102             :          */
     103           1 :         if (!test_domainopen(torture, net_ctx, mem_ctx, &name, &h)) {
     104           0 :                 ret = false;
     105           0 :                 goto done;
     106             :         }
     107             : 
     108           1 :         if (!test_cleanup(torture, net_ctx->samr.pipe->binding_handle, mem_ctx, &h)) {
     109           0 :                 ret = false;
     110           0 :                 goto done;
     111             :         }
     112             : 
     113           1 : done:
     114           1 :         talloc_free(mem_ctx);
     115             : 
     116           1 :         return ret;
     117             : }

Generated by: LCOV version 1.14