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];
111 union spoolss_PortInfo *info;
113 r.in.servername = "";
117 r.out.needed = &needed;
118 r.out.count = &count;
121 torture_comment(tctx, "Testing EnumPorts level %u\n", r.in.level);
123 status = dcerpc_spoolss_EnumPorts(p, ctx, &r);
124 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPorts failed");
125 if (W_ERROR_IS_OK(r.out.result)) {
126 /* TODO: do some more checks here */
129 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
130 "EnumPorts unexpected return code");
132 blob = data_blob_talloc(ctx, NULL, needed);
133 data_blob_clear(&blob);
135 r.in.offered = needed;
137 status = dcerpc_spoolss_EnumPorts(p, ctx, &r);
138 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPorts failed");
140 torture_assert_werr_ok(tctx, r.out.result, "EnumPorts failed");
142 torture_assert(tctx, info, "EnumPorts returned no info");
144 ctx->port_count[level] = count;
145 ctx->ports[level] = info;
148 for (i=1;i<ARRAY_SIZE(levels);i++) {
149 int level = levels[i];
150 int old_level = levels[i-1];
151 torture_assert_int_equal(tctx, ctx->port_count[level], ctx->port_count[old_level],
152 "EnumPorts invalid value");
154 /* if the array sizes are not the same we would maybe segfault in the following code */
156 for (i=0;i<ARRAY_SIZE(levels);i++) {
157 int level = levels[i];
158 for (j=0;j<ctx->port_count[level];j++) {
159 union spoolss_PortInfo *cur = &ctx->ports[level][j];
160 union spoolss_PortInfo *ref = &ctx->ports[2][j];
163 COMPARE_STRING(tctx, cur->info1, ref->info2, port_name);
166 /* level 2 is our reference, and it makes no sense to compare it to itself */
175 static bool test_GetPrintProcessorDirectory(struct torture_context *tctx,
176 struct dcerpc_pipe *p,
177 struct test_spoolss_context *ctx)
180 struct spoolss_GetPrintProcessorDirectory r;
195 .server = talloc_asprintf(ctx, "\\\\%s", dcerpc_server_name(p))
198 .server = talloc_asprintf(ctx, "\\\\%s", dcerpc_server_name(p))
204 for (i=0;i<ARRAY_SIZE(levels);i++) {
205 int level = levels[i].level;
208 r.in.server = levels[i].server;
209 r.in.environment = SPOOLSS_ARCHITECTURE_NT_X86;
213 r.out.needed = &needed;
215 torture_comment(tctx, "Testing GetPrintProcessorDirectory level %u\n", r.in.level);
217 status = dcerpc_spoolss_GetPrintProcessorDirectory(p, ctx, &r);
218 torture_assert_ntstatus_ok(tctx, status,
219 "dcerpc_spoolss_GetPrintProcessorDirectory failed");
220 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
221 "GetPrintProcessorDirectory unexpected return code");
223 blob = data_blob_talloc(ctx, NULL, needed);
224 data_blob_clear(&blob);
226 r.in.offered = needed;
228 status = dcerpc_spoolss_GetPrintProcessorDirectory(p, ctx, &r);
229 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_GetPrintProcessorDirectory failed");
231 torture_assert_werr_ok(tctx, r.out.result, "GetPrintProcessorDirectory failed");
238 static bool test_GetPrinterDriverDirectory(struct torture_context *tctx,
239 struct dcerpc_pipe *p,
240 struct test_spoolss_context *ctx)
243 struct spoolss_GetPrinterDriverDirectory r;
258 .server = talloc_asprintf(ctx, "\\\\%s", dcerpc_server_name(p))
261 .server = talloc_asprintf(ctx, "\\\\%s", dcerpc_server_name(p))
267 for (i=0;i<ARRAY_SIZE(levels);i++) {
268 int level = levels[i].level;
271 r.in.server = levels[i].server;
272 r.in.environment = SPOOLSS_ARCHITECTURE_NT_X86;
276 r.out.needed = &needed;
278 torture_comment(tctx, "Testing GetPrinterDriverDirectory level %u\n", r.in.level);
280 status = dcerpc_spoolss_GetPrinterDriverDirectory(p, ctx, &r);
281 torture_assert_ntstatus_ok(tctx, status,
282 "dcerpc_spoolss_GetPrinterDriverDirectory failed");
283 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
284 "GetPrinterDriverDirectory unexpected return code");
286 blob = data_blob_talloc(ctx, NULL, needed);
287 data_blob_clear(&blob);
289 r.in.offered = needed;
291 status = dcerpc_spoolss_GetPrinterDriverDirectory(p, ctx, &r);
292 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_GetPrinterDriverDirectory failed");
294 torture_assert_werr_ok(tctx, r.out.result, "GetPrinterDriverDirectory failed");
300 static bool test_EnumPrinterDrivers(struct torture_context *tctx,
301 struct dcerpc_pipe *p,
302 struct test_spoolss_context *ctx)
305 struct spoolss_EnumPrinterDrivers r;
306 uint16_t levels[] = { 1, 2, 3, 4, 5, 6 };
309 for (i=0;i<ARRAY_SIZE(levels);i++) {
310 int level = levels[i];
314 union spoolss_DriverInfo *info;
316 /* FIXME: gd, come back and fix "" as server, and handle
317 * priority of returned error codes in torture test and samba 3
320 r.in.server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
321 r.in.environment = SPOOLSS_ARCHITECTURE_NT_X86;
325 r.out.needed = &needed;
326 r.out.count = &count;
329 torture_comment(tctx, "Testing EnumPrinterDrivers level %u\n", r.in.level);
331 status = dcerpc_spoolss_EnumPrinterDrivers(p, ctx, &r);
332 torture_assert_ntstatus_ok(tctx, status,
333 "dcerpc_spoolss_EnumPrinterDrivers failed");
334 if (W_ERROR_IS_OK(r.out.result)) {
335 /* TODO: do some more checks here */
338 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
339 blob = data_blob_talloc(ctx, NULL, needed);
340 data_blob_clear(&blob);
342 r.in.offered = needed;
344 status = dcerpc_spoolss_EnumPrinterDrivers(p, ctx, &r);
345 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrinterDrivers failed");
348 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinterDrivers failed");
350 ctx->driver_count[level] = count;
351 ctx->drivers[level] = info;
354 for (i=1;i<ARRAY_SIZE(levels);i++) {
355 int level = levels[i];
356 int old_level = levels[i-1];
357 torture_assert_int_equal(tctx, ctx->driver_count[level], ctx->driver_count[old_level],
358 "EnumPrinterDrivers invalid value");
361 for (i=0;i<ARRAY_SIZE(levels);i++) {
362 int level = levels[i];
363 for (j=0;j<ctx->driver_count[level];j++) {
364 union spoolss_DriverInfo *cur = &ctx->drivers[level][j];
365 union spoolss_DriverInfo *ref = &ctx->drivers[6][j];
368 COMPARE_STRING(tctx, cur->info1, ref->info6, driver_name);
371 COMPARE_UINT32(tctx, cur->info2, ref->info6, version);
372 COMPARE_STRING(tctx, cur->info2, ref->info6, driver_name);
373 COMPARE_STRING(tctx, cur->info2, ref->info6, architecture);
374 COMPARE_STRING(tctx, cur->info2, ref->info6, driver_path);
375 COMPARE_STRING(tctx, cur->info2, ref->info6, data_file);
376 COMPARE_STRING(tctx, cur->info2, ref->info6, config_file);
379 COMPARE_UINT32(tctx, cur->info3, ref->info6, version);
380 COMPARE_STRING(tctx, cur->info3, ref->info6, driver_name);
381 COMPARE_STRING(tctx, cur->info3, ref->info6, architecture);
382 COMPARE_STRING(tctx, cur->info3, ref->info6, driver_path);
383 COMPARE_STRING(tctx, cur->info3, ref->info6, data_file);
384 COMPARE_STRING(tctx, cur->info3, ref->info6, config_file);
385 COMPARE_STRING(tctx, cur->info3, ref->info6, help_file);
386 COMPARE_STRING_ARRAY(tctx, cur->info3, ref->info6, dependent_files);
387 COMPARE_STRING(tctx, cur->info3, ref->info6, monitor_name);
388 COMPARE_STRING(tctx, cur->info3, ref->info6, default_datatype);
391 COMPARE_UINT32(tctx, cur->info4, ref->info6, version);
392 COMPARE_STRING(tctx, cur->info4, ref->info6, driver_name);
393 COMPARE_STRING(tctx, cur->info4, ref->info6, architecture);
394 COMPARE_STRING(tctx, cur->info4, ref->info6, driver_path);
395 COMPARE_STRING(tctx, cur->info4, ref->info6, data_file);
396 COMPARE_STRING(tctx, cur->info4, ref->info6, config_file);
397 COMPARE_STRING(tctx, cur->info4, ref->info6, help_file);
398 COMPARE_STRING_ARRAY(tctx, cur->info4, ref->info6, dependent_files);
399 COMPARE_STRING(tctx, cur->info4, ref->info6, monitor_name);
400 COMPARE_STRING(tctx, cur->info4, ref->info6, default_datatype);
401 COMPARE_STRING_ARRAY(tctx, cur->info4, ref->info6, previous_names);
404 COMPARE_UINT32(tctx, cur->info5, ref->info6, version);
405 COMPARE_STRING(tctx, cur->info5, ref->info6, driver_name);
406 COMPARE_STRING(tctx, cur->info5, ref->info6, architecture);
407 COMPARE_STRING(tctx, cur->info5, ref->info6, driver_path);
408 COMPARE_STRING(tctx, cur->info5, ref->info6, data_file);
409 COMPARE_STRING(tctx, cur->info5, ref->info6, config_file);
410 /*COMPARE_UINT32(tctx, cur->info5, ref->info6, driver_attributes);*/
411 /*COMPARE_UINT32(tctx, cur->info5, ref->info6, config_version);*/
412 /*TODO: ! COMPARE_UINT32(tctx, cur->info5, ref->info6, driver_version); */
415 /* level 6 is our reference, and it makes no sense to compare it to itself */
424 static bool test_EnumMonitors(struct torture_context *tctx,
425 struct dcerpc_pipe *p,
426 struct test_spoolss_context *ctx)
429 struct spoolss_EnumMonitors r;
430 uint16_t levels[] = { 1, 2 };
433 for (i=0;i<ARRAY_SIZE(levels);i++) {
434 int level = levels[i];
438 union spoolss_MonitorInfo *info;
440 r.in.servername = "";
444 r.out.needed = &needed;
445 r.out.count = &count;
448 torture_comment(tctx, "Testing EnumMonitors level %u\n", r.in.level);
450 status = dcerpc_spoolss_EnumMonitors(p, ctx, &r);
451 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumMonitors failed");
452 if (W_ERROR_IS_OK(r.out.result)) {
453 /* TODO: do some more checks here */
456 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
457 "EnumMonitors failed");
459 blob = data_blob_talloc(ctx, NULL, needed);
460 data_blob_clear(&blob);
462 r.in.offered = needed;
464 status = dcerpc_spoolss_EnumMonitors(p, ctx, &r);
465 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumMonitors failed");
467 torture_assert_werr_ok(tctx, r.out.result, "EnumMonitors failed");
469 ctx->monitor_count[level] = count;
470 ctx->monitors[level] = info;
473 for (i=1;i<ARRAY_SIZE(levels);i++) {
474 int level = levels[i];
475 int old_level = levels[i-1];
476 torture_assert_int_equal(tctx, ctx->monitor_count[level], ctx->monitor_count[old_level],
477 "EnumMonitors invalid value");
480 for (i=0;i<ARRAY_SIZE(levels);i++) {
481 int level = levels[i];
482 for (j=0;j<ctx->monitor_count[level];j++) {
483 union spoolss_MonitorInfo *cur = &ctx->monitors[level][j];
484 union spoolss_MonitorInfo *ref = &ctx->monitors[2][j];
487 COMPARE_STRING(tctx, cur->info1, ref->info2, monitor_name);
490 /* level 2 is our reference, and it makes no sense to compare it to itself */
499 static bool test_EnumPrintProcessors(struct torture_context *tctx,
500 struct dcerpc_pipe *p,
501 struct test_spoolss_context *ctx)
504 struct spoolss_EnumPrintProcessors r;
505 uint16_t levels[] = { 1 };
508 for (i=0;i<ARRAY_SIZE(levels);i++) {
509 int level = levels[i];
513 union spoolss_PrintProcessorInfo *info;
515 r.in.servername = "";
516 r.in.environment = "Windows NT x86";
520 r.out.needed = &needed;
521 r.out.count = &count;
524 torture_comment(tctx, "Testing EnumPrintProcessors level %u\n", r.in.level);
526 status = dcerpc_spoolss_EnumPrintProcessors(p, ctx, &r);
527 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrintProcessors failed");
528 if (W_ERROR_IS_OK(r.out.result)) {
529 /* TODO: do some more checks here */
532 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
533 "EnumPrintProcessors unexpected return code");
535 blob = data_blob_talloc(ctx, NULL, needed);
536 data_blob_clear(&blob);
538 r.in.offered = needed;
540 status = dcerpc_spoolss_EnumPrintProcessors(p, ctx, &r);
541 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrintProcessors failed");
543 torture_assert_werr_ok(tctx, r.out.result, "EnumPrintProcessors failed");
545 ctx->print_processor_count[level] = count;
546 ctx->print_processors[level] = info;
549 for (i=1;i<ARRAY_SIZE(levels);i++) {
550 int level = levels[i];
551 int old_level = levels[i-1];
552 torture_assert_int_equal(tctx, ctx->print_processor_count[level], ctx->print_processor_count[old_level],
553 "EnumPrintProcessors failed");
556 for (i=0;i<ARRAY_SIZE(levels);i++) {
557 int level = levels[i];
558 for (j=0;j<ctx->print_processor_count[level];j++) {
560 union spoolss_PrintProcessorInfo *cur = &ctx->print_processors[level][j];
561 union spoolss_PrintProcessorInfo *ref = &ctx->print_processors[1][j];
565 /* level 1 is our reference, and it makes no sense to compare it to itself */
574 static bool test_EnumPrintProcDataTypes(struct torture_context *tctx,
575 struct dcerpc_pipe *p,
576 struct test_spoolss_context *ctx)
579 struct spoolss_EnumPrintProcDataTypes r;
580 uint16_t levels[] = { 1 };
583 for (i=0;i<ARRAY_SIZE(levels);i++) {
584 int level = levels[i];
588 union spoolss_PrintProcDataTypesInfo *info;
590 r.in.servername = "";
591 r.in.print_processor_name = "winprint";
595 r.out.needed = &needed;
596 r.out.count = &count;
599 torture_comment(tctx, "Testing EnumPrintProcDataTypes level %u\n", r.in.level);
601 status = dcerpc_spoolss_EnumPrintProcDataTypes(p, ctx, &r);
602 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrintProcDataType failed");
603 if (W_ERROR_IS_OK(r.out.result)) {
604 /* TODO: do some more checks here */
607 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
608 "EnumPrintProcDataTypes unexpected return code");
610 blob = data_blob_talloc(ctx, NULL, needed);
611 data_blob_clear(&blob);
613 r.in.offered = needed;
615 status = dcerpc_spoolss_EnumPrintProcDataTypes(p, ctx, &r);
616 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrintProcDataTypes failed");
618 torture_assert_werr_ok(tctx, r.out.result, "EnumPrintProcDataTypes failed");
625 static bool test_EnumPrinters(struct torture_context *tctx,
626 struct dcerpc_pipe *p,
627 struct test_spoolss_context *ctx)
629 struct spoolss_EnumPrinters r;
631 uint16_t levels[] = { 0, 1, 2, 4, 5 };
634 for (i=0;i<ARRAY_SIZE(levels);i++) {
635 int level = levels[i];
639 union spoolss_PrinterInfo *info;
641 r.in.flags = PRINTER_ENUM_LOCAL;
646 r.out.needed = &needed;
647 r.out.count = &count;
650 torture_comment(tctx, "Testing EnumPrinters level %u\n", r.in.level);
652 status = dcerpc_spoolss_EnumPrinters(p, ctx, &r);
653 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrinters failed");
654 if (W_ERROR_IS_OK(r.out.result)) {
655 /* TODO: do some more checks here */
658 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
659 "EnumPrinters unexpected return code");
661 blob = data_blob_talloc(ctx, NULL, needed);
662 data_blob_clear(&blob);
664 r.in.offered = needed;
666 status = dcerpc_spoolss_EnumPrinters(p, ctx, &r);
667 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrinters failed");
669 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinters failed");
671 ctx->printer_count[level] = count;
672 ctx->printers[level] = info;
675 for (i=1;i<ARRAY_SIZE(levels);i++) {
676 int level = levels[i];
677 int old_level = levels[i-1];
678 torture_assert_int_equal(tctx, ctx->printer_count[level], ctx->printer_count[old_level],
679 "EnumPrinters invalid value");
682 for (i=0;i<ARRAY_SIZE(levels);i++) {
683 int level = levels[i];
684 for (j=0;j<ctx->printer_count[level];j++) {
685 union spoolss_PrinterInfo *cur = &ctx->printers[level][j];
686 union spoolss_PrinterInfo *ref = &ctx->printers[2][j];
689 COMPARE_STRING(tctx, cur->info0, ref->info2, printername);
690 COMPARE_STRING(tctx, cur->info0, ref->info2, servername);
691 COMPARE_UINT32(tctx, cur->info0, ref->info2, cjobs);
692 /*COMPARE_UINT32(tctx, cur->info0, ref->info2, total_jobs);
693 COMPARE_UINT32(tctx, cur->info0, ref->info2, total_bytes);
694 COMPARE_SPOOLSS_TIME(cur->info0, ref->info2, spoolss_Time time);
695 COMPARE_UINT32(tctx, cur->info0, ref->info2, global_counter);
696 COMPARE_UINT32(tctx, cur->info0, ref->info2, total_pages);
697 COMPARE_UINT32(tctx, cur->info0, ref->info2, version);
698 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown10);
699 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown11);
700 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown12);
701 COMPARE_UINT32(tctx, cur->info0, ref->info2, session_counter);
702 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown14);
703 COMPARE_UINT32(tctx, cur->info0, ref->info2, printer_errors);
704 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown16);
705 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown17);
706 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown18);
707 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown19);
708 COMPARE_UINT32(tctx, cur->info0, ref->info2, change_id);
709 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown21);*/
710 COMPARE_UINT32(tctx, cur->info0, ref->info2, status);
711 /*COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown23);
712 COMPARE_UINT32(tctx, cur->info0, ref->info2, c_setprinter);
713 COMPARE_UINT16(cur->info0, ref->info2, unknown25);
714 COMPARE_UINT16(cur->info0, ref->info2, unknown26);
715 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown27);
716 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown28);
717 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown29);*/
720 /*COMPARE_UINT32(tctx, cur->info1, ref->info2, flags);*/
721 /*COMPARE_STRING(tctx, cur->info1, ref->info2, name);*/
722 /*COMPARE_STRING(tctx, cur->info1, ref->info2, description);*/
723 COMPARE_STRING(tctx, cur->info1, ref->info2, comment);
726 /* level 2 is our reference, and it makes no sense to compare it to itself */
729 COMPARE_STRING(tctx, cur->info4, ref->info2, printername);
730 COMPARE_STRING(tctx, cur->info4, ref->info2, servername);
731 COMPARE_UINT32(tctx, cur->info4, ref->info2, attributes);
734 COMPARE_STRING(tctx, cur->info5, ref->info2, printername);
735 COMPARE_STRING(tctx, cur->info5, ref->info2, portname);
736 COMPARE_UINT32(tctx, cur->info5, ref->info2, attributes);
737 /*COMPARE_UINT32(tctx, cur->info5, ref->info2, device_not_selected_timeout);
738 COMPARE_UINT32(tctx, cur->info5, ref->info2, transmission_retry_timeout);*/
745 * - verify that the port of a printer was in the list returned by EnumPorts
751 static bool test_GetPrinter(struct torture_context *tctx,
752 struct dcerpc_pipe *p,
753 struct policy_handle *handle)
756 struct spoolss_GetPrinter r;
757 uint16_t levels[] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
761 for (i=0;i<ARRAY_SIZE(levels);i++) {
762 r.in.handle = handle;
763 r.in.level = levels[i];
766 r.out.needed = &needed;
768 torture_comment(tctx, "Testing GetPrinter level %u\n", r.in.level);
770 status = dcerpc_spoolss_GetPrinter(p, tctx, &r);
771 torture_assert_ntstatus_ok(tctx, status, "GetPrinter failed");
773 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
774 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
775 data_blob_clear(&blob);
777 r.in.offered = needed;
778 status = dcerpc_spoolss_GetPrinter(p, tctx, &r);
781 torture_assert_ntstatus_ok(tctx, status, "GetPrinter failed");
783 torture_assert_werr_ok(tctx, r.out.result, "GetPrinter failed");
790 static bool test_ClosePrinter(struct torture_context *tctx,
791 struct dcerpc_pipe *p,
792 struct policy_handle *handle)
795 struct spoolss_ClosePrinter r;
797 r.in.handle = handle;
798 r.out.handle = handle;
800 torture_comment(tctx, "Testing ClosePrinter\n");
802 status = dcerpc_spoolss_ClosePrinter(p, tctx, &r);
803 torture_assert_ntstatus_ok(tctx, status, "ClosePrinter failed");
808 static bool test_GetForm(struct torture_context *tctx,
809 struct dcerpc_pipe *p,
810 struct policy_handle *handle,
811 const char *form_name,
815 struct spoolss_GetForm r;
818 r.in.handle = handle;
819 r.in.form_name = form_name;
823 r.out.needed = &needed;
825 torture_comment(tctx, "Testing GetForm level %d\n", r.in.level);
827 status = dcerpc_spoolss_GetForm(p, tctx, &r);
828 torture_assert_ntstatus_ok(tctx, status, "GetForm failed");
830 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
831 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
832 data_blob_clear(&blob);
834 r.in.offered = needed;
835 status = dcerpc_spoolss_GetForm(p, tctx, &r);
836 torture_assert_ntstatus_ok(tctx, status, "GetForm failed");
838 torture_assert_werr_ok(tctx, r.out.result, "GetForm failed");
840 torture_assert(tctx, r.out.info, "No form info returned");
843 torture_assert_werr_ok(tctx, r.out.result, "GetForm failed");
848 static bool test_EnumForms(struct torture_context *tctx,
849 struct dcerpc_pipe *p,
850 struct policy_handle *handle, bool print_server)
853 struct spoolss_EnumForms r;
857 uint32_t levels[] = { 1, 2 };
860 for (i=0; i<ARRAY_SIZE(levels); i++) {
862 union spoolss_FormInfo *info;
864 r.in.handle = handle;
865 r.in.level = levels[i];
868 r.out.needed = &needed;
869 r.out.count = &count;
872 torture_comment(tctx, "Testing EnumForms level %d\n", levels[i]);
874 status = dcerpc_spoolss_EnumForms(p, tctx, &r);
875 torture_assert_ntstatus_ok(tctx, status, "EnumForms failed");
877 if ((r.in.level == 2) && (W_ERROR_EQUAL(r.out.result, WERR_UNKNOWN_LEVEL))) {
881 if (print_server && W_ERROR_EQUAL(r.out.result, WERR_BADFID))
882 torture_fail(tctx, "EnumForms on the PrintServer isn't supported by test server (NT4)");
884 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
886 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
887 data_blob_clear(&blob);
889 r.in.offered = needed;
891 status = dcerpc_spoolss_EnumForms(p, tctx, &r);
893 torture_assert(tctx, info, "No forms returned");
895 for (j = 0; j < count; j++) {
897 ret &= test_GetForm(tctx, p, handle, info[j].info1.form_name, levels[i]);
901 torture_assert_ntstatus_ok(tctx, status, "EnumForms failed");
903 torture_assert_werr_ok(tctx, r.out.result, "EnumForms failed");
909 static bool test_DeleteForm(struct torture_context *tctx,
910 struct dcerpc_pipe *p,
911 struct policy_handle *handle,
912 const char *form_name)
915 struct spoolss_DeleteForm r;
917 r.in.handle = handle;
918 r.in.form_name = form_name;
920 status = dcerpc_spoolss_DeleteForm(p, tctx, &r);
922 torture_assert_ntstatus_ok(tctx, status, "DeleteForm failed");
924 torture_assert_werr_ok(tctx, r.out.result, "DeleteForm failed");
929 static bool test_AddForm(struct torture_context *tctx,
930 struct dcerpc_pipe *p,
931 struct policy_handle *handle, bool print_server)
933 struct spoolss_AddForm r;
934 struct spoolss_AddFormInfo1 addform;
935 const char *form_name = "testform3";
939 r.in.handle = handle;
941 r.in.info.info1 = &addform;
942 addform.flags = SPOOLSS_FORM_USER;
943 addform.form_name = form_name;
944 addform.size.width = 50;
945 addform.size.height = 25;
946 addform.area.left = 5;
947 addform.area.top = 10;
948 addform.area.right = 45;
949 addform.area.bottom = 15;
951 status = dcerpc_spoolss_AddForm(p, tctx, &r);
953 torture_assert_ntstatus_ok(tctx, status, "AddForm failed");
955 torture_assert_werr_ok(tctx, r.out.result, "AddForm failed");
957 if (!print_server) ret &= test_GetForm(tctx, p, handle, form_name, 1);
960 struct spoolss_SetForm sf;
961 struct spoolss_AddFormInfo1 setform;
963 sf.in.handle = handle;
964 sf.in.form_name = form_name;
966 sf.in.info.info1= &setform;
967 setform.flags = addform.flags;
968 setform.form_name = addform.form_name;
969 setform.size = addform.size;
970 setform.area = addform.area;
972 setform.size.width = 1234;
974 status = dcerpc_spoolss_SetForm(p, tctx, &sf);
976 torture_assert_ntstatus_ok(tctx, status, "SetForm failed");
978 torture_assert_werr_ok(tctx, r.out.result, "SetForm failed");
981 if (!print_server) ret &= test_GetForm(tctx, p, handle, form_name, 1);
983 if (!test_DeleteForm(tctx, p, handle, form_name)) {
990 static bool test_EnumPorts_old(struct torture_context *tctx,
991 struct dcerpc_pipe *p)
994 struct spoolss_EnumPorts r;
997 union spoolss_PortInfo *info;
999 r.in.servername = talloc_asprintf(tctx, "\\\\%s",
1000 dcerpc_server_name(p));
1004 r.out.needed = &needed;
1005 r.out.count = &count;
1008 torture_comment(tctx, "Testing EnumPorts\n");
1010 status = dcerpc_spoolss_EnumPorts(p, tctx, &r);
1012 torture_assert_ntstatus_ok(tctx, status, "EnumPorts failed");
1014 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
1015 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
1016 data_blob_clear(&blob);
1017 r.in.buffer = &blob;
1018 r.in.offered = needed;
1020 status = dcerpc_spoolss_EnumPorts(p, tctx, &r);
1021 torture_assert_ntstatus_ok(tctx, status, "EnumPorts failed");
1023 torture_assert(tctx, info, "No ports returned");
1029 static bool test_AddPort(struct torture_context *tctx,
1030 struct dcerpc_pipe *p)
1033 struct spoolss_AddPort r;
1035 r.in.server_name = talloc_asprintf(tctx, "\\\\%s",
1036 dcerpc_server_name(p));
1038 r.in.monitor_name = "foo";
1040 torture_comment(tctx, "Testing AddPort\n");
1042 status = dcerpc_spoolss_AddPort(p, tctx, &r);
1044 torture_assert_ntstatus_ok(tctx, status, "AddPort failed");
1046 /* win2k3 returns WERR_NOT_SUPPORTED */
1050 if (!W_ERROR_IS_OK(r.out.result)) {
1051 printf("AddPort failed - %s\n", win_errstr(r.out.result));
1060 static bool test_GetJob(struct torture_context *tctx,
1061 struct dcerpc_pipe *p,
1062 struct policy_handle *handle, uint32_t job_id)
1065 struct spoolss_GetJob r;
1067 uint32_t levels[] = {1, 2 /* 3, 4 */};
1070 r.in.handle = handle;
1071 r.in.job_id = job_id;
1075 r.out.needed = &needed;
1077 torture_comment(tctx, "Testing GetJob level %d\n", r.in.level);
1079 status = dcerpc_spoolss_GetJob(p, tctx, &r);
1080 torture_assert_werr_equal(tctx, r.out.result, WERR_UNKNOWN_LEVEL, "Unexpected return code");
1082 for (i = 0; i < ARRAY_SIZE(levels); i++) {
1084 torture_comment(tctx, "Testing GetJob level %d\n", r.in.level);
1086 r.in.level = levels[i];
1089 status = dcerpc_spoolss_GetJob(p, tctx, &r);
1090 torture_assert_ntstatus_ok(tctx, status, "GetJob failed");
1092 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
1093 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
1094 data_blob_clear(&blob);
1095 r.in.buffer = &blob;
1096 r.in.offered = needed;
1098 status = dcerpc_spoolss_GetJob(p, tctx, &r);
1099 torture_assert_ntstatus_ok(tctx, status, "GetJob failed");
1102 torture_assert(tctx, r.out.info, "No job info returned");
1103 torture_assert_werr_ok(tctx, r.out.result, "GetJob failed");
1109 static bool test_SetJob(struct torture_context *tctx,
1110 struct dcerpc_pipe *p,
1111 struct policy_handle *handle, uint32_t job_id,
1112 enum spoolss_JobControl command)
1115 struct spoolss_SetJob r;
1117 r.in.handle = handle;
1118 r.in.job_id = job_id;
1120 r.in.command = command;
1123 case SPOOLSS_JOB_CONTROL_PAUSE:
1124 torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_PAUSE\n");
1126 case SPOOLSS_JOB_CONTROL_RESUME:
1127 torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_RESUME\n");
1129 case SPOOLSS_JOB_CONTROL_CANCEL:
1130 torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_CANCEL\n");
1132 case SPOOLSS_JOB_CONTROL_RESTART:
1133 torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_RESTART\n");
1135 case SPOOLSS_JOB_CONTROL_DELETE:
1136 torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_DELETE\n");
1138 case SPOOLSS_JOB_CONTROL_SEND_TO_PRINTER:
1139 torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_SEND_TO_PRINTER\n");
1141 case SPOOLSS_JOB_CONTROL_LAST_PAGE_EJECTED:
1142 torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_LAST_PAGE_EJECTED\n");
1144 case SPOOLSS_JOB_CONTROL_RETAIN:
1145 torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_RETAIN\n");
1147 case SPOOLSS_JOB_CONTROL_RELEASE:
1148 torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_RELEASE\n");
1151 torture_comment(tctx, "Testing SetJob\n");
1155 status = dcerpc_spoolss_SetJob(p, tctx, &r);
1156 torture_assert_ntstatus_ok(tctx, status, "SetJob failed");
1157 torture_assert_werr_ok(tctx, r.out.result, "SetJob failed");
1162 static bool test_AddJob(struct torture_context *tctx,
1163 struct dcerpc_pipe *p,
1164 struct policy_handle *handle)
1167 struct spoolss_AddJob r;
1171 r.in.handle = handle;
1173 r.out.needed = &needed;
1174 r.in.buffer = r.out.buffer = NULL;
1176 torture_comment(tctx, "Testing AddJob\n");
1178 status = dcerpc_spoolss_AddJob(p, tctx, &r);
1179 torture_assert_werr_equal(tctx, r.out.result, WERR_UNKNOWN_LEVEL, "AddJob failed");
1183 status = dcerpc_spoolss_AddJob(p, tctx, &r);
1184 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAM, "AddJob failed");
1190 static bool test_EnumJobs(struct torture_context *tctx,
1191 struct dcerpc_pipe *p,
1192 struct policy_handle *handle)
1195 struct spoolss_EnumJobs r;
1198 union spoolss_JobInfo *info;
1200 r.in.handle = handle;
1202 r.in.numjobs = 0xffffffff;
1206 r.out.needed = &needed;
1207 r.out.count = &count;
1210 torture_comment(tctx, "Testing EnumJobs\n");
1212 status = dcerpc_spoolss_EnumJobs(p, tctx, &r);
1214 torture_assert_ntstatus_ok(tctx, status, "EnumJobs failed");
1216 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
1218 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
1219 data_blob_clear(&blob);
1220 r.in.buffer = &blob;
1221 r.in.offered = needed;
1223 status = dcerpc_spoolss_EnumJobs(p, tctx, &r);
1225 torture_assert(tctx, info, "No jobs returned");
1227 for (j = 0; j < count; j++) {
1229 test_GetJob(tctx, p, handle, info[j].info1.job_id);
1232 if (!torture_setting_bool(tctx, "samba3", false)) {
1233 test_SetJob(tctx, p, handle, info[j].info1.job_id, SPOOLSS_JOB_CONTROL_PAUSE);
1234 test_SetJob(tctx, p, handle, info[j].info1.job_id, SPOOLSS_JOB_CONTROL_RESUME);
1239 torture_assert_werr_ok(tctx, r.out.result, "EnumJobs failed");
1245 static bool test_DoPrintTest(struct torture_context *tctx,
1246 struct dcerpc_pipe *p,
1247 struct policy_handle *handle)
1251 struct spoolss_StartDocPrinter s;
1252 struct spoolss_DocumentInfo1 info1;
1253 struct spoolss_StartPagePrinter sp;
1254 struct spoolss_WritePrinter w;
1255 struct spoolss_EndPagePrinter ep;
1256 struct spoolss_EndDocPrinter e;
1259 uint32_t num_written;
1261 torture_comment(tctx, "Testing StartDocPrinter\n");
1263 s.in.handle = handle;
1265 s.in.info.info1 = &info1;
1266 s.out.job_id = &job_id;
1267 info1.document_name = "TorturePrintJob";
1268 info1.output_file = NULL;
1269 info1.datatype = "RAW";
1271 status = dcerpc_spoolss_StartDocPrinter(p, tctx, &s);
1272 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_StartDocPrinter failed");
1273 torture_assert_werr_ok(tctx, s.out.result, "StartDocPrinter failed");
1275 for (i=1; i < 4; i++) {
1276 torture_comment(tctx, "Testing StartPagePrinter: Page[%d]\n", i);
1278 sp.in.handle = handle;
1280 status = dcerpc_spoolss_StartPagePrinter(p, tctx, &sp);
1281 torture_assert_ntstatus_ok(tctx, status,
1282 "dcerpc_spoolss_StartPagePrinter failed");
1283 torture_assert_werr_ok(tctx, sp.out.result, "StartPagePrinter failed");
1285 torture_comment(tctx, "Testing WritePrinter: Page[%d]\n", i);
1287 w.in.handle = handle;
1288 w.in.data = data_blob_string_const(talloc_asprintf(tctx,"TortureTestPage: %d\nData\n",i));
1289 w.out.num_written = &num_written;
1291 status = dcerpc_spoolss_WritePrinter(p, tctx, &w);
1292 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_WritePrinter failed");
1293 torture_assert_werr_ok(tctx, w.out.result, "WritePrinter failed");
1295 torture_comment(tctx, "Testing EndPagePrinter: Page[%d]\n", i);
1297 ep.in.handle = handle;
1299 status = dcerpc_spoolss_EndPagePrinter(p, tctx, &ep);
1300 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EndPagePrinter failed");
1301 torture_assert_werr_ok(tctx, ep.out.result, "EndPagePrinter failed");
1304 torture_comment(tctx, "Testing EndDocPrinter\n");
1306 e.in.handle = handle;
1308 status = dcerpc_spoolss_EndDocPrinter(p, tctx, &e);
1309 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EndDocPrinter failed");
1310 torture_assert_werr_ok(tctx, e.out.result, "EndDocPrinter failed");
1312 ret &= test_AddJob(tctx, p, handle);
1313 ret &= test_EnumJobs(tctx, p, handle);
1315 ret &= test_SetJob(tctx, p, handle, job_id, SPOOLSS_JOB_CONTROL_DELETE);
1320 static bool test_PausePrinter(struct torture_context *tctx,
1321 struct dcerpc_pipe *p,
1322 struct policy_handle *handle)
1325 struct spoolss_SetPrinter r;
1326 struct spoolss_SetPrinterInfoCtr info_ctr;
1327 struct spoolss_DevmodeContainer devmode_ctr;
1328 struct sec_desc_buf secdesc_ctr;
1331 info_ctr.info.info0 = NULL;
1333 ZERO_STRUCT(devmode_ctr);
1334 ZERO_STRUCT(secdesc_ctr);
1336 r.in.handle = handle;
1337 r.in.info_ctr = &info_ctr;
1338 r.in.devmode_ctr = &devmode_ctr;
1339 r.in.secdesc_ctr = &secdesc_ctr;
1340 r.in.command = SPOOLSS_PRINTER_CONTROL_PAUSE;
1342 torture_comment(tctx, "Testing SetPrinter: SPOOLSS_PRINTER_CONTROL_PAUSE\n");
1344 status = dcerpc_spoolss_SetPrinter(p, tctx, &r);
1346 torture_assert_ntstatus_ok(tctx, status, "SetPrinter failed");
1348 torture_assert_werr_ok(tctx, r.out.result, "SetPrinter failed");
1353 static bool test_ResumePrinter(struct torture_context *tctx,
1354 struct dcerpc_pipe *p,
1355 struct policy_handle *handle)
1358 struct spoolss_SetPrinter r;
1359 struct spoolss_SetPrinterInfoCtr info_ctr;
1360 struct spoolss_DevmodeContainer devmode_ctr;
1361 struct sec_desc_buf secdesc_ctr;
1364 info_ctr.info.info0 = NULL;
1366 ZERO_STRUCT(devmode_ctr);
1367 ZERO_STRUCT(secdesc_ctr);
1369 r.in.handle = handle;
1370 r.in.info_ctr = &info_ctr;
1371 r.in.devmode_ctr = &devmode_ctr;
1372 r.in.secdesc_ctr = &secdesc_ctr;
1373 r.in.command = SPOOLSS_PRINTER_CONTROL_RESUME;
1375 torture_comment(tctx, "Testing SetPrinter: SPOOLSS_PRINTER_CONTROL_RESUME\n");
1377 status = dcerpc_spoolss_SetPrinter(p, tctx, &r);
1379 torture_assert_ntstatus_ok(tctx, status, "SetPrinter failed");
1381 torture_assert_werr_ok(tctx, r.out.result, "SetPrinter failed");
1386 static bool test_GetPrinterData(struct torture_context *tctx,
1387 struct dcerpc_pipe *p,
1388 struct policy_handle *handle,
1389 const char *value_name)
1392 struct spoolss_GetPrinterData r;
1394 enum winreg_Type type;
1395 union spoolss_PrinterData data;
1397 r.in.handle = handle;
1398 r.in.value_name = value_name;
1400 r.out.needed = &needed;
1404 torture_comment(tctx, "Testing GetPrinterData\n");
1406 status = dcerpc_spoolss_GetPrinterData(p, tctx, &r);
1407 torture_assert_ntstatus_ok(tctx, status, "GetPrinterData failed");
1409 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
1410 r.in.offered = needed;
1412 status = dcerpc_spoolss_GetPrinterData(p, tctx, &r);
1413 torture_assert_ntstatus_ok(tctx, status, "GetPrinterData failed");
1415 torture_assert_werr_ok(tctx, r.out.result, "GetPrinterData failed");
1421 static bool test_GetPrinterDataEx(struct torture_context *tctx,
1422 struct dcerpc_pipe *p,
1423 struct policy_handle *handle,
1424 const char *key_name,
1425 const char *value_name)
1428 struct spoolss_GetPrinterDataEx r;
1429 enum winreg_Type type;
1432 r.in.handle = handle;
1433 r.in.key_name = key_name;
1434 r.in.value_name = value_name;
1437 r.out.needed = &needed;
1438 r.out.buffer = NULL;
1440 torture_comment(tctx, "Testing GetPrinterDataEx\n");
1442 status = dcerpc_spoolss_GetPrinterDataEx(p, tctx, &r);
1443 if (!NT_STATUS_IS_OK(status)) {
1444 if (NT_STATUS_EQUAL(status,NT_STATUS_NET_WRITE_FAULT) &&
1445 p->last_fault_code == DCERPC_FAULT_OP_RNG_ERROR) {
1446 torture_skip(tctx, "GetPrinterDataEx not supported by server\n");
1448 torture_assert_ntstatus_ok(tctx, status, "GetPrinterDataEx failed");
1451 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
1452 r.in.offered = needed;
1453 r.out.buffer = talloc_array(tctx, uint8_t, needed);
1455 status = dcerpc_spoolss_GetPrinterDataEx(p, tctx, &r);
1456 torture_assert_ntstatus_ok(tctx, status, "GetPrinterDataEx failed");
1458 torture_assert_werr_ok(tctx, r.out.result, "GetPrinterDataEx failed");
1464 static bool test_EnumPrinterData(struct torture_context *tctx, struct dcerpc_pipe *p,
1465 struct policy_handle *handle)
1468 struct spoolss_EnumPrinterData r;
1471 r.in.handle = handle;
1472 r.in.enum_index = 0;
1475 uint32_t value_size = 0;
1476 uint32_t data_size = 0;
1477 enum winreg_Type type = 0;
1479 r.in.value_offered = value_size;
1480 r.out.value_needed = &value_size;
1481 r.in.data_offered = data_size;
1482 r.out.data_needed = &data_size;
1485 r.out.data = talloc_zero_array(tctx, uint8_t, 0);
1487 torture_comment(tctx, "Testing EnumPrinterData\n");
1489 status = dcerpc_spoolss_EnumPrinterData(p, tctx, &r);
1491 torture_assert_ntstatus_ok(tctx, status, "EnumPrinterData failed");
1493 r.in.value_offered = value_size;
1494 r.out.value_name = talloc_zero_array(tctx, const char, value_size);
1495 r.in.data_offered = data_size;
1496 r.out.data = talloc_zero_array(tctx, uint8_t, data_size);
1498 status = dcerpc_spoolss_EnumPrinterData(p, tctx, &r);
1500 torture_assert_ntstatus_ok(tctx, status, "EnumPrinterData failed");
1502 test_GetPrinterData(tctx, p, handle, r.out.value_name);
1504 test_GetPrinterDataEx(tctx,
1505 p, handle, "PrinterDriverData",
1510 } while (W_ERROR_IS_OK(r.out.result));
1515 static bool test_EnumPrinterDataEx(struct torture_context *tctx,
1516 struct dcerpc_pipe *p,
1517 struct policy_handle *handle)
1520 struct spoolss_EnumPrinterDataEx r;
1521 struct spoolss_PrinterEnumValues *info;
1525 r.in.handle = handle;
1526 r.in.key_name = "PrinterDriverData";
1528 r.out.needed = &needed;
1529 r.out.count = &count;
1532 torture_comment(tctx, "Testing EnumPrinterDataEx\n");
1534 status = dcerpc_spoolss_EnumPrinterDataEx(p, tctx, &r);
1535 torture_assert_ntstatus_ok(tctx, status, "EnumPrinterDataEx failed");
1537 r.in.offered = needed;
1539 status = dcerpc_spoolss_EnumPrinterDataEx(p, tctx, &r);
1541 torture_assert_ntstatus_ok(tctx, status, "EnumPrinterDataEx failed");
1547 static bool test_DeletePrinterData(struct torture_context *tctx,
1548 struct dcerpc_pipe *p,
1549 struct policy_handle *handle,
1550 const char *value_name)
1553 struct spoolss_DeletePrinterData r;
1555 r.in.handle = handle;
1556 r.in.value_name = value_name;
1558 torture_comment(tctx, "Testing DeletePrinterData\n");
1560 status = dcerpc_spoolss_DeletePrinterData(p, tctx, &r);
1562 torture_assert_ntstatus_ok(tctx, status, "DeletePrinterData failed");
1567 static bool test_SetPrinterData(struct torture_context *tctx,
1568 struct dcerpc_pipe *p,
1569 struct policy_handle *handle)
1572 struct spoolss_SetPrinterData r;
1573 const char *value_name = "spottyfoot";
1575 r.in.handle = handle;
1576 r.in.value_name = value_name;
1578 r.in.data.string = "dog";
1580 torture_comment(tctx, "Testing SetPrinterData\n");
1582 status = dcerpc_spoolss_SetPrinterData(p, tctx, &r);
1584 torture_assert_ntstatus_ok(tctx, status, "SetPrinterData failed");
1586 if (!test_GetPrinterData(tctx, p, handle, value_name)) {
1590 if (!test_DeletePrinterData(tctx, p, handle, value_name)) {
1597 static bool test_SecondaryClosePrinter(struct torture_context *tctx,
1598 struct dcerpc_pipe *p,
1599 struct policy_handle *handle)
1602 struct dcerpc_binding *b;
1603 struct dcerpc_pipe *p2;
1604 struct spoolss_ClosePrinter cp;
1606 /* only makes sense on SMB */
1607 if (p->conn->transport.transport != NCACN_NP) {
1611 torture_comment(tctx, "testing close on secondary pipe\n");
1613 status = dcerpc_parse_binding(tctx, p->conn->binding_string, &b);
1614 torture_assert_ntstatus_ok(tctx, status, "Failed to parse dcerpc binding");
1616 status = dcerpc_secondary_connection(p, &p2, b);
1617 torture_assert_ntstatus_ok(tctx, status, "Failed to create secondary connection");
1619 status = dcerpc_bind_auth_none(p2, &ndr_table_spoolss);
1620 torture_assert_ntstatus_ok(tctx, status, "Failed to create bind on secondary connection");
1622 cp.in.handle = handle;
1623 cp.out.handle = handle;
1625 status = dcerpc_spoolss_ClosePrinter(p2, tctx, &cp);
1626 torture_assert_ntstatus_equal(tctx, status, NT_STATUS_NET_WRITE_FAULT,
1627 "ERROR: Allowed close on secondary connection");
1629 torture_assert_int_equal(tctx, p2->last_fault_code, DCERPC_FAULT_CONTEXT_MISMATCH,
1630 "Unexpected fault code");
1637 static bool test_OpenPrinter_badname(struct torture_context *tctx,
1638 struct dcerpc_pipe *p, const char *name)
1641 struct spoolss_OpenPrinter op;
1642 struct spoolss_OpenPrinterEx opEx;
1643 struct policy_handle handle;
1646 op.in.printername = name;
1647 op.in.datatype = NULL;
1648 op.in.devmode_ctr.devmode= NULL;
1649 op.in.access_mask = 0;
1650 op.out.handle = &handle;
1652 torture_comment(tctx, "\nTesting OpenPrinter(%s) with bad name\n", op.in.printername);
1654 status = dcerpc_spoolss_OpenPrinter(p, tctx, &op);
1655 torture_assert_ntstatus_ok(tctx, status, "OpenPrinter failed");
1656 if (!W_ERROR_EQUAL(WERR_INVALID_PRINTER_NAME,op.out.result)) {
1657 torture_comment(tctx, "OpenPrinter(%s) unexpected result[%s] should be WERR_INVALID_PRINTER_NAME\n",
1658 name, win_errstr(op.out.result));
1661 if (W_ERROR_IS_OK(op.out.result)) {
1662 ret &=test_ClosePrinter(tctx, p, &handle);
1665 opEx.in.printername = name;
1666 opEx.in.datatype = NULL;
1667 opEx.in.devmode_ctr.devmode = NULL;
1668 opEx.in.access_mask = 0;
1670 opEx.in.userlevel.level1 = NULL;
1671 opEx.out.handle = &handle;
1673 torture_comment(tctx, "Testing OpenPrinterEx(%s) with bad name\n", opEx.in.printername);
1675 status = dcerpc_spoolss_OpenPrinterEx(p, tctx, &opEx);
1676 torture_assert_ntstatus_ok(tctx, status, "OpenPrinterEx failed");
1677 if (!W_ERROR_EQUAL(WERR_INVALID_PARAM,opEx.out.result)) {
1678 torture_comment(tctx, "OpenPrinterEx(%s) unexpected result[%s] should be WERR_INVALID_PARAM\n",
1679 name, win_errstr(opEx.out.result));
1682 if (W_ERROR_IS_OK(opEx.out.result)) {
1683 ret &=test_ClosePrinter(tctx, p, &handle);
1689 static bool test_OpenPrinter(struct torture_context *tctx,
1690 struct dcerpc_pipe *p,
1694 struct spoolss_OpenPrinter r;
1695 struct policy_handle handle;
1698 r.in.printername = talloc_asprintf(tctx, "\\\\%s\\%s", dcerpc_server_name(p), name);
1699 r.in.datatype = NULL;
1700 r.in.devmode_ctr.devmode= NULL;
1701 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1702 r.out.handle = &handle;
1704 torture_comment(tctx, "Testing OpenPrinter(%s)\n", r.in.printername);
1706 status = dcerpc_spoolss_OpenPrinter(p, tctx, &r);
1708 torture_assert_ntstatus_ok(tctx, status, "OpenPrinter failed");
1710 torture_assert_werr_ok(tctx, r.out.result, "OpenPrinter failed");
1712 if (!test_GetPrinter(tctx, p, &handle)) {
1716 if (!torture_setting_bool(tctx, "samba3", false)) {
1717 if (!test_SecondaryClosePrinter(tctx, p, &handle)) {
1722 if (!test_ClosePrinter(tctx, p, &handle)) {
1729 static bool call_OpenPrinterEx(struct torture_context *tctx,
1730 struct dcerpc_pipe *p,
1731 const char *name, struct policy_handle *handle)
1733 struct spoolss_OpenPrinterEx r;
1734 struct spoolss_UserLevel1 userlevel1;
1737 if (name && name[0]) {
1738 r.in.printername = talloc_asprintf(tctx, "\\\\%s\\%s",
1739 dcerpc_server_name(p), name);
1741 r.in.printername = talloc_asprintf(tctx, "\\\\%s",
1742 dcerpc_server_name(p));
1745 r.in.datatype = NULL;
1746 r.in.devmode_ctr.devmode= NULL;
1747 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1749 r.in.userlevel.level1 = &userlevel1;
1750 r.out.handle = handle;
1752 userlevel1.size = 1234;
1753 userlevel1.client = "hello";
1754 userlevel1.user = "spottyfoot!";
1755 userlevel1.build = 1;
1756 userlevel1.major = 2;
1757 userlevel1.minor = 3;
1758 userlevel1.processor = 4;
1760 torture_comment(tctx, "Testing OpenPrinterEx(%s)\n", r.in.printername);
1762 status = dcerpc_spoolss_OpenPrinterEx(p, tctx, &r);
1764 torture_assert_ntstatus_ok(tctx, status, "OpenPrinterEx failed");
1766 torture_assert_werr_ok(tctx, r.out.result, "OpenPrinterEx failed");
1771 static bool test_OpenPrinterEx(struct torture_context *tctx,
1772 struct dcerpc_pipe *p,
1775 struct policy_handle handle;
1778 if (!call_OpenPrinterEx(tctx, p, name, &handle)) {
1782 if (!test_GetPrinter(tctx, p, &handle)) {
1786 if (!test_EnumForms(tctx, p, &handle, false)) {
1790 if (!test_AddForm(tctx, p, &handle, false)) {
1794 if (!test_EnumPrinterData(tctx, p, &handle)) {
1798 if (!test_EnumPrinterDataEx(tctx, p, &handle)) {
1802 if (!test_PausePrinter(tctx, p, &handle)) {
1806 if (!test_DoPrintTest(tctx, p, &handle)) {
1810 if (!test_ResumePrinter(tctx, p, &handle)) {
1814 if (!test_SetPrinterData(tctx, p, &handle)) {
1818 if (!torture_setting_bool(tctx, "samba3", false)) {
1819 if (!test_SecondaryClosePrinter(tctx, p, &handle)) {
1824 if (!test_ClosePrinter(tctx, p, &handle)) {
1831 static bool test_EnumPrinters_old(struct torture_context *tctx, struct dcerpc_pipe *p)
1833 struct spoolss_EnumPrinters r;
1835 uint16_t levels[] = {1, 2, 4, 5};
1839 for (i=0;i<ARRAY_SIZE(levels);i++) {
1840 union spoolss_PrinterInfo *info;
1845 r.in.flags = PRINTER_ENUM_LOCAL;
1847 r.in.level = levels[i];
1850 r.out.needed = &needed;
1851 r.out.count = &count;
1854 torture_comment(tctx, "Testing EnumPrinters level %u\n", r.in.level);
1856 status = dcerpc_spoolss_EnumPrinters(p, tctx, &r);
1857 torture_assert_ntstatus_ok(tctx, status, "EnumPrinters failed");
1859 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
1860 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
1861 data_blob_clear(&blob);
1862 r.in.buffer = &blob;
1863 r.in.offered = needed;
1864 status = dcerpc_spoolss_EnumPrinters(p, tctx, &r);
1867 torture_assert_ntstatus_ok(tctx, status, "EnumPrinters failed");
1869 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinters failed");
1872 torture_comment(tctx, "No printers returned\n");
1876 for (j=0;j<count;j++) {
1877 if (r.in.level == 1) {
1878 char *unc = talloc_strdup(tctx, info[j].info1.name);
1881 if (unc[0] == '\\' && unc[1] == '\\') {
1884 slash = strchr(unc, '\\');
1889 if (!test_OpenPrinter(tctx, p, name)) {
1892 if (!test_OpenPrinterEx(tctx, p, name)) {
1903 static bool test_GetPrinterDriver2(struct dcerpc_pipe *p,
1904 struct policy_handle *handle,
1905 const char *driver_name)
1908 struct spoolss_GetPrinterDriver2 r;
1910 uint32_t server_major_version;
1911 uint32_t server_minor_version;
1913 r.in.handle = handle;
1914 r.in.architecture = "W32X86";
1918 r.in.client_major_version = 0;
1919 r.in.client_minor_version = 0;
1920 r.out.needed = &needed;
1921 r.out.server_major_version = &server_major_version;
1922 r.out.server_minor_version = &server_minor_version;
1924 printf("Testing GetPrinterDriver2\n");
1926 status = dcerpc_spoolss_GetPrinterDriver2(p, tctx, &r);
1927 if (!NT_STATUS_IS_OK(status)) {
1928 printf("GetPrinterDriver2 failed - %s\n", nt_errstr(status));
1932 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
1933 r.in.offered = needed;
1934 status = dcerpc_spoolss_GetPrinterDriver2(p, tctx, &r);
1937 if (!NT_STATUS_IS_OK(status)) {
1938 printf("GetPrinterDriver2 failed - %s\n",
1943 if (!W_ERROR_IS_OK(r.out.result)) {
1944 printf("GetPrinterDriver2 failed - %s\n",
1945 win_errstr(r.out.result));
1953 static bool test_EnumPrinterDrivers_old(struct torture_context *tctx,
1954 struct dcerpc_pipe *p)
1956 struct spoolss_EnumPrinterDrivers r;
1958 uint16_t levels[] = {1, 2, 3, 4, 5, 6};
1961 for (i=0;i<ARRAY_SIZE(levels);i++) {
1965 union spoolss_DriverInfo *info;
1967 r.in.server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
1968 r.in.environment = "Windows NT x86";
1969 r.in.level = levels[i];
1972 r.out.needed = &needed;
1973 r.out.count = &count;
1976 torture_comment(tctx, "Testing EnumPrinterDrivers level %u\n", r.in.level);
1978 status = dcerpc_spoolss_EnumPrinterDrivers(p, tctx, &r);
1980 torture_assert_ntstatus_ok(tctx, status, "EnumPrinterDrivers failed");
1982 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
1983 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
1984 data_blob_clear(&blob);
1985 r.in.buffer = &blob;
1986 r.in.offered = needed;
1987 status = dcerpc_spoolss_EnumPrinterDrivers(p, tctx, &r);
1990 torture_assert_ntstatus_ok(tctx, status, "EnumPrinterDrivers failed");
1992 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinterDrivers failed");
1995 torture_comment(tctx, "No printer drivers returned\n");
2003 bool torture_rpc_spoolss(struct torture_context *torture)
2006 struct dcerpc_pipe *p;
2008 struct test_spoolss_context *ctx;
2010 status = torture_rpc_connection(torture, &p, &ndr_table_spoolss);
2011 if (!NT_STATUS_IS_OK(status)) {
2015 ctx = talloc_zero(torture, struct test_spoolss_context);
2017 ret &= test_OpenPrinter_server(torture, p, ctx);
2019 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "W3SvcInstalled");
2020 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "BeepEnabled");
2021 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "EventLog");
2022 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "NetPopup");
2023 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "NetPopupToComputer");
2024 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "MajorVersion");
2025 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "MinorVersion");
2026 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "DefaultSpoolDirectory");
2027 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "Architecture");
2028 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "DsPresent");
2029 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "OSVersion");
2030 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "OSVersionEx");
2031 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "DNSMachineName");
2032 ret &= test_EnumForms(torture, p, &ctx->server_handle, true);
2033 ret &= test_AddForm(torture, p, &ctx->server_handle, true);
2034 ret &= test_EnumPorts(torture, p, ctx);
2035 ret &= test_GetPrinterDriverDirectory(torture, p, ctx);
2036 ret &= test_GetPrintProcessorDirectory(torture, p, ctx);
2037 ret &= test_EnumPrinterDrivers(torture, p, ctx);
2038 ret &= test_EnumMonitors(torture, p, ctx);
2039 ret &= test_EnumPrintProcessors(torture, p, ctx);
2040 ret &= test_EnumPrintProcDataTypes(torture, p, ctx);
2041 ret &= test_EnumPrinters(torture, p, ctx);
2042 ret &= test_OpenPrinter_badname(torture, p, "__INVALID_PRINTER__");
2043 ret &= test_OpenPrinter_badname(torture, p, "\\\\__INVALID_HOST__");
2044 ret &= test_OpenPrinter_badname(torture, p, "");
2045 ret &= test_OpenPrinter_badname(torture, p, "\\\\\\");
2046 ret &= test_OpenPrinter_badname(torture, p, "\\\\\\__INVALID_PRINTER__");
2047 ret &= test_OpenPrinter_badname(torture, p, talloc_asprintf(torture, "\\\\%s\\", dcerpc_server_name(p)));
2048 ret &= test_OpenPrinter_badname(torture, p,
2049 talloc_asprintf(torture, "\\\\%s\\__INVALID_PRINTER__", dcerpc_server_name(p)));
2052 ret &= test_AddPort(torture, p);
2053 ret &= test_EnumPorts_old(torture, p);
2054 ret &= test_EnumPrinters_old(torture, p);
2055 ret &= test_EnumPrinterDrivers_old(torture, p);