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

          Line data    Source code
       1             : #include "includes.h"
       2             : #include "torture/torture.h"
       3             : #include "librpc/gen_ndr/ndr_winspool.h"
       4             : #include "librpc/gen_ndr/ndr_winspool_c.h"
       5             : #include "librpc/gen_ndr/ndr_spoolss_c.h"
       6             : #include "torture/rpc/torture_rpc.h"
       7             : #include "libcli/registry/util_reg.h"
       8             : #include "torture/rpc/iremotewinspool_common.h"
       9             : #include "lib/printer_driver/printer_driver.h"
      10             : 
      11           0 : void init_winreg_String(struct winreg_String *name, const char *s)
      12             : {
      13           0 :         name->name = s;
      14           0 :         if (s != NULL) {
      15           0 :                 name->name_len = 2 * (strlen_m(s) + 1);
      16           0 :                 name->name_size = name->name_len;
      17             :         } else {
      18           0 :                 name->name_len = 0;
      19           0 :                 name->name_size = 0;
      20             :         }
      21           0 : }
      22             : 
      23           0 : struct spoolss_UserLevel1 test_get_client_info(struct torture_context *tctx,
      24             :                                                       enum client_os_version os,
      25             :                                                       enum spoolss_MajorVersion major_number,
      26             :                                                       enum spoolss_MinorVersion minor_number,
      27             :                                                       const char *machine,
      28             :                                                       const char *user)
      29             : {
      30             :         struct spoolss_UserLevel1 level1;
      31             : 
      32           0 :         level1.size     = 28;
      33           0 :         level1.client   = talloc_asprintf(tctx, "\\\\%s", machine);
      34           0 :         level1.user     = user;
      35           0 :         level1.processor = PROCESSOR_ARCHITECTURE_AMD64;
      36           0 :         level1.major    = major_number;
      37           0 :         level1.minor    = minor_number;
      38             : 
      39           0 :         if (os == WIN_SERVER_2016 || os == WIN_10) {
      40           0 :                 level1.build = 10586;
      41           0 :         } else if (os == WIN_SERVER_2012 || os == WIN_8) {
      42           0 :                 level1.build = 9200;
      43           0 :         } else if (os == WIN_SERVER_2008R2 || os == WIN_7) {
      44           0 :                 level1.build = 7007;
      45           0 :         } else if (os == WIN_SERVER_2008 || os == WIN_VISTA) {
      46           0 :                 level1.build = 6000;
      47           0 :         } else if (os == WIN_2000) {
      48           0 :                 level1.build = 1382;
      49             :         }
      50             : 
      51           0 :         return level1;
      52             : }
      53             : 
      54           0 : bool test_AsyncOpenPrinter_byprinter(struct torture_context *tctx,
      55             :                                             struct test_iremotewinspool_context *ctx,
      56             :                                             struct dcerpc_pipe *p,
      57             :                                             const char *printer_name,
      58             :                                             struct spoolss_UserLevel1 cinfo,
      59             :                                             struct policy_handle *handle)
      60             : {
      61           0 :         struct dcerpc_binding_handle *b = p->binding_handle;
      62             :         struct spoolss_DevmodeContainer devmode_ctr;
      63             :         struct spoolss_UserLevelCtr client_info_ctr;
      64           0 :         uint32_t access_mask = SERVER_ALL_ACCESS;
      65             :         struct winspool_AsyncOpenPrinter r;
      66             :         NTSTATUS status;
      67           0 :         bool ok = true;
      68             : 
      69           0 :         ZERO_STRUCT(devmode_ctr);
      70             : 
      71           0 :         client_info_ctr.level = 1;
      72           0 :         client_info_ctr.user_info.level1 = &cinfo;
      73             : 
      74           0 :         r.in.pPrinterName       = printer_name;
      75           0 :         r.in.pDatatype          = NULL;
      76           0 :         r.in.pDevModeContainer  = &devmode_ctr;
      77           0 :         r.in.AccessRequired     = access_mask;
      78           0 :         r.in.pClientInfo        = &client_info_ctr;
      79           0 :         r.out.pHandle           = handle;
      80             : 
      81           0 :         status = dcerpc_winspool_AsyncOpenPrinter_r(b, tctx, &r);
      82           0 :         torture_assert_ntstatus_ok_goto(tctx, status, ok, done, "AsyncOpenPrinter failed");
      83             : 
      84           0 :         torture_assert_werr_ok(tctx, r.out.result,
      85             :                 "AsyncOpenPrinter failed");
      86             : 
      87           0 : done:
      88             : 
      89           0 :         return ok;
      90             : }
      91             : 
      92           0 : bool test_get_environment(struct torture_context *tctx,
      93             :                                  struct dcerpc_binding_handle *b,
      94             :                                  struct policy_handle *handle,
      95             :                                  const char **architecture)
      96             : {
      97             :         DATA_BLOB blob;
      98             :         enum winreg_Type type;
      99             :         uint8_t *data;
     100             :         uint32_t needed;
     101             :         bool ok;
     102             : 
     103           0 :         ok = test_AsyncGetPrinterData_args(tctx, b, handle, "Architecture", &type, &data, &needed);
     104           0 :         torture_assert(tctx, ok, "failed to get Architecture");
     105             : 
     106           0 :         torture_assert_int_equal(tctx, type, REG_SZ, "unexpected type");
     107             : 
     108           0 :         blob = data_blob_const(data, needed);
     109             : 
     110           0 :         torture_assert(tctx,
     111             :                 pull_reg_sz(tctx, &blob, architecture),
     112             :                 "failed to pull environment");
     113             : 
     114           0 :         return true;
     115             : }
     116             : 
     117           0 : bool test_AsyncClosePrinter_byhandle(struct torture_context *tctx,
     118             :                                             struct test_iremotewinspool_context *ctx,
     119             :                                             struct dcerpc_pipe *p,
     120             :                                             struct policy_handle *handle)
     121             : {
     122           0 :         struct dcerpc_binding_handle *b = p->binding_handle;
     123             : 
     124             :         struct winspool_AsyncClosePrinter r;
     125             :         NTSTATUS status;
     126           0 :         bool ok = true;
     127             : 
     128           0 :         r.in.phPrinter = handle;
     129           0 :         r.out.phPrinter = handle;
     130             : 
     131           0 :         status = dcerpc_winspool_AsyncClosePrinter_r(b, tctx, &r);
     132           0 :         torture_assert_ntstatus_ok_goto(tctx, status, ok, done, "AsyncClosePrinter failed");
     133             : 
     134           0 :         torture_assert_werr_ok(tctx, r.out.result,
     135             :                 "AsyncClosePrinter failed");
     136             : 
     137           0 : done:
     138             : 
     139           0 :         return ok;
     140             : }
     141             : 
     142           0 : static bool test_AsyncGetPrinterData_checktype(struct torture_context *tctx,
     143             :                                                struct dcerpc_binding_handle *b,
     144             :                                                struct policy_handle *handle,
     145             :                                                const char *value_name,
     146             :                                                enum winreg_Type *expected_type,
     147             :                                                enum winreg_Type *type_p,
     148             :                                                uint8_t **data_p,
     149             :                                                uint32_t *needed_p)
     150             : {
     151             :         struct winspool_AsyncGetPrinterData r;
     152             :         enum winreg_Type type;
     153             :         uint32_t needed;
     154             :         NTSTATUS status;
     155           0 :         bool ok = true;
     156             : 
     157           0 :         r.in.hPrinter = *handle;
     158           0 :         r.in.pValueName = value_name;
     159           0 :         r.in.nSize = 0;
     160           0 :         r.out.pType = &type;
     161           0 :         r.out.pData = talloc_zero_array(tctx, uint8_t, r.in.nSize);
     162           0 :         r.out.pcbNeeded = &needed;
     163             : 
     164           0 :         torture_comment(tctx, "Testing AsyncGetPrinterData(%s)\n",
     165             :                 r.in.pValueName);
     166             : 
     167           0 :         status = dcerpc_winspool_AsyncGetPrinterData_r(b, tctx, &r);
     168           0 :         torture_assert_ntstatus_ok_goto(tctx, status, ok, done, "AsyncGetPrinterData failed");
     169             : 
     170           0 :         if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
     171           0 :                 if (expected_type) {
     172           0 :                         torture_assert_int_equal(tctx, type, *expected_type, "unexpected type");
     173             :                 }
     174           0 :                 r.in.nSize = needed;
     175           0 :                 r.out.pData = talloc_zero_array(tctx, uint8_t, r.in.nSize);
     176             : 
     177           0 :                 status = dcerpc_winspool_AsyncGetPrinterData_r(b, tctx, &r);
     178           0 :                 torture_assert_ntstatus_ok_goto(tctx, status, ok, done, "AsyncGetPrinterData failed");
     179             :         }
     180             : 
     181           0 :         torture_assert_werr_ok(tctx, r.out.result,
     182             :                 "AsyncGetPrinterData failed");
     183             : 
     184           0 :         if (type_p) {
     185           0 :                 *type_p = type;
     186             :         }
     187             : 
     188           0 :         if (data_p) {
     189           0 :                 *data_p = r.out.pData;
     190             :         }
     191             : 
     192           0 :         if (needed_p) {
     193           0 :                 *needed_p = needed;
     194             :         }
     195             : 
     196           0 : done:
     197             : 
     198           0 :         return ok;
     199             : }
     200             : 
     201           0 : bool test_AsyncGetPrinterData_args(struct torture_context *tctx,
     202             :                                           struct dcerpc_binding_handle *b,
     203             :                                           struct policy_handle *handle,
     204             :                                           const char *value_name,
     205             :                                           enum winreg_Type *type_p,
     206             :                                           uint8_t **data_p,
     207             :                                           uint32_t *needed_p)
     208             : {
     209           0 :         return test_AsyncGetPrinterData_checktype(tctx, b, handle,
     210             :                                                   value_name,
     211             :                                                   NULL,
     212             :                                                   type_p, data_p, needed_p);
     213             : }
     214             : 
     215             : /* Parse a driver inf file */
     216           0 : bool parse_inf_driver(struct torture_context *tctx,
     217             :                       const char *driver_name,
     218             :                       const char *abs_inf_path,
     219             :                       const char *driver_arch,
     220             :                       const char *core_driver_inf,
     221             :                       struct spoolss_AddDriverInfo8 **_parsed_dinfo)
     222             : {
     223             :         struct spoolss_AddDriverInfo8 *drv_info;
     224           0 :         const char *source_disk_name = NULL;
     225             :         NTSTATUS status;
     226           0 :         bool ok = true;
     227             : 
     228           0 :         drv_info = talloc_zero(tctx, struct spoolss_AddDriverInfo8);
     229           0 :         torture_assert_not_null_goto(tctx, drv_info, ok, done, "Cannot allocate memory");
     230             : 
     231           0 :         status = driver_inf_parse(tctx,
     232             :                                   core_driver_inf,
     233             :                                   abs_inf_path,
     234             :                                   driver_arch,
     235             :                                   driver_name,
     236             :                                   drv_info,
     237             :                                   &source_disk_name);
     238             : 
     239           0 :         if (NT_STATUS_EQUAL(status, NT_STATUS_DRIVER_INTERNAL_ERROR)) {
     240           0 :                 torture_comment(tctx, "--- Verify the correct torture option:driver_name is provided\n");
     241             :         }
     242           0 :         torture_assert_ntstatus_ok_goto(tctx, status, ok, done, "Failed to parse driver inf\n");
     243             : 
     244           0 :         *_parsed_dinfo = drv_info;
     245           0 : done:
     246           0 :         return ok;
     247             : }

Generated by: LCOV version 1.13