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 struct torture_printer_context {
94 struct spoolss_SetPrinterInfo2 info2;
95 struct torture_driver_context driver;
102 static bool upload_printer_driver(struct torture_context *tctx,
103 const char *server_name,
104 struct torture_driver_context *d);
105 static bool remove_printer_driver(struct torture_context *tctx,
106 const char *server_name,
107 struct torture_driver_context *d);
108 static bool fillup_printserver_info(struct torture_context *tctx,
109 struct dcerpc_pipe *p,
110 struct torture_driver_context *d);
111 static bool test_AddPrinterDriver_args_level_3(struct torture_context *tctx,
112 struct dcerpc_binding_handle *b,
113 const char *server_name,
114 struct spoolss_AddDriverInfo8 *r,
118 #define COMPARE_STRING(tctx, c,r,e) \
119 torture_assert_str_equal(tctx, c.e, r.e, "invalid value")
121 /* not every compiler supports __typeof__() */
123 #define _CHECK_FIELD_SIZE(c,r,e,type) do {\
124 if (sizeof(__typeof__(c.e)) != sizeof(type)) { \
125 torture_fail(tctx, #c "." #e "field is not " #type "\n"); \
127 if (sizeof(__typeof__(r.e)) != sizeof(type)) { \
128 torture_fail(tctx, #r "." #e "field is not " #type "\n"); \
132 #define _CHECK_FIELD_SIZE(c,r,e,type) do {} while(0)
135 #define COMPARE_UINT32(tctx, c, r, e) do {\
136 _CHECK_FIELD_SIZE(c, r, e, uint32_t); \
137 torture_assert_int_equal(tctx, c.e, r.e, "invalid value"); \
140 #define COMPARE_UINT64(tctx, c, r, e) do {\
141 _CHECK_FIELD_SIZE(c, r, e, uint64_t); \
142 torture_assert_int_equal(tctx, c.e, r.e, "invalid value"); \
146 #define COMPARE_NTTIME(tctx, c, r, e) do {\
147 _CHECK_FIELD_SIZE(c, r, e, NTTIME); \
148 torture_assert_int_equal(tctx, c.e, r.e, "invalid value"); \
151 #define COMPARE_STRING_ARRAY(tctx, c,r,e) do {\
153 if (!c.e && !r.e) { \
157 torture_fail(tctx, #r "." #e " field is NULL and " #c "." #e " is not\n"); \
160 torture_fail(tctx, #c "." #e " field is NULL and " #r "." #e " is not\n"); \
162 for (__i=0;c.e[__i] != NULL; __i++) { \
163 torture_assert_str_equal(tctx, c.e[__i], r.e[__i], "invalid value"); \
167 #define CHECK_ALIGN(size, n) do {\
169 torture_warning(tctx, "%d is *NOT* %d byte aligned, should be %d",\
170 size, n, size + n - (size % n));\
174 #define DO_ROUND(size, n) (((size)+((n)-1)) & ~((n)-1))
176 #define CHECK_NEEDED_SIZE_ENUM_LEVEL(fn, info, level, count, ic, needed, align) do { \
177 if (torture_setting_bool(tctx, "spoolss_check_size", false)) {\
178 uint32_t size = ndr_size_##fn##_info(tctx, ic, level, count, info);\
179 uint32_t round_size = DO_ROUND(size, align);\
180 if (round_size != needed) {\
181 torture_warning(tctx, __location__": "#fn" level %d (count: %d) got unexpected needed size: %d, we calculated: %d", level, count, needed, round_size);\
182 CHECK_ALIGN(size, align);\
187 #define CHECK_NEEDED_SIZE_ENUM(fn, info, count, ic, needed, align) do { \
188 if (torture_setting_bool(tctx, "spoolss_check_size", false)) {\
189 uint32_t size = ndr_size_##fn##_info(tctx, ic, count, info);\
190 uint32_t round_size = DO_ROUND(size, align);\
191 if (round_size != needed) {\
192 torture_warning(tctx, __location__": "#fn" (count: %d) got unexpected needed size: %d, we calculated: %d", count, needed, round_size);\
193 CHECK_ALIGN(size, align);\
198 #define CHECK_NEEDED_SIZE_LEVEL(fn, info, level, ic, needed, align) do { \
199 if (torture_setting_bool(tctx, "spoolss_check_size", false)) {\
200 uint32_t size = ndr_size_##fn(info, level, ic, 0);\
201 uint32_t round_size = DO_ROUND(size, align);\
202 if (round_size != needed) {\
203 torture_warning(tctx, __location__": "#fn" level %d got unexpected needed size: %d, we calculated: %d", level, needed, round_size);\
204 CHECK_ALIGN(size, align);\
209 static bool PrinterInfo_to_SetPrinterInfo(struct torture_context *tctx,
210 const union spoolss_PrinterInfo *i,
212 union spoolss_SetPrinterInfo *s)
216 s->info0 = talloc(tctx, struct spoolss_SetPrinterInfo0);
219 s->info2 = talloc(tctx, struct spoolss_SetPrinterInfo2);
220 s->info2->servername = i->info2.servername;
221 s->info2->printername = i->info2.printername;
222 s->info2->sharename = i->info2.sharename;
223 s->info2->portname = i->info2.portname;
224 s->info2->drivername = i->info2.drivername;
225 s->info2->comment = i->info2.comment;
226 s->info2->location = i->info2.location;
227 s->info2->devmode_ptr = 0;
228 s->info2->sepfile = i->info2.sepfile;
229 s->info2->printprocessor = i->info2.printprocessor;
230 s->info2->datatype = i->info2.datatype;
231 s->info2->parameters = i->info2.parameters;
232 s->info2->secdesc_ptr = 0;
233 s->info2->attributes = i->info2.attributes;
234 s->info2->priority = i->info2.priority;
235 s->info2->defaultpriority = i->info2.defaultpriority;
236 s->info2->starttime = i->info2.starttime;
237 s->info2->untiltime = i->info2.untiltime;
238 s->info2->status = i->info2.status;
239 s->info2->cjobs = i->info2.cjobs;
240 s->info2->averageppm = i->info2.averageppm;
256 static bool test_OpenPrinter_server(struct torture_context *tctx,
257 struct dcerpc_pipe *p,
258 struct policy_handle *server_handle)
261 struct spoolss_OpenPrinter op;
262 struct dcerpc_binding_handle *b = p->binding_handle;
264 op.in.printername = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
265 op.in.datatype = NULL;
266 op.in.devmode_ctr.devmode= NULL;
267 op.in.access_mask = 0;
268 op.out.handle = server_handle;
270 torture_comment(tctx, "Testing OpenPrinter(%s)\n", op.in.printername);
272 status = dcerpc_spoolss_OpenPrinter_r(b, tctx, &op);
273 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_OpenPrinter failed");
274 torture_assert_werr_ok(tctx, op.out.result, "dcerpc_spoolss_OpenPrinter failed");
279 static bool test_EnumPorts(struct torture_context *tctx,
280 struct dcerpc_binding_handle *b,
281 struct test_spoolss_context *ctx)
284 struct spoolss_EnumPorts r;
285 uint16_t levels[] = { 1, 2 };
288 for (i=0;i<ARRAY_SIZE(levels);i++) {
289 int level = levels[i];
293 union spoolss_PortInfo *info;
295 r.in.servername = "";
299 r.out.needed = &needed;
300 r.out.count = &count;
303 torture_comment(tctx, "Testing EnumPorts level %u\n", r.in.level);
305 status = dcerpc_spoolss_EnumPorts_r(b, ctx, &r);
306 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPorts failed");
307 if (W_ERROR_IS_OK(r.out.result)) {
308 /* TODO: do some more checks here */
311 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
312 "EnumPorts unexpected return code");
314 blob = data_blob_talloc_zero(ctx, needed);
316 r.in.offered = needed;
318 status = dcerpc_spoolss_EnumPorts_r(b, ctx, &r);
319 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPorts failed");
321 torture_assert_werr_ok(tctx, r.out.result, "EnumPorts failed");
323 torture_assert(tctx, info, "EnumPorts returned no info");
325 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPorts, info, r.in.level, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
327 ctx->port_count[level] = count;
328 ctx->ports[level] = info;
331 for (i=1;i<ARRAY_SIZE(levels);i++) {
332 int level = levels[i];
333 int old_level = levels[i-1];
334 torture_assert_int_equal(tctx, ctx->port_count[level], ctx->port_count[old_level],
335 "EnumPorts invalid value");
337 /* if the array sizes are not the same we would maybe segfault in the following code */
339 for (i=0;i<ARRAY_SIZE(levels);i++) {
340 int level = levels[i];
341 for (j=0;j<ctx->port_count[level];j++) {
342 union spoolss_PortInfo *cur = &ctx->ports[level][j];
343 union spoolss_PortInfo *ref = &ctx->ports[2][j];
346 COMPARE_STRING(tctx, cur->info1, ref->info2, port_name);
349 /* level 2 is our reference, and it makes no sense to compare it to itself */
358 static bool test_GetPrintProcessorDirectory(struct torture_context *tctx,
359 struct dcerpc_pipe *p,
360 const char *environment)
363 struct dcerpc_binding_handle *b = p->binding_handle;
364 struct spoolss_GetPrintProcessorDirectory r;
379 .server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p))
382 .server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p))
388 for (i=0;i<ARRAY_SIZE(levels);i++) {
389 int level = levels[i].level;
392 r.in.server = levels[i].server;
393 r.in.environment = environment;
397 r.out.needed = &needed;
399 torture_comment(tctx, "Testing GetPrintProcessorDirectory level %u\n", r.in.level);
401 status = dcerpc_spoolss_GetPrintProcessorDirectory_r(b, tctx, &r);
402 torture_assert_ntstatus_ok(tctx, status,
403 "dcerpc_spoolss_GetPrintProcessorDirectory failed");
404 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
405 "GetPrintProcessorDirectory unexpected return code");
407 blob = data_blob_talloc_zero(tctx, needed);
409 r.in.offered = needed;
411 status = dcerpc_spoolss_GetPrintProcessorDirectory_r(b, tctx, &r);
412 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_GetPrintProcessorDirectory failed");
414 torture_assert_werr_ok(tctx, r.out.result, "GetPrintProcessorDirectory failed");
416 CHECK_NEEDED_SIZE_LEVEL(spoolss_PrintProcessorDirectoryInfo, r.out.info, r.in.level, lp_iconv_convenience(tctx->lp_ctx), needed, 2);
423 static bool test_GetPrinterDriverDirectory(struct torture_context *tctx,
424 struct dcerpc_pipe *p,
425 const char *environment)
428 struct dcerpc_binding_handle *b = p->binding_handle;
429 struct spoolss_GetPrinterDriverDirectory r;
444 .server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p))
447 .server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p))
453 for (i=0;i<ARRAY_SIZE(levels);i++) {
454 int level = levels[i].level;
457 r.in.server = levels[i].server;
458 r.in.environment = environment;
462 r.out.needed = &needed;
464 torture_comment(tctx, "Testing GetPrinterDriverDirectory level %u\n", r.in.level);
466 status = dcerpc_spoolss_GetPrinterDriverDirectory_r(b, tctx, &r);
467 torture_assert_ntstatus_ok(tctx, status,
468 "dcerpc_spoolss_GetPrinterDriverDirectory failed");
469 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
470 "GetPrinterDriverDirectory unexpected return code");
472 blob = data_blob_talloc_zero(tctx, needed);
474 r.in.offered = needed;
476 status = dcerpc_spoolss_GetPrinterDriverDirectory_r(b, tctx, &r);
477 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_GetPrinterDriverDirectory failed");
479 torture_assert_werr_ok(tctx, r.out.result, "GetPrinterDriverDirectory failed");
481 CHECK_NEEDED_SIZE_LEVEL(spoolss_DriverDirectoryInfo, r.out.info, r.in.level, lp_iconv_convenience(tctx->lp_ctx), needed, 2);
487 static bool test_EnumPrinterDrivers_args(struct torture_context *tctx,
488 struct dcerpc_binding_handle *b,
489 const char *server_name,
490 const char *environment,
493 union spoolss_DriverInfo **info_p)
495 struct spoolss_EnumPrinterDrivers r;
498 union spoolss_DriverInfo *info;
500 r.in.server = server_name;
501 r.in.environment = environment;
505 r.out.needed = &needed;
506 r.out.count = &count;
509 torture_comment(tctx, "Testing EnumPrinterDrivers(%s) level %u\n",
510 r.in.environment, r.in.level);
512 torture_assert_ntstatus_ok(tctx,
513 dcerpc_spoolss_EnumPrinterDrivers_r(b, tctx, &r),
514 "EnumPrinterDrivers failed");
515 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
516 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
518 r.in.offered = needed;
520 torture_assert_ntstatus_ok(tctx,
521 dcerpc_spoolss_EnumPrinterDrivers_r(b, tctx, &r),
522 "EnumPrinterDrivers failed");
525 torture_assert_werr_ok(tctx, r.out.result,
526 "EnumPrinterDrivers failed");
535 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPrinterDrivers, info, r.in.level, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
541 static bool test_EnumPrinterDrivers_findone(struct torture_context *tctx,
542 struct dcerpc_binding_handle *b,
543 const char *server_name,
544 const char *environment,
546 const char *driver_name)
549 union spoolss_DriverInfo *info;
553 test_EnumPrinterDrivers_args(tctx, b, server_name, environment, level, &count, &info),
554 "failed to enumerate printer drivers");
556 for (i=0; i < count; i++) {
557 const char *driver_name_ret;
560 driver_name_ret = info[i].info1.driver_name;
563 driver_name_ret = info[i].info2.driver_name;
566 driver_name_ret = info[i].info3.driver_name;
569 driver_name_ret = info[i].info4.driver_name;
572 driver_name_ret = info[i].info5.driver_name;
575 driver_name_ret = info[i].info6.driver_name;
578 driver_name_ret = info[i].info7.driver_name;
581 driver_name_ret = info[i].info8.driver_name;
586 if (strequal(driver_name, driver_name_ret)) {
594 static bool test_EnumPrinterDrivers(struct torture_context *tctx,
595 struct dcerpc_pipe *p,
596 struct test_spoolss_context *ctx,
597 const char *architecture)
599 struct dcerpc_binding_handle *b = p->binding_handle;
600 uint16_t levels[] = { 1, 2, 3, 4, 5, 6, 8 };
603 /* FIXME: gd, come back and fix "" as server, and handle
604 * priority of returned error codes in torture test and samba 3
606 const char *server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
608 for (i=0;i<ARRAY_SIZE(levels);i++) {
609 int level = levels[i];
611 union spoolss_DriverInfo *info;
614 test_EnumPrinterDrivers_args(tctx, b, server_name, architecture, level, &count, &info),
615 "failed to enumerate drivers");
617 ctx->driver_count[level] = count;
618 ctx->drivers[level] = info;
621 for (i=1;i<ARRAY_SIZE(levels);i++) {
622 int level = levels[i];
623 int old_level = levels[i-1];
625 torture_assert_int_equal(tctx, ctx->driver_count[level], ctx->driver_count[old_level],
626 "EnumPrinterDrivers invalid value");
629 for (i=0;i<ARRAY_SIZE(levels);i++) {
630 int level = levels[i];
632 for (j=0;j<ctx->driver_count[level];j++) {
633 union spoolss_DriverInfo *cur = &ctx->drivers[level][j];
634 union spoolss_DriverInfo *ref = &ctx->drivers[8][j];
638 COMPARE_STRING(tctx, cur->info1, ref->info8, driver_name);
641 COMPARE_UINT32(tctx, cur->info2, ref->info8, version);
642 COMPARE_STRING(tctx, cur->info2, ref->info8, driver_name);
643 COMPARE_STRING(tctx, cur->info2, ref->info8, architecture);
644 COMPARE_STRING(tctx, cur->info2, ref->info8, driver_path);
645 COMPARE_STRING(tctx, cur->info2, ref->info8, data_file);
646 COMPARE_STRING(tctx, cur->info2, ref->info8, config_file);
649 COMPARE_UINT32(tctx, cur->info3, ref->info8, version);
650 COMPARE_STRING(tctx, cur->info3, ref->info8, driver_name);
651 COMPARE_STRING(tctx, cur->info3, ref->info8, architecture);
652 COMPARE_STRING(tctx, cur->info3, ref->info8, driver_path);
653 COMPARE_STRING(tctx, cur->info3, ref->info8, data_file);
654 COMPARE_STRING(tctx, cur->info3, ref->info8, config_file);
655 COMPARE_STRING(tctx, cur->info3, ref->info8, help_file);
656 COMPARE_STRING_ARRAY(tctx, cur->info3, ref->info8, dependent_files);
657 COMPARE_STRING(tctx, cur->info3, ref->info8, monitor_name);
658 COMPARE_STRING(tctx, cur->info3, ref->info8, default_datatype);
661 COMPARE_UINT32(tctx, cur->info4, ref->info8, version);
662 COMPARE_STRING(tctx, cur->info4, ref->info8, driver_name);
663 COMPARE_STRING(tctx, cur->info4, ref->info8, architecture);
664 COMPARE_STRING(tctx, cur->info4, ref->info8, driver_path);
665 COMPARE_STRING(tctx, cur->info4, ref->info8, data_file);
666 COMPARE_STRING(tctx, cur->info4, ref->info8, config_file);
667 COMPARE_STRING(tctx, cur->info4, ref->info8, help_file);
668 COMPARE_STRING_ARRAY(tctx, cur->info4, ref->info8, dependent_files);
669 COMPARE_STRING(tctx, cur->info4, ref->info8, monitor_name);
670 COMPARE_STRING(tctx, cur->info4, ref->info8, default_datatype);
671 COMPARE_STRING_ARRAY(tctx, cur->info4, ref->info8, previous_names);
674 COMPARE_UINT32(tctx, cur->info5, ref->info8, version);
675 COMPARE_STRING(tctx, cur->info5, ref->info8, driver_name);
676 COMPARE_STRING(tctx, cur->info5, ref->info8, architecture);
677 COMPARE_STRING(tctx, cur->info5, ref->info8, driver_path);
678 COMPARE_STRING(tctx, cur->info5, ref->info8, data_file);
679 COMPARE_STRING(tctx, cur->info5, ref->info8, config_file);
680 /*COMPARE_UINT32(tctx, cur->info5, ref->info8, driver_attributes);*/
681 /*COMPARE_UINT32(tctx, cur->info5, ref->info8, config_version);*/
682 /*TODO: ! COMPARE_UINT32(tctx, cur->info5, ref->info8, driver_version); */
685 COMPARE_UINT32(tctx, cur->info6, ref->info8, version);
686 COMPARE_STRING(tctx, cur->info6, ref->info8, driver_name);
687 COMPARE_STRING(tctx, cur->info6, ref->info8, architecture);
688 COMPARE_STRING(tctx, cur->info6, ref->info8, driver_path);
689 COMPARE_STRING(tctx, cur->info6, ref->info8, data_file);
690 COMPARE_STRING(tctx, cur->info6, ref->info8, config_file);
691 COMPARE_STRING(tctx, cur->info6, ref->info8, help_file);
692 COMPARE_STRING_ARRAY(tctx, cur->info6, ref->info8, dependent_files);
693 COMPARE_STRING(tctx, cur->info6, ref->info8, monitor_name);
694 COMPARE_STRING(tctx, cur->info6, ref->info8, default_datatype);
695 COMPARE_STRING_ARRAY(tctx, cur->info6, ref->info8, previous_names);
696 COMPARE_NTTIME(tctx, cur->info6, ref->info8, driver_date);
697 COMPARE_UINT64(tctx, cur->info6, ref->info8, driver_version);
698 COMPARE_STRING(tctx, cur->info6, ref->info8, manufacturer_name);
699 COMPARE_STRING(tctx, cur->info6, ref->info8, manufacturer_url);
700 COMPARE_STRING(tctx, cur->info6, ref->info8, hardware_id);
701 COMPARE_STRING(tctx, cur->info6, ref->info8, provider);
704 /* level 8 is our reference, and it makes no sense to compare it to itself */
713 static bool test_EnumMonitors(struct torture_context *tctx,
714 struct dcerpc_binding_handle *b,
715 struct test_spoolss_context *ctx)
718 struct spoolss_EnumMonitors r;
719 uint16_t levels[] = { 1, 2 };
722 for (i=0;i<ARRAY_SIZE(levels);i++) {
723 int level = levels[i];
727 union spoolss_MonitorInfo *info;
729 r.in.servername = "";
733 r.out.needed = &needed;
734 r.out.count = &count;
737 torture_comment(tctx, "Testing EnumMonitors level %u\n", r.in.level);
739 status = dcerpc_spoolss_EnumMonitors_r(b, ctx, &r);
740 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumMonitors failed");
741 if (W_ERROR_IS_OK(r.out.result)) {
742 /* TODO: do some more checks here */
745 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
746 "EnumMonitors failed");
748 blob = data_blob_talloc_zero(ctx, needed);
750 r.in.offered = needed;
752 status = dcerpc_spoolss_EnumMonitors_r(b, ctx, &r);
753 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumMonitors failed");
755 torture_assert_werr_ok(tctx, r.out.result, "EnumMonitors failed");
757 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumMonitors, info, r.in.level, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
759 ctx->monitor_count[level] = count;
760 ctx->monitors[level] = info;
763 for (i=1;i<ARRAY_SIZE(levels);i++) {
764 int level = levels[i];
765 int old_level = levels[i-1];
766 torture_assert_int_equal(tctx, ctx->monitor_count[level], ctx->monitor_count[old_level],
767 "EnumMonitors invalid value");
770 for (i=0;i<ARRAY_SIZE(levels);i++) {
771 int level = levels[i];
772 for (j=0;j<ctx->monitor_count[level];j++) {
773 union spoolss_MonitorInfo *cur = &ctx->monitors[level][j];
774 union spoolss_MonitorInfo *ref = &ctx->monitors[2][j];
777 COMPARE_STRING(tctx, cur->info1, ref->info2, monitor_name);
780 /* level 2 is our reference, and it makes no sense to compare it to itself */
789 static bool test_EnumPrintProcessors(struct torture_context *tctx,
790 struct dcerpc_binding_handle *b,
791 struct test_spoolss_context *ctx,
792 const char *environment)
795 struct spoolss_EnumPrintProcessors r;
796 uint16_t levels[] = { 1 };
799 for (i=0;i<ARRAY_SIZE(levels);i++) {
800 int level = levels[i];
804 union spoolss_PrintProcessorInfo *info;
806 r.in.servername = "";
807 r.in.environment = environment;
811 r.out.needed = &needed;
812 r.out.count = &count;
815 torture_comment(tctx, "Testing EnumPrintProcessors level %u\n", r.in.level);
817 status = dcerpc_spoolss_EnumPrintProcessors_r(b, ctx, &r);
818 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrintProcessors failed");
819 if (W_ERROR_IS_OK(r.out.result)) {
820 /* TODO: do some more checks here */
823 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
824 "EnumPrintProcessors unexpected return code");
826 blob = data_blob_talloc_zero(ctx, needed);
828 r.in.offered = needed;
830 status = dcerpc_spoolss_EnumPrintProcessors_r(b, ctx, &r);
831 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrintProcessors failed");
833 torture_assert_werr_ok(tctx, r.out.result, "EnumPrintProcessors failed");
835 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPrintProcessors, info, r.in.level, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
837 ctx->print_processor_count[level] = count;
838 ctx->print_processors[level] = info;
841 for (i=1;i<ARRAY_SIZE(levels);i++) {
842 int level = levels[i];
843 int old_level = levels[i-1];
844 torture_assert_int_equal(tctx, ctx->print_processor_count[level], ctx->print_processor_count[old_level],
845 "EnumPrintProcessors failed");
848 for (i=0;i<ARRAY_SIZE(levels);i++) {
849 int level = levels[i];
850 for (j=0;j<ctx->print_processor_count[level];j++) {
852 union spoolss_PrintProcessorInfo *cur = &ctx->print_processors[level][j];
853 union spoolss_PrintProcessorInfo *ref = &ctx->print_processors[1][j];
857 /* level 1 is our reference, and it makes no sense to compare it to itself */
866 static bool test_EnumPrintProcDataTypes(struct torture_context *tctx,
867 struct dcerpc_binding_handle *b)
870 struct spoolss_EnumPrintProcDataTypes r;
871 uint16_t levels[] = { 1 };
874 for (i=0;i<ARRAY_SIZE(levels);i++) {
875 int level = levels[i];
879 union spoolss_PrintProcDataTypesInfo *info;
881 r.in.servername = "";
882 r.in.print_processor_name = "winprint";
886 r.out.needed = &needed;
887 r.out.count = &count;
890 torture_comment(tctx, "Testing EnumPrintProcDataTypes level %u\n", r.in.level);
892 status = dcerpc_spoolss_EnumPrintProcDataTypes_r(b, tctx, &r);
893 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrintProcDataType failed");
894 if (W_ERROR_IS_OK(r.out.result)) {
895 /* TODO: do some more checks here */
898 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
899 "EnumPrintProcDataTypes unexpected return code");
901 blob = data_blob_talloc_zero(tctx, needed);
903 r.in.offered = needed;
905 status = dcerpc_spoolss_EnumPrintProcDataTypes_r(b, tctx, &r);
906 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrintProcDataTypes failed");
908 torture_assert_werr_ok(tctx, r.out.result, "EnumPrintProcDataTypes failed");
910 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPrintProcDataTypes, info, r.in.level, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
918 static bool test_EnumPrinters(struct torture_context *tctx,
919 struct dcerpc_binding_handle *b,
920 struct test_spoolss_context *ctx)
922 struct spoolss_EnumPrinters r;
924 uint16_t levels[] = { 0, 1, 2, 4, 5 };
927 for (i=0;i<ARRAY_SIZE(levels);i++) {
928 int level = levels[i];
932 union spoolss_PrinterInfo *info;
934 r.in.flags = PRINTER_ENUM_LOCAL;
939 r.out.needed = &needed;
940 r.out.count = &count;
943 torture_comment(tctx, "Testing EnumPrinters level %u\n", r.in.level);
945 status = dcerpc_spoolss_EnumPrinters_r(b, ctx, &r);
946 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrinters failed");
947 if (W_ERROR_IS_OK(r.out.result)) {
948 /* TODO: do some more checks here */
951 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
952 "EnumPrinters unexpected return code");
954 blob = data_blob_talloc_zero(ctx, needed);
956 r.in.offered = needed;
958 status = dcerpc_spoolss_EnumPrinters_r(b, ctx, &r);
959 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrinters failed");
961 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinters failed");
963 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPrinters, info, r.in.level, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
965 ctx->printer_count[level] = count;
966 ctx->printers[level] = info;
969 for (i=1;i<ARRAY_SIZE(levels);i++) {
970 int level = levels[i];
971 int old_level = levels[i-1];
972 torture_assert_int_equal(tctx, ctx->printer_count[level], ctx->printer_count[old_level],
973 "EnumPrinters invalid value");
976 for (i=0;i<ARRAY_SIZE(levels);i++) {
977 int level = levels[i];
978 for (j=0;j<ctx->printer_count[level];j++) {
979 union spoolss_PrinterInfo *cur = &ctx->printers[level][j];
980 union spoolss_PrinterInfo *ref = &ctx->printers[2][j];
983 COMPARE_STRING(tctx, cur->info0, ref->info2, printername);
984 COMPARE_STRING(tctx, cur->info0, ref->info2, servername);
985 COMPARE_UINT32(tctx, cur->info0, ref->info2, cjobs);
986 /*COMPARE_UINT32(tctx, cur->info0, ref->info2, total_jobs);
987 COMPARE_UINT32(tctx, cur->info0, ref->info2, total_bytes);
988 COMPARE_SPOOLSS_TIME(cur->info0, ref->info2, spoolss_Time time);
989 COMPARE_UINT32(tctx, cur->info0, ref->info2, global_counter);
990 COMPARE_UINT32(tctx, cur->info0, ref->info2, total_pages);
991 COMPARE_UINT32(tctx, cur->info0, ref->info2, version);
992 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown10);
993 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown11);
994 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown12);
995 COMPARE_UINT32(tctx, cur->info0, ref->info2, session_counter);
996 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown14);
997 COMPARE_UINT32(tctx, cur->info0, ref->info2, printer_errors);
998 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown16);
999 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown17);
1000 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown18);
1001 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown19);
1002 COMPARE_UINT32(tctx, cur->info0, ref->info2, change_id);
1003 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown21);*/
1004 COMPARE_UINT32(tctx, cur->info0, ref->info2, status);
1005 /*COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown23);
1006 COMPARE_UINT32(tctx, cur->info0, ref->info2, c_setprinter);
1007 COMPARE_UINT16(cur->info0, ref->info2, unknown25);
1008 COMPARE_UINT16(cur->info0, ref->info2, unknown26);
1009 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown27);
1010 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown28);
1011 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown29);*/
1014 /*COMPARE_UINT32(tctx, cur->info1, ref->info2, flags);*/
1015 /*COMPARE_STRING(tctx, cur->info1, ref->info2, name);*/
1016 /*COMPARE_STRING(tctx, cur->info1, ref->info2, description);*/
1017 COMPARE_STRING(tctx, cur->info1, ref->info2, comment);
1020 /* level 2 is our reference, and it makes no sense to compare it to itself */
1023 COMPARE_STRING(tctx, cur->info4, ref->info2, printername);
1024 COMPARE_STRING(tctx, cur->info4, ref->info2, servername);
1025 COMPARE_UINT32(tctx, cur->info4, ref->info2, attributes);
1028 COMPARE_STRING(tctx, cur->info5, ref->info2, printername);
1029 COMPARE_STRING(tctx, cur->info5, ref->info2, portname);
1030 COMPARE_UINT32(tctx, cur->info5, ref->info2, attributes);
1031 /*COMPARE_UINT32(tctx, cur->info5, ref->info2, device_not_selected_timeout);
1032 COMPARE_UINT32(tctx, cur->info5, ref->info2, transmission_retry_timeout);*/
1039 * - verify that the port of a printer was in the list returned by EnumPorts
1045 static bool test_GetPrinterDriver2(struct torture_context *tctx,
1046 struct dcerpc_binding_handle *b,
1047 struct policy_handle *handle,
1048 const char *driver_name,
1049 const char *environment);
1051 bool test_GetPrinter_level(struct torture_context *tctx,
1052 struct dcerpc_binding_handle *b,
1053 struct policy_handle *handle,
1055 union spoolss_PrinterInfo *info)
1057 struct spoolss_GetPrinter r;
1060 r.in.handle = handle;
1064 r.out.needed = &needed;
1066 torture_comment(tctx, "Testing GetPrinter level %u\n", r.in.level);
1068 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_GetPrinter_r(b, tctx, &r),
1069 "GetPrinter failed");
1071 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
1072 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
1073 r.in.buffer = &blob;
1074 r.in.offered = needed;
1076 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_GetPrinter_r(b, tctx, &r),
1077 "GetPrinter failed");
1080 torture_assert_werr_ok(tctx, r.out.result, "GetPrinter failed");
1082 CHECK_NEEDED_SIZE_LEVEL(spoolss_PrinterInfo, r.out.info, r.in.level, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
1084 if (info && r.out.info) {
1085 *info = *r.out.info;
1092 static bool test_GetPrinter(struct torture_context *tctx,
1093 struct dcerpc_binding_handle *b,
1094 struct policy_handle *handle,
1095 const char *environment)
1097 uint32_t levels[] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
1100 for (i=0;i<ARRAY_SIZE(levels);i++) {
1102 union spoolss_PrinterInfo info;
1106 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, levels[i], &info),
1107 "failed to call GetPrinter");
1109 if ((levels[i] == 2) && info.info2.drivername && strlen(info.info2.drivername)) {
1110 torture_assert(tctx,
1111 test_GetPrinterDriver2(tctx, b, handle, info.info2.drivername, environment),
1112 "failed to call test_GetPrinterDriver2");
1119 static bool test_SetPrinter(struct torture_context *tctx,
1120 struct dcerpc_binding_handle *b,
1121 struct policy_handle *handle,
1122 struct spoolss_SetPrinterInfoCtr *info_ctr,
1123 struct spoolss_DevmodeContainer *devmode_ctr,
1124 struct sec_desc_buf *secdesc_ctr,
1125 enum spoolss_PrinterControl command)
1127 struct spoolss_SetPrinter r;
1129 r.in.handle = handle;
1130 r.in.info_ctr = info_ctr;
1131 r.in.devmode_ctr = devmode_ctr;
1132 r.in.secdesc_ctr = secdesc_ctr;
1133 r.in.command = command;
1135 torture_comment(tctx, "Testing SetPrinter level %d\n", r.in.info_ctr->level);
1137 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_SetPrinter_r(b, tctx, &r),
1138 "failed to call SetPrinter");
1139 torture_assert_werr_ok(tctx, r.out.result,
1140 "failed to call SetPrinter");
1145 static bool test_SetPrinter_errors(struct torture_context *tctx,
1146 struct dcerpc_binding_handle *b,
1147 struct policy_handle *handle)
1149 struct spoolss_SetPrinter r;
1150 uint16_t levels[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
1153 struct spoolss_SetPrinterInfoCtr info_ctr;
1154 struct spoolss_DevmodeContainer devmode_ctr;
1155 struct sec_desc_buf secdesc_ctr;
1158 info_ctr.info.info0 = NULL;
1160 ZERO_STRUCT(devmode_ctr);
1161 ZERO_STRUCT(secdesc_ctr);
1163 r.in.handle = handle;
1164 r.in.info_ctr = &info_ctr;
1165 r.in.devmode_ctr = &devmode_ctr;
1166 r.in.secdesc_ctr = &secdesc_ctr;
1169 torture_comment(tctx, "Testing SetPrinter all zero\n");
1171 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_SetPrinter_r(b, tctx, &r),
1172 "failed to call SetPrinter");
1173 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAM,
1174 "failed to call SetPrinter");
1177 for (i=0; i < ARRAY_SIZE(levels); i++) {
1179 struct spoolss_SetPrinterInfo0 info0;
1180 struct spoolss_SetPrinterInfo1 info1;
1181 struct spoolss_SetPrinterInfo2 info2;
1182 struct spoolss_SetPrinterInfo3 info3;
1183 struct spoolss_SetPrinterInfo4 info4;
1184 struct spoolss_SetPrinterInfo5 info5;
1185 struct spoolss_SetPrinterInfo6 info6;
1186 struct spoolss_SetPrinterInfo7 info7;
1187 struct spoolss_SetPrinterInfo8 info8;
1188 struct spoolss_SetPrinterInfo9 info9;
1191 info_ctr.level = levels[i];
1192 switch (levels[i]) {
1195 info_ctr.info.info0 = &info0;
1199 info_ctr.info.info1 = &info1;
1203 info_ctr.info.info2 = &info2;
1207 info_ctr.info.info3 = &info3;
1211 info_ctr.info.info4 = &info4;
1215 info_ctr.info.info5 = &info5;
1219 info_ctr.info.info6 = &info6;
1223 info_ctr.info.info7 = &info7;
1227 info_ctr.info.info8 = &info8;
1231 info_ctr.info.info9 = &info9;
1235 torture_comment(tctx, "Testing SetPrinter level %d, command %d\n",
1236 info_ctr.level, r.in.command);
1238 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_SetPrinter_r(b, tctx, &r),
1239 "failed to call SetPrinter");
1241 switch (r.in.command) {
1242 case SPOOLSS_PRINTER_CONTROL_UNPAUSE: /* 0 */
1243 /* is ignored for all levels other then 0 */
1244 if (info_ctr.level > 0) {
1248 case SPOOLSS_PRINTER_CONTROL_PAUSE: /* 1 */
1249 case SPOOLSS_PRINTER_CONTROL_RESUME: /* 2 */
1250 case SPOOLSS_PRINTER_CONTROL_PURGE: /* 3 */
1251 if (info_ctr.level > 0) {
1252 /* is invalid for all levels other then 0 */
1253 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PRINTER_COMMAND,
1254 "unexpected error code returned");
1257 torture_assert_werr_ok(tctx, r.out.result,
1258 "failed to call SetPrinter with non 0 command");
1263 case SPOOLSS_PRINTER_CONTROL_SET_STATUS: /* 4 */
1264 /* FIXME: gd needs further investigation */
1266 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PRINTER_COMMAND,
1267 "unexpected error code returned");
1271 switch (info_ctr.level) {
1273 torture_assert_werr_equal(tctx, r.out.result, WERR_UNKNOWN_LEVEL,
1274 "unexpected error code returned");
1277 torture_assert_werr_equal(tctx, r.out.result, WERR_UNKNOWN_PRINTER_DRIVER,
1278 "unexpected error code returned");
1284 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAM,
1285 "unexpected error code returned");
1288 torture_assert_werr_equal(tctx, r.out.result, WERR_NOT_SUPPORTED,
1289 "unexpected error code returned");
1292 torture_assert_werr_ok(tctx, r.out.result,
1293 "failed to call SetPrinter");
1298 if (r.in.command < 5) {
1306 static void clear_info2(struct spoolss_SetPrinterInfoCtr *r)
1308 if ((r->level == 2) && (r->info.info2)) {
1309 r->info.info2->secdesc_ptr = 0;
1310 r->info.info2->devmode_ptr = 0;
1314 static bool test_PrinterInfo(struct torture_context *tctx,
1315 struct dcerpc_binding_handle *b,
1316 struct policy_handle *handle)
1319 struct spoolss_SetPrinter s;
1320 struct spoolss_GetPrinter q;
1321 struct spoolss_GetPrinter q0;
1322 struct spoolss_SetPrinterInfoCtr info_ctr;
1323 union spoolss_PrinterInfo info;
1324 struct spoolss_DevmodeContainer devmode_ctr;
1325 struct sec_desc_buf secdesc_ctr;
1330 uint32_t status_list[] = {
1331 /* these do not stick
1332 PRINTER_STATUS_PAUSED,
1333 PRINTER_STATUS_ERROR,
1334 PRINTER_STATUS_PENDING_DELETION, */
1335 PRINTER_STATUS_PAPER_JAM,
1336 PRINTER_STATUS_PAPER_OUT,
1337 PRINTER_STATUS_MANUAL_FEED,
1338 PRINTER_STATUS_PAPER_PROBLEM,
1339 PRINTER_STATUS_OFFLINE,
1340 PRINTER_STATUS_IO_ACTIVE,
1341 PRINTER_STATUS_BUSY,
1342 PRINTER_STATUS_PRINTING,
1343 PRINTER_STATUS_OUTPUT_BIN_FULL,
1344 PRINTER_STATUS_NOT_AVAILABLE,
1345 PRINTER_STATUS_WAITING,
1346 PRINTER_STATUS_PROCESSING,
1347 PRINTER_STATUS_INITIALIZING,
1348 PRINTER_STATUS_WARMING_UP,
1349 PRINTER_STATUS_TONER_LOW,
1350 PRINTER_STATUS_NO_TONER,
1351 PRINTER_STATUS_PAGE_PUNT,
1352 PRINTER_STATUS_USER_INTERVENTION,
1353 PRINTER_STATUS_OUT_OF_MEMORY,
1354 PRINTER_STATUS_DOOR_OPEN,
1355 PRINTER_STATUS_SERVER_UNKNOWN,
1356 PRINTER_STATUS_POWER_SAVE,
1357 /* these do not stick
1366 uint32_t default_attribute = PRINTER_ATTRIBUTE_LOCAL;
1367 uint32_t attribute_list[] = {
1368 PRINTER_ATTRIBUTE_QUEUED,
1369 /* fails with WERR_INVALID_DATATYPE:
1370 PRINTER_ATTRIBUTE_DIRECT, */
1372 PRINTER_ATTRIBUTE_DEFAULT, */
1373 PRINTER_ATTRIBUTE_SHARED,
1375 PRINTER_ATTRIBUTE_NETWORK, */
1376 PRINTER_ATTRIBUTE_HIDDEN,
1377 PRINTER_ATTRIBUTE_LOCAL,
1378 PRINTER_ATTRIBUTE_ENABLE_DEVQ,
1379 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS,
1380 PRINTER_ATTRIBUTE_DO_COMPLETE_FIRST,
1381 PRINTER_ATTRIBUTE_WORK_OFFLINE,
1383 PRINTER_ATTRIBUTE_ENABLE_BIDI, */
1384 /* fails with WERR_INVALID_DATATYPE:
1385 PRINTER_ATTRIBUTE_RAW_ONLY, */
1386 /* these do not stick
1387 PRINTER_ATTRIBUTE_PUBLISHED,
1388 PRINTER_ATTRIBUTE_FAX,
1389 PRINTER_ATTRIBUTE_TS,
1408 ZERO_STRUCT(devmode_ctr);
1409 ZERO_STRUCT(secdesc_ctr);
1411 s.in.handle = handle;
1413 s.in.info_ctr = &info_ctr;
1414 s.in.devmode_ctr = &devmode_ctr;
1415 s.in.secdesc_ctr = &secdesc_ctr;
1417 q.in.handle = handle;
1421 #define TESTGETCALL(call, r) \
1422 r.in.buffer = NULL; \
1424 r.out.needed = &needed; \
1425 status = dcerpc_spoolss_ ##call## _r(b, tctx, &r); \
1426 if (!NT_STATUS_IS_OK(status)) { \
1427 torture_comment(tctx, #call " level %u failed - %s (%s)\n", \
1428 r.in.level, nt_errstr(status), __location__); \
1432 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {\
1433 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed); \
1434 r.in.buffer = &blob; \
1435 r.in.offered = needed; \
1437 status = dcerpc_spoolss_ ##call## _r(b, tctx, &r); \
1438 if (!NT_STATUS_IS_OK(status)) { \
1439 torture_comment(tctx, #call " level %u failed - %s (%s)\n", \
1440 r.in.level, nt_errstr(status), __location__); \
1444 if (!W_ERROR_IS_OK(r.out.result)) { \
1445 torture_comment(tctx, #call " level %u failed - %s (%s)\n", \
1446 r.in.level, win_errstr(r.out.result), __location__); \
1452 #define TESTSETCALL_EXP(call, r, err) \
1453 clear_info2(&info_ctr);\
1454 status = dcerpc_spoolss_ ##call## _r(b, tctx, &r); \
1455 if (!NT_STATUS_IS_OK(status)) { \
1456 torture_comment(tctx, #call " level %u failed - %s (%s)\n", \
1457 r.in.info_ctr->level, nt_errstr(status), __location__); \
1461 if (!W_ERROR_IS_OK(err)) { \
1462 if (!W_ERROR_EQUAL(err, r.out.result)) { \
1463 torture_comment(tctx, #call " level %u failed - %s, expected %s (%s)\n", \
1464 r.in.info_ctr->level, win_errstr(r.out.result), win_errstr(err), __location__); \
1469 if (!W_ERROR_IS_OK(r.out.result)) { \
1470 torture_comment(tctx, #call " level %u failed - %s (%s)\n", \
1471 r.in.info_ctr->level, win_errstr(r.out.result), __location__); \
1476 #define TESTSETCALL(call, r) \
1477 TESTSETCALL_EXP(call, r, WERR_OK)
1479 #define STRING_EQUAL(s1, s2, field) \
1480 if ((s1 && !s2) || (s2 && !s1) || strcmp(s1, s2)) { \
1481 torture_comment(tctx, "Failed to set %s to '%s' (%s)\n", \
1482 #field, s2, __location__); \
1487 #define MEM_EQUAL(s1, s2, length, field) \
1488 if ((s1 && !s2) || (s2 && !s1) || memcmp(s1, s2, length)) { \
1489 torture_comment(tctx, "Failed to set %s to '%s' (%s)\n", \
1490 #field, (const char *)s2, __location__); \
1495 #define INT_EQUAL(i1, i2, field) \
1497 torture_comment(tctx, "Failed to set %s to 0x%llx - got 0x%llx (%s)\n", \
1498 #field, (unsigned long long)i2, (unsigned long long)i1, __location__); \
1503 #define SD_EQUAL(sd1, sd2, field) \
1504 if (!security_descriptor_equal(sd1, sd2)) { \
1505 torture_comment(tctx, "Failed to set %s (%s)\n", \
1506 #field, __location__); \
1511 #define TEST_PRINTERINFO_STRING_EXP_ERR(lvl1, field1, lvl2, field2, value, err) do { \
1512 torture_comment(tctx, "field test %d/%s vs %d/%s\n", lvl1, #field1, lvl2, #field2); \
1513 q.in.level = lvl1; \
1514 TESTGETCALL(GetPrinter, q) \
1515 info_ctr.level = lvl1; \
1516 info_ctr.info.info ## lvl1 = (struct spoolss_SetPrinterInfo ## lvl1 *)(void *)&q.out.info->info ## lvl1; \
1517 info_ctr.info.info ## lvl1->field1 = value;\
1518 TESTSETCALL_EXP(SetPrinter, s, err) \
1519 info_ctr.info.info ## lvl1->field1 = ""; \
1520 TESTGETCALL(GetPrinter, q) \
1521 info_ctr.info.info ## lvl1->field1 = value; \
1522 STRING_EQUAL(info_ctr.info.info ## lvl1->field1, value, field1); \
1523 q.in.level = lvl2; \
1524 TESTGETCALL(GetPrinter, q) \
1525 info_ctr.info.info ## lvl2 = (struct spoolss_SetPrinterInfo ## lvl2 *)(void *)&q.out.info->info ## lvl2; \
1526 STRING_EQUAL(info_ctr.info.info ## lvl2->field2, value, field2); \
1529 #define TEST_PRINTERINFO_STRING(lvl1, field1, lvl2, field2, value) do { \
1530 TEST_PRINTERINFO_STRING_EXP_ERR(lvl1, field1, lvl2, field2, value, WERR_OK); \
1533 #define TEST_PRINTERINFO_INT_EXP(lvl1, field1, lvl2, field2, value, exp_value) do { \
1534 torture_comment(tctx, "field test %d/%s vs %d/%s\n", lvl1, #field1, lvl2, #field2); \
1535 q.in.level = lvl1; \
1536 TESTGETCALL(GetPrinter, q) \
1537 info_ctr.level = lvl1; \
1538 info_ctr.info.info ## lvl1 = (struct spoolss_SetPrinterInfo ## lvl1 *)(void *)&q.out.info->info ## lvl1; \
1539 info_ctr.info.info ## lvl1->field1 = value; \
1540 TESTSETCALL(SetPrinter, s) \
1541 info_ctr.info.info ## lvl1->field1 = 0; \
1542 TESTGETCALL(GetPrinter, q) \
1543 info_ctr.info.info ## lvl1 = (struct spoolss_SetPrinterInfo ## lvl1 *)(void *)&q.out.info->info ## lvl1; \
1544 INT_EQUAL(info_ctr.info.info ## lvl1->field1, exp_value, field1); \
1545 q.in.level = lvl2; \
1546 TESTGETCALL(GetPrinter, q) \
1547 info_ctr.info.info ## lvl2 = (struct spoolss_SetPrinterInfo ## lvl2 *)(void *)&q.out.info->info ## lvl2; \
1548 INT_EQUAL(info_ctr.info.info ## lvl2->field2, exp_value, field1); \
1551 #define TEST_PRINTERINFO_INT(lvl1, field1, lvl2, field2, value) do { \
1552 TEST_PRINTERINFO_INT_EXP(lvl1, field1, lvl2, field2, value, value); \
1556 do { TESTGETCALL(GetPrinter, q0) } while (0);
1558 TEST_PRINTERINFO_STRING(2, comment, 1, comment, "xx2-1 comment");
1559 TEST_PRINTERINFO_STRING(2, comment, 2, comment, "xx2-2 comment");
1561 /* level 0 printername does not stick */
1562 /* TEST_PRINTERINFO_STRING(2, printername, 0, printername, "xx2-0 printer"); */
1563 TEST_PRINTERINFO_STRING(2, printername, 1, name, "xx2-1 printer");
1564 TEST_PRINTERINFO_STRING(2, printername, 2, printername, "xx2-2 printer");
1565 TEST_PRINTERINFO_STRING(2, printername, 4, printername, "xx2-4 printer");
1566 TEST_PRINTERINFO_STRING(2, printername, 5, printername, "xx2-5 printer");
1567 /* TEST_PRINTERINFO_STRING(4, printername, 0, printername, "xx4-0 printer"); */
1568 TEST_PRINTERINFO_STRING(4, printername, 1, name, "xx4-1 printer");
1569 TEST_PRINTERINFO_STRING(4, printername, 2, printername, "xx4-2 printer");
1570 TEST_PRINTERINFO_STRING(4, printername, 4, printername, "xx4-4 printer");
1571 TEST_PRINTERINFO_STRING(4, printername, 5, printername, "xx4-5 printer");
1572 /* TEST_PRINTERINFO_STRING(5, printername, 0, printername, "xx5-0 printer"); */
1573 TEST_PRINTERINFO_STRING(5, printername, 1, name, "xx5-1 printer");
1574 TEST_PRINTERINFO_STRING(5, printername, 2, printername, "xx5-2 printer");
1575 TEST_PRINTERINFO_STRING(5, printername, 4, printername, "xx5-4 printer");
1576 TEST_PRINTERINFO_STRING(5, printername, 5, printername, "xx5-5 printer");
1578 /* servername can be set but does not stick
1579 TEST_PRINTERINFO_STRING(2, servername, 0, servername, "xx2-0 servername");
1580 TEST_PRINTERINFO_STRING(2, servername, 2, servername, "xx2-2 servername");
1581 TEST_PRINTERINFO_STRING(2, servername, 4, servername, "xx2-4 servername");
1584 /* passing an invalid port will result in WERR_UNKNOWN_PORT */
1585 TEST_PRINTERINFO_STRING_EXP_ERR(2, portname, 2, portname, "xx2-2 portname", WERR_UNKNOWN_PORT);
1586 TEST_PRINTERINFO_STRING_EXP_ERR(2, portname, 5, portname, "xx2-5 portname", WERR_UNKNOWN_PORT);
1587 TEST_PRINTERINFO_STRING_EXP_ERR(5, portname, 2, portname, "xx5-2 portname", WERR_UNKNOWN_PORT);
1588 TEST_PRINTERINFO_STRING_EXP_ERR(5, portname, 5, portname, "xx5-5 portname", WERR_UNKNOWN_PORT);
1590 TEST_PRINTERINFO_STRING(2, sharename, 2, sharename, "xx2-2 sharename");
1591 /* passing an invalid driver will result in WERR_UNKNOWN_PRINTER_DRIVER */
1592 TEST_PRINTERINFO_STRING_EXP_ERR(2, drivername, 2, drivername, "xx2-2 drivername", WERR_UNKNOWN_PRINTER_DRIVER);
1593 TEST_PRINTERINFO_STRING(2, location, 2, location, "xx2-2 location");
1594 /* passing an invalid sepfile will result in WERR_INVALID_SEPARATOR_FILE */
1595 TEST_PRINTERINFO_STRING_EXP_ERR(2, sepfile, 2, sepfile, "xx2-2 sepfile", WERR_INVALID_SEPARATOR_FILE);
1596 /* passing an invalid printprocessor will result in WERR_UNKNOWN_PRINTPROCESSOR */
1597 TEST_PRINTERINFO_STRING_EXP_ERR(2, printprocessor, 2, printprocessor, "xx2-2 printprocessor", WERR_UNKNOWN_PRINTPROCESSOR);
1598 TEST_PRINTERINFO_STRING(2, datatype, 2, datatype, "xx2-2 datatype");
1599 TEST_PRINTERINFO_STRING(2, parameters, 2, parameters, "xx2-2 parameters");
1601 for (i=0; i < ARRAY_SIZE(attribute_list); i++) {
1602 /* TEST_PRINTERINFO_INT_EXP(2, attributes, 1, flags,
1604 (attribute_list[i] | default_attribute)
1606 TEST_PRINTERINFO_INT_EXP(2, attributes, 2, attributes,
1608 (attribute_list[i] | default_attribute)
1610 TEST_PRINTERINFO_INT_EXP(2, attributes, 4, attributes,
1612 (attribute_list[i] | default_attribute)
1614 TEST_PRINTERINFO_INT_EXP(2, attributes, 5, attributes,
1616 (attribute_list[i] | default_attribute)
1618 /* TEST_PRINTERINFO_INT_EXP(4, attributes, 1, flags,
1620 (attribute_list[i] | default_attribute)
1622 TEST_PRINTERINFO_INT_EXP(4, attributes, 2, attributes,
1624 (attribute_list[i] | default_attribute)
1626 TEST_PRINTERINFO_INT_EXP(4, attributes, 4, attributes,
1628 (attribute_list[i] | default_attribute)
1630 TEST_PRINTERINFO_INT_EXP(4, attributes, 5, attributes,
1632 (attribute_list[i] | default_attribute)
1634 /* TEST_PRINTERINFO_INT_EXP(5, attributes, 1, flags,
1636 (attribute_list[i] | default_attribute)
1638 TEST_PRINTERINFO_INT_EXP(5, attributes, 2, attributes,
1640 (attribute_list[i] | default_attribute)
1642 TEST_PRINTERINFO_INT_EXP(5, attributes, 4, attributes,
1644 (attribute_list[i] | default_attribute)
1646 TEST_PRINTERINFO_INT_EXP(5, attributes, 5, attributes,
1648 (attribute_list[i] | default_attribute)
1652 for (i=0; i < ARRAY_SIZE(status_list); i++) {
1653 /* level 2 sets do not stick
1654 TEST_PRINTERINFO_INT(2, status, 0, status, status_list[i]);
1655 TEST_PRINTERINFO_INT(2, status, 2, status, status_list[i]);
1656 TEST_PRINTERINFO_INT(2, status, 6, status, status_list[i]); */
1657 TEST_PRINTERINFO_INT(6, status, 0, status, status_list[i]);
1658 TEST_PRINTERINFO_INT(6, status, 2, status, status_list[i]);
1659 TEST_PRINTERINFO_INT(6, status, 6, status, status_list[i]);
1662 /* priorities need to be between 0 and 99
1663 passing an invalid priority will result in WERR_INVALID_PRIORITY */
1664 TEST_PRINTERINFO_INT(2, priority, 2, priority, 0);
1665 TEST_PRINTERINFO_INT(2, priority, 2, priority, 1);
1666 TEST_PRINTERINFO_INT(2, priority, 2, priority, 99);
1667 /* TEST_PRINTERINFO_INT(2, priority, 2, priority, 100); */
1668 TEST_PRINTERINFO_INT(2, defaultpriority,2, defaultpriority, 0);
1669 TEST_PRINTERINFO_INT(2, defaultpriority,2, defaultpriority, 1);
1670 TEST_PRINTERINFO_INT(2, defaultpriority,2, defaultpriority, 99);
1671 /* TEST_PRINTERINFO_INT(2, defaultpriority,2, defaultpriority, 100); */
1673 TEST_PRINTERINFO_INT(2, starttime, 2, starttime, __LINE__);
1674 TEST_PRINTERINFO_INT(2, untiltime, 2, untiltime, __LINE__);
1677 TEST_PRINTERINFO_INT(2, cjobs, 2, cjobs, __LINE__);
1678 TEST_PRINTERINFO_INT(2, averageppm, 2, averageppm, __LINE__); */
1681 TEST_PRINTERINFO_INT(5, device_not_selected_timeout, 5, device_not_selected_timeout, __LINE__);
1682 TEST_PRINTERINFO_INT(5, transmission_retry_timeout, 5, transmission_retry_timeout, __LINE__); */
1684 /* FIXME: gd also test devmode and secdesc behavior */
1687 /* verify composition of level 1 description field */
1688 const char *description;
1692 do { TESTGETCALL(GetPrinter, q0) } while (0);
1694 description = talloc_strdup(tctx, q0.out.info->info1.description);
1697 do { TESTGETCALL(GetPrinter, q0) } while (0);
1699 tmp = talloc_asprintf(tctx, "%s,%s,%s",
1700 q0.out.info->info2.printername,
1701 q0.out.info->info2.drivername,
1702 q0.out.info->info2.location);
1704 do { STRING_EQUAL(description, tmp, "description")} while (0);
1710 #define torture_assert_sid_equal(torture_ctx,got,expected,cmt)\
1711 do { struct dom_sid *__got = (got), *__expected = (expected); \
1712 if (!dom_sid_equal(__got, __expected)) { \
1713 torture_result(torture_ctx, TORTURE_FAIL, \
1714 __location__": "#got" was %s, expected %s: %s", \
1715 dom_sid_string(torture_ctx, __got), dom_sid_string(torture_ctx, __expected), cmt); \
1720 static bool test_security_descriptor_equal(struct torture_context *tctx,
1721 const struct security_descriptor *sd1,
1722 const struct security_descriptor *sd2)
1729 torture_comment(tctx, "%s\n", __location__);
1733 torture_assert_int_equal(tctx, sd1->revision, sd2->revision, "revision mismatch");
1734 torture_assert_int_equal(tctx, sd1->type, sd2->type, "type mismatch");
1736 torture_assert_sid_equal(tctx, sd1->owner_sid, sd2->owner_sid, "owner mismatch");
1737 torture_assert_sid_equal(tctx, sd1->group_sid, sd2->group_sid, "group mismatch");
1739 if (!security_acl_equal(sd1->sacl, sd2->sacl)) {
1740 torture_comment(tctx, "%s: sacl mismatch\n", __location__);
1741 NDR_PRINT_DEBUG(security_acl, sd1->sacl);
1742 NDR_PRINT_DEBUG(security_acl, sd2->sacl);
1745 if (!security_acl_equal(sd1->dacl, sd2->dacl)) {
1746 torture_comment(tctx, "%s: dacl mismatch\n", __location__);
1747 NDR_PRINT_DEBUG(security_acl, sd1->dacl);
1748 NDR_PRINT_DEBUG(security_acl, sd2->dacl);
1755 static bool test_sd_set_level(struct torture_context *tctx,
1756 struct dcerpc_binding_handle *b,
1757 struct policy_handle *handle,
1759 struct security_descriptor *sd)
1761 struct spoolss_SetPrinterInfoCtr info_ctr;
1762 struct spoolss_DevmodeContainer devmode_ctr;
1763 struct sec_desc_buf secdesc_ctr;
1764 union spoolss_SetPrinterInfo sinfo;
1766 ZERO_STRUCT(devmode_ctr);
1767 ZERO_STRUCT(secdesc_ctr);
1771 union spoolss_PrinterInfo info;
1772 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
1773 torture_assert(tctx, PrinterInfo_to_SetPrinterInfo(tctx, &info, 2, &sinfo), "");
1776 info_ctr.info = sinfo;
1781 struct spoolss_SetPrinterInfo3 info3;
1783 info3.sec_desc_ptr = 0;
1786 info_ctr.info.info3 = &info3;
1794 secdesc_ctr.sd = sd;
1796 torture_assert(tctx,
1797 test_SetPrinter(tctx, b, handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0), "");
1802 static bool test_PrinterInfo_SDs(struct torture_context *tctx,
1803 struct dcerpc_binding_handle *b,
1804 struct policy_handle *handle)
1806 union spoolss_PrinterInfo info;
1807 struct security_descriptor *sd1, *sd2;
1810 /* just compare level 2 and level 3 */
1812 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
1814 sd1 = info.info2.secdesc;
1816 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 3, &info), "");
1818 sd2 = info.info3.secdesc;
1820 torture_assert(tctx, test_security_descriptor_equal(tctx, sd1, sd2),
1821 "SD level 2 != SD level 3");
1824 /* query level 2, set level 2, query level 2 */
1826 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
1828 sd1 = info.info2.secdesc;
1830 torture_assert(tctx, test_sd_set_level(tctx, b, handle, 2, sd1), "");
1832 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
1834 sd2 = info.info2.secdesc;
1835 if (sd1->type & SEC_DESC_DACL_DEFAULTED) {
1836 torture_comment(tctx, "removing SEC_DESC_DACL_DEFAULTED\n");
1837 sd1->type &= ~SEC_DESC_DACL_DEFAULTED;
1840 torture_assert(tctx, test_security_descriptor_equal(tctx, sd1, sd2),
1841 "SD level 2 != SD level 2 after SD has been set via level 2");
1844 /* query level 2, set level 3, query level 2 */
1846 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
1848 sd1 = info.info2.secdesc;
1850 torture_assert(tctx, test_sd_set_level(tctx, b, handle, 3, sd1), "");
1852 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
1854 sd2 = info.info2.secdesc;
1856 torture_assert(tctx, test_security_descriptor_equal(tctx, sd1, sd2),
1857 "SD level 2 != SD level 2 after SD has been set via level 3");
1859 /* set modified sd level 3, query level 2 */
1861 for (i=0; i < 93; i++) {
1862 struct security_ace a;
1863 const char *sid_string = talloc_asprintf(tctx, "S-1-5-32-9999%i", i);
1864 a.type = SEC_ACE_TYPE_ACCESS_ALLOWED;
1866 a.size = 0; /* autogenerated */
1868 a.trustee = *dom_sid_parse_talloc(tctx, sid_string);
1869 torture_assert_ntstatus_ok(tctx, security_descriptor_dacl_add(sd1, &a), "");
1872 torture_assert(tctx, test_sd_set_level(tctx, b, handle, 3, sd1), "");
1874 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
1875 sd2 = info.info2.secdesc;
1877 if (sd1->type & SEC_DESC_DACL_DEFAULTED) {
1878 torture_comment(tctx, "removing SEC_DESC_DACL_DEFAULTED\n");
1879 sd1->type &= ~SEC_DESC_DACL_DEFAULTED;
1882 torture_assert(tctx, test_security_descriptor_equal(tctx, sd1, sd2),
1883 "modified SD level 2 != SD level 2 after SD has been set via level 3");
1890 * wrapper call that saves original sd, runs tests, and restores sd
1893 static bool test_PrinterInfo_SD(struct torture_context *tctx,
1894 struct dcerpc_binding_handle *b,
1895 struct policy_handle *handle)
1897 union spoolss_PrinterInfo info;
1898 struct security_descriptor *sd;
1901 torture_comment(tctx, "Testing Printer Security Descriptors\n");
1903 /* save original sd */
1905 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info),
1906 "failed to get initial security descriptor");
1908 sd = security_descriptor_copy(tctx, info.info2.secdesc);
1912 ret = test_PrinterInfo_SDs(tctx, b, handle);
1914 /* restore original sd */
1916 torture_assert(tctx, test_sd_set_level(tctx, b, handle, 3, sd),
1917 "failed to restore initial security descriptor");
1919 torture_comment(tctx, "Printer Security Descriptors test %s\n\n",
1920 ret ? "succeeded" : "failed");
1926 static bool test_devmode_set_level(struct torture_context *tctx,
1927 struct dcerpc_binding_handle *b,
1928 struct policy_handle *handle,
1930 struct spoolss_DeviceMode *devmode)
1932 struct spoolss_SetPrinterInfoCtr info_ctr;
1933 struct spoolss_DevmodeContainer devmode_ctr;
1934 struct sec_desc_buf secdesc_ctr;
1935 union spoolss_SetPrinterInfo sinfo;
1937 ZERO_STRUCT(devmode_ctr);
1938 ZERO_STRUCT(secdesc_ctr);
1942 union spoolss_PrinterInfo info;
1943 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
1944 torture_assert(tctx, PrinterInfo_to_SetPrinterInfo(tctx, &info, 2, &sinfo), "");
1947 info_ctr.info = sinfo;
1952 struct spoolss_SetPrinterInfo8 info8;
1954 info8.devmode_ptr = 0;
1957 info_ctr.info.info8 = &info8;
1965 devmode_ctr.devmode = devmode;
1967 torture_assert(tctx,
1968 test_SetPrinter(tctx, b, handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0), "");
1974 static bool test_devicemode_equal(struct torture_context *tctx,
1975 const struct spoolss_DeviceMode *d1,
1976 const struct spoolss_DeviceMode *d2)
1983 torture_comment(tctx, "%s\n", __location__);
1986 torture_assert_str_equal(tctx, d1->devicename, d2->devicename, "devicename mismatch");
1987 torture_assert_int_equal(tctx, d1->specversion, d2->specversion, "specversion mismatch");
1988 torture_assert_int_equal(tctx, d1->driverversion, d2->driverversion, "driverversion mismatch");
1989 torture_assert_int_equal(tctx, d1->size, d2->size, "size mismatch");
1990 torture_assert_int_equal(tctx, d1->__driverextra_length, d2->__driverextra_length, "__driverextra_length mismatch");
1991 torture_assert_int_equal(tctx, d1->fields, d2->fields, "fields mismatch");
1992 torture_assert_int_equal(tctx, d1->orientation, d2->orientation, "orientation mismatch");
1993 torture_assert_int_equal(tctx, d1->papersize, d2->papersize, "papersize mismatch");
1994 torture_assert_int_equal(tctx, d1->paperlength, d2->paperlength, "paperlength mismatch");
1995 torture_assert_int_equal(tctx, d1->paperwidth, d2->paperwidth, "paperwidth mismatch");
1996 torture_assert_int_equal(tctx, d1->scale, d2->scale, "scale mismatch");
1997 torture_assert_int_equal(tctx, d1->copies, d2->copies, "copies mismatch");
1998 torture_assert_int_equal(tctx, d1->defaultsource, d2->defaultsource, "defaultsource mismatch");
1999 torture_assert_int_equal(tctx, d1->printquality, d2->printquality, "printquality mismatch");
2000 torture_assert_int_equal(tctx, d1->color, d2->color, "color mismatch");
2001 torture_assert_int_equal(tctx, d1->duplex, d2->duplex, "duplex mismatch");
2002 torture_assert_int_equal(tctx, d1->yresolution, d2->yresolution, "yresolution mismatch");
2003 torture_assert_int_equal(tctx, d1->ttoption, d2->ttoption, "ttoption mismatch");
2004 torture_assert_int_equal(tctx, d1->collate, d2->collate, "collate mismatch");
2005 torture_assert_str_equal(tctx, d1->formname, d2->formname, "formname mismatch");
2006 torture_assert_int_equal(tctx, d1->logpixels, d2->logpixels, "logpixels mismatch");
2007 torture_assert_int_equal(tctx, d1->bitsperpel, d2->bitsperpel, "bitsperpel mismatch");
2008 torture_assert_int_equal(tctx, d1->pelswidth, d2->pelswidth, "pelswidth mismatch");
2009 torture_assert_int_equal(tctx, d1->pelsheight, d2->pelsheight, "pelsheight mismatch");
2010 torture_assert_int_equal(tctx, d1->displayflags, d2->displayflags, "displayflags mismatch");
2011 torture_assert_int_equal(tctx, d1->displayfrequency, d2->displayfrequency, "displayfrequency mismatch");
2012 torture_assert_int_equal(tctx, d1->icmmethod, d2->icmmethod, "icmmethod mismatch");
2013 torture_assert_int_equal(tctx, d1->icmintent, d2->icmintent, "icmintent mismatch");
2014 torture_assert_int_equal(tctx, d1->mediatype, d2->mediatype, "mediatype mismatch");
2015 torture_assert_int_equal(tctx, d1->dithertype, d2->dithertype, "dithertype mismatch");
2016 torture_assert_int_equal(tctx, d1->reserved1, d2->reserved1, "reserved1 mismatch");
2017 torture_assert_int_equal(tctx, d1->reserved2, d2->reserved2, "reserved2 mismatch");
2018 torture_assert_int_equal(tctx, d1->panningwidth, d2->panningwidth, "panningwidth mismatch");
2019 torture_assert_int_equal(tctx, d1->panningheight, d2->panningheight, "panningheight mismatch");
2020 torture_assert_data_blob_equal(tctx, d1->driverextra_data, d2->driverextra_data, "driverextra_data mismatch");
2025 static bool test_devicemode_full(struct torture_context *tctx,
2026 struct dcerpc_binding_handle *b,
2027 struct policy_handle *handle)
2029 struct spoolss_SetPrinter s;
2030 struct spoolss_GetPrinter q;
2031 struct spoolss_GetPrinter q0;
2032 struct spoolss_SetPrinterInfoCtr info_ctr;
2033 struct spoolss_SetPrinterInfo8 info8;
2034 union spoolss_PrinterInfo info;
2035 struct spoolss_DevmodeContainer devmode_ctr;
2036 struct sec_desc_buf secdesc_ctr;
2041 #define TEST_DEVMODE_INT_EXP(lvl1, field1, lvl2, field2, value, exp_value) do { \
2042 torture_comment(tctx, "field test %d/%s vs %d/%s\n", lvl1, #field1, lvl2, #field2); \
2043 q.in.level = lvl1; \
2044 TESTGETCALL(GetPrinter, q) \
2045 info_ctr.level = lvl1; \
2047 info_ctr.info.info ## lvl1 = (struct spoolss_SetPrinterInfo ## lvl1 *)(void *)&q.out.info->info ## lvl1; \
2048 } else if (lvl1 == 8) {\
2049 info_ctr.info.info ## lvl1 = &info8; \
2051 devmode_ctr.devmode = q.out.info->info ## lvl1.devmode; \
2052 devmode_ctr.devmode->field1 = value; \
2053 TESTSETCALL(SetPrinter, s) \
2054 TESTGETCALL(GetPrinter, q) \
2055 INT_EQUAL(q.out.info->info ## lvl1.devmode->field1, exp_value, field1); \
2056 q.in.level = lvl2; \
2057 TESTGETCALL(GetPrinter, q) \
2058 INT_EQUAL(q.out.info->info ## lvl2.devmode->field2, exp_value, field1); \
2061 #define TEST_DEVMODE_INT(lvl1, field1, lvl2, field2, value) do { \
2062 TEST_DEVMODE_INT_EXP(lvl1, field1, lvl2, field2, value, value); \
2065 ZERO_STRUCT(devmode_ctr);
2066 ZERO_STRUCT(secdesc_ctr);
2069 s.in.handle = handle;
2071 s.in.info_ctr = &info_ctr;
2072 s.in.devmode_ctr = &devmode_ctr;
2073 s.in.secdesc_ctr = &secdesc_ctr;
2075 q.in.handle = handle;
2080 const char *devicename;/* [charset(UTF16)] */
2081 enum spoolss_DeviceModeSpecVersion specversion;
2082 uint16_t driverversion;
2084 uint16_t __driverextra_length;/* [value(r->driverextra_data.length)] */
2088 TEST_DEVMODE_INT(8, orientation, 8, orientation, __LINE__);
2089 TEST_DEVMODE_INT(8, papersize, 8, papersize, __LINE__);
2090 TEST_DEVMODE_INT(8, paperlength, 8, paperlength, __LINE__);
2091 TEST_DEVMODE_INT(8, paperwidth, 8, paperwidth, __LINE__);
2092 TEST_DEVMODE_INT(8, scale, 8, scale, __LINE__);
2093 TEST_DEVMODE_INT(8, copies, 8, copies, __LINE__);
2094 TEST_DEVMODE_INT(8, defaultsource, 8, defaultsource, __LINE__);
2095 TEST_DEVMODE_INT(8, printquality, 8, printquality, __LINE__);
2096 TEST_DEVMODE_INT(8, color, 8, color, __LINE__);
2097 TEST_DEVMODE_INT(8, duplex, 8, duplex, __LINE__);
2098 TEST_DEVMODE_INT(8, yresolution, 8, yresolution, __LINE__);
2099 TEST_DEVMODE_INT(8, ttoption, 8, ttoption, __LINE__);
2100 TEST_DEVMODE_INT(8, collate, 8, collate, __LINE__);
2102 const char *formname;/* [charset(UTF16)] */
2104 TEST_DEVMODE_INT(8, logpixels, 8, logpixels, __LINE__);
2105 TEST_DEVMODE_INT(8, bitsperpel, 8, bitsperpel, __LINE__);
2106 TEST_DEVMODE_INT(8, pelswidth, 8, pelswidth, __LINE__);
2107 TEST_DEVMODE_INT(8, pelsheight, 8, pelsheight, __LINE__);
2108 TEST_DEVMODE_INT(8, displayflags, 8, displayflags, __LINE__);
2109 TEST_DEVMODE_INT(8, displayfrequency, 8, displayfrequency, __LINE__);
2110 TEST_DEVMODE_INT(8, icmmethod, 8, icmmethod, __LINE__);
2111 TEST_DEVMODE_INT(8, icmintent, 8, icmintent, __LINE__);
2112 TEST_DEVMODE_INT(8, mediatype, 8, mediatype, __LINE__);
2113 TEST_DEVMODE_INT(8, dithertype, 8, dithertype, __LINE__);
2114 TEST_DEVMODE_INT(8, reserved1, 8, reserved1, __LINE__);
2115 TEST_DEVMODE_INT(8, reserved2, 8, reserved2, __LINE__);
2116 TEST_DEVMODE_INT(8, panningwidth, 8, panningwidth, __LINE__);
2117 TEST_DEVMODE_INT(8, panningheight, 8, panningheight, __LINE__);
2122 static bool call_OpenPrinterEx(struct torture_context *tctx,
2123 struct dcerpc_pipe *p,
2125 struct spoolss_DeviceMode *devmode,
2126 struct policy_handle *handle);
2128 static bool test_ClosePrinter(struct torture_context *tctx,
2129 struct dcerpc_binding_handle *b,
2130 struct policy_handle *handle);
2132 static bool test_PrinterInfo_DevModes(struct torture_context *tctx,
2133 struct dcerpc_pipe *p,
2134 struct policy_handle *handle,
2137 union spoolss_PrinterInfo info;
2138 struct spoolss_DeviceMode *devmode;
2139 struct spoolss_DeviceMode *devmode2;
2140 struct policy_handle handle_devmode;
2141 struct dcerpc_binding_handle *b = p->binding_handle;
2143 /* simply compare level8 and level2 devmode */
2145 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 8, &info), "");
2147 devmode = info.info8.devmode;
2149 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
2151 devmode2 = info.info2.devmode;
2153 torture_assert(tctx, test_devicemode_equal(tctx, devmode, devmode2),
2154 "DM level 8 != DM level 2");
2157 /* set devicemode level 8 and see if it persists */
2159 devmode->copies = 93;
2160 devmode->formname = talloc_strdup(tctx, "Legal");
2162 torture_assert(tctx, test_devmode_set_level(tctx, b, handle, 8, devmode), "");
2164 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 8, &info), "");
2166 devmode2 = info.info8.devmode;
2168 torture_assert(tctx, test_devicemode_equal(tctx, devmode, devmode2),
2169 "modified DM level 8 != DM level 8 after DM has been set via level 8");
2171 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
2173 devmode2 = info.info2.devmode;
2175 torture_assert(tctx, test_devicemode_equal(tctx, devmode, devmode2),
2176 "modified DM level 8 != DM level 2");
2179 /* set devicemode level 2 and see if it persists */
2181 devmode->copies = 39;
2182 devmode->formname = talloc_strdup(tctx, "Executive");
2184 torture_assert(tctx, test_devmode_set_level(tctx, b, handle, 2, devmode), "");
2186 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 8, &info), "");
2188 devmode2 = info.info8.devmode;
2190 torture_assert(tctx, test_devicemode_equal(tctx, devmode, devmode2),
2191 "modified DM level 8 != DM level 8 after DM has been set via level 2");
2193 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
2195 devmode2 = info.info2.devmode;
2197 torture_assert(tctx, test_devicemode_equal(tctx, devmode, devmode2),
2198 "modified DM level 8 != DM level 2");
2201 /* check every single bit in public part of devicemode */
2203 torture_assert(tctx, test_devicemode_full(tctx, b, handle),
2204 "failed to set every single devicemode component");
2207 /* change formname upon open and see if it persists in getprinter calls */
2209 devmode->formname = talloc_strdup(tctx, "A4");
2210 devmode->copies = 42;
2212 torture_assert(tctx, call_OpenPrinterEx(tctx, p, name, devmode, &handle_devmode),
2213 "failed to open printer handle");
2215 torture_assert(tctx, test_GetPrinter_level(tctx, b, &handle_devmode, 8, &info), "");
2217 devmode2 = info.info8.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 8 get: %s\n", devmode2->devicename);
2226 if (strequal(devmode->formname, devmode2->formname)) {
2227 torture_warning(tctx, "formname are the same\n");
2229 torture_comment(tctx, "formname passed in for open: %s\n", devmode->formname);
2230 torture_comment(tctx, "formname after level 8 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 8 get: %d\n", devmode2->copies);
2240 torture_assert(tctx, test_GetPrinter_level(tctx, b, &handle_devmode, 2, &info), "");
2242 devmode2 = info.info2.devmode;
2244 if (strequal(devmode->devicename, devmode2->devicename)) {
2245 torture_warning(tctx, "devicenames are the same\n");
2247 torture_comment(tctx, "devicename passed in for open: %s\n", devmode->devicename);
2248 torture_comment(tctx, "devicename after level 2 get: %s\n", devmode2->devicename);
2251 if (strequal(devmode->formname, devmode2->formname)) {
2252 torture_warning(tctx, "formname is the same\n");
2254 torture_comment(tctx, "formname passed in for open: %s\n", devmode->formname);
2255 torture_comment(tctx, "formname after level 2 get: %s\n", devmode2->formname);
2258 if (devmode->copies == devmode2->copies) {
2259 torture_warning(tctx, "copies are the same\n");
2261 torture_comment(tctx, "copies passed in for open: %d\n", devmode->copies);
2262 torture_comment(tctx, "copies after level 2 get: %d\n", devmode2->copies);
2265 test_ClosePrinter(tctx, b, &handle_devmode);
2271 * wrapper call that saves original devmode, runs tests, and restores devmode
2274 static bool test_PrinterInfo_DevMode(struct torture_context *tctx,
2275 struct dcerpc_pipe *p,
2276 struct policy_handle *handle,
2279 union spoolss_PrinterInfo info;
2280 struct spoolss_DeviceMode *devmode;
2282 struct dcerpc_binding_handle *b = p->binding_handle;
2284 torture_comment(tctx, "Testing Printer Devicemodes\n");
2286 /* save original devmode */
2288 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 8, &info),
2289 "failed to get initial global devicemode");
2291 devmode = info.info8.devmode;
2295 ret = test_PrinterInfo_DevModes(tctx, p, handle, name);
2297 /* restore original devmode */
2299 torture_assert(tctx, test_devmode_set_level(tctx, b, handle, 8, devmode),
2300 "failed to restore initial global device mode");
2302 torture_comment(tctx, "Printer Devicemodes test %s\n\n",
2303 ret ? "succeeded" : "failed");
2309 static bool test_ClosePrinter(struct torture_context *tctx,
2310 struct dcerpc_binding_handle *b,
2311 struct policy_handle *handle)
2314 struct spoolss_ClosePrinter r;
2316 r.in.handle = handle;
2317 r.out.handle = handle;
2319 torture_comment(tctx, "Testing ClosePrinter\n");
2321 status = dcerpc_spoolss_ClosePrinter_r(b, tctx, &r);
2322 torture_assert_ntstatus_ok(tctx, status, "ClosePrinter failed");
2323 torture_assert_werr_ok(tctx, r.out.result, "ClosePrinter failed");
2328 static bool test_GetForm_args(struct torture_context *tctx,
2329 struct dcerpc_binding_handle *b,
2330 struct policy_handle *handle,
2331 const char *form_name,
2333 union spoolss_FormInfo *info_p)
2336 struct spoolss_GetForm r;
2339 r.in.handle = handle;
2340 r.in.form_name = form_name;
2344 r.out.needed = &needed;
2346 torture_comment(tctx, "Testing GetForm(%s) level %d\n", form_name, r.in.level);
2348 status = dcerpc_spoolss_GetForm_r(b, tctx, &r);
2349 torture_assert_ntstatus_ok(tctx, status, "GetForm failed");
2351 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
2352 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
2353 r.in.buffer = &blob;
2354 r.in.offered = needed;
2355 status = dcerpc_spoolss_GetForm_r(b, tctx, &r);
2356 torture_assert_ntstatus_ok(tctx, status, "GetForm failed");
2358 torture_assert_werr_ok(tctx, r.out.result, "GetForm failed");
2360 torture_assert(tctx, r.out.info, "No form info returned");
2363 torture_assert_werr_ok(tctx, r.out.result, "GetForm failed");
2365 CHECK_NEEDED_SIZE_LEVEL(spoolss_FormInfo, r.out.info, r.in.level, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
2368 *info_p = *r.out.info;
2374 static bool test_GetForm(struct torture_context *tctx,
2375 struct dcerpc_binding_handle *b,
2376 struct policy_handle *handle,
2377 const char *form_name,
2380 return test_GetForm_args(tctx, b, handle, form_name, level, NULL);
2383 static bool test_EnumForms(struct torture_context *tctx,
2384 struct dcerpc_binding_handle *b,
2385 struct policy_handle *handle,
2389 union spoolss_FormInfo **info_p)
2391 struct spoolss_EnumForms r;
2394 union spoolss_FormInfo *info;
2396 r.in.handle = handle;
2400 r.out.needed = &needed;
2401 r.out.count = &count;
2404 torture_comment(tctx, "Testing EnumForms level %d\n", r.in.level);
2406 torture_assert_ntstatus_ok(tctx,
2407 dcerpc_spoolss_EnumForms_r(b, tctx, &r),
2408 "EnumForms failed");
2410 if ((r.in.level == 2) && (W_ERROR_EQUAL(r.out.result, WERR_UNKNOWN_LEVEL))) {
2411 torture_skip(tctx, "EnumForms level 2 not supported");
2414 if (print_server && W_ERROR_EQUAL(r.out.result, WERR_BADFID)) {
2415 torture_fail(tctx, "EnumForms on the PrintServer isn't supported by test server (NT4)");
2418 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
2419 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
2420 r.in.buffer = &blob;
2421 r.in.offered = needed;
2423 torture_assert_ntstatus_ok(tctx,
2424 dcerpc_spoolss_EnumForms_r(b, tctx, &r),
2425 "EnumForms failed");
2427 torture_assert(tctx, info, "No forms returned");
2430 torture_assert_werr_ok(tctx, r.out.result, "EnumForms failed");
2432 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumForms, info, r.in.level, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
2444 static bool test_EnumForms_all(struct torture_context *tctx,
2445 struct dcerpc_binding_handle *b,
2446 struct policy_handle *handle,
2449 uint32_t levels[] = { 1, 2 };
2452 for (i=0; i<ARRAY_SIZE(levels); i++) {
2455 union spoolss_FormInfo *info = NULL;
2457 torture_assert(tctx,
2458 test_EnumForms(tctx, b, handle, print_server, levels[i], &count, &info),
2459 "failed to enum forms");
2461 for (j = 0; j < count; j++) {
2462 if (!print_server) {
2463 torture_assert(tctx,
2464 test_GetForm(tctx, b, handle, info[j].info1.form_name, levels[i]),
2465 "failed to get form");
2473 static bool test_EnumForms_find_one(struct torture_context *tctx,
2474 struct dcerpc_binding_handle *b,
2475 struct policy_handle *handle,
2477 const char *form_name)
2479 union spoolss_FormInfo *info;
2484 torture_assert(tctx,
2485 test_EnumForms(tctx, b, handle, print_server, 1, &count, &info),
2486 "failed to enumerate forms");
2488 for (i=0; i<count; i++) {
2489 if (strequal(form_name, info[i].info1.form_name)) {
2498 static bool test_DeleteForm(struct torture_context *tctx,
2499 struct dcerpc_binding_handle *b,
2500 struct policy_handle *handle,
2501 const char *form_name,
2502 WERROR expected_result)
2504 struct spoolss_DeleteForm r;
2506 r.in.handle = handle;
2507 r.in.form_name = form_name;
2509 torture_comment(tctx, "Testing DeleteForm(%s)\n", form_name);
2511 torture_assert_ntstatus_ok(tctx,
2512 dcerpc_spoolss_DeleteForm_r(b, tctx, &r),
2513 "DeleteForm failed");
2514 torture_assert_werr_equal(tctx, r.out.result, expected_result,
2515 "DeleteForm gave unexpected result");
2516 if (W_ERROR_IS_OK(r.out.result)) {
2517 torture_assert_ntstatus_ok(tctx,
2518 dcerpc_spoolss_DeleteForm_r(b, tctx, &r),
2519 "2nd DeleteForm failed");
2520 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_FORM_NAME,
2521 "2nd DeleteForm failed");
2527 static bool test_AddForm(struct torture_context *tctx,
2528 struct dcerpc_binding_handle *b,
2529 struct policy_handle *handle,
2531 union spoolss_AddFormInfo *info,
2532 WERROR expected_result)
2534 struct spoolss_AddForm r;
2537 torture_skip(tctx, "only level 1 supported");
2540 r.in.handle = handle;
2544 torture_comment(tctx, "Testing AddForm(%s) level %d, type %d\n",
2545 r.in.info.info1->form_name, r.in.level,
2546 r.in.info.info1->flags);
2548 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_AddForm_r(b, tctx, &r),
2550 torture_assert_werr_equal(tctx, r.out.result, expected_result,
2551 "AddForm gave unexpected result");
2553 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_AddForm_r(b, tctx, &r),
2554 "2nd AddForm failed");
2555 if (W_ERROR_EQUAL(expected_result, WERR_INVALID_PARAM)) {
2556 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAM,
2557 "2nd AddForm gave unexpected result");
2559 torture_assert_werr_equal(tctx, r.out.result, WERR_FILE_EXISTS,
2560 "2nd AddForm gave unexpected result");
2566 static bool test_SetForm(struct torture_context *tctx,
2567 struct dcerpc_binding_handle *b,
2568 struct policy_handle *handle,
2569 const char *form_name,
2571 union spoolss_AddFormInfo *info)
2573 struct spoolss_SetForm r;
2575 r.in.handle = handle;
2576 r.in.form_name = form_name;
2580 torture_comment(tctx, "Testing SetForm(%s) level %d\n",
2581 form_name, r.in.level);
2583 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_SetForm_r(b, tctx, &r),
2586 torture_assert_werr_ok(tctx, r.out.result,
2592 static bool test_GetForm_winreg(struct torture_context *tctx,
2593 struct dcerpc_binding_handle *b,
2594 struct policy_handle *handle,
2595 const char *key_name,
2596 const char *form_name,
2597 enum winreg_Type *w_type,
2602 static bool test_Forms_args(struct torture_context *tctx,
2603 struct dcerpc_binding_handle *b,
2604 struct policy_handle *handle,
2606 const char *printer_name,
2607 struct dcerpc_binding_handle *winreg_handle,
2608 struct policy_handle *hive_handle,
2609 const char *form_name,
2610 struct spoolss_AddFormInfo1 *info1,
2611 WERROR expected_add_result,
2612 WERROR expected_delete_result)
2614 union spoolss_FormInfo info;
2615 union spoolss_AddFormInfo add_info;
2617 enum winreg_Type w_type;
2622 add_info.info1 = info1;
2624 torture_assert(tctx,
2625 test_AddForm(tctx, b, handle, 1, &add_info, expected_add_result),
2626 "failed to add form");
2628 if (winreg_handle && hive_handle && W_ERROR_IS_OK(expected_add_result)) {
2630 torture_assert(tctx,
2631 test_GetForm_winreg(tctx, winreg_handle, hive_handle, TOP_LEVEL_CONTROL_FORMS_KEY, form_name, &w_type, &w_size, &w_length, &w_data),
2632 "failed to get form via winreg");
2634 torture_assert_int_equal(tctx, w_type, REG_BINARY, "unexpected type");
2635 torture_assert_int_equal(tctx, w_size, 0x20, "unexpected size");
2636 torture_assert_int_equal(tctx, w_length, 0x20, "unexpected length");
2637 torture_assert_mem_equal(tctx, &w_data[0], &add_info.info1->size.width, 4, "width mismatch");
2638 torture_assert_mem_equal(tctx, &w_data[4], &add_info.info1->size.height, 4, "height mismatch");
2639 torture_assert_mem_equal(tctx, &w_data[8], &add_info.info1->area.left, 4, "left mismatch");
2640 torture_assert_mem_equal(tctx, &w_data[12], &add_info.info1->area.top, 4, "top mismatch");
2641 torture_assert_mem_equal(tctx, &w_data[16], &add_info.info1->area.right, 4, "right mismatch");
2642 torture_assert_mem_equal(tctx, &w_data[20], &add_info.info1->area.bottom, 4, "bottom mismatch");
2643 /* skip index here */
2644 torture_assert_mem_equal(tctx, &w_data[28], &add_info.info1->flags, 4, "flags mismatch");
2647 if (!print_server && W_ERROR_IS_OK(expected_add_result)) {
2648 torture_assert(tctx,
2649 test_GetForm_args(tctx, b, handle, form_name, 1, &info),
2650 "failed to get added form");
2652 torture_assert_int_equal(tctx, info.info1.size.width, add_info.info1->size.width, "width mismatch");
2653 torture_assert_int_equal(tctx, info.info1.size.height, add_info.info1->size.height, "height mismatch");
2654 torture_assert_int_equal(tctx, info.info1.area.left, add_info.info1->area.left, "left mismatch");
2655 torture_assert_int_equal(tctx, info.info1.area.top, add_info.info1->area.top, "top mismatch");
2656 torture_assert_int_equal(tctx, info.info1.area.right, add_info.info1->area.right, "right mismatch");
2657 torture_assert_int_equal(tctx, info.info1.area.bottom, add_info.info1->area.bottom, "bottom mismatch");
2658 torture_assert_int_equal(tctx, info.info1.flags, add_info.info1->flags, "flags mismatch");
2660 if (winreg_handle && hive_handle) {
2661 torture_assert_mem_equal(tctx, &w_data[0], &info.info1.size.width, 4, "width mismatch");
2662 torture_assert_mem_equal(tctx, &w_data[4], &info.info1.size.height, 4, "height mismatch");
2663 torture_assert_mem_equal(tctx, &w_data[8], &info.info1.area.left, 4, "left mismatch");
2664 torture_assert_mem_equal(tctx, &w_data[12], &info.info1.area.top, 4, "top mismatch");
2665 torture_assert_mem_equal(tctx, &w_data[16], &info.info1.area.right, 4, "right mismatch");
2666 torture_assert_mem_equal(tctx, &w_data[20], &info.info1.area.bottom, 4, "bottom mismatch");
2667 /* skip index here */
2668 torture_assert_mem_equal(tctx, &w_data[28], &info.info1.flags, 4, "flags mismatch");
2671 add_info.info1->size.width = 1234;
2673 torture_assert(tctx,
2674 test_SetForm(tctx, b, handle, form_name, 1, &add_info),
2675 "failed to set form");
2676 torture_assert(tctx,
2677 test_GetForm_args(tctx, b, handle, form_name, 1, &info),
2678 "failed to get setted form");
2680 torture_assert_int_equal(tctx, info.info1.size.width, add_info.info1->size.width, "width mismatch");
2683 if (!W_ERROR_EQUAL(expected_add_result, WERR_INVALID_PARAM)) {
2684 torture_assert(tctx,
2685 test_EnumForms_find_one(tctx, b, handle, print_server, form_name),
2686 "Newly added form not found in enum call");
2689 torture_assert(tctx,
2690 test_DeleteForm(tctx, b, handle, form_name, expected_delete_result),
2691 "failed to delete form");
2696 static bool test_Forms(struct torture_context *tctx,
2697 struct dcerpc_binding_handle *b,
2698 struct policy_handle *handle,
2700 const char *printer_name,
2701 struct dcerpc_binding_handle *winreg_handle,
2702 struct policy_handle *hive_handle)
2704 const struct spoolss_FormSize size = {
2708 const struct spoolss_FormArea area = {
2717 struct spoolss_AddFormInfo1 info1;
2718 WERROR expected_add_result;
2719 WERROR expected_delete_result;
2723 .flags = SPOOLSS_FORM_USER,
2724 .form_name = "testform_user",
2728 .expected_add_result = WERR_OK,
2729 .expected_delete_result = WERR_OK
2732 weird, we can add a builtin form but we can never remove it
2737 .flags = SPOOLSS_FORM_BUILTIN,
2738 .form_name = "testform_builtin",
2742 .expected_add_result = WERR_OK,
2743 .expected_delete_result = WERR_INVALID_PARAM,
2748 .flags = SPOOLSS_FORM_PRINTER,
2749 .form_name = "testform_printer",
2753 .expected_add_result = WERR_OK,
2754 .expected_delete_result = WERR_OK
2758 .flags = SPOOLSS_FORM_USER,
2759 .form_name = "Letter",
2763 .expected_add_result = WERR_FILE_EXISTS,
2764 .expected_delete_result = WERR_INVALID_PARAM
2768 .flags = SPOOLSS_FORM_BUILTIN,
2769 .form_name = "Letter",
2773 .expected_add_result = WERR_FILE_EXISTS,
2774 .expected_delete_result = WERR_INVALID_PARAM
2778 .flags = SPOOLSS_FORM_PRINTER,
2779 .form_name = "Letter",
2783 .expected_add_result = WERR_FILE_EXISTS,
2784 .expected_delete_result = WERR_INVALID_PARAM
2789 .form_name = "invalid_flags",
2793 .expected_add_result = WERR_INVALID_PARAM,
2794 .expected_delete_result = WERR_INVALID_FORM_NAME
2799 for (i=0; i < ARRAY_SIZE(forms); i++) {
2800 torture_assert(tctx,
2801 test_Forms_args(tctx, b, handle, print_server, printer_name,
2802 winreg_handle, hive_handle,
2803 forms[i].info1.form_name,
2805 forms[i].expected_add_result,
2806 forms[i].expected_delete_result),
2807 talloc_asprintf(tctx, "failed to test form '%s'", forms[i].info1.form_name));
2813 static bool test_EnumPorts_old(struct torture_context *tctx,
2814 struct dcerpc_pipe *p)
2817 struct spoolss_EnumPorts r;
2820 union spoolss_PortInfo *info;
2821 struct dcerpc_binding_handle *b = p->binding_handle;
2823 r.in.servername = talloc_asprintf(tctx, "\\\\%s",
2824 dcerpc_server_name(p));
2828 r.out.needed = &needed;
2829 r.out.count = &count;
2832 torture_comment(tctx, "Testing EnumPorts\n");
2834 status = dcerpc_spoolss_EnumPorts_r(b, tctx, &r);
2836 torture_assert_ntstatus_ok(tctx, status, "EnumPorts failed");
2838 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
2839 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
2840 r.in.buffer = &blob;
2841 r.in.offered = needed;
2843 status = dcerpc_spoolss_EnumPorts_r(b, tctx, &r);
2844 torture_assert_ntstatus_ok(tctx, status, "EnumPorts failed");
2845 torture_assert_werr_ok(tctx, r.out.result, "EnumPorts failed");
2847 torture_assert(tctx, info, "No ports returned");
2850 torture_assert_werr_ok(tctx, r.out.result, "EnumPorts failed");
2852 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPorts, info, 2, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
2857 static bool test_AddPort(struct torture_context *tctx,
2858 struct dcerpc_pipe *p)
2861 struct spoolss_AddPort r;
2862 struct dcerpc_binding_handle *b = p->binding_handle;
2864 r.in.server_name = talloc_asprintf(tctx, "\\\\%s",
2865 dcerpc_server_name(p));
2867 r.in.monitor_name = "foo";
2869 torture_comment(tctx, "Testing AddPort\n");
2871 status = dcerpc_spoolss_AddPort_r(b, tctx, &r);
2873 torture_assert_ntstatus_ok(tctx, status, "AddPort failed");
2875 /* win2k3 returns WERR_NOT_SUPPORTED */
2879 if (!W_ERROR_IS_OK(r.out.result)) {
2880 printf("AddPort failed - %s\n", win_errstr(r.out.result));
2889 static bool test_GetJob_args(struct torture_context *tctx,
2890 struct dcerpc_binding_handle *b,
2891 struct policy_handle *handle,
2894 union spoolss_JobInfo *info_p)
2897 struct spoolss_GetJob r;
2898 union spoolss_JobInfo info;
2901 r.in.handle = handle;
2902 r.in.job_id = job_id;
2906 r.out.needed = &needed;
2909 torture_comment(tctx, "Testing GetJob(%d), level %d\n", job_id, r.in.level);
2911 status = dcerpc_spoolss_GetJob_r(b, tctx, &r);
2912 torture_assert_ntstatus_ok(tctx, status, "GetJob failed");
2914 torture_assert_werr_equal(tctx, r.out.result, WERR_UNKNOWN_LEVEL, "Unexpected return code");
2917 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
2918 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
2919 r.in.buffer = &blob;
2920 r.in.offered = needed;
2922 status = dcerpc_spoolss_GetJob_r(b, tctx, &r);
2923 torture_assert_ntstatus_ok(tctx, status, "GetJob failed");
2926 torture_assert_werr_ok(tctx, r.out.result, "GetJob failed");
2927 torture_assert(tctx, r.out.info, "No job info returned");
2929 CHECK_NEEDED_SIZE_LEVEL(spoolss_JobInfo, r.out.info, r.in.level, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
2932 *info_p = *r.out.info;
2938 static bool test_GetJob(struct torture_context *tctx,
2939 struct dcerpc_binding_handle *b,
2940 struct policy_handle *handle,
2943 uint32_t levels[] = {0, 1, 2 /* 3, 4 */};
2946 for (i=0; i < ARRAY_SIZE(levels); i++) {
2947 torture_assert(tctx,
2948 test_GetJob_args(tctx, b, handle, job_id, levels[i], NULL),
2955 static bool test_SetJob(struct torture_context *tctx,
2956 struct dcerpc_binding_handle *b,
2957 struct policy_handle *handle,
2959 struct spoolss_JobInfoContainer *ctr,
2960 enum spoolss_JobControl command)
2963 struct spoolss_SetJob r;
2965 r.in.handle = handle;
2966 r.in.job_id = job_id;
2968 r.in.command = command;
2971 case SPOOLSS_JOB_CONTROL_PAUSE:
2972 torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_PAUSE\n", job_id);
2974 case SPOOLSS_JOB_CONTROL_RESUME:
2975 torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_RESUME\n", job_id);
2977 case SPOOLSS_JOB_CONTROL_CANCEL:
2978 torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_CANCEL\n", job_id);
2980 case SPOOLSS_JOB_CONTROL_RESTART:
2981 torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_RESTART\n", job_id);
2983 case SPOOLSS_JOB_CONTROL_DELETE:
2984 torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_DELETE\n", job_id);
2986 case SPOOLSS_JOB_CONTROL_SEND_TO_PRINTER:
2987 torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_SEND_TO_PRINTER\n", job_id);
2989 case SPOOLSS_JOB_CONTROL_LAST_PAGE_EJECTED:
2990 torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_LAST_PAGE_EJECTED\n", job_id);
2992 case SPOOLSS_JOB_CONTROL_RETAIN:
2993 torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_RETAIN\n", job_id);
2995 case SPOOLSS_JOB_CONTROL_RELEASE:
2996 torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_RELEASE\n", job_id);
2999 torture_comment(tctx, "Testing SetJob(%d)\n", job_id);
3003 status = dcerpc_spoolss_SetJob_r(b, tctx, &r);
3004 torture_assert_ntstatus_ok(tctx, status, "SetJob failed");
3005 torture_assert_werr_ok(tctx, r.out.result, "SetJob failed");
3010 static bool test_AddJob(struct torture_context *tctx,
3011 struct dcerpc_binding_handle *b,
3012 struct policy_handle *handle)
3015 struct spoolss_AddJob r;
3019 r.in.handle = handle;
3021 r.out.needed = &needed;
3022 r.in.buffer = r.out.buffer = NULL;
3024 torture_comment(tctx, "Testing AddJob\n");
3026 status = dcerpc_spoolss_AddJob_r(b, tctx, &r);
3027 torture_assert_werr_equal(tctx, r.out.result, WERR_UNKNOWN_LEVEL, "AddJob failed");
3031 status = dcerpc_spoolss_AddJob_r(b, tctx, &r);
3032 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAM, "AddJob failed");
3038 static bool test_EnumJobs_args(struct torture_context *tctx,
3039 struct dcerpc_binding_handle *b,
3040 struct policy_handle *handle,
3043 union spoolss_JobInfo **info_p)
3046 struct spoolss_EnumJobs r;
3049 union spoolss_JobInfo *info;
3051 r.in.handle = handle;
3053 r.in.numjobs = 0xffffffff;
3057 r.out.needed = &needed;
3058 r.out.count = &count;
3061 torture_comment(tctx, "Testing EnumJobs level %d\n", level);
3063 status = dcerpc_spoolss_EnumJobs_r(b, tctx, &r);
3065 torture_assert_ntstatus_ok(tctx, status, "EnumJobs failed");
3067 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
3068 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
3069 r.in.buffer = &blob;
3070 r.in.offered = needed;
3072 status = dcerpc_spoolss_EnumJobs_r(b, tctx, &r);
3074 torture_assert_ntstatus_ok(tctx, status, "EnumJobs failed");
3075 torture_assert_werr_ok(tctx, r.out.result, "EnumJobs failed");
3076 torture_assert(tctx, info, "No jobs returned");
3078 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumJobs, *r.out.info, r.in.level, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
3081 torture_assert_werr_ok(tctx, r.out.result, "EnumJobs failed");
3094 static bool test_DoPrintTest_add_one_job(struct torture_context *tctx,
3095 struct dcerpc_binding_handle *b,
3096 struct policy_handle *handle,
3100 struct spoolss_StartDocPrinter s;
3101 struct spoolss_DocumentInfo1 info1;
3102 struct spoolss_StartPagePrinter sp;
3103 struct spoolss_WritePrinter w;
3104 struct spoolss_EndPagePrinter ep;
3105 struct spoolss_EndDocPrinter e;
3107 uint32_t num_written;
3109 torture_comment(tctx, "Testing StartDocPrinter\n");
3111 s.in.handle = handle;
3113 s.in.info.info1 = &info1;
3114 s.out.job_id = job_id;
3115 info1.document_name = "TorturePrintJob";
3116 info1.output_file = NULL;
3117 info1.datatype = "RAW";
3119 status = dcerpc_spoolss_StartDocPrinter_r(b, tctx, &s);
3120 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_StartDocPrinter failed");
3121 torture_assert_werr_ok(tctx, s.out.result, "StartDocPrinter failed");
3123 for (i=1; i < 4; i++) {
3124 torture_comment(tctx, "Testing StartPagePrinter: Page[%d], JobId[%d]\n", i, *job_id);
3126 sp.in.handle = handle;
3128 status = dcerpc_spoolss_StartPagePrinter_r(b, tctx, &sp);
3129 torture_assert_ntstatus_ok(tctx, status,
3130 "dcerpc_spoolss_StartPagePrinter failed");
3131 torture_assert_werr_ok(tctx, sp.out.result, "StartPagePrinter failed");
3133 torture_comment(tctx, "Testing WritePrinter: Page[%d], JobId[%d]\n", i, *job_id);
3135 w.in.handle = handle;
3136 w.in.data = data_blob_string_const(talloc_asprintf(tctx,"TortureTestPage: %d\nData\n",i));
3137 w.out.num_written = &num_written;
3139 status = dcerpc_spoolss_WritePrinter_r(b, tctx, &w);
3140 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_WritePrinter failed");
3141 torture_assert_werr_ok(tctx, w.out.result, "WritePrinter failed");
3143 torture_comment(tctx, "Testing EndPagePrinter: Page[%d], JobId[%d]\n", i, *job_id);
3145 ep.in.handle = handle;
3147 status = dcerpc_spoolss_EndPagePrinter_r(b, tctx, &ep);
3148 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EndPagePrinter failed");
3149 torture_assert_werr_ok(tctx, ep.out.result, "EndPagePrinter failed");
3152 torture_comment(tctx, "Testing EndDocPrinter: JobId[%d]\n", *job_id);
3154 e.in.handle = handle;
3156 status = dcerpc_spoolss_EndDocPrinter_r(b, tctx, &e);
3157 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EndDocPrinter failed");
3158 torture_assert_werr_ok(tctx, e.out.result, "EndDocPrinter failed");
3163 static bool test_DoPrintTest_check_jobs(struct torture_context *tctx,
3164 struct dcerpc_binding_handle *b,
3165 struct policy_handle *handle,
3170 union spoolss_JobInfo *info = NULL;
3173 torture_assert(tctx,
3174 test_AddJob(tctx, b, handle),
3177 torture_assert(tctx,
3178 test_EnumJobs_args(tctx, b, handle, 1, &count, &info),
3179 "EnumJobs level 1 failed");
3181 torture_assert_int_equal(tctx, count, num_jobs, "unexpected number of jobs in queue");
3183 for (i=0; i < num_jobs; i++) {
3184 union spoolss_JobInfo ginfo;
3186 torture_assert_int_equal(tctx, info[i].info1.job_id, job_ids[i], "job id mismatch");
3188 torture_assert(tctx,
3189 test_GetJob_args(tctx, b, handle, info[i].info1.job_id, 1, &ginfo),
3190 "failed to call test_GetJob");
3192 torture_assert_int_equal(tctx, ginfo.info1.job_id, info[i].info1.job_id, "job id mismatch");
3195 for (i=0; i < num_jobs; i++) {
3196 if (!test_SetJob(tctx, b, handle, info[i].info1.job_id, NULL, SPOOLSS_JOB_CONTROL_PAUSE)) {
3197 torture_warning(tctx, "failed to pause printjob\n");
3199 if (!test_SetJob(tctx, b, handle, info[i].info1.job_id, NULL, SPOOLSS_JOB_CONTROL_RESUME)) {
3200 torture_warning(tctx, "failed to resume printjob\n");
3207 static bool test_DoPrintTest(struct torture_context *tctx,
3208 struct dcerpc_binding_handle *b,
3209 struct policy_handle *handle)
3212 uint32_t num_jobs = 8;
3216 job_ids = talloc_zero_array(tctx, uint32_t, num_jobs);
3218 for (i=0; i < num_jobs; i++) {
3219 ret &= test_DoPrintTest_add_one_job(tctx, b, handle, &job_ids[i]);
3222 ret &= test_DoPrintTest_check_jobs(tctx, b, handle, num_jobs, job_ids);
3224 for (i=0; i < num_jobs; i++) {
3225 ret &= test_SetJob(tctx, b, handle, job_ids[i], NULL, SPOOLSS_JOB_CONTROL_DELETE);
3231 static bool test_PausePrinter(struct torture_context *tctx,
3232 struct dcerpc_binding_handle *b,
3233 struct policy_handle *handle)
3236 struct spoolss_SetPrinter r;
3237 struct spoolss_SetPrinterInfoCtr info_ctr;
3238 struct spoolss_DevmodeContainer devmode_ctr;
3239 struct sec_desc_buf secdesc_ctr;
3242 info_ctr.info.info0 = NULL;
3244 ZERO_STRUCT(devmode_ctr);
3245 ZERO_STRUCT(secdesc_ctr);
3247 r.in.handle = handle;
3248 r.in.info_ctr = &info_ctr;
3249 r.in.devmode_ctr = &devmode_ctr;
3250 r.in.secdesc_ctr = &secdesc_ctr;
3251 r.in.command = SPOOLSS_PRINTER_CONTROL_PAUSE;
3253 torture_comment(tctx, "Testing SetPrinter: SPOOLSS_PRINTER_CONTROL_PAUSE\n");
3255 status = dcerpc_spoolss_SetPrinter_r(b, tctx, &r);
3257 torture_assert_ntstatus_ok(tctx, status, "SetPrinter failed");
3259 torture_assert_werr_ok(tctx, r.out.result, "SetPrinter failed");
3264 static bool test_ResumePrinter(struct torture_context *tctx,
3265 struct dcerpc_binding_handle *b,
3266 struct policy_handle *handle)
3269 struct spoolss_SetPrinter r;
3270 struct spoolss_SetPrinterInfoCtr info_ctr;
3271 struct spoolss_DevmodeContainer devmode_ctr;
3272 struct sec_desc_buf secdesc_ctr;
3275 info_ctr.info.info0 = NULL;
3277 ZERO_STRUCT(devmode_ctr);
3278 ZERO_STRUCT(secdesc_ctr);
3280 r.in.handle = handle;
3281 r.in.info_ctr = &info_ctr;
3282 r.in.devmode_ctr = &devmode_ctr;
3283 r.in.secdesc_ctr = &secdesc_ctr;
3284 r.in.command = SPOOLSS_PRINTER_CONTROL_RESUME;
3286 torture_comment(tctx, "Testing SetPrinter: SPOOLSS_PRINTER_CONTROL_RESUME\n");
3288 status = dcerpc_spoolss_SetPrinter_r(b, tctx, &r);
3290 torture_assert_ntstatus_ok(tctx, status, "SetPrinter failed");
3292 torture_assert_werr_ok(tctx, r.out.result, "SetPrinter failed");
3297 static bool test_GetPrinterData(struct torture_context *tctx,
3298 struct dcerpc_binding_handle *b,
3299 struct policy_handle *handle,
3300 const char *value_name,
3301 enum winreg_Type *type_p,
3306 struct spoolss_GetPrinterData r;
3308 enum winreg_Type type;
3309 union spoolss_PrinterData data;
3311 r.in.handle = handle;
3312 r.in.value_name = value_name;
3314 r.out.needed = &needed;
3316 r.out.data = talloc_zero_array(tctx, uint8_t, r.in.offered);
3318 torture_comment(tctx, "Testing GetPrinterData(%s)\n", r.in.value_name);
3320 status = dcerpc_spoolss_GetPrinterData_r(b, tctx, &r);
3321 torture_assert_ntstatus_ok(tctx, status, "GetPrinterData failed");
3323 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
3324 r.in.offered = needed;
3325 r.out.data = talloc_zero_array(tctx, uint8_t, r.in.offered);
3326 status = dcerpc_spoolss_GetPrinterData_r(b, tctx, &r);
3327 torture_assert_ntstatus_ok(tctx, status, "GetPrinterData failed");
3330 torture_assert_werr_ok(tctx, r.out.result,
3331 talloc_asprintf(tctx, "GetPrinterData(%s) failed", r.in.value_name));
3333 CHECK_NEEDED_SIZE_LEVEL(spoolss_PrinterData, &data, type, lp_iconv_convenience(tctx->lp_ctx), needed, 1);
3340 *data_p = r.out.data;
3350 static bool test_GetPrinterDataEx(struct torture_context *tctx,
3351 struct dcerpc_pipe *p,
3352 struct policy_handle *handle,
3353 const char *key_name,
3354 const char *value_name,
3355 enum winreg_Type *type_p,
3360 struct spoolss_GetPrinterDataEx r;
3361 enum winreg_Type type;
3363 union spoolss_PrinterData data;
3364 struct dcerpc_binding_handle *b = p->binding_handle;
3366 r.in.handle = handle;
3367 r.in.key_name = key_name;
3368 r.in.value_name = value_name;
3371 r.out.needed = &needed;
3372 r.out.data = talloc_zero_array(tctx, uint8_t, r.in.offered);
3374 torture_comment(tctx, "Testing GetPrinterDataEx(%s - %s)\n",
3375 r.in.key_name, r.in.value_name);
3377 status = dcerpc_spoolss_GetPrinterDataEx_r(b, tctx, &r);
3378 if (!NT_STATUS_IS_OK(status)) {
3379 if (NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROCNUM_OUT_OF_RANGE)) {
3380 torture_skip(tctx, "GetPrinterDataEx not supported by server\n");
3382 torture_assert_ntstatus_ok(tctx, status, "GetPrinterDataEx failed");
3385 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
3386 r.in.offered = needed;
3387 r.out.data = talloc_zero_array(tctx, uint8_t, r.in.offered);
3388 status = dcerpc_spoolss_GetPrinterDataEx_r(b, tctx, &r);
3389 torture_assert_ntstatus_ok(tctx, status, "GetPrinterDataEx failed");
3392 torture_assert_werr_ok(tctx, r.out.result,
3393 talloc_asprintf(tctx, "GetPrinterDataEx(%s - %s) failed", r.in.key_name, r.in.value_name));
3395 CHECK_NEEDED_SIZE_LEVEL(spoolss_PrinterData, &data, type, lp_iconv_convenience(tctx->lp_ctx), needed, 1);
3402 *data_p = r.out.data;
3412 static bool test_get_environment(struct torture_context *tctx,
3413 struct dcerpc_binding_handle *b,
3414 struct policy_handle *handle,
3415 const char **architecture)
3418 enum winreg_Type type;
3422 torture_assert(tctx,
3423 test_GetPrinterData(tctx, b, handle, "Architecture", &type, &data, &needed),
3424 "failed to get Architecture");
3426 torture_assert_int_equal(tctx, type, REG_SZ, "unexpected type");
3428 blob = data_blob_const(data, needed);
3429 *architecture = reg_val_data_string(tctx, lp_iconv_convenience(tctx->lp_ctx), REG_SZ, blob);
3434 static bool test_GetPrinterData_list(struct torture_context *tctx,
3435 struct dcerpc_pipe *p,
3436 struct policy_handle *handle,
3437 const char **architecture)
3439 struct dcerpc_binding_handle *b = p->binding_handle;
3440 const char *list[] = {
3444 /* "NetPopup", not on w2k8 */
3445 /* "NetPopupToComputer", not on w2k8 */
3448 "DefaultSpoolDirectory",
3452 /* "OSVersionEx", not on s3 */
3457 for (i=0; i < ARRAY_SIZE(list); i++) {
3458 enum winreg_Type type, type_ex;
3459 uint8_t *data, *data_ex;
3460 uint32_t needed, needed_ex;
3462 torture_assert(tctx, test_GetPrinterData(tctx, b, handle, list[i], &type, &data, &needed),
3463 talloc_asprintf(tctx, "GetPrinterData failed on %s\n", list[i]));
3464 torture_assert(tctx, test_GetPrinterDataEx(tctx, p, handle, "random_string", list[i], &type_ex, &data_ex, &needed_ex),
3465 talloc_asprintf(tctx, "GetPrinterDataEx failed on %s\n", list[i]));
3466 torture_assert_int_equal(tctx, type, type_ex, "type mismatch");
3467 torture_assert_int_equal(tctx, needed, needed_ex, "needed mismatch");
3468 torture_assert_mem_equal(tctx, data, data_ex, needed, "data mismatch");
3470 if (strequal(list[i], "Architecture")) {
3472 DATA_BLOB blob = data_blob_const(data, needed);
3473 *architecture = reg_val_data_string(tctx, lp_iconv_convenience(tctx->lp_ctx), REG_SZ, blob);
3481 static bool test_EnumPrinterData(struct torture_context *tctx,
3482 struct dcerpc_pipe *p,
3483 struct policy_handle *handle,
3484 uint32_t enum_index,
3485 uint32_t value_offered,
3486 uint32_t data_offered,
3487 enum winreg_Type *type_p,
3488 uint32_t *value_needed_p,
3489 uint32_t *data_needed_p,
3490 const char **value_name_p,
3494 struct spoolss_EnumPrinterData r;
3495 uint32_t data_needed;
3496 uint32_t value_needed;
3497 enum winreg_Type type;
3498 struct dcerpc_binding_handle *b = p->binding_handle;
3500 r.in.handle = handle;
3501 r.in.enum_index = enum_index;
3502 r.in.value_offered = value_offered;
3503 r.in.data_offered = data_offered;
3504 r.out.data_needed = &data_needed;
3505 r.out.value_needed = &value_needed;
3507 r.out.data = talloc_zero_array(tctx, uint8_t, r.in.data_offered);
3508 r.out.value_name = talloc_zero_array(tctx, const char, r.in.value_offered);
3510 torture_comment(tctx, "Testing EnumPrinterData(%d)\n", enum_index);
3512 torture_assert_ntstatus_ok(tctx,
3513 dcerpc_spoolss_EnumPrinterData_r(b, tctx, &r),
3514 "EnumPrinterData failed");
3519 if (value_needed_p) {
3520 *value_needed_p = value_needed;
3522 if (data_needed_p) {
3523 *data_needed_p = data_needed;
3526 *value_name_p = r.out.value_name;
3529 *data_p = r.out.data;
3532 *result_p = r.out.result;
3539 static bool test_EnumPrinterData_all(struct torture_context *tctx,
3540 struct dcerpc_pipe *p,
3541 struct policy_handle *handle)
3543 uint32_t enum_index = 0;
3544 enum winreg_Type type;
3545 uint32_t value_needed;
3546 uint32_t data_needed;
3548 const char *value_name;
3551 torture_comment(tctx, "Testing EnumPrinterData\n");
3554 torture_assert(tctx,
3555 test_EnumPrinterData(tctx, p, handle, enum_index, 0, 0,
3556 &type, &value_needed, &data_needed,
3557 &value_name, &data, &result),
3558 "EnumPrinterData failed");
3560 if (W_ERROR_EQUAL(result, WERR_NO_MORE_ITEMS)) {
3564 torture_assert(tctx,
3565 test_EnumPrinterData(tctx, p, handle, enum_index, value_needed, data_needed,
3566 &type, &value_needed, &data_needed,
3567 &value_name, &data, &result),
3568 "EnumPrinterData failed");
3570 if (W_ERROR_EQUAL(result, WERR_NO_MORE_ITEMS)) {
3576 } while (W_ERROR_IS_OK(result));
3578 torture_comment(tctx, "EnumPrinterData test succeeded\n");
3583 static bool test_EnumPrinterDataEx(struct torture_context *tctx,
3584 struct dcerpc_binding_handle *b,
3585 struct policy_handle *handle,
3586 const char *key_name,
3588 struct spoolss_PrinterEnumValues **info_p)
3590 struct spoolss_EnumPrinterDataEx r;
3591 struct spoolss_PrinterEnumValues *info;
3595 r.in.handle = handle;
3596 r.in.key_name = key_name;
3598 r.out.needed = &needed;
3599 r.out.count = &count;
3602 torture_comment(tctx, "Testing EnumPrinterDataEx(%s)\n", key_name);
3604 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinterDataEx_r(b, tctx, &r),
3605 "EnumPrinterDataEx failed");
3606 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
3607 r.in.offered = needed;
3608 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinterDataEx_r(b, tctx, &r),
3609 "EnumPrinterDataEx failed");
3612 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinterDataEx failed");
3614 CHECK_NEEDED_SIZE_ENUM(spoolss_EnumPrinterDataEx, info, count, lp_iconv_convenience(tctx->lp_ctx), needed, 1);
3626 static bool test_SetPrinterData(struct torture_context *tctx,
3627 struct dcerpc_binding_handle *b,
3628 struct policy_handle *handle,
3629 const char *value_name,
3630 enum winreg_Type type,
3633 static bool test_DeletePrinterData(struct torture_context *tctx,
3634 struct dcerpc_binding_handle *b,
3635 struct policy_handle *handle,
3636 const char *value_name);
3638 static bool test_EnumPrinterData_consistency(struct torture_context *tctx,
3639 struct dcerpc_pipe *p,
3640 struct policy_handle *handle)
3643 struct spoolss_PrinterEnumValues *info;
3645 uint32_t value_needed, data_needed;
3646 uint32_t value_offered, data_offered;
3648 struct dcerpc_binding_handle *b = p->binding_handle;
3650 enum winreg_Type type;
3653 torture_comment(tctx, "Testing EnumPrinterData vs EnumPrinterDataEx consistency\n");
3655 torture_assert(tctx,
3656 reg_string_to_val(tctx, lp_iconv_convenience(tctx->lp_ctx),
3657 "REG_SZ", "torture_data1", &type, &blob), "");
3659 torture_assert(tctx,
3660 test_SetPrinterData(tctx, b, handle, "torture_value1", type, blob.data, blob.length),
3661 "SetPrinterData failed");
3663 blob = data_blob_string_const("torture_data2");
3665 torture_assert(tctx,
3666 test_SetPrinterData(tctx, b, handle, "torture_value2", REG_BINARY, blob.data, blob.length),
3667 "SetPrinterData failed");
3669 blob = data_blob_talloc(tctx, NULL, 4);
3670 SIVAL(blob.data, 0, 0x11223344);
3672 torture_assert(tctx,
3673 test_SetPrinterData(tctx, b, handle, "torture_value3", type, blob.data, blob.length),
3674 "SetPrinterData failed");
3676 torture_assert(tctx,
3677 test_EnumPrinterDataEx(tctx, b, handle, "PrinterDriverData", &count, &info),
3678 "failed to call EnumPrinterDataEx");
3680 /* get the max sizes for value and data */
3682 torture_assert(tctx,
3683 test_EnumPrinterData(tctx, p, handle, 0, 0, 0,
3684 NULL, &value_needed, &data_needed,
3685 NULL, NULL, &result),
3686 "EnumPrinterData failed");
3687 torture_assert_werr_ok(tctx, result, "unexpected result");
3689 /* check if the reply from the EnumPrinterData really matches max values */
3691 for (i=0; i < count; i++) {
3692 if (info[i].value_name_len > value_needed) {
3694 talloc_asprintf(tctx,
3695 "EnumPrinterDataEx gave a reply with value length %d which is larger then expected max value length %d from EnumPrinterData",
3696 info[i].value_name_len, value_needed));
3698 if (info[i].data_length > data_needed) {
3700 talloc_asprintf(tctx,
3701 "EnumPrinterDataEx gave a reply with data length %d which is larger then expected max data length %d from EnumPrinterData",
3702 info[i].data_length, data_needed));
3706 /* assuming that both EnumPrinterData and EnumPrinterDataEx do either
3707 * sort or not sort the replies by value name, we should be able to do
3708 * the following entry comparison */
3710 data_offered = data_needed;
3711 value_offered = value_needed;
3713 for (i=0; i < count; i++) {
3715 const char *value_name;
3718 torture_assert(tctx,
3719 test_EnumPrinterData(tctx, p, handle, i, value_offered, data_offered,
3720 &type, &value_needed, &data_needed,
3721 &value_name, &data, &result),
3722 "EnumPrinterData failed");
3724 if (i -1 == count) {
3725 torture_assert_werr_equal(tctx, result, WERR_NO_MORE_ITEMS,
3726 "unexpected result");
3729 torture_assert_werr_ok(tctx, result, "unexpected result");
3732 torture_assert_int_equal(tctx, type, info[i].type, "type mismatch");
3733 torture_assert_int_equal(tctx, value_needed, info[i].value_name_len, "value name length mismatch");
3734 torture_assert_str_equal(tctx, value_name, info[i].value_name, "value name mismatch");
3735 torture_assert_int_equal(tctx, data_needed, info[i].data_length, "data length mismatch");
3736 torture_assert_mem_equal(tctx, data, info[i].data->data, info[i].data_length, "data mismatch");
3739 torture_assert(tctx,
3740 test_DeletePrinterData(tctx, b, handle, "torture_value1"),
3741 "DeletePrinterData failed");
3742 torture_assert(tctx,
3743 test_DeletePrinterData(tctx, b, handle, "torture_value2"),
3744 "DeletePrinterData failed");
3745 torture_assert(tctx,
3746 test_DeletePrinterData(tctx, b, handle, "torture_value3"),
3747 "DeletePrinterData failed");
3749 torture_comment(tctx, "EnumPrinterData vs EnumPrinterDataEx consistency test succeeded\n\n");
3754 static bool test_DeletePrinterData(struct torture_context *tctx,
3755 struct dcerpc_binding_handle *b,
3756 struct policy_handle *handle,
3757 const char *value_name)
3760 struct spoolss_DeletePrinterData r;
3762 r.in.handle = handle;
3763 r.in.value_name = value_name;
3765 torture_comment(tctx, "Testing DeletePrinterData(%s)\n",
3768 status = dcerpc_spoolss_DeletePrinterData_r(b, tctx, &r);
3770 torture_assert_ntstatus_ok(tctx, status, "DeletePrinterData failed");
3771 torture_assert_werr_ok(tctx, r.out.result, "DeletePrinterData failed");
3776 static bool test_DeletePrinterDataEx(struct torture_context *tctx,
3777 struct dcerpc_binding_handle *b,
3778 struct policy_handle *handle,
3779 const char *key_name,
3780 const char *value_name)
3782 struct spoolss_DeletePrinterDataEx r;
3784 r.in.handle = handle;
3785 r.in.key_name = key_name;
3786 r.in.value_name = value_name;
3788 torture_comment(tctx, "Testing DeletePrinterDataEx(%s - %s)\n",
3789 r.in.key_name, r.in.value_name);
3791 torture_assert_ntstatus_ok(tctx,
3792 dcerpc_spoolss_DeletePrinterDataEx_r(b, tctx, &r),
3793 "DeletePrinterDataEx failed");
3794 torture_assert_werr_ok(tctx, r.out.result,
3795 "DeletePrinterDataEx failed");
3800 static bool test_DeletePrinterKey(struct torture_context *tctx,
3801 struct dcerpc_binding_handle *b,
3802 struct policy_handle *handle,
3803 const char *key_name)
3805 struct spoolss_DeletePrinterKey r;
3807 r.in.handle = handle;
3808 r.in.key_name = key_name;
3810 torture_comment(tctx, "Testing DeletePrinterKey(%s)\n", r.in.key_name);
3812 if (strequal(key_name, "") && !torture_setting_bool(tctx, "dangerous", false)) {
3813 torture_skip(tctx, "not wiping out printer registry - enable dangerous tests to use\n");
3817 torture_assert_ntstatus_ok(tctx,
3818 dcerpc_spoolss_DeletePrinterKey_r(b, tctx, &r),
3819 "DeletePrinterKey failed");
3820 torture_assert_werr_ok(tctx, r.out.result,
3821 "DeletePrinterKey failed");
3826 static bool test_winreg_OpenHKLM(struct torture_context *tctx,
3827 struct dcerpc_binding_handle *b,
3828 struct policy_handle *handle)
3830 struct winreg_OpenHKLM r;
3832 r.in.system_name = NULL;
3833 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3834 r.out.handle = handle;
3836 torture_comment(tctx, "Testing winreg_OpenHKLM\n");
3838 torture_assert_ntstatus_ok(tctx, dcerpc_winreg_OpenHKLM_r(b, tctx, &r), "OpenHKLM failed");
3839 torture_assert_werr_ok(tctx, r.out.result, "OpenHKLM failed");
3844 static void init_winreg_String(struct winreg_String *name, const char *s)
3848 name->name_len = 2 * (strlen_m(s) + 1);
3849 name->name_size = name->name_len;
3852 name->name_size = 0;
3856 static bool test_winreg_OpenKey_opts(struct torture_context *tctx,
3857 struct dcerpc_binding_handle *b,
3858 struct policy_handle *hive_handle,
3859 const char *keyname,
3861 struct policy_handle *key_handle)
3863 struct winreg_OpenKey r;
3865 r.in.parent_handle = hive_handle;
3866 init_winreg_String(&r.in.keyname, keyname);
3867 r.in.options = options;
3868 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3869 r.out.handle = key_handle;
3871 torture_comment(tctx, "Testing winreg_OpenKey(%s)\n", keyname);
3873 torture_assert_ntstatus_ok(tctx, dcerpc_winreg_OpenKey_r(b, tctx, &r), "OpenKey failed");
3874 torture_assert_werr_ok(tctx, r.out.result, "OpenKey failed");
3879 static bool test_winreg_OpenKey(struct torture_context *tctx,
3880 struct dcerpc_binding_handle *b,
3881 struct policy_handle *hive_handle,
3882 const char *keyname,
3883 struct policy_handle *key_handle)
3885 return test_winreg_OpenKey_opts(tctx, b, hive_handle, keyname,
3886 REG_OPTION_NON_VOLATILE, key_handle);
3889 static bool test_winreg_CloseKey(struct torture_context *tctx,
3890 struct dcerpc_binding_handle *b,
3891 struct policy_handle *handle)
3893 struct winreg_CloseKey r;
3895 r.in.handle = handle;
3896 r.out.handle = handle;
3898 torture_comment(tctx, "Testing winreg_CloseKey\n");
3900 torture_assert_ntstatus_ok(tctx, dcerpc_winreg_CloseKey_r(b, tctx, &r), "CloseKey failed");
3901 torture_assert_werr_ok(tctx, r.out.result, "CloseKey failed");
3906 bool test_winreg_QueryValue(struct torture_context *tctx,
3907 struct dcerpc_binding_handle *b,
3908 struct policy_handle *handle,
3909 const char *value_name,
3910 enum winreg_Type *type_p,
3911 uint32_t *data_size_p,
3912 uint32_t *data_length_p,
3915 struct winreg_QueryValue r;
3916 enum winreg_Type type = REG_NONE;
3917 uint32_t data_size = 0;
3918 uint32_t data_length = 0;
3919 struct winreg_String valuename;
3920 uint8_t *data = NULL;
3922 init_winreg_String(&valuename, value_name);
3924 data = talloc_zero_array(tctx, uint8_t, 0);
3926 r.in.handle = handle;
3927 r.in.value_name = &valuename;
3929 r.in.data_size = &data_size;
3930 r.in.data_length = &data_length;
3934 r.out.data_size = &data_size;
3935 r.out.data_length = &data_length;
3937 torture_comment(tctx, "Testing winreg_QueryValue(%s)\n", value_name);
3939 torture_assert_ntstatus_ok(tctx, dcerpc_winreg_QueryValue_r(b, tctx, &r), "QueryValue failed");
3940 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
3941 *r.in.data_size = *r.out.data_size;
3942 data = talloc_zero_array(tctx, uint8_t, *r.in.data_size);
3945 torture_assert_ntstatus_ok(tctx, dcerpc_winreg_QueryValue_r(b, tctx, &r), "QueryValue failed");
3947 torture_assert_werr_ok(tctx, r.out.result, "QueryValue failed");
3950 *type_p = *r.out.type;
3953 *data_size_p = *r.out.data_size;
3955 if (data_length_p) {
3956 *data_length_p = *r.out.data_length;
3959 *data_p = r.out.data;
3965 static bool test_winreg_query_printerdata(struct torture_context *tctx,
3966 struct dcerpc_binding_handle *b,
3967 struct policy_handle *handle,
3968 const char *printer_name,
3969 const char *key_name,
3970 const char *value_name,
3971 enum winreg_Type *w_type,
3976 const char *printer_key;
3977 struct policy_handle key_handle;
3979 printer_key = talloc_asprintf(tctx, "%s\\%s\\%s",
3980 TOP_LEVEL_PRINT_PRINTERS_KEY, printer_name, key_name);
3982 torture_assert(tctx,
3983 test_winreg_OpenKey(tctx, b, handle, printer_key, &key_handle), "");
3985 torture_assert(tctx,
3986 test_winreg_QueryValue(tctx, b, &key_handle, value_name, w_type, w_size, w_length, w_data), "");
3988 torture_assert(tctx,
3989 test_winreg_CloseKey(tctx, b, &key_handle), "");
3994 static bool test_GetForm_winreg(struct torture_context *tctx,
3995 struct dcerpc_binding_handle *b,
3996 struct policy_handle *handle,
3997 const char *key_name,
3998 const char *form_name,
3999 enum winreg_Type *w_type,
4004 struct policy_handle key_handle;
4006 torture_assert(tctx,
4007 test_winreg_OpenKey(tctx, b, handle, key_name, &key_handle), "");
4009 torture_assert(tctx,
4010 test_winreg_QueryValue(tctx, b, &key_handle, form_name, w_type, w_size, w_length, w_data), "");
4012 torture_assert(tctx,
4013 test_winreg_CloseKey(tctx, b, &key_handle), "");
4018 static bool test_winreg_symbolic_link(struct torture_context *tctx,
4019 struct dcerpc_binding_handle *b,
4020 struct policy_handle *handle,
4021 const char *symlink_keyname,
4022 const char *symlink_destination)
4024 /* check if the first key is a symlink to the second key */
4026 enum winreg_Type w_type;
4030 struct policy_handle key_handle;
4034 if (torture_setting_bool(tctx, "samba3", false)) {
4035 torture_skip(tctx, "skip winreg symlink test against samba");
4038 torture_assert(tctx,
4039 test_winreg_OpenKey_opts(tctx, b, handle, symlink_keyname, REG_OPTION_OPEN_LINK, &key_handle),
4040 "failed to open key link");
4042 torture_assert(tctx,
4043 test_winreg_QueryValue(tctx, b, &key_handle,
4044 "SymbolicLinkValue",
4045 &w_type, &w_size, &w_length, &w_data),
4046 "failed to query for 'SymbolicLinkValue' attribute");
4048 torture_assert_int_equal(tctx, w_type, REG_LINK, "unexpected type");
4050 blob = data_blob(w_data, w_size);
4051 str = reg_val_data_string(tctx, lp_iconv_convenience(tctx->lp_ctx), REG_SZ, blob);
4053 torture_assert_str_equal(tctx, str, symlink_destination, "unexpected symlink target string");
4055 torture_assert(tctx,
4056 test_winreg_CloseKey(tctx, b, &key_handle),
4057 "failed to close key link");
4062 static const char *strip_unc(const char *unc)
4070 if (unc[0] == '\\' && unc[1] == '\\') {
4074 name = strchr(unc, '\\');
4082 static bool test_GetPrinterInfo_winreg(struct torture_context *tctx,
4083 struct dcerpc_binding_handle *b,
4084 struct policy_handle *handle,
4085 const char *printer_name,
4086 struct dcerpc_binding_handle *winreg_handle,
4087 struct policy_handle *hive_handle)
4089 union spoolss_PrinterInfo info;
4090 const char *keys[] = {
4091 TOP_LEVEL_CONTROL_PRINTERS_KEY,
4092 TOP_LEVEL_PRINT_PRINTERS_KEY
4095 const char *printername, *sharename;
4097 torture_comment(tctx, "Testing Printer Info and winreg consistency\n");
4099 torture_assert(tctx,
4100 test_GetPrinter_level(tctx, b, handle, 2, &info),
4101 "failed to get printer info level 2");
4103 printername = strip_unc(info.info2.printername);
4104 sharename = strip_unc(info.info2.sharename);
4106 #define test_sz(wname, iname) \
4110 enum winreg_Type w_type;\
4114 torture_assert(tctx,\
4115 test_winreg_QueryValue(tctx, winreg_handle, &key_handle, wname,\
4116 &w_type, &w_size, &w_length, &w_data),\
4117 "failed to query winreg");\
4118 torture_assert_int_equal(tctx, w_type, REG_SZ, "unexpected type");\
4119 blob = data_blob(w_data, w_size);\
4120 str = reg_val_data_string(tctx, lp_iconv_convenience(tctx->lp_ctx), REG_SZ, blob);\
4121 if (w_size == 2 && iname == NULL) {\
4122 /*torture_comment(tctx, "%s: \"\", %s: (null)\n", #wname, #iname);\ */\
4124 torture_assert_str_equal(tctx, str, iname,\
4125 talloc_asprintf(tctx, "%s - %s mismatch", #wname, #iname));\
4129 #define test_dword(wname, iname) \
4132 enum winreg_Type w_type;\
4136 torture_assert(tctx,\
4137 test_winreg_QueryValue(tctx, winreg_handle, &key_handle, wname,\
4138 &w_type, &w_size, &w_length, &w_data),\
4139 "failed to query winreg");\
4140 torture_assert_int_equal(tctx, w_type, REG_DWORD, "unexpected type");\
4141 torture_assert_int_equal(tctx, w_size, 4, "unexpected size");\
4142 torture_assert_int_equal(tctx, w_length, 4, "unexpected length");\
4143 value = IVAL(w_data, 0);\
4144 torture_assert_int_equal(tctx, value, iname,\
4145 talloc_asprintf(tctx, "%s - %s mismatch", #wname, #iname));\
4148 #define test_dm(wname, iname) \
4151 struct spoolss_DeviceMode dm;\
4152 enum ndr_err_code ndr_err;\
4153 enum winreg_Type w_type;\
4157 torture_assert(tctx,\
4158 test_winreg_QueryValue(tctx, winreg_handle, &key_handle, wname,\
4159 &w_type, &w_size, &w_length, &w_data),\
4160 "failed to query winreg");\
4161 torture_assert_int_equal(tctx, w_type, REG_BINARY, "unexpected type");\
4162 blob = data_blob(w_data, w_size);\
4163 ndr_err = ndr_pull_struct_blob(&blob, tctx, lp_iconv_convenience(tctx->lp_ctx), &dm,\
4164 (ndr_pull_flags_fn_t)ndr_pull_spoolss_DeviceMode);\
4165 torture_assert_ndr_success(tctx, ndr_err, "failed to unmarshall dm");\
4166 torture_assert(tctx, test_devicemode_equal(tctx, &dm, iname),\
4170 #define test_sd(wname, iname) \
4173 struct security_descriptor sd;\
4174 enum ndr_err_code ndr_err;\
4175 enum winreg_Type w_type;\
4179 torture_assert(tctx,\
4180 test_winreg_QueryValue(tctx, winreg_handle, &key_handle, wname,\
4181 &w_type, &w_size, &w_length, &w_data),\
4182 "failed to query winreg");\
4183 torture_assert_int_equal(tctx, w_type, REG_BINARY, "unexpected type");\
4184 blob = data_blob(w_data, w_size);\
4185 ndr_err = ndr_pull_struct_blob(&blob, tctx, lp_iconv_convenience(tctx->lp_ctx), &sd,\
4186 (ndr_pull_flags_fn_t)ndr_pull_security_descriptor);\
4187 torture_assert_ndr_success(tctx, ndr_err, "failed to unmarshall sd");\
4188 torture_assert(tctx, test_security_descriptor_equal(tctx, &sd, iname),\
4192 #define test_multi_sz(wname, iname) \
4195 const char **array;\
4196 enum winreg_Type w_type;\
4201 torture_assert(tctx,\
4202 test_winreg_QueryValue(tctx, winreg_handle, &key_handle, wname,\
4203 &w_type, &w_size, &w_length, &w_data),\
4204 "failed to query winreg");\
4205 torture_assert_int_equal(tctx, w_type, REG_MULTI_SZ, "unexpected type");\
4206 blob = data_blob(w_data, w_size);\
4207 torture_assert(tctx, \
4208 pull_reg_multi_sz(tctx, lp_iconv_convenience(tctx->lp_ctx), &blob, &array),\
4209 "failed to pull multi sz");\
4210 for (i=0; array[i] != NULL; i++) {\
4211 torture_assert_str_equal(tctx, array[i], iname[i],\
4212 talloc_asprintf(tctx, "%s - %s mismatch", #wname, iname[i]));\
4217 if (!test_winreg_symbolic_link(tctx, winreg_handle, hive_handle,
4218 TOP_LEVEL_CONTROL_PRINTERS_KEY,
4219 "\\Registry\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Print\\Printers"))
4221 torture_warning(tctx, "failed to check for winreg symlink");
4225 for (i=0; i < ARRAY_SIZE(keys); i++) {
4227 const char *printer_key;
4228 struct policy_handle key_handle;
4230 printer_key = talloc_asprintf(tctx, "%s\\%s",
4231 keys[i], printer_name);
4233 torture_assert(tctx,
4234 test_winreg_OpenKey(tctx, winreg_handle, hive_handle, printer_key, &key_handle), "");
4236 test_sz("Name", printername);
4237 test_sz("Share Name", sharename);
4238 test_sz("Port", info.info2.portname);
4239 test_sz("Printer Driver", info.info2.drivername);
4240 test_sz("Description", info.info2.comment);
4241 test_sz("Location", info.info2.location);
4242 test_sz("Separator File", info.info2.sepfile);
4243 test_sz("Print Processor", info.info2.printprocessor);
4244 test_sz("Datatype", info.info2.datatype);
4245 test_sz("Parameters", info.info2.parameters);
4246 /* winreg: 0, spoolss not */
4247 /* test_dword("Attributes", info.info2.attributes); */
4248 test_dword("Priority", info.info2.priority);
4249 test_dword("Default Priority", info.info2.defaultpriority);
4250 /* winreg: 60, spoolss: 0 */
4251 /* test_dword("StartTime", info.info2.starttime); */
4252 /* test_dword("UntilTime", info.info2.untiltime); */
4253 /* winreg != spoolss */
4254 /* test_dword("Status", info.info2.status); */
4255 test_dm("Default DevMode", info.info2.devmode);
4256 test_sd("Security", info.info2.secdesc);
4258 torture_assert(tctx,
4259 test_winreg_CloseKey(tctx, winreg_handle, &key_handle), "");
4265 torture_comment(tctx, "Printer Info and winreg consistency test succeeded\n\n");
4270 static bool test_GetPrinterDriver2_level(struct torture_context *tctx,
4271 struct dcerpc_binding_handle *b,
4272 struct policy_handle *handle,
4273 const char *driver_name,
4274 const char *architecture,
4276 uint32_t client_major_version,
4277 uint32_t client_minor_version,
4278 union spoolss_DriverInfo *info_p,
4281 static const char *strip_path(const char *path)
4289 p = strrchr(path, '\\');
4297 static const char **strip_paths(const char **path_array)
4301 if (path_array == NULL) {
4305 for (i=0; path_array[i] != NULL; i++) {
4306 path_array[i] = strip_path(path_array[i]);
4312 static const char *driver_winreg_date(TALLOC_CTX *mem_ctx, NTTIME nt)
4316 t = nt_time_to_unix(nt);
4319 return talloc_asprintf(mem_ctx, "%02d/%02d/%04d",
4320 tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900);
4323 static const char *driver_winreg_version(TALLOC_CTX *mem_ctx, uint64_t v)
4325 return talloc_asprintf(mem_ctx, "%u.%u.%u.%u",
4326 (unsigned)((v >> 48) & 0xFFFF),
4327 (unsigned)((v >> 32) & 0xFFFF),
4328 (unsigned)((v >> 16) & 0xFFFF),
4329 (unsigned)(v & 0xFFFF));
4332 static bool test_GetDriverInfo_winreg(struct torture_context *tctx,
4333 struct dcerpc_binding_handle *b,
4334 struct policy_handle *handle,
4335 const char *printer_name,
4336 const char *driver_name,
4337 const char *environment,
4338 struct dcerpc_binding_handle *winreg_handle,
4339 struct policy_handle *hive_handle)
4342 union spoolss_DriverInfo info;
4343 const char *driver_key;
4344 struct policy_handle key_handle;
4346 const char *driver_path;
4347 const char *data_file;
4348 const char *config_file;
4349 const char *help_file;
4350 const char **dependent_files;
4352 const char *driver_date;
4353 const char *inbox_driver_date;
4355 const char *driver_version;
4356 const char *inbox_driver_version;
4358 torture_comment(tctx, "Testing Driver Info and winreg consistency\n");
4360 driver_key = talloc_asprintf(tctx, "%s\\%s\\Drivers\\Version-%d\\%s",
4361 TOP_LEVEL_CONTROL_ENVIRONMENTS_KEY,
4366 torture_assert(tctx,
4367 test_winreg_OpenKey(tctx, winreg_handle, hive_handle, driver_key, &key_handle),
4368 "failed to open driver key");
4370 if (torture_setting_bool(tctx, "samba3", false)) {
4374 torture_assert(tctx,
4375 test_GetPrinterDriver2_level(tctx, b, handle, driver_name, environment, 8, 3, 0, &info, &result),
4376 "failed to get driver info level 8");
4378 if (W_ERROR_EQUAL(result, WERR_INVALID_LEVEL)) {
4382 driver_path = strip_path(info.info8.driver_path);
4383 data_file = strip_path(info.info8.data_file);
4384 config_file = strip_path(info.info8.config_file);
4385 help_file = strip_path(info.info8.help_file);
4386 dependent_files = strip_paths(info.info8.dependent_files);
4388 driver_date = driver_winreg_date(tctx, info.info8.driver_date);
4389 inbox_driver_date = driver_winreg_date(tctx, info.info8.min_inbox_driver_ver_date);
4391 driver_version = driver_winreg_version(tctx, info.info8.driver_version);
4392 inbox_driver_version = driver_winreg_version(tctx, info.info8.min_inbox_driver_ver_version);
4394 test_sz("Configuration File", config_file);
4395 test_sz("Data File", data_file);
4396 test_sz("Datatype", info.info8.default_datatype);
4397 test_sz("Driver", driver_path);
4398 test_sz("DriverDate", driver_date);
4399 test_sz("DriverVersion", driver_version);
4400 test_sz("HardwareID", info.info8.hardware_id);
4401 test_sz("Help File", help_file);
4402 test_sz("InfPath", info.info8.inf_path);
4403 test_sz("Manufacturer", info.info8.manufacturer_name);
4404 test_sz("MinInboxDriverVerDate", inbox_driver_date);
4405 test_sz("MinInboxDriverVerVersion", inbox_driver_version);
4406 test_sz("Monitor", info.info8.monitor_name);
4407 test_sz("OEM URL", info.info8.manufacturer_url);
4408 test_sz("Print Processor", info.info8.print_processor);
4409 test_sz("Provider", info.info8.provider);
4410 test_sz("VendorSetup", info.info8.vendor_setup);
4411 test_multi_sz("ColorProfiles", info.info8.color_profiles);
4412 test_multi_sz("Dependent Files", dependent_files);
4413 test_multi_sz("CoreDependencies", info.info8.core_driver_dependencies);
4414 test_multi_sz("Previous Names", info.info8.previous_names);
4415 /* test_dword("Attributes", ?); */
4416 test_dword("PrinterDriverAttributes", info.info8.printer_driver_attributes);
4417 test_dword("Version", info.info8.version);
4418 /* test_dword("TempDir", ?); */
4422 torture_assert(tctx,
4423 test_GetPrinterDriver2_level(tctx, b, handle, driver_name, environment, 6, 3, 0, &info, &result),
4424 "failed to get driver info level 6");
4426 driver_path = strip_path(info.info6.driver_path);
4427 data_file = strip_path(info.info6.data_file);
4428 config_file = strip_path(info.info6.config_file);
4429 help_file = strip_path(info.info6.help_file);
4430 dependent_files = strip_paths(info.info6.dependent_files);
4432 driver_date = driver_winreg_date(tctx, info.info6.driver_date);
4434 driver_version = driver_winreg_version(tctx, info.info6.driver_version);
4436 test_sz("Configuration File", config_file);
4437 test_sz("Data File", data_file);
4438 test_sz("Datatype", info.info6.default_datatype);
4439 test_sz("Driver", driver_path);
4440 test_sz("DriverDate", driver_date);
4441 test_sz("DriverVersion", driver_version);
4442 test_sz("HardwareID", info.info6.hardware_id);
4443 test_sz("Help File", help_file);
4444 test_sz("Manufacturer", info.info6.manufacturer_name);
4445 test_sz("Monitor", info.info6.monitor_name);
4446 test_sz("OEM URL", info.info6.manufacturer_url);
4447 test_sz("Provider", info.info6.provider);
4448 test_multi_sz("Dependent Files", dependent_files);
4449 test_multi_sz("Previous Names", info.info6.previous_names);
4450 /* test_dword("Attributes", ?); */
4451 test_dword("Version", info.info6.version);
4452 /* test_dword("TempDir", ?); */
4456 torture_assert(tctx,
4457 test_GetPrinterDriver2_level(tctx, b, handle, driver_name, environment, 3, 3, 0, &info, &result),
4458 "failed to get driver info level 3");
4460 driver_path = strip_path(info.info3.driver_path);
4461 data_file = strip_path(info.info3.data_file);
4462 config_file = strip_path(info.info3.config_file);
4463 help_file = strip_path(info.info3.help_file);
4464 dependent_files = strip_paths(info.info3.dependent_files);
4466 test_sz("Configuration File", config_file);
4467 test_sz("Data File", data_file);
4468 test_sz("Datatype", info.info3.default_datatype);
4469 test_sz("Driver", driver_path);
4470 test_sz("Help File", help_file);
4471 test_sz("Monitor", info.info3.monitor_name);
4472 test_multi_sz("Dependent Files", dependent_files);
4473 /* test_dword("Attributes", ?); */
4474 test_dword("Version", info.info3.version);
4475 /* test_dword("TempDir", ?); */
4478 torture_assert(tctx,
4479 test_winreg_CloseKey(tctx, winreg_handle, &key_handle), "");
4481 torture_comment(tctx, "Driver Info and winreg consistency test succeeded\n\n");
4489 static bool test_SetPrinterData(struct torture_context *tctx,
4490 struct dcerpc_binding_handle *b,
4491 struct policy_handle *handle,
4492 const char *value_name,
4493 enum winreg_Type type,
4497 struct spoolss_SetPrinterData r;
4499 r.in.handle = handle;
4500 r.in.value_name = value_name;
4503 r.in.offered = offered;
4505 torture_comment(tctx, "Testing SetPrinterData(%s)\n",
4508 torture_assert_ntstatus_ok(tctx,
4509 dcerpc_spoolss_SetPrinterData_r(b, tctx, &r),
4510 "SetPrinterData failed");
4511 torture_assert_werr_ok(tctx, r.out.result,
4512 "SetPrinterData failed");
4517 static bool test_SetPrinterData_matrix(struct torture_context *tctx,
4518 struct dcerpc_binding_handle *b,
4519 struct policy_handle *handle,
4520 const char *printer_name,
4521 struct dcerpc_binding_handle *winreg_handle,
4522 struct policy_handle *hive_handle)
4524 const char *values[] = {
4528 /* FIXME: not working with s3 atm. */
4534 /* FIXME: not working with s3 atm. */
4541 for (i=0; i < ARRAY_SIZE(values); i++) {
4543 enum winreg_Type type;
4548 torture_assert(tctx,
4549 reg_string_to_val(tctx, lp_iconv_convenience(tctx->lp_ctx),
4550 "REG_SZ", "dog", &type, &blob), "");
4552 torture_assert(tctx,
4553 test_SetPrinterData(tctx, b, handle, values[i], REG_SZ, blob.data, blob.length),
4554 "SetPrinterData failed");
4556 torture_assert(tctx,
4557 test_GetPrinterData(tctx, b, handle, values[i], &type, &data, &needed),
4558 "GetPrinterData failed");
4560 torture_assert_int_equal(tctx, type, REG_SZ, "type mismatch");
4561 torture_assert_int_equal(tctx, needed, blob.length, "size mismatch");
4562 torture_assert_mem_equal(tctx, data, blob.data, blob.length, "buffer mismatch");
4564 if (winreg_handle && hive_handle) {
4566 enum winreg_Type w_type;
4571 torture_assert(tctx,
4572 test_winreg_query_printerdata(tctx, winreg_handle, hive_handle,
4573 printer_name, "PrinterDriverData", values[i],
4574 &w_type, &w_size, &w_length, &w_data), "");
4576 torture_assert_int_equal(tctx, w_type, REG_SZ, "winreg type mismatch");
4577 torture_assert_int_equal(tctx, w_size, blob.length, "winreg size mismatch");
4578 torture_assert_int_equal(tctx, w_length, blob.length, "winreg length mismatch");
4579 torture_assert_mem_equal(tctx, w_data, blob.data, blob.length, "winreg buffer mismatch");
4582 torture_assert(tctx,
4583 test_DeletePrinterData(tctx, b, handle, values[i]),
4584 "DeletePrinterData failed");
4591 static bool test_EnumPrinterKey(struct torture_context *tctx,
4592 struct dcerpc_binding_handle *b,
4593 struct policy_handle *handle,
4594 const char *key_name,
4595 const char ***array);
4597 static bool test_SetPrinterDataEx(struct torture_context *tctx,
4598 struct dcerpc_binding_handle *b,
4599 struct policy_handle *handle,
4600 const char *key_name,
4601 const char *value_name,
4602 enum winreg_Type type,
4607 struct spoolss_SetPrinterDataEx r;
4609 r.in.handle = handle;
4610 r.in.key_name = key_name;
4611 r.in.value_name = value_name;
4614 r.in.offered = offered;
4616 torture_comment(tctx, "Testing SetPrinterDataEx(%s - %s) type: %s, offered: 0x%08x\n",
4617 r.in.key_name, r.in.value_name, str_regtype(r.in.type), r.in.offered);
4619 status = dcerpc_spoolss_SetPrinterDataEx_r(b, tctx, &r);
4621 torture_assert_ntstatus_ok(tctx, status, "SetPrinterDataEx failed");
4622 torture_assert_werr_ok(tctx, r.out.result, "SetPrinterDataEx failed");
4627 static bool test_SetPrinterDataEx_matrix(struct torture_context *tctx,
4628 struct dcerpc_pipe *p,
4629 struct policy_handle *handle,
4630 const char *printername,
4631 struct dcerpc_binding_handle *winreg_handle,
4632 struct policy_handle *hive_handle)
4634 struct dcerpc_binding_handle *b = p->binding_handle;
4635 const char *value_name = "dog";
4636 const char *keys[] = {
4640 /* FIXME: not working with s3 atm. */
4641 "torturedataex_with_subkey\\subkey",
4642 "torturedataex_with_subkey\\subkey:0",
4643 "torturedataex_with_subkey\\subkey:1",
4644 "torturedataex_with_subkey\\subkey\\subsubkey",
4645 "torturedataex_with_subkey\\subkey\\subsubkey:0",
4646 "torturedataex_with_subkey\\subkey\\subsubkey:1",
4650 /* FIXME: not working with s3 atm. */
4657 enum winreg_Type types[] = {
4663 const char *str = "abcdefghijklmnopqrstuvwxzy";
4667 for (i=0; i < ARRAY_SIZE(keys); i++) {
4668 for (t=0; t < ARRAY_SIZE(types); t++) {
4669 for (s=0; s < strlen(str); s++) {
4673 enum winreg_Type type;
4674 const char *string = talloc_strndup(tctx, str, s);
4675 DATA_BLOB blob = data_blob_string_const(string);
4676 const char **subkeys;
4679 uint32_t needed, offered = 0;
4681 struct spoolss_PrinterEnumValues *einfo;
4683 if (types[t] == REG_DWORD) {
4687 if (torture_setting_bool(tctx, "samba3", false)) {
4688 if ((types[t] == REG_MULTI_SZ) && s == 0) {
4689 torture_warning(tctx, "samba3 does not handle 4 byte emtpy REG_MULTI_SZ buffers");
4697 offered = blob.length;
4700 data = data_blob_talloc(tctx, NULL, 4);
4701 SIVAL(data.data, 0, 0x12345678);
4705 torture_assert(tctx,
4706 reg_string_to_val(tctx, lp_iconv_convenience(tctx->lp_ctx),
4707 "REG_SZ", string, &type, &data), "");
4708 offered = data.length;
4709 /*strlen_m_term(data.string)*2;*/
4712 torture_assert(tctx,
4713 reg_string_to_val(tctx, lp_iconv_convenience(tctx->lp_ctx),
4714 "REG_SZ", string, &type, &data), "");
4715 torture_assert(tctx, data_blob_realloc(tctx, &data, data.length + 2), "");
4716 memset(&data.data[data.length - 2], '\0', 2);
4717 offered = data.length;
4720 torture_fail(tctx, talloc_asprintf(tctx, "type %d untested\n", types[t]));
4723 torture_assert(tctx,
4724 test_SetPrinterDataEx(tctx, b, handle, keys[i], value_name, types[t], data.data, offered),
4725 "failed to call SetPrinterDataEx");
4727 torture_assert(tctx,
4728 test_GetPrinterDataEx(tctx, p, handle, keys[i], value_name, &type, &data_out, &needed),
4729 "failed to call GetPrinterDataEx");
4731 torture_assert(tctx,
4732 test_EnumPrinterDataEx(tctx, b, handle, keys[i], &ecount, &einfo),
4733 "failed to call EnumPrinterDataEx");
4735 torture_assert_int_equal(tctx, types[t], type, "type mismatch");
4736 torture_assert_int_equal(tctx, needed, offered, "size mismatch");
4737 torture_assert_mem_equal(tctx, data_out, data.data, offered, "buffer mismatch");
4739 torture_assert_int_equal(tctx, ecount, 1, "unexpected enum count");
4740 torture_assert_str_equal(tctx, einfo[0].value_name, value_name, "value_name mismatch");
4741 torture_assert_int_equal(tctx, einfo[0].value_name_len, strlen_m_term(value_name)*2, "unexpected value_name_len");
4742 torture_assert_int_equal(tctx, einfo[0].type, types[t], "type mismatch");
4743 torture_assert_int_equal(tctx, einfo[0].data_length, offered, "size mismatch");
4744 if (einfo[0].data_length > 0) {
4745 torture_assert_mem_equal(tctx, einfo[0].data->data, data.data, offered, "buffer mismatch");
4748 if (winreg_handle && hive_handle) {
4749 enum winreg_Type w_type;
4754 torture_assert(tctx,
4755 test_winreg_query_printerdata(tctx, winreg_handle, hive_handle,
4756 printername, keys[i], value_name,
4757 &w_type, &w_size, &w_length, &w_data), "");
4759 torture_assert_int_equal(tctx, w_type, types[t], "winreg type mismatch");
4760 torture_assert_int_equal(tctx, w_size, offered, "winreg size mismatch");
4761 torture_assert_int_equal(tctx, w_length, offered, "winreg length mismatch");
4762 torture_assert_mem_equal(tctx, w_data, data.data, offered, "winreg buffer mismatch");
4765 key = talloc_strdup(tctx, keys[i]);
4767 if (!test_DeletePrinterDataEx(tctx, b, handle, keys[i], value_name)) {
4771 c = strchr(key, '\\');
4775 /* we have subkeys */
4779 if (!test_EnumPrinterKey(tctx, b, handle, key, &subkeys)) {
4783 for (k=0; subkeys && subkeys[k]; k++) {
4785 const char *current_key = talloc_asprintf(tctx, "%s\\%s", key, subkeys[k]);
4787 if (!test_DeletePrinterKey(tctx, b, handle, current_key)) {
4792 if (!test_DeletePrinterKey(tctx, b, handle, key)) {
4797 if (!test_DeletePrinterKey(tctx, b, handle, key)) {
4808 static bool test_PrinterData_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_SetPrinterData_matrix(tctx, b, handle, printer_name, b2, &hive_handle);
4827 ret &= test_SetPrinterDataEx_matrix(tctx, p, handle, printer_name, b2, &hive_handle);
4829 test_winreg_CloseKey(tctx, b2, &hive_handle);
4836 static bool test_Forms_winreg(struct torture_context *tctx,
4837 struct dcerpc_binding_handle *b,
4838 struct policy_handle *handle,
4840 const char *printer_name)
4842 struct dcerpc_pipe *p2;
4844 struct policy_handle hive_handle;
4845 struct dcerpc_binding_handle *b2;
4847 torture_assert_ntstatus_ok(tctx,
4848 torture_rpc_connection(tctx, &p2, &ndr_table_winreg),
4849 "could not open winreg pipe");
4850 b2 = p2->binding_handle;
4852 torture_assert(tctx, test_winreg_OpenHKLM(tctx, b2, &hive_handle), "");
4854 ret = test_Forms(tctx, b, handle, print_server, printer_name, b2, &hive_handle);
4856 test_winreg_CloseKey(tctx, b2, &hive_handle);
4863 static bool test_PrinterInfo_winreg(struct torture_context *tctx,
4864 struct dcerpc_pipe *p,
4865 struct policy_handle *handle,
4866 const char *printer_name)
4868 struct dcerpc_binding_handle *b = p->binding_handle;
4869 struct dcerpc_pipe *p2;
4871 struct policy_handle hive_handle;
4872 struct dcerpc_binding_handle *b2;
4874 torture_assert_ntstatus_ok(tctx,
4875 torture_rpc_connection(tctx, &p2, &ndr_table_winreg),
4876 "could not open winreg pipe");
4877 b2 = p2->binding_handle;
4879 torture_assert(tctx, test_winreg_OpenHKLM(tctx, b2, &hive_handle), "");
4881 ret = test_GetPrinterInfo_winreg(tctx, b, handle, printer_name, b2, &hive_handle);
4883 test_winreg_CloseKey(tctx, b2, &hive_handle);
4890 static bool test_DriverInfo_winreg(struct torture_context *tctx,
4891 struct dcerpc_pipe *p,
4892 struct policy_handle *handle,
4893 const char *printer_name,
4894 const char *driver_name,
4895 const char *environment)
4897 struct dcerpc_binding_handle *b = p->binding_handle;
4898 struct dcerpc_pipe *p2;
4900 struct policy_handle hive_handle;
4901 struct dcerpc_binding_handle *b2;
4903 torture_assert_ntstatus_ok(tctx,
4904 torture_rpc_connection(tctx, &p2, &ndr_table_winreg),
4905 "could not open winreg pipe");
4906 b2 = p2->binding_handle;
4908 torture_assert(tctx, test_winreg_OpenHKLM(tctx, b2, &hive_handle), "");
4910 ret = test_GetDriverInfo_winreg(tctx, b, handle, printer_name, driver_name, environment, b2, &hive_handle);
4912 test_winreg_CloseKey(tctx, b2, &hive_handle);
4919 static bool test_GetChangeID_PrinterData(struct torture_context *tctx,
4920 struct dcerpc_binding_handle *b,
4921 struct policy_handle *handle,
4922 uint32_t *change_id)
4924 enum winreg_Type type;
4928 torture_assert(tctx,
4929 test_GetPrinterData(tctx, b, handle, "ChangeID", &type, &data, &needed),
4930 "failed to call GetPrinterData");
4932 torture_assert(tctx, type == REG_DWORD, "unexpected type");
4933 torture_assert_int_equal(tctx, needed, 4, "unexpected size");
4935 *change_id = IVAL(data, 0);
4940 static bool test_GetChangeID_PrinterDataEx(struct torture_context *tctx,
4941 struct dcerpc_pipe *p,
4942 struct policy_handle *handle,
4943 uint32_t *change_id)
4945 enum winreg_Type type;
4949 torture_assert(tctx,
4950 test_GetPrinterDataEx(tctx, p, handle, "PrinterDriverData", "ChangeID", &type, &data, &needed),
4951 "failed to call GetPrinterData");
4953 torture_assert(tctx, type == REG_DWORD, "unexpected type");
4954 torture_assert_int_equal(tctx, needed, 4, "unexpected size");
4956 *change_id = IVAL(data, 0);
4961 static bool test_GetChangeID_PrinterInfo(struct torture_context *tctx,
4962 struct dcerpc_binding_handle *b,
4963 struct policy_handle *handle,
4964 uint32_t *change_id)
4966 union spoolss_PrinterInfo info;
4968 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 0, &info),
4969 "failed to query Printer level 0");
4971 *change_id = info.info0.change_id;
4976 static bool test_ChangeID(struct torture_context *tctx,
4977 struct dcerpc_pipe *p,
4978 struct policy_handle *handle)
4980 uint32_t change_id, change_id_ex, change_id_info;
4981 uint32_t change_id2, change_id_ex2, change_id_info2;
4982 union spoolss_PrinterInfo info;
4983 const char *comment;
4984 struct dcerpc_binding_handle *b = p->binding_handle;
4986 torture_comment(tctx, "Testing ChangeID: id change test #1\n");
4988 torture_assert(tctx, test_GetChangeID_PrinterData(tctx, b, handle, &change_id),
4989 "failed to query for ChangeID");
4990 torture_assert(tctx, test_GetChangeID_PrinterDataEx(tctx, p, handle, &change_id_ex),
4991 "failed to query for ChangeID");
4992 torture_assert(tctx, test_GetChangeID_PrinterInfo(tctx, b, handle, &change_id_info),
4993 "failed to query for ChangeID");
4995 torture_assert_int_equal(tctx, change_id, change_id_ex,
4996 "change_ids should all be equal");
4997 torture_assert_int_equal(tctx, change_id_ex, change_id_info,
4998 "change_ids should all be equal");
5001 torture_comment(tctx, "Testing ChangeID: id change test #2\n");
5003 torture_assert(tctx, test_GetChangeID_PrinterData(tctx, b, handle, &change_id),
5004 "failed to query for ChangeID");
5005 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info),
5006 "failed to query Printer level 2");
5007 torture_assert(tctx, test_GetChangeID_PrinterDataEx(tctx, p, handle, &change_id_ex),
5008 "failed to query for ChangeID");
5009 torture_assert(tctx, test_GetChangeID_PrinterInfo(tctx, b, handle, &change_id_info),
5010 "failed to query for ChangeID");
5011 torture_assert_int_equal(tctx, change_id, change_id_ex,
5012 "change_id should not have changed");
5013 torture_assert_int_equal(tctx, change_id_ex, change_id_info,
5014 "change_id should not have changed");
5017 torture_comment(tctx, "Testing ChangeID: id change test #3\n");
5019 torture_assert(tctx, test_GetChangeID_PrinterData(tctx, b, handle, &change_id),
5020 "failed to query for ChangeID");
5021 torture_assert(tctx, test_GetChangeID_PrinterDataEx(tctx, p, handle, &change_id_ex),
5022 "failed to query for ChangeID");
5023 torture_assert(tctx, test_GetChangeID_PrinterInfo(tctx, b, handle, &change_id_info),
5024 "failed to query for ChangeID");
5025 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info),
5026 "failed to query Printer level 2");
5027 comment = talloc_strdup(tctx, info.info2.comment);
5030 struct spoolss_SetPrinterInfoCtr info_ctr;
5031 struct spoolss_DevmodeContainer devmode_ctr;
5032 struct sec_desc_buf secdesc_ctr;
5033 union spoolss_SetPrinterInfo sinfo;
5035 ZERO_STRUCT(info_ctr);
5036 ZERO_STRUCT(devmode_ctr);
5037 ZERO_STRUCT(secdesc_ctr);
5040 torture_assert(tctx, PrinterInfo_to_SetPrinterInfo(tctx, &info, 2, &sinfo), "");
5041 sinfo.info2->comment = "torture_comment";
5044 info_ctr.info = sinfo;
5046 torture_assert(tctx, test_SetPrinter(tctx, b, handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0),
5047 "failed to call SetPrinter");
5049 sinfo.info2->comment = comment;
5051 torture_assert(tctx, test_SetPrinter(tctx, b, handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0),
5052 "failed to call SetPrinter");
5056 torture_assert(tctx, test_GetChangeID_PrinterData(tctx, b, handle, &change_id2),
5057 "failed to query for ChangeID");
5058 torture_assert(tctx, test_GetChangeID_PrinterDataEx(tctx, p, handle, &change_id_ex2),
5059 "failed to query for ChangeID");
5060 torture_assert(tctx, test_GetChangeID_PrinterInfo(tctx, b, handle, &change_id_info2),
5061 "failed to query for ChangeID");
5063 torture_assert_int_equal(tctx, change_id2, change_id_ex2,
5064 "change_ids should all be equal");
5065 torture_assert_int_equal(tctx, change_id_ex2, change_id_info2,
5066 "change_ids should all be equal");
5068 torture_assert(tctx, (change_id < change_id2),
5069 talloc_asprintf(tctx, "change_id %d needs to be larger than change_id %d",
5070 change_id2, change_id));
5071 torture_assert(tctx, (change_id_ex < change_id_ex2),
5072 talloc_asprintf(tctx, "change_id %d needs to be larger than change_id %d",
5073 change_id_ex2, change_id_ex));
5074 torture_assert(tctx, (change_id_info < change_id_info2),
5075 talloc_asprintf(tctx, "change_id %d needs to be larger than change_id %d",
5076 change_id_info2, change_id_info));
5078 torture_comment(tctx, "ChangeID tests succeeded\n\n");
5083 static bool test_SecondaryClosePrinter(struct torture_context *tctx,
5084 struct dcerpc_pipe *p,
5085 struct policy_handle *handle)
5088 struct dcerpc_binding *b;
5089 struct dcerpc_pipe *p2;
5090 struct spoolss_ClosePrinter cp;
5092 /* only makes sense on SMB */
5093 if (p->conn->transport.transport != NCACN_NP) {
5097 torture_comment(tctx, "Testing close on secondary pipe\n");
5099 status = dcerpc_parse_binding(tctx, p->conn->binding_string, &b);
5100 torture_assert_ntstatus_ok(tctx, status, "Failed to parse dcerpc binding");
5102 status = dcerpc_secondary_connection(p, &p2, b);
5103 torture_assert_ntstatus_ok(tctx, status, "Failed to create secondary connection");
5105 status = dcerpc_bind_auth_none(p2, &ndr_table_spoolss);
5106 torture_assert_ntstatus_ok(tctx, status, "Failed to create bind on secondary connection");
5108 cp.in.handle = handle;
5109 cp.out.handle = handle;
5111 status = dcerpc_spoolss_ClosePrinter_r(p2->binding_handle, tctx, &cp);
5112 torture_assert_ntstatus_equal(tctx, status, NT_STATUS_RPC_SS_CONTEXT_MISMATCH,
5113 "ERROR: Allowed close on secondary connection");
5120 static bool test_OpenPrinter_badname(struct torture_context *tctx,
5121 struct dcerpc_binding_handle *b, const char *name)
5124 struct spoolss_OpenPrinter op;
5125 struct spoolss_OpenPrinterEx opEx;
5126 struct policy_handle handle;
5129 op.in.printername = name;
5130 op.in.datatype = NULL;
5131 op.in.devmode_ctr.devmode= NULL;
5132 op.in.access_mask = 0;
5133 op.out.handle = &handle;
5135 torture_comment(tctx, "Testing OpenPrinter(%s) with bad name\n", op.in.printername);
5137 status = dcerpc_spoolss_OpenPrinter_r(b, tctx, &op);
5138 torture_assert_ntstatus_ok(tctx, status, "OpenPrinter failed");
5139 torture_assert_werr_equal(tctx, op.out.result, WERR_INVALID_PRINTER_NAME,
5140 "unexpected result");
5142 if (W_ERROR_IS_OK(op.out.result)) {
5143 ret &=test_ClosePrinter(tctx, b, &handle);
5146 opEx.in.printername = name;
5147 opEx.in.datatype = NULL;
5148 opEx.in.devmode_ctr.devmode = NULL;
5149 opEx.in.access_mask = 0;
5151 opEx.in.userlevel.level1 = NULL;
5152 opEx.out.handle = &handle;
5154 torture_comment(tctx, "Testing OpenPrinterEx(%s) with bad name\n", opEx.in.printername);
5156 status = dcerpc_spoolss_OpenPrinterEx_r(b, tctx, &opEx);
5157 torture_assert_ntstatus_ok(tctx, status, "OpenPrinterEx failed");
5158 torture_assert_werr_equal(tctx, opEx.out.result, WERR_INVALID_PARAM,
5159 "unexpected result");
5161 if (W_ERROR_IS_OK(opEx.out.result)) {
5162 ret &=test_ClosePrinter(tctx, b, &handle);
5168 static bool test_OpenPrinter_badname_list(struct torture_context *tctx,
5169 struct dcerpc_binding_handle *b,
5170 const char *server_name)
5172 const char *badnames[] = {
5173 "__INVALID_PRINTER__",
5174 "\\\\__INVALID_HOST__",
5177 "\\\\\\__INVALID_PRINTER__"
5179 const char *badname;
5182 for (i=0; i < ARRAY_SIZE(badnames); i++) {
5183 torture_assert(tctx,
5184 test_OpenPrinter_badname(tctx, b, badnames[i]),
5188 badname = talloc_asprintf(tctx, "\\\\%s\\", server_name);
5189 torture_assert(tctx,
5190 test_OpenPrinter_badname(tctx, b, badname),
5193 badname = talloc_asprintf(tctx, "\\\\%s\\__INVALID_PRINTER__", server_name);
5194 torture_assert(tctx,
5195 test_OpenPrinter_badname(tctx, b, badname),
5201 static bool test_OpenPrinter(struct torture_context *tctx,
5202 struct dcerpc_pipe *p,
5204 const char *environment)
5207 struct spoolss_OpenPrinter r;
5208 struct policy_handle handle;
5210 struct dcerpc_binding_handle *b = p->binding_handle;
5212 r.in.printername = talloc_asprintf(tctx, "\\\\%s\\%s", dcerpc_server_name(p), name);
5213 r.in.datatype = NULL;
5214 r.in.devmode_ctr.devmode= NULL;
5215 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
5216 r.out.handle = &handle;
5218 torture_comment(tctx, "Testing OpenPrinter(%s)\n", r.in.printername);
5220 status = dcerpc_spoolss_OpenPrinter_r(b, tctx, &r);
5222 torture_assert_ntstatus_ok(tctx, status, "OpenPrinter failed");
5224 torture_assert_werr_ok(tctx, r.out.result, "OpenPrinter failed");
5226 if (!test_GetPrinter(tctx, b, &handle, environment)) {
5230 if (!torture_setting_bool(tctx, "samba3", false)) {
5231 if (!test_SecondaryClosePrinter(tctx, p, &handle)) {
5236 if (!test_ClosePrinter(tctx, b, &handle)) {
5243 static bool call_OpenPrinterEx(struct torture_context *tctx,
5244 struct dcerpc_pipe *p,
5246 struct spoolss_DeviceMode *devmode,
5247 struct policy_handle *handle)
5249 struct spoolss_OpenPrinterEx r;
5250 struct spoolss_UserLevel1 userlevel1;
5252 struct dcerpc_binding_handle *b = p->binding_handle;
5254 if (name && name[0]) {
5255 r.in.printername = talloc_asprintf(tctx, "\\\\%s\\%s",
5256 dcerpc_server_name(p), name);
5258 r.in.printername = talloc_asprintf(tctx, "\\\\%s",
5259 dcerpc_server_name(p));
5262 r.in.datatype = NULL;
5263 r.in.devmode_ctr.devmode= devmode;
5264 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
5266 r.in.userlevel.level1 = &userlevel1;
5267 r.out.handle = handle;
5269 userlevel1.size = 1234;
5270 userlevel1.client = "hello";
5271 userlevel1.user = "spottyfoot!";
5272 userlevel1.build = 1;
5273 userlevel1.major = 2;
5274 userlevel1.minor = 3;
5275 userlevel1.processor = 4;
5277 torture_comment(tctx, "Testing OpenPrinterEx(%s)\n", r.in.printername);
5279 status = dcerpc_spoolss_OpenPrinterEx_r(b, tctx, &r);
5281 torture_assert_ntstatus_ok(tctx, status, "OpenPrinterEx failed");
5283 torture_assert_werr_ok(tctx, r.out.result, "OpenPrinterEx failed");
5288 static bool test_printer_rename(struct torture_context *tctx,
5289 struct dcerpc_pipe *p,
5290 struct policy_handle *handle,
5294 union spoolss_PrinterInfo info;
5295 union spoolss_SetPrinterInfo sinfo;
5296 struct spoolss_SetPrinterInfoCtr info_ctr;
5297 struct spoolss_DevmodeContainer devmode_ctr;
5298 struct sec_desc_buf secdesc_ctr;
5299 const char *printer_name;
5300 const char *printer_name_orig;
5301 const char *printer_name_new = "SAMBA smbtorture Test Printer (Copy 2)";
5302 struct policy_handle new_handle;
5304 struct dcerpc_binding_handle *b = p->binding_handle;
5306 ZERO_STRUCT(devmode_ctr);
5307 ZERO_STRUCT(secdesc_ctr);
5309 torture_comment(tctx, "Testing Printer rename operations\n");
5311 torture_assert(tctx,
5312 test_GetPrinter_level(tctx, b, handle, 2, &info),
5313 "failed to call GetPrinter level 2");
5315 printer_name_orig = talloc_strdup(tctx, info.info2.printername);
5317 q = strrchr(info.info2.printername, '\\');
5319 torture_warning(tctx,
5320 "server returns printername %s incl. servername although we did not set servername", info.info2.printername);
5323 torture_assert(tctx,
5324 PrinterInfo_to_SetPrinterInfo(tctx, &info, 2, &sinfo), "");
5326 sinfo.info2->printername = printer_name_new;
5329 info_ctr.info = sinfo;
5331 torture_assert(tctx,
5332 test_SetPrinter(tctx, b, handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0),
5333 "failed to call SetPrinter level 2");
5335 torture_assert(tctx,
5336 test_GetPrinter_level(tctx, b, handle, 2, &info),
5337 "failed to call GetPrinter level 2");
5339 printer_name = talloc_strdup(tctx, info.info2.printername);
5341 q = strrchr(info.info2.printername, '\\');
5343 torture_warning(tctx,
5344 "server returns printername %s incl. servername although we did not set servername", info.info2.printername);
5349 torture_assert_str_equal(tctx, printer_name, printer_name_new,
5350 "new printer name was not set");
5352 /* samba currently cannot fully rename printers */
5353 if (!torture_setting_bool(tctx, "samba3", false)) {
5354 torture_assert(tctx,
5355 test_OpenPrinter_badname(tctx, b, printer_name_orig),
5356 "still can open printer with oldname after rename");
5358 torture_warning(tctx, "*not* checking for open with oldname after rename for samba3");
5361 torture_assert(tctx,
5362 call_OpenPrinterEx(tctx, p, printer_name_new, NULL, &new_handle),
5363 "failed to open printer with new name");
5365 torture_assert(tctx,
5366 test_GetPrinter_level(tctx, b, &new_handle, 2, &info),
5367 "failed to call GetPrinter level 2");
5369 /* FIXME: we openend with servername! */
5370 printer_name = talloc_asprintf(tctx, "\\\\%s\\%s",
5371 dcerpc_server_name(p), printer_name_new);
5373 torture_assert_str_equal(tctx, info.info2.printername, printer_name,
5374 "new printer name was not set");
5376 torture_assert(tctx,
5377 test_ClosePrinter(tctx, b, &new_handle),
5378 "failed to close printer");
5380 torture_comment(tctx, "Printer rename operations test succeeded\n\n");
5386 static bool test_OpenPrinterEx(struct torture_context *tctx,
5387 struct dcerpc_pipe *p,
5389 const char *environment)
5391 struct policy_handle handle;
5393 struct dcerpc_binding_handle *b = p->binding_handle;
5395 if (!call_OpenPrinterEx(tctx, p, name, NULL, &handle)) {
5399 if (!test_PrinterInfo_SD(tctx, b, &handle)) {
5403 if (!test_GetPrinter(tctx, b, &handle, environment)) {
5407 if (!test_EnumForms_all(tctx, b, &handle, false)) {
5411 if (!test_Forms(tctx, b, &handle, false, name, NULL, NULL)) {
5415 if (!test_Forms_winreg(tctx, b, &handle, false, name)) {
5419 if (!test_EnumPrinterData_all(tctx, p, &handle)) {
5423 if (!test_EnumPrinterDataEx(tctx, b, &handle, "PrinterDriverData", NULL, NULL)) {
5427 if (!test_EnumPrinterData_consistency(tctx, p, &handle)) {
5431 if (!test_printer_keys(tctx, b, &handle)) {
5435 if (!test_PausePrinter(tctx, b, &handle)) {
5439 if (!test_DoPrintTest(tctx, b, &handle)) {
5443 if (!test_ResumePrinter(tctx, b, &handle)) {
5447 if (!test_SetPrinterData_matrix(tctx, b, &handle, name, NULL, NULL)) {
5451 if (!test_SetPrinterDataEx_matrix(tctx, p, &handle, name, NULL, NULL)) {
5455 if (!torture_setting_bool(tctx, "samba3", false)) {
5456 if (!test_SecondaryClosePrinter(tctx, p, &handle)) {
5461 if (!test_ClosePrinter(tctx, b, &handle)) {
5468 static bool test_EnumPrinters_old(struct torture_context *tctx,
5469 struct dcerpc_pipe *p,
5470 const char *environment)
5472 struct spoolss_EnumPrinters r;
5474 uint16_t levels[] = {1, 2, 4, 5};
5477 struct dcerpc_binding_handle *b = p->binding_handle;
5479 for (i=0;i<ARRAY_SIZE(levels);i++) {
5480 union spoolss_PrinterInfo *info;
5485 r.in.flags = PRINTER_ENUM_LOCAL;
5487 r.in.level = levels[i];
5490 r.out.needed = &needed;
5491 r.out.count = &count;
5494 torture_comment(tctx, "Testing EnumPrinters level %u\n", r.in.level);
5496 status = dcerpc_spoolss_EnumPrinters_r(b, tctx, &r);
5497 torture_assert_ntstatus_ok(tctx, status, "EnumPrinters failed");
5499 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
5500 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
5501 r.in.buffer = &blob;
5502 r.in.offered = needed;
5503 status = dcerpc_spoolss_EnumPrinters_r(b, tctx, &r);
5506 torture_assert_ntstatus_ok(tctx, status, "EnumPrinters failed");
5508 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinters failed");
5510 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPrinters, info, r.in.level, count, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
5513 torture_comment(tctx, "No printers returned\n");
5517 for (j=0;j<count;j++) {
5518 if (r.in.level == 1) {
5519 char *unc = talloc_strdup(tctx, info[j].info1.name);
5522 if (unc[0] == '\\' && unc[1] == '\\') {
5525 slash = strchr(unc, '\\');
5530 if (!test_OpenPrinter(tctx, p, name, environment)) {
5533 if (!test_OpenPrinterEx(tctx, p, name, environment)) {
5543 static bool test_GetPrinterDriver(struct torture_context *tctx,
5544 struct dcerpc_binding_handle *b,
5545 struct policy_handle *handle,
5546 const char *driver_name)
5548 struct spoolss_GetPrinterDriver r;
5551 r.in.handle = handle;
5552 r.in.architecture = "W32X86";
5556 r.out.needed = &needed;
5558 torture_comment(tctx, "Testing GetPrinterDriver level %d\n", r.in.level);
5560 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_GetPrinterDriver_r(b, tctx, &r),
5561 "failed to call GetPrinterDriver");
5562 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
5563 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
5564 r.in.buffer = &blob;
5565 r.in.offered = needed;
5566 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_GetPrinterDriver_r(b, tctx, &r),
5567 "failed to call GetPrinterDriver");
5570 torture_assert_werr_ok(tctx, r.out.result,
5571 "failed to call GetPrinterDriver");
5573 CHECK_NEEDED_SIZE_LEVEL(spoolss_DriverInfo, r.out.info, r.in.level, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
5578 static bool test_GetPrinterDriver2_level(struct torture_context *tctx,
5579 struct dcerpc_binding_handle *b,
5580 struct policy_handle *handle,
5581 const char *driver_name,
5582 const char *architecture,
5584 uint32_t client_major_version,
5585 uint32_t client_minor_version,
5586 union spoolss_DriverInfo *info_p,
5590 struct spoolss_GetPrinterDriver2 r;
5592 uint32_t server_major_version;
5593 uint32_t server_minor_version;
5595 r.in.handle = handle;
5596 r.in.architecture = architecture;
5597 r.in.client_major_version = client_major_version;
5598 r.in.client_minor_version = client_minor_version;
5602 r.out.needed = &needed;
5603 r.out.server_major_version = &server_major_version;
5604 r.out.server_minor_version = &server_minor_version;
5606 torture_comment(tctx, "Testing GetPrinterDriver2(%s) level %d\n",
5607 driver_name, r.in.level);
5609 torture_assert_ntstatus_ok(tctx,
5610 dcerpc_spoolss_GetPrinterDriver2_r(b, tctx, &r),
5611 "failed to call GetPrinterDriver2");
5612 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
5613 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
5614 r.in.buffer = &blob;
5615 r.in.offered = needed;
5616 torture_assert_ntstatus_ok(tctx,
5617 dcerpc_spoolss_GetPrinterDriver2_r(b, tctx, &r),
5618 "failed to call GetPrinterDriver2");
5622 *result_p = r.out.result;
5625 if (W_ERROR_EQUAL(r.out.result, WERR_INVALID_LEVEL)) {
5626 switch (r.in.level) {
5629 torture_comment(tctx,
5630 "level %d not implemented, not considering as an error\n",
5638 torture_assert_werr_ok(tctx, r.out.result,
5639 "failed to call GetPrinterDriver2");
5641 CHECK_NEEDED_SIZE_LEVEL(spoolss_DriverInfo, r.out.info, r.in.level, lp_iconv_convenience(tctx->lp_ctx), needed, 4);
5644 *info_p = *r.out.info;
5650 static bool test_GetPrinterDriver2(struct torture_context *tctx,
5651 struct dcerpc_binding_handle *b,
5652 struct policy_handle *handle,
5653 const char *driver_name,
5654 const char *architecture)
5656 uint16_t levels[] = {1, 2, 3, 4, 5, 6, 8, 101 };
5660 for (i=0;i<ARRAY_SIZE(levels);i++) {
5662 torture_assert(tctx,
5663 test_GetPrinterDriver2_level(tctx, b, handle, driver_name, architecture, levels[i], 3, 0, NULL, NULL),
5670 static bool test_EnumPrinterDrivers_old(struct torture_context *tctx,
5671 struct dcerpc_pipe *p,
5672 const char *environment)
5674 uint16_t levels[] = {1, 2, 3, 4, 5, 6};
5676 struct dcerpc_binding_handle *b = p->binding_handle;
5677 const char *server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
5679 for (i=0;i<ARRAY_SIZE(levels);i++) {
5682 union spoolss_DriverInfo *info;
5684 torture_assert(tctx,
5685 test_EnumPrinterDrivers_args(tctx, b, server_name, environment, levels[i], &count, &info),
5686 "failed to enumerate drivers");
5689 torture_comment(tctx, "No printer drivers returned\n");
5697 static bool test_DeletePrinter(struct torture_context *tctx,
5698 struct dcerpc_binding_handle *b,
5699 struct policy_handle *handle)
5701 struct spoolss_DeletePrinter r;
5703 torture_comment(tctx, "Testing DeletePrinter\n");
5705 r.in.handle = handle;
5707 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_DeletePrinter_r(b, tctx, &r),
5708 "failed to delete printer");
5709 torture_assert_werr_ok(tctx, r.out.result,
5710 "failed to delete printer");
5715 static bool test_EnumPrinters_findname(struct torture_context *tctx,
5716 struct dcerpc_binding_handle *b,
5722 struct spoolss_EnumPrinters e;
5724 union spoolss_PrinterInfo *info;
5735 e.out.count = &count;
5737 e.out.needed = &needed;
5739 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinters_r(b, tctx, &e),
5740 "failed to enum printers");
5742 if (W_ERROR_EQUAL(e.out.result, WERR_INSUFFICIENT_BUFFER)) {
5743 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
5744 e.in.buffer = &blob;
5745 e.in.offered = needed;
5747 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinters_r(b, tctx, &e),
5748 "failed to enum printers");
5751 torture_assert_werr_ok(tctx, e.out.result,
5752 "failed to enum printers");
5754 for (i=0; i < count; i++) {
5756 const char *current = NULL;
5761 current = info[i].info1.name;
5765 if (strequal(current, name)) {
5770 q = strrchr(current, '\\');
5773 torture_warning(tctx,
5774 "server returns printername %s incl. servername although we did not set servername", current);
5777 if (strequal(q, name)) {
5787 static bool test_AddPrinter_wellknown(struct torture_context *tctx,
5788 struct dcerpc_pipe *p,
5789 const char *printername,
5793 struct spoolss_AddPrinter r;
5794 struct spoolss_AddPrinterEx rex;
5795 struct spoolss_SetPrinterInfoCtr info_ctr;
5796 struct spoolss_SetPrinterInfo1 info1;
5797 struct spoolss_DevmodeContainer devmode_ctr;
5798 struct sec_desc_buf secdesc_ctr;
5799 struct spoolss_UserLevelCtr userlevel_ctr;
5800 struct policy_handle handle;
5802 struct dcerpc_binding_handle *b = p->binding_handle;
5804 ZERO_STRUCT(devmode_ctr);
5805 ZERO_STRUCT(secdesc_ctr);
5806 ZERO_STRUCT(userlevel_ctr);
5809 torture_comment(tctx, "Testing AddPrinter%s level 1\n", ex ? "Ex":"");
5811 /* try to add printer to wellknown printer list (level 1) */
5813 userlevel_ctr.level = 1;
5815 info_ctr.info.info1 = &info1;
5818 rex.in.server = NULL;
5819 rex.in.info_ctr = &info_ctr;
5820 rex.in.devmode_ctr = &devmode_ctr;
5821 rex.in.secdesc_ctr = &secdesc_ctr;
5822 rex.in.userlevel_ctr = &userlevel_ctr;
5823 rex.out.handle = &handle;
5826 r.in.info_ctr = &info_ctr;
5827 r.in.devmode_ctr = &devmode_ctr;
5828 r.in.secdesc_ctr = &secdesc_ctr;
5829 r.out.handle = &handle;
5831 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) :
5832 dcerpc_spoolss_AddPrinter_r(b, tctx, &r),
5833 "failed to add printer");
5834 result = ex ? rex.out.result : r.out.result;
5835 torture_assert_werr_equal(tctx, result, WERR_INVALID_PRINTER_NAME,
5836 "unexpected result code");
5838 info1.name = printername;
5839 info1.flags = PRINTER_ATTRIBUTE_SHARED;
5841 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) :
5842 dcerpc_spoolss_AddPrinter_r(b, tctx, &r),
5843 "failed to add printer");
5844 result = ex ? rex.out.result : r.out.result;
5845 torture_assert_werr_equal(tctx, result, WERR_PRINTER_ALREADY_EXISTS,
5846 "unexpected result code");
5848 /* bizarre protocol, WERR_PRINTER_ALREADY_EXISTS means success here,
5849 better do a real check to see the printer is really there */
5851 torture_assert(tctx, test_EnumPrinters_findname(tctx, b,
5852 PRINTER_ENUM_NETWORK, 1,
5855 "failed to enum printers");
5857 torture_assert(tctx, found, "failed to find newly added printer");
5861 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) :
5862 dcerpc_spoolss_AddPrinter_r(b, tctx, &r),
5863 "failed to add printer");
5864 result = ex ? rex.out.result : r.out.result;
5865 torture_assert_werr_equal(tctx, result, WERR_PRINTER_ALREADY_EXISTS,
5866 "unexpected result code");
5868 /* bizarre protocol, WERR_PRINTER_ALREADY_EXISTS means success here,
5869 better do a real check to see the printer has really been removed
5870 from the well known printer list */
5874 torture_assert(tctx, test_EnumPrinters_findname(tctx, b,
5875 PRINTER_ENUM_NETWORK, 1,
5878 "failed to enum printers");
5880 torture_assert(tctx, !found, "printer still in well known printer list");
5885 static bool test_AddPrinter_normal(struct torture_context *tctx,
5886 struct dcerpc_pipe *p,
5887 struct policy_handle *handle_p,
5888 const char *printername,
5889 const char *drivername,
5890 const char *portname,
5894 struct spoolss_AddPrinter r;
5895 struct spoolss_AddPrinterEx rex;
5896 struct spoolss_SetPrinterInfoCtr info_ctr;
5897 struct spoolss_SetPrinterInfo2 info2;
5898 struct spoolss_DevmodeContainer devmode_ctr;
5899 struct sec_desc_buf secdesc_ctr;
5900 struct spoolss_UserLevelCtr userlevel_ctr;
5901 struct policy_handle handle;
5903 bool existing_printer_deleted = false;
5904 struct dcerpc_binding_handle *b = p->binding_handle;
5906 ZERO_STRUCT(devmode_ctr);
5907 ZERO_STRUCT(secdesc_ctr);
5908 ZERO_STRUCT(userlevel_ctr);
5910 torture_comment(tctx, "Testing AddPrinter%s level 2\n", ex ? "Ex":"");
5912 userlevel_ctr.level = 1;
5914 rex.in.server = NULL;
5915 rex.in.info_ctr = &info_ctr;
5916 rex.in.devmode_ctr = &devmode_ctr;
5917 rex.in.secdesc_ctr = &secdesc_ctr;
5918 rex.in.userlevel_ctr = &userlevel_ctr;
5919 rex.out.handle = &handle;
5922 r.in.info_ctr = &info_ctr;
5923 r.in.devmode_ctr = &devmode_ctr;
5924 r.in.secdesc_ctr = &secdesc_ctr;
5925 r.out.handle = &handle;
5929 /* try to add printer to printer list (level 2) */
5933 info_ctr.info.info2 = &info2;
5936 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) :
5937 dcerpc_spoolss_AddPrinter_r(b, tctx, &r),
5938 "failed to add printer");
5939 result = ex ? rex.out.result : r.out.result;
5940 torture_assert_werr_equal(tctx, result, WERR_INVALID_PRINTER_NAME,
5941 "unexpected result code");
5943 info2.printername = printername;
5945 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) :
5946 dcerpc_spoolss_AddPrinter_r(b, tctx, &r),
5947 "failed to add printer");
5948 result = ex ? rex.out.result : r.out.result;
5950 if (W_ERROR_EQUAL(result, WERR_PRINTER_ALREADY_EXISTS)) {
5951 struct policy_handle printer_handle;
5953 if (existing_printer_deleted) {
5954 torture_fail(tctx, "already deleted printer still existing?");
5957 torture_assert(tctx, call_OpenPrinterEx(tctx, p, printername, NULL, &printer_handle),
5958 "failed to open printer handle");
5960 torture_assert(tctx, test_DeletePrinter(tctx, b, &printer_handle),
5961 "failed to delete printer");
5963 torture_assert(tctx, test_ClosePrinter(tctx, b, &printer_handle),
5964 "failed to close server handle");
5966 existing_printer_deleted = true;
5971 torture_assert_werr_equal(tctx, result, WERR_UNKNOWN_PORT,
5972 "unexpected result code");
5974 info2.portname = portname;
5976 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) :
5977 dcerpc_spoolss_AddPrinter_r(b, tctx, &r),
5978 "failed to add printer");
5979 result = ex ? rex.out.result : r.out.result;
5980 torture_assert_werr_equal(tctx, result, WERR_UNKNOWN_PRINTER_DRIVER,
5981 "unexpected result code");
5983 info2.drivername = drivername;
5985 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) :
5986 dcerpc_spoolss_AddPrinter_r(b, tctx, &r),
5987 "failed to add printer");
5988 result = ex ? rex.out.result : r.out.result;
5990 /* w2k8r2 allows to add printer w/o defining printprocessor */
5992 if (!W_ERROR_IS_OK(result)) {
5993 torture_assert_werr_equal(tctx, result, WERR_UNKNOWN_PRINTPROCESSOR,
5994 "unexpected result code");
5996 info2.printprocessor = "winprint";
5998 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) :
5999 dcerpc_spoolss_AddPrinter_r(b, tctx, &r),
6000 "failed to add printer");
6001 result = ex ? rex.out.result : r.out.result;
6002 torture_assert_werr_ok(tctx, result,
6003 "failed to add printer");
6008 /* we are paranoid, really check if the printer is there now */
6010 torture_assert(tctx, test_EnumPrinters_findname(tctx, b,
6011 PRINTER_ENUM_LOCAL, 1,
6014 "failed to enum printers");
6015 torture_assert(tctx, found, "failed to find newly added printer");
6017 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) :
6018 dcerpc_spoolss_AddPrinter_r(b, tctx, &r),
6019 "failed to add printer");
6020 result = ex ? rex.out.result : r.out.result;
6021 torture_assert_werr_equal(tctx, result, WERR_PRINTER_ALREADY_EXISTS,
6022 "unexpected result code");
6027 static bool test_printer_info(struct torture_context *tctx,
6028 struct dcerpc_binding_handle *b,
6029 struct policy_handle *handle)
6033 if (torture_setting_bool(tctx, "samba3", false)) {
6034 torture_skip(tctx, "skipping printer info cross tests against samba 3");
6037 if (!test_PrinterInfo(tctx, b, handle)) {
6041 if (!test_SetPrinter_errors(tctx, b, handle)) {
6048 static bool test_EnumPrinterKey(struct torture_context *tctx,
6049 struct dcerpc_binding_handle *b,
6050 struct policy_handle *handle,
6051 const char *key_name,
6052 const char ***array)
6054 struct spoolss_EnumPrinterKey r;
6055 uint32_t needed = 0;
6056 union spoolss_KeyNames key_buffer;
6057 int32_t offered[] = { 0, 1, 2, 3, 4, 5, -1, -2, -3, -4, -5, 256, 512, 1024, 2048 };
6061 r.in.handle = handle;
6062 r.in.key_name = key_name;
6063 r.out.key_buffer = &key_buffer;
6064 r.out.needed = &needed;
6065 r.out._ndr_size = &_ndr_size;
6067 for (i=0; i < ARRAY_SIZE(offered); i++) {
6069 if (offered[i] < 0 && needed) {
6073 r.in.offered = needed + offered[i];
6075 r.in.offered = offered[i];
6078 ZERO_STRUCT(key_buffer);
6080 torture_comment(tctx, "Testing EnumPrinterKey(%s) with %d offered\n", r.in.key_name, r.in.offered);
6082 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinterKey_r(b, tctx, &r),
6083 "failed to call EnumPrinterKey");
6084 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
6086 torture_assert(tctx, (_ndr_size == r.in.offered/2),
6087 talloc_asprintf(tctx, "EnumPrinterKey size mismatch, _ndr_size %d (expected %d)",
6088 _ndr_size, r.in.offered/2));
6090 r.in.offered = needed;
6091 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinterKey_r(b, tctx, &r),
6092 "failed to call EnumPrinterKey");
6095 if (offered[i] > 0) {
6096 torture_assert_werr_ok(tctx, r.out.result,
6097 "failed to call EnumPrinterKey");
6100 torture_assert(tctx, (_ndr_size == r.in.offered/2),
6101 talloc_asprintf(tctx, "EnumPrinterKey size mismatch, _ndr_size %d (expected %d)",
6102 _ndr_size, r.in.offered/2));
6104 torture_assert(tctx, (*r.out.needed <= r.in.offered),
6105 talloc_asprintf(tctx, "EnumPrinterKey size mismatch: needed %d is not <= offered %d", *r.out.needed, r.in.offered));
6107 torture_assert(tctx, (*r.out.needed <= _ndr_size * 2),
6108 talloc_asprintf(tctx, "EnumPrinterKey size mismatch: needed %d is not <= _ndr_size %d * 2", *r.out.needed, _ndr_size));
6110 if (key_buffer.string_array) {
6111 uint32_t calc_needed = 0;
6113 for (s=0; key_buffer.string_array[s]; s++) {
6114 calc_needed += strlen_m_term(key_buffer.string_array[s])*2;
6116 if (!key_buffer.string_array[0]) {
6121 torture_assert_int_equal(tctx, *r.out.needed, calc_needed,
6122 "EnumPrinterKey unexpected size");
6127 *array = key_buffer.string_array;
6133 bool test_printer_keys(struct torture_context *tctx,
6134 struct dcerpc_binding_handle *b,
6135 struct policy_handle *handle)
6137 const char **key_array = NULL;
6140 torture_comment(tctx, "Testing Printer Keys\n");
6142 torture_assert(tctx, test_EnumPrinterKey(tctx, b, handle, "", &key_array),
6143 "failed to call test_EnumPrinterKey");
6145 for (i=0; key_array && key_array[i]; i++) {
6146 torture_assert(tctx, test_EnumPrinterKey(tctx, b, handle, key_array[i], NULL),
6147 "failed to call test_EnumPrinterKey");
6149 for (i=0; key_array && key_array[i]; i++) {
6150 torture_assert(tctx, test_EnumPrinterDataEx(tctx, b, handle, key_array[i], NULL, NULL),
6151 "failed to call test_EnumPrinterDataEx");
6154 torture_comment(tctx, "Printer Keys test succeeded\n\n");
6159 static bool test_one_printer(struct torture_context *tctx,
6160 struct dcerpc_pipe *p,
6161 struct policy_handle *handle,
6163 const char *drivername,
6164 const char *environment,
6168 struct dcerpc_binding_handle *b = p->binding_handle;
6170 if (!test_PausePrinter(tctx, b, handle)) {
6174 if (!test_DoPrintTest(tctx, b, handle)) {
6178 if (!test_ResumePrinter(tctx, b, handle)) {
6182 if (!test_printer_info(tctx, b, handle)) {
6186 if (!test_PrinterInfo_SD(tctx, b, handle)) {
6190 if (!test_PrinterInfo_DevMode(tctx, p, handle, name)) {
6194 if (!test_PrinterInfo_winreg(tctx, p, handle, name)) {
6198 if (!test_ChangeID(tctx, p, handle)) {
6202 if (!test_printer_keys(tctx, b, handle)) {
6206 if (!test_EnumPrinterData_consistency(tctx, p, handle)) {
6210 if (!test_SetPrinterDataEx_matrix(tctx, p, handle, name, NULL, NULL)) {
6214 if (!test_PrinterData_winreg(tctx, p, handle, name)) {
6219 if (!test_DriverInfo_winreg(tctx, p, handle, name, drivername, environment)) {
6224 if (!test_printer_rename(tctx, p, handle, name)) {
6231 static bool test_csetprinter(struct torture_context *tctx,
6232 struct dcerpc_pipe *p,
6233 struct policy_handle *handle,
6234 const char *printername,
6235 const char *drivername,
6236 const char *portname)
6238 union spoolss_PrinterInfo info;
6239 struct policy_handle new_handle, new_handle2;
6240 struct dcerpc_binding_handle *b = p->binding_handle;
6242 torture_comment(tctx, "Testing c_setprinter\n");
6244 torture_assert(tctx,
6245 test_GetPrinter_level(tctx, b, handle, 0, &info),
6246 "failed to get level 0 printer info");
6247 torture_comment(tctx, "csetprinter on initial printer handle: %d\n",
6248 info.info0.c_setprinter);
6250 /* check if c_setprinter on 1st handle increases after a printer has
6253 torture_assert(tctx,
6254 test_AddPrinter_normal(tctx, p, &new_handle, printername, drivername, portname, false),
6255 "failed to add new printer");
6256 torture_assert(tctx,
6257 test_GetPrinter_level(tctx, b, handle, 0, &info),
6258 "failed to get level 0 printer info");
6259 torture_comment(tctx, "csetprinter on initial printer handle (after add): %d\n",
6260 info.info0.c_setprinter);
6262 /* check if c_setprinter on new handle increases after a printer has
6265 torture_assert(tctx,
6266 test_GetPrinter_level(tctx, b, &new_handle, 0, &info),
6267 "failed to get level 0 printer info");
6268 torture_comment(tctx, "csetprinter on created handle: %d\n",
6269 info.info0.c_setprinter);
6271 /* open the new printer and check if c_setprinter increases */
6273 torture_assert(tctx,
6274 call_OpenPrinterEx(tctx, p, printername, NULL, &new_handle2),
6275 "failed to open created printer");
6276 torture_assert(tctx,
6277 test_GetPrinter_level(tctx, b, &new_handle2, 0, &info),
6278 "failed to get level 0 printer info");
6279 torture_comment(tctx, "csetprinter on new handle (after openprinter): %d\n",
6280 info.info0.c_setprinter);
6284 torture_assert(tctx,
6285 test_ClosePrinter(tctx, b, &new_handle2),
6286 "failed to close printer");
6287 torture_assert(tctx,
6288 test_DeletePrinter(tctx, b, &new_handle),
6289 "failed to delete new printer");
6294 static bool test_add_printer_args_with_driver(struct torture_context *tctx,
6295 struct dcerpc_pipe *p,
6296 struct torture_printer_context *t)
6299 struct policy_handle handle;
6301 struct dcerpc_binding_handle *b = p->binding_handle;
6302 const char *printer_name = t->info2.printername;
6303 const char *driver_name = t->added_driver ? t->driver.info8.driver_name : t->info2.drivername;
6304 const char *port_name = t->info2.portname;
6305 const char *printer_name2 = talloc_asprintf(tctx, "%s2", printer_name);
6308 torture_assert(tctx,
6309 test_AddPrinter_wellknown(tctx, p, printer_name, t->ex),
6310 "failed to add wellknown printer");
6312 torture_assert(tctx,
6313 test_AddPrinter_normal(tctx, p, &handle, printer_name, driver_name, port_name, t->ex),
6314 "failed to add printer");
6317 if (!test_csetprinter(tctx, p, &handle, printer_name2, driver_name, port_name)) {
6321 if (!test_one_printer(tctx, p, &handle, printer_name, driver_name, t->driver.remote.environment, t->have_driver)) {
6325 if (!test_DeletePrinter(tctx, b, &handle)) {
6329 if (!test_EnumPrinters_findname(tctx, b, PRINTER_ENUM_LOCAL, 1,
6330 printer_name, &found)) {
6334 torture_assert(tctx, !found, "deleted printer still there");
6339 static bool compose_local_driver_directory(struct torture_context *tctx,
6340 const char *environment,
6341 const char *local_dir,
6346 p = strrchr(local_dir, '/');
6352 if (strequal(environment, "Windows x64")) {
6353 if (!strequal(p, "x64")) {
6354 *path = talloc_asprintf(tctx, "%s/x64", local_dir);
6356 } else if (strequal(environment, "Windows NT x86")) {
6357 if (!strequal(p, "i386")) {
6358 *path = talloc_asprintf(tctx, "%s/i386", local_dir);
6361 torture_assert(tctx, "unknown environment: '%s'\n", environment);
6367 static bool test_add_printer_args(struct torture_context *tctx,
6368 struct dcerpc_pipe *p,
6369 struct torture_printer_context *t)
6372 struct dcerpc_binding_handle *b = p->binding_handle;
6373 const char *server_name_slash = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
6375 if (t->wellknown && torture_setting_bool(tctx, "samba3", false)) {
6376 torture_skip(tctx, "skipping AddPrinter level 1 against samba");
6379 torture_assert(tctx,
6380 fillup_printserver_info(tctx, p, &t->driver),
6381 "failed to fillup printserver info");
6383 t->driver.info8.architecture = talloc_strdup(t, t->driver.remote.environment);
6385 torture_assert(tctx,
6386 compose_local_driver_directory(tctx, t->driver.remote.environment,
6387 t->driver.local.driver_directory,
6388 &t->driver.local.driver_directory),
6389 "failed to compose local driver directory");
6391 if (test_EnumPrinterDrivers_findone(tctx, b, server_name_slash, t->driver.remote.environment, 3, t->info2.drivername)) {
6392 t->have_driver = true;
6396 torture_comment(tctx, "driver '%s' (architecture: %s, version: 3) does not exist on the server\n",
6397 t->info2.drivername, t->driver.remote.environment);
6398 torture_comment(tctx, "trying to upload own driver\n");
6400 if (!directory_exist(t->driver.local.driver_directory)) {
6401 torture_warning(tctx, "no local driver is available!");
6402 t->have_driver = false;
6406 torture_assert(tctx,
6407 upload_printer_driver(tctx, dcerpc_server_name(p), &t->driver),
6408 "failed to upload printer driver");
6410 torture_assert(tctx,
6411 test_AddPrinterDriver_args_level_3(tctx, b, server_name_slash, &t->driver.info8, 0, false),
6412 "failed to add driver");
6414 t->added_driver = true;
6415 t->have_driver = true;
6418 ret = test_add_printer_args_with_driver(tctx, p, t);
6420 if (t->added_driver) {
6421 torture_assert(tctx,
6422 remove_printer_driver(tctx, dcerpc_server_name(p), &t->driver),
6423 "failed to remove printer driver");
6429 static bool test_add_printer(struct torture_context *tctx,
6430 struct dcerpc_pipe *p,
6433 struct torture_printer_context *t =
6434 (struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context);
6437 t->wellknown = false;
6438 t->info2.printername = TORTURE_PRINTER;
6440 return test_add_printer_args(tctx, p, t);
6443 static bool test_add_printer_wellknown(struct torture_context *tctx,
6444 struct dcerpc_pipe *p,
6447 struct torture_printer_context *t =
6448 (struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context);
6451 t->wellknown = true;
6452 t->info2.printername = TORTURE_WELLKNOWN_PRINTER;
6454 return test_add_printer_args(tctx, p, t);
6457 static bool test_add_printer_ex(struct torture_context *tctx,
6458 struct dcerpc_pipe *p,
6461 struct torture_printer_context *t =
6462 (struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context);
6465 t->wellknown = false;
6466 t->info2.printername = TORTURE_PRINTER_EX;
6468 return test_add_printer_args(tctx, p, t);
6471 static bool test_add_printer_ex_wellknown(struct torture_context *tctx,
6472 struct dcerpc_pipe *p,
6475 struct torture_printer_context *t =
6476 (struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context);
6479 t->wellknown = true;
6480 t->info2.printername = TORTURE_WELLKNOWN_PRINTER_EX;
6482 return test_add_printer_args(tctx, p, t);
6485 static bool test_architecture_buffer(struct torture_context *tctx,
6486 struct dcerpc_pipe *p)
6488 struct spoolss_OpenPrinterEx r;
6489 struct spoolss_UserLevel1 u1;
6490 struct policy_handle handle;
6491 uint32_t architectures[] = {
6492 PROCESSOR_ARCHITECTURE_INTEL,
6493 PROCESSOR_ARCHITECTURE_IA64,
6494 PROCESSOR_ARCHITECTURE_AMD64
6498 struct dcerpc_binding_handle *b = p->binding_handle;
6500 for (i=0; i < ARRAY_SIZE(architectures); i++) {
6502 torture_comment(tctx, "Testing OpenPrinterEx with architecture %d\n", architectures[i]);
6510 u1.processor = architectures[i];
6512 r.in.printername = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
6513 r.in.datatype = NULL;
6514 r.in.devmode_ctr.devmode= NULL;
6515 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
6517 r.in.userlevel.level1 = &u1;
6518 r.out.handle = &handle;
6520 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_OpenPrinterEx_r(b, tctx, &r), "");
6521 torture_assert_werr_ok(tctx, r.out.result, "");
6524 struct spoolss_EnumPrinters e;
6526 union spoolss_PrinterInfo *info;
6528 e.in.flags = PRINTER_ENUM_LOCAL;
6533 e.out.count = &count;
6535 e.out.needed = &needed[i];
6537 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinters_r(b, tctx, &e), "");
6539 torture_comment(tctx, "needed was %d\n", needed[i]);
6543 torture_assert(tctx, test_ClosePrinter(tctx, b, &handle), "");
6546 for (i=1; i < ARRAY_SIZE(architectures); i++) {
6547 if (needed[i-1] != needed[i]) {
6549 talloc_asprintf(tctx, "needed size %d for architecture %d != needed size %d for architecture %d\n",
6550 needed[i-1], architectures[i-1], needed[i], architectures[i]));
6557 bool torture_rpc_spoolss(struct torture_context *torture)
6560 struct dcerpc_pipe *p;
6561 struct dcerpc_binding_handle *b;
6563 struct test_spoolss_context *ctx;
6564 const char *environment = SPOOLSS_ARCHITECTURE_NT_X86;
6566 status = torture_rpc_connection(torture, &p, &ndr_table_spoolss);
6567 if (!NT_STATUS_IS_OK(status)) {
6570 b = p->binding_handle;
6572 ctx = talloc_zero(torture, struct test_spoolss_context);
6574 ret &= test_OpenPrinter_server(torture, p, &ctx->server_handle);
6575 ret &= test_GetPrinterData_list(torture, p, &ctx->server_handle, &environment);
6576 ret &= test_EnumForms_all(torture, b, &ctx->server_handle, true);
6577 ret &= test_Forms(torture, b, &ctx->server_handle, true, NULL, NULL, NULL);
6578 ret &= test_Forms_winreg(torture, b, &ctx->server_handle, true, NULL);
6579 ret &= test_EnumPorts(torture, b, ctx);
6580 ret &= test_GetPrinterDriverDirectory(torture, p, environment);
6581 ret &= test_GetPrintProcessorDirectory(torture, p, environment);
6582 ret &= test_EnumPrinterDrivers(torture, p, ctx, environment);
6583 ret &= test_EnumPrinterDrivers(torture, p, ctx, SPOOLSS_ARCHITECTURE_ALL);
6584 ret &= test_EnumMonitors(torture, b, ctx);
6585 ret &= test_EnumPrintProcessors(torture, b, ctx, environment);
6586 ret &= test_EnumPrintProcDataTypes(torture, b);
6587 ret &= test_EnumPrinters(torture, b, ctx);
6588 ret &= test_OpenPrinter_badname_list(torture, b, dcerpc_server_name(p));
6590 ret &= test_AddPort(torture, p);
6591 ret &= test_EnumPorts_old(torture, p);
6592 ret &= test_EnumPrinters_old(torture, p, environment);
6593 ret &= test_EnumPrinterDrivers_old(torture, p, environment);
6594 ret &= test_architecture_buffer(torture, p);
6599 struct torture_suite *torture_rpc_spoolss_printer(TALLOC_CTX *mem_ctx)
6601 struct torture_suite *suite = torture_suite_create(mem_ctx, "SPOOLSS-PRINTER");
6603 struct torture_rpc_tcase *tcase = torture_suite_add_rpc_iface_tcase(suite,
6604 "printer", &ndr_table_spoolss);
6606 struct torture_printer_context *t;
6608 t = talloc_zero(mem_ctx, struct torture_printer_context);
6610 t->driver.info8.version = SPOOLSS_DRIVER_VERSION_200X;
6611 t->driver.info8.driver_name = TORTURE_DRIVER;
6612 t->driver.info8.driver_path = "pscript5.dll";
6613 t->driver.info8.data_file = "cups6.ppd";
6614 t->driver.info8.config_file = "ps5ui.dll";
6615 t->driver.info8.help_file = "pscript.hlp";
6616 t->driver.info8.default_datatype = "RAW";
6617 t->driver.info8.dependent_files = talloc_zero(t, struct spoolss_StringArray);
6618 t->driver.info8.dependent_files->string = talloc_zero_array(t, const char *, 8 + 1);
6619 t->driver.info8.dependent_files->string[0] = "pscript5.dll";
6620 t->driver.info8.dependent_files->string[1] = "cups6.ppd";
6621 t->driver.info8.dependent_files->string[2] = "ps5ui.dll";
6622 t->driver.info8.dependent_files->string[3] = "pscript.hlp";
6623 t->driver.info8.dependent_files->string[4] = "pscript.ntf";
6624 t->driver.info8.dependent_files->string[5] = "cups6.ini";
6625 t->driver.info8.dependent_files->string[6] = "cupsps6.dll";
6626 t->driver.info8.dependent_files->string[7] = "cupsui6.dll";
6628 t->driver.local.driver_directory= "/usr/share/cups/drivers";
6630 t->info2.drivername = "Microsoft XPS Document Writer";
6631 t->info2.portname = "LPT1:";
6633 torture_rpc_tcase_add_test_ex(tcase, "add_printer", test_add_printer, t);
6634 torture_rpc_tcase_add_test_ex(tcase, "add_printer_wellknown", test_add_printer_wellknown, t);
6635 torture_rpc_tcase_add_test_ex(tcase, "add_printer_ex", test_add_printer_ex, t);
6636 torture_rpc_tcase_add_test_ex(tcase, "add_printer_ex_wellknown", test_add_printer_ex_wellknown, t);
6641 static bool test_GetPrinterDriverDirectory_getdir(struct torture_context *tctx,
6642 struct dcerpc_binding_handle *b,
6644 const char *environment,
6647 struct spoolss_GetPrinterDriverDirectory r;
6650 r.in.server = server;
6651 r.in.environment = environment;
6655 r.out.needed = &needed;
6657 torture_assert_ntstatus_ok(tctx,
6658 dcerpc_spoolss_GetPrinterDriverDirectory_r(b, tctx, &r),
6659 "failed to query driver directory");
6661 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
6662 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
6663 r.in.buffer = &blob;
6664 r.in.offered = needed;
6666 torture_assert_ntstatus_ok(tctx,
6667 dcerpc_spoolss_GetPrinterDriverDirectory_r(b, tctx, &r),
6668 "failed to query driver directory");
6671 torture_assert_werr_ok(tctx, r.out.result,
6672 "failed to query driver directory");
6675 *dir_p = r.out.info->info1.directory_name;
6681 static const char *get_driver_from_info(struct spoolss_AddDriverInfoCtr *info_ctr)
6683 if (info_ctr == NULL) {
6687 switch (info_ctr->level) {
6689 return info_ctr->info.info1->driver_name;
6691 return info_ctr->info.info2->driver_name;
6693 return info_ctr->info.info3->driver_name;
6695 return info_ctr->info.info4->driver_name;
6697 return info_ctr->info.info6->driver_name;
6699 return info_ctr->info.info8->driver_name;
6705 static const char *get_environment_from_info(struct spoolss_AddDriverInfoCtr *info_ctr)
6707 if (info_ctr == NULL) {
6711 switch (info_ctr->level) {
6713 return info_ctr->info.info2->architecture;
6715 return info_ctr->info.info3->architecture;
6717 return info_ctr->info.info4->architecture;
6719 return info_ctr->info.info6->architecture;
6721 return info_ctr->info.info8->architecture;
6728 static bool test_AddPrinterDriver_exp(struct torture_context *tctx,
6729 struct dcerpc_binding_handle *b,
6730 const char *servername,
6731 struct spoolss_AddDriverInfoCtr *info_ctr,
6732 WERROR expected_result)
6734 struct spoolss_AddPrinterDriver r;
6735 const char *drivername = get_driver_from_info(info_ctr);
6736 const char *environment = get_environment_from_info(info_ctr);
6738 r.in.servername = servername;
6739 r.in.info_ctr = info_ctr;
6741 torture_comment(tctx, "Testing AddPrinterDriver(%s) level: %d, environment: '%s'\n",
6742 drivername, info_ctr->level, environment);
6744 torture_assert_ntstatus_ok(tctx,
6745 dcerpc_spoolss_AddPrinterDriver_r(b, tctx, &r),
6746 "spoolss_AddPrinterDriver failed");
6747 torture_assert_werr_equal(tctx, r.out.result, expected_result,
6748 "spoolss_AddPrinterDriver failed with unexpected result");
6754 static bool test_AddPrinterDriverEx_exp(struct torture_context *tctx,
6755 struct dcerpc_binding_handle *b,
6756 const char *servername,
6757 struct spoolss_AddDriverInfoCtr *info_ctr,
6759 WERROR expected_result)
6761 struct spoolss_AddPrinterDriverEx r;
6762 const char *drivername = get_driver_from_info(info_ctr);
6763 const char *environment = get_environment_from_info(info_ctr);
6765 r.in.servername = servername;
6766 r.in.info_ctr = info_ctr;
6769 torture_comment(tctx, "Testing AddPrinterDriverEx(%s) level: %d, environment: '%s'\n",
6770 drivername, info_ctr->level, environment);
6772 torture_assert_ntstatus_ok(tctx,
6773 dcerpc_spoolss_AddPrinterDriverEx_r(b, tctx, &r),
6774 "AddPrinterDriverEx failed");
6775 torture_assert_werr_equal(tctx, r.out.result, expected_result,
6776 "AddPrinterDriverEx failed with unexpected result");
6781 static bool test_AddPrinterDriver_args_level_1(struct torture_context *tctx,
6782 struct dcerpc_binding_handle *b,
6783 const char *server_name,
6784 struct spoolss_AddDriverInfo8 *r,
6788 struct spoolss_AddDriverInfoCtr info_ctr;
6789 struct spoolss_AddDriverInfo1 info1;
6794 info_ctr.info.info1 = &info1;
6797 torture_assert(tctx,
6798 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_UNKNOWN_LEVEL),
6799 "failed to test AddPrinterDriverEx level 1");
6801 torture_assert(tctx,
6802 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_UNKNOWN_LEVEL),
6803 "failed to test AddPrinterDriver level 1");
6806 info1.driver_name = r->driver_name;
6809 torture_assert(tctx,
6810 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_UNKNOWN_LEVEL),
6811 "failed to test AddPrinterDriverEx level 1");
6813 torture_assert(tctx,
6814 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_UNKNOWN_LEVEL),
6815 "failed to test AddPrinterDriver level 1");
6821 static bool test_AddPrinterDriver_args_level_2(struct torture_context *tctx,
6822 struct dcerpc_binding_handle *b,
6823 const char *server_name,
6824 struct spoolss_AddDriverInfo8 *r,
6828 struct spoolss_AddDriverInfoCtr info_ctr;
6829 struct spoolss_AddDriverInfo2 info2;
6834 info_ctr.info.info2 = &info2;
6837 torture_assert(tctx,
6838 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_INVALID_PARAM),
6839 "failed to test AddPrinterDriverEx level 2");
6841 torture_assert(tctx,
6842 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_INVALID_PARAM),
6843 "failed to test AddPrinterDriver level 2");
6846 info2.driver_name = r->driver_name;
6849 torture_assert(tctx,
6850 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_INVALID_PARAM),
6851 "failed to test AddPrinterDriverEx level 2");
6853 torture_assert(tctx,
6854 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_INVALID_PARAM),
6855 "failed to test AddPrinterDriver level 2");
6858 info2.version = r->version;
6861 torture_assert(tctx,
6862 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_INVALID_PARAM),
6863 "failed to test AddPrinterDriverEx level 2");
6865 torture_assert(tctx,
6866 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_INVALID_PARAM),
6867 "failed to test AddPrinterDriver level 2");
6870 info2.architecture = r->architecture;
6873 torture_assert(tctx,
6874 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_INVALID_PARAM),
6875 "failed to test AddPrinterDriverEx level 2");
6877 torture_assert(tctx,
6878 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_INVALID_PARAM),
6879 "failed to test AddPrinterDriver level 2");
6882 info2.driver_path = r->driver_path;
6885 torture_assert(tctx,
6886 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_INVALID_PARAM),
6887 "failed to test AddPrinterDriverEx level 2");
6889 torture_assert(tctx,
6890 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_INVALID_PARAM),
6891 "failed to test AddPrinterDriver level 2");
6894 info2.data_file = r->data_file;
6897 torture_assert(tctx,
6898 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_INVALID_PARAM),
6899 "failed to test AddPrinterDriverEx level 2");
6901 torture_assert(tctx,
6902 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_INVALID_PARAM),
6903 "failed to test AddPrinterDriver level 2");
6906 info2.config_file = r->config_file;
6909 torture_assert(tctx,
6910 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, 0, WERR_INVALID_PARAM),
6911 "failed to test AddPrinterDriverEx");
6915 torture_assert(tctx,
6916 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_OK),
6917 "failed to test AddPrinterDriverEx level 2");
6919 torture_assert(tctx,
6920 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_OK),
6921 "failed to test AddPrinterDriver level 2");
6924 torture_assert(tctx,
6925 test_EnumPrinterDrivers_findone(tctx, b, server_name, r->architecture, 2, r->driver_name),
6926 "failed to find added printer driver");
6931 static bool test_AddPrinterDriver_args_level_3(struct torture_context *tctx,
6932 struct dcerpc_binding_handle *b,
6933 const char *server_name,
6934 struct spoolss_AddDriverInfo8 *r,
6938 struct spoolss_AddDriverInfoCtr info_ctr;
6939 struct spoolss_AddDriverInfo3 info3;
6941 info3.driver_name = r->driver_name;
6942 info3.version = r->version;
6943 info3.architecture = r->architecture;
6944 info3.driver_path = r->driver_path;
6945 info3.data_file = r->data_file;
6946 info3.config_file = r->config_file;
6947 info3.help_file = r->help_file;
6948 info3.monitor_name = r->monitor_name;
6949 info3.default_datatype = r->default_datatype;
6950 info3._ndr_size_dependent_files = r->_ndr_size_dependent_files;
6951 info3.dependent_files = r->dependent_files;
6954 info_ctr.info.info3 = &info3;
6957 torture_assert(tctx,
6958 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_OK),
6959 "failed to test AddPrinterDriverEx level 3");
6961 torture_assert(tctx,
6962 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_OK),
6963 "failed to test AddPrinterDriver level 3");
6966 torture_assert(tctx,
6967 test_EnumPrinterDrivers_findone(tctx, b, server_name, r->architecture, 3, r->driver_name),
6968 "failed to find added printer driver");
6973 static bool test_AddPrinterDriver_args_level_4(struct torture_context *tctx,
6974 struct dcerpc_binding_handle *b,
6975 const char *server_name,
6976 struct spoolss_AddDriverInfo8 *r,
6980 struct spoolss_AddDriverInfoCtr info_ctr;
6981 struct spoolss_AddDriverInfo4 info4;
6983 info4.version = r->version;
6984 info4.driver_name = r->driver_name;
6985 info4.architecture = r->architecture;
6986 info4.driver_path = r->driver_path;
6987 info4.data_file = r->data_file;
6988 info4.config_file = r->config_file;
6989 info4.help_file = r->help_file;
6990 info4.monitor_name = r->monitor_name;
6991 info4.default_datatype = r->default_datatype;
6992 info4._ndr_size_dependent_files = r->_ndr_size_dependent_files;
6993 info4.dependent_files = r->dependent_files;
6994 info4._ndr_size_previous_names = r->_ndr_size_previous_names;
6995 info4.previous_names = r->previous_names;
6998 info_ctr.info.info4 = &info4;
7001 torture_assert(tctx,
7002 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_OK),
7003 "failed to test AddPrinterDriverEx level 4");
7005 torture_assert(tctx,
7006 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_OK),
7007 "failed to test AddPrinterDriver level 4");
7010 torture_assert(tctx,
7011 test_EnumPrinterDrivers_findone(tctx, b, server_name, r->architecture, 4, r->driver_name),
7012 "failed to find added printer driver");
7017 static bool test_AddPrinterDriver_args_level_6(struct torture_context *tctx,
7018 struct dcerpc_binding_handle *b,
7019 const char *server_name,
7020 struct spoolss_AddDriverInfo8 *r,
7024 struct spoolss_AddDriverInfoCtr info_ctr;
7025 struct spoolss_AddDriverInfo6 info6;
7027 info6.version = r->version;
7028 info6.driver_name = r->driver_name;
7029 info6.architecture = r->architecture;
7030 info6.driver_path = r->driver_path;
7031 info6.data_file = r->data_file;
7032 info6.config_file = r->config_file;
7033 info6.help_file = r->help_file;
7034 info6.monitor_name = r->monitor_name;
7035 info6.default_datatype = r->default_datatype;
7036 info6._ndr_size_dependent_files = r->_ndr_size_dependent_files;
7037 info6.dependent_files = r->dependent_files;
7038 info6._ndr_size_previous_names = r->_ndr_size_previous_names;
7039 info6.previous_names = r->previous_names;
7040 info6.driver_date = r->driver_date;
7041 info6.driver_version = r->driver_version;
7042 info6.manufacturer_name = r->manufacturer_name;
7043 info6.manufacturer_url = r->manufacturer_url;
7044 info6.hardware_id = r->hardware_id;
7045 info6.provider = r->provider;
7048 info_ctr.info.info6 = &info6;
7051 torture_assert(tctx,
7052 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_OK),
7053 "failed to test AddPrinterDriverEx level 6");
7055 torture_assert(tctx,
7056 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_UNKNOWN_LEVEL),
7057 "failed to test AddPrinterDriver level 6");
7060 /* spoolss_AddPrinterDriver does not deal with level 6 or 8 - gd */
7066 torture_assert(tctx,
7067 test_EnumPrinterDrivers_findone(tctx, b, server_name, r->architecture, 6, r->driver_name),
7068 "failed to find added printer driver");
7073 static bool test_AddPrinterDriver_args_level_8(struct torture_context *tctx,
7074 struct dcerpc_binding_handle *b,
7075 const char *server_name,
7076 struct spoolss_AddDriverInfo8 *r,
7080 struct spoolss_AddDriverInfoCtr info_ctr;
7083 info_ctr.info.info8 = r;
7086 torture_assert(tctx,
7087 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_OK),
7088 "failed to test AddPrinterDriverEx level 8");
7090 torture_assert(tctx,
7091 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_UNKNOWN_LEVEL),
7092 "failed to test AddPrinterDriver level 8");
7095 /* spoolss_AddPrinterDriver does not deal with level 6 or 8 - gd */
7101 torture_assert(tctx,
7102 test_EnumPrinterDrivers_findone(tctx, b, server_name, r->architecture, 8, r->driver_name),
7103 "failed to find added printer driver");
7108 static bool test_DeletePrinterDriver_exp(struct torture_context *tctx,
7109 struct dcerpc_binding_handle *b,
7112 const char *environment,
7113 WERROR expected_result)
7115 struct spoolss_DeletePrinterDriver r;
7117 r.in.server = server;
7118 r.in.architecture = environment;
7119 r.in.driver = driver;
7121 torture_comment(tctx, "Testing DeletePrinterDriver(%s)\n", driver);
7123 torture_assert_ntstatus_ok(tctx,
7124 dcerpc_spoolss_DeletePrinterDriver_r(b, tctx, &r),
7125 "DeletePrinterDriver failed");
7126 torture_assert_werr_equal(tctx, r.out.result, expected_result,
7127 "DeletePrinterDriver failed with unexpected result");
7132 static bool test_DeletePrinterDriverEx_exp(struct torture_context *tctx,
7133 struct dcerpc_binding_handle *b,
7136 const char *environment,
7137 uint32_t delete_flags,
7139 WERROR expected_result)
7141 struct spoolss_DeletePrinterDriverEx r;
7143 r.in.server = server;
7144 r.in.architecture = environment;
7145 r.in.driver = driver;
7146 r.in.delete_flags = delete_flags;
7147 r.in.version = version;
7149 torture_comment(tctx, "Testing DeletePrinterDriverEx(%s)\n", driver);
7151 torture_assert_ntstatus_ok(tctx,
7152 dcerpc_spoolss_DeletePrinterDriverEx_r(b, tctx, &r),
7153 "DeletePrinterDriverEx failed");
7154 torture_assert_werr_equal(tctx, r.out.result, expected_result,
7155 "DeletePrinterDriverEx failed with unexpected result");
7160 static bool test_DeletePrinterDriver(struct torture_context *tctx,
7161 struct dcerpc_binding_handle *b,
7162 const char *server_name,
7164 const char *environment)
7166 torture_assert(tctx,
7167 test_DeletePrinterDriver_exp(tctx, b, server_name, driver, "FOOBAR", WERR_INVALID_ENVIRONMENT),
7168 "failed to delete driver");
7170 torture_assert(tctx,
7171 test_DeletePrinterDriver_exp(tctx, b, server_name, driver, environment, WERR_OK),
7172 "failed to delete driver");
7174 if (test_EnumPrinterDrivers_findone(tctx, b, server_name, environment, 1, driver)) {
7175 torture_fail(tctx, "deleted driver still enumerated");
7178 torture_assert(tctx,
7179 test_DeletePrinterDriver_exp(tctx, b, server_name, driver, environment, WERR_UNKNOWN_PRINTER_DRIVER),
7180 "2nd delete failed");
7185 static bool test_DeletePrinterDriverEx(struct torture_context *tctx,
7186 struct dcerpc_binding_handle *b,
7187 const char *server_name,
7189 const char *environment,
7190 uint32_t delete_flags,
7193 torture_assert(tctx,
7194 test_DeletePrinterDriverEx_exp(tctx, b, server_name, driver, "FOOBAR", delete_flags, version, WERR_INVALID_ENVIRONMENT),
7195 "failed to delete driver");
7197 torture_assert(tctx,
7198 test_DeletePrinterDriverEx_exp(tctx, b, server_name, driver, environment, delete_flags, version, WERR_OK),
7199 "failed to delete driver");
7201 if (test_EnumPrinterDrivers_findone(tctx, b, server_name, environment, 1, driver)) {
7202 torture_fail(tctx, "deleted driver still enumerated");
7205 torture_assert(tctx,
7206 test_DeletePrinterDriverEx_exp(tctx, b, server_name, driver, environment, delete_flags, version, WERR_UNKNOWN_PRINTER_DRIVER),
7207 "2nd delete failed");
7212 static bool test_PrinterDriver_args(struct torture_context *tctx,
7213 struct dcerpc_binding_handle *b,
7214 const char *server_name,
7216 struct spoolss_AddDriverInfo8 *r,
7218 uint32_t delete_flags,
7219 uint32_t delete_version,
7226 ret = test_AddPrinterDriver_args_level_1(tctx, b, server_name, r, add_flags, ex);
7229 ret = test_AddPrinterDriver_args_level_2(tctx, b, server_name, r, add_flags, ex);
7232 ret = test_AddPrinterDriver_args_level_3(tctx, b, server_name, r, add_flags, ex);
7235 ret = test_AddPrinterDriver_args_level_4(tctx, b, server_name, r, add_flags, ex);
7238 ret = test_AddPrinterDriver_args_level_6(tctx, b, server_name, r, add_flags, ex);
7241 ret = test_AddPrinterDriver_args_level_8(tctx, b, server_name, r, add_flags, ex);
7255 /* spoolss_AddPrinterDriver does not deal with level 6 or 8 - gd */
7257 if (!ex && (level == 6 || level == 8)) {
7262 return test_DeletePrinterDriverEx(tctx, b, server_name, r->driver_name, r->architecture, delete_flags, r->version);
7264 return test_DeletePrinterDriver(tctx, b, server_name, r->driver_name, r->architecture);
7268 static bool fillup_printserver_info(struct torture_context *tctx,
7269 struct dcerpc_pipe *p,
7270 struct torture_driver_context *d)
7272 struct policy_handle server_handle;
7273 struct dcerpc_binding_handle *b = p->binding_handle;
7274 const char *server_name_slash = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
7276 torture_assert(tctx,
7277 test_OpenPrinter_server(tctx, p, &server_handle),
7278 "failed to open printserver");
7279 torture_assert(tctx,
7280 test_get_environment(tctx, b, &server_handle, &d->remote.environment),
7281 "failed to get environment");
7282 torture_assert(tctx,
7283 test_ClosePrinter(tctx, b, &server_handle),
7284 "failed to close printserver");
7286 torture_assert(tctx,
7287 test_GetPrinterDriverDirectory_getdir(tctx, b, server_name_slash,
7288 d->local.environment ? d->local.environment : d->remote.environment,
7289 &d->remote.driver_directory),
7290 "failed to get driver directory");
7295 static const char *driver_directory_dir(const char *driver_directory)
7299 p = strrchr(driver_directory, '\\');
7307 static const char *driver_directory_share(struct torture_context *tctx,
7308 const char *driver_directory)
7313 if (driver_directory[0] == '\\' && driver_directory[1] == '\\') {
7314 driver_directory += 2;
7317 p = talloc_strdup(tctx, driver_directory);
7319 torture_assert(tctx,
7320 next_token_talloc(tctx, &p, &tok, "\\"),
7321 "cannot explode uri");
7322 torture_assert(tctx,
7323 next_token_talloc(tctx, &p, &tok, "\\"),
7324 "cannot explode uri");
7329 static bool upload_printer_driver_file(struct torture_context *tctx,
7330 struct smbcli_state *cli,
7331 struct torture_driver_context *d,
7332 const char *file_name)
7337 int maxwrite = 64512;
7340 const char *remote_dir = driver_directory_dir(d->remote.driver_directory);
7341 const char *local_name = talloc_asprintf(tctx, "%s/%s", d->local.driver_directory, file_name);
7342 const char *remote_name = talloc_asprintf(tctx, "%s\\%s", remote_dir, file_name);
7348 torture_comment(tctx, "Uploading %s to %s\n", local_name, remote_name);
7350 fnum = smbcli_open(cli->tree, remote_name, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE);
7352 torture_fail(tctx, talloc_asprintf(tctx, "failed to open remote file: %s\n", remote_name));
7355 f = x_fopen(local_name, O_RDONLY, 0);
7357 torture_fail(tctx, talloc_asprintf(tctx, "failed to open local file: %s\n", local_name));
7360 buf = talloc_array(tctx, uint8_t, maxwrite);
7365 while (!x_feof(f)) {
7369 if ((n = x_fread(buf, 1, n, f)) < 1) {
7370 if((n == 0) && x_feof(f))
7371 break; /* Empty local file. */
7373 torture_warning(tctx,
7374 "failed to read file: %s\n", strerror(errno));
7378 ret = smbcli_write(cli->tree, fnum, 0, buf, nread + start, n);
7381 torture_warning(tctx,
7382 "failed to write file: %s\n", smbcli_errstr(cli->tree));
7391 torture_assert_ntstatus_ok(tctx,
7392 smbcli_close(cli->tree, fnum),
7393 "failed to close file");
7398 static bool connect_printer_driver_share(struct torture_context *tctx,
7399 const char *server_name,
7400 const char *share_name,
7401 struct smbcli_state **cli)
7403 struct smbcli_options smb_options;
7404 struct smbcli_session_options smb_session_options;
7406 torture_comment(tctx, "Connecting printer driver share '%s' on '%s'\n",
7407 share_name, server_name);
7409 lp_smbcli_options(tctx->lp_ctx, &smb_options);
7410 lp_smbcli_session_options(tctx->lp_ctx, &smb_session_options);
7412 torture_assert_ntstatus_ok(tctx,
7413 smbcli_full_connection(tctx, cli, server_name,
7414 lp_smb_ports(tctx->lp_ctx),
7416 lp_socket_options(tctx->lp_ctx),
7417 cmdline_credentials,
7418 lp_resolve_context(tctx->lp_ctx),
7421 &smb_session_options,
7422 lp_iconv_convenience(tctx->lp_ctx),
7423 lp_gensec_settings(tctx, tctx->lp_ctx)),
7424 "failed to open driver share");
7429 static bool upload_printer_driver(struct torture_context *tctx,
7430 const char *server_name,
7431 struct torture_driver_context *d)
7433 struct smbcli_state *cli;
7434 const char *share_name = driver_directory_share(tctx, d->remote.driver_directory);
7437 torture_assert(tctx,
7438 connect_printer_driver_share(tctx, server_name, share_name, &cli),
7439 "failed to connect to driver share");
7441 torture_comment(tctx, "Uploading printer driver files to \\\\%s\\%s\n",
7442 server_name, share_name);
7444 torture_assert(tctx,
7445 upload_printer_driver_file(tctx, cli, d, d->info8.driver_path),
7446 "failed to upload driver_path");
7447 torture_assert(tctx,
7448 upload_printer_driver_file(tctx, cli, d, d->info8.data_file),
7449 "failed to upload data_file");
7450 torture_assert(tctx,
7451 upload_printer_driver_file(tctx, cli, d, d->info8.config_file),
7452 "failed to upload config_file");
7453 torture_assert(tctx,
7454 upload_printer_driver_file(tctx, cli, d, d->info8.help_file),
7455 "failed to upload help_file");
7456 if (d->info8.dependent_files) {
7457 for (i=0; d->info8.dependent_files->string && d->info8.dependent_files->string[i] != NULL; i++) {
7458 torture_assert(tctx,
7459 upload_printer_driver_file(tctx, cli, d, d->info8.dependent_files->string[i]),
7460 "failed to upload dependent_files");
7469 static bool remove_printer_driver_file(struct torture_context *tctx,
7470 struct smbcli_state *cli,
7471 struct torture_driver_context *d,
7472 const char *file_name)
7474 const char *remote_name;
7475 const char *remote_dir = driver_directory_dir(d->remote.driver_directory);
7481 remote_name = talloc_asprintf(tctx, "%s\\%s", remote_dir, file_name);
7483 torture_comment(tctx, "Removing %s\n", remote_name);
7485 torture_assert_ntstatus_ok(tctx,
7486 smbcli_unlink(cli->tree, remote_name),
7487 "failed to unlink");
7492 static bool remove_printer_driver(struct torture_context *tctx,
7493 const char *server_name,
7494 struct torture_driver_context *d)
7496 struct smbcli_state *cli;
7497 const char *share_name = driver_directory_share(tctx, d->remote.driver_directory);
7500 torture_assert(tctx,
7501 connect_printer_driver_share(tctx, server_name, share_name, &cli),
7502 "failed to connect to driver share");
7504 torture_comment(tctx, "Removing printer driver files from \\\\%s\\%s\n",
7505 server_name, share_name);
7507 torture_assert(tctx,
7508 remove_printer_driver_file(tctx, cli, d, d->info8.driver_path),
7509 "failed to remove driver_path");
7510 torture_assert(tctx,
7511 remove_printer_driver_file(tctx, cli, d, d->info8.data_file),
7512 "failed to remove data_file");
7513 torture_assert(tctx,
7514 remove_printer_driver_file(tctx, cli, d, d->info8.config_file),
7515 "failed to remove config_file");
7516 torture_assert(tctx,
7517 remove_printer_driver_file(tctx, cli, d, d->info8.help_file),
7518 "failed to remove help_file");
7519 if (d->info8.dependent_files) {
7520 for (i=0; d->info8.dependent_files->string && d->info8.dependent_files->string[i] != NULL; i++) {
7521 if (strequal(d->info8.dependent_files->string[i], d->info8.driver_path) ||
7522 strequal(d->info8.dependent_files->string[i], d->info8.data_file) ||
7523 strequal(d->info8.dependent_files->string[i], d->info8.config_file) ||
7524 strequal(d->info8.dependent_files->string[i], d->info8.help_file)) {
7527 torture_assert(tctx,
7528 remove_printer_driver_file(tctx, cli, d, d->info8.dependent_files->string[i]),
7529 "failed to remove dependent_files");
7539 static bool test_add_driver_arg(struct torture_context *tctx,
7540 struct dcerpc_pipe *p,
7541 struct torture_driver_context *d)
7544 struct dcerpc_binding_handle *b = p->binding_handle;
7545 const char *server_name_slash = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
7546 uint32_t levels[] = { 1, 2, 3, 4, 6, 8 };
7548 struct spoolss_AddDriverInfo8 info8;
7549 uint32_t add_flags = APD_COPY_NEW_FILES;
7550 uint32_t delete_flags = 0;
7554 torture_comment(tctx, "Testing PrinterDriver%s '%s' for environment '%s'\n",
7555 d->ex ? "Ex" : "", d->info8.driver_name, d->local.environment);
7557 torture_assert(tctx,
7558 fillup_printserver_info(tctx, p, d),
7559 "failed to fillup printserver info");
7561 if (!directory_exist(d->local.driver_directory)) {
7562 torture_skip(tctx, "Skipping Printer Driver test as no local driver is available");
7565 torture_assert(tctx,
7566 upload_printer_driver(tctx, dcerpc_server_name(p), d),
7567 "failed to upload printer driver");
7569 info8.version = d->info8.version;
7570 info8.driver_name = d->info8.driver_name;
7571 info8.architecture = d->local.environment;
7572 info8.driver_path = d->info8.driver_path;
7573 info8.data_file = d->info8.data_file;
7574 info8.config_file = d->info8.config_file;
7576 for (i=0; i < ARRAY_SIZE(levels); i++) {
7578 if (torture_setting_bool(tctx, "samba3", false)) {
7579 switch (levels[i]) {
7583 torture_comment(tctx, "skipping level %d against samba\n", levels[i]);
7590 torture_comment(tctx,
7591 "Testing PrinterDriver%s '%s' add & delete level %d\n",
7592 d->ex ? "Ex" : "", info8.driver_name, levels[i]);
7594 ret &= test_PrinterDriver_args(tctx, b, server_name_slash, levels[i], &info8, add_flags, delete_flags, d->info8.version, d->ex);
7597 info8.driver_path = talloc_asprintf(tctx, "%s\\%s", d->remote.driver_directory, d->info8.driver_path);
7598 info8.data_file = talloc_asprintf(tctx, "%s\\%s", d->remote.driver_directory, d->info8.data_file);
7599 info8.config_file = talloc_asprintf(tctx, "%s\\%s", d->remote.driver_directory, d->info8.config_file);
7601 for (i=0; i < ARRAY_SIZE(levels); i++) {
7603 if (torture_setting_bool(tctx, "samba3", false)) {
7604 switch (levels[i]) {
7608 torture_comment(tctx, "skipping level %d against samba\n", levels[i]);
7616 torture_comment(tctx,
7617 "Testing PrinterDriver%s '%s' add & delete level %d (full unc paths)\n",
7618 d->ex ? "Ex" : "", info8.driver_name, levels[i]);
7620 ret &= test_PrinterDriver_args(tctx, b, server_name_slash, levels[i], &info8, add_flags, delete_flags, d->info8.version, d->ex);
7623 torture_assert(tctx,
7624 remove_printer_driver(tctx, dcerpc_server_name(p), d),
7625 "failed to remove printer driver");
7627 torture_comment(tctx, "\n");
7632 static bool test_add_driver_ex_64(struct torture_context *tctx,
7633 struct dcerpc_pipe *p,
7636 struct torture_driver_context *d =
7637 (struct torture_driver_context *)talloc_get_type_abort(private_data, struct torture_driver_context);
7639 d->local.environment = talloc_strdup(d, "Windows x64");
7640 d->local.driver_directory = talloc_strdup(d, "/usr/share/cups/drivers/x64");
7641 d->info8.driver_name = TORTURE_DRIVER_EX;
7644 return test_add_driver_arg(tctx, p, d);
7647 static bool test_add_driver_ex_32(struct torture_context *tctx,
7648 struct dcerpc_pipe *p,
7651 struct torture_driver_context *d =
7652 (struct torture_driver_context *)talloc_get_type_abort(private_data, struct torture_driver_context);
7654 d->local.environment = talloc_strdup(d, "Windows NT x86");
7655 d->local.driver_directory = talloc_strdup(d, "/usr/share/cups/drivers/i386");
7656 d->info8.driver_name = TORTURE_DRIVER_EX;
7659 return test_add_driver_arg(tctx, p, d);
7662 static bool test_add_driver_64(struct torture_context *tctx,
7663 struct dcerpc_pipe *p,
7666 struct torture_driver_context *d =
7667 (struct torture_driver_context *)talloc_get_type_abort(private_data, struct torture_driver_context);
7669 d->local.environment = talloc_strdup(d, "Windows x64");
7670 d->local.driver_directory = talloc_strdup(d, "/usr/share/cups/drivers/x64");
7671 d->info8.driver_name = TORTURE_DRIVER;
7674 return test_add_driver_arg(tctx, p, d);
7677 static bool test_add_driver_32(struct torture_context *tctx,
7678 struct dcerpc_pipe *p,
7681 struct torture_driver_context *d =
7682 (struct torture_driver_context *)talloc_get_type_abort(private_data, struct torture_driver_context);
7684 d->local.environment = talloc_strdup(d, "Windows NT x86");
7685 d->local.driver_directory = talloc_strdup(d, "/usr/share/cups/drivers/i386");
7686 d->info8.driver_name = TORTURE_DRIVER;
7689 return test_add_driver_arg(tctx, p, d);
7692 struct torture_suite *torture_rpc_spoolss_driver(TALLOC_CTX *mem_ctx)
7694 struct torture_suite *suite = torture_suite_create(mem_ctx, "SPOOLSS-DRIVER");
7696 struct torture_rpc_tcase *tcase = torture_suite_add_rpc_iface_tcase(suite,
7697 "driver", &ndr_table_spoolss);
7698 struct torture_driver_context *t;
7700 t = talloc_zero(mem_ctx, struct torture_driver_context);
7702 t->info8.version = SPOOLSS_DRIVER_VERSION_200X;
7703 t->info8.driver_name = NULL;
7704 t->info8.architecture = NULL;
7705 t->info8.driver_path = talloc_strdup(t, "pscript5.dll");
7706 t->info8.data_file = talloc_strdup(t, "cups6.ppd");
7707 t->info8.config_file = talloc_strdup(t, "cupsui6.dll");
7709 torture_rpc_tcase_add_test_ex(tcase, "add_driver_64", test_add_driver_64, t);
7710 torture_rpc_tcase_add_test_ex(tcase, "add_driver_ex_64", test_add_driver_ex_64, t);
7712 torture_rpc_tcase_add_test_ex(tcase, "add_driver_32", test_add_driver_32, t);
7713 torture_rpc_tcase_add_test_ex(tcase, "add_driver_ex_32", test_add_driver_ex_32, t);