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-2011,2013
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 "libcli/smb2/smb2.h"
39 #include "libcli/smb2/smb2_calls.h"
40 #include "lib/cmdline/popt_common.h"
41 #include "system/filesys.h"
42 #include "torture/ndr/ndr.h"
43 #include "torture/smb2/proto.h"
45 #define TORTURE_WELLKNOWN_PRINTER "torture_wkn_printer"
46 #define TORTURE_PRINTER "torture_printer"
47 #define TORTURE_WELLKNOWN_PRINTER_EX "torture_wkn_printer_ex"
48 #define TORTURE_PRINTER_EX "torture_printer_ex"
49 #define TORTURE_DRIVER "torture_driver"
50 #define TORTURE_DRIVER_EX "torture_driver_ex"
51 #define TORTURE_DRIVER_ADOBE "torture_driver_adobe"
52 #define TORTURE_DRIVER_EX_ADOBE "torture_driver_ex_adobe"
53 #define TORTURE_DRIVER_ADOBE_CUPSADDSMB "torture_driver_adobe_cupsaddsmb"
54 #define TORTURE_DRIVER_TIMESTAMPS "torture_driver_timestamps"
55 #define TORTURE_DRIVER_DELETER "torture_driver_deleter"
56 #define TORTURE_DRIVER_DELETERIN "torture_driver_deleterin"
57 #define TORTURE_PRINTER_STATIC1 "print1"
59 #define TOP_LEVEL_PRINT_KEY "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print"
60 #define TOP_LEVEL_PRINT_PRINTERS_KEY TOP_LEVEL_PRINT_KEY "\\Printers"
61 #define TOP_LEVEL_CONTROL_KEY "SYSTEM\\CurrentControlSet\\Control\\Print"
62 #define TOP_LEVEL_CONTROL_FORMS_KEY TOP_LEVEL_CONTROL_KEY "\\Forms"
63 #define TOP_LEVEL_CONTROL_PRINTERS_KEY TOP_LEVEL_CONTROL_KEY "\\Printers"
64 #define TOP_LEVEL_CONTROL_ENVIRONMENTS_KEY TOP_LEVEL_CONTROL_KEY "\\Environments"
66 struct test_spoolss_context {
67 struct dcerpc_pipe *spoolss_pipe;
69 /* server environment */
70 const char *environment;
72 /* print server handle */
73 struct policy_handle server_handle;
76 uint32_t port_count[3];
77 union spoolss_PortInfo *ports[3];
79 /* for EnumPrinterDrivers */
80 uint32_t driver_count[9];
81 union spoolss_DriverInfo *drivers[9];
83 /* for EnumMonitors */
84 uint32_t monitor_count[3];
85 union spoolss_MonitorInfo *monitors[3];
87 /* for EnumPrintProcessors */
88 uint32_t print_processor_count[2];
89 union spoolss_PrintProcessorInfo *print_processors[2];
91 /* for EnumPrinters */
92 uint32_t printer_count[6];
93 union spoolss_PrinterInfo *printers[6];
96 struct torture_driver_context {
98 const char *driver_directory;
99 const char *environment;
102 const char *driver_directory;
103 const char *environment;
105 struct spoolss_AddDriverInfo8 info8;
109 struct torture_printer_context {
110 struct dcerpc_pipe *spoolss_pipe;
111 struct spoolss_SetPrinterInfo2 info2;
112 struct torture_driver_context driver;
117 struct spoolss_DeviceMode *devmode;
118 struct policy_handle handle;
121 static bool upload_printer_driver(struct torture_context *tctx,
122 const char *server_name,
123 struct torture_driver_context *d);
124 static bool remove_printer_driver(struct torture_context *tctx,
125 const char *server_name,
126 struct torture_driver_context *d);
127 static bool fillup_printserver_info(struct torture_context *tctx,
128 struct dcerpc_pipe *p,
129 struct torture_driver_context *d);
130 static bool test_AddPrinterDriver_args_level_3(struct torture_context *tctx,
131 struct dcerpc_binding_handle *b,
132 const char *server_name,
133 struct spoolss_AddDriverInfo8 *r,
136 const char *remote_driver_dir);
138 #define COMPARE_STRING(tctx, c,r,e) \
139 torture_assert_str_equal(tctx, c.e, r.e, "invalid value")
141 /* not every compiler supports __typeof__() */
143 #define _CHECK_FIELD_SIZE(c,r,e,type) do {\
144 if (sizeof(__typeof__(c.e)) != sizeof(type)) { \
145 torture_fail(tctx, #c "." #e "field is not " #type "\n"); \
147 if (sizeof(__typeof__(r.e)) != sizeof(type)) { \
148 torture_fail(tctx, #r "." #e "field is not " #type "\n"); \
152 #define _CHECK_FIELD_SIZE(c,r,e,type) do {} while(0)
155 #define COMPARE_UINT32(tctx, c, r, e) do {\
156 _CHECK_FIELD_SIZE(c, r, e, uint32_t); \
157 torture_assert_int_equal(tctx, c.e, r.e, "invalid value"); \
160 #define COMPARE_UINT64(tctx, c, r, e) do {\
161 _CHECK_FIELD_SIZE(c, r, e, uint64_t); \
162 torture_assert_int_equal(tctx, c.e, r.e, "invalid value"); \
166 #define COMPARE_NTTIME(tctx, c, r, e) do {\
167 _CHECK_FIELD_SIZE(c, r, e, NTTIME); \
168 torture_assert_int_equal(tctx, c.e, r.e, "invalid value"); \
171 #define COMPARE_STRING_ARRAY(tctx, c,r,e) do {\
173 if (!c.e && !r.e) { \
177 torture_fail(tctx, #r "." #e " field is NULL and " #c "." #e " is not\n"); \
180 torture_fail(tctx, #c "." #e " field is NULL and " #r "." #e " is not\n"); \
182 for (__i=0;c.e[__i] != NULL; __i++) { \
183 torture_assert_str_equal(tctx, c.e[__i], r.e[__i], "invalid value"); \
187 #define CHECK_ALIGN(size, n) do {\
189 torture_warning(tctx, "%d is *NOT* %d byte aligned, should be %d",\
190 size, n, size + n - (size % n));\
194 #define DO_ROUND(size, n) (((size)+((n)-1)) & ~((n)-1))
196 #define CHECK_NEEDED_SIZE_ENUM_LEVEL(fn, info, level, count, needed, align) do { \
197 if (torture_setting_bool(tctx, "spoolss_check_size", false)) {\
198 uint32_t size = ndr_size_##fn##_info(tctx, level, count, info);\
199 uint32_t round_size = DO_ROUND(size, align);\
200 if (round_size != needed) {\
201 torture_warning(tctx, __location__": "#fn" level %d (count: %d) got unexpected needed size: %d, we calculated: %d", level, count, needed, round_size);\
202 CHECK_ALIGN(size, align);\
207 #define CHECK_NEEDED_SIZE_ENUM(fn, info, count, needed, align) do { \
208 if (torture_setting_bool(tctx, "spoolss_check_size", false)) {\
209 uint32_t size = ndr_size_##fn##_info(tctx, count, info);\
210 uint32_t round_size = DO_ROUND(size, align);\
211 if (round_size != needed) {\
212 torture_warning(tctx, __location__": "#fn" (count: %d) got unexpected needed size: %d, we calculated: %d", count, needed, round_size);\
213 CHECK_ALIGN(size, align);\
218 #define CHECK_NEEDED_SIZE_LEVEL(fn, info, level, needed, align) do { \
219 if (torture_setting_bool(tctx, "spoolss_check_size", false)) {\
220 uint32_t size = ndr_size_##fn(info, level, 0);\
221 uint32_t round_size = DO_ROUND(size, align);\
222 if (round_size != needed) {\
223 torture_warning(tctx, __location__": "#fn" level %d got unexpected needed size: %d, we calculated: %d", level, needed, round_size);\
224 CHECK_ALIGN(size, align);\
229 static bool PrinterInfo_to_SetPrinterInfo(struct torture_context *tctx,
230 const union spoolss_PrinterInfo *i,
232 union spoolss_SetPrinterInfo *s)
236 s->info0 = talloc(tctx, struct spoolss_SetPrinterInfo0);
239 s->info2 = talloc(tctx, struct spoolss_SetPrinterInfo2);
240 s->info2->servername = i->info2.servername;
241 s->info2->printername = i->info2.printername;
242 s->info2->sharename = i->info2.sharename;
243 s->info2->portname = i->info2.portname;
244 s->info2->drivername = i->info2.drivername;
245 s->info2->comment = i->info2.comment;
246 s->info2->location = i->info2.location;
247 s->info2->devmode_ptr = NULL;
248 s->info2->sepfile = i->info2.sepfile;
249 s->info2->printprocessor = i->info2.printprocessor;
250 s->info2->datatype = i->info2.datatype;
251 s->info2->parameters = i->info2.parameters;
252 s->info2->secdesc_ptr = NULL;
253 s->info2->attributes = i->info2.attributes;
254 s->info2->priority = i->info2.priority;
255 s->info2->defaultpriority = i->info2.defaultpriority;
256 s->info2->starttime = i->info2.starttime;
257 s->info2->untiltime = i->info2.untiltime;
258 s->info2->status = i->info2.status;
259 s->info2->cjobs = i->info2.cjobs;
260 s->info2->averageppm = i->info2.averageppm;
276 static bool test_OpenPrinter_server(struct torture_context *tctx,
277 struct dcerpc_pipe *p,
278 struct policy_handle *server_handle)
281 struct spoolss_OpenPrinter op;
282 struct dcerpc_binding_handle *b = p->binding_handle;
284 op.in.printername = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
285 op.in.datatype = NULL;
286 op.in.devmode_ctr.devmode= NULL;
287 op.in.access_mask = 0;
288 op.out.handle = server_handle;
290 torture_comment(tctx, "Testing OpenPrinter(%s)\n", op.in.printername);
292 status = dcerpc_spoolss_OpenPrinter_r(b, tctx, &op);
293 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_OpenPrinter failed");
294 torture_assert_werr_ok(tctx, op.out.result, "dcerpc_spoolss_OpenPrinter failed");
299 static bool test_EnumPorts(struct torture_context *tctx,
302 struct test_spoolss_context *ctx =
303 talloc_get_type_abort(private_data, struct test_spoolss_context);
304 struct dcerpc_pipe *p = ctx->spoolss_pipe;
305 struct dcerpc_binding_handle *b = p->binding_handle;
307 struct spoolss_EnumPorts r;
308 uint16_t levels[] = { 1, 2 };
311 for (i=0;i<ARRAY_SIZE(levels);i++) {
312 int level = levels[i];
316 union spoolss_PortInfo *info;
318 r.in.servername = "";
322 r.out.needed = &needed;
323 r.out.count = &count;
326 torture_comment(tctx, "Testing EnumPorts level %u\n", r.in.level);
328 status = dcerpc_spoolss_EnumPorts_r(b, ctx, &r);
329 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPorts failed");
330 if (W_ERROR_IS_OK(r.out.result)) {
331 /* TODO: do some more checks here */
334 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
335 "EnumPorts unexpected return code");
337 blob = data_blob_talloc_zero(ctx, needed);
339 r.in.offered = needed;
341 status = dcerpc_spoolss_EnumPorts_r(b, ctx, &r);
342 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPorts failed");
344 torture_assert_werr_ok(tctx, r.out.result, "EnumPorts failed");
346 torture_assert(tctx, info, "EnumPorts returned no info");
348 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPorts, info, r.in.level, count, needed, 4);
350 ctx->port_count[level] = count;
351 ctx->ports[level] = info;
354 for (i=1;i<ARRAY_SIZE(levels);i++) {
355 int level = levels[i];
356 int old_level = levels[i-1];
357 torture_assert_int_equal(tctx, ctx->port_count[level], ctx->port_count[old_level],
358 "EnumPorts invalid value");
360 /* if the array sizes are not the same we would maybe segfault in the following code */
362 for (i=0;i<ARRAY_SIZE(levels);i++) {
363 int level = levels[i];
364 for (j=0;j<ctx->port_count[level];j++) {
365 union spoolss_PortInfo *cur = &ctx->ports[level][j];
366 union spoolss_PortInfo *ref = &ctx->ports[2][j];
369 COMPARE_STRING(tctx, cur->info1, ref->info2, port_name);
372 /* level 2 is our reference, and it makes no sense to compare it to itself */
381 static bool test_GetPrintProcessorDirectory(struct torture_context *tctx,
384 struct test_spoolss_context *ctx =
385 talloc_get_type_abort(private_data, struct test_spoolss_context);
388 struct dcerpc_pipe *p = ctx->spoolss_pipe;
389 struct dcerpc_binding_handle *b = p->binding_handle;
390 struct spoolss_GetPrintProcessorDirectory r;
405 .server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p))
408 .server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p))
414 for (i=0;i<ARRAY_SIZE(levels);i++) {
415 int level = levels[i].level;
418 r.in.server = levels[i].server;
419 r.in.environment = ctx->environment;
423 r.out.needed = &needed;
425 torture_comment(tctx, "Testing GetPrintProcessorDirectory level %u\n", r.in.level);
427 status = dcerpc_spoolss_GetPrintProcessorDirectory_r(b, tctx, &r);
428 torture_assert_ntstatus_ok(tctx, status,
429 "dcerpc_spoolss_GetPrintProcessorDirectory failed");
430 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
431 "GetPrintProcessorDirectory unexpected return code");
433 blob = data_blob_talloc_zero(tctx, needed);
435 r.in.offered = needed;
437 status = dcerpc_spoolss_GetPrintProcessorDirectory_r(b, tctx, &r);
438 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_GetPrintProcessorDirectory failed");
440 torture_assert_werr_ok(tctx, r.out.result, "GetPrintProcessorDirectory failed");
442 CHECK_NEEDED_SIZE_LEVEL(spoolss_PrintProcessorDirectoryInfo, r.out.info, r.in.level, needed, 2);
449 static bool test_GetPrinterDriverDirectory(struct torture_context *tctx,
452 struct test_spoolss_context *ctx =
453 talloc_get_type_abort(private_data, struct test_spoolss_context);
456 struct dcerpc_pipe *p = ctx->spoolss_pipe;
457 struct dcerpc_binding_handle *b = p->binding_handle;
458 struct spoolss_GetPrinterDriverDirectory r;
473 .server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p))
476 .server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p))
482 for (i=0;i<ARRAY_SIZE(levels);i++) {
483 int level = levels[i].level;
486 r.in.server = levels[i].server;
487 r.in.environment = ctx->environment;
491 r.out.needed = &needed;
493 torture_comment(tctx, "Testing GetPrinterDriverDirectory level %u\n", r.in.level);
495 status = dcerpc_spoolss_GetPrinterDriverDirectory_r(b, tctx, &r);
496 torture_assert_ntstatus_ok(tctx, status,
497 "dcerpc_spoolss_GetPrinterDriverDirectory failed");
498 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
499 "GetPrinterDriverDirectory unexpected return code");
501 blob = data_blob_talloc_zero(tctx, needed);
503 r.in.offered = needed;
505 status = dcerpc_spoolss_GetPrinterDriverDirectory_r(b, tctx, &r);
506 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_GetPrinterDriverDirectory failed");
508 torture_assert_werr_ok(tctx, r.out.result, "GetPrinterDriverDirectory failed");
510 CHECK_NEEDED_SIZE_LEVEL(spoolss_DriverDirectoryInfo, r.out.info, r.in.level, needed, 2);
516 static bool test_EnumPrinterDrivers_buffers(struct torture_context *tctx,
517 struct dcerpc_binding_handle *b,
518 const char *server_name,
519 const char *environment,
523 union spoolss_DriverInfo **info_p)
525 struct spoolss_EnumPrinterDrivers r;
528 union spoolss_DriverInfo *info;
532 buffer = data_blob_talloc_zero(tctx, offered);
535 r.in.server = server_name;
536 r.in.environment = environment;
538 r.in.buffer = offered ? &buffer : NULL;
539 r.in.offered = offered;
540 r.out.needed = &needed;
541 r.out.count = &count;
544 torture_comment(tctx, "Testing EnumPrinterDrivers(%s) level %u, offered: %u\n",
545 r.in.environment, r.in.level, r.in.offered);
547 torture_assert_ntstatus_ok(tctx,
548 dcerpc_spoolss_EnumPrinterDrivers_r(b, tctx, &r),
549 "EnumPrinterDrivers failed");
550 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
551 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
553 r.in.offered = needed;
555 torture_assert_ntstatus_ok(tctx,
556 dcerpc_spoolss_EnumPrinterDrivers_r(b, tctx, &r),
557 "EnumPrinterDrivers failed");
560 torture_assert_werr_ok(tctx, r.out.result,
561 "EnumPrinterDrivers failed");
570 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPrinterDrivers, info, r.in.level, count, needed, 4);
577 static bool test_EnumPrinterDrivers_args(struct torture_context *tctx,
578 struct dcerpc_binding_handle *b,
579 const char *server_name,
580 const char *environment,
583 union spoolss_DriverInfo **info_p)
585 return test_EnumPrinterDrivers_buffers(tctx, b, server_name,
586 environment, level, 0,
590 static bool test_EnumPrinterDrivers_findone(struct torture_context *tctx,
591 struct dcerpc_binding_handle *b,
592 const char *server_name,
593 const char *environment,
595 const char *driver_name,
596 union spoolss_DriverInfo *info_p)
599 union spoolss_DriverInfo *info;
601 const char *environment_ret = NULL;
604 test_EnumPrinterDrivers_args(tctx, b, server_name, environment, level, &count, &info),
605 "failed to enumerate printer drivers");
607 for (i=0; i < count; i++) {
608 const char *driver_name_ret = "";
611 driver_name_ret = info[i].info1.driver_name;
614 driver_name_ret = info[i].info2.driver_name;
615 environment_ret = info[i].info2.architecture;
618 driver_name_ret = info[i].info3.driver_name;
619 environment_ret = info[i].info3.architecture;
622 driver_name_ret = info[i].info4.driver_name;
623 environment_ret = info[i].info4.architecture;
626 driver_name_ret = info[i].info5.driver_name;
627 environment_ret = info[i].info5.architecture;
630 driver_name_ret = info[i].info6.driver_name;
631 environment_ret = info[i].info6.architecture;
634 driver_name_ret = info[i].info7.driver_name;
637 driver_name_ret = info[i].info8.driver_name;
638 environment_ret = info[i].info8.architecture;
643 if (environment_ret) {
644 torture_assert_str_equal(tctx, environment, environment_ret, "architecture mismatch");
646 if (strequal(driver_name, driver_name_ret)) {
657 static bool test_EnumPrinterDrivers(struct torture_context *tctx,
660 struct test_spoolss_context *ctx =
661 talloc_get_type_abort(private_data, struct test_spoolss_context);
662 struct dcerpc_pipe *p = ctx->spoolss_pipe;
663 struct dcerpc_binding_handle *b = p->binding_handle;
664 uint16_t levels[] = { 1, 2, 3, 4, 5, 6, 8 };
667 /* FIXME: gd, come back and fix "" as server, and handle
668 * priority of returned error codes in torture test and samba 3
670 const char *server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
671 const char *environments[2];
673 environments[0] = SPOOLSS_ARCHITECTURE_ALL;
674 environments[1] = ctx->environment;
676 for (a=0;a<ARRAY_SIZE(environments);a++) {
678 for (i=0;i<ARRAY_SIZE(levels);i++) {
679 int level = levels[i];
681 union spoolss_DriverInfo *info;
684 test_EnumPrinterDrivers_args(tctx, b, server_name, environments[a], level, &count, &info),
685 "failed to enumerate drivers");
687 ctx->driver_count[level] = count;
688 ctx->drivers[level] = info;
691 for (i=1;i<ARRAY_SIZE(levels);i++) {
692 int level = levels[i];
693 int old_level = levels[i-1];
695 torture_assert_int_equal(tctx, ctx->driver_count[level], ctx->driver_count[old_level],
696 "EnumPrinterDrivers invalid value");
699 for (i=0;i<ARRAY_SIZE(levels);i++) {
700 int level = levels[i];
702 for (j=0;j<ctx->driver_count[level - 1];j++) {
703 union spoolss_DriverInfo *cur = &ctx->drivers[level - 1][j];
704 union spoolss_DriverInfo *ref = &ctx->drivers[7][j];
708 COMPARE_STRING(tctx, cur->info1, ref->info8, driver_name);
711 COMPARE_UINT32(tctx, cur->info2, ref->info8, version);
712 COMPARE_STRING(tctx, cur->info2, ref->info8, driver_name);
713 COMPARE_STRING(tctx, cur->info2, ref->info8, architecture);
714 COMPARE_STRING(tctx, cur->info2, ref->info8, driver_path);
715 COMPARE_STRING(tctx, cur->info2, ref->info8, data_file);
716 COMPARE_STRING(tctx, cur->info2, ref->info8, config_file);
719 COMPARE_UINT32(tctx, cur->info3, ref->info8, version);
720 COMPARE_STRING(tctx, cur->info3, ref->info8, driver_name);
721 COMPARE_STRING(tctx, cur->info3, ref->info8, architecture);
722 COMPARE_STRING(tctx, cur->info3, ref->info8, driver_path);
723 COMPARE_STRING(tctx, cur->info3, ref->info8, data_file);
724 COMPARE_STRING(tctx, cur->info3, ref->info8, config_file);
725 COMPARE_STRING(tctx, cur->info3, ref->info8, help_file);
726 COMPARE_STRING_ARRAY(tctx, cur->info3, ref->info8, dependent_files);
727 COMPARE_STRING(tctx, cur->info3, ref->info8, monitor_name);
728 COMPARE_STRING(tctx, cur->info3, ref->info8, default_datatype);
731 COMPARE_UINT32(tctx, cur->info4, ref->info8, version);
732 COMPARE_STRING(tctx, cur->info4, ref->info8, driver_name);
733 COMPARE_STRING(tctx, cur->info4, ref->info8, architecture);
734 COMPARE_STRING(tctx, cur->info4, ref->info8, driver_path);
735 COMPARE_STRING(tctx, cur->info4, ref->info8, data_file);
736 COMPARE_STRING(tctx, cur->info4, ref->info8, config_file);
737 COMPARE_STRING(tctx, cur->info4, ref->info8, help_file);
738 COMPARE_STRING_ARRAY(tctx, cur->info4, ref->info8, dependent_files);
739 COMPARE_STRING(tctx, cur->info4, ref->info8, monitor_name);
740 COMPARE_STRING(tctx, cur->info4, ref->info8, default_datatype);
741 COMPARE_STRING_ARRAY(tctx, cur->info4, ref->info8, previous_names);
744 COMPARE_UINT32(tctx, cur->info5, ref->info8, version);
745 COMPARE_STRING(tctx, cur->info5, ref->info8, driver_name);
746 COMPARE_STRING(tctx, cur->info5, ref->info8, architecture);
747 COMPARE_STRING(tctx, cur->info5, ref->info8, driver_path);
748 COMPARE_STRING(tctx, cur->info5, ref->info8, data_file);
749 COMPARE_STRING(tctx, cur->info5, ref->info8, config_file);
750 /*COMPARE_UINT32(tctx, cur->info5, ref->info8, driver_attributes);*/
751 /*COMPARE_UINT32(tctx, cur->info5, ref->info8, config_version);*/
752 /*TODO: ! COMPARE_UINT32(tctx, cur->info5, ref->info8, driver_version); */
755 COMPARE_UINT32(tctx, cur->info6, ref->info8, version);
756 COMPARE_STRING(tctx, cur->info6, ref->info8, driver_name);
757 COMPARE_STRING(tctx, cur->info6, ref->info8, architecture);
758 COMPARE_STRING(tctx, cur->info6, ref->info8, driver_path);
759 COMPARE_STRING(tctx, cur->info6, ref->info8, data_file);
760 COMPARE_STRING(tctx, cur->info6, ref->info8, config_file);
761 COMPARE_STRING(tctx, cur->info6, ref->info8, help_file);
762 COMPARE_STRING_ARRAY(tctx, cur->info6, ref->info8, dependent_files);
763 COMPARE_STRING(tctx, cur->info6, ref->info8, monitor_name);
764 COMPARE_STRING(tctx, cur->info6, ref->info8, default_datatype);
765 COMPARE_STRING_ARRAY(tctx, cur->info6, ref->info8, previous_names);
766 COMPARE_NTTIME(tctx, cur->info6, ref->info8, driver_date);
767 COMPARE_UINT64(tctx, cur->info6, ref->info8, driver_version);
768 COMPARE_STRING(tctx, cur->info6, ref->info8, manufacturer_name);
769 COMPARE_STRING(tctx, cur->info6, ref->info8, manufacturer_url);
770 COMPARE_STRING(tctx, cur->info6, ref->info8, hardware_id);
771 COMPARE_STRING(tctx, cur->info6, ref->info8, provider);
774 /* level 8 is our reference, and it makes no sense to compare it to itself */
784 static bool test_EnumMonitors(struct torture_context *tctx,
787 struct test_spoolss_context *ctx =
788 talloc_get_type_abort(private_data, struct test_spoolss_context);
789 struct dcerpc_pipe *p = ctx->spoolss_pipe;
790 struct dcerpc_binding_handle *b = p->binding_handle;
792 struct spoolss_EnumMonitors r;
793 uint16_t levels[] = { 1, 2 };
796 for (i=0;i<ARRAY_SIZE(levels);i++) {
797 int level = levels[i];
801 union spoolss_MonitorInfo *info;
803 r.in.servername = "";
807 r.out.needed = &needed;
808 r.out.count = &count;
811 torture_comment(tctx, "Testing EnumMonitors level %u\n", r.in.level);
813 status = dcerpc_spoolss_EnumMonitors_r(b, ctx, &r);
814 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumMonitors failed");
815 if (W_ERROR_IS_OK(r.out.result)) {
816 /* TODO: do some more checks here */
819 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
820 "EnumMonitors failed");
822 blob = data_blob_talloc_zero(ctx, needed);
824 r.in.offered = needed;
826 status = dcerpc_spoolss_EnumMonitors_r(b, ctx, &r);
827 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumMonitors failed");
829 torture_assert_werr_ok(tctx, r.out.result, "EnumMonitors failed");
831 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumMonitors, info, r.in.level, count, needed, 4);
833 ctx->monitor_count[level] = count;
834 ctx->monitors[level] = info;
837 for (i=1;i<ARRAY_SIZE(levels);i++) {
838 int level = levels[i];
839 int old_level = levels[i-1];
840 torture_assert_int_equal(tctx, ctx->monitor_count[level], ctx->monitor_count[old_level],
841 "EnumMonitors invalid value");
844 for (i=0;i<ARRAY_SIZE(levels);i++) {
845 int level = levels[i];
846 for (j=0;j<ctx->monitor_count[level];j++) {
847 union spoolss_MonitorInfo *cur = &ctx->monitors[level][j];
848 union spoolss_MonitorInfo *ref = &ctx->monitors[2][j];
851 COMPARE_STRING(tctx, cur->info1, ref->info2, monitor_name);
854 /* level 2 is our reference, and it makes no sense to compare it to itself */
863 static bool test_EnumPrintProcessors_level(struct torture_context *tctx,
864 struct dcerpc_binding_handle *b,
865 const char *environment,
868 union spoolss_PrintProcessorInfo **info_p,
869 WERROR expected_result)
871 struct spoolss_EnumPrintProcessors r;
875 union spoolss_PrintProcessorInfo *info;
877 r.in.servername = "";
878 r.in.environment = environment;
882 r.out.needed = &needed;
883 r.out.count = &count;
886 torture_comment(tctx, "Testing EnumPrintProcessors(%s) level %u\n",
887 r.in.environment, r.in.level);
889 torture_assert_ntstatus_ok(tctx,
890 dcerpc_spoolss_EnumPrintProcessors_r(b, tctx, &r),
891 "EnumPrintProcessors failed");
892 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
893 blob = data_blob_talloc_zero(tctx, needed);
895 r.in.offered = needed;
896 torture_assert_ntstatus_ok(tctx,
897 dcerpc_spoolss_EnumPrintProcessors_r(b, tctx, &r),
898 "EnumPrintProcessors failed");
900 torture_assert_werr_equal(tctx, r.out.result, expected_result,
901 "EnumPrintProcessors failed");
903 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPrintProcessors, info, level, count, needed, 4);
915 static bool test_EnumPrintProcessors(struct torture_context *tctx,
918 struct test_spoolss_context *ctx =
919 talloc_get_type_abort(private_data, struct test_spoolss_context);
921 uint16_t levels[] = {0, 1, 2, 3, 32, 256 };
922 uint16_t ok[] = {0, 1, 0, 0, 0, 0 };
924 struct dcerpc_pipe *p = ctx->spoolss_pipe;
925 struct dcerpc_binding_handle *b = p->binding_handle;
928 test_EnumPrintProcessors_level(tctx, b, "phantasy", 1, NULL, NULL, WERR_INVALID_ENVIRONMENT),
929 "test_EnumPrintProcessors_level failed");
931 for (i=0;i<ARRAY_SIZE(levels);i++) {
932 union spoolss_PrintProcessorInfo *info;
934 WERROR expected_result = ok[i] ? WERR_OK : WERR_INVALID_LEVEL;
937 test_EnumPrintProcessors_level(tctx, b, ctx->environment, levels[i], &count, &info, expected_result),
938 "test_EnumPrintProcessors_level failed");
944 static bool test_EnumPrintProcDataTypes_level(struct torture_context *tctx,
945 struct dcerpc_binding_handle *b,
946 const char *print_processor_name,
949 union spoolss_PrintProcDataTypesInfo **info_p,
950 WERROR expected_result)
952 struct spoolss_EnumPrintProcDataTypes r;
956 union spoolss_PrintProcDataTypesInfo *info;
958 r.in.servername = "";
959 r.in.print_processor_name = print_processor_name;
963 r.out.needed = &needed;
964 r.out.count = &count;
967 torture_comment(tctx, "Testing EnumPrintProcDataTypes(%s) level %u\n",
968 r.in.print_processor_name, r.in.level);
970 torture_assert_ntstatus_ok(tctx,
971 dcerpc_spoolss_EnumPrintProcDataTypes_r(b, tctx, &r),
972 "EnumPrintProcDataTypes failed");
973 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
974 blob = data_blob_talloc_zero(tctx, needed);
976 r.in.offered = needed;
977 torture_assert_ntstatus_ok(tctx,
978 dcerpc_spoolss_EnumPrintProcDataTypes_r(b, tctx, &r),
979 "EnumPrintProcDataTypes failed");
981 torture_assert_werr_equal(tctx, r.out.result, expected_result,
982 "EnumPrintProcDataTypes failed");
984 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPrintProcDataTypes, info, level, count, needed, 4);
996 static bool test_EnumPrintProcDataTypes(struct torture_context *tctx,
999 struct test_spoolss_context *ctx =
1000 talloc_get_type_abort(private_data, struct test_spoolss_context);
1002 uint16_t levels[] = {0, 1, 2, 3, 32, 256 };
1003 uint16_t ok[] = {0, 1, 0, 0, 0, 0 };
1005 struct dcerpc_pipe *p = ctx->spoolss_pipe;
1006 struct dcerpc_binding_handle *b = p->binding_handle;
1008 torture_assert(tctx,
1009 test_EnumPrintProcDataTypes_level(tctx, b, NULL, 1, NULL, NULL, WERR_UNKNOWN_PRINTPROCESSOR),
1010 "test_EnumPrintProcDataTypes_level failed");
1012 torture_assert(tctx,
1013 test_EnumPrintProcDataTypes_level(tctx, b, "nonexisting", 1, NULL, NULL, WERR_UNKNOWN_PRINTPROCESSOR),
1014 "test_EnumPrintProcDataTypes_level failed");
1016 for (i=0;i<ARRAY_SIZE(levels);i++) {
1017 int level = levels[i];
1019 union spoolss_PrintProcDataTypesInfo *info;
1020 WERROR expected_result = ok[i] ? WERR_OK : WERR_INVALID_LEVEL;
1022 torture_assert(tctx,
1023 test_EnumPrintProcDataTypes_level(tctx, b, "winprint", level, &count, &info, expected_result),
1024 "test_EnumPrintProcDataTypes_level failed");
1028 union spoolss_PrintProcessorInfo *info;
1031 torture_assert(tctx,
1032 test_EnumPrintProcessors_level(tctx, b, ctx->environment, 1, &count, &info, WERR_OK),
1033 "test_EnumPrintProcessors_level failed");
1035 for (i=0; i < count; i++) {
1036 torture_assert(tctx,
1037 test_EnumPrintProcDataTypes_level(tctx, b, info[i].info1.print_processor_name, 1, NULL, NULL, WERR_OK),
1038 "test_EnumPrintProcDataTypes_level failed");
1046 static bool test_EnumPrinters(struct torture_context *tctx,
1049 struct test_spoolss_context *ctx =
1050 talloc_get_type_abort(private_data, struct test_spoolss_context);
1051 struct dcerpc_pipe *p = ctx->spoolss_pipe;
1052 struct dcerpc_binding_handle *b = p->binding_handle;
1053 struct spoolss_EnumPrinters r;
1055 uint16_t levels[] = { 0, 1, 2, 4, 5 };
1058 for (i=0;i<ARRAY_SIZE(levels);i++) {
1059 int level = levels[i];
1063 union spoolss_PrinterInfo *info;
1065 r.in.flags = PRINTER_ENUM_LOCAL;
1070 r.out.needed = &needed;
1071 r.out.count = &count;
1074 torture_comment(tctx, "Testing EnumPrinters level %u\n", r.in.level);
1076 status = dcerpc_spoolss_EnumPrinters_r(b, ctx, &r);
1077 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrinters failed");
1078 if (W_ERROR_IS_OK(r.out.result)) {
1079 /* TODO: do some more checks here */
1082 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
1083 "EnumPrinters unexpected return code");
1085 blob = data_blob_talloc_zero(ctx, needed);
1086 r.in.buffer = &blob;
1087 r.in.offered = needed;
1089 status = dcerpc_spoolss_EnumPrinters_r(b, ctx, &r);
1090 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrinters failed");
1092 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinters failed");
1094 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPrinters, info, r.in.level, count, needed, 4);
1096 ctx->printer_count[level] = count;
1097 ctx->printers[level] = info;
1100 for (i=1;i<ARRAY_SIZE(levels);i++) {
1101 int level = levels[i];
1102 int old_level = levels[i-1];
1103 torture_assert_int_equal(tctx, ctx->printer_count[level], ctx->printer_count[old_level],
1104 "EnumPrinters invalid value");
1107 for (i=0;i<ARRAY_SIZE(levels);i++) {
1108 int level = levels[i];
1109 for (j=0;j<ctx->printer_count[level];j++) {
1110 union spoolss_PrinterInfo *cur = &ctx->printers[level][j];
1111 union spoolss_PrinterInfo *ref = &ctx->printers[2][j];
1114 COMPARE_STRING(tctx, cur->info0, ref->info2, printername);
1115 COMPARE_STRING(tctx, cur->info0, ref->info2, servername);
1116 COMPARE_UINT32(tctx, cur->info0, ref->info2, cjobs);
1117 /*COMPARE_UINT32(tctx, cur->info0, ref->info2, total_jobs);
1118 COMPARE_UINT32(tctx, cur->info0, ref->info2, total_bytes);
1119 COMPARE_SPOOLSS_TIME(cur->info0, ref->info2, spoolss_Time time);
1120 COMPARE_UINT32(tctx, cur->info0, ref->info2, global_counter);
1121 COMPARE_UINT32(tctx, cur->info0, ref->info2, total_pages);
1122 COMPARE_UINT32(tctx, cur->info0, ref->info2, version);
1123 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown10);
1124 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown11);
1125 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown12);
1126 COMPARE_UINT32(tctx, cur->info0, ref->info2, session_counter);
1127 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown14);
1128 COMPARE_UINT32(tctx, cur->info0, ref->info2, printer_errors);
1129 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown16);
1130 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown17);
1131 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown18);
1132 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown19);
1133 COMPARE_UINT32(tctx, cur->info0, ref->info2, change_id);
1134 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown21);*/
1135 COMPARE_UINT32(tctx, cur->info0, ref->info2, status);
1136 /*COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown23);
1137 COMPARE_UINT32(tctx, cur->info0, ref->info2, c_setprinter);
1138 COMPARE_UINT16(cur->info0, ref->info2, unknown25);
1139 COMPARE_UINT16(cur->info0, ref->info2, unknown26);
1140 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown27);
1141 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown28);
1142 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown29);*/
1145 /*COMPARE_UINT32(tctx, cur->info1, ref->info2, flags);*/
1146 /*COMPARE_STRING(tctx, cur->info1, ref->info2, name);*/
1147 /*COMPARE_STRING(tctx, cur->info1, ref->info2, description);*/
1148 COMPARE_STRING(tctx, cur->info1, ref->info2, comment);
1151 /* level 2 is our reference, and it makes no sense to compare it to itself */
1154 COMPARE_STRING(tctx, cur->info4, ref->info2, printername);
1155 COMPARE_STRING(tctx, cur->info4, ref->info2, servername);
1156 COMPARE_UINT32(tctx, cur->info4, ref->info2, attributes);
1159 COMPARE_STRING(tctx, cur->info5, ref->info2, printername);
1160 COMPARE_STRING(tctx, cur->info5, ref->info2, portname);
1161 COMPARE_UINT32(tctx, cur->info5, ref->info2, attributes);
1162 /*COMPARE_UINT32(tctx, cur->info5, ref->info2, device_not_selected_timeout);
1163 COMPARE_UINT32(tctx, cur->info5, ref->info2, transmission_retry_timeout);*/
1170 * - verify that the port of a printer was in the list returned by EnumPorts
1176 static bool test_GetPrinterDriver2(struct torture_context *tctx,
1177 struct dcerpc_binding_handle *b,
1178 struct policy_handle *handle,
1179 const char *driver_name,
1180 const char *environment);
1182 bool test_GetPrinter_level(struct torture_context *tctx,
1183 struct dcerpc_binding_handle *b,
1184 struct policy_handle *handle,
1186 union spoolss_PrinterInfo *info)
1188 struct spoolss_GetPrinter r;
1191 r.in.handle = handle;
1195 r.out.needed = &needed;
1197 torture_comment(tctx, "Testing GetPrinter level %u\n", r.in.level);
1199 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_GetPrinter_r(b, tctx, &r),
1200 "GetPrinter failed");
1202 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
1203 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
1204 r.in.buffer = &blob;
1205 r.in.offered = needed;
1207 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_GetPrinter_r(b, tctx, &r),
1208 "GetPrinter failed");
1211 torture_assert_werr_ok(tctx, r.out.result, "GetPrinter failed");
1213 CHECK_NEEDED_SIZE_LEVEL(spoolss_PrinterInfo, r.out.info, r.in.level, needed, 4);
1215 if (info && r.out.info) {
1216 *info = *r.out.info;
1223 static bool test_GetPrinter(struct torture_context *tctx,
1224 struct dcerpc_binding_handle *b,
1225 struct policy_handle *handle,
1226 const char *environment)
1228 uint32_t levels[] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
1231 for (i=0;i<ARRAY_SIZE(levels);i++) {
1233 union spoolss_PrinterInfo info;
1237 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, levels[i], &info),
1238 "failed to call GetPrinter");
1240 if ((levels[i] == 2) && info.info2.drivername && strlen(info.info2.drivername)) {
1241 torture_assert(tctx,
1242 test_GetPrinterDriver2(tctx, b, handle, info.info2.drivername, environment),
1243 "failed to call test_GetPrinterDriver2");
1250 static bool test_SetPrinter(struct torture_context *tctx,
1251 struct dcerpc_binding_handle *b,
1252 struct policy_handle *handle,
1253 struct spoolss_SetPrinterInfoCtr *info_ctr,
1254 struct spoolss_DevmodeContainer *devmode_ctr,
1255 struct sec_desc_buf *secdesc_ctr,
1256 enum spoolss_PrinterControl command)
1258 struct spoolss_SetPrinter r;
1260 r.in.handle = handle;
1261 r.in.info_ctr = info_ctr;
1262 r.in.devmode_ctr = devmode_ctr;
1263 r.in.secdesc_ctr = secdesc_ctr;
1264 r.in.command = command;
1266 torture_comment(tctx, "Testing SetPrinter level %d\n", r.in.info_ctr->level);
1268 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_SetPrinter_r(b, tctx, &r),
1269 "failed to call SetPrinter");
1270 torture_assert(tctx, (W_ERROR_EQUAL(r.out.result, WERR_OK)
1271 || W_ERROR_EQUAL(r.out.result, WERR_IO_PENDING)),
1272 "SetPrinter failed");
1277 static bool test_SetPrinter_errors(struct torture_context *tctx,
1278 struct dcerpc_binding_handle *b,
1279 struct policy_handle *handle)
1281 struct spoolss_SetPrinter r;
1282 uint16_t levels[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
1285 struct spoolss_SetPrinterInfoCtr info_ctr;
1286 struct spoolss_DevmodeContainer devmode_ctr;
1287 struct sec_desc_buf secdesc_ctr;
1290 info_ctr.info.info0 = NULL;
1292 ZERO_STRUCT(devmode_ctr);
1293 ZERO_STRUCT(secdesc_ctr);
1295 r.in.handle = handle;
1296 r.in.info_ctr = &info_ctr;
1297 r.in.devmode_ctr = &devmode_ctr;
1298 r.in.secdesc_ctr = &secdesc_ctr;
1301 torture_comment(tctx, "Testing SetPrinter all zero\n");
1303 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_SetPrinter_r(b, tctx, &r),
1304 "failed to call SetPrinter");
1305 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAM,
1306 "failed to call SetPrinter");
1309 for (i=0; i < ARRAY_SIZE(levels); i++) {
1311 struct spoolss_SetPrinterInfo0 info0;
1312 struct spoolss_SetPrinterInfo1 info1;
1313 struct spoolss_SetPrinterInfo2 info2;
1314 struct spoolss_SetPrinterInfo3 info3;
1315 struct spoolss_SetPrinterInfo4 info4;
1316 struct spoolss_SetPrinterInfo5 info5;
1317 struct spoolss_SetPrinterInfo6 info6;
1318 struct spoolss_SetPrinterInfo7 info7;
1319 struct spoolss_SetPrinterInfo8 info8;
1320 struct spoolss_SetPrinterInfo9 info9;
1323 info_ctr.level = levels[i];
1324 switch (levels[i]) {
1327 info_ctr.info.info0 = &info0;
1331 info_ctr.info.info1 = &info1;
1335 info_ctr.info.info2 = &info2;
1339 info_ctr.info.info3 = &info3;
1343 info_ctr.info.info4 = &info4;
1347 info_ctr.info.info5 = &info5;
1351 info_ctr.info.info6 = &info6;
1355 info_ctr.info.info7 = &info7;
1359 info_ctr.info.info8 = &info8;
1363 info_ctr.info.info9 = &info9;
1367 torture_comment(tctx, "Testing SetPrinter level %d, command %d\n",
1368 info_ctr.level, r.in.command);
1370 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_SetPrinter_r(b, tctx, &r),
1371 "failed to call SetPrinter");
1373 switch (r.in.command) {
1374 case SPOOLSS_PRINTER_CONTROL_UNPAUSE: /* 0 */
1375 /* is ignored for all levels other then 0 */
1376 if (info_ctr.level > 0) {
1380 case SPOOLSS_PRINTER_CONTROL_PAUSE: /* 1 */
1381 case SPOOLSS_PRINTER_CONTROL_RESUME: /* 2 */
1382 case SPOOLSS_PRINTER_CONTROL_PURGE: /* 3 */
1383 if (info_ctr.level > 0) {
1384 /* is invalid for all levels other then 0 */
1385 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PRINTER_COMMAND,
1386 "unexpected error code returned");
1389 torture_assert_werr_ok(tctx, r.out.result,
1390 "failed to call SetPrinter with non 0 command");
1395 case SPOOLSS_PRINTER_CONTROL_SET_STATUS: /* 4 */
1396 /* FIXME: gd needs further investigation */
1398 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PRINTER_COMMAND,
1399 "unexpected error code returned");
1403 switch (info_ctr.level) {
1405 torture_assert_werr_equal(tctx, r.out.result, WERR_UNKNOWN_LEVEL,
1406 "unexpected error code returned");
1409 torture_assert_werr_equal(tctx, r.out.result, WERR_UNKNOWN_PRINTER_DRIVER,
1410 "unexpected error code returned");
1416 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAM,
1417 "unexpected error code returned");
1420 torture_assert_werr_equal(tctx, r.out.result, WERR_NOT_SUPPORTED,
1421 "unexpected error code returned");
1424 torture_assert_werr_ok(tctx, r.out.result,
1425 "failed to call SetPrinter");
1430 if (r.in.command < 5) {
1438 static void clear_info2(struct spoolss_SetPrinterInfoCtr *r)
1440 if ((r->level == 2) && (r->info.info2)) {
1441 r->info.info2->secdesc_ptr = NULL;
1442 r->info.info2->devmode_ptr = NULL;
1446 static bool test_PrinterInfo(struct torture_context *tctx,
1447 struct dcerpc_binding_handle *b,
1448 struct policy_handle *handle)
1451 struct spoolss_SetPrinter s;
1452 struct spoolss_GetPrinter q;
1453 struct spoolss_GetPrinter q0;
1454 struct spoolss_SetPrinterInfoCtr info_ctr;
1455 union spoolss_PrinterInfo info;
1456 struct spoolss_DevmodeContainer devmode_ctr;
1457 struct sec_desc_buf secdesc_ctr;
1462 uint32_t status_list[] = {
1463 /* these do not stick
1464 PRINTER_STATUS_PAUSED,
1465 PRINTER_STATUS_ERROR,
1466 PRINTER_STATUS_PENDING_DELETION, */
1467 PRINTER_STATUS_PAPER_JAM,
1468 PRINTER_STATUS_PAPER_OUT,
1469 PRINTER_STATUS_MANUAL_FEED,
1470 PRINTER_STATUS_PAPER_PROBLEM,
1471 PRINTER_STATUS_OFFLINE,
1472 PRINTER_STATUS_IO_ACTIVE,
1473 PRINTER_STATUS_BUSY,
1474 PRINTER_STATUS_PRINTING,
1475 PRINTER_STATUS_OUTPUT_BIN_FULL,
1476 PRINTER_STATUS_NOT_AVAILABLE,
1477 PRINTER_STATUS_WAITING,
1478 PRINTER_STATUS_PROCESSING,
1479 PRINTER_STATUS_INITIALIZING,
1480 PRINTER_STATUS_WARMING_UP,
1481 PRINTER_STATUS_TONER_LOW,
1482 PRINTER_STATUS_NO_TONER,
1483 PRINTER_STATUS_PAGE_PUNT,
1484 PRINTER_STATUS_USER_INTERVENTION,
1485 PRINTER_STATUS_OUT_OF_MEMORY,
1486 PRINTER_STATUS_DOOR_OPEN,
1487 PRINTER_STATUS_SERVER_UNKNOWN,
1488 PRINTER_STATUS_POWER_SAVE,
1489 /* these do not stick
1498 uint32_t default_attribute = PRINTER_ATTRIBUTE_LOCAL;
1499 uint32_t attribute_list[] = {
1500 PRINTER_ATTRIBUTE_QUEUED,
1501 /* fails with WERR_INVALID_DATATYPE:
1502 PRINTER_ATTRIBUTE_DIRECT, */
1504 PRINTER_ATTRIBUTE_DEFAULT, */
1505 PRINTER_ATTRIBUTE_SHARED,
1507 PRINTER_ATTRIBUTE_NETWORK, */
1508 PRINTER_ATTRIBUTE_HIDDEN,
1509 PRINTER_ATTRIBUTE_LOCAL,
1510 PRINTER_ATTRIBUTE_ENABLE_DEVQ,
1511 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS,
1512 PRINTER_ATTRIBUTE_DO_COMPLETE_FIRST,
1513 PRINTER_ATTRIBUTE_WORK_OFFLINE,
1515 PRINTER_ATTRIBUTE_ENABLE_BIDI, */
1516 /* fails with WERR_INVALID_DATATYPE:
1517 PRINTER_ATTRIBUTE_RAW_ONLY, */
1518 /* these do not stick
1519 PRINTER_ATTRIBUTE_PUBLISHED,
1520 PRINTER_ATTRIBUTE_FAX,
1521 PRINTER_ATTRIBUTE_TS,
1540 torture_skip(tctx, "Printer Info test is currently broken, skipping");
1543 ZERO_STRUCT(devmode_ctr);
1544 ZERO_STRUCT(secdesc_ctr);
1546 s.in.handle = handle;
1548 s.in.info_ctr = &info_ctr;
1549 s.in.devmode_ctr = &devmode_ctr;
1550 s.in.secdesc_ctr = &secdesc_ctr;
1552 q.in.handle = handle;
1556 #define TESTGETCALL(call, r) \
1557 r.in.buffer = NULL; \
1559 r.out.needed = &needed; \
1560 status = dcerpc_spoolss_ ##call## _r(b, tctx, &r); \
1561 if (!NT_STATUS_IS_OK(status)) { \
1562 torture_comment(tctx, #call " level %u failed - %s (%s)\n", \
1563 r.in.level, nt_errstr(status), __location__); \
1567 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {\
1568 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed); \
1569 r.in.buffer = &blob; \
1570 r.in.offered = needed; \
1572 status = dcerpc_spoolss_ ##call## _r(b, tctx, &r); \
1573 if (!NT_STATUS_IS_OK(status)) { \
1574 torture_comment(tctx, #call " level %u failed - %s (%s)\n", \
1575 r.in.level, nt_errstr(status), __location__); \
1579 if (!W_ERROR_IS_OK(r.out.result)) { \
1580 torture_comment(tctx, #call " level %u failed - %s (%s)\n", \
1581 r.in.level, win_errstr(r.out.result), __location__); \
1587 #define TESTSETCALL_EXP(call, r, err) \
1588 clear_info2(&info_ctr);\
1589 status = dcerpc_spoolss_ ##call## _r(b, tctx, &r); \
1590 if (!NT_STATUS_IS_OK(status)) { \
1591 torture_comment(tctx, #call " level %u failed - %s (%s)\n", \
1592 r.in.info_ctr->level, nt_errstr(status), __location__); \
1596 if (!W_ERROR_IS_OK(err)) { \
1597 if (!W_ERROR_EQUAL(err, r.out.result)) { \
1598 torture_comment(tctx, #call " level %u failed - %s, expected %s (%s)\n", \
1599 r.in.info_ctr->level, win_errstr(r.out.result), win_errstr(err), __location__); \
1604 if (!W_ERROR_IS_OK(r.out.result)) { \
1605 torture_comment(tctx, #call " level %u failed - %s (%s)\n", \
1606 r.in.info_ctr->level, win_errstr(r.out.result), __location__); \
1611 #define TESTSETCALL(call, r) \
1612 TESTSETCALL_EXP(call, r, WERR_OK)
1614 #define STRING_EQUAL(s1, s2, field) \
1615 if ((s1 && !s2) || (s2 && !s1) || strcmp(s1, s2)) { \
1616 torture_comment(tctx, "Failed to set %s to '%s' (%s)\n", \
1617 #field, s2, __location__); \
1622 #define MEM_EQUAL(s1, s2, length, field) \
1623 if ((s1 && !s2) || (s2 && !s1) || memcmp(s1, s2, length)) { \
1624 torture_comment(tctx, "Failed to set %s to '%s' (%s)\n", \
1625 #field, (const char *)s2, __location__); \
1630 #define INT_EQUAL(i1, i2, field) \
1632 torture_comment(tctx, "Failed to set %s to 0x%llx - got 0x%llx (%s)\n", \
1633 #field, (unsigned long long)i2, (unsigned long long)i1, __location__); \
1638 #define SD_EQUAL(sd1, sd2, field) \
1639 if (!security_descriptor_equal(sd1, sd2)) { \
1640 torture_comment(tctx, "Failed to set %s (%s)\n", \
1641 #field, __location__); \
1646 #define TEST_PRINTERINFO_STRING_EXP_ERR(lvl1, field1, lvl2, field2, value, err) do { \
1648 torture_comment(tctx, "field test %d/%s vs %d/%s\n", lvl1, #field1, lvl2, #field2); \
1649 q.in.level = lvl1; \
1650 TESTGETCALL(GetPrinter, q) \
1651 info_ctr.level = lvl1; \
1652 p = (void *)&q.out.info->info ## lvl1; \
1653 info_ctr.info.info ## lvl1 = (struct spoolss_SetPrinterInfo ## lvl1 *)p; \
1654 info_ctr.info.info ## lvl1->field1 = value;\
1655 TESTSETCALL_EXP(SetPrinter, s, err) \
1656 info_ctr.info.info ## lvl1->field1 = ""; \
1657 TESTGETCALL(GetPrinter, q) \
1658 info_ctr.info.info ## lvl1->field1 = value; \
1659 STRING_EQUAL(info_ctr.info.info ## lvl1->field1, value, field1); \
1660 q.in.level = lvl2; \
1661 TESTGETCALL(GetPrinter, q) \
1662 p = (void *)&q.out.info->info ## lvl2; \
1663 info_ctr.info.info ## lvl2 = (struct spoolss_SetPrinterInfo ## lvl2 *)p; \
1664 STRING_EQUAL(info_ctr.info.info ## lvl2->field2, value, field2); \
1667 #define TEST_PRINTERINFO_STRING(lvl1, field1, lvl2, field2, value) do { \
1668 TEST_PRINTERINFO_STRING_EXP_ERR(lvl1, field1, lvl2, field2, value, WERR_OK); \
1671 #define TEST_PRINTERINFO_INT_EXP(lvl1, field1, lvl2, field2, value, exp_value) do { \
1673 torture_comment(tctx, "field test %d/%s vs %d/%s\n", lvl1, #field1, lvl2, #field2); \
1674 q.in.level = lvl1; \
1675 TESTGETCALL(GetPrinter, q) \
1676 info_ctr.level = lvl1; \
1677 p = (void *)&q.out.info->info ## lvl1; \
1678 info_ctr.info.info ## lvl1 = (struct spoolss_SetPrinterInfo ## lvl1 *)p; \
1679 info_ctr.info.info ## lvl1->field1 = value; \
1680 TESTSETCALL(SetPrinter, s) \
1681 info_ctr.info.info ## lvl1->field1 = 0; \
1682 TESTGETCALL(GetPrinter, q) \
1683 p = (void *)&q.out.info->info ## lvl1; \
1684 info_ctr.info.info ## lvl1 = (struct spoolss_SetPrinterInfo ## lvl1 *)p; \
1685 INT_EQUAL(info_ctr.info.info ## lvl1->field1, exp_value, field1); \
1686 q.in.level = lvl2; \
1687 TESTGETCALL(GetPrinter, q) \
1688 p = (void *)&q.out.info->info ## lvl2; \
1689 info_ctr.info.info ## lvl2 = (struct spoolss_SetPrinterInfo ## lvl2 *)p; \
1690 INT_EQUAL(info_ctr.info.info ## lvl2->field2, exp_value, field1); \
1693 #define TEST_PRINTERINFO_INT(lvl1, field1, lvl2, field2, value) do { \
1694 TEST_PRINTERINFO_INT_EXP(lvl1, field1, lvl2, field2, value, value); \
1698 do { TESTGETCALL(GetPrinter, q0) } while (0);
1700 TEST_PRINTERINFO_STRING(2, comment, 1, comment, "xx2-1 comment");
1701 TEST_PRINTERINFO_STRING(2, comment, 2, comment, "xx2-2 comment");
1703 /* level 0 printername does not stick */
1704 /* TEST_PRINTERINFO_STRING(2, printername, 0, printername, "xx2-0 printer"); */
1705 TEST_PRINTERINFO_STRING(2, printername, 1, name, "xx2-1 printer");
1706 TEST_PRINTERINFO_STRING(2, printername, 2, printername, "xx2-2 printer");
1707 TEST_PRINTERINFO_STRING(2, printername, 4, printername, "xx2-4 printer");
1708 TEST_PRINTERINFO_STRING(2, printername, 5, printername, "xx2-5 printer");
1709 /* TEST_PRINTERINFO_STRING(4, printername, 0, printername, "xx4-0 printer"); */
1710 TEST_PRINTERINFO_STRING(4, printername, 1, name, "xx4-1 printer");
1711 TEST_PRINTERINFO_STRING(4, printername, 2, printername, "xx4-2 printer");
1712 TEST_PRINTERINFO_STRING(4, printername, 4, printername, "xx4-4 printer");
1713 TEST_PRINTERINFO_STRING(4, printername, 5, printername, "xx4-5 printer");
1714 /* TEST_PRINTERINFO_STRING(5, printername, 0, printername, "xx5-0 printer"); */
1715 TEST_PRINTERINFO_STRING(5, printername, 1, name, "xx5-1 printer");
1716 TEST_PRINTERINFO_STRING(5, printername, 2, printername, "xx5-2 printer");
1717 TEST_PRINTERINFO_STRING(5, printername, 4, printername, "xx5-4 printer");
1718 TEST_PRINTERINFO_STRING(5, printername, 5, printername, "xx5-5 printer");
1720 /* servername can be set but does not stick
1721 TEST_PRINTERINFO_STRING(2, servername, 0, servername, "xx2-0 servername");
1722 TEST_PRINTERINFO_STRING(2, servername, 2, servername, "xx2-2 servername");
1723 TEST_PRINTERINFO_STRING(2, servername, 4, servername, "xx2-4 servername");
1726 /* passing an invalid port will result in WERR_UNKNOWN_PORT */
1727 TEST_PRINTERINFO_STRING_EXP_ERR(2, portname, 2, portname, "xx2-2 portname", WERR_UNKNOWN_PORT);
1728 TEST_PRINTERINFO_STRING_EXP_ERR(2, portname, 5, portname, "xx2-5 portname", WERR_UNKNOWN_PORT);
1729 TEST_PRINTERINFO_STRING_EXP_ERR(5, portname, 2, portname, "xx5-2 portname", WERR_UNKNOWN_PORT);
1730 TEST_PRINTERINFO_STRING_EXP_ERR(5, portname, 5, portname, "xx5-5 portname", WERR_UNKNOWN_PORT);
1732 TEST_PRINTERINFO_STRING(2, sharename, 2, sharename, "xx2-2 sharename");
1733 /* passing an invalid driver will result in WERR_UNKNOWN_PRINTER_DRIVER */
1734 TEST_PRINTERINFO_STRING_EXP_ERR(2, drivername, 2, drivername, "xx2-2 drivername", WERR_UNKNOWN_PRINTER_DRIVER);
1735 TEST_PRINTERINFO_STRING(2, location, 2, location, "xx2-2 location");
1736 /* passing an invalid sepfile will result in WERR_INVALID_SEPARATOR_FILE */
1737 TEST_PRINTERINFO_STRING_EXP_ERR(2, sepfile, 2, sepfile, "xx2-2 sepfile", WERR_INVALID_SEPARATOR_FILE);
1738 /* passing an invalid printprocessor will result in WERR_UNKNOWN_PRINTPROCESSOR */
1739 TEST_PRINTERINFO_STRING_EXP_ERR(2, printprocessor, 2, printprocessor, "xx2-2 printprocessor", WERR_UNKNOWN_PRINTPROCESSOR);
1740 TEST_PRINTERINFO_STRING(2, datatype, 2, datatype, "xx2-2 datatype");
1741 TEST_PRINTERINFO_STRING(2, parameters, 2, parameters, "xx2-2 parameters");
1743 for (i=0; i < ARRAY_SIZE(attribute_list); i++) {
1744 /* TEST_PRINTERINFO_INT_EXP(2, attributes, 1, flags,
1746 (attribute_list[i] | default_attribute)
1748 TEST_PRINTERINFO_INT_EXP(2, attributes, 2, attributes,
1750 (attribute_list[i] | default_attribute)
1752 TEST_PRINTERINFO_INT_EXP(2, attributes, 4, attributes,
1754 (attribute_list[i] | default_attribute)
1756 TEST_PRINTERINFO_INT_EXP(2, attributes, 5, attributes,
1758 (attribute_list[i] | default_attribute)
1760 /* TEST_PRINTERINFO_INT_EXP(4, attributes, 1, flags,
1762 (attribute_list[i] | default_attribute)
1764 TEST_PRINTERINFO_INT_EXP(4, attributes, 2, attributes,
1766 (attribute_list[i] | default_attribute)
1768 TEST_PRINTERINFO_INT_EXP(4, attributes, 4, attributes,
1770 (attribute_list[i] | default_attribute)
1772 TEST_PRINTERINFO_INT_EXP(4, attributes, 5, attributes,
1774 (attribute_list[i] | default_attribute)
1776 /* TEST_PRINTERINFO_INT_EXP(5, attributes, 1, flags,
1778 (attribute_list[i] | default_attribute)
1780 TEST_PRINTERINFO_INT_EXP(5, attributes, 2, attributes,
1782 (attribute_list[i] | default_attribute)
1784 TEST_PRINTERINFO_INT_EXP(5, attributes, 4, attributes,
1786 (attribute_list[i] | default_attribute)
1788 TEST_PRINTERINFO_INT_EXP(5, attributes, 5, attributes,
1790 (attribute_list[i] | default_attribute)
1794 for (i=0; i < ARRAY_SIZE(status_list); i++) {
1795 /* level 2 sets do not stick
1796 TEST_PRINTERINFO_INT(2, status, 0, status, status_list[i]);
1797 TEST_PRINTERINFO_INT(2, status, 2, status, status_list[i]);
1798 TEST_PRINTERINFO_INT(2, status, 6, status, status_list[i]); */
1799 TEST_PRINTERINFO_INT(6, status, 0, status, status_list[i]);
1800 TEST_PRINTERINFO_INT(6, status, 2, status, status_list[i]);
1801 TEST_PRINTERINFO_INT(6, status, 6, status, status_list[i]);
1804 /* priorities need to be between 0 and 99
1805 passing an invalid priority will result in WERR_INVALID_PRIORITY */
1806 TEST_PRINTERINFO_INT(2, priority, 2, priority, 0);
1807 TEST_PRINTERINFO_INT(2, priority, 2, priority, 1);
1808 TEST_PRINTERINFO_INT(2, priority, 2, priority, 99);
1809 /* TEST_PRINTERINFO_INT(2, priority, 2, priority, 100); */
1810 TEST_PRINTERINFO_INT(2, defaultpriority,2, defaultpriority, 0);
1811 TEST_PRINTERINFO_INT(2, defaultpriority,2, defaultpriority, 1);
1812 TEST_PRINTERINFO_INT(2, defaultpriority,2, defaultpriority, 99);
1813 /* TEST_PRINTERINFO_INT(2, defaultpriority,2, defaultpriority, 100); */
1815 TEST_PRINTERINFO_INT(2, starttime, 2, starttime, __LINE__);
1816 TEST_PRINTERINFO_INT(2, untiltime, 2, untiltime, __LINE__);
1819 TEST_PRINTERINFO_INT(2, cjobs, 2, cjobs, __LINE__);
1820 TEST_PRINTERINFO_INT(2, averageppm, 2, averageppm, __LINE__); */
1823 TEST_PRINTERINFO_INT(5, device_not_selected_timeout, 5, device_not_selected_timeout, __LINE__);
1824 TEST_PRINTERINFO_INT(5, transmission_retry_timeout, 5, transmission_retry_timeout, __LINE__); */
1826 /* FIXME: gd also test devmode and secdesc behavior */
1829 /* verify composition of level 1 description field */
1830 const char *description;
1834 do { TESTGETCALL(GetPrinter, q0) } while (0);
1836 description = talloc_strdup(tctx, q0.out.info->info1.description);
1839 do { TESTGETCALL(GetPrinter, q0) } while (0);
1841 tmp = talloc_asprintf(tctx, "%s,%s,%s",
1842 q0.out.info->info2.printername,
1843 q0.out.info->info2.drivername,
1844 q0.out.info->info2.location);
1846 do { STRING_EQUAL(description, tmp, "description")} while (0);
1852 static bool test_security_descriptor_equal(struct torture_context *tctx,
1853 const struct security_descriptor *sd1,
1854 const struct security_descriptor *sd2)
1861 torture_comment(tctx, "%s\n", __location__);
1865 torture_assert_int_equal(tctx, sd1->revision, sd2->revision, "revision mismatch");
1866 torture_assert_int_equal(tctx, sd1->type, sd2->type, "type mismatch");
1868 torture_assert_sid_equal(tctx, sd1->owner_sid, sd2->owner_sid, "owner mismatch");
1869 torture_assert_sid_equal(tctx, sd1->group_sid, sd2->group_sid, "group mismatch");
1871 if (!security_acl_equal(sd1->sacl, sd2->sacl)) {
1872 torture_comment(tctx, "%s: sacl mismatch\n", __location__);
1873 NDR_PRINT_DEBUG(security_acl, sd1->sacl);
1874 NDR_PRINT_DEBUG(security_acl, sd2->sacl);
1877 if (!security_acl_equal(sd1->dacl, sd2->dacl)) {
1878 torture_comment(tctx, "%s: dacl mismatch\n", __location__);
1879 NDR_PRINT_DEBUG(security_acl, sd1->dacl);
1880 NDR_PRINT_DEBUG(security_acl, sd2->dacl);
1887 static bool test_sd_set_level(struct torture_context *tctx,
1888 struct dcerpc_binding_handle *b,
1889 struct policy_handle *handle,
1891 struct security_descriptor *sd)
1893 struct spoolss_SetPrinterInfoCtr info_ctr;
1894 struct spoolss_DevmodeContainer devmode_ctr;
1895 struct sec_desc_buf secdesc_ctr;
1896 union spoolss_SetPrinterInfo sinfo;
1897 union spoolss_PrinterInfo info;
1898 struct spoolss_SetPrinterInfo3 info3;
1900 ZERO_STRUCT(devmode_ctr);
1901 ZERO_STRUCT(secdesc_ctr);
1905 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
1906 torture_assert(tctx, PrinterInfo_to_SetPrinterInfo(tctx, &info, 2, &sinfo), "");
1909 info_ctr.info = sinfo;
1915 info3.sec_desc_ptr = NULL;
1918 info_ctr.info.info3 = &info3;
1926 secdesc_ctr.sd = sd;
1928 torture_assert(tctx,
1929 test_SetPrinter(tctx, b, handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0), "");
1934 static bool test_PrinterInfo_SDs(struct torture_context *tctx,
1935 struct dcerpc_binding_handle *b,
1936 struct policy_handle *handle)
1938 union spoolss_PrinterInfo info;
1939 struct security_descriptor *sd1, *sd2;
1942 /* just compare level 2 and level 3 */
1944 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
1946 sd1 = info.info2.secdesc;
1948 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 3, &info), "");
1950 sd2 = info.info3.secdesc;
1952 torture_assert(tctx, test_security_descriptor_equal(tctx, sd1, sd2),
1953 "SD level 2 != SD level 3");
1956 /* query level 2, set level 2, query level 2 */
1958 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
1960 sd1 = info.info2.secdesc;
1962 torture_assert(tctx, test_sd_set_level(tctx, b, handle, 2, sd1), "");
1964 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
1966 sd2 = info.info2.secdesc;
1967 if (sd1->type & SEC_DESC_DACL_DEFAULTED) {
1968 torture_comment(tctx, "removing SEC_DESC_DACL_DEFAULTED\n");
1969 sd1->type &= ~SEC_DESC_DACL_DEFAULTED;
1972 torture_assert(tctx, test_security_descriptor_equal(tctx, sd1, sd2),
1973 "SD level 2 != SD level 2 after SD has been set via level 2");
1976 /* query level 2, set level 3, query level 2 */
1978 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
1980 sd1 = info.info2.secdesc;
1982 torture_assert(tctx, test_sd_set_level(tctx, b, handle, 3, sd1), "");
1984 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
1986 sd2 = info.info2.secdesc;
1988 torture_assert(tctx, test_security_descriptor_equal(tctx, sd1, sd2),
1989 "SD level 2 != SD level 2 after SD has been set via level 3");
1991 /* set modified sd level 3, query level 2 */
1993 for (i=0; i < 93; i++) {
1994 struct security_ace a;
1995 const char *sid_string = talloc_asprintf(tctx, "S-1-5-32-9999%i", i);
1996 a.type = SEC_ACE_TYPE_ACCESS_ALLOWED;
1998 a.size = 0; /* autogenerated */
2000 a.trustee = *dom_sid_parse_talloc(tctx, sid_string);
2001 torture_assert_ntstatus_ok(tctx, security_descriptor_dacl_add(sd1, &a), "");
2004 torture_assert(tctx, test_sd_set_level(tctx, b, handle, 3, sd1), "");
2006 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
2007 sd2 = info.info2.secdesc;
2009 if (sd1->type & SEC_DESC_DACL_DEFAULTED) {
2010 torture_comment(tctx, "removing SEC_DESC_DACL_DEFAULTED\n");
2011 sd1->type &= ~SEC_DESC_DACL_DEFAULTED;
2014 torture_assert(tctx, test_security_descriptor_equal(tctx, sd1, sd2),
2015 "modified SD level 2 != SD level 2 after SD has been set via level 3");
2022 * wrapper call that saves original sd, runs tests, and restores sd
2025 static bool test_PrinterInfo_SD(struct torture_context *tctx,
2026 struct dcerpc_binding_handle *b,
2027 struct policy_handle *handle)
2029 union spoolss_PrinterInfo info;
2030 struct security_descriptor *sd;
2033 torture_comment(tctx, "Testing Printer Security Descriptors\n");
2035 /* save original sd */
2037 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info),
2038 "failed to get initial security descriptor");
2040 sd = security_descriptor_copy(tctx, info.info2.secdesc);
2044 ret = test_PrinterInfo_SDs(tctx, b, handle);
2046 /* restore original sd */
2048 torture_assert(tctx, test_sd_set_level(tctx, b, handle, 3, sd),
2049 "failed to restore initial security descriptor");
2051 torture_comment(tctx, "Printer Security Descriptors test %s\n\n",
2052 ret ? "succeeded" : "failed");
2058 static bool test_devmode_set_level(struct torture_context *tctx,
2059 struct dcerpc_binding_handle *b,
2060 struct policy_handle *handle,
2062 struct spoolss_DeviceMode *devmode)
2064 struct spoolss_SetPrinterInfoCtr info_ctr;
2065 struct spoolss_DevmodeContainer devmode_ctr;
2066 struct sec_desc_buf secdesc_ctr;
2067 union spoolss_SetPrinterInfo sinfo;
2069 ZERO_STRUCT(devmode_ctr);
2070 ZERO_STRUCT(secdesc_ctr);
2074 union spoolss_PrinterInfo info;
2075 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
2076 torture_assert(tctx, PrinterInfo_to_SetPrinterInfo(tctx, &info, 2, &sinfo), "");
2079 info_ctr.info = sinfo;
2084 struct spoolss_SetPrinterInfo8 info8;
2086 info8.devmode_ptr = NULL;
2089 info_ctr.info.info8 = &info8;
2097 devmode_ctr.devmode = devmode;
2099 torture_assert(tctx,
2100 test_SetPrinter(tctx, b, handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0), "");
2106 static bool test_devicemode_equal(struct torture_context *tctx,
2107 const struct spoolss_DeviceMode *d1,
2108 const struct spoolss_DeviceMode *d2)
2115 torture_comment(tctx, "%s\n", __location__);
2118 torture_assert_str_equal(tctx, d1->devicename, d2->devicename, "devicename mismatch");
2119 torture_assert_int_equal(tctx, d1->specversion, d2->specversion, "specversion mismatch");
2120 torture_assert_int_equal(tctx, d1->driverversion, d2->driverversion, "driverversion mismatch");
2121 torture_assert_int_equal(tctx, d1->size, d2->size, "size mismatch");
2122 torture_assert_int_equal(tctx, d1->__driverextra_length, d2->__driverextra_length, "__driverextra_length mismatch");
2123 torture_assert_int_equal(tctx, d1->fields, d2->fields, "fields mismatch");
2124 torture_assert_int_equal(tctx, d1->orientation, d2->orientation, "orientation mismatch");
2125 torture_assert_int_equal(tctx, d1->papersize, d2->papersize, "papersize mismatch");
2126 torture_assert_int_equal(tctx, d1->paperlength, d2->paperlength, "paperlength mismatch");
2127 torture_assert_int_equal(tctx, d1->paperwidth, d2->paperwidth, "paperwidth mismatch");
2128 torture_assert_int_equal(tctx, d1->scale, d2->scale, "scale mismatch");
2129 torture_assert_int_equal(tctx, d1->copies, d2->copies, "copies mismatch");
2130 torture_assert_int_equal(tctx, d1->defaultsource, d2->defaultsource, "defaultsource mismatch");
2131 torture_assert_int_equal(tctx, d1->printquality, d2->printquality, "printquality mismatch");
2132 torture_assert_int_equal(tctx, d1->color, d2->color, "color mismatch");
2133 torture_assert_int_equal(tctx, d1->duplex, d2->duplex, "duplex mismatch");
2134 torture_assert_int_equal(tctx, d1->yresolution, d2->yresolution, "yresolution mismatch");
2135 torture_assert_int_equal(tctx, d1->ttoption, d2->ttoption, "ttoption mismatch");
2136 torture_assert_int_equal(tctx, d1->collate, d2->collate, "collate mismatch");
2137 torture_assert_str_equal(tctx, d1->formname, d2->formname, "formname mismatch");
2138 torture_assert_int_equal(tctx, d1->logpixels, d2->logpixels, "logpixels mismatch");
2139 torture_assert_int_equal(tctx, d1->bitsperpel, d2->bitsperpel, "bitsperpel mismatch");
2140 torture_assert_int_equal(tctx, d1->pelswidth, d2->pelswidth, "pelswidth mismatch");
2141 torture_assert_int_equal(tctx, d1->pelsheight, d2->pelsheight, "pelsheight mismatch");
2142 torture_assert_int_equal(tctx, d1->displayflags, d2->displayflags, "displayflags mismatch");
2143 torture_assert_int_equal(tctx, d1->displayfrequency, d2->displayfrequency, "displayfrequency mismatch");
2144 torture_assert_int_equal(tctx, d1->icmmethod, d2->icmmethod, "icmmethod mismatch");
2145 torture_assert_int_equal(tctx, d1->icmintent, d2->icmintent, "icmintent mismatch");
2146 torture_assert_int_equal(tctx, d1->mediatype, d2->mediatype, "mediatype mismatch");
2147 torture_assert_int_equal(tctx, d1->dithertype, d2->dithertype, "dithertype mismatch");
2148 torture_assert_int_equal(tctx, d1->reserved1, d2->reserved1, "reserved1 mismatch");
2149 torture_assert_int_equal(tctx, d1->reserved2, d2->reserved2, "reserved2 mismatch");
2150 torture_assert_int_equal(tctx, d1->panningwidth, d2->panningwidth, "panningwidth mismatch");
2151 torture_assert_int_equal(tctx, d1->panningheight, d2->panningheight, "panningheight mismatch");
2152 torture_assert_data_blob_equal(tctx, d1->driverextra_data, d2->driverextra_data, "driverextra_data mismatch");
2157 static bool test_devicemode_full(struct torture_context *tctx,
2158 struct dcerpc_binding_handle *b,
2159 struct policy_handle *handle)
2161 struct spoolss_SetPrinter s;
2162 struct spoolss_GetPrinter q;
2163 struct spoolss_SetPrinterInfoCtr info_ctr;
2164 struct spoolss_SetPrinterInfo8 info8;
2165 union spoolss_PrinterInfo info;
2166 struct spoolss_DevmodeContainer devmode_ctr;
2167 struct sec_desc_buf secdesc_ctr;
2172 #define TEST_DEVMODE_INT_EXP_RESULT(lvl1, field1, lvl2, field2, value, exp_value, expected_result) do { \
2173 torture_comment(tctx, "field test %d/%s vs %d/%s\n", lvl1, #field1, lvl2, #field2); \
2174 q.in.level = lvl1; \
2175 TESTGETCALL(GetPrinter, q) \
2176 info_ctr.level = lvl1; \
2178 void *p = (void *)&q.out.info->info ## lvl1; \
2179 info_ctr.info.info ## lvl1 = (struct spoolss_SetPrinterInfo ## lvl1 *)p; \
2180 } else if (lvl1 == 8) {\
2181 info_ctr.info.info ## lvl1 = &info8; \
2183 devmode_ctr.devmode = q.out.info->info ## lvl1.devmode; \
2184 devmode_ctr.devmode->field1 = value; \
2185 TESTSETCALL_EXP(SetPrinter, s, expected_result) \
2186 if (W_ERROR_IS_OK(expected_result)) { \
2187 TESTGETCALL(GetPrinter, q) \
2188 INT_EQUAL(q.out.info->info ## lvl1.devmode->field1, exp_value, field1); \
2189 q.in.level = lvl2; \
2190 TESTGETCALL(GetPrinter, q) \
2191 INT_EQUAL(q.out.info->info ## lvl2.devmode->field2, exp_value, field1); \
2195 #define TEST_DEVMODE_INT_EXP(lvl1, field1, lvl2, field2, value, expected_result) do { \
2196 TEST_DEVMODE_INT_EXP_RESULT(lvl1, field1, lvl2, field2, value, value, expected_result); \
2199 #define TEST_DEVMODE_INT(lvl1, field1, lvl2, field2, value) do { \
2200 TEST_DEVMODE_INT_EXP_RESULT(lvl1, field1, lvl2, field2, value, value, WERR_OK); \
2203 ZERO_STRUCT(devmode_ctr);
2204 ZERO_STRUCT(secdesc_ctr);
2207 s.in.handle = handle;
2209 s.in.info_ctr = &info_ctr;
2210 s.in.devmode_ctr = &devmode_ctr;
2211 s.in.secdesc_ctr = &secdesc_ctr;
2213 q.in.handle = handle;
2217 const char *devicename;/* [charset(UTF16)] */
2218 enum spoolss_DeviceModeSpecVersion specversion;
2219 uint16_t driverversion;
2220 uint16_t __driverextra_length;/* [value(r->driverextra_data.length)] */
2223 TEST_DEVMODE_INT_EXP(8, size, 8, size, __LINE__, WERR_INVALID_PARAM);
2224 TEST_DEVMODE_INT_EXP(8, size, 8, size, 0, WERR_INVALID_PARAM);
2225 TEST_DEVMODE_INT_EXP(8, size, 8, size, 0xffff, WERR_INVALID_PARAM);
2226 TEST_DEVMODE_INT_EXP(8, size, 8, size, ndr_size_spoolss_DeviceMode(devmode_ctr.devmode, 0), (devmode_ctr.devmode->__driverextra_length > 0 ) ? WERR_INVALID_PARAM : WERR_OK);
2227 TEST_DEVMODE_INT(8, size, 8, size, ndr_size_spoolss_DeviceMode(devmode_ctr.devmode, 0) - devmode_ctr.devmode->__driverextra_length);
2229 devmode_ctr.devmode->driverextra_data = data_blob_string_const("foobar");
2230 torture_assert(tctx,
2231 test_devmode_set_level(tctx, b, handle, 8, devmode_ctr.devmode),
2232 "failed to set devmode");
2234 TEST_DEVMODE_INT_EXP(8, size, 8, size, ndr_size_spoolss_DeviceMode(devmode_ctr.devmode, 0), (devmode_ctr.devmode->__driverextra_length > 0 ) ? WERR_INVALID_PARAM : WERR_OK);
2235 TEST_DEVMODE_INT(8, size, 8, size, ndr_size_spoolss_DeviceMode(devmode_ctr.devmode, 0) - devmode_ctr.devmode->__driverextra_length);
2237 TEST_DEVMODE_INT(8, orientation, 8, orientation, __LINE__);
2238 TEST_DEVMODE_INT(8, papersize, 8, papersize, __LINE__);
2239 TEST_DEVMODE_INT(8, paperlength, 8, paperlength, __LINE__);
2240 TEST_DEVMODE_INT(8, paperwidth, 8, paperwidth, __LINE__);
2241 TEST_DEVMODE_INT(8, scale, 8, scale, __LINE__);
2242 TEST_DEVMODE_INT(8, copies, 8, copies, __LINE__);
2243 TEST_DEVMODE_INT(8, defaultsource, 8, defaultsource, __LINE__);
2244 TEST_DEVMODE_INT(8, printquality, 8, printquality, __LINE__);
2245 TEST_DEVMODE_INT(8, color, 8, color, __LINE__);
2246 TEST_DEVMODE_INT(8, duplex, 8, duplex, __LINE__);
2247 TEST_DEVMODE_INT(8, yresolution, 8, yresolution, __LINE__);
2248 TEST_DEVMODE_INT(8, ttoption, 8, ttoption, __LINE__);
2249 TEST_DEVMODE_INT(8, collate, 8, collate, __LINE__);
2251 const char *formname;/* [charset(UTF16)] */
2253 TEST_DEVMODE_INT(8, logpixels, 8, logpixels, __LINE__);
2254 TEST_DEVMODE_INT(8, bitsperpel, 8, bitsperpel, __LINE__);
2255 TEST_DEVMODE_INT(8, pelswidth, 8, pelswidth, __LINE__);
2256 TEST_DEVMODE_INT(8, pelsheight, 8, pelsheight, __LINE__);
2257 TEST_DEVMODE_INT(8, displayflags, 8, displayflags, __LINE__);
2258 TEST_DEVMODE_INT(8, displayfrequency, 8, displayfrequency, __LINE__);
2259 TEST_DEVMODE_INT(8, icmmethod, 8, icmmethod, __LINE__);
2260 TEST_DEVMODE_INT(8, icmintent, 8, icmintent, __LINE__);
2261 TEST_DEVMODE_INT(8, mediatype, 8, mediatype, __LINE__);
2262 TEST_DEVMODE_INT(8, dithertype, 8, dithertype, __LINE__);
2263 TEST_DEVMODE_INT(8, reserved1, 8, reserved1, __LINE__);
2264 TEST_DEVMODE_INT(8, reserved2, 8, reserved2, __LINE__);
2265 TEST_DEVMODE_INT(8, panningwidth, 8, panningwidth, __LINE__);
2266 TEST_DEVMODE_INT(8, panningheight, 8, panningheight, __LINE__);
2271 static bool call_OpenPrinterEx(struct torture_context *tctx,
2272 struct dcerpc_pipe *p,
2274 struct spoolss_DeviceMode *devmode,
2275 struct policy_handle *handle);
2277 static bool test_PrinterInfo_DevModes(struct torture_context *tctx,
2278 struct dcerpc_pipe *p,
2279 struct policy_handle *handle,
2282 union spoolss_PrinterInfo info;
2283 struct spoolss_DeviceMode *devmode;
2284 struct spoolss_DeviceMode *devmode2;
2285 struct policy_handle handle_devmode;
2286 struct dcerpc_binding_handle *b = p->binding_handle;
2288 /* simply compare level8 and level2 devmode */
2290 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 8, &info), "");
2292 devmode = info.info8.devmode;
2294 if (devmode && devmode->size == 0) {
2296 "devmode of zero size!");
2299 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
2301 devmode2 = info.info2.devmode;
2303 if (devmode2 && devmode2->size == 0) {
2305 "devmode of zero size!");
2308 torture_assert(tctx, test_devicemode_equal(tctx, devmode, devmode2),
2309 "DM level 8 != DM level 2");
2312 /* set devicemode level 8 and see if it persists */
2314 devmode->copies = 93;
2315 devmode->formname = talloc_strdup(tctx, "Legal");
2317 torture_assert(tctx, test_devmode_set_level(tctx, b, handle, 8, devmode), "");
2319 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 8, &info), "");
2321 devmode2 = info.info8.devmode;
2323 torture_assert(tctx, test_devicemode_equal(tctx, devmode, devmode2),
2324 "modified DM level 8 != DM level 8 after DM has been set via level 8");
2326 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
2328 devmode2 = info.info2.devmode;
2330 torture_assert(tctx, test_devicemode_equal(tctx, devmode, devmode2),
2331 "modified DM level 8 != DM level 2");
2334 /* set devicemode level 2 and see if it persists */
2336 devmode->copies = 39;
2337 devmode->formname = talloc_strdup(tctx, "Executive");
2339 torture_assert(tctx, test_devmode_set_level(tctx, b, handle, 2, devmode), "");
2341 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 8, &info), "");
2343 devmode2 = info.info8.devmode;
2345 torture_assert(tctx, test_devicemode_equal(tctx, devmode, devmode2),
2346 "modified DM level 8 != DM level 8 after DM has been set via level 2");
2348 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info), "");
2350 devmode2 = info.info2.devmode;
2352 torture_assert(tctx, test_devicemode_equal(tctx, devmode, devmode2),
2353 "modified DM level 8 != DM level 2");
2356 /* check every single bit in public part of devicemode */
2358 torture_assert(tctx, test_devicemode_full(tctx, b, handle),
2359 "failed to set every single devicemode component");
2362 /* change formname upon open and see if it persists in getprinter calls */
2364 devmode->formname = talloc_strdup(tctx, "A4");
2365 devmode->copies = 42;
2367 torture_assert(tctx, call_OpenPrinterEx(tctx, p, name, devmode, &handle_devmode),
2368 "failed to open printer handle");
2370 torture_assert(tctx, test_GetPrinter_level(tctx, b, &handle_devmode, 8, &info), "");
2372 devmode2 = info.info8.devmode;
2374 if (strequal(devmode->devicename, devmode2->devicename)) {
2375 torture_warning(tctx, "devicenames are the same\n");
2377 torture_comment(tctx, "devicename passed in for open: %s\n", devmode->devicename);
2378 torture_comment(tctx, "devicename after level 8 get: %s\n", devmode2->devicename);
2381 if (strequal(devmode->formname, devmode2->formname)) {
2382 torture_warning(tctx, "formname are the same\n");
2384 torture_comment(tctx, "formname passed in for open: %s\n", devmode->formname);
2385 torture_comment(tctx, "formname after level 8 get: %s\n", devmode2->formname);
2388 if (devmode->copies == devmode2->copies) {
2389 torture_warning(tctx, "copies are the same\n");
2391 torture_comment(tctx, "copies passed in for open: %d\n", devmode->copies);
2392 torture_comment(tctx, "copies after level 8 get: %d\n", devmode2->copies);
2395 torture_assert(tctx, test_GetPrinter_level(tctx, b, &handle_devmode, 2, &info), "");
2397 devmode2 = info.info2.devmode;
2399 if (strequal(devmode->devicename, devmode2->devicename)) {
2400 torture_warning(tctx, "devicenames are the same\n");
2402 torture_comment(tctx, "devicename passed in for open: %s\n", devmode->devicename);
2403 torture_comment(tctx, "devicename after level 2 get: %s\n", devmode2->devicename);
2406 if (strequal(devmode->formname, devmode2->formname)) {
2407 torture_warning(tctx, "formname is the same\n");
2409 torture_comment(tctx, "formname passed in for open: %s\n", devmode->formname);
2410 torture_comment(tctx, "formname after level 2 get: %s\n", devmode2->formname);
2413 if (devmode->copies == devmode2->copies) {
2414 torture_warning(tctx, "copies are the same\n");
2416 torture_comment(tctx, "copies passed in for open: %d\n", devmode->copies);
2417 torture_comment(tctx, "copies after level 2 get: %d\n", devmode2->copies);
2420 test_ClosePrinter(tctx, b, &handle_devmode);
2426 * wrapper call that saves original devmode, runs tests, and restores devmode
2429 static bool test_PrinterInfo_DevMode(struct torture_context *tctx,
2430 struct dcerpc_pipe *p,
2431 struct policy_handle *handle,
2433 struct spoolss_DeviceMode *addprinter_devmode)
2435 union spoolss_PrinterInfo info;
2436 struct spoolss_DeviceMode *devmode;
2438 struct dcerpc_binding_handle *b = p->binding_handle;
2440 torture_comment(tctx, "Testing Printer Devicemodes\n");
2442 /* save original devmode */
2444 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 8, &info),
2445 "failed to get initial global devicemode");
2447 devmode = info.info8.devmode;
2449 if (devmode && devmode->size == 0) {
2451 "devmode of zero size!");
2454 if (addprinter_devmode) {
2455 if (!test_devicemode_equal(tctx, devmode, addprinter_devmode)) {
2456 torture_warning(tctx, "current global DM is != DM provided in addprinter");
2462 ret = test_PrinterInfo_DevModes(tctx, p, handle, name);
2464 /* restore original devmode */
2466 torture_assert(tctx, test_devmode_set_level(tctx, b, handle, 8, devmode),
2467 "failed to restore initial global device mode");
2469 torture_comment(tctx, "Printer Devicemodes test %s\n\n",
2470 ret ? "succeeded" : "failed");
2476 bool test_ClosePrinter(struct torture_context *tctx,
2477 struct dcerpc_binding_handle *b,
2478 struct policy_handle *handle)
2481 struct spoolss_ClosePrinter r;
2483 r.in.handle = handle;
2484 r.out.handle = handle;
2486 torture_comment(tctx, "Testing ClosePrinter\n");
2488 status = dcerpc_spoolss_ClosePrinter_r(b, tctx, &r);
2489 torture_assert_ntstatus_ok(tctx, status, "ClosePrinter failed");
2490 torture_assert_werr_ok(tctx, r.out.result, "ClosePrinter failed");
2495 static bool test_GetForm_args(struct torture_context *tctx,
2496 struct dcerpc_binding_handle *b,
2497 struct policy_handle *handle,
2498 const char *form_name,
2500 union spoolss_FormInfo *info_p)
2503 struct spoolss_GetForm r;
2506 r.in.handle = handle;
2507 r.in.form_name = form_name;
2511 r.out.needed = &needed;
2513 torture_comment(tctx, "Testing GetForm(%s) level %d\n", form_name, r.in.level);
2515 status = dcerpc_spoolss_GetForm_r(b, tctx, &r);
2516 torture_assert_ntstatus_ok(tctx, status, "GetForm failed");
2518 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
2519 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
2520 r.in.buffer = &blob;
2521 r.in.offered = needed;
2522 status = dcerpc_spoolss_GetForm_r(b, tctx, &r);
2523 torture_assert_ntstatus_ok(tctx, status, "GetForm failed");
2525 torture_assert_werr_ok(tctx, r.out.result, "GetForm failed");
2527 torture_assert(tctx, r.out.info, "No form info returned");
2530 torture_assert_werr_ok(tctx, r.out.result, "GetForm failed");
2532 CHECK_NEEDED_SIZE_LEVEL(spoolss_FormInfo, r.out.info, r.in.level, needed, 4);
2535 *info_p = *r.out.info;
2541 static bool test_GetForm(struct torture_context *tctx,
2542 struct dcerpc_binding_handle *b,
2543 struct policy_handle *handle,
2544 const char *form_name,
2547 return test_GetForm_args(tctx, b, handle, form_name, level, NULL);
2550 static bool test_EnumForms(struct torture_context *tctx,
2551 struct dcerpc_binding_handle *b,
2552 struct policy_handle *handle,
2556 union spoolss_FormInfo **info_p)
2558 struct spoolss_EnumForms r;
2561 union spoolss_FormInfo *info;
2563 r.in.handle = handle;
2567 r.out.needed = &needed;
2568 r.out.count = &count;
2571 torture_comment(tctx, "Testing EnumForms level %d\n", r.in.level);
2573 torture_assert_ntstatus_ok(tctx,
2574 dcerpc_spoolss_EnumForms_r(b, tctx, &r),
2575 "EnumForms failed");
2577 if ((r.in.level == 2) && (W_ERROR_EQUAL(r.out.result, WERR_UNKNOWN_LEVEL))) {
2578 torture_skip(tctx, "EnumForms level 2 not supported");
2581 if (print_server && W_ERROR_EQUAL(r.out.result, WERR_BADFID)) {
2582 torture_fail(tctx, "EnumForms on the PrintServer isn't supported by test server (NT4)");
2585 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
2586 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
2587 r.in.buffer = &blob;
2588 r.in.offered = needed;
2590 torture_assert_ntstatus_ok(tctx,
2591 dcerpc_spoolss_EnumForms_r(b, tctx, &r),
2592 "EnumForms failed");
2594 torture_assert(tctx, info, "No forms returned");
2597 torture_assert_werr_ok(tctx, r.out.result, "EnumForms failed");
2599 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumForms, info, r.in.level, count, needed, 4);
2611 static bool test_EnumForms_all(struct torture_context *tctx,
2612 struct dcerpc_binding_handle *b,
2613 struct policy_handle *handle,
2616 uint32_t levels[] = { 1, 2 };
2619 for (i=0; i<ARRAY_SIZE(levels); i++) {
2622 union spoolss_FormInfo *info = NULL;
2624 torture_assert(tctx,
2625 test_EnumForms(tctx, b, handle, print_server, levels[i], &count, &info),
2626 "failed to enum forms");
2628 for (j = 0; j < count; j++) {
2629 if (!print_server) {
2630 torture_assert(tctx,
2631 test_GetForm(tctx, b, handle, info[j].info1.form_name, levels[i]),
2632 "failed to get form");
2640 static bool test_EnumForms_find_one(struct torture_context *tctx,
2641 struct dcerpc_binding_handle *b,
2642 struct policy_handle *handle,
2644 const char *form_name)
2646 union spoolss_FormInfo *info;
2651 torture_assert(tctx,
2652 test_EnumForms(tctx, b, handle, print_server, 1, &count, &info),
2653 "failed to enumerate forms");
2655 for (i=0; i<count; i++) {
2656 if (strequal(form_name, info[i].info1.form_name)) {
2665 static bool test_DeleteForm(struct torture_context *tctx,
2666 struct dcerpc_binding_handle *b,
2667 struct policy_handle *handle,
2668 const char *form_name,
2669 WERROR expected_result)
2671 struct spoolss_DeleteForm r;
2673 r.in.handle = handle;
2674 r.in.form_name = form_name;
2676 torture_comment(tctx, "Testing DeleteForm(%s)\n", form_name);
2678 torture_assert_ntstatus_ok(tctx,
2679 dcerpc_spoolss_DeleteForm_r(b, tctx, &r),
2680 "DeleteForm failed");
2681 torture_assert_werr_equal(tctx, r.out.result, expected_result,
2682 "DeleteForm gave unexpected result");
2683 if (W_ERROR_IS_OK(r.out.result)) {
2684 torture_assert_ntstatus_ok(tctx,
2685 dcerpc_spoolss_DeleteForm_r(b, tctx, &r),
2686 "2nd DeleteForm failed");
2687 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_FORM_NAME,
2688 "2nd DeleteForm failed");
2694 static bool test_AddForm(struct torture_context *tctx,
2695 struct dcerpc_binding_handle *b,
2696 struct policy_handle *handle,
2698 union spoolss_AddFormInfo *info,
2699 WERROR expected_result)
2701 struct spoolss_AddForm r;
2702 struct spoolss_AddFormInfoCtr info_ctr;
2704 info_ctr.level = level;
2705 info_ctr.info = *info;
2708 torture_skip(tctx, "only level 1 supported");
2711 r.in.handle = handle;
2712 r.in.info_ctr = &info_ctr;
2714 torture_comment(tctx, "Testing AddForm(%s) level %d, type %d\n",
2715 r.in.info_ctr->info.info1->form_name, level,
2716 r.in.info_ctr->info.info1->flags);
2718 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_AddForm_r(b, tctx, &r),
2720 torture_assert_werr_equal(tctx, r.out.result, expected_result,
2721 "AddForm gave unexpected result");
2723 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_AddForm_r(b, tctx, &r),
2724 "2nd AddForm failed");
2725 if (W_ERROR_EQUAL(expected_result, WERR_INVALID_PARAM)) {
2726 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAM,
2727 "2nd AddForm gave unexpected result");
2729 torture_assert_werr_equal(tctx, r.out.result, WERR_FILE_EXISTS,
2730 "2nd AddForm gave unexpected result");
2736 static bool test_SetForm(struct torture_context *tctx,
2737 struct dcerpc_binding_handle *b,
2738 struct policy_handle *handle,
2739 const char *form_name,
2741 union spoolss_AddFormInfo *info)
2743 struct spoolss_SetForm r;
2744 struct spoolss_AddFormInfoCtr info_ctr;
2746 info_ctr.level = level;
2747 info_ctr.info = *info;
2749 r.in.handle = handle;
2750 r.in.form_name = form_name;
2751 r.in.info_ctr = &info_ctr;
2753 torture_comment(tctx, "Testing SetForm(%s) level %d\n",
2756 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_SetForm_r(b, tctx, &r),
2759 torture_assert_werr_ok(tctx, r.out.result,
2765 static bool test_GetForm_winreg(struct torture_context *tctx,
2766 struct dcerpc_binding_handle *b,
2767 struct policy_handle *handle,
2768 const char *key_name,
2769 const char *form_name,
2770 enum winreg_Type *w_type,
2775 static bool test_Forms_args(struct torture_context *tctx,
2776 struct dcerpc_binding_handle *b,
2777 struct policy_handle *handle,
2779 const char *printer_name,
2780 struct dcerpc_binding_handle *winreg_handle,
2781 struct policy_handle *hive_handle,
2782 const char *form_name,
2783 struct spoolss_AddFormInfo1 *info1,
2784 WERROR expected_add_result,
2785 WERROR expected_delete_result)
2787 union spoolss_FormInfo info;
2788 union spoolss_AddFormInfo add_info;
2790 enum winreg_Type w_type;
2795 add_info.info1 = info1;
2797 torture_assert(tctx,
2798 test_AddForm(tctx, b, handle, 1, &add_info, expected_add_result),
2799 "failed to add form");
2801 if (winreg_handle && hive_handle && W_ERROR_IS_OK(expected_add_result)) {
2803 struct spoolss_FormInfo1 i1;
2805 torture_assert(tctx,
2806 test_GetForm_winreg(tctx, winreg_handle, hive_handle, TOP_LEVEL_CONTROL_FORMS_KEY, form_name, &w_type, &w_size, &w_length, &w_data),
2807 "failed to get form via winreg");
2809 i1.size.width = IVAL(w_data, 0);
2810 i1.size.height = IVAL(w_data, 4);
2811 i1.area.left = IVAL(w_data, 8);
2812 i1.area.top = IVAL(w_data, 12);
2813 i1.area.right = IVAL(w_data, 16);
2814 i1.area.bottom = IVAL(w_data, 20);
2815 /* skip index here */
2816 i1.flags = IVAL(w_data, 28);
2818 torture_assert_int_equal(tctx, w_type, REG_BINARY, "unexpected type");
2819 torture_assert_int_equal(tctx, w_size, 0x20, "unexpected size");
2820 torture_assert_int_equal(tctx, w_length, 0x20, "unexpected length");
2821 torture_assert_int_equal(tctx, i1.size.width, add_info.info1->size.width, "width mismatch");
2822 torture_assert_int_equal(tctx, i1.size.height, add_info.info1->size.height, "height mismatch");
2823 torture_assert_int_equal(tctx, i1.area.left, add_info.info1->area.left, "left mismatch");
2824 torture_assert_int_equal(tctx, i1.area.top, add_info.info1->area.top, "top mismatch");
2825 torture_assert_int_equal(tctx, i1.area.right, add_info.info1->area.right, "right mismatch");
2826 torture_assert_int_equal(tctx, i1.area.bottom, add_info.info1->area.bottom, "bottom mismatch");
2827 torture_assert_int_equal(tctx, i1.flags, add_info.info1->flags, "flags mismatch");
2830 if (!print_server && W_ERROR_IS_OK(expected_add_result)) {
2831 torture_assert(tctx,
2832 test_GetForm_args(tctx, b, handle, form_name, 1, &info),
2833 "failed to get added form");
2835 torture_assert_int_equal(tctx, info.info1.size.width, add_info.info1->size.width, "width mismatch");
2836 torture_assert_int_equal(tctx, info.info1.size.height, add_info.info1->size.height, "height mismatch");
2837 torture_assert_int_equal(tctx, info.info1.area.left, add_info.info1->area.left, "left mismatch");
2838 torture_assert_int_equal(tctx, info.info1.area.top, add_info.info1->area.top, "top mismatch");
2839 torture_assert_int_equal(tctx, info.info1.area.right, add_info.info1->area.right, "right mismatch");
2840 torture_assert_int_equal(tctx, info.info1.area.bottom, add_info.info1->area.bottom, "bottom mismatch");
2841 torture_assert_int_equal(tctx, info.info1.flags, add_info.info1->flags, "flags mismatch");
2843 if (winreg_handle && hive_handle) {
2845 struct spoolss_FormInfo1 i1;
2847 i1.size.width = IVAL(w_data, 0);
2848 i1.size.height = IVAL(w_data, 4);
2849 i1.area.left = IVAL(w_data, 8);
2850 i1.area.top = IVAL(w_data, 12);
2851 i1.area.right = IVAL(w_data, 16);
2852 i1.area.bottom = IVAL(w_data, 20);
2853 /* skip index here */
2854 i1.flags = IVAL(w_data, 28);
2856 torture_assert_int_equal(tctx, i1.size.width, info.info1.size.width, "width mismatch");
2857 torture_assert_int_equal(tctx, i1.size.height, info.info1.size.height, "height mismatch");
2858 torture_assert_int_equal(tctx, i1.area.left, info.info1.area.left, "left mismatch");
2859 torture_assert_int_equal(tctx, i1.area.top, info.info1.area.top, "top mismatch");
2860 torture_assert_int_equal(tctx, i1.area.right, info.info1.area.right, "right mismatch");
2861 torture_assert_int_equal(tctx, i1.area.bottom, info.info1.area.bottom, "bottom mismatch");
2862 torture_assert_int_equal(tctx, i1.flags, info.info1.flags, "flags mismatch");
2865 add_info.info1->size.width = 1234;
2867 torture_assert(tctx,
2868 test_SetForm(tctx, b, handle, form_name, 1, &add_info),
2869 "failed to set form");
2870 torture_assert(tctx,
2871 test_GetForm_args(tctx, b, handle, form_name, 1, &info),
2872 "failed to get setted form");
2874 torture_assert_int_equal(tctx, info.info1.size.width, add_info.info1->size.width, "width mismatch");
2877 if (!W_ERROR_EQUAL(expected_add_result, WERR_INVALID_PARAM)) {
2878 torture_assert(tctx,
2879 test_EnumForms_find_one(tctx, b, handle, print_server, form_name),
2880 "Newly added form not found in enum call");
2883 torture_assert(tctx,
2884 test_DeleteForm(tctx, b, handle, form_name, expected_delete_result),
2885 "failed to delete form");
2890 static bool test_Forms(struct torture_context *tctx,
2891 struct dcerpc_binding_handle *b,
2892 struct policy_handle *handle,
2894 const char *printer_name,
2895 struct dcerpc_binding_handle *winreg_handle,
2896 struct policy_handle *hive_handle)
2898 const struct spoolss_FormSize size = {
2902 const struct spoolss_FormArea area = {
2911 struct spoolss_AddFormInfo1 info1;
2912 WERROR expected_add_result;
2913 WERROR expected_delete_result;
2917 .flags = SPOOLSS_FORM_USER,
2918 .form_name = "testform_user",
2922 .expected_add_result = WERR_OK,
2923 .expected_delete_result = WERR_OK
2926 weird, we can add a builtin form but we can never remove it
2931 .flags = SPOOLSS_FORM_BUILTIN,
2932 .form_name = "testform_builtin",
2936 .expected_add_result = WERR_OK,
2937 .expected_delete_result = WERR_INVALID_PARAM,
2942 .flags = SPOOLSS_FORM_PRINTER,
2943 .form_name = "testform_printer",
2947 .expected_add_result = WERR_OK,
2948 .expected_delete_result = WERR_OK
2952 .flags = SPOOLSS_FORM_USER,
2953 .form_name = "Letter",
2957 .expected_add_result = WERR_FILE_EXISTS,
2958 .expected_delete_result = WERR_INVALID_PARAM
2962 .flags = SPOOLSS_FORM_BUILTIN,
2963 .form_name = "Letter",
2967 .expected_add_result = WERR_FILE_EXISTS,
2968 .expected_delete_result = WERR_INVALID_PARAM
2972 .flags = SPOOLSS_FORM_PRINTER,
2973 .form_name = "Letter",
2977 .expected_add_result = WERR_FILE_EXISTS,
2978 .expected_delete_result = WERR_INVALID_PARAM
2983 .form_name = "invalid_flags",
2987 .expected_add_result = WERR_INVALID_PARAM,
2988 .expected_delete_result = WERR_INVALID_FORM_NAME
2993 for (i=0; i < ARRAY_SIZE(forms); i++) {
2994 torture_assert(tctx,
2995 test_Forms_args(tctx, b, handle, print_server, printer_name,
2996 winreg_handle, hive_handle,
2997 forms[i].info1.form_name,
2999 forms[i].expected_add_result,
3000 forms[i].expected_delete_result),
3001 talloc_asprintf(tctx, "failed to test form '%s'", forms[i].info1.form_name));
3007 static bool test_EnumPorts_old(struct torture_context *tctx,
3010 struct test_spoolss_context *ctx =
3011 talloc_get_type_abort(private_data, struct test_spoolss_context);
3014 struct spoolss_EnumPorts r;
3017 union spoolss_PortInfo *info;
3018 struct dcerpc_pipe *p = ctx->spoolss_pipe;
3019 struct dcerpc_binding_handle *b = p->binding_handle;
3021 r.in.servername = talloc_asprintf(tctx, "\\\\%s",
3022 dcerpc_server_name(p));
3026 r.out.needed = &needed;
3027 r.out.count = &count;
3030 torture_comment(tctx, "Testing EnumPorts\n");
3032 status = dcerpc_spoolss_EnumPorts_r(b, tctx, &r);
3034 torture_assert_ntstatus_ok(tctx, status, "EnumPorts failed");
3036 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
3037 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
3038 r.in.buffer = &blob;
3039 r.in.offered = needed;
3041 status = dcerpc_spoolss_EnumPorts_r(b, tctx, &r);
3042 torture_assert_ntstatus_ok(tctx, status, "EnumPorts failed");
3043 torture_assert_werr_ok(tctx, r.out.result, "EnumPorts failed");
3045 torture_assert(tctx, info, "No ports returned");
3048 torture_assert_werr_ok(tctx, r.out.result, "EnumPorts failed");
3050 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPorts, info, 2, count, needed, 4);
3055 static bool test_AddPort(struct torture_context *tctx,
3058 struct test_spoolss_context *ctx =
3059 talloc_get_type_abort(private_data, struct test_spoolss_context);
3062 struct spoolss_AddPort r;
3063 struct dcerpc_pipe *p = ctx->spoolss_pipe;
3064 struct dcerpc_binding_handle *b = p->binding_handle;
3066 r.in.server_name = talloc_asprintf(tctx, "\\\\%s",
3067 dcerpc_server_name(p));
3069 r.in.monitor_name = "foo";
3071 torture_comment(tctx, "Testing AddPort\n");
3073 status = dcerpc_spoolss_AddPort_r(b, tctx, &r);
3075 torture_assert_ntstatus_ok(tctx, status, "AddPort failed");
3077 /* win2k3 returns WERR_NOT_SUPPORTED */
3081 if (!W_ERROR_IS_OK(r.out.result)) {
3082 printf("AddPort failed - %s\n", win_errstr(r.out.result));
3091 static bool test_GetJob_args(struct torture_context *tctx,
3092 struct dcerpc_binding_handle *b,
3093 struct policy_handle *handle,
3096 union spoolss_JobInfo *info_p)
3099 struct spoolss_GetJob r;
3100 union spoolss_JobInfo info;
3103 r.in.handle = handle;
3104 r.in.job_id = job_id;
3108 r.out.needed = &needed;
3111 torture_comment(tctx, "Testing GetJob(%d), level %d\n", job_id, r.in.level);
3113 status = dcerpc_spoolss_GetJob_r(b, tctx, &r);
3114 torture_assert_ntstatus_ok(tctx, status, "GetJob failed");
3116 torture_assert_werr_equal(tctx, r.out.result, WERR_UNKNOWN_LEVEL, "Unexpected return code");
3119 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
3120 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
3121 r.in.buffer = &blob;
3122 r.in.offered = needed;
3124 status = dcerpc_spoolss_GetJob_r(b, tctx, &r);
3125 torture_assert_ntstatus_ok(tctx, status, "GetJob failed");
3128 torture_assert_werr_ok(tctx, r.out.result, "GetJob failed");
3129 torture_assert(tctx, r.out.info, "No job info returned");
3131 CHECK_NEEDED_SIZE_LEVEL(spoolss_JobInfo, r.out.info, r.in.level, needed, 4);
3134 *info_p = *r.out.info;
3141 static bool test_GetJob(struct torture_context *tctx,
3142 struct dcerpc_binding_handle *b,
3143 struct policy_handle *handle,
3146 uint32_t levels[] = {0, 1, 2 /* 3, 4 */};
3149 for (i=0; i < ARRAY_SIZE(levels); i++) {
3150 torture_assert(tctx,
3151 test_GetJob_args(tctx, b, handle, job_id, levels[i], NULL),
3159 static bool test_SetJob(struct torture_context *tctx,
3160 struct dcerpc_binding_handle *b,
3161 struct policy_handle *handle,
3163 struct spoolss_JobInfoContainer *ctr,
3164 enum spoolss_JobControl command)
3167 struct spoolss_SetJob r;
3169 r.in.handle = handle;
3170 r.in.job_id = job_id;
3172 r.in.command = command;
3175 case SPOOLSS_JOB_CONTROL_PAUSE:
3176 torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_PAUSE\n", job_id);
3178 case SPOOLSS_JOB_CONTROL_RESUME:
3179 torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_RESUME\n", job_id);
3181 case SPOOLSS_JOB_CONTROL_CANCEL:
3182 torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_CANCEL\n", job_id);
3184 case SPOOLSS_JOB_CONTROL_RESTART:
3185 torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_RESTART\n", job_id);
3187 case SPOOLSS_JOB_CONTROL_DELETE:
3188 torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_DELETE\n", job_id);
3190 case SPOOLSS_JOB_CONTROL_SEND_TO_PRINTER:
3191 torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_SEND_TO_PRINTER\n", job_id);
3193 case SPOOLSS_JOB_CONTROL_LAST_PAGE_EJECTED:
3194 torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_LAST_PAGE_EJECTED\n", job_id);
3196 case SPOOLSS_JOB_CONTROL_RETAIN:
3197 torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_RETAIN\n", job_id);
3199 case SPOOLSS_JOB_CONTROL_RELEASE:
3200 torture_comment(tctx, "Testing SetJob(%d), SPOOLSS_JOB_CONTROL_RELEASE\n", job_id);
3203 torture_comment(tctx, "Testing SetJob(%d)\n", job_id);
3207 status = dcerpc_spoolss_SetJob_r(b, tctx, &r);
3208 torture_assert_ntstatus_ok(tctx, status, "SetJob failed");
3209 torture_assert_werr_ok(tctx, r.out.result, "SetJob failed");
3214 static bool test_AddJob(struct torture_context *tctx,
3215 struct dcerpc_binding_handle *b,
3216 struct policy_handle *handle)
3219 struct spoolss_AddJob r;
3223 r.in.handle = handle;
3225 r.out.needed = &needed;
3226 r.in.buffer = r.out.buffer = NULL;
3228 torture_comment(tctx, "Testing AddJob\n");
3230 status = dcerpc_spoolss_AddJob_r(b, tctx, &r);
3231 torture_assert_ntstatus_ok(tctx, status, "AddJob failed");
3232 torture_assert_werr_equal(tctx, r.out.result, WERR_UNKNOWN_LEVEL, "AddJob failed");
3236 status = dcerpc_spoolss_AddJob_r(b, tctx, &r);
3237 torture_assert_ntstatus_ok(tctx, status, "AddJob failed");
3238 torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_PARAM, "AddJob failed");
3244 static bool test_EnumJobs_args(struct torture_context *tctx,
3245 struct dcerpc_binding_handle *b,
3246 struct policy_handle *handle,
3249 union spoolss_JobInfo **info_p)
3252 struct spoolss_EnumJobs r;
3255 union spoolss_JobInfo *info;
3257 r.in.handle = handle;
3259 r.in.numjobs = 0xffffffff;
3263 r.out.needed = &needed;
3264 r.out.count = &count;
3267 torture_comment(tctx, "Testing EnumJobs level %d\n", level);
3269 status = dcerpc_spoolss_EnumJobs_r(b, tctx, &r);
3271 torture_assert_ntstatus_ok(tctx, status, "EnumJobs failed");
3273 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
3274 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
3275 r.in.buffer = &blob;
3276 r.in.offered = needed;
3278 status = dcerpc_spoolss_EnumJobs_r(b, tctx, &r);
3280 torture_assert_ntstatus_ok(tctx, status, "EnumJobs failed");
3281 torture_assert_werr_ok(tctx, r.out.result, "EnumJobs failed");
3282 torture_assert(tctx, info, "No jobs returned");
3284 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumJobs, *r.out.info, r.in.level, count, needed, 4);
3287 torture_assert_werr_ok(tctx, r.out.result, "EnumJobs failed");
3300 static bool test_JobPropertiesEnum(struct torture_context *tctx,
3301 struct dcerpc_binding_handle *b,
3302 struct policy_handle *handle,
3305 struct spoolss_RpcEnumJobNamedProperties r;
3306 uint32_t pcProperties = 0;
3307 struct RPC_PrintNamedProperty *ppProperties = NULL;
3309 r.in.hPrinter = handle;
3310 r.in.JobId = job_id;
3311 r.out.pcProperties = &pcProperties;
3312 r.out.ppProperties = &ppProperties;
3314 torture_comment(tctx, "Testing RpcEnumJobNamedProperties(%d)\n", job_id);
3316 torture_assert_ntstatus_ok(tctx,
3317 dcerpc_spoolss_RpcEnumJobNamedProperties_r(b, tctx, &r),
3318 "spoolss_RpcEnumJobNamedProperties failed");
3319 torture_assert_werr_ok(tctx, r.out.result,
3320 "spoolss_RpcEnumJobNamedProperties failed");
3325 static bool test_JobPropertySet(struct torture_context *tctx,
3326 struct dcerpc_binding_handle *b,
3327 struct policy_handle *handle,
3329 struct RPC_PrintNamedProperty *property)
3331 struct spoolss_RpcSetJobNamedProperty r;
3333 r.in.hPrinter = handle;
3334 r.in.JobId = job_id;
3335 r.in.pProperty = property;
3337 torture_comment(tctx, "Testing RpcSetJobNamedProperty(%d) %s - %d\n",
3338 job_id, property->propertyName,
3339 property->propertyValue.ePropertyType);
3341 torture_assert_ntstatus_ok(tctx,
3342 dcerpc_spoolss_RpcSetJobNamedProperty_r(b, tctx, &r),
3343 "spoolss_RpcSetJobNamedProperty failed");
3344 torture_assert_werr_ok(tctx, r.out.result,
3345 "spoolss_RpcSetJobNamedProperty failed");
3350 static bool test_JobPropertyGetValue(struct torture_context *tctx,
3351 struct dcerpc_binding_handle *b,
3352 struct policy_handle *handle,
3354 const char *property_name,
3355 struct RPC_PrintPropertyValue *value)
3357 struct spoolss_RpcGetJobNamedPropertyValue r;
3359 r.in.hPrinter = handle;
3360 r.in.JobId = job_id;
3361 r.in.pszName = property_name;
3362 r.out.pValue = value;
3364 torture_comment(tctx, "Testing RpcGetJobNamedPropertyValue(%d) %s\n",
3365 job_id, property_name);
3367 torture_assert_ntstatus_ok(tctx,
3368 dcerpc_spoolss_RpcGetJobNamedPropertyValue_r(b, tctx, &r),
3369 "spoolss_RpcGetJobNamedPropertyValue failed");
3370 torture_assert_werr_ok(tctx, r.out.result,
3371 "spoolss_RpcGetJobNamedPropertyValue failed");
3376 static bool test_JobPropertyDelete(struct torture_context *tctx,
3377 struct dcerpc_binding_handle *b,
3378 struct policy_handle *handle,
3380 const char *property_name)
3382 struct spoolss_RpcDeleteJobNamedProperty r;
3384 r.in.hPrinter = handle;
3385 r.in.JobId = job_id;
3386 r.in.pszName = property_name;
3388 torture_comment(tctx, "Testing RpcDeleteJobNamedProperty(%d) %s\n",
3389 job_id, property_name);
3391 torture_assert_ntstatus_ok(tctx,
3392 dcerpc_spoolss_RpcDeleteJobNamedProperty_r(b, tctx, &r),
3393 "spoolss_RpcDeleteJobNamedProperty failed");
3394 torture_assert_werr_ok(tctx, r.out.result,
3395 "spoolss_RpcDeleteJobNamedProperty failed");
3400 static bool test_DoPrintTest_add_one_job_common(struct torture_context *tctx,
3401 struct dcerpc_binding_handle *b,
3402 struct policy_handle *handle,
3403 const char *document_name,
3404 const char *datatype,
3408 struct spoolss_StartDocPrinter s;
3409 struct spoolss_DocumentInfoCtr info_ctr;
3410 struct spoolss_DocumentInfo1 info1;
3411 struct spoolss_StartPagePrinter sp;
3412 struct spoolss_WritePrinter w;
3413 struct spoolss_EndPagePrinter ep;
3414 struct spoolss_EndDocPrinter e;
3416 uint32_t num_written;
3418 torture_comment(tctx, "Testing StartDocPrinter\n");
3420 s.in.handle = handle;
3421 s.in.info_ctr = &info_ctr;
3422 s.out.job_id = job_id;
3424 info1.document_name = document_name;
3425 info1.output_file = NULL;
3426 info1.datatype = datatype;
3429 info_ctr.info.info1 = &info1;
3431 status = dcerpc_spoolss_StartDocPrinter_r(b, tctx, &s);
3432 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_StartDocPrinter failed");
3433 torture_assert_werr_ok(tctx, s.out.result, "StartDocPrinter failed");
3435 for (i=1; i < 4; i++) {
3436 torture_comment(tctx, "Testing StartPagePrinter: Page[%d], JobId[%d]\n", i, *job_id);
3438 sp.in.handle = handle;
3440 status = dcerpc_spoolss_StartPagePrinter_r(b, tctx, &sp);
3441 torture_assert_ntstatus_ok(tctx, status,
3442 "dcerpc_spoolss_StartPagePrinter failed");
3443 torture_assert_werr_ok(tctx, sp.out.result, "StartPagePrinter failed");
3445 torture_comment(tctx, "Testing WritePrinter: Page[%d], JobId[%d]\n", i, *job_id);
3447 w.in.handle = handle;
3448 w.in.data = data_blob_string_const(talloc_asprintf(tctx,"TortureTestPage: %d\nData\n",i));
3449 w.out.num_written = &num_written;
3451 status = dcerpc_spoolss_WritePrinter_r(b, tctx, &w);
3452 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_WritePrinter failed");
3453 torture_assert_werr_ok(tctx, w.out.result, "WritePrinter failed");
3455 torture_comment(tctx, "Testing EndPagePrinter: Page[%d], JobId[%d]\n", i, *job_id);
3457 ep.in.handle = handle;
3459 status = dcerpc_spoolss_EndPagePrinter_r(b, tctx, &ep);
3460 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EndPagePrinter failed");
3461 torture_assert_werr_ok(tctx, ep.out.result, "EndPagePrinter failed");
3464 torture_comment(tctx, "Testing EndDocPrinter: JobId[%d]\n", *job_id);
3466 e.in.handle = handle;
3468 status = dcerpc_spoolss_EndDocPrinter_r(b, tctx, &e);
3469 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EndDocPrinter failed");
3470 torture_assert_werr_ok(tctx, e.out.result, "EndDocPrinter failed");
3475 static bool test_DoPrintTest_add_one_job(struct torture_context *tctx,
3476 struct dcerpc_binding_handle *b,
3477 struct policy_handle *handle,
3478 const char *document_name,
3481 test_DoPrintTest_add_one_job_common(tctx, b, handle, document_name, "RAW", job_id);
3486 static bool test_DoPrintTest_add_one_job_v4(struct torture_context *tctx,
3487 struct dcerpc_binding_handle *b,
3488 struct policy_handle *handle,
3489 const char *document_name,
3492 test_DoPrintTest_add_one_job_common(tctx, b, handle, document_name, "XPS_PASS", job_id);
3498 static bool test_DoPrintTest_check_jobs(struct torture_context *tctx,
3499 struct dcerpc_binding_handle *b,
3500 struct policy_handle *handle,
3505 union spoolss_JobInfo *info = NULL;
3508 torture_assert(tctx,
3509 test_AddJob(tctx, b, handle),
3512 torture_assert(tctx,
3513 test_EnumJobs_args(tctx, b, handle, 1, &count, &info),
3514 "EnumJobs level 1 failed");
3516 torture_assert_int_equal(tctx, count, num_jobs, "unexpected number of jobs in queue");
3518 for (i=0; i < num_jobs; i++) {
3519 union spoolss_JobInfo ginfo;
3520 const char *document_name;
3521 const char *new_document_name = "any_other_docname";
3522 struct spoolss_JobInfoContainer ctr;
3523 struct spoolss_SetJobInfo1 info1;
3525 torture_assert_int_equal(tctx, info[i].info1.job_id, job_ids[i], "job id mismatch");
3527 torture_assert(tctx,
3528 test_GetJob_args(tctx, b, handle, info[i].info1.job_id, 1, &ginfo),
3529 "failed to call test_GetJob");
3531 torture_assert_int_equal(tctx, ginfo.info1.job_id, info[i].info1.job_id, "job id mismatch");
3533 document_name = ginfo.info1.document_name;
3535 info1.job_id = ginfo.info1.job_id;
3536 info1.printer_name = ginfo.info1.printer_name;
3537 info1.server_name = ginfo.info1.server_name;
3538 info1.user_name = ginfo.info1.user_name;
3539 info1.document_name = new_document_name;
3540 info1.data_type = ginfo.info1.data_type;
3541 info1.text_status = ginfo.info1.text_status;
3542 info1.status = ginfo.info1.status;
3543 info1.priority = ginfo.info1.priority;
3544 info1.position = ginfo.info1.position;
3545 info1.total_pages = ginfo.info1.total_pages;
3546 info1.pages_printed = ginfo.info1.pages_printed;
3547 info1.submitted = ginfo.info1.submitted;
3550 ctr.info.info1 = &info1;
3552 torture_assert(tctx,
3553 test_SetJob(tctx, b, handle, info[i].info1.job_id, &ctr, 0),
3554 "failed to call test_SetJob level 1");
3556 torture_assert(tctx,
3557 test_GetJob_args(tctx, b, handle, info[i].info1.job_id, 1, &ginfo),
3558 "failed to call test_GetJob");
3560 if (strequal(ginfo.info1.document_name, document_name)) {
3561 torture_warning(tctx,
3562 "document_name did *NOT* change from '%s' to '%s'\n",
3563 document_name, new_document_name);
3567 for (i=0; i < num_jobs; i++) {
3568 if (!test_SetJob(tctx, b, handle, info[i].info1.job_id, NULL, SPOOLSS_JOB_CONTROL_PAUSE)) {
3569 torture_warning(tctx, "failed to pause printjob\n");
3571 if (!test_SetJob(tctx, b, handle, info[i].info1.job_id, NULL, SPOOLSS_JOB_CONTROL_RESUME)) {
3572 torture_warning(tctx, "failed to resume printjob\n");
3579 static bool test_DoPrintTest(struct torture_context *tctx,
3580 struct dcerpc_binding_handle *b,
3581 struct policy_handle *handle)
3584 uint32_t num_jobs = 8;
3588 torture_comment(tctx, "Testing real print operations\n");
3590 job_ids = talloc_zero_array(tctx, uint32_t, num_jobs);
3592 for (i=0; i < num_jobs; i++) {
3593 ret &= test_DoPrintTest_add_one_job(tctx, b, handle, "TorturePrintJob", &job_ids[i]);
3596 for (i=0; i < num_jobs; i++) {
3597 ret &= test_SetJob(tctx, b, handle, job_ids[i], NULL, SPOOLSS_JOB_CONTROL_DELETE);
3600 for (i=0; i < num_jobs; i++) {
3601 ret &= test_DoPrintTest_add_one_job_v4(tctx, b, handle, "TorturePrintJob v4", &job_ids[i]);
3604 for (i=0; i < num_jobs; i++) {
3605 ret &= test_SetJob(tctx, b, handle, job_ids[i], NULL, SPOOLSS_JOB_CONTROL_DELETE);
3609 torture_comment(tctx, "real print operations test succeeded\n\n");
3615 static bool test_DoPrintTest_extended(struct torture_context *tctx,
3616 struct dcerpc_binding_handle *b,
3617 struct policy_handle *handle)
3620 uint32_t num_jobs = 8;
3623 torture_comment(tctx, "Testing real print operations (extended)\n");
3625 job_ids = talloc_zero_array(tctx, uint32_t, num_jobs);
3627 for (i=0; i < num_jobs; i++) {
3628 ret &= test_DoPrintTest_add_one_job(tctx, b, handle, "TorturePrintJob", &job_ids[i]);
3631 ret &= test_DoPrintTest_check_jobs(tctx, b, handle, num_jobs, job_ids);
3633 for (i=0; i < num_jobs; i++) {
3634 ret &= test_SetJob(tctx, b, handle, job_ids[i], NULL, SPOOLSS_JOB_CONTROL_DELETE);
3638 torture_comment(tctx, "real print operations (extended) test succeeded\n\n");
3644 static bool test_JobPrintProperties_equal(struct torture_context *tctx,
3645 struct RPC_PrintPropertyValue *got,
3646 struct RPC_PrintNamedProperty *exp)
3648 torture_assert_int_equal(tctx,
3650 exp->propertyValue.ePropertyType,
3653 switch (exp->propertyValue.ePropertyType) {
3654 case kRpcPropertyTypeString:
3655 torture_assert_str_equal(tctx,
3656 got->value.propertyString,
3657 exp->propertyValue.value.propertyString,
3660 case kRpcPropertyTypeInt32:
3661 torture_assert_int_equal(tctx,
3662 got->value.propertyInt32,
3663 exp->propertyValue.value.propertyInt32,
3666 case kRpcPropertyTypeInt64:
3667 torture_assert_u64_equal(tctx,
3668 got->value.propertyInt64,
3669 exp->propertyValue.value.propertyInt64,
3672 case kRpcPropertyTypeByte:
3673 torture_assert_int_equal(tctx,
3674 got->value.propertyByte,
3675 exp->propertyValue.value.propertyByte,
3678 case kRpcPropertyTypeBuffer:
3679 torture_assert_int_equal(tctx,
3680 got->value.propertyBlob.cbBuf,
3681 exp->propertyValue.value.propertyBlob.cbBuf,
3682 "propertyBlob.cbBuf");
3683 torture_assert_mem_equal(tctx,
3684 got->value.propertyBlob.pBuf,
3685 exp->propertyValue.value.propertyBlob.pBuf,
3686 exp->propertyValue.value.propertyBlob.cbBuf,
3687 "propertyBlob.pBuf");
3696 static bool test_JobPrintProperties(struct torture_context *tctx,
3697 struct dcerpc_binding_handle *b,
3698 struct policy_handle *handle,
3701 struct RPC_PrintNamedProperty in;
3702 struct RPC_PrintPropertyValue out;
3704 DATA_BLOB blob = data_blob_string_const("blob");
3706 const char *property_name;
3707 enum RPC_EPrintPropertyType type;
3708 union RPC_PrintPropertyValueUnion value;
3709 WERROR expected_result;
3712 .property_name = "torture_property_string",
3713 .type = kRpcPropertyTypeString,
3714 .value.propertyString = "torture_property_value_string",
3716 .property_name = "torture_property_int32",
3717 .type = kRpcPropertyTypeInt32,
3718 .value.propertyInt32 = 42,
3720 .property_name = "torture_property_int64",
3721 .type = kRpcPropertyTypeInt64,
3722 .value.propertyInt64 = 0xaffe,
3724 .property_name = "torture_property_byte",
3725 .type = kRpcPropertyTypeByte,
3726 .value.propertyByte = 0xab,
3728 .property_name = "torture_property_buffer",
3729 .type = kRpcPropertyTypeBuffer,
3730 .value.propertyBlob.cbBuf = blob.length,
3731 .value.propertyBlob.pBuf = blob.data,
3735 torture_assert(tctx,
3736 test_JobPropertiesEnum(tctx, b, handle, job_id),
3737 "failed to enum properties");
3739 for (i=0; i <ARRAY_SIZE(tests); i++) {
3741 in.propertyName = tests[i].property_name;
3742 in.propertyValue.ePropertyType = tests[i].type;
3743 in.propertyValue.value = tests[i].value;
3745 torture_assert(tctx,
3746 test_JobPropertySet(tctx, b, handle, job_id, &in),
3747 "failed to set property");
3749 torture_assert(tctx,
3750 test_JobPropertyGetValue(tctx, b, handle, job_id, in.propertyName, &out),
3751 "failed to get property");
3753 torture_assert(tctx,
3754 test_JobPrintProperties_equal(tctx, &out, &in),
3755 "property unequal");
3757 torture_assert(tctx,
3758 test_JobPropertiesEnum(tctx, b, handle, job_id),
3759 "failed to enum properties");
3761 torture_assert(tctx,
3762 test_JobPropertyDelete(tctx, b, handle, job_id, in.propertyName),
3763 "failed to delete job property");
3766 torture_assert(tctx,
3767 test_JobPropertiesEnum(tctx, b, handle, job_id),
3768 "failed to enum properties");
3773 static bool test_DoPrintTest_properties(struct torture_context *tctx,
3774 struct dcerpc_binding_handle *b,
3775 struct policy_handle *handle)
3777 uint32_t num_jobs = 8;
3780 torture_comment(tctx, "Testing real print operations (properties)\n");
3782 job_ids = talloc_zero_array(tctx, uint32_t, num_jobs);
3784 for (i=0; i < num_jobs; i++) {
3785 torture_assert(tctx,
3786 test_DoPrintTest_add_one_job(tctx, b, handle, "TorturePrintJob", &job_ids[i]),
3787 "failed to create print job");
3790 for (i=0; i < num_jobs; i++) {
3791 torture_assert(tctx,
3792 test_JobPrintProperties(tctx, b, handle, job_ids[i]),
3793 "failed to test job properties");
3797 for (i=0; i < num_jobs; i++) {
3798 torture_assert(tctx,
3799 test_SetJob(tctx, b, handle, job_ids[i], NULL, SPOOLSS_JOB_CONTROL_DELETE),
3800 "failed to delete printjob");
3803 torture_comment(tctx, "real print operations (properties) test succeeded\n\n");
3808 static bool test_PausePrinter(struct torture_context *tctx,
3809 struct dcerpc_binding_handle *b,
3810 struct policy_handle *handle)
3813 struct spoolss_SetPrinter r;
3814 struct spoolss_SetPrinterInfoCtr info_ctr;
3815 struct spoolss_DevmodeContainer devmode_ctr;
3816 struct sec_desc_buf secdesc_ctr;
3819 info_ctr.info.info0 = NULL;
3821 ZERO_STRUCT(devmode_ctr);
3822 ZERO_STRUCT(secdesc_ctr);
3824 r.in.handle = handle;
3825 r.in.info_ctr = &info_ctr;
3826 r.in.devmode_ctr = &devmode_ctr;
3827 r.in.secdesc_ctr = &secdesc_ctr;
3828 r.in.command = SPOOLSS_PRINTER_CONTROL_PAUSE;
3830 torture_comment(tctx, "Testing SetPrinter: SPOOLSS_PRINTER_CONTROL_PAUSE\n");
3832 status = dcerpc_spoolss_SetPrinter_r(b, tctx, &r);
3834 torture_assert_ntstatus_ok(tctx, status, "SetPrinter failed");
3836 torture_assert_werr_ok(tctx, r.out.result, "SetPrinter failed");
3841 static bool test_ResumePrinter(struct torture_context *tctx,
3842 struct dcerpc_binding_handle *b,
3843 struct policy_handle *handle)
3846 struct spoolss_SetPrinter r;
3847 struct spoolss_SetPrinterInfoCtr info_ctr;
3848 struct spoolss_DevmodeContainer devmode_ctr;
3849 struct sec_desc_buf secdesc_ctr;
3852 info_ctr.info.info0 = NULL;
3854 ZERO_STRUCT(devmode_ctr);
3855 ZERO_STRUCT(secdesc_ctr);
3857 r.in.handle = handle;
3858 r.in.info_ctr = &info_ctr;
3859 r.in.devmode_ctr = &devmode_ctr;
3860 r.in.secdesc_ctr = &secdesc_ctr;
3861 r.in.command = SPOOLSS_PRINTER_CONTROL_RESUME;
3863 torture_comment(tctx, "Testing SetPrinter: SPOOLSS_PRINTER_CONTROL_RESUME\n");
3865 status = dcerpc_spoolss_SetPrinter_r(b, tctx, &r);
3867 torture_assert_ntstatus_ok(tctx, status, "SetPrinter failed");
3869 torture_assert_werr_ok(tctx, r.out.result, "SetPrinter failed");
3874 static bool test_GetPrinterData_checktype(struct torture_context *tctx,
3875 struct dcerpc_binding_handle *b,
3876 struct policy_handle *handle,
3877 const char *value_name,
3878 enum winreg_Type *expected_type,
3879 enum winreg_Type *type_p,
3884 struct spoolss_GetPrinterData r;
3886 enum winreg_Type type;
3887 union spoolss_PrinterData data;
3889 r.in.handle = handle;
3890 r.in.value_name = value_name;
3892 r.out.needed = &needed;
3894 r.out.data = talloc_zero_array(tctx, uint8_t, r.in.offered);
3896 torture_comment(tctx, "Testing GetPrinterData(%s)\n", r.in.value_name);
3898 status = dcerpc_spoolss_GetPrinterData_r(b, tctx, &r);
3899 torture_assert_ntstatus_ok(tctx, status, "GetPrinterData failed");
3901 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
3902 if (expected_type) {
3903 torture_assert_int_equal(tctx, type, *expected_type, "unexpected type");
3905 r.in.offered = needed;
3906 r.out.data = talloc_zero_array(tctx, uint8_t, r.in.offered);
3907 status = dcerpc_spoolss_GetPrinterData_r(b, tctx, &r);
3908 torture_assert_ntstatus_ok(tctx, status, "GetPrinterData failed");
3911 torture_assert_werr_ok(tctx, r.out.result,
3912 talloc_asprintf(tctx, "GetPrinterData(%s) failed", r.in.value_name));
3914 CHECK_NEEDED_SIZE_LEVEL(spoolss_PrinterData, &data, type, needed, 1);
3921 *data_p = r.out.data;
3931 static bool test_GetPrinterData(struct torture_context *tctx,
3932 struct dcerpc_binding_handle *b,
3933 struct policy_handle *handle,
3934 const char *value_name,
3935 enum winreg_Type *type_p,
3939 return test_GetPrinterData_checktype(tctx, b, handle, value_name,
3940 NULL, type_p, data_p, needed_p);
3943 static bool test_GetPrinterDataEx_checktype(struct torture_context *tctx,
3944 struct dcerpc_pipe *p,
3945 struct policy_handle *handle,
3946 const char *key_name,
3947 const char *value_name,
3948 enum winreg_Type *expected_type,
3949 enum winreg_Type *type_p,
3954 struct spoolss_GetPrinterDataEx r;
3955 enum winreg_Type type;
3957 union spoolss_PrinterData data;
3958 struct dcerpc_binding_handle *b = p->binding_handle;
3960 r.in.handle = handle;
3961 r.in.key_name = key_name;
3962 r.in.value_name = value_name;
3965 r.out.needed = &needed;
3966 r.out.data = talloc_zero_array(tctx, uint8_t, r.in.offered);
3968 torture_comment(tctx, "Testing GetPrinterDataEx(%s - %s)\n",
3969 r.in.key_name, r.in.value_name);
3971 status = dcerpc_spoolss_GetPrinterDataEx_r(b, tctx, &r);
3972 if (!NT_STATUS_IS_OK(status)) {
3973 if (NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROCNUM_OUT_OF_RANGE)) {
3974 torture_skip(tctx, "GetPrinterDataEx not supported by server\n");
3976 torture_assert_ntstatus_ok(tctx, status, "GetPrinterDataEx failed");
3979 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
3980 if (expected_type) {
3981 torture_assert_int_equal(tctx, type, *expected_type, "unexpected type");
3983 r.in.offered = needed;
3984 r.out.data = talloc_zero_array(tctx, uint8_t, r.in.offered);
3985 status = dcerpc_spoolss_GetPrinterDataEx_r(b, tctx, &r);
3986 torture_assert_ntstatus_ok(tctx, status, "GetPrinterDataEx failed");
3989 torture_assert_werr_ok(tctx, r.out.result,
3990 talloc_asprintf(tctx, "GetPrinterDataEx(%s - %s) failed", r.in.key_name, r.in.value_name));
3992 CHECK_NEEDED_SIZE_LEVEL(spoolss_PrinterData, &data, type, needed, 1);
3999 *data_p = r.out.data;
4009 static bool test_GetPrinterDataEx(struct torture_context *tctx,
4010 struct dcerpc_pipe *p,
4011 struct policy_handle *handle,
4012 const char *key_name,
4013 const char *value_name,
4014 enum winreg_Type *type_p,
4018 return test_GetPrinterDataEx_checktype(tctx, p, handle, key_name, value_name,
4019 NULL, type_p, data_p, needed_p);
4022 static bool test_get_environment(struct torture_context *tctx,
4023 struct dcerpc_binding_handle *b,
4024 struct policy_handle *handle,
4025 const char **architecture)
4028 enum winreg_Type type;
4032 torture_assert(tctx,
4033 test_GetPrinterData(tctx, b, handle, "Architecture", &type, &data, &needed),
4034 "failed to get Architecture");
4036 torture_assert_int_equal(tctx, type, REG_SZ, "unexpected type");
4038 blob = data_blob_const(data, needed);
4039 *architecture = reg_val_data_string(tctx, REG_SZ, blob);
4044 static bool test_GetPrinterData_list(struct torture_context *tctx,
4047 struct test_spoolss_context *ctx =
4048 talloc_get_type_abort(private_data, struct test_spoolss_context);
4049 struct dcerpc_pipe *p = ctx->spoolss_pipe;
4050 struct dcerpc_binding_handle *b = p->binding_handle;
4051 const char *list[] = {
4055 /* "NetPopup", not on w2k8 */
4056 /* "NetPopupToComputer", not on w2k8 */
4059 "DefaultSpoolDirectory",
4063 /* "OSVersionEx", not on s3 */
4068 for (i=0; i < ARRAY_SIZE(list); i++) {
4069 enum winreg_Type type, type_ex;
4070 uint8_t *data, *data_ex;
4071 uint32_t needed, needed_ex;
4073 torture_assert(tctx, test_GetPrinterData(tctx, b, &ctx->server_handle, list[i], &type, &data, &needed),
4074 talloc_asprintf(tctx, "GetPrinterData failed on %s\n", list[i]));
4075 torture_assert(tctx, test_GetPrinterDataEx(tctx, p, &ctx->server_handle, "random_string", list[i], &type_ex, &data_ex, &needed_ex),
4076 talloc_asprintf(tctx, "GetPrinterDataEx failed on %s\n", list[i]));
4077 torture_assert_int_equal(tctx, type, type_ex, "type mismatch");
4078 torture_assert_int_equal(tctx, needed, needed_ex, "needed mismatch");
4079 torture_assert_mem_equal(tctx, data, data_ex, needed, "data mismatch");
4085 static bool test_EnumPrinterData(struct torture_context *tctx,
4086 struct dcerpc_pipe *p,
4087 struct policy_handle *handle,
4088 uint32_t enum_index,
4089 uint32_t value_offered,
4090 uint32_t data_offered,
4091 enum winreg_Type *type_p,
4092 uint32_t *value_needed_p,
4093 uint32_t *data_needed_p,
4094 const char **value_name_p,
4098 struct spoolss_EnumPrinterData r;
4099 uint32_t data_needed;
4100 uint32_t value_needed;
4101 enum winreg_Type type;
4102 struct dcerpc_binding_handle *b = p->binding_handle;
4104 r.in.handle = handle;
4105 r.in.enum_index = enum_index;
4106 r.in.value_offered = value_offered;
4107 r.in.data_offered = data_offered;
4108 r.out.data_needed = &data_needed;
4109 r.out.value_needed = &value_needed;
4111 r.out.data = talloc_zero_array(tctx, uint8_t, r.in.data_offered);
4112 r.out.value_name = talloc_zero_array(tctx, const char, r.in.value_offered);
4114 torture_comment(tctx, "Testing EnumPrinterData(%d)\n", enum_index);
4116 torture_assert_ntstatus_ok(tctx,
4117 dcerpc_spoolss_EnumPrinterData_r(b, tctx, &r),
4118 "EnumPrinterData failed");
4123 if (value_needed_p) {
4124 *value_needed_p = value_needed;
4126 if (data_needed_p) {
4127 *data_needed_p = data_needed;
4130 *value_name_p = r.out.value_name;
4133 *data_p = r.out.data;
4136 *result_p = r.out.result;
4143 static bool test_EnumPrinterData_all(struct torture_context *tctx,
4144 struct dcerpc_pipe *p,
4145 struct policy_handle *handle)
4147 uint32_t enum_index = 0;
4148 enum winreg_Type type;
4149 uint32_t value_needed;
4150 uint32_t data_needed;
4152 const char *value_name;
4155 torture_comment(tctx, "Testing EnumPrinterData\n");
4158 torture_assert(tctx,
4159 test_EnumPrinterData(tctx, p, handle, enum_index, 0, 0,
4160 &type, &value_needed, &data_needed,
4161 &value_name, &data, &result),
4162 "EnumPrinterData failed");
4164 if (W_ERROR_EQUAL(result, WERR_NO_MORE_ITEMS)) {
4168 torture_assert(tctx,
4169 test_EnumPrinterData(tctx, p, handle, enum_index, value_needed, data_needed,
4170 &type, &value_needed, &data_needed,
4171 &value_name, &data, &result),
4172 "EnumPrinterData failed");
4174 if (W_ERROR_EQUAL(result, WERR_NO_MORE_ITEMS)) {
4180 } while (W_ERROR_IS_OK(result));
4182 torture_comment(tctx, "EnumPrinterData test succeeded\n");
4187 static bool test_EnumPrinterDataEx(struct torture_context *tctx,
4188 struct dcerpc_binding_handle *b,
4189 struct policy_handle *handle,
4190 const char *key_name,
4192 struct spoolss_PrinterEnumValues **info_p)
4194 struct spoolss_EnumPrinterDataEx r;
4195 struct spoolss_PrinterEnumValues *info;
4199 r.in.handle = handle;
4200 r.in.key_name = key_name;
4202 r.out.needed = &needed;
4203 r.out.count = &count;
4206 torture_comment(tctx, "Testing EnumPrinterDataEx(%s)\n", key_name);
4208 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinterDataEx_r(b, tctx, &r),
4209 "EnumPrinterDataEx failed");
4210 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
4211 r.in.offered = needed;
4212 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinterDataEx_r(b, tctx, &r),
4213 "EnumPrinterDataEx failed");
4216 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinterDataEx failed");
4218 CHECK_NEEDED_SIZE_ENUM(spoolss_EnumPrinterDataEx, info, count, needed, 1);
4230 static bool test_SetPrinterData(struct torture_context *tctx,
4231 struct dcerpc_binding_handle *b,
4232 struct policy_handle *handle,
4233 const char *value_name,
4234 enum winreg_Type type,
4237 static bool test_DeletePrinterData(struct torture_context *tctx,
4238 struct dcerpc_binding_handle *b,
4239 struct policy_handle *handle,
4240 const char *value_name);
4242 static bool test_EnumPrinterData_consistency(struct torture_context *tctx,
4243 struct dcerpc_pipe *p,
4244 struct policy_handle *handle)
4247 struct spoolss_PrinterEnumValues *info;
4249 uint32_t value_needed, data_needed;
4250 uint32_t value_offered, data_offered;
4252 struct dcerpc_binding_handle *b = p->binding_handle;
4254 enum winreg_Type type;
4257 torture_comment(tctx, "Testing EnumPrinterData vs EnumPrinterDataEx consistency\n");
4259 torture_assert(tctx, push_reg_sz(tctx, &blob, "torture_data1"), "");
4262 torture_assert(tctx,
4263 test_SetPrinterData(tctx, b, handle, "torture_value1", type, blob.data, blob.length),
4264 "SetPrinterData failed");
4266 blob = data_blob_string_const("torture_data2");
4268 torture_assert(tctx,
4269 test_SetPrinterData(tctx, b, handle, "torture_value2", REG_BINARY, blob.data, blob.length),
4270 "SetPrinterData failed");
4272 blob = data_blob_talloc(tctx, NULL, 4);
4273 SIVAL(blob.data, 0, 0x11223344);
4275 torture_assert(tctx,
4276 test_SetPrinterData(tctx, b, handle, "torture_value3", type, blob.data, blob.length),
4277 "SetPrinterData failed");
4279 torture_assert(tctx,
4280 test_EnumPrinterDataEx(tctx, b, handle, "PrinterDriverData", &count, &info),
4281 "failed to call EnumPrinterDataEx");
4283 /* get the max sizes for value and data */
4285 torture_assert(tctx,
4286 test_EnumPrinterData(tctx, p, handle, 0, 0, 0,
4287 NULL, &value_needed, &data_needed,
4288 NULL, NULL, &result),
4289 "EnumPrinterData failed");
4290 torture_assert_werr_ok(tctx, result, "unexpected result");
4292 /* check if the reply from the EnumPrinterData really matches max values */
4294 for (i=0; i < count; i++) {
4295 if (info[i].value_name_len > value_needed) {
4297 talloc_asprintf(tctx,
4298 "EnumPrinterDataEx gave a reply with value length %d which is larger then expected max value length %d from EnumPrinterData",
4299 info[i].value_name_len, value_needed));
4301 if (info[i].data_length > data_needed) {
4303 talloc_asprintf(tctx,
4304 "EnumPrinterDataEx gave a reply with data length %d which is larger then expected max data length %d from EnumPrinterData",
4305 info[i].data_length, data_needed));
4309 /* assuming that both EnumPrinterData and EnumPrinterDataEx do either
4310 * sort or not sort the replies by value name, we should be able to do
4311 * the following entry comparison */
4313 data_offered = data_needed;
4314 value_offered = value_needed;
4316 for (i=0; i < count; i++) {
4318 const char *value_name;
4321 torture_assert(tctx,
4322 test_EnumPrinterData(tctx, p, handle, i, value_offered, data_offered,
4323 &type, &value_needed, &data_needed,
4324 &value_name, &data, &result),
4325 "EnumPrinterData failed");
4327 if (i -1 == count) {
4328 torture_assert_werr_equal(tctx, result, WERR_NO_MORE_ITEMS,
4329 "unexpected result");
4332 torture_assert_werr_ok(tctx, result, "unexpected result");
4335 torture_assert_int_equal(tctx, type, info[i].type, "type mismatch");
4336 torture_assert_int_equal(tctx, value_needed, info[i].value_name_len, "value name length mismatch");
4337 torture_assert_str_equal(tctx, value_name, info[i].value_name, "value name mismatch");
4338 torture_assert_int_equal(tctx, data_needed, info[i].data_length, "data length mismatch");
4339 torture_assert_mem_equal(tctx, data, info[i].data->data, info[i].data_length, "data mismatch");
4342 torture_assert(tctx,
4343 test_DeletePrinterData(tctx, b, handle, "torture_value1"),
4344 "DeletePrinterData failed");
4345 torture_assert(tctx,
4346 test_DeletePrinterData(tctx, b, handle, "torture_value2"),
4347 "DeletePrinterData failed");
4348 torture_assert(tctx,
4349 test_DeletePrinterData(tctx, b, handle, "torture_value3"),
4350 "DeletePrinterData failed");
4352 torture_comment(tctx, "EnumPrinterData vs EnumPrinterDataEx consistency test succeeded\n\n");
4357 static bool test_DeletePrinterData(struct torture_context *tctx,
4358 struct dcerpc_binding_handle *b,
4359 struct policy_handle *handle,
4360 const char *value_name)
4363 struct spoolss_DeletePrinterData r;
4365 r.in.handle = handle;
4366 r.in.value_name = value_name;
4368 torture_comment(tctx, "Testing DeletePrinterData(%s)\n",
4371 status = dcerpc_spoolss_DeletePrinterData_r(b, tctx, &r);
4373 torture_assert_ntstatus_ok(tctx, status, "DeletePrinterData failed");
4374 torture_assert_werr_ok(tctx, r.out.result, "DeletePrinterData failed");
4379 static bool test_DeletePrinterDataEx(struct torture_context *tctx,
4380 struct dcerpc_binding_handle *b,
4381 struct policy_handle *handle,
4382 const char *key_name,
4383 const char *value_name)
4385 struct spoolss_DeletePrinterDataEx r;
4387 r.in.handle = handle;
4388 r.in.key_name = key_name;
4389 r.in.value_name = value_name;
4391 torture_comment(tctx, "Testing DeletePrinterDataEx(%s - %s)\n",
4392 r.in.key_name, r.in.value_name);
4394 torture_assert_ntstatus_ok(tctx,
4395 dcerpc_spoolss_DeletePrinterDataEx_r(b, tctx, &r),
4396 "DeletePrinterDataEx failed");
4397 torture_assert_werr_ok(tctx, r.out.result,
4398 "DeletePrinterDataEx failed");
4403 static bool test_DeletePrinterKey(struct torture_context *tctx,
4404 struct dcerpc_binding_handle *b,
4405 struct policy_handle *handle,
4406 const char *key_name)
4408 struct spoolss_DeletePrinterKey r;
4410 r.in.handle = handle;
4411 r.in.key_name = key_name;
4413 torture_comment(tctx, "Testing DeletePrinterKey(%s)\n", r.in.key_name);
4415 if (strequal(key_name, "") && !torture_setting_bool(tctx, "dangerous", false)) {
4416 torture_skip(tctx, "not wiping out printer registry - enable dangerous tests to use\n");
4420 torture_assert_ntstatus_ok(tctx,
4421 dcerpc_spoolss_DeletePrinterKey_r(b, tctx, &r),
4422 "DeletePrinterKey failed");
4423 torture_assert_werr_ok(tctx, r.out.result,
4424 "DeletePrinterKey failed");
4429 static bool test_winreg_OpenHKLM(struct torture_context *tctx,
4430 struct dcerpc_binding_handle *b,
4431 struct policy_handle *handle)
4433 struct winreg_OpenHKLM r;
4435 r.in.system_name = NULL;
4436 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
4437 r.out.handle = handle;
4439 torture_comment(tctx, "Testing winreg_OpenHKLM\n");
4441 torture_assert_ntstatus_ok(tctx, dcerpc_winreg_OpenHKLM_r(b, tctx, &r), "OpenHKLM failed");
4442 torture_assert_werr_ok(tctx, r.out.result, "OpenHKLM failed");
4447 static void init_winreg_String(struct winreg_String *name, const char *s)
4451 name->name_len = 2 * (strlen_m(s) + 1);
4452 name->name_size = name->name_len;
4455 name->name_size = 0;
4459 static bool test_winreg_OpenKey_opts(struct torture_context *tctx,
4460 struct dcerpc_binding_handle *b,
4461 struct policy_handle *hive_handle,
4462 const char *keyname,
4464 struct policy_handle *key_handle)
4466 struct winreg_OpenKey r;
4468 r.in.parent_handle = hive_handle;
4469 init_winreg_String(&r.in.keyname, keyname);
4470 r.in.options = options;
4471 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
4472 r.out.handle = key_handle;
4474 torture_comment(tctx, "Testing winreg_OpenKey(%s)\n", keyname);
4476 torture_assert_ntstatus_ok(tctx, dcerpc_winreg_OpenKey_r(b, tctx, &r), "OpenKey failed");
4477 torture_assert_werr_ok(tctx, r.out.result, "OpenKey failed");
4482 static bool test_winreg_OpenKey(struct torture_context *tctx,
4483 struct dcerpc_binding_handle *b,
4484 struct policy_handle *hive_handle,
4485 const char *keyname,
4486 struct policy_handle *key_handle)
4488 return test_winreg_OpenKey_opts(tctx, b, hive_handle, keyname,
4489 REG_OPTION_NON_VOLATILE, key_handle);
4492 static bool test_winreg_CloseKey(struct torture_context *tctx,
4493 struct dcerpc_binding_handle *b,
4494 struct policy_handle *handle)
4496 struct winreg_CloseKey r;
4498 r.in.handle = handle;
4499 r.out.handle = handle;
4501 torture_comment(tctx, "Testing winreg_CloseKey\n");
4503 torture_assert_ntstatus_ok(tctx, dcerpc_winreg_CloseKey_r(b, tctx, &r), "CloseKey failed");
4504 torture_assert_werr_ok(tctx, r.out.result, "CloseKey failed");
4509 bool test_winreg_QueryValue(struct torture_context *tctx,
4510 struct dcerpc_binding_handle *b,
4511 struct policy_handle *handle,
4512 const char *value_name,
4513 enum winreg_Type *type_p,
4514 uint32_t *data_size_p,
4515 uint32_t *data_length_p,
4518 struct winreg_QueryValue r;
4519 enum winreg_Type type = REG_NONE;
4520 uint32_t data_size = 0;
4521 uint32_t data_length = 0;
4522 struct winreg_String valuename;
4523 uint8_t *data = NULL;
4525 init_winreg_String(&valuename, value_name);
4527 data = talloc_zero_array(tctx, uint8_t, 0);
4529 r.in.handle = handle;
4530 r.in.value_name = &valuename;
4532 r.in.data_size = &data_size;
4533 r.in.data_length = &data_length;
4537 r.out.data_size = &data_size;
4538 r.out.data_length = &data_length;
4540 torture_comment(tctx, "Testing winreg_QueryValue(%s)\n", value_name);
4542 torture_assert_ntstatus_ok(tctx, dcerpc_winreg_QueryValue_r(b, tctx, &r), "QueryValue failed");
4543 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
4544 *r.in.data_size = *r.out.data_size;
4545 data = talloc_zero_array(tctx, uint8_t, *r.in.data_size);
4548 torture_assert_ntstatus_ok(tctx, dcerpc_winreg_QueryValue_r(b, tctx, &r), "QueryValue failed");
4550 torture_assert_werr_ok(tctx, r.out.result, "QueryValue failed");
4553 *type_p = *r.out.type;
4556 *data_size_p = *r.out.data_size;
4558 if (data_length_p) {
4559 *data_length_p = *r.out.data_length;
4562 *data_p = r.out.data;
4568 static bool test_winreg_query_printerdata(struct torture_context *tctx,
4569 struct dcerpc_binding_handle *b,
4570 struct policy_handle *handle,
4571 const char *printer_name,
4572 const char *key_name,
4573 const char *value_name,
4574 enum winreg_Type *w_type,
4579 const char *printer_key;
4580 struct policy_handle key_handle;
4582 printer_key = talloc_asprintf(tctx, "%s\\%s\\%s",
4583 TOP_LEVEL_PRINT_PRINTERS_KEY, printer_name, key_name);
4585 torture_assert(tctx,
4586 test_winreg_OpenKey(tctx, b, handle, printer_key, &key_handle), "");
4588 torture_assert(tctx,
4589 test_winreg_QueryValue(tctx, b, &key_handle, value_name, w_type, w_size, w_length, w_data), "");
4591 torture_assert(tctx,
4592 test_winreg_CloseKey(tctx, b, &key_handle), "");
4597 static bool test_GetForm_winreg(struct torture_context *tctx,
4598 struct dcerpc_binding_handle *b,
4599 struct policy_handle *handle,
4600 const char *key_name,
4601 const char *form_name,
4602 enum winreg_Type *w_type,
4607 struct policy_handle key_handle;
4609 torture_assert(tctx,
4610 test_winreg_OpenKey(tctx, b, handle, key_name, &key_handle), "");
4612 torture_assert(tctx,
4613 test_winreg_QueryValue(tctx, b, &key_handle, form_name, w_type, w_size, w_length, w_data), "");
4615 torture_assert(tctx,
4616 test_winreg_CloseKey(tctx, b, &key_handle), "");
4621 static bool test_winreg_symbolic_link(struct torture_context *tctx,
4622 struct dcerpc_binding_handle *b,
4623 struct policy_handle *handle,
4624 const char *symlink_keyname,
4625 const char *symlink_destination)
4627 /* check if the first key is a symlink to the second key */
4629 enum winreg_Type w_type;
4633 struct policy_handle key_handle;
4637 if (torture_setting_bool(tctx, "samba3", false)) {
4638 torture_skip(tctx, "skip winreg symlink test against samba");
4641 torture_assert(tctx,
4642 test_winreg_OpenKey_opts(tctx, b, handle, symlink_keyname, REG_OPTION_OPEN_LINK, &key_handle),
4643 "failed to open key link");
4645 torture_assert(tctx,
4646 test_winreg_QueryValue(tctx, b, &key_handle,
4647 "SymbolicLinkValue",
4648 &w_type, &w_size, &w_length, &w_data),
4649 "failed to query for 'SymbolicLinkValue' attribute");
4651 torture_assert_int_equal(tctx, w_type, REG_LINK, "unexpected type");
4653 blob = data_blob(w_data, w_size);
4654 str = reg_val_data_string(tctx, REG_SZ, blob);
4656 torture_assert_str_equal(tctx, str, symlink_destination, "unexpected symlink target string");
4658 torture_assert(tctx,
4659 test_winreg_CloseKey(tctx, b, &key_handle),
4660 "failed to close key link");
4665 static const char *strip_unc(const char *unc)
4673 if (unc[0] == '\\' && unc[1] == '\\') {
4677 name = strchr(unc, '\\');
4685 static bool test_GetPrinterInfo_winreg(struct torture_context *tctx,
4686 struct dcerpc_binding_handle *b,
4687 struct policy_handle *handle,
4688 const char *printer_name,
4689 struct dcerpc_binding_handle *winreg_handle,
4690 struct policy_handle *hive_handle)
4692 union spoolss_PrinterInfo info;
4693 const char *keys[] = {
4694 TOP_LEVEL_CONTROL_PRINTERS_KEY,
4695 TOP_LEVEL_PRINT_PRINTERS_KEY
4698 const char *printername, *sharename;
4700 torture_comment(tctx, "Testing Printer Info and winreg consistency\n");
4702 torture_assert(tctx,
4703 test_GetPrinter_level(tctx, b, handle, 2, &info),
4704 "failed to get printer info level 2");
4706 printername = strip_unc(info.info2.printername);
4707 sharename = strip_unc(info.info2.sharename);
4709 #define test_sz(wname, iname) \
4713 enum winreg_Type w_type;\
4717 torture_assert(tctx,\
4718 test_winreg_QueryValue(tctx, winreg_handle, &key_handle, wname,\
4719 &w_type, &w_size, &w_length, &w_data),\
4720 "failed to query winreg");\
4721 torture_assert_int_equal(tctx, w_type, REG_SZ, "unexpected type");\
4722 blob = data_blob(w_data, w_size);\
4723 str = reg_val_data_string(tctx, REG_SZ, blob);\
4724 if (w_size == 2 && iname == NULL) {\
4725 /*torture_comment(tctx, "%s: \"\", %s: (null)\n", #wname, #iname);\ */\
4727 torture_assert_str_equal(tctx, str, iname,\
4728 talloc_asprintf(tctx, "%s - %s mismatch", #wname, #iname));\
4732 #define test_dword(wname, iname) \
4735 enum winreg_Type w_type;\
4739 torture_assert(tctx,\
4740 test_winreg_QueryValue(tctx, winreg_handle, &key_handle, wname,\
4741 &w_type, &w_size, &w_length, &w_data),\
4742 "failed to query winreg");\
4743 torture_assert_int_equal(tctx, w_type, REG_DWORD, "unexpected type");\
4744 torture_assert_int_equal(tctx, w_size, 4, "unexpected size");\
4745 torture_assert_int_equal(tctx, w_length, 4, "unexpected length");\
4746 value = IVAL(w_data, 0);\
4747 torture_assert_int_equal(tctx, value, iname,\
4748 talloc_asprintf(tctx, "%s - %s mismatch", #wname, #iname));\
4751 #define test_binary(wname, iname) \
4753 enum winreg_Type w_type;\
4757 torture_assert(tctx,\
4758 test_winreg_QueryValue(tctx, winreg_handle, &key_handle, wname,\
4759 &w_type, &w_size, &w_length, &w_data),\
4760 "failed to query winreg");\
4761 torture_assert_int_equal(tctx, w_type, REG_BINARY, "unexpected type");\
4762 torture_assert_int_equal(tctx, w_size, iname.length, "unexpected length");\
4763 torture_assert_mem_equal(tctx, w_data, iname.data, w_size, \
4768 #define test_dm(wname, iname) \
4771 struct spoolss_DeviceMode dm;\
4772 enum ndr_err_code ndr_err;\
4773 enum winreg_Type w_type;\
4777 torture_assert(tctx,\
4778 test_winreg_QueryValue(tctx, winreg_handle, &key_handle, wname,\
4779 &w_type, &w_size, &w_length, &w_data),\
4780 "failed to query winreg");\
4781 torture_assert_int_equal(tctx, w_type, REG_BINARY, "unexpected type");\
4782 blob = data_blob(w_data, w_size);\
4783 ndr_err = ndr_pull_struct_blob(&blob, tctx, &dm,\
4784 (ndr_pull_flags_fn_t)ndr_pull_spoolss_DeviceMode);\
4785 torture_assert_ndr_success(tctx, ndr_err, "failed to unmarshall dm");\
4786 torture_assert(tctx, test_devicemode_equal(tctx, &dm, iname),\
4790 #define test_sd(wname, iname) \
4793 struct security_descriptor sd;\
4794 enum ndr_err_code ndr_err;\
4795 enum winreg_Type w_type;\
4799 torture_assert(tctx,\
4800 test_winreg_QueryValue(tctx, winreg_handle, &key_handle, wname,\
4801 &w_type, &w_size, &w_length, &w_data),\
4802 "failed to query winreg");\
4803 torture_assert_int_equal(tctx, w_type, REG_BINARY, "unexpected type");\
4804 blob = data_blob(w_data, w_size);\
4805 ndr_err = ndr_pull_struct_blob(&blob, tctx, &sd,\
4806 (ndr_pull_flags_fn_t)ndr_pull_security_descriptor);\
4807 torture_assert_ndr_success(tctx, ndr_err, "failed to unmarshall sd");\
4808 torture_assert(tctx, test_security_descriptor_equal(tctx, &sd, iname),\
4812 #define test_multi_sz(wname, iname) \
4815 const char **array;\
4816 enum winreg_Type w_type;\
4821 torture_assert(tctx,\
4822 test_winreg_QueryValue(tctx, winreg_handle, &key_handle, wname,\
4823 &w_type, &w_size, &w_length, &w_data),\
4824 "failed to query winreg");\
4825 torture_assert_int_equal(tctx, w_type, REG_MULTI_SZ, "unexpected type");\
4826 blob = data_blob(w_data, w_size);\
4827 torture_assert(tctx, \
4828 pull_reg_multi_sz(tctx, &blob, &array),\
4829 "failed to pull multi sz");\
4830 for (i=0; array[i] != NULL; i++) {\
4831 torture_assert_str_equal(tctx, array[i], iname[i],\
4832 talloc_asprintf(tctx, "%s - %s mismatch", #wname, iname[i]));\
4836 if (!test_winreg_symbolic_link(tctx, winreg_handle, hive_handle,
4837 TOP_LEVEL_CONTROL_PRINTERS_KEY,
4838 "\\Registry\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Print\\Printers"))
4840 torture_warning(tctx, "failed to check for winreg symlink");
4843 for (i=0; i < ARRAY_SIZE(keys); i++) {
4845 const char *printer_key;
4846 struct policy_handle key_handle;
4848 printer_key = talloc_asprintf(tctx, "%s\\%s",
4849 keys[i], printer_name);
4851 torture_assert(tctx,
4852 test_winreg_OpenKey(tctx, winreg_handle, hive_handle, printer_key, &key_handle), "");
4854 test_sz("Name", printername);
4855 test_sz("Share Name", sharename);
4856 test_sz("Port", info.info2.portname);
4857 test_sz("Printer Driver", info.info2.drivername);
4858 test_sz("Description", info.info2.comment);
4859 test_sz("Location", info.info2.location);
4860 test_sz("Separator File", info.info2.sepfile);
4861 test_sz("Print Processor", info.info2.printprocessor);
4862 test_sz("Datatype", info.info2.datatype);
4863 test_sz("Parameters", info.info2.parameters);
4864 /* winreg: 0, spoolss not */
4865 /* test_dword("Attributes", info.info2.attributes); */
4866 test_dword("Priority", info.info2.priority);
4867 test_dword("Default Priority", info.info2.defaultpriority);
4868 /* winreg: 60, spoolss: 0 */
4869 /* test_dword("StartTime", info.info2.starttime); */
4870 /* test_dword("UntilTime", info.info2.untiltime); */
4871 /* winreg != spoolss */
4872 /* test_dword("Status", info.info2.status); */
4873 test_dm("Default DevMode", info.info2.devmode);
4874 test_sd("Security", info.info2.secdesc);
4876 torture_assert(tctx,
4877 test_winreg_CloseKey(tctx, winreg_handle, &key_handle), "");
4883 torture_comment(tctx, "Printer Info and winreg consistency test succeeded\n\n");
4888 static bool test_PrintProcessors(struct torture_context *tctx,
4889 struct dcerpc_binding_handle *b,
4890 const char *environment,
4891 struct dcerpc_binding_handle *winreg_handle,
4892 struct policy_handle *hive_handle)
4894 union spoolss_PrintProcessorInfo *info;
4898 torture_comment(tctx, "Testing Print Processor Info and winreg consistency\n");
4900 torture_assert(tctx,
4901 test_EnumPrintProcessors_level(tctx, b, environment, 1, &count, &info, WERR_OK),
4902 "failed to enum print processors level 1");
4904 for (i=0; i < count; i++) {
4906 const char *processor_key;
4907 struct policy_handle key_handle;
4909 processor_key = talloc_asprintf(tctx, "%s\\%s\\Print Processors\\%s",
4910 TOP_LEVEL_CONTROL_ENVIRONMENTS_KEY,
4912 info[i].info1.print_processor_name);
4914 torture_assert(tctx,
4915 test_winreg_OpenKey(tctx, winreg_handle, hive_handle, processor_key, &key_handle), "");
4917 /* nothing to check in there so far */
4919 torture_assert(tctx,
4920 test_winreg_CloseKey(tctx, winreg_handle, &key_handle), "");
4923 torture_comment(tctx, "Print Processor Info and winreg consistency test succeeded\n\n");
4928 static bool test_GetPrinterDriver2_level(struct torture_context *tctx,
4929 struct dcerpc_binding_handle *b,
4930 struct policy_handle *handle,
4931 const char *driver_name,
4932 const char *architecture,
4934 uint32_t client_major_version,
4935 uint32_t client_minor_version,
4936 union spoolss_DriverInfo *info_p,
4939 static const char *strip_path(const char *path)
4947 p = strrchr(path, '\\');
4955 static const char **strip_paths(const char **path_array)
4959 if (path_array == NULL) {
4963 for (i=0; path_array[i] != NULL; i++) {
4964 path_array[i] = strip_path(path_array[i]);
4970 static const char *driver_winreg_date(TALLOC_CTX *mem_ctx, NTTIME nt)
4976 return talloc_strdup(mem_ctx, "01/01/1601");
4979 t = nt_time_to_unix(nt);
4982 return talloc_asprintf(mem_ctx, "%02d/%02d/%04d",
4983 tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900);
4986 static const char *driver_winreg_version(TALLOC_CTX *mem_ctx, uint64_t v)
4988 return talloc_asprintf(mem_ctx, "%u.%u.%u.%u",
4989 (unsigned)((v >> 48) & 0xFFFF),
4990 (unsigned)((v >> 32) & 0xFFFF),
4991 (unsigned)((v >> 16) & 0xFFFF),
4992 (unsigned)(v & 0xFFFF));
4995 static bool test_GetDriverInfo_winreg(struct torture_context *tctx,
4996 struct dcerpc_binding_handle *b,
4997 struct policy_handle *handle,
4998 const char *printer_name,
4999 const char *driver_name,
5000 const char *environment,
5001 enum spoolss_DriverOSVersion version,
5002 struct dcerpc_binding_handle *winreg_handle,
5003 struct policy_handle *hive_handle,
5004 const char *server_name_slash)
5006 WERROR result = WERR_OK;
5007 union spoolss_DriverInfo info;
5008 const char *driver_key;
5009 struct policy_handle key_handle;
5011 const char *driver_path;
5012 const char *data_file;
5013 const char *config_file;
5014 const char *help_file;
5015 const char **dependent_files;
5017 const char *driver_date;
5018 const char *inbox_driver_date;
5020 const char *driver_version;
5021 const char *inbox_driver_version;
5023 ZERO_STRUCT(key_handle);
5025 torture_comment(tctx, "Testing Driver Info and winreg consistency\n");
5027 driver_key = talloc_asprintf(tctx, "%s\\%s\\Drivers\\Version-%d\\%s",
5028 TOP_LEVEL_CONTROL_ENVIRONMENTS_KEY,
5033 torture_assert(tctx,
5034 test_winreg_OpenKey(tctx, winreg_handle, hive_handle, driver_key, &key_handle),
5035 "failed to open driver key");
5037 if (torture_setting_bool(tctx, "samba3", false) ||
5038 torture_setting_bool(tctx, "w2k3", false)) {
5043 torture_assert(tctx,
5044 test_GetPrinterDriver2_level(tctx, b, handle, driver_name, environment, 8, version, 0, &info, &result),
5045 "failed to get driver info level 8");
5047 torture_assert(tctx,
5048 test_EnumPrinterDrivers_findone(tctx, b, server_name_slash, environment, 8, driver_name, &info),
5049 "failed to get driver info level 8");
5052 if (W_ERROR_EQUAL(result, WERR_INVALID_LEVEL)) {
5056 driver_path = strip_path(info.info8.driver_path);
5057 data_file = strip_path(info.info8.data_file);
5058 config_file = strip_path(info.info8.config_file);
5059 help_file = strip_path(info.info8.help_file);
5060 dependent_files = strip_paths(info.info8.dependent_files);
5062 driver_date = driver_winreg_date(tctx, info.info8.driver_date);
5063 inbox_driver_date = driver_winreg_date(tctx, info.info8.min_inbox_driver_ver_date);
5065 driver_version = driver_winreg_version(tctx, info.info8.driver_version);
5066 inbox_driver_version = driver_winreg_version(tctx, info.info8.min_inbox_driver_ver_version);
5068 test_sz("Configuration File", config_file);
5069 test_sz("Data File", data_file);
5070 test_sz("Datatype", info.info8.default_datatype);
5071 test_sz("Driver", driver_path);
5072 test_sz("DriverDate", driver_date);
5073 test_sz("DriverVersion", driver_version);
5074 test_sz("HardwareID", info.info8.hardware_id);
5075 test_sz("Help File", help_file);
5076 test_sz("InfPath", info.info8.inf_path);
5077 test_sz("Manufacturer", info.info8.manufacturer_name);
5078 test_sz("MinInboxDriverVerDate", inbox_driver_date);
5079 test_sz("MinInboxDriverVerVersion", inbox_driver_version);
5080 test_sz("Monitor", info.info8.monitor_name);
5081 test_sz("OEM URL", info.info8.manufacturer_url);
5082 test_sz("Print Processor", info.info8.print_processor);
5083 test_sz("Provider", info.info8.provider);
5084 test_sz("VendorSetup", info.info8.vendor_setup);
5085 test_multi_sz("ColorProfiles", info.info8.color_profiles);
5086 test_multi_sz("Dependent Files", dependent_files);
5087 test_multi_sz("CoreDependencies", info.info8.core_driver_dependencies);
5088 test_multi_sz("Previous Names", info.info8.previous_names);
5089 /* test_dword("Attributes", ?); */
5090 test_dword("PrinterDriverAttributes", info.info8.printer_driver_attributes);
5091 test_dword("Version", info.info8.version);
5092 /* test_dword("TempDir", ?); */
5097 torture_assert(tctx,
5098 test_GetPrinterDriver2_level(tctx, b, handle, driver_name, environment, 6, version, 0, &info, &result),
5099 "failed to get driver info level 6");
5101 torture_assert(tctx,
5102 test_EnumPrinterDrivers_findone(tctx, b, server_name_slash, environment, 6, driver_name, &info),
5103 "failed to get driver info level 6");
5106 driver_path = strip_path(info.info6.driver_path);
5107 data_file = strip_path(info.info6.data_file);
5108 config_file = strip_path(info.info6.config_file);
5109 help_file = strip_path(info.info6.help_file);
5110 dependent_files = strip_paths(info.info6.dependent_files);
5112 driver_date = driver_winreg_date(tctx, info.info6.driver_date);
5114 driver_version = driver_winreg_version(tctx, info.info6.driver_version);
5116 test_sz("Configuration File", config_file);
5117 test_sz("Data File", data_file);
5118 test_sz("Datatype", info.info6.default_datatype);
5119 test_sz("Driver", driver_path);
5120 if (torture_setting_bool(tctx, "w2k3", false)) {
5121 DATA_BLOB blob = data_blob_talloc_zero(tctx, 8);
5122 push_nttime(blob.data, 0, info.info6.driver_date);
5123 test_binary("DriverDate", blob);
5124 SBVAL(blob.data, 0, info.info6.driver_version);
5125 test_binary("DriverVersion", blob);
5127 test_sz("DriverDate", driver_date);
5128 test_sz("DriverVersion", driver_version);
5130 test_sz("HardwareID", info.info6.hardware_id);
5131 test_sz("Help File", help_file);
5132 test_sz("Manufacturer", info.info6.manufacturer_name);
5133 test_sz("Monitor", info.info6.monitor_name);
5134 test_sz("OEM URL", info.info6.manufacturer_url);
5135 test_sz("Provider", info.info6.provider);
5136 test_multi_sz("Dependent Files", dependent_files);
5137 test_multi_sz("Previous Names", info.info6.previous_names);
5138 /* test_dword("Attributes", ?); */
5139 test_dword("Version", info.info6.version);
5140 /* test_dword("TempDir", ?); */
5143 torture_assert(tctx,
5144 test_GetPrinterDriver2_level(tctx, b, handle, driver_name, environment, 3, version, 0, &info, &result),
5145 "failed to get driver info level 3");
5147 torture_assert(tctx,
5148 test_EnumPrinterDrivers_findone(tctx, b, server_name_slash, environment, 3, driver_name, &info),
5149 "failed to get driver info level 3");
5152 driver_path = strip_path(info.info3.driver_path);
5153 data_file = strip_path(info.info3.data_file);
5154 config_file = strip_path(info.info3.config_file);
5155 help_file = strip_path(info.info3.help_file);
5156 dependent_files = strip_paths(info.info3.dependent_files);
5158 test_sz("Configuration File", config_file);
5159 test_sz("Data File", data_file);
5160 test_sz("Datatype", info.info3.default_datatype);
5161 test_sz("Driver", driver_path);
5162 test_sz("Help File", help_file);
5163 test_sz("Monitor", info.info3.monitor_name);
5164 test_multi_sz("Dependent Files", dependent_files);
5165 /* test_dword("Attributes", ?); */
5166 test_dword("Version", info.info3.version);
5167 /* test_dword("TempDir", ?); */
5170 torture_assert(tctx,
5171 test_winreg_CloseKey(tctx, winreg_handle, &key_handle), "");
5173 torture_comment(tctx, "Driver Info and winreg consistency test succeeded\n\n");
5181 static bool test_SetPrinterData(struct torture_context *tctx,
5182 struct dcerpc_binding_handle *b,
5183 struct policy_handle *handle,
5184 const char *value_name,
5185 enum winreg_Type type,
5189 struct spoolss_SetPrinterData r;
5191 r.in.handle = handle;
5192 r.in.value_name = value_name;
5195 r.in.offered = offered;
5197 torture_comment(tctx, "Testing SetPrinterData(%s)\n",
5200 torture_assert_ntstatus_ok(tctx,
5201 dcerpc_spoolss_SetPrinterData_r(b, tctx, &r),
5202 "SetPrinterData failed");
5203 torture_assert_werr_ok(tctx, r.out.result,
5204 "SetPrinterData failed");
5209 static bool test_SetPrinterData_matrix(struct torture_context *tctx,
5210 struct dcerpc_binding_handle *b,
5211 struct policy_handle *handle,
5212 const char *printer_name,
5213 struct dcerpc_binding_handle *winreg_handle,
5214 struct policy_handle *hive_handle)
5216 const char *values[] = {
5220 /* FIXME: not working with s3 atm. */
5226 /* FIXME: not working with s3 atm. */
5233 for (i=0; i < ARRAY_SIZE(values); i++) {
5235 enum winreg_Type type, expected_type = REG_SZ;
5240 torture_assert(tctx, push_reg_sz(tctx, &blob, "dog"), "");
5243 torture_assert(tctx,
5244 test_SetPrinterData(tctx, b, handle, values[i], REG_SZ, blob.data, blob.length),
5245 "SetPrinterData failed");
5247 torture_assert(tctx,
5248 test_GetPrinterData_checktype(tctx, b, handle, values[i], &expected_type, &type, &data, &needed),
5249 "GetPrinterData failed");
5251 torture_assert_int_equal(tctx, type, REG_SZ, "type mismatch");
5252 torture_assert_int_equal(tctx, needed, blob.length, "size mismatch");
5253 torture_assert_mem_equal(tctx, data, blob.data, blob.length, "buffer mismatch");
5255 if (winreg_handle && hive_handle) {
5257 enum winreg_Type w_type;
5262 torture_assert(tctx,
5263 test_winreg_query_printerdata(tctx, winreg_handle, hive_handle,
5264 printer_name, "PrinterDriverData", values[i],
5265 &w_type, &w_size, &w_length, &w_data), "");
5267 torture_assert_int_equal(tctx, w_type, REG_SZ, "winreg type mismatch");
5268 torture_assert_int_equal(tctx, w_size, blob.length, "winreg size mismatch");
5269 torture_assert_int_equal(tctx, w_length, blob.length, "winreg length mismatch");
5270 torture_assert_mem_equal(tctx, w_data, blob.data, blob.length, "winreg buffer mismatch");
5273 torture_assert(tctx,
5274 test_DeletePrinterData(tctx, b, handle, values[i]),
5275 "DeletePrinterData failed");
5282 static bool test_EnumPrinterKey(struct torture_context *tctx,
5283 struct dcerpc_binding_handle *b,
5284 struct policy_handle *handle,
5285 const char *key_name,
5286 const char ***array);
5288 static bool test_SetPrinterDataEx(struct torture_context *tctx,
5289 struct dcerpc_binding_handle *b,
5290 struct policy_handle *handle,
5291 const char *key_name,
5292 const char *value_name,
5293 enum winreg_Type type,
5298 struct spoolss_SetPrinterDataEx r;
5300 r.in.handle = handle;
5301 r.in.key_name = key_name;
5302 r.in.value_name = value_name;
5305 r.in.offered = offered;
5307 torture_comment(tctx, "Testing SetPrinterDataEx(%s - %s) type: %s, offered: 0x%08x\n",
5308 r.in.key_name, r.in.value_name, str_regtype(r.in.type), r.in.offered);
5310 status = dcerpc_spoolss_SetPrinterDataEx_r(b, tctx, &r);
5312 torture_assert_ntstatus_ok(tctx, status, "SetPrinterDataEx failed");
5313 torture_assert_werr_ok(tctx, r.out.result, "SetPrinterDataEx failed");
5318 static bool test_SetPrinterDataEx_keys(struct torture_context *tctx,
5319 struct dcerpc_pipe *p,
5320 struct policy_handle *handle)
5322 struct dcerpc_binding_handle *b = p->binding_handle;
5323 const char *value_name = "dog";
5324 const char *keys[] = {
5327 "torturedataex_with_subkey\\subkey",
5328 "torturedataex_with_subkey\\subkey:0",
5329 "torturedataex_with_subkey\\subkey:1",
5330 "torturedataex_with_subkey\\subkey\\subsubkey",
5331 "torturedataex_with_subkey\\subkey\\subsubkey:0",
5332 "torturedataex_with_subkey\\subkey\\subsubkey:1",
5339 "torture/data ex/sub",
5342 "torture//data ex/sub",
5343 "torture//data ex//sub",
5347 for (i=0; i < ARRAY_SIZE(keys); i++) {
5351 enum winreg_Type type;
5352 DATA_BLOB blob_in, blob_out;
5353 const char **subkeys;
5355 struct spoolss_PrinterEnumValues *einfo;
5358 blob_in = data_blob_talloc(tctx, NULL, 42);
5360 generate_random_buffer(blob_in.data, blob_in.length);
5362 torture_assert(tctx,
5363 test_SetPrinterDataEx(tctx, b, handle, keys[i], value_name, REG_BINARY, blob_in.data, blob_in.length),
5364 "failed to call SetPrinterDataEx");
5366 torture_assert(tctx,
5367 test_GetPrinterDataEx(tctx, p, handle, keys[i], value_name, &type, &blob_out.data, &needed),
5368 "failed to call GetPrinterDataEx");
5370 blob_out.length = needed;
5371 torture_assert(tctx,
5372 test_EnumPrinterDataEx(tctx, b, handle, keys[i], &ecount, &einfo),
5373 "failed to call EnumPrinterDataEx");
5375 torture_assert_int_equal(tctx, type, REG_BINARY, "type mismatch");
5376 torture_assert_int_equal(tctx, blob_out.length, blob_in.length, "size mismatch");
5377 torture_assert_mem_equal(tctx, blob_out.data, blob_in.data, blob_in.length, "buffer mismatch");
5379 torture_assert_int_equal(tctx, ecount, 1, "unexpected enum count");
5380 torture_assert_str_equal(tctx, einfo[0].value_name, value_name, "value_name mismatch");
5381 torture_assert_int_equal(tctx, einfo[0].value_name_len, strlen_m_term(value_name)*2, "unexpected value_name_len");
5382 torture_assert_int_equal(tctx, einfo[0].type, REG_BINARY, "type mismatch");
5383 torture_assert_int_equal(tctx, einfo[0].data_length, blob_in.length, "size mismatch");
5384 if (einfo[0].data_length > 0) {
5385 torture_assert_mem_equal(tctx, einfo[0].data->data, blob_in.data, blob_in.length, "buffer mismatch");
5388 key = talloc_strdup(tctx, keys[i]);
5390 if (!test_DeletePrinterDataEx(tctx, b, handle, keys[i], value_name)) {
5394 c = strchr(key, '\\');
5398 /* we have subkeys */
5402 if (!test_EnumPrinterKey(tctx, b, handle, key, &subkeys)) {
5406 for (k=0; subkeys && subkeys[k]; k++) {
5408 const char *current_key = talloc_asprintf(tctx, "%s\\%s", key, subkeys[k]);
5410 if (!test_DeletePrinterKey(tctx, b, handle, current_key)) {
5415 if (!test_DeletePrinterKey(tctx, b, handle, key)) {
5420 if (!test_DeletePrinterKey(tctx, b, handle, key)) {
5429 static bool test_SetPrinterDataEx_values(struct torture_context *tctx,
5430 struct dcerpc_pipe *p,
5431 struct policy_handle *handle)
5433 struct dcerpc_binding_handle *b = p->binding_handle;
5434 const char *key = "torturedataex";
5435 const char *values[] = {
5445 for (i=0; i < ARRAY_SIZE(values); i++) {
5447 enum winreg_Type type;
5448 DATA_BLOB blob_in, blob_out;
5450 struct spoolss_PrinterEnumValues *einfo;
5453 if (torture_setting_bool(tctx, "samba3", false)) {
5455 q = strrchr(values[i], ',');
5457 torture_comment(tctx, "skipping valuename '%s' including ',' character against Samba3\n",
5463 blob_in = data_blob_talloc(tctx, NULL, 42);
5465 generate_random_buffer(blob_in.data, blob_in.length);
5467 torture_assert(tctx,
5468 test_SetPrinterDataEx(tctx, b, handle, key, values[i], REG_BINARY, blob_in.data, blob_in.length),
5469 "failed to call SetPrinterDataEx");
5471 torture_assert(tctx,
5472 test_GetPrinterDataEx(tctx, p, handle, key, values[i], &type, &blob_out.data, &needed),
5473 "failed to call GetPrinterDataEx");
5475 blob_out.length = needed;
5476 torture_assert(tctx,
5477 test_EnumPrinterDataEx(tctx, b, handle, key, &ecount, &einfo),
5478 "failed to call EnumPrinterDataEx");
5480 torture_assert_int_equal(tctx, type, REG_BINARY, "type mismatch");
5481 torture_assert_int_equal(tctx, blob_out.length, blob_in.length, "size mismatch");
5482 torture_assert_mem_equal(tctx, blob_out.data, blob_in.data, blob_in.length, "buffer mismatch");
5484 torture_assert_int_equal(tctx, ecount, 1, "unexpected enum count");
5485 torture_assert_str_equal(tctx, einfo[0].value_name, values[i], "value_name mismatch");
5486 torture_assert_int_equal(tctx, einfo[0].value_name_len, strlen_m_term(values[i])*2, "unexpected value_name_len");
5487 torture_assert_int_equal(tctx, einfo[0].type, REG_BINARY, "type mismatch");
5488 torture_assert_int_equal(tctx, einfo[0].data_length, blob_in.length, "size mismatch");
5489 if (einfo[0].data_length > 0) {
5490 torture_assert_mem_equal(tctx, einfo[0].data->data, blob_in.data, blob_in.length, "buffer mismatch");
5493 torture_assert(tctx,
5494 test_DeletePrinterDataEx(tctx, b, handle, key, values[i]),
5495 "failed to call DeletePrinterDataEx");
5502 static bool test_SetPrinterDataEx_matrix(struct torture_context *tctx,
5503 struct dcerpc_pipe *p,
5504 struct policy_handle *handle,
5505 const char *printername,
5506 struct dcerpc_binding_handle *winreg_handle,
5507 struct policy_handle *hive_handle)
5509 struct dcerpc_binding_handle *b = p->binding_handle;
5510 const char *value_name = "dog";
5511 const char *key_name = "torturedataex";
5512 enum winreg_Type types[] = {
5518 const char *str = "abcdefghi";
5521 for (t=0; t < ARRAY_SIZE(types); t++) {
5522 for (s=0; s < strlen(str); s++) {
5524 enum winreg_Type type;
5525 const char *string = talloc_strndup(tctx, str, s);
5526 const char *array[2];
5527 DATA_BLOB blob = data_blob_string_const(string);
5530 uint32_t needed, offered = 0;
5532 struct spoolss_PrinterEnumValues *einfo;
5534 array[0] = talloc_strdup(tctx, string);
5537 if (types[t] == REG_DWORD) {
5544 offered = blob.length;
5547 data = data_blob_talloc(tctx, NULL, 4);
5548 SIVAL(data.data, 0, 0x12345678);
5552 torture_assert(tctx, push_reg_sz(tctx, &data, string), "");
5554 offered = data.length;
5555 /*strlen_m_term(data.string)*2;*/
5558 torture_assert(tctx, push_reg_multi_sz(tctx, &data, array), "");
5559 type = REG_MULTI_SZ;
5560 offered = data.length;
5563 torture_fail(tctx, talloc_asprintf(tctx, "type %d untested\n", types[t]));
5566 torture_assert(tctx,
5567 test_SetPrinterDataEx(tctx, b, handle, key_name, value_name, types[t], data.data, offered),
5568 "failed to call SetPrinterDataEx");
5570 torture_assert(tctx,
5571 test_GetPrinterDataEx_checktype(tctx, p, handle, key_name, value_name, &types[t], &type, &data_out, &needed),
5572 "failed to call GetPrinterDataEx");
5574 torture_assert(tctx,
5575 test_EnumPrinterDataEx(tctx, b, handle, key_name, &ecount, &einfo),
5576 "failed to call EnumPrinterDataEx");
5578 torture_assert_int_equal(tctx, types[t], type, "type mismatch");
5579 torture_assert_int_equal(tctx, needed, offered, "size mismatch");
5580 torture_assert_mem_equal(tctx, data_out, data.data, offered, "buffer mismatch");
5582 torture_assert_int_equal(tctx, ecount, 1, "unexpected enum count");
5583 torture_assert_str_equal(tctx, einfo[0].value_name, value_name, "value_name mismatch");
5584 torture_assert_int_equal(tctx, einfo[0].value_name_len, strlen_m_term(value_name)*2, "unexpected value_name_len");
5585 torture_assert_int_equal(tctx, einfo[0].type, types[t], "type mismatch");
5586 torture_assert_int_equal(tctx, einfo[0].data_length, offered, "size mismatch");
5587 if (einfo[0].data_length > 0) {
5588 torture_assert_mem_equal(tctx, einfo[0].data->data, data.data, offered, "buffer mismatch");
5591 if (winreg_handle && hive_handle) {
5592 enum winreg_Type w_type;
5597 torture_assert(tctx,
5598 test_winreg_query_printerdata(tctx, winreg_handle, hive_handle,
5599 printername, key_name, value_name,
5600 &w_type, &w_size, &w_length, &w_data), "");
5602 torture_assert_int_equal(tctx, w_type, types[t], "winreg type mismatch");
5603 torture_assert_int_equal(tctx, w_size, offered, "winreg size mismatch");
5604 torture_assert_int_equal(tctx, w_length, offered, "winreg length mismatch");
5605 torture_assert_mem_equal(tctx, w_data, data.data, offered, "winreg buffer mismatch");
5608 torture_assert(tctx,
5609 test_DeletePrinterDataEx(tctx, b, handle, key_name, value_name),
5610 "failed to call DeletePrinterDataEx");
5617 static bool test_PrinterData_winreg(struct torture_context *tctx,
5618 struct dcerpc_pipe *p,
5619 struct policy_handle *handle,
5620 const char *printer_name)
5622 struct dcerpc_binding_handle *b = p->binding_handle;
5623 struct dcerpc_pipe *p2;
5625 struct policy_handle hive_handle;
5626 struct dcerpc_binding_handle *b2;
5628 torture_assert_ntstatus_ok(tctx,
5629 torture_rpc_connection(tctx, &p2, &ndr_table_winreg),
5630 "could not open winreg pipe");
5631 b2 = p2->binding_handle;
5633 torture_assert(tctx, test_winreg_OpenHKLM(tctx, b2, &hive_handle), "");
5635 ret &= test_SetPrinterData_matrix(tctx, b, handle, printer_name, b2, &hive_handle);
5636 ret &= test_SetPrinterDataEx_matrix(tctx, p, handle, printer_name, b2, &hive_handle);
5638 test_winreg_CloseKey(tctx, b2, &hive_handle);
5645 static bool test_Forms_winreg(struct torture_context *tctx,
5646 struct dcerpc_binding_handle *b,
5647 struct policy_handle *handle,
5649 const char *printer_name)
5651 struct dcerpc_pipe *p2;
5653 struct policy_handle hive_handle;
5654 struct dcerpc_binding_handle *b2;
5656 torture_assert_ntstatus_ok(tctx,
5657 torture_rpc_connection(tctx, &p2, &ndr_table_winreg),
5658 "could not open winreg pipe");
5659 b2 = p2->binding_handle;
5661 torture_assert(tctx, test_winreg_OpenHKLM(tctx, b2, &hive_handle), "");
5663 ret = test_Forms(tctx, b, handle, print_server, printer_name, b2, &hive_handle);
5665 test_winreg_CloseKey(tctx, b2, &hive_handle);
5672 static bool test_PrinterInfo_winreg(struct torture_context *tctx,
5673 struct dcerpc_pipe *p,
5674 struct policy_handle *handle,
5675 const char *printer_name)
5677 struct dcerpc_binding_handle *b = p->binding_handle;
5678 struct dcerpc_pipe *p2;
5680 struct policy_handle hive_handle;
5681 struct dcerpc_binding_handle *b2;
5683 torture_assert_ntstatus_ok(tctx,
5684 torture_rpc_connection(tctx, &p2, &ndr_table_winreg),
5685 "could not open winreg pipe");
5686 b2 = p2->binding_handle;
5688 torture_assert(tctx, test_winreg_OpenHKLM(tctx, b2, &hive_handle), "");
5690 ret = test_GetPrinterInfo_winreg(tctx, b, handle, printer_name, b2, &hive_handle);
5692 test_winreg_CloseKey(tctx, b2, &hive_handle);
5699 static bool test_DriverInfo_winreg(struct torture_context *tctx,
5700 struct dcerpc_pipe *p,
5701 struct policy_handle *handle,
5702 const char *printer_name,
5703 const char *driver_name,
5704 const char *environment,
5705 enum spoolss_DriverOSVersion version)
5707 struct dcerpc_binding_handle *b = p->binding_handle;
5708 struct dcerpc_pipe *p2;
5710 struct policy_handle hive_handle;
5711 struct dcerpc_binding_handle *b2;
5713 torture_assert_ntstatus_ok(tctx,
5714 torture_rpc_connection(tctx, &p2, &ndr_table_winreg),
5715 "could not open winreg pipe");
5716 b2 = p2->binding_handle;
5718 torture_assert(tctx, test_winreg_OpenHKLM(tctx, b2, &hive_handle), "");
5720 ret = test_GetDriverInfo_winreg(tctx, b, handle, printer_name, driver_name, environment, version, b2, &hive_handle, NULL);
5722 test_winreg_CloseKey(tctx, b2, &hive_handle);
5729 static bool test_PrintProcessors_winreg(struct torture_context *tctx,
5730 struct dcerpc_binding_handle *b,
5731 const char *environment)
5733 struct dcerpc_pipe *p2;
5735 struct policy_handle hive_handle;
5736 struct dcerpc_binding_handle *b2;
5738 torture_assert_ntstatus_ok(tctx,
5739 torture_rpc_connection(tctx, &p2, &ndr_table_winreg),
5740 "could not open winreg pipe");
5741 b2 = p2->binding_handle;
5743 torture_assert(tctx, test_winreg_OpenHKLM(tctx, b2, &hive_handle), "");
5745 ret = test_PrintProcessors(tctx, b, environment, b2, &hive_handle);
5747 test_winreg_CloseKey(tctx, b2, &hive_handle);
5754 static bool test_PrinterData_DsSpooler(struct torture_context *tctx,
5755 struct dcerpc_pipe *p,
5756 struct policy_handle *handle,
5757 const char *printer_name)
5759 struct spoolss_SetPrinterInfoCtr info_ctr;
5760 struct spoolss_DevmodeContainer devmode_ctr;
5761 struct sec_desc_buf secdesc_ctr;
5762 union spoolss_SetPrinterInfo sinfo;
5763 union spoolss_PrinterInfo info;
5764 struct dcerpc_binding_handle *b = p->binding_handle;
5767 ZERO_STRUCT(info_ctr);
5768 ZERO_STRUCT(devmode_ctr);
5769 ZERO_STRUCT(secdesc_ctr);
5771 torture_comment(tctx, "Testing DsSpooler <-> SetPrinter relations\n");
5773 torture_assert(tctx,
5774 test_GetPrinter_level(tctx, b, handle, 2, &info),
5775 "failed to query Printer level 2");
5777 torture_assert(tctx,
5778 PrinterInfo_to_SetPrinterInfo(tctx, &info, 2, &sinfo),
5779 "failed to convert");
5782 info_ctr.info = sinfo;
5784 #define TEST_SZ(wname, iname) \
5786 enum winreg_Type type;\
5791 torture_assert(tctx,\
5792 test_GetPrinterDataEx(tctx, p, handle, "DsSpooler", wname, &type, &data, &needed),\
5793 "failed to query");\
5794 torture_assert_int_equal(tctx, type, REG_SZ, "unexpected type");\
5795 blob = data_blob_const(data, needed);\
5796 torture_assert(tctx,\
5797 pull_reg_sz(tctx, &blob, &str),\
5798 "failed to pull REG_SZ");\
5799 torture_assert_str_equal(tctx, str, iname, "unexpected result");\
5803 #define TEST_SET_SZ(wname, iname, val) \
5805 enum winreg_Type type;\
5810 sinfo.info2->iname = val;\
5811 torture_assert(tctx,\
5812 test_SetPrinter(tctx, b, handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0),\
5813 "failed to call SetPrinter");\
5814 torture_assert(tctx,\
5815 test_GetPrinterDataEx(tctx, p, handle, "DsSpooler", wname, &type, &data, &needed),\
5816 "failed to query");\
5817 torture_assert_int_equal(tctx, type, REG_SZ, "unexpected type");\
5818 blob = data_blob_const(data, needed);\
5819 torture_assert(tctx,\
5820 pull_reg_sz(tctx, &blob, &str),\
5821 "failed to pull REG_SZ");\
5822 torture_assert_str_equal(tctx, str, val, "unexpected result");\
5825 #define TEST_SET_DWORD(wname, iname, val) \
5827 enum winreg_Type type;\
5831 sinfo.info2->iname = val;\
5832 torture_assert(tctx,\
5833 test_SetPrinter(tctx, b, handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0),\
5834 "failed to call SetPrinter");\
5835 torture_assert(tctx,\
5836 test_GetPrinterDataEx(tctx, p, handle, "DsSpooler", wname, &type, &data, &needed),\
5837 "failed to query");\
5838 torture_assert_int_equal(tctx, type, REG_DWORD, "unexpected type");\
5839 torture_assert_int_equal(tctx, needed, 4, "unexpected length");\
5840 value = IVAL(data, 0); \
5841 torture_assert_int_equal(tctx, value, val, "unexpected result");\
5844 TEST_SET_SZ("description", comment, "newval");
5845 TEST_SET_SZ("location", location, "newval");
5846 TEST_SET_SZ("driverName", drivername, "newval");
5847 /* TEST_SET_DWORD("priority", priority, 25); */
5849 torture_assert(tctx,
5850 test_GetPrinter_level(tctx, b, handle, 2, &info),
5851 "failed to query Printer level 2");
5853 TEST_SZ("description", info.info2.comment);
5854 TEST_SZ("driverName", info.info2.drivername);
5855 TEST_SZ("location", info.info2.location);
5857 pname = strrchr(info.info2.printername, '\\');
5858 if (pname == NULL) {
5859 pname = info.info2.printername;
5863 TEST_SZ("printerName", pname);
5864 /* TEST_SZ("printSeparatorFile", info.info2.sepfile); */
5865 /* TEST_SZ("printShareName", info.info2.sharename); */
5867 /* FIXME gd: complete the list */
5873 torture_comment(tctx, "DsSpooler <-> SetPrinter relations test succeeded\n\n");
5878 static bool test_print_processors_winreg(struct torture_context *tctx,
5881 struct test_spoolss_context *ctx =
5882 talloc_get_type_abort(private_data, struct test_spoolss_context);
5883 struct dcerpc_pipe *p = ctx->spoolss_pipe;
5884 struct dcerpc_binding_handle *b = p->binding_handle;
5886 return test_PrintProcessors_winreg(tctx, b, ctx->environment);
5889 static bool test_AddPrintProcessor(struct torture_context *tctx,
5890 struct dcerpc_binding_handle *b,
5891 const char *environment,
5892 const char *path_name,
5893 const char *print_processor_name,
5894 WERROR expected_error)
5896 struct spoolss_AddPrintProcessor r;
5899 r.in.architecture = environment;
5900 r.in.path_name = path_name;
5901 r.in.print_processor_name = print_processor_name;
5903 torture_comment(tctx, "Testing AddPrintProcessor(%s)\n",
5904 print_processor_name);
5906 torture_assert_ntstatus_ok(tctx,
5907 dcerpc_spoolss_AddPrintProcessor_r(b, tctx, &r),
5908 "spoolss_AddPrintProcessor failed");
5909 torture_assert_werr_equal(tctx, r.out.result, expected_error,
5910 "spoolss_AddPrintProcessor failed");
5915 static bool test_DeletePrintProcessor(struct torture_context *tctx,
5916 struct dcerpc_binding_handle *b,
5917 const char *environment,
5918 const char *print_processor_name,
5919 WERROR expected_error)
5921 struct spoolss_DeletePrintProcessor r;
5924 r.in.architecture = environment;
5925 r.in.print_processor_name = print_processor_name;
5927 torture_comment(tctx, "Testing DeletePrintProcessor(%s)\n",
5928 print_processor_name);
5930 torture_assert_ntstatus_ok(tctx,
5931 dcerpc_spoolss_DeletePrintProcessor_r(b, tctx, &r),
5932 "spoolss_DeletePrintProcessor failed");
5933 torture_assert_werr_equal(tctx, r.out.result, expected_error,
5934 "spoolss_DeletePrintProcessor failed");
5939 static bool test_add_print_processor(struct torture_context *tctx,
5942 struct test_spoolss_context *ctx =
5943 talloc_get_type_abort(private_data, struct test_spoolss_context);
5944 struct dcerpc_pipe *p = ctx->spoolss_pipe;
5945 struct dcerpc_binding_handle *b = p->binding_handle;
5949 const char *environment;
5950 const char *path_name;
5951 const char *print_processor_name;
5952 WERROR expected_add_result;
5953 WERROR expected_del_result;
5956 .environment = ctx->environment,
5958 .print_processor_name = "winprint",
5959 .expected_add_result = WERR_PRINT_PROCESSOR_ALREADY_INSTALLED,
5960 .expected_del_result = WERR_CAN_NOT_COMPLETE
5962 .environment = ctx->environment,
5964 .print_processor_name = "unknown",
5965 .expected_add_result = WERR_MOD_NOT_FOUND,
5966 .expected_del_result = WERR_UNKNOWN_PRINTPROCESSOR
5970 for (i=0; i < ARRAY_SIZE(tests); i++) {
5971 torture_assert(tctx,
5972 test_AddPrintProcessor(tctx, b,
5973 tests[i].environment,
5975 tests[i].print_processor_name,
5976 tests[i].expected_add_result),
5977 "add print processor failed");
5978 torture_assert(tctx,
5979 test_DeletePrintProcessor(tctx, b,
5980 tests[i].environment,
5981 tests[i].print_processor_name,
5982 tests[i].expected_del_result),
5983 "delete print processor failed");
5989 static bool test_GetChangeID_PrinterData(struct torture_context *tctx,
5990 struct dcerpc_binding_handle *b,
5991 struct policy_handle *handle,
5992 uint32_t *change_id)
5994 enum winreg_Type type;
5998 torture_assert(tctx,
5999 test_GetPrinterData(tctx, b, handle, "ChangeID", &type, &data, &needed),
6000 "failed to call GetPrinterData");
6002 torture_assert(tctx, type == REG_DWORD, "unexpected type");
6003 torture_assert_int_equal(tctx, needed, 4, "unexpected size");
6005 *change_id = IVAL(data, 0);
6010 static bool test_GetChangeID_PrinterDataEx(struct torture_context *tctx,
6011 struct dcerpc_pipe *p,
6012 struct policy_handle *handle,
6013 uint32_t *change_id)
6015 enum winreg_Type type;
6019 torture_assert(tctx,
6020 test_GetPrinterDataEx(tctx, p, handle, "PrinterDriverData", "ChangeID", &type, &data, &needed),
6021 "failed to call GetPrinterData");
6023 torture_assert(tctx, type == REG_DWORD, "unexpected type");
6024 torture_assert_int_equal(tctx, needed, 4, "unexpected size");
6026 *change_id = IVAL(data, 0);
6031 static bool test_GetChangeID_PrinterInfo(struct torture_context *tctx,
6032 struct dcerpc_binding_handle *b,
6033 struct policy_handle *handle,
6034 uint32_t *change_id)
6036 union spoolss_PrinterInfo info;
6038 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 0, &info),
6039 "failed to query Printer level 0");
6041 *change_id = info.info0.change_id;
6046 static bool test_ChangeID(struct torture_context *tctx,
6047 struct dcerpc_pipe *p,
6048 struct policy_handle *handle)
6050 uint32_t change_id, change_id_ex, change_id_info;
6051 uint32_t change_id2, change_id_ex2, change_id_info2;
6052 union spoolss_PrinterInfo info;
6053 const char *comment;
6054 struct dcerpc_binding_handle *b = p->binding_handle;
6056 torture_comment(tctx, "Testing ChangeID: id change test #1\n");
6058 torture_assert(tctx, test_GetChangeID_PrinterData(tctx, b, handle, &change_id),
6059 "failed to query for ChangeID");
6060 torture_assert(tctx, test_GetChangeID_PrinterDataEx(tctx, p, handle, &change_id_ex),
6061 "failed to query for ChangeID");
6062 torture_assert(tctx, test_GetChangeID_PrinterInfo(tctx, b, handle, &change_id_info),
6063 "failed to query for ChangeID");
6065 torture_assert_int_equal(tctx, change_id, change_id_ex,
6066 "change_ids should all be equal");
6067 torture_assert_int_equal(tctx, change_id_ex, change_id_info,
6068 "change_ids should all be equal");
6071 torture_comment(tctx, "Testing ChangeID: id change test #2\n");
6073 torture_assert(tctx, test_GetChangeID_PrinterData(tctx, b, handle, &change_id),
6074 "failed to query for ChangeID");
6075 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info),
6076 "failed to query Printer level 2");
6077 torture_assert(tctx, test_GetChangeID_PrinterDataEx(tctx, p, handle, &change_id_ex),
6078 "failed to query for ChangeID");
6079 torture_assert(tctx, test_GetChangeID_PrinterInfo(tctx, b, handle, &change_id_info),
6080 "failed to query for ChangeID");
6081 torture_assert_int_equal(tctx, change_id, change_id_ex,
6082 "change_id should not have changed");
6083 torture_assert_int_equal(tctx, change_id_ex, change_id_info,
6084 "change_id should not have changed");
6087 torture_comment(tctx, "Testing ChangeID: id change test #3\n");
6089 torture_assert(tctx, test_GetChangeID_PrinterData(tctx, b, handle, &change_id),
6090 "failed to query for ChangeID");
6091 torture_assert(tctx, test_GetChangeID_PrinterDataEx(tctx, p, handle, &change_id_ex),
6092 "failed to query for ChangeID");
6093 torture_assert(tctx, test_GetChangeID_PrinterInfo(tctx, b, handle, &change_id_info),
6094 "failed to query for ChangeID");
6095 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info),
6096 "failed to query Printer level 2");
6097 comment = talloc_strdup(tctx, info.info2.comment);
6100 struct spoolss_SetPrinterInfoCtr info_ctr;
6101 struct spoolss_DevmodeContainer devmode_ctr;
6102 struct sec_desc_buf secdesc_ctr;
6103 union spoolss_SetPrinterInfo sinfo;
6105 ZERO_STRUCT(info_ctr);
6106 ZERO_STRUCT(devmode_ctr);
6107 ZERO_STRUCT(secdesc_ctr);
6110 torture_assert(tctx, PrinterInfo_to_SetPrinterInfo(tctx, &info, 2, &sinfo), "");
6111 sinfo.info2->comment = "torture_comment";
6114 info_ctr.info = sinfo;
6116 torture_assert(tctx, test_SetPrinter(tctx, b, handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0),
6117 "failed to call SetPrinter");
6119 sinfo.info2->comment = comment;
6121 torture_assert(tctx, test_SetPrinter(tctx, b, handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0),
6122 "failed to call SetPrinter");
6126 torture_assert(tctx, test_GetChangeID_PrinterData(tctx, b, handle, &change_id2),
6127 "failed to query for ChangeID");
6128 torture_assert(tctx, test_GetChangeID_PrinterDataEx(tctx, p, handle, &change_id_ex2),
6129 "failed to query for ChangeID");
6130 torture_assert(tctx, test_GetChangeID_PrinterInfo(tctx, b, handle, &change_id_info2),
6131 "failed to query for ChangeID");
6133 torture_assert_int_equal(tctx, change_id2, change_id_ex2,
6134 "change_ids should all be equal");
6135 torture_assert_int_equal(tctx, change_id_ex2, change_id_info2,
6136 "change_ids should all be equal");
6138 torture_assert(tctx, (change_id < change_id2),
6139 talloc_asprintf(tctx, "change_id %d needs to be larger than change_id %d",
6140 change_id2, change_id));
6141 torture_assert(tctx, (change_id_ex < change_id_ex2),
6142 talloc_asprintf(tctx, "change_id %d needs to be larger than change_id %d",
6143 change_id_ex2, change_id_ex));
6144 torture_assert(tctx, (change_id_info < change_id_info2),
6145 talloc_asprintf(tctx, "change_id %d needs to be larger than change_id %d",
6146 change_id_info2, change_id_info));
6148 torture_comment(tctx, "ChangeID tests succeeded\n\n");
6153 static bool test_SecondaryClosePrinter(struct torture_context *tctx,
6154 struct dcerpc_pipe *p,
6155 struct policy_handle *handle)
6158 struct dcerpc_binding *b;
6159 struct dcerpc_pipe *p2;
6160 struct spoolss_ClosePrinter cp;
6162 /* only makes sense on SMB */
6163 if (p->conn->transport.transport != NCACN_NP) {
6167 torture_comment(tctx, "Testing close on secondary pipe\n");
6169 status = dcerpc_parse_binding(tctx, p->conn->binding_string, &b);
6170 torture_assert_ntstatus_ok(tctx, status, "Failed to parse dcerpc binding");
6172 status = dcerpc_secondary_connection(p, &p2, b);
6173 torture_assert_ntstatus_ok(tctx, status, "Failed to create secondary connection");
6175 status = dcerpc_bind_auth_none(p2, &ndr_table_spoolss);
6176 torture_assert_ntstatus_ok(tctx, status, "Failed to create bind on secondary connection");
6178 cp.in.handle = handle;
6179 cp.out.handle = handle;
6181 status = dcerpc_spoolss_ClosePrinter_r(p2->binding_handle, tctx, &cp);
6182 torture_assert_ntstatus_equal(tctx, status, NT_STATUS_RPC_SS_CONTEXT_MISMATCH,
6183 "ERROR: Allowed close on secondary connection");
6190 static bool test_OpenPrinter_badname(struct torture_context *tctx,
6191 struct dcerpc_binding_handle *b, const char *name)
6194 struct spoolss_OpenPrinter op;
6195 struct spoolss_OpenPrinterEx opEx;
6196 struct policy_handle handle;
6199 op.in.printername = name;
6200 op.in.datatype = NULL;
6201 op.in.devmode_ctr.devmode= NULL;
6202 op.in.access_mask = 0;
6203 op.out.handle = &handle;
6205 torture_comment(tctx, "Testing OpenPrinter(%s) with bad name\n", op.in.printername);
6207 status = dcerpc_spoolss_OpenPrinter_r(b, tctx, &op);
6208 torture_assert_ntstatus_ok(tctx, status, "OpenPrinter failed");
6209 torture_assert_werr_equal(tctx, op.out.result, WERR_INVALID_PRINTER_NAME,
6210 "unexpected result");
6212 if (W_ERROR_IS_OK(op.out.result)) {
6213 ret &=test_ClosePrinter(tctx, b, &handle);
6216 opEx.in.printername = name;
6217 opEx.in.datatype = NULL;
6218 opEx.in.devmode_ctr.devmode = NULL;
6219 opEx.in.access_mask = 0;
6220 opEx.in.userlevel_ctr.level = 1;
6221 opEx.in.userlevel_ctr.user_info.level1 = NULL;
6222 opEx.out.handle = &handle;
6224 torture_comment(tctx, "Testing OpenPrinterEx(%s) with bad name\n", opEx.in.printername);
6226 status = dcerpc_spoolss_OpenPrinterEx_r(b, tctx, &opEx);
6227 torture_assert_ntstatus_ok(tctx, status, "OpenPrinterEx failed");
6228 torture_assert_werr_equal(tctx, opEx.out.result, WERR_INVALID_PARAM,
6229 "unexpected result");
6231 if (W_ERROR_IS_OK(opEx.out.result)) {
6232 ret &=test_ClosePrinter(tctx, b, &handle);
6238 static bool test_OpenPrinter_badname_list(struct torture_context *tctx,
6241 struct test_spoolss_context *ctx =
6242 talloc_get_type_abort(private_data, struct test_spoolss_context);
6244 const char *badnames[] = {
6245 "__INVALID_PRINTER__",
6246 "\\\\__INVALID_HOST__",
6249 "\\\\\\__INVALID_PRINTER__"
6251 const char *badname;
6252 struct dcerpc_pipe *p = ctx->spoolss_pipe;
6253 const char *server_name = dcerpc_server_name(p);
6254 struct dcerpc_binding_handle *b = p->binding_handle;
6257 for (i=0; i < ARRAY_SIZE(badnames); i++) {
6258 torture_assert(tctx,
6259 test_OpenPrinter_badname(tctx, b, badnames[i]),
6263 badname = talloc_asprintf(tctx, "\\\\%s\\", server_name);
6264 torture_assert(tctx,
6265 test_OpenPrinter_badname(tctx, b, badname),
6268 badname = talloc_asprintf(tctx, "\\\\%s\\__INVALID_PRINTER__", server_name);
6269 torture_assert(tctx,
6270 test_OpenPrinter_badname(tctx, b, badname),
6276 static bool test_OpenPrinter(struct torture_context *tctx,
6277 struct dcerpc_pipe *p,
6279 const char *environment,
6283 struct spoolss_OpenPrinter r;
6284 struct policy_handle handle;
6286 struct dcerpc_binding_handle *b = p->binding_handle;
6288 r.in.printername = name;
6289 r.in.datatype = NULL;
6290 r.in.devmode_ctr.devmode= NULL;
6291 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
6292 r.out.handle = &handle;
6294 torture_comment(tctx, "Testing OpenPrinter(%s)\n", r.in.printername);
6296 status = dcerpc_spoolss_OpenPrinter_r(b, tctx, &r);
6298 torture_assert_ntstatus_ok(tctx, status, "OpenPrinter failed");
6300 torture_assert_werr_ok(tctx, r.out.result, "OpenPrinter failed");
6306 if (!test_GetPrinter(tctx, b, &handle, environment)) {
6310 if (!torture_setting_bool(tctx, "samba3", false)) {
6311 if (!test_SecondaryClosePrinter(tctx, p, &handle)) {
6317 if (!test_ClosePrinter(tctx, b, &handle)) {
6324 static bool test_OpenPrinterEx(struct torture_context *tctx,
6325 struct dcerpc_binding_handle *b,
6326 const char *printername,
6327 const char *datatype,
6328 struct spoolss_DeviceMode *devmode,
6329 uint32_t access_mask,
6330 struct spoolss_UserLevelCtr *userlevel_ctr,
6331 struct policy_handle *handle,
6332 WERROR expected_result)
6334 struct spoolss_OpenPrinterEx r;
6336 r.in.printername = printername;
6337 r.in.datatype = datatype;
6338 r.in.devmode_ctr.devmode= devmode;
6339 r.in.access_mask = access_mask;
6340 r.in.userlevel_ctr = *userlevel_ctr;
6341 r.out.handle = handle;
6343 torture_comment(tctx, "Testing OpenPrinterEx(%s)\n", r.in.printername);
6345 torture_assert_ntstatus_ok(tctx,
6346 dcerpc_spoolss_OpenPrinterEx_r(b, tctx, &r),
6347 "OpenPrinterEx failed");
6349 torture_assert_werr_equal(tctx, r.out.result, expected_result,
6350 "OpenPrinterEx failed");
6355 static bool call_OpenPrinterEx(struct torture_context *tctx,
6356 struct dcerpc_pipe *p,
6358 struct spoolss_DeviceMode *devmode,
6359 struct policy_handle *handle)
6361 struct spoolss_UserLevelCtr userlevel_ctr;
6362 struct spoolss_UserLevel1 userlevel1;
6363 struct dcerpc_binding_handle *b = p->binding_handle;
6365 userlevel1.size = 1234;
6366 userlevel1.client = "hello";
6367 userlevel1.user = "spottyfoot!";
6368 userlevel1.build = 1;
6369 userlevel1.major = 2;
6370 userlevel1.minor = 3;
6371 userlevel1.processor = 4;
6373 userlevel_ctr.level = 1;
6374 userlevel_ctr.user_info.level1 = &userlevel1;
6376 return test_OpenPrinterEx(tctx, b, name, NULL, devmode,
6377 SEC_FLAG_MAXIMUM_ALLOWED,
6383 static bool test_printer_rename(struct torture_context *tctx,
6386 struct torture_printer_context *t =
6387 (struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context);
6388 struct dcerpc_pipe *p = t->spoolss_pipe;
6391 union spoolss_PrinterInfo info;
6392 union spoolss_SetPrinterInfo sinfo;
6393 struct spoolss_SetPrinterInfoCtr info_ctr;
6394 struct spoolss_DevmodeContainer devmode_ctr;
6395 struct sec_desc_buf secdesc_ctr;
6396 const char *printer_name;
6397 const char *printer_name_orig;
6398 const char *printer_name_new = "SAMBA smbtorture Test Printer (Copy 2)";
6399 struct policy_handle new_handle;
6401 struct dcerpc_binding_handle *b = p->binding_handle;
6403 ZERO_STRUCT(devmode_ctr);
6404 ZERO_STRUCT(secdesc_ctr);
6406 torture_comment(tctx, "Testing Printer rename operations\n");
6408 torture_assert(tctx,
6409 test_GetPrinter_level(tctx, b, &t->handle, 2, &info),
6410 "failed to call GetPrinter level 2");
6412 printer_name_orig = talloc_strdup(tctx, info.info2.printername);
6414 q = strrchr(info.info2.printername, '\\');
6416 torture_warning(tctx,
6417 "server returns printername %s incl. servername although we did not set servername", info.info2.printername);
6420 torture_assert(tctx,
6421 PrinterInfo_to_SetPrinterInfo(tctx, &info, 2, &sinfo), "");
6423 sinfo.info2->printername = printer_name_new;
6426 info_ctr.info = sinfo;
6428 torture_assert(tctx,
6429 test_SetPrinter(tctx, b, &t->handle, &info_ctr, &devmode_ctr, &secdesc_ctr, 0),
6430 "failed to call SetPrinter level 2");
6432 torture_assert(tctx,
6433 test_GetPrinter_level(tctx, b, &t->handle, 2, &info),
6434 "failed to call GetPrinter level 2");
6436 printer_name = talloc_strdup(tctx, info.info2.printername);
6438 q = strrchr(info.info2.printername, '\\');
6440 torture_warning(tctx,
6441 "server returns printername %s incl. servername although we did not set servername", info.info2.printername);
6446 torture_assert_str_equal(tctx, printer_name, printer_name_new,
6447 "new printer name was not set");
6449 /* samba currently cannot fully rename printers */
6450 if (!torture_setting_bool(tctx, "samba3", false)) {
6451 torture_assert(tctx,
6452 test_OpenPrinter_badname(tctx, b, printer_name_orig),
6453 "still can open printer with oldname after rename");
6455 torture_warning(tctx, "*not* checking for open with oldname after rename for samba3");
6458 torture_assert(tctx,
6459 call_OpenPrinterEx(tctx, p, printer_name_new, NULL, &new_handle),
6460 "failed to open printer with new name");
6462 torture_assert(tctx,
6463 test_GetPrinter_level(tctx, b, &new_handle, 2, &info),
6464 "failed to call GetPrinter level 2");
6466 torture_assert_str_equal(tctx, info.info2.printername, printer_name_new,
6467 "new printer name was not set");
6469 torture_assert(tctx,
6470 test_ClosePrinter(tctx, b, &new_handle),
6471 "failed to close printer");
6473 torture_comment(tctx, "Printer rename operations test succeeded\n\n");
6478 static bool test_openprinter(struct torture_context *tctx,
6479 struct dcerpc_binding_handle *b,
6480 const char *real_printername)
6482 struct spoolss_UserLevelCtr userlevel_ctr;
6483 struct policy_handle handle;
6484 struct spoolss_UserLevel1 userlevel1;
6485 const char *printername = NULL;
6490 WERROR expected_result;
6493 .suffix = "rubbish",
6494 .expected_result = WERR_INVALID_PRINTER_NAME
6496 .suffix = ", LocalOnl",
6497 .expected_result = WERR_INVALID_PRINTER_NAME
6499 .suffix = ", localOnly",
6500 .expected_result = WERR_INVALID_PRINTER_NAME
6502 .suffix = ", localonl",
6503 .expected_result = WERR_INVALID_PRINTER_NAME
6505 .suffix = ",LocalOnl",
6506 .expected_result = WERR_INVALID_PRINTER_NAME
6508 .suffix = ",localOnl2",
6509 .expected_result = WERR_INVALID_PRINTER_NAME
6511 .suffix = ", DrvConver2t",
6512 .expected_result = WERR_INVALID_PRINTER_NAME
6514 .suffix = ", drvconvert",
6515 .expected_result = WERR_INVALID_PRINTER_NAME
6517 .suffix = ",drvconvert",
6518 .expected_result = WERR_INVALID_PRINTER_NAME
6520 .suffix = ", DrvConvert",
6521 .expected_result = WERR_OK
6523 .suffix = " , DrvConvert",
6524 .expected_result = WERR_INVALID_PRINTER_NAME
6526 .suffix = ",DrvConvert",
6527 .expected_result = WERR_OK
6529 .suffix = ", DrvConvertsadfasdf",
6530 .expected_result = WERR_OK
6532 .suffix = ",DrvConvertasdfasd",
6533 .expected_result = WERR_OK
6535 .suffix = ", LocalOnly",
6536 .expected_result = WERR_OK
6538 .suffix = " , LocalOnly",
6539 .expected_result = WERR_INVALID_PRINTER_NAME
6541 .suffix = ",LocalOnly",
6542 .expected_result = WERR_OK
6544 .suffix = ", LocalOnlysagi4gjfkd",
6545 .expected_result = WERR_OK
6547 .suffix = ",LocalOnlysagi4gjfkd",
6548 .expected_result = WERR_OK
6552 userlevel1.size = 1234;
6553 userlevel1.client = "hello";
6554 userlevel1.user = "spottyfoot!";
6555 userlevel1.build = 1;
6556 userlevel1.major = 2;
6557 userlevel1.minor = 3;
6558 userlevel1.processor = 4;
6560 userlevel_ctr.level = 1;
6561 userlevel_ctr.user_info.level1 = &userlevel1;
6563 torture_comment(tctx, "Testing openprinterex printername pattern\n");
6565 torture_assert(tctx,
6566 test_OpenPrinterEx(tctx, b, real_printername, NULL, NULL, 0,
6567 &userlevel_ctr, &handle,
6569 "OpenPrinterEx failed");
6570 test_ClosePrinter(tctx, b, &handle);
6572 for (i=0; i < ARRAY_SIZE(tests); i++) {
6574 printername = talloc_asprintf(tctx, "%s%s",
6578 torture_assert(tctx,
6579 test_OpenPrinterEx(tctx, b, printername, NULL, NULL, 0,
6580 &userlevel_ctr, &handle,
6581 tests[i].expected_result),
6582 "OpenPrinterEx failed");
6583 if (W_ERROR_IS_OK(tests[i].expected_result)) {
6584 test_ClosePrinter(tctx, b, &handle);
6592 static bool test_existing_printer_openprinterex(struct torture_context *tctx,
6593 struct dcerpc_pipe *p,
6595 const char *environment)
6597 struct policy_handle handle;
6599 struct dcerpc_binding_handle *b = p->binding_handle;
6601 if (!test_openprinter(tctx, b, name)) {
6605 if (!call_OpenPrinterEx(tctx, p, name, NULL, &handle)) {
6609 if (!test_PrinterInfo_SD(tctx, b, &handle)) {
6613 if (!test_GetPrinter(tctx, b, &handle, environment)) {
6617 if (!test_EnumForms_all(tctx, b, &handle, false)) {
6621 if (!test_Forms(tctx, b, &handle, false, name, NULL, NULL)) {
6625 if (!test_Forms_winreg(tctx, b, &handle, false, name)) {
6629 if (!test_EnumPrinterData_all(tctx, p, &handle)) {
6633 if (!test_EnumPrinterDataEx(tctx, b, &handle, "PrinterDriverData", NULL, NULL)) {
6637 if (!test_EnumPrinterData_consistency(tctx, p, &handle)) {
6641 if (!test_printer_all_keys(tctx, b, &handle)) {
6645 if (!test_PausePrinter(tctx, b, &handle)) {
6649 if (!test_DoPrintTest(tctx, b, &handle)) {
6653 if (!test_ResumePrinter(tctx, b, &handle)) {
6657 if (!test_SetPrinterData_matrix(tctx, b, &handle, name, NULL, NULL)) {
6661 if (!test_SetPrinterDataEx_matrix(tctx, p, &handle, name, NULL, NULL)) {
6665 if (!torture_setting_bool(tctx, "samba3", false)) {
6666 if (!test_SecondaryClosePrinter(tctx, p, &handle)) {
6671 if (!test_ClosePrinter(tctx, b, &handle)) {
6678 static bool test_EnumPrinters_old(struct torture_context *tctx,
6681 struct test_spoolss_context *ctx =
6682 talloc_get_type_abort(private_data, struct test_spoolss_context);
6683 struct spoolss_EnumPrinters r;
6685 uint16_t levels[] = {1, 2, 4, 5};
6688 struct dcerpc_pipe *p = ctx->spoolss_pipe;
6689 struct dcerpc_binding_handle *b = p->binding_handle;
6691 for (i=0;i<ARRAY_SIZE(levels);i++) {
6692 union spoolss_PrinterInfo *info;
6697 r.in.flags = PRINTER_ENUM_LOCAL;
6699 r.in.level = levels[i];
6702 r.out.needed = &needed;
6703 r.out.count = &count;
6706 torture_comment(tctx, "Testing EnumPrinters level %u\n", r.in.level);
6708 status = dcerpc_spoolss_EnumPrinters_r(b, tctx, &r);
6709 torture_assert_ntstatus_ok(tctx, status, "EnumPrinters failed");
6711 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
6712 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
6713 r.in.buffer = &blob;
6714 r.in.offered = needed;
6715 status = dcerpc_spoolss_EnumPrinters_r(b, tctx, &r);
6718 torture_assert_ntstatus_ok(tctx, status, "EnumPrinters failed");
6720 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinters failed");
6722 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPrinters, info, r.in.level, count, needed, 4);
6725 torture_comment(tctx, "No printers returned\n");
6729 for (j=0;j<count;j++) {
6730 if (r.in.level == 1) {
6731 char *unc = talloc_strdup(tctx, info[j].info1.name);
6732 char *slash, *name, *full_name;
6734 if (unc[0] == '\\' && unc[1] == '\\') {
6737 slash = strchr(unc, '\\');
6742 full_name = talloc_asprintf(tctx, "\\\\%s\\%s",
6743 dcerpc_server_name(p), name);
6744 if (!test_OpenPrinter(tctx, p, name, ctx->environment, true)) {
6747 if (!test_OpenPrinter(tctx, p, full_name, ctx->environment, true)) {
6750 if (!test_OpenPrinter(tctx, p, name, ctx->environment, false)) {
6753 if (!test_existing_printer_openprinterex(tctx, p, name, ctx->environment)) {
6763 static bool test_EnumPrinters_level(struct torture_context *tctx,
6764 struct dcerpc_binding_handle *b,
6766 const char *servername,
6769 union spoolss_PrinterInfo **info_p)
6771 struct spoolss_EnumPrinters r;
6772 union spoolss_PrinterInfo *info;
6777 r.in.server = servername;
6781 r.out.needed = &needed;
6782 r.out.count = &count;
6785 torture_comment(tctx, "Testing EnumPrinters(%s) level %u\n",
6786 r.in.server, r.in.level);
6788 torture_assert_ntstatus_ok(tctx,
6789 dcerpc_spoolss_EnumPrinters_r(b, tctx, &r),
6790 "EnumPrinters failed");
6791 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
6792 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
6793 r.in.buffer = &blob;
6794 r.in.offered = needed;
6795 torture_assert_ntstatus_ok(tctx,
6796 dcerpc_spoolss_EnumPrinters_r(b, tctx, &r),
6797 "EnumPrinters failed");
6800 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinters failed");
6802 CHECK_NEEDED_SIZE_ENUM_LEVEL(spoolss_EnumPrinters, info, r.in.level, count, needed, 4);
6814 static const char *get_short_printername(struct torture_context *tctx,
6817 const char *short_name;
6819 if (name[0] == '\\' && name[1] == '\\') {
6821 short_name = strchr(name, '\\');
6823 return talloc_strdup(tctx, short_name+1);
6830 static const char *get_full_printername(struct torture_context *tctx,
6833 const char *full_name = talloc_strdup(tctx, name);
6836 if (name && name[0] == '\\' && name[1] == '\\') {
6838 p = strchr(name, '\\');
6847 static bool test_OnePrinter_servername(struct torture_context *tctx,
6848 struct dcerpc_pipe *p,
6849 struct dcerpc_binding_handle *b,
6850 const char *servername,
6851 const char *printername)
6853 union spoolss_PrinterInfo info;
6854 const char *short_name = get_short_printername(tctx, printername);
6855 const char *full_name = get_full_printername(tctx, printername);
6858 struct policy_handle handle;
6859 torture_assert(tctx,
6860 call_OpenPrinterEx(tctx, p, short_name, NULL, &handle),
6861 "failed to open printer");
6863 torture_assert(tctx,
6864 test_GetPrinter_level(tctx, b, &handle, 2, &info),
6865 "failed to get printer info");
6867 torture_assert_casestr_equal(tctx, info.info2.servername, NULL,
6868 "unexpected servername");
6869 torture_assert_casestr_equal(tctx, info.info2.printername, short_name,
6870 "unexpected printername");
6872 if (info.info2.devmode) {
6873 const char *expected_devicename;
6874 expected_devicename = talloc_strndup(tctx, short_name, MIN(strlen(short_name), 31));
6875 torture_assert_casestr_equal(tctx, info.info2.devmode->devicename, expected_devicename,
6876 "unexpected devicemode devicename");
6879 torture_assert(tctx,
6880 test_ClosePrinter(tctx, b, &handle),
6881 "failed to close printer");
6885 struct policy_handle handle;
6887 torture_assert(tctx,
6888 call_OpenPrinterEx(tctx, p, full_name, NULL, &handle),
6889 "failed to open printer");
6891 torture_assert(tctx,
6892 test_GetPrinter_level(tctx, b, &handle, 2, &info),
6893 "failed to get printer info");
6895 torture_assert_casestr_equal(tctx, info.info2.servername, servername,
6896 "unexpected servername");
6897 torture_assert_casestr_equal(tctx, info.info2.printername, full_name,
6898 "unexpected printername");
6900 if (info.info2.devmode) {
6901 const char *expected_devicename;
6902 expected_devicename = talloc_strndup(tctx, full_name, MIN(strlen(full_name), 31));
6903 torture_assert_casestr_equal(tctx, info.info2.devmode->devicename, expected_devicename,
6904 "unexpected devicemode devicename");
6907 torture_assert(tctx,
6908 test_ClosePrinter(tctx, b, &handle),
6909 "failed to close printer");
6915 static bool test_EnumPrinters_servername(struct torture_context *tctx,
6918 struct test_spoolss_context *ctx =
6919 talloc_get_type_abort(private_data, struct test_spoolss_context);
6921 struct dcerpc_pipe *p = ctx->spoolss_pipe;
6922 struct dcerpc_binding_handle *b = p->binding_handle;
6924 union spoolss_PrinterInfo *info;
6925 const char *servername;
6926 uint32_t flags = PRINTER_ENUM_NAME|PRINTER_ENUM_LOCAL;
6928 torture_comment(tctx, "Testing servername behaviour in EnumPrinters and GetPrinters\n");
6930 servername = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
6932 torture_assert(tctx,
6933 test_EnumPrinters_level(tctx, b, flags, servername, 2, &count, &info),
6934 "failed to enumerate printers");
6936 for (i=0; i < count; i++) {
6938 torture_assert_casestr_equal(tctx, info[i].info2.servername, servername,
6939 "unexpected servername");
6941 torture_assert(tctx,
6942 test_OnePrinter_servername(tctx, p, b, servername, info[i].info2.printername),
6943 "failed to check printer");
6948 torture_assert(tctx,
6949 test_EnumPrinters_level(tctx, b, flags, servername, 2, &count, &info),
6950 "failed to enumerate printers");
6952 for (i=0; i < count; i++) {
6954 torture_assert_casestr_equal(tctx, info[i].info2.servername, NULL,
6955 "unexpected servername");
6957 torture_assert(tctx,
6958 test_OnePrinter_servername(tctx, p, b, servername, info[i].info2.printername),
6959 "failed to check printer");
6967 static bool test_GetPrinterDriver(struct torture_context *tctx,
6968 struct dcerpc_binding_handle *b,
6969 struct policy_handle *handle,
6970 const char *driver_name)
6972 struct spoolss_GetPrinterDriver r;
6975 r.in.handle = handle;
6976 r.in.architecture = "W32X86";
6980 r.out.needed = &needed;
6982 torture_comment(tctx, "Testing GetPrinterDriver level %d\n", r.in.level);
6984 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_GetPrinterDriver_r(b, tctx, &r),
6985 "failed to call GetPrinterDriver");
6986 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
6987 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
6988 r.in.buffer = &blob;
6989 r.in.offered = needed;
6990 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_GetPrinterDriver_r(b, tctx, &r),
6991 "failed to call GetPrinterDriver");
6994 torture_assert_werr_ok(tctx, r.out.result,
6995 "failed to call GetPrinterDriver");
6997 CHECK_NEEDED_SIZE_LEVEL(spoolss_DriverInfo, r.out.info, r.in.level, needed, 4);
7003 static bool test_GetPrinterDriver2_level(struct torture_context *tctx,
7004 struct dcerpc_binding_handle *b,
7005 struct policy_handle *handle,
7006 const char *driver_name,
7007 const char *architecture,
7009 uint32_t client_major_version,
7010 uint32_t client_minor_version,
7011 union spoolss_DriverInfo *info_p,
7015 struct spoolss_GetPrinterDriver2 r;
7017 uint32_t server_major_version;
7018 uint32_t server_minor_version;
7020 r.in.handle = handle;
7021 r.in.architecture = architecture;
7022 r.in.client_major_version = client_major_version;
7023 r.in.client_minor_version = client_minor_version;
7027 r.out.needed = &needed;
7028 r.out.server_major_version = &server_major_version;
7029 r.out.server_minor_version = &server_minor_version;
7031 torture_comment(tctx, "Testing GetPrinterDriver2(%s) level %d\n",
7032 driver_name, r.in.level);
7034 torture_assert_ntstatus_ok(tctx,
7035 dcerpc_spoolss_GetPrinterDriver2_r(b, tctx, &r),
7036 "failed to call GetPrinterDriver2");
7037 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
7038 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
7039 r.in.buffer = &blob;
7040 r.in.offered = needed;
7041 torture_assert_ntstatus_ok(tctx,
7042 dcerpc_spoolss_GetPrinterDriver2_r(b, tctx, &r),
7043 "failed to call GetPrinterDriver2");
7047 *result_p = r.out.result;
7050 if (W_ERROR_EQUAL(r.out.result, WERR_INVALID_LEVEL)) {
7051 switch (r.in.level) {
7054 torture_comment(tctx,
7055 "level %d not implemented, not considering as an error\n",
7063 torture_assert_werr_ok(tctx, r.out.result,
7064 "failed to call GetPrinterDriver2");
7066 CHECK_NEEDED_SIZE_LEVEL(spoolss_DriverInfo, r.out.info, r.in.level, needed, 4);
7069 *info_p = *r.out.info;
7075 static bool test_GetPrinterDriver2(struct torture_context *tctx,
7076 struct dcerpc_binding_handle *b,
7077 struct policy_handle *handle,
7078 const char *driver_name,
7079 const char *architecture)
7081 uint16_t levels[] = {1, 2, 3, 4, 5, 6, 8, 101 };
7085 for (i=0;i<ARRAY_SIZE(levels);i++) {
7087 torture_assert(tctx,
7088 test_GetPrinterDriver2_level(tctx, b, handle, driver_name, architecture, levels[i], 3, 0, NULL, NULL),
7095 static bool test_EnumPrinterDrivers_old(struct torture_context *tctx,
7098 struct test_spoolss_context *ctx =
7099 talloc_get_type_abort(private_data, struct test_spoolss_context);
7100 uint16_t levels[] = {1, 2, 3, 4, 5, 6};
7102 struct dcerpc_pipe *p = ctx->spoolss_pipe;
7103 struct dcerpc_binding_handle *b = p->binding_handle;
7104 const char *server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
7106 for (i=0;i<ARRAY_SIZE(levels);i++) {
7109 union spoolss_DriverInfo *info;
7111 torture_assert(tctx,
7112 test_EnumPrinterDrivers_args(tctx, b, server_name, ctx->environment, levels[i], &count, &info),
7113 "failed to enumerate drivers");
7116 torture_comment(tctx, "No printer drivers returned\n");
7124 static bool test_DeletePrinter(struct torture_context *tctx,
7125 struct dcerpc_binding_handle *b,
7126 struct policy_handle *handle)
7128 struct spoolss_DeletePrinter r;
7130 torture_comment(tctx, "Testing DeletePrinter\n");
7132 r.in.handle = handle;
7134 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_DeletePrinter_r(b, tctx, &r),
7135 "failed to delete printer");
7136 torture_assert_werr_ok(tctx, r.out.result,
7137 "failed to delete printer");
7142 static bool test_EnumPrinters_findname(struct torture_context *tctx,
7143 struct dcerpc_binding_handle *b,
7149 struct spoolss_EnumPrinters e;
7151 union spoolss_PrinterInfo *info;
7162 e.out.count = &count;
7164 e.out.needed = &needed;
7166 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinters_r(b, tctx, &e),
7167 "failed to enum printers");
7169 if (W_ERROR_EQUAL(e.out.result, WERR_INSUFFICIENT_BUFFER)) {
7170 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
7171 e.in.buffer = &blob;
7172 e.in.offered = needed;
7174 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinters_r(b, tctx, &e),
7175 "failed to enum printers");
7178 torture_assert_werr_ok(tctx, e.out.result,
7179 "failed to enum printers");
7181 for (i=0; i < count; i++) {
7183 const char *current = NULL;
7188 current = info[i].info1.name;
7192 if (strequal(current, name)) {
7197 q = strrchr(current, '\\');
7200 torture_warning(tctx,
7201 "server returns printername %s incl. servername although we did not set servername", current);
7204 if (strequal(q, name)) {
7214 static bool test_AddPrinter_wellknown(struct torture_context *tctx,
7215 struct dcerpc_pipe *p,
7216 const char *printername,
7220 struct spoolss_AddPrinter r;
7221 struct spoolss_AddPrinterEx rex;
7222 struct spoolss_SetPrinterInfoCtr info_ctr;
7223 struct spoolss_SetPrinterInfo1 info1;
7224 struct spoolss_DevmodeContainer devmode_ctr;
7225 struct sec_desc_buf secdesc_ctr;
7226 struct spoolss_UserLevelCtr userlevel_ctr;
7227 struct policy_handle handle;
7229 struct dcerpc_binding_handle *b = p->binding_handle;
7231 ZERO_STRUCT(devmode_ctr);
7232 ZERO_STRUCT(secdesc_ctr);
7233 ZERO_STRUCT(userlevel_ctr);
7236 torture_comment(tctx, "Testing AddPrinter%s(%s) level 1\n",
7237 ex ? "Ex":"", printername);
7239 /* try to add printer to wellknown printer list (level 1) */
7241 userlevel_ctr.level = 1;
7243 info_ctr.info.info1 = &info1;
7246 rex.in.server = NULL;
7247 rex.in.info_ctr = &info_ctr;
7248 rex.in.devmode_ctr = &devmode_ctr;
7249 rex.in.secdesc_ctr = &secdesc_ctr;
7250 rex.in.userlevel_ctr = &userlevel_ctr;
7251 rex.out.handle = &handle;
7254 r.in.info_ctr = &info_ctr;
7255 r.in.devmode_ctr = &devmode_ctr;
7256 r.in.secdesc_ctr = &secdesc_ctr;
7257 r.out.handle = &handle;
7259 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) :
7260 dcerpc_spoolss_AddPrinter_r(b, tctx, &r),
7261 "failed to add printer");
7262 result = ex ? rex.out.result : r.out.result;
7263 torture_assert_werr_equal(tctx, result, WERR_INVALID_PRINTER_NAME,
7264 "unexpected result code");
7266 info1.name = printername;
7267 info1.flags = PRINTER_ATTRIBUTE_SHARED;
7269 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) :
7270 dcerpc_spoolss_AddPrinter_r(b, tctx, &r),
7271 "failed to add printer");
7272 result = ex ? rex.out.result : r.out.result;
7273 torture_assert_werr_equal(tctx, result, WERR_PRINTER_ALREADY_EXISTS,
7274 "unexpected result code");
7276 /* bizarre protocol, WERR_PRINTER_ALREADY_EXISTS means success here,
7277 better do a real check to see the printer is really there */
7279 torture_assert(tctx, test_EnumPrinters_findname(tctx, b,
7280 PRINTER_ENUM_NETWORK, 1,
7283 "failed to enum printers");
7285 torture_assert(tctx, found, "failed to find newly added printer");
7289 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) :
7290 dcerpc_spoolss_AddPrinter_r(b, tctx, &r),
7291 "failed to add printer");
7292 result = ex ? rex.out.result : r.out.result;
7293 torture_assert_werr_equal(tctx, result, WERR_PRINTER_ALREADY_EXISTS,
7294 "unexpected result code");
7296 /* bizarre protocol, WERR_PRINTER_ALREADY_EXISTS means success here,
7297 better do a real check to see the printer has really been removed
7298 from the well known printer list */
7302 torture_assert(tctx, test_EnumPrinters_findname(tctx, b,
7303 PRINTER_ENUM_NETWORK, 1,
7306 "failed to enum printers");
7308 torture_assert(tctx, !found, "printer still in well known printer list");
7313 static bool test_AddPrinter_normal(struct torture_context *tctx,
7314 struct dcerpc_pipe *p,
7315 struct policy_handle *handle_p,
7316 const char *printername,
7317 const char *drivername,
7318 const char *portname,
7319 struct spoolss_DeviceMode *devmode,
7323 struct spoolss_AddPrinter r;
7324 struct spoolss_AddPrinterEx rex;
7325 struct spoolss_SetPrinterInfoCtr info_ctr;
7326 struct spoolss_SetPrinterInfo2 info2;
7327 struct spoolss_DevmodeContainer devmode_ctr;
7328 struct sec_desc_buf secdesc_ctr;
7329 struct spoolss_UserLevelCtr userlevel_ctr;
7330 struct policy_handle handle;
7332 bool existing_printer_deleted = false;
7333 struct dcerpc_binding_handle *b = p->binding_handle;
7335 ZERO_STRUCT(devmode_ctr);
7336 ZERO_STRUCT(secdesc_ctr);
7337 ZERO_STRUCT(userlevel_ctr);
7339 torture_comment(tctx, "Testing AddPrinter%s(%s) level 2\n",
7340 ex ? "Ex":"", printername);
7342 devmode_ctr.devmode = devmode;
7344 userlevel_ctr.level = 1;
7346 rex.in.server = NULL;
7347 rex.in.info_ctr = &info_ctr;
7348 rex.in.devmode_ctr = &devmode_ctr;
7349 rex.in.secdesc_ctr = &secdesc_ctr;
7350 rex.in.userlevel_ctr = &userlevel_ctr;
7351 rex.out.handle = &handle;
7354 r.in.info_ctr = &info_ctr;
7355 r.in.devmode_ctr = &devmode_ctr;
7356 r.in.secdesc_ctr = &secdesc_ctr;
7357 r.out.handle = &handle;
7361 /* try to add printer to printer list (level 2) */
7365 info_ctr.info.info2 = &info2;
7368 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) :
7369 dcerpc_spoolss_AddPrinter_r(b, tctx, &r),
7370 "failed to add printer");
7371 result = ex ? rex.out.result : r.out.result;
7372 torture_assert_werr_equal(tctx, result, WERR_INVALID_PRINTER_NAME,
7373 "unexpected result code");
7375 info2.printername = printername;
7377 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) :
7378 dcerpc_spoolss_AddPrinter_r(b, tctx, &r),
7379 "failed to add printer");
7380 result = ex ? rex.out.result : r.out.result;
7382 if (W_ERROR_EQUAL(result, WERR_PRINTER_ALREADY_EXISTS)) {
7383 struct policy_handle printer_handle;
7385 if (existing_printer_deleted) {
7386 torture_fail(tctx, "already deleted printer still existing?");
7389 torture_assert(tctx, call_OpenPrinterEx(tctx, p, printername, NULL, &printer_handle),
7390 "failed to open printer handle");
7392 torture_assert(tctx, test_DeletePrinter(tctx, b, &printer_handle),
7393 "failed to delete printer");
7395 torture_assert(tctx, test_ClosePrinter(tctx, b, &printer_handle),
7396 "failed to close server handle");
7398 existing_printer_deleted = true;
7403 torture_assert_werr_equal(tctx, result, WERR_UNKNOWN_PORT,
7404 "unexpected result code");
7406 info2.portname = portname;
7408 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) :
7409 dcerpc_spoolss_AddPrinter_r(b, tctx, &r),
7410 "failed to add printer");
7411 result = ex ? rex.out.result : r.out.result;
7412 torture_assert_werr_equal(tctx, result, WERR_UNKNOWN_PRINTER_DRIVER,
7413 "unexpected result code");
7415 info2.drivername = drivername;
7417 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) :
7418 dcerpc_spoolss_AddPrinter_r(b, tctx, &r),
7419 "failed to add printer");
7420 result = ex ? rex.out.result : r.out.result;
7422 /* w2k8r2 allows to add printer w/o defining printprocessor */
7424 if (!W_ERROR_IS_OK(result)) {
7425 torture_assert_werr_equal(tctx, result, WERR_UNKNOWN_PRINTPROCESSOR,
7426 "unexpected result code");
7428 info2.printprocessor = "winprint";
7430 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) :
7431 dcerpc_spoolss_AddPrinter_r(b, tctx, &r),
7432 "failed to add printer");
7433 result = ex ? rex.out.result : r.out.result;
7434 torture_assert_werr_ok(tctx, result,
7435 "failed to add printer");
7440 /* we are paranoid, really check if the printer is there now */
7442 torture_assert(tctx, test_EnumPrinters_findname(tctx, b,
7443 PRINTER_ENUM_LOCAL, 1,
7446 "failed to enum printers");
7447 torture_assert(tctx, found, "failed to find newly added printer");
7449 torture_assert_ntstatus_ok(tctx, ex ? dcerpc_spoolss_AddPrinterEx_r(b, tctx, &rex) :
7450 dcerpc_spoolss_AddPrinter_r(b, tctx, &r),
7451 "failed to add printer");
7452 result = ex ? rex.out.result : r.out.result;
7453 torture_assert_werr_equal(tctx, result, WERR_PRINTER_ALREADY_EXISTS,
7454 "unexpected result code");
7459 static bool test_printer_info(struct torture_context *tctx,
7462 struct torture_printer_context *t =
7463 (struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context);
7464 struct dcerpc_pipe *p = t->spoolss_pipe;
7465 struct dcerpc_binding_handle *b = p->binding_handle;
7469 if (torture_setting_bool(tctx, "samba3", false)) {
7470 torture_skip(tctx, "skipping printer info cross tests against samba 3");
7473 if (!test_PrinterInfo(tctx, b, &t->handle)) {
7477 if (!test_SetPrinter_errors(tctx, b, &t->handle)) {
7484 static bool test_EnumPrinterKey(struct torture_context *tctx,
7485 struct dcerpc_binding_handle *b,
7486 struct policy_handle *handle,
7487 const char *key_name,
7488 const char ***array)
7490 struct spoolss_EnumPrinterKey r;
7491 uint32_t needed = 0;
7492 union spoolss_KeyNames key_buffer;
7493 int32_t offered[] = { 0, 1, 2, 3, 4, 5, -1, -2, -3, -4, -5, 256, 512, 1024, 2048 };
7497 r.in.handle = handle;
7498 r.in.key_name = key_name;
7499 r.out.key_buffer = &key_buffer;
7500 r.out.needed = &needed;
7501 r.out._ndr_size = &_ndr_size;
7503 for (i=0; i < ARRAY_SIZE(offered); i++) {
7505 if (offered[i] < 0 && needed) {
7509 r.in.offered = needed + offered[i];
7511 r.in.offered = offered[i];
7514 ZERO_STRUCT(key_buffer);
7516 torture_comment(tctx, "Testing EnumPrinterKey(%s) with %d offered\n", r.in.key_name, r.in.offered);
7518 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinterKey_r(b, tctx, &r),
7519 "failed to call EnumPrinterKey");
7520 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
7522 torture_assert(tctx, (_ndr_size == r.in.offered/2),
7523 talloc_asprintf(tctx, "EnumPrinterKey size mismatch, _ndr_size %d (expected %d)",
7524 _ndr_size, r.in.offered/2));
7526 r.in.offered = needed;
7527 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinterKey_r(b, tctx, &r),
7528 "failed to call EnumPrinterKey");
7531 if (offered[i] > 0) {
7532 torture_assert_werr_ok(tctx, r.out.result,
7533 "failed to call EnumPrinterKey");
7536 torture_assert(tctx, (_ndr_size == r.in.offered/2),
7537 talloc_asprintf(tctx, "EnumPrinterKey size mismatch, _ndr_size %d (expected %d)",
7538 _ndr_size, r.in.offered/2));
7540 torture_assert(tctx, (*r.out.needed <= r.in.offered),
7541 talloc_asprintf(tctx, "EnumPrinterKey size mismatch: needed %d is not <= offered %d", *r.out.needed, r.in.offered));
7543 torture_assert(tctx, (*r.out.needed <= _ndr_size * 2),
7544 talloc_asprintf(tctx, "EnumPrinterKey size mismatch: needed %d is not <= _ndr_size %d * 2", *r.out.needed, _ndr_size));
7546 if (key_buffer.string_array) {
7547 uint32_t calc_needed = 0;
7549 for (s=0; key_buffer.string_array[s]; s++) {
7550 calc_needed += strlen_m_term(key_buffer.string_array[s])*2;
7552 if (!key_buffer.string_array[0]) {
7557 torture_assert_int_equal(tctx, *r.out.needed, calc_needed,
7558 "EnumPrinterKey unexpected size");
7563 *array = key_buffer.string_array;
7569 bool test_printer_all_keys(struct torture_context *tctx,
7570 struct dcerpc_binding_handle *b,
7571 struct policy_handle *handle)
7573 const char **key_array = NULL;
7576 torture_comment(tctx, "Testing Printer Keys\n");
7578 torture_assert(tctx, test_EnumPrinterKey(tctx, b, handle, "", &key_array),
7579 "failed to call test_EnumPrinterKey");
7581 for (i=0; key_array && key_array[i]; i++) {
7582 torture_assert(tctx, test_EnumPrinterKey(tctx, b, handle, key_array[i], NULL),
7583 "failed to call test_EnumPrinterKey");
7585 for (i=0; key_array && key_array[i]; i++) {
7586 torture_assert(tctx, test_EnumPrinterDataEx(tctx, b, handle, key_array[i], NULL, NULL),
7587 "failed to call test_EnumPrinterDataEx");
7590 torture_comment(tctx, "Printer Keys test succeeded\n\n");
7595 static bool test_openprinter_wrap(struct torture_context *tctx,
7598 struct torture_printer_context *t =
7599 (struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context);
7600 struct dcerpc_pipe *p = t->spoolss_pipe;
7601 struct dcerpc_binding_handle *b = p->binding_handle;
7602 const char *printername = t->info2.printername;
7604 return test_openprinter(tctx, b, printername);
7607 static bool test_csetprinter(struct torture_context *tctx,
7610 struct torture_printer_context *t =
7611 (struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context);
7612 struct dcerpc_pipe *p = t->spoolss_pipe;
7614 const char *printername = talloc_asprintf(tctx, "%s2", t->info2.printername);
7615 const char *drivername = t->added_driver ? t->driver.info8.driver_name : t->info2.drivername;
7616 const char *portname = t->info2.portname;
7618 union spoolss_PrinterInfo info;
7619 struct policy_handle new_handle, new_handle2;
7620 struct dcerpc_binding_handle *b = p->binding_handle;
7622 torture_comment(tctx, "Testing c_setprinter\n");
7624 torture_assert(tctx,
7625 test_GetPrinter_level(tctx, b, &t->handle, 0, &info),
7626 "failed to get level 0 printer info");
7627 torture_comment(tctx, "csetprinter on initial printer handle: %d\n",
7628 info.info0.c_setprinter);
7630 /* check if c_setprinter on 1st handle increases after a printer has
7633 torture_assert(tctx,
7634 test_AddPrinter_normal(tctx, p, &new_handle, printername, drivername, portname, NULL, false),
7635 "failed to add new printer");
7636 torture_assert(tctx,
7637 test_GetPrinter_level(tctx, b, &t->handle, 0, &info),
7638 "failed to get level 0 printer info");
7639 torture_comment(tctx, "csetprinter on initial printer handle (after add): %d\n",
7640 info.info0.c_setprinter);
7642 /* check if c_setprinter on new handle increases after a printer has
7645 torture_assert(tctx,
7646 test_GetPrinter_level(tctx, b, &new_handle, 0, &info),
7647 "failed to get level 0 printer info");
7648 torture_comment(tctx, "csetprinter on created handle: %d\n",
7649 info.info0.c_setprinter);
7651 /* open the new printer and check if c_setprinter increases */
7653 torture_assert(tctx,
7654 call_OpenPrinterEx(tctx, p, printername, NULL, &new_handle2),
7655 "failed to open created printer");
7656 torture_assert(tctx,
7657 test_GetPrinter_level(tctx, b, &new_handle2, 0, &info),
7658 "failed to get level 0 printer info");
7659 torture_comment(tctx, "csetprinter on new handle (after openprinter): %d\n",
7660 info.info0.c_setprinter);
7664 torture_assert(tctx,
7665 test_ClosePrinter(tctx, b, &new_handle2),
7666 "failed to close printer");
7667 torture_assert(tctx,
7668 test_DeletePrinter(tctx, b, &new_handle),
7669 "failed to delete new printer");
7674 static bool compose_local_driver_directory(struct torture_context *tctx,
7675 const char *environment,
7676 const char *local_dir,
7681 p = strrchr(local_dir, '/');
7687 if (strequal(environment, "Windows x64")) {
7688 if (!strequal(p, "x64")) {
7689 *path = talloc_asprintf(tctx, "%s/x64", local_dir);
7691 } else if (strequal(environment, "Windows NT x86")) {
7692 if (!strequal(p, "i386")) {
7693 *path = talloc_asprintf(tctx, "%s/i386", local_dir);
7696 torture_assert(tctx, "unknown environment: '%s'\n", environment);
7703 static struct spoolss_DeviceMode *torture_devicemode(TALLOC_CTX *mem_ctx,
7704 const char *devicename)
7706 struct spoolss_DeviceMode *r;
7708 r = talloc_zero(mem_ctx, struct spoolss_DeviceMode);
7713 r->devicename = talloc_strdup(r, devicename);
7714 r->specversion = DMSPEC_NT4_AND_ABOVE;
7715 r->driverversion = 0x0600;
7717 r->__driverextra_length = 0;
7718 r->fields = DEVMODE_FORMNAME |
7720 DEVMODE_PRINTQUALITY |
7721 DEVMODE_DEFAULTSOURCE |
7725 DEVMODE_ORIENTATION;
7726 r->orientation = DMORIENT_PORTRAIT;
7727 r->papersize = DMPAPER_LETTER;
7732 r->defaultsource = DMBIN_FORMSOURCE;
7733 r->printquality = DMRES_HIGH;
7734 r->color = DMRES_MONOCHROME;
7735 r->duplex = DMDUP_SIMPLEX;
7737 r->ttoption = DMTT_SUBDEV;
7738 r->collate = DMCOLLATE_FALSE;
7739 r->formname = talloc_strdup(r, "Letter");
7745 static bool test_architecture_buffer(struct torture_context *tctx,
7748 struct test_spoolss_context *ctx =
7749 talloc_get_type_abort(private_data, struct test_spoolss_context);
7751 struct spoolss_OpenPrinterEx r;
7752 struct spoolss_UserLevel1 u1;
7753 struct policy_handle handle;
7754 uint32_t architectures[] = {
7755 PROCESSOR_ARCHITECTURE_INTEL,
7756 PROCESSOR_ARCHITECTURE_IA64,
7757 PROCESSOR_ARCHITECTURE_AMD64
7761 struct dcerpc_pipe *p = ctx->spoolss_pipe;
7762 struct dcerpc_binding_handle *b = p->binding_handle;
7764 for (i=0; i < ARRAY_SIZE(architectures); i++) {
7766 torture_comment(tctx, "Testing OpenPrinterEx with architecture %d\n", architectures[i]);
7774 u1.processor = architectures[i];
7776 r.in.printername = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
7777 r.in.datatype = NULL;
7778 r.in.devmode_ctr.devmode= NULL;
7779 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
7780 r.in.userlevel_ctr.level = 1;
7781 r.in.userlevel_ctr.user_info.level1 = &u1;
7782 r.out.handle = &handle;
7784 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_OpenPrinterEx_r(b, tctx, &r), "");
7785 torture_assert_werr_ok(tctx, r.out.result, "");
7788 struct spoolss_EnumPrinters e;
7790 union spoolss_PrinterInfo *info;
7792 e.in.flags = PRINTER_ENUM_LOCAL;
7797 e.out.count = &count;
7799 e.out.needed = &needed[i];
7801 torture_assert_ntstatus_ok(tctx, dcerpc_spoolss_EnumPrinters_r(b, tctx, &e), "");
7803 torture_comment(tctx, "needed was %d\n", needed[i]);
7807 torture_assert(tctx, test_ClosePrinter(tctx, b, &handle), "");
7810 for (i=1; i < ARRAY_SIZE(architectures); i++) {
7811 if (needed[i-1] != needed[i]) {
7813 talloc_asprintf(tctx, "needed size %d for architecture %d != needed size %d for architecture %d\n",
7814 needed[i-1], architectures[i-1], needed[i], architectures[i]));
7821 static bool test_PrintServer_Forms_Winreg(struct torture_context *tctx,
7824 struct test_spoolss_context *ctx =
7825 talloc_get_type_abort(private_data, struct test_spoolss_context);
7826 struct dcerpc_pipe *p = ctx->spoolss_pipe;
7827 struct dcerpc_binding_handle *b = p->binding_handle;
7829 return test_Forms_winreg(tctx, b, &ctx->server_handle, true, NULL);
7832 static bool test_PrintServer_Forms(struct torture_context *tctx,
7835 struct test_spoolss_context *ctx =
7836 talloc_get_type_abort(private_data, struct test_spoolss_context);
7837 struct dcerpc_pipe *p = ctx->spoolss_pipe;
7838 struct dcerpc_binding_handle *b = p->binding_handle;
7840 return test_Forms(tctx, b, &ctx->server_handle, true, NULL, NULL, NULL);
7843 static bool test_PrintServer_EnumForms(struct torture_context *tctx,
7846 struct test_spoolss_context *ctx =
7847 talloc_get_type_abort(private_data, struct test_spoolss_context);
7848 struct dcerpc_pipe *p = ctx->spoolss_pipe;
7849 struct dcerpc_binding_handle *b = p->binding_handle;
7851 return test_EnumForms_all(tctx, b, &ctx->server_handle, true);
7854 static bool torture_rpc_spoolss_setup_common(struct torture_context *tctx, struct test_spoolss_context *t)
7858 status = torture_rpc_connection(tctx, &t->spoolss_pipe, &ndr_table_spoolss);
7860 torture_assert_ntstatus_ok(tctx, status, "Error connecting to server");
7862 torture_assert(tctx,
7863 test_OpenPrinter_server(tctx, t->spoolss_pipe, &t->server_handle),
7864 "failed to open printserver");
7865 torture_assert(tctx,
7866 test_get_environment(tctx, t->spoolss_pipe->binding_handle, &t->server_handle, &t->environment),
7867 "failed to get environment");
7872 static bool torture_rpc_spoolss_setup(struct torture_context *tctx, void **data)
7874 struct test_spoolss_context *t;
7876 *data = t = talloc_zero(tctx, struct test_spoolss_context);
7878 return torture_rpc_spoolss_setup_common(tctx, t);
7881 static bool torture_rpc_spoolss_teardown_common(struct torture_context *tctx, struct test_spoolss_context *t)
7883 test_ClosePrinter(tctx, t->spoolss_pipe->binding_handle, &t->server_handle);
7888 static bool torture_rpc_spoolss_teardown(struct torture_context *tctx, void *data)
7890 struct test_spoolss_context *t = talloc_get_type(data, struct test_spoolss_context);
7893 ret = torture_rpc_spoolss_teardown_common(tctx, t);
7899 static bool torture_rpc_spoolss_printer_setup_common(struct torture_context *tctx, struct torture_printer_context *t)
7901 struct dcerpc_pipe *p;
7902 struct dcerpc_binding_handle *b;
7903 const char *server_name_slash;
7904 const char *driver_name;
7905 const char *printer_name;
7906 const char *port_name;
7908 torture_assert_ntstatus_ok(tctx,
7909 torture_rpc_connection(tctx, &t->spoolss_pipe, &ndr_table_spoolss),
7910 "Error connecting to server");
7912 p = t->spoolss_pipe;
7913 b = p->binding_handle;
7914 server_name_slash = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
7916 t->driver.info8.version = SPOOLSS_DRIVER_VERSION_200X;
7917 t->driver.info8.driver_name = TORTURE_DRIVER;
7918 t->driver.info8.driver_path = "pscript5.dll";
7919 t->driver.info8.data_file = "cups6.ppd";
7920 t->driver.info8.config_file = "ps5ui.dll";
7921 t->driver.info8.help_file = "pscript.hlp";
7922 t->driver.info8.default_datatype = "RAW";
7923 t->driver.info8.dependent_files = talloc_zero(t, struct spoolss_StringArray);
7924 t->driver.info8.dependent_files->string = talloc_zero_array(t, const char *, 8 + 1);
7925 t->driver.info8.dependent_files->string[0] = "pscript5.dll";
7926 t->driver.info8.dependent_files->string[1] = "cups6.ppd";
7927 t->driver.info8.dependent_files->string[2] = "ps5ui.dll";
7928 t->driver.info8.dependent_files->string[3] = "pscript.hlp";
7929 t->driver.info8.dependent_files->string[4] = "pscript.ntf";
7930 t->driver.info8.dependent_files->string[5] = "cups6.ini";
7931 t->driver.info8.dependent_files->string[6] = "cupsps6.dll";
7932 t->driver.info8.dependent_files->string[7] = "cupsui6.dll";
7934 t->driver.local.driver_directory= "/usr/share/cups/drivers";
7936 t->info2.portname = "LPT1:";
7938 printer_name = t->info2.printername;
7939 port_name = t->info2.portname;
7941 torture_assert(tctx,
7942 fillup_printserver_info(tctx, p, &t->driver),
7943 "failed to fillup printserver info");
7945 t->driver.info8.architecture = talloc_strdup(t, t->driver.remote.environment);
7947 torture_assert(tctx,
7948 compose_local_driver_directory(tctx, t->driver.remote.environment,
7949 t->driver.local.driver_directory,
7950 &t->driver.local.driver_directory),
7951 "failed to compose local driver directory");
7953 t->info2.drivername = "Microsoft XPS Document Writer";
7955 if (test_EnumPrinterDrivers_findone(tctx, b, server_name_slash, t->driver.remote.environment, 3, t->info2.drivername, NULL)) {
7956 torture_comment(tctx, "driver '%s' (architecture: %s, version: 3) is present on server\n",
7957 t->info2.drivername, t->driver.remote.environment);
7958 t->have_driver = true;
7962 torture_comment(tctx, "driver '%s' (architecture: %s, version: 3) does not exist on the server\n",
7963 t->info2.drivername, t->driver.remote.environment);
7965 t->info2.drivername = "Microsoft XPS Document Writer v4";
7967 if (test_EnumPrinterDrivers_findone(tctx, b, server_name_slash, t->driver.remote.environment, 3, t->info2.drivername, NULL)) {
7968 torture_comment(tctx, "driver '%s' (architecture: %s, version: 4) is present on server\n",
7969 t->info2.drivername, t->driver.remote.environment);
7970 t->have_driver = true;
7974 torture_comment(tctx, "trying to upload own driver\n");
7976 if (!directory_exist(t->driver.local.driver_directory)) {
7977 torture_warning(tctx, "no local driver is available!");
7978 t->have_driver = false;
7982 torture_assert(tctx,
7983 upload_printer_driver(tctx, dcerpc_server_name(p), &t->driver),
7984 "failed to upload printer driver");
7986 torture_assert(tctx,
7987 test_AddPrinterDriver_args_level_3(tctx, b, server_name_slash, &t->driver.info8, 0, false, NULL),
7988 "failed to add driver");
7990 t->added_driver = true;
7991 t->have_driver = true;
7994 driver_name = t->added_driver ? t->driver.info8.driver_name : t->info2.drivername;
7997 torture_assert(tctx,
7998 test_AddPrinter_wellknown(tctx, p, printer_name, t->ex),
7999 "failed to add wellknown printer");
8001 torture_assert(tctx,
8002 test_AddPrinter_normal(tctx, p, &t->handle, printer_name, driver_name, port_name, t->devmode, t->ex),
8003 "failed to add printer");
8009 static bool torture_rpc_spoolss_printer_setup(struct torture_context *tctx, void **data)
8011 struct torture_printer_context *t;
8013 *data = t = talloc_zero(tctx, struct torture_printer_context);
8016 t->wellknown = false;
8017 t->info2.printername = TORTURE_PRINTER;
8020 return torture_rpc_spoolss_printer_setup_common(tctx, t);
8023 static bool torture_rpc_spoolss_printerex_setup(struct torture_context *tctx, void **data)
8025 struct torture_printer_context *t;
8027 *data = t = talloc_zero(tctx, struct torture_printer_context);
8030 t->wellknown = false;
8031 t->info2.printername = TORTURE_PRINTER_EX;
8034 return torture_rpc_spoolss_printer_setup_common(tctx, t);
8037 static bool torture_rpc_spoolss_printerwkn_setup(struct torture_context *tctx, void **data)
8039 struct torture_printer_context *t;
8041 *data = t = talloc_zero(tctx, struct torture_printer_context);
8044 t->wellknown = true;
8045 t->info2.printername = TORTURE_WELLKNOWN_PRINTER;
8050 torture_skip(tctx, "skipping AddPrinter level 1");
8053 return torture_rpc_spoolss_printer_setup_common(tctx, t);
8056 static bool torture_rpc_spoolss_printerexwkn_setup(struct torture_context *tctx, void **data)
8058 struct torture_printer_context *t;
8060 *data = t = talloc_zero(tctx, struct torture_printer_context);
8063 t->wellknown = true;
8064 t->info2.printername = TORTURE_WELLKNOWN_PRINTER_EX;
8069 torture_skip(tctx, "skipping AddPrinterEx level 1");
8072 return torture_rpc_spoolss_printer_setup_common(tctx, t);
8076 static bool torture_rpc_spoolss_printerdm_setup(struct torture_context *tctx, void **data)
8078 struct torture_printer_context *t;
8080 *data = t = talloc_zero(tctx, struct torture_printer_context);
8083 t->wellknown = false;
8084 t->info2.printername = TORTURE_PRINTER_EX;
8085 t->devmode = torture_devicemode(t, TORTURE_PRINTER_EX);
8087 return torture_rpc_spoolss_printer_setup_common(tctx, t);
8091 static bool torture_rpc_spoolss_printer_teardown_common(struct torture_context *tctx, struct torture_printer_context *t)
8094 struct dcerpc_pipe *p = t->spoolss_pipe;
8095 struct dcerpc_binding_handle *b;
8096 const char *printer_name = t->info2.printername;
8098 if (t->added_driver) {
8099 torture_assert(tctx,
8100 remove_printer_driver(tctx, dcerpc_server_name(t->spoolss_pipe), &t->driver),
8101 "failed to remove printer driver");
8104 if (p && !t->wellknown) {
8105 b = p->binding_handle;
8107 torture_assert(tctx,
8108 test_DeletePrinter(tctx, b, &t->handle),
8109 "failed to delete printer");
8111 torture_assert(tctx,
8112 test_EnumPrinters_findname(tctx, b, PRINTER_ENUM_LOCAL, 1,
8113 printer_name, &found),
8114 "failed to enumerate printers");
8116 torture_assert(tctx, !found, "deleted printer still there");
8122 static bool torture_rpc_spoolss_printer_teardown(struct torture_context *tctx, void *data)
8124 struct torture_printer_context *t = talloc_get_type(data, struct torture_printer_context);
8127 ret = torture_rpc_spoolss_printer_teardown_common(tctx, t);
8133 static bool test_print_test(struct torture_context *tctx,
8136 struct torture_printer_context *t =
8137 (struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context);
8138 struct dcerpc_pipe *p = t->spoolss_pipe;
8139 struct dcerpc_binding_handle *b = p->binding_handle;
8141 torture_assert(tctx,
8142 test_PausePrinter(tctx, b, &t->handle),
8143 "failed to pause printer");
8145 torture_assert(tctx,
8146 test_DoPrintTest(tctx, b, &t->handle),
8147 "failed to do print test");
8149 torture_assert(tctx,
8150 test_ResumePrinter(tctx, b, &t->handle),
8151 "failed to resume printer");
8156 static bool test_print_test_extended(struct torture_context *tctx,
8159 struct torture_printer_context *t =
8160 (struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context);
8161 struct dcerpc_pipe *p = t->spoolss_pipe;
8162 struct dcerpc_binding_handle *b = p->binding_handle;
8165 torture_assert(tctx,
8166 test_PausePrinter(tctx, b, &t->handle),
8167 "failed to pause printer");
8169 ret = test_DoPrintTest_extended(tctx, b, &t->handle);
8171 torture_comment(tctx, "WARNING! failed to do extended print test\n");
8172 if (torture_setting_bool(tctx, "samba3", false)) {
8173 torture_comment(tctx, "non-critical for samba3\n");
8175 tctx->last_result = TORTURE_SKIP;
8179 torture_assert(tctx,
8180 test_ResumePrinter(tctx, b, &t->handle),
8181 "failed to resume printer");
8186 static bool test_print_test_properties(struct torture_context *tctx,
8189 struct torture_printer_context *t =
8190 (struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context);
8191 struct dcerpc_pipe *p = t->spoolss_pipe;
8192 struct dcerpc_binding_handle *b = p->binding_handle;
8194 if (torture_setting_bool(tctx, "samba3", false)) {
8195 torture_skip(tctx, "skip printer job property tests against samba");
8198 torture_assert(tctx,
8199 test_PausePrinter(tctx, b, &t->handle),
8200 "failed to pause printer");
8202 torture_assert(tctx,
8203 test_DoPrintTest_properties(tctx, b, &t->handle),
8204 "failed to test print job properties");
8206 torture_assert(tctx,
8207 test_ResumePrinter(tctx, b, &t->handle),
8208 "failed to resume printer");
8213 /* use smbd file IO to spool a print job */
8214 static bool test_print_test_smbd(struct torture_context *tctx,
8217 struct torture_printer_context *t =
8218 (struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context);
8219 struct dcerpc_pipe *p = t->spoolss_pipe;
8220 struct dcerpc_binding_handle *b = p->binding_handle;
8223 union spoolss_JobInfo *info = NULL;
8226 struct smb2_tree *tree;
8227 struct smb2_handle job_h;
8228 struct cli_credentials *credentials = cmdline_credentials;
8229 struct smbcli_options options;
8230 TALLOC_CTX *mem_ctx = talloc_new(tctx);
8232 * Do not test against the dynamically added printers, printing via
8233 * smbd means that a different spoolss process may handle the
8234 * OpenPrinter request to the one that handled the AddPrinter request.
8235 * This currently leads to an ugly race condition where one process
8236 * sees the new printer and one doesn't.
8238 const char *share = TORTURE_PRINTER_STATIC1;
8240 torture_comment(tctx, "Testing smbd job spooling\n");
8241 lpcfg_smbcli_options(tctx->lp_ctx, &options);
8243 status = smb2_connect(mem_ctx,
8244 torture_setting_string(tctx, "host", NULL),
8245 lpcfg_smb_ports(tctx->lp_ctx),
8247 lpcfg_resolve_context(tctx->lp_ctx),
8252 lpcfg_socket_options(tctx->lp_ctx),
8253 lpcfg_gensec_settings(tctx, tctx->lp_ctx));
8254 if (!NT_STATUS_IS_OK(status)) {
8255 printf("Failed to connect to SMB2 printer %s - %s\n",
8256 share, nt_errstr(status));
8260 status = torture_smb2_testfile(tree, "smbd_spooler_job", &job_h);
8261 torture_assert_ntstatus_ok(tctx, status, "smbd spool job create");
8263 status = smb2_util_write(tree, job_h, "exciting print job data", 0,
8264 sizeof("exciting print job data"));
8265 torture_assert_ntstatus_ok(tctx, status, "smbd spool job write");
8267 /* check back end spoolss job was created */
8268 torture_assert(tctx,
8269 test_EnumJobs_args(tctx, b, &t->handle, 1, &count, &info),
8270 "EnumJobs level 1 failed");
8272 for (i = 0; i < count; i++) {
8273 if (!strcmp(info[i].info1.document_name, "smbd_spooler_job")) {
8277 torture_assert(tctx, (i != count), "smbd_spooler_job not found");
8279 status = smb2_util_close(tree, job_h);
8280 torture_assert_ntstatus_ok(tctx, status, "smbd spool job close");
8282 /* disconnect from printer share */
8283 talloc_free(mem_ctx);
8288 static bool test_printer_sd(struct torture_context *tctx,
8291 struct torture_printer_context *t =
8292 (struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context);
8293 struct dcerpc_pipe *p = t->spoolss_pipe;
8294 struct dcerpc_binding_handle *b = p->binding_handle;
8296 torture_assert(tctx,
8297 test_PrinterInfo_SD(tctx, b, &t->handle),
8298 "failed to test security descriptors");
8303 static bool test_printer_dm(struct torture_context *tctx,
8306 struct torture_printer_context *t =
8307 (struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context);
8308 struct dcerpc_pipe *p = t->spoolss_pipe;
8310 torture_assert(tctx,
8311 test_PrinterInfo_DevMode(tctx, p, &t->handle, t->info2.printername, t->devmode),
8312 "failed to test devicemodes");
8317 static bool test_printer_info_winreg(struct torture_context *tctx,
8320 struct torture_printer_context *t =
8321 (struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context);
8322 struct dcerpc_pipe *p = t->spoolss_pipe;
8324 torture_assert(tctx,
8325 test_PrinterInfo_winreg(tctx, p, &t->handle, t->info2.printername),
8326 "failed to test printer info winreg");
8331 static bool test_printer_change_id(struct torture_context *tctx,
8334 struct torture_printer_context *t =
8335 (struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context);
8336 struct dcerpc_pipe *p = t->spoolss_pipe;
8338 torture_assert(tctx,
8339 test_ChangeID(tctx, p, &t->handle),
8340 "failed to test change id");
8345 static bool test_printer_keys(struct torture_context *tctx,
8348 struct torture_printer_context *t =
8349 (struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context);
8350 struct dcerpc_pipe *p = t->spoolss_pipe;
8351 struct dcerpc_binding_handle *b = p->binding_handle;
8353 torture_assert(tctx,
8354 test_printer_all_keys(tctx, b, &t->handle),
8355 "failed to test printer keys");
8360 static bool test_printer_data_consistency(struct torture_context *tctx,
8363 struct torture_printer_context *t =
8364 (struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context);
8365 struct dcerpc_pipe *p = t->spoolss_pipe;
8367 torture_assert(tctx,
8368 test_EnumPrinterData_consistency(tctx, p, &t->handle),
8369 "failed to test printer data consistency");
8374 static bool test_printer_data_keys(struct torture_context *tctx,
8377 struct torture_printer_context *t =
8378 (struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context);
8379 struct dcerpc_pipe *p = t->spoolss_pipe;
8381 torture_assert(tctx,
8382 test_SetPrinterDataEx_keys(tctx, p, &t->handle),
8383 "failed to test printer data keys");
8388 static bool test_printer_data_values(struct torture_context *tctx,
8391 struct torture_printer_context *t =
8392 (struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context);
8393 struct dcerpc_pipe *p = t->spoolss_pipe;
8395 torture_assert(tctx,
8396 test_SetPrinterDataEx_values(tctx, p, &t->handle),
8397 "failed to test printer data values");
8402 static bool test_printer_data_set(struct torture_context *tctx,
8405 struct torture_printer_context *t =
8406 (struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context);
8407 struct dcerpc_pipe *p = t->spoolss_pipe;
8409 torture_assert(tctx,
8410 test_SetPrinterDataEx_matrix(tctx, p, &t->handle, t->info2.printername, NULL, NULL),
8411 "failed to test printer data set");
8416 static bool test_printer_data_winreg(struct torture_context *tctx,
8419 struct torture_printer_context *t =
8420 (struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context);
8421 struct dcerpc_pipe *p = t->spoolss_pipe;
8423 torture_assert(tctx,
8424 test_PrinterData_winreg(tctx, p, &t->handle, t->info2.printername),
8425 "failed to test printer data winreg");
8430 static bool test_printer_data_dsspooler(struct torture_context *tctx,
8433 struct torture_printer_context *t =
8434 (struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context);
8435 struct dcerpc_pipe *p = t->spoolss_pipe;
8437 torture_assert(tctx,
8438 test_PrinterData_DsSpooler(tctx, p, &t->handle, t->info2.printername),
8439 "failed to test printer data winreg dsspooler");
8444 static bool test_printer_ic(struct torture_context *tctx,
8447 struct torture_printer_context *t =
8448 talloc_get_type_abort(private_data,
8449 struct torture_printer_context);
8450 struct dcerpc_pipe *p = t->spoolss_pipe;
8451 struct dcerpc_binding_handle *b = p->binding_handle;
8452 struct policy_handle gdi_handle;
8454 if (torture_setting_bool(tctx, "samba3", false)) {
8455 torture_skip(tctx, "skip printer information context tests against samba");
8459 struct spoolss_CreatePrinterIC r;
8460 struct spoolss_DevmodeContainer devmode_ctr;
8462 ZERO_STRUCT(devmode_ctr);
8464 r.in.handle = &t->handle;
8465 r.in.devmode_ctr = &devmode_ctr;
8466 r.out.gdi_handle = &gdi_handle;
8468 torture_assert_ntstatus_ok(tctx,
8469 dcerpc_spoolss_CreatePrinterIC_r(b, tctx, &r),
8470 "CreatePrinterIC failed");
8471 torture_assert_werr_ok(tctx, r.out.result,
8472 "CreatePrinterIC failed");
8476 struct spoolss_PlayGDIScriptOnPrinterIC r;
8479 uint32_t num_fonts = 0;
8481 in = data_blob_string_const("");
8483 r.in.gdi_handle = &gdi_handle;
8485 r.in.cIn = in.length;
8488 for (i = 0; i < 4; i++) {
8490 out = data_blob_talloc_zero(tctx, i);
8492 r.in.cOut = out.length;
8493 r.out.pOut = out.data;
8495 torture_assert_ntstatus_ok(tctx,
8496 dcerpc_spoolss_PlayGDIScriptOnPrinterIC_r(b, tctx, &r),
8497 "PlayGDIScriptOnPrinterIC failed");
8498 torture_assert_werr_equal(tctx, r.out.result, WERR_NOMEM,
8499 "PlayGDIScriptOnPrinterIC failed");
8502 out = data_blob_talloc_zero(tctx, 4);
8504 r.in.cOut = out.length;
8505 r.out.pOut = out.data;
8507 torture_assert_ntstatus_ok(tctx,
8508 dcerpc_spoolss_PlayGDIScriptOnPrinterIC_r(b, tctx, &r),
8509 "PlayGDIScriptOnPrinterIC failed");
8510 torture_assert_werr_equal(tctx, r.out.result, WERR_OK,
8511 "PlayGDIScriptOnPrinterIC failed");
8513 /* now we should have the required length, so retry with a
8514 * buffer which is large enough to carry all font ids */
8516 num_fonts = IVAL(r.out.pOut, 0);
8518 torture_comment(tctx, "PlayGDIScriptOnPrinterIC gave font count of %d\n", num_fonts);
8520 out = data_blob_talloc_zero(tctx,
8521 num_fonts * sizeof(struct UNIVERSAL_FONT_ID) + 4);
8523 r.in.cOut = out.length;
8524 r.out.pOut = out.data;
8526 torture_assert_ntstatus_ok(tctx,
8527 dcerpc_spoolss_PlayGDIScriptOnPrinterIC_r(b, tctx, &r),
8528 "PlayGDIScriptOnPrinterIC failed");
8529 torture_assert_werr_equal(tctx, r.out.result, WERR_OK,
8530 "PlayGDIScriptOnPrinterIC failed");
8535 struct spoolss_DeletePrinterIC r;
8537 r.in.gdi_handle = &gdi_handle;
8538 r.out.gdi_handle = &gdi_handle;
8540 torture_assert_ntstatus_ok(tctx,
8541 dcerpc_spoolss_DeletePrinterIC_r(b, tctx, &r),
8542 "DeletePrinterIC failed");
8543 torture_assert_werr_ok(tctx, r.out.result,
8544 "DeletePrinterIC failed");
8551 static bool test_printer_bidi(struct torture_context *tctx,
8554 struct torture_printer_context *t =
8555 talloc_get_type_abort(private_data,
8556 struct torture_printer_context);
8557 struct dcerpc_pipe *p = t->spoolss_pipe;
8558 struct dcerpc_binding_handle *b = p->binding_handle;
8559 struct spoolss_RpcSendRecvBidiData r;
8560 struct RPC_BIDI_REQUEST_CONTAINER bidi_req;
8561 struct RPC_BIDI_RESPONSE_CONTAINER *bidi_rep = NULL;
8563 if (torture_setting_bool(tctx, "samba3", false)) {
8564 torture_skip(tctx, "skip printer bidirectional tests against samba");
8567 ZERO_STRUCT(bidi_req);
8569 r.in.hPrinter = t->handle;
8570 r.in.pAction = "foobar";
8571 r.in.pReqData = &bidi_req;
8572 r.out.ppRespData = &bidi_rep;
8574 torture_assert_ntstatus_ok(tctx,
8575 dcerpc_spoolss_RpcSendRecvBidiData_r(b, tctx, &r),
8576 "RpcSendRecvBidiData failed");
8577 torture_assert_werr_equal(tctx, r.out.result, WERR_NOT_SUPPORTED,
8578 "RpcSendRecvBidiData failed");
8580 if (!(t->info2.attributes & PRINTER_ATTRIBUTE_ENABLE_BIDI)) {
8581 torture_skip(tctx, "skipping further tests as printer is not BIDI enabled");
8584 r.in.pAction = BIDI_ACTION_ENUM_SCHEMA;
8586 torture_assert_ntstatus_ok(tctx,
8587 dcerpc_spoolss_RpcSendRecvBidiData_r(b, tctx, &r),
8588 "RpcSendRecvBidiData failed");
8589 torture_assert_werr_ok(tctx, r.out.result,
8590 "RpcSendRecvBidiData failed");
8595 static bool test_printer_set_publish(struct torture_context *tctx,
8596 struct dcerpc_binding_handle *b,
8597 struct policy_handle *handle)
8599 union spoolss_PrinterInfo info;
8600 struct spoolss_SetPrinterInfo7 info7;
8601 struct spoolss_SetPrinterInfoCtr info_ctr;
8602 struct spoolss_DevmodeContainer devmode_ctr;
8603 struct sec_desc_buf secdesc_ctr;
8606 info7.action = DSPRINT_PUBLISH;
8608 ZERO_STRUCT(info_ctr);
8609 ZERO_STRUCT(devmode_ctr);
8610 ZERO_STRUCT(secdesc_ctr);
8612 info_ctr.info.info7 = &info7;
8614 torture_assert(tctx,
8615 test_SetPrinter(tctx, b, handle, &info_ctr,
8616 &devmode_ctr, &secdesc_ctr, 0), "");
8618 torture_assert(tctx,
8619 test_GetPrinter_level(tctx, b, handle, 2, &info),
8621 torture_assert(tctx,
8622 (info.info2.attributes & PRINTER_ATTRIBUTE_PUBLISHED),
8623 "info2 publish flag not set");
8624 torture_assert(tctx,
8625 test_GetPrinter_level(tctx, b, handle, 7, &info),
8627 if (info.info7.action & DSPRINT_PENDING) {
8628 torture_comment(tctx, "publish is pending\n");
8629 torture_assert_int_equal(tctx,
8631 (DSPRINT_PENDING | DSPRINT_PUBLISH),
8632 "info7 publish flag not set");
8635 torture_assert_int_equal(tctx,
8638 "info7 publish flag not set");
8639 torture_assert_ntstatus_ok(tctx,
8640 GUID_from_string(info.info7.guid,
8642 "invalid published printer GUID");
8648 static bool test_printer_set_unpublish(struct torture_context *tctx,
8649 struct dcerpc_binding_handle *b,
8650 struct policy_handle *handle)
8652 union spoolss_PrinterInfo info;
8653 struct spoolss_SetPrinterInfo7 info7;
8654 struct spoolss_SetPrinterInfoCtr info_ctr;
8655 struct spoolss_DevmodeContainer devmode_ctr;
8656 struct sec_desc_buf secdesc_ctr;
8658 info7.action = DSPRINT_UNPUBLISH;
8661 ZERO_STRUCT(info_ctr);
8662 ZERO_STRUCT(devmode_ctr);
8663 ZERO_STRUCT(secdesc_ctr);
8665 info_ctr.info.info7 = &info7;
8667 torture_assert(tctx,
8668 test_SetPrinter(tctx, b, handle, &info_ctr,
8669 &devmode_ctr, &secdesc_ctr, 0), "");
8671 torture_assert(tctx,
8672 test_GetPrinter_level(tctx, b, handle, 2, &info),
8674 torture_assert(tctx,
8675 !(info.info2.attributes & PRINTER_ATTRIBUTE_PUBLISHED),
8676 "info2 publish flag still set");
8677 torture_assert(tctx,
8678 test_GetPrinter_level(tctx, b, handle, 7, &info),
8681 if (info.info7.action & DSPRINT_PENDING) {
8683 torture_comment(tctx, "unpublish is pending\n");
8684 torture_assert_int_equal(tctx,
8686 (DSPRINT_PENDING | DSPRINT_UNPUBLISH),
8687 "info7 unpublish flag not set");
8688 torture_assert_ntstatus_ok(tctx,
8689 GUID_from_string(info.info7.guid,
8691 "invalid printer GUID");
8693 torture_assert_int_equal(tctx,
8694 info.info7.action, DSPRINT_UNPUBLISH,
8695 "info7 unpublish flag not set");
8701 static bool test_printer_publish_toggle(struct torture_context *tctx,
8704 struct torture_printer_context *t =
8705 talloc_get_type_abort(private_data,
8706 struct torture_printer_context);
8707 struct dcerpc_pipe *p = t->spoolss_pipe;
8708 struct dcerpc_binding_handle *b = p->binding_handle;
8709 struct policy_handle *handle = &t->handle;
8710 union spoolss_PrinterInfo info7;
8711 union spoolss_PrinterInfo info2;
8713 /* check publish status via level 7 and level 2 */
8714 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 7, &info7),
8716 torture_assert(tctx, test_GetPrinter_level(tctx, b, handle, 2, &info2),
8719 if (info2.info2.attributes & PRINTER_ATTRIBUTE_PUBLISHED) {
8720 torture_assert_int_equal(tctx,
8721 info7.info7.action, DSPRINT_PUBLISH,
8722 "info7 publish flag not set");
8723 torture_assert(tctx, test_printer_set_unpublish(tctx, b, handle), "");
8724 torture_assert(tctx, test_printer_set_publish(tctx, b, handle), "");
8726 torture_assert_int_equal(tctx,
8727 info7.info7.action, DSPRINT_UNPUBLISH,
8728 "info7 unpublish flag not set");
8729 torture_assert(tctx, test_printer_set_publish(tctx, b, handle), "");
8730 torture_assert(tctx, test_printer_set_unpublish(tctx, b, handle), "");
8736 static bool test_driver_info_winreg(struct torture_context *tctx,
8739 struct torture_printer_context *t =
8740 (struct torture_printer_context *)talloc_get_type_abort(private_data, struct torture_printer_context);
8741 struct dcerpc_pipe *p = t->spoolss_pipe;
8742 const char *driver_name = t->added_driver ? t->driver.info8.driver_name : t->info2.drivername;
8744 if (!t->have_driver) {
8745 torture_skip(tctx, "skipping driver info winreg test as we don't have a driver");
8748 torture_assert(tctx,
8749 test_DriverInfo_winreg(tctx, p, &t->handle, t->info2.printername, driver_name, t->driver.remote.environment, 3),
8750 "failed to test driver info winreg");
8755 void torture_tcase_printer(struct torture_tcase *tcase)
8757 torture_tcase_add_simple_test(tcase, "openprinter", test_openprinter_wrap);
8758 torture_tcase_add_simple_test(tcase, "csetprinter", test_csetprinter);
8759 torture_tcase_add_simple_test(tcase, "print_test", test_print_test);
8760 torture_tcase_add_simple_test(tcase, "print_test_extended", test_print_test_extended);
8761 torture_tcase_add_simple_test(tcase, "print_test_smbd", test_print_test_smbd);
8762 torture_tcase_add_simple_test(tcase, "print_test_properties", test_print_test_properties);
8763 torture_tcase_add_simple_test(tcase, "printer_info", test_printer_info);
8764 torture_tcase_add_simple_test(tcase, "sd", test_printer_sd);
8765 torture_tcase_add_simple_test(tcase, "dm", test_printer_dm);
8766 torture_tcase_add_simple_test(tcase, "printer_info_winreg", test_printer_info_winreg);
8767 torture_tcase_add_simple_test(tcase, "change_id", test_printer_change_id);
8768 torture_tcase_add_simple_test(tcase, "keys", test_printer_keys);
8769 torture_tcase_add_simple_test(tcase, "printerdata_consistency", test_printer_data_consistency);
8770 torture_tcase_add_simple_test(tcase, "printerdata_keys", test_printer_data_keys);
8771 torture_tcase_add_simple_test(tcase, "printerdata_values", test_printer_data_values);
8772 torture_tcase_add_simple_test(tcase, "printerdata_set", test_printer_data_set);
8773 torture_tcase_add_simple_test(tcase, "printerdata_winreg", test_printer_data_winreg);
8774 torture_tcase_add_simple_test(tcase, "printerdata_dsspooler", test_printer_data_dsspooler);
8775 torture_tcase_add_simple_test(tcase, "driver_info_winreg", test_driver_info_winreg);
8776 torture_tcase_add_simple_test(tcase, "printer_rename", test_printer_rename);
8777 torture_tcase_add_simple_test(tcase, "printer_ic", test_printer_ic);
8778 torture_tcase_add_simple_test(tcase, "bidi", test_printer_bidi);
8779 torture_tcase_add_simple_test(tcase, "publish_toggle",
8780 test_printer_publish_toggle);
8783 struct torture_suite *torture_rpc_spoolss_printer(TALLOC_CTX *mem_ctx)
8785 struct torture_suite *suite = torture_suite_create(mem_ctx, "printer");
8786 struct torture_tcase *tcase;
8788 tcase = torture_suite_add_tcase(suite, "addprinter");
8790 torture_tcase_set_fixture(tcase,
8791 torture_rpc_spoolss_printer_setup,
8792 torture_rpc_spoolss_printer_teardown);
8794 torture_tcase_printer(tcase);
8796 tcase = torture_suite_add_tcase(suite, "addprinterex");
8798 torture_tcase_set_fixture(tcase,
8799 torture_rpc_spoolss_printerex_setup,
8800 torture_rpc_spoolss_printer_teardown);
8802 torture_tcase_printer(tcase);
8804 tcase = torture_suite_add_tcase(suite, "addprinterwkn");
8806 torture_tcase_set_fixture(tcase,
8807 torture_rpc_spoolss_printerwkn_setup,
8808 torture_rpc_spoolss_printer_teardown);
8810 tcase = torture_suite_add_tcase(suite, "addprinterexwkn");
8812 torture_tcase_set_fixture(tcase,
8813 torture_rpc_spoolss_printerexwkn_setup,
8814 torture_rpc_spoolss_printer_teardown);
8817 /* test is not correct */
8818 tcase = torture_suite_add_tcase(suite, "addprinterdm");
8820 torture_tcase_set_fixture(tcase,
8821 torture_rpc_spoolss_printerdm_setup,
8822 torture_rpc_spoolss_printer_teardown);
8824 torture_tcase_printer(tcase);
8829 struct torture_suite *torture_rpc_spoolss(TALLOC_CTX *mem_ctx)
8831 struct torture_suite *suite = torture_suite_create(mem_ctx, "spoolss");
8832 struct torture_tcase *tcase = torture_suite_add_tcase(suite, "printserver");
8834 torture_tcase_set_fixture(tcase,
8835 torture_rpc_spoolss_setup,
8836 torture_rpc_spoolss_teardown);
8838 torture_tcase_add_simple_test(tcase, "openprinter_badnamelist", test_OpenPrinter_badname_list);
8839 torture_tcase_add_simple_test(tcase, "printer_data_list", test_GetPrinterData_list);
8840 torture_tcase_add_simple_test(tcase, "enum_forms", test_PrintServer_EnumForms);
8841 torture_tcase_add_simple_test(tcase, "forms", test_PrintServer_Forms);
8842 torture_tcase_add_simple_test(tcase, "forms_winreg", test_PrintServer_Forms_Winreg);
8843 torture_tcase_add_simple_test(tcase, "enum_ports", test_EnumPorts);
8844 torture_tcase_add_simple_test(tcase, "add_port", test_AddPort);
8845 torture_tcase_add_simple_test(tcase, "get_printer_driver_directory", test_GetPrinterDriverDirectory);
8846 torture_tcase_add_simple_test(tcase, "get_print_processor_directory", test_GetPrintProcessorDirectory);
8847 torture_tcase_add_simple_test(tcase, "enum_printer_drivers", test_EnumPrinterDrivers);
8848 torture_tcase_add_simple_test(tcase, "enum_monitors", test_EnumMonitors);
8849 torture_tcase_add_simple_test(tcase, "enum_print_processors", test_EnumPrintProcessors);
8850 torture_tcase_add_simple_test(tcase, "print_processors_winreg", test_print_processors_winreg);
8851 torture_tcase_add_simple_test(tcase, "add_processor", test_add_print_processor);
8852 torture_tcase_add_simple_test(tcase, "enum_printprocdata", test_EnumPrintProcDataTypes);
8853 torture_tcase_add_simple_test(tcase, "enum_printers", test_EnumPrinters);
8854 torture_tcase_add_simple_test(tcase, "enum_ports_old", test_EnumPorts_old);
8855 torture_tcase_add_simple_test(tcase, "enum_printers_old", test_EnumPrinters_old);
8856 torture_tcase_add_simple_test(tcase, "enum_printers_servername", test_EnumPrinters_servername);
8857 torture_tcase_add_simple_test(tcase, "enum_printer_drivers_old", test_EnumPrinterDrivers_old);
8858 torture_tcase_add_simple_test(tcase, "architecture_buffer", test_architecture_buffer);
8860 torture_suite_add_suite(suite, torture_rpc_spoolss_printer(suite));
8865 static bool test_GetPrinterDriverDirectory_getdir(struct torture_context *tctx,
8866 struct dcerpc_binding_handle *b,
8868 const char *environment,
8871 struct spoolss_GetPrinterDriverDirectory r;
8874 r.in.server = server;
8875 r.in.environment = environment;
8879 r.out.needed = &needed;
8881 torture_assert_ntstatus_ok(tctx,
8882 dcerpc_spoolss_GetPrinterDriverDirectory_r(b, tctx, &r),
8883 "failed to query driver directory");
8885 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
8886 DATA_BLOB blob = data_blob_talloc_zero(tctx, needed);
8887 r.in.buffer = &blob;
8888 r.in.offered = needed;
8890 torture_assert_ntstatus_ok(tctx,
8891 dcerpc_spoolss_GetPrinterDriverDirectory_r(b, tctx, &r),
8892 "failed to query driver directory");
8895 torture_assert_werr_ok(tctx, r.out.result,
8896 "failed to query driver directory");
8899 *dir_p = r.out.info->info1.directory_name;
8905 static const char *get_driver_from_info(struct spoolss_AddDriverInfoCtr *info_ctr)
8907 if (info_ctr == NULL) {
8911 switch (info_ctr->level) {
8913 return info_ctr->info.info1->driver_name;
8915 return info_ctr->info.info2->driver_name;
8917 return info_ctr->info.info3->driver_name;
8919 return info_ctr->info.info4->driver_name;
8921 return info_ctr->info.info6->driver_name;
8923 return info_ctr->info.info8->driver_name;
8929 static const char *get_environment_from_info(struct spoolss_AddDriverInfoCtr *info_ctr)
8931 if (info_ctr == NULL) {
8935 switch (info_ctr->level) {
8937 return info_ctr->info.info2->architecture;
8939 return info_ctr->info.info3->architecture;
8941 return info_ctr->info.info4->architecture;
8943 return info_ctr->info.info6->architecture;
8945 return info_ctr->info.info8->architecture;
8952 static bool test_AddPrinterDriver_exp(struct torture_context *tctx,
8953 struct dcerpc_binding_handle *b,
8954 const char *servername,
8955 struct spoolss_AddDriverInfoCtr *info_ctr,
8956 WERROR expected_result)
8958 struct spoolss_AddPrinterDriver r;
8959 const char *drivername = get_driver_from_info(info_ctr);
8960 const char *environment = get_environment_from_info(info_ctr);
8962 r.in.servername = servername;
8963 r.in.info_ctr = info_ctr;
8965 torture_comment(tctx, "Testing AddPrinterDriver(%s) level: %d, environment: '%s'\n",
8966 drivername, info_ctr->level, environment);
8968 torture_assert_ntstatus_ok(tctx,
8969 dcerpc_spoolss_AddPrinterDriver_r(b, tctx, &r),
8970 "spoolss_AddPrinterDriver failed");
8971 torture_assert_werr_equal(tctx, r.out.result, expected_result,
8972 "spoolss_AddPrinterDriver failed with unexpected result");
8978 static bool test_AddPrinterDriverEx_exp(struct torture_context *tctx,
8979 struct dcerpc_binding_handle *b,
8980 const char *servername,
8981 struct spoolss_AddDriverInfoCtr *info_ctr,
8983 WERROR expected_result)
8985 struct spoolss_AddPrinterDriverEx r;
8986 const char *drivername = get_driver_from_info(info_ctr);
8987 const char *environment = get_environment_from_info(info_ctr);
8989 r.in.servername = servername;
8990 r.in.info_ctr = info_ctr;
8993 torture_comment(tctx, "Testing AddPrinterDriverEx(%s) level: %d, environment: '%s'\n",
8994 drivername, info_ctr->level, environment);
8996 torture_assert_ntstatus_ok(tctx,
8997 dcerpc_spoolss_AddPrinterDriverEx_r(b, tctx, &r),
8998 "AddPrinterDriverEx failed");
8999 torture_assert_werr_equal(tctx, r.out.result, expected_result,
9000 "AddPrinterDriverEx failed with unexpected result");
9005 #define ASSERT_DRIVER_PATH(tctx, path, driver_dir, cmt) \
9006 if (path && strlen(path)) {\
9007 torture_assert_strn_equal(tctx, path, driver_dir, strlen(driver_dir), cmt); \
9010 static bool test_AddPrinterDriver_args_level_1(struct torture_context *tctx,
9011 struct dcerpc_binding_handle *b,
9012 const char *server_name,
9013 struct spoolss_AddDriverInfo8 *r,
9016 const char *remote_driver_dir)
9018 struct spoolss_AddDriverInfoCtr info_ctr;
9019 struct spoolss_AddDriverInfo1 info1;
9024 info_ctr.info.info1 = &info1;
9027 torture_assert(tctx,
9028 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_UNKNOWN_LEVEL),
9029 "failed to test AddPrinterDriverEx level 1");
9031 torture_assert(tctx,
9032 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_UNKNOWN_LEVEL),
9033 "failed to test AddPrinterDriver level 1");
9036 info1.driver_name = r->driver_name;
9039 torture_assert(tctx,
9040 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_UNKNOWN_LEVEL),
9041 "failed to test AddPrinterDriverEx level 1");
9043 torture_assert(tctx,
9044 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_UNKNOWN_LEVEL),
9045 "failed to test AddPrinterDriver level 1");
9051 static bool test_AddPrinterDriver_args_level_2(struct torture_context *tctx,
9052 struct dcerpc_binding_handle *b,
9053 const char *server_name,
9054 struct spoolss_AddDriverInfo8 *r,
9057 const char *remote_driver_dir)
9059 struct spoolss_AddDriverInfoCtr info_ctr;
9060 struct spoolss_AddDriverInfo2 info2;
9061 union spoolss_DriverInfo info;
9066 info_ctr.info.info2 = &info2;
9069 torture_assert(tctx,
9070 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_INVALID_PARAM),
9071 "failed to test AddPrinterDriverEx level 2");
9073 torture_assert(tctx,
9074 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_INVALID_PARAM),
9075 "failed to test AddPrinterDriver level 2");
9078 info2.driver_name = r->driver_name;
9081 torture_assert(tctx,
9082 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_INVALID_PARAM),
9083 "failed to test AddPrinterDriverEx level 2");
9085 torture_assert(tctx,
9086 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_INVALID_PARAM),
9087 "failed to test AddPrinterDriver level 2");
9090 info2.version = r->version;
9093 torture_assert(tctx,
9094 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_INVALID_PARAM),
9095 "failed to test AddPrinterDriverEx level 2");
9097 torture_assert(tctx,
9098 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_INVALID_PARAM),
9099 "failed to test AddPrinterDriver level 2");
9102 info2.architecture = r->architecture;
9105 torture_assert(tctx,
9106 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_INVALID_PARAM),
9107 "failed to test AddPrinterDriverEx level 2");
9109 torture_assert(tctx,
9110 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_INVALID_PARAM),
9111 "failed to test AddPrinterDriver level 2");
9114 info2.driver_path = r->driver_path;
9117 torture_assert(tctx,
9118 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_INVALID_PARAM),
9119 "failed to test AddPrinterDriverEx level 2");
9121 torture_assert(tctx,
9122 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_INVALID_PARAM),
9123 "failed to test AddPrinterDriver level 2");
9126 info2.data_file = r->data_file;
9129 torture_assert(tctx,
9130 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_INVALID_PARAM),
9131 "failed to test AddPrinterDriverEx level 2");
9133 torture_assert(tctx,
9134 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_INVALID_PARAM),
9135 "failed to test AddPrinterDriver level 2");
9138 info2.config_file = r->config_file;
9141 torture_assert(tctx,
9142 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, 0, WERR_INVALID_PARAM),
9143 "failed to test AddPrinterDriverEx");
9147 torture_assert(tctx,
9148 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_OK),
9149 "failed to test AddPrinterDriverEx level 2");
9151 torture_assert(tctx,
9152 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_OK),
9153 "failed to test AddPrinterDriver level 2");
9156 torture_assert(tctx,
9157 test_EnumPrinterDrivers_findone(tctx, b, server_name, r->architecture, 2, r->driver_name, &info),
9158 "failed to find added printer driver");
9160 if (remote_driver_dir) {
9161 ASSERT_DRIVER_PATH(tctx, info.info2.driver_path, remote_driver_dir, "unexpected path");
9162 ASSERT_DRIVER_PATH(tctx, info.info2.data_file, remote_driver_dir, "unexpected path");
9163 ASSERT_DRIVER_PATH(tctx, info.info2.config_file, remote_driver_dir, "unexpected path");
9169 static bool test_AddPrinterDriver_args_level_3(struct torture_context *tctx,
9170 struct dcerpc_binding_handle *b,
9171 const char *server_name,
9172 struct spoolss_AddDriverInfo8 *r,
9175 const char *remote_driver_dir)
9177 struct spoolss_AddDriverInfoCtr info_ctr;
9178 struct spoolss_AddDriverInfo3 info3;
9179 union spoolss_DriverInfo info;
9181 info3.driver_name = r->driver_name;
9182 info3.version = r->version;
9183 info3.architecture = r->architecture;
9184 info3.driver_path = r->driver_path;
9185 info3.data_file = r->data_file;
9186 info3.config_file = r->config_file;
9187 info3.help_file = r->help_file;
9188 info3.monitor_name = r->monitor_name;
9189 info3.default_datatype = r->default_datatype;
9190 info3._ndr_size_dependent_files = r->_ndr_size_dependent_files;
9191 info3.dependent_files = r->dependent_files;
9194 info_ctr.info.info3 = &info3;
9197 torture_assert(tctx,
9198 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_OK),
9199 "failed to test AddPrinterDriverEx level 3");
9201 torture_assert(tctx,
9202 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_OK),
9203 "failed to test AddPrinterDriver level 3");
9206 torture_assert(tctx,
9207 test_EnumPrinterDrivers_findone(tctx, b, server_name, r->architecture, 3, r->driver_name, &info),
9208 "failed to find added printer driver");
9210 if (remote_driver_dir) {
9212 ASSERT_DRIVER_PATH(tctx, info.info3.driver_path, remote_driver_dir, "unexpected path");
9213 ASSERT_DRIVER_PATH(tctx, info.info3.data_file, remote_driver_dir, "unexpected path");
9214 ASSERT_DRIVER_PATH(tctx, info.info3.config_file, remote_driver_dir, "unexpected path");
9215 ASSERT_DRIVER_PATH(tctx, info.info3.help_file, remote_driver_dir, "unexpected path");
9216 for (i=0; info.info3.dependent_files && info.info3.dependent_files[i] != NULL; i++) {
9217 ASSERT_DRIVER_PATH(tctx, info.info3.dependent_files[i], remote_driver_dir, "unexpected path");
9224 static bool test_AddPrinterDriver_args_level_4(struct torture_context *tctx,
9225 struct dcerpc_binding_handle *b,
9226 const char *server_name,
9227 struct spoolss_AddDriverInfo8 *r,
9230 const char *remote_driver_dir)
9232 struct spoolss_AddDriverInfoCtr info_ctr;
9233 struct spoolss_AddDriverInfo4 info4;
9234 union spoolss_DriverInfo info;
9236 info4.version = r->version;
9237 info4.driver_name = r->driver_name;
9238 info4.architecture = r->architecture;
9239 info4.driver_path = r->driver_path;
9240 info4.data_file = r->data_file;
9241 info4.config_file = r->config_file;
9242 info4.help_file = r->help_file;
9243 info4.monitor_name = r->monitor_name;
9244 info4.default_datatype = r->default_datatype;
9245 info4._ndr_size_dependent_files = r->_ndr_size_dependent_files;
9246 info4.dependent_files = r->dependent_files;
9247 info4._ndr_size_previous_names = r->_ndr_size_previous_names;
9248 info4.previous_names = r->previous_names;
9251 info_ctr.info.info4 = &info4;
9254 torture_assert(tctx,
9255 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_OK),
9256 "failed to test AddPrinterDriverEx level 4");
9258 torture_assert(tctx,
9259 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_OK),
9260 "failed to test AddPrinterDriver level 4");
9263 torture_assert(tctx,
9264 test_EnumPrinterDrivers_findone(tctx, b, server_name, r->architecture, 4, r->driver_name, &info),
9265 "failed to find added printer driver");
9267 if (remote_driver_dir) {
9269 ASSERT_DRIVER_PATH(tctx, info.info4.driver_path, remote_driver_dir, "unexpected path");
9270 ASSERT_DRIVER_PATH(tctx, info.info4.data_file, remote_driver_dir, "unexpected path");
9271 ASSERT_DRIVER_PATH(tctx, info.info4.config_file, remote_driver_dir, "unexpected path");
9272 ASSERT_DRIVER_PATH(tctx, info.info4.help_file, remote_driver_dir, "unexpected path");
9273 for (i=0; info.info4.dependent_files && info.info4.dependent_files[i] != NULL; i++) {
9274 ASSERT_DRIVER_PATH(tctx, info.info4.dependent_files[i], remote_driver_dir, "unexpected path");
9281 static bool test_AddPrinterDriver_args_level_6(struct torture_context *tctx,
9282 struct dcerpc_binding_handle *b,
9283 const char *server_name,
9284 struct spoolss_AddDriverInfo8 *r,
9287 const char *remote_driver_dir)
9289 struct spoolss_AddDriverInfoCtr info_ctr;
9290 struct spoolss_AddDriverInfo6 info6;
9291 union spoolss_DriverInfo info;
9293 info6.version = r->version;
9294 info6.driver_name = r->driver_name;
9295 info6.architecture = r->architecture;
9296 info6.driver_path = r->driver_path;
9297 info6.data_file = r->data_file;
9298 info6.config_file = r->config_file;
9299 info6.help_file = r->help_file;
9300 info6.monitor_name = r->monitor_name;
9301 info6.default_datatype = r->default_datatype;
9302 info6._ndr_size_dependent_files = r->_ndr_size_dependent_files;
9303 info6.dependent_files = r->dependent_files;
9304 info6._ndr_size_previous_names = r->_ndr_size_previous_names;
9305 info6.previous_names = r->previous_names;
9306 info6.driver_date = r->driver_date;
9307 info6.driver_version = r->driver_version;
9308 info6.manufacturer_name = r->manufacturer_name;
9309 info6.manufacturer_url = r->manufacturer_url;
9310 info6.hardware_id = r->hardware_id;
9311 info6.provider = r->provider;
9314 info_ctr.info.info6 = &info6;
9317 torture_assert(tctx,
9318 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_OK),
9319 "failed to test AddPrinterDriverEx level 6");
9321 torture_assert(tctx,
9322 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_UNKNOWN_LEVEL),
9323 "failed to test AddPrinterDriver level 6");
9326 /* spoolss_AddPrinterDriver does not deal with level 6 or 8 - gd */
9332 torture_assert(tctx,
9333 test_EnumPrinterDrivers_findone(tctx, b, server_name, r->architecture, 6, r->driver_name, &info),
9334 "failed to find added printer driver");
9336 if (remote_driver_dir) {
9338 ASSERT_DRIVER_PATH(tctx, info.info6.driver_path, remote_driver_dir, "unexpected path");
9339 ASSERT_DRIVER_PATH(tctx, info.info6.data_file, remote_driver_dir, "unexpected path");
9340 ASSERT_DRIVER_PATH(tctx, info.info6.config_file, remote_driver_dir, "unexpected path");
9341 ASSERT_DRIVER_PATH(tctx, info.info6.help_file, remote_driver_dir, "unexpected path");
9342 for (i=0; info.info6.dependent_files && info.info6.dependent_files[i] != NULL; i++) {
9343 ASSERT_DRIVER_PATH(tctx, info.info6.dependent_files[i], remote_driver_dir, "unexpected path");
9347 torture_assert_nttime_equal(tctx, info.info6.driver_date, info6.driver_date, "driverdate mismatch");
9348 torture_assert_u64_equal(tctx, info.info6.driver_version, info6.driver_version, "driverversion mismatch");
9353 static bool test_AddPrinterDriver_args_level_8(struct torture_context *tctx,
9354 struct dcerpc_binding_handle *b,
9355 const char *server_name,
9356 struct spoolss_AddDriverInfo8 *r,
9359 const char *remote_driver_dir)
9361 struct spoolss_AddDriverInfoCtr info_ctr;
9362 union spoolss_DriverInfo info;
9365 info_ctr.info.info8 = r;
9368 torture_assert(tctx,
9369 test_AddPrinterDriverEx_exp(tctx, b, server_name, &info_ctr, flags, WERR_OK),
9370 "failed to test AddPrinterDriverEx level 8");
9372 torture_assert(tctx,
9373 test_AddPrinterDriver_exp(tctx, b, server_name, &info_ctr, WERR_UNKNOWN_LEVEL),
9374 "failed to test AddPrinterDriver level 8");
9377 /* spoolss_AddPrinterDriver does not deal with level 6 or 8 - gd */
9383 torture_assert(tctx,
9384 test_EnumPrinterDrivers_findone(tctx, b, server_name, r->architecture, 8, r->driver_name, &info),
9385 "failed to find added printer driver");
9387 if (remote_driver_dir) {
9389 ASSERT_DRIVER_PATH(tctx, info.info8.driver_path, remote_driver_dir, "unexpected path");
9390 ASSERT_DRIVER_PATH(tctx, info.info8.data_file, remote_driver_dir, "unexpected path");
9391 ASSERT_DRIVER_PATH(tctx, info.info8.config_file, remote_driver_dir, "unexpected path");
9392 ASSERT_DRIVER_PATH(tctx, info.info8.help_file, remote_driver_dir, "unexpected path");
9393 for (i=0; info.info8.dependent_files && info.info8.dependent_files[i] != NULL; i++) {
9394 ASSERT_DRIVER_PATH(tctx, info.info8.dependent_files[i], remote_driver_dir, "unexpected path");
9398 torture_assert_nttime_equal(tctx, info.info8.driver_date, r->driver_date, "driverdate mismatch");
9399 torture_assert_u64_equal(tctx, info.info8.driver_version, r->driver_version, "driverversion mismatch");
9404 #undef ASSERT_DRIVER_PATH
9406 static bool test_DeletePrinterDriver_exp(struct torture_context *tctx,
9407 struct dcerpc_binding_handle *b,
9410 const char *environment,
9411 WERROR expected_result)
9413 struct spoolss_DeletePrinterDriver r;
9415 r.in.server = server;
9416 r.in.architecture = environment;
9417 r.in.driver = driver;
9419 torture_comment(tctx, "Testing DeletePrinterDriver(%s)\n", driver);
9421 torture_assert_ntstatus_ok(tctx,
9422 dcerpc_spoolss_DeletePrinterDriver_r(b, tctx, &r),
9423 "DeletePrinterDriver failed");
9424 torture_assert_werr_equal(tctx, r.out.result, expected_result,
9425 "DeletePrinterDriver failed with unexpected result");
9430 static bool test_DeletePrinterDriverEx_exp(struct torture_context *tctx,
9431 struct dcerpc_binding_handle *b,
9434 const char *environment,
9435 uint32_t delete_flags,
9437 WERROR expected_result)
9439 struct spoolss_DeletePrinterDriverEx r;
9441 r.in.server = server;
9442 r.in.architecture = environment;
9443 r.in.driver = driver;
9444 r.in.delete_flags = delete_flags;
9445 r.in.version = version;
9447 torture_comment(tctx, "Testing DeletePrinterDriverEx(%s)\n", driver);
9449 torture_assert_ntstatus_ok(tctx,
9450 dcerpc_spoolss_DeletePrinterDriverEx_r(b, tctx, &r),
9451 "DeletePrinterDriverEx failed");
9452 torture_assert_werr_equal(tctx, r.out.result, expected_result,
9453 "DeletePrinterDriverEx failed with unexpected result");
9458 static bool test_DeletePrinterDriver(struct torture_context *tctx,
9459 struct dcerpc_binding_handle *b,
9460 const char *server_name,
9462 const char *environment)
9464 torture_assert(tctx,
9465 test_DeletePrinterDriver_exp(tctx, b, server_name, driver, "FOOBAR", WERR_INVALID_ENVIRONMENT),
9466 "failed to delete driver");
9468 torture_assert(tctx,
9469 test_DeletePrinterDriver_exp(tctx, b, server_name, driver, environment, WERR_OK),
9470 "failed to delete driver");
9472 if (test_EnumPrinterDrivers_findone(tctx, b, server_name, environment, 1, driver, NULL)) {
9473 torture_fail(tctx, "deleted driver still enumerated");
9476 torture_assert(tctx,
9477 test_DeletePrinterDriver_exp(tctx, b, server_name, driver, environment, WERR_UNKNOWN_PRINTER_DRIVER),
9478 "2nd delete failed");
9483 static bool test_DeletePrinterDriverEx(struct torture_context *tctx,
9484 struct dcerpc_binding_handle *b,
9485 const char *server_name,
9487 const char *environment,
9488 uint32_t delete_flags,
9491 torture_assert(tctx,
9492 test_DeletePrinterDriverEx_exp(tctx, b, server_name, driver, "FOOBAR", delete_flags, version, WERR_INVALID_ENVIRONMENT),
9493 "failed to delete driver");
9495 torture_assert(tctx,
9496 test_DeletePrinterDriverEx_exp(tctx, b, server_name, driver, environment, delete_flags, version, WERR_OK),
9497 "failed to delete driver");
9499 if (test_EnumPrinterDrivers_findone(tctx, b, server_name, environment, 1, driver, NULL)) {
9500 torture_fail(tctx, "deleted driver still enumerated");
9503 torture_assert(tctx,
9504 test_DeletePrinterDriverEx_exp(tctx, b, server_name, driver, environment, delete_flags, version, WERR_UNKNOWN_PRINTER_DRIVER),
9505 "2nd delete failed");
9510 static bool test_PrinterDriver_args(struct torture_context *tctx,
9511 struct dcerpc_binding_handle *b,
9512 const char *server_name,
9514 struct spoolss_AddDriverInfo8 *r,
9516 uint32_t delete_flags,
9517 uint32_t delete_version,
9519 const char *remote_driver_dir)
9525 ret = test_AddPrinterDriver_args_level_1(tctx, b, server_name, r, add_flags, ex, remote_driver_dir);
9528 ret = test_AddPrinterDriver_args_level_2(tctx, b, server_name, r, add_flags, ex, remote_driver_dir);
9531 ret = test_AddPrinterDriver_args_level_3(tctx, b, server_name, r, add_flags, ex, remote_driver_dir);
9534 ret = test_AddPrinterDriver_args_level_4(tctx, b, server_name, r, add_flags, ex, remote_driver_dir);
9537 ret = test_AddPrinterDriver_args_level_6(tctx, b, server_name, r, add_flags, ex, remote_driver_dir);
9540 ret = test_AddPrinterDriver_args_level_8(tctx, b, server_name, r, add_flags, ex, remote_driver_dir);
9554 /* spoolss_AddPrinterDriver does not deal with level 6 or 8 - gd */
9556 if (!ex && (level == 6 || level == 8)) {
9561 struct dcerpc_pipe *p2;
9562 struct policy_handle hive_handle;
9563 struct dcerpc_binding_handle *b2;
9565 torture_assert_ntstatus_ok(tctx,
9566 torture_rpc_connection(tctx, &p2, &ndr_table_winreg),
9567 "could not open winreg pipe");
9568 b2 = p2->binding_handle;
9570 torture_assert(tctx, test_winreg_OpenHKLM(tctx, b2, &hive_handle), "");
9572 ret = test_GetDriverInfo_winreg(tctx, b, NULL, NULL, r->driver_name, r->architecture, r->version, b2, &hive_handle, server_name);
9574 test_winreg_CloseKey(tctx, b2, &hive_handle);
9580 return test_DeletePrinterDriverEx(tctx, b, server_name, r->driver_name, r->architecture, delete_flags, r->version);
9582 return test_DeletePrinterDriver(tctx, b, server_name, r->driver_name, r->architecture);
9586 static bool fillup_printserver_info(struct torture_context *tctx,
9587 struct dcerpc_pipe *p,
9588 struct torture_driver_context *d)
9590 struct policy_handle server_handle;
9591 struct dcerpc_binding_handle *b = p->binding_handle;
9592 const char *server_name_slash = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
9594 torture_assert(tctx,
9595 test_OpenPrinter_server(tctx, p, &server_handle),
9596 "failed to open printserver");
9597 torture_assert(tctx,
9598 test_get_environment(tctx, b, &server_handle, &d->remote.environment),
9599 "failed to get environment");
9600 torture_assert(tctx,
9601 test_ClosePrinter(tctx, b, &server_handle),
9602 "failed to close printserver");
9604 torture_assert(tctx,
9605 test_GetPrinterDriverDirectory_getdir(tctx, b, server_name_slash,
9606 d->local.environment ? d->local.environment : d->remote.environment,
9607 &d->remote.driver_directory),
9608 "failed to get driver directory");
9613 static const char *driver_directory_dir(const char *driver_directory)
9617 p = strrchr(driver_directory, '\\');
9625 static const char *driver_directory_share(struct torture_context *tctx,
9626 const char *driver_directory)
9631 if (driver_directory[0] == '\\' && driver_directory[1] == '\\') {
9632 driver_directory += 2;
9635 p = talloc_strdup(tctx, driver_directory);
9637 torture_assert(tctx,
9638 next_token_talloc(tctx, &p, &tok, "\\"),
9639 "cannot explode uri");
9640 torture_assert(tctx,
9641 next_token_talloc(tctx, &p, &tok, "\\"),
9642 "cannot explode uri");
9647 static bool upload_printer_driver_file(struct torture_context *tctx,
9648 struct smbcli_state *cli,
9649 struct torture_driver_context *d,
9650 const char *file_name)
9655 int maxwrite = 64512;
9658 const char *remote_dir = driver_directory_dir(d->remote.driver_directory);
9659 const char *local_name = talloc_asprintf(tctx, "%s/%s", d->local.driver_directory, file_name);
9660 const char *remote_name = talloc_asprintf(tctx, "%s\\%s", remote_dir, file_name);
9662 if (!file_name || strlen(file_name) == 0) {
9666 torture_comment(tctx, "Uploading %s to %s\n", local_name, remote_name);
9668 fnum = smbcli_open(cli->tree, remote_name, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE);
9670 torture_fail(tctx, talloc_asprintf(tctx, "failed to open remote file: %s\n", remote_name));
9673 f = x_fopen(local_name, O_RDONLY, 0);
9675 torture_fail(tctx, talloc_asprintf(tctx, "failed to open local file: %s\n", local_name));
9678 buf = talloc_array(tctx, uint8_t, maxwrite);
9684 while (!x_feof(f)) {
9688 if ((n = x_fread(buf, 1, n, f)) < 1) {
9689 if((n == 0) && x_feof(f))
9690 break; /* Empty local file. */
9692 torture_warning(tctx,
9693 "failed to read file: %s\n", strerror(errno));
9697 ret = smbcli_write(cli->tree, fnum, 0, buf, nread + start, n);
9700 torture_warning(tctx,
9701 "failed to write file: %s\n", smbcli_errstr(cli->tree));
9710 torture_assert_ntstatus_ok(tctx,
9711 smbcli_close(cli->tree, fnum),
9712 "failed to close file");
9717 static bool connect_printer_driver_share(struct torture_context *tctx,
9718 const char *server_name,
9719 const char *share_name,
9720 struct smbcli_state **cli)
9722 struct smbcli_options smb_options;
9723 struct smbcli_session_options smb_session_options;
9725 torture_comment(tctx, "Connecting printer driver share '%s' on '%s'\n",
9726 share_name, server_name);
9728 lpcfg_smbcli_options(tctx->lp_ctx, &smb_options);
9729 lpcfg_smbcli_session_options(tctx->lp_ctx, &smb_session_options);
9731 torture_assert_ntstatus_ok(tctx,
9732 smbcli_full_connection(tctx, cli, server_name,
9733 lpcfg_smb_ports(tctx->lp_ctx),
9735 lpcfg_socket_options(tctx->lp_ctx),
9736 cmdline_credentials,
9737 lpcfg_resolve_context(tctx->lp_ctx),
9740 &smb_session_options,
9741 lpcfg_gensec_settings(tctx, tctx->lp_ctx)),
9742 "failed to open driver share");
9747 static bool upload_printer_driver(struct torture_context *tctx,
9748 const char *server_name,
9749 struct torture_driver_context *d)
9751 struct smbcli_state *cli;
9752 const char *share_name = driver_directory_share(tctx, d->remote.driver_directory);
9755 torture_assert(tctx,
9756 connect_printer_driver_share(tctx, server_name, share_name, &cli),
9757 "failed to connect to driver share");
9759 torture_comment(tctx, "Uploading printer driver files to \\\\%s\\%s\n",
9760 server_name, share_name);
9762 torture_assert(tctx,
9763 upload_printer_driver_file(tctx, cli, d, d->info8.driver_path),
9764 "failed to upload driver_path");
9765 torture_assert(tctx,
9766 upload_printer_driver_file(tctx, cli, d, d->info8.data_file),
9767 "failed to upload data_file");
9768 torture_assert(tctx,
9769 upload_printer_driver_file(tctx, cli, d, d->info8.config_file),
9770 "failed to upload config_file");
9771 torture_assert(tctx,
9772 upload_printer_driver_file(tctx, cli, d, d->info8.help_file),
9773 "failed to upload help_file");
9774 if (d->info8.dependent_files) {
9775 for (i=0; d->info8.dependent_files->string && d->info8.dependent_files->string[i] != NULL; i++) {
9776 torture_assert(tctx,
9777 upload_printer_driver_file(tctx, cli, d, d->info8.dependent_files->string[i]),
9778 "failed to upload dependent_files");
9787 static bool check_printer_driver_file(struct torture_context *tctx,
9788 struct smbcli_state *cli,
9789 struct torture_driver_context *d,
9790 const char *file_name)
9792 const char *remote_arch_dir = driver_directory_dir(d->remote.driver_directory);
9793 const char *remote_name = talloc_asprintf(tctx, "%s\\%d\\%s",
9799 torture_assert(tctx, (file_name && strlen(file_name) != 0), "invalid filename");
9801 torture_comment(tctx, "checking for driver file at %s\n", remote_name);
9803 fnum = smbcli_open(cli->tree, remote_name, O_RDONLY, DENY_NONE);
9808 torture_assert_ntstatus_ok(tctx,
9809 smbcli_close(cli->tree, fnum),
9810 "failed to close driver file");
9815 static bool check_printer_driver_files(struct torture_context *tctx,
9816 const char *server_name,
9817 struct torture_driver_context *d,
9820 struct smbcli_state *cli;
9821 const char *share_name = driver_directory_share(tctx, d->remote.driver_directory);
9824 torture_assert(tctx,
9825 connect_printer_driver_share(tctx, server_name, share_name, &cli),
9826 "failed to connect to driver share");
9828 torture_comment(tctx, "checking %sexistent driver files at \\\\%s\\%s\n",
9829 (expect_exist ? "": "non-"),
9830 server_name, share_name);
9832 if (d->info8.driver_path && d->info8.driver_path[0]) {
9833 torture_assert(tctx,
9834 check_printer_driver_file(tctx, cli, d, d->info8.driver_path) == expect_exist,
9835 "failed driver_path check");
9837 if (d->info8.data_file && d->info8.data_file[0]) {
9838 torture_assert(tctx,
9839 check_printer_driver_file(tctx, cli, d, d->info8.data_file) == expect_exist,
9840 "failed data_file check");
9842 if (d->info8.config_file && d->info8.config_file[0]) {
9843 torture_assert(tctx,
9844 check_printer_driver_file(tctx, cli, d, d->info8.config_file) == expect_exist,
9845 "failed config_file check");
9847 if (d->info8.help_file && d->info8.help_file[0]) {
9848 torture_assert(tctx,
9849 check_printer_driver_file(tctx, cli, d, d->info8.help_file) == expect_exist,
9850 "failed help_file check");
9852 if (d->info8.dependent_files) {
9853 for (i=0; d->info8.dependent_files->string && d->info8.dependent_files->string[i] != NULL; i++) {
9854 torture_assert(tctx,
9855 check_printer_driver_file(tctx, cli, d, d->info8.dependent_files->string[i]) == expect_exist,
9856 "failed dependent_files check");
9865 static bool remove_printer_driver_file(struct torture_context *tctx,
9866 struct smbcli_state *cli,
9867 struct torture_driver_context *d,
9868 const char *file_name)
9870 const char *remote_name;
9871 const char *remote_dir = driver_directory_dir(d->remote.driver_directory);
9873 if (!file_name || strlen(file_name) == 0) {
9877 remote_name = talloc_asprintf(tctx, "%s\\%s", remote_dir, file_name);
9879 torture_comment(tctx, "Removing %s\n", remote_name);
9881 torture_assert_ntstatus_ok(tctx,
9882 smbcli_unlink(cli->tree, remote_name),
9883 "failed to unlink");
9888 static bool remove_printer_driver(struct torture_context *tctx,
9889 const char *server_name,
9890 struct torture_driver_context *d)
9892 struct smbcli_state *cli;
9893 const char *share_name = driver_directory_share(tctx, d->remote.driver_directory);
9896 torture_assert(tctx,
9897 connect_printer_driver_share(tctx, server_name, share_name, &cli),
9898 "failed to connect to driver share");
9900 torture_comment(tctx, "Removing printer driver files from \\\\%s\\%s\n",
9901 server_name, share_name);
9903 torture_assert(tctx,
9904 remove_printer_driver_file(tctx, cli, d, d->info8.driver_path),
9905 "failed to remove driver_path");
9906 torture_assert(tctx,
9907 remove_printer_driver_file(tctx, cli, d, d->info8.data_file),
9908 "failed to remove data_file");
9909 if (!strequal(d->info8.config_file, d->info8.driver_path)) {
9910 torture_assert(tctx,
9911 remove_printer_driver_file(tctx, cli, d, d->info8.config_file),
9912 "failed to remove config_file");
9914 torture_assert(tctx,
9915 remove_printer_driver_file(tctx, cli, d, d->info8.help_file),
9916 "failed to remove help_file");
9917 if (d->info8.dependent_files) {
9918 for (i=0; d->info8.dependent_files->string && d->info8.dependent_files->string[i] != NULL; i++) {
9919 if (strequal(d->info8.dependent_files->string[i], d->info8.driver_path) ||
9920 strequal(d->info8.dependent_files->string[i], d->info8.data_file) ||
9921 strequal(d->info8.dependent_files->string[i], d->info8.config_file) ||
9922 strequal(d->info8.dependent_files->string[i], d->info8.help_file)) {
9925 torture_assert(tctx,
9926 remove_printer_driver_file(tctx, cli, d, d->info8.dependent_files->string[i]),
9927 "failed to remove dependent_files");
9937 static bool test_add_driver_arg(struct torture_context *tctx,
9938 struct dcerpc_pipe *p,
9939 struct torture_driver_context *d)
9942 struct dcerpc_binding_handle *b = p->binding_handle;
9943 const char *server_name_slash = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
9944 uint32_t levels[] = { 1, 2, 3, 4, 6, 8 };
9946 struct spoolss_AddDriverInfo8 info8;
9947 uint32_t add_flags = APD_COPY_NEW_FILES;
9948 uint32_t delete_flags = 0;
9952 torture_comment(tctx, "Testing PrinterDriver%s '%s' for environment '%s'\n",
9953 d->ex ? "Ex" : "", d->info8.driver_name, d->local.environment);
9955 torture_assert(tctx,
9956 fillup_printserver_info(tctx, p, d),
9957 "failed to fillup printserver info");
9959 if (!directory_exist(d->local.driver_directory)) {
9960 torture_skip(tctx, "Skipping Printer Driver test as no local driver is available");
9963 torture_assert(tctx,
9964 upload_printer_driver(tctx, dcerpc_server_name(p), d),
9965 "failed to upload printer driver");
9968 if (d->info8.dependent_files) {
9969 info8.dependent_files = talloc_zero(tctx, struct spoolss_StringArray);
9970 if (d->info8.dependent_files->string) {
9971 for (i=0; d->info8.dependent_files->string[i] != NULL; i++) {
9973 info8.dependent_files->string = talloc_zero_array(info8.dependent_files, const char *, i+1);
9974 for (i=0; d->info8.dependent_files->string[i] != NULL; i++) {
9975 info8.dependent_files->string[i] = talloc_strdup(info8.dependent_files->string, d->info8.dependent_files->string[i]);
9979 info8.architecture = d->local.environment;
9981 for (i=0; i < ARRAY_SIZE(levels); i++) {
9983 if (torture_setting_bool(tctx, "samba3", false)) {
9984 switch (levels[i]) {
9988 torture_comment(tctx, "skipping level %d against samba\n", levels[i]);
9994 if (torture_setting_bool(tctx, "w2k3", false)) {
9995 switch (levels[i]) {
9997 torture_comment(tctx, "skipping level %d against w2k3\n", levels[i]);
10004 torture_comment(tctx,
10005 "Testing PrinterDriver%s '%s' add & delete level %d\n",
10006 d->ex ? "Ex" : "", info8.driver_name, levels[i]);
10008 ret &= test_PrinterDriver_args(tctx, b, server_name_slash, levels[i], &info8, add_flags, delete_flags, d->info8.version, d->ex, d->remote.driver_directory);
10011 info8.driver_path = talloc_asprintf(tctx, "%s\\%s", d->remote.driver_directory, d->info8.driver_path);
10012 info8.data_file = talloc_asprintf(tctx, "%s\\%s", d->remote.driver_directory, d->info8.data_file);
10013 if (d->info8.config_file) {
10014 info8.config_file = talloc_asprintf(tctx, "%s\\%s", d->remote.driver_directory, d->info8.config_file);
10016 if (d->info8.help_file) {
10017 info8.help_file = talloc_asprintf(tctx, "%s\\%s", d->remote.driver_directory, d->info8.help_file);
10019 if (d->info8.dependent_files && d->info8.dependent_files->string) {
10020 for (i=0; d->info8.dependent_files->string[i] != NULL; i++) {
10021 info8.dependent_files->string[i] = talloc_asprintf(tctx, "%s\\%s", d->remote.driver_directory, d->info8.dependent_files->string[i]);
10025 for (i=0; i < ARRAY_SIZE(levels); i++) {
10027 if (torture_setting_bool(tctx, "samba3", false)) {
10028 switch (levels[i]) {
10032 torture_comment(tctx, "skipping level %d against samba\n", levels[i]);
10038 if (torture_setting_bool(tctx, "w2k3", false)) {
10039 switch (levels[i]) {
10041 torture_comment(tctx, "skipping level %d against w2k3\n", levels[i]);
10048 torture_comment(tctx,
10049 "Testing PrinterDriver%s '%s' add & delete level %d (full unc paths)\n",
10050 d->ex ? "Ex" : "", info8.driver_name, levels[i]);
10052 ret &= test_PrinterDriver_args(tctx, b, server_name_slash, levels[i], &info8, add_flags, delete_flags, d->info8.version, d->ex, d->remote.driver_directory);
10055 torture_assert(tctx,
10056 remove_printer_driver(tctx, dcerpc_server_name(p), d),
10057 "failed to remove printer driver");
10059 torture_comment(tctx, "\n");
10064 static bool test_add_driver_ex_64(struct torture_context *tctx,
10065 struct dcerpc_pipe *p)
10067 struct torture_driver_context *d;
10069 d = talloc_zero(tctx, struct torture_driver_context);
10071 d->info8.version = SPOOLSS_DRIVER_VERSION_200X;
10072 d->info8.driver_name = TORTURE_DRIVER_EX;
10073 d->info8.architecture = NULL;
10074 d->info8.driver_path = talloc_strdup(d, "pscript5.dll");
10075 d->info8.data_file = talloc_strdup(d, "cups6.ppd");
10076 d->info8.config_file = talloc_strdup(d, "cupsui6.dll");
10077 d->local.environment = talloc_strdup(d, "Windows x64");
10078 d->local.driver_directory = talloc_strdup(d, "/usr/share/cups/drivers/x64");
10081 return test_add_driver_arg(tctx, p, d);
10084 static bool test_add_driver_ex_32(struct torture_context *tctx,
10085 struct dcerpc_pipe *p)
10087 struct torture_driver_context *d;
10089 d = talloc_zero(tctx, struct torture_driver_context);
10091 d->info8.version = SPOOLSS_DRIVER_VERSION_200X;
10092 d->info8.driver_name = TORTURE_DRIVER_EX;
10093 d->info8.architecture = NULL;
10094 d->info8.driver_path = talloc_strdup(d, "pscript5.dll");
10095 d->info8.data_file = talloc_strdup(d, "cups6.ppd");
10096 d->info8.config_file = talloc_strdup(d, "cupsui6.dll");
10097 d->local.environment = talloc_strdup(d, "Windows NT x86");
10098 d->local.driver_directory = talloc_strdup(d, "/usr/share/cups/drivers/i386");
10101 return test_add_driver_arg(tctx, p, d);
10104 static bool test_add_driver_64(struct torture_context *tctx,
10105 struct dcerpc_pipe *p)
10107 struct torture_driver_context *d;
10109 d = talloc_zero(tctx, struct torture_driver_context);
10111 d->info8.version = SPOOLSS_DRIVER_VERSION_200X;
10112 d->info8.driver_name = TORTURE_DRIVER;
10113 d->info8.architecture = NULL;
10114 d->info8.driver_path = talloc_strdup(d, "pscript5.dll");
10115 d->info8.data_file = talloc_strdup(d, "cups6.ppd");
10116 d->info8.config_file = talloc_strdup(d, "cupsui6.dll");
10117 d->local.environment = talloc_strdup(d, "Windows x64");
10118 d->local.driver_directory = talloc_strdup(d, "/usr/share/cups/drivers/x64");
10121 return test_add_driver_arg(tctx, p, d);
10124 static bool test_add_driver_32(struct torture_context *tctx,
10125 struct dcerpc_pipe *p)
10127 struct torture_driver_context *d;
10129 d = talloc_zero(tctx, struct torture_driver_context);
10131 d->info8.version = SPOOLSS_DRIVER_VERSION_200X;
10132 d->info8.driver_name = TORTURE_DRIVER;
10133 d->info8.architecture = NULL;
10134 d->info8.driver_path = talloc_strdup(d, "pscript5.dll");
10135 d->info8.data_file = talloc_strdup(d, "cups6.ppd");
10136 d->info8.config_file = talloc_strdup(d, "cupsui6.dll");
10137 d->local.environment = talloc_strdup(d, "Windows NT x86");
10138 d->local.driver_directory = talloc_strdup(d, "/usr/share/cups/drivers/i386");
10141 return test_add_driver_arg(tctx, p, d);
10144 static bool test_add_driver_adobe(struct torture_context *tctx,
10145 struct dcerpc_pipe *p)
10147 struct torture_driver_context *d;
10149 if (!torture_setting_bool(tctx, "samba3", false)) {
10150 torture_skip(tctx, "skipping adobe test which only works against samba3");
10153 d = talloc_zero(tctx, struct torture_driver_context);
10155 d->info8.version = SPOOLSS_DRIVER_VERSION_9X;
10156 d->info8.driver_name = TORTURE_DRIVER_ADOBE;
10157 d->info8.architecture = NULL;
10158 d->info8.driver_path = talloc_strdup(d, "ADOBEPS4.DRV");
10159 d->info8.data_file = talloc_strdup(d, "DEFPRTR2.PPD");
10160 d->info8.config_file = talloc_strdup(d, "ADOBEPS4.DRV");
10162 d->info8.help_file = talloc_strdup(d, "ADOBEPS4.HLP");
10163 d->info8.monitor_name = talloc_strdup(d, "PSMON.DLL");
10165 d->local.environment = talloc_strdup(d, "Windows 4.0");
10166 d->local.driver_directory = talloc_strdup(d, "/usr/share/cups/drivers/adobe/");
10169 return test_add_driver_arg(tctx, p, d);
10172 static bool test_add_driver_adobe_cupsaddsmb(struct torture_context *tctx,
10173 struct dcerpc_pipe *p)
10175 struct torture_driver_context *d;
10176 struct spoolss_StringArray *a;
10178 if (!torture_setting_bool(tctx, "samba3", false)) {
10179 torture_skip(tctx, "skipping cupsaddsmb test which only works against samba3");
10182 d = talloc_zero(tctx, struct torture_driver_context);
10184 d->info8.version = SPOOLSS_DRIVER_VERSION_9X;
10185 d->info8.driver_name = TORTURE_DRIVER_ADOBE_CUPSADDSMB;
10186 d->info8.architecture = NULL;
10187 d->info8.driver_path = talloc_strdup(d, "ADOBEPS4.DRV");
10188 d->info8.data_file = talloc_strdup(d, "DEFPRTR2.PPD");
10189 d->info8.config_file = NULL;
10190 d->info8.help_file = talloc_strdup(d, "ADOBEPS4.HLP");
10191 d->info8.monitor_name = talloc_strdup(d, "PSMON.DLL");
10192 d->info8.default_datatype = talloc_strdup(d, "RAW");
10194 a = talloc_zero(d, struct spoolss_StringArray);
10195 a->string = talloc_zero_array(a, const char *, 7);
10196 a->string[0] = talloc_strdup(a->string, "ADOBEPS4.DRV");
10197 a->string[1] = talloc_strdup(a->string, "DEFPRTR2.PPD");
10198 a->string[2] = talloc_strdup(a->string, "ADOBEPS4.HLP");
10199 a->string[3] = talloc_strdup(a->string, "PSMON.DLL");
10200 a->string[4] = talloc_strdup(a->string, "ADFONTS.MFM");
10201 a->string[5] = talloc_strdup(a->string, "ICONLIB.DLL");
10203 d->info8.dependent_files = a;
10204 d->local.environment = talloc_strdup(d, "Windows 4.0");
10205 d->local.driver_directory = talloc_strdup(d, "/usr/share/cups/drivers/adobe/");
10208 return test_add_driver_arg(tctx, p, d);
10211 static bool test_add_driver_timestamps(struct torture_context *tctx,
10212 struct dcerpc_pipe *p)
10214 struct torture_driver_context *d;
10215 struct timeval t = timeval_current();
10217 d = talloc_zero(tctx, struct torture_driver_context);
10219 d->info8.version = SPOOLSS_DRIVER_VERSION_200X;
10220 d->info8.driver_name = TORTURE_DRIVER_TIMESTAMPS;
10221 d->info8.architecture = NULL;
10222 d->info8.driver_path = talloc_strdup(d, "pscript5.dll");
10223 d->info8.data_file = talloc_strdup(d, "cups6.ppd");
10224 d->info8.config_file = talloc_strdup(d, "cupsui6.dll");
10225 d->info8.driver_date = timeval_to_nttime(&t);
10226 d->local.environment = talloc_strdup(d, "Windows NT x86");
10227 d->local.driver_directory = talloc_strdup(d, "/usr/share/cups/drivers/i386");
10230 torture_assert(tctx,
10231 test_add_driver_arg(tctx, p, d),
10234 unix_to_nt_time(&d->info8.driver_date, 1);
10236 torture_assert(tctx,
10237 test_add_driver_arg(tctx, p, d),
10243 static bool test_multiple_drivers(struct torture_context *tctx,
10244 struct dcerpc_pipe *p)
10246 struct torture_driver_context *d;
10247 struct dcerpc_binding_handle *b = p->binding_handle;
10248 const char *server_name_slash = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
10250 struct spoolss_AddDriverInfo8 info8;
10251 uint32_t add_flags = APD_COPY_NEW_FILES;
10252 uint32_t delete_flags = 0;
10254 d = talloc_zero(tctx, struct torture_driver_context);
10256 d->info8.version = SPOOLSS_DRIVER_VERSION_200X;
10257 d->info8.driver_path = talloc_strdup(d, "pscript5.dll");
10258 d->info8.data_file = talloc_strdup(d, "cups6.ppd");
10259 d->info8.config_file = talloc_strdup(d, "cupsui6.dll");
10260 d->local.environment = talloc_strdup(d, "Windows NT x86");
10261 d->local.driver_directory = talloc_strdup(d, "/usr/share/cups/drivers/i386");
10264 torture_assert(tctx,
10265 fillup_printserver_info(tctx, p, d),
10266 "failed to fillup printserver info");
10268 if (!directory_exist(d->local.driver_directory)) {
10269 torture_skip(tctx, "Skipping Printer Driver test as no local driver is available");
10272 torture_assert(tctx,
10273 upload_printer_driver(tctx, dcerpc_server_name(p), d),
10274 "failed to upload printer driver");
10277 info8.architecture = d->local.environment;
10279 for (i=0; i < 3; i++) {
10280 info8.driver_name = talloc_asprintf(d, "torture_test_driver_%d", i);
10282 torture_assert(tctx,
10283 test_AddPrinterDriver_args_level_3(tctx, b, server_name_slash, &info8, add_flags, true, NULL),
10284 "failed to add driver");
10287 torture_assert(tctx,
10288 test_DeletePrinterDriverEx(tctx, b, server_name_slash, "torture_test_driver_0", info8.architecture, delete_flags, info8.version),
10289 "failed to delete driver");
10291 torture_assert(tctx,
10292 test_EnumPrinterDrivers_findone(tctx, b, server_name_slash, info8.architecture, 3, "torture_test_driver_1", NULL),
10293 "torture_test_driver_1 no longer on the server");
10295 torture_assert(tctx,
10296 test_EnumPrinterDrivers_findone(tctx, b, server_name_slash, info8.architecture, 3, "torture_test_driver_2", NULL),
10297 "torture_test_driver_2 no longer on the server");
10299 torture_assert(tctx,
10300 test_DeletePrinterDriverEx(tctx, b, server_name_slash, "torture_test_driver_1", info8.architecture, delete_flags, info8.version),
10301 "failed to delete driver");
10303 torture_assert(tctx,
10304 test_EnumPrinterDrivers_findone(tctx, b, server_name_slash, info8.architecture, 3, "torture_test_driver_2", NULL),
10305 "torture_test_driver_2 no longer on the server");
10307 torture_assert(tctx,
10308 test_DeletePrinterDriverEx(tctx, b, server_name_slash, "torture_test_driver_2", info8.architecture, delete_flags, info8.version),
10309 "failed to delete driver");
10311 torture_assert(tctx,
10312 remove_printer_driver(tctx, dcerpc_server_name(p), d),
10313 "failed to remove printer driver");
10318 static bool test_del_driver_all_files(struct torture_context *tctx,
10319 struct dcerpc_pipe *p)
10321 struct torture_driver_context *d;
10322 struct spoolss_StringArray *a;
10323 uint32_t add_flags = APD_COPY_NEW_FILES;
10324 uint32_t delete_flags = DPD_DELETE_ALL_FILES;
10325 struct dcerpc_binding_handle *b = p->binding_handle;
10326 const char *server_name_slash = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
10328 d = talloc_zero(tctx, struct torture_driver_context);
10331 d->info8.version = SPOOLSS_DRIVER_VERSION_200X;
10332 d->info8.driver_name = TORTURE_DRIVER_DELETER;
10333 d->info8.architecture = NULL;
10334 d->info8.driver_path = talloc_strdup(d, "pscript5.dll");
10335 d->info8.data_file = talloc_strdup(d, "cups6.ppd");
10336 d->info8.config_file = talloc_strdup(d, "cupsui6.dll");
10337 d->info8.help_file = talloc_strdup(d, "pscript.hlp");
10338 d->local.environment = talloc_strdup(d, SPOOLSS_ARCHITECTURE_x64);
10339 d->local.driver_directory = talloc_strdup(d, "/usr/share/cups/drivers/x64");
10341 a = talloc_zero(d, struct spoolss_StringArray);
10342 a->string = talloc_zero_array(a, const char *, 3);
10343 a->string[0] = talloc_strdup(a->string, "cups6.inf");
10344 a->string[1] = talloc_strdup(a->string, "cups6.ini");
10346 d->info8.dependent_files = a;
10347 d->info8.architecture = d->local.environment;
10349 torture_assert(tctx,
10350 fillup_printserver_info(tctx, p, d),
10351 "failed to fillup printserver info");
10353 if (!directory_exist(d->local.driver_directory)) {
10354 torture_skip(tctx, "Skipping Printer Driver test as no local driver is available");
10357 torture_assert(tctx,
10358 upload_printer_driver(tctx, dcerpc_server_name(p), d),
10359 "failed to upload printer driver");
10361 torture_assert(tctx,
10362 test_AddPrinterDriver_args_level_3(tctx, b, server_name_slash, &d->info8, add_flags, true, NULL),
10363 "failed to add driver");
10365 torture_assert(tctx,
10366 test_DeletePrinterDriverEx(tctx, b, server_name_slash,
10367 d->info8.driver_name,
10368 d->local.environment,
10371 "failed to delete driver");
10373 torture_assert(tctx,
10374 check_printer_driver_files(tctx, dcerpc_server_name(p), d, false),
10375 "printer driver file check failed");
10381 static bool test_del_driver_unused_files(struct torture_context *tctx,
10382 struct dcerpc_pipe *p)
10384 struct torture_driver_context *d1;
10385 struct torture_driver_context *d2;
10386 uint32_t add_flags = APD_COPY_NEW_FILES;
10387 struct dcerpc_binding_handle *b = p->binding_handle;
10388 const char *server_name_slash = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
10390 d1 = talloc_zero(tctx, struct torture_driver_context);
10392 d1->info8.version = SPOOLSS_DRIVER_VERSION_200X;
10393 d1->info8.driver_name = TORTURE_DRIVER_DELETER;
10394 d1->info8.architecture = NULL;
10395 d1->info8.driver_path = talloc_strdup(d1, "pscript5.dll");
10396 d1->info8.data_file = talloc_strdup(d1, "cups6.ppd");
10397 d1->info8.config_file = talloc_strdup(d1, "cupsui6.dll");
10398 d1->info8.help_file = talloc_strdup(d1, "pscript.hlp");
10399 d1->local.environment = talloc_strdup(d1, SPOOLSS_ARCHITECTURE_x64);
10400 d1->local.driver_directory = talloc_strdup(d1, "/usr/share/cups/drivers/x64");
10401 d1->info8.architecture = d1->local.environment;
10403 d2 = talloc_zero(tctx, struct torture_driver_context);
10405 d2->info8.version = SPOOLSS_DRIVER_VERSION_200X;
10406 d2->info8.driver_name = TORTURE_DRIVER_DELETERIN;
10407 d2->info8.architecture = NULL;
10408 d2->info8.driver_path = talloc_strdup(d2, "pscript5.dll"); /* overlapping */
10409 d2->info8.data_file = talloc_strdup(d2, "cupsps6.dll");
10410 d2->info8.config_file = talloc_strdup(d2, "cups6.ini");
10411 d2->info8.help_file = talloc_strdup(d2, "pscript.hlp"); /* overlapping */
10412 d2->local.environment = talloc_strdup(d2, SPOOLSS_ARCHITECTURE_x64);
10413 d2->local.driver_directory = talloc_strdup(d2, "/usr/share/cups/drivers/x64");
10414 d2->info8.architecture = d2->local.environment;
10416 torture_assert(tctx,
10417 fillup_printserver_info(tctx, p, d1),
10418 "failed to fillup printserver info");
10419 torture_assert(tctx,
10420 fillup_printserver_info(tctx, p, d2),
10421 "failed to fillup printserver info");
10423 if (!directory_exist(d1->local.driver_directory)) {
10424 torture_skip(tctx, "Skipping Printer Driver test as no local driver is available");
10427 torture_assert(tctx,
10428 upload_printer_driver(tctx, dcerpc_server_name(p), d1),
10429 "failed to upload printer driver");
10430 torture_assert(tctx,
10431 test_AddPrinterDriver_args_level_3(tctx, b, server_name_slash, &d1->info8, add_flags, true, NULL),
10432 "failed to add driver");
10434 torture_assert(tctx,
10435 upload_printer_driver(tctx, dcerpc_server_name(p), d2),
10436 "failed to upload printer driver");
10437 torture_assert(tctx,
10438 test_AddPrinterDriver_args_level_3(tctx, b, server_name_slash, &d2->info8, add_flags, true, NULL),
10439 "failed to add driver");
10441 /* some files are in use by a separate driver, should fail */
10442 torture_assert(tctx,
10443 test_DeletePrinterDriverEx_exp(tctx, b, server_name_slash,
10444 d1->info8.driver_name,
10445 d1->local.environment,
10446 DPD_DELETE_ALL_FILES,
10448 WERR_PRINTER_DRIVER_IN_USE),
10449 "invalid delete driver response");
10451 /* should only delete files not in use by other driver */
10452 torture_assert(tctx,
10453 test_DeletePrinterDriverEx_exp(tctx, b, server_name_slash,
10454 d1->info8.driver_name,
10455 d1->local.environment,
10456 DPD_DELETE_UNUSED_FILES,
10459 "failed to delete driver (unused files)");
10461 /* check non-overlapping were deleted */
10462 d1->info8.driver_path = NULL;
10463 d1->info8.help_file = NULL;
10464 torture_assert(tctx,
10465 check_printer_driver_files(tctx, dcerpc_server_name(p), d1, false),
10466 "printer driver file check failed");
10467 /* d2 files should be uneffected */
10468 torture_assert(tctx,
10469 check_printer_driver_files(tctx, dcerpc_server_name(p), d2, true),
10470 "printer driver file check failed");
10472 torture_assert(tctx,
10473 test_DeletePrinterDriverEx_exp(tctx, b, server_name_slash,
10474 d2->info8.driver_name,
10475 d2->local.environment,
10476 DPD_DELETE_ALL_FILES,
10479 "failed to delete driver");
10481 torture_assert(tctx,
10482 check_printer_driver_files(tctx, dcerpc_server_name(p), d2, false),
10483 "printer driver file check failed");
10490 struct torture_suite *torture_rpc_spoolss_driver(TALLOC_CTX *mem_ctx)
10492 struct torture_suite *suite = torture_suite_create(mem_ctx, "spoolss.driver");
10494 struct torture_rpc_tcase *tcase = torture_suite_add_rpc_iface_tcase(suite,
10495 "driver", &ndr_table_spoolss);
10496 torture_rpc_tcase_add_test(tcase, "add_driver_64", test_add_driver_64);
10497 torture_rpc_tcase_add_test(tcase, "add_driver_ex_64", test_add_driver_ex_64);
10499 torture_rpc_tcase_add_test(tcase, "add_driver_32", test_add_driver_32);
10500 torture_rpc_tcase_add_test(tcase, "add_driver_ex_32", test_add_driver_ex_32);
10502 torture_rpc_tcase_add_test(tcase, "add_driver_adobe", test_add_driver_adobe);
10504 torture_rpc_tcase_add_test(tcase, "add_driver_adobe_cupsaddsmb", test_add_driver_adobe_cupsaddsmb);
10506 torture_rpc_tcase_add_test(tcase, "add_driver_timestamps", test_add_driver_timestamps);
10508 torture_rpc_tcase_add_test(tcase, "multiple_drivers", test_multiple_drivers);
10510 torture_rpc_tcase_add_test(tcase, "del_driver_all_files", test_del_driver_all_files);
10512 torture_rpc_tcase_add_test(tcase, "del_driver_unused_files", test_del_driver_unused_files);