Debian Codegraph @

source4/torture/rpc/iremotewinspool_common.c

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