2 Unix SMB/CIFS implementation.
3 test suite for spoolss rpc operations
5 Copyright (C) Tim Potter 2003
6 Copyright (C) Stefan Metzmacher 2005
7 Copyright (C) Jelmer Vernooij 2007
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "torture/torture.h"
25 #include "torture/rpc/rpc.h"
26 #include "librpc/gen_ndr/ndr_spoolss_c.h"
28 struct test_spoolss_context {
29 /* print server handle */
30 struct policy_handle server_handle;
33 uint32_t port_count[3];
34 union spoolss_PortInfo *ports[3];
36 /* for EnumPrinterDrivers */
37 uint32_t driver_count[7];
38 union spoolss_DriverInfo *drivers[7];
40 /* for EnumMonitors */
41 uint32_t monitor_count[3];
42 union spoolss_MonitorInfo *monitors[3];
44 /* for EnumPrintProcessors */
45 uint32_t print_processor_count[2];
46 union spoolss_PrintProcessorInfo *print_processors[2];
48 /* for EnumPrinters */
49 uint32_t printer_count[6];
50 union spoolss_PrinterInfo *printers[6];
53 #define COMPARE_STRING(tctx, c,r,e) \
54 torture_assert_str_equal(tctx, c.e, r.e, "invalid value")
56 /* not every compiler supports __typeof__() */
58 #define _CHECK_FIELD_SIZE(c,r,e,type) do {\
59 if (sizeof(__typeof__(c.e)) != sizeof(type)) { \
60 torture_fail(tctx, #c "." #e "field is not " #type "\n"); \
62 if (sizeof(__typeof__(r.e)) != sizeof(type)) { \
63 torture_fail(tctx, #r "." #e "field is not " #type "\n"); \
67 #define _CHECK_FIELD_SIZE(c,r,e,type) do {} while(0)
70 #define COMPARE_UINT32(tctx, c, r, e) do {\
71 _CHECK_FIELD_SIZE(c, r, e, uint32_t); \
72 torture_assert_int_equal(tctx, c.e, r.e, "invalid value"); \
75 #define COMPARE_STRING_ARRAY(tctx, c,r,e)
77 static bool test_OpenPrinter_server(struct torture_context *tctx, struct dcerpc_pipe *p, struct test_spoolss_context *ctx)
80 struct spoolss_OpenPrinter op;
82 op.in.printername = talloc_asprintf(ctx, "\\\\%s", dcerpc_server_name(p));
83 op.in.datatype = NULL;
84 op.in.devmode_ctr.devmode= NULL;
85 op.in.access_mask = 0;
86 op.out.handle = &ctx->server_handle;
88 torture_comment(tctx, "Testing OpenPrinter(%s)\n", op.in.printername);
90 status = dcerpc_spoolss_OpenPrinter(p, ctx, &op);
91 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_OpenPrinter failed");
92 torture_assert_werr_ok(tctx, op.out.result, "dcerpc_spoolss_OpenPrinter failed");
97 static bool test_EnumPorts(struct torture_context *tctx,
98 struct dcerpc_pipe *p,
99 struct test_spoolss_context *ctx)
102 struct spoolss_EnumPorts r;
103 uint16_t levels[] = { 1, 2 };
106 for (i=0;i<ARRAY_SIZE(levels);i++) {
107 int level = levels[i];
112 r.in.servername = "";
116 r.out.needed = &needed;
117 r.out.count = &count;
119 torture_comment(tctx, "Testing EnumPorts level %u\n", r.in.level);
121 status = dcerpc_spoolss_EnumPorts(p, ctx, &r);
122 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPorts failed");
123 if (W_ERROR_IS_OK(r.out.result)) {
124 /* TODO: do some more checks here */
127 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
128 "EnumPorts unexpected return code");
130 blob = data_blob_talloc(ctx, NULL, needed);
131 data_blob_clear(&blob);
133 r.in.offered = needed;
135 status = dcerpc_spoolss_EnumPorts(p, ctx, &r);
136 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPorts failed");
138 torture_assert_werr_ok(tctx, r.out.result, "EnumPorts failed");
140 ctx->port_count[level] = count;
141 ctx->ports[level] = r.out.info;
144 for (i=1;i<ARRAY_SIZE(levels);i++) {
145 int level = levels[i];
146 int old_level = levels[i-1];
147 torture_assert_int_equal(tctx, ctx->port_count[level], ctx->port_count[old_level],
148 "EnumPorts invalid value");
150 /* if the array sizes are not the same we would maybe segfault in the following code */
152 for (i=0;i<ARRAY_SIZE(levels);i++) {
153 int level = levels[i];
154 for (j=0;j<ctx->port_count[level];j++) {
155 union spoolss_PortInfo *cur = &ctx->ports[level][j];
156 union spoolss_PortInfo *ref = &ctx->ports[2][j];
159 COMPARE_STRING(tctx, cur->info1, ref->info2, port_name);
162 /* level 2 is our reference, and it makes no sense to compare it to itself */
171 static bool test_GetPrintProcessorDirectory(struct torture_context *tctx,
172 struct dcerpc_pipe *p,
173 struct test_spoolss_context *ctx)
176 struct spoolss_GetPrintProcessorDirectory r;
191 .server = talloc_asprintf(ctx, "\\\\%s", dcerpc_server_name(p))
194 .server = talloc_asprintf(ctx, "\\\\%s", dcerpc_server_name(p))
200 for (i=0;i<ARRAY_SIZE(levels);i++) {
201 int level = levels[i].level;
204 r.in.server = levels[i].server;
205 r.in.environment = SPOOLSS_ARCHITECTURE_NT_X86;
209 r.out.needed = &needed;
211 torture_comment(tctx, "Testing GetPrintProcessorDirectory level %u\n", r.in.level);
213 status = dcerpc_spoolss_GetPrintProcessorDirectory(p, ctx, &r);
214 torture_assert_ntstatus_ok(tctx, status,
215 "dcerpc_spoolss_GetPrintProcessorDirectory failed");
216 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
217 "GetPrintProcessorDirectory unexpected return code");
219 blob = data_blob_talloc(ctx, NULL, needed);
220 data_blob_clear(&blob);
222 r.in.offered = needed;
224 status = dcerpc_spoolss_GetPrintProcessorDirectory(p, ctx, &r);
225 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_GetPrintProcessorDirectory failed");
227 torture_assert_werr_ok(tctx, r.out.result, "GetPrintProcessorDirectory failed");
234 static bool test_GetPrinterDriverDirectory(struct torture_context *tctx,
235 struct dcerpc_pipe *p,
236 struct test_spoolss_context *ctx)
239 struct spoolss_GetPrinterDriverDirectory r;
254 .server = talloc_asprintf(ctx, "\\\\%s", dcerpc_server_name(p))
257 .server = talloc_asprintf(ctx, "\\\\%s", dcerpc_server_name(p))
263 for (i=0;i<ARRAY_SIZE(levels);i++) {
264 int level = levels[i].level;
267 r.in.server = levels[i].server;
268 r.in.environment = SPOOLSS_ARCHITECTURE_NT_X86;
272 r.out.needed = &needed;
274 torture_comment(tctx, "Testing GetPrinterDriverDirectory level %u\n", r.in.level);
276 status = dcerpc_spoolss_GetPrinterDriverDirectory(p, ctx, &r);
277 torture_assert_ntstatus_ok(tctx, status,
278 "dcerpc_spoolss_GetPrinterDriverDirectory failed");
279 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
280 "GetPrinterDriverDirectory unexpected return code");
282 blob = data_blob_talloc(ctx, NULL, needed);
283 data_blob_clear(&blob);
285 r.in.offered = needed;
287 status = dcerpc_spoolss_GetPrinterDriverDirectory(p, ctx, &r);
288 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_GetPrinterDriverDirectory failed");
290 torture_assert_werr_ok(tctx, r.out.result, "GetPrinterDriverDirectory failed");
296 static bool test_EnumPrinterDrivers(struct torture_context *tctx,
297 struct dcerpc_pipe *p,
298 struct test_spoolss_context *ctx)
301 struct spoolss_EnumPrinterDrivers r;
302 uint16_t levels[] = { 1, 2, 3, 4, 5, 6 };
305 for (i=0;i<ARRAY_SIZE(levels);i++) {
306 int level = levels[i];
312 r.in.environment = SPOOLSS_ARCHITECTURE_NT_X86;
316 r.out.needed = &needed;
317 r.out.count = &count;
319 torture_comment(tctx, "Testing EnumPrinterDrivers level %u\n", r.in.level);
321 status = dcerpc_spoolss_EnumPrinterDrivers(p, ctx, &r);
322 torture_assert_ntstatus_ok(tctx, status,
323 "dcerpc_spoolss_EnumPrinterDrivers failed");
324 if (W_ERROR_IS_OK(r.out.result)) {
325 /* TODO: do some more checks here */
328 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
329 "EnumPrinterDrivers failed");
331 blob = data_blob_talloc(ctx, NULL, needed);
332 data_blob_clear(&blob);
334 r.in.offered = needed;
336 status = dcerpc_spoolss_EnumPrinterDrivers(p, ctx, &r);
337 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrinterDrivers failed");
339 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinterDrivers failed");
341 ctx->driver_count[level] = count;
342 ctx->drivers[level] = r.out.info;
345 for (i=1;i<ARRAY_SIZE(levels);i++) {
346 int level = levels[i];
347 int old_level = levels[i-1];
348 torture_assert_int_equal(tctx, ctx->driver_count[level], ctx->driver_count[old_level],
349 "EnumPrinterDrivers invalid value");
352 for (i=0;i<ARRAY_SIZE(levels);i++) {
353 int level = levels[i];
354 for (j=0;j<ctx->driver_count[level];j++) {
355 union spoolss_DriverInfo *cur = &ctx->drivers[level][j];
356 union spoolss_DriverInfo *ref = &ctx->drivers[6][j];
359 COMPARE_STRING(tctx, cur->info1, ref->info6, driver_name);
362 COMPARE_UINT32(tctx, cur->info2, ref->info6, version);
363 COMPARE_STRING(tctx, cur->info2, ref->info6, driver_name);
364 COMPARE_STRING(tctx, cur->info2, ref->info6, architecture);
365 COMPARE_STRING(tctx, cur->info2, ref->info6, driver_path);
366 COMPARE_STRING(tctx, cur->info2, ref->info6, data_file);
367 COMPARE_STRING(tctx, cur->info2, ref->info6, config_file);
370 COMPARE_UINT32(tctx, cur->info3, ref->info6, version);
371 COMPARE_STRING(tctx, cur->info3, ref->info6, driver_name);
372 COMPARE_STRING(tctx, cur->info3, ref->info6, architecture);
373 COMPARE_STRING(tctx, cur->info3, ref->info6, driver_path);
374 COMPARE_STRING(tctx, cur->info3, ref->info6, data_file);
375 COMPARE_STRING(tctx, cur->info3, ref->info6, config_file);
376 COMPARE_STRING(tctx, cur->info3, ref->info6, help_file);
377 COMPARE_STRING_ARRAY(tctx, cur->info3, ref->info6, dependent_files);
378 COMPARE_STRING(tctx, cur->info3, ref->info6, monitor_name);
379 COMPARE_STRING(tctx, cur->info3, ref->info6, default_datatype);
382 COMPARE_UINT32(tctx, cur->info4, ref->info6, version);
383 COMPARE_STRING(tctx, cur->info4, ref->info6, driver_name);
384 COMPARE_STRING(tctx, cur->info4, ref->info6, architecture);
385 COMPARE_STRING(tctx, cur->info4, ref->info6, driver_path);
386 COMPARE_STRING(tctx, cur->info4, ref->info6, data_file);
387 COMPARE_STRING(tctx, cur->info4, ref->info6, config_file);
388 COMPARE_STRING(tctx, cur->info4, ref->info6, help_file);
389 COMPARE_STRING_ARRAY(tctx, cur->info4, ref->info6, dependent_files);
390 COMPARE_STRING(tctx, cur->info4, ref->info6, monitor_name);
391 COMPARE_STRING(tctx, cur->info4, ref->info6, default_datatype);
392 COMPARE_STRING_ARRAY(tctx, cur->info4, ref->info6, previous_names);
395 COMPARE_UINT32(tctx, cur->info5, ref->info6, version);
396 COMPARE_STRING(tctx, cur->info5, ref->info6, driver_name);
397 COMPARE_STRING(tctx, cur->info5, ref->info6, architecture);
398 COMPARE_STRING(tctx, cur->info5, ref->info6, driver_path);
399 COMPARE_STRING(tctx, cur->info5, ref->info6, data_file);
400 COMPARE_STRING(tctx, cur->info5, ref->info6, config_file);
401 /*COMPARE_UINT32(tctx, cur->info5, ref->info6, driver_attributes);*/
402 /*COMPARE_UINT32(tctx, cur->info5, ref->info6, config_version);*/
403 /*TODO: ! COMPARE_UINT32(tctx, cur->info5, ref->info6, driver_version); */
406 /* level 6 is our reference, and it makes no sense to compare it to itself */
415 static bool test_EnumMonitors(struct torture_context *tctx,
416 struct dcerpc_pipe *p,
417 struct test_spoolss_context *ctx)
420 struct spoolss_EnumMonitors r;
421 uint16_t levels[] = { 1, 2 };
424 for (i=0;i<ARRAY_SIZE(levels);i++) {
425 int level = levels[i];
430 r.in.servername = "";
434 r.out.needed = &needed;
435 r.out.count = &count;
437 torture_comment(tctx, "Testing EnumMonitors level %u\n", r.in.level);
439 status = dcerpc_spoolss_EnumMonitors(p, ctx, &r);
440 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumMonitors failed");
441 if (W_ERROR_IS_OK(r.out.result)) {
442 /* TODO: do some more checks here */
445 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
446 "EnumMonitors failed");
448 blob = data_blob_talloc(ctx, NULL, needed);
449 data_blob_clear(&blob);
451 r.in.offered = needed;
453 status = dcerpc_spoolss_EnumMonitors(p, ctx, &r);
454 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumMonitors failed");
456 torture_assert_werr_ok(tctx, r.out.result, "EnumMonitors failed");
458 ctx->monitor_count[level] = count;
459 ctx->monitors[level] = r.out.info;
462 for (i=1;i<ARRAY_SIZE(levels);i++) {
463 int level = levels[i];
464 int old_level = levels[i-1];
465 torture_assert_int_equal(tctx, ctx->monitor_count[level], ctx->monitor_count[old_level],
466 "EnumMonitors invalid value");
469 for (i=0;i<ARRAY_SIZE(levels);i++) {
470 int level = levels[i];
471 for (j=0;j<ctx->monitor_count[level];j++) {
472 union spoolss_MonitorInfo *cur = &ctx->monitors[level][j];
473 union spoolss_MonitorInfo *ref = &ctx->monitors[2][j];
476 COMPARE_STRING(tctx, cur->info1, ref->info2, monitor_name);
479 /* level 2 is our reference, and it makes no sense to compare it to itself */
488 static bool test_EnumPrintProcessors(struct torture_context *tctx,
489 struct dcerpc_pipe *p,
490 struct test_spoolss_context *ctx)
493 struct spoolss_EnumPrintProcessors r;
494 uint16_t levels[] = { 1 };
497 for (i=0;i<ARRAY_SIZE(levels);i++) {
498 int level = levels[i];
503 r.in.servername = "";
504 r.in.environment = "Windows NT x86";
508 r.out.needed = &needed;
509 r.out.count = &count;
511 torture_comment(tctx, "Testing EnumPrintProcessors level %u\n", r.in.level);
513 status = dcerpc_spoolss_EnumPrintProcessors(p, ctx, &r);
514 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrintProcessors failed");
515 if (W_ERROR_IS_OK(r.out.result)) {
516 /* TODO: do some more checks here */
519 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
520 "EnumPrintProcessors unexpected return code");
522 blob = data_blob_talloc(ctx, NULL, needed);
523 data_blob_clear(&blob);
525 r.in.offered = needed;
527 status = dcerpc_spoolss_EnumPrintProcessors(p, ctx, &r);
528 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrintProcessors failed");
530 torture_assert_werr_ok(tctx, r.out.result, "EnumPrintProcessors failed");
532 ctx->print_processor_count[level] = count;
533 ctx->print_processors[level] = r.out.info;
536 for (i=1;i<ARRAY_SIZE(levels);i++) {
537 int level = levels[i];
538 int old_level = levels[i-1];
539 torture_assert_int_equal(tctx, ctx->print_processor_count[level], ctx->print_processor_count[old_level],
540 "EnumPrintProcessors failed");
543 for (i=0;i<ARRAY_SIZE(levels);i++) {
544 int level = levels[i];
545 for (j=0;j<ctx->print_processor_count[level];j++) {
547 union spoolss_PrintProcessorInfo *cur = &ctx->print_processors[level][j];
548 union spoolss_PrintProcessorInfo *ref = &ctx->print_processors[1][j];
552 /* level 1 is our reference, and it makes no sense to compare it to itself */
561 static bool test_EnumPrinters(struct torture_context *tctx,
562 struct dcerpc_pipe *p,
563 struct test_spoolss_context *ctx)
565 struct spoolss_EnumPrinters r;
567 uint16_t levels[] = { 0, 1, 2, 4, 5 };
570 for (i=0;i<ARRAY_SIZE(levels);i++) {
571 int level = levels[i];
576 r.in.flags = PRINTER_ENUM_LOCAL;
581 r.out.needed = &needed;
582 r.out.count = &count;
584 torture_comment(tctx, "Testing EnumPrinters level %u\n", r.in.level);
586 status = dcerpc_spoolss_EnumPrinters(p, ctx, &r);
587 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrinters failed");
588 if (W_ERROR_IS_OK(r.out.result)) {
589 /* TODO: do some more checks here */
592 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
593 "EnumPrinters unexpected return code");
595 blob = data_blob_talloc(ctx, NULL, needed);
596 data_blob_clear(&blob);
598 r.in.offered = needed;
600 status = dcerpc_spoolss_EnumPrinters(p, ctx, &r);
601 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrinters failed");
603 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinters failed");
605 ctx->printer_count[level] = count;
606 ctx->printers[level] = r.out.info;
609 for (i=1;i<ARRAY_SIZE(levels);i++) {
610 int level = levels[i];
611 int old_level = levels[i-1];
612 torture_assert_int_equal(tctx, ctx->printer_count[level], ctx->printer_count[old_level],
613 "EnumPrinters invalid value");
616 for (i=0;i<ARRAY_SIZE(levels);i++) {
617 int level = levels[i];
618 for (j=0;j<ctx->printer_count[level];j++) {
619 union spoolss_PrinterInfo *cur = &ctx->printers[level][j];
620 union spoolss_PrinterInfo *ref = &ctx->printers[2][j];
623 COMPARE_STRING(tctx, cur->info0, ref->info2, printername);
624 COMPARE_STRING(tctx, cur->info0, ref->info2, servername);
625 COMPARE_UINT32(tctx, cur->info0, ref->info2, cjobs);
626 /*COMPARE_UINT32(tctx, cur->info0, ref->info2, total_jobs);
627 COMPARE_UINT32(tctx, cur->info0, ref->info2, total_bytes);
628 COMPARE_SPOOLSS_TIME(cur->info0, ref->info2, spoolss_Time time);
629 COMPARE_UINT32(tctx, cur->info0, ref->info2, global_counter);
630 COMPARE_UINT32(tctx, cur->info0, ref->info2, total_pages);
631 COMPARE_UINT32(tctx, cur->info0, ref->info2, version);
632 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown10);
633 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown11);
634 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown12);
635 COMPARE_UINT32(tctx, cur->info0, ref->info2, session_counter);
636 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown14);
637 COMPARE_UINT32(tctx, cur->info0, ref->info2, printer_errors);
638 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown16);
639 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown17);
640 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown18);
641 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown19);
642 COMPARE_UINT32(tctx, cur->info0, ref->info2, change_id);
643 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown21);*/
644 COMPARE_UINT32(tctx, cur->info0, ref->info2, status);
645 /*COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown23);
646 COMPARE_UINT32(tctx, cur->info0, ref->info2, c_setprinter);
647 COMPARE_UINT16(cur->info0, ref->info2, unknown25);
648 COMPARE_UINT16(cur->info0, ref->info2, unknown26);
649 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown27);
650 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown28);
651 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown29);*/
654 /*COMPARE_UINT32(tctx, cur->info1, ref->info2, flags);*/
655 /*COMPARE_STRING(tctx, cur->info1, ref->info2, name);*/
656 /*COMPARE_STRING(tctx, cur->info1, ref->info2, description);*/
657 COMPARE_STRING(tctx, cur->info1, ref->info2, comment);
660 /* level 2 is our reference, and it makes no sense to compare it to itself */
663 COMPARE_STRING(tctx, cur->info4, ref->info2, printername);
664 COMPARE_STRING(tctx, cur->info4, ref->info2, servername);
665 COMPARE_UINT32(tctx, cur->info4, ref->info2, attributes);
668 COMPARE_STRING(tctx, cur->info5, ref->info2, printername);
669 COMPARE_STRING(tctx, cur->info5, ref->info2, portname);
670 COMPARE_UINT32(tctx, cur->info5, ref->info2, attributes);
671 /*COMPARE_UINT32(tctx, cur->info5, ref->info2, device_not_selected_timeout);
672 COMPARE_UINT32(tctx, cur->info5, ref->info2, transmission_retry_timeout);*/
679 * - verify that the port of a printer was in the list returned by EnumPorts
685 static bool test_GetPrinter(struct torture_context *tctx,
686 struct dcerpc_pipe *p,
687 struct policy_handle *handle)
690 struct spoolss_GetPrinter r;
691 uint16_t levels[] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
695 for (i=0;i<ARRAY_SIZE(levels);i++) {
696 r.in.handle = handle;
697 r.in.level = levels[i];
700 r.out.needed = &needed;
702 torture_comment(tctx, "Testing GetPrinter level %u\n", r.in.level);
704 status = dcerpc_spoolss_GetPrinter(p, tctx, &r);
705 torture_assert_ntstatus_ok(tctx, status, "GetPrinter failed");
707 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
708 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
709 data_blob_clear(&blob);
711 r.in.offered = needed;
712 status = dcerpc_spoolss_GetPrinter(p, tctx, &r);
715 torture_assert_ntstatus_ok(tctx, status, "GetPrinter failed");
717 torture_assert_werr_ok(tctx, r.out.result, "GetPrinter failed");
724 static bool test_ClosePrinter(struct torture_context *tctx,
725 struct dcerpc_pipe *p,
726 struct policy_handle *handle)
729 struct spoolss_ClosePrinter r;
731 r.in.handle = handle;
732 r.out.handle = handle;
734 torture_comment(tctx, "Testing ClosePrinter\n");
736 status = dcerpc_spoolss_ClosePrinter(p, tctx, &r);
737 torture_assert_ntstatus_ok(tctx, status, "ClosePrinter failed");
742 static bool test_GetForm(struct torture_context *tctx,
743 struct dcerpc_pipe *p,
744 struct policy_handle *handle,
745 const char *form_name,
749 struct spoolss_GetForm r;
752 r.in.handle = handle;
753 r.in.form_name = form_name;
757 r.out.needed = &needed;
759 torture_comment(tctx, "Testing GetForm level %d\n", r.in.level);
761 status = dcerpc_spoolss_GetForm(p, tctx, &r);
762 torture_assert_ntstatus_ok(tctx, status, "GetForm failed");
764 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
765 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
766 data_blob_clear(&blob);
768 r.in.offered = needed;
769 status = dcerpc_spoolss_GetForm(p, tctx, &r);
770 torture_assert_ntstatus_ok(tctx, status, "GetForm failed");
772 torture_assert_werr_ok(tctx, r.out.result, "GetForm failed");
774 torture_assert(tctx, r.out.info, "No form info returned");
777 torture_assert_werr_ok(tctx, r.out.result, "GetForm failed");
782 static bool test_EnumForms(struct torture_context *tctx,
783 struct dcerpc_pipe *p,
784 struct policy_handle *handle, bool print_server)
787 struct spoolss_EnumForms r;
791 uint32_t levels[] = { 1, 2 };
794 for (i=0; i<ARRAY_SIZE(levels); i++) {
796 r.in.handle = handle;
797 r.in.level = levels[i];
800 r.out.needed = &needed;
801 r.out.count = &count;
803 torture_comment(tctx, "Testing EnumForms level %d\n", levels[i]);
805 status = dcerpc_spoolss_EnumForms(p, tctx, &r);
806 torture_assert_ntstatus_ok(tctx, status, "EnumForms failed");
808 if ((r.in.level == 2) && (W_ERROR_EQUAL(r.out.result, WERR_UNKNOWN_LEVEL))) {
812 if (print_server && W_ERROR_EQUAL(r.out.result, WERR_BADFID))
813 torture_fail(tctx, "EnumForms on the PrintServer isn't supported by test server (NT4)");
815 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
816 union spoolss_FormInfo *info;
818 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
819 data_blob_clear(&blob);
821 r.in.offered = needed;
823 status = dcerpc_spoolss_EnumForms(p, tctx, &r);
825 torture_assert(tctx, r.out.info, "No forms returned");
829 for (j = 0; j < count; j++) {
831 ret &= test_GetForm(tctx, p, handle, info[j].info1.form_name, levels[i]);
835 torture_assert_ntstatus_ok(tctx, status, "EnumForms failed");
837 torture_assert_werr_ok(tctx, r.out.result, "EnumForms failed");
843 static bool test_DeleteForm(struct torture_context *tctx,
844 struct dcerpc_pipe *p,
845 struct policy_handle *handle,
846 const char *form_name)
849 struct spoolss_DeleteForm r;
851 r.in.handle = handle;
852 r.in.form_name = form_name;
854 status = dcerpc_spoolss_DeleteForm(p, tctx, &r);
856 torture_assert_ntstatus_ok(tctx, status, "DeleteForm failed");
858 torture_assert_werr_ok(tctx, r.out.result, "DeleteForm failed");
863 static bool test_AddForm(struct torture_context *tctx,
864 struct dcerpc_pipe *p,
865 struct policy_handle *handle, bool print_server)
867 struct spoolss_AddForm r;
868 struct spoolss_AddFormInfo1 addform;
869 const char *form_name = "testform3";
873 r.in.handle = handle;
875 r.in.info.info1 = &addform;
876 addform.flags = SPOOLSS_FORM_USER;
877 addform.form_name = form_name;
878 addform.size.width = 50;
879 addform.size.height = 25;
880 addform.area.left = 5;
881 addform.area.top = 10;
882 addform.area.right = 45;
883 addform.area.bottom = 15;
885 status = dcerpc_spoolss_AddForm(p, tctx, &r);
887 torture_assert_ntstatus_ok(tctx, status, "AddForm failed");
889 torture_assert_werr_ok(tctx, r.out.result, "AddForm failed");
891 if (!print_server) ret &= test_GetForm(tctx, p, handle, form_name, 1);
894 struct spoolss_SetForm sf;
895 struct spoolss_AddFormInfo1 setform;
897 sf.in.handle = handle;
898 sf.in.form_name = form_name;
900 sf.in.info.info1= &setform;
901 setform.flags = addform.flags;
902 setform.form_name = addform.form_name;
903 setform.size = addform.size;
904 setform.area = addform.area;
906 setform.size.width = 1234;
908 status = dcerpc_spoolss_SetForm(p, tctx, &sf);
910 torture_assert_ntstatus_ok(tctx, status, "SetForm failed");
912 torture_assert_werr_ok(tctx, r.out.result, "SetForm failed");
915 if (!print_server) ret &= test_GetForm(tctx, p, handle, form_name, 1);
917 if (!test_DeleteForm(tctx, p, handle, form_name)) {
924 static bool test_EnumPorts_old(struct torture_context *tctx,
925 struct dcerpc_pipe *p)
928 struct spoolss_EnumPorts r;
932 r.in.servername = talloc_asprintf(tctx, "\\\\%s",
933 dcerpc_server_name(p));
937 r.out.needed = &needed;
938 r.out.count = &count;
940 torture_comment(tctx, "Testing EnumPorts\n");
942 status = dcerpc_spoolss_EnumPorts(p, tctx, &r);
944 torture_assert_ntstatus_ok(tctx, status, "EnumPorts failed");
946 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
947 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
948 data_blob_clear(&blob);
950 r.in.offered = needed;
952 status = dcerpc_spoolss_EnumPorts(p, tctx, &r);
953 torture_assert_ntstatus_ok(tctx, status, "EnumPorts failed");
955 torture_assert(tctx, r.out.info, "No ports returned");
961 static bool test_AddPort(struct torture_context *tctx,
962 struct dcerpc_pipe *p)
965 struct spoolss_AddPort r;
967 r.in.server_name = talloc_asprintf(tctx, "\\\\%s",
968 dcerpc_server_name(p));
970 r.in.monitor_name = "foo";
972 torture_comment(tctx, "Testing AddPort\n");
974 status = dcerpc_spoolss_AddPort(p, tctx, &r);
976 torture_assert_ntstatus_ok(tctx, status, "AddPort failed");
978 /* win2k3 returns WERR_NOT_SUPPORTED */
982 if (!W_ERROR_IS_OK(r.out.result)) {
983 printf("AddPort failed - %s\n", win_errstr(r.out.result));
992 static bool test_GetJob(struct torture_context *tctx,
993 struct dcerpc_pipe *p,
994 struct policy_handle *handle, uint32_t job_id)
997 struct spoolss_GetJob r;
1000 r.in.handle = handle;
1001 r.in.job_id = job_id;
1005 r.out.needed = &needed;
1007 torture_comment(tctx, "Testing GetJob\n");
1009 status = dcerpc_spoolss_GetJob(p, tctx, &r);
1010 torture_assert_ntstatus_ok(tctx, status, "GetJob failed");
1012 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
1013 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
1014 data_blob_clear(&blob);
1015 r.in.buffer = &blob;
1016 r.in.offered = needed;
1018 status = dcerpc_spoolss_GetJob(p, tctx, &r);
1020 torture_assert(tctx, r.out.info, "No job info returned");
1026 static bool test_SetJob(struct torture_context *tctx,
1027 struct dcerpc_pipe *p,
1028 struct policy_handle *handle, uint32_t job_id,
1029 enum spoolss_JobControl command)
1032 struct spoolss_SetJob r;
1034 r.in.handle = handle;
1035 r.in.job_id = job_id;
1037 r.in.command = command;
1039 torture_comment(tctx, "Testing SetJob\n");
1041 status = dcerpc_spoolss_SetJob(p, tctx, &r);
1042 torture_assert_ntstatus_ok(tctx, status, "SetJob failed");
1043 torture_assert_werr_ok(tctx, r.out.result, "SetJob failed");
1048 static bool test_EnumJobs(struct torture_context *tctx,
1049 struct dcerpc_pipe *p,
1050 struct policy_handle *handle)
1053 struct spoolss_EnumJobs r;
1057 r.in.handle = handle;
1059 r.in.numjobs = 0xffffffff;
1063 r.out.needed = &needed;
1064 r.out.count = &count;
1066 torture_comment(tctx, "Testing EnumJobs\n");
1068 status = dcerpc_spoolss_EnumJobs(p, tctx, &r);
1070 torture_assert_ntstatus_ok(tctx, status, "EnumJobs failed");
1072 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
1073 union spoolss_JobInfo *info;
1075 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
1076 data_blob_clear(&blob);
1077 r.in.buffer = &blob;
1078 r.in.offered = needed;
1080 status = dcerpc_spoolss_EnumJobs(p, tctx, &r);
1082 torture_assert(tctx, r.out.info, "No jobs returned");
1086 for (j = 0; j < count; j++) {
1087 test_GetJob(tctx, p, handle, info[j].info1.job_id);
1088 test_SetJob(tctx, p, handle, info[j].info1.job_id, SPOOLSS_JOB_CONTROL_PAUSE);
1089 test_SetJob(tctx, p, handle, info[j].info1.job_id, SPOOLSS_JOB_CONTROL_RESUME);
1093 torture_assert_werr_ok(tctx, r.out.result, "EnumJobs failed");
1099 static bool test_DoPrintTest(struct torture_context *tctx,
1100 struct dcerpc_pipe *p,
1101 struct policy_handle *handle)
1105 struct spoolss_StartDocPrinter s;
1106 struct spoolss_DocumentInfo1 info1;
1107 struct spoolss_StartPagePrinter sp;
1108 struct spoolss_WritePrinter w;
1109 struct spoolss_EndPagePrinter ep;
1110 struct spoolss_EndDocPrinter e;
1113 uint32_t num_written;
1115 torture_comment(tctx, "Testing StartDocPrinter\n");
1117 s.in.handle = handle;
1119 s.in.info.info1 = &info1;
1120 s.out.job_id = &job_id;
1121 info1.document_name = "TorturePrintJob";
1122 info1.output_file = NULL;
1123 info1.datatype = "RAW";
1125 status = dcerpc_spoolss_StartDocPrinter(p, tctx, &s);
1126 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_StartDocPrinter failed");
1127 torture_assert_werr_ok(tctx, s.out.result, "StartDocPrinter failed");
1129 for (i=1; i < 4; i++) {
1130 torture_comment(tctx, "Testing StartPagePrinter: Page[%d]\n", i);
1132 sp.in.handle = handle;
1134 status = dcerpc_spoolss_StartPagePrinter(p, tctx, &sp);
1135 torture_assert_ntstatus_ok(tctx, status,
1136 "dcerpc_spoolss_StartPagePrinter failed");
1137 torture_assert_werr_ok(tctx, sp.out.result, "StartPagePrinter failed");
1139 torture_comment(tctx, "Testing WritePrinter: Page[%d]\n", i);
1141 w.in.handle = handle;
1142 w.in.data = data_blob_string_const(talloc_asprintf(tctx,"TortureTestPage: %d\nData\n",i));
1143 w.out.num_written = &num_written;
1145 status = dcerpc_spoolss_WritePrinter(p, tctx, &w);
1146 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_WritePrinter failed");
1147 torture_assert_werr_ok(tctx, w.out.result, "WritePrinter failed");
1149 torture_comment(tctx, "Testing EndPagePrinter: Page[%d]\n", i);
1151 ep.in.handle = handle;
1153 status = dcerpc_spoolss_EndPagePrinter(p, tctx, &ep);
1154 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EndPagePrinter failed");
1155 torture_assert_werr_ok(tctx, ep.out.result, "EndPagePrinter failed");
1158 torture_comment(tctx, "Testing EndDocPrinter\n");
1160 e.in.handle = handle;
1162 status = dcerpc_spoolss_EndDocPrinter(p, tctx, &e);
1163 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EndDocPrinter failed");
1164 torture_assert_werr_ok(tctx, e.out.result, "EndDocPrinter failed");
1166 ret &= test_EnumJobs(tctx, p, handle);
1168 ret &= test_SetJob(tctx, p, handle, job_id, SPOOLSS_JOB_CONTROL_DELETE);
1173 static bool test_PausePrinter(struct torture_context *tctx,
1174 struct dcerpc_pipe *p,
1175 struct policy_handle *handle)
1178 struct spoolss_SetPrinter r;
1179 struct spoolss_SetPrinterInfoCtr info_ctr;
1180 struct spoolss_DevmodeContainer devmode_ctr;
1181 struct sec_desc_buf secdesc_ctr;
1184 info_ctr.info.info0 = NULL;
1186 ZERO_STRUCT(devmode_ctr);
1187 ZERO_STRUCT(secdesc_ctr);
1189 r.in.handle = handle;
1190 r.in.info_ctr = &info_ctr;
1191 r.in.devmode_ctr = &devmode_ctr;
1192 r.in.secdesc_ctr = &secdesc_ctr;
1193 r.in.command = SPOOLSS_PRINTER_CONTROL_PAUSE;
1195 torture_comment(tctx, "Testing SetPrinter: SPOOLSS_PRINTER_CONTROL_PAUSE\n");
1197 status = dcerpc_spoolss_SetPrinter(p, tctx, &r);
1199 torture_assert_ntstatus_ok(tctx, status, "SetPrinter failed");
1201 torture_assert_werr_ok(tctx, r.out.result, "SetPrinter failed");
1206 static bool test_ResumePrinter(struct torture_context *tctx,
1207 struct dcerpc_pipe *p,
1208 struct policy_handle *handle)
1211 struct spoolss_SetPrinter r;
1212 struct spoolss_SetPrinterInfoCtr info_ctr;
1213 struct spoolss_DevmodeContainer devmode_ctr;
1214 struct sec_desc_buf secdesc_ctr;
1217 info_ctr.info.info0 = NULL;
1219 ZERO_STRUCT(devmode_ctr);
1220 ZERO_STRUCT(secdesc_ctr);
1222 r.in.handle = handle;
1223 r.in.info_ctr = &info_ctr;
1224 r.in.devmode_ctr = &devmode_ctr;
1225 r.in.secdesc_ctr = &secdesc_ctr;
1226 r.in.command = SPOOLSS_PRINTER_CONTROL_RESUME;
1228 torture_comment(tctx, "Testing SetPrinter: SPOOLSS_PRINTER_CONTROL_RESUME\n");
1230 status = dcerpc_spoolss_SetPrinter(p, tctx, &r);
1232 torture_assert_ntstatus_ok(tctx, status, "SetPrinter failed");
1234 torture_assert_werr_ok(tctx, r.out.result, "SetPrinter failed");
1239 static bool test_GetPrinterData(struct torture_context *tctx,
1240 struct dcerpc_pipe *p,
1241 struct policy_handle *handle,
1242 const char *value_name)
1245 struct spoolss_GetPrinterData r;
1247 enum spoolss_PrinterDataType type;
1249 r.in.handle = handle;
1250 r.in.value_name = value_name;
1252 r.out.needed = &needed;
1255 torture_comment(tctx, "Testing GetPrinterData\n");
1257 status = dcerpc_spoolss_GetPrinterData(p, tctx, &r);
1258 torture_assert_ntstatus_ok(tctx, status, "GetPrinterData failed");
1260 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
1261 r.in.offered = needed;
1263 status = dcerpc_spoolss_GetPrinterData(p, tctx, &r);
1264 torture_assert_ntstatus_ok(tctx, status, "GetPrinterData failed");
1266 torture_assert_werr_ok(tctx, r.out.result, "GetPrinterData failed");
1272 static bool test_GetPrinterDataEx(struct torture_context *tctx,
1273 struct dcerpc_pipe *p,
1274 struct policy_handle *handle,
1275 const char *key_name,
1276 const char *value_name)
1279 struct spoolss_GetPrinterDataEx r;
1283 r.in.handle = handle;
1284 r.in.key_name = key_name;
1285 r.in.value_name = value_name;
1288 r.out.needed = &needed;
1290 torture_comment(tctx, "Testing GetPrinterDataEx\n");
1292 status = dcerpc_spoolss_GetPrinterDataEx(p, tctx, &r);
1293 if (!NT_STATUS_IS_OK(status)) {
1294 if (NT_STATUS_EQUAL(status,NT_STATUS_NET_WRITE_FAULT) &&
1295 p->last_fault_code == DCERPC_FAULT_OP_RNG_ERROR) {
1296 torture_skip(tctx, "GetPrinterDataEx not supported by server\n");
1298 torture_assert_ntstatus_ok(tctx, status, "GetPrinterDataEx failed");
1301 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
1302 r.in.offered = needed;
1303 r.out.buffer = talloc_array(tctx, uint8_t, needed);
1305 status = dcerpc_spoolss_GetPrinterDataEx(p, tctx, &r);
1306 torture_assert_ntstatus_ok(tctx, status, "GetPrinterDataEx failed");
1308 torture_assert_werr_ok(tctx, r.out.result, "GetPrinterDataEx failed");
1314 static bool test_EnumPrinterData(struct torture_context *tctx, struct dcerpc_pipe *p,
1315 struct policy_handle *handle)
1318 struct spoolss_EnumPrinterData r;
1321 r.in.handle = handle;
1322 r.in.enum_index = 0;
1325 uint32_t value_size = 0;
1326 uint32_t data_size = 0;
1327 uint32_t printerdata_type = 0;
1328 DATA_BLOB data = data_blob(NULL,0);
1330 r.in.value_offered = value_size;
1331 r.out.value_needed = &value_size;
1332 r.in.data_offered = data_size;
1333 r.out.data_needed = &data_size;
1335 r.out.printerdata_type = &printerdata_type;
1336 r.out.buffer = &data;
1338 torture_comment(tctx, "Testing EnumPrinterData\n");
1340 status = dcerpc_spoolss_EnumPrinterData(p, tctx, &r);
1342 torture_assert_ntstatus_ok(tctx, status, "EnumPrinterData failed");
1344 r.in.value_offered = value_size;
1345 r.in.data_offered = data_size;
1347 status = dcerpc_spoolss_EnumPrinterData(p, tctx, &r);
1349 torture_assert_ntstatus_ok(tctx, status, "EnumPrinterData failed");
1351 test_GetPrinterData(tctx, p, handle, r.out.value_name);
1353 test_GetPrinterDataEx(tctx,
1354 p, handle, "PrinterDriverData",
1359 } while (W_ERROR_IS_OK(r.out.result));
1364 static bool test_EnumPrinterDataEx(struct torture_context *tctx,
1365 struct dcerpc_pipe *p,
1366 struct policy_handle *handle)
1369 struct spoolss_EnumPrinterDataEx r;
1373 r.in.handle = handle;
1374 r.in.key_name = "PrinterDriverData";
1376 r.out.needed = &needed;
1377 r.out.count = &count;
1379 torture_comment(tctx, "Testing EnumPrinterDataEx\n");
1381 status = dcerpc_spoolss_EnumPrinterDataEx(p, tctx, &r);
1382 torture_assert_ntstatus_ok(tctx, status, "EnumPrinterDataEx failed");
1384 r.in.offered = needed;
1385 r.out.buffer = talloc_array(tctx, uint8_t, needed);
1387 status = dcerpc_spoolss_EnumPrinterDataEx(p, tctx, &r);
1389 torture_assert_ntstatus_ok(tctx, status, "EnumPrinterDataEx failed");
1395 static bool test_DeletePrinterData(struct torture_context *tctx,
1396 struct dcerpc_pipe *p,
1397 struct policy_handle *handle,
1398 const char *value_name)
1401 struct spoolss_DeletePrinterData r;
1403 r.in.handle = handle;
1404 r.in.value_name = value_name;
1406 torture_comment(tctx, "Testing DeletePrinterData\n");
1408 status = dcerpc_spoolss_DeletePrinterData(p, tctx, &r);
1410 torture_assert_ntstatus_ok(tctx, status, "DeletePrinterData failed");
1415 static bool test_SetPrinterData(struct torture_context *tctx,
1416 struct dcerpc_pipe *p,
1417 struct policy_handle *handle)
1420 struct spoolss_SetPrinterData r;
1421 const char *value_name = "spottyfoot";
1423 r.in.handle = handle;
1424 r.in.value_name = value_name;
1425 r.in.type = SPOOLSS_PRINTER_DATA_TYPE_STRING;
1426 r.in.data.string = "dog";
1428 torture_comment(tctx, "Testing SetPrinterData\n");
1430 status = dcerpc_spoolss_SetPrinterData(p, tctx, &r);
1432 torture_assert_ntstatus_ok(tctx, status, "SetPrinterData failed");
1434 if (!test_GetPrinterData(tctx, p, handle, value_name)) {
1438 if (!test_DeletePrinterData(tctx, p, handle, value_name)) {
1445 static bool test_SecondaryClosePrinter(struct torture_context *tctx,
1446 struct dcerpc_pipe *p,
1447 struct policy_handle *handle)
1450 struct dcerpc_binding *b;
1451 struct dcerpc_pipe *p2;
1452 struct spoolss_ClosePrinter cp;
1454 /* only makes sense on SMB */
1455 if (p->conn->transport.transport != NCACN_NP) {
1459 torture_comment(tctx, "testing close on secondary pipe\n");
1461 status = dcerpc_parse_binding(tctx, p->conn->binding_string, &b);
1462 torture_assert_ntstatus_ok(tctx, status, "Failed to parse dcerpc binding");
1464 status = dcerpc_secondary_connection(p, &p2, b);
1465 torture_assert_ntstatus_ok(tctx, status, "Failed to create secondary connection");
1467 status = dcerpc_bind_auth_none(p2, &ndr_table_spoolss);
1468 torture_assert_ntstatus_ok(tctx, status, "Failed to create bind on secondary connection");
1470 cp.in.handle = handle;
1471 cp.out.handle = handle;
1473 status = dcerpc_spoolss_ClosePrinter(p2, tctx, &cp);
1474 torture_assert_ntstatus_equal(tctx, status, NT_STATUS_NET_WRITE_FAULT,
1475 "ERROR: Allowed close on secondary connection");
1477 torture_assert_int_equal(tctx, p2->last_fault_code, DCERPC_FAULT_CONTEXT_MISMATCH,
1478 "Unexpected fault code");
1485 static bool test_OpenPrinter_badname(struct torture_context *tctx,
1486 struct dcerpc_pipe *p, const char *name)
1489 struct spoolss_OpenPrinter op;
1490 struct spoolss_OpenPrinterEx opEx;
1491 struct policy_handle handle;
1494 op.in.printername = name;
1495 op.in.datatype = NULL;
1496 op.in.devmode_ctr.devmode= NULL;
1497 op.in.access_mask = 0;
1498 op.out.handle = &handle;
1500 torture_comment(tctx, "\nTesting OpenPrinter(%s) with bad name\n", op.in.printername);
1502 status = dcerpc_spoolss_OpenPrinter(p, tctx, &op);
1503 torture_assert_ntstatus_ok(tctx, status, "OpenPrinter failed");
1504 if (!W_ERROR_EQUAL(WERR_INVALID_PRINTER_NAME,op.out.result)) {
1505 torture_comment(tctx, "OpenPrinter(%s) unexpected result[%s] should be WERR_INVALID_PRINTER_NAME\n",
1506 name, win_errstr(op.out.result));
1509 if (W_ERROR_IS_OK(op.out.result)) {
1510 ret &=test_ClosePrinter(tctx, p, &handle);
1513 opEx.in.printername = name;
1514 opEx.in.datatype = NULL;
1515 opEx.in.devmode_ctr.devmode = NULL;
1516 opEx.in.access_mask = 0;
1518 opEx.in.userlevel.level1 = NULL;
1519 opEx.out.handle = &handle;
1521 torture_comment(tctx, "Testing OpenPrinterEx(%s) with bad name\n", opEx.in.printername);
1523 status = dcerpc_spoolss_OpenPrinterEx(p, tctx, &opEx);
1524 torture_assert_ntstatus_ok(tctx, status, "OpenPrinterEx failed");
1525 if (!W_ERROR_EQUAL(WERR_INVALID_PARAM,opEx.out.result)) {
1526 torture_comment(tctx, "OpenPrinterEx(%s) unexpected result[%s] should be WERR_INVALID_PARAM\n",
1527 name, win_errstr(opEx.out.result));
1530 if (W_ERROR_IS_OK(opEx.out.result)) {
1531 ret &=test_ClosePrinter(tctx, p, &handle);
1537 static bool test_OpenPrinter(struct torture_context *tctx,
1538 struct dcerpc_pipe *p,
1542 struct spoolss_OpenPrinter r;
1543 struct policy_handle handle;
1546 r.in.printername = talloc_asprintf(tctx, "\\\\%s\\%s", dcerpc_server_name(p), name);
1547 r.in.datatype = NULL;
1548 r.in.devmode_ctr.devmode= NULL;
1549 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1550 r.out.handle = &handle;
1552 torture_comment(tctx, "Testing OpenPrinter(%s)\n", r.in.printername);
1554 status = dcerpc_spoolss_OpenPrinter(p, tctx, &r);
1556 torture_assert_ntstatus_ok(tctx, status, "OpenPrinter failed");
1558 torture_assert_werr_ok(tctx, r.out.result, "OpenPrinter failed");
1560 if (!test_GetPrinter(tctx, p, &handle)) {
1564 if (!test_SecondaryClosePrinter(tctx, p, &handle)) {
1568 if (!test_ClosePrinter(tctx, p, &handle)) {
1575 static bool call_OpenPrinterEx(struct torture_context *tctx,
1576 struct dcerpc_pipe *p,
1577 const char *name, struct policy_handle *handle)
1579 struct spoolss_OpenPrinterEx r;
1580 struct spoolss_UserLevel1 userlevel1;
1583 if (name && name[0]) {
1584 r.in.printername = talloc_asprintf(tctx, "\\\\%s\\%s",
1585 dcerpc_server_name(p), name);
1587 r.in.printername = talloc_asprintf(tctx, "\\\\%s",
1588 dcerpc_server_name(p));
1591 r.in.datatype = NULL;
1592 r.in.devmode_ctr.devmode= NULL;
1593 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1595 r.in.userlevel.level1 = &userlevel1;
1596 r.out.handle = handle;
1598 userlevel1.size = 1234;
1599 userlevel1.client = "hello";
1600 userlevel1.user = "spottyfoot!";
1601 userlevel1.build = 1;
1602 userlevel1.major = 2;
1603 userlevel1.minor = 3;
1604 userlevel1.processor = 4;
1606 torture_comment(tctx, "Testing OpenPrinterEx(%s)\n", r.in.printername);
1608 status = dcerpc_spoolss_OpenPrinterEx(p, tctx, &r);
1610 torture_assert_ntstatus_ok(tctx, status, "OpenPrinterEx failed");
1612 torture_assert_werr_ok(tctx, r.out.result, "OpenPrinterEx failed");
1617 static bool test_OpenPrinterEx(struct torture_context *tctx,
1618 struct dcerpc_pipe *p,
1621 struct policy_handle handle;
1624 if (!call_OpenPrinterEx(tctx, p, name, &handle)) {
1628 if (!test_GetPrinter(tctx, p, &handle)) {
1632 if (!test_EnumForms(tctx, p, &handle, false)) {
1636 if (!test_AddForm(tctx, p, &handle, false)) {
1640 if (!test_EnumPrinterData(tctx, p, &handle)) {
1644 if (!test_EnumPrinterDataEx(tctx, p, &handle)) {
1648 if (!test_PausePrinter(tctx, p, &handle)) {
1652 if (!test_DoPrintTest(tctx, p, &handle)) {
1656 if (!test_ResumePrinter(tctx, p, &handle)) {
1660 if (!test_SetPrinterData(tctx, p, &handle)) {
1664 if (!test_SecondaryClosePrinter(tctx, p, &handle)) {
1668 if (!test_ClosePrinter(tctx, p, &handle)) {
1675 static bool test_EnumPrinters_old(struct torture_context *tctx, struct dcerpc_pipe *p)
1677 struct spoolss_EnumPrinters r;
1679 uint16_t levels[] = {1, 2, 4, 5};
1683 for (i=0;i<ARRAY_SIZE(levels);i++) {
1684 union spoolss_PrinterInfo *info;
1689 r.in.flags = PRINTER_ENUM_LOCAL;
1691 r.in.level = levels[i];
1694 r.out.needed = &needed;
1695 r.out.count = &count;
1697 torture_comment(tctx, "Testing EnumPrinters level %u\n", r.in.level);
1699 status = dcerpc_spoolss_EnumPrinters(p, tctx, &r);
1700 torture_assert_ntstatus_ok(tctx, status, "EnumPrinters failed");
1702 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
1703 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
1704 data_blob_clear(&blob);
1705 r.in.buffer = &blob;
1706 r.in.offered = needed;
1707 status = dcerpc_spoolss_EnumPrinters(p, tctx, &r);
1710 torture_assert_ntstatus_ok(tctx, status, "EnumPrinters failed");
1712 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinters failed");
1715 torture_comment(tctx, "No printers returned\n");
1721 for (j=0;j<count;j++) {
1722 if (r.in.level == 1) {
1723 /* the names appear to be comma-separated name lists? */
1724 char *name = talloc_strdup(tctx, info[j].info1.name);
1725 char *comma = strchr(name, ',');
1726 if (comma) *comma = 0;
1727 if (!test_OpenPrinter(tctx, p, name)) {
1730 if (!test_OpenPrinterEx(tctx, p, name)) {
1741 static bool test_GetPrinterDriver2(struct dcerpc_pipe *p,
1742 struct policy_handle *handle,
1743 const char *driver_name)
1746 struct spoolss_GetPrinterDriver2 r;
1748 uint32_t server_major_version;
1749 uint32_t server_minor_version;
1751 r.in.handle = handle;
1752 r.in.architecture = "W32X86";
1756 r.in.client_major_version = 0;
1757 r.in.client_minor_version = 0;
1758 r.out.needed = &needed;
1759 r.out.server_major_version = &server_major_version;
1760 r.out.server_minor_version = &server_minor_version;
1762 printf("Testing GetPrinterDriver2\n");
1764 status = dcerpc_spoolss_GetPrinterDriver2(p, tctx, &r);
1765 if (!NT_STATUS_IS_OK(status)) {
1766 printf("GetPrinterDriver2 failed - %s\n", nt_errstr(status));
1770 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
1771 r.in.offered = needed;
1772 status = dcerpc_spoolss_GetPrinterDriver2(p, tctx, &r);
1775 if (!NT_STATUS_IS_OK(status)) {
1776 printf("GetPrinterDriver2 failed - %s\n",
1781 if (!W_ERROR_IS_OK(r.out.result)) {
1782 printf("GetPrinterDriver2 failed - %s\n",
1783 win_errstr(r.out.result));
1791 static bool test_EnumPrinterDrivers_old(struct torture_context *tctx,
1792 struct dcerpc_pipe *p)
1794 struct spoolss_EnumPrinterDrivers r;
1796 uint16_t levels[] = {1, 2, 3, 4, 5, 6};
1799 for (i=0;i<ARRAY_SIZE(levels);i++) {
1804 r.in.server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
1805 r.in.environment = "Windows NT x86";
1806 r.in.level = levels[i];
1809 r.out.needed = &needed;
1810 r.out.count = &count;
1812 torture_comment(tctx, "Testing EnumPrinterDrivers level %u\n", r.in.level);
1814 status = dcerpc_spoolss_EnumPrinterDrivers(p, tctx, &r);
1816 torture_assert_ntstatus_ok(tctx, status, "EnumPrinterDrivers failed");
1818 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
1819 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
1820 data_blob_clear(&blob);
1821 r.in.buffer = &blob;
1822 r.in.offered = needed;
1823 status = dcerpc_spoolss_EnumPrinterDrivers(p, tctx, &r);
1826 torture_assert_ntstatus_ok(tctx, status, "EnumPrinterDrivers failed");
1828 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinterDrivers failed");
1831 torture_comment(tctx, "No printer drivers returned\n");
1839 /** Test that makes sure that calling ReplyOpenPrinter()
1840 * on Samba 4 will cause an irpc broadcast call.
1842 static bool test_ReplyOpenPrinter(struct torture_context *tctx,
1843 struct dcerpc_pipe *pipe)
1845 struct spoolss_ReplyOpenPrinter r;
1846 struct spoolss_ReplyClosePrinter s;
1847 struct policy_handle h;
1849 r.in.server_name = "earth";
1850 r.in.printer_local = 2;
1851 r.in.type = REG_DWORD;
1856 torture_assert_ntstatus_ok(tctx,
1857 dcerpc_spoolss_ReplyOpenPrinter(pipe, tctx, &r),
1858 "spoolss_ReplyOpenPrinter call failed");
1860 torture_assert_werr_ok(tctx, r.out.result, "error return code");
1865 torture_assert_ntstatus_ok(tctx,
1866 dcerpc_spoolss_ReplyClosePrinter(pipe, tctx, &s),
1867 "spoolss_ReplyClosePrinter call failed");
1869 torture_assert_werr_ok(tctx, r.out.result, "error return code");
1874 bool torture_rpc_spoolss(struct torture_context *torture)
1877 struct dcerpc_pipe *p;
1879 struct test_spoolss_context *ctx;
1881 status = torture_rpc_connection(torture, &p, &ndr_table_spoolss);
1882 if (!NT_STATUS_IS_OK(status)) {
1886 ctx = talloc_zero(torture, struct test_spoolss_context);
1888 ret &= test_OpenPrinter_server(torture, p, ctx);
1890 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "W3SvcInstalled");
1891 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "BeepEnabled");
1892 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "EventLog");
1893 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "NetPopup");
1894 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "NetPopupToComputer");
1895 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "MajorVersion");
1896 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "MinorVersion");
1897 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "DefaultSpoolDirectory");
1898 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "Architecture");
1899 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "DsPresent");
1900 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "OSVersion");
1901 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "OSVersionEx");
1902 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "DNSMachineName");
1903 ret &= test_EnumForms(torture, p, &ctx->server_handle, true);
1904 ret &= test_AddForm(torture, p, &ctx->server_handle, true);
1905 ret &= test_EnumPorts(torture, p, ctx);
1906 ret &= test_GetPrinterDriverDirectory(torture, p, ctx);
1907 ret &= test_GetPrintProcessorDirectory(torture, p, ctx);
1908 ret &= test_EnumPrinterDrivers(torture, p, ctx);
1909 ret &= test_EnumMonitors(torture, p, ctx);
1910 ret &= test_EnumPrintProcessors(torture, p, ctx);
1911 ret &= test_EnumPrinters(torture, p, ctx);
1912 ret &= test_OpenPrinter_badname(torture, p, "__INVALID_PRINTER__");
1913 ret &= test_OpenPrinter_badname(torture, p, "\\\\__INVALID_HOST__");
1914 ret &= test_OpenPrinter_badname(torture, p, "");
1915 ret &= test_OpenPrinter_badname(torture, p, "\\\\\\");
1916 ret &= test_OpenPrinter_badname(torture, p, "\\\\\\__INVALID_PRINTER__");
1917 ret &= test_OpenPrinter_badname(torture, p, talloc_asprintf(torture, "\\\\%s\\", dcerpc_server_name(p)));
1918 ret &= test_OpenPrinter_badname(torture, p,
1919 talloc_asprintf(torture, "\\\\%s\\__INVALID_PRINTER__", dcerpc_server_name(p)));
1922 ret &= test_AddPort(torture, p);
1923 ret &= test_EnumPorts_old(torture, p);
1924 ret &= test_EnumPrinters_old(torture, p);
1925 ret &= test_EnumPrinterDrivers_old(torture, p);
1926 ret &= test_ReplyOpenPrinter(torture, p);