2 Unix SMB/CIFS implementation.
3 test suite for spoolss rpc operations
5 Copyright (C) Tim Potter 2003
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 2 of the License, or
10 (at your option) any later version.
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.
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.
24 BOOL test_GetPrinter(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
25 struct policy_handle *handle)
28 struct spoolss_GetPrinter r;
29 uint16 levels[] = {1, 2, 3, 4, 5, 6, 7};
33 for (i=0;i<ARRAY_SIZE(levels);i++) {
36 r.in.level = levels[i];
38 r.in.buf_size = &buf_size;
39 r.out.buf_size = &buf_size;
41 printf("Testing GetPrinter level %u\n", r.in.level);
43 status = dcerpc_spoolss_GetPrinter(p, mem_ctx, &r);
44 if (!NT_STATUS_IS_OK(status)) {
45 printf("GetPrinter failed - %s\n", nt_errstr(status));
50 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
51 DATA_BLOB blob = data_blob_talloc(mem_ctx, NULL, buf_size);
52 data_blob_clear(&blob);
54 status = dcerpc_spoolss_GetPrinter(p, mem_ctx, &r);
57 if (!NT_STATUS_IS_OK(status) ||
58 !W_ERROR_IS_OK(r.out.result)) {
59 printf("GetPrinter failed - %s/%s\n",
60 nt_errstr(status), win_errstr(r.out.result));
70 BOOL test_ClosePrinter(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
71 struct policy_handle *handle)
74 struct spoolss_ClosePrinter r;
77 r.out.handle = handle;
79 printf("Testing ClosePrinter\n");
81 status = dcerpc_spoolss_ClosePrinter(p, mem_ctx, &r);
82 if (!NT_STATUS_IS_OK(status)) {
83 printf("ClosePrinter failed - %s\n", nt_errstr(status));
90 BOOL test_GetForm(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
91 struct policy_handle *handle, char *formname)
94 struct spoolss_GetForm r;
98 r.in.formname = formname;
102 r.in.buf_size = r.out.buf_size = &buf_size;
104 printf("Testing GetForm\n");
106 status = dcerpc_spoolss_GetForm(p, mem_ctx, &r);
108 if (!NT_STATUS_IS_OK(status)) {
109 printf("GetForm failed - %s\n", nt_errstr(status));
113 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
114 DATA_BLOB blob = data_blob_talloc(mem_ctx, NULL, buf_size);
116 data_blob_clear(&blob);
119 status = dcerpc_spoolss_GetForm(p, mem_ctx, &r);
122 printf("No form info returned");
130 BOOL test_EnumForms(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
131 struct policy_handle *handle)
134 struct spoolss_EnumForms r;
137 r.in.handle = handle;
141 r.in.buf_size = &buf_size;
142 r.out.buf_size = &buf_size;
144 printf("Testing EnumForms\n");
146 status = dcerpc_spoolss_EnumForms(p, mem_ctx, &r);
148 if (!NT_STATUS_IS_OK(status)) {
149 printf("EnumForms failed - %s\n", nt_errstr(status));
153 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
154 DATA_BLOB blob = data_blob_talloc(mem_ctx, NULL, buf_size);
155 union spoolss_FormInfo *info;
158 data_blob_clear(&blob);
161 status = dcerpc_spoolss_EnumForms(p, mem_ctx, &r);
164 printf("No forms returned");
168 status = pull_spoolss_FormInfoArray(r.out.buffer, mem_ctx, r.in.level, r.out.count, &info);
169 if (!NT_STATUS_IS_OK(status)) {
170 printf("EnumFormsArray parse failed - %s\n", nt_errstr(status));
174 for (j=0;j<r.out.count;j++) {
175 printf("Form %d\n", j);
176 NDR_PRINT_UNION_DEBUG(spoolss_FormInfo, r.in.level, &info[j]);
179 for (j = 0; j < r.out.count; j++)
180 test_GetForm(p, mem_ctx, handle, info[j].info1.name);
183 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
184 printf("EnumForms failed - %s/%s\n",
185 nt_errstr(status), win_errstr(r.out.result));
192 BOOL test_DeleteForm(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
193 struct policy_handle *handle, char *formname)
196 struct spoolss_DeleteForm r;
198 r.in.handle = handle;
199 r.in.formname = formname;
201 status = dcerpc_spoolss_DeleteForm(p, mem_ctx, &r);
203 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
204 printf("DeleteForm failed - %s/%s\n",
205 nt_errstr(status), win_errstr(r.out.result));
212 BOOL test_AddForm(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
213 struct policy_handle *handle)
215 struct spoolss_AddForm r;
216 struct spoolss_AddFormInfo1 form;
218 char *formname = "testform3";
220 r.in.handle = handle;
222 form.flags = 2; /* User form */
223 form.name = formname;
230 r.in.info.info1 = &form;
232 status = dcerpc_spoolss_AddForm(p, mem_ctx, &r);
234 if (!NT_STATUS_IS_OK(status)) {
235 printf("AddForm failed - %s\n", nt_errstr(status));
239 if (!W_ERROR_IS_OK(r.out.result)) {
240 printf("AddForm failed - %s\n", nt_errstr(status));
241 /* Fall through to delete form */
244 if (!test_DeleteForm(p, mem_ctx, handle, formname)) {
245 printf("DeleteForm failed\n");
252 BOOL test_EnumPrinterData(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
253 struct policy_handle *handle)
256 struct spoolss_EnumPrinterData r;
258 r.in.handle = handle;
264 r.in.value_offered = 0;
266 r.in.data_size = &data_size;
267 r.out.data_size = &data_size;
269 printf("Testing EnumPrinterData\n");
271 status = dcerpc_spoolss_EnumPrinterData(p, mem_ctx, &r);
273 if (!NT_STATUS_IS_OK(status)) {
274 printf("EnumPrinterData failed - %s\n", nt_errstr(status));
278 r.in.value_offered = r.out.value_needed;
280 status = dcerpc_spoolss_EnumPrinterData(p, mem_ctx, &r);
282 if (!NT_STATUS_IS_OK(status)) {
283 printf("EnumPrinterData failed - %s\n", nt_errstr(status));
288 } while (!W_ERROR_IS_OK(r.out.result));
293 static BOOL test_OpenPrinter(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
297 struct spoolss_OpenPrinter r;
298 struct policy_handle handle;
302 blob = data_blob(NULL, 0);
304 r.in.server = talloc_asprintf(mem_ctx, "\\\\%s\\%s", dcerpc_server_name(p), name);
307 r.in.access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED;
308 r.out.handle = &handle;
310 printf("\nTesting OpenPrinter(\\\\%s)\n", r.in.server);
312 status = dcerpc_spoolss_OpenPrinter(p, mem_ctx, &r);
313 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
314 printf("OpenPrinter failed - %s/%s\n",
315 nt_errstr(status), win_errstr(r.out.result));
316 /* don't consider failing this an error until we understand it */
321 if (!test_GetPrinter(p, mem_ctx, &handle)) {
325 if (!test_ClosePrinter(p, mem_ctx, &handle)) {
332 static BOOL test_OpenPrinterEx(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
335 struct policy_handle handle;
336 struct spoolss_OpenPrinterEx r;
337 struct spoolss_UserLevel1 userlevel1;
341 r.in.printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
342 dcerpc_server_name(p), name);
343 r.in.datatype = NULL;
344 r.in.devmode_ctr.size = 0;
345 r.in.devmode_ctr.devmode = NULL;
346 r.in.access_required = 0x02000000;
348 r.out.handle = &handle;
350 userlevel1.size = 1234;
351 userlevel1.client = "hello";
352 userlevel1.user = "spottyfoot!";
353 userlevel1.build = 1;
354 userlevel1.major = 2;
355 userlevel1.minor = 3;
356 userlevel1.processor = 4;
357 r.in.userlevel.level1 = &userlevel1;
359 printf("Testing OpenPrinterEx(%s)\n", r.in.printername);
361 status = dcerpc_spoolss_OpenPrinterEx(p, mem_ctx, &r);
363 if (!NT_STATUS_IS_OK(status)) {
364 printf("OpenPrinterEx failed - %s\n", nt_errstr(status));
368 if (!W_ERROR_IS_OK(r.out.result)) {
369 printf("OpenPrinterEx failed - %s\n", win_errstr(r.out.result));
373 if (!test_GetPrinter(p, mem_ctx, &handle)) {
377 if (!test_EnumForms(p, mem_ctx, &handle)) {
381 if (!test_AddForm(p, mem_ctx, &handle)) {
385 if (!test_EnumPrinterData(p, mem_ctx, &handle)) {
389 if (!test_ClosePrinter(p, mem_ctx, &handle)) {
397 static BOOL test_EnumPrinters(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
399 struct spoolss_EnumPrinters r;
401 uint16 levels[] = {1, 2, 4, 5};
405 for (i=0;i<ARRAY_SIZE(levels);i++) {
407 union spoolss_PrinterInfo *info;
412 r.in.level = levels[i];
414 r.in.buf_size = &buf_size;
415 r.out.buf_size = &buf_size;
417 printf("\nTesting EnumPrinters level %u\n", r.in.level);
419 status = dcerpc_spoolss_EnumPrinters(p, mem_ctx, &r);
420 if (!NT_STATUS_IS_OK(status)) {
421 printf("EnumPrinters failed - %s\n", nt_errstr(status));
426 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
427 DATA_BLOB blob = data_blob_talloc(mem_ctx, NULL, buf_size);
428 data_blob_clear(&blob);
430 status = dcerpc_spoolss_EnumPrinters(p, mem_ctx, &r);
433 if (!NT_STATUS_IS_OK(status) ||
434 !W_ERROR_IS_OK(r.out.result)) {
435 printf("EnumPrinters failed - %s/%s\n",
436 nt_errstr(status), win_errstr(r.out.result));
441 printf("No printers returned");
445 status = pull_spoolss_PrinterInfoArray(r.out.buffer, mem_ctx, r.in.level, r.out.count, &info);
446 if (!NT_STATUS_IS_OK(status)) {
447 printf("EnumPrintersArray parse failed - %s\n", nt_errstr(status));
451 for (j=0;j<r.out.count;j++) {
452 printf("Printer %d\n", j);
453 NDR_PRINT_UNION_DEBUG(spoolss_PrinterInfo, r.in.level, &info[j]);
456 for (j=0;j<r.out.count;j++) {
457 if (r.in.level == 1) {
458 /* the names appear to be comma-separated name lists? */
459 char *name = talloc_strdup(mem_ctx, info[j].info1.name);
460 char *comma = strchr(name, ',');
461 if (comma) *comma = 0;
462 if (!test_OpenPrinter(p, mem_ctx, name)) {
465 if (!test_OpenPrinterEx(p, mem_ctx, name)) {
475 BOOL torture_rpc_spoolss(int dummy)
478 struct dcerpc_pipe *p;
482 mem_ctx = talloc_init("torture_rpc_spoolss");
484 status = torture_rpc_connection(&p,
487 DCERPC_SPOOLSS_VERSION);
488 if (!NT_STATUS_IS_OK(status)) {
492 p->flags |= DCERPC_DEBUG_PRINT_BOTH;
494 if (!test_EnumPrinters(p, mem_ctx)) {
498 talloc_destroy(mem_ctx);
500 torture_rpc_close(p);