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_winreg_c.h"
30 #include "librpc/gen_ndr/ndr_security.h"
31 #include "libcli/security/security.h"
32 #include "torture/rpc/torture_rpc.h"
33 #include "param/param.h"
34 #include "lib/registry/registry.h"
35 #include "libcli/libcli.h"
36 #include "libcli/raw/raw_proto.h"
37 #include "libcli/resolve/resolve.h"
38 #include "lib/cmdline/popt_common.h"
39 #include "system/filesys.h"
41 #define TORTURE_WELLKNOWN_PRINTER "torture_wkn_printer"
42 #define TORTURE_PRINTER "torture_printer"
43 #define TORTURE_WELLKNOWN_PRINTER_EX "torture_wkn_printer_ex"
44 #define TORTURE_PRINTER_EX "torture_printer_ex"
45 #define TORTURE_DRIVER "torture_driver"
46 #define TORTURE_DRIVER_EX "torture_driver_ex"
48 #define TOP_LEVEL_PRINT_KEY "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print"
49 #define TOP_LEVEL_PRINT_PRINTERS_KEY TOP_LEVEL_PRINT_KEY "\\Printers"
50 #define TOP_LEVEL_CONTROL_KEY "SYSTEM\\CurrentControlSet\\Control\\Print"
51 #define TOP_LEVEL_CONTROL_FORMS_KEY TOP_LEVEL_CONTROL_KEY "\\Forms"
52 #define TOP_LEVEL_CONTROL_PRINTERS_KEY TOP_LEVEL_CONTROL_KEY "\\Printers"
53 #define TOP_LEVEL_CONTROL_ENVIRONMENTS_KEY TOP_LEVEL_CONTROL_KEY "\\Environments"
55 struct test_spoolss_context {
56 /* print server handle */
57 struct policy_handle server_handle;
60 uint32_t port_count[3];
61 union spoolss_PortInfo *ports[3];
63 /* for EnumPrinterDrivers */
64 uint32_t driver_count[8];
65 union spoolss_DriverInfo *drivers[8];
67 /* for EnumMonitors */
68 uint32_t monitor_count[3];
69 union spoolss_MonitorInfo *monitors[3];
71 /* for EnumPrintProcessors */
72 uint32_t print_processor_count[2];
73 union spoolss_PrintProcessorInfo *print_processors[2];
75 /* for EnumPrinters */
76 uint32_t printer_count[6];
77 union spoolss_PrinterInfo *printers[6];
80 struct torture_driver_context {
82 const char *driver_directory;
83 const char *environment;
86 const char *driver_directory;
87 const char *environment;
89 struct spoolss_AddDriverInfo8 info8;
93 #define COMPARE_STRING(tctx, c,r,e) \
94 torture_assert_str_equal(tctx, c.e, r.e, "invalid value")
96 /* not every compiler supports __typeof__() */
98 #define _CHECK_FIELD_SIZE(c,r,e,type) do {\
99 if (sizeof(__typeof__(c.e)) != sizeof(type)) { \
100 torture_fail(tctx, #c "." #e "field is not " #type "\n"); \
102 if (sizeof(__typeof__(r.e)) != sizeof(type)) { \
103 torture_fail(tctx, #r "." #e "field is not " #type "\n"); \
107 #define _CHECK_FIELD_SIZE(c,r,e,type) do {} while(0)
110 #define COMPARE_UINT32(tctx, c, r, e) do {\
111 _CHECK_FIELD_SIZE(c, r, e, uint32_t); \
112 torture_assert_int_equal(tctx, c.e, r.e, "invalid value"); \
115 #define COMPARE_UINT64(tctx, c, r, e) do {\
116 _CHECK_FIELD_SIZE(c, r, e, uint64_t); \
117 torture_assert_int_equal(tctx, c.e, r.e, "invalid value"); \
121 #define COMPARE_NTTIME(tctx, c, r, e) do {\
122 _CHECK_FIELD_SIZE(c, r, e, NTTIME); \
123 torture_assert_int_equal(tctx, c.e, r.e, "invalid value"); \
126 #define COMPARE_STRING_ARRAY(tctx, c,r,e) do {\
128 if (!c.e && !r.e) { \
132 torture_fail(tctx, #r "." #e " field is NULL and " #c "." #e " is not\n"); \
135 torture_fail(tctx, #c "." #e " field is NULL and " #r "." #e " is not\n"); \
137 for (__i=0;c.e[__i] != NULL; __i++) { \
138 torture_assert_str_equal(tctx, c.e[__i], r.e[__i], "invalid value"); \
142 #define CHECK_ALIGN(size, n) do {\
144 torture_warning(tctx, "%d is *NOT* %d byte aligned, should be %d",\
145 size, n, size + n - (size % n));\
149 #define DO_ROUND(size, n) (((size)+((n)-1)) & ~((n)-1))
151 #define CHECK_NEEDED_SIZE_ENUM_LEVEL(fn, info, level, count, ic, needed, align) do { \
152 if (torture_setting_bool(tctx, "spoolss_check_size", false)) {\
153 uint32_t size = ndr_size_##fn##_info(tctx, ic, level, count, info);\
154 uint32_t round_size = DO_ROUND(size, align);\
155 if (round_size != needed) {\
156 torture_warning(tctx, __location__": "#fn" level %d (count: %d) got unexpected needed size: %d, we calculated: %d", level, count, needed, round_size);\
157 CHECK_ALIGN(size, align);\
162 #define CHECK_NEEDED_SIZE_ENUM(fn, info, count, ic, needed, align) do { \
163 if (torture_setting_bool(tctx, "spoolss_check_size", false)) {\
164 uint32_t size = ndr_size_##fn##_info(tctx, ic, count, info);\
165 uint32_t round_size = DO_ROUND(size, align);\
166 if (round_size != needed) {\
167 torture_warning(tctx, __location__": "#fn" (count: %d) got unexpected needed size: %d, we calculated: %d", count, needed, round_size);\
168 CHECK_ALIGN(size, align);\
173 #define CHECK_NEEDED_SIZE_LEVEL(fn, info, level, ic, needed, align) do { \
174 if (torture_setting_bool(tctx, "spoolss_check_size", false)) {\
175 uint32_t size = ndr_size_##fn(info, level, ic, 0);\
176 uint32_t round_size = DO_ROUND(size, align);\
177 if (round_size != needed) {\
178 torture_warning(tctx, __location__": "#fn" level %d got unexpected needed size: %d, we calculated: %d", level, needed, round_size);\
179 CHECK_ALIGN(size, align);\
184 static bool PrinterInfo_to_SetPrinterInfo(struct torture_context *tctx,
185 const union spoolss_PrinterInfo *i,
187 union spoolss_SetPrinterInfo *s)
191 s->info0 = talloc(tctx, struct spoolss_SetPrinterInfo0);
194 s->info2 = talloc(tctx, struct spoolss_SetPrinterInfo2);
195 s->info2->servername = i->info2.servername;
196 s->info2->printername = i->info2.printername;
197 s->info2->sharename = i->info2.sharename;
198 s->info2->portname = i->info2.portname;
199 s->info2->drivername = i->info2.drivername;
200 s->info2->comment = i->info2.comment;
201 s->info2->location = i->info2.location;
202 s->info2->devmode_ptr = 0;
203 s->info2->sepfile = i->info2.sepfile;
204 s->info2->printprocessor = i->info2.printprocessor;
205 s->info2->datatype = i->info2.datatype;
206 s->info2->parameters = i->info2.parameters;
207 s->info2->secdesc_ptr = 0;
208 s->info2->attributes = i->info2.attributes;
209 s->info2->priority = i->info2.priority;
210 s->info2->defaultpriority = i->info2.defaultpriority;
211 s->info2->starttime = i->info2.starttime;
212 s->info2->untiltime = i->info2.untiltime;
213 s->info2->status = i->info2.status;
214 s->info2->cjobs = i->info2.cjobs;
215 s->info2->averageppm = i->info2.averageppm;
231 static bool test_OpenPrinter_server(struct torture_context *tctx,
232 struct dcerpc_pipe *p,
233 struct policy_handle *server_handle)
236 struct spoolss_OpenPrinter op;
237 struct dcerpc_binding_handle *b = p->binding_handle;
239 op.in.printername = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
240 op.in.datatype = NULL;
241 op.in.devmode_ctr.devmode= NULL;
242 op.in.access_mask = 0;
243 op.out.handle = server_handle;
245 torture_comment(tctx, "Testing OpenPrinter(%s)\n", op.in.printername);
247 status = dcerpc_spoolss_OpenPrinter_r(b, tctx, &op);
248 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_OpenPrinter failed");
249 torture_assert_werr_ok(tctx, op.out.result, "dcerpc_spoolss_OpenPrinter failed");
254 static bool test_EnumPorts(struct torture_context *tctx,
255 struct dcerpc_binding_handle *b,
256 struct test_spoolss_context *ctx)
259 struct spoolss_EnumPorts r;
260 uint16_t levels[] = { 1, 2 };
263 for (i=0;i<ARRAY_SIZE(levels);i++) {
264 int level = levels[i];
268 union spoolss_PortInfo *info;
270 r.in.servername = "";
274 r.out.needed = &needed;
275 r.out.count = &count;
278 torture_comment(tctx, "Testing EnumPorts level %u\n", r.in.level);
280 status = dcerpc_spoolss_EnumPorts_r(b, ctx, &r);
281 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPorts failed");
282 if (W_ERROR_IS_OK(r.out.result)) {
283 /* TODO: do some more checks here */
286 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
287 "EnumPorts unexpected return code");
289 blob = data_blob_talloc_zero(ctx, needed);
291 r.in.offered = needed;
293 status = dcerpc_spoolss_EnumPorts_r(b, ctx, &r);
294 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPorts failed");
296 torture_assert_werr_ok(tctx, r.out.result, "EnumPorts failed");
298 torture_assert(tctx, info, "EnumPorts returned no info");
300 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPorts, info, r.in.level, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
302 ctx->port_count[level] = count;
303 ctx->ports[level] = info;
306 for (i=1;i<ARRAY_SIZE(levels);i++) {
307 int level = levels[i];
308 int old_level = levels[i-1];
309 torture_assert_int_equal(tctx, ctx->port_count[level], ctx->port_count[old_level],
310 "EnumPorts invalid value");
312 /* if the array sizes are not the same we would maybe segfault in the following code */
314 for (i=0;i<ARRAY_SIZE(levels);i++) {
315 int level = levels[i];
316 for (j=0;j<ctx->port_count[level];j++) {
317 union spoolss_PortInfo *cur = &ctx->ports[level][j];
318 union spoolss_PortInfo *ref = &ctx->ports[2][j];
321 COMPARE_STRING(tctx, cur->info1, ref->info2, port_name);
324 /* level 2 is our reference, and it makes no sense to compare it to itself */
333 static bool test_GetPrintProcessorDirectory(struct torture_context *tctx,
334 struct dcerpc_pipe *p,
335 const char *environment)
338 struct dcerpc_binding_handle *b = p->binding_handle;
339 struct spoolss_GetPrintProcessorDirectory r;
354 .server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p))
357 .server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p))
363 for (i=0;i<ARRAY_SIZE(levels);i++) {
364 int level = levels[i].level;
367 r.in.server = levels[i].server;
368 r.in.environment = environment;
372 r.out.needed = &needed;
374 torture_comment(tctx, "Testing GetPrintProcessorDirectory level %u\n", r.in.level);
376 status = dcerpc_spoolss_GetPrintProcessorDirectory_r(b, tctx, &r);
377 torture_assert_ntstatus_ok(tctx, status,
378 "dcerpc_spoolss_GetPrintProcessorDirectory failed");
379 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
380 "GetPrintProcessorDirectory unexpected return code");
382 blob = data_blob_talloc_zero(tctx, needed);
384 r.in.offered = needed;
386 status = dcerpc_spoolss_GetPrintProcessorDirectory_r(b, tctx, &r);
387 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_GetPrintProcessorDirectory failed");
389 torture_assert_werr_ok(tctx, r.out.result, "GetPrintProcessorDirectory failed");
391 CHECK_NEEDED_SIZE_LEVEL(spoolss_PrintProcessorDirectoryInfo, r.out.info, r.in.level, lp_iconv_convenience(tctx->lp_ctx), needed, 2);
398 static bool test_GetPrinterDriverDirectory(struct torture_context *tctx,
399 struct dcerpc_pipe *p,
400 const char *environment)
403 struct dcerpc_binding_handle *b = p->binding_handle;
404 struct spoolss_GetPrinterDriverDirectory r;
419 .server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p))
422 .server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p))
428 for (i=0;i<ARRAY_SIZE(levels);i++) {
429 int level = levels[i].level;
432 r.in.server = levels[i].server;
433 r.in.environment = environment;
437 r.out.needed = &needed;
439 torture_comment(tctx, "Testing GetPrinterDriverDirectory level %u\n", r.in.level);
441 status = dcerpc_spoolss_GetPrinterDriverDirectory_r(b, tctx, &r);
442 torture_assert_ntstatus_ok(tctx, status,
443 "dcerpc_spoolss_GetPrinterDriverDirectory failed");
444 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
445 "GetPrinterDriverDirectory unexpected return code");
447 blob = data_blob_talloc_zero(tctx, needed);
449 r.in.offered = needed;
451 status = dcerpc_spoolss_GetPrinterDriverDirectory_r(b, tctx, &r);
452 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_GetPrinterDriverDirectory failed");
454 torture_assert_werr_ok(tctx, r.out.result, "GetPrinterDriverDirectory failed");
456 CHECK_NEEDED_SIZE_LEVEL(spoolss_DriverDirectoryInfo, r.out.info, r.in.level, lp_iconv_convenience(tctx->lp_ctx), needed, 2);
462 static bool test_EnumPrinterDrivers_args(struct torture_context *tctx,
463 struct dcerpc_binding_handle *b,
464 const char *server_name,
465 const char *environment,
468 union spoolss_DriverInfo **info_p)
470 struct spoolss_EnumPrinterDrivers r;
473 union spoolss_DriverInfo *info;
475 r.in.server = server_name;
476 r.in.environment = environment;
480 r.out.needed = &needed;
481 r.out.count = &count;
484 torture_comment(tctx, "Testing EnumPrinterDrivers(%s) level %u\n",
485 r.in.environment, r.in.level);
487 torture_assert_ntstatus_ok(tctx,
488 dcerpc_spoolss_EnumPrinterDrivers_r(b, tctx, &r),
489 "EnumPrinterDrivers failed");
490 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
491 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
493 r.in.offered = needed;
495 torture_assert_ntstatus_ok(tctx,
496 dcerpc_spoolss_EnumPrinterDrivers_r(b, tctx, &r),
497 "EnumPrinterDrivers failed");
500 torture_assert_werr_ok(tctx, r.out.result,
501 "EnumPrinterDrivers failed");
510 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPrinterDrivers, info, r.in.level, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
516 static bool test_EnumPrinterDrivers_findone(struct torture_context *tctx,
517 struct dcerpc_binding_handle *b,
518 const char *server_name,
519 const char *environment,
521 const char *driver_name)
524 union spoolss_DriverInfo *info;
528 test_EnumPrinterDrivers_args(tctx, b, server_name, environment, level, &count, &info),
529 "failed to enumerate printer drivers");
531 for (i=0; i < count; i++) {
532 const char *driver_name_ret;
535 driver_name_ret = info[i].info1.driver_name;
538 driver_name_ret = info[i].info2.driver_name;
541 driver_name_ret = info[i].info3.driver_name;
544 driver_name_ret = info[i].info4.driver_name;
547 driver_name_ret = info[i].info5.driver_name;
550 driver_name_ret = info[i].info6.driver_name;
553 driver_name_ret = info[i].info7.driver_name;
556 driver_name_ret = info[i].info8.driver_name;
561 if (strequal(driver_name, driver_name_ret)) {
569 static bool test_EnumPrinterDrivers(struct torture_context *tctx,
570 struct dcerpc_pipe *p,
571 struct test_spoolss_context *ctx,
572 const char *architecture)
574 struct dcerpc_binding_handle *b = p->binding_handle;
575 uint16_t levels[] = { 1, 2, 3, 4, 5, 6, 8 };
578 /* FIXME: gd, come back and fix "" as server, and handle
579 * priority of returned error codes in torture test and samba 3
581 const char *server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
583 for (i=0;i<ARRAY_SIZE(levels);i++) {
584 int level = levels[i];
586 union spoolss_DriverInfo *info;
589 test_EnumPrinterDrivers_args(tctx, b, server_name, architecture, level, &count, &info),
590 "failed to enumerate drivers");
592 ctx->driver_count[level] = count;
593 ctx->drivers[level] = info;
596 for (i=1;i<ARRAY_SIZE(levels);i++) {
597 int level = levels[i];
598 int old_level = levels[i-1];
600 torture_assert_int_equal(tctx, ctx->driver_count[level], ctx->driver_count[old_level],
601 "EnumPrinterDrivers invalid value");
604 for (i=0;i<ARRAY_SIZE(levels);i++) {
605 int level = levels[i];
607 for (j=0;j<ctx->driver_count[level];j++) {
608 union spoolss_DriverInfo *cur = &ctx->drivers[level][j];
609 union spoolss_DriverInfo *ref = &ctx->drivers[8][j];
613 COMPARE_STRING(tctx, cur->info1, ref->info8, driver_name);
616 COMPARE_UINT32(tctx, cur->info2, ref->info8, version);
617 COMPARE_STRING(tctx, cur->info2, ref->info8, driver_name);
618 COMPARE_STRING(tctx, cur->info2, ref->info8, architecture);
619 COMPARE_STRING(tctx, cur->info2, ref->info8, driver_path);
620 COMPARE_STRING(tctx, cur->info2, ref->info8, data_file);
621 COMPARE_STRING(tctx, cur->info2, ref->info8, config_file);
624 COMPARE_UINT32(tctx, cur->info3, ref->info8, version);
625 COMPARE_STRING(tctx, cur->info3, ref->info8, driver_name);
626 COMPARE_STRING(tctx, cur->info3, ref->info8, architecture);
627 COMPARE_STRING(tctx, cur->info3, ref->info8, driver_path);
628 COMPARE_STRING(tctx, cur->info3, ref->info8, data_file);
629 COMPARE_STRING(tctx, cur->info3, ref->info8, config_file);
630 COMPARE_STRING(tctx, cur->info3, ref->info8, help_file);
631 COMPARE_STRING_ARRAY(tctx, cur->info3, ref->info8, dependent_files);
632 COMPARE_STRING(tctx, cur->info3, ref->info8, monitor_name);
633 COMPARE_STRING(tctx, cur->info3, ref->info8, default_datatype);
636 COMPARE_UINT32(tctx, cur->info4, ref->info8, version);
637 COMPARE_STRING(tctx, cur->info4, ref->info8, driver_name);
638 COMPARE_STRING(tctx, cur->info4, ref->info8, architecture);
639 COMPARE_STRING(tctx, cur->info4, ref->info8, driver_path);
640 COMPARE_STRING(tctx, cur->info4, ref->info8, data_file);
641 COMPARE_STRING(tctx, cur->info4, ref->info8, config_file);
642 COMPARE_STRING(tctx, cur->info4, ref->info8, help_file);
643 COMPARE_STRING_ARRAY(tctx, cur->info4, ref->info8, dependent_files);
644 COMPARE_STRING(tctx, cur->info4, ref->info8, monitor_name);
645 COMPARE_STRING(tctx, cur->info4, ref->info8, default_datatype);
646 COMPARE_STRING_ARRAY(tctx, cur->info4, ref->info8, previous_names);
649 COMPARE_UINT32(tctx, cur->info5, ref->info8, version);
650 COMPARE_STRING(tctx, cur->info5, ref->info8, driver_name);
651 COMPARE_STRING(tctx, cur->info5, ref->info8, architecture);
652 COMPARE_STRING(tctx, cur->info5, ref->info8, driver_path);
653 COMPARE_STRING(tctx, cur->info5, ref->info8, data_file);
654 COMPARE_STRING(tctx, cur->info5, ref->info8, config_file);
655 /*COMPARE_UINT32(tctx, cur->info5, ref->info8, driver_attributes);*/
656 /*COMPARE_UINT32(tctx, cur->info5, ref->info8, config_version);*/
657 /*TODO: ! COMPARE_UINT32(tctx, cur->info5, ref->info8, driver_version); */
660 COMPARE_UINT32(tctx, cur->info6, ref->info8, version);
661 COMPARE_STRING(tctx, cur->info6, ref->info8, driver_name);
662 COMPARE_STRING(tctx, cur->info6, ref->info8, architecture);
663 COMPARE_STRING(tctx, cur->info6, ref->info8, driver_path);
664 COMPARE_STRING(tctx, cur->info6, ref->info8, data_file);
665 COMPARE_STRING(tctx, cur->info6, ref->info8, config_file);
666 COMPARE_STRING(tctx, cur->info6, ref->info8, help_file);
667 COMPARE_STRING_ARRAY(tctx, cur->info6, ref->info8, dependent_files);
668 COMPARE_STRING(tctx, cur->info6, ref->info8, monitor_name);
669 COMPARE_STRING(tctx, cur->info6, ref->info8, default_datatype);
670 COMPARE_STRING_ARRAY(tctx, cur->info6, ref->info8, previous_names);
671 COMPARE_NTTIME(tctx, cur->info6, ref->info8, driver_date);
672 COMPARE_UINT64(tctx, cur->info6, ref->info8, driver_version);
673 COMPARE_STRING(tctx, cur->info6, ref->info8, manufacturer_name);
674 COMPARE_STRING(tctx, cur->info6, ref->info8, manufacturer_url);
675 COMPARE_STRING(tctx, cur->info6, ref->info8, hardware_id);
676 COMPARE_STRING(tctx, cur->info6, ref->info8, provider);
679 /* level 8 is our reference, and it makes no sense to compare it to itself */
688 static bool test_EnumMonitors(struct torture_context *tctx,
689 struct dcerpc_binding_handle *b,
690 struct test_spoolss_context *ctx)
693 struct spoolss_EnumMonitors r;
694 uint16_t levels[] = { 1, 2 };
697 for (i=0;i<ARRAY_SIZE(levels);i++) {
698 int level = levels[i];
702 union spoolss_MonitorInfo *info;
704 r.in.servername = "";
708 r.out.needed = &needed;
709 r.out.count = &count;
712 torture_comment(tctx, "Testing EnumMonitors level %u\n", r.in.level);
714 status = dcerpc_spoolss_EnumMonitors_r(b, ctx, &r);
715 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumMonitors failed");
716 if (W_ERROR_IS_OK(r.out.result)) {
717 /* TODO: do some more checks here */
720 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
721 "EnumMonitors failed");
723 blob = data_blob_talloc_zero(ctx, needed);
725 r.in.offered = needed;
727 status = dcerpc_spoolss_EnumMonitors_r(b, ctx, &r);
728 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumMonitors failed");
730 torture_assert_werr_ok(tctx, r.out.result, "EnumMonitors failed");
732 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumMonitors, info, r.in.level, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
734 ctx->monitor_count[level] = count;
735 ctx->monitors[level] = info;
738 for (i=1;i<ARRAY_SIZE(levels);i++) {
739 int level = levels[i];
740 int old_level = levels[i-1];
741 torture_assert_int_equal(tctx, ctx->monitor_count[level], ctx->monitor_count[old_level],
742 "EnumMonitors invalid value");
745 for (i=0;i<ARRAY_SIZE(levels);i++) {
746 int level = levels[i];
747 for (j=0;j<ctx->monitor_count[level];j++) {
748 union spoolss_MonitorInfo *cur = &ctx->monitors[level][j];
749 union spoolss_MonitorInfo *ref = &ctx->monitors[2][j];
752 COMPARE_STRING(tctx, cur->info1, ref->info2, monitor_name);
755 /* level 2 is our reference, and it makes no sense to compare it to itself */
764 static bool test_EnumPrintProcessors(struct torture_context *tctx,
765 struct dcerpc_binding_handle *b,
766 struct test_spoolss_context *ctx,
767 const char *environment)
770 struct spoolss_EnumPrintProcessors r;
771 uint16_t levels[] = { 1 };
774 for (i=0;i<ARRAY_SIZE(levels);i++) {
775 int level = levels[i];
779 union spoolss_PrintProcessorInfo *info;
781 r.in.servername = "";
782 r.in.environment = environment;
786 r.out.needed = &needed;
787 r.out.count = &count;
790 torture_comment(tctx, "Testing EnumPrintProcessors level %u\n", r.in.level);
792 status = dcerpc_spoolss_EnumPrintProcessors_r(b, ctx, &r);
793 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrintProcessors failed");
794 if (W_ERROR_IS_OK(r.out.result)) {
795 /* TODO: do some more checks here */
798 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
799 "EnumPrintProcessors unexpected return code");
801 blob = data_blob_talloc_zero(ctx, needed);
803 r.in.offered = needed;
805 status = dcerpc_spoolss_EnumPrintProcessors_r(b, ctx, &r);
806 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrintProcessors failed");
808 torture_assert_werr_ok(tctx, r.out.result, "EnumPrintProcessors failed");
810 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPrintProcessors, info, r.in.level, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
812 ctx->print_processor_count[level] = count;
813 ctx->print_processors[level] = info;
816 for (i=1;i<ARRAY_SIZE(levels);i++) {
817 int level = levels[i];
818 int old_level = levels[i-1];
819 torture_assert_int_equal(tctx, ctx->print_processor_count[level], ctx->print_processor_count[old_level],
820 "EnumPrintProcessors failed");
823 for (i=0;i<ARRAY_SIZE(levels);i++) {
824 int level = levels[i];
825 for (j=0;j<ctx->print_processor_count[level];j++) {
827 union spoolss_PrintProcessorInfo *cur = &ctx->print_processors[level][j];
828 union spoolss_PrintProcessorInfo *ref = &ctx->print_processors[1][j];
832 /* level 1 is our reference, and it makes no sense to compare it to itself */
841 static bool test_EnumPrintProcDataTypes(struct torture_context *tctx,
842 struct dcerpc_binding_handle *b)
845 struct spoolss_EnumPrintProcDataTypes r;
846 uint16_t levels[] = { 1 };
849 for (i=0;i<ARRAY_SIZE(levels);i++) {
850 int level = levels[i];
854 union spoolss_PrintProcDataTypesInfo *info;
856 r.in.servername = "";
857 r.in.print_processor_name = "winprint";
861 r.out.needed = &needed;
862 r.out.count = &count;
865 torture_comment(tctx, "Testing EnumPrintProcDataTypes level %u\n", r.in.level);
867 status = dcerpc_spoolss_EnumPrintProcDataTypes_r(b, tctx, &r);
868 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrintProcDataType failed");
869 if (W_ERROR_IS_OK(r.out.result)) {
870 /* TODO: do some more checks here */
873 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
874 "EnumPrintProcDataTypes unexpected return code");
876 blob = data_blob_talloc_zero(tctx, needed);
878 r.in.offered = needed;
880 status = dcerpc_spoolss_EnumPrintProcDataTypes_r(b, tctx, &r);
881 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrintProcDataTypes failed");
883 torture_assert_werr_ok(tctx, r.out.result, "EnumPrintProcDataTypes failed");
885 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPrintProcDataTypes, info, r.in.level, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
893 static bool test_EnumPrinters(struct torture_context *tctx,
894 struct dcerpc_binding_handle *b,
895 struct test_spoolss_context *ctx)
897 struct spoolss_EnumPrinters r;
899 uint16_t levels[] = { 0, 1, 2, 4, 5 };
902 for (i=0;i<ARRAY_SIZE(levels);i++) {
903 int level = levels[i];
907 union spoolss_PrinterInfo *info;
909 r.in.flags = PRINTER_ENUM_LOCAL;
914 r.out.needed = &needed;
915 r.out.count = &count;
918 torture_comment(tctx, "Testing EnumPrinters level %u\n", r.in.level);
920 status = dcerpc_spoolss_EnumPrinters_r(b, ctx, &r);
921 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrinters failed");
922 if (W_ERROR_IS_OK(r.out.result)) {
923 /* TODO: do some more checks here */
926 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
927 "EnumPrinters unexpected return code");
929 blob = data_blob_talloc_zero(ctx, needed);
931 r.in.offered = needed;
933 status = dcerpc_spoolss_EnumPrinters_r(b, ctx, &r);
934 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrinters failed");
936 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinters failed");
938 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPrinters, info, r.in.level, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
940 ctx->printer_count[level] = count;
941 ctx->printers[level] = info;
944 for (i=1;i<ARRAY_SIZE(levels);i++) {
945 int level = levels[i];
946 int old_level = levels[i-1];
947 torture_assert_int_equal(tctx, ctx->printer_count[level], ctx->printer_count[old_level],
948 "EnumPrinters invalid value");
951 for (i=0;i<ARRAY_SIZE(levels);i++) {
952 int level = levels[i];
953 for (j=0;j<ctx->printer_count[level];j++) {
954 union spoolss_PrinterInfo *cur = &ctx->printers[level][j];
955 union spoolss_PrinterInfo *ref = &ctx->printers[2][j];
958 COMPARE_STRING(tctx, cur->info0, ref->info2, printername);
959 COMPARE_STRING(tctx, cur->info0, ref->info2, servername);
960 COMPARE_UINT32(tctx, cur->info0, ref->info2, cjobs);
961 /*COMPARE_UINT32(tctx, cur->info0, ref->info2, total_jobs);
962 COMPARE_UINT32(tctx, cur->info0, ref->info2, total_bytes);
963 COMPARE_SPOOLSS_TIME(cur->info0, ref->info2, spoolss_Time time);
964 COMPARE_UINT32(tctx, cur->info0, ref->info2, global_counter);
965 COMPARE_UINT32(tctx, cur->info0, ref->info2, total_pages);
966 COMPARE_UINT32(tctx, cur->info0, ref->info2, version);
967 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown10);
968 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown11);
969 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown12);
970 COMPARE_UINT32(tctx, cur->info0, ref->info2, session_counter);
971 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown14);
972 COMPARE_UINT32(tctx, cur->info0, ref->info2, printer_errors);
973 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown16);
974 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown17);
975 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown18);
976 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown19);
977 COMPARE_UINT32(tctx, cur->info0, ref->info2, change_id);
978 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown21);*/
979 COMPARE_UINT32(tctx, cur->info0, ref->info2, status);
980 /*COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown23);
981 COMPARE_UINT32(tctx, cur->info0, ref->info2, c_setprinter);
982 COMPARE_UINT16(cur->info0, ref->info2, unknown25);
983 COMPARE_UINT16(cur->info0, ref->info2, unknown26);
984 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown27);
985 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown28);
986 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown29);*/
989 /*COMPARE_UINT32(tctx, cur->info1, ref->info2, flags);*/
990 /*COMPARE_STRING(tctx, cur->info1, ref->info2, name);*/
991 /*COMPARE_STRING(tctx, cur->info1, ref->info2, description);*/
992 COMPARE_STRING(tctx, cur->info1, ref->info2, comment);
995 /* level 2 is our reference, and it makes no sense to compare it to itself */
998 COMPARE_STRING(tctx, cur->info4, ref->info2, printername);
999 COMPARE_STRING(tctx, cur->info4, ref->info2, servername);
1000 COMPARE_UINT32(tctx, cur->info4, ref->info2, attributes);
1003 COMPARE_STRING(tctx, cur->info5, ref->info2, printername);
1004 COMPARE_STRING(tctx, cur->info5, ref->info2, portname);
1005 COMPARE_UINT32(tctx, cur->info5, ref->info2, attributes);
1006 /*COMPARE_UINT32(tctx, cur->info5, ref->info2, device_not_selected_timeout);
1007 COMPARE_UINT32(tctx, cur->info5, ref->info2, transmission_retry_timeout);*/
1014 * - verify that the port of a printer was in the list returned by EnumPorts
1020 static bool test_GetPrinterDriver2(struct torture_context *tctx,
1021 struct dcerpc_binding_handle *b,
1022 struct policy_handle *handle,
1023 const char *driver_name,
1024 const char *environment);
1026 bool test_GetPrinter_level(struct torture_context *tctx,
1027 struct dcerpc_binding_handle *b,
1028 struct policy_handle *handle,
1030 union spoolss_PrinterInfo *info)
1032 struct spoolss_GetPrinter r;
1035 r.in.handle = handle;
1039 r.out.needed = &needed;
1041 torture_comment(tctx, "Testing GetPrinter level %u\n", r.in.level);
1043 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_GetPrinter_r(b, tctx, &r),
1044 "GetPrinter failed");
1046 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
1047 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
1048 r.in.buffer = &blob;
1049 r.in.offered = needed;
1051 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_GetPrinter_r(b, tctx, &r),
1052 "GetPrinter failed");
1055 torture_assert_werr_ok(tctx, r.out.result, "GetPrinter failed");
1057 CHECK_NEEDED_SIZE_LEVEL(spoolss_PrinterInfo, r.out.info, r.in.level, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
1059 if (info && r.out.info) {
1060 *info = *r.out.info;
1067 static bool test_GetPrinter(struct torture_context *tctx,
1068 struct dcerpc_binding_handle *b,
1069 struct policy_handle *handle,
1070 const char *environment)
1072 uint32_t levels[] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
1075 for (i=0;i<ARRAY_SIZE(levels);i++) {
1077 union spoolss_PrinterInfo info;
1081 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, levels[i], &info),
1082 "failed to call GetPrinter");
1084 if ((levels[i] == 2) && info.info2.drivername && strlen(info.info2.drivername)) {
1085 torture_assert(tctx,
1086 test_GetPrinterDriver2(tctx, b, handle, info.info2.drivername, environment),
1087 "failed to call test_GetPrinterDriver2");
1094 static bool test_SetPrinter(struct torture_context *tctx,
1095 struct dcerpc_binding_handle *b,
1096 struct policy_handle *handle,
1097 struct spoolss_SetPrinterInfoCtr *info_ctr,
1098 struct spoolss_DevmodeContainer *devmode_ctr,
1099 struct sec_desc_buf *secdesc_ctr,
1100 enum spoolss_PrinterControl command)
1102 struct spoolss_SetPrinter r;
1104 r.in.handle = handle;
1105 r.in.info_ctr = info_ctr;
1106 r.in.devmode_ctr = devmode_ctr;
1107 r.in.secdesc_ctr = secdesc_ctr;
1108 r.in.command = command;
1110 torture_comment(tctx, "Testing SetPrinter level %d\n", r.in.info_ctr->level);
1112 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_SetPrinter_r(b, tctx, &r),
1113 "failed to call SetPrinter");
1114 torture_assert_werr_ok(tctx, r.out.result,
1115 "failed to call SetPrinter");
1120 static bool test_SetPrinter_errors(struct torture_context *tctx,
1121 struct dcerpc_binding_handle *b,
1122 struct policy_handle *handle)
1124 struct spoolss_SetPrinter r;
1125 uint16_t levels[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
1128 struct spoolss_SetPrinterInfoCtr info_ctr;
1129 struct spoolss_DevmodeContainer devmode_ctr;
1130 struct sec_desc_buf secdesc_ctr;
1133 info_ctr.info.info0 = NULL;
1135 ZERO_STRUCT(devmode_ctr);
1136 ZERO_STRUCT(secdesc_ctr);
1138 r.in.handle = handle;
1139 r.in.info_ctr = &info_ctr;
1140 r.in.devmode_ctr = &devmode_ctr;
1141 r.in.secdesc_ctr = &secdesc_ctr;
1144 torture_comment(tctx, "Testing SetPrinter all zero\n");
1146 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_SetPrinter_r(b, tctx, &r),
1147 "failed to call SetPrinter");
1148 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAM,
1149 "failed to call SetPrinter");
1152 for (i=0; i < ARRAY_SIZE(levels); i++) {
1154 struct spoolss_SetPrinterInfo0 info0;
1155 struct spoolss_SetPrinterInfo1 info1;
1156 struct spoolss_SetPrinterInfo2 info2;
1157 struct spoolss_SetPrinterInfo3 info3;
1158 struct spoolss_SetPrinterInfo4 info4;
1159 struct spoolss_SetPrinterInfo5 info5;
1160 struct spoolss_SetPrinterInfo6 info6;
1161 struct spoolss_SetPrinterInfo7 info7;
1162 struct spoolss_SetPrinterInfo8 info8;
1163 struct spoolss_SetPrinterInfo9 info9;
1166 info_ctr.level = levels[i];
1167 switch (levels[i]) {
1170 info_ctr.info.info0 = &info0;
1174 info_ctr.info.info1 = &info1;
1178 info_ctr.info.info2 = &info2;
1182 info_ctr.info.info3 = &info3;
1186 info_ctr.info.info4 = &info4;
1190 info_ctr.info.info5 = &info5;
1194 info_ctr.info.info6 = &info6;
1198 info_ctr.info.info7 = &info7;
1202 info_ctr.info.info8 = &info8;
1206 info_ctr.info.info9 = &info9;
1210 torture_comment(tctx, "Testing SetPrinter level %d, command %d\n",
1211 info_ctr.level, r.in.command);
1213 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_SetPrinter_r(b, tctx, &r),
1214 "failed to call SetPrinter");
1216 switch (r.in.command) {
1217 case SPOOLSS_PRINTER_CONTROL_UNPAUSE: /* 0 */
1218 /* is ignored for all levels other then 0 */
1219 if (info_ctr.level > 0) {
1223 case SPOOLSS_PRINTER_CONTROL_PAUSE: /* 1 */
1224 case SPOOLSS_PRINTER_CONTROL_RESUME: /* 2 */
1225 case SPOOLSS_PRINTER_CONTROL_PURGE: /* 3 */
1226 if (info_ctr.level > 0) {
1227 /* is invalid for all levels other then 0 */
1228 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PRINTER_COMMAND,
1229 "unexpected error code returned");
1232 torture_assert_werr_ok(tctx, r.out.result,
1233 "failed to call SetPrinter with non 0 command");
1238 case SPOOLSS_PRINTER_CONTROL_SET_STATUS: /* 4 */
1239 /* FIXME: gd needs further investigation */
1241 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PRINTER_COMMAND,
1242 "unexpected error code returned");
1246 switch (info_ctr.level) {
1248 torture_assert_werr_equal(tctx, r.out.result, WERR_UNKNOWN_LEVEL,
1249 "unexpected error code returned");
1252 torture_assert_werr_equal(tctx, r.out.result, WERR_UNKNOWN_PRINTER_DRIVER,
1253 "unexpected error code returned");
1259 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAM,
1260 "unexpected error code returned");
1263 torture_assert_werr_equal(tctx, r.out.result, WERR_NOT_SUPPORTED,
1264 "unexpected error code returned");
1267 torture_assert_werr_ok(tctx, r.out.result,
1268 "failed to call SetPrinter");
1273 if (r.in.command < 5) {
1281 static void clear_info2(struct spoolss_SetPrinterInfoCtr *r)
1283 if ((r->level == 2) && (r->info.info2)) {
1284 r->info.info2->secdesc_ptr = 0;
1285 r->info.info2->devmode_ptr = 0;
1289 static bool test_PrinterInfo(struct torture_context *tctx,
1290 struct dcerpc_binding_handle *b,
1291 struct policy_handle *handle)
1294 struct spoolss_SetPrinter s;
1295 struct spoolss_GetPrinter q;
1296 struct spoolss_GetPrinter q0;
1297 struct spoolss_SetPrinterInfoCtr info_ctr;
1298 union spoolss_PrinterInfo info;
1299 struct spoolss_DevmodeContainer devmode_ctr;
1300 struct sec_desc_buf secdesc_ctr;
1305 uint32_t status_list[] = {
1306 /* these do not stick
1307 PRINTER_STATUS_PAUSED,
1308 PRINTER_STATUS_ERROR,
1309 PRINTER_STATUS_PENDING_DELETION, */
1310 PRINTER_STATUS_PAPER_JAM,
1311 PRINTER_STATUS_PAPER_OUT,
1312 PRINTER_STATUS_MANUAL_FEED,
1313 PRINTER_STATUS_PAPER_PROBLEM,
1314 PRINTER_STATUS_OFFLINE,
1315 PRINTER_STATUS_IO_ACTIVE,
1316 PRINTER_STATUS_BUSY,
1317 PRINTER_STATUS_PRINTING,
1318 PRINTER_STATUS_OUTPUT_BIN_FULL,
1319 PRINTER_STATUS_NOT_AVAILABLE,
1320 PRINTER_STATUS_WAITING,
1321 PRINTER_STATUS_PROCESSING,
1322 PRINTER_STATUS_INITIALIZING,
1323 PRINTER_STATUS_WARMING_UP,
1324 PRINTER_STATUS_TONER_LOW,
1325 PRINTER_STATUS_NO_TONER,
1326 PRINTER_STATUS_PAGE_PUNT,
1327 PRINTER_STATUS_USER_INTERVENTION,
1328 PRINTER_STATUS_OUT_OF_MEMORY,
1329 PRINTER_STATUS_DOOR_OPEN,
1330 PRINTER_STATUS_SERVER_UNKNOWN,
1331 PRINTER_STATUS_POWER_SAVE,
1332 /* these do not stick
1341 uint32_t default_attribute = PRINTER_ATTRIBUTE_LOCAL;
1342 uint32_t attribute_list[] = {
1343 PRINTER_ATTRIBUTE_QUEUED,
1344 /* fails with WERR_INVALID_DATATYPE:
1345 PRINTER_ATTRIBUTE_DIRECT, */
1347 PRINTER_ATTRIBUTE_DEFAULT, */
1348 PRINTER_ATTRIBUTE_SHARED,
1350 PRINTER_ATTRIBUTE_NETWORK, */
1351 PRINTER_ATTRIBUTE_HIDDEN,
1352 PRINTER_ATTRIBUTE_LOCAL,
1353 PRINTER_ATTRIBUTE_ENABLE_DEVQ,
1354 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS,
1355 PRINTER_ATTRIBUTE_DO_COMPLETE_FIRST,
1356 PRINTER_ATTRIBUTE_WORK_OFFLINE,
1358 PRINTER_ATTRIBUTE_ENABLE_BIDI, */
1359 /* fails with WERR_INVALID_DATATYPE:
1360 PRINTER_ATTRIBUTE_RAW_ONLY, */
1361 /* these do not stick
1362 PRINTER_ATTRIBUTE_PUBLISHED,
1363 PRINTER_ATTRIBUTE_FAX,
1364 PRINTER_ATTRIBUTE_TS,
1383 ZERO_STRUCT(devmode_ctr);
1384 ZERO_STRUCT(secdesc_ctr);
1386 s.in.handle = handle;
1388 s.in.info_ctr = &info_ctr;
1389 s.in.devmode_ctr = &devmode_ctr;
1390 s.in.secdesc_ctr = &secdesc_ctr;
1392 q.in.handle = handle;
1396 #define TESTGETCALL(call, r) \
1397 r.in.buffer = NULL; \
1399 r.out.needed = &needed; \
1400 status = dcerpc_spoolss_ ##call## _r(b, tctx, &r); \
1401 if (!NT_STATUS_IS_OK(status)) { \
1402 torture_comment(tctx, #call " level %u failed - %s (%s)\n", \
1403 r.in.level, nt_errstr(status), __location__); \
1407 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {\
1408 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed); \
1409 r.in.buffer = &blob; \
1410 r.in.offered = needed; \
1412 status = dcerpc_spoolss_ ##call## _r(b, tctx, &r); \
1413 if (!NT_STATUS_IS_OK(status)) { \
1414 torture_comment(tctx, #call " level %u failed - %s (%s)\n", \
1415 r.in.level, nt_errstr(status), __location__); \
1419 if (!W_ERROR_IS_OK(r.out.result)) { \
1420 torture_comment(tctx, #call " level %u failed - %s (%s)\n", \
1421 r.in.level, win_errstr(r.out.result), __location__); \
1427 #define TESTSETCALL_EXP(call, r, err) \
1428 clear_info2(&info_ctr);\
1429 status = dcerpc_spoolss_ ##call## _r(b, tctx, &r); \
1430 if (!NT_STATUS_IS_OK(status)) { \
1431 torture_comment(tctx, #call " level %u failed - %s (%s)\n", \
1432 r.in.info_ctr->level, nt_errstr(status), __location__); \
1436 if (!W_ERROR_IS_OK(err)) { \
1437 if (!W_ERROR_EQUAL(err, r.out.result)) { \
1438 torture_comment(tctx, #call " level %u failed - %s, expected %s (%s)\n", \
1439 r.in.info_ctr->level, win_errstr(r.out.result), win_errstr(err), __location__); \
1444 if (!W_ERROR_IS_OK(r.out.result)) { \
1445 torture_comment(tctx, #call " level %u failed - %s (%s)\n", \
1446 r.in.info_ctr->level, win_errstr(r.out.result), __location__); \
1451 #define TESTSETCALL(call, r) \
1452 TESTSETCALL_EXP(call, r, WERR_OK)
1454 #define STRING_EQUAL(s1, s2, field) \
1455 if ((s1 && !s2) || (s2 && !s1) || strcmp(s1, s2)) { \
1456 torture_comment(tctx, "Failed to set %s to '%s' (%s)\n", \
1457 #field, s2, __location__); \
1462 #define MEM_EQUAL(s1, s2, length, field) \
1463 if ((s1 && !s2) || (s2 && !s1) || memcmp(s1, s2, length)) { \
1464 torture_comment(tctx, "Failed to set %s to '%s' (%s)\n", \
1465 #field, (const char *)s2, __location__); \
1470 #define INT_EQUAL(i1, i2, field) \
1472 torture_comment(tctx, "Failed to set %s to 0x%llx - got 0x%llx (%s)\n", \
1473 #field, (unsigned long long)i2, (unsigned long long)i1, __location__); \
1478 #define SD_EQUAL(sd1, sd2, field) \
1479 if (!security_descriptor_equal(sd1, sd2)) { \
1480 torture_comment(tctx, "Failed to set %s (%s)\n", \
1481 #field, __location__); \
1486 #define TEST_PRINTERINFO_STRING_EXP_ERR(lvl1, field1, lvl2, field2, value, err) do { \
1487 torture_comment(tctx, "field test %d/%s vs %d/%s\n", lvl1, #field1, lvl2, #field2); \
1488 q.in.level = lvl1; \
1489 TESTGETCALL(GetPrinter, q) \
1490 info_ctr.level = lvl1; \
1491 info_ctr.info.info ## lvl1 = (struct spoolss_SetPrinterInfo ## lvl1 *)(void *)&q.out.info->info ## lvl1; \
1492 info_ctr.info.info ## lvl1->field1 = value;\
1493 TESTSETCALL_EXP(SetPrinter, s, err) \
1494 info_ctr.info.info ## lvl1->field1 = ""; \
1495 TESTGETCALL(GetPrinter, q) \
1496 info_ctr.info.info ## lvl1->field1 = value; \
1497 STRING_EQUAL(info_ctr.info.info ## lvl1->field1, value, field1); \
1498 q.in.level = lvl2; \
1499 TESTGETCALL(GetPrinter, q) \
1500 info_ctr.info.info ## lvl2 = (struct spoolss_SetPrinterInfo ## lvl2 *)(void *)&q.out.info->info ## lvl2; \
1501 STRING_EQUAL(info_ctr.info.info ## lvl2->field2, value, field2); \
1504 #define TEST_PRINTERINFO_STRING(lvl1, field1, lvl2, field2, value) do { \
1505 TEST_PRINTERINFO_STRING_EXP_ERR(lvl1, field1, lvl2, field2, value, WERR_OK); \
1508 #define TEST_PRINTERINFO_INT_EXP(lvl1, field1, lvl2, field2, value, exp_value) do { \
1509 torture_comment(tctx, "field test %d/%s vs %d/%s\n", lvl1, #field1, lvl2, #field2); \
1510 q.in.level = lvl1; \
1511 TESTGETCALL(GetPrinter, q) \
1512 info_ctr.level = lvl1; \
1513 info_ctr.info.info ## lvl1 = (struct spoolss_SetPrinterInfo ## lvl1 *)(void *)&q.out.info->info ## lvl1; \
1514 info_ctr.info.info ## lvl1->field1 = value; \
1515 TESTSETCALL(SetPrinter, s) \
1516 info_ctr.info.info ## lvl1->field1 = 0; \
1517 TESTGETCALL(GetPrinter, q) \
1518 info_ctr.info.info ## lvl1 = (struct spoolss_SetPrinterInfo ## lvl1 *)(void *)&q.out.info->info ## lvl1; \
1519 INT_EQUAL(info_ctr.info.info ## lvl1->field1, exp_value, field1); \
1520 q.in.level = lvl2; \
1521 TESTGETCALL(GetPrinter, q) \
1522 info_ctr.info.info ## lvl2 = (struct spoolss_SetPrinterInfo ## lvl2 *)(void *)&q.out.info->info ## lvl2; \
1523 INT_EQUAL(info_ctr.info.info ## lvl2->field2, exp_value, field1); \
1526 #define TEST_PRINTERINFO_INT(lvl1, field1, lvl2, field2, value) do { \
1527 TEST_PRINTERINFO_INT_EXP(lvl1, field1, lvl2, field2, value, value); \
1531 do { TESTGETCALL(GetPrinter, q0) } while (0);
1533 TEST_PRINTERINFO_STRING(2, comment, 1, comment, "xx2-1 comment");
1534 TEST_PRINTERINFO_STRING(2, comment, 2, comment, "xx2-2 comment");
1536 /* level 0 printername does not stick */
1537 /* TEST_PRINTERINFO_STRING(2, printername, 0, printername, "xx2-0 printer"); */
1538 TEST_PRINTERINFO_STRING(2, printername, 1, name, "xx2-1 printer");
1539 TEST_PRINTERINFO_STRING(2, printername, 2, printername, "xx2-2 printer");
1540 TEST_PRINTERINFO_STRING(2, printername, 4, printername, "xx2-4 printer");
1541 TEST_PRINTERINFO_STRING(2, printername, 5, printername, "xx2-5 printer");
1542 /* TEST_PRINTERINFO_STRING(4, printername, 0, printername, "xx4-0 printer"); */
1543 TEST_PRINTERINFO_STRING(4, printername, 1, name, "xx4-1 printer");
1544 TEST_PRINTERINFO_STRING(4, printername, 2, printername, "xx4-2 printer");
1545 TEST_PRINTERINFO_STRING(4, printername, 4, printername, "xx4-4 printer");
1546 TEST_PRINTERINFO_STRING(4, printername, 5, printername, "xx4-5 printer");
1547 /* TEST_PRINTERINFO_STRING(5, printername, 0, printername, "xx5-0 printer"); */
1548 TEST_PRINTERINFO_STRING(5, printername, 1, name, "xx5-1 printer");
1549 TEST_PRINTERINFO_STRING(5, printername, 2, printername, "xx5-2 printer");
1550 TEST_PRINTERINFO_STRING(5, printername, 4, printername, "xx5-4 printer");
1551 TEST_PRINTERINFO_STRING(5, printername, 5, printername, "xx5-5 printer");
1553 /* servername can be set but does not stick
1554 TEST_PRINTERINFO_STRING(2, servername, 0, servername, "xx2-0 servername");
1555 TEST_PRINTERINFO_STRING(2, servername, 2, servername, "xx2-2 servername");
1556 TEST_PRINTERINFO_STRING(2, servername, 4, servername, "xx2-4 servername");
1559 /* passing an invalid port will result in WERR_UNKNOWN_PORT */
1560 TEST_PRINTERINFO_STRING_EXP_ERR(2, portname, 2, portname, "xx2-2 portname", WERR_UNKNOWN_PORT);
1561 TEST_PRINTERINFO_STRING_EXP_ERR(2, portname, 5, portname, "xx2-5 portname", WERR_UNKNOWN_PORT);
1562 TEST_PRINTERINFO_STRING_EXP_ERR(5, portname, 2, portname, "xx5-2 portname", WERR_UNKNOWN_PORT);
1563 TEST_PRINTERINFO_STRING_EXP_ERR(5, portname, 5, portname, "xx5-5 portname", WERR_UNKNOWN_PORT);
1565 TEST_PRINTERINFO_STRING(2, sharename, 2, sharename, "xx2-2 sharename");
1566 /* passing an invalid driver will result in WERR_UNKNOWN_PRINTER_DRIVER */
1567 TEST_PRINTERINFO_STRING_EXP_ERR(2, drivername, 2, drivername, "xx2-2 drivername", WERR_UNKNOWN_PRINTER_DRIVER);
1568 TEST_PRINTERINFO_STRING(2, location, 2, location, "xx2-2 location");
1569 /* passing an invalid sepfile will result in WERR_INVALID_SEPARATOR_FILE */
1570 TEST_PRINTERINFO_STRING_EXP_ERR(2, sepfile, 2, sepfile, "xx2-2 sepfile", WERR_INVALID_SEPARATOR_FILE);
1571 /* passing an invalid printprocessor will result in WERR_UNKNOWN_PRINTPROCESSOR */
1572 TEST_PRINTERINFO_STRING_EXP_ERR(2, printprocessor, 2, printprocessor, "xx2-2 printprocessor", WERR_UNKNOWN_PRINTPROCESSOR);
1573 TEST_PRINTERINFO_STRING(2, datatype, 2, datatype, "xx2-2 datatype");
1574 TEST_PRINTERINFO_STRING(2, parameters, 2, parameters, "xx2-2 parameters");
1576 for (i=0; i < ARRAY_SIZE(attribute_list); i++) {
1577 /* TEST_PRINTERINFO_INT_EXP(2, attributes, 1, flags,
1579 (attribute_list[i] | default_attribute)
1581 TEST_PRINTERINFO_INT_EXP(2, attributes, 2, attributes,
1583 (attribute_list[i] | default_attribute)
1585 TEST_PRINTERINFO_INT_EXP(2, attributes, 4, attributes,
1587 (attribute_list[i] | default_attribute)
1589 TEST_PRINTERINFO_INT_EXP(2, attributes, 5, attributes,
1591 (attribute_list[i] | default_attribute)
1593 /* TEST_PRINTERINFO_INT_EXP(4, attributes, 1, flags,
1595 (attribute_list[i] | default_attribute)
1597 TEST_PRINTERINFO_INT_EXP(4, attributes, 2, attributes,
1599 (attribute_list[i] | default_attribute)
1601 TEST_PRINTERINFO_INT_EXP(4, attributes, 4, attributes,
1603 (attribute_list[i] | default_attribute)
1605 TEST_PRINTERINFO_INT_EXP(4, attributes, 5, attributes,
1607 (attribute_list[i] | default_attribute)
1609 /* TEST_PRINTERINFO_INT_EXP(5, attributes, 1, flags,
1611 (attribute_list[i] | default_attribute)
1613 TEST_PRINTERINFO_INT_EXP(5, attributes, 2, attributes,
1615 (attribute_list[i] | default_attribute)
1617 TEST_PRINTERINFO_INT_EXP(5, attributes, 4, attributes,
1619 (attribute_list[i] | default_attribute)
1621 TEST_PRINTERINFO_INT_EXP(5, attributes, 5, attributes,
1623 (attribute_list[i] | default_attribute)
1627 for (i=0; i < ARRAY_SIZE(status_list); i++) {
1628 /* level 2 sets do not stick
1629 TEST_PRINTERINFO_INT(2, status, 0, status, status_list[i]);
1630 TEST_PRINTERINFO_INT(2, status, 2, status, status_list[i]);
1631 TEST_PRINTERINFO_INT(2, status, 6, status, status_list[i]); */
1632 TEST_PRINTERINFO_INT(6, status, 0, status, status_list[i]);
1633 TEST_PRINTERINFO_INT(6, status, 2, status, status_list[i]);
1634 TEST_PRINTERINFO_INT(6, status, 6, status, status_list[i]);
1637 /* priorities need to be between 0 and 99
1638 passing an invalid priority will result in WERR_INVALID_PRIORITY */
1639 TEST_PRINTERINFO_INT(2, priority, 2, priority, 0);
1640 TEST_PRINTERINFO_INT(2, priority, 2, priority, 1);
1641 TEST_PRINTERINFO_INT(2, priority, 2, priority, 99);
1642 /* TEST_PRINTERINFO_INT(2, priority, 2, priority, 100); */
1643 TEST_PRINTERINFO_INT(2, defaultpriority,2, defaultpriority, 0);
1644 TEST_PRINTERINFO_INT(2, defaultpriority,2, defaultpriority, 1);
1645 TEST_PRINTERINFO_INT(2, defaultpriority,2, defaultpriority, 99);
1646 /* TEST_PRINTERINFO_INT(2, defaultpriority,2, defaultpriority, 100); */
1648 TEST_PRINTERINFO_INT(2, starttime, 2, starttime, __LINE__);
1649 TEST_PRINTERINFO_INT(2, untiltime, 2, untiltime, __LINE__);
1652 TEST_PRINTERINFO_INT(2, cjobs, 2, cjobs, __LINE__);
1653 TEST_PRINTERINFO_INT(2, averageppm, 2, averageppm, __LINE__); */
1656 TEST_PRINTERINFO_INT(5, device_not_selected_timeout, 5, device_not_selected_timeout, __LINE__);
1657 TEST_PRINTERINFO_INT(5, transmission_retry_timeout, 5, transmission_retry_timeout, __LINE__); */
1659 /* FIXME: gd also test devmode and secdesc behavior */
1662 /* verify composition of level 1 description field */
1663 const char *description;
1667 do { TESTGETCALL(GetPrinter, q0) } while (0);
1669 description = talloc_strdup(tctx, q0.out.info->info1.description);
1672 do { TESTGETCALL(GetPrinter, q0) } while (0);
1674 tmp = talloc_asprintf(tctx, "%s,%s,%s",
1675 q0.out.info->info2.printername,
1676 q0.out.info->info2.drivername,
1677 q0.out.info->info2.location);
1679 do { STRING_EQUAL(description, tmp, "description")} while (0);
1685 #define torture_assert_sid_equal(torture_ctx,got,expected,cmt)\
1686 do { struct dom_sid *__got = (got), *__expected = (expected); \
1687 if (!dom_sid_equal(__got, __expected)) { \
1688 torture_result(torture_ctx, TORTURE_FAIL, \
1689 __location__": "#got" was %s, expected %s: %s", \
1690 dom_sid_string(torture_ctx, __got), dom_sid_string(torture_ctx, __expected), cmt); \
1695 static bool test_security_descriptor_equal(struct torture_context *tctx,
1696 const struct security_descriptor *sd1,
1697 const struct security_descriptor *sd2)
1704 torture_comment(tctx, "%s\n", __location__);
1708 torture_assert_int_equal(tctx, sd1->revision, sd2->revision, "revision mismatch");
1709 torture_assert_int_equal(tctx, sd1->type, sd2->type, "type mismatch");
1711 torture_assert_sid_equal(tctx, sd1->owner_sid, sd2->owner_sid, "owner mismatch");
1712 torture_assert_sid_equal(tctx, sd1->group_sid, sd2->group_sid, "group mismatch");
1714 if (!security_acl_equal(sd1->sacl, sd2->sacl)) {
1715 torture_comment(tctx, "%s: sacl mismatch\n", __location__);
1716 NDR_PRINT_DEBUG(security_acl, sd1->sacl);
1717 NDR_PRINT_DEBUG(security_acl, sd2->sacl);
1720 if (!security_acl_equal(sd1->dacl, sd2->dacl)) {
1721 torture_comment(tctx, "%s: dacl mismatch\n", __location__);
1722 NDR_PRINT_DEBUG(security_acl, sd1->dacl);
1723 NDR_PRINT_DEBUG(security_acl, sd2->dacl);
1730 static bool test_sd_set_level(struct torture_context *tctx,
1731 struct dcerpc_binding_handle *b,
1732 struct policy_handle *handle,
1734 struct security_descriptor *sd)
1736 struct spoolss_SetPrinterInfoCtr info_ctr;
1737 struct spoolss_DevmodeContainer devmode_ctr;
1738 struct sec_desc_buf secdesc_ctr;
1739 union spoolss_SetPrinterInfo sinfo;
1741 ZERO_STRUCT(devmode_ctr);
1742 ZERO_STRUCT(secdesc_ctr);
1746 union spoolss_PrinterInfo info;
1747 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
1748 torture_assert(tctx, PrinterInfo_to_SetPrinterInfo(tctx, &info, 2, &sinfo), "");
1751 info_ctr.info = sinfo;
1756 struct spoolss_SetPrinterInfo3 info3;
1758 info3.sec_desc_ptr = 0;
1761 info_ctr.info.info3 = &info3;
1769 secdesc_ctr.sd = sd;
1771 torture_assert(tctx,
1772 test_SetPrinter(tctx, b, handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0), "");
1777 static bool test_PrinterInfo_SDs(struct torture_context *tctx,
1778 struct dcerpc_binding_handle *b,
1779 struct policy_handle *handle)
1781 union spoolss_PrinterInfo info;
1782 struct security_descriptor *sd1, *sd2;
1785 /* just compare level 2 and level 3 */
1787 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
1789 sd1 = info.info2.secdesc;
1791 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 3, &info), "");
1793 sd2 = info.info3.secdesc;
1795 torture_assert(tctx, test_security_descriptor_equal(tctx, sd1, sd2),
1796 "SD level 2 != SD level 3");
1799 /* query level 2, set level 2, query level 2 */
1801 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
1803 sd1 = info.info2.secdesc;
1805 torture_assert(tctx, test_sd_set_level(tctx, b, handle, 2, sd1), "");
1807 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
1809 sd2 = info.info2.secdesc;
1810 if (sd1->type & SEC_DESC_DACL_DEFAULTED) {
1811 torture_comment(tctx, "removing SEC_DESC_DACL_DEFAULTED\n");
1812 sd1->type &= ~SEC_DESC_DACL_DEFAULTED;
1815 torture_assert(tctx, test_security_descriptor_equal(tctx, sd1, sd2),
1816 "SD level 2 != SD level 2 after SD has been set via level 2");
1819 /* query level 2, set level 3, query level 2 */
1821 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
1823 sd1 = info.info2.secdesc;
1825 torture_assert(tctx, test_sd_set_level(tctx, b, handle, 3, sd1), "");
1827 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
1829 sd2 = info.info2.secdesc;
1831 torture_assert(tctx, test_security_descriptor_equal(tctx, sd1, sd2),
1832 "SD level 2 != SD level 2 after SD has been set via level 3");
1834 /* set modified sd level 3, query level 2 */
1836 for (i=0; i < 93; i++) {
1837 struct security_ace a;
1838 const char *sid_string = talloc_asprintf(tctx, "S-1-5-32-9999%i", i);
1839 a.type = SEC_ACE_TYPE_ACCESS_ALLOWED;
1841 a.size = 0; /* autogenerated */
1843 a.trustee = *dom_sid_parse_talloc(tctx, sid_string);
1844 torture_assert_ntstatus_ok(tctx, security_descriptor_dacl_add(sd1, &a), "");
1847 torture_assert(tctx, test_sd_set_level(tctx, b, handle, 3, sd1), "");
1849 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
1850 sd2 = info.info2.secdesc;
1852 if (sd1->type & SEC_DESC_DACL_DEFAULTED) {
1853 torture_comment(tctx, "removing SEC_DESC_DACL_DEFAULTED\n");
1854 sd1->type &= ~SEC_DESC_DACL_DEFAULTED;
1857 torture_assert(tctx, test_security_descriptor_equal(tctx, sd1, sd2),
1858 "modified SD level 2 != SD level 2 after SD has been set via level 3");
1865 * wrapper call that saves original sd, runs tests, and restores sd
1868 static bool test_PrinterInfo_SD(struct torture_context *tctx,
1869 struct dcerpc_binding_handle *b,
1870 struct policy_handle *handle)
1872 union spoolss_PrinterInfo info;
1873 struct security_descriptor *sd;
1876 torture_comment(tctx, "Testing Printer Security Descriptors\n");
1878 /* save original sd */
1880 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info),
1881 "failed to get initial security descriptor");
1883 sd = security_descriptor_copy(tctx, info.info2.secdesc);
1887 ret = test_PrinterInfo_SDs(tctx, b, handle);
1889 /* restore original sd */
1891 torture_assert(tctx, test_sd_set_level(tctx, b, handle, 3, sd),
1892 "failed to restore initial security descriptor");
1894 torture_comment(tctx, "Printer Security Descriptors test %s\n\n",
1895 ret ? "succeeded" : "failed");
1901 static bool test_devmode_set_level(struct torture_context *tctx,
1902 struct dcerpc_binding_handle *b,
1903 struct policy_handle *handle,
1905 struct spoolss_DeviceMode *devmode)
1907 struct spoolss_SetPrinterInfoCtr info_ctr;
1908 struct spoolss_DevmodeContainer devmode_ctr;
1909 struct sec_desc_buf secdesc_ctr;
1910 union spoolss_SetPrinterInfo sinfo;
1912 ZERO_STRUCT(devmode_ctr);
1913 ZERO_STRUCT(secdesc_ctr);
1917 union spoolss_PrinterInfo info;
1918 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
1919 torture_assert(tctx, PrinterInfo_to_SetPrinterInfo(tctx, &info, 2, &sinfo), "");
1922 info_ctr.info = sinfo;
1927 struct spoolss_SetPrinterInfo8 info8;
1929 info8.devmode_ptr = 0;
1932 info_ctr.info.info8 = &info8;
1940 devmode_ctr.devmode = devmode;
1942 torture_assert(tctx,
1943 test_SetPrinter(tctx, b, handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0), "");
1949 static bool test_devicemode_equal(struct torture_context *tctx,
1950 const struct spoolss_DeviceMode *d1,
1951 const struct spoolss_DeviceMode *d2)
1958 torture_comment(tctx, "%s\n", __location__);
1961 torture_assert_str_equal(tctx, d1->devicename, d2->devicename, "devicename mismatch");
1962 torture_assert_int_equal(tctx, d1->specversion, d2->specversion, "specversion mismatch");
1963 torture_assert_int_equal(tctx, d1->driverversion, d2->driverversion, "driverversion mismatch");
1964 torture_assert_int_equal(tctx, d1->size, d2->size, "size mismatch");
1965 torture_assert_int_equal(tctx, d1->__driverextra_length, d2->__driverextra_length, "__driverextra_length mismatch");
1966 torture_assert_int_equal(tctx, d1->fields, d2->fields, "fields mismatch");
1967 torture_assert_int_equal(tctx, d1->orientation, d2->orientation, "orientation mismatch");
1968 torture_assert_int_equal(tctx, d1->papersize, d2->papersize, "papersize mismatch");
1969 torture_assert_int_equal(tctx, d1->paperlength, d2->paperlength, "paperlength mismatch");
1970 torture_assert_int_equal(tctx, d1->paperwidth, d2->paperwidth, "paperwidth mismatch");
1971 torture_assert_int_equal(tctx, d1->scale, d2->scale, "scale mismatch");
1972 torture_assert_int_equal(tctx, d1->copies, d2->copies, "copies mismatch");
1973 torture_assert_int_equal(tctx, d1->defaultsource, d2->defaultsource, "defaultsource mismatch");
1974 torture_assert_int_equal(tctx, d1->printquality, d2->printquality, "printquality mismatch");
1975 torture_assert_int_equal(tctx, d1->color, d2->color, "color mismatch");
1976 torture_assert_int_equal(tctx, d1->duplex, d2->duplex, "duplex mismatch");
1977 torture_assert_int_equal(tctx, d1->yresolution, d2->yresolution, "yresolution mismatch");
1978 torture_assert_int_equal(tctx, d1->ttoption, d2->ttoption, "ttoption mismatch");
1979 torture_assert_int_equal(tctx, d1->collate, d2->collate, "collate mismatch");
1980 torture_assert_str_equal(tctx, d1->formname, d2->formname, "formname mismatch");
1981 torture_assert_int_equal(tctx, d1->logpixels, d2->logpixels, "logpixels mismatch");
1982 torture_assert_int_equal(tctx, d1->bitsperpel, d2->bitsperpel, "bitsperpel mismatch");
1983 torture_assert_int_equal(tctx, d1->pelswidth, d2->pelswidth, "pelswidth mismatch");
1984 torture_assert_int_equal(tctx, d1->pelsheight, d2->pelsheight, "pelsheight mismatch");
1985 torture_assert_int_equal(tctx, d1->displayflags, d2->displayflags, "displayflags mismatch");
1986 torture_assert_int_equal(tctx, d1->displayfrequency, d2->displayfrequency, "displayfrequency mismatch");
1987 torture_assert_int_equal(tctx, d1->icmmethod, d2->icmmethod, "icmmethod mismatch");
1988 torture_assert_int_equal(tctx, d1->icmintent, d2->icmintent, "icmintent mismatch");
1989 torture_assert_int_equal(tctx, d1->mediatype, d2->mediatype, "mediatype mismatch");
1990 torture_assert_int_equal(tctx, d1->dithertype, d2->dithertype, "dithertype mismatch");
1991 torture_assert_int_equal(tctx, d1->reserved1, d2->reserved1, "reserved1 mismatch");
1992 torture_assert_int_equal(tctx, d1->reserved2, d2->reserved2, "reserved2 mismatch");
1993 torture_assert_int_equal(tctx, d1->panningwidth, d2->panningwidth, "panningwidth mismatch");
1994 torture_assert_int_equal(tctx, d1->panningheight, d2->panningheight, "panningheight mismatch");
1995 torture_assert_data_blob_equal(tctx, d1->driverextra_data, d2->driverextra_data, "driverextra_data mismatch");
2000 static bool test_devicemode_full(struct torture_context *tctx,
2001 struct dcerpc_binding_handle *b,
2002 struct policy_handle *handle)
2004 struct spoolss_SetPrinter s;
2005 struct spoolss_GetPrinter q;
2006 struct spoolss_GetPrinter q0;
2007 struct spoolss_SetPrinterInfoCtr info_ctr;
2008 struct spoolss_SetPrinterInfo8 info8;
2009 union spoolss_PrinterInfo info;
2010 struct spoolss_DevmodeContainer devmode_ctr;
2011 struct sec_desc_buf secdesc_ctr;
2016 #define TEST_DEVMODE_INT_EXP(lvl1, field1, lvl2, field2, value, exp_value) do { \
2017 torture_comment(tctx, "field test %d/%s vs %d/%s\n", lvl1, #field1, lvl2, #field2); \
2018 q.in.level = lvl1; \
2019 TESTGETCALL(GetPrinter, q) \
2020 info_ctr.level = lvl1; \
2022 info_ctr.info.info ## lvl1 = (struct spoolss_SetPrinterInfo ## lvl1 *)(void *)&q.out.info->info ## lvl1; \
2023 } else if (lvl1 == 8) {\
2024 info_ctr.info.info ## lvl1 = &info8; \
2026 devmode_ctr.devmode = q.out.info->info ## lvl1.devmode; \
2027 devmode_ctr.devmode->field1 = value; \
2028 TESTSETCALL(SetPrinter, s) \
2029 TESTGETCALL(GetPrinter, q) \
2030 INT_EQUAL(q.out.info->info ## lvl1.devmode->field1, exp_value, field1); \
2031 q.in.level = lvl2; \
2032 TESTGETCALL(GetPrinter, q) \
2033 INT_EQUAL(q.out.info->info ## lvl2.devmode->field2, exp_value, field1); \
2036 #define TEST_DEVMODE_INT(lvl1, field1, lvl2, field2, value) do { \
2037 TEST_DEVMODE_INT_EXP(lvl1, field1, lvl2, field2, value, value); \
2040 ZERO_STRUCT(devmode_ctr);
2041 ZERO_STRUCT(secdesc_ctr);
2044 s.in.handle = handle;
2046 s.in.info_ctr = &info_ctr;
2047 s.in.devmode_ctr = &devmode_ctr;
2048 s.in.secdesc_ctr = &secdesc_ctr;
2050 q.in.handle = handle;
2055 const char *devicename;/* [charset(UTF16)] */
2056 enum spoolss_DeviceModeSpecVersion specversion;
2057 uint16_t driverversion;
2059 uint16_t __driverextra_length;/* [value(r->driverextra_data.length)] */
2063 TEST_DEVMODE_INT(8, orientation, 8, orientation, __LINE__);
2064 TEST_DEVMODE_INT(8, papersize, 8, papersize, __LINE__);
2065 TEST_DEVMODE_INT(8, paperlength, 8, paperlength, __LINE__);
2066 TEST_DEVMODE_INT(8, paperwidth, 8, paperwidth, __LINE__);
2067 TEST_DEVMODE_INT(8, scale, 8, scale, __LINE__);
2068 TEST_DEVMODE_INT(8, copies, 8, copies, __LINE__);
2069 TEST_DEVMODE_INT(8, defaultsource, 8, defaultsource, __LINE__);
2070 TEST_DEVMODE_INT(8, printquality, 8, printquality, __LINE__);
2071 TEST_DEVMODE_INT(8, color, 8, color, __LINE__);
2072 TEST_DEVMODE_INT(8, duplex, 8, duplex, __LINE__);
2073 TEST_DEVMODE_INT(8, yresolution, 8, yresolution, __LINE__);
2074 TEST_DEVMODE_INT(8, ttoption, 8, ttoption, __LINE__);
2075 TEST_DEVMODE_INT(8, collate, 8, collate, __LINE__);
2077 const char *formname;/* [charset(UTF16)] */
2079 TEST_DEVMODE_INT(8, logpixels, 8, logpixels, __LINE__);
2080 TEST_DEVMODE_INT(8, bitsperpel, 8, bitsperpel, __LINE__);
2081 TEST_DEVMODE_INT(8, pelswidth, 8, pelswidth, __LINE__);
2082 TEST_DEVMODE_INT(8, pelsheight, 8, pelsheight, __LINE__);
2083 TEST_DEVMODE_INT(8, displayflags, 8, displayflags, __LINE__);
2084 TEST_DEVMODE_INT(8, displayfrequency, 8, displayfrequency, __LINE__);
2085 TEST_DEVMODE_INT(8, icmmethod, 8, icmmethod, __LINE__);
2086 TEST_DEVMODE_INT(8, icmintent, 8, icmintent, __LINE__);
2087 TEST_DEVMODE_INT(8, mediatype, 8, mediatype, __LINE__);
2088 TEST_DEVMODE_INT(8, dithertype, 8, dithertype, __LINE__);
2089 TEST_DEVMODE_INT(8, reserved1, 8, reserved1, __LINE__);
2090 TEST_DEVMODE_INT(8, reserved2, 8, reserved2, __LINE__);
2091 TEST_DEVMODE_INT(8, panningwidth, 8, panningwidth, __LINE__);
2092 TEST_DEVMODE_INT(8, panningheight, 8, panningheight, __LINE__);
2097 static bool call_OpenPrinterEx(struct torture_context *tctx,
2098 struct dcerpc_pipe *p,
2100 struct spoolss_DeviceMode *devmode,
2101 struct policy_handle *handle);
2103 static bool test_ClosePrinter(struct torture_context *tctx,
2104 struct dcerpc_binding_handle *b,
2105 struct policy_handle *handle);
2107 static bool test_PrinterInfo_DevModes(struct torture_context *tctx,
2108 struct dcerpc_pipe *p,
2109 struct policy_handle *handle,
2112 union spoolss_PrinterInfo info;
2113 struct spoolss_DeviceMode *devmode;
2114 struct spoolss_DeviceMode *devmode2;
2115 struct policy_handle handle_devmode;
2116 struct dcerpc_binding_handle *b = p->binding_handle;
2118 /* simply compare level8 and level2 devmode */
2120 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 8, &info), "");
2122 devmode = info.info8.devmode;
2124 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
2126 devmode2 = info.info2.devmode;
2128 torture_assert(tctx, test_devicemode_equal(tctx, devmode, devmode2),
2129 "DM level 8 != DM level 2");
2132 /* set devicemode level 8 and see if it persists */
2134 devmode->copies = 93;
2135 devmode->formname = talloc_strdup(tctx, "Legal");
2137 torture_assert(tctx, test_devmode_set_level(tctx, b, handle, 8, devmode), "");
2139 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 8, &info), "");
2141 devmode2 = info.info8.devmode;
2143 torture_assert(tctx, test_devicemode_equal(tctx, devmode, devmode2),
2144 "modified DM level 8 != DM level 8 after DM has been set via level 8");
2146 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
2148 devmode2 = info.info2.devmode;
2150 torture_assert(tctx, test_devicemode_equal(tctx, devmode, devmode2),
2151 "modified DM level 8 != DM level 2");
2154 /* set devicemode level 2 and see if it persists */
2156 devmode->copies = 39;
2157 devmode->formname = talloc_strdup(tctx, "Executive");
2159 torture_assert(tctx, test_devmode_set_level(tctx, b, handle, 2, devmode), "");
2161 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 8, &info), "");
2163 devmode2 = info.info8.devmode;
2165 torture_assert(tctx, test_devicemode_equal(tctx, devmode, devmode2),
2166 "modified DM level 8 != DM level 8 after DM has been set via level 2");
2168 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
2170 devmode2 = info.info2.devmode;
2172 torture_assert(tctx, test_devicemode_equal(tctx, devmode, devmode2),
2173 "modified DM level 8 != DM level 2");
2176 /* check every single bit in public part of devicemode */
2178 torture_assert(tctx, test_devicemode_full(tctx, b, handle),
2179 "failed to set every single devicemode component");
2182 /* change formname upon open and see if it persists in getprinter calls */
2184 devmode->formname = talloc_strdup(tctx, "A4");
2185 devmode->copies = 42;
2187 torture_assert(tctx, call_OpenPrinterEx(tctx, p, name, devmode, &handle_devmode),
2188 "failed to open printer handle");
2190 torture_assert(tctx, test_GetPrinter_level(tctx, b, &handle_devmode, 8, &info), "");
2192 devmode2 = info.info8.devmode;
2194 if (strequal(devmode->devicename, devmode2->devicename)) {
2195 torture_warning(tctx, "devicenames are the same\n");
2197 torture_comment(tctx, "devicename passed in for open: %s\n", devmode->devicename);
2198 torture_comment(tctx, "devicename after level 8 get: %s\n", devmode2->devicename);
2201 if (strequal(devmode->formname, devmode2->formname)) {
2202 torture_warning(tctx, "formname are the same\n");
2204 torture_comment(tctx, "formname passed in for open: %s\n", devmode->formname);
2205 torture_comment(tctx, "formname after level 8 get: %s\n", devmode2->formname);
2208 if (devmode->copies == devmode2->copies) {
2209 torture_warning(tctx, "copies are the same\n");
2211 torture_comment(tctx, "copies passed in for open: %d\n", devmode->copies);
2212 torture_comment(tctx, "copies after level 8 get: %d\n", devmode2->copies);
2215 torture_assert(tctx, test_GetPrinter_level(tctx, b, &handle_devmode, 2, &info), "");
2217 devmode2 = info.info2.devmode;
2219 if (strequal(devmode->devicename, devmode2->devicename)) {
2220 torture_warning(tctx, "devicenames are the same\n");
2222 torture_comment(tctx, "devicename passed in for open: %s\n", devmode->devicename);
2223 torture_comment(tctx, "devicename after level 2 get: %s\n", devmode2->devicename);
2226 if (strequal(devmode->formname, devmode2->formname)) {
2227 torture_warning(tctx, "formname is the same\n");
2229 torture_comment(tctx, "formname passed in for open: %s\n", devmode->formname);
2230 torture_comment(tctx, "formname after level 2 get: %s\n", devmode2->formname);
2233 if (devmode->copies == devmode2->copies) {
2234 torture_warning(tctx, "copies are the same\n");
2236 torture_comment(tctx, "copies passed in for open: %d\n", devmode->copies);
2237 torture_comment(tctx, "copies after level 2 get: %d\n", devmode2->copies);
2240 test_ClosePrinter(tctx, b, &handle_devmode);
2246 * wrapper call that saves original devmode, runs tests, and restores devmode
2249 static bool test_PrinterInfo_DevMode(struct torture_context *tctx,
2250 struct dcerpc_pipe *p,
2251 struct policy_handle *handle,
2254 union spoolss_PrinterInfo info;
2255 struct spoolss_DeviceMode *devmode;
2257 struct dcerpc_binding_handle *b = p->binding_handle;
2259 torture_comment(tctx, "Testing Printer Devicemodes\n");
2261 /* save original devmode */
2263 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 8, &info),
2264 "failed to get initial global devicemode");
2266 devmode = info.info8.devmode;
2270 ret = test_PrinterInfo_DevModes(tctx, p, handle, name);
2272 /* restore original devmode */
2274 torture_assert(tctx, test_devmode_set_level(tctx, b, handle, 8, devmode),
2275 "failed to restore initial global device mode");
2277 torture_comment(tctx, "Printer Devicemodes test %s\n\n",
2278 ret ? "succeeded" : "failed");
2284 static bool test_ClosePrinter(struct torture_context *tctx,
2285 struct dcerpc_binding_handle *b,
2286 struct policy_handle *handle)
2289 struct spoolss_ClosePrinter r;
2291 r.in.handle = handle;
2292 r.out.handle = handle;
2294 torture_comment(tctx, "Testing ClosePrinter\n");
2296 status = dcerpc_spoolss_ClosePrinter_r(b, tctx, &r);
2297 torture_assert_ntstatus_ok(tctx, status, "ClosePrinter failed");
2298 torture_assert_werr_ok(tctx, r.out.result, "ClosePrinter failed");
2303 static bool test_GetForm_args(struct torture_context *tctx,
2304 struct dcerpc_binding_handle *b,
2305 struct policy_handle *handle,
2306 const char *form_name,
2308 union spoolss_FormInfo *info_p)
2311 struct spoolss_GetForm r;
2314 r.in.handle = handle;
2315 r.in.form_name = form_name;
2319 r.out.needed = &needed;
2321 torture_comment(tctx, "Testing GetForm(%s) level %d\n", form_name, r.in.level);
2323 status = dcerpc_spoolss_GetForm_r(b, tctx, &r);
2324 torture_assert_ntstatus_ok(tctx, status, "GetForm failed");
2326 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
2327 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
2328 r.in.buffer = &blob;
2329 r.in.offered = needed;
2330 status = dcerpc_spoolss_GetForm_r(b, tctx, &r);
2331 torture_assert_ntstatus_ok(tctx, status, "GetForm failed");
2333 torture_assert_werr_ok(tctx, r.out.result, "GetForm failed");
2335 torture_assert(tctx, r.out.info, "No form info returned");
2338 torture_assert_werr_ok(tctx, r.out.result, "GetForm failed");
2340 CHECK_NEEDED_SIZE_LEVEL(spoolss_FormInfo, r.out.info, r.in.level, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
2343 *info_p = *r.out.info;
2349 static bool test_GetForm(struct torture_context *tctx,
2350 struct dcerpc_binding_handle *b,
2351 struct policy_handle *handle,
2352 const char *form_name,
2355 return test_GetForm_args(tctx, b, handle, form_name, level, NULL);
2358 static bool test_EnumForms(struct torture_context *tctx,
2359 struct dcerpc_binding_handle *b,
2360 struct policy_handle *handle,
2364 union spoolss_FormInfo **info_p)
2366 struct spoolss_EnumForms r;
2369 union spoolss_FormInfo *info;
2371 r.in.handle = handle;
2375 r.out.needed = &needed;
2376 r.out.count = &count;
2379 torture_comment(tctx, "Testing EnumForms level %d\n", r.in.level);
2381 torture_assert_ntstatus_ok(tctx,
2382 dcerpc_spoolss_EnumForms_r(b, tctx, &r),
2383 "EnumForms failed");
2385 if ((r.in.level == 2) && (W_ERROR_EQUAL(r.out.result, WERR_UNKNOWN_LEVEL))) {
2386 torture_skip(tctx, "EnumForms level 2 not supported");
2389 if (print_server && W_ERROR_EQUAL(r.out.result, WERR_BADFID)) {
2390 torture_fail(tctx, "EnumForms on the PrintServer isn't supported by test server (NT4)");
2393 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
2394 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
2395 r.in.buffer = &blob;
2396 r.in.offered = needed;
2398 torture_assert_ntstatus_ok(tctx,
2399 dcerpc_spoolss_EnumForms_r(b, tctx, &r),
2400 "EnumForms failed");
2402 torture_assert(tctx, info, "No forms returned");
2405 torture_assert_werr_ok(tctx, r.out.result, "EnumForms failed");
2407 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumForms, info, r.in.level, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
2419 static bool test_EnumForms_all(struct torture_context *tctx,
2420 struct dcerpc_binding_handle *b,
2421 struct policy_handle *handle,
2424 uint32_t levels[] = { 1, 2 };
2427 for (i=0; i<ARRAY_SIZE(levels); i++) {
2430 union spoolss_FormInfo *info = NULL;
2432 torture_assert(tctx,
2433 test_EnumForms(tctx, b, handle, print_server, levels[i], &count, &info),
2434 "failed to enum forms");
2436 for (j = 0; j < count; j++) {
2437 if (!print_server) {
2438 torture_assert(tctx,
2439 test_GetForm(tctx, b, handle, info[j].info1.form_name, levels[i]),
2440 "failed to get form");
2448 static bool test_EnumForms_find_one(struct torture_context *tctx,
2449 struct dcerpc_binding_handle *b,
2450 struct policy_handle *handle,
2452 const char *form_name)
2454 union spoolss_FormInfo *info;
2459 torture_assert(tctx,
2460 test_EnumForms(tctx, b, handle, print_server, 1, &count, &info),
2461 "failed to enumerate forms");
2463 for (i=0; i<count; i++) {
2464 if (strequal(form_name, info[i].info1.form_name)) {
2473 static bool test_DeleteForm(struct torture_context *tctx,
2474 struct dcerpc_binding_handle *b,
2475 struct policy_handle *handle,
2476 const char *form_name,
2477 WERROR expected_result)
2479 struct spoolss_DeleteForm r;
2481 r.in.handle = handle;
2482 r.in.form_name = form_name;
2484 torture_comment(tctx, "Testing DeleteForm(%s)\n", form_name);
2486 torture_assert_ntstatus_ok(tctx,
2487 dcerpc_spoolss_DeleteForm_r(b, tctx, &r),
2488 "DeleteForm failed");
2489 torture_assert_werr_equal(tctx, r.out.result, expected_result,
2490 "DeleteForm gave unexpected result");
2491 if (W_ERROR_IS_OK(r.out.result)) {
2492 torture_assert_ntstatus_ok(tctx,
2493 dcerpc_spoolss_DeleteForm_r(b, tctx, &r),
2494 "2nd DeleteForm failed");
2495 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_FORM_NAME,
2496 "2nd DeleteForm failed");
2502 static bool test_AddForm(struct torture_context *tctx,
2503 struct dcerpc_binding_handle *b,
2504 struct policy_handle *handle,
2506 union spoolss_AddFormInfo *info,
2507 WERROR expected_result)
2509 struct spoolss_AddForm r;
2512 torture_skip(tctx, "only level 1 supported");
2515 r.in.handle = handle;
2519 torture_comment(tctx, "Testing AddForm(%s) level %d, type %d\n",
2520 r.in.info.info1->form_name, r.in.level,
2521 r.in.info.info1->flags);
2523 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_AddForm_r(b, tctx, &r),
2525 torture_assert_werr_equal(tctx, r.out.result, expected_result,
2526 "AddForm gave unexpected result");
2528 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_AddForm_r(b, tctx, &r),
2529 "2nd AddForm failed");
2530 if (W_ERROR_EQUAL(expected_result, WERR_INVALID_PARAM)) {
2531 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAM,
2532 "2nd AddForm gave unexpected result");
2534 torture_assert_werr_equal(tctx, r.out.result, WERR_FILE_EXISTS,
2535 "2nd AddForm gave unexpected result");
2541 static bool test_SetForm(struct torture_context *tctx,
2542 struct dcerpc_binding_handle *b,
2543 struct policy_handle *handle,
2544 const char *form_name,
2546 union spoolss_AddFormInfo *info)
2548 struct spoolss_SetForm r;
2550 r.in.handle = handle;
2551 r.in.form_name = form_name;
2555 torture_comment(tctx, "Testing SetForm(%s) level %d\n",
2556 form_name, r.in.level);
2558 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_SetForm_r(b, tctx, &r),
2561 torture_assert_werr_ok(tctx, r.out.result,
2567 static bool test_GetForm_winreg(struct torture_context *tctx,
2568 struct dcerpc_binding_handle *b,
2569 struct policy_handle *handle,
2570 const char *key_name,
2571 const char *form_name,
2572 enum winreg_Type *w_type,
2577 static bool test_Forms_args(struct torture_context *tctx,
2578 struct dcerpc_binding_handle *b,
2579 struct policy_handle *handle,
2581 const char *printer_name,
2582 struct dcerpc_binding_handle *winreg_handle,
2583 struct policy_handle *hive_handle,
2584 const char *form_name,
2585 struct spoolss_AddFormInfo1 *info1,
2586 WERROR expected_add_result,
2587 WERROR expected_delete_result)
2589 union spoolss_FormInfo info;
2590 union spoolss_AddFormInfo add_info;
2592 enum winreg_Type w_type;
2597 add_info.info1 = info1;
2599 torture_assert(tctx,
2600 test_AddForm(tctx, b, handle, 1, &add_info, expected_add_result),
2601 "failed to add form");
2603 if (winreg_handle && hive_handle && W_ERROR_IS_OK(expected_add_result)) {
2605 torture_assert(tctx,
2606 test_GetForm_winreg(tctx, winreg_handle, hive_handle, TOP_LEVEL_CONTROL_FORMS_KEY, form_name, &w_type, &w_size, &w_length, &w_data),
2607 "failed to get form via winreg");
2609 torture_assert_int_equal(tctx, w_type, REG_BINARY, "unexpected type");
2610 torture_assert_int_equal(tctx, w_size, 0x20, "unexpected size");
2611 torture_assert_int_equal(tctx, w_length, 0x20, "unexpected length");
2612 torture_assert_mem_equal(tctx, &w_data[0], &add_info.info1->size.width, 4, "width mismatch");
2613 torture_assert_mem_equal(tctx, &w_data[4], &add_info.info1->size.height, 4, "height mismatch");
2614 torture_assert_mem_equal(tctx, &w_data[8], &add_info.info1->area.left, 4, "left mismatch");
2615 torture_assert_mem_equal(tctx, &w_data[12], &add_info.info1->area.top, 4, "top mismatch");
2616 torture_assert_mem_equal(tctx, &w_data[16], &add_info.info1->area.right, 4, "right mismatch");
2617 torture_assert_mem_equal(tctx, &w_data[20], &add_info.info1->area.bottom, 4, "bottom mismatch");
2618 /* skip index here */
2619 torture_assert_mem_equal(tctx, &w_data[28], &add_info.info1->flags, 4, "flags mismatch");
2622 if (!print_server && W_ERROR_IS_OK(expected_add_result)) {
2623 torture_assert(tctx,
2624 test_GetForm_args(tctx, b, handle, form_name, 1, &info),
2625 "failed to get added form");
2627 torture_assert_int_equal(tctx, info.info1.size.width, add_info.info1->size.width, "width mismatch");
2628 torture_assert_int_equal(tctx, info.info1.size.height, add_info.info1->size.height, "height mismatch");
2629 torture_assert_int_equal(tctx, info.info1.area.left, add_info.info1->area.left, "left mismatch");
2630 torture_assert_int_equal(tctx, info.info1.area.top, add_info.info1->area.top, "top mismatch");
2631 torture_assert_int_equal(tctx, info.info1.area.right, add_info.info1->area.right, "right mismatch");
2632 torture_assert_int_equal(tctx, info.info1.area.bottom, add_info.info1->area.bottom, "bottom mismatch");
2633 torture_assert_int_equal(tctx, info.info1.flags, add_info.info1->flags, "flags mismatch");
2635 if (winreg_handle && hive_handle) {
2636 torture_assert_mem_equal(tctx, &w_data[0], &info.info1.size.width, 4, "width mismatch");
2637 torture_assert_mem_equal(tctx, &w_data[4], &info.info1.size.height, 4, "height mismatch");
2638 torture_assert_mem_equal(tctx, &w_data[8], &info.info1.area.left, 4, "left mismatch");
2639 torture_assert_mem_equal(tctx, &w_data[12], &info.info1.area.top, 4, "top mismatch");
2640 torture_assert_mem_equal(tctx, &w_data[16], &info.info1.area.right, 4, "right mismatch");
2641 torture_assert_mem_equal(tctx, &w_data[20], &info.info1.area.bottom, 4, "bottom mismatch");
2642 /* skip index here */
2643 torture_assert_mem_equal(tctx, &w_data[28], &info.info1.flags, 4, "flags mismatch");
2646 add_info.info1->size.width = 1234;
2648 torture_assert(tctx,
2649 test_SetForm(tctx, b, handle, form_name, 1, &add_info),
2650 "failed to set form");
2651 torture_assert(tctx,
2652 test_GetForm_args(tctx, b, handle, form_name, 1, &info),
2653 "failed to get setted form");
2655 torture_assert_int_equal(tctx, info.info1.size.width, add_info.info1->size.width, "width mismatch");
2658 if (!W_ERROR_EQUAL(expected_add_result, WERR_INVALID_PARAM)) {
2659 torture_assert(tctx,
2660 test_EnumForms_find_one(tctx, b, handle, print_server, form_name),
2661 "Newly added form not found in enum call");
2664 torture_assert(tctx,
2665 test_DeleteForm(tctx, b, handle, form_name, expected_delete_result),
2666 "failed to delete form");
2671 static bool test_Forms(struct torture_context *tctx,
2672 struct dcerpc_binding_handle *b,
2673 struct policy_handle *handle,
2675 const char *printer_name,
2676 struct dcerpc_binding_handle *winreg_handle,
2677 struct policy_handle *hive_handle)
2679 const struct spoolss_FormSize size = {
2683 const struct spoolss_FormArea area = {
2692 struct spoolss_AddFormInfo1 info1;
2693 WERROR expected_add_result;
2694 WERROR expected_delete_result;
2698 .flags = SPOOLSS_FORM_USER,
2699 .form_name = "testform_user",
2703 .expected_add_result = WERR_OK,
2704 .expected_delete_result = WERR_OK
2707 weird, we can add a builtin form but we can never remove it
2712 .flags = SPOOLSS_FORM_BUILTIN,
2713 .form_name = "testform_builtin",
2717 .expected_add_result = WERR_OK,
2718 .expected_delete_result = WERR_INVALID_PARAM,
2723 .flags = SPOOLSS_FORM_PRINTER,
2724 .form_name = "testform_printer",
2728 .expected_add_result = WERR_OK,
2729 .expected_delete_result = WERR_OK
2733 .flags = SPOOLSS_FORM_USER,
2734 .form_name = "Letter",
2738 .expected_add_result = WERR_FILE_EXISTS,
2739 .expected_delete_result = WERR_INVALID_PARAM
2743 .flags = SPOOLSS_FORM_BUILTIN,
2744 .form_name = "Letter",
2748 .expected_add_result = WERR_FILE_EXISTS,
2749 .expected_delete_result = WERR_INVALID_PARAM
2753 .flags = SPOOLSS_FORM_PRINTER,
2754 .form_name = "Letter",
2758 .expected_add_result = WERR_FILE_EXISTS,
2759 .expected_delete_result = WERR_INVALID_PARAM
2764 .form_name = "invalid_flags",
2768 .expected_add_result = WERR_INVALID_PARAM,
2769 .expected_delete_result = WERR_INVALID_FORM_NAME
2774 for (i=0; i < ARRAY_SIZE(forms); i++) {
2775 torture_assert(tctx,
2776 test_Forms_args(tctx, b, handle, print_server, printer_name,
2777 winreg_handle, hive_handle,
2778 forms[i].info1.form_name,
2780 forms[i].expected_add_result,
2781 forms[i].expected_delete_result),
2782 talloc_asprintf(tctx, "failed to test form '%s'", forms[i].info1.form_name));
2788 static bool test_EnumPorts_old(struct torture_context *tctx,
2789 struct dcerpc_pipe *p)
2792 struct spoolss_EnumPorts r;
2795 union spoolss_PortInfo *info;
2796 struct dcerpc_binding_handle *b = p->binding_handle;
2798 r.in.servername = talloc_asprintf(tctx, "\\\\%s",
2799 dcerpc_server_name(p));
2803 r.out.needed = &needed;
2804 r.out.count = &count;
2807 torture_comment(tctx, "Testing EnumPorts\n");
2809 status = dcerpc_spoolss_EnumPorts_r(b, tctx, &r);
2811 torture_assert_ntstatus_ok(tctx, status, "EnumPorts failed");
2813 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
2814 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
2815 r.in.buffer = &blob;
2816 r.in.offered = needed;
2818 status = dcerpc_spoolss_EnumPorts_r(b, tctx, &r);
2819 torture_assert_ntstatus_ok(tctx, status, "EnumPorts failed");
2820 torture_assert_werr_ok(tctx, r.out.result, "EnumPorts failed");
2822 torture_assert(tctx, info, "No ports returned");
2825 torture_assert_werr_ok(tctx, r.out.result, "EnumPorts failed");
2827 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPorts, info, 2, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
2832 static bool test_AddPort(struct torture_context *tctx,
2833 struct dcerpc_pipe *p)
2836 struct spoolss_AddPort r;
2837 struct dcerpc_binding_handle *b = p->binding_handle;
2839 r.in.server_name = talloc_asprintf(tctx, "\\\\%s",
2840 dcerpc_server_name(p));
2842 r.in.monitor_name = "foo";
2844 torture_comment(tctx, "Testing AddPort\n");
2846 status = dcerpc_spoolss_AddPort_r(b, tctx, &r);
2848 torture_assert_ntstatus_ok(tctx, status, "AddPort failed");
2850 /* win2k3 returns WERR_NOT_SUPPORTED */
2854 if (!W_ERROR_IS_OK(r.out.result)) {
2855 printf("AddPort failed - %s\n", win_errstr(r.out.result));
2864 static bool test_GetJob_args(struct torture_context *tctx,
2865 struct dcerpc_binding_handle *b,
2866 struct policy_handle *handle,
2869 union spoolss_JobInfo *info_p)
2872 struct spoolss_GetJob r;
2873 union spoolss_JobInfo info;
2876 r.in.handle = handle;
2877 r.in.job_id = job_id;
2881 r.out.needed = &needed;
2884 torture_comment(tctx, "Testing GetJob(%d), level %d\n", job_id, r.in.level);
2886 status = dcerpc_spoolss_GetJob_r(b, tctx, &r);
2887 torture_assert_ntstatus_ok(tctx, status, "GetJob failed");
2889 torture_assert_werr_equal(tctx, r.out.result, WERR_UNKNOWN_LEVEL, "Unexpected return code");
2892 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
2893 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
2894 r.in.buffer = &blob;
2895 r.in.offered = needed;
2897 status = dcerpc_spoolss_GetJob_r(b, tctx, &r);
2898 torture_assert_ntstatus_ok(tctx, status, "GetJob failed");
2901 torture_assert_werr_ok(tctx, r.out.result, "GetJob failed");
2902 torture_assert(tctx, r.out.info, "No job info returned");
2904 CHECK_NEEDED_SIZE_LEVEL(spoolss_JobInfo, r.out.info, r.in.level, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
2907 *info_p = *r.out.info;
2913 static bool test_GetJob(struct torture_context *tctx,
2914 struct dcerpc_binding_handle *b,
2915 struct policy_handle *handle,
2918 uint32_t levels[] = {0, 1, 2 /* 3, 4 */};
2921 for (i=0; i < ARRAY_SIZE(levels); i++) {
2922 torture_assert(tctx,
2923 test_GetJob_args(tctx, b, handle, job_id, levels[i], NULL),
2930 static bool test_SetJob(struct torture_context *tctx,
2931 struct dcerpc_binding_handle *b,
2932 struct policy_handle *handle, uint32_t job_id,
2933 enum spoolss_JobControl command)
2936 struct spoolss_SetJob r;
2938 r.in.handle = handle;
2939 r.in.job_id = job_id;
2941 r.in.command = command;
2944 case SPOOLSS_JOB_CONTROL_PAUSE:
2945 torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_PAUSE\n", job_id);
2947 case SPOOLSS_JOB_CONTROL_RESUME:
2948 torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_RESUME\n", job_id);
2950 case SPOOLSS_JOB_CONTROL_CANCEL:
2951 torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_CANCEL\n", job_id);
2953 case SPOOLSS_JOB_CONTROL_RESTART:
2954 torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_RESTART\n", job_id);
2956 case SPOOLSS_JOB_CONTROL_DELETE:
2957 torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_DELETE\n", job_id);
2959 case SPOOLSS_JOB_CONTROL_SEND_TO_PRINTER:
2960 torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_SEND_TO_PRINTER\n", job_id);
2962 case SPOOLSS_JOB_CONTROL_LAST_PAGE_EJECTED:
2963 torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_LAST_PAGE_EJECTED\n", job_id);
2965 case SPOOLSS_JOB_CONTROL_RETAIN:
2966 torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_RETAIN\n", job_id);
2968 case SPOOLSS_JOB_CONTROL_RELEASE:
2969 torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_RELEASE\n", job_id);
2972 torture_comment(tctx, "Testing SetJob(%d)\n", job_id);
2976 status = dcerpc_spoolss_SetJob_r(b, tctx, &r);
2977 torture_assert_ntstatus_ok(tctx, status, "SetJob failed");
2978 torture_assert_werr_ok(tctx, r.out.result, "SetJob failed");
2983 static bool test_AddJob(struct torture_context *tctx,
2984 struct dcerpc_binding_handle *b,
2985 struct policy_handle *handle)
2988 struct spoolss_AddJob r;
2992 r.in.handle = handle;
2994 r.out.needed = &needed;
2995 r.in.buffer = r.out.buffer = NULL;
2997 torture_comment(tctx, "Testing AddJob\n");
2999 status = dcerpc_spoolss_AddJob_r(b, tctx, &r);
3000 torture_assert_werr_equal(tctx, r.out.result, WERR_UNKNOWN_LEVEL, "AddJob failed");
3004 status = dcerpc_spoolss_AddJob_r(b, tctx, &r);
3005 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAM, "AddJob failed");
3011 static bool test_EnumJobs_args(struct torture_context *tctx,
3012 struct dcerpc_binding_handle *b,
3013 struct policy_handle *handle,
3016 union spoolss_JobInfo **info_p)
3019 struct spoolss_EnumJobs r;
3022 union spoolss_JobInfo *info;
3024 r.in.handle = handle;
3026 r.in.numjobs = 0xffffffff;
3030 r.out.needed = &needed;
3031 r.out.count = &count;
3034 torture_comment(tctx, "Testing EnumJobs level %d\n", level);
3036 status = dcerpc_spoolss_EnumJobs_r(b, tctx, &r);
3038 torture_assert_ntstatus_ok(tctx, status, "EnumJobs failed");
3040 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
3041 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
3042 r.in.buffer = &blob;
3043 r.in.offered = needed;
3045 status = dcerpc_spoolss_EnumJobs_r(b, tctx, &r);
3047 torture_assert_ntstatus_ok(tctx, status, "EnumJobs failed");
3048 torture_assert_werr_ok(tctx, r.out.result, "EnumJobs failed");
3049 torture_assert(tctx, info, "No jobs returned");
3051 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumJobs, *r.out.info, r.in.level, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
3054 torture_assert_werr_ok(tctx, r.out.result, "EnumJobs failed");
3067 static bool test_DoPrintTest_add_one_job(struct torture_context *tctx,
3068 struct dcerpc_binding_handle *b,
3069 struct policy_handle *handle,
3073 struct spoolss_StartDocPrinter s;
3074 struct spoolss_DocumentInfo1 info1;
3075 struct spoolss_StartPagePrinter sp;
3076 struct spoolss_WritePrinter w;
3077 struct spoolss_EndPagePrinter ep;
3078 struct spoolss_EndDocPrinter e;
3080 uint32_t num_written;
3082 torture_comment(tctx, "Testing StartDocPrinter\n");
3084 s.in.handle = handle;
3086 s.in.info.info1 = &info1;
3087 s.out.job_id = job_id;
3088 info1.document_name = "TorturePrintJob";
3089 info1.output_file = NULL;
3090 info1.datatype = "RAW";
3092 status = dcerpc_spoolss_StartDocPrinter_r(b, tctx, &s);
3093 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_StartDocPrinter failed");
3094 torture_assert_werr_ok(tctx, s.out.result, "StartDocPrinter failed");
3096 for (i=1; i < 4; i++) {
3097 torture_comment(tctx, "Testing StartPagePrinter: Page[%d], JobId[%d]\n", i, *job_id);
3099 sp.in.handle = handle;
3101 status = dcerpc_spoolss_StartPagePrinter_r(b, tctx, &sp);
3102 torture_assert_ntstatus_ok(tctx, status,
3103 "dcerpc_spoolss_StartPagePrinter failed");
3104 torture_assert_werr_ok(tctx, sp.out.result, "StartPagePrinter failed");
3106 torture_comment(tctx, "Testing WritePrinter: Page[%d], JobId[%d]\n", i, *job_id);
3108 w.in.handle = handle;
3109 w.in.data = data_blob_string_const(talloc_asprintf(tctx,"TortureTestPage: %d\nData\n",i));
3110 w.out.num_written = &num_written;
3112 status = dcerpc_spoolss_WritePrinter_r(b, tctx, &w);
3113 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_WritePrinter failed");
3114 torture_assert_werr_ok(tctx, w.out.result, "WritePrinter failed");
3116 torture_comment(tctx, "Testing EndPagePrinter: Page[%d], JobId[%d]\n", i, *job_id);
3118 ep.in.handle = handle;
3120 status = dcerpc_spoolss_EndPagePrinter_r(b, tctx, &ep);
3121 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EndPagePrinter failed");
3122 torture_assert_werr_ok(tctx, ep.out.result, "EndPagePrinter failed");
3125 torture_comment(tctx, "Testing EndDocPrinter: JobId[%d]\n", *job_id);
3127 e.in.handle = handle;
3129 status = dcerpc_spoolss_EndDocPrinter_r(b, tctx, &e);
3130 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EndDocPrinter failed");
3131 torture_assert_werr_ok(tctx, e.out.result, "EndDocPrinter failed");
3136 static bool test_DoPrintTest_check_jobs(struct torture_context *tctx,
3137 struct dcerpc_binding_handle *b,
3138 struct policy_handle *handle,
3143 union spoolss_JobInfo *info = NULL;
3146 torture_assert(tctx,
3147 test_AddJob(tctx, b, handle),
3150 torture_assert(tctx,
3151 test_EnumJobs_args(tctx, b, handle, 1, &count, &info),
3152 "EnumJobs level 1 failed");
3154 torture_assert_int_equal(tctx, count, num_jobs, "unexpected number of jobs in queue");
3156 for (i=0; i < num_jobs; i++) {
3157 union spoolss_JobInfo ginfo;
3159 torture_assert_int_equal(tctx, info[i].info1.job_id, job_ids[i], "job id mismatch");
3161 torture_assert(tctx,
3162 test_GetJob_args(tctx, b, handle, info[i].info1.job_id, 1, &ginfo),
3163 "failed to call test_GetJob");
3165 torture_assert_int_equal(tctx, ginfo.info1.job_id, info[i].info1.job_id, "job id mismatch");
3168 for (i=0; i < num_jobs; i++) {
3169 torture_assert(tctx,
3170 test_SetJob(tctx, b, handle, info[i].info1.job_id, SPOOLSS_JOB_CONTROL_PAUSE),
3171 "failed to pause printjob");
3172 torture_assert(tctx,
3173 test_SetJob(tctx, b, handle, info[i].info1.job_id, SPOOLSS_JOB_CONTROL_RESUME),
3174 "failed to resume printjob");
3180 static bool test_DoPrintTest(struct torture_context *tctx,
3181 struct dcerpc_binding_handle *b,
3182 struct policy_handle *handle)
3185 uint32_t num_jobs = 8;
3189 job_ids = talloc_zero_array(tctx, uint32_t, num_jobs);
3191 for (i=0; i < num_jobs; i++) {
3192 ret &= test_DoPrintTest_add_one_job(tctx, b, handle, &job_ids[i]);
3195 ret &= test_DoPrintTest_check_jobs(tctx, b, handle, num_jobs, job_ids);
3197 for (i=0; i < num_jobs; i++) {
3198 ret &= test_SetJob(tctx, b, handle, job_ids[i], SPOOLSS_JOB_CONTROL_DELETE);
3204 static bool test_PausePrinter(struct torture_context *tctx,
3205 struct dcerpc_binding_handle *b,
3206 struct policy_handle *handle)
3209 struct spoolss_SetPrinter r;
3210 struct spoolss_SetPrinterInfoCtr info_ctr;
3211 struct spoolss_DevmodeContainer devmode_ctr;
3212 struct sec_desc_buf secdesc_ctr;
3215 info_ctr.info.info0 = NULL;
3217 ZERO_STRUCT(devmode_ctr);
3218 ZERO_STRUCT(secdesc_ctr);
3220 r.in.handle = handle;
3221 r.in.info_ctr = &info_ctr;
3222 r.in.devmode_ctr = &devmode_ctr;
3223 r.in.secdesc_ctr = &secdesc_ctr;
3224 r.in.command = SPOOLSS_PRINTER_CONTROL_PAUSE;
3226 torture_comment(tctx, "Testing SetPrinter: SPOOLSS_PRINTER_CONTROL_PAUSE\n");
3228 status = dcerpc_spoolss_SetPrinter_r(b, tctx, &r);
3230 torture_assert_ntstatus_ok(tctx, status, "SetPrinter failed");
3232 torture_assert_werr_ok(tctx, r.out.result, "SetPrinter failed");
3237 static bool test_ResumePrinter(struct torture_context *tctx,
3238 struct dcerpc_binding_handle *b,
3239 struct policy_handle *handle)
3242 struct spoolss_SetPrinter r;
3243 struct spoolss_SetPrinterInfoCtr info_ctr;
3244 struct spoolss_DevmodeContainer devmode_ctr;
3245 struct sec_desc_buf secdesc_ctr;
3248 info_ctr.info.info0 = NULL;
3250 ZERO_STRUCT(devmode_ctr);
3251 ZERO_STRUCT(secdesc_ctr);
3253 r.in.handle = handle;
3254 r.in.info_ctr = &info_ctr;
3255 r.in.devmode_ctr = &devmode_ctr;
3256 r.in.secdesc_ctr = &secdesc_ctr;
3257 r.in.command = SPOOLSS_PRINTER_CONTROL_RESUME;
3259 torture_comment(tctx, "Testing SetPrinter: SPOOLSS_PRINTER_CONTROL_RESUME\n");
3261 status = dcerpc_spoolss_SetPrinter_r(b, tctx, &r);
3263 torture_assert_ntstatus_ok(tctx, status, "SetPrinter failed");
3265 torture_assert_werr_ok(tctx, r.out.result, "SetPrinter failed");
3270 static bool test_GetPrinterData(struct torture_context *tctx,
3271 struct dcerpc_binding_handle *b,
3272 struct policy_handle *handle,
3273 const char *value_name,
3274 enum winreg_Type *type_p,
3279 struct spoolss_GetPrinterData r;
3281 enum winreg_Type type;
3282 union spoolss_PrinterData data;
3284 r.in.handle = handle;
3285 r.in.value_name = value_name;
3287 r.out.needed = &needed;
3289 r.out.data = talloc_zero_array(tctx, uint8_t, r.in.offered);
3291 torture_comment(tctx, "Testing GetPrinterData(%s)\n", r.in.value_name);
3293 status = dcerpc_spoolss_GetPrinterData_r(b, tctx, &r);
3294 torture_assert_ntstatus_ok(tctx, status, "GetPrinterData failed");
3296 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
3297 r.in.offered = needed;
3298 r.out.data = talloc_zero_array(tctx, uint8_t, r.in.offered);
3299 status = dcerpc_spoolss_GetPrinterData_r(b, tctx, &r);
3300 torture_assert_ntstatus_ok(tctx, status, "GetPrinterData failed");
3303 torture_assert_werr_ok(tctx, r.out.result,
3304 talloc_asprintf(tctx, "GetPrinterData(%s) failed", r.in.value_name));
3306 CHECK_NEEDED_SIZE_LEVEL(spoolss_PrinterData, &data, type, lp_iconv_convenience(tctx->lp_ctx), needed, 1);
3313 *data_p = r.out.data;
3323 static bool test_GetPrinterDataEx(struct torture_context *tctx,
3324 struct dcerpc_pipe *p,
3325 struct policy_handle *handle,
3326 const char *key_name,
3327 const char *value_name,
3328 enum winreg_Type *type_p,
3333 struct spoolss_GetPrinterDataEx r;
3334 enum winreg_Type type;
3336 union spoolss_PrinterData data;
3337 struct dcerpc_binding_handle *b = p->binding_handle;
3339 r.in.handle = handle;
3340 r.in.key_name = key_name;
3341 r.in.value_name = value_name;
3344 r.out.needed = &needed;
3345 r.out.data = talloc_zero_array(tctx, uint8_t, r.in.offered);
3347 torture_comment(tctx, "Testing GetPrinterDataEx(%s - %s)\n",
3348 r.in.key_name, r.in.value_name);
3350 status = dcerpc_spoolss_GetPrinterDataEx_r(b, tctx, &r);
3351 if (!NT_STATUS_IS_OK(status)) {
3352 if (NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROCNUM_OUT_OF_RANGE)) {
3353 torture_skip(tctx, "GetPrinterDataEx not supported by server\n");
3355 torture_assert_ntstatus_ok(tctx, status, "GetPrinterDataEx failed");
3358 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
3359 r.in.offered = needed;
3360 r.out.data = talloc_zero_array(tctx, uint8_t, r.in.offered);
3361 status = dcerpc_spoolss_GetPrinterDataEx_r(b, tctx, &r);
3362 torture_assert_ntstatus_ok(tctx, status, "GetPrinterDataEx failed");
3365 torture_assert_werr_ok(tctx, r.out.result,
3366 talloc_asprintf(tctx, "GetPrinterDataEx(%s - %s) failed", r.in.key_name, r.in.value_name));
3368 CHECK_NEEDED_SIZE_LEVEL(spoolss_PrinterData, &data, type, lp_iconv_convenience(tctx->lp_ctx), needed, 1);
3375 *data_p = r.out.data;
3385 static bool test_get_environment(struct torture_context *tctx,
3386 struct dcerpc_binding_handle *b,
3387 struct policy_handle *handle,
3388 const char **architecture)
3391 enum winreg_Type type;
3395 torture_assert(tctx,
3396 test_GetPrinterData(tctx, b, handle, "Architecture", &type, &data, &needed),
3397 "failed to get Architecture");
3399 torture_assert_int_equal(tctx, type, REG_SZ, "unexpected type");
3401 blob = data_blob_const(data, needed);
3402 *architecture = reg_val_data_string(tctx, lp_iconv_convenience(tctx->lp_ctx), REG_SZ, blob);
3407 static bool test_GetPrinterData_list(struct torture_context *tctx,
3408 struct dcerpc_pipe *p,
3409 struct policy_handle *handle,
3410 const char **architecture)
3412 struct dcerpc_binding_handle *b = p->binding_handle;
3413 const char *list[] = {
3417 /* "NetPopup", not on w2k8 */
3418 /* "NetPopupToComputer", not on w2k8 */
3421 "DefaultSpoolDirectory",
3425 /* "OSVersionEx", not on s3 */
3430 for (i=0; i < ARRAY_SIZE(list); i++) {
3431 enum winreg_Type type, type_ex;
3432 uint8_t *data, *data_ex;
3433 uint32_t needed, needed_ex;
3435 torture_assert(tctx, test_GetPrinterData(tctx, b, handle, list[i], &type, &data, &needed),
3436 talloc_asprintf(tctx, "GetPrinterData failed on %s\n", list[i]));
3437 torture_assert(tctx, test_GetPrinterDataEx(tctx, p, handle, "random_string", list[i], &type_ex, &data_ex, &needed_ex),
3438 talloc_asprintf(tctx, "GetPrinterDataEx failed on %s\n", list[i]));
3439 torture_assert_int_equal(tctx, type, type_ex, "type mismatch");
3440 torture_assert_int_equal(tctx, needed, needed_ex, "needed mismatch");
3441 torture_assert_mem_equal(tctx, data, data_ex, needed, "data mismatch");
3443 if (strequal(list[i], "Architecture")) {
3445 DATA_BLOB blob = data_blob_const(data, needed);
3446 *architecture = reg_val_data_string(tctx, lp_iconv_convenience(tctx->lp_ctx), REG_SZ, blob);
3454 static bool test_EnumPrinterData(struct torture_context *tctx,
3455 struct dcerpc_pipe *p,
3456 struct policy_handle *handle,
3457 uint32_t enum_index,
3458 uint32_t value_offered,
3459 uint32_t data_offered,
3460 enum winreg_Type *type_p,
3461 uint32_t *value_needed_p,
3462 uint32_t *data_needed_p,
3463 const char **value_name_p,
3467 struct spoolss_EnumPrinterData r;
3468 uint32_t data_needed;
3469 uint32_t value_needed;
3470 enum winreg_Type type;
3471 struct dcerpc_binding_handle *b = p->binding_handle;
3473 r.in.handle = handle;
3474 r.in.enum_index = enum_index;
3475 r.in.value_offered = value_offered;
3476 r.in.data_offered = data_offered;
3477 r.out.data_needed = &data_needed;
3478 r.out.value_needed = &value_needed;
3480 r.out.data = talloc_zero_array(tctx, uint8_t, r.in.data_offered);
3481 r.out.value_name = talloc_zero_array(tctx, const char, r.in.value_offered);
3483 torture_comment(tctx, "Testing EnumPrinterData(%d)\n", enum_index);
3485 torture_assert_ntstatus_ok(tctx,
3486 dcerpc_spoolss_EnumPrinterData_r(b, tctx, &r),
3487 "EnumPrinterData failed");
3492 if (value_needed_p) {
3493 *value_needed_p = value_needed;
3495 if (data_needed_p) {
3496 *data_needed_p = data_needed;
3499 *value_name_p = r.out.value_name;
3502 *data_p = r.out.data;
3505 *result_p = r.out.result;
3512 static bool test_EnumPrinterData_all(struct torture_context *tctx,
3513 struct dcerpc_pipe *p,
3514 struct policy_handle *handle)
3516 uint32_t enum_index = 0;
3517 enum winreg_Type type;
3518 uint32_t value_needed;
3519 uint32_t data_needed;
3521 const char *value_name;
3524 torture_comment(tctx, "Testing EnumPrinterData\n");
3527 torture_assert(tctx,
3528 test_EnumPrinterData(tctx, p, handle, enum_index, 0, 0,
3529 &type, &value_needed, &data_needed,
3530 &value_name, &data, &result),
3531 "EnumPrinterData failed");
3533 if (W_ERROR_EQUAL(result, WERR_NO_MORE_ITEMS)) {
3537 torture_assert(tctx,
3538 test_EnumPrinterData(tctx, p, handle, enum_index, value_needed, data_needed,
3539 &type, &value_needed, &data_needed,
3540 &value_name, &data, &result),
3541 "EnumPrinterData failed");
3543 if (W_ERROR_EQUAL(result, WERR_NO_MORE_ITEMS)) {
3549 } while (W_ERROR_IS_OK(result));
3551 torture_comment(tctx, "EnumPrinterData test succeeded\n");
3556 static bool test_EnumPrinterDataEx(struct torture_context *tctx,
3557 struct dcerpc_binding_handle *b,
3558 struct policy_handle *handle,
3559 const char *key_name,
3561 struct spoolss_PrinterEnumValues **info_p)
3563 struct spoolss_EnumPrinterDataEx r;
3564 struct spoolss_PrinterEnumValues *info;
3568 r.in.handle = handle;
3569 r.in.key_name = key_name;
3571 r.out.needed = &needed;
3572 r.out.count = &count;
3575 torture_comment(tctx, "Testing EnumPrinterDataEx(%s)\n", key_name);
3577 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinterDataEx_r(b, tctx, &r),
3578 "EnumPrinterDataEx failed");
3579 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
3580 r.in.offered = needed;
3581 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinterDataEx_r(b, tctx, &r),
3582 "EnumPrinterDataEx failed");
3585 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinterDataEx failed");
3587 CHECK_NEEDED_SIZE_ENUM(spoolss_EnumPrinterDataEx, info, count, lp_iconv_convenience(tctx->lp_ctx), needed, 1);
3599 static bool test_SetPrinterData(struct torture_context *tctx,
3600 struct dcerpc_binding_handle *b,
3601 struct policy_handle *handle,
3602 const char *value_name,
3603 enum winreg_Type type,
3606 static bool test_DeletePrinterData(struct torture_context *tctx,
3607 struct dcerpc_binding_handle *b,
3608 struct policy_handle *handle,
3609 const char *value_name);
3611 static bool test_EnumPrinterData_consistency(struct torture_context *tctx,
3612 struct dcerpc_pipe *p,
3613 struct policy_handle *handle)
3616 struct spoolss_PrinterEnumValues *info;
3618 uint32_t value_needed, data_needed;
3619 uint32_t value_offered, data_offered;
3621 struct dcerpc_binding_handle *b = p->binding_handle;
3623 enum winreg_Type type;
3626 torture_comment(tctx, "Testing EnumPrinterData vs EnumPrinterDataEx consistency\n");
3628 torture_assert(tctx,
3629 reg_string_to_val(tctx, lp_iconv_convenience(tctx->lp_ctx),
3630 "REG_SZ", "torture_data1", &type, &blob), "");
3632 torture_assert(tctx,
3633 test_SetPrinterData(tctx, b, handle, "torture_value1", type, blob.data, blob.length),
3634 "SetPrinterData failed");
3636 blob = data_blob_string_const("torture_data2");
3638 torture_assert(tctx,
3639 test_SetPrinterData(tctx, b, handle, "torture_value2", REG_BINARY, blob.data, blob.length),
3640 "SetPrinterData failed");
3642 blob = data_blob_talloc(tctx, NULL, 4);
3643 SIVAL(blob.data, 0, 0x11223344);
3645 torture_assert(tctx,
3646 test_SetPrinterData(tctx, b, handle, "torture_value3", type, blob.data, blob.length),
3647 "SetPrinterData failed");
3649 torture_assert(tctx,
3650 test_EnumPrinterDataEx(tctx, b, handle, "PrinterDriverData", &count, &info),
3651 "failed to call EnumPrinterDataEx");
3653 /* get the max sizes for value and data */
3655 torture_assert(tctx,
3656 test_EnumPrinterData(tctx, p, handle, 0, 0, 0,
3657 NULL, &value_needed, &data_needed,
3658 NULL, NULL, &result),
3659 "EnumPrinterData failed");
3660 torture_assert_werr_ok(tctx, result, "unexpected result");
3662 /* check if the reply from the EnumPrinterData really matches max values */
3664 for (i=0; i < count; i++) {
3665 if (info[i].value_name_len > value_needed) {
3667 talloc_asprintf(tctx,
3668 "EnumPrinterDataEx gave a reply with value length %d which is larger then expected max value length %d from EnumPrinterData",
3669 info[i].value_name_len, value_needed));
3671 if (info[i].data_length > data_needed) {
3673 talloc_asprintf(tctx,
3674 "EnumPrinterDataEx gave a reply with data length %d which is larger then expected max data length %d from EnumPrinterData",
3675 info[i].data_length, data_needed));
3679 /* assuming that both EnumPrinterData and EnumPrinterDataEx do either
3680 * sort or not sort the replies by value name, we should be able to do
3681 * the following entry comparison */
3683 data_offered = data_needed;
3684 value_offered = value_needed;
3686 for (i=0; i < count; i++) {
3688 const char *value_name;
3691 torture_assert(tctx,
3692 test_EnumPrinterData(tctx, p, handle, i, value_offered, data_offered,
3693 &type, &value_needed, &data_needed,
3694 &value_name, &data, &result),
3695 "EnumPrinterData failed");
3697 if (i -1 == count) {
3698 torture_assert_werr_equal(tctx, result, WERR_NO_MORE_ITEMS,
3699 "unexpected result");
3702 torture_assert_werr_ok(tctx, result, "unexpected result");
3705 torture_assert_int_equal(tctx, type, info[i].type, "type mismatch");
3706 torture_assert_int_equal(tctx, value_needed, info[i].value_name_len, "value name length mismatch");
3707 torture_assert_str_equal(tctx, value_name, info[i].value_name, "value name mismatch");
3708 torture_assert_int_equal(tctx, data_needed, info[i].data_length, "data length mismatch");
3709 torture_assert_mem_equal(tctx, data, info[i].data->data, info[i].data_length, "data mismatch");
3712 torture_assert(tctx,
3713 test_DeletePrinterData(tctx, b, handle, "torture_value1"),
3714 "DeletePrinterData failed");
3715 torture_assert(tctx,
3716 test_DeletePrinterData(tctx, b, handle, "torture_value2"),
3717 "DeletePrinterData failed");
3718 torture_assert(tctx,
3719 test_DeletePrinterData(tctx, b, handle, "torture_value3"),
3720 "DeletePrinterData failed");
3722 torture_comment(tctx, "EnumPrinterData vs EnumPrinterDataEx consistency test succeeded\n\n");
3727 static bool test_DeletePrinterData(struct torture_context *tctx,
3728 struct dcerpc_binding_handle *b,
3729 struct policy_handle *handle,
3730 const char *value_name)
3733 struct spoolss_DeletePrinterData r;
3735 r.in.handle = handle;
3736 r.in.value_name = value_name;
3738 torture_comment(tctx, "Testing DeletePrinterData(%s)\n",
3741 status = dcerpc_spoolss_DeletePrinterData_r(b, tctx, &r);
3743 torture_assert_ntstatus_ok(tctx, status, "DeletePrinterData failed");
3744 torture_assert_werr_ok(tctx, r.out.result, "DeletePrinterData failed");
3749 static bool test_DeletePrinterDataEx(struct torture_context *tctx,
3750 struct dcerpc_binding_handle *b,
3751 struct policy_handle *handle,
3752 const char *key_name,
3753 const char *value_name)
3755 struct spoolss_DeletePrinterDataEx r;
3757 r.in.handle = handle;
3758 r.in.key_name = key_name;
3759 r.in.value_name = value_name;
3761 torture_comment(tctx, "Testing DeletePrinterDataEx(%s - %s)\n",
3762 r.in.key_name, r.in.value_name);
3764 torture_assert_ntstatus_ok(tctx,
3765 dcerpc_spoolss_DeletePrinterDataEx_r(b, tctx, &r),
3766 "DeletePrinterDataEx failed");
3767 torture_assert_werr_ok(tctx, r.out.result,
3768 "DeletePrinterDataEx failed");
3773 static bool test_DeletePrinterKey(struct torture_context *tctx,
3774 struct dcerpc_binding_handle *b,
3775 struct policy_handle *handle,
3776 const char *key_name)
3778 struct spoolss_DeletePrinterKey r;
3780 r.in.handle = handle;
3781 r.in.key_name = key_name;
3783 torture_comment(tctx, "Testing DeletePrinterKey(%s)\n", r.in.key_name);
3785 if (strequal(key_name, "") && !torture_setting_bool(tctx, "dangerous", false)) {
3786 torture_skip(tctx, "not wiping out printer registry - enable dangerous tests to use\n");
3790 torture_assert_ntstatus_ok(tctx,
3791 dcerpc_spoolss_DeletePrinterKey_r(b, tctx, &r),
3792 "DeletePrinterKey failed");
3793 torture_assert_werr_ok(tctx, r.out.result,
3794 "DeletePrinterKey failed");
3799 static bool test_winreg_OpenHKLM(struct torture_context *tctx,
3800 struct dcerpc_binding_handle *b,
3801 struct policy_handle *handle)
3803 struct winreg_OpenHKLM r;
3805 r.in.system_name = NULL;
3806 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3807 r.out.handle = handle;
3809 torture_comment(tctx, "Testing winreg_OpenHKLM\n");
3811 torture_assert_ntstatus_ok(tctx, dcerpc_winreg_OpenHKLM_r(b, tctx, &r), "OpenHKLM failed");
3812 torture_assert_werr_ok(tctx, r.out.result, "OpenHKLM failed");
3817 static void init_winreg_String(struct winreg_String *name, const char *s)
3821 name->name_len = 2 * (strlen_m(s) + 1);
3822 name->name_size = name->name_len;
3825 name->name_size = 0;
3829 static bool test_winreg_OpenKey_opts(struct torture_context *tctx,
3830 struct dcerpc_binding_handle *b,
3831 struct policy_handle *hive_handle,
3832 const char *keyname,
3834 struct policy_handle *key_handle)
3836 struct winreg_OpenKey r;
3838 r.in.parent_handle = hive_handle;
3839 init_winreg_String(&r.in.keyname, keyname);
3840 r.in.options = options;
3841 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3842 r.out.handle = key_handle;
3844 torture_comment(tctx, "Testing winreg_OpenKey(%s)\n", keyname);
3846 torture_assert_ntstatus_ok(tctx, dcerpc_winreg_OpenKey_r(b, tctx, &r), "OpenKey failed");
3847 torture_assert_werr_ok(tctx, r.out.result, "OpenKey failed");
3852 static bool test_winreg_OpenKey(struct torture_context *tctx,
3853 struct dcerpc_binding_handle *b,
3854 struct policy_handle *hive_handle,
3855 const char *keyname,
3856 struct policy_handle *key_handle)
3858 return test_winreg_OpenKey_opts(tctx, b, hive_handle, keyname,
3859 REG_OPTION_NON_VOLATILE, key_handle);
3862 static bool test_winreg_CloseKey(struct torture_context *tctx,
3863 struct dcerpc_binding_handle *b,
3864 struct policy_handle *handle)
3866 struct winreg_CloseKey r;
3868 r.in.handle = handle;
3869 r.out.handle = handle;
3871 torture_comment(tctx, "Testing winreg_CloseKey\n");
3873 torture_assert_ntstatus_ok(tctx, dcerpc_winreg_CloseKey_r(b, tctx, &r), "CloseKey failed");
3874 torture_assert_werr_ok(tctx, r.out.result, "CloseKey failed");
3879 bool test_winreg_QueryValue(struct torture_context *tctx,
3880 struct dcerpc_binding_handle *b,
3881 struct policy_handle *handle,
3882 const char *value_name,
3883 enum winreg_Type *type_p,
3884 uint32_t *data_size_p,
3885 uint32_t *data_length_p,
3888 struct winreg_QueryValue r;
3889 enum winreg_Type type = REG_NONE;
3890 uint32_t data_size = 0;
3891 uint32_t data_length = 0;
3892 struct winreg_String valuename;
3893 uint8_t *data = NULL;
3895 init_winreg_String(&valuename, value_name);
3897 data = talloc_zero_array(tctx, uint8_t, 0);
3899 r.in.handle = handle;
3900 r.in.value_name = &valuename;
3902 r.in.data_size = &data_size;
3903 r.in.data_length = &data_length;
3907 r.out.data_size = &data_size;
3908 r.out.data_length = &data_length;
3910 torture_comment(tctx, "Testing winreg_QueryValue(%s)\n", value_name);
3912 torture_assert_ntstatus_ok(tctx, dcerpc_winreg_QueryValue_r(b, tctx, &r), "QueryValue failed");
3913 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
3914 *r.in.data_size = *r.out.data_size;
3915 data = talloc_zero_array(tctx, uint8_t, *r.in.data_size);
3918 torture_assert_ntstatus_ok(tctx, dcerpc_winreg_QueryValue_r(b, tctx, &r), "QueryValue failed");
3920 torture_assert_werr_ok(tctx, r.out.result, "QueryValue failed");
3923 *type_p = *r.out.type;
3926 *data_size_p = *r.out.data_size;
3928 if (data_length_p) {
3929 *data_length_p = *r.out.data_length;
3932 *data_p = r.out.data;
3938 static bool test_winreg_query_printerdata(struct torture_context *tctx,
3939 struct dcerpc_binding_handle *b,
3940 struct policy_handle *handle,
3941 const char *printer_name,
3942 const char *key_name,
3943 const char *value_name,
3944 enum winreg_Type *w_type,
3949 const char *printer_key;
3950 struct policy_handle key_handle;
3952 printer_key = talloc_asprintf(tctx, "%s\\%s\\%s",
3953 TOP_LEVEL_PRINT_PRINTERS_KEY, printer_name, key_name);
3955 torture_assert(tctx,
3956 test_winreg_OpenKey(tctx, b, handle, printer_key, &key_handle), "");
3958 torture_assert(tctx,
3959 test_winreg_QueryValue(tctx, b, &key_handle, value_name, w_type, w_size, w_length, w_data), "");
3961 torture_assert(tctx,
3962 test_winreg_CloseKey(tctx, b, &key_handle), "");
3967 static bool test_GetForm_winreg(struct torture_context *tctx,
3968 struct dcerpc_binding_handle *b,
3969 struct policy_handle *handle,
3970 const char *key_name,
3971 const char *form_name,
3972 enum winreg_Type *w_type,
3977 struct policy_handle key_handle;
3979 torture_assert(tctx,
3980 test_winreg_OpenKey(tctx, b, handle, key_name, &key_handle), "");
3982 torture_assert(tctx,
3983 test_winreg_QueryValue(tctx, b, &key_handle, form_name, w_type, w_size, w_length, w_data), "");
3985 torture_assert(tctx,
3986 test_winreg_CloseKey(tctx, b, &key_handle), "");
3991 static bool test_winreg_symbolic_link(struct torture_context *tctx,
3992 struct dcerpc_binding_handle *b,
3993 struct policy_handle *handle,
3994 const char *symlink_keyname,
3995 const char *symlink_destination)
3997 /* check if the first key is a symlink to the second key */
3999 enum winreg_Type w_type;
4003 struct policy_handle key_handle;
4007 if (torture_setting_bool(tctx, "samba3", false)) {
4008 torture_skip(tctx, "skip winreg symlink test against samba");
4011 torture_assert(tctx,
4012 test_winreg_OpenKey_opts(tctx, b, handle, symlink_keyname, REG_OPTION_OPEN_LINK, &key_handle),
4013 "failed to open key link");
4015 torture_assert(tctx,
4016 test_winreg_QueryValue(tctx, b, &key_handle,
4017 "SymbolicLinkValue",
4018 &w_type, &w_size, &w_length, &w_data),
4019 "failed to query for 'SymbolicLinkValue' attribute");
4021 torture_assert_int_equal(tctx, w_type, REG_LINK, "unexpected type");
4023 blob = data_blob(w_data, w_size);
4024 str = reg_val_data_string(tctx, lp_iconv_convenience(tctx->lp_ctx), REG_SZ, blob);
4026 torture_assert_str_equal(tctx, str, symlink_destination, "unexpected symlink target string");
4028 torture_assert(tctx,
4029 test_winreg_CloseKey(tctx, b, &key_handle),
4030 "failed to close key link");
4035 static const char *strip_unc(const char *unc)
4043 if (unc[0] == '\\' && unc[1] == '\\') {
4047 name = strchr(unc, '\\');
4055 static bool test_GetPrinterInfo_winreg(struct torture_context *tctx,
4056 struct dcerpc_binding_handle *b,
4057 struct policy_handle *handle,
4058 const char *printer_name,
4059 struct dcerpc_binding_handle *winreg_handle,
4060 struct policy_handle *hive_handle)
4062 union spoolss_PrinterInfo info;
4063 const char *keys[] = {
4064 TOP_LEVEL_CONTROL_PRINTERS_KEY,
4065 TOP_LEVEL_PRINT_PRINTERS_KEY
4068 const char *printername, *sharename;
4070 torture_comment(tctx, "Testing Printer Info and winreg consistency\n");
4072 torture_assert(tctx,
4073 test_GetPrinter_level(tctx, b, handle, 2, &info),
4074 "failed to get printer info level 2");
4076 printername = strip_unc(info.info2.printername);
4077 sharename = strip_unc(info.info2.sharename);
4079 #define test_sz(wname, iname) \
4083 enum winreg_Type w_type;\
4087 torture_assert(tctx,\
4088 test_winreg_QueryValue(tctx, winreg_handle, &key_handle, wname,\
4089 &w_type, &w_size, &w_length, &w_data),\
4090 "failed to query winreg");\
4091 torture_assert_int_equal(tctx, w_type, REG_SZ, "unexpected type");\
4092 blob = data_blob(w_data, w_size);\
4093 str = reg_val_data_string(tctx, lp_iconv_convenience(tctx->lp_ctx), REG_SZ, blob);\
4094 if (w_size == 2 && iname == NULL) {\
4095 /*torture_comment(tctx, "%s: \"\", %s: (null)\n", #wname, #iname);\ */\
4097 torture_assert_str_equal(tctx, str, iname,\
4098 talloc_asprintf(tctx, "%s - %s mismatch", #wname, #iname));\
4102 #define test_dword(wname, iname) \
4105 enum winreg_Type w_type;\
4109 torture_assert(tctx,\
4110 test_winreg_QueryValue(tctx, winreg_handle, &key_handle, wname,\
4111 &w_type, &w_size, &w_length, &w_data),\
4112 "failed to query winreg");\
4113 torture_assert_int_equal(tctx, w_type, REG_DWORD, "unexpected type");\
4114 torture_assert_int_equal(tctx, w_size, 4, "unexpected size");\
4115 torture_assert_int_equal(tctx, w_length, 4, "unexpected length");\
4116 value = IVAL(w_data, 0);\
4117 torture_assert_int_equal(tctx, value, iname,\
4118 talloc_asprintf(tctx, "%s - %s mismatch", #wname, #iname));\
4121 #define test_dm(wname, iname) \
4124 struct spoolss_DeviceMode dm;\
4125 enum ndr_err_code ndr_err;\
4126 enum winreg_Type w_type;\
4130 torture_assert(tctx,\
4131 test_winreg_QueryValue(tctx, winreg_handle, &key_handle, wname,\
4132 &w_type, &w_size, &w_length, &w_data),\
4133 "failed to query winreg");\
4134 torture_assert_int_equal(tctx, w_type, REG_BINARY, "unexpected type");\
4135 blob = data_blob(w_data, w_size);\
4136 ndr_err = ndr_pull_struct_blob(&blob, tctx, lp_iconv_convenience(tctx->lp_ctx), &dm,\
4137 (ndr_pull_flags_fn_t)ndr_pull_spoolss_DeviceMode);\
4138 torture_assert_ndr_success(tctx, ndr_err, "failed to unmarshall dm");\
4139 torture_assert(tctx, test_devicemode_equal(tctx, &dm, iname),\
4143 #define test_sd(wname, iname) \
4146 struct security_descriptor sd;\
4147 enum ndr_err_code ndr_err;\
4148 enum winreg_Type w_type;\
4152 torture_assert(tctx,\
4153 test_winreg_QueryValue(tctx, winreg_handle, &key_handle, wname,\
4154 &w_type, &w_size, &w_length, &w_data),\
4155 "failed to query winreg");\
4156 torture_assert_int_equal(tctx, w_type, REG_BINARY, "unexpected type");\
4157 blob = data_blob(w_data, w_size);\
4158 ndr_err = ndr_pull_struct_blob(&blob, tctx, lp_iconv_convenience(tctx->lp_ctx), &sd,\
4159 (ndr_pull_flags_fn_t)ndr_pull_security_descriptor);\
4160 torture_assert_ndr_success(tctx, ndr_err, "failed to unmarshall sd");\
4161 torture_assert(tctx, test_security_descriptor_equal(tctx, &sd, iname),\
4165 #define test_multi_sz(wname, iname) \
4168 const char **array;\
4169 enum winreg_Type w_type;\
4174 torture_assert(tctx,\
4175 test_winreg_QueryValue(tctx, winreg_handle, &key_handle, wname,\
4176 &w_type, &w_size, &w_length, &w_data),\
4177 "failed to query winreg");\
4178 torture_assert_int_equal(tctx, w_type, REG_MULTI_SZ, "unexpected type");\
4179 blob = data_blob(w_data, w_size);\
4180 torture_assert(tctx, \
4181 pull_reg_multi_sz(tctx, lp_iconv_convenience(tctx->lp_ctx), &blob, &array),\
4182 "failed to pull multi sz");\
4183 for (i=0; array[i] != NULL; i++) {\
4184 torture_assert_str_equal(tctx, array[i], iname[i],\
4185 talloc_asprintf(tctx, "%s - %s mismatch", #wname, iname[i]));\
4190 if (!test_winreg_symbolic_link(tctx, winreg_handle, hive_handle,
4191 TOP_LEVEL_CONTROL_PRINTERS_KEY,
4192 "\\Registry\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Print\\Printers"))
4194 torture_warning(tctx, "failed to check for winreg symlink");
4198 for (i=0; i < ARRAY_SIZE(keys); i++) {
4200 const char *printer_key;
4201 struct policy_handle key_handle;
4203 printer_key = talloc_asprintf(tctx, "%s\\%s",
4204 keys[i], printer_name);
4206 torture_assert(tctx,
4207 test_winreg_OpenKey(tctx, winreg_handle, hive_handle, printer_key, &key_handle), "");
4209 test_sz("Name", printername);
4210 test_sz("Share Name", sharename);
4211 test_sz("Port", info.info2.portname);
4212 test_sz("Printer Driver", info.info2.drivername);
4213 test_sz("Description", info.info2.comment);
4214 test_sz("Location", info.info2.location);
4215 test_sz("Separator File", info.info2.sepfile);
4216 test_sz("Print Processor", info.info2.printprocessor);
4217 test_sz("Datatype", info.info2.datatype);
4218 test_sz("Parameters", info.info2.parameters);
4219 /* winreg: 0, spoolss not */
4220 /* test_dword("Attributes", info.info2.attributes); */
4221 test_dword("Priority", info.info2.priority);
4222 test_dword("Default Priority", info.info2.defaultpriority);
4223 /* winreg: 60, spoolss: 0 */
4224 /* test_dword("StartTime", info.info2.starttime); */
4225 /* test_dword("UntilTime", info.info2.untiltime); */
4226 /* winreg != spoolss */
4227 /* test_dword("Status", info.info2.status); */
4228 test_dm("Default DevMode", info.info2.devmode);
4229 test_sd("Security", info.info2.secdesc);
4231 torture_assert(tctx,
4232 test_winreg_CloseKey(tctx, winreg_handle, &key_handle), "");
4238 torture_comment(tctx, "Printer Info and winreg consistency test succeeded\n\n");
4243 static bool test_GetPrinterDriver2_level(struct torture_context *tctx,
4244 struct dcerpc_binding_handle *b,
4245 struct policy_handle *handle,
4246 const char *driver_name,
4247 const char *architecture,
4249 uint32_t client_major_version,
4250 uint32_t client_minor_version,
4251 union spoolss_DriverInfo *info_p,
4254 static const char *strip_path(const char *path)
4262 p = strrchr(path, '\\');
4270 static const char **strip_paths(const char **path_array)
4274 if (path_array == NULL) {
4278 for (i=0; path_array[i] != NULL; i++) {
4279 path_array[i] = strip_path(path_array[i]);
4285 static const char *driver_winreg_date(TALLOC_CTX *mem_ctx, NTTIME nt)
4289 t = nt_time_to_unix(nt);
4292 return talloc_asprintf(mem_ctx, "%02d/%02d/%04d",
4293 tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900);
4296 static const char *driver_winreg_version(TALLOC_CTX *mem_ctx, uint64_t v)
4298 return talloc_asprintf(mem_ctx, "%u.%u.%u.%u",
4299 (unsigned)((v >> 48) & 0xFFFF),
4300 (unsigned)((v >> 32) & 0xFFFF),
4301 (unsigned)((v >> 16) & 0xFFFF),
4302 (unsigned)(v & 0xFFFF));
4305 static bool test_GetDriverInfo_winreg(struct torture_context *tctx,
4306 struct dcerpc_binding_handle *b,
4307 struct policy_handle *handle,
4308 const char *printer_name,
4309 const char *driver_name,
4310 const char *environment,
4311 struct dcerpc_binding_handle *winreg_handle,
4312 struct policy_handle *hive_handle)
4315 union spoolss_DriverInfo info;
4316 const char *driver_key;
4317 struct policy_handle key_handle;
4319 const char *driver_path;
4320 const char *data_file;
4321 const char *config_file;
4322 const char *help_file;
4323 const char **dependent_files;
4325 const char *driver_date;
4326 const char *inbox_driver_date;
4328 const char *driver_version;
4329 const char *inbox_driver_version;
4331 torture_comment(tctx, "Testing Driver Info and winreg consistency\n");
4333 driver_key = talloc_asprintf(tctx, "%s\\%s\\Drivers\\Version-%d\\%s",
4334 TOP_LEVEL_CONTROL_ENVIRONMENTS_KEY,
4339 torture_assert(tctx,
4340 test_winreg_OpenKey(tctx, winreg_handle, hive_handle, driver_key, &key_handle),
4341 "failed to open driver key");
4343 torture_assert(tctx,
4344 test_GetPrinterDriver2_level(tctx, b, handle, driver_name, environment, 8, 3, 0, &info, &result),
4345 "failed to get driver info level 8");
4347 if (W_ERROR_EQUAL(result, WERR_INVALID_LEVEL)) {
4351 driver_path = strip_path(info.info8.driver_path);
4352 data_file = strip_path(info.info8.data_file);
4353 config_file = strip_path(info.info8.config_file);
4354 help_file = strip_path(info.info8.help_file);
4355 dependent_files = strip_paths(info.info8.dependent_files);
4357 driver_date = driver_winreg_date(tctx, info.info8.driver_date);
4358 inbox_driver_date = driver_winreg_date(tctx, info.info8.min_inbox_driver_ver_date);
4360 driver_version = driver_winreg_version(tctx, info.info8.driver_version);
4361 inbox_driver_version = driver_winreg_version(tctx, info.info8.min_inbox_driver_ver_version);
4363 test_sz("Configuration File", config_file);
4364 test_sz("Data File", data_file);
4365 test_sz("Datatype", info.info8.default_datatype);
4366 test_sz("Driver", driver_path);
4367 test_sz("DriverDate", driver_date);
4368 test_sz("DriverVersion", driver_version);
4369 test_sz("HardwareID", info.info8.hardware_id);
4370 test_sz("Help File", help_file);
4371 test_sz("InfPath", info.info8.inf_path);
4372 test_sz("Manufacturer", info.info8.manufacturer_name);
4373 test_sz("MinInboxDriverVerDate", inbox_driver_date);
4374 test_sz("MinInboxDriverVerVersion", inbox_driver_version);
4375 test_sz("Monitor", info.info8.monitor_name);
4376 test_sz("OEM URL", info.info8.manufacturer_url);
4377 test_sz("Print Processor", info.info8.print_processor);
4378 test_sz("Provider", info.info8.provider);
4379 test_sz("VendorSetup", info.info8.vendor_setup);
4380 test_multi_sz("ColorProfiles", info.info8.color_profiles);
4381 test_multi_sz("Dependent Files", dependent_files);
4382 test_multi_sz("CoreDependencies", info.info8.core_driver_dependencies);
4383 test_multi_sz("Previous Names", info.info8.previous_names);
4384 /* test_dword("Attributes", ?); */
4385 test_dword("PrinterDriverAttributes", info.info8.printer_driver_attributes);
4386 test_dword("Version", info.info8.version);
4387 /* test_dword("TempDir", ?); */
4391 torture_assert(tctx,
4392 test_GetPrinterDriver2_level(tctx, b, handle, driver_name, environment, 6, 3, 0, &info, &result),
4393 "failed to get driver info level 6");
4395 driver_path = strip_path(info.info6.driver_path);
4396 data_file = strip_path(info.info6.data_file);
4397 config_file = strip_path(info.info6.config_file);
4398 help_file = strip_path(info.info6.help_file);
4399 dependent_files = strip_paths(info.info6.dependent_files);
4401 driver_date = driver_winreg_date(tctx, info.info6.driver_date);
4403 driver_version = driver_winreg_version(tctx, info.info6.driver_version);
4405 test_sz("Configuration File", config_file);
4406 test_sz("Data File", data_file);
4407 test_sz("Datatype", info.info6.default_datatype);
4408 test_sz("Driver", driver_path);
4409 test_sz("DriverDate", driver_date);
4410 test_sz("DriverVersion", driver_version);
4411 test_sz("HardwareID", info.info6.hardware_id);
4412 test_sz("Help File", help_file);
4413 test_sz("Manufacturer", info.info6.manufacturer_name);
4414 test_sz("Monitor", info.info6.monitor_name);
4415 test_sz("OEM URL", info.info6.manufacturer_url);
4416 test_sz("Provider", info.info6.provider);
4417 test_multi_sz("Dependent Files", dependent_files);
4418 test_multi_sz("Previous Names", info.info6.previous_names);
4419 /* test_dword("Attributes", ?); */
4420 test_dword("Version", info.info6.version);
4421 /* test_dword("TempDir", ?); */
4423 torture_assert(tctx,
4424 test_winreg_CloseKey(tctx, winreg_handle, &key_handle), "");
4426 torture_comment(tctx, "Driver Info and winreg consistency test succeeded\n\n");
4434 static bool test_SetPrinterData(struct torture_context *tctx,
4435 struct dcerpc_binding_handle *b,
4436 struct policy_handle *handle,
4437 const char *value_name,
4438 enum winreg_Type type,
4442 struct spoolss_SetPrinterData r;
4444 r.in.handle = handle;
4445 r.in.value_name = value_name;
4448 r.in.offered = offered;
4450 torture_comment(tctx, "Testing SetPrinterData(%s)\n",
4453 torture_assert_ntstatus_ok(tctx,
4454 dcerpc_spoolss_SetPrinterData_r(b, tctx, &r),
4455 "SetPrinterData failed");
4456 torture_assert_werr_ok(tctx, r.out.result,
4457 "SetPrinterData failed");
4462 static bool test_SetPrinterData_matrix(struct torture_context *tctx,
4463 struct dcerpc_binding_handle *b,
4464 struct policy_handle *handle,
4465 const char *printer_name,
4466 struct dcerpc_binding_handle *winreg_handle,
4467 struct policy_handle *hive_handle)
4469 const char *values[] = {
4473 /* FIXME: not working with s3 atm. */
4479 /* FIXME: not working with s3 atm. */
4486 for (i=0; i < ARRAY_SIZE(values); i++) {
4488 enum winreg_Type type;
4493 torture_assert(tctx,
4494 reg_string_to_val(tctx, lp_iconv_convenience(tctx->lp_ctx),
4495 "REG_SZ", "dog", &type, &blob), "");
4497 torture_assert(tctx,
4498 test_SetPrinterData(tctx, b, handle, values[i], REG_SZ, blob.data, blob.length),
4499 "SetPrinterData failed");
4501 torture_assert(tctx,
4502 test_GetPrinterData(tctx, b, handle, values[i], &type, &data, &needed),
4503 "GetPrinterData failed");
4505 torture_assert_int_equal(tctx, type, REG_SZ, "type mismatch");
4506 torture_assert_int_equal(tctx, needed, blob.length, "size mismatch");
4507 torture_assert_mem_equal(tctx, data, blob.data, blob.length, "buffer mismatch");
4509 if (winreg_handle && hive_handle) {
4511 enum winreg_Type w_type;
4516 torture_assert(tctx,
4517 test_winreg_query_printerdata(tctx, winreg_handle, hive_handle,
4518 printer_name, "PrinterDriverData", values[i],
4519 &w_type, &w_size, &w_length, &w_data), "");
4521 torture_assert_int_equal(tctx, w_type, REG_SZ, "winreg type mismatch");
4522 torture_assert_int_equal(tctx, w_size, blob.length, "winreg size mismatch");
4523 torture_assert_int_equal(tctx, w_length, blob.length, "winreg length mismatch");
4524 torture_assert_mem_equal(tctx, w_data, blob.data, blob.length, "winreg buffer mismatch");
4527 torture_assert(tctx,
4528 test_DeletePrinterData(tctx, b, handle, values[i]),
4529 "DeletePrinterData failed");
4536 static bool test_EnumPrinterKey(struct torture_context *tctx,
4537 struct dcerpc_binding_handle *b,
4538 struct policy_handle *handle,
4539 const char *key_name,
4540 const char ***array);
4542 static bool test_SetPrinterDataEx(struct torture_context *tctx,
4543 struct dcerpc_binding_handle *b,
4544 struct policy_handle *handle,
4545 const char *key_name,
4546 const char *value_name,
4547 enum winreg_Type type,
4552 struct spoolss_SetPrinterDataEx r;
4554 r.in.handle = handle;
4555 r.in.key_name = key_name;
4556 r.in.value_name = value_name;
4559 r.in.offered = offered;
4561 torture_comment(tctx, "Testing SetPrinterDataEx(%s - %s) type: %s, offered: 0x%08x\n",
4562 r.in.key_name, r.in.value_name, str_regtype(r.in.type), r.in.offered);
4564 status = dcerpc_spoolss_SetPrinterDataEx_r(b, tctx, &r);
4566 torture_assert_ntstatus_ok(tctx, status, "SetPrinterDataEx failed");
4567 torture_assert_werr_ok(tctx, r.out.result, "SetPrinterDataEx failed");
4572 static bool test_SetPrinterDataEx_matrix(struct torture_context *tctx,
4573 struct dcerpc_pipe *p,
4574 struct policy_handle *handle,
4575 const char *printername,
4576 struct dcerpc_binding_handle *winreg_handle,
4577 struct policy_handle *hive_handle)
4579 struct dcerpc_binding_handle *b = p->binding_handle;
4580 const char *value_name = "dog";
4581 const char *keys[] = {
4585 /* FIXME: not working with s3 atm. */
4586 "torturedataex_with_subkey\\subkey",
4587 "torturedataex_with_subkey\\subkey:0",
4588 "torturedataex_with_subkey\\subkey:1",
4589 "torturedataex_with_subkey\\subkey\\subsubkey",
4590 "torturedataex_with_subkey\\subkey\\subsubkey:0",
4591 "torturedataex_with_subkey\\subkey\\subsubkey:1",
4595 /* FIXME: not working with s3 atm. */
4602 enum winreg_Type types[] = {
4608 const char *str = "abcdefghijklmnopqrstuvwxzy";
4612 for (i=0; i < ARRAY_SIZE(keys); i++) {
4613 for (t=0; t < ARRAY_SIZE(types); t++) {
4614 for (s=0; s < strlen(str); s++) {
4618 enum winreg_Type type;
4619 const char *string = talloc_strndup(tctx, str, s);
4620 DATA_BLOB blob = data_blob_string_const(string);
4621 const char **subkeys;
4624 uint32_t needed, offered = 0;
4626 struct spoolss_PrinterEnumValues *einfo;
4628 if (types[t] == REG_DWORD) {
4632 if (torture_setting_bool(tctx, "samba3", false)) {
4633 if ((types[t] == REG_MULTI_SZ) && s == 0) {
4634 torture_warning(tctx, "samba3 does not handle 4 byte emtpy REG_MULTI_SZ buffers");
4642 offered = blob.length;
4645 data = data_blob_talloc(tctx, NULL, 4);
4646 SIVAL(data.data, 0, 0x12345678);
4650 torture_assert(tctx,
4651 reg_string_to_val(tctx, lp_iconv_convenience(tctx->lp_ctx),
4652 "REG_SZ", string, &type, &data), "");
4653 offered = data.length;
4654 /*strlen_m_term(data.string)*2;*/
4657 torture_assert(tctx,
4658 reg_string_to_val(tctx, lp_iconv_convenience(tctx->lp_ctx),
4659 "REG_SZ", string, &type, &data), "");
4660 torture_assert(tctx, data_blob_realloc(tctx, &data, data.length + 2), "");
4661 memset(&data.data[data.length - 2], '\0', 2);
4662 offered = data.length;
4665 torture_fail(tctx, talloc_asprintf(tctx, "type %d untested\n", types[t]));
4668 torture_assert(tctx,
4669 test_SetPrinterDataEx(tctx, b, handle, keys[i], value_name, types[t], data.data, offered),
4670 "failed to call SetPrinterDataEx");
4672 torture_assert(tctx,
4673 test_GetPrinterDataEx(tctx, p, handle, keys[i], value_name, &type, &data_out, &needed),
4674 "failed to call GetPrinterDataEx");
4676 torture_assert(tctx,
4677 test_EnumPrinterDataEx(tctx, b, handle, keys[i], &ecount, &einfo),
4678 "failed to call EnumPrinterDataEx");
4680 torture_assert_int_equal(tctx, types[t], type, "type mismatch");
4681 torture_assert_int_equal(tctx, needed, offered, "size mismatch");
4682 torture_assert_mem_equal(tctx, data_out, data.data, offered, "buffer mismatch");
4684 torture_assert_int_equal(tctx, ecount, 1, "unexpected enum count");
4685 torture_assert_str_equal(tctx, einfo[0].value_name, value_name, "value_name mismatch");
4686 torture_assert_int_equal(tctx, einfo[0].value_name_len, strlen_m_term(value_name)*2, "unexpected value_name_len");
4687 torture_assert_int_equal(tctx, einfo[0].type, types[t], "type mismatch");
4688 torture_assert_int_equal(tctx, einfo[0].data_length, offered, "size mismatch");
4689 if (einfo[0].data_length > 0) {
4690 torture_assert_mem_equal(tctx, einfo[0].data->data, data.data, offered, "buffer mismatch");
4693 if (winreg_handle && hive_handle) {
4694 enum winreg_Type w_type;
4699 torture_assert(tctx,
4700 test_winreg_query_printerdata(tctx, winreg_handle, hive_handle,
4701 printername, keys[i], value_name,
4702 &w_type, &w_size, &w_length, &w_data), "");
4704 torture_assert_int_equal(tctx, w_type, types[t], "winreg type mismatch");
4705 torture_assert_int_equal(tctx, w_size, offered, "winreg size mismatch");
4706 torture_assert_int_equal(tctx, w_length, offered, "winreg length mismatch");
4707 torture_assert_mem_equal(tctx, w_data, data.data, offered, "winreg buffer mismatch");
4710 key = talloc_strdup(tctx, keys[i]);
4712 if (!test_DeletePrinterDataEx(tctx, b, handle, keys[i], value_name)) {
4716 c = strchr(key, '\\');
4720 /* we have subkeys */
4724 if (!test_EnumPrinterKey(tctx, b, handle, key, &subkeys)) {
4728 for (k=0; subkeys && subkeys[k]; k++) {
4730 const char *current_key = talloc_asprintf(tctx, "%s\\%s", key, subkeys[k]);
4732 if (!test_DeletePrinterKey(tctx, b, handle, current_key)) {
4737 if (!test_DeletePrinterKey(tctx, b, handle, key)) {
4742 if (!test_DeletePrinterKey(tctx, b, handle, key)) {
4753 static bool test_PrinterData_winreg(struct torture_context *tctx,
4754 struct dcerpc_pipe *p,
4755 struct policy_handle *handle,
4756 const char *printer_name)
4758 struct dcerpc_binding_handle *b = p->binding_handle;
4759 struct dcerpc_pipe *p2;
4761 struct policy_handle hive_handle;
4762 struct dcerpc_binding_handle *b2;
4764 torture_assert_ntstatus_ok(tctx,
4765 torture_rpc_connection(tctx, &p2, &ndr_table_winreg),
4766 "could not open winreg pipe");
4767 b2 = p2->binding_handle;
4769 torture_assert(tctx, test_winreg_OpenHKLM(tctx, b2, &hive_handle), "");
4771 ret &= test_SetPrinterData_matrix(tctx, b, handle, printer_name, b2, &hive_handle);
4772 ret &= test_SetPrinterDataEx_matrix(tctx, p, handle, printer_name, b2, &hive_handle);
4774 test_winreg_CloseKey(tctx, b2, &hive_handle);
4781 static bool test_Forms_winreg(struct torture_context *tctx,
4782 struct dcerpc_binding_handle *b,
4783 struct policy_handle *handle,
4785 const char *printer_name)
4787 struct dcerpc_pipe *p2;
4789 struct policy_handle hive_handle;
4790 struct dcerpc_binding_handle *b2;
4792 torture_assert_ntstatus_ok(tctx,
4793 torture_rpc_connection(tctx, &p2, &ndr_table_winreg),
4794 "could not open winreg pipe");
4795 b2 = p2->binding_handle;
4797 torture_assert(tctx, test_winreg_OpenHKLM(tctx, b2, &hive_handle), "");
4799 ret = test_Forms(tctx, b, handle, print_server, printer_name, b2, &hive_handle);
4801 test_winreg_CloseKey(tctx, b2, &hive_handle);
4808 static bool test_PrinterInfo_winreg(struct torture_context *tctx,
4809 struct dcerpc_pipe *p,
4810 struct policy_handle *handle,
4811 const char *printer_name)
4813 struct dcerpc_binding_handle *b = p->binding_handle;
4814 struct dcerpc_pipe *p2;
4816 struct policy_handle hive_handle;
4817 struct dcerpc_binding_handle *b2;
4819 torture_assert_ntstatus_ok(tctx,
4820 torture_rpc_connection(tctx, &p2, &ndr_table_winreg),
4821 "could not open winreg pipe");
4822 b2 = p2->binding_handle;
4824 torture_assert(tctx, test_winreg_OpenHKLM(tctx, b2, &hive_handle), "");
4826 ret = test_GetPrinterInfo_winreg(tctx, b, handle, printer_name, b2, &hive_handle);
4828 test_winreg_CloseKey(tctx, b2, &hive_handle);
4835 static bool test_DriverInfo_winreg(struct torture_context *tctx,
4836 struct dcerpc_pipe *p,
4837 struct policy_handle *handle,
4838 const char *printer_name,
4839 const char *driver_name,
4840 const char *environment)
4842 struct dcerpc_binding_handle *b = p->binding_handle;
4843 struct dcerpc_pipe *p2;
4845 struct policy_handle hive_handle;
4846 struct dcerpc_binding_handle *b2;
4848 torture_assert_ntstatus_ok(tctx,
4849 torture_rpc_connection(tctx, &p2, &ndr_table_winreg),
4850 "could not open winreg pipe");
4851 b2 = p2->binding_handle;
4853 torture_assert(tctx, test_winreg_OpenHKLM(tctx, b2, &hive_handle), "");
4855 ret = test_GetDriverInfo_winreg(tctx, b, handle, printer_name, driver_name, environment, b2, &hive_handle);
4857 test_winreg_CloseKey(tctx, b2, &hive_handle);
4864 static bool test_GetChangeID_PrinterData(struct torture_context *tctx,
4865 struct dcerpc_binding_handle *b,
4866 struct policy_handle *handle,
4867 uint32_t *change_id)
4869 enum winreg_Type type;
4873 torture_assert(tctx,
4874 test_GetPrinterData(tctx, b, handle, "ChangeID", &type, &data, &needed),
4875 "failed to call GetPrinterData");
4877 torture_assert(tctx, type == REG_DWORD, "unexpected type");
4878 torture_assert_int_equal(tctx, needed, 4, "unexpected size");
4880 *change_id = IVAL(data, 0);
4885 static bool test_GetChangeID_PrinterDataEx(struct torture_context *tctx,
4886 struct dcerpc_pipe *p,
4887 struct policy_handle *handle,
4888 uint32_t *change_id)
4890 enum winreg_Type type;
4894 torture_assert(tctx,
4895 test_GetPrinterDataEx(tctx, p, handle, "PrinterDriverData", "ChangeID", &type, &data, &needed),
4896 "failed to call GetPrinterData");
4898 torture_assert(tctx, type == REG_DWORD, "unexpected type");
4899 torture_assert_int_equal(tctx, needed, 4, "unexpected size");
4901 *change_id = IVAL(data, 0);
4906 static bool test_GetChangeID_PrinterInfo(struct torture_context *tctx,
4907 struct dcerpc_binding_handle *b,
4908 struct policy_handle *handle,
4909 uint32_t *change_id)
4911 union spoolss_PrinterInfo info;
4913 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 0, &info),
4914 "failed to query Printer level 0");
4916 *change_id = info.info0.change_id;
4921 static bool test_ChangeID(struct torture_context *tctx,
4922 struct dcerpc_pipe *p,
4923 struct policy_handle *handle)
4925 uint32_t change_id, change_id_ex, change_id_info;
4926 uint32_t change_id2, change_id_ex2, change_id_info2;
4927 union spoolss_PrinterInfo info;
4928 const char *comment;
4929 struct dcerpc_binding_handle *b = p->binding_handle;
4931 torture_comment(tctx, "Testing ChangeID: id change test #1\n");
4933 torture_assert(tctx, test_GetChangeID_PrinterData(tctx, b, handle, &change_id),
4934 "failed to query for ChangeID");
4935 torture_assert(tctx, test_GetChangeID_PrinterDataEx(tctx, p, handle, &change_id_ex),
4936 "failed to query for ChangeID");
4937 torture_assert(tctx, test_GetChangeID_PrinterInfo(tctx, b, handle, &change_id_info),
4938 "failed to query for ChangeID");
4940 torture_assert_int_equal(tctx, change_id, change_id_ex,
4941 "change_ids should all be equal");
4942 torture_assert_int_equal(tctx, change_id_ex, change_id_info,
4943 "change_ids should all be equal");
4946 torture_comment(tctx, "Testing ChangeID: id change test #2\n");
4948 torture_assert(tctx, test_GetChangeID_PrinterData(tctx, b, handle, &change_id),
4949 "failed to query for ChangeID");
4950 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info),
4951 "failed to query Printer level 2");
4952 torture_assert(tctx, test_GetChangeID_PrinterDataEx(tctx, p, handle, &change_id_ex),
4953 "failed to query for ChangeID");
4954 torture_assert(tctx, test_GetChangeID_PrinterInfo(tctx, b, handle, &change_id_info),
4955 "failed to query for ChangeID");
4956 torture_assert_int_equal(tctx, change_id, change_id_ex,
4957 "change_id should not have changed");
4958 torture_assert_int_equal(tctx, change_id_ex, change_id_info,
4959 "change_id should not have changed");
4962 torture_comment(tctx, "Testing ChangeID: id change test #3\n");
4964 torture_assert(tctx, test_GetChangeID_PrinterData(tctx, b, handle, &change_id),
4965 "failed to query for ChangeID");
4966 torture_assert(tctx, test_GetChangeID_PrinterDataEx(tctx, p, handle, &change_id_ex),
4967 "failed to query for ChangeID");
4968 torture_assert(tctx, test_GetChangeID_PrinterInfo(tctx, b, handle, &change_id_info),
4969 "failed to query for ChangeID");
4970 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info),
4971 "failed to query Printer level 2");
4972 comment = talloc_strdup(tctx, info.info2.comment);
4975 struct spoolss_SetPrinterInfoCtr info_ctr;
4976 struct spoolss_DevmodeContainer devmode_ctr;
4977 struct sec_desc_buf secdesc_ctr;
4978 union spoolss_SetPrinterInfo sinfo;
4980 ZERO_STRUCT(info_ctr);
4981 ZERO_STRUCT(devmode_ctr);
4982 ZERO_STRUCT(secdesc_ctr);
4985 torture_assert(tctx, PrinterInfo_to_SetPrinterInfo(tctx, &info, 2, &sinfo), "");
4986 sinfo.info2->comment = "torture_comment";
4989 info_ctr.info = sinfo;
4991 torture_assert(tctx, test_SetPrinter(tctx, b, handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0),
4992 "failed to call SetPrinter");
4994 sinfo.info2->comment = comment;
4996 torture_assert(tctx, test_SetPrinter(tctx, b, handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0),
4997 "failed to call SetPrinter");
5001 torture_assert(tctx, test_GetChangeID_PrinterData(tctx, b, handle, &change_id2),
5002 "failed to query for ChangeID");
5003 torture_assert(tctx, test_GetChangeID_PrinterDataEx(tctx, p, handle, &change_id_ex2),
5004 "failed to query for ChangeID");
5005 torture_assert(tctx, test_GetChangeID_PrinterInfo(tctx, b, handle, &change_id_info2),
5006 "failed to query for ChangeID");
5008 torture_assert_int_equal(tctx, change_id2, change_id_ex2,
5009 "change_ids should all be equal");
5010 torture_assert_int_equal(tctx, change_id_ex2, change_id_info2,
5011 "change_ids should all be equal");
5013 torture_assert(tctx, (change_id < change_id2),
5014 talloc_asprintf(tctx, "change_id %d needs to be larger than change_id %d",
5015 change_id2, change_id));
5016 torture_assert(tctx, (change_id_ex < change_id_ex2),
5017 talloc_asprintf(tctx, "change_id %d needs to be larger than change_id %d",
5018 change_id_ex2, change_id_ex));
5019 torture_assert(tctx, (change_id_info < change_id_info2),
5020 talloc_asprintf(tctx, "change_id %d needs to be larger than change_id %d",
5021 change_id_info2, change_id_info));
5023 torture_comment(tctx, "ChangeID tests succeeded\n\n");
5028 static bool test_SecondaryClosePrinter(struct torture_context *tctx,
5029 struct dcerpc_pipe *p,
5030 struct policy_handle *handle)
5033 struct dcerpc_binding *b;
5034 struct dcerpc_pipe *p2;
5035 struct spoolss_ClosePrinter cp;
5037 /* only makes sense on SMB */
5038 if (p->conn->transport.transport != NCACN_NP) {
5042 torture_comment(tctx, "Testing close on secondary pipe\n");
5044 status = dcerpc_parse_binding(tctx, p->conn->binding_string, &b);
5045 torture_assert_ntstatus_ok(tctx, status, "Failed to parse dcerpc binding");
5047 status = dcerpc_secondary_connection(p, &p2, b);
5048 torture_assert_ntstatus_ok(tctx, status, "Failed to create secondary connection");
5050 status = dcerpc_bind_auth_none(p2, &ndr_table_spoolss);
5051 torture_assert_ntstatus_ok(tctx, status, "Failed to create bind on secondary connection");
5053 cp.in.handle = handle;
5054 cp.out.handle = handle;
5056 status = dcerpc_spoolss_ClosePrinter_r(p2->binding_handle, tctx, &cp);
5057 torture_assert_ntstatus_equal(tctx, status, NT_STATUS_RPC_SS_CONTEXT_MISMATCH,
5058 "ERROR: Allowed close on secondary connection");
5065 static bool test_OpenPrinter_badname(struct torture_context *tctx,
5066 struct dcerpc_binding_handle *b, const char *name)
5069 struct spoolss_OpenPrinter op;
5070 struct spoolss_OpenPrinterEx opEx;
5071 struct policy_handle handle;
5074 op.in.printername = name;
5075 op.in.datatype = NULL;
5076 op.in.devmode_ctr.devmode= NULL;
5077 op.in.access_mask = 0;
5078 op.out.handle = &handle;
5080 torture_comment(tctx, "Testing OpenPrinter(%s) with bad name\n", op.in.printername);
5082 status = dcerpc_spoolss_OpenPrinter_r(b, tctx, &op);
5083 torture_assert_ntstatus_ok(tctx, status, "OpenPrinter failed");
5084 torture_assert_werr_equal(tctx, op.out.result, WERR_INVALID_PRINTER_NAME,
5085 "unexpected result");
5087 if (W_ERROR_IS_OK(op.out.result)) {
5088 ret &=test_ClosePrinter(tctx, b, &handle);
5091 opEx.in.printername = name;
5092 opEx.in.datatype = NULL;
5093 opEx.in.devmode_ctr.devmode = NULL;
5094 opEx.in.access_mask = 0;
5096 opEx.in.userlevel.level1 = NULL;
5097 opEx.out.handle = &handle;
5099 torture_comment(tctx, "Testing OpenPrinterEx(%s) with bad name\n", opEx.in.printername);
5101 status = dcerpc_spoolss_OpenPrinterEx_r(b, tctx, &opEx);
5102 torture_assert_ntstatus_ok(tctx, status, "OpenPrinterEx failed");
5103 torture_assert_werr_equal(tctx, opEx.out.result, WERR_INVALID_PARAM,
5104 "unexpected result");
5106 if (W_ERROR_IS_OK(opEx.out.result)) {
5107 ret &=test_ClosePrinter(tctx, b, &handle);
5113 static bool test_OpenPrinter_badname_list(struct torture_context *tctx,
5114 struct dcerpc_binding_handle *b,
5115 const char *server_name)
5117 const char *badnames[] = {
5118 "__INVALID_PRINTER__",
5119 "\\\\__INVALID_HOST__",
5122 "\\\\\\__INVALID_PRINTER__"
5124 const char *badname;
5127 for (i=0; i < ARRAY_SIZE(badnames); i++) {
5128 torture_assert(tctx,
5129 test_OpenPrinter_badname(tctx, b, badnames[i]),
5133 badname = talloc_asprintf(tctx, "\\\\%s\\", server_name);
5134 torture_assert(tctx,
5135 test_OpenPrinter_badname(tctx, b, badname),
5138 badname = talloc_asprintf(tctx, "\\\\%s\\__INVALID_PRINTER__", server_name);
5139 torture_assert(tctx,
5140 test_OpenPrinter_badname(tctx, b, badname),
5146 static bool test_OpenPrinter(struct torture_context *tctx,
5147 struct dcerpc_pipe *p,
5149 const char *environment)
5152 struct spoolss_OpenPrinter r;
5153 struct policy_handle handle;
5155 struct dcerpc_binding_handle *b = p->binding_handle;
5157 r.in.printername = talloc_asprintf(tctx, "\\\\%s\\%s", dcerpc_server_name(p), name);
5158 r.in.datatype = NULL;
5159 r.in.devmode_ctr.devmode= NULL;
5160 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
5161 r.out.handle = &handle;
5163 torture_comment(tctx, "Testing OpenPrinter(%s)\n", r.in.printername);
5165 status = dcerpc_spoolss_OpenPrinter_r(b, tctx, &r);
5167 torture_assert_ntstatus_ok(tctx, status, "OpenPrinter failed");
5169 torture_assert_werr_ok(tctx, r.out.result, "OpenPrinter failed");
5171 if (!test_GetPrinter(tctx, b, &handle, environment)) {
5175 if (!torture_setting_bool(tctx, "samba3", false)) {
5176 if (!test_SecondaryClosePrinter(tctx, p, &handle)) {
5181 if (!test_ClosePrinter(tctx, b, &handle)) {
5188 static bool call_OpenPrinterEx(struct torture_context *tctx,
5189 struct dcerpc_pipe *p,
5191 struct spoolss_DeviceMode *devmode,
5192 struct policy_handle *handle)
5194 struct spoolss_OpenPrinterEx r;
5195 struct spoolss_UserLevel1 userlevel1;
5197 struct dcerpc_binding_handle *b = p->binding_handle;
5199 if (name && name[0]) {
5200 r.in.printername = talloc_asprintf(tctx, "\\\\%s\\%s",
5201 dcerpc_server_name(p), name);
5203 r.in.printername = talloc_asprintf(tctx, "\\\\%s",
5204 dcerpc_server_name(p));
5207 r.in.datatype = NULL;
5208 r.in.devmode_ctr.devmode= devmode;
5209 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
5211 r.in.userlevel.level1 = &userlevel1;
5212 r.out.handle = handle;
5214 userlevel1.size = 1234;
5215 userlevel1.client = "hello";
5216 userlevel1.user = "spottyfoot!";
5217 userlevel1.build = 1;
5218 userlevel1.major = 2;
5219 userlevel1.minor = 3;
5220 userlevel1.processor = 4;
5222 torture_comment(tctx, "Testing OpenPrinterEx(%s)\n", r.in.printername);
5224 status = dcerpc_spoolss_OpenPrinterEx_r(b, tctx, &r);
5226 torture_assert_ntstatus_ok(tctx, status, "OpenPrinterEx failed");
5228 torture_assert_werr_ok(tctx, r.out.result, "OpenPrinterEx failed");
5233 static bool test_printer_rename(struct torture_context *tctx,
5234 struct dcerpc_pipe *p,
5235 struct policy_handle *handle,
5239 union spoolss_PrinterInfo info;
5240 union spoolss_SetPrinterInfo sinfo;
5241 struct spoolss_SetPrinterInfoCtr info_ctr;
5242 struct spoolss_DevmodeContainer devmode_ctr;
5243 struct sec_desc_buf secdesc_ctr;
5244 const char *printer_name;
5245 const char *printer_name_orig;
5246 const char *printer_name_new = "SAMBA smbtorture Test Printer (Copy 2)";
5247 struct policy_handle new_handle;
5249 struct dcerpc_binding_handle *b = p->binding_handle;
5251 ZERO_STRUCT(devmode_ctr);
5252 ZERO_STRUCT(secdesc_ctr);
5254 torture_comment(tctx, "Testing Printer rename operations\n");
5256 torture_assert(tctx,
5257 test_GetPrinter_level(tctx, b, handle, 2, &info),
5258 "failed to call GetPrinter level 2");
5260 printer_name_orig = talloc_strdup(tctx, info.info2.printername);
5262 q = strrchr(info.info2.printername, '\\');
5264 torture_warning(tctx,
5265 "server returns printername %s incl. servername although we did not set servername", info.info2.printername);
5268 torture_assert(tctx,
5269 PrinterInfo_to_SetPrinterInfo(tctx, &info, 2, &sinfo), "");
5271 sinfo.info2->printername = printer_name_new;
5274 info_ctr.info = sinfo;
5276 torture_assert(tctx,
5277 test_SetPrinter(tctx, b, handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0),
5278 "failed to call SetPrinter level 2");
5280 torture_assert(tctx,
5281 test_GetPrinter_level(tctx, b, handle, 2, &info),
5282 "failed to call GetPrinter level 2");
5284 printer_name = talloc_strdup(tctx, info.info2.printername);
5286 q = strrchr(info.info2.printername, '\\');
5288 torture_warning(tctx,
5289 "server returns printername %s incl. servername although we did not set servername", info.info2.printername);
5294 torture_assert_str_equal(tctx, printer_name, printer_name_new,
5295 "new printer name was not set");
5297 /* samba currently cannot fully rename printers */
5298 if (!torture_setting_bool(tctx, "samba3", false)) {
5299 torture_assert(tctx,
5300 test_OpenPrinter_badname(tctx, b, printer_name_orig),
5301 "still can open printer with oldname after rename");
5303 torture_warning(tctx, "*not* checking for open with oldname after rename for samba3");
5306 torture_assert(tctx,
5307 call_OpenPrinterEx(tctx, p, printer_name_new, NULL, &new_handle),
5308 "failed to open printer with new name");
5310 torture_assert(tctx,
5311 test_GetPrinter_level(tctx, b, &new_handle, 2, &info),
5312 "failed to call GetPrinter level 2");
5314 /* FIXME: we openend with servername! */
5315 printer_name = talloc_asprintf(tctx, "\\\\%s\\%s",
5316 dcerpc_server_name(p), printer_name_new);
5318 torture_assert_str_equal(tctx, info.info2.printername, printer_name,
5319 "new printer name was not set");
5321 torture_assert(tctx,
5322 test_ClosePrinter(tctx, b, &new_handle),
5323 "failed to close printer");
5325 torture_comment(tctx, "Printer rename operations test succeeded\n\n");
5331 static bool test_OpenPrinterEx(struct torture_context *tctx,
5332 struct dcerpc_pipe *p,
5334 const char *environment)
5336 struct policy_handle handle;
5338 struct dcerpc_binding_handle *b = p->binding_handle;
5340 if (!call_OpenPrinterEx(tctx, p, name, NULL, &handle)) {
5344 if (!test_PrinterInfo_SD(tctx, b, &handle)) {
5348 if (!test_GetPrinter(tctx, b, &handle, environment)) {
5352 if (!test_EnumForms_all(tctx, b, &handle, false)) {
5356 if (!test_Forms(tctx, b, &handle, false, name, NULL, NULL)) {
5360 if (!test_Forms_winreg(tctx, b, &handle, false, name)) {
5364 if (!test_EnumPrinterData_all(tctx, p, &handle)) {
5368 if (!test_EnumPrinterDataEx(tctx, b, &handle, "PrinterDriverData", NULL, NULL)) {
5372 if (!test_EnumPrinterData_consistency(tctx, p, &handle)) {
5376 if (!test_printer_keys(tctx, b, &handle)) {
5380 if (!test_PausePrinter(tctx, b, &handle)) {
5384 if (!test_DoPrintTest(tctx, b, &handle)) {
5388 if (!test_ResumePrinter(tctx, b, &handle)) {
5392 if (!test_SetPrinterData_matrix(tctx, b, &handle, name, NULL, NULL)) {
5396 if (!test_SetPrinterDataEx_matrix(tctx, p, &handle, name, NULL, NULL)) {
5400 if (!torture_setting_bool(tctx, "samba3", false)) {
5401 if (!test_SecondaryClosePrinter(tctx, p, &handle)) {
5406 if (!test_ClosePrinter(tctx, b, &handle)) {
5413 static bool test_EnumPrinters_old(struct torture_context *tctx,
5414 struct dcerpc_pipe *p,
5415 const char *environment)
5417 struct spoolss_EnumPrinters r;
5419 uint16_t levels[] = {1, 2, 4, 5};
5422 struct dcerpc_binding_handle *b = p->binding_handle;
5424 for (i=0;i<ARRAY_SIZE(levels);i++) {
5425 union spoolss_PrinterInfo *info;
5430 r.in.flags = PRINTER_ENUM_LOCAL;
5432 r.in.level = levels[i];
5435 r.out.needed = &needed;
5436 r.out.count = &count;
5439 torture_comment(tctx, "Testing EnumPrinters level %u\n", r.in.level);
5441 status = dcerpc_spoolss_EnumPrinters_r(b, tctx, &r);
5442 torture_assert_ntstatus_ok(tctx, status, "EnumPrinters failed");
5444 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
5445 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
5446 r.in.buffer = &blob;
5447 r.in.offered = needed;
5448 status = dcerpc_spoolss_EnumPrinters_r(b, tctx, &r);
5451 torture_assert_ntstatus_ok(tctx, status, "EnumPrinters failed");
5453 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinters failed");
5455 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPrinters, info, r.in.level, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
5458 torture_comment(tctx, "No printers returned\n");
5462 for (j=0;j<count;j++) {
5463 if (r.in.level == 1) {
5464 char *unc = talloc_strdup(tctx, info[j].info1.name);
5467 if (unc[0] == '\\' && unc[1] == '\\') {
5470 slash = strchr(unc, '\\');
5475 if (!test_OpenPrinter(tctx, p, name, environment)) {
5478 if (!test_OpenPrinterEx(tctx, p, name, environment)) {
5488 static bool test_GetPrinterDriver(struct torture_context *tctx,
5489 struct dcerpc_binding_handle *b,
5490 struct policy_handle *handle,
5491 const char *driver_name)
5493 struct spoolss_GetPrinterDriver r;
5496 r.in.handle = handle;
5497 r.in.architecture = "W32X86";
5501 r.out.needed = &needed;
5503 torture_comment(tctx, "Testing GetPrinterDriver level %d\n", r.in.level);
5505 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_GetPrinterDriver_r(b, tctx, &r),
5506 "failed to call GetPrinterDriver");
5507 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
5508 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
5509 r.in.buffer = &blob;
5510 r.in.offered = needed;
5511 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_GetPrinterDriver_r(b, tctx, &r),
5512 "failed to call GetPrinterDriver");
5515 torture_assert_werr_ok(tctx, r.out.result,
5516 "failed to call GetPrinterDriver");
5518 CHECK_NEEDED_SIZE_LEVEL(spoolss_DriverInfo, r.out.info, r.in.level, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
5523 static bool test_GetPrinterDriver2_level(struct torture_context *tctx,
5524 struct dcerpc_binding_handle *b,
5525 struct policy_handle *handle,
5526 const char *driver_name,
5527 const char *architecture,
5529 uint32_t client_major_version,
5530 uint32_t client_minor_version,
5531 union spoolss_DriverInfo *info_p,
5535 struct spoolss_GetPrinterDriver2 r;
5537 uint32_t server_major_version;
5538 uint32_t server_minor_version;
5540 r.in.handle = handle;
5541 r.in.architecture = architecture;
5542 r.in.client_major_version = client_major_version;
5543 r.in.client_minor_version = client_minor_version;
5547 r.out.needed = &needed;
5548 r.out.server_major_version = &server_major_version;
5549 r.out.server_minor_version = &server_minor_version;
5551 torture_comment(tctx, "Testing GetPrinterDriver2(%s) level %d\n",
5552 driver_name, r.in.level);
5554 torture_assert_ntstatus_ok(tctx,
5555 dcerpc_spoolss_GetPrinterDriver2_r(b, tctx, &r),
5556 "failed to call GetPrinterDriver2");
5557 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
5558 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
5559 r.in.buffer = &blob;
5560 r.in.offered = needed;
5561 torture_assert_ntstatus_ok(tctx,
5562 dcerpc_spoolss_GetPrinterDriver2_r(b, tctx, &r),
5563 "failed to call GetPrinterDriver2");
5567 *result_p = r.out.result;
5570 if (W_ERROR_EQUAL(r.out.result, WERR_INVALID_LEVEL)) {
5571 switch (r.in.level) {
5574 torture_comment(tctx,
5575 "level %d not implemented, not considering as an error\n",
5583 torture_assert_werr_ok(tctx, r.out.result,
5584 "failed to call GetPrinterDriver2");
5586 CHECK_NEEDED_SIZE_LEVEL(spoolss_DriverInfo, r.out.info, r.in.level, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
5589 *info_p = *r.out.info;
5595 static bool test_GetPrinterDriver2(struct torture_context *tctx,
5596 struct dcerpc_binding_handle *b,
5597 struct policy_handle *handle,
5598 const char *driver_name,
5599 const char *architecture)
5601 uint16_t levels[] = {1, 2, 3, 4, 5, 6, 8, 101 };
5605 for (i=0;i<ARRAY_SIZE(levels);i++) {
5607 torture_assert(tctx,
5608 test_GetPrinterDriver2_level(tctx, b, handle, driver_name, architecture, levels[i], 3, 0, NULL, NULL),
5615 static bool test_EnumPrinterDrivers_old(struct torture_context *tctx,
5616 struct dcerpc_pipe *p,
5617 const char *environment)
5619 uint16_t levels[] = {1, 2, 3, 4, 5, 6};
5621 struct dcerpc_binding_handle *b = p->binding_handle;
5622 const char *server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
5624 for (i=0;i<ARRAY_SIZE(levels);i++) {
5627 union spoolss_DriverInfo *info;
5629 torture_assert(tctx,
5630 test_EnumPrinterDrivers_args(tctx, b, server_name, environment, levels[i], &count, &info),
5631 "failed to enumerate drivers");
5634 torture_comment(tctx, "No printer drivers returned\n");
5642 static bool test_DeletePrinter(struct torture_context *tctx,
5643 struct dcerpc_binding_handle *b,
5644 struct policy_handle *handle)
5646 struct spoolss_DeletePrinter r;
5648 torture_comment(tctx, "Testing DeletePrinter\n");
5650 r.in.handle = handle;
5652 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_DeletePrinter_r(b, tctx, &r),
5653 "failed to delete printer");
5654 torture_assert_werr_ok(tctx, r.out.result,
5655 "failed to delete printer");
5660 static bool test_EnumPrinters_findname(struct torture_context *tctx,
5661 struct dcerpc_binding_handle *b,
5667 struct spoolss_EnumPrinters e;
5669 union spoolss_PrinterInfo *info;
5680 e.out.count = &count;
5682 e.out.needed = &needed;
5684 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinters_r(b, tctx, &e),
5685 "failed to enum printers");
5687 if (W_ERROR_EQUAL(e.out.result, WERR_INSUFFICIENT_BUFFER)) {
5688 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
5689 e.in.buffer = &blob;
5690 e.in.offered = needed;
5692 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinters_r(b, tctx, &e),
5693 "failed to enum printers");
5696 torture_assert_werr_ok(tctx, e.out.result,
5697 "failed to enum printers");
5699 for (i=0; i < count; i++) {
5701 const char *current = NULL;
5706 current = info[i].info1.name;
5710 if (strequal(current, name)) {
5715 q = strrchr(current, '\\');
5718 torture_warning(tctx,
5719 "server returns printername %s incl. servername although we did not set servername", current);
5722 if (strequal(q, name)) {
5732 static bool test_AddPrinter_wellknown(struct torture_context *tctx,
5733 struct dcerpc_pipe *p,
5734 const char *printername,
5738 struct spoolss_AddPrinter r;
5739 struct spoolss_AddPrinterEx rex;
5740 struct spoolss_SetPrinterInfoCtr info_ctr;
5741 struct spoolss_SetPrinterInfo1 info1;
5742 struct spoolss_DevmodeContainer devmode_ctr;
5743 struct sec_desc_buf secdesc_ctr;
5744 struct spoolss_UserLevelCtr userlevel_ctr;
5745 struct policy_handle handle;
5747 struct dcerpc_binding_handle *b = p->binding_handle;
5749 ZERO_STRUCT(devmode_ctr);
5750 ZERO_STRUCT(secdesc_ctr);
5751 ZERO_STRUCT(userlevel_ctr);
5754 torture_comment(tctx, "Testing AddPrinter%s level 1\n", ex ? "Ex":"");
5756 /* try to add printer to wellknown printer list (level 1) */
5758 userlevel_ctr.level = 1;
5760 info_ctr.info.info1 = &info1;
5763 rex.in.server = NULL;
5764 rex.in.info_ctr = &info_ctr;
5765 rex.in.devmode_ctr = &devmode_ctr;
5766 rex.in.secdesc_ctr = &secdesc_ctr;
5767 rex.in.userlevel_ctr = &userlevel_ctr;
5768 rex.out.handle = &handle;
5771 r.in.info_ctr = &info_ctr;
5772 r.in.devmode_ctr = &devmode_ctr;
5773 r.in.secdesc_ctr = &secdesc_ctr;
5774 r.out.handle = &handle;
5776 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) :
5777 dcerpc_spoolss_AddPrinter_r(b, tctx, &r),
5778 "failed to add printer");
5779 result = ex ? rex.out.result : r.out.result;
5780 torture_assert_werr_equal(tctx, result, WERR_INVALID_PRINTER_NAME,
5781 "unexpected result code");
5783 info1.name = printername;
5784 info1.flags = PRINTER_ATTRIBUTE_SHARED;
5786 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) :
5787 dcerpc_spoolss_AddPrinter_r(b, tctx, &r),
5788 "failed to add printer");
5789 result = ex ? rex.out.result : r.out.result;
5790 torture_assert_werr_equal(tctx, result, WERR_PRINTER_ALREADY_EXISTS,
5791 "unexpected result code");
5793 /* bizarre protocol, WERR_PRINTER_ALREADY_EXISTS means success here,
5794 better do a real check to see the printer is really there */
5796 torture_assert(tctx, test_EnumPrinters_findname(tctx, b,
5797 PRINTER_ENUM_NETWORK, 1,
5800 "failed to enum printers");
5802 torture_assert(tctx, found, "failed to find newly added printer");
5806 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) :
5807 dcerpc_spoolss_AddPrinter_r(b, tctx, &r),
5808 "failed to add printer");
5809 result = ex ? rex.out.result : r.out.result;
5810 torture_assert_werr_equal(tctx, result, WERR_PRINTER_ALREADY_EXISTS,
5811 "unexpected result code");
5813 /* bizarre protocol, WERR_PRINTER_ALREADY_EXISTS means success here,
5814 better do a real check to see the printer has really been removed
5815 from the well known printer list */
5819 torture_assert(tctx, test_EnumPrinters_findname(tctx, b,
5820 PRINTER_ENUM_NETWORK, 1,
5823 "failed to enum printers");
5825 torture_assert(tctx, !found, "printer still in well known printer list");
5830 static bool test_AddPrinter_normal(struct torture_context *tctx,
5831 struct dcerpc_pipe *p,
5832 struct policy_handle *handle_p,
5833 const char *printername,
5834 const char *drivername,
5835 const char *portname,
5839 struct spoolss_AddPrinter r;
5840 struct spoolss_AddPrinterEx rex;
5841 struct spoolss_SetPrinterInfoCtr info_ctr;
5842 struct spoolss_SetPrinterInfo2 info2;
5843 struct spoolss_DevmodeContainer devmode_ctr;
5844 struct sec_desc_buf secdesc_ctr;
5845 struct spoolss_UserLevelCtr userlevel_ctr;
5846 struct policy_handle handle;
5848 bool existing_printer_deleted = false;
5849 struct dcerpc_binding_handle *b = p->binding_handle;
5851 ZERO_STRUCT(devmode_ctr);
5852 ZERO_STRUCT(secdesc_ctr);
5853 ZERO_STRUCT(userlevel_ctr);
5855 torture_comment(tctx, "Testing AddPrinter%s level 2\n", ex ? "Ex":"");
5857 userlevel_ctr.level = 1;
5859 rex.in.server = NULL;
5860 rex.in.info_ctr = &info_ctr;
5861 rex.in.devmode_ctr = &devmode_ctr;
5862 rex.in.secdesc_ctr = &secdesc_ctr;
5863 rex.in.userlevel_ctr = &userlevel_ctr;
5864 rex.out.handle = &handle;
5867 r.in.info_ctr = &info_ctr;
5868 r.in.devmode_ctr = &devmode_ctr;
5869 r.in.secdesc_ctr = &secdesc_ctr;
5870 r.out.handle = &handle;
5874 /* try to add printer to printer list (level 2) */
5878 info_ctr.info.info2 = &info2;
5881 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) :
5882 dcerpc_spoolss_AddPrinter_r(b, tctx, &r),
5883 "failed to add printer");
5884 result = ex ? rex.out.result : r.out.result;
5885 torture_assert_werr_equal(tctx, result, WERR_INVALID_PRINTER_NAME,
5886 "unexpected result code");
5888 info2.printername = printername;
5890 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) :
5891 dcerpc_spoolss_AddPrinter_r(b, tctx, &r),
5892 "failed to add printer");
5893 result = ex ? rex.out.result : r.out.result;
5895 if (W_ERROR_EQUAL(result, WERR_PRINTER_ALREADY_EXISTS)) {
5896 struct policy_handle printer_handle;
5898 if (existing_printer_deleted) {
5899 torture_fail(tctx, "already deleted printer still existing?");
5902 torture_assert(tctx, call_OpenPrinterEx(tctx, p, printername, NULL, &printer_handle),
5903 "failed to open printer handle");
5905 torture_assert(tctx, test_DeletePrinter(tctx, b, &printer_handle),
5906 "failed to delete printer");
5908 torture_assert(tctx, test_ClosePrinter(tctx, b, &printer_handle),
5909 "failed to close server handle");
5911 existing_printer_deleted = true;
5916 torture_assert_werr_equal(tctx, result, WERR_UNKNOWN_PORT,
5917 "unexpected result code");
5919 info2.portname = portname;
5921 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) :
5922 dcerpc_spoolss_AddPrinter_r(b, tctx, &r),
5923 "failed to add printer");
5924 result = ex ? rex.out.result : r.out.result;
5925 torture_assert_werr_equal(tctx, result, WERR_UNKNOWN_PRINTER_DRIVER,
5926 "unexpected result code");
5928 info2.drivername = drivername;
5930 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) :
5931 dcerpc_spoolss_AddPrinter_r(b, tctx, &r),
5932 "failed to add printer");
5933 result = ex ? rex.out.result : r.out.result;
5935 /* w2k8r2 allows to add printer w/o defining printprocessor */
5937 if (!W_ERROR_IS_OK(result)) {
5938 torture_assert_werr_equal(tctx, result, WERR_UNKNOWN_PRINTPROCESSOR,
5939 "unexpected result code");
5941 info2.printprocessor = "winprint";
5943 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) :
5944 dcerpc_spoolss_AddPrinter_r(b, tctx, &r),
5945 "failed to add printer");
5946 result = ex ? rex.out.result : r.out.result;
5947 torture_assert_werr_ok(tctx, result,
5948 "failed to add printer");
5953 /* we are paranoid, really check if the printer is there now */
5955 torture_assert(tctx, test_EnumPrinters_findname(tctx, b,
5956 PRINTER_ENUM_LOCAL, 1,
5959 "failed to enum printers");
5960 torture_assert(tctx, found, "failed to find newly added printer");
5962 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) :
5963 dcerpc_spoolss_AddPrinter_r(b, tctx, &r),
5964 "failed to add printer");
5965 result = ex ? rex.out.result : r.out.result;
5966 torture_assert_werr_equal(tctx, result, WERR_PRINTER_ALREADY_EXISTS,
5967 "unexpected result code");
5972 static bool test_printer_info(struct torture_context *tctx,
5973 struct dcerpc_binding_handle *b,
5974 struct policy_handle *handle)
5978 if (torture_setting_bool(tctx, "samba3", false)) {
5979 torture_skip(tctx, "skipping printer info cross tests against samba 3");
5982 if (!test_PrinterInfo(tctx, b, handle)) {
5986 if (!test_SetPrinter_errors(tctx, b, handle)) {
5993 static bool test_EnumPrinterKey(struct torture_context *tctx,
5994 struct dcerpc_binding_handle *b,
5995 struct policy_handle *handle,
5996 const char *key_name,
5997 const char ***array)
5999 struct spoolss_EnumPrinterKey r;
6000 uint32_t needed = 0;
6001 union spoolss_KeyNames key_buffer;
6002 int32_t offered[] = { 0, 1, 2, 3, 4, 5, -1, -2, -3, -4, -5, 256, 512, 1024, 2048 };
6006 r.in.handle = handle;
6007 r.in.key_name = key_name;
6008 r.out.key_buffer = &key_buffer;
6009 r.out.needed = &needed;
6010 r.out._ndr_size = &_ndr_size;
6012 for (i=0; i < ARRAY_SIZE(offered); i++) {
6014 if (offered[i] < 0 && needed) {
6018 r.in.offered = needed + offered[i];
6020 r.in.offered = offered[i];
6023 ZERO_STRUCT(key_buffer);
6025 torture_comment(tctx, "Testing EnumPrinterKey(%s) with %d offered\n", r.in.key_name, r.in.offered);
6027 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinterKey_r(b, tctx, &r),
6028 "failed to call EnumPrinterKey");
6029 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
6031 torture_assert(tctx, (_ndr_size == r.in.offered/2),
6032 talloc_asprintf(tctx, "EnumPrinterKey size mismatch, _ndr_size %d (expected %d)",
6033 _ndr_size, r.in.offered/2));
6035 r.in.offered = needed;
6036 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinterKey_r(b, tctx, &r),
6037 "failed to call EnumPrinterKey");
6040 if (offered[i] > 0) {
6041 torture_assert_werr_ok(tctx, r.out.result,
6042 "failed to call EnumPrinterKey");
6045 torture_assert(tctx, (_ndr_size == r.in.offered/2),
6046 talloc_asprintf(tctx, "EnumPrinterKey size mismatch, _ndr_size %d (expected %d)",
6047 _ndr_size, r.in.offered/2));
6049 torture_assert(tctx, (*r.out.needed <= r.in.offered),
6050 talloc_asprintf(tctx, "EnumPrinterKey size mismatch: needed %d is not <= offered %d", *r.out.needed, r.in.offered));
6052 torture_assert(tctx, (*r.out.needed <= _ndr_size * 2),
6053 talloc_asprintf(tctx, "EnumPrinterKey size mismatch: needed %d is not <= _ndr_size %d * 2", *r.out.needed, _ndr_size));
6055 if (key_buffer.string_array) {
6056 uint32_t calc_needed = 0;
6058 for (s=0; key_buffer.string_array[s]; s++) {
6059 calc_needed += strlen_m_term(key_buffer.string_array[s])*2;
6061 if (!key_buffer.string_array[0]) {
6066 torture_assert_int_equal(tctx, *r.out.needed, calc_needed,
6067 "EnumPrinterKey unexpected size");
6072 *array = key_buffer.string_array;
6078 bool test_printer_keys(struct torture_context *tctx,
6079 struct dcerpc_binding_handle *b,
6080 struct policy_handle *handle)
6082 const char **key_array = NULL;
6085 torture_comment(tctx, "Testing Printer Keys\n");
6087 torture_assert(tctx, test_EnumPrinterKey(tctx, b, handle, "", &key_array),
6088 "failed to call test_EnumPrinterKey");
6090 for (i=0; key_array && key_array[i]; i++) {
6091 torture_assert(tctx, test_EnumPrinterKey(tctx, b, handle, key_array[i], NULL),
6092 "failed to call test_EnumPrinterKey");
6094 for (i=0; key_array && key_array[i]; i++) {
6095 torture_assert(tctx, test_EnumPrinterDataEx(tctx, b, handle, key_array[i], NULL, NULL),
6096 "failed to call test_EnumPrinterDataEx");
6099 torture_comment(tctx, "Printer Keys test succeeded\n\n");
6104 static bool test_one_printer(struct torture_context *tctx,
6105 struct dcerpc_pipe *p,
6106 struct policy_handle *handle,
6108 const char *drivername,
6109 const char *environment)
6112 struct dcerpc_binding_handle *b = p->binding_handle;
6114 if (!test_PausePrinter(tctx, b, handle)) {
6118 if (!test_DoPrintTest(tctx, b, handle)) {
6122 if (!test_ResumePrinter(tctx, b, handle)) {
6126 if (!test_printer_info(tctx, b, handle)) {
6130 if (!test_PrinterInfo_SD(tctx, b, handle)) {
6134 if (!test_PrinterInfo_DevMode(tctx, p, handle, name)) {
6138 if (!test_PrinterInfo_winreg(tctx, p, handle, name)) {
6142 if (!test_ChangeID(tctx, p, handle)) {
6146 if (!test_printer_keys(tctx, b, handle)) {
6150 if (!test_EnumPrinterData_consistency(tctx, p, handle)) {
6154 if (!test_SetPrinterDataEx_matrix(tctx, p, handle, name, NULL, NULL)) {
6158 if (!test_PrinterData_winreg(tctx, p, handle, name)) {
6162 if (!test_DriverInfo_winreg(tctx, p, handle, name, drivername, environment)) {
6166 if (!test_printer_rename(tctx, p, handle, name)) {
6173 static bool test_csetprinter(struct torture_context *tctx,
6174 struct dcerpc_pipe *p,
6175 struct policy_handle *handle,
6176 const char *printername,
6177 const char *drivername,
6178 const char *portname)
6180 union spoolss_PrinterInfo info;
6181 struct policy_handle new_handle, new_handle2;
6182 struct dcerpc_binding_handle *b = p->binding_handle;
6184 torture_comment(tctx, "Testing c_setprinter\n");
6186 torture_assert(tctx,
6187 test_GetPrinter_level(tctx, b, handle, 0, &info),
6188 "failed to get level 0 printer info");
6189 torture_comment(tctx, "csetprinter on initial printer handle: %d\n",
6190 info.info0.c_setprinter);
6192 /* check if c_setprinter on 1st handle increases after a printer has
6195 torture_assert(tctx,
6196 test_AddPrinter_normal(tctx, p, &new_handle, printername, drivername, portname, false),
6197 "failed to add new printer");
6198 torture_assert(tctx,
6199 test_GetPrinter_level(tctx, b, handle, 0, &info),
6200 "failed to get level 0 printer info");
6201 torture_comment(tctx, "csetprinter on initial printer handle (after add): %d\n",
6202 info.info0.c_setprinter);
6204 /* check if c_setprinter on new handle increases after a printer has
6207 torture_assert(tctx,
6208 test_GetPrinter_level(tctx, b, &new_handle, 0, &info),
6209 "failed to get level 0 printer info");
6210 torture_comment(tctx, "csetprinter on created handle: %d\n",
6211 info.info0.c_setprinter);
6213 /* open the new printer and check if c_setprinter increases */
6215 torture_assert(tctx,
6216 call_OpenPrinterEx(tctx, p, printername, NULL, &new_handle2),
6217 "failed to open created printer");
6218 torture_assert(tctx,
6219 test_GetPrinter_level(tctx, b, &new_handle2, 0, &info),
6220 "failed to get level 0 printer info");
6221 torture_comment(tctx, "csetprinter on new handle (after openprinter): %d\n",
6222 info.info0.c_setprinter);
6226 torture_assert(tctx,
6227 test_ClosePrinter(tctx, b, &new_handle2),
6228 "failed to close printer");
6229 torture_assert(tctx,
6230 test_DeletePrinter(tctx, b, &new_handle),
6231 "failed to delete new printer");
6236 static bool test_add_printer_args(struct torture_context *tctx,
6237 struct dcerpc_pipe *p,
6238 const char *printer_name,
6239 const char *driver_name,
6240 const char *port_name,
6245 struct policy_handle handle;
6246 struct policy_handle printserver_handle;
6248 struct dcerpc_binding_handle *b = p->binding_handle;
6249 const char *environment;
6250 const char *printer_name2 = talloc_asprintf(tctx, "%s2", printer_name);
6252 torture_assert(tctx,
6253 test_OpenPrinter_server(tctx, p, &printserver_handle),
6254 "failed to open printserver");
6255 torture_assert(tctx,
6256 test_get_environment(tctx, b, &printserver_handle, &environment),
6257 "failed to get environment");
6258 torture_assert(tctx,
6259 test_ClosePrinter(tctx, b, &printserver_handle),
6260 "failed to close printserver");
6264 if (torture_setting_bool(tctx, "samba3", false)) {
6265 torture_skip(tctx, "skipping AddPrinter level 1 against samba");
6268 torture_assert(tctx,
6269 test_AddPrinter_wellknown(tctx, p, printer_name, ex),
6270 "failed to add wellknown printer");
6272 torture_assert(tctx,
6273 test_AddPrinter_normal(tctx, p, &handle, printer_name, driver_name, port_name, ex),
6274 "failed to add printer");
6277 if (!test_csetprinter(tctx, p, &handle, printer_name2, driver_name, port_name)) {
6281 if (!test_one_printer(tctx, p, &handle, printer_name, driver_name, environment)) {
6285 if (!test_DeletePrinter(tctx, b, &handle)) {
6289 if (!test_EnumPrinters_findname(tctx, b, PRINTER_ENUM_LOCAL, 1,
6290 printer_name, &found)) {
6294 torture_assert(tctx, !found, "deleted printer still there");
6299 static bool test_add_printer(struct torture_context *tctx,
6300 struct dcerpc_pipe *p)
6302 return test_add_printer_args(tctx, p,
6304 "Microsoft XPS Document Writer",
6309 static bool test_add_printer_wellknown(struct torture_context *tctx,
6310 struct dcerpc_pipe *p)
6312 return test_add_printer_args(tctx, p,
6313 TORTURE_WELLKNOWN_PRINTER,
6314 "Microsoft XPS Document Writer",
6319 static bool test_add_printer_ex(struct torture_context *tctx,
6320 struct dcerpc_pipe *p)
6322 return test_add_printer_args(tctx, p,
6324 "Microsoft XPS Document Writer",
6329 static bool test_add_printer_ex_wellknown(struct torture_context *tctx,
6330 struct dcerpc_pipe *p)
6332 return test_add_printer_args(tctx, p,
6333 TORTURE_WELLKNOWN_PRINTER_EX,
6334 "Microsoft XPS Document Writer",
6339 static bool test_architecture_buffer(struct torture_context *tctx,
6340 struct dcerpc_pipe *p)
6342 struct spoolss_OpenPrinterEx r;
6343 struct spoolss_UserLevel1 u1;
6344 struct policy_handle handle;
6345 uint32_t architectures[] = {
6346 PROCESSOR_ARCHITECTURE_INTEL,
6347 PROCESSOR_ARCHITECTURE_IA64,
6348 PROCESSOR_ARCHITECTURE_AMD64
6352 struct dcerpc_binding_handle *b = p->binding_handle;
6354 for (i=0; i < ARRAY_SIZE(architectures); i++) {
6356 torture_comment(tctx, "Testing OpenPrinterEx with architecture %d\n", architectures[i]);
6364 u1.processor = architectures[i];
6366 r.in.printername = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
6367 r.in.datatype = NULL;
6368 r.in.devmode_ctr.devmode= NULL;
6369 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
6371 r.in.userlevel.level1 = &u1;
6372 r.out.handle = &handle;
6374 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_OpenPrinterEx_r(b, tctx, &r), "");
6375 torture_assert_werr_ok(tctx, r.out.result, "");
6378 struct spoolss_EnumPrinters e;
6380 union spoolss_PrinterInfo *info;
6382 e.in.flags = PRINTER_ENUM_LOCAL;
6387 e.out.count = &count;
6389 e.out.needed = &needed[i];
6391 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinters_r(b, tctx, &e), "");
6393 torture_comment(tctx, "needed was %d\n", needed[i]);
6397 torture_assert(tctx, test_ClosePrinter(tctx, b, &handle), "");
6400 for (i=1; i < ARRAY_SIZE(architectures); i++) {
6401 if (needed[i-1] != needed[i]) {
6403 talloc_asprintf(tctx, "needed size %d for architecture %d != needed size %d for architecture %d\n",
6404 needed[i-1], architectures[i-1], needed[i], architectures[i]));
6411 bool torture_rpc_spoolss(struct torture_context *torture)
6414 struct dcerpc_pipe *p;
6415 struct dcerpc_binding_handle *b;
6417 struct test_spoolss_context *ctx;
6418 const char *environment = SPOOLSS_ARCHITECTURE_NT_X86;
6420 status = torture_rpc_connection(torture, &p, &ndr_table_spoolss);
6421 if (!NT_STATUS_IS_OK(status)) {
6424 b = p->binding_handle;
6426 ctx = talloc_zero(torture, struct test_spoolss_context);
6428 ret &= test_OpenPrinter_server(torture, p, &ctx->server_handle);
6429 ret &= test_GetPrinterData_list(torture, p, &ctx->server_handle, &environment);
6430 ret &= test_EnumForms_all(torture, b, &ctx->server_handle, true);
6431 ret &= test_Forms(torture, b, &ctx->server_handle, true, NULL, NULL, NULL);
6432 ret &= test_Forms_winreg(torture, b, &ctx->server_handle, true, NULL);
6433 ret &= test_EnumPorts(torture, b, ctx);
6434 ret &= test_GetPrinterDriverDirectory(torture, p, environment);
6435 ret &= test_GetPrintProcessorDirectory(torture, p, environment);
6436 ret &= test_EnumPrinterDrivers(torture, p, ctx, environment);
6437 ret &= test_EnumPrinterDrivers(torture, p, ctx, SPOOLSS_ARCHITECTURE_ALL);
6438 ret &= test_EnumMonitors(torture, b, ctx);
6439 ret &= test_EnumPrintProcessors(torture, b, ctx, environment);
6440 ret &= test_EnumPrintProcDataTypes(torture, b);
6441 ret &= test_EnumPrinters(torture, b, ctx);
6442 ret &= test_OpenPrinter_badname_list(torture, b, dcerpc_server_name(p));
6444 ret &= test_AddPort(torture, p);
6445 ret &= test_EnumPorts_old(torture, p);
6446 ret &= test_EnumPrinters_old(torture, p, environment);
6447 ret &= test_EnumPrinterDrivers_old(torture, p, environment);
6448 ret &= test_architecture_buffer(torture, p);
6453 struct torture_suite *torture_rpc_spoolss_printer(TALLOC_CTX *mem_ctx)
6455 struct torture_suite *suite = torture_suite_create(mem_ctx, "SPOOLSS-PRINTER");
6457 struct torture_rpc_tcase *tcase = torture_suite_add_rpc_iface_tcase(suite,
6458 "printer", &ndr_table_spoolss);
6460 torture_rpc_tcase_add_test(tcase, "add_printer", test_add_printer);
6461 torture_rpc_tcase_add_test(tcase, "add_printer_wellknown", test_add_printer_wellknown);
6462 torture_rpc_tcase_add_test(tcase, "add_printer_ex", test_add_printer_ex);
6463 torture_rpc_tcase_add_test(tcase, "add_printer_ex_wellknown", test_add_printer_ex_wellknown);
6468 static bool test_GetPrinterDriverDirectory_getdir(struct torture_context *tctx,
6469 struct dcerpc_binding_handle *b,
6471 const char *environment,
6474 struct spoolss_GetPrinterDriverDirectory r;
6477 r.in.server = server;
6478 r.in.environment = environment;
6482 r.out.needed = &needed;
6484 torture_assert_ntstatus_ok(tctx,
6485 dcerpc_spoolss_GetPrinterDriverDirectory_r(b, tctx, &r),
6486 "failed to query driver directory");
6488 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
6489 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
6490 r.in.buffer = &blob;
6491 r.in.offered = needed;
6493 torture_assert_ntstatus_ok(tctx,
6494 dcerpc_spoolss_GetPrinterDriverDirectory_r(b, tctx, &r),
6495 "failed to query driver directory");
6498 torture_assert_werr_ok(tctx, r.out.result,
6499 "failed to query driver directory");
6502 *dir_p = r.out.info->info1.directory_name;
6508 static const char *get_driver_from_info(struct spoolss_AddDriverInfoCtr *info_ctr)
6510 if (info_ctr == NULL) {
6514 switch (info_ctr->level) {
6516 return info_ctr->info.info1->driver_name;
6518 return info_ctr->info.info2->driver_name;
6520 return info_ctr->info.info3->driver_name;
6522 return info_ctr->info.info4->driver_name;
6524 return info_ctr->info.info6->driver_name;
6526 return info_ctr->info.info8->driver_name;
6532 static bool test_AddPrinterDriver_exp(struct torture_context *tctx,
6533 struct dcerpc_binding_handle *b,
6534 const char *servername,
6535 struct spoolss_AddDriverInfoCtr *info_ctr,
6536 WERROR expected_result)
6538 struct spoolss_AddPrinterDriver r;
6539 const char *drivername = get_driver_from_info(info_ctr);
6541 r.in.servername = servername;
6542 r.in.info_ctr = info_ctr;
6544 torture_comment(tctx, "Testing AddPrinterDriver(%s) level %d\n",
6545 drivername, info_ctr->level);
6547 torture_assert_ntstatus_ok(tctx,
6548 dcerpc_spoolss_AddPrinterDriver_r(b, tctx, &r),
6549 "spoolss_AddPrinterDriver failed");
6550 torture_assert_werr_equal(tctx, r.out.result, expected_result,
6551 "spoolss_AddPrinterDriver failed with unexpected result");
6557 static bool test_AddPrinterDriverEx_exp(struct torture_context *tctx,
6558 struct dcerpc_binding_handle *b,
6559 const char *servername,
6560 struct spoolss_AddDriverInfoCtr *info_ctr,
6562 WERROR expected_result)
6564 struct spoolss_AddPrinterDriverEx r;
6565 const char *drivername = get_driver_from_info(info_ctr);
6567 r.in.servername = servername;
6568 r.in.info_ctr = info_ctr;
6571 torture_comment(tctx, "Testing AddPrinterDriverEx(%s) level %d\n",
6572 drivername, info_ctr->level);
6574 torture_assert_ntstatus_ok(tctx,
6575 dcerpc_spoolss_AddPrinterDriverEx_r(b, tctx, &r),
6576 "AddPrinterDriverEx failed");
6577 torture_assert_werr_equal(tctx, r.out.result, expected_result,
6578 "AddPrinterDriverEx failed with unexpected result");
6583 static bool test_AddPrinterDriver_args_level_1(struct torture_context *tctx,
6584 struct dcerpc_binding_handle *b,
6585 const char *server_name,
6586 struct spoolss_AddDriverInfo8 *r,
6590 struct spoolss_AddDriverInfoCtr info_ctr;
6591 struct spoolss_AddDriverInfo1 info1;
6596 info_ctr.info.info1 = &info1;
6599 torture_assert(tctx,
6600 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_UNKNOWN_LEVEL),
6601 "failed to test AddPrinterDriverEx level 1");
6603 torture_assert(tctx,
6604 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_UNKNOWN_LEVEL),
6605 "failed to test AddPrinterDriver level 1");
6608 info1.driver_name = r->driver_name;
6611 torture_assert(tctx,
6612 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_UNKNOWN_LEVEL),
6613 "failed to test AddPrinterDriverEx level 1");
6615 torture_assert(tctx,
6616 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_UNKNOWN_LEVEL),
6617 "failed to test AddPrinterDriver level 1");
6623 static bool test_AddPrinterDriver_args_level_2(struct torture_context *tctx,
6624 struct dcerpc_binding_handle *b,
6625 const char *server_name,
6626 struct spoolss_AddDriverInfo8 *r,
6630 struct spoolss_AddDriverInfoCtr info_ctr;
6631 struct spoolss_AddDriverInfo2 info2;
6636 info_ctr.info.info2 = &info2;
6639 torture_assert(tctx,
6640 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_INVALID_PARAM),
6641 "failed to test AddPrinterDriverEx level 2");
6643 torture_assert(tctx,
6644 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_INVALID_PARAM),
6645 "failed to test AddPrinterDriver level 2");
6648 info2.driver_name = r->driver_name;
6651 torture_assert(tctx,
6652 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_INVALID_PARAM),
6653 "failed to test AddPrinterDriverEx level 2");
6655 torture_assert(tctx,
6656 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_INVALID_PARAM),
6657 "failed to test AddPrinterDriver level 2");
6660 info2.version = r->version;
6663 torture_assert(tctx,
6664 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_INVALID_PARAM),
6665 "failed to test AddPrinterDriverEx level 2");
6667 torture_assert(tctx,
6668 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_INVALID_PARAM),
6669 "failed to test AddPrinterDriver level 2");
6672 info2.architecture = r->architecture;
6675 torture_assert(tctx,
6676 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_INVALID_PARAM),
6677 "failed to test AddPrinterDriverEx level 2");
6679 torture_assert(tctx,
6680 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_INVALID_PARAM),
6681 "failed to test AddPrinterDriver level 2");
6684 info2.driver_path = r->driver_path;
6687 torture_assert(tctx,
6688 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_INVALID_PARAM),
6689 "failed to test AddPrinterDriverEx level 2");
6691 torture_assert(tctx,
6692 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_INVALID_PARAM),
6693 "failed to test AddPrinterDriver level 2");
6696 info2.data_file = r->data_file;
6699 torture_assert(tctx,
6700 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_INVALID_PARAM),
6701 "failed to test AddPrinterDriverEx level 2");
6703 torture_assert(tctx,
6704 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_INVALID_PARAM),
6705 "failed to test AddPrinterDriver level 2");
6708 info2.config_file = r->config_file;
6711 torture_assert(tctx,
6712 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, 0, WERR_INVALID_PARAM),
6713 "failed to test AddPrinterDriverEx");
6717 torture_assert(tctx,
6718 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_OK),
6719 "failed to test AddPrinterDriverEx level 2");
6721 torture_assert(tctx,
6722 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_OK),
6723 "failed to test AddPrinterDriver level 2");
6726 torture_assert(tctx,
6727 test_EnumPrinterDrivers_findone(tctx, b, server_name, r->architecture, 2, r->driver_name),
6728 "failed to find added printer driver");
6733 static bool test_AddPrinterDriver_args_level_3(struct torture_context *tctx,
6734 struct dcerpc_binding_handle *b,
6735 const char *server_name,
6736 struct spoolss_AddDriverInfo8 *r,
6740 struct spoolss_AddDriverInfoCtr info_ctr;
6741 struct spoolss_AddDriverInfo3 info3;
6745 info3.driver_name = r->driver_name;
6746 info3.version = r->version;
6747 info3.architecture = r->architecture;
6748 info3.driver_path = r->driver_path;
6749 info3.data_file = r->data_file;
6750 info3.config_file = r->config_file;
6753 info_ctr.info.info3 = &info3;
6756 torture_assert(tctx,
6757 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_OK),
6758 "failed to test AddPrinterDriverEx level 3");
6760 torture_assert(tctx,
6761 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_OK),
6762 "failed to test AddPrinterDriver level 3");
6765 torture_assert(tctx,
6766 test_EnumPrinterDrivers_findone(tctx, b, server_name, r->architecture, 3, r->driver_name),
6767 "failed to find added printer driver");
6772 static bool test_AddPrinterDriver_args_level_4(struct torture_context *tctx,
6773 struct dcerpc_binding_handle *b,
6774 const char *server_name,
6775 struct spoolss_AddDriverInfo8 *r,
6779 struct spoolss_AddDriverInfoCtr info_ctr;
6780 struct spoolss_AddDriverInfo4 info4;
6784 info4.driver_name = r->driver_name;
6785 info4.version = r->version;
6786 info4.architecture = r->architecture;
6787 info4.driver_path = r->driver_path;
6788 info4.data_file = r->data_file;
6789 info4.config_file = r->config_file;
6792 info_ctr.info.info4 = &info4;
6795 torture_assert(tctx,
6796 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_OK),
6797 "failed to test AddPrinterDriverEx level 4");
6799 torture_assert(tctx,
6800 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_OK),
6801 "failed to test AddPrinterDriver level 4");
6804 torture_assert(tctx,
6805 test_EnumPrinterDrivers_findone(tctx, b, server_name, r->architecture, 4, r->driver_name),
6806 "failed to find added printer driver");
6811 static bool test_AddPrinterDriver_args_level_6(struct torture_context *tctx,
6812 struct dcerpc_binding_handle *b,
6813 const char *server_name,
6814 struct spoolss_AddDriverInfo8 *r,
6818 struct spoolss_AddDriverInfoCtr info_ctr;
6819 struct spoolss_AddDriverInfo6 info6;
6823 info6.driver_name = r->driver_name;
6824 info6.version = r->version;
6825 info6.architecture = r->architecture;
6826 info6.driver_path = r->driver_path;
6827 info6.data_file = r->data_file;
6828 info6.config_file = r->config_file;
6831 info_ctr.info.info6 = &info6;
6834 torture_assert(tctx,
6835 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_OK),
6836 "failed to test AddPrinterDriverEx level 6");
6838 torture_assert(tctx,
6839 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_UNKNOWN_LEVEL),
6840 "failed to test AddPrinterDriver level 6");
6843 /* spoolss_AddPrinterDriver does not deal with level 6 or 8 - gd */
6849 torture_assert(tctx,
6850 test_EnumPrinterDrivers_findone(tctx, b, server_name, r->architecture, 6, r->driver_name),
6851 "failed to find added printer driver");
6856 static bool test_AddPrinterDriver_args_level_8(struct torture_context *tctx,
6857 struct dcerpc_binding_handle *b,
6858 const char *server_name,
6859 struct spoolss_AddDriverInfo8 *r,
6863 struct spoolss_AddDriverInfoCtr info_ctr;
6864 struct spoolss_AddDriverInfo8 info8;
6868 info8.driver_name = r->driver_name;
6869 info8.version = r->version;
6870 info8.architecture = r->architecture;
6871 info8.driver_path = r->driver_path;
6872 info8.data_file = r->data_file;
6873 info8.config_file = r->config_file;
6876 info_ctr.info.info8 = &info8;
6879 torture_assert(tctx,
6880 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_OK),
6881 "failed to test AddPrinterDriverEx level 8");
6883 torture_assert(tctx,
6884 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_UNKNOWN_LEVEL),
6885 "failed to test AddPrinterDriver level 8");
6888 /* spoolss_AddPrinterDriver does not deal with level 6 or 8 - gd */
6894 torture_assert(tctx,
6895 test_EnumPrinterDrivers_findone(tctx, b, server_name, r->architecture, 8, r->driver_name),
6896 "failed to find added printer driver");
6901 static bool test_DeletePrinterDriver_exp(struct torture_context *tctx,
6902 struct dcerpc_binding_handle *b,
6905 const char *environment,
6906 WERROR expected_result)
6908 struct spoolss_DeletePrinterDriver r;
6910 r.in.server = server;
6911 r.in.architecture = environment;
6912 r.in.driver = driver;
6914 torture_comment(tctx, "Testing DeletePrinterDriver(%s)\n", driver);
6916 torture_assert_ntstatus_ok(tctx,
6917 dcerpc_spoolss_DeletePrinterDriver_r(b, tctx, &r),
6918 "DeletePrinterDriver failed");
6919 torture_assert_werr_equal(tctx, r.out.result, expected_result,
6920 "DeletePrinterDriver failed with unexpected result");
6925 static bool test_DeletePrinterDriverEx_exp(struct torture_context *tctx,
6926 struct dcerpc_binding_handle *b,
6929 const char *environment,
6930 uint32_t delete_flags,
6932 WERROR expected_result)
6934 struct spoolss_DeletePrinterDriverEx r;
6936 r.in.server = server;
6937 r.in.architecture = environment;
6938 r.in.driver = driver;
6939 r.in.delete_flags = delete_flags;
6940 r.in.version = version;
6942 torture_comment(tctx, "Testing DeletePrinterDriverEx(%s)\n", driver);
6944 torture_assert_ntstatus_ok(tctx,
6945 dcerpc_spoolss_DeletePrinterDriverEx_r(b, tctx, &r),
6946 "DeletePrinterDriverEx failed");
6947 torture_assert_werr_equal(tctx, r.out.result, expected_result,
6948 "DeletePrinterDriverEx failed with unexpected result");
6953 static bool test_DeletePrinterDriver(struct torture_context *tctx,
6954 struct dcerpc_binding_handle *b,
6955 const char *server_name,
6957 const char *environment)
6959 torture_assert(tctx,
6960 test_DeletePrinterDriver_exp(tctx, b, server_name, driver, "FOOBAR", WERR_INVALID_ENVIRONMENT),
6961 "failed to delete driver");
6963 torture_assert(tctx,
6964 test_DeletePrinterDriver_exp(tctx, b, server_name, driver, environment, WERR_OK),
6965 "failed to delete driver");
6967 if (test_EnumPrinterDrivers_findone(tctx, b, server_name, environment, 1, driver)) {
6968 torture_fail(tctx, "deleted driver still enumerated");
6971 torture_assert(tctx,
6972 test_DeletePrinterDriver_exp(tctx, b, server_name, driver, environment, WERR_UNKNOWN_PRINTER_DRIVER),
6973 "2nd delete failed");
6978 static bool test_DeletePrinterDriverEx(struct torture_context *tctx,
6979 struct dcerpc_binding_handle *b,
6980 const char *server_name,
6982 const char *environment,
6983 uint32_t delete_flags,
6986 torture_assert(tctx,
6987 test_DeletePrinterDriverEx_exp(tctx, b, server_name, driver, "FOOBAR", delete_flags, version, WERR_INVALID_ENVIRONMENT),
6988 "failed to delete driver");
6990 torture_assert(tctx,
6991 test_DeletePrinterDriverEx_exp(tctx, b, server_name, driver, environment, delete_flags, version, WERR_OK),
6992 "failed to delete driver");
6994 if (test_EnumPrinterDrivers_findone(tctx, b, server_name, environment, 1, driver)) {
6995 torture_fail(tctx, "deleted driver still enumerated");
6998 torture_assert(tctx,
6999 test_DeletePrinterDriverEx_exp(tctx, b, server_name, driver, environment, delete_flags, version, WERR_UNKNOWN_PRINTER_DRIVER),
7000 "2nd delete failed");
7005 static bool test_PrinterDriver_args(struct torture_context *tctx,
7006 struct dcerpc_binding_handle *b,
7007 const char *server_name,
7009 struct spoolss_AddDriverInfo8 *r,
7011 uint32_t delete_flags,
7012 uint32_t delete_version,
7019 ret = test_AddPrinterDriver_args_level_1(tctx, b, server_name, r, add_flags, ex);
7022 ret = test_AddPrinterDriver_args_level_2(tctx, b, server_name, r, add_flags, ex);
7025 ret = test_AddPrinterDriver_args_level_3(tctx, b, server_name, r, add_flags, ex);
7028 ret = test_AddPrinterDriver_args_level_4(tctx, b, server_name, r, add_flags, ex);
7031 ret = test_AddPrinterDriver_args_level_6(tctx, b, server_name, r, add_flags, ex);
7034 ret = test_AddPrinterDriver_args_level_8(tctx, b, server_name, r, add_flags, ex);
7048 /* spoolss_AddPrinterDriver does not deal with level 6 or 8 - gd */
7050 if (!ex && (level == 6 || level == 8)) {
7055 return test_DeletePrinterDriverEx(tctx, b, server_name, r->driver_name, r->architecture, delete_flags, r->version);
7057 return test_DeletePrinterDriver(tctx, b, server_name, r->driver_name, r->architecture);
7061 static bool fillup_printserver_info(struct torture_context *tctx,
7062 struct dcerpc_pipe *p,
7063 struct torture_driver_context *d)
7065 struct policy_handle server_handle;
7066 struct dcerpc_binding_handle *b = p->binding_handle;
7067 const char *server_name_slash = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
7069 torture_assert(tctx,
7070 test_OpenPrinter_server(tctx, p, &server_handle),
7071 "failed to open printserver");
7072 torture_assert(tctx,
7073 test_get_environment(tctx, b, &server_handle, &d->remote.environment),
7074 "failed to get environment");
7075 torture_assert(tctx,
7076 test_ClosePrinter(tctx, b, &server_handle),
7077 "failed to close printserver");
7079 torture_assert(tctx,
7080 test_GetPrinterDriverDirectory_getdir(tctx, b, server_name_slash,
7081 d->local.environment ? d->local.environment : d->remote.environment,
7082 &d->remote.driver_directory),
7083 "failed to get driver directory");
7088 static const char *driver_directory_dir(const char *driver_directory)
7092 p = strrchr(driver_directory, '\\');
7100 static const char *driver_directory_share(struct torture_context *tctx,
7101 const char *driver_directory)
7106 if (driver_directory[0] == '\\' && driver_directory[1] == '\\') {
7107 driver_directory += 2;
7110 p = talloc_strdup(tctx, driver_directory);
7112 torture_assert(tctx,
7113 next_token_talloc(tctx, &p, &tok, "\\"),
7114 "cannot explode uri");
7115 torture_assert(tctx,
7116 next_token_talloc(tctx, &p, &tok, "\\"),
7117 "cannot explode uri");
7122 static bool upload_printer_driver_file(struct torture_context *tctx,
7123 struct smbcli_state *cli,
7124 struct torture_driver_context *d,
7125 const char *file_name)
7130 int maxwrite = 64512;
7133 const char *remote_dir = driver_directory_dir(d->remote.driver_directory);
7134 const char *local_name = talloc_asprintf(tctx, "%s/%s", d->local.driver_directory, file_name);
7135 const char *remote_name = talloc_asprintf(tctx, "%s\\%s", remote_dir, file_name);
7141 torture_comment(tctx, "Uploading %s to %s\n", local_name, remote_name);
7143 fnum = smbcli_open(cli->tree, remote_name, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE);
7145 torture_fail(tctx, talloc_asprintf(tctx, "failed to open remote file: %s\n", remote_name));
7148 f = x_fopen(local_name, O_RDONLY, 0);
7150 torture_fail(tctx, talloc_asprintf(tctx, "failed to open local file: %s\n", local_name));
7153 buf = talloc_array(tctx, uint8_t, maxwrite);
7158 while (!x_feof(f)) {
7162 if ((n = x_fread(buf, 1, n, f)) < 1) {
7163 if((n == 0) && x_feof(f))
7164 break; /* Empty local file. */
7166 torture_warning(tctx,
7167 "failed to read file: %s\n", strerror(errno));
7171 ret = smbcli_write(cli->tree, fnum, 0, buf, nread + start, n);
7174 torture_warning(tctx,
7175 "failed to write file: %s\n", smbcli_errstr(cli->tree));
7184 torture_assert_ntstatus_ok(tctx,
7185 smbcli_close(cli->tree, fnum),
7186 "failed to close file");
7191 static bool connect_printer_driver_share(struct torture_context *tctx,
7192 const char *server_name,
7193 const char *share_name,
7194 struct smbcli_state **cli)
7196 struct smbcli_options smb_options;
7197 struct smbcli_session_options smb_session_options;
7199 torture_comment(tctx, "Connecting printer driver share\n");
7201 lp_smbcli_options(tctx->lp_ctx, &smb_options);
7202 lp_smbcli_session_options(tctx->lp_ctx, &smb_session_options);
7204 torture_assert_ntstatus_ok(tctx,
7205 smbcli_full_connection(tctx, cli, server_name,
7206 lp_smb_ports(tctx->lp_ctx),
7208 lp_socket_options(tctx->lp_ctx),
7209 cmdline_credentials,
7210 lp_resolve_context(tctx->lp_ctx),
7213 &smb_session_options,
7214 lp_iconv_convenience(tctx->lp_ctx),
7215 lp_gensec_settings(tctx, tctx->lp_ctx)),
7216 "failed to open driver share");
7221 static bool upload_printer_driver(struct torture_context *tctx,
7222 const char *server_name,
7223 struct torture_driver_context *d)
7225 struct smbcli_state *cli;
7226 const char *share_name = driver_directory_share(tctx, d->remote.driver_directory);
7229 torture_assert(tctx,
7230 connect_printer_driver_share(tctx, server_name, share_name, &cli),
7231 "failed to connect to driver share");
7233 torture_comment(tctx, "Uploading printer driver files to \\\\%s\\%s\n",
7234 server_name, share_name);
7236 torture_assert(tctx,
7237 upload_printer_driver_file(tctx, cli, d, d->info8.driver_path),
7238 "failed to upload driver_path");
7239 torture_assert(tctx,
7240 upload_printer_driver_file(tctx, cli, d, d->info8.data_file),
7241 "failed to upload data_file");
7242 torture_assert(tctx,
7243 upload_printer_driver_file(tctx, cli, d, d->info8.config_file),
7244 "failed to upload config_file");
7245 torture_assert(tctx,
7246 upload_printer_driver_file(tctx, cli, d, d->info8.help_file),
7247 "failed to upload help_file");
7248 if (d->info8.dependent_files) {
7249 for (i=0; d->info8.dependent_files->string && d->info8.dependent_files->string[i] != NULL; i++) {
7250 torture_assert(tctx,
7251 upload_printer_driver_file(tctx, cli, d, d->info8.dependent_files->string[i]),
7252 "failed to upload dependent_files");
7261 static bool remove_printer_driver_file(struct torture_context *tctx,
7262 struct smbcli_state *cli,
7263 struct torture_driver_context *d,
7264 const char *file_name)
7266 const char *remote_name;
7267 const char *remote_dir = driver_directory_dir(d->remote.driver_directory);
7273 remote_name = talloc_asprintf(tctx, "%s\\%s", remote_dir, file_name);
7275 torture_comment(tctx, "Removing %s\n", remote_name);
7277 torture_assert_ntstatus_ok(tctx,
7278 smbcli_unlink(cli->tree, remote_name),
7279 "failed to unlink");
7284 static bool remove_printer_driver(struct torture_context *tctx,
7285 const char *server_name,
7286 struct torture_driver_context *d)
7288 struct smbcli_state *cli;
7289 const char *share_name = driver_directory_share(tctx, d->remote.driver_directory);
7292 torture_assert(tctx,
7293 connect_printer_driver_share(tctx, server_name, share_name, &cli),
7294 "failed to connect to driver share");
7296 torture_comment(tctx, "Removing printer driver files from \\\\%s\\%s\n",
7297 server_name, share_name);
7299 torture_assert(tctx,
7300 remove_printer_driver_file(tctx, cli, d, d->info8.driver_path),
7301 "failed to remove driver_path");
7302 torture_assert(tctx,
7303 remove_printer_driver_file(tctx, cli, d, d->info8.data_file),
7304 "failed to remove data_file");
7305 torture_assert(tctx,
7306 remove_printer_driver_file(tctx, cli, d, d->info8.config_file),
7307 "failed to remove config_file");
7308 torture_assert(tctx,
7309 remove_printer_driver_file(tctx, cli, d, d->info8.help_file),
7310 "failed to remove help_file");
7311 if (d->info8.dependent_files) {
7312 for (i=0; d->info8.dependent_files->string && d->info8.dependent_files->string[i] != NULL; i++) {
7313 torture_assert(tctx,
7314 remove_printer_driver_file(tctx, cli, d, d->info8.dependent_files->string[i]),
7315 "failed to remove dependent_files");
7325 static bool test_add_driver_arg(struct torture_context *tctx,
7326 struct dcerpc_pipe *p,
7327 struct torture_driver_context *d)
7330 struct dcerpc_binding_handle *b = p->binding_handle;
7331 const char *server_name_slash = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
7332 uint32_t levels[] = { 1, 2, 3, 4, 6, 8 };
7334 struct spoolss_AddDriverInfo8 info8;
7335 uint32_t add_flags = APD_COPY_NEW_FILES;
7336 uint32_t delete_flags = 0;
7338 torture_comment(tctx, "Testing PrinterDriver%s '%s' for environment '%s'\n",
7339 d->ex ? "Ex" : "", d->info8.driver_name, d->local.environment);
7341 torture_assert(tctx,
7342 fillup_printserver_info(tctx, p, d),
7343 "failed to fillup printserver info");
7345 if (!directory_exist(d->local.driver_directory)) {
7346 torture_skip(tctx, "Skipping Printer Driver test as no local driver is available");
7349 torture_assert(tctx,
7350 upload_printer_driver(tctx, dcerpc_server_name(p), d),
7351 "failed to upload printer driver");
7353 info8.version = d->info8.version;
7354 info8.driver_name = d->info8.driver_name;
7355 info8.architecture = d->local.environment;
7356 info8.driver_path = d->info8.driver_path;
7357 info8.data_file = d->info8.data_file;
7358 info8.config_file = d->info8.config_file;
7360 for (i=0; i < ARRAY_SIZE(levels); i++) {
7362 if (torture_setting_bool(tctx, "samba3", false)) {
7363 switch (levels[i]) {
7367 torture_comment(tctx, "skipping level %d against samba\n", levels[i]);
7374 torture_comment(tctx,
7375 "Testing PrinterDriver%s '%s' add & delete level %d\n",
7376 d->ex ? "Ex" : "", info8.driver_name, levels[i]);
7378 ret &= test_PrinterDriver_args(tctx, b, server_name_slash, levels[i], &info8, add_flags, delete_flags, d->info8.version, d->ex);
7381 info8.driver_path = talloc_asprintf(tctx, "%s\\%s", d->remote.driver_directory, d->info8.driver_path);
7382 info8.data_file = talloc_asprintf(tctx, "%s\\%s", d->remote.driver_directory, d->info8.data_file);
7383 info8.config_file = talloc_asprintf(tctx, "%s\\%s", d->remote.driver_directory, d->info8.config_file);
7385 for (i=0; i < ARRAY_SIZE(levels); i++) {
7387 if (torture_setting_bool(tctx, "samba3", false)) {
7388 switch (levels[i]) {
7392 torture_comment(tctx, "skipping level %d against samba\n", levels[i]);
7400 torture_comment(tctx,
7401 "Testing PrinterDriver%s '%s' add & delete level %d (full unc paths)\n",
7402 d->ex ? "Ex" : "", info8.driver_name, levels[i]);
7404 ret &= test_PrinterDriver_args(tctx, b, server_name_slash, levels[i], &info8, add_flags, delete_flags, d->info8.version, d->ex);
7407 torture_assert(tctx,
7408 remove_printer_driver(tctx, dcerpc_server_name(p), d),
7409 "failed to remove printer driver");
7411 torture_comment(tctx, "\n");
7416 static bool test_add_driver_ex_64(struct torture_context *tctx,
7417 struct dcerpc_pipe *p,
7420 struct torture_driver_context *d =
7421 (struct torture_driver_context *)talloc_get_type_abort(private_data, struct torture_driver_context);
7423 d->local.environment = talloc_strdup(d, "Windows x64");
7424 d->local.driver_directory = talloc_strdup(d, "/usr/share/cups/drivers/x64");
7425 d->info8.driver_name = TORTURE_DRIVER_EX;
7428 return test_add_driver_arg(tctx, p, d);
7431 static bool test_add_driver_ex_32(struct torture_context *tctx,
7432 struct dcerpc_pipe *p,
7435 struct torture_driver_context *d =
7436 (struct torture_driver_context *)talloc_get_type_abort(private_data, struct torture_driver_context);
7438 d->local.environment = talloc_strdup(d, "Windows NT x86");
7439 d->local.driver_directory = talloc_strdup(d, "/usr/share/cups/drivers/i386");
7440 d->info8.driver_name = TORTURE_DRIVER_EX;
7443 return test_add_driver_arg(tctx, p, d);
7446 static bool test_add_driver_64(struct torture_context *tctx,
7447 struct dcerpc_pipe *p,
7450 struct torture_driver_context *d =
7451 (struct torture_driver_context *)talloc_get_type_abort(private_data, struct torture_driver_context);
7453 d->local.environment = talloc_strdup(d, "Windows x64");
7454 d->local.driver_directory = talloc_strdup(d, "/usr/share/cups/drivers/x64");
7455 d->info8.driver_name = TORTURE_DRIVER;
7458 return test_add_driver_arg(tctx, p, d);
7461 static bool test_add_driver_32(struct torture_context *tctx,
7462 struct dcerpc_pipe *p,
7465 struct torture_driver_context *d =
7466 (struct torture_driver_context *)talloc_get_type_abort(private_data, struct torture_driver_context);
7468 d->local.environment = talloc_strdup(d, "Windows NT x86");
7469 d->local.driver_directory = talloc_strdup(d, "/usr/share/cups/drivers/i386");
7470 d->info8.driver_name = TORTURE_DRIVER;
7473 return test_add_driver_arg(tctx, p, d);
7476 struct torture_suite *torture_rpc_spoolss_driver(TALLOC_CTX *mem_ctx)
7478 struct torture_suite *suite = torture_suite_create(mem_ctx, "SPOOLSS-DRIVER");
7480 struct torture_rpc_tcase *tcase = torture_suite_add_rpc_iface_tcase(suite,
7481 "driver", &ndr_table_spoolss);
7482 struct torture_driver_context *t;
7484 t = talloc_zero(mem_ctx, struct torture_driver_context);
7486 t->info8.version = SPOOLSS_DRIVER_VERSION_200X;
7487 t->info8.driver_name = NULL;
7488 t->info8.architecture = NULL;
7489 t->info8.driver_path = talloc_strdup(t, "pscript5.dll");
7490 t->info8.data_file = talloc_strdup(t, "cups6.ppd");
7491 t->info8.config_file = talloc_strdup(t, "cupsui6.dll");
7493 torture_rpc_tcase_add_test_ex(tcase, "add_driver_64", test_add_driver_64, t);
7494 torture_rpc_tcase_add_test_ex(tcase, "add_driver_ex_64", test_add_driver_ex_64, t);
7496 torture_rpc_tcase_add_test_ex(tcase, "add_driver_32", test_add_driver_32, t);
7497 torture_rpc_tcase_add_test_ex(tcase, "add_driver_ex_32", test_add_driver_ex_32, t);