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-2010
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 "librpc/gen_ndr/ndr_misc.h"
27 #include "librpc/gen_ndr/ndr_spoolss.h"
28 #include "librpc/gen_ndr/ndr_spoolss_c.h"
29 #include "librpc/gen_ndr/ndr_security.h"
30 #include "libcli/security/security.h"
31 #include "torture/rpc/rpc.h"
32 #include "param/param.h"
34 #define TORTURE_WELLKNOWN_PRINTER "torture_wkn_printer"
35 #define TORTURE_PRINTER "torture_printer"
36 #define TORTURE_WELLKNOWN_PRINTER_EX "torture_wkn_printer_ex"
37 #define TORTURE_PRINTER_EX "torture_printer_ex"
39 struct test_spoolss_context {
40 /* print server handle */
41 struct policy_handle server_handle;
44 uint32_t port_count[3];
45 union spoolss_PortInfo *ports[3];
47 /* for EnumPrinterDrivers */
48 uint32_t driver_count[8];
49 union spoolss_DriverInfo *drivers[8];
51 /* for EnumMonitors */
52 uint32_t monitor_count[3];
53 union spoolss_MonitorInfo *monitors[3];
55 /* for EnumPrintProcessors */
56 uint32_t print_processor_count[2];
57 union spoolss_PrintProcessorInfo *print_processors[2];
59 /* for EnumPrinters */
60 uint32_t printer_count[6];
61 union spoolss_PrinterInfo *printers[6];
64 #define COMPARE_STRING(tctx, c,r,e) \
65 torture_assert_str_equal(tctx, c.e, r.e, "invalid value")
67 /* not every compiler supports __typeof__() */
69 #define _CHECK_FIELD_SIZE(c,r,e,type) do {\
70 if (sizeof(__typeof__(c.e)) != sizeof(type)) { \
71 torture_fail(tctx, #c "." #e "field is not " #type "\n"); \
73 if (sizeof(__typeof__(r.e)) != sizeof(type)) { \
74 torture_fail(tctx, #r "." #e "field is not " #type "\n"); \
78 #define _CHECK_FIELD_SIZE(c,r,e,type) do {} while(0)
81 #define COMPARE_UINT32(tctx, c, r, e) do {\
82 _CHECK_FIELD_SIZE(c, r, e, uint32_t); \
83 torture_assert_int_equal(tctx, c.e, r.e, "invalid value"); \
86 #define COMPARE_UINT64(tctx, c, r, e) do {\
87 _CHECK_FIELD_SIZE(c, r, e, uint64_t); \
88 torture_assert_int_equal(tctx, c.e, r.e, "invalid value"); \
92 #define COMPARE_NTTIME(tctx, c, r, e) do {\
93 _CHECK_FIELD_SIZE(c, r, e, NTTIME); \
94 torture_assert_int_equal(tctx, c.e, r.e, "invalid value"); \
97 #define COMPARE_STRING_ARRAY(tctx, c,r,e) do {\
103 torture_fail(tctx, #r "." #e " field is NULL and " #c "." #e " is not\n"); \
106 torture_fail(tctx, #c "." #e " field is NULL and " #r "." #e " is not\n"); \
108 for (__i=0;c.e[__i] != NULL; __i++) { \
109 torture_assert_str_equal(tctx, c.e[__i], r.e[__i], "invalid value"); \
113 #define CHECK_ALIGN(size, n) do {\
115 torture_warning(tctx, "%d is *NOT* %d byte aligned, should be %d",\
116 size, n, size + n - (size % n));\
120 #define DO_ROUND(size, n) (((size)+((n)-1)) & ~((n)-1))
122 #define CHECK_NEEDED_SIZE_ENUM_LEVEL(fn, info, level, count, ic, needed, align) do { \
123 if (torture_setting_bool(tctx, "spoolss_check_size", false)) {\
124 uint32_t size = ndr_size_##fn##_info(tctx, ic, level, count, info);\
125 uint32_t round_size = DO_ROUND(size, align);\
126 if (round_size != needed) {\
127 torture_warning(tctx, __location__": "#fn" level %d (count: %d) got unexpected needed size: %d, we calculated: %d", level, count, needed, round_size);\
128 CHECK_ALIGN(size, align);\
133 #define CHECK_NEEDED_SIZE_ENUM(fn, info, count, ic, needed, align) do { \
134 if (torture_setting_bool(tctx, "spoolss_check_size", false)) {\
135 uint32_t size = ndr_size_##fn##_info(tctx, ic, count, info);\
136 uint32_t round_size = DO_ROUND(size, align);\
137 if (round_size != needed) {\
138 torture_warning(tctx, __location__": "#fn" (count: %d) got unexpected needed size: %d, we calculated: %d", count, needed, round_size);\
139 CHECK_ALIGN(size, align);\
144 #define CHECK_NEEDED_SIZE_LEVEL(fn, info, level, ic, needed, align) do { \
145 if (torture_setting_bool(tctx, "spoolss_check_size", false)) {\
146 uint32_t size = ndr_size_##fn(info, level, ic, 0);\
147 uint32_t round_size = DO_ROUND(size, align);\
148 if (round_size != needed) {\
149 torture_warning(tctx, __location__": "#fn" level %d got unexpected needed size: %d, we calculated: %d", level, needed, round_size);\
150 CHECK_ALIGN(size, align);\
155 static bool test_OpenPrinter_server(struct torture_context *tctx,
156 struct dcerpc_pipe *p,
157 struct policy_handle *server_handle)
160 struct spoolss_OpenPrinter op;
162 op.in.printername = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
163 op.in.datatype = NULL;
164 op.in.devmode_ctr.devmode= NULL;
165 op.in.access_mask = 0;
166 op.out.handle = server_handle;
168 torture_comment(tctx, "Testing OpenPrinter(%s)\n", op.in.printername);
170 status = dcerpc_spoolss_OpenPrinter(p, tctx, &op);
171 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_OpenPrinter failed");
172 torture_assert_werr_ok(tctx, op.out.result, "dcerpc_spoolss_OpenPrinter failed");
177 static bool test_EnumPorts(struct torture_context *tctx,
178 struct dcerpc_pipe *p,
179 struct test_spoolss_context *ctx)
182 struct spoolss_EnumPorts r;
183 uint16_t levels[] = { 1, 2 };
186 for (i=0;i<ARRAY_SIZE(levels);i++) {
187 int level = levels[i];
191 union spoolss_PortInfo *info;
193 r.in.servername = "";
197 r.out.needed = &needed;
198 r.out.count = &count;
201 torture_comment(tctx, "Testing EnumPorts level %u\n", r.in.level);
203 status = dcerpc_spoolss_EnumPorts(p, ctx, &r);
204 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPorts failed");
205 if (W_ERROR_IS_OK(r.out.result)) {
206 /* TODO: do some more checks here */
209 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
210 "EnumPorts unexpected return code");
212 blob = data_blob_talloc(ctx, NULL, needed);
213 data_blob_clear(&blob);
215 r.in.offered = needed;
217 status = dcerpc_spoolss_EnumPorts(p, ctx, &r);
218 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPorts failed");
220 torture_assert_werr_ok(tctx, r.out.result, "EnumPorts failed");
222 torture_assert(tctx, info, "EnumPorts returned no info");
224 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPorts, info, r.in.level, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
226 ctx->port_count[level] = count;
227 ctx->ports[level] = info;
230 for (i=1;i<ARRAY_SIZE(levels);i++) {
231 int level = levels[i];
232 int old_level = levels[i-1];
233 torture_assert_int_equal(tctx, ctx->port_count[level], ctx->port_count[old_level],
234 "EnumPorts invalid value");
236 /* if the array sizes are not the same we would maybe segfault in the following code */
238 for (i=0;i<ARRAY_SIZE(levels);i++) {
239 int level = levels[i];
240 for (j=0;j<ctx->port_count[level];j++) {
241 union spoolss_PortInfo *cur = &ctx->ports[level][j];
242 union spoolss_PortInfo *ref = &ctx->ports[2][j];
245 COMPARE_STRING(tctx, cur->info1, ref->info2, port_name);
248 /* level 2 is our reference, and it makes no sense to compare it to itself */
257 static bool test_GetPrintProcessorDirectory(struct torture_context *tctx,
258 struct dcerpc_pipe *p,
259 struct test_spoolss_context *ctx)
262 struct spoolss_GetPrintProcessorDirectory r;
277 .server = talloc_asprintf(ctx, "\\\\%s", dcerpc_server_name(p))
280 .server = talloc_asprintf(ctx, "\\\\%s", dcerpc_server_name(p))
286 for (i=0;i<ARRAY_SIZE(levels);i++) {
287 int level = levels[i].level;
290 r.in.server = levels[i].server;
291 r.in.environment = SPOOLSS_ARCHITECTURE_NT_X86;
295 r.out.needed = &needed;
297 torture_comment(tctx, "Testing GetPrintProcessorDirectory level %u\n", r.in.level);
299 status = dcerpc_spoolss_GetPrintProcessorDirectory(p, ctx, &r);
300 torture_assert_ntstatus_ok(tctx, status,
301 "dcerpc_spoolss_GetPrintProcessorDirectory failed");
302 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
303 "GetPrintProcessorDirectory unexpected return code");
305 blob = data_blob_talloc(ctx, NULL, needed);
306 data_blob_clear(&blob);
308 r.in.offered = needed;
310 status = dcerpc_spoolss_GetPrintProcessorDirectory(p, ctx, &r);
311 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_GetPrintProcessorDirectory failed");
313 torture_assert_werr_ok(tctx, r.out.result, "GetPrintProcessorDirectory failed");
315 CHECK_NEEDED_SIZE_LEVEL(spoolss_PrintProcessorDirectoryInfo, r.out.info, r.in.level, lp_iconv_convenience(tctx->lp_ctx), needed, 2);
322 static bool test_GetPrinterDriverDirectory(struct torture_context *tctx,
323 struct dcerpc_pipe *p,
324 struct test_spoolss_context *ctx)
327 struct spoolss_GetPrinterDriverDirectory r;
342 .server = talloc_asprintf(ctx, "\\\\%s", dcerpc_server_name(p))
345 .server = talloc_asprintf(ctx, "\\\\%s", dcerpc_server_name(p))
351 for (i=0;i<ARRAY_SIZE(levels);i++) {
352 int level = levels[i].level;
355 r.in.server = levels[i].server;
356 r.in.environment = SPOOLSS_ARCHITECTURE_NT_X86;
360 r.out.needed = &needed;
362 torture_comment(tctx, "Testing GetPrinterDriverDirectory level %u\n", r.in.level);
364 status = dcerpc_spoolss_GetPrinterDriverDirectory(p, ctx, &r);
365 torture_assert_ntstatus_ok(tctx, status,
366 "dcerpc_spoolss_GetPrinterDriverDirectory failed");
367 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
368 "GetPrinterDriverDirectory unexpected return code");
370 blob = data_blob_talloc(ctx, NULL, needed);
371 data_blob_clear(&blob);
373 r.in.offered = needed;
375 status = dcerpc_spoolss_GetPrinterDriverDirectory(p, ctx, &r);
376 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_GetPrinterDriverDirectory failed");
378 torture_assert_werr_ok(tctx, r.out.result, "GetPrinterDriverDirectory failed");
380 CHECK_NEEDED_SIZE_LEVEL(spoolss_DriverDirectoryInfo, r.out.info, r.in.level, lp_iconv_convenience(tctx->lp_ctx), needed, 2);
386 static bool test_EnumPrinterDrivers(struct torture_context *tctx,
387 struct dcerpc_pipe *p,
388 struct test_spoolss_context *ctx,
389 const char *architecture)
392 struct spoolss_EnumPrinterDrivers r;
393 uint16_t levels[] = { 1, 2, 3, 4, 5, 6, 8 };
396 for (i=0;i<ARRAY_SIZE(levels);i++) {
397 int level = levels[i];
401 union spoolss_DriverInfo *info;
403 /* FIXME: gd, come back and fix "" as server, and handle
404 * priority of returned error codes in torture test and samba 3
407 r.in.server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
408 r.in.environment = architecture;
412 r.out.needed = &needed;
413 r.out.count = &count;
416 torture_comment(tctx, "Testing EnumPrinterDrivers level %u (%s)\n", r.in.level, r.in.environment);
418 status = dcerpc_spoolss_EnumPrinterDrivers(p, ctx, &r);
419 torture_assert_ntstatus_ok(tctx, status,
420 "dcerpc_spoolss_EnumPrinterDrivers failed");
421 if (W_ERROR_IS_OK(r.out.result)) {
422 /* TODO: do some more checks here */
425 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
426 blob = data_blob_talloc(ctx, NULL, needed);
427 data_blob_clear(&blob);
429 r.in.offered = needed;
431 status = dcerpc_spoolss_EnumPrinterDrivers(p, ctx, &r);
432 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrinterDrivers failed");
435 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinterDrivers failed");
437 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPrinterDrivers, info, r.in.level, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
439 ctx->driver_count[level] = count;
440 ctx->drivers[level] = info;
443 for (i=1;i<ARRAY_SIZE(levels);i++) {
444 int level = levels[i];
445 int old_level = levels[i-1];
447 torture_assert_int_equal(tctx, ctx->driver_count[level], ctx->driver_count[old_level],
448 "EnumPrinterDrivers invalid value");
451 for (i=0;i<ARRAY_SIZE(levels);i++) {
452 int level = levels[i];
454 for (j=0;j<ctx->driver_count[level];j++) {
455 union spoolss_DriverInfo *cur = &ctx->drivers[level][j];
456 union spoolss_DriverInfo *ref = &ctx->drivers[8][j];
460 COMPARE_STRING(tctx, cur->info1, ref->info8, driver_name);
463 COMPARE_UINT32(tctx, cur->info2, ref->info8, version);
464 COMPARE_STRING(tctx, cur->info2, ref->info8, driver_name);
465 COMPARE_STRING(tctx, cur->info2, ref->info8, architecture);
466 COMPARE_STRING(tctx, cur->info2, ref->info8, driver_path);
467 COMPARE_STRING(tctx, cur->info2, ref->info8, data_file);
468 COMPARE_STRING(tctx, cur->info2, ref->info8, config_file);
471 COMPARE_UINT32(tctx, cur->info3, ref->info8, version);
472 COMPARE_STRING(tctx, cur->info3, ref->info8, driver_name);
473 COMPARE_STRING(tctx, cur->info3, ref->info8, architecture);
474 COMPARE_STRING(tctx, cur->info3, ref->info8, driver_path);
475 COMPARE_STRING(tctx, cur->info3, ref->info8, data_file);
476 COMPARE_STRING(tctx, cur->info3, ref->info8, config_file);
477 COMPARE_STRING(tctx, cur->info3, ref->info8, help_file);
478 COMPARE_STRING_ARRAY(tctx, cur->info3, ref->info8, dependent_files);
479 COMPARE_STRING(tctx, cur->info3, ref->info8, monitor_name);
480 COMPARE_STRING(tctx, cur->info3, ref->info8, default_datatype);
483 COMPARE_UINT32(tctx, cur->info4, ref->info8, version);
484 COMPARE_STRING(tctx, cur->info4, ref->info8, driver_name);
485 COMPARE_STRING(tctx, cur->info4, ref->info8, architecture);
486 COMPARE_STRING(tctx, cur->info4, ref->info8, driver_path);
487 COMPARE_STRING(tctx, cur->info4, ref->info8, data_file);
488 COMPARE_STRING(tctx, cur->info4, ref->info8, config_file);
489 COMPARE_STRING(tctx, cur->info4, ref->info8, help_file);
490 COMPARE_STRING_ARRAY(tctx, cur->info4, ref->info8, dependent_files);
491 COMPARE_STRING(tctx, cur->info4, ref->info8, monitor_name);
492 COMPARE_STRING(tctx, cur->info4, ref->info8, default_datatype);
493 COMPARE_STRING_ARRAY(tctx, cur->info4, ref->info8, previous_names);
496 COMPARE_UINT32(tctx, cur->info5, ref->info8, version);
497 COMPARE_STRING(tctx, cur->info5, ref->info8, driver_name);
498 COMPARE_STRING(tctx, cur->info5, ref->info8, architecture);
499 COMPARE_STRING(tctx, cur->info5, ref->info8, driver_path);
500 COMPARE_STRING(tctx, cur->info5, ref->info8, data_file);
501 COMPARE_STRING(tctx, cur->info5, ref->info8, config_file);
502 /*COMPARE_UINT32(tctx, cur->info5, ref->info8, driver_attributes);*/
503 /*COMPARE_UINT32(tctx, cur->info5, ref->info8, config_version);*/
504 /*TODO: ! COMPARE_UINT32(tctx, cur->info5, ref->info8, driver_version); */
507 COMPARE_UINT32(tctx, cur->info6, ref->info8, version);
508 COMPARE_STRING(tctx, cur->info6, ref->info8, driver_name);
509 COMPARE_STRING(tctx, cur->info6, ref->info8, architecture);
510 COMPARE_STRING(tctx, cur->info6, ref->info8, driver_path);
511 COMPARE_STRING(tctx, cur->info6, ref->info8, data_file);
512 COMPARE_STRING(tctx, cur->info6, ref->info8, config_file);
513 COMPARE_STRING(tctx, cur->info6, ref->info8, help_file);
514 COMPARE_STRING_ARRAY(tctx, cur->info6, ref->info8, dependent_files);
515 COMPARE_STRING(tctx, cur->info6, ref->info8, monitor_name);
516 COMPARE_STRING(tctx, cur->info6, ref->info8, default_datatype);
517 COMPARE_STRING_ARRAY(tctx, cur->info6, ref->info8, previous_names);
518 COMPARE_NTTIME(tctx, cur->info6, ref->info8, driver_date);
519 COMPARE_UINT64(tctx, cur->info6, ref->info8, driver_version);
520 COMPARE_STRING(tctx, cur->info6, ref->info8, manufacturer_name);
521 COMPARE_STRING(tctx, cur->info6, ref->info8, manufacturer_url);
522 COMPARE_STRING(tctx, cur->info6, ref->info8, hardware_id);
523 COMPARE_STRING(tctx, cur->info6, ref->info8, provider);
526 /* level 8 is our reference, and it makes no sense to compare it to itself */
535 static bool test_EnumMonitors(struct torture_context *tctx,
536 struct dcerpc_pipe *p,
537 struct test_spoolss_context *ctx)
540 struct spoolss_EnumMonitors r;
541 uint16_t levels[] = { 1, 2 };
544 for (i=0;i<ARRAY_SIZE(levels);i++) {
545 int level = levels[i];
549 union spoolss_MonitorInfo *info;
551 r.in.servername = "";
555 r.out.needed = &needed;
556 r.out.count = &count;
559 torture_comment(tctx, "Testing EnumMonitors level %u\n", r.in.level);
561 status = dcerpc_spoolss_EnumMonitors(p, ctx, &r);
562 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumMonitors failed");
563 if (W_ERROR_IS_OK(r.out.result)) {
564 /* TODO: do some more checks here */
567 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
568 "EnumMonitors failed");
570 blob = data_blob_talloc(ctx, NULL, needed);
571 data_blob_clear(&blob);
573 r.in.offered = needed;
575 status = dcerpc_spoolss_EnumMonitors(p, ctx, &r);
576 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumMonitors failed");
578 torture_assert_werr_ok(tctx, r.out.result, "EnumMonitors failed");
580 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumMonitors, info, r.in.level, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
582 ctx->monitor_count[level] = count;
583 ctx->monitors[level] = info;
586 for (i=1;i<ARRAY_SIZE(levels);i++) {
587 int level = levels[i];
588 int old_level = levels[i-1];
589 torture_assert_int_equal(tctx, ctx->monitor_count[level], ctx->monitor_count[old_level],
590 "EnumMonitors invalid value");
593 for (i=0;i<ARRAY_SIZE(levels);i++) {
594 int level = levels[i];
595 for (j=0;j<ctx->monitor_count[level];j++) {
596 union spoolss_MonitorInfo *cur = &ctx->monitors[level][j];
597 union spoolss_MonitorInfo *ref = &ctx->monitors[2][j];
600 COMPARE_STRING(tctx, cur->info1, ref->info2, monitor_name);
603 /* level 2 is our reference, and it makes no sense to compare it to itself */
612 static bool test_EnumPrintProcessors(struct torture_context *tctx,
613 struct dcerpc_pipe *p,
614 struct test_spoolss_context *ctx)
617 struct spoolss_EnumPrintProcessors r;
618 uint16_t levels[] = { 1 };
621 for (i=0;i<ARRAY_SIZE(levels);i++) {
622 int level = levels[i];
626 union spoolss_PrintProcessorInfo *info;
628 r.in.servername = "";
629 r.in.environment = SPOOLSS_ARCHITECTURE_NT_X86;
633 r.out.needed = &needed;
634 r.out.count = &count;
637 torture_comment(tctx, "Testing EnumPrintProcessors level %u\n", r.in.level);
639 status = dcerpc_spoolss_EnumPrintProcessors(p, ctx, &r);
640 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrintProcessors failed");
641 if (W_ERROR_IS_OK(r.out.result)) {
642 /* TODO: do some more checks here */
645 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
646 "EnumPrintProcessors unexpected return code");
648 blob = data_blob_talloc(ctx, NULL, needed);
649 data_blob_clear(&blob);
651 r.in.offered = needed;
653 status = dcerpc_spoolss_EnumPrintProcessors(p, ctx, &r);
654 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrintProcessors failed");
656 torture_assert_werr_ok(tctx, r.out.result, "EnumPrintProcessors failed");
658 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPrintProcessors, info, r.in.level, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
660 ctx->print_processor_count[level] = count;
661 ctx->print_processors[level] = info;
664 for (i=1;i<ARRAY_SIZE(levels);i++) {
665 int level = levels[i];
666 int old_level = levels[i-1];
667 torture_assert_int_equal(tctx, ctx->print_processor_count[level], ctx->print_processor_count[old_level],
668 "EnumPrintProcessors failed");
671 for (i=0;i<ARRAY_SIZE(levels);i++) {
672 int level = levels[i];
673 for (j=0;j<ctx->print_processor_count[level];j++) {
675 union spoolss_PrintProcessorInfo *cur = &ctx->print_processors[level][j];
676 union spoolss_PrintProcessorInfo *ref = &ctx->print_processors[1][j];
680 /* level 1 is our reference, and it makes no sense to compare it to itself */
689 static bool test_EnumPrintProcDataTypes(struct torture_context *tctx,
690 struct dcerpc_pipe *p,
691 struct test_spoolss_context *ctx)
694 struct spoolss_EnumPrintProcDataTypes r;
695 uint16_t levels[] = { 1 };
698 for (i=0;i<ARRAY_SIZE(levels);i++) {
699 int level = levels[i];
703 union spoolss_PrintProcDataTypesInfo *info;
705 r.in.servername = "";
706 r.in.print_processor_name = "winprint";
710 r.out.needed = &needed;
711 r.out.count = &count;
714 torture_comment(tctx, "Testing EnumPrintProcDataTypes level %u\n", r.in.level);
716 status = dcerpc_spoolss_EnumPrintProcDataTypes(p, ctx, &r);
717 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrintProcDataType failed");
718 if (W_ERROR_IS_OK(r.out.result)) {
719 /* TODO: do some more checks here */
722 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
723 "EnumPrintProcDataTypes unexpected return code");
725 blob = data_blob_talloc(ctx, NULL, needed);
726 data_blob_clear(&blob);
728 r.in.offered = needed;
730 status = dcerpc_spoolss_EnumPrintProcDataTypes(p, ctx, &r);
731 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrintProcDataTypes failed");
733 torture_assert_werr_ok(tctx, r.out.result, "EnumPrintProcDataTypes failed");
735 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPrintProcDataTypes, info, r.in.level, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
743 static bool test_EnumPrinters(struct torture_context *tctx,
744 struct dcerpc_pipe *p,
745 struct test_spoolss_context *ctx)
747 struct spoolss_EnumPrinters r;
749 uint16_t levels[] = { 0, 1, 2, 4, 5 };
752 for (i=0;i<ARRAY_SIZE(levels);i++) {
753 int level = levels[i];
757 union spoolss_PrinterInfo *info;
759 r.in.flags = PRINTER_ENUM_LOCAL;
764 r.out.needed = &needed;
765 r.out.count = &count;
768 torture_comment(tctx, "Testing EnumPrinters level %u\n", r.in.level);
770 status = dcerpc_spoolss_EnumPrinters(p, ctx, &r);
771 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrinters failed");
772 if (W_ERROR_IS_OK(r.out.result)) {
773 /* TODO: do some more checks here */
776 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
777 "EnumPrinters unexpected return code");
779 blob = data_blob_talloc(ctx, NULL, needed);
780 data_blob_clear(&blob);
782 r.in.offered = needed;
784 status = dcerpc_spoolss_EnumPrinters(p, ctx, &r);
785 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrinters failed");
787 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinters failed");
789 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPrinters, info, r.in.level, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
791 ctx->printer_count[level] = count;
792 ctx->printers[level] = info;
795 for (i=1;i<ARRAY_SIZE(levels);i++) {
796 int level = levels[i];
797 int old_level = levels[i-1];
798 torture_assert_int_equal(tctx, ctx->printer_count[level], ctx->printer_count[old_level],
799 "EnumPrinters invalid value");
802 for (i=0;i<ARRAY_SIZE(levels);i++) {
803 int level = levels[i];
804 for (j=0;j<ctx->printer_count[level];j++) {
805 union spoolss_PrinterInfo *cur = &ctx->printers[level][j];
806 union spoolss_PrinterInfo *ref = &ctx->printers[2][j];
809 COMPARE_STRING(tctx, cur->info0, ref->info2, printername);
810 COMPARE_STRING(tctx, cur->info0, ref->info2, servername);
811 COMPARE_UINT32(tctx, cur->info0, ref->info2, cjobs);
812 /*COMPARE_UINT32(tctx, cur->info0, ref->info2, total_jobs);
813 COMPARE_UINT32(tctx, cur->info0, ref->info2, total_bytes);
814 COMPARE_SPOOLSS_TIME(cur->info0, ref->info2, spoolss_Time time);
815 COMPARE_UINT32(tctx, cur->info0, ref->info2, global_counter);
816 COMPARE_UINT32(tctx, cur->info0, ref->info2, total_pages);
817 COMPARE_UINT32(tctx, cur->info0, ref->info2, version);
818 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown10);
819 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown11);
820 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown12);
821 COMPARE_UINT32(tctx, cur->info0, ref->info2, session_counter);
822 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown14);
823 COMPARE_UINT32(tctx, cur->info0, ref->info2, printer_errors);
824 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown16);
825 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown17);
826 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown18);
827 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown19);
828 COMPARE_UINT32(tctx, cur->info0, ref->info2, change_id);
829 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown21);*/
830 COMPARE_UINT32(tctx, cur->info0, ref->info2, status);
831 /*COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown23);
832 COMPARE_UINT32(tctx, cur->info0, ref->info2, c_setprinter);
833 COMPARE_UINT16(cur->info0, ref->info2, unknown25);
834 COMPARE_UINT16(cur->info0, ref->info2, unknown26);
835 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown27);
836 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown28);
837 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown29);*/
840 /*COMPARE_UINT32(tctx, cur->info1, ref->info2, flags);*/
841 /*COMPARE_STRING(tctx, cur->info1, ref->info2, name);*/
842 /*COMPARE_STRING(tctx, cur->info1, ref->info2, description);*/
843 COMPARE_STRING(tctx, cur->info1, ref->info2, comment);
846 /* level 2 is our reference, and it makes no sense to compare it to itself */
849 COMPARE_STRING(tctx, cur->info4, ref->info2, printername);
850 COMPARE_STRING(tctx, cur->info4, ref->info2, servername);
851 COMPARE_UINT32(tctx, cur->info4, ref->info2, attributes);
854 COMPARE_STRING(tctx, cur->info5, ref->info2, printername);
855 COMPARE_STRING(tctx, cur->info5, ref->info2, portname);
856 COMPARE_UINT32(tctx, cur->info5, ref->info2, attributes);
857 /*COMPARE_UINT32(tctx, cur->info5, ref->info2, device_not_selected_timeout);
858 COMPARE_UINT32(tctx, cur->info5, ref->info2, transmission_retry_timeout);*/
865 * - verify that the port of a printer was in the list returned by EnumPorts
871 static bool test_GetPrinterDriver2(struct torture_context *tctx,
872 struct dcerpc_pipe *p,
873 struct policy_handle *handle,
874 const char *driver_name);
876 bool test_GetPrinter_level(struct torture_context *tctx,
877 struct dcerpc_pipe *p,
878 struct policy_handle *handle,
880 union spoolss_PrinterInfo *info)
882 struct spoolss_GetPrinter r;
885 r.in.handle = handle;
889 r.out.needed = &needed;
891 torture_comment(tctx, "Testing GetPrinter level %u\n", r.in.level);
893 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_GetPrinter(p, tctx, &r),
894 "GetPrinter failed");
896 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
897 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
898 data_blob_clear(&blob);
900 r.in.offered = needed;
902 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_GetPrinter(p, tctx, &r),
903 "GetPrinter failed");
906 torture_assert_werr_ok(tctx, r.out.result, "GetPrinter failed");
908 CHECK_NEEDED_SIZE_LEVEL(spoolss_PrinterInfo, r.out.info, r.in.level, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
910 if (info && r.out.info) {
918 static bool test_GetPrinter(struct torture_context *tctx,
919 struct dcerpc_pipe *p,
920 struct policy_handle *handle)
922 uint32_t levels[] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
925 for (i=0;i<ARRAY_SIZE(levels);i++) {
927 union spoolss_PrinterInfo info;
931 torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, levels[i], &info),
932 "failed to call GetPrinter");
934 if ((levels[i] == 2) && info.info2.drivername && strlen(info.info2.drivername)) {
936 test_GetPrinterDriver2(tctx, p, handle, info.info2.drivername),
937 "failed to call test_GetPrinterDriver2");
944 static bool test_SetPrinter(struct torture_context *tctx,
945 struct dcerpc_pipe *p,
946 struct policy_handle *handle,
947 struct spoolss_SetPrinterInfoCtr *info_ctr,
948 struct spoolss_DevmodeContainer *devmode_ctr,
949 struct sec_desc_buf *secdesc_ctr,
950 enum spoolss_PrinterControl command)
952 struct spoolss_SetPrinter r;
954 r.in.handle = handle;
955 r.in.info_ctr = info_ctr;
956 r.in.devmode_ctr = devmode_ctr;
957 r.in.secdesc_ctr = secdesc_ctr;
958 r.in.command = command;
960 torture_comment(tctx, "Testing SetPrinter level %d\n", r.in.info_ctr->level);
962 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_SetPrinter(p, tctx, &r),
963 "failed to call SetPrinter");
964 torture_assert_werr_ok(tctx, r.out.result,
965 "failed to call SetPrinter");
970 static bool test_SetPrinter_errors(struct torture_context *tctx,
971 struct dcerpc_pipe *p,
972 struct policy_handle *handle)
974 struct spoolss_SetPrinter r;
975 uint16_t levels[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
978 struct spoolss_SetPrinterInfoCtr info_ctr;
979 struct spoolss_DevmodeContainer devmode_ctr;
980 struct sec_desc_buf secdesc_ctr;
983 info_ctr.info.info0 = NULL;
985 ZERO_STRUCT(devmode_ctr);
986 ZERO_STRUCT(secdesc_ctr);
988 r.in.handle = handle;
989 r.in.info_ctr = &info_ctr;
990 r.in.devmode_ctr = &devmode_ctr;
991 r.in.secdesc_ctr = &secdesc_ctr;
994 torture_comment(tctx, "Testing SetPrinter all zero\n");
996 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_SetPrinter(p, tctx, &r),
997 "failed to call SetPrinter");
998 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAM,
999 "failed to call SetPrinter");
1002 for (i=0; i < ARRAY_SIZE(levels); i++) {
1004 struct spoolss_SetPrinterInfo0 info0;
1005 struct spoolss_SetPrinterInfo1 info1;
1006 struct spoolss_SetPrinterInfo2 info2;
1007 struct spoolss_SetPrinterInfo3 info3;
1008 struct spoolss_SetPrinterInfo4 info4;
1009 struct spoolss_SetPrinterInfo5 info5;
1010 struct spoolss_SetPrinterInfo6 info6;
1011 struct spoolss_SetPrinterInfo7 info7;
1012 struct spoolss_SetPrinterInfo8 info8;
1013 struct spoolss_SetPrinterInfo9 info9;
1016 info_ctr.level = levels[i];
1017 switch (levels[i]) {
1020 info_ctr.info.info0 = &info0;
1024 info_ctr.info.info1 = &info1;
1028 info_ctr.info.info2 = &info2;
1032 info_ctr.info.info3 = &info3;
1036 info_ctr.info.info4 = &info4;
1040 info_ctr.info.info5 = &info5;
1044 info_ctr.info.info6 = &info6;
1048 info_ctr.info.info7 = &info7;
1052 info_ctr.info.info8 = &info8;
1056 info_ctr.info.info9 = &info9;
1060 torture_comment(tctx, "Testing SetPrinter level %d, command %d\n",
1061 info_ctr.level, r.in.command);
1063 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_SetPrinter(p, tctx, &r),
1064 "failed to call SetPrinter");
1066 switch (r.in.command) {
1067 case SPOOLSS_PRINTER_CONTROL_UNPAUSE: /* 0 */
1068 /* is ignored for all levels other then 0 */
1069 if (info_ctr.level > 0) {
1073 case SPOOLSS_PRINTER_CONTROL_PAUSE: /* 1 */
1074 case SPOOLSS_PRINTER_CONTROL_RESUME: /* 2 */
1075 case SPOOLSS_PRINTER_CONTROL_PURGE: /* 3 */
1076 if (info_ctr.level > 0) {
1077 /* is invalid for all levels other then 0 */
1078 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PRINTER_COMMAND,
1079 "unexpected error code returned");
1082 torture_assert_werr_ok(tctx, r.out.result,
1083 "failed to call SetPrinter with non 0 command");
1088 case SPOOLSS_PRINTER_CONTROL_SET_STATUS: /* 4 */
1089 /* FIXME: gd needs further investigation */
1091 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PRINTER_COMMAND,
1092 "unexpected error code returned");
1096 switch (info_ctr.level) {
1098 torture_assert_werr_equal(tctx, r.out.result, WERR_UNKNOWN_LEVEL,
1099 "unexpected error code returned");
1102 torture_assert_werr_equal(tctx, r.out.result, WERR_UNKNOWN_PRINTER_DRIVER,
1103 "unexpected error code returned");
1109 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAM,
1110 "unexpected error code returned");
1113 torture_assert_werr_equal(tctx, r.out.result, WERR_NOT_SUPPORTED,
1114 "unexpected error code returned");
1117 torture_assert_werr_ok(tctx, r.out.result,
1118 "failed to call SetPrinter");
1123 if (r.in.command < 5) {
1131 static void clear_info2(struct spoolss_SetPrinterInfoCtr *r)
1133 if ((r->level == 2) && (r->info.info2)) {
1134 r->info.info2->secdesc_ptr = 0;
1135 r->info.info2->devmode_ptr = 0;
1139 static bool test_PrinterInfo(struct torture_context *tctx,
1140 struct dcerpc_pipe *p,
1141 struct policy_handle *handle)
1144 struct spoolss_SetPrinter s;
1145 struct spoolss_GetPrinter q;
1146 struct spoolss_GetPrinter q0;
1147 struct spoolss_SetPrinterInfoCtr info_ctr;
1148 union spoolss_PrinterInfo info;
1149 struct spoolss_DevmodeContainer devmode_ctr;
1150 struct sec_desc_buf secdesc_ctr;
1155 uint32_t status_list[] = {
1156 /* these do not stick
1157 PRINTER_STATUS_PAUSED,
1158 PRINTER_STATUS_ERROR,
1159 PRINTER_STATUS_PENDING_DELETION, */
1160 PRINTER_STATUS_PAPER_JAM,
1161 PRINTER_STATUS_PAPER_OUT,
1162 PRINTER_STATUS_MANUAL_FEED,
1163 PRINTER_STATUS_PAPER_PROBLEM,
1164 PRINTER_STATUS_OFFLINE,
1165 PRINTER_STATUS_IO_ACTIVE,
1166 PRINTER_STATUS_BUSY,
1167 PRINTER_STATUS_PRINTING,
1168 PRINTER_STATUS_OUTPUT_BIN_FULL,
1169 PRINTER_STATUS_NOT_AVAILABLE,
1170 PRINTER_STATUS_WAITING,
1171 PRINTER_STATUS_PROCESSING,
1172 PRINTER_STATUS_INITIALIZING,
1173 PRINTER_STATUS_WARMING_UP,
1174 PRINTER_STATUS_TONER_LOW,
1175 PRINTER_STATUS_NO_TONER,
1176 PRINTER_STATUS_PAGE_PUNT,
1177 PRINTER_STATUS_USER_INTERVENTION,
1178 PRINTER_STATUS_OUT_OF_MEMORY,
1179 PRINTER_STATUS_DOOR_OPEN,
1180 PRINTER_STATUS_SERVER_UNKNOWN,
1181 PRINTER_STATUS_POWER_SAVE,
1182 /* these do not stick
1191 uint32_t default_attribute = PRINTER_ATTRIBUTE_LOCAL;
1192 uint32_t attribute_list[] = {
1193 PRINTER_ATTRIBUTE_QUEUED,
1194 /* fails with WERR_INVALID_DATATYPE:
1195 PRINTER_ATTRIBUTE_DIRECT, */
1197 PRINTER_ATTRIBUTE_DEFAULT, */
1198 PRINTER_ATTRIBUTE_SHARED,
1200 PRINTER_ATTRIBUTE_NETWORK, */
1201 PRINTER_ATTRIBUTE_HIDDEN,
1202 PRINTER_ATTRIBUTE_LOCAL,
1203 PRINTER_ATTRIBUTE_ENABLE_DEVQ,
1204 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS,
1205 PRINTER_ATTRIBUTE_DO_COMPLETE_FIRST,
1206 PRINTER_ATTRIBUTE_WORK_OFFLINE,
1208 PRINTER_ATTRIBUTE_ENABLE_BIDI, */
1209 /* fails with WERR_INVALID_DATATYPE:
1210 PRINTER_ATTRIBUTE_RAW_ONLY, */
1211 /* these do not stick
1212 PRINTER_ATTRIBUTE_PUBLISHED,
1213 PRINTER_ATTRIBUTE_FAX,
1214 PRINTER_ATTRIBUTE_TS,
1233 ZERO_STRUCT(devmode_ctr);
1234 ZERO_STRUCT(secdesc_ctr);
1236 s.in.handle = handle;
1238 s.in.info_ctr = &info_ctr;
1239 s.in.devmode_ctr = &devmode_ctr;
1240 s.in.secdesc_ctr = &secdesc_ctr;
1242 q.in.handle = handle;
1246 #define TESTGETCALL(call, r) \
1247 r.in.buffer = NULL; \
1249 r.out.needed = &needed; \
1250 status = dcerpc_spoolss_ ##call(p, tctx, &r); \
1251 if (!NT_STATUS_IS_OK(status)) { \
1252 torture_comment(tctx, #call " level %u failed - %s (%s)\n", \
1253 r.in.level, nt_errstr(status), __location__); \
1257 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {\
1258 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed); \
1259 data_blob_clear(&blob); \
1260 r.in.buffer = &blob; \
1261 r.in.offered = needed; \
1263 status = dcerpc_spoolss_ ##call(p, tctx, &r); \
1264 if (!NT_STATUS_IS_OK(status)) { \
1265 torture_comment(tctx, #call " level %u failed - %s (%s)\n", \
1266 r.in.level, nt_errstr(status), __location__); \
1270 if (!W_ERROR_IS_OK(r.out.result)) { \
1271 torture_comment(tctx, #call " level %u failed - %s (%s)\n", \
1272 r.in.level, win_errstr(r.out.result), __location__); \
1278 #define TESTSETCALL_EXP(call, r, err) \
1279 clear_info2(&info_ctr);\
1280 status = dcerpc_spoolss_ ##call(p, tctx, &r); \
1281 if (!NT_STATUS_IS_OK(status)) { \
1282 torture_comment(tctx, #call " level %u failed - %s (%s)\n", \
1283 r.in.info_ctr->level, nt_errstr(status), __location__); \
1287 if (!W_ERROR_IS_OK(err)) { \
1288 if (!W_ERROR_EQUAL(err, r.out.result)) { \
1289 torture_comment(tctx, #call " level %u failed - %s, expected %s (%s)\n", \
1290 r.in.info_ctr->level, win_errstr(r.out.result), win_errstr(err), __location__); \
1295 if (!W_ERROR_IS_OK(r.out.result)) { \
1296 torture_comment(tctx, #call " level %u failed - %s (%s)\n", \
1297 r.in.info_ctr->level, win_errstr(r.out.result), __location__); \
1302 #define TESTSETCALL(call, r) \
1303 TESTSETCALL_EXP(call, r, WERR_OK)
1305 #define STRING_EQUAL(s1, s2, field) \
1306 if ((s1 && !s2) || (s2 && !s1) || strcmp(s1, s2)) { \
1307 torture_comment(tctx, "Failed to set %s to '%s' (%s)\n", \
1308 #field, s2, __location__); \
1313 #define MEM_EQUAL(s1, s2, length, field) \
1314 if ((s1 && !s2) || (s2 && !s1) || memcmp(s1, s2, length)) { \
1315 torture_comment(tctx, "Failed to set %s to '%s' (%s)\n", \
1316 #field, (const char *)s2, __location__); \
1321 #define INT_EQUAL(i1, i2, field) \
1323 torture_comment(tctx, "Failed to set %s to 0x%llx - got 0x%llx (%s)\n", \
1324 #field, (unsigned long long)i2, (unsigned long long)i1, __location__); \
1329 #define SD_EQUAL(sd1, sd2, field) \
1330 if (!security_descriptor_equal(sd1, sd2)) { \
1331 torture_comment(tctx, "Failed to set %s (%s)\n", \
1332 #field, __location__); \
1337 #define TEST_PRINTERINFO_STRING_EXP_ERR(lvl1, field1, lvl2, field2, value, err) do { \
1338 torture_comment(tctx, "field test %d/%s vs %d/%s\n", lvl1, #field1, lvl2, #field2); \
1339 q.in.level = lvl1; \
1340 TESTGETCALL(GetPrinter, q) \
1341 info_ctr.level = lvl1; \
1342 info_ctr.info.info ## lvl1 = (struct spoolss_SetPrinterInfo ## lvl1 *)&q.out.info->info ## lvl1; \
1343 info_ctr.info.info ## lvl1->field1 = value;\
1344 TESTSETCALL_EXP(SetPrinter, s, err) \
1345 info_ctr.info.info ## lvl1->field1 = ""; \
1346 TESTGETCALL(GetPrinter, q) \
1347 info_ctr.info.info ## lvl1->field1 = value; \
1348 STRING_EQUAL(info_ctr.info.info ## lvl1->field1, value, field1); \
1349 q.in.level = lvl2; \
1350 TESTGETCALL(GetPrinter, q) \
1351 info_ctr.info.info ## lvl2 = (struct spoolss_SetPrinterInfo ## lvl2 *)&q.out.info->info ## lvl2; \
1352 STRING_EQUAL(info_ctr.info.info ## lvl2->field2, value, field2); \
1355 #define TEST_PRINTERINFO_STRING(lvl1, field1, lvl2, field2, value) do { \
1356 TEST_PRINTERINFO_STRING_EXP_ERR(lvl1, field1, lvl2, field2, value, WERR_OK); \
1359 #define TEST_PRINTERINFO_INT_EXP(lvl1, field1, lvl2, field2, value, exp_value) do { \
1360 torture_comment(tctx, "field test %d/%s vs %d/%s\n", lvl1, #field1, lvl2, #field2); \
1361 q.in.level = lvl1; \
1362 TESTGETCALL(GetPrinter, q) \
1363 info_ctr.level = lvl1; \
1364 info_ctr.info.info ## lvl1 = (struct spoolss_SetPrinterInfo ## lvl1 *)&q.out.info->info ## lvl1; \
1365 info_ctr.info.info ## lvl1->field1 = value; \
1366 TESTSETCALL(SetPrinter, s) \
1367 info_ctr.info.info ## lvl1->field1 = 0; \
1368 TESTGETCALL(GetPrinter, q) \
1369 info_ctr.info.info ## lvl1 = (struct spoolss_SetPrinterInfo ## lvl1 *)&q.out.info->info ## lvl1; \
1370 INT_EQUAL(info_ctr.info.info ## lvl1->field1, exp_value, field1); \
1371 q.in.level = lvl2; \
1372 TESTGETCALL(GetPrinter, q) \
1373 info_ctr.info.info ## lvl2 = (struct spoolss_SetPrinterInfo ## lvl2 *)&q.out.info->info ## lvl2; \
1374 INT_EQUAL(info_ctr.info.info ## lvl2->field2, exp_value, field1); \
1377 #define TEST_PRINTERINFO_INT(lvl1, field1, lvl2, field2, value) do { \
1378 TEST_PRINTERINFO_INT_EXP(lvl1, field1, lvl2, field2, value, value); \
1382 do { TESTGETCALL(GetPrinter, q0) } while (0);
1384 TEST_PRINTERINFO_STRING(2, comment, 1, comment, "xx2-1 comment");
1385 TEST_PRINTERINFO_STRING(2, comment, 2, comment, "xx2-2 comment");
1387 /* level 0 printername does not stick */
1388 /* TEST_PRINTERINFO_STRING(2, printername, 0, printername, "xx2-0 printer"); */
1389 TEST_PRINTERINFO_STRING(2, printername, 1, name, "xx2-1 printer");
1390 TEST_PRINTERINFO_STRING(2, printername, 2, printername, "xx2-2 printer");
1391 TEST_PRINTERINFO_STRING(2, printername, 4, printername, "xx2-4 printer");
1392 TEST_PRINTERINFO_STRING(2, printername, 5, printername, "xx2-5 printer");
1393 /* TEST_PRINTERINFO_STRING(4, printername, 0, printername, "xx4-0 printer"); */
1394 TEST_PRINTERINFO_STRING(4, printername, 1, name, "xx4-1 printer");
1395 TEST_PRINTERINFO_STRING(4, printername, 2, printername, "xx4-2 printer");
1396 TEST_PRINTERINFO_STRING(4, printername, 4, printername, "xx4-4 printer");
1397 TEST_PRINTERINFO_STRING(4, printername, 5, printername, "xx4-5 printer");
1398 /* TEST_PRINTERINFO_STRING(5, printername, 0, printername, "xx5-0 printer"); */
1399 TEST_PRINTERINFO_STRING(5, printername, 1, name, "xx5-1 printer");
1400 TEST_PRINTERINFO_STRING(5, printername, 2, printername, "xx5-2 printer");
1401 TEST_PRINTERINFO_STRING(5, printername, 4, printername, "xx5-4 printer");
1402 TEST_PRINTERINFO_STRING(5, printername, 5, printername, "xx5-5 printer");
1404 /* servername can be set but does not stick
1405 TEST_PRINTERINFO_STRING(2, servername, 0, servername, "xx2-0 servername");
1406 TEST_PRINTERINFO_STRING(2, servername, 2, servername, "xx2-2 servername");
1407 TEST_PRINTERINFO_STRING(2, servername, 4, servername, "xx2-4 servername");
1410 /* passing an invalid port will result in WERR_UNKNOWN_PORT */
1411 TEST_PRINTERINFO_STRING_EXP_ERR(2, portname, 2, portname, "xx2-2 portname", WERR_UNKNOWN_PORT);
1412 TEST_PRINTERINFO_STRING_EXP_ERR(2, portname, 5, portname, "xx2-5 portname", WERR_UNKNOWN_PORT);
1413 TEST_PRINTERINFO_STRING_EXP_ERR(5, portname, 2, portname, "xx5-2 portname", WERR_UNKNOWN_PORT);
1414 TEST_PRINTERINFO_STRING_EXP_ERR(5, portname, 5, portname, "xx5-5 portname", WERR_UNKNOWN_PORT);
1416 TEST_PRINTERINFO_STRING(2, sharename, 2, sharename, "xx2-2 sharename");
1417 /* passing an invalid driver will result in WERR_UNKNOWN_PRINTER_DRIVER */
1418 TEST_PRINTERINFO_STRING_EXP_ERR(2, drivername, 2, drivername, "xx2-2 drivername", WERR_UNKNOWN_PRINTER_DRIVER);
1419 TEST_PRINTERINFO_STRING(2, location, 2, location, "xx2-2 location");
1420 /* passing an invalid sepfile will result in WERR_INVALID_SEPARATOR_FILE */
1421 TEST_PRINTERINFO_STRING_EXP_ERR(2, sepfile, 2, sepfile, "xx2-2 sepfile", WERR_INVALID_SEPARATOR_FILE);
1422 /* passing an invalid printprocessor will result in WERR_UNKNOWN_PRINTPROCESSOR */
1423 TEST_PRINTERINFO_STRING_EXP_ERR(2, printprocessor, 2, printprocessor, "xx2-2 printprocessor", WERR_UNKNOWN_PRINTPROCESSOR);
1424 TEST_PRINTERINFO_STRING(2, datatype, 2, datatype, "xx2-2 datatype");
1425 TEST_PRINTERINFO_STRING(2, parameters, 2, parameters, "xx2-2 parameters");
1427 for (i=0; i < ARRAY_SIZE(attribute_list); i++) {
1428 /* TEST_PRINTERINFO_INT_EXP(2, attributes, 1, flags,
1430 (attribute_list[i] | default_attribute)
1432 TEST_PRINTERINFO_INT_EXP(2, attributes, 2, attributes,
1434 (attribute_list[i] | default_attribute)
1436 TEST_PRINTERINFO_INT_EXP(2, attributes, 4, attributes,
1438 (attribute_list[i] | default_attribute)
1440 TEST_PRINTERINFO_INT_EXP(2, attributes, 5, attributes,
1442 (attribute_list[i] | default_attribute)
1444 /* TEST_PRINTERINFO_INT_EXP(4, attributes, 1, flags,
1446 (attribute_list[i] | default_attribute)
1448 TEST_PRINTERINFO_INT_EXP(4, attributes, 2, attributes,
1450 (attribute_list[i] | default_attribute)
1452 TEST_PRINTERINFO_INT_EXP(4, attributes, 4, attributes,
1454 (attribute_list[i] | default_attribute)
1456 TEST_PRINTERINFO_INT_EXP(4, attributes, 5, attributes,
1458 (attribute_list[i] | default_attribute)
1460 /* TEST_PRINTERINFO_INT_EXP(5, attributes, 1, flags,
1462 (attribute_list[i] | default_attribute)
1464 TEST_PRINTERINFO_INT_EXP(5, attributes, 2, attributes,
1466 (attribute_list[i] | default_attribute)
1468 TEST_PRINTERINFO_INT_EXP(5, attributes, 4, attributes,
1470 (attribute_list[i] | default_attribute)
1472 TEST_PRINTERINFO_INT_EXP(5, attributes, 5, attributes,
1474 (attribute_list[i] | default_attribute)
1478 for (i=0; i < ARRAY_SIZE(status_list); i++) {
1479 /* level 2 sets do not stick
1480 TEST_PRINTERINFO_INT(2, status, 0, status, status_list[i]);
1481 TEST_PRINTERINFO_INT(2, status, 2, status, status_list[i]);
1482 TEST_PRINTERINFO_INT(2, status, 6, status, status_list[i]); */
1483 TEST_PRINTERINFO_INT(6, status, 0, status, status_list[i]);
1484 TEST_PRINTERINFO_INT(6, status, 2, status, status_list[i]);
1485 TEST_PRINTERINFO_INT(6, status, 6, status, status_list[i]);
1488 /* priorities need to be between 0 and 99
1489 passing an invalid priority will result in WERR_INVALID_PRIORITY */
1490 TEST_PRINTERINFO_INT(2, priority, 2, priority, 0);
1491 TEST_PRINTERINFO_INT(2, priority, 2, priority, 1);
1492 TEST_PRINTERINFO_INT(2, priority, 2, priority, 99);
1493 /* TEST_PRINTERINFO_INT(2, priority, 2, priority, 100); */
1494 TEST_PRINTERINFO_INT(2, defaultpriority,2, defaultpriority, 0);
1495 TEST_PRINTERINFO_INT(2, defaultpriority,2, defaultpriority, 1);
1496 TEST_PRINTERINFO_INT(2, defaultpriority,2, defaultpriority, 99);
1497 /* TEST_PRINTERINFO_INT(2, defaultpriority,2, defaultpriority, 100); */
1499 TEST_PRINTERINFO_INT(2, starttime, 2, starttime, __LINE__);
1500 TEST_PRINTERINFO_INT(2, untiltime, 2, untiltime, __LINE__);
1503 TEST_PRINTERINFO_INT(2, cjobs, 2, cjobs, __LINE__);
1504 TEST_PRINTERINFO_INT(2, averageppm, 2, averageppm, __LINE__); */
1507 TEST_PRINTERINFO_INT(5, device_not_selected_timeout, 5, device_not_selected_timeout, __LINE__);
1508 TEST_PRINTERINFO_INT(5, transmission_retry_timeout, 5, transmission_retry_timeout, __LINE__); */
1510 /* FIXME: gd also test devmode and secdesc behavior */
1513 /* verify composition of level 1 description field */
1514 const char *description;
1518 do { TESTGETCALL(GetPrinter, q0) } while (0);
1520 description = talloc_strdup(tctx, q0.out.info->info1.description);
1523 do { TESTGETCALL(GetPrinter, q0) } while (0);
1525 tmp = talloc_asprintf(tctx, "%s,%s,%s",
1526 q0.out.info->info2.printername,
1527 q0.out.info->info2.drivername,
1528 q0.out.info->info2.location);
1530 do { STRING_EQUAL(description, tmp, "description")} while (0);
1536 #define torture_assert_sid_equal(torture_ctx,got,expected,cmt)\
1537 do { struct dom_sid *__got = (got), *__expected = (expected); \
1538 if (!dom_sid_equal(__got, __expected)) { \
1539 torture_result(torture_ctx, TORTURE_FAIL, \
1540 __location__": "#got" was %s, expected %s: %s", \
1541 dom_sid_string(torture_ctx, __got), dom_sid_string(torture_ctx, __expected), cmt); \
1546 static bool test_security_descriptor_equal(struct torture_context *tctx,
1547 const struct security_descriptor *sd1,
1548 const struct security_descriptor *sd2)
1555 torture_comment(tctx, "%s\n", __location__);
1559 torture_assert_int_equal(tctx, sd1->revision, sd2->revision, "revision mismatch");
1560 torture_assert_int_equal(tctx, sd1->type, sd2->type, "type mismatch");
1562 torture_assert_sid_equal(tctx, sd1->owner_sid, sd2->owner_sid, "owner mismatch");
1563 torture_assert_sid_equal(tctx, sd1->group_sid, sd2->group_sid, "group mismatch");
1565 if (!security_acl_equal(sd1->sacl, sd2->sacl)) {
1566 torture_comment(tctx, "%s: sacl mismatch\n", __location__);
1567 NDR_PRINT_DEBUG(security_acl, sd1->sacl);
1568 NDR_PRINT_DEBUG(security_acl, sd2->sacl);
1571 if (!security_acl_equal(sd1->dacl, sd2->dacl)) {
1572 torture_comment(tctx, "%s: dacl mismatch\n", __location__);
1573 NDR_PRINT_DEBUG(security_acl, sd1->dacl);
1574 NDR_PRINT_DEBUG(security_acl, sd2->dacl);
1581 static bool test_sd_set_level(struct torture_context *tctx,
1582 struct dcerpc_pipe *p,
1583 struct policy_handle *handle,
1585 struct security_descriptor *sd)
1587 struct spoolss_SetPrinterInfoCtr info_ctr;
1588 struct spoolss_DevmodeContainer devmode_ctr;
1589 struct sec_desc_buf secdesc_ctr;
1591 ZERO_STRUCT(devmode_ctr);
1592 ZERO_STRUCT(secdesc_ctr);
1596 union spoolss_PrinterInfo info;
1597 struct spoolss_SetPrinterInfo2 info2;
1598 torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 2, &info), "");
1600 info2.servername = info.info2.servername;
1601 info2.printername = info.info2.printername;
1602 info2.sharename = info.info2.sharename;
1603 info2.portname = info.info2.portname;
1604 info2.drivername = info.info2.drivername;
1605 info2.comment = info.info2.comment;
1606 info2.location = info.info2.location;
1607 info2.devmode_ptr = 0;
1608 info2.sepfile = info.info2.sepfile;
1609 info2.printprocessor = info.info2.printprocessor;
1610 info2.datatype = info.info2.datatype;
1611 info2.parameters = info.info2.parameters;
1612 info2.secdesc_ptr = 0;
1613 info2.attributes = info.info2.attributes;
1614 info2.priority = info.info2.priority;
1615 info2.defaultpriority = info.info2.defaultpriority;
1616 info2.starttime = info.info2.starttime;
1617 info2.untiltime = info.info2.untiltime;
1618 info2.status = info.info2.status;
1619 info2.cjobs = info.info2.cjobs;
1620 info2.averageppm = info.info2.averageppm;
1623 info_ctr.info.info2 = &info2;
1628 struct spoolss_SetPrinterInfo3 info3;
1630 info3.sec_desc_ptr = 0;
1633 info_ctr.info.info3 = &info3;
1641 secdesc_ctr.sd = sd;
1643 torture_assert(tctx,
1644 test_SetPrinter(tctx, p, handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0), "");
1649 static bool test_PrinterInfo_SDs(struct torture_context *tctx,
1650 struct dcerpc_pipe *p,
1651 struct policy_handle *handle)
1653 union spoolss_PrinterInfo info;
1654 struct security_descriptor *sd1, *sd2;
1657 /* just compare level 2 and level 3 */
1659 torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 2, &info), "");
1661 sd1 = info.info2.secdesc;
1663 torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 3, &info), "");
1665 sd2 = info.info3.secdesc;
1667 torture_assert(tctx, test_security_descriptor_equal(tctx, sd1, sd2),
1668 "SD level 2 != SD level 3");
1671 /* query level 2, set level 2, query level 2 */
1673 torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 2, &info), "");
1675 sd1 = info.info2.secdesc;
1677 torture_assert(tctx, test_sd_set_level(tctx, p, handle, 2, sd1), "");
1679 torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 2, &info), "");
1681 sd2 = info.info2.secdesc;
1682 if (sd1->type & SEC_DESC_DACL_DEFAULTED) {
1683 torture_comment(tctx, "removing SEC_DESC_DACL_DEFAULTED\n");
1684 sd1->type &= ~SEC_DESC_DACL_DEFAULTED;
1687 torture_assert(tctx, test_security_descriptor_equal(tctx, sd1, sd2),
1688 "SD level 2 != SD level 2 after SD has been set via level 2");
1691 /* query level 2, set level 3, query level 2 */
1693 torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 2, &info), "");
1695 sd1 = info.info2.secdesc;
1697 torture_assert(tctx, test_sd_set_level(tctx, p, handle, 3, sd1), "");
1699 torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 2, &info), "");
1701 sd2 = info.info2.secdesc;
1703 torture_assert(tctx, test_security_descriptor_equal(tctx, sd1, sd2),
1704 "SD level 2 != SD level 2 after SD has been set via level 3");
1706 /* set modified sd level 3, query level 2 */
1708 for (i=0; i < 93; i++) {
1709 struct security_ace a;
1710 const char *sid_string = talloc_asprintf(tctx, "S-1-5-32-9999%i", i);
1711 a.type = SEC_ACE_TYPE_ACCESS_ALLOWED;
1713 a.size = 0; /* autogenerated */
1715 a.trustee = *dom_sid_parse_talloc(tctx, sid_string);
1716 torture_assert_ntstatus_ok(tctx, security_descriptor_dacl_add(sd1, &a), "");
1719 torture_assert(tctx, test_sd_set_level(tctx, p, handle, 3, sd1), "");
1721 torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 2, &info), "");
1722 sd2 = info.info2.secdesc;
1724 if (sd1->type & SEC_DESC_DACL_DEFAULTED) {
1725 torture_comment(tctx, "removing SEC_DESC_DACL_DEFAULTED\n");
1726 sd1->type &= ~SEC_DESC_DACL_DEFAULTED;
1729 torture_assert(tctx, test_security_descriptor_equal(tctx, sd1, sd2),
1730 "modified SD level 2 != SD level 2 after SD has been set via level 3");
1737 * wrapper call that saves original sd, runs tests, and restores sd
1740 static bool test_PrinterInfo_SD(struct torture_context *tctx,
1741 struct dcerpc_pipe *p,
1742 struct policy_handle *handle)
1744 union spoolss_PrinterInfo info;
1745 struct security_descriptor *sd;
1748 torture_comment(tctx, "\nTesting Printer Security Descriptors\n");
1750 /* save original sd */
1752 torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 2, &info),
1753 "failed to get initial security descriptor");
1755 sd = security_descriptor_copy(tctx, info.info2.secdesc);
1759 ret = test_PrinterInfo_SDs(tctx, p, handle);
1761 /* restore original sd */
1763 torture_assert(tctx, test_sd_set_level(tctx, p, handle, 3, sd),
1764 "failed to restore initial security descriptor");
1766 torture_comment(tctx, "Printer Security Descriptors test %s\n",
1767 ret ? "succeeded" : "failed");
1773 static bool test_devmode_set_level(struct torture_context *tctx,
1774 struct dcerpc_pipe *p,
1775 struct policy_handle *handle,
1777 struct spoolss_DeviceMode *devmode)
1779 struct spoolss_SetPrinterInfoCtr info_ctr;
1780 struct spoolss_DevmodeContainer devmode_ctr;
1781 struct sec_desc_buf secdesc_ctr;
1783 ZERO_STRUCT(devmode_ctr);
1784 ZERO_STRUCT(secdesc_ctr);
1788 union spoolss_PrinterInfo info;
1789 struct spoolss_SetPrinterInfo2 info2;
1790 torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 2, &info), "");
1792 info2.servername = info.info2.servername;
1793 info2.printername = info.info2.printername;
1794 info2.sharename = info.info2.sharename;
1795 info2.portname = info.info2.portname;
1796 info2.drivername = info.info2.drivername;
1797 info2.comment = info.info2.comment;
1798 info2.location = info.info2.location;
1799 info2.devmode_ptr = 0;
1800 info2.sepfile = info.info2.sepfile;
1801 info2.printprocessor = info.info2.printprocessor;
1802 info2.datatype = info.info2.datatype;
1803 info2.parameters = info.info2.parameters;
1804 info2.secdesc_ptr = 0;
1805 info2.attributes = info.info2.attributes;
1806 info2.priority = info.info2.priority;
1807 info2.defaultpriority = info.info2.defaultpriority;
1808 info2.starttime = info.info2.starttime;
1809 info2.untiltime = info.info2.untiltime;
1810 info2.status = info.info2.status;
1811 info2.cjobs = info.info2.cjobs;
1812 info2.averageppm = info.info2.averageppm;
1815 info_ctr.info.info2 = &info2;
1820 struct spoolss_SetPrinterInfo8 info8;
1822 info8.devmode_ptr = 0;
1825 info_ctr.info.info8 = &info8;
1833 devmode_ctr.devmode = devmode;
1835 torture_assert(tctx,
1836 test_SetPrinter(tctx, p, handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0), "");
1842 static bool test_devicemode_equal(struct torture_context *tctx,
1843 const struct spoolss_DeviceMode *d1,
1844 const struct spoolss_DeviceMode *d2)
1851 torture_comment(tctx, "%s\n", __location__);
1854 torture_assert_str_equal(tctx, d1->devicename, d2->devicename, "devicename mismatch");
1855 torture_assert_int_equal(tctx, d1->specversion, d2->specversion, "specversion mismatch");
1856 torture_assert_int_equal(tctx, d1->driverversion, d2->driverversion, "driverversion mismatch");
1857 torture_assert_int_equal(tctx, d1->size, d2->size, "size mismatch");
1858 torture_assert_int_equal(tctx, d1->__driverextra_length, d2->__driverextra_length, "__driverextra_length mismatch");
1859 torture_assert_int_equal(tctx, d1->fields, d2->fields, "fields mismatch");
1860 torture_assert_int_equal(tctx, d1->orientation, d2->orientation, "orientation mismatch");
1861 torture_assert_int_equal(tctx, d1->papersize, d2->papersize, "papersize mismatch");
1862 torture_assert_int_equal(tctx, d1->paperlength, d2->paperlength, "paperlength mismatch");
1863 torture_assert_int_equal(tctx, d1->paperwidth, d2->paperwidth, "paperwidth mismatch");
1864 torture_assert_int_equal(tctx, d1->scale, d2->scale, "scale mismatch");
1865 torture_assert_int_equal(tctx, d1->copies, d2->copies, "copies mismatch");
1866 torture_assert_int_equal(tctx, d1->defaultsource, d2->defaultsource, "defaultsource mismatch");
1867 torture_assert_int_equal(tctx, d1->printquality, d2->printquality, "printquality mismatch");
1868 torture_assert_int_equal(tctx, d1->color, d2->color, "color mismatch");
1869 torture_assert_int_equal(tctx, d1->duplex, d2->duplex, "duplex mismatch");
1870 torture_assert_int_equal(tctx, d1->yresolution, d2->yresolution, "yresolution mismatch");
1871 torture_assert_int_equal(tctx, d1->ttoption, d2->ttoption, "ttoption mismatch");
1872 torture_assert_int_equal(tctx, d1->collate, d2->collate, "collate mismatch");
1873 torture_assert_str_equal(tctx, d1->formname, d2->formname, "formname mismatch");
1874 torture_assert_int_equal(tctx, d1->logpixels, d2->logpixels, "logpixels mismatch");
1875 torture_assert_int_equal(tctx, d1->bitsperpel, d2->bitsperpel, "bitsperpel mismatch");
1876 torture_assert_int_equal(tctx, d1->pelswidth, d2->pelswidth, "pelswidth mismatch");
1877 torture_assert_int_equal(tctx, d1->pelsheight, d2->pelsheight, "pelsheight mismatch");
1878 torture_assert_int_equal(tctx, d1->displayflags, d2->displayflags, "displayflags mismatch");
1879 torture_assert_int_equal(tctx, d1->displayfrequency, d2->displayfrequency, "displayfrequency mismatch");
1880 torture_assert_int_equal(tctx, d1->icmmethod, d2->icmmethod, "icmmethod mismatch");
1881 torture_assert_int_equal(tctx, d1->icmintent, d2->icmintent, "icmintent mismatch");
1882 torture_assert_int_equal(tctx, d1->mediatype, d2->mediatype, "mediatype mismatch");
1883 torture_assert_int_equal(tctx, d1->dithertype, d2->dithertype, "dithertype mismatch");
1884 torture_assert_int_equal(tctx, d1->reserved1, d2->reserved1, "reserved1 mismatch");
1885 torture_assert_int_equal(tctx, d1->reserved2, d2->reserved2, "reserved2 mismatch");
1886 torture_assert_int_equal(tctx, d1->panningwidth, d2->panningwidth, "panningwidth mismatch");
1887 torture_assert_int_equal(tctx, d1->panningheight, d2->panningheight, "panningheight mismatch");
1888 torture_assert_data_blob_equal(tctx, d1->driverextra_data, d2->driverextra_data, "driverextra_data mismatch");
1893 static bool call_OpenPrinterEx(struct torture_context *tctx,
1894 struct dcerpc_pipe *p,
1896 struct spoolss_DeviceMode *devmode,
1897 struct policy_handle *handle);
1899 static bool test_ClosePrinter(struct torture_context *tctx,
1900 struct dcerpc_pipe *p,
1901 struct policy_handle *handle);
1903 static bool test_PrinterInfo_DevModes(struct torture_context *tctx,
1904 struct dcerpc_pipe *p,
1905 struct policy_handle *handle,
1908 union spoolss_PrinterInfo info;
1909 struct spoolss_DeviceMode *devmode;
1910 struct spoolss_DeviceMode *devmode2;
1911 struct policy_handle handle_devmode;
1913 /* simply compare level8 and level2 devmode */
1915 torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 8, &info), "");
1917 devmode = info.info8.devmode;
1919 torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 2, &info), "");
1921 devmode2 = info.info2.devmode;
1923 torture_assert(tctx, test_devicemode_equal(tctx, devmode, devmode2),
1924 "DM level 8 != DM level 2");
1927 /* change formname upon open and see if it persists in getprinter calls */
1929 devmode->formname = talloc_strdup(tctx, "A4");
1931 torture_assert(tctx, call_OpenPrinterEx(tctx, p, name, devmode, &handle_devmode),
1932 "failed to open printer handle");
1934 torture_assert(tctx, test_GetPrinter_level(tctx, p, &handle_devmode, 8, &info), "");
1936 devmode2 = info.info8.devmode;
1938 if (strequal(devmode->devicename, devmode2->devicename)) {
1939 torture_fail(tctx, "devicename is the same");
1942 if (strequal(devmode->formname, devmode2->formname)) {
1943 torture_fail(tctx, "formname is the same");
1946 torture_assert(tctx, test_GetPrinter_level(tctx, p, &handle_devmode, 2, &info), "");
1948 devmode2 = info.info2.devmode;
1950 if (strequal(devmode->devicename, devmode2->devicename)) {
1951 torture_fail(tctx, "devicename is the same");
1954 if (strequal(devmode->formname, devmode2->formname)) {
1955 torture_fail(tctx, "formname is the same");
1958 test_ClosePrinter(tctx, p, &handle_devmode);
1961 /* set devicemode level 8 and see if it persists */
1963 devmode->copies = 93;
1964 devmode->formname = talloc_strdup(tctx, "Legal");
1966 torture_assert(tctx, test_devmode_set_level(tctx, p, handle, 8, devmode), "");
1968 torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 8, &info), "");
1970 devmode2 = info.info8.devmode;
1972 torture_assert(tctx, test_devicemode_equal(tctx, devmode, devmode2),
1973 "modified DM level 8 != DM level 8 after DM has been set via level 8");
1975 torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 2, &info), "");
1977 devmode2 = info.info2.devmode;
1979 torture_assert(tctx, test_devicemode_equal(tctx, devmode, devmode2),
1980 "modified DM level 8 != DM level 2");
1983 /* set devicemode level 2 and see if it persists */
1985 devmode->copies = 39;
1986 devmode->formname = talloc_strdup(tctx, "Letter");
1988 torture_assert(tctx, test_devmode_set_level(tctx, p, handle, 2, devmode), "");
1990 torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 8, &info), "");
1992 devmode2 = info.info8.devmode;
1994 torture_assert(tctx, test_devicemode_equal(tctx, devmode, devmode2),
1995 "modified DM level 8 != DM level 8 after DM has been set via level 2");
1997 torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 2, &info), "");
1999 devmode2 = info.info2.devmode;
2001 torture_assert(tctx, test_devicemode_equal(tctx, devmode, devmode2),
2002 "modified DM level 8 != DM level 2");
2009 * wrapper call that saves original devmode, runs tests, and restores devmode
2012 static bool test_PrinterInfo_DevMode(struct torture_context *tctx,
2013 struct dcerpc_pipe *p,
2014 struct policy_handle *handle,
2017 union spoolss_PrinterInfo info;
2018 struct spoolss_DeviceMode *devmode;
2021 torture_comment(tctx, "\nTesting Printer Devicemodes\n");
2023 /* save original devmode */
2025 torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 8, &info),
2026 "failed to get initial global devicemode");
2028 devmode = info.info8.devmode;
2032 ret = test_PrinterInfo_DevModes(tctx, p, handle, name);
2034 /* restore original devmode */
2036 torture_assert(tctx, test_devmode_set_level(tctx, p, handle, 8, devmode),
2037 "failed to restore initial global device mode");
2039 torture_comment(tctx, "Printer Devicemodes test %s\n",
2040 ret ? "succeeded" : "failed");
2046 static bool test_ClosePrinter(struct torture_context *tctx,
2047 struct dcerpc_pipe *p,
2048 struct policy_handle *handle)
2051 struct spoolss_ClosePrinter r;
2053 r.in.handle = handle;
2054 r.out.handle = handle;
2056 torture_comment(tctx, "Testing ClosePrinter\n");
2058 status = dcerpc_spoolss_ClosePrinter(p, tctx, &r);
2059 torture_assert_ntstatus_ok(tctx, status, "ClosePrinter failed");
2060 torture_assert_werr_ok(tctx, r.out.result, "ClosePrinter failed");
2065 static bool test_GetForm(struct torture_context *tctx,
2066 struct dcerpc_pipe *p,
2067 struct policy_handle *handle,
2068 const char *form_name,
2072 struct spoolss_GetForm r;
2075 r.in.handle = handle;
2076 r.in.form_name = form_name;
2080 r.out.needed = &needed;
2082 torture_comment(tctx, "Testing GetForm level %d\n", r.in.level);
2084 status = dcerpc_spoolss_GetForm(p, tctx, &r);
2085 torture_assert_ntstatus_ok(tctx, status, "GetForm failed");
2087 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
2088 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
2089 data_blob_clear(&blob);
2090 r.in.buffer = &blob;
2091 r.in.offered = needed;
2092 status = dcerpc_spoolss_GetForm(p, tctx, &r);
2093 torture_assert_ntstatus_ok(tctx, status, "GetForm failed");
2095 torture_assert_werr_ok(tctx, r.out.result, "GetForm failed");
2097 torture_assert(tctx, r.out.info, "No form info returned");
2100 torture_assert_werr_ok(tctx, r.out.result, "GetForm failed");
2102 CHECK_NEEDED_SIZE_LEVEL(spoolss_FormInfo, r.out.info, r.in.level, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
2107 static bool test_EnumForms(struct torture_context *tctx,
2108 struct dcerpc_pipe *p,
2109 struct policy_handle *handle, bool print_server)
2112 struct spoolss_EnumForms r;
2116 uint32_t levels[] = { 1, 2 };
2119 for (i=0; i<ARRAY_SIZE(levels); i++) {
2121 union spoolss_FormInfo *info;
2123 r.in.handle = handle;
2124 r.in.level = levels[i];
2127 r.out.needed = &needed;
2128 r.out.count = &count;
2131 torture_comment(tctx, "Testing EnumForms level %d\n", levels[i]);
2133 status = dcerpc_spoolss_EnumForms(p, tctx, &r);
2134 torture_assert_ntstatus_ok(tctx, status, "EnumForms failed");
2136 if ((r.in.level == 2) && (W_ERROR_EQUAL(r.out.result, WERR_UNKNOWN_LEVEL))) {
2140 if (print_server && W_ERROR_EQUAL(r.out.result, WERR_BADFID))
2141 torture_fail(tctx, "EnumForms on the PrintServer isn't supported by test server (NT4)");
2143 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
2145 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
2146 data_blob_clear(&blob);
2147 r.in.buffer = &blob;
2148 r.in.offered = needed;
2150 status = dcerpc_spoolss_EnumForms(p, tctx, &r);
2152 torture_assert(tctx, info, "No forms returned");
2154 for (j = 0; j < count; j++) {
2156 ret &= test_GetForm(tctx, p, handle, info[j].info1.form_name, levels[i]);
2160 torture_assert_ntstatus_ok(tctx, status, "EnumForms failed");
2162 torture_assert_werr_ok(tctx, r.out.result, "EnumForms failed");
2164 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumForms, info, r.in.level, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
2170 static bool test_DeleteForm(struct torture_context *tctx,
2171 struct dcerpc_pipe *p,
2172 struct policy_handle *handle,
2173 const char *form_name)
2176 struct spoolss_DeleteForm r;
2178 r.in.handle = handle;
2179 r.in.form_name = form_name;
2181 status = dcerpc_spoolss_DeleteForm(p, tctx, &r);
2183 torture_assert_ntstatus_ok(tctx, status, "DeleteForm failed");
2185 torture_assert_werr_ok(tctx, r.out.result, "DeleteForm failed");
2190 static bool test_AddForm(struct torture_context *tctx,
2191 struct dcerpc_pipe *p,
2192 struct policy_handle *handle, bool print_server)
2194 struct spoolss_AddForm r;
2195 struct spoolss_AddFormInfo1 addform;
2196 const char *form_name = "testform3";
2200 r.in.handle = handle;
2202 r.in.info.info1 = &addform;
2203 addform.flags = SPOOLSS_FORM_USER;
2204 addform.form_name = form_name;
2205 addform.size.width = 50;
2206 addform.size.height = 25;
2207 addform.area.left = 5;
2208 addform.area.top = 10;
2209 addform.area.right = 45;
2210 addform.area.bottom = 15;
2212 status = dcerpc_spoolss_AddForm(p, tctx, &r);
2214 torture_assert_ntstatus_ok(tctx, status, "AddForm failed");
2216 torture_assert_werr_ok(tctx, r.out.result, "AddForm failed");
2218 if (!print_server) ret &= test_GetForm(tctx, p, handle, form_name, 1);
2221 struct spoolss_SetForm sf;
2222 struct spoolss_AddFormInfo1 setform;
2224 sf.in.handle = handle;
2225 sf.in.form_name = form_name;
2227 sf.in.info.info1= &setform;
2228 setform.flags = addform.flags;
2229 setform.form_name = addform.form_name;
2230 setform.size = addform.size;
2231 setform.area = addform.area;
2233 setform.size.width = 1234;
2235 status = dcerpc_spoolss_SetForm(p, tctx, &sf);
2237 torture_assert_ntstatus_ok(tctx, status, "SetForm failed");
2239 torture_assert_werr_ok(tctx, r.out.result, "SetForm failed");
2242 if (!print_server) ret &= test_GetForm(tctx, p, handle, form_name, 1);
2245 struct spoolss_EnumForms e;
2246 union spoolss_FormInfo *info;
2251 e.in.handle = handle;
2255 e.out.needed = &needed;
2256 e.out.count = &count;
2259 torture_comment(tctx, "Testing EnumForms level 1\n");
2261 status = dcerpc_spoolss_EnumForms(p, tctx, &e);
2262 torture_assert_ntstatus_ok(tctx, status, "EnumForms failed");
2264 if (print_server && W_ERROR_EQUAL(e.out.result, WERR_BADFID))
2265 torture_fail(tctx, "EnumForms on the PrintServer isn't supported by test server (NT4)");
2267 if (W_ERROR_EQUAL(e.out.result, WERR_INSUFFICIENT_BUFFER)) {
2269 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
2270 data_blob_clear(&blob);
2271 e.in.buffer = &blob;
2272 e.in.offered = needed;
2274 status = dcerpc_spoolss_EnumForms(p, tctx, &e);
2276 torture_assert(tctx, info, "No forms returned");
2278 for (j = 0; j < count; j++) {
2279 if (strequal(form_name, info[j].info1.form_name)) {
2285 torture_assert(tctx, found, "Newly added form not found in enum call");
2288 if (!test_DeleteForm(tctx, p, handle, form_name)) {
2295 static bool test_EnumPorts_old(struct torture_context *tctx,
2296 struct dcerpc_pipe *p)
2299 struct spoolss_EnumPorts r;
2302 union spoolss_PortInfo *info;
2304 r.in.servername = talloc_asprintf(tctx, "\\\\%s",
2305 dcerpc_server_name(p));
2309 r.out.needed = &needed;
2310 r.out.count = &count;
2313 torture_comment(tctx, "Testing EnumPorts\n");
2315 status = dcerpc_spoolss_EnumPorts(p, tctx, &r);
2317 torture_assert_ntstatus_ok(tctx, status, "EnumPorts failed");
2319 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
2320 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
2321 data_blob_clear(&blob);
2322 r.in.buffer = &blob;
2323 r.in.offered = needed;
2325 status = dcerpc_spoolss_EnumPorts(p, tctx, &r);
2326 torture_assert_ntstatus_ok(tctx, status, "EnumPorts failed");
2327 torture_assert_werr_ok(tctx, r.out.result, "EnumPorts failed");
2329 torture_assert(tctx, info, "No ports returned");
2332 torture_assert_werr_ok(tctx, r.out.result, "EnumPorts failed");
2334 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPorts, info, 2, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
2339 static bool test_AddPort(struct torture_context *tctx,
2340 struct dcerpc_pipe *p)
2343 struct spoolss_AddPort r;
2345 r.in.server_name = talloc_asprintf(tctx, "\\\\%s",
2346 dcerpc_server_name(p));
2348 r.in.monitor_name = "foo";
2350 torture_comment(tctx, "Testing AddPort\n");
2352 status = dcerpc_spoolss_AddPort(p, tctx, &r);
2354 torture_assert_ntstatus_ok(tctx, status, "AddPort failed");
2356 /* win2k3 returns WERR_NOT_SUPPORTED */
2360 if (!W_ERROR_IS_OK(r.out.result)) {
2361 printf("AddPort failed - %s\n", win_errstr(r.out.result));
2370 static bool test_GetJob(struct torture_context *tctx,
2371 struct dcerpc_pipe *p,
2372 struct policy_handle *handle, uint32_t job_id)
2375 struct spoolss_GetJob r;
2376 union spoolss_JobInfo info;
2378 uint32_t levels[] = {1, 2 /* 3, 4 */};
2381 r.in.handle = handle;
2382 r.in.job_id = job_id;
2386 r.out.needed = &needed;
2389 torture_comment(tctx, "Testing GetJob level %d\n", r.in.level);
2391 status = dcerpc_spoolss_GetJob(p, tctx, &r);
2392 torture_assert_werr_equal(tctx, r.out.result, WERR_UNKNOWN_LEVEL, "Unexpected return code");
2394 for (i = 0; i < ARRAY_SIZE(levels); i++) {
2396 torture_comment(tctx, "Testing GetJob level %d\n", r.in.level);
2400 r.in.level = levels[i];
2404 status = dcerpc_spoolss_GetJob(p, tctx, &r);
2405 torture_assert_ntstatus_ok(tctx, status, "GetJob failed");
2407 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
2408 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
2409 data_blob_clear(&blob);
2410 r.in.buffer = &blob;
2411 r.in.offered = needed;
2413 status = dcerpc_spoolss_GetJob(p, tctx, &r);
2414 torture_assert_ntstatus_ok(tctx, status, "GetJob failed");
2417 torture_assert(tctx, r.out.info, "No job info returned");
2418 torture_assert_werr_ok(tctx, r.out.result, "GetJob failed");
2420 CHECK_NEEDED_SIZE_LEVEL(spoolss_JobInfo, r.out.info, r.in.level, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
2426 static bool test_SetJob(struct torture_context *tctx,
2427 struct dcerpc_pipe *p,
2428 struct policy_handle *handle, uint32_t job_id,
2429 enum spoolss_JobControl command)
2432 struct spoolss_SetJob r;
2434 r.in.handle = handle;
2435 r.in.job_id = job_id;
2437 r.in.command = command;
2440 case SPOOLSS_JOB_CONTROL_PAUSE:
2441 torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_PAUSE\n");
2443 case SPOOLSS_JOB_CONTROL_RESUME:
2444 torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_RESUME\n");
2446 case SPOOLSS_JOB_CONTROL_CANCEL:
2447 torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_CANCEL\n");
2449 case SPOOLSS_JOB_CONTROL_RESTART:
2450 torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_RESTART\n");
2452 case SPOOLSS_JOB_CONTROL_DELETE:
2453 torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_DELETE\n");
2455 case SPOOLSS_JOB_CONTROL_SEND_TO_PRINTER:
2456 torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_SEND_TO_PRINTER\n");
2458 case SPOOLSS_JOB_CONTROL_LAST_PAGE_EJECTED:
2459 torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_LAST_PAGE_EJECTED\n");
2461 case SPOOLSS_JOB_CONTROL_RETAIN:
2462 torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_RETAIN\n");
2464 case SPOOLSS_JOB_CONTROL_RELEASE:
2465 torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_RELEASE\n");
2468 torture_comment(tctx, "Testing SetJob\n");
2472 status = dcerpc_spoolss_SetJob(p, tctx, &r);
2473 torture_assert_ntstatus_ok(tctx, status, "SetJob failed");
2474 torture_assert_werr_ok(tctx, r.out.result, "SetJob failed");
2479 static bool test_AddJob(struct torture_context *tctx,
2480 struct dcerpc_pipe *p,
2481 struct policy_handle *handle)
2484 struct spoolss_AddJob r;
2488 r.in.handle = handle;
2490 r.out.needed = &needed;
2491 r.in.buffer = r.out.buffer = NULL;
2493 torture_comment(tctx, "Testing AddJob\n");
2495 status = dcerpc_spoolss_AddJob(p, tctx, &r);
2496 torture_assert_werr_equal(tctx, r.out.result, WERR_UNKNOWN_LEVEL, "AddJob failed");
2500 status = dcerpc_spoolss_AddJob(p, tctx, &r);
2501 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAM, "AddJob failed");
2507 static bool test_EnumJobs(struct torture_context *tctx,
2508 struct dcerpc_pipe *p,
2509 struct policy_handle *handle)
2512 struct spoolss_EnumJobs r;
2515 union spoolss_JobInfo *info;
2517 r.in.handle = handle;
2519 r.in.numjobs = 0xffffffff;
2523 r.out.needed = &needed;
2524 r.out.count = &count;
2527 torture_comment(tctx, "Testing EnumJobs\n");
2529 status = dcerpc_spoolss_EnumJobs(p, tctx, &r);
2531 torture_assert_ntstatus_ok(tctx, status, "EnumJobs failed");
2533 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
2535 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
2536 data_blob_clear(&blob);
2537 r.in.buffer = &blob;
2538 r.in.offered = needed;
2540 status = dcerpc_spoolss_EnumJobs(p, tctx, &r);
2542 torture_assert_ntstatus_ok(tctx, status, "EnumJobs failed");
2543 torture_assert_werr_ok(tctx, r.out.result, "EnumJobs failed");
2544 torture_assert(tctx, info, "No jobs returned");
2546 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumJobs, *r.out.info, r.in.level, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
2548 for (j = 0; j < count; j++) {
2550 torture_assert(tctx, test_GetJob(tctx, p, handle, info[j].info1.job_id),
2551 "failed to call test_GetJob");
2554 if (!torture_setting_bool(tctx, "samba3", false)) {
2555 test_SetJob(tctx, p, handle, info[j].info1.job_id, SPOOLSS_JOB_CONTROL_PAUSE);
2556 test_SetJob(tctx, p, handle, info[j].info1.job_id, SPOOLSS_JOB_CONTROL_RESUME);
2561 torture_assert_werr_ok(tctx, r.out.result, "EnumJobs failed");
2567 static bool test_DoPrintTest(struct torture_context *tctx,
2568 struct dcerpc_pipe *p,
2569 struct policy_handle *handle)
2573 struct spoolss_StartDocPrinter s;
2574 struct spoolss_DocumentInfo1 info1;
2575 struct spoolss_StartPagePrinter sp;
2576 struct spoolss_WritePrinter w;
2577 struct spoolss_EndPagePrinter ep;
2578 struct spoolss_EndDocPrinter e;
2581 uint32_t num_written;
2583 torture_comment(tctx, "Testing StartDocPrinter\n");
2585 s.in.handle = handle;
2587 s.in.info.info1 = &info1;
2588 s.out.job_id = &job_id;
2589 info1.document_name = "TorturePrintJob";
2590 info1.output_file = NULL;
2591 info1.datatype = "RAW";
2593 status = dcerpc_spoolss_StartDocPrinter(p, tctx, &s);
2594 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_StartDocPrinter failed");
2595 torture_assert_werr_ok(tctx, s.out.result, "StartDocPrinter failed");
2597 for (i=1; i < 4; i++) {
2598 torture_comment(tctx, "Testing StartPagePrinter: Page[%d]\n", i);
2600 sp.in.handle = handle;
2602 status = dcerpc_spoolss_StartPagePrinter(p, tctx, &sp);
2603 torture_assert_ntstatus_ok(tctx, status,
2604 "dcerpc_spoolss_StartPagePrinter failed");
2605 torture_assert_werr_ok(tctx, sp.out.result, "StartPagePrinter failed");
2607 torture_comment(tctx, "Testing WritePrinter: Page[%d]\n", i);
2609 w.in.handle = handle;
2610 w.in.data = data_blob_string_const(talloc_asprintf(tctx,"TortureTestPage: %d\nData\n",i));
2611 w.out.num_written = &num_written;
2613 status = dcerpc_spoolss_WritePrinter(p, tctx, &w);
2614 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_WritePrinter failed");
2615 torture_assert_werr_ok(tctx, w.out.result, "WritePrinter failed");
2617 torture_comment(tctx, "Testing EndPagePrinter: Page[%d]\n", i);
2619 ep.in.handle = handle;
2621 status = dcerpc_spoolss_EndPagePrinter(p, tctx, &ep);
2622 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EndPagePrinter failed");
2623 torture_assert_werr_ok(tctx, ep.out.result, "EndPagePrinter failed");
2626 torture_comment(tctx, "Testing EndDocPrinter\n");
2628 e.in.handle = handle;
2630 status = dcerpc_spoolss_EndDocPrinter(p, tctx, &e);
2631 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EndDocPrinter failed");
2632 torture_assert_werr_ok(tctx, e.out.result, "EndDocPrinter failed");
2634 ret &= test_AddJob(tctx, p, handle);
2635 ret &= test_EnumJobs(tctx, p, handle);
2637 ret &= test_SetJob(tctx, p, handle, job_id, SPOOLSS_JOB_CONTROL_DELETE);
2642 static bool test_PausePrinter(struct torture_context *tctx,
2643 struct dcerpc_pipe *p,
2644 struct policy_handle *handle)
2647 struct spoolss_SetPrinter r;
2648 struct spoolss_SetPrinterInfoCtr info_ctr;
2649 struct spoolss_DevmodeContainer devmode_ctr;
2650 struct sec_desc_buf secdesc_ctr;
2653 info_ctr.info.info0 = NULL;
2655 ZERO_STRUCT(devmode_ctr);
2656 ZERO_STRUCT(secdesc_ctr);
2658 r.in.handle = handle;
2659 r.in.info_ctr = &info_ctr;
2660 r.in.devmode_ctr = &devmode_ctr;
2661 r.in.secdesc_ctr = &secdesc_ctr;
2662 r.in.command = SPOOLSS_PRINTER_CONTROL_PAUSE;
2664 torture_comment(tctx, "Testing SetPrinter: SPOOLSS_PRINTER_CONTROL_PAUSE\n");
2666 status = dcerpc_spoolss_SetPrinter(p, tctx, &r);
2668 torture_assert_ntstatus_ok(tctx, status, "SetPrinter failed");
2670 torture_assert_werr_ok(tctx, r.out.result, "SetPrinter failed");
2675 static bool test_ResumePrinter(struct torture_context *tctx,
2676 struct dcerpc_pipe *p,
2677 struct policy_handle *handle)
2680 struct spoolss_SetPrinter r;
2681 struct spoolss_SetPrinterInfoCtr info_ctr;
2682 struct spoolss_DevmodeContainer devmode_ctr;
2683 struct sec_desc_buf secdesc_ctr;
2686 info_ctr.info.info0 = NULL;
2688 ZERO_STRUCT(devmode_ctr);
2689 ZERO_STRUCT(secdesc_ctr);
2691 r.in.handle = handle;
2692 r.in.info_ctr = &info_ctr;
2693 r.in.devmode_ctr = &devmode_ctr;
2694 r.in.secdesc_ctr = &secdesc_ctr;
2695 r.in.command = SPOOLSS_PRINTER_CONTROL_RESUME;
2697 torture_comment(tctx, "Testing SetPrinter: SPOOLSS_PRINTER_CONTROL_RESUME\n");
2699 status = dcerpc_spoolss_SetPrinter(p, tctx, &r);
2701 torture_assert_ntstatus_ok(tctx, status, "SetPrinter failed");
2703 torture_assert_werr_ok(tctx, r.out.result, "SetPrinter failed");
2708 static bool test_GetPrinterData(struct torture_context *tctx,
2709 struct dcerpc_pipe *p,
2710 struct policy_handle *handle,
2711 const char *value_name,
2712 enum winreg_Type *type_p,
2713 union spoolss_PrinterData *data_p)
2716 struct spoolss_GetPrinterData r;
2718 enum winreg_Type type;
2719 union spoolss_PrinterData data;
2721 r.in.handle = handle;
2722 r.in.value_name = value_name;
2724 r.out.needed = &needed;
2728 torture_comment(tctx, "Testing GetPrinterData(%s)\n", r.in.value_name);
2730 status = dcerpc_spoolss_GetPrinterData(p, tctx, &r);
2731 torture_assert_ntstatus_ok(tctx, status, "GetPrinterData failed");
2733 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
2734 r.in.offered = needed;
2736 status = dcerpc_spoolss_GetPrinterData(p, tctx, &r);
2737 torture_assert_ntstatus_ok(tctx, status, "GetPrinterData failed");
2740 torture_assert_werr_ok(tctx, r.out.result,
2741 talloc_asprintf(tctx, "GetPrinterData(%s) failed", r.in.value_name));
2743 CHECK_NEEDED_SIZE_LEVEL(spoolss_PrinterData, &data, type, lp_iconv_convenience(tctx->lp_ctx), needed, 1);
2756 static bool test_GetPrinterDataEx(struct torture_context *tctx,
2757 struct dcerpc_pipe *p,
2758 struct policy_handle *handle,
2759 const char *key_name,
2760 const char *value_name,
2761 enum winreg_Type *type_p,
2762 union spoolss_PrinterData *data_p)
2765 struct spoolss_GetPrinterDataEx r;
2766 enum winreg_Type type;
2768 union spoolss_PrinterData data;
2770 r.in.handle = handle;
2771 r.in.key_name = key_name;
2772 r.in.value_name = value_name;
2775 r.out.needed = &needed;
2778 torture_comment(tctx, "Testing GetPrinterDataEx(%s - %s)\n",
2779 r.in.key_name, r.in.value_name);
2781 status = dcerpc_spoolss_GetPrinterDataEx(p, tctx, &r);
2782 if (!NT_STATUS_IS_OK(status)) {
2783 if (NT_STATUS_EQUAL(status,NT_STATUS_NET_WRITE_FAULT) &&
2784 p->last_fault_code == DCERPC_FAULT_OP_RNG_ERROR) {
2785 torture_skip(tctx, "GetPrinterDataEx not supported by server\n");
2787 torture_assert_ntstatus_ok(tctx, status, "GetPrinterDataEx failed");
2790 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
2791 r.in.offered = needed;
2792 status = dcerpc_spoolss_GetPrinterDataEx(p, tctx, &r);
2793 torture_assert_ntstatus_ok(tctx, status, "GetPrinterDataEx failed");
2796 torture_assert_werr_ok(tctx, r.out.result,
2797 talloc_asprintf(tctx, "GetPrinterDataEx(%s - %s) failed", r.in.key_name, r.in.value_name));
2799 CHECK_NEEDED_SIZE_LEVEL(spoolss_PrinterData, &data, type, lp_iconv_convenience(tctx->lp_ctx), needed, 1);
2812 static bool test_GetPrinterData_list(struct torture_context *tctx,
2813 struct dcerpc_pipe *p,
2814 struct policy_handle *handle)
2816 const char *list[] = {
2820 /* "NetPopup", not on w2k8 */
2821 /* "NetPopupToComputer", not on w2k8 */
2824 "DefaultSpoolDirectory",
2828 /* "OSVersionEx", not on s3 */
2833 for (i=0; i < ARRAY_SIZE(list); i++) {
2834 enum winreg_Type type, type_ex;
2835 union spoolss_PrinterData data, data_ex;
2837 torture_assert(tctx, test_GetPrinterData(tctx, p, handle, list[i], &type, &data),
2838 talloc_asprintf(tctx, "GetPrinterData failed on %s\n", list[i]));
2839 torture_assert(tctx, test_GetPrinterDataEx(tctx, p, handle, "random_string", list[i], &type_ex, &data_ex),
2840 talloc_asprintf(tctx, "GetPrinterDataEx failed on %s\n", list[i]));
2841 torture_assert_int_equal(tctx, type, type_ex, "type mismatch");
2844 torture_assert_str_equal(tctx, data.string, data_ex.string, "REG_SZ mismatch");
2847 torture_assert_int_equal(tctx, data.value, data_ex.value, "REG_DWORD mismatch");
2850 torture_assert_data_blob_equal(tctx, data.binary, data_ex.binary, "REG_BINARY mismatch");
2860 static bool test_EnumPrinterData(struct torture_context *tctx, struct dcerpc_pipe *p,
2861 struct policy_handle *handle)
2864 struct spoolss_EnumPrinterData r;
2867 r.in.handle = handle;
2868 r.in.enum_index = 0;
2871 uint32_t value_size = 0;
2872 uint32_t data_size = 0;
2873 enum winreg_Type type = 0;
2875 r.in.value_offered = value_size;
2876 r.out.value_needed = &value_size;
2877 r.in.data_offered = data_size;
2878 r.out.data_needed = &data_size;
2881 r.out.data = talloc_zero_array(tctx, uint8_t, 0);
2883 torture_comment(tctx, "Testing EnumPrinterData\n");
2885 status = dcerpc_spoolss_EnumPrinterData(p, tctx, &r);
2887 torture_assert_ntstatus_ok(tctx, status, "EnumPrinterData failed");
2888 if (W_ERROR_EQUAL(r.out.result, WERR_NO_MORE_ITEMS)) {
2891 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinterData");
2893 r.in.value_offered = value_size;
2894 r.out.value_name = talloc_zero_array(tctx, const char, value_size);
2895 r.in.data_offered = data_size;
2896 r.out.data = talloc_zero_array(tctx, uint8_t, data_size);
2898 status = dcerpc_spoolss_EnumPrinterData(p, tctx, &r);
2900 torture_assert_ntstatus_ok(tctx, status, "EnumPrinterData failed");
2901 if (W_ERROR_EQUAL(r.out.result, WERR_NO_MORE_ITEMS)) {
2905 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinterData failed");
2907 torture_assert(tctx, test_GetPrinterData(tctx, p, handle, r.out.value_name, NULL, NULL),
2908 talloc_asprintf(tctx, "failed to call GetPrinterData for %s\n", r.out.value_name));
2910 torture_assert(tctx, test_GetPrinterDataEx(tctx, p, handle, "PrinterDriverData", r.out.value_name, NULL, NULL),
2911 talloc_asprintf(tctx, "failed to call GetPrinterDataEx on PrinterDriverData for %s\n", r.out.value_name));
2915 } while (W_ERROR_IS_OK(r.out.result));
2920 static bool test_EnumPrinterDataEx(struct torture_context *tctx,
2921 struct dcerpc_pipe *p,
2922 struct policy_handle *handle,
2923 const char *key_name)
2925 struct spoolss_EnumPrinterDataEx r;
2926 struct spoolss_PrinterEnumValues *info;
2930 r.in.handle = handle;
2931 r.in.key_name = key_name;
2933 r.out.needed = &needed;
2934 r.out.count = &count;
2937 torture_comment(tctx, "Testing EnumPrinterDataEx(%s)\n", key_name);
2939 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinterDataEx(p, tctx, &r),
2940 "EnumPrinterDataEx failed");
2941 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
2942 r.in.offered = needed;
2943 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinterDataEx(p, tctx, &r),
2944 "EnumPrinterDataEx failed");
2947 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinterDataEx failed");
2949 CHECK_NEEDED_SIZE_ENUM(spoolss_EnumPrinterDataEx, info, count, lp_iconv_convenience(tctx->lp_ctx), needed, 1);
2955 static bool test_DeletePrinterData(struct torture_context *tctx,
2956 struct dcerpc_pipe *p,
2957 struct policy_handle *handle,
2958 const char *value_name)
2961 struct spoolss_DeletePrinterData r;
2963 r.in.handle = handle;
2964 r.in.value_name = value_name;
2966 torture_comment(tctx, "Testing DeletePrinterData(%s)\n",
2969 status = dcerpc_spoolss_DeletePrinterData(p, tctx, &r);
2971 torture_assert_ntstatus_ok(tctx, status, "DeletePrinterData failed");
2972 torture_assert_werr_ok(tctx, r.out.result, "DeletePrinterData failed");
2977 static bool test_DeletePrinterDataEx(struct torture_context *tctx,
2978 struct dcerpc_pipe *p,
2979 struct policy_handle *handle,
2980 const char *key_name,
2981 const char *value_name)
2983 struct spoolss_DeletePrinterDataEx r;
2985 r.in.handle = handle;
2986 r.in.key_name = key_name;
2987 r.in.value_name = value_name;
2989 torture_comment(tctx, "Testing DeletePrinterDataEx(%s - %s)\n",
2990 r.in.key_name, r.in.value_name);
2992 torture_assert_ntstatus_ok(tctx,
2993 dcerpc_spoolss_DeletePrinterDataEx(p, tctx, &r),
2994 "DeletePrinterDataEx failed");
2995 torture_assert_werr_ok(tctx, r.out.result,
2996 "DeletePrinterDataEx failed");
3001 static bool test_DeletePrinterKey(struct torture_context *tctx,
3002 struct dcerpc_pipe *p,
3003 struct policy_handle *handle,
3004 const char *key_name)
3006 struct spoolss_DeletePrinterKey r;
3008 r.in.handle = handle;
3009 r.in.key_name = key_name;
3011 torture_comment(tctx, "Testing DeletePrinterKey(%s)\n", r.in.key_name);
3013 if (strequal(key_name, "") && !torture_setting_bool(tctx, "dangerous", false)) {
3014 torture_skip(tctx, "not wiping out printer registry - enable dangerous tests to use\n");
3018 torture_assert_ntstatus_ok(tctx,
3019 dcerpc_spoolss_DeletePrinterKey(p, tctx, &r),
3020 "DeletePrinterKey failed");
3021 torture_assert_werr_ok(tctx, r.out.result,
3022 "DeletePrinterKey failed");
3027 static bool test_SetPrinterData(struct torture_context *tctx,
3028 struct dcerpc_pipe *p,
3029 struct policy_handle *handle)
3032 struct spoolss_SetPrinterData r;
3033 const char *values[] = {
3037 /* FIXME: not working with s3 atm. */
3043 /* FIXME: not working with s3 atm. */
3050 for (i=0; i < ARRAY_SIZE(values); i++) {
3052 enum winreg_Type type;
3053 union spoolss_PrinterData data;
3055 r.in.handle = handle;
3056 r.in.value_name = values[i];
3058 r.in.data.string = "dog";
3060 torture_comment(tctx, "Testing SetPrinterData(%s)\n",
3063 status = dcerpc_spoolss_SetPrinterData(p, tctx, &r);
3065 torture_assert_ntstatus_ok(tctx, status, "SetPrinterData failed");
3066 torture_assert_werr_ok(tctx, r.out.result, "SetPrinterData failed");
3068 if (!test_GetPrinterData(tctx, p, handle, r.in.value_name, &type, &data)) {
3072 torture_assert_int_equal(tctx, r.in.type, type, "type mismatch");
3073 torture_assert_str_equal(tctx, r.in.data.string, data.string, "data mismatch");
3075 if (!test_DeletePrinterData(tctx, p, handle, r.in.value_name)) {
3083 static bool test_EnumPrinterKey(struct torture_context *tctx,
3084 struct dcerpc_pipe *p,
3085 struct policy_handle *handle,
3086 const char *key_name,
3087 const char ***array);
3089 static bool test_SetPrinterDataEx(struct torture_context *tctx,
3090 struct dcerpc_pipe *p,
3091 struct policy_handle *handle)
3094 struct spoolss_SetPrinterDataEx r;
3095 const char *value_name = "dog";
3096 const char *keys[] = {
3100 /* FIXME: not working with s3 atm. */
3101 "torturedataex_with_subkey\\subkey",
3102 "torturedataex_with_subkey\\subkey:0",
3103 "torturedataex_with_subkey\\subkey:1",
3104 "torturedataex_with_subkey\\subkey\\subsubkey",
3105 "torturedataex_with_subkey\\subkey\\subsubkey:0",
3106 "torturedataex_with_subkey\\subkey\\subsubkey:1",
3110 /* FIXME: not working with s3 atm. */
3118 DATA_BLOB blob = data_blob_string_const("catfoobar");
3121 for (i=0; i < ARRAY_SIZE(keys); i++) {
3125 enum winreg_Type type;
3126 const char **subkeys;
3127 union spoolss_PrinterData data;
3129 r.in.handle = handle;
3130 r.in.key_name = keys[i];
3131 r.in.value_name = value_name;
3132 r.in.type = REG_BINARY;
3133 r.in.data.binary = blob;
3135 torture_comment(tctx, "Testing SetPrinterDataEx(%s - %s)\n", r.in.key_name, value_name);
3137 status = dcerpc_spoolss_SetPrinterDataEx(p, tctx, &r);
3139 torture_assert_ntstatus_ok(tctx, status, "SetPrinterDataEx failed");
3140 torture_assert_werr_ok(tctx, r.out.result, "SetPrinterDataEx failed");
3142 key = talloc_strdup(tctx, r.in.key_name);
3144 if (!test_GetPrinterDataEx(tctx, p, handle, r.in.key_name, value_name, &type, &data)) {
3148 torture_assert_int_equal(tctx, r.in.type, type, "type mismatch");
3149 torture_assert_data_blob_equal(tctx, blob, data.binary, "data mismatch");
3151 if (!test_EnumPrinterDataEx(tctx, p, handle, r.in.key_name)) {
3155 if (!test_DeletePrinterDataEx(tctx, p, handle, r.in.key_name, value_name)) {
3159 c = strchr(key, '\\');
3163 /* we have subkeys */
3167 if (!test_EnumPrinterKey(tctx, p, handle, key, &subkeys)) {
3171 for (i=0; subkeys && subkeys[i]; i++) {
3173 const char *current_key = talloc_asprintf(tctx, "%s\\%s", key, subkeys[i]);
3175 if (!test_DeletePrinterKey(tctx, p, handle, current_key)) {
3180 if (!test_DeletePrinterKey(tctx, p, handle, key)) {
3185 if (!test_DeletePrinterKey(tctx, p, handle, key)) {
3194 static bool test_GetChangeID_PrinterData(struct torture_context *tctx,
3195 struct dcerpc_pipe *p,
3196 struct policy_handle *handle,
3197 uint32_t *change_id)
3199 enum winreg_Type type;
3200 union spoolss_PrinterData data;
3202 torture_assert(tctx,
3203 test_GetPrinterData(tctx, p, handle, "ChangeID", &type, &data),
3204 "failed to call GetPrinterData");
3206 torture_assert(tctx, type == REG_DWORD, "unexpected type");
3208 *change_id = data.value;
3213 static bool test_GetChangeID_PrinterDataEx(struct torture_context *tctx,
3214 struct dcerpc_pipe *p,
3215 struct policy_handle *handle,
3216 uint32_t *change_id)
3218 enum winreg_Type type;
3219 union spoolss_PrinterData data;
3221 torture_assert(tctx,
3222 test_GetPrinterDataEx(tctx, p, handle, "PrinterDriverData", "ChangeID", &type, &data),
3223 "failed to call GetPrinterData");
3225 torture_assert(tctx, type == REG_DWORD, "unexpected type");
3227 *change_id = data.value;
3232 static bool test_GetChangeID_PrinterInfo(struct torture_context *tctx,
3233 struct dcerpc_pipe *p,
3234 struct policy_handle *handle,
3235 uint32_t *change_id)
3237 union spoolss_PrinterInfo info;
3239 torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 0, &info),
3240 "failed to query Printer level 0");
3242 *change_id = info.info0.change_id;
3247 static bool test_ChangeID(struct torture_context *tctx,
3248 struct dcerpc_pipe *p,
3249 struct policy_handle *handle)
3251 uint32_t change_id, change_id_ex, change_id_info;
3252 uint32_t change_id2, change_id_ex2, change_id_info2;
3253 union spoolss_PrinterInfo info;
3254 const char *comment;
3257 torture_comment(tctx, "Testing ChangeID: id change test #1\n");
3259 torture_assert(tctx, test_GetChangeID_PrinterData(tctx, p, handle, &change_id),
3260 "failed to query for ChangeID");
3261 torture_assert(tctx, test_GetChangeID_PrinterDataEx(tctx, p, handle, &change_id_ex),
3262 "failed to query for ChangeID");
3263 torture_assert(tctx, test_GetChangeID_PrinterInfo(tctx, p, handle, &change_id_info),
3264 "failed to query for ChangeID");
3266 torture_assert_int_equal(tctx, change_id, change_id_ex,
3267 "change_ids should all be equal");
3268 torture_assert_int_equal(tctx, change_id_ex, change_id_info,
3269 "change_ids should all be equal");
3272 torture_comment(tctx, "Testing ChangeID: id change test #2\n");
3274 torture_assert(tctx, test_GetChangeID_PrinterData(tctx, p, handle, &change_id),
3275 "failed to query for ChangeID");
3276 torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 2, &info),
3277 "failed to query Printer level 2");
3278 torture_assert(tctx, test_GetChangeID_PrinterDataEx(tctx, p, handle, &change_id_ex),
3279 "failed to query for ChangeID");
3280 torture_assert(tctx, test_GetChangeID_PrinterInfo(tctx, p, handle, &change_id_info),
3281 "failed to query for ChangeID");
3282 torture_assert_int_equal(tctx, change_id, change_id_ex,
3283 "change_id should not have changed");
3284 torture_assert_int_equal(tctx, change_id_ex, change_id_info,
3285 "change_id should not have changed");
3288 torture_comment(tctx, "Testing ChangeID: id change test #3\n");
3290 torture_assert(tctx, test_GetChangeID_PrinterData(tctx, p, handle, &change_id),
3291 "failed to query for ChangeID");
3292 torture_assert(tctx, test_GetChangeID_PrinterDataEx(tctx, p, handle, &change_id_ex),
3293 "failed to query for ChangeID");
3294 torture_assert(tctx, test_GetChangeID_PrinterInfo(tctx, p, handle, &change_id_info),
3295 "failed to query for ChangeID");
3296 torture_assert(tctx, test_GetPrinter_level(tctx, p, handle, 2, &info),
3297 "failed to query Printer level 2");
3298 comment = talloc_strdup(tctx, info.info2.comment);
3301 struct spoolss_SetPrinterInfoCtr info_ctr;
3302 struct spoolss_DevmodeContainer devmode_ctr;
3303 struct sec_desc_buf secdesc_ctr;
3304 struct spoolss_SetPrinterInfo2 info2;
3306 ZERO_STRUCT(info_ctr);
3307 ZERO_STRUCT(devmode_ctr);
3308 ZERO_STRUCT(secdesc_ctr);
3310 info2.servername = info.info2.servername;
3311 info2.printername = info.info2.printername;
3312 info2.sharename = info.info2.sharename;
3313 info2.portname = info.info2.portname;
3314 info2.drivername = info.info2.drivername;
3315 info2.comment = "torture_comment";
3316 info2.location = info.info2.location;
3317 info2.devmode_ptr = 0;
3318 info2.sepfile = info.info2.sepfile;
3319 info2.printprocessor = info.info2.printprocessor;
3320 info2.datatype = info.info2.datatype;
3321 info2.parameters = info.info2.parameters;
3322 info2.secdesc_ptr = 0;
3323 info2.attributes = info.info2.attributes;
3324 info2.priority = info.info2.priority;
3325 info2.defaultpriority = info.info2.defaultpriority;
3326 info2.starttime = info.info2.starttime;
3327 info2.untiltime = info.info2.untiltime;
3328 info2.status = info.info2.status;
3329 info2.cjobs = info.info2.cjobs;
3330 info2.averageppm = info.info2.averageppm;
3333 info_ctr.info.info2 = &info2;
3335 torture_assert(tctx, test_SetPrinter(tctx, p, handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0),
3336 "failed to call SetPrinter");
3338 info2.comment = comment;
3340 torture_assert(tctx, test_SetPrinter(tctx, p, handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0),
3341 "failed to call SetPrinter");
3345 torture_assert(tctx, test_GetChangeID_PrinterData(tctx, p, handle, &change_id2),
3346 "failed to query for ChangeID");
3347 torture_assert(tctx, test_GetChangeID_PrinterDataEx(tctx, p, handle, &change_id_ex2),
3348 "failed to query for ChangeID");
3349 torture_assert(tctx, test_GetChangeID_PrinterInfo(tctx, p, handle, &change_id_info2),
3350 "failed to query for ChangeID");
3352 torture_assert_int_equal(tctx, change_id2, change_id_ex2,
3353 "change_ids should all be equal");
3354 torture_assert_int_equal(tctx, change_id_ex2, change_id_info2,
3355 "change_ids should all be equal");
3357 torture_assert(tctx, (change_id < change_id2),
3358 talloc_asprintf(tctx, "change_id %d needs to be larger than change_id %d",
3359 change_id2, change_id));
3360 torture_assert(tctx, (change_id_ex < change_id_ex2),
3361 talloc_asprintf(tctx, "change_id %d needs to be larger than change_id %d",
3362 change_id_ex2, change_id_ex));
3363 torture_assert(tctx, (change_id_info < change_id_info2),
3364 talloc_asprintf(tctx, "change_id %d needs to be larger than change_id %d",
3365 change_id_info2, change_id_info));
3370 static bool test_SecondaryClosePrinter(struct torture_context *tctx,
3371 struct dcerpc_pipe *p,
3372 struct policy_handle *handle)
3375 struct dcerpc_binding *b;
3376 struct dcerpc_pipe *p2;
3377 struct spoolss_ClosePrinter cp;
3379 /* only makes sense on SMB */
3380 if (p->conn->transport.transport != NCACN_NP) {
3384 torture_comment(tctx, "testing close on secondary pipe\n");
3386 status = dcerpc_parse_binding(tctx, p->conn->binding_string, &b);
3387 torture_assert_ntstatus_ok(tctx, status, "Failed to parse dcerpc binding");
3389 status = dcerpc_secondary_connection(p, &p2, b);
3390 torture_assert_ntstatus_ok(tctx, status, "Failed to create secondary connection");
3392 status = dcerpc_bind_auth_none(p2, &ndr_table_spoolss);
3393 torture_assert_ntstatus_ok(tctx, status, "Failed to create bind on secondary connection");
3395 cp.in.handle = handle;
3396 cp.out.handle = handle;
3398 status = dcerpc_spoolss_ClosePrinter(p2, tctx, &cp);
3399 torture_assert_ntstatus_equal(tctx, status, NT_STATUS_NET_WRITE_FAULT,
3400 "ERROR: Allowed close on secondary connection");
3402 torture_assert_int_equal(tctx, p2->last_fault_code, DCERPC_FAULT_CONTEXT_MISMATCH,
3403 "Unexpected fault code");
3410 static bool test_OpenPrinter_badname(struct torture_context *tctx,
3411 struct dcerpc_pipe *p, const char *name)
3414 struct spoolss_OpenPrinter op;
3415 struct spoolss_OpenPrinterEx opEx;
3416 struct policy_handle handle;
3419 op.in.printername = name;
3420 op.in.datatype = NULL;
3421 op.in.devmode_ctr.devmode= NULL;
3422 op.in.access_mask = 0;
3423 op.out.handle = &handle;
3425 torture_comment(tctx, "\nTesting OpenPrinter(%s) with bad name\n", op.in.printername);
3427 status = dcerpc_spoolss_OpenPrinter(p, tctx, &op);
3428 torture_assert_ntstatus_ok(tctx, status, "OpenPrinter failed");
3429 if (!W_ERROR_EQUAL(WERR_INVALID_PRINTER_NAME,op.out.result)) {
3430 torture_comment(tctx, "OpenPrinter(%s) unexpected result[%s] should be WERR_INVALID_PRINTER_NAME\n",
3431 name, win_errstr(op.out.result));
3434 if (W_ERROR_IS_OK(op.out.result)) {
3435 ret &=test_ClosePrinter(tctx, p, &handle);
3438 opEx.in.printername = name;
3439 opEx.in.datatype = NULL;
3440 opEx.in.devmode_ctr.devmode = NULL;
3441 opEx.in.access_mask = 0;
3443 opEx.in.userlevel.level1 = NULL;
3444 opEx.out.handle = &handle;
3446 torture_comment(tctx, "Testing OpenPrinterEx(%s) with bad name\n", opEx.in.printername);
3448 status = dcerpc_spoolss_OpenPrinterEx(p, tctx, &opEx);
3449 torture_assert_ntstatus_ok(tctx, status, "OpenPrinterEx failed");
3450 if (!W_ERROR_EQUAL(WERR_INVALID_PARAM,opEx.out.result)) {
3451 torture_comment(tctx, "OpenPrinterEx(%s) unexpected result[%s] should be WERR_INVALID_PARAM\n",
3452 name, win_errstr(opEx.out.result));
3455 if (W_ERROR_IS_OK(opEx.out.result)) {
3456 ret &=test_ClosePrinter(tctx, p, &handle);
3462 static bool test_OpenPrinter(struct torture_context *tctx,
3463 struct dcerpc_pipe *p,
3467 struct spoolss_OpenPrinter r;
3468 struct policy_handle handle;
3471 r.in.printername = talloc_asprintf(tctx, "\\\\%s\\%s", dcerpc_server_name(p), name);
3472 r.in.datatype = NULL;
3473 r.in.devmode_ctr.devmode= NULL;
3474 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3475 r.out.handle = &handle;
3477 torture_comment(tctx, "Testing OpenPrinter(%s)\n", r.in.printername);
3479 status = dcerpc_spoolss_OpenPrinter(p, tctx, &r);
3481 torture_assert_ntstatus_ok(tctx, status, "OpenPrinter failed");
3483 torture_assert_werr_ok(tctx, r.out.result, "OpenPrinter failed");
3485 if (!test_GetPrinter(tctx, p, &handle)) {
3489 if (!torture_setting_bool(tctx, "samba3", false)) {
3490 if (!test_SecondaryClosePrinter(tctx, p, &handle)) {
3495 if (!test_ClosePrinter(tctx, p, &handle)) {
3502 static bool call_OpenPrinterEx(struct torture_context *tctx,
3503 struct dcerpc_pipe *p,
3505 struct spoolss_DeviceMode *devmode,
3506 struct policy_handle *handle)
3508 struct spoolss_OpenPrinterEx r;
3509 struct spoolss_UserLevel1 userlevel1;
3512 if (name && name[0]) {
3513 r.in.printername = talloc_asprintf(tctx, "\\\\%s\\%s",
3514 dcerpc_server_name(p), name);
3516 r.in.printername = talloc_asprintf(tctx, "\\\\%s",
3517 dcerpc_server_name(p));
3520 r.in.datatype = NULL;
3521 r.in.devmode_ctr.devmode= devmode;
3522 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3524 r.in.userlevel.level1 = &userlevel1;
3525 r.out.handle = handle;
3527 userlevel1.size = 1234;
3528 userlevel1.client = "hello";
3529 userlevel1.user = "spottyfoot!";
3530 userlevel1.build = 1;
3531 userlevel1.major = 2;
3532 userlevel1.minor = 3;
3533 userlevel1.processor = 4;
3535 torture_comment(tctx, "Testing OpenPrinterEx(%s)\n", r.in.printername);
3537 status = dcerpc_spoolss_OpenPrinterEx(p, tctx, &r);
3539 torture_assert_ntstatus_ok(tctx, status, "OpenPrinterEx failed");
3541 torture_assert_werr_ok(tctx, r.out.result, "OpenPrinterEx failed");
3546 static bool test_OpenPrinterEx(struct torture_context *tctx,
3547 struct dcerpc_pipe *p,
3550 struct policy_handle handle;
3553 if (!call_OpenPrinterEx(tctx, p, name, NULL, &handle)) {
3557 if (!test_PrinterInfo_SD(tctx, p, &handle)) {
3561 if (!test_GetPrinter(tctx, p, &handle)) {
3565 if (!test_EnumForms(tctx, p, &handle, false)) {
3569 if (!test_AddForm(tctx, p, &handle, false)) {
3573 if (!test_EnumPrinterData(tctx, p, &handle)) {
3577 if (!test_EnumPrinterDataEx(tctx, p, &handle, "PrinterDriverData")) {
3581 if (!test_printer_keys(tctx, p, &handle)) {
3585 if (!test_PausePrinter(tctx, p, &handle)) {
3589 if (!test_DoPrintTest(tctx, p, &handle)) {
3593 if (!test_ResumePrinter(tctx, p, &handle)) {
3597 if (!test_SetPrinterData(tctx, p, &handle)) {
3601 if (!test_SetPrinterDataEx(tctx, p, &handle)) {
3605 if (!test_ChangeID(tctx, p, &handle)) {
3609 if (!torture_setting_bool(tctx, "samba3", false)) {
3610 if (!test_SecondaryClosePrinter(tctx, p, &handle)) {
3615 if (!test_ClosePrinter(tctx, p, &handle)) {
3622 static bool test_EnumPrinters_old(struct torture_context *tctx, struct dcerpc_pipe *p)
3624 struct spoolss_EnumPrinters r;
3626 uint16_t levels[] = {1, 2, 4, 5};
3630 for (i=0;i<ARRAY_SIZE(levels);i++) {
3631 union spoolss_PrinterInfo *info;
3636 r.in.flags = PRINTER_ENUM_LOCAL;
3638 r.in.level = levels[i];
3641 r.out.needed = &needed;
3642 r.out.count = &count;
3645 torture_comment(tctx, "Testing EnumPrinters level %u\n", r.in.level);
3647 status = dcerpc_spoolss_EnumPrinters(p, tctx, &r);
3648 torture_assert_ntstatus_ok(tctx, status, "EnumPrinters failed");
3650 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
3651 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
3652 data_blob_clear(&blob);
3653 r.in.buffer = &blob;
3654 r.in.offered = needed;
3655 status = dcerpc_spoolss_EnumPrinters(p, tctx, &r);
3658 torture_assert_ntstatus_ok(tctx, status, "EnumPrinters failed");
3660 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinters failed");
3662 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPrinters, info, r.in.level, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
3665 torture_comment(tctx, "No printers returned\n");
3669 for (j=0;j<count;j++) {
3670 if (r.in.level == 1) {
3671 char *unc = talloc_strdup(tctx, info[j].info1.name);
3674 if (unc[0] == '\\' && unc[1] == '\\') {
3677 slash = strchr(unc, '\\');
3682 if (!test_OpenPrinter(tctx, p, name)) {
3685 if (!test_OpenPrinterEx(tctx, p, name)) {
3695 static bool test_GetPrinterDriver(struct torture_context *tctx,
3696 struct dcerpc_pipe *p,
3697 struct policy_handle *handle,
3698 const char *driver_name)
3700 struct spoolss_GetPrinterDriver r;
3703 r.in.handle = handle;
3704 r.in.architecture = "W32X86";
3708 r.out.needed = &needed;
3710 torture_comment(tctx, "Testing GetPrinterDriver level %d\n", r.in.level);
3712 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_GetPrinterDriver(p, tctx, &r),
3713 "failed to call GetPrinterDriver");
3714 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
3715 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
3716 data_blob_clear(&blob);
3717 r.in.buffer = &blob;
3718 r.in.offered = needed;
3719 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_GetPrinterDriver(p, tctx, &r),
3720 "failed to call GetPrinterDriver");
3723 torture_assert_werr_ok(tctx, r.out.result,
3724 "failed to call GetPrinterDriver");
3726 CHECK_NEEDED_SIZE_LEVEL(spoolss_DriverInfo, r.out.info, r.in.level, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
3731 static bool test_GetPrinterDriver2(struct torture_context *tctx,
3732 struct dcerpc_pipe *p,
3733 struct policy_handle *handle,
3734 const char *driver_name)
3736 struct spoolss_GetPrinterDriver2 r;
3737 uint16_t levels[] = {1, 2, 3, 4, 5, 6, 8, 101 };
3739 uint32_t server_major_version;
3740 uint32_t server_minor_version;
3743 r.in.handle = handle;
3744 r.in.architecture = SPOOLSS_ARCHITECTURE_NT_X86;
3745 r.in.client_major_version = 3;
3746 r.in.client_minor_version = 0;
3747 r.out.needed = &needed;
3748 r.out.server_major_version = &server_major_version;
3749 r.out.server_minor_version = &server_minor_version;
3751 for (i=0;i<ARRAY_SIZE(levels);i++) {
3755 r.in.level = levels[i];
3757 torture_comment(tctx, "Testing GetPrinterDriver2(%s) level %d\n",
3758 driver_name, r.in.level);
3760 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_GetPrinterDriver2(p, tctx, &r),
3761 "failed to call GetPrinterDriver2");
3762 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
3763 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
3764 data_blob_clear(&blob);
3765 r.in.buffer = &blob;
3766 r.in.offered = needed;
3767 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_GetPrinterDriver2(p, tctx, &r),
3768 "failed to call GetPrinterDriver2");
3771 if (W_ERROR_EQUAL(r.out.result, WERR_INVALID_LEVEL)) {
3772 switch (r.in.level) {
3781 torture_assert_werr_ok(tctx, r.out.result,
3782 "failed to call GetPrinterDriver2");
3784 CHECK_NEEDED_SIZE_LEVEL(spoolss_DriverInfo, r.out.info, r.in.level, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
3790 static bool test_EnumPrinterDrivers_old(struct torture_context *tctx,
3791 struct dcerpc_pipe *p)
3793 struct spoolss_EnumPrinterDrivers r;
3795 uint16_t levels[] = {1, 2, 3, 4, 5, 6};
3798 for (i=0;i<ARRAY_SIZE(levels);i++) {
3802 union spoolss_DriverInfo *info;
3804 r.in.server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
3805 r.in.environment = SPOOLSS_ARCHITECTURE_NT_X86;
3806 r.in.level = levels[i];
3809 r.out.needed = &needed;
3810 r.out.count = &count;
3813 torture_comment(tctx, "Testing EnumPrinterDrivers level %u\n", r.in.level);
3815 status = dcerpc_spoolss_EnumPrinterDrivers(p, tctx, &r);
3817 torture_assert_ntstatus_ok(tctx, status, "EnumPrinterDrivers failed");
3819 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
3820 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
3821 data_blob_clear(&blob);
3822 r.in.buffer = &blob;
3823 r.in.offered = needed;
3824 status = dcerpc_spoolss_EnumPrinterDrivers(p, tctx, &r);
3827 torture_assert_ntstatus_ok(tctx, status, "EnumPrinterDrivers failed");
3829 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinterDrivers failed");
3832 torture_comment(tctx, "No printer drivers returned\n");
3836 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPrinterDrivers, info, r.in.level, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
3842 static bool test_DeletePrinter(struct torture_context *tctx,
3843 struct dcerpc_pipe *p,
3844 struct policy_handle *handle)
3846 struct spoolss_DeletePrinter r;
3848 torture_comment(tctx, "Testing DeletePrinter\n");
3850 r.in.handle = handle;
3852 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_DeletePrinter(p, tctx, &r),
3853 "failed to delete printer");
3854 torture_assert_werr_ok(tctx, r.out.result,
3855 "failed to delete printer");
3860 static bool test_EnumPrinters_findname(struct torture_context *tctx,
3861 struct dcerpc_pipe *p,
3867 struct spoolss_EnumPrinters e;
3869 union spoolss_PrinterInfo *info;
3880 e.out.count = &count;
3882 e.out.needed = &needed;
3884 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinters(p, tctx, &e),
3885 "failed to enum printers");
3887 if (W_ERROR_EQUAL(e.out.result, WERR_INSUFFICIENT_BUFFER)) {
3888 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
3889 data_blob_clear(&blob);
3890 e.in.buffer = &blob;
3891 e.in.offered = needed;
3893 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinters(p, tctx, &e),
3894 "failed to enum printers");
3897 torture_assert_werr_ok(tctx, e.out.result,
3898 "failed to enum printers");
3900 for (i=0; i < count; i++) {
3902 const char *current = NULL;
3907 current = info[i].info1.name;
3911 if (strequal(current, name)) {
3916 p = strrchr(current, '\\');
3919 torture_warning(tctx,
3920 "server returns printername %s incl. servername although we did not set servername", current);
3923 if (strequal(p, name)) {
3933 static bool test_AddPrinter_wellknown(struct torture_context *tctx,
3934 struct dcerpc_pipe *p,
3935 const char *printername,
3939 struct spoolss_AddPrinter r;
3940 struct spoolss_AddPrinterEx rex;
3941 struct spoolss_SetPrinterInfoCtr info_ctr;
3942 struct spoolss_SetPrinterInfo1 info1;
3943 struct spoolss_DevmodeContainer devmode_ctr;
3944 struct sec_desc_buf secdesc_ctr;
3945 struct spoolss_UserLevelCtr userlevel_ctr;
3946 struct policy_handle handle;
3949 ZERO_STRUCT(devmode_ctr);
3950 ZERO_STRUCT(secdesc_ctr);
3951 ZERO_STRUCT(userlevel_ctr);
3954 torture_comment(tctx, "Testing AddPrinter%s level 1\n", ex ? "Ex":"");
3956 /* try to add printer to wellknown printer list (level 1) */
3958 userlevel_ctr.level = 1;
3960 info_ctr.info.info1 = &info1;
3963 rex.in.server = NULL;
3964 rex.in.info_ctr = &info_ctr;
3965 rex.in.devmode_ctr = &devmode_ctr;
3966 rex.in.secdesc_ctr = &secdesc_ctr;
3967 rex.in.userlevel_ctr = &userlevel_ctr;
3968 rex.out.handle = &handle;
3971 r.in.info_ctr = &info_ctr;
3972 r.in.devmode_ctr = &devmode_ctr;
3973 r.in.secdesc_ctr = &secdesc_ctr;
3974 r.out.handle = &handle;
3976 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx(p, tctx, &rex) :
3977 dcerpc_spoolss_AddPrinter(p, tctx, &r),
3978 "failed to add printer");
3979 result = ex ? rex.out.result : r.out.result;
3980 torture_assert_werr_equal(tctx, result, WERR_INVALID_PRINTER_NAME,
3981 "unexpected result code");
3983 info1.name = printername;
3984 info1.flags = PRINTER_ATTRIBUTE_SHARED;
3986 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx(p, tctx, &rex) :
3987 dcerpc_spoolss_AddPrinter(p, tctx, &r),
3988 "failed to add printer");
3989 result = ex ? rex.out.result : r.out.result;
3990 torture_assert_werr_equal(tctx, result, WERR_PRINTER_ALREADY_EXISTS,
3991 "unexpected result code");
3993 /* bizarre protocol, WERR_PRINTER_ALREADY_EXISTS means success here,
3994 better do a real check to see the printer is really there */
3996 torture_assert(tctx, test_EnumPrinters_findname(tctx, p,
3997 PRINTER_ENUM_NETWORK, 1,
4000 "failed to enum printers");
4002 torture_assert(tctx, found, "failed to find newly added printer");
4006 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx(p, tctx, &rex) :
4007 dcerpc_spoolss_AddPrinter(p, tctx, &r),
4008 "failed to add printer");
4009 result = ex ? rex.out.result : r.out.result;
4010 torture_assert_werr_equal(tctx, result, WERR_PRINTER_ALREADY_EXISTS,
4011 "unexpected result code");
4013 /* bizarre protocol, WERR_PRINTER_ALREADY_EXISTS means success here,
4014 better do a real check to see the printer has really been removed
4015 from the well known printer list */
4019 torture_assert(tctx, test_EnumPrinters_findname(tctx, p,
4020 PRINTER_ENUM_NETWORK, 1,
4023 "failed to enum printers");
4025 torture_assert(tctx, !found, "printer still in well known printer list");
4030 static bool test_AddPrinter_normal(struct torture_context *tctx,
4031 struct dcerpc_pipe *p,
4032 struct policy_handle *handle_p,
4033 const char *printername,
4034 const char *drivername,
4035 const char *portname,
4039 struct spoolss_AddPrinter r;
4040 struct spoolss_AddPrinterEx rex;
4041 struct spoolss_SetPrinterInfoCtr info_ctr;
4042 struct spoolss_SetPrinterInfo2 info2;
4043 struct spoolss_DevmodeContainer devmode_ctr;
4044 struct sec_desc_buf secdesc_ctr;
4045 struct spoolss_UserLevelCtr userlevel_ctr;
4046 struct policy_handle handle;
4048 bool existing_printer_deleted = false;
4050 ZERO_STRUCT(devmode_ctr);
4051 ZERO_STRUCT(secdesc_ctr);
4052 ZERO_STRUCT(userlevel_ctr);
4054 torture_comment(tctx, "Testing AddPrinter%s level 2\n", ex ? "Ex":"");
4056 userlevel_ctr.level = 1;
4058 rex.in.server = NULL;
4059 rex.in.info_ctr = &info_ctr;
4060 rex.in.devmode_ctr = &devmode_ctr;
4061 rex.in.secdesc_ctr = &secdesc_ctr;
4062 rex.in.userlevel_ctr = &userlevel_ctr;
4063 rex.out.handle = &handle;
4066 r.in.info_ctr = &info_ctr;
4067 r.in.devmode_ctr = &devmode_ctr;
4068 r.in.secdesc_ctr = &secdesc_ctr;
4069 r.out.handle = &handle;
4073 /* try to add printer to printer list (level 2) */
4077 info_ctr.info.info2 = &info2;
4080 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx(p, tctx, &rex) :
4081 dcerpc_spoolss_AddPrinter(p, tctx, &r),
4082 "failed to add printer");
4083 result = ex ? rex.out.result : r.out.result;
4084 torture_assert_werr_equal(tctx, result, WERR_INVALID_PRINTER_NAME,
4085 "unexpected result code");
4087 info2.printername = printername;
4089 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx(p, tctx, &rex) :
4090 dcerpc_spoolss_AddPrinter(p, tctx, &r),
4091 "failed to add printer");
4092 result = ex ? rex.out.result : r.out.result;
4094 if (W_ERROR_EQUAL(result, WERR_PRINTER_ALREADY_EXISTS)) {
4095 struct policy_handle printer_handle;
4097 if (existing_printer_deleted) {
4098 torture_fail(tctx, "already deleted printer still existing?");
4101 torture_assert(tctx, call_OpenPrinterEx(tctx, p, printername, NULL, &printer_handle),
4102 "failed to open printer handle");
4104 torture_assert(tctx, test_DeletePrinter(tctx, p, &printer_handle),
4105 "failed to delete printer");
4107 torture_assert(tctx, test_ClosePrinter(tctx, p, &printer_handle),
4108 "failed to close server handle");
4110 existing_printer_deleted = true;
4115 torture_assert_werr_equal(tctx, result, WERR_UNKNOWN_PORT,
4116 "unexpected result code");
4118 info2.portname = portname;
4120 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx(p, tctx, &rex) :
4121 dcerpc_spoolss_AddPrinter(p, tctx, &r),
4122 "failed to add printer");
4123 result = ex ? rex.out.result : r.out.result;
4124 torture_assert_werr_equal(tctx, result, WERR_UNKNOWN_PRINTER_DRIVER,
4125 "unexpected result code");
4127 info2.drivername = drivername;
4129 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx(p, tctx, &rex) :
4130 dcerpc_spoolss_AddPrinter(p, tctx, &r),
4131 "failed to add printer");
4132 result = ex ? rex.out.result : r.out.result;
4134 /* w2k8r2 allows to add printer w/o defining printprocessor */
4136 if (!W_ERROR_IS_OK(result)) {
4137 torture_assert_werr_equal(tctx, result, WERR_UNKNOWN_PRINTPROCESSOR,
4138 "unexpected result code");
4140 info2.printprocessor = "winprint";
4142 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx(p, tctx, &rex) :
4143 dcerpc_spoolss_AddPrinter(p, tctx, &r),
4144 "failed to add printer");
4145 result = ex ? rex.out.result : r.out.result;
4146 torture_assert_werr_ok(tctx, result,
4147 "failed to add printer");
4152 /* we are paranoid, really check if the printer is there now */
4154 torture_assert(tctx, test_EnumPrinters_findname(tctx, p,
4155 PRINTER_ENUM_LOCAL, 1,
4158 "failed to enum printers");
4159 torture_assert(tctx, found, "failed to find newly added printer");
4161 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx(p, tctx, &rex) :
4162 dcerpc_spoolss_AddPrinter(p, tctx, &r),
4163 "failed to add printer");
4164 result = ex ? rex.out.result : r.out.result;
4165 torture_assert_werr_equal(tctx, result, WERR_PRINTER_ALREADY_EXISTS,
4166 "unexpected result code");
4171 static bool test_AddPrinterEx(struct torture_context *tctx,
4172 struct dcerpc_pipe *p,
4173 struct policy_handle *handle_p,
4174 const char *printername,
4175 const char *drivername,
4176 const char *portname)
4180 if (!torture_setting_bool(tctx, "samba3", false)) {
4181 if (!test_AddPrinter_wellknown(tctx, p, TORTURE_WELLKNOWN_PRINTER_EX, true)) {
4182 torture_comment(tctx, "failed to add printer to well known list\n");
4187 if (!test_AddPrinter_normal(tctx, p, handle_p,
4188 printername, drivername, portname,
4190 torture_comment(tctx, "failed to add printer to printer list\n");
4197 static bool test_AddPrinter(struct torture_context *tctx,
4198 struct dcerpc_pipe *p,
4199 struct policy_handle *handle_p,
4200 const char *printername,
4201 const char *drivername,
4202 const char *portname)
4206 if (!torture_setting_bool(tctx, "samba3", false)) {
4207 if (!test_AddPrinter_wellknown(tctx, p, TORTURE_WELLKNOWN_PRINTER, false)) {
4208 torture_comment(tctx, "failed to add printer to well known list\n");
4213 if (!test_AddPrinter_normal(tctx, p, handle_p,
4214 printername, drivername, portname,
4216 torture_comment(tctx, "failed to add printer to printer list\n");
4223 static bool test_printer_info(struct torture_context *tctx,
4224 struct dcerpc_pipe *p,
4225 struct policy_handle *handle)
4229 if (torture_setting_bool(tctx, "samba3", false)) {
4230 torture_skip(tctx, "skipping printer info cross tests against samba 3");
4233 if (!test_PrinterInfo(tctx, p, handle)) {
4237 if (!test_SetPrinter_errors(tctx, p, handle)) {
4244 static bool test_EnumPrinterKey(struct torture_context *tctx,
4245 struct dcerpc_pipe *p,
4246 struct policy_handle *handle,
4247 const char *key_name,
4248 const char ***array)
4250 struct spoolss_EnumPrinterKey r;
4251 uint32_t needed = 0;
4252 union spoolss_KeyNames key_buffer;
4253 int32_t offered[] = { 0, 1, 2, 3, 4, 5, -1, -2, -3, -4, -5, 256, 512, 1024, 2048 };
4257 r.in.handle = handle;
4258 r.in.key_name = key_name;
4259 r.out.key_buffer = &key_buffer;
4260 r.out.needed = &needed;
4261 r.out._ndr_size = &_ndr_size;
4263 for (i=0; i < ARRAY_SIZE(offered); i++) {
4265 if (offered[i] < 0 && needed) {
4269 r.in.offered = needed + offered[i];
4271 r.in.offered = offered[i];
4274 ZERO_STRUCT(key_buffer);
4276 torture_comment(tctx, "Testing EnumPrinterKey(%s) with %d offered\n", r.in.key_name, r.in.offered);
4278 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinterKey(p, tctx, &r),
4279 "failed to call EnumPrinterKey");
4280 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
4282 torture_assert(tctx, (_ndr_size == r.in.offered/2),
4283 talloc_asprintf(tctx, "EnumPrinterKey size mismatch, _ndr_size %d (expected %d)",
4284 _ndr_size, r.in.offered/2));
4286 r.in.offered = needed;
4287 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinterKey(p, tctx, &r),
4288 "failed to call EnumPrinterKey");
4291 if (offered[i] > 0) {
4292 torture_assert_werr_ok(tctx, r.out.result,
4293 "failed to call EnumPrinterKey");
4296 torture_assert(tctx, (_ndr_size == r.in.offered/2),
4297 talloc_asprintf(tctx, "EnumPrinterKey size mismatch, _ndr_size %d (expected %d)",
4298 _ndr_size, r.in.offered/2));
4300 torture_assert(tctx, (*r.out.needed <= r.in.offered),
4301 talloc_asprintf(tctx, "EnumPrinterKey size mismatch: needed %d is not <= offered %d", *r.out.needed, r.in.offered));
4303 torture_assert(tctx, (*r.out.needed <= _ndr_size * 2),
4304 talloc_asprintf(tctx, "EnumPrinterKey size mismatch: needed %d is not <= _ndr_size %d * 2", *r.out.needed, _ndr_size));
4306 if (key_buffer.string_array) {
4307 uint32_t calc_needed = 0;
4309 for (s=0; key_buffer.string_array[s]; s++) {
4310 calc_needed += strlen_m_term(key_buffer.string_array[s])*2;
4312 if (!key_buffer.string_array[0]) {
4317 torture_assert_int_equal(tctx, *r.out.needed, calc_needed,
4318 "EnumPrinterKey unexpected size");
4323 *array = key_buffer.string_array;
4329 bool test_printer_keys(struct torture_context *tctx,
4330 struct dcerpc_pipe *p,
4331 struct policy_handle *handle)
4333 const char **key_array = NULL;
4336 torture_assert(tctx, test_EnumPrinterKey(tctx, p, handle, "", &key_array),
4337 "failed to call test_EnumPrinterKey");
4339 for (i=0; key_array && key_array[i]; i++) {
4340 torture_assert(tctx, test_EnumPrinterKey(tctx, p, handle, key_array[i], NULL),
4341 "failed to call test_EnumPrinterKey");
4343 for (i=0; key_array && key_array[i]; i++) {
4344 torture_assert(tctx, test_EnumPrinterDataEx(tctx, p, handle, key_array[i]),
4345 "failed to call test_EnumPrinterDataEx");
4351 static bool test_one_printer(struct torture_context *tctx,
4352 struct dcerpc_pipe *p,
4353 struct policy_handle *handle,
4358 if (!test_printer_info(tctx, p, handle)) {
4362 if (!test_PrinterInfo_SD(tctx, p, handle)) {
4366 if (!test_PrinterInfo_DevMode(tctx, p, handle, name)) {
4370 if (!test_printer_keys(tctx, p, handle)) {
4377 static bool test_printer(struct torture_context *tctx,
4378 struct dcerpc_pipe *p)
4381 struct policy_handle handle[2];
4383 const char *drivername = "Microsoft XPS Document Writer";
4384 const char *portname = "LPT1:";
4386 /* test printer created via AddPrinter */
4388 if (!test_AddPrinter(tctx, p, &handle[0], TORTURE_PRINTER, drivername, portname)) {
4392 if (!test_one_printer(tctx, p, &handle[0], TORTURE_PRINTER)) {
4396 if (!test_DeletePrinter(tctx, p, &handle[0])) {
4400 if (!test_EnumPrinters_findname(tctx, p, PRINTER_ENUM_LOCAL, 1,
4401 TORTURE_PRINTER, &found)) {
4405 torture_assert(tctx, !found, "deleted printer still there");
4407 /* test printer created via AddPrinterEx */
4409 if (!test_AddPrinterEx(tctx, p, &handle[1], TORTURE_PRINTER_EX, drivername, portname)) {
4413 if (!test_one_printer(tctx, p, &handle[1], TORTURE_PRINTER_EX)) {
4417 if (!test_DeletePrinter(tctx, p, &handle[1])) {
4421 if (!test_EnumPrinters_findname(tctx, p, PRINTER_ENUM_LOCAL, 1,
4422 TORTURE_PRINTER_EX, &found)) {
4426 torture_assert(tctx, !found, "deleted printer still there");
4431 bool torture_rpc_spoolss(struct torture_context *torture)
4434 struct dcerpc_pipe *p;
4436 struct test_spoolss_context *ctx;
4438 status = torture_rpc_connection(torture, &p, &ndr_table_spoolss);
4439 if (!NT_STATUS_IS_OK(status)) {
4443 ctx = talloc_zero(torture, struct test_spoolss_context);
4445 ret &= test_OpenPrinter_server(torture, p, &ctx->server_handle);
4446 ret &= test_GetPrinterData_list(torture, p, &ctx->server_handle);
4447 ret &= test_EnumForms(torture, p, &ctx->server_handle, true);
4448 ret &= test_AddForm(torture, p, &ctx->server_handle, true);
4449 ret &= test_EnumPorts(torture, p, ctx);
4450 ret &= test_GetPrinterDriverDirectory(torture, p, ctx);
4451 ret &= test_GetPrintProcessorDirectory(torture, p, ctx);
4452 ret &= test_EnumPrinterDrivers(torture, p, ctx, SPOOLSS_ARCHITECTURE_NT_X86);
4453 ret &= test_EnumPrinterDrivers(torture, p, ctx, SPOOLSS_ARCHITECTURE_ALL);
4454 ret &= test_EnumMonitors(torture, p, ctx);
4455 ret &= test_EnumPrintProcessors(torture, p, ctx);
4456 ret &= test_EnumPrintProcDataTypes(torture, p, ctx);
4457 ret &= test_EnumPrinters(torture, p, ctx);
4458 ret &= test_OpenPrinter_badname(torture, p, "__INVALID_PRINTER__");
4459 ret &= test_OpenPrinter_badname(torture, p, "\\\\__INVALID_HOST__");
4460 ret &= test_OpenPrinter_badname(torture, p, "");
4461 ret &= test_OpenPrinter_badname(torture, p, "\\\\\\");
4462 ret &= test_OpenPrinter_badname(torture, p, "\\\\\\__INVALID_PRINTER__");
4463 ret &= test_OpenPrinter_badname(torture, p, talloc_asprintf(torture, "\\\\%s\\", dcerpc_server_name(p)));
4464 ret &= test_OpenPrinter_badname(torture, p,
4465 talloc_asprintf(torture, "\\\\%s\\__INVALID_PRINTER__", dcerpc_server_name(p)));
4468 ret &= test_AddPort(torture, p);
4469 ret &= test_EnumPorts_old(torture, p);
4470 ret &= test_EnumPrinters_old(torture, p);
4471 ret &= test_EnumPrinterDrivers_old(torture, p);
4476 struct torture_suite *torture_rpc_spoolss_printer(TALLOC_CTX *mem_ctx)
4478 struct torture_suite *suite = torture_suite_create(mem_ctx, "SPOOLSS-PRINTER");
4480 struct torture_rpc_tcase *tcase = torture_suite_add_rpc_iface_tcase(suite,
4481 "printer", &ndr_table_spoolss);
4483 torture_rpc_tcase_add_test(tcase, "printer", test_printer);