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
8 Copyright (C) Guenther Deschner 2009
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "torture/torture.h"
26 #include "torture/rpc/rpc.h"
27 #include "librpc/gen_ndr/ndr_misc.h"
28 #include "librpc/gen_ndr/ndr_spoolss_c.h"
29 #include "param/param.h"
31 #define TORTURE_WELLKNOWN_PRINTER "torture_wkn_printer"
32 #define TORTURE_PRINTER "torture_printer"
33 #define TORTURE_WELLKNOWN_PRINTER_EX "torture_wkn_printer_ex"
34 #define TORTURE_PRINTER_EX "torture_printer_ex"
36 struct test_spoolss_context {
37 /* print server handle */
38 struct policy_handle server_handle;
41 uint32_t port_count[3];
42 union spoolss_PortInfo *ports[3];
44 /* for EnumPrinterDrivers */
45 uint32_t driver_count[7];
46 union spoolss_DriverInfo *drivers[7];
48 /* for EnumMonitors */
49 uint32_t monitor_count[3];
50 union spoolss_MonitorInfo *monitors[3];
52 /* for EnumPrintProcessors */
53 uint32_t print_processor_count[2];
54 union spoolss_PrintProcessorInfo *print_processors[2];
56 /* for EnumPrinters */
57 uint32_t printer_count[6];
58 union spoolss_PrinterInfo *printers[6];
61 #define COMPARE_STRING(tctx, c,r,e) \
62 torture_assert_str_equal(tctx, c.e, r.e, "invalid value")
64 /* not every compiler supports __typeof__() */
66 #define _CHECK_FIELD_SIZE(c,r,e,type) do {\
67 if (sizeof(__typeof__(c.e)) != sizeof(type)) { \
68 torture_fail(tctx, #c "." #e "field is not " #type "\n"); \
70 if (sizeof(__typeof__(r.e)) != sizeof(type)) { \
71 torture_fail(tctx, #r "." #e "field is not " #type "\n"); \
75 #define _CHECK_FIELD_SIZE(c,r,e,type) do {} while(0)
78 #define COMPARE_UINT32(tctx, c, r, e) do {\
79 _CHECK_FIELD_SIZE(c, r, e, uint32_t); \
80 torture_assert_int_equal(tctx, c.e, r.e, "invalid value"); \
83 #define COMPARE_STRING_ARRAY(tctx, c,r,e) do {\
89 torture_fail(tctx, #r "." #e " field is NULL and " #c "." #e " is not\n"); \
92 torture_fail(tctx, #c "." #e " field is NULL and " #r "." #e " is not\n"); \
94 for (__i=0;c.e[__i] != NULL; __i++) { \
95 torture_assert_str_equal(tctx, c.e[__i], r.e[__i], "invalid value"); \
99 static bool test_OpenPrinter_server(struct torture_context *tctx,
100 struct dcerpc_pipe *p,
101 struct policy_handle *server_handle)
104 struct spoolss_OpenPrinter op;
106 op.in.printername = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
107 op.in.datatype = NULL;
108 op.in.devmode_ctr.devmode= NULL;
109 op.in.access_mask = 0;
110 op.out.handle = server_handle;
112 torture_comment(tctx, "Testing OpenPrinter(%s)\n", op.in.printername);
114 status = dcerpc_spoolss_OpenPrinter(p, tctx, &op);
115 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_OpenPrinter failed");
116 torture_assert_werr_ok(tctx, op.out.result, "dcerpc_spoolss_OpenPrinter failed");
121 static bool test_EnumPorts(struct torture_context *tctx,
122 struct dcerpc_pipe *p,
123 struct test_spoolss_context *ctx)
126 struct spoolss_EnumPorts r;
127 uint16_t levels[] = { 1, 2 };
130 for (i=0;i<ARRAY_SIZE(levels);i++) {
131 int level = levels[i];
135 union spoolss_PortInfo *info;
137 r.in.servername = "";
141 r.out.needed = &needed;
142 r.out.count = &count;
145 torture_comment(tctx, "Testing EnumPorts level %u\n", r.in.level);
147 status = dcerpc_spoolss_EnumPorts(p, ctx, &r);
148 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPorts failed");
149 if (W_ERROR_IS_OK(r.out.result)) {
150 /* TODO: do some more checks here */
153 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
154 "EnumPorts unexpected return code");
156 blob = data_blob_talloc(ctx, NULL, needed);
157 data_blob_clear(&blob);
159 r.in.offered = needed;
161 status = dcerpc_spoolss_EnumPorts(p, ctx, &r);
162 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPorts failed");
164 torture_assert_werr_ok(tctx, r.out.result, "EnumPorts failed");
166 torture_assert(tctx, info, "EnumPorts returned no info");
168 ctx->port_count[level] = count;
169 ctx->ports[level] = info;
172 for (i=1;i<ARRAY_SIZE(levels);i++) {
173 int level = levels[i];
174 int old_level = levels[i-1];
175 torture_assert_int_equal(tctx, ctx->port_count[level], ctx->port_count[old_level],
176 "EnumPorts invalid value");
178 /* if the array sizes are not the same we would maybe segfault in the following code */
180 for (i=0;i<ARRAY_SIZE(levels);i++) {
181 int level = levels[i];
182 for (j=0;j<ctx->port_count[level];j++) {
183 union spoolss_PortInfo *cur = &ctx->ports[level][j];
184 union spoolss_PortInfo *ref = &ctx->ports[2][j];
187 COMPARE_STRING(tctx, cur->info1, ref->info2, port_name);
190 /* level 2 is our reference, and it makes no sense to compare it to itself */
199 static bool test_GetPrintProcessorDirectory(struct torture_context *tctx,
200 struct dcerpc_pipe *p,
201 struct test_spoolss_context *ctx)
204 struct spoolss_GetPrintProcessorDirectory r;
219 .server = talloc_asprintf(ctx, "\\\\%s", dcerpc_server_name(p))
222 .server = talloc_asprintf(ctx, "\\\\%s", dcerpc_server_name(p))
228 for (i=0;i<ARRAY_SIZE(levels);i++) {
229 int level = levels[i].level;
232 r.in.server = levels[i].server;
233 r.in.environment = SPOOLSS_ARCHITECTURE_NT_X86;
237 r.out.needed = &needed;
239 torture_comment(tctx, "Testing GetPrintProcessorDirectory level %u\n", r.in.level);
241 status = dcerpc_spoolss_GetPrintProcessorDirectory(p, ctx, &r);
242 torture_assert_ntstatus_ok(tctx, status,
243 "dcerpc_spoolss_GetPrintProcessorDirectory failed");
244 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
245 "GetPrintProcessorDirectory unexpected return code");
247 blob = data_blob_talloc(ctx, NULL, needed);
248 data_blob_clear(&blob);
250 r.in.offered = needed;
252 status = dcerpc_spoolss_GetPrintProcessorDirectory(p, ctx, &r);
253 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_GetPrintProcessorDirectory failed");
255 torture_assert_werr_ok(tctx, r.out.result, "GetPrintProcessorDirectory failed");
262 static bool test_GetPrinterDriverDirectory(struct torture_context *tctx,
263 struct dcerpc_pipe *p,
264 struct test_spoolss_context *ctx)
267 struct spoolss_GetPrinterDriverDirectory r;
282 .server = talloc_asprintf(ctx, "\\\\%s", dcerpc_server_name(p))
285 .server = talloc_asprintf(ctx, "\\\\%s", dcerpc_server_name(p))
291 for (i=0;i<ARRAY_SIZE(levels);i++) {
292 int level = levels[i].level;
295 r.in.server = levels[i].server;
296 r.in.environment = SPOOLSS_ARCHITECTURE_NT_X86;
300 r.out.needed = &needed;
302 torture_comment(tctx, "Testing GetPrinterDriverDirectory level %u\n", r.in.level);
304 status = dcerpc_spoolss_GetPrinterDriverDirectory(p, ctx, &r);
305 torture_assert_ntstatus_ok(tctx, status,
306 "dcerpc_spoolss_GetPrinterDriverDirectory failed");
307 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
308 "GetPrinterDriverDirectory unexpected return code");
310 blob = data_blob_talloc(ctx, NULL, needed);
311 data_blob_clear(&blob);
313 r.in.offered = needed;
315 status = dcerpc_spoolss_GetPrinterDriverDirectory(p, ctx, &r);
316 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_GetPrinterDriverDirectory failed");
318 torture_assert_werr_ok(tctx, r.out.result, "GetPrinterDriverDirectory failed");
324 static bool test_EnumPrinterDrivers(struct torture_context *tctx,
325 struct dcerpc_pipe *p,
326 struct test_spoolss_context *ctx,
327 const char *architecture)
330 struct spoolss_EnumPrinterDrivers r;
331 uint16_t levels[] = { 1, 2, 3, 4, 5, 6 };
334 for (i=0;i<ARRAY_SIZE(levels);i++) {
335 int level = levels[i];
339 union spoolss_DriverInfo *info;
341 /* FIXME: gd, come back and fix "" as server, and handle
342 * priority of returned error codes in torture test and samba 3
345 r.in.server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
346 r.in.environment = architecture;
350 r.out.needed = &needed;
351 r.out.count = &count;
354 torture_comment(tctx, "Testing EnumPrinterDrivers level %u (%s)\n", r.in.level, r.in.environment);
356 status = dcerpc_spoolss_EnumPrinterDrivers(p, ctx, &r);
357 torture_assert_ntstatus_ok(tctx, status,
358 "dcerpc_spoolss_EnumPrinterDrivers failed");
359 if (W_ERROR_IS_OK(r.out.result)) {
360 /* TODO: do some more checks here */
363 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
364 blob = data_blob_talloc(ctx, NULL, needed);
365 data_blob_clear(&blob);
367 r.in.offered = needed;
369 status = dcerpc_spoolss_EnumPrinterDrivers(p, ctx, &r);
370 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrinterDrivers failed");
373 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinterDrivers failed");
375 ctx->driver_count[level] = count;
376 ctx->drivers[level] = info;
379 for (i=1;i<ARRAY_SIZE(levels);i++) {
380 int level = levels[i];
381 int old_level = levels[i-1];
383 torture_assert_int_equal(tctx, ctx->driver_count[level], ctx->driver_count[old_level],
384 "EnumPrinterDrivers invalid value");
387 for (i=0;i<ARRAY_SIZE(levels);i++) {
388 int level = levels[i];
390 for (j=0;j<ctx->driver_count[level];j++) {
391 union spoolss_DriverInfo *cur = &ctx->drivers[level][j];
392 union spoolss_DriverInfo *ref = &ctx->drivers[6][j];
395 COMPARE_STRING(tctx, cur->info1, ref->info6, driver_name);
398 COMPARE_UINT32(tctx, cur->info2, ref->info6, version);
399 COMPARE_STRING(tctx, cur->info2, ref->info6, driver_name);
400 COMPARE_STRING(tctx, cur->info2, ref->info6, architecture);
401 COMPARE_STRING(tctx, cur->info2, ref->info6, driver_path);
402 COMPARE_STRING(tctx, cur->info2, ref->info6, data_file);
403 COMPARE_STRING(tctx, cur->info2, ref->info6, config_file);
406 COMPARE_UINT32(tctx, cur->info3, ref->info6, version);
407 COMPARE_STRING(tctx, cur->info3, ref->info6, driver_name);
408 COMPARE_STRING(tctx, cur->info3, ref->info6, architecture);
409 COMPARE_STRING(tctx, cur->info3, ref->info6, driver_path);
410 COMPARE_STRING(tctx, cur->info3, ref->info6, data_file);
411 COMPARE_STRING(tctx, cur->info3, ref->info6, config_file);
412 COMPARE_STRING(tctx, cur->info3, ref->info6, help_file);
413 COMPARE_STRING_ARRAY(tctx, cur->info3, ref->info6, dependent_files);
414 COMPARE_STRING(tctx, cur->info3, ref->info6, monitor_name);
415 COMPARE_STRING(tctx, cur->info3, ref->info6, default_datatype);
418 COMPARE_UINT32(tctx, cur->info4, ref->info6, version);
419 COMPARE_STRING(tctx, cur->info4, ref->info6, driver_name);
420 COMPARE_STRING(tctx, cur->info4, ref->info6, architecture);
421 COMPARE_STRING(tctx, cur->info4, ref->info6, driver_path);
422 COMPARE_STRING(tctx, cur->info4, ref->info6, data_file);
423 COMPARE_STRING(tctx, cur->info4, ref->info6, config_file);
424 COMPARE_STRING(tctx, cur->info4, ref->info6, help_file);
425 COMPARE_STRING_ARRAY(tctx, cur->info4, ref->info6, dependent_files);
426 COMPARE_STRING(tctx, cur->info4, ref->info6, monitor_name);
427 COMPARE_STRING(tctx, cur->info4, ref->info6, default_datatype);
428 COMPARE_STRING_ARRAY(tctx, cur->info4, ref->info6, previous_names);
431 COMPARE_UINT32(tctx, cur->info5, ref->info6, version);
432 COMPARE_STRING(tctx, cur->info5, ref->info6, driver_name);
433 COMPARE_STRING(tctx, cur->info5, ref->info6, architecture);
434 COMPARE_STRING(tctx, cur->info5, ref->info6, driver_path);
435 COMPARE_STRING(tctx, cur->info5, ref->info6, data_file);
436 COMPARE_STRING(tctx, cur->info5, ref->info6, config_file);
437 /*COMPARE_UINT32(tctx, cur->info5, ref->info6, driver_attributes);*/
438 /*COMPARE_UINT32(tctx, cur->info5, ref->info6, config_version);*/
439 /*TODO: ! COMPARE_UINT32(tctx, cur->info5, ref->info6, driver_version); */
442 /* level 6 is our reference, and it makes no sense to compare it to itself */
451 static bool test_EnumMonitors(struct torture_context *tctx,
452 struct dcerpc_pipe *p,
453 struct test_spoolss_context *ctx)
456 struct spoolss_EnumMonitors r;
457 uint16_t levels[] = { 1, 2 };
460 for (i=0;i<ARRAY_SIZE(levels);i++) {
461 int level = levels[i];
465 union spoolss_MonitorInfo *info;
467 r.in.servername = "";
471 r.out.needed = &needed;
472 r.out.count = &count;
475 torture_comment(tctx, "Testing EnumMonitors level %u\n", r.in.level);
477 status = dcerpc_spoolss_EnumMonitors(p, ctx, &r);
478 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumMonitors failed");
479 if (W_ERROR_IS_OK(r.out.result)) {
480 /* TODO: do some more checks here */
483 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
484 "EnumMonitors failed");
486 blob = data_blob_talloc(ctx, NULL, needed);
487 data_blob_clear(&blob);
489 r.in.offered = needed;
491 status = dcerpc_spoolss_EnumMonitors(p, ctx, &r);
492 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumMonitors failed");
494 torture_assert_werr_ok(tctx, r.out.result, "EnumMonitors failed");
496 ctx->monitor_count[level] = count;
497 ctx->monitors[level] = info;
500 for (i=1;i<ARRAY_SIZE(levels);i++) {
501 int level = levels[i];
502 int old_level = levels[i-1];
503 torture_assert_int_equal(tctx, ctx->monitor_count[level], ctx->monitor_count[old_level],
504 "EnumMonitors invalid value");
507 for (i=0;i<ARRAY_SIZE(levels);i++) {
508 int level = levels[i];
509 for (j=0;j<ctx->monitor_count[level];j++) {
510 union spoolss_MonitorInfo *cur = &ctx->monitors[level][j];
511 union spoolss_MonitorInfo *ref = &ctx->monitors[2][j];
514 COMPARE_STRING(tctx, cur->info1, ref->info2, monitor_name);
517 /* level 2 is our reference, and it makes no sense to compare it to itself */
526 static bool test_EnumPrintProcessors(struct torture_context *tctx,
527 struct dcerpc_pipe *p,
528 struct test_spoolss_context *ctx)
531 struct spoolss_EnumPrintProcessors r;
532 uint16_t levels[] = { 1 };
535 for (i=0;i<ARRAY_SIZE(levels);i++) {
536 int level = levels[i];
540 union spoolss_PrintProcessorInfo *info;
542 r.in.servername = "";
543 r.in.environment = SPOOLSS_ARCHITECTURE_NT_X86;
547 r.out.needed = &needed;
548 r.out.count = &count;
551 torture_comment(tctx, "Testing EnumPrintProcessors level %u\n", r.in.level);
553 status = dcerpc_spoolss_EnumPrintProcessors(p, ctx, &r);
554 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrintProcessors failed");
555 if (W_ERROR_IS_OK(r.out.result)) {
556 /* TODO: do some more checks here */
559 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
560 "EnumPrintProcessors unexpected return code");
562 blob = data_blob_talloc(ctx, NULL, needed);
563 data_blob_clear(&blob);
565 r.in.offered = needed;
567 status = dcerpc_spoolss_EnumPrintProcessors(p, ctx, &r);
568 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrintProcessors failed");
570 torture_assert_werr_ok(tctx, r.out.result, "EnumPrintProcessors failed");
572 ctx->print_processor_count[level] = count;
573 ctx->print_processors[level] = info;
576 for (i=1;i<ARRAY_SIZE(levels);i++) {
577 int level = levels[i];
578 int old_level = levels[i-1];
579 torture_assert_int_equal(tctx, ctx->print_processor_count[level], ctx->print_processor_count[old_level],
580 "EnumPrintProcessors failed");
583 for (i=0;i<ARRAY_SIZE(levels);i++) {
584 int level = levels[i];
585 for (j=0;j<ctx->print_processor_count[level];j++) {
587 union spoolss_PrintProcessorInfo *cur = &ctx->print_processors[level][j];
588 union spoolss_PrintProcessorInfo *ref = &ctx->print_processors[1][j];
592 /* level 1 is our reference, and it makes no sense to compare it to itself */
601 static bool test_EnumPrintProcDataTypes(struct torture_context *tctx,
602 struct dcerpc_pipe *p,
603 struct test_spoolss_context *ctx)
606 struct spoolss_EnumPrintProcDataTypes r;
607 uint16_t levels[] = { 1 };
610 for (i=0;i<ARRAY_SIZE(levels);i++) {
611 int level = levels[i];
615 union spoolss_PrintProcDataTypesInfo *info;
617 r.in.servername = "";
618 r.in.print_processor_name = "winprint";
622 r.out.needed = &needed;
623 r.out.count = &count;
626 torture_comment(tctx, "Testing EnumPrintProcDataTypes level %u\n", r.in.level);
628 status = dcerpc_spoolss_EnumPrintProcDataTypes(p, ctx, &r);
629 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrintProcDataType failed");
630 if (W_ERROR_IS_OK(r.out.result)) {
631 /* TODO: do some more checks here */
634 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
635 "EnumPrintProcDataTypes unexpected return code");
637 blob = data_blob_talloc(ctx, NULL, needed);
638 data_blob_clear(&blob);
640 r.in.offered = needed;
642 status = dcerpc_spoolss_EnumPrintProcDataTypes(p, ctx, &r);
643 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrintProcDataTypes failed");
645 torture_assert_werr_ok(tctx, r.out.result, "EnumPrintProcDataTypes failed");
652 static bool test_EnumPrinters(struct torture_context *tctx,
653 struct dcerpc_pipe *p,
654 struct test_spoolss_context *ctx)
656 struct spoolss_EnumPrinters r;
658 uint16_t levels[] = { 0, 1, 2, 4, 5 };
661 for (i=0;i<ARRAY_SIZE(levels);i++) {
662 int level = levels[i];
666 union spoolss_PrinterInfo *info;
668 r.in.flags = PRINTER_ENUM_LOCAL;
673 r.out.needed = &needed;
674 r.out.count = &count;
677 torture_comment(tctx, "Testing EnumPrinters level %u\n", r.in.level);
679 status = dcerpc_spoolss_EnumPrinters(p, ctx, &r);
680 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrinters failed");
681 if (W_ERROR_IS_OK(r.out.result)) {
682 /* TODO: do some more checks here */
685 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
686 "EnumPrinters unexpected return code");
688 blob = data_blob_talloc(ctx, NULL, needed);
689 data_blob_clear(&blob);
691 r.in.offered = needed;
693 status = dcerpc_spoolss_EnumPrinters(p, ctx, &r);
694 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrinters failed");
696 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinters failed");
698 ctx->printer_count[level] = count;
699 ctx->printers[level] = info;
702 for (i=1;i<ARRAY_SIZE(levels);i++) {
703 int level = levels[i];
704 int old_level = levels[i-1];
705 torture_assert_int_equal(tctx, ctx->printer_count[level], ctx->printer_count[old_level],
706 "EnumPrinters invalid value");
709 for (i=0;i<ARRAY_SIZE(levels);i++) {
710 int level = levels[i];
711 for (j=0;j<ctx->printer_count[level];j++) {
712 union spoolss_PrinterInfo *cur = &ctx->printers[level][j];
713 union spoolss_PrinterInfo *ref = &ctx->printers[2][j];
716 COMPARE_STRING(tctx, cur->info0, ref->info2, printername);
717 COMPARE_STRING(tctx, cur->info0, ref->info2, servername);
718 COMPARE_UINT32(tctx, cur->info0, ref->info2, cjobs);
719 /*COMPARE_UINT32(tctx, cur->info0, ref->info2, total_jobs);
720 COMPARE_UINT32(tctx, cur->info0, ref->info2, total_bytes);
721 COMPARE_SPOOLSS_TIME(cur->info0, ref->info2, spoolss_Time time);
722 COMPARE_UINT32(tctx, cur->info0, ref->info2, global_counter);
723 COMPARE_UINT32(tctx, cur->info0, ref->info2, total_pages);
724 COMPARE_UINT32(tctx, cur->info0, ref->info2, version);
725 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown10);
726 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown11);
727 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown12);
728 COMPARE_UINT32(tctx, cur->info0, ref->info2, session_counter);
729 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown14);
730 COMPARE_UINT32(tctx, cur->info0, ref->info2, printer_errors);
731 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown16);
732 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown17);
733 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown18);
734 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown19);
735 COMPARE_UINT32(tctx, cur->info0, ref->info2, change_id);
736 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown21);*/
737 COMPARE_UINT32(tctx, cur->info0, ref->info2, status);
738 /*COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown23);
739 COMPARE_UINT32(tctx, cur->info0, ref->info2, c_setprinter);
740 COMPARE_UINT16(cur->info0, ref->info2, unknown25);
741 COMPARE_UINT16(cur->info0, ref->info2, unknown26);
742 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown27);
743 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown28);
744 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown29);*/
747 /*COMPARE_UINT32(tctx, cur->info1, ref->info2, flags);*/
748 /*COMPARE_STRING(tctx, cur->info1, ref->info2, name);*/
749 /*COMPARE_STRING(tctx, cur->info1, ref->info2, description);*/
750 COMPARE_STRING(tctx, cur->info1, ref->info2, comment);
753 /* level 2 is our reference, and it makes no sense to compare it to itself */
756 COMPARE_STRING(tctx, cur->info4, ref->info2, printername);
757 COMPARE_STRING(tctx, cur->info4, ref->info2, servername);
758 COMPARE_UINT32(tctx, cur->info4, ref->info2, attributes);
761 COMPARE_STRING(tctx, cur->info5, ref->info2, printername);
762 COMPARE_STRING(tctx, cur->info5, ref->info2, portname);
763 COMPARE_UINT32(tctx, cur->info5, ref->info2, attributes);
764 /*COMPARE_UINT32(tctx, cur->info5, ref->info2, device_not_selected_timeout);
765 COMPARE_UINT32(tctx, cur->info5, ref->info2, transmission_retry_timeout);*/
772 * - verify that the port of a printer was in the list returned by EnumPorts
778 static bool test_GetPrinter(struct torture_context *tctx,
779 struct dcerpc_pipe *p,
780 struct policy_handle *handle)
783 struct spoolss_GetPrinter r;
784 uint16_t levels[] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
788 for (i=0;i<ARRAY_SIZE(levels);i++) {
789 r.in.handle = handle;
790 r.in.level = levels[i];
793 r.out.needed = &needed;
795 torture_comment(tctx, "Testing GetPrinter level %u\n", r.in.level);
797 status = dcerpc_spoolss_GetPrinter(p, tctx, &r);
798 torture_assert_ntstatus_ok(tctx, status, "GetPrinter failed");
800 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
801 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
802 data_blob_clear(&blob);
804 r.in.offered = needed;
805 status = dcerpc_spoolss_GetPrinter(p, tctx, &r);
808 torture_assert_ntstatus_ok(tctx, status, "GetPrinter failed");
810 torture_assert_werr_ok(tctx, r.out.result, "GetPrinter failed");
816 static bool test_SetPrinter_errors(struct torture_context *tctx,
817 struct dcerpc_pipe *p,
818 struct policy_handle *handle)
820 struct spoolss_SetPrinter r;
821 uint16_t levels[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
824 struct spoolss_SetPrinterInfoCtr info_ctr;
825 struct spoolss_DevmodeContainer devmode_ctr;
826 struct sec_desc_buf secdesc_ctr;
829 info_ctr.info.info0 = NULL;
831 ZERO_STRUCT(devmode_ctr);
832 ZERO_STRUCT(secdesc_ctr);
834 r.in.handle = handle;
835 r.in.info_ctr = &info_ctr;
836 r.in.devmode_ctr = &devmode_ctr;
837 r.in.secdesc_ctr = &secdesc_ctr;
840 torture_comment(tctx, "Testing SetPrinter all zero\n");
842 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_SetPrinter(p, tctx, &r),
843 "failed to call SetPrinter");
844 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAM,
845 "failed to call SetPrinter");
848 for (i=0; i < ARRAY_SIZE(levels); i++) {
850 struct spoolss_SetPrinterInfo0 info0;
851 struct spoolss_SetPrinterInfo1 info1;
852 struct spoolss_SetPrinterInfo2 info2;
853 struct spoolss_SetPrinterInfo3 info3;
854 struct spoolss_SetPrinterInfo4 info4;
855 struct spoolss_SetPrinterInfo5 info5;
856 struct spoolss_SetPrinterInfo6 info6;
857 struct spoolss_SetPrinterInfo7 info7;
858 struct spoolss_DeviceModeInfo info8;
859 struct spoolss_DeviceModeInfo info9;
862 info_ctr.level = levels[i];
866 info_ctr.info.info0 = &info0;
870 info_ctr.info.info1 = &info1;
874 info_ctr.info.info2 = &info2;
878 info_ctr.info.info3 = &info3;
882 info_ctr.info.info4 = &info4;
886 info_ctr.info.info5 = &info5;
890 info_ctr.info.info6 = &info6;
894 info_ctr.info.info7 = &info7;
898 info_ctr.info.info8 = &info8;
902 info_ctr.info.info9 = &info9;
906 torture_comment(tctx, "Testing SetPrinter level %d, command %d\n",
907 info_ctr.level, r.in.command);
909 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_SetPrinter(p, tctx, &r),
910 "failed to call SetPrinter");
912 switch (r.in.command) {
913 case SPOOLSS_PRINTER_CONTROL_UNPAUSE: /* 0 */
914 /* is ignored for all levels other then 0 */
915 if (info_ctr.level > 0) {
919 case SPOOLSS_PRINTER_CONTROL_PAUSE: /* 1 */
920 case SPOOLSS_PRINTER_CONTROL_RESUME: /* 2 */
921 case SPOOLSS_PRINTER_CONTROL_PURGE: /* 3 */
922 if (info_ctr.level > 0) {
923 /* is invalid for all levels other then 0 */
924 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PRINTER_COMMAND,
925 "unexpected error code returned");
928 torture_assert_werr_ok(tctx, r.out.result,
929 "failed to call SetPrinter with non 0 command");
934 case SPOOLSS_PRINTER_CONTROL_SET_STATUS: /* 4 */
935 /* FIXME: gd needs further investigation */
937 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PRINTER_COMMAND,
938 "unexpected error code returned");
942 switch (info_ctr.level) {
944 torture_assert_werr_equal(tctx, r.out.result, WERR_UNKNOWN_LEVEL,
945 "unexpected error code returned");
948 torture_assert_werr_equal(tctx, r.out.result, WERR_UNKNOWN_PRINTER_DRIVER,
949 "unexpected error code returned");
955 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAM,
956 "unexpected error code returned");
959 torture_assert_werr_equal(tctx, r.out.result, WERR_NOT_SUPPORTED,
960 "unexpected error code returned");
963 torture_assert_werr_ok(tctx, r.out.result,
964 "failed to call SetPrinter");
969 if (r.in.command < 5) {
977 static void clear_info2(struct spoolss_SetPrinterInfoCtr *r)
979 if ((r->level == 2) && (r->info.info2)) {
980 r->info.info2->secdesc = NULL;
981 r->info.info2->devmode = NULL;
985 static bool test_PrinterInfo(struct torture_context *tctx,
986 struct dcerpc_pipe *p,
987 struct policy_handle *handle)
990 struct spoolss_SetPrinter s;
991 struct spoolss_GetPrinter q;
992 struct spoolss_GetPrinter q0;
993 struct spoolss_SetPrinterInfoCtr info_ctr;
994 union spoolss_PrinterInfo info;
995 struct spoolss_DevmodeContainer devmode_ctr;
996 struct sec_desc_buf secdesc_ctr;
1001 uint32_t status_list[] = {
1002 /* these do not stick
1003 PRINTER_STATUS_PAUSED,
1004 PRINTER_STATUS_ERROR,
1005 PRINTER_STATUS_PENDING_DELETION, */
1006 PRINTER_STATUS_PAPER_JAM,
1007 PRINTER_STATUS_PAPER_OUT,
1008 PRINTER_STATUS_MANUAL_FEED,
1009 PRINTER_STATUS_PAPER_PROBLEM,
1010 PRINTER_STATUS_OFFLINE,
1011 PRINTER_STATUS_IO_ACTIVE,
1012 PRINTER_STATUS_BUSY,
1013 PRINTER_STATUS_PRINTING,
1014 PRINTER_STATUS_OUTPUT_BIN_FULL,
1015 PRINTER_STATUS_NOT_AVAILABLE,
1016 PRINTER_STATUS_WAITING,
1017 PRINTER_STATUS_PROCESSING,
1018 PRINTER_STATUS_INITIALIZING,
1019 PRINTER_STATUS_WARMING_UP,
1020 PRINTER_STATUS_TONER_LOW,
1021 PRINTER_STATUS_NO_TONER,
1022 PRINTER_STATUS_PAGE_PUNT,
1023 PRINTER_STATUS_USER_INTERVENTION,
1024 PRINTER_STATUS_OUT_OF_MEMORY,
1025 PRINTER_STATUS_DOOR_OPEN,
1026 PRINTER_STATUS_SERVER_UNKNOWN,
1027 PRINTER_STATUS_POWER_SAVE,
1028 /* these do not stick
1037 uint32_t default_attribute = PRINTER_ATTRIBUTE_LOCAL;
1038 uint32_t attribute_list[] = {
1039 PRINTER_ATTRIBUTE_QUEUED,
1040 /* fails with WERR_INVALID_DATATYPE:
1041 PRINTER_ATTRIBUTE_DIRECT, */
1043 PRINTER_ATTRIBUTE_DEFAULT, */
1044 PRINTER_ATTRIBUTE_SHARED,
1046 PRINTER_ATTRIBUTE_NETWORK, */
1047 PRINTER_ATTRIBUTE_HIDDEN,
1048 PRINTER_ATTRIBUTE_LOCAL,
1049 PRINTER_ATTRIBUTE_ENABLE_DEVQ,
1050 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS,
1051 PRINTER_ATTRIBUTE_DO_COMPLETE_FIRST,
1052 PRINTER_ATTRIBUTE_WORK_OFFLINE,
1054 PRINTER_ATTRIBUTE_ENABLE_BIDI, */
1055 /* fails with WERR_INVALID_DATATYPE:
1056 PRINTER_ATTRIBUTE_RAW_ONLY, */
1057 /* these do not stick
1058 PRINTER_ATTRIBUTE_PUBLISHED,
1059 PRINTER_ATTRIBUTE_FAX,
1060 PRINTER_ATTRIBUTE_TS,
1079 ZERO_STRUCT(devmode_ctr);
1080 ZERO_STRUCT(secdesc_ctr);
1082 s.in.handle = handle;
1084 s.in.info_ctr = &info_ctr;
1085 s.in.devmode_ctr = &devmode_ctr;
1086 s.in.secdesc_ctr = &secdesc_ctr;
1088 q.in.handle = handle;
1092 #define TESTGETCALL(call, r) \
1093 r.in.buffer = NULL; \
1095 r.out.needed = &needed; \
1096 status = dcerpc_spoolss_ ##call(p, tctx, &r); \
1097 if (!NT_STATUS_IS_OK(status)) { \
1098 torture_comment(tctx, #call " level %u failed - %s (%s)\n", \
1099 r.in.level, nt_errstr(status), __location__); \
1103 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {\
1104 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed); \
1105 data_blob_clear(&blob); \
1106 r.in.buffer = &blob; \
1107 r.in.offered = needed; \
1109 status = dcerpc_spoolss_ ##call(p, tctx, &r); \
1110 if (!NT_STATUS_IS_OK(status)) { \
1111 torture_comment(tctx, #call " level %u failed - %s (%s)\n", \
1112 r.in.level, nt_errstr(status), __location__); \
1116 if (!W_ERROR_IS_OK(r.out.result)) { \
1117 torture_comment(tctx, #call " level %u failed - %s (%s)\n", \
1118 r.in.level, win_errstr(r.out.result), __location__); \
1124 #define TESTSETCALL_EXP(call, r, err) \
1125 clear_info2(&info_ctr);\
1126 status = dcerpc_spoolss_ ##call(p, tctx, &r); \
1127 if (!NT_STATUS_IS_OK(status)) { \
1128 torture_comment(tctx, #call " level %u failed - %s (%s)\n", \
1129 r.in.info_ctr->level, nt_errstr(status), __location__); \
1133 if (!W_ERROR_IS_OK(err)) { \
1134 if (!W_ERROR_EQUAL(err, r.out.result)) { \
1135 torture_comment(tctx, #call " level %u failed - %s, expected %s (%s)\n", \
1136 r.in.info_ctr->level, win_errstr(r.out.result), win_errstr(err), __location__); \
1141 if (!W_ERROR_IS_OK(r.out.result)) { \
1142 torture_comment(tctx, #call " level %u failed - %s (%s)\n", \
1143 r.in.info_ctr->level, win_errstr(r.out.result), __location__); \
1148 #define TESTSETCALL(call, r) \
1149 TESTSETCALL_EXP(call, r, WERR_OK)
1151 #define STRING_EQUAL(s1, s2, field) \
1152 if ((s1 && !s2) || (s2 && !s1) || strcmp(s1, s2)) { \
1153 torture_comment(tctx, "Failed to set %s to '%s' (%s)\n", \
1154 #field, s2, __location__); \
1159 #define MEM_EQUAL(s1, s2, length, field) \
1160 if ((s1 && !s2) || (s2 && !s1) || memcmp(s1, s2, length)) { \
1161 torture_comment(tctx, "Failed to set %s to '%s' (%s)\n", \
1162 #field, (const char *)s2, __location__); \
1167 #define INT_EQUAL(i1, i2, field) \
1169 torture_comment(tctx, "Failed to set %s to 0x%llx - got 0x%llx (%s)\n", \
1170 #field, (unsigned long long)i2, (unsigned long long)i1, __location__); \
1175 #define TEST_PRINTERINFO_STRING_EXP_ERR(lvl1, field1, lvl2, field2, value, err) do { \
1176 torture_comment(tctx, "field test %d/%s vs %d/%s\n", lvl1, #field1, lvl2, #field2); \
1177 q.in.level = lvl1; \
1178 TESTGETCALL(GetPrinter, q) \
1179 info_ctr.level = lvl1; \
1180 info_ctr.info.info ## lvl1 = (struct spoolss_SetPrinterInfo ## lvl1 *)&q.out.info->info ## lvl1; \
1181 info_ctr.info.info ## lvl1->field1 = value;\
1182 TESTSETCALL_EXP(SetPrinter, s, err) \
1183 info_ctr.info.info ## lvl1->field1 = ""; \
1184 TESTGETCALL(GetPrinter, q) \
1185 info_ctr.info.info ## lvl1->field1 = value; \
1186 STRING_EQUAL(info_ctr.info.info ## lvl1->field1, value, field1); \
1187 q.in.level = lvl2; \
1188 TESTGETCALL(GetPrinter, q) \
1189 info_ctr.info.info ## lvl2 = (struct spoolss_SetPrinterInfo ## lvl2 *)&q.out.info->info ## lvl2; \
1190 STRING_EQUAL(info_ctr.info.info ## lvl2->field2, value, field2); \
1193 #define TEST_PRINTERINFO_STRING(lvl1, field1, lvl2, field2, value) do { \
1194 TEST_PRINTERINFO_STRING_EXP_ERR(lvl1, field1, lvl2, field2, value, WERR_OK); \
1197 #define TEST_PRINTERINFO_INT_EXP(lvl1, field1, lvl2, field2, value, exp_value) do { \
1198 torture_comment(tctx, "field test %d/%s vs %d/%s\n", lvl1, #field1, lvl2, #field2); \
1199 q.in.level = lvl1; \
1200 TESTGETCALL(GetPrinter, q) \
1201 info_ctr.level = lvl1; \
1202 info_ctr.info.info ## lvl1 = (struct spoolss_SetPrinterInfo ## lvl1 *)&q.out.info->info ## lvl1; \
1203 info_ctr.info.info ## lvl1->field1 = value; \
1204 TESTSETCALL(SetPrinter, s) \
1205 info_ctr.info.info ## lvl1->field1 = 0; \
1206 TESTGETCALL(GetPrinter, q) \
1207 info_ctr.info.info ## lvl1 = (struct spoolss_SetPrinterInfo ## lvl1 *)&q.out.info->info ## lvl1; \
1208 INT_EQUAL(info_ctr.info.info ## lvl1->field1, exp_value, field1); \
1209 q.in.level = lvl2; \
1210 TESTGETCALL(GetPrinter, q) \
1211 info_ctr.info.info ## lvl2 = (struct spoolss_SetPrinterInfo ## lvl2 *)&q.out.info->info ## lvl2; \
1212 INT_EQUAL(info_ctr.info.info ## lvl2->field2, exp_value, field1); \
1215 #define TEST_PRINTERINFO_INT(lvl1, field1, lvl2, field2, value) do { \
1216 TEST_PRINTERINFO_INT_EXP(lvl1, field1, lvl2, field2, value, value); \
1220 do { TESTGETCALL(GetPrinter, q0) } while (0);
1222 TEST_PRINTERINFO_STRING(2, comment, 1, comment, "xx2-1 comment");
1223 TEST_PRINTERINFO_STRING(2, comment, 2, comment, "xx2-2 comment");
1225 /* level 0 printername does not stick */
1226 /* TEST_PRINTERINFO_STRING(2, printername, 0, printername, "xx2-0 printer"); */
1227 TEST_PRINTERINFO_STRING(2, printername, 1, name, "xx2-1 printer");
1228 TEST_PRINTERINFO_STRING(2, printername, 2, printername, "xx2-2 printer");
1229 TEST_PRINTERINFO_STRING(2, printername, 4, printername, "xx2-4 printer");
1230 TEST_PRINTERINFO_STRING(2, printername, 5, printername, "xx2-5 printer");
1231 /* TEST_PRINTERINFO_STRING(4, printername, 0, printername, "xx4-0 printer"); */
1232 TEST_PRINTERINFO_STRING(4, printername, 1, name, "xx4-1 printer");
1233 TEST_PRINTERINFO_STRING(4, printername, 2, printername, "xx4-2 printer");
1234 TEST_PRINTERINFO_STRING(4, printername, 4, printername, "xx4-4 printer");
1235 TEST_PRINTERINFO_STRING(4, printername, 5, printername, "xx4-5 printer");
1236 /* TEST_PRINTERINFO_STRING(5, printername, 0, printername, "xx5-0 printer"); */
1237 TEST_PRINTERINFO_STRING(5, printername, 1, name, "xx5-1 printer");
1238 TEST_PRINTERINFO_STRING(5, printername, 2, printername, "xx5-2 printer");
1239 TEST_PRINTERINFO_STRING(5, printername, 4, printername, "xx5-4 printer");
1240 TEST_PRINTERINFO_STRING(5, printername, 5, printername, "xx5-5 printer");
1242 /* servername can be set but does not stick
1243 TEST_PRINTERINFO_STRING(2, servername, 0, servername, "xx2-0 servername");
1244 TEST_PRINTERINFO_STRING(2, servername, 2, servername, "xx2-2 servername");
1245 TEST_PRINTERINFO_STRING(2, servername, 4, servername, "xx2-4 servername");
1248 /* passing an invalid port will result in WERR_UNKNOWN_PORT */
1249 TEST_PRINTERINFO_STRING_EXP_ERR(2, portname, 2, portname, "xx2-2 portname", WERR_UNKNOWN_PORT);
1250 TEST_PRINTERINFO_STRING_EXP_ERR(2, portname, 5, portname, "xx2-5 portname", WERR_UNKNOWN_PORT);
1251 TEST_PRINTERINFO_STRING_EXP_ERR(5, portname, 2, portname, "xx5-2 portname", WERR_UNKNOWN_PORT);
1252 TEST_PRINTERINFO_STRING_EXP_ERR(5, portname, 5, portname, "xx5-5 portname", WERR_UNKNOWN_PORT);
1254 TEST_PRINTERINFO_STRING(2, sharename, 2, sharename, "xx2-2 sharename");
1255 /* passing an invalid driver will result in WERR_UNKNOWN_PRINTER_DRIVER */
1256 TEST_PRINTERINFO_STRING_EXP_ERR(2, drivername, 2, drivername, "xx2-2 drivername", WERR_UNKNOWN_PRINTER_DRIVER);
1257 TEST_PRINTERINFO_STRING(2, location, 2, location, "xx2-2 location");
1258 /* passing an invalid sepfile will result in WERR_INVALID_SEPARATOR_FILE */
1259 TEST_PRINTERINFO_STRING_EXP_ERR(2, sepfile, 2, sepfile, "xx2-2 sepfile", WERR_INVALID_SEPARATOR_FILE);
1260 /* passing an invalid printprocessor will result in WERR_UNKNOWN_PRINTPROCESSOR */
1261 TEST_PRINTERINFO_STRING_EXP_ERR(2, printprocessor, 2, printprocessor, "xx2-2 printprocessor", WERR_UNKNOWN_PRINTPROCESSOR);
1262 TEST_PRINTERINFO_STRING(2, datatype, 2, datatype, "xx2-2 datatype");
1263 TEST_PRINTERINFO_STRING(2, parameters, 2, parameters, "xx2-2 parameters");
1265 for (i=0; i < ARRAY_SIZE(attribute_list); i++) {
1266 /* TEST_PRINTERINFO_INT_EXP(2, attributes, 1, flags,
1268 (attribute_list[i] | default_attribute)
1270 TEST_PRINTERINFO_INT_EXP(2, attributes, 2, attributes,
1272 (attribute_list[i] | default_attribute)
1274 TEST_PRINTERINFO_INT_EXP(2, attributes, 4, attributes,
1276 (attribute_list[i] | default_attribute)
1278 TEST_PRINTERINFO_INT_EXP(2, attributes, 5, attributes,
1280 (attribute_list[i] | default_attribute)
1282 /* TEST_PRINTERINFO_INT_EXP(4, attributes, 1, flags,
1284 (attribute_list[i] | default_attribute)
1286 TEST_PRINTERINFO_INT_EXP(4, attributes, 2, attributes,
1288 (attribute_list[i] | default_attribute)
1290 TEST_PRINTERINFO_INT_EXP(4, attributes, 4, attributes,
1292 (attribute_list[i] | default_attribute)
1294 TEST_PRINTERINFO_INT_EXP(4, attributes, 5, attributes,
1296 (attribute_list[i] | default_attribute)
1298 /* TEST_PRINTERINFO_INT_EXP(5, attributes, 1, flags,
1300 (attribute_list[i] | default_attribute)
1302 TEST_PRINTERINFO_INT_EXP(5, attributes, 2, attributes,
1304 (attribute_list[i] | default_attribute)
1306 TEST_PRINTERINFO_INT_EXP(5, attributes, 4, attributes,
1308 (attribute_list[i] | default_attribute)
1310 TEST_PRINTERINFO_INT_EXP(5, attributes, 5, attributes,
1312 (attribute_list[i] | default_attribute)
1316 for (i=0; i < ARRAY_SIZE(status_list); i++) {
1317 /* level 2 sets do not stick
1318 TEST_PRINTERINFO_INT(2, status, 0, status, status_list[i]);
1319 TEST_PRINTERINFO_INT(2, status, 2, status, status_list[i]);
1320 TEST_PRINTERINFO_INT(2, status, 6, status, status_list[i]); */
1321 TEST_PRINTERINFO_INT(6, status, 0, status, status_list[i]);
1322 TEST_PRINTERINFO_INT(6, status, 2, status, status_list[i]);
1323 TEST_PRINTERINFO_INT(6, status, 6, status, status_list[i]);
1326 /* priorities need to be between 0 and 99
1327 passing an invalid priority will result in WERR_INVALID_PRIORITY */
1328 TEST_PRINTERINFO_INT(2, priority, 2, priority, 0);
1329 TEST_PRINTERINFO_INT(2, priority, 2, priority, 1);
1330 TEST_PRINTERINFO_INT(2, priority, 2, priority, 99);
1331 /* TEST_PRINTERINFO_INT(2, priority, 2, priority, 100); */
1332 TEST_PRINTERINFO_INT(2, defaultpriority,2, defaultpriority, 0);
1333 TEST_PRINTERINFO_INT(2, defaultpriority,2, defaultpriority, 1);
1334 TEST_PRINTERINFO_INT(2, defaultpriority,2, defaultpriority, 99);
1335 /* TEST_PRINTERINFO_INT(2, defaultpriority,2, defaultpriority, 100); */
1337 TEST_PRINTERINFO_INT(2, starttime, 2, starttime, __LINE__);
1338 TEST_PRINTERINFO_INT(2, untiltime, 2, untiltime, __LINE__);
1341 TEST_PRINTERINFO_INT(2, cjobs, 2, cjobs, __LINE__);
1342 TEST_PRINTERINFO_INT(2, averageppm, 2, averageppm, __LINE__); */
1345 TEST_PRINTERINFO_INT(5, device_not_selected_timeout, 5, device_not_selected_timeout, __LINE__);
1346 TEST_PRINTERINFO_INT(5, transmission_retry_timeout, 5, transmission_retry_timeout, __LINE__); */
1348 /* FIXME: gd also test devmode and secdesc behavior */
1351 /* verify composition of level 1 description field */
1352 const char *description;
1356 do { TESTGETCALL(GetPrinter, q0) } while (0);
1358 description = talloc_strdup(tctx, q0.out.info->info1.description);
1361 do { TESTGETCALL(GetPrinter, q0) } while (0);
1363 tmp = talloc_asprintf(tctx, "%s,%s,%s",
1364 q0.out.info->info2.printername,
1365 q0.out.info->info2.drivername,
1366 q0.out.info->info2.location);
1368 do { STRING_EQUAL(description, tmp, "description")} while (0);
1375 static bool test_ClosePrinter(struct torture_context *tctx,
1376 struct dcerpc_pipe *p,
1377 struct policy_handle *handle)
1380 struct spoolss_ClosePrinter r;
1382 r.in.handle = handle;
1383 r.out.handle = handle;
1385 torture_comment(tctx, "Testing ClosePrinter\n");
1387 status = dcerpc_spoolss_ClosePrinter(p, tctx, &r);
1388 torture_assert_ntstatus_ok(tctx, status, "ClosePrinter failed");
1389 torture_assert_werr_ok(tctx, r.out.result, "ClosePrinter failed");
1394 static bool test_GetForm(struct torture_context *tctx,
1395 struct dcerpc_pipe *p,
1396 struct policy_handle *handle,
1397 const char *form_name,
1401 struct spoolss_GetForm r;
1404 r.in.handle = handle;
1405 r.in.form_name = form_name;
1409 r.out.needed = &needed;
1411 torture_comment(tctx, "Testing GetForm level %d\n", r.in.level);
1413 status = dcerpc_spoolss_GetForm(p, tctx, &r);
1414 torture_assert_ntstatus_ok(tctx, status, "GetForm failed");
1416 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
1417 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
1418 data_blob_clear(&blob);
1419 r.in.buffer = &blob;
1420 r.in.offered = needed;
1421 status = dcerpc_spoolss_GetForm(p, tctx, &r);
1422 torture_assert_ntstatus_ok(tctx, status, "GetForm failed");
1424 torture_assert_werr_ok(tctx, r.out.result, "GetForm failed");
1426 torture_assert(tctx, r.out.info, "No form info returned");
1429 torture_assert_werr_ok(tctx, r.out.result, "GetForm failed");
1434 static bool test_EnumForms(struct torture_context *tctx,
1435 struct dcerpc_pipe *p,
1436 struct policy_handle *handle, bool print_server)
1439 struct spoolss_EnumForms r;
1443 uint32_t levels[] = { 1, 2 };
1446 for (i=0; i<ARRAY_SIZE(levels); i++) {
1448 union spoolss_FormInfo *info;
1450 r.in.handle = handle;
1451 r.in.level = levels[i];
1454 r.out.needed = &needed;
1455 r.out.count = &count;
1458 torture_comment(tctx, "Testing EnumForms level %d\n", levels[i]);
1460 status = dcerpc_spoolss_EnumForms(p, tctx, &r);
1461 torture_assert_ntstatus_ok(tctx, status, "EnumForms failed");
1463 if ((r.in.level == 2) && (W_ERROR_EQUAL(r.out.result, WERR_UNKNOWN_LEVEL))) {
1467 if (print_server && W_ERROR_EQUAL(r.out.result, WERR_BADFID))
1468 torture_fail(tctx, "EnumForms on the PrintServer isn't supported by test server (NT4)");
1470 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
1472 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
1473 data_blob_clear(&blob);
1474 r.in.buffer = &blob;
1475 r.in.offered = needed;
1477 status = dcerpc_spoolss_EnumForms(p, tctx, &r);
1479 torture_assert(tctx, info, "No forms returned");
1481 for (j = 0; j < count; j++) {
1483 ret &= test_GetForm(tctx, p, handle, info[j].info1.form_name, levels[i]);
1487 torture_assert_ntstatus_ok(tctx, status, "EnumForms failed");
1489 torture_assert_werr_ok(tctx, r.out.result, "EnumForms failed");
1495 static bool test_DeleteForm(struct torture_context *tctx,
1496 struct dcerpc_pipe *p,
1497 struct policy_handle *handle,
1498 const char *form_name)
1501 struct spoolss_DeleteForm r;
1503 r.in.handle = handle;
1504 r.in.form_name = form_name;
1506 status = dcerpc_spoolss_DeleteForm(p, tctx, &r);
1508 torture_assert_ntstatus_ok(tctx, status, "DeleteForm failed");
1510 torture_assert_werr_ok(tctx, r.out.result, "DeleteForm failed");
1515 static bool test_AddForm(struct torture_context *tctx,
1516 struct dcerpc_pipe *p,
1517 struct policy_handle *handle, bool print_server)
1519 struct spoolss_AddForm r;
1520 struct spoolss_AddFormInfo1 addform;
1521 const char *form_name = "testform3";
1525 r.in.handle = handle;
1527 r.in.info.info1 = &addform;
1528 addform.flags = SPOOLSS_FORM_USER;
1529 addform.form_name = form_name;
1530 addform.size.width = 50;
1531 addform.size.height = 25;
1532 addform.area.left = 5;
1533 addform.area.top = 10;
1534 addform.area.right = 45;
1535 addform.area.bottom = 15;
1537 status = dcerpc_spoolss_AddForm(p, tctx, &r);
1539 torture_assert_ntstatus_ok(tctx, status, "AddForm failed");
1541 torture_assert_werr_ok(tctx, r.out.result, "AddForm failed");
1543 if (!print_server) ret &= test_GetForm(tctx, p, handle, form_name, 1);
1546 struct spoolss_SetForm sf;
1547 struct spoolss_AddFormInfo1 setform;
1549 sf.in.handle = handle;
1550 sf.in.form_name = form_name;
1552 sf.in.info.info1= &setform;
1553 setform.flags = addform.flags;
1554 setform.form_name = addform.form_name;
1555 setform.size = addform.size;
1556 setform.area = addform.area;
1558 setform.size.width = 1234;
1560 status = dcerpc_spoolss_SetForm(p, tctx, &sf);
1562 torture_assert_ntstatus_ok(tctx, status, "SetForm failed");
1564 torture_assert_werr_ok(tctx, r.out.result, "SetForm failed");
1567 if (!print_server) ret &= test_GetForm(tctx, p, handle, form_name, 1);
1570 struct spoolss_EnumForms e;
1571 union spoolss_FormInfo *info;
1576 e.in.handle = handle;
1580 e.out.needed = &needed;
1581 e.out.count = &count;
1584 torture_comment(tctx, "Testing EnumForms level 1\n");
1586 status = dcerpc_spoolss_EnumForms(p, tctx, &e);
1587 torture_assert_ntstatus_ok(tctx, status, "EnumForms failed");
1589 if (print_server && W_ERROR_EQUAL(e.out.result, WERR_BADFID))
1590 torture_fail(tctx, "EnumForms on the PrintServer isn't supported by test server (NT4)");
1592 if (W_ERROR_EQUAL(e.out.result, WERR_INSUFFICIENT_BUFFER)) {
1594 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
1595 data_blob_clear(&blob);
1596 e.in.buffer = &blob;
1597 e.in.offered = needed;
1599 status = dcerpc_spoolss_EnumForms(p, tctx, &e);
1601 torture_assert(tctx, info, "No forms returned");
1603 for (j = 0; j < count; j++) {
1604 if (strequal(form_name, info[j].info1.form_name)) {
1610 torture_assert(tctx, found, "Newly added form not found in enum call");
1613 if (!test_DeleteForm(tctx, p, handle, form_name)) {
1620 static bool test_EnumPorts_old(struct torture_context *tctx,
1621 struct dcerpc_pipe *p)
1624 struct spoolss_EnumPorts r;
1627 union spoolss_PortInfo *info;
1629 r.in.servername = talloc_asprintf(tctx, "\\\\%s",
1630 dcerpc_server_name(p));
1634 r.out.needed = &needed;
1635 r.out.count = &count;
1638 torture_comment(tctx, "Testing EnumPorts\n");
1640 status = dcerpc_spoolss_EnumPorts(p, tctx, &r);
1642 torture_assert_ntstatus_ok(tctx, status, "EnumPorts failed");
1644 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
1645 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
1646 data_blob_clear(&blob);
1647 r.in.buffer = &blob;
1648 r.in.offered = needed;
1650 status = dcerpc_spoolss_EnumPorts(p, tctx, &r);
1651 torture_assert_ntstatus_ok(tctx, status, "EnumPorts failed");
1652 torture_assert_werr_ok(tctx, r.out.result, "EnumPorts failed");
1654 torture_assert(tctx, info, "No ports returned");
1657 torture_assert_werr_ok(tctx, r.out.result, "EnumPorts failed");
1662 static bool test_AddPort(struct torture_context *tctx,
1663 struct dcerpc_pipe *p)
1666 struct spoolss_AddPort r;
1668 r.in.server_name = talloc_asprintf(tctx, "\\\\%s",
1669 dcerpc_server_name(p));
1671 r.in.monitor_name = "foo";
1673 torture_comment(tctx, "Testing AddPort\n");
1675 status = dcerpc_spoolss_AddPort(p, tctx, &r);
1677 torture_assert_ntstatus_ok(tctx, status, "AddPort failed");
1679 /* win2k3 returns WERR_NOT_SUPPORTED */
1683 if (!W_ERROR_IS_OK(r.out.result)) {
1684 printf("AddPort failed - %s\n", win_errstr(r.out.result));
1693 static bool test_GetJob(struct torture_context *tctx,
1694 struct dcerpc_pipe *p,
1695 struct policy_handle *handle, uint32_t job_id)
1698 struct spoolss_GetJob r;
1699 union spoolss_JobInfo info;
1701 uint32_t levels[] = {1, 2 /* 3, 4 */};
1704 r.in.handle = handle;
1705 r.in.job_id = job_id;
1709 r.out.needed = &needed;
1712 torture_comment(tctx, "Testing GetJob level %d\n", r.in.level);
1714 status = dcerpc_spoolss_GetJob(p, tctx, &r);
1715 torture_assert_werr_equal(tctx, r.out.result, WERR_UNKNOWN_LEVEL, "Unexpected return code");
1717 for (i = 0; i < ARRAY_SIZE(levels); i++) {
1719 torture_comment(tctx, "Testing GetJob level %d\n", r.in.level);
1723 r.in.level = levels[i];
1727 status = dcerpc_spoolss_GetJob(p, tctx, &r);
1728 torture_assert_ntstatus_ok(tctx, status, "GetJob failed");
1730 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
1731 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
1732 data_blob_clear(&blob);
1733 r.in.buffer = &blob;
1734 r.in.offered = needed;
1736 status = dcerpc_spoolss_GetJob(p, tctx, &r);
1737 torture_assert_ntstatus_ok(tctx, status, "GetJob failed");
1740 torture_assert(tctx, r.out.info, "No job info returned");
1741 torture_assert_werr_ok(tctx, r.out.result, "GetJob failed");
1747 static bool test_SetJob(struct torture_context *tctx,
1748 struct dcerpc_pipe *p,
1749 struct policy_handle *handle, uint32_t job_id,
1750 enum spoolss_JobControl command)
1753 struct spoolss_SetJob r;
1755 r.in.handle = handle;
1756 r.in.job_id = job_id;
1758 r.in.command = command;
1761 case SPOOLSS_JOB_CONTROL_PAUSE:
1762 torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_PAUSE\n");
1764 case SPOOLSS_JOB_CONTROL_RESUME:
1765 torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_RESUME\n");
1767 case SPOOLSS_JOB_CONTROL_CANCEL:
1768 torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_CANCEL\n");
1770 case SPOOLSS_JOB_CONTROL_RESTART:
1771 torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_RESTART\n");
1773 case SPOOLSS_JOB_CONTROL_DELETE:
1774 torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_DELETE\n");
1776 case SPOOLSS_JOB_CONTROL_SEND_TO_PRINTER:
1777 torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_SEND_TO_PRINTER\n");
1779 case SPOOLSS_JOB_CONTROL_LAST_PAGE_EJECTED:
1780 torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_LAST_PAGE_EJECTED\n");
1782 case SPOOLSS_JOB_CONTROL_RETAIN:
1783 torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_RETAIN\n");
1785 case SPOOLSS_JOB_CONTROL_RELEASE:
1786 torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_RELEASE\n");
1789 torture_comment(tctx, "Testing SetJob\n");
1793 status = dcerpc_spoolss_SetJob(p, tctx, &r);
1794 torture_assert_ntstatus_ok(tctx, status, "SetJob failed");
1795 torture_assert_werr_ok(tctx, r.out.result, "SetJob failed");
1800 static bool test_AddJob(struct torture_context *tctx,
1801 struct dcerpc_pipe *p,
1802 struct policy_handle *handle)
1805 struct spoolss_AddJob r;
1809 r.in.handle = handle;
1811 r.out.needed = &needed;
1812 r.in.buffer = r.out.buffer = NULL;
1814 torture_comment(tctx, "Testing AddJob\n");
1816 status = dcerpc_spoolss_AddJob(p, tctx, &r);
1817 torture_assert_werr_equal(tctx, r.out.result, WERR_UNKNOWN_LEVEL, "AddJob failed");
1821 status = dcerpc_spoolss_AddJob(p, tctx, &r);
1822 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAM, "AddJob failed");
1828 static bool test_EnumJobs(struct torture_context *tctx,
1829 struct dcerpc_pipe *p,
1830 struct policy_handle *handle)
1833 struct spoolss_EnumJobs r;
1836 union spoolss_JobInfo *info;
1838 r.in.handle = handle;
1840 r.in.numjobs = 0xffffffff;
1844 r.out.needed = &needed;
1845 r.out.count = &count;
1848 torture_comment(tctx, "Testing EnumJobs\n");
1850 status = dcerpc_spoolss_EnumJobs(p, tctx, &r);
1852 torture_assert_ntstatus_ok(tctx, status, "EnumJobs failed");
1854 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
1856 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
1857 data_blob_clear(&blob);
1858 r.in.buffer = &blob;
1859 r.in.offered = needed;
1861 status = dcerpc_spoolss_EnumJobs(p, tctx, &r);
1863 torture_assert_ntstatus_ok(tctx, status, "EnumJobs failed");
1864 torture_assert_werr_ok(tctx, r.out.result, "EnumJobs failed");
1865 torture_assert(tctx, info, "No jobs returned");
1867 for (j = 0; j < count; j++) {
1869 torture_assert(tctx, test_GetJob(tctx, p, handle, info[j].info1.job_id),
1870 "failed to call test_GetJob");
1873 if (!torture_setting_bool(tctx, "samba3", false)) {
1874 test_SetJob(tctx, p, handle, info[j].info1.job_id, SPOOLSS_JOB_CONTROL_PAUSE);
1875 test_SetJob(tctx, p, handle, info[j].info1.job_id, SPOOLSS_JOB_CONTROL_RESUME);
1880 torture_assert_werr_ok(tctx, r.out.result, "EnumJobs failed");
1886 static bool test_DoPrintTest(struct torture_context *tctx,
1887 struct dcerpc_pipe *p,
1888 struct policy_handle *handle)
1892 struct spoolss_StartDocPrinter s;
1893 struct spoolss_DocumentInfo1 info1;
1894 struct spoolss_StartPagePrinter sp;
1895 struct spoolss_WritePrinter w;
1896 struct spoolss_EndPagePrinter ep;
1897 struct spoolss_EndDocPrinter e;
1900 uint32_t num_written;
1902 torture_comment(tctx, "Testing StartDocPrinter\n");
1904 s.in.handle = handle;
1906 s.in.info.info1 = &info1;
1907 s.out.job_id = &job_id;
1908 info1.document_name = "TorturePrintJob";
1909 info1.output_file = NULL;
1910 info1.datatype = "RAW";
1912 status = dcerpc_spoolss_StartDocPrinter(p, tctx, &s);
1913 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_StartDocPrinter failed");
1914 torture_assert_werr_ok(tctx, s.out.result, "StartDocPrinter failed");
1916 for (i=1; i < 4; i++) {
1917 torture_comment(tctx, "Testing StartPagePrinter: Page[%d]\n", i);
1919 sp.in.handle = handle;
1921 status = dcerpc_spoolss_StartPagePrinter(p, tctx, &sp);
1922 torture_assert_ntstatus_ok(tctx, status,
1923 "dcerpc_spoolss_StartPagePrinter failed");
1924 torture_assert_werr_ok(tctx, sp.out.result, "StartPagePrinter failed");
1926 torture_comment(tctx, "Testing WritePrinter: Page[%d]\n", i);
1928 w.in.handle = handle;
1929 w.in.data = data_blob_string_const(talloc_asprintf(tctx,"TortureTestPage: %d\nData\n",i));
1930 w.out.num_written = &num_written;
1932 status = dcerpc_spoolss_WritePrinter(p, tctx, &w);
1933 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_WritePrinter failed");
1934 torture_assert_werr_ok(tctx, w.out.result, "WritePrinter failed");
1936 torture_comment(tctx, "Testing EndPagePrinter: Page[%d]\n", i);
1938 ep.in.handle = handle;
1940 status = dcerpc_spoolss_EndPagePrinter(p, tctx, &ep);
1941 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EndPagePrinter failed");
1942 torture_assert_werr_ok(tctx, ep.out.result, "EndPagePrinter failed");
1945 torture_comment(tctx, "Testing EndDocPrinter\n");
1947 e.in.handle = handle;
1949 status = dcerpc_spoolss_EndDocPrinter(p, tctx, &e);
1950 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EndDocPrinter failed");
1951 torture_assert_werr_ok(tctx, e.out.result, "EndDocPrinter failed");
1953 ret &= test_AddJob(tctx, p, handle);
1954 ret &= test_EnumJobs(tctx, p, handle);
1956 ret &= test_SetJob(tctx, p, handle, job_id, SPOOLSS_JOB_CONTROL_DELETE);
1961 static bool test_PausePrinter(struct torture_context *tctx,
1962 struct dcerpc_pipe *p,
1963 struct policy_handle *handle)
1966 struct spoolss_SetPrinter r;
1967 struct spoolss_SetPrinterInfoCtr info_ctr;
1968 struct spoolss_DevmodeContainer devmode_ctr;
1969 struct sec_desc_buf secdesc_ctr;
1972 info_ctr.info.info0 = NULL;
1974 ZERO_STRUCT(devmode_ctr);
1975 ZERO_STRUCT(secdesc_ctr);
1977 r.in.handle = handle;
1978 r.in.info_ctr = &info_ctr;
1979 r.in.devmode_ctr = &devmode_ctr;
1980 r.in.secdesc_ctr = &secdesc_ctr;
1981 r.in.command = SPOOLSS_PRINTER_CONTROL_PAUSE;
1983 torture_comment(tctx, "Testing SetPrinter: SPOOLSS_PRINTER_CONTROL_PAUSE\n");
1985 status = dcerpc_spoolss_SetPrinter(p, tctx, &r);
1987 torture_assert_ntstatus_ok(tctx, status, "SetPrinter failed");
1989 torture_assert_werr_ok(tctx, r.out.result, "SetPrinter failed");
1994 static bool test_ResumePrinter(struct torture_context *tctx,
1995 struct dcerpc_pipe *p,
1996 struct policy_handle *handle)
1999 struct spoolss_SetPrinter r;
2000 struct spoolss_SetPrinterInfoCtr info_ctr;
2001 struct spoolss_DevmodeContainer devmode_ctr;
2002 struct sec_desc_buf secdesc_ctr;
2005 info_ctr.info.info0 = NULL;
2007 ZERO_STRUCT(devmode_ctr);
2008 ZERO_STRUCT(secdesc_ctr);
2010 r.in.handle = handle;
2011 r.in.info_ctr = &info_ctr;
2012 r.in.devmode_ctr = &devmode_ctr;
2013 r.in.secdesc_ctr = &secdesc_ctr;
2014 r.in.command = SPOOLSS_PRINTER_CONTROL_RESUME;
2016 torture_comment(tctx, "Testing SetPrinter: SPOOLSS_PRINTER_CONTROL_RESUME\n");
2018 status = dcerpc_spoolss_SetPrinter(p, tctx, &r);
2020 torture_assert_ntstatus_ok(tctx, status, "SetPrinter failed");
2022 torture_assert_werr_ok(tctx, r.out.result, "SetPrinter failed");
2027 static bool test_GetPrinterData(struct torture_context *tctx,
2028 struct dcerpc_pipe *p,
2029 struct policy_handle *handle,
2030 const char *value_name,
2031 enum winreg_Type *type_p,
2032 union spoolss_PrinterData *data_p)
2035 struct spoolss_GetPrinterData r;
2037 enum winreg_Type type;
2038 union spoolss_PrinterData data;
2040 r.in.handle = handle;
2041 r.in.value_name = value_name;
2043 r.out.needed = &needed;
2047 torture_comment(tctx, "Testing GetPrinterData(%s)\n", r.in.value_name);
2049 status = dcerpc_spoolss_GetPrinterData(p, tctx, &r);
2050 torture_assert_ntstatus_ok(tctx, status, "GetPrinterData failed");
2052 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
2053 r.in.offered = needed;
2055 status = dcerpc_spoolss_GetPrinterData(p, tctx, &r);
2056 torture_assert_ntstatus_ok(tctx, status, "GetPrinterData failed");
2059 torture_assert_werr_ok(tctx, r.out.result,
2060 talloc_asprintf(tctx, "GetPrinterData(%s) failed", r.in.value_name));
2073 static bool test_GetPrinterDataEx(struct torture_context *tctx,
2074 struct dcerpc_pipe *p,
2075 struct policy_handle *handle,
2076 const char *key_name,
2077 const char *value_name,
2078 enum winreg_Type *type_p,
2079 union spoolss_PrinterData *data_p)
2082 struct spoolss_GetPrinterDataEx r;
2083 enum winreg_Type type;
2085 union spoolss_PrinterData data;
2087 r.in.handle = handle;
2088 r.in.key_name = key_name;
2089 r.in.value_name = value_name;
2092 r.out.needed = &needed;
2095 torture_comment(tctx, "Testing GetPrinterDataEx(%s - %s)\n",
2096 r.in.key_name, r.in.value_name);
2098 status = dcerpc_spoolss_GetPrinterDataEx(p, tctx, &r);
2099 if (!NT_STATUS_IS_OK(status)) {
2100 if (NT_STATUS_EQUAL(status,NT_STATUS_NET_WRITE_FAULT) &&
2101 p->last_fault_code == DCERPC_FAULT_OP_RNG_ERROR) {
2102 torture_skip(tctx, "GetPrinterDataEx not supported by server\n");
2104 torture_assert_ntstatus_ok(tctx, status, "GetPrinterDataEx failed");
2107 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
2108 r.in.offered = needed;
2109 status = dcerpc_spoolss_GetPrinterDataEx(p, tctx, &r);
2110 torture_assert_ntstatus_ok(tctx, status, "GetPrinterDataEx failed");
2113 torture_assert_werr_ok(tctx, r.out.result,
2114 talloc_asprintf(tctx, "GetPrinterDataEx(%s - %s) failed", r.in.key_name, r.in.value_name));
2127 static bool test_GetPrinterData_list(struct torture_context *tctx,
2128 struct dcerpc_pipe *p,
2129 struct policy_handle *handle)
2131 const char *list[] = {
2135 /* "NetPopup", not on w2k8 */
2136 /* "NetPopupToComputer", not on w2k8 */
2139 "DefaultSpoolDirectory",
2143 /* "OSVersionEx", not on s3 */
2148 for (i=0; i < ARRAY_SIZE(list); i++) {
2149 enum winreg_Type type, type_ex;
2150 union spoolss_PrinterData data, data_ex;
2152 torture_assert(tctx, test_GetPrinterData(tctx, p, handle, list[i], &type, &data),
2153 talloc_asprintf(tctx, "GetPrinterData failed on %s\n", list[i]));
2154 torture_assert(tctx, test_GetPrinterDataEx(tctx, p, handle, "random_string", list[i], &type_ex, &data_ex),
2155 talloc_asprintf(tctx, "GetPrinterDataEx failed on %s\n", list[i]));
2156 torture_assert_int_equal(tctx, type, type_ex, "type mismatch");
2159 torture_assert_str_equal(tctx, data.string, data_ex.string, "REG_SZ mismatch");
2162 torture_assert_int_equal(tctx, data.value, data_ex.value, "REG_DWORD mismatch");
2165 torture_assert_data_blob_equal(tctx, data.binary, data_ex.binary, "REG_BINARY mismatch");
2175 static bool test_EnumPrinterData(struct torture_context *tctx, struct dcerpc_pipe *p,
2176 struct policy_handle *handle)
2179 struct spoolss_EnumPrinterData r;
2182 r.in.handle = handle;
2183 r.in.enum_index = 0;
2186 uint32_t value_size = 0;
2187 uint32_t data_size = 0;
2188 enum winreg_Type type = 0;
2190 r.in.value_offered = value_size;
2191 r.out.value_needed = &value_size;
2192 r.in.data_offered = data_size;
2193 r.out.data_needed = &data_size;
2196 r.out.data = talloc_zero_array(tctx, uint8_t, 0);
2198 torture_comment(tctx, "Testing EnumPrinterData\n");
2200 status = dcerpc_spoolss_EnumPrinterData(p, tctx, &r);
2202 torture_assert_ntstatus_ok(tctx, status, "EnumPrinterData failed");
2203 if (W_ERROR_EQUAL(r.out.result, WERR_NO_MORE_ITEMS)) {
2206 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinterData");
2208 r.in.value_offered = value_size;
2209 r.out.value_name = talloc_zero_array(tctx, const char, value_size);
2210 r.in.data_offered = data_size;
2211 r.out.data = talloc_zero_array(tctx, uint8_t, data_size);
2213 status = dcerpc_spoolss_EnumPrinterData(p, tctx, &r);
2215 torture_assert_ntstatus_ok(tctx, status, "EnumPrinterData failed");
2216 if (W_ERROR_EQUAL(r.out.result, WERR_NO_MORE_ITEMS)) {
2220 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinterData failed");
2222 torture_assert(tctx, test_GetPrinterData(tctx, p, handle, r.out.value_name, NULL, NULL),
2223 talloc_asprintf(tctx, "failed to call GetPrinterData for %s\n", r.out.value_name));
2225 torture_assert(tctx, test_GetPrinterDataEx(tctx, p, handle, "PrinterDriverData", r.out.value_name, NULL, NULL),
2226 talloc_asprintf(tctx, "failed to call GetPrinterDataEx on PrinterDriverData for %s\n", r.out.value_name));
2230 } while (W_ERROR_IS_OK(r.out.result));
2235 static bool test_EnumPrinterDataEx(struct torture_context *tctx,
2236 struct dcerpc_pipe *p,
2237 struct policy_handle *handle,
2238 const char *key_name)
2240 struct spoolss_EnumPrinterDataEx r;
2241 struct spoolss_PrinterEnumValues *info;
2245 r.in.handle = handle;
2246 r.in.key_name = key_name;
2248 r.out.needed = &needed;
2249 r.out.count = &count;
2252 torture_comment(tctx, "Testing EnumPrinterDataEx(%s)\n", key_name);
2254 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinterDataEx(p, tctx, &r),
2255 "EnumPrinterDataEx failed");
2256 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
2257 r.in.offered = needed;
2258 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinterDataEx(p, tctx, &r),
2259 "EnumPrinterDataEx failed");
2262 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinterDataEx failed");
2268 static bool test_DeletePrinterData(struct torture_context *tctx,
2269 struct dcerpc_pipe *p,
2270 struct policy_handle *handle,
2271 const char *value_name)
2274 struct spoolss_DeletePrinterData r;
2276 r.in.handle = handle;
2277 r.in.value_name = value_name;
2279 torture_comment(tctx, "Testing DeletePrinterData(%s)\n",
2282 status = dcerpc_spoolss_DeletePrinterData(p, tctx, &r);
2284 torture_assert_ntstatus_ok(tctx, status, "DeletePrinterData failed");
2285 torture_assert_werr_ok(tctx, r.out.result, "DeletePrinterData failed");
2290 static bool test_DeletePrinterDataEx(struct torture_context *tctx,
2291 struct dcerpc_pipe *p,
2292 struct policy_handle *handle,
2293 const char *key_name,
2294 const char *value_name)
2296 struct spoolss_DeletePrinterDataEx r;
2298 r.in.handle = handle;
2299 r.in.key_name = key_name;
2300 r.in.value_name = value_name;
2302 torture_comment(tctx, "Testing DeletePrinterDataEx(%s - %s)\n",
2303 r.in.key_name, r.in.value_name);
2305 torture_assert_ntstatus_ok(tctx,
2306 dcerpc_spoolss_DeletePrinterDataEx(p, tctx, &r),
2307 "DeletePrinterDataEx failed");
2308 torture_assert_werr_ok(tctx, r.out.result,
2309 "DeletePrinterDataEx failed");
2314 static bool test_DeletePrinterKey(struct torture_context *tctx,
2315 struct dcerpc_pipe *p,
2316 struct policy_handle *handle,
2317 const char *key_name)
2319 struct spoolss_DeletePrinterKey r;
2321 r.in.handle = handle;
2322 r.in.key_name = key_name;
2324 torture_comment(tctx, "Testing DeletePrinterKey(%s)\n", r.in.key_name);
2326 if (strequal(key_name, "") && !torture_setting_bool(tctx, "dangerous", false)) {
2327 torture_skip(tctx, "not wiping out printer registry - enable dangerous tests to use\n");
2331 torture_assert_ntstatus_ok(tctx,
2332 dcerpc_spoolss_DeletePrinterKey(p, tctx, &r),
2333 "DeletePrinterKey failed");
2334 torture_assert_werr_ok(tctx, r.out.result,
2335 "DeletePrinterKey failed");
2340 static bool test_SetPrinterData(struct torture_context *tctx,
2341 struct dcerpc_pipe *p,
2342 struct policy_handle *handle)
2345 struct spoolss_SetPrinterData r;
2346 const char *values[] = {
2350 /* FIXME: not working with s3 atm. */
2356 /* FIXME: not working with s3 atm. */
2363 for (i=0; i < ARRAY_SIZE(values); i++) {
2365 enum winreg_Type type;
2366 union spoolss_PrinterData data;
2368 r.in.handle = handle;
2369 r.in.value_name = values[i];
2371 r.in.data.string = "dog";
2373 torture_comment(tctx, "Testing SetPrinterData(%s)\n",
2376 status = dcerpc_spoolss_SetPrinterData(p, tctx, &r);
2378 torture_assert_ntstatus_ok(tctx, status, "SetPrinterData failed");
2379 torture_assert_werr_ok(tctx, r.out.result, "SetPrinterData failed");
2381 if (!test_GetPrinterData(tctx, p, handle, r.in.value_name, &type, &data)) {
2385 torture_assert_int_equal(tctx, r.in.type, type, "type mismatch");
2386 torture_assert_str_equal(tctx, r.in.data.string, data.string, "data mismatch");
2388 if (!test_DeletePrinterData(tctx, p, handle, r.in.value_name)) {
2396 static bool test_EnumPrinterKey(struct torture_context *tctx,
2397 struct dcerpc_pipe *p,
2398 struct policy_handle *handle,
2399 const char *key_name,
2400 const char ***array);
2402 static bool test_SetPrinterDataEx(struct torture_context *tctx,
2403 struct dcerpc_pipe *p,
2404 struct policy_handle *handle)
2407 struct spoolss_SetPrinterDataEx r;
2408 const char *value_name = "dog";
2409 const char *keys[] = {
2413 /* FIXME: not working with s3 atm. */
2414 "torturedataex_with_subkey\\subkey",
2415 "torturedataex_with_subkey\\subkey:0",
2416 "torturedataex_with_subkey\\subkey:1",
2417 "torturedataex_with_subkey\\subkey\\subsubkey",
2418 "torturedataex_with_subkey\\subkey\\subsubkey:0",
2419 "torturedataex_with_subkey\\subkey\\subsubkey:1",
2423 /* FIXME: not working with s3 atm. */
2431 DATA_BLOB blob = data_blob_string_const("catfoobar");
2434 for (i=0; i < ARRAY_SIZE(keys); i++) {
2438 enum winreg_Type type;
2439 const char **subkeys;
2440 union spoolss_PrinterData data;
2442 r.in.handle = handle;
2443 r.in.key_name = keys[i];
2444 r.in.value_name = value_name;
2445 r.in.type = REG_BINARY;
2446 r.in.data.binary = blob;
2448 torture_comment(tctx, "Testing SetPrinterDataEx(%s - %s)\n", r.in.key_name, value_name);
2450 status = dcerpc_spoolss_SetPrinterDataEx(p, tctx, &r);
2452 torture_assert_ntstatus_ok(tctx, status, "SetPrinterDataEx failed");
2453 torture_assert_werr_ok(tctx, r.out.result, "SetPrinterDataEx failed");
2455 key = talloc_strdup(tctx, r.in.key_name);
2457 if (!test_GetPrinterDataEx(tctx, p, handle, r.in.key_name, value_name, &type, &data)) {
2461 torture_assert_int_equal(tctx, r.in.type, type, "type mismatch");
2462 torture_assert_data_blob_equal(tctx, blob, data.binary, "data mismatch");
2464 if (!test_EnumPrinterDataEx(tctx, p, handle, r.in.key_name)) {
2468 if (!test_DeletePrinterDataEx(tctx, p, handle, r.in.key_name, value_name)) {
2472 c = strchr(key, '\\');
2476 /* we have subkeys */
2480 if (!test_EnumPrinterKey(tctx, p, handle, key, &subkeys)) {
2484 for (i=0; subkeys && subkeys[i]; i++) {
2486 const char *current_key = talloc_asprintf(tctx, "%s\\%s", key, subkeys[i]);
2488 if (!test_DeletePrinterKey(tctx, p, handle, current_key)) {
2493 if (!test_DeletePrinterKey(tctx, p, handle, key)) {
2498 if (!test_DeletePrinterKey(tctx, p, handle, key)) {
2508 static bool test_SecondaryClosePrinter(struct torture_context *tctx,
2509 struct dcerpc_pipe *p,
2510 struct policy_handle *handle)
2513 struct dcerpc_binding *b;
2514 struct dcerpc_pipe *p2;
2515 struct spoolss_ClosePrinter cp;
2517 /* only makes sense on SMB */
2518 if (p->conn->transport.transport != NCACN_NP) {
2522 torture_comment(tctx, "testing close on secondary pipe\n");
2524 status = dcerpc_parse_binding(tctx, p->conn->binding_string, &b);
2525 torture_assert_ntstatus_ok(tctx, status, "Failed to parse dcerpc binding");
2527 status = dcerpc_secondary_connection(p, &p2, b);
2528 torture_assert_ntstatus_ok(tctx, status, "Failed to create secondary connection");
2530 status = dcerpc_bind_auth_none(p2, &ndr_table_spoolss);
2531 torture_assert_ntstatus_ok(tctx, status, "Failed to create bind on secondary connection");
2533 cp.in.handle = handle;
2534 cp.out.handle = handle;
2536 status = dcerpc_spoolss_ClosePrinter(p2, tctx, &cp);
2537 torture_assert_ntstatus_equal(tctx, status, NT_STATUS_NET_WRITE_FAULT,
2538 "ERROR: Allowed close on secondary connection");
2540 torture_assert_int_equal(tctx, p2->last_fault_code, DCERPC_FAULT_CONTEXT_MISMATCH,
2541 "Unexpected fault code");
2548 static bool test_OpenPrinter_badname(struct torture_context *tctx,
2549 struct dcerpc_pipe *p, const char *name)
2552 struct spoolss_OpenPrinter op;
2553 struct spoolss_OpenPrinterEx opEx;
2554 struct policy_handle handle;
2557 op.in.printername = name;
2558 op.in.datatype = NULL;
2559 op.in.devmode_ctr.devmode= NULL;
2560 op.in.access_mask = 0;
2561 op.out.handle = &handle;
2563 torture_comment(tctx, "\nTesting OpenPrinter(%s) with bad name\n", op.in.printername);
2565 status = dcerpc_spoolss_OpenPrinter(p, tctx, &op);
2566 torture_assert_ntstatus_ok(tctx, status, "OpenPrinter failed");
2567 if (!W_ERROR_EQUAL(WERR_INVALID_PRINTER_NAME,op.out.result)) {
2568 torture_comment(tctx, "OpenPrinter(%s) unexpected result[%s] should be WERR_INVALID_PRINTER_NAME\n",
2569 name, win_errstr(op.out.result));
2572 if (W_ERROR_IS_OK(op.out.result)) {
2573 ret &=test_ClosePrinter(tctx, p, &handle);
2576 opEx.in.printername = name;
2577 opEx.in.datatype = NULL;
2578 opEx.in.devmode_ctr.devmode = NULL;
2579 opEx.in.access_mask = 0;
2581 opEx.in.userlevel.level1 = NULL;
2582 opEx.out.handle = &handle;
2584 torture_comment(tctx, "Testing OpenPrinterEx(%s) with bad name\n", opEx.in.printername);
2586 status = dcerpc_spoolss_OpenPrinterEx(p, tctx, &opEx);
2587 torture_assert_ntstatus_ok(tctx, status, "OpenPrinterEx failed");
2588 if (!W_ERROR_EQUAL(WERR_INVALID_PARAM,opEx.out.result)) {
2589 torture_comment(tctx, "OpenPrinterEx(%s) unexpected result[%s] should be WERR_INVALID_PARAM\n",
2590 name, win_errstr(opEx.out.result));
2593 if (W_ERROR_IS_OK(opEx.out.result)) {
2594 ret &=test_ClosePrinter(tctx, p, &handle);
2600 static bool test_OpenPrinter(struct torture_context *tctx,
2601 struct dcerpc_pipe *p,
2605 struct spoolss_OpenPrinter r;
2606 struct policy_handle handle;
2609 r.in.printername = talloc_asprintf(tctx, "\\\\%s\\%s", dcerpc_server_name(p), name);
2610 r.in.datatype = NULL;
2611 r.in.devmode_ctr.devmode= NULL;
2612 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2613 r.out.handle = &handle;
2615 torture_comment(tctx, "Testing OpenPrinter(%s)\n", r.in.printername);
2617 status = dcerpc_spoolss_OpenPrinter(p, tctx, &r);
2619 torture_assert_ntstatus_ok(tctx, status, "OpenPrinter failed");
2621 torture_assert_werr_ok(tctx, r.out.result, "OpenPrinter failed");
2623 if (!test_GetPrinter(tctx, p, &handle)) {
2627 if (!torture_setting_bool(tctx, "samba3", false)) {
2628 if (!test_SecondaryClosePrinter(tctx, p, &handle)) {
2633 if (!test_ClosePrinter(tctx, p, &handle)) {
2640 static bool call_OpenPrinterEx(struct torture_context *tctx,
2641 struct dcerpc_pipe *p,
2642 const char *name, struct policy_handle *handle)
2644 struct spoolss_OpenPrinterEx r;
2645 struct spoolss_UserLevel1 userlevel1;
2648 if (name && name[0]) {
2649 r.in.printername = talloc_asprintf(tctx, "\\\\%s\\%s",
2650 dcerpc_server_name(p), name);
2652 r.in.printername = talloc_asprintf(tctx, "\\\\%s",
2653 dcerpc_server_name(p));
2656 r.in.datatype = NULL;
2657 r.in.devmode_ctr.devmode= NULL;
2658 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2660 r.in.userlevel.level1 = &userlevel1;
2661 r.out.handle = handle;
2663 userlevel1.size = 1234;
2664 userlevel1.client = "hello";
2665 userlevel1.user = "spottyfoot!";
2666 userlevel1.build = 1;
2667 userlevel1.major = 2;
2668 userlevel1.minor = 3;
2669 userlevel1.processor = 4;
2671 torture_comment(tctx, "Testing OpenPrinterEx(%s)\n", r.in.printername);
2673 status = dcerpc_spoolss_OpenPrinterEx(p, tctx, &r);
2675 torture_assert_ntstatus_ok(tctx, status, "OpenPrinterEx failed");
2677 torture_assert_werr_ok(tctx, r.out.result, "OpenPrinterEx failed");
2682 static bool test_OpenPrinterEx(struct torture_context *tctx,
2683 struct dcerpc_pipe *p,
2686 struct policy_handle handle;
2689 if (!call_OpenPrinterEx(tctx, p, name, &handle)) {
2693 if (!test_GetPrinter(tctx, p, &handle)) {
2697 if (!test_EnumForms(tctx, p, &handle, false)) {
2701 if (!test_AddForm(tctx, p, &handle, false)) {
2705 if (!test_EnumPrinterData(tctx, p, &handle)) {
2709 if (!test_EnumPrinterDataEx(tctx, p, &handle, "PrinterDriverData")) {
2713 if (!test_printer_keys(tctx, p, &handle)) {
2717 if (!test_PausePrinter(tctx, p, &handle)) {
2721 if (!test_DoPrintTest(tctx, p, &handle)) {
2725 if (!test_ResumePrinter(tctx, p, &handle)) {
2729 if (!test_SetPrinterData(tctx, p, &handle)) {
2733 if (!test_SetPrinterDataEx(tctx, p, &handle)) {
2737 if (!torture_setting_bool(tctx, "samba3", false)) {
2738 if (!test_SecondaryClosePrinter(tctx, p, &handle)) {
2743 if (!test_ClosePrinter(tctx, p, &handle)) {
2750 static bool test_EnumPrinters_old(struct torture_context *tctx, struct dcerpc_pipe *p)
2752 struct spoolss_EnumPrinters r;
2754 uint16_t levels[] = {1, 2, 4, 5};
2758 for (i=0;i<ARRAY_SIZE(levels);i++) {
2759 union spoolss_PrinterInfo *info;
2764 r.in.flags = PRINTER_ENUM_LOCAL;
2766 r.in.level = levels[i];
2769 r.out.needed = &needed;
2770 r.out.count = &count;
2773 torture_comment(tctx, "Testing EnumPrinters level %u\n", r.in.level);
2775 status = dcerpc_spoolss_EnumPrinters(p, tctx, &r);
2776 torture_assert_ntstatus_ok(tctx, status, "EnumPrinters failed");
2778 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
2779 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
2780 data_blob_clear(&blob);
2781 r.in.buffer = &blob;
2782 r.in.offered = needed;
2783 status = dcerpc_spoolss_EnumPrinters(p, tctx, &r);
2786 torture_assert_ntstatus_ok(tctx, status, "EnumPrinters failed");
2788 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinters failed");
2791 torture_comment(tctx, "No printers returned\n");
2795 for (j=0;j<count;j++) {
2796 if (r.in.level == 1) {
2797 char *unc = talloc_strdup(tctx, info[j].info1.name);
2800 if (unc[0] == '\\' && unc[1] == '\\') {
2803 slash = strchr(unc, '\\');
2808 if (!test_OpenPrinter(tctx, p, name)) {
2811 if (!test_OpenPrinterEx(tctx, p, name)) {
2821 static bool test_GetPrinterDriver(struct torture_context *tctx,
2822 struct dcerpc_pipe *p,
2823 struct policy_handle *handle,
2824 const char *driver_name)
2826 struct spoolss_GetPrinterDriver r;
2829 r.in.handle = handle;
2830 r.in.architecture = "W32X86";
2834 r.out.needed = &needed;
2836 torture_comment(tctx, "Testing GetPrinterDriver level %d\n", r.in.level);
2838 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_GetPrinterDriver(p, tctx, &r),
2839 "failed to call GetPrinterDriver");
2840 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
2841 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
2842 data_blob_clear(&blob);
2843 r.in.buffer = &blob;
2844 r.in.offered = needed;
2845 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_GetPrinterDriver(p, tctx, &r),
2846 "failed to call GetPrinterDriver");
2849 torture_assert_werr_ok(tctx, r.out.result,
2850 "failed to call GetPrinterDriver");
2855 static bool test_GetPrinterDriver2(struct torture_context *tctx,
2856 struct dcerpc_pipe *p,
2857 struct policy_handle *handle,
2858 const char *driver_name)
2860 struct spoolss_GetPrinterDriver2 r;
2862 uint32_t server_major_version;
2863 uint32_t server_minor_version;
2865 r.in.handle = handle;
2866 r.in.architecture = "W32X86";
2870 r.in.client_major_version = 0;
2871 r.in.client_minor_version = 0;
2872 r.out.needed = &needed;
2873 r.out.server_major_version = &server_major_version;
2874 r.out.server_minor_version = &server_minor_version;
2876 torture_comment(tctx, "Testing GetPrinterDriver2 level %d\n", r.in.level);
2878 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_GetPrinterDriver2(p, tctx, &r),
2879 "failed to call GetPrinterDriver2");
2880 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
2881 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
2882 data_blob_clear(&blob);
2883 r.in.buffer = &blob;
2884 r.in.offered = needed;
2885 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_GetPrinterDriver2(p, tctx, &r),
2886 "failed to call GetPrinterDriver2");
2889 torture_assert_werr_ok(tctx, r.out.result,
2890 "failed to call GetPrinterDriver2");
2895 static bool test_EnumPrinterDrivers_old(struct torture_context *tctx,
2896 struct dcerpc_pipe *p)
2898 struct spoolss_EnumPrinterDrivers r;
2900 uint16_t levels[] = {1, 2, 3, 4, 5, 6};
2903 for (i=0;i<ARRAY_SIZE(levels);i++) {
2907 union spoolss_DriverInfo *info;
2909 r.in.server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
2910 r.in.environment = SPOOLSS_ARCHITECTURE_NT_X86;
2911 r.in.level = levels[i];
2914 r.out.needed = &needed;
2915 r.out.count = &count;
2918 torture_comment(tctx, "Testing EnumPrinterDrivers level %u\n", r.in.level);
2920 status = dcerpc_spoolss_EnumPrinterDrivers(p, tctx, &r);
2922 torture_assert_ntstatus_ok(tctx, status, "EnumPrinterDrivers failed");
2924 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
2925 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
2926 data_blob_clear(&blob);
2927 r.in.buffer = &blob;
2928 r.in.offered = needed;
2929 status = dcerpc_spoolss_EnumPrinterDrivers(p, tctx, &r);
2932 torture_assert_ntstatus_ok(tctx, status, "EnumPrinterDrivers failed");
2934 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinterDrivers failed");
2937 torture_comment(tctx, "No printer drivers returned\n");
2945 static bool test_DeletePrinter(struct torture_context *tctx,
2946 struct dcerpc_pipe *p,
2947 struct policy_handle *handle)
2949 struct spoolss_DeletePrinter r;
2951 torture_comment(tctx, "Testing DeletePrinter\n");
2953 r.in.handle = handle;
2955 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_DeletePrinter(p, tctx, &r),
2956 "failed to delete printer");
2957 torture_assert_werr_ok(tctx, r.out.result,
2958 "failed to delete printer");
2963 static bool test_EnumPrinters_findname(struct torture_context *tctx,
2964 struct dcerpc_pipe *p,
2970 struct spoolss_EnumPrinters e;
2972 union spoolss_PrinterInfo *info;
2983 e.out.count = &count;
2985 e.out.needed = &needed;
2987 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinters(p, tctx, &e),
2988 "failed to enum printers");
2990 if (W_ERROR_EQUAL(e.out.result, WERR_INSUFFICIENT_BUFFER)) {
2991 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
2992 data_blob_clear(&blob);
2993 e.in.buffer = &blob;
2994 e.in.offered = needed;
2996 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinters(p, tctx, &e),
2997 "failed to enum printers");
3000 torture_assert_werr_ok(tctx, e.out.result,
3001 "failed to enum printers");
3003 for (i=0; i < count; i++) {
3005 const char *current = NULL;
3009 current = info[i].info1.name;
3013 if (strequal(current, name)) {
3022 static bool test_AddPrinter_wellknown(struct torture_context *tctx,
3023 struct dcerpc_pipe *p,
3024 const char *printername,
3028 struct spoolss_AddPrinter r;
3029 struct spoolss_AddPrinterEx rex;
3030 struct spoolss_SetPrinterInfoCtr info_ctr;
3031 struct spoolss_SetPrinterInfo1 info1;
3032 struct spoolss_DevmodeContainer devmode_ctr;
3033 struct sec_desc_buf secdesc_ctr;
3034 struct spoolss_UserLevelCtr userlevel_ctr;
3035 struct policy_handle handle;
3038 ZERO_STRUCT(devmode_ctr);
3039 ZERO_STRUCT(secdesc_ctr);
3040 ZERO_STRUCT(userlevel_ctr);
3043 torture_comment(tctx, "Testing AddPrinter%s level 1\n", ex ? "Ex":"");
3045 /* try to add printer to wellknown printer list (level 1) */
3047 userlevel_ctr.level = 1;
3049 info_ctr.info.info1 = &info1;
3052 rex.in.server = NULL;
3053 rex.in.info_ctr = &info_ctr;
3054 rex.in.devmode_ctr = &devmode_ctr;
3055 rex.in.secdesc_ctr = &secdesc_ctr;
3056 rex.in.userlevel_ctr = &userlevel_ctr;
3057 rex.out.handle = &handle;
3060 r.in.info_ctr = &info_ctr;
3061 r.in.devmode_ctr = &devmode_ctr;
3062 r.in.secdesc_ctr = &secdesc_ctr;
3063 r.out.handle = &handle;
3065 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx(p, tctx, &rex) :
3066 dcerpc_spoolss_AddPrinter(p, tctx, &r),
3067 "failed to add printer");
3068 result = ex ? rex.out.result : r.out.result;
3069 torture_assert_werr_equal(tctx, result, WERR_INVALID_PRINTER_NAME,
3070 "unexpected result code");
3072 info1.name = printername;
3073 info1.flags = PRINTER_ATTRIBUTE_SHARED;
3075 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx(p, tctx, &rex) :
3076 dcerpc_spoolss_AddPrinter(p, tctx, &r),
3077 "failed to add printer");
3078 result = ex ? rex.out.result : r.out.result;
3079 torture_assert_werr_equal(tctx, result, WERR_PRINTER_ALREADY_EXISTS,
3080 "unexpected result code");
3082 /* bizarre protocol, WERR_PRINTER_ALREADY_EXISTS means success here,
3083 better do a real check to see the printer is really there */
3085 torture_assert(tctx, test_EnumPrinters_findname(tctx, p,
3086 PRINTER_ENUM_NETWORK, 1,
3089 "failed to enum printers");
3091 torture_assert(tctx, found, "failed to find newly added printer");
3095 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx(p, tctx, &rex) :
3096 dcerpc_spoolss_AddPrinter(p, tctx, &r),
3097 "failed to add printer");
3098 result = ex ? rex.out.result : r.out.result;
3099 torture_assert_werr_equal(tctx, result, WERR_PRINTER_ALREADY_EXISTS,
3100 "unexpected result code");
3102 /* bizarre protocol, WERR_PRINTER_ALREADY_EXISTS means success here,
3103 better do a real check to see the printer has really been removed
3104 from the well known printer list */
3108 torture_assert(tctx, test_EnumPrinters_findname(tctx, p,
3109 PRINTER_ENUM_NETWORK, 1,
3112 "failed to enum printers");
3114 torture_assert(tctx, !found, "printer still in well known printer list");
3119 static bool test_AddPrinter_normal(struct torture_context *tctx,
3120 struct dcerpc_pipe *p,
3121 struct policy_handle *handle_p,
3122 const char *printername,
3123 const char *drivername,
3124 const char *portname,
3128 struct spoolss_AddPrinter r;
3129 struct spoolss_AddPrinterEx rex;
3130 struct spoolss_SetPrinterInfoCtr info_ctr;
3131 struct spoolss_SetPrinterInfo2 info2;
3132 struct spoolss_DevmodeContainer devmode_ctr;
3133 struct sec_desc_buf secdesc_ctr;
3134 struct spoolss_UserLevelCtr userlevel_ctr;
3135 struct policy_handle handle;
3138 ZERO_STRUCT(devmode_ctr);
3139 ZERO_STRUCT(secdesc_ctr);
3140 ZERO_STRUCT(userlevel_ctr);
3142 torture_comment(tctx, "Testing AddPrinter%s level 2\n", ex ? "Ex":"");
3144 userlevel_ctr.level = 1;
3146 rex.in.server = NULL;
3147 rex.in.info_ctr = &info_ctr;
3148 rex.in.devmode_ctr = &devmode_ctr;
3149 rex.in.secdesc_ctr = &secdesc_ctr;
3150 rex.in.userlevel_ctr = &userlevel_ctr;
3151 rex.out.handle = &handle;
3154 r.in.info_ctr = &info_ctr;
3155 r.in.devmode_ctr = &devmode_ctr;
3156 r.in.secdesc_ctr = &secdesc_ctr;
3157 r.out.handle = &handle;
3161 /* try to add printer to printer list (level 2) */
3165 info_ctr.info.info2 = &info2;
3168 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx(p, tctx, &rex) :
3169 dcerpc_spoolss_AddPrinter(p, tctx, &r),
3170 "failed to add printer");
3171 result = ex ? rex.out.result : r.out.result;
3172 torture_assert_werr_equal(tctx, result, WERR_INVALID_PRINTER_NAME,
3173 "unexpected result code");
3175 info2.printername = printername;
3177 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx(p, tctx, &rex) :
3178 dcerpc_spoolss_AddPrinter(p, tctx, &r),
3179 "failed to add printer");
3180 result = ex ? rex.out.result : r.out.result;
3182 if (W_ERROR_EQUAL(result, WERR_PRINTER_ALREADY_EXISTS)) {
3183 struct policy_handle printer_handle;
3185 torture_assert(tctx, call_OpenPrinterEx(tctx, p, printername, &printer_handle),
3186 "failed to open printer handle");
3188 torture_assert(tctx, test_DeletePrinter(tctx, p, &printer_handle),
3189 "failed to delete printer");
3191 torture_assert(tctx, test_ClosePrinter(tctx, p, &printer_handle),
3192 "failed to close server handle");
3197 torture_assert_werr_equal(tctx, result, WERR_UNKNOWN_PORT,
3198 "unexpected result code");
3200 info2.portname = portname;
3202 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx(p, tctx, &rex) :
3203 dcerpc_spoolss_AddPrinter(p, tctx, &r),
3204 "failed to add printer");
3205 result = ex ? rex.out.result : r.out.result;
3206 torture_assert_werr_equal(tctx, result, WERR_UNKNOWN_PRINTER_DRIVER,
3207 "unexpected result code");
3209 info2.drivername = drivername;
3211 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx(p, tctx, &rex) :
3212 dcerpc_spoolss_AddPrinter(p, tctx, &r),
3213 "failed to add printer");
3214 result = ex ? rex.out.result : r.out.result;
3215 torture_assert_werr_equal(tctx, result, WERR_UNKNOWN_PRINTPROCESSOR,
3216 "unexpected result code");
3218 info2.printprocessor = "winprint";
3220 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx(p, tctx, &rex) :
3221 dcerpc_spoolss_AddPrinter(p, tctx, &r),
3222 "failed to add printer");
3223 result = ex ? rex.out.result : r.out.result;
3224 torture_assert_werr_ok(tctx, result,
3225 "failed to add printer");
3229 /* we are paranoid, really check if the printer is there now */
3231 torture_assert(tctx, test_EnumPrinters_findname(tctx, p,
3232 PRINTER_ENUM_LOCAL, 1,
3235 "failed to enum printers");
3236 torture_assert(tctx, found, "failed to find newly added printer");
3238 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx(p, tctx, &rex) :
3239 dcerpc_spoolss_AddPrinter(p, tctx, &r),
3240 "failed to add printer");
3241 result = ex ? rex.out.result : r.out.result;
3242 torture_assert_werr_equal(tctx, result, WERR_PRINTER_ALREADY_EXISTS,
3243 "unexpected result code");
3248 static bool test_AddPrinterEx(struct torture_context *tctx,
3249 struct dcerpc_pipe *p,
3250 struct policy_handle *handle_p,
3251 const char *printername,
3252 const char *drivername,
3253 const char *portname)
3257 if (!torture_setting_bool(tctx, "samba3", false)) {
3258 if (!test_AddPrinter_wellknown(tctx, p, TORTURE_WELLKNOWN_PRINTER_EX, true)) {
3259 torture_comment(tctx, "failed to add printer to well known list\n");
3264 if (!test_AddPrinter_normal(tctx, p, handle_p,
3265 printername, drivername, portname,
3267 torture_comment(tctx, "failed to add printer to printer list\n");
3274 static bool test_AddPrinter(struct torture_context *tctx,
3275 struct dcerpc_pipe *p,
3276 struct policy_handle *handle_p,
3277 const char *printername,
3278 const char *drivername,
3279 const char *portname)
3283 if (!torture_setting_bool(tctx, "samba3", false)) {
3284 if (!test_AddPrinter_wellknown(tctx, p, TORTURE_WELLKNOWN_PRINTER, false)) {
3285 torture_comment(tctx, "failed to add printer to well known list\n");
3290 if (!test_AddPrinter_normal(tctx, p, handle_p,
3291 printername, drivername, portname,
3293 torture_comment(tctx, "failed to add printer to printer list\n");
3300 static bool test_printer_info(struct torture_context *tctx,
3301 struct dcerpc_pipe *p,
3302 struct policy_handle *handle)
3306 if (!test_PrinterInfo(tctx, p, handle)) {
3310 if (!test_SetPrinter_errors(tctx, p, handle)) {
3317 static bool test_EnumPrinterKey(struct torture_context *tctx,
3318 struct dcerpc_pipe *p,
3319 struct policy_handle *handle,
3320 const char *key_name,
3321 const char ***array)
3323 struct spoolss_EnumPrinterKey r;
3325 struct spoolss_StringArray2 key_buffer;
3327 r.in.handle = handle;
3328 r.in.key_name = key_name;
3330 r.out.key_buffer = &key_buffer;
3331 r.out.needed = &needed;
3333 torture_comment(tctx, "Testing EnumPrinterKey(%s)\n", r.in.key_name);
3335 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinterKey(p, tctx, &r),
3336 "failed to call EnumPrinterKey");
3337 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
3338 torture_assert(tctx, (key_buffer._ndr_size == 0),
3339 talloc_asprintf(tctx, "EnumPrinterKey did not return 0 _ndr_size (but %d), windows clients would abort here!", key_buffer._ndr_size));
3340 r.in.offered = needed;
3341 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinterKey(p, tctx, &r),
3342 "failed to call EnumPrinterKey");
3344 torture_assert_werr_ok(tctx, r.out.result,
3345 "failed to call EnumPrinterKey");
3347 torture_assert(tctx, (key_buffer._ndr_size * 2 == needed),
3348 talloc_asprintf(tctx, "EnumPrinterKey size mismatch, _ndr_size %d (expected %d)",
3349 key_buffer._ndr_size, needed/2));
3352 *array = key_buffer.string;
3358 bool test_printer_keys(struct torture_context *tctx,
3359 struct dcerpc_pipe *p,
3360 struct policy_handle *handle)
3362 const char **key_array = NULL;
3365 torture_assert(tctx, test_EnumPrinterKey(tctx, p, handle, "", &key_array),
3366 "failed to call test_EnumPrinterKey");
3368 for (i=0; key_array && key_array[i]; i++) {
3369 torture_assert(tctx, test_EnumPrinterKey(tctx, p, handle, key_array[i], NULL),
3370 "failed to call test_EnumPrinterKey");
3372 for (i=0; key_array && key_array[i]; i++) {
3373 torture_assert(tctx, test_EnumPrinterDataEx(tctx, p, handle, key_array[i]),
3374 "failed to call test_EnumPrinterDataEx");
3380 static bool test_printer(struct torture_context *tctx,
3381 struct dcerpc_pipe *p)
3384 struct policy_handle handle[2];
3386 const char *drivername = "Microsoft XPS Document Writer";
3387 const char *portname = "LPT1:";
3389 /* test printer created via AddPrinter */
3391 if (!test_AddPrinter(tctx, p, &handle[0], TORTURE_PRINTER, drivername, portname)) {
3395 if (!test_printer_info(tctx, p, &handle[0])) {
3399 if (!test_printer_keys(tctx, p, &handle[0])) {
3403 if (!test_DeletePrinter(tctx, p, &handle[0])) {
3407 if (!test_EnumPrinters_findname(tctx, p, PRINTER_ENUM_LOCAL, 1,
3408 TORTURE_PRINTER, &found)) {
3412 torture_assert(tctx, !found, "deleted printer still there");
3414 /* test printer created via AddPrinterEx */
3416 if (!test_AddPrinterEx(tctx, p, &handle[1], TORTURE_PRINTER_EX, drivername, portname)) {
3420 if (!test_printer_info(tctx, p, &handle[1])) {
3424 if (!test_printer_keys(tctx, p, &handle[1])) {
3428 if (!test_DeletePrinter(tctx, p, &handle[1])) {
3432 if (!test_EnumPrinters_findname(tctx, p, PRINTER_ENUM_LOCAL, 1,
3433 TORTURE_PRINTER_EX, &found)) {
3437 torture_assert(tctx, !found, "deleted printer still there");
3442 bool torture_rpc_spoolss(struct torture_context *torture)
3445 struct dcerpc_pipe *p;
3447 struct test_spoolss_context *ctx;
3449 status = torture_rpc_connection(torture, &p, &ndr_table_spoolss);
3450 if (!NT_STATUS_IS_OK(status)) {
3454 ctx = talloc_zero(torture, struct test_spoolss_context);
3456 ret &= test_OpenPrinter_server(torture, p, &ctx->server_handle);
3457 ret &= test_GetPrinterData_list(torture, p, &ctx->server_handle);
3458 ret &= test_EnumForms(torture, p, &ctx->server_handle, true);
3459 ret &= test_AddForm(torture, p, &ctx->server_handle, true);
3460 ret &= test_EnumPorts(torture, p, ctx);
3461 ret &= test_GetPrinterDriverDirectory(torture, p, ctx);
3462 ret &= test_GetPrintProcessorDirectory(torture, p, ctx);
3463 ret &= test_EnumPrinterDrivers(torture, p, ctx, SPOOLSS_ARCHITECTURE_NT_X86);
3464 ret &= test_EnumPrinterDrivers(torture, p, ctx, SPOOLSS_ARCHITECTURE_ALL);
3465 ret &= test_EnumMonitors(torture, p, ctx);
3466 ret &= test_EnumPrintProcessors(torture, p, ctx);
3467 ret &= test_EnumPrintProcDataTypes(torture, p, ctx);
3468 ret &= test_EnumPrinters(torture, p, ctx);
3469 ret &= test_OpenPrinter_badname(torture, p, "__INVALID_PRINTER__");
3470 ret &= test_OpenPrinter_badname(torture, p, "\\\\__INVALID_HOST__");
3471 ret &= test_OpenPrinter_badname(torture, p, "");
3472 ret &= test_OpenPrinter_badname(torture, p, "\\\\\\");
3473 ret &= test_OpenPrinter_badname(torture, p, "\\\\\\__INVALID_PRINTER__");
3474 ret &= test_OpenPrinter_badname(torture, p, talloc_asprintf(torture, "\\\\%s\\", dcerpc_server_name(p)));
3475 ret &= test_OpenPrinter_badname(torture, p,
3476 talloc_asprintf(torture, "\\\\%s\\__INVALID_PRINTER__", dcerpc_server_name(p)));
3479 ret &= test_AddPort(torture, p);
3480 ret &= test_EnumPorts_old(torture, p);
3481 ret &= test_EnumPrinters_old(torture, p);
3482 ret &= test_EnumPrinterDrivers_old(torture, p);
3487 struct torture_suite *torture_rpc_spoolss_printer(TALLOC_CTX *mem_ctx)
3489 struct torture_suite *suite = torture_suite_create(mem_ctx, "SPOOLSS-PRINTER");
3491 struct torture_rpc_tcase *tcase = torture_suite_add_rpc_iface_tcase(suite,
3492 "printer", &ndr_table_spoolss);
3494 torture_rpc_tcase_add_test(tcase, "printer", test_printer);