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"
11 void init_winreg_String(struct winreg_String *name, const char *s)
15 name->name_len = 2 * (strlen_m(s) + 1);
16 name->name_size = name->name_len;
23 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,
30 struct spoolss_UserLevel1 level1;
33 level1.client = talloc_asprintf(tctx, "\\\\%s", machine);
35 level1.processor = PROCESSOR_ARCHITECTURE_AMD64;
36 level1.major = major_number;
37 level1.minor = minor_number;
39 if (os == WIN_SERVER_2016 || os == WIN_10) {
41 } else if (os == WIN_SERVER_2012 || os == WIN_8) {
43 } else if (os == WIN_SERVER_2008R2 || os == WIN_7) {
45 } else if (os == WIN_SERVER_2008 || os == WIN_VISTA) {
47 } else if (os == WIN_2000) {
54 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)
61 struct dcerpc_binding_handle *b = p->binding_handle;
62 struct spoolss_DevmodeContainer devmode_ctr;
63 struct spoolss_UserLevelCtr client_info_ctr;
64 uint32_t access_mask = SERVER_ALL_ACCESS;
65 struct winspool_AsyncOpenPrinter r;
69 ZERO_STRUCT(devmode_ctr);
71 client_info_ctr.level = 1;
72 client_info_ctr.user_info.level1 = &cinfo;
74 r.in.pPrinterName = printer_name;
75 r.in.pDatatype = NULL;
76 r.in.pDevModeContainer = &devmode_ctr;
77 r.in.AccessRequired = access_mask;
78 r.in.pClientInfo = &client_info_ctr;
79 r.out.pHandle = handle;
81 status = dcerpc_winspool_AsyncOpenPrinter_r(b, tctx, &r);
82 torture_assert_ntstatus_ok_goto(tctx, status, ok, done, "AsyncOpenPrinter failed");
84 torture_assert_werr_ok(tctx, r.out.result,
85 "AsyncOpenPrinter failed");
92 bool test_get_environment(struct torture_context *tctx,
93 struct dcerpc_binding_handle *b,
94 struct policy_handle *handle,
95 const char **architecture)
98 enum winreg_Type type;
103 ok = test_AsyncGetPrinterData_args(tctx, b, handle, "Architecture", &type, &data, &needed);
104 torture_assert(tctx, ok, "failed to get Architecture");
106 torture_assert_int_equal(tctx, type, REG_SZ, "unexpected type");
108 blob = data_blob_const(data, needed);
111 pull_reg_sz(tctx, &blob, architecture),
112 "failed to pull environment");
117 bool test_AsyncClosePrinter_byhandle(struct torture_context *tctx,
118 struct test_iremotewinspool_context *ctx,
119 struct dcerpc_pipe *p,
120 struct policy_handle *handle)
122 struct dcerpc_binding_handle *b = p->binding_handle;
124 struct winspool_AsyncClosePrinter r;
128 r.in.phPrinter = handle;
129 r.out.phPrinter = handle;
131 status = dcerpc_winspool_AsyncClosePrinter_r(b, tctx, &r);
132 torture_assert_ntstatus_ok_goto(tctx, status, ok, done, "AsyncClosePrinter failed");
134 torture_assert_werr_ok(tctx, r.out.result,
135 "AsyncClosePrinter failed");
142 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,
151 struct winspool_AsyncGetPrinterData r;
152 enum winreg_Type type;
157 r.in.hPrinter = *handle;
158 r.in.pValueName = value_name;
161 r.out.pData = talloc_zero_array(tctx, uint8_t, r.in.nSize);
162 r.out.pcbNeeded = &needed;
164 torture_comment(tctx, "Testing AsyncGetPrinterData(%s)\n",
167 status = dcerpc_winspool_AsyncGetPrinterData_r(b, tctx, &r);
168 torture_assert_ntstatus_ok_goto(tctx, status, ok, done, "AsyncGetPrinterData failed");
170 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
172 torture_assert_int_equal(tctx, type, *expected_type, "unexpected type");
175 r.out.pData = talloc_zero_array(tctx, uint8_t, r.in.nSize);
177 status = dcerpc_winspool_AsyncGetPrinterData_r(b, tctx, &r);
178 torture_assert_ntstatus_ok_goto(tctx, status, ok, done, "AsyncGetPrinterData failed");
181 torture_assert_werr_ok(tctx, r.out.result,
182 "AsyncGetPrinterData failed");
189 *data_p = r.out.pData;
201 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,
209 return test_AsyncGetPrinterData_checktype(tctx, b, handle,
212 type_p, data_p, needed_p);
215 /* Parse a driver inf file */
216 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)
223 struct spoolss_AddDriverInfo8 *drv_info;
224 const char *source_disk_name = NULL;
228 drv_info = talloc_zero(tctx, struct spoolss_AddDriverInfo8);
229 torture_assert_not_null_goto(tctx, drv_info, ok, done, "Cannot allocate memory");
231 status = driver_inf_parse(tctx,
239 if (NT_STATUS_EQUAL(status, NT_STATUS_DRIVER_INTERNAL_ERROR)) {
240 torture_comment(tctx, "--- Verify the correct torture option:driver_name is provided\n");
242 torture_assert_ntstatus_ok_goto(tctx, status, ok, done, "Failed to parse driver inf\n");
244 *_parsed_dinfo = drv_info;