LCOV - code coverage report
Current view: top level - source4/torture/rpc - ntsvcs.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 76 80 95.0 %
Date: 2021-09-23 10:06:22 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    test suite for rpc ntsvcs operations
       4             : 
       5             :    Copyright (C) Guenther Deschner 2008
       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, write to the Free Software
      19             :    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
      20             : */
      21             : 
      22             : #include "includes.h"
      23             : #include "torture/rpc/torture_rpc.h"
      24             : #include "librpc/gen_ndr/ndr_ntsvcs_c.h"
      25             : 
      26           4 : static bool test_PNP_GetVersion(struct torture_context *tctx,
      27             :                                 struct dcerpc_pipe *p)
      28             : {
      29           4 :         struct dcerpc_binding_handle *b = p->binding_handle;
      30             :         NTSTATUS status;
      31             :         struct PNP_GetVersion r;
      32           4 :         uint16_t version = 0;
      33             : 
      34           4 :         r.out.version = &version;
      35             : 
      36           4 :         status = dcerpc_PNP_GetVersion_r(b, tctx, &r);
      37             : 
      38           4 :         torture_assert_ntstatus_ok(tctx, status, "PNP_GetVersion");
      39           4 :         torture_assert_werr_ok(tctx, r.out.result, "PNP_GetVersion");
      40           4 :         torture_assert_int_equal(tctx, version, 0x400, "invalid version");
      41             : 
      42           4 :         return true;
      43             : }
      44             : 
      45           4 : static bool test_PNP_GetDeviceListSize(struct torture_context *tctx,
      46             :                                        struct dcerpc_pipe *p)
      47             : {
      48           4 :         struct dcerpc_binding_handle *b = p->binding_handle;
      49             :         struct PNP_GetDeviceListSize r;
      50           4 :         uint32_t size = 0;
      51             : 
      52           4 :         r.in.devicename = NULL;
      53           4 :         r.in.flags = CM_GETIDLIST_FILTER_SERVICE;
      54           4 :         r.out.size = &size;
      55             : 
      56           4 :         torture_assert_ntstatus_ok(tctx,
      57             :                 dcerpc_PNP_GetDeviceListSize_r(b, tctx, &r),
      58             :                 "PNP_GetDeviceListSize");
      59           4 :         torture_assert_werr_equal(tctx, r.out.result, WERR_CM_INVALID_POINTER,
      60             :                 "PNP_GetDeviceListSize");
      61             : 
      62           4 :         r.in.devicename = "Spooler";
      63             : 
      64           4 :         torture_assert_ntstatus_ok(tctx,
      65             :                 dcerpc_PNP_GetDeviceListSize_r(b, tctx, &r),
      66             :                 "PNP_GetDeviceListSize");
      67           4 :         torture_assert_werr_ok(tctx, r.out.result,
      68             :                 "PNP_GetDeviceListSize");
      69             : 
      70           4 :         return true;
      71             : }
      72             : 
      73           4 : static bool test_PNP_GetDeviceList(struct torture_context *tctx,
      74             :                                    struct dcerpc_pipe *p)
      75             : {
      76           4 :         struct dcerpc_binding_handle *b = p->binding_handle;
      77             :         struct PNP_GetDeviceList r;
      78           4 :         uint16_t *buffer = NULL;
      79           4 :         uint32_t length = 0;
      80             : 
      81           4 :         buffer = talloc_array(tctx, uint16_t, 0);
      82             : 
      83           4 :         r.in.filter = NULL;
      84           4 :         r.in.flags = CM_GETIDLIST_FILTER_SERVICE;
      85           4 :         r.in.length = &length;
      86           4 :         r.out.length = &length;
      87           4 :         r.out.buffer = buffer;
      88             : 
      89           4 :         torture_assert_ntstatus_ok(tctx,
      90             :                 dcerpc_PNP_GetDeviceList_r(b, tctx, &r),
      91             :                 "PNP_GetDeviceList failed");
      92           4 :         torture_assert_werr_equal(tctx, r.out.result, WERR_CM_INVALID_POINTER,
      93             :                 "PNP_GetDeviceList failed");
      94             : 
      95           4 :         r.in.filter = "Spooler";
      96             : 
      97           4 :         torture_assert_ntstatus_ok(tctx,
      98             :                 dcerpc_PNP_GetDeviceList_r(b, tctx, &r),
      99             :                 "PNP_GetDeviceList failed");
     100             : 
     101           4 :         if (W_ERROR_EQUAL(r.out.result, WERR_CM_BUFFER_SMALL)) {
     102             :                 struct PNP_GetDeviceListSize s;
     103             : 
     104           4 :                 s.in.devicename = "Spooler";
     105           4 :                 s.in.flags = CM_GETIDLIST_FILTER_SERVICE;
     106           4 :                 s.out.size = &length;
     107             : 
     108           4 :                 torture_assert_ntstatus_ok(tctx,
     109             :                         dcerpc_PNP_GetDeviceListSize_r(b, tctx, &s),
     110             :                         "PNP_GetDeviceListSize failed");
     111           4 :                 torture_assert_werr_ok(tctx, s.out.result,
     112             :                         "PNP_GetDeviceListSize failed");
     113             :         }
     114             : 
     115           4 :         buffer = talloc_array(tctx, uint16_t, length);
     116             : 
     117           4 :         r.in.length = &length;
     118           4 :         r.out.length = &length;
     119           4 :         r.out.buffer = buffer;
     120             : 
     121           4 :         torture_assert_ntstatus_ok(tctx,
     122             :                 dcerpc_PNP_GetDeviceList_r(b, tctx, &r),
     123             :                 "PNP_GetDeviceList failed");
     124             : 
     125           4 :         torture_assert_werr_ok(tctx, r.out.result,
     126             :                 "PNP_GetDeviceList failed");
     127             : 
     128           4 :         return true;
     129             : }
     130             : 
     131           4 : static bool test_PNP_GetDeviceRegProp(struct torture_context *tctx,
     132             :                                       struct dcerpc_pipe *p)
     133             : {
     134           4 :         struct dcerpc_binding_handle *b = p->binding_handle;
     135             :         NTSTATUS status;
     136             :         struct PNP_GetDeviceRegProp r;
     137             : 
     138           4 :         enum winreg_Type reg_data_type = REG_NONE;
     139           4 :         uint32_t buffer_size = 0;
     140           4 :         uint32_t needed = 0;
     141             :         uint8_t *buffer;
     142             : 
     143           4 :         buffer = talloc(tctx, uint8_t);
     144             : 
     145           4 :         r.in.devicepath = "ACPI\\ACPI0003\\1";
     146           4 :         r.in.property = DEV_REGPROP_DESC;
     147           4 :         r.in.flags = 0;
     148           4 :         r.in.reg_data_type = &reg_data_type;
     149           4 :         r.in.buffer_size = &buffer_size;
     150           4 :         r.in.needed = &needed;
     151           4 :         r.out.buffer = buffer;
     152           4 :         r.out.reg_data_type = &reg_data_type;
     153           4 :         r.out.buffer_size = &buffer_size;
     154           4 :         r.out.needed = &needed;
     155             : 
     156           4 :         status = dcerpc_PNP_GetDeviceRegProp_r(b, tctx, &r);
     157           4 :         torture_assert_ntstatus_ok(tctx, status, "PNP_GetDeviceRegProp");
     158             : 
     159           4 :         if (W_ERROR_EQUAL(r.out.result, WERR_CM_BUFFER_SMALL)) {
     160             : 
     161           0 :                 buffer = talloc_array(tctx, uint8_t, needed);
     162           0 :                 r.in.buffer_size = &needed;
     163             : 
     164           0 :                 status = dcerpc_PNP_GetDeviceRegProp_r(b, tctx, &r);
     165           0 :                 torture_assert_ntstatus_ok(tctx, status, "PNP_GetDeviceRegProp");
     166             :         }
     167             : 
     168           4 :         return true;
     169             : }
     170             : 
     171        2355 : struct torture_suite *torture_rpc_ntsvcs(TALLOC_CTX *mem_ctx)
     172             : {
     173             :         struct torture_rpc_tcase *tcase;
     174        2355 :         struct torture_suite *suite = torture_suite_create(mem_ctx, "ntsvcs");
     175             : 
     176        2355 :         tcase = torture_suite_add_rpc_iface_tcase(suite, "ntsvcs",
     177             :                                                   &ndr_table_ntsvcs);
     178             : 
     179        2355 :         torture_rpc_tcase_add_test(tcase, "PNP_GetDeviceRegProp",
     180             :                                    test_PNP_GetDeviceRegProp);
     181        2355 :         torture_rpc_tcase_add_test(tcase, "PNP_GetDeviceList",
     182             :                                    test_PNP_GetDeviceList);
     183        2355 :         torture_rpc_tcase_add_test(tcase, "PNP_GetDeviceListSize",
     184             :                                    test_PNP_GetDeviceListSize);
     185        2355 :         torture_rpc_tcase_add_test(tcase, "PNP_GetVersion",
     186             :                                    test_PNP_GetVersion);
     187             : 
     188        2355 :         return suite;
     189             : }

Generated by: LCOV version 1.13