2 Unix SMB/CIFS implementation.
3 test suite for spoolss rpc operations
5 Copyright (C) Tim Potter 2003
6 Copyright (C) Stefan Metzmacher 2005
7 Copyright (C) Jelmer Vernooij 2007
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "torture/torture.h"
25 #include "torture/rpc/rpc.h"
26 #include "librpc/gen_ndr/ndr_spoolss_c.h"
28 struct test_spoolss_context
{
29 /* print server handle */
30 struct policy_handle server_handle
;
33 uint32_t port_count
[3];
34 union spoolss_PortInfo
*ports
[3];
36 /* for EnumPrinterDrivers */
37 uint32_t driver_count
[7];
38 union spoolss_DriverInfo
*drivers
[7];
40 /* for EnumMonitors */
41 uint32_t monitor_count
[3];
42 union spoolss_MonitorInfo
*monitors
[3];
44 /* for EnumPrintProcessors */
45 uint32_t print_processor_count
[2];
46 union spoolss_PrintProcessorInfo
*print_processors
[2];
48 /* for EnumPrinters */
49 uint32_t printer_count
[6];
50 union spoolss_PrinterInfo
*printers
[6];
53 #define COMPARE_STRING(tctx, c,r,e) \
54 torture_assert_str_equal(tctx, c.e, r.e, "invalid value")
56 /* not every compiler supports __typeof__() */
58 #define _CHECK_FIELD_SIZE(c,r,e,type) do {\
59 if (sizeof(__typeof__(c.e)) != sizeof(type)) { \
60 torture_fail(tctx, #c "." #e "field is not " #type "\n"); \
62 if (sizeof(__typeof__(r.e)) != sizeof(type)) { \
63 torture_fail(tctx, #r "." #e "field is not " #type "\n"); \
67 #define _CHECK_FIELD_SIZE(c,r,e,type) do {} while(0)
70 #define COMPARE_UINT32(tctx, c, r, e) do {\
71 _CHECK_FIELD_SIZE(c, r, e, uint32_t); \
72 torture_assert_int_equal(tctx, c.e, r.e, "invalid value"); \
75 #define COMPARE_STRING_ARRAY(tctx, c,r,e)
77 static bool test_OpenPrinter_server(struct torture_context
*tctx
, struct dcerpc_pipe
*p
, struct test_spoolss_context
*ctx
)
80 struct spoolss_OpenPrinter op
;
82 op
.in
.printername
= talloc_asprintf(ctx
, "\\\\%s", dcerpc_server_name(p
));
83 op
.in
.datatype
= NULL
;
84 op
.in
.devmode_ctr
.devmode
= NULL
;
85 op
.in
.access_mask
= 0;
86 op
.out
.handle
= &ctx
->server_handle
;
88 torture_comment(tctx
, "Testing OpenPrinter(%s)\n", op
.in
.printername
);
90 status
= dcerpc_spoolss_OpenPrinter(p
, ctx
, &op
);
91 torture_assert_ntstatus_ok(tctx
, status
, "dcerpc_spoolss_OpenPrinter failed");
92 torture_assert_werr_ok(tctx
, op
.out
.result
, "dcerpc_spoolss_OpenPrinter failed");
97 static bool test_EnumPorts(struct torture_context
*tctx
,
98 struct dcerpc_pipe
*p
,
99 struct test_spoolss_context
*ctx
)
102 struct spoolss_EnumPorts r
;
103 uint16_t levels
[] = { 1, 2 };
106 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
107 int level
= levels
[i
];
111 union spoolss_PortInfo
*info
;
113 r
.in
.servername
= "";
117 r
.out
.needed
= &needed
;
118 r
.out
.count
= &count
;
121 torture_comment(tctx
, "Testing EnumPorts level %u\n", r
.in
.level
);
123 status
= dcerpc_spoolss_EnumPorts(p
, ctx
, &r
);
124 torture_assert_ntstatus_ok(tctx
, status
, "dcerpc_spoolss_EnumPorts failed");
125 if (W_ERROR_IS_OK(r
.out
.result
)) {
126 /* TODO: do some more checks here */
129 torture_assert_werr_equal(tctx
, r
.out
.result
, WERR_INSUFFICIENT_BUFFER
,
130 "EnumPorts unexpected return code");
132 blob
= data_blob_talloc(ctx
, NULL
, needed
);
133 data_blob_clear(&blob
);
135 r
.in
.offered
= needed
;
137 status
= dcerpc_spoolss_EnumPorts(p
, ctx
, &r
);
138 torture_assert_ntstatus_ok(tctx
, status
, "dcerpc_spoolss_EnumPorts failed");
140 torture_assert_werr_ok(tctx
, r
.out
.result
, "EnumPorts failed");
142 torture_assert(tctx
, info
, "EnumPorts returned no info");
144 ctx
->port_count
[level
] = count
;
145 ctx
->ports
[level
] = info
;
148 for (i
=1;i
<ARRAY_SIZE(levels
);i
++) {
149 int level
= levels
[i
];
150 int old_level
= levels
[i
-1];
151 torture_assert_int_equal(tctx
, ctx
->port_count
[level
], ctx
->port_count
[old_level
],
152 "EnumPorts invalid value");
154 /* if the array sizes are not the same we would maybe segfault in the following code */
156 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
157 int level
= levels
[i
];
158 for (j
=0;j
<ctx
->port_count
[level
];j
++) {
159 union spoolss_PortInfo
*cur
= &ctx
->ports
[level
][j
];
160 union spoolss_PortInfo
*ref
= &ctx
->ports
[2][j
];
163 COMPARE_STRING(tctx
, cur
->info1
, ref
->info2
, port_name
);
166 /* level 2 is our reference, and it makes no sense to compare it to itself */
175 static bool test_GetPrintProcessorDirectory(struct torture_context
*tctx
,
176 struct dcerpc_pipe
*p
,
177 struct test_spoolss_context
*ctx
)
180 struct spoolss_GetPrintProcessorDirectory r
;
195 .server
= talloc_asprintf(ctx
, "\\\\%s", dcerpc_server_name(p
))
198 .server
= talloc_asprintf(ctx
, "\\\\%s", dcerpc_server_name(p
))
204 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
205 int level
= levels
[i
].level
;
208 r
.in
.server
= levels
[i
].server
;
209 r
.in
.environment
= SPOOLSS_ARCHITECTURE_NT_X86
;
213 r
.out
.needed
= &needed
;
215 torture_comment(tctx
, "Testing GetPrintProcessorDirectory level %u\n", r
.in
.level
);
217 status
= dcerpc_spoolss_GetPrintProcessorDirectory(p
, ctx
, &r
);
218 torture_assert_ntstatus_ok(tctx
, status
,
219 "dcerpc_spoolss_GetPrintProcessorDirectory failed");
220 torture_assert_werr_equal(tctx
, r
.out
.result
, WERR_INSUFFICIENT_BUFFER
,
221 "GetPrintProcessorDirectory unexpected return code");
223 blob
= data_blob_talloc(ctx
, NULL
, needed
);
224 data_blob_clear(&blob
);
226 r
.in
.offered
= needed
;
228 status
= dcerpc_spoolss_GetPrintProcessorDirectory(p
, ctx
, &r
);
229 torture_assert_ntstatus_ok(tctx
, status
, "dcerpc_spoolss_GetPrintProcessorDirectory failed");
231 torture_assert_werr_ok(tctx
, r
.out
.result
, "GetPrintProcessorDirectory failed");
238 static bool test_GetPrinterDriverDirectory(struct torture_context
*tctx
,
239 struct dcerpc_pipe
*p
,
240 struct test_spoolss_context
*ctx
)
243 struct spoolss_GetPrinterDriverDirectory r
;
258 .server
= talloc_asprintf(ctx
, "\\\\%s", dcerpc_server_name(p
))
261 .server
= talloc_asprintf(ctx
, "\\\\%s", dcerpc_server_name(p
))
267 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
268 int level
= levels
[i
].level
;
271 r
.in
.server
= levels
[i
].server
;
272 r
.in
.environment
= SPOOLSS_ARCHITECTURE_NT_X86
;
276 r
.out
.needed
= &needed
;
278 torture_comment(tctx
, "Testing GetPrinterDriverDirectory level %u\n", r
.in
.level
);
280 status
= dcerpc_spoolss_GetPrinterDriverDirectory(p
, ctx
, &r
);
281 torture_assert_ntstatus_ok(tctx
, status
,
282 "dcerpc_spoolss_GetPrinterDriverDirectory failed");
283 torture_assert_werr_equal(tctx
, r
.out
.result
, WERR_INSUFFICIENT_BUFFER
,
284 "GetPrinterDriverDirectory unexpected return code");
286 blob
= data_blob_talloc(ctx
, NULL
, needed
);
287 data_blob_clear(&blob
);
289 r
.in
.offered
= needed
;
291 status
= dcerpc_spoolss_GetPrinterDriverDirectory(p
, ctx
, &r
);
292 torture_assert_ntstatus_ok(tctx
, status
, "dcerpc_spoolss_GetPrinterDriverDirectory failed");
294 torture_assert_werr_ok(tctx
, r
.out
.result
, "GetPrinterDriverDirectory failed");
300 static bool test_EnumPrinterDrivers(struct torture_context
*tctx
,
301 struct dcerpc_pipe
*p
,
302 struct test_spoolss_context
*ctx
)
305 struct spoolss_EnumPrinterDrivers r
;
306 uint16_t levels
[] = { 1, 2, 3, 4, 5, 6 };
309 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
310 int level
= levels
[i
];
314 union spoolss_DriverInfo
*info
;
317 r
.in
.environment
= SPOOLSS_ARCHITECTURE_NT_X86
;
321 r
.out
.needed
= &needed
;
322 r
.out
.count
= &count
;
325 torture_comment(tctx
, "Testing EnumPrinterDrivers level %u\n", r
.in
.level
);
327 status
= dcerpc_spoolss_EnumPrinterDrivers(p
, ctx
, &r
);
328 torture_assert_ntstatus_ok(tctx
, status
,
329 "dcerpc_spoolss_EnumPrinterDrivers 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 "EnumPrinterDrivers failed");
337 blob
= data_blob_talloc(ctx
, NULL
, needed
);
338 data_blob_clear(&blob
);
340 r
.in
.offered
= needed
;
342 status
= dcerpc_spoolss_EnumPrinterDrivers(p
, ctx
, &r
);
343 torture_assert_ntstatus_ok(tctx
, status
, "dcerpc_spoolss_EnumPrinterDrivers failed");
345 torture_assert_werr_ok(tctx
, r
.out
.result
, "EnumPrinterDrivers failed");
347 ctx
->driver_count
[level
] = count
;
348 ctx
->drivers
[level
] = info
;
351 for (i
=1;i
<ARRAY_SIZE(levels
);i
++) {
352 int level
= levels
[i
];
353 int old_level
= levels
[i
-1];
354 torture_assert_int_equal(tctx
, ctx
->driver_count
[level
], ctx
->driver_count
[old_level
],
355 "EnumPrinterDrivers invalid value");
358 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
359 int level
= levels
[i
];
360 for (j
=0;j
<ctx
->driver_count
[level
];j
++) {
361 union spoolss_DriverInfo
*cur
= &ctx
->drivers
[level
][j
];
362 union spoolss_DriverInfo
*ref
= &ctx
->drivers
[6][j
];
365 COMPARE_STRING(tctx
, cur
->info1
, ref
->info6
, driver_name
);
368 COMPARE_UINT32(tctx
, cur
->info2
, ref
->info6
, version
);
369 COMPARE_STRING(tctx
, cur
->info2
, ref
->info6
, driver_name
);
370 COMPARE_STRING(tctx
, cur
->info2
, ref
->info6
, architecture
);
371 COMPARE_STRING(tctx
, cur
->info2
, ref
->info6
, driver_path
);
372 COMPARE_STRING(tctx
, cur
->info2
, ref
->info6
, data_file
);
373 COMPARE_STRING(tctx
, cur
->info2
, ref
->info6
, config_file
);
376 COMPARE_UINT32(tctx
, cur
->info3
, ref
->info6
, version
);
377 COMPARE_STRING(tctx
, cur
->info3
, ref
->info6
, driver_name
);
378 COMPARE_STRING(tctx
, cur
->info3
, ref
->info6
, architecture
);
379 COMPARE_STRING(tctx
, cur
->info3
, ref
->info6
, driver_path
);
380 COMPARE_STRING(tctx
, cur
->info3
, ref
->info6
, data_file
);
381 COMPARE_STRING(tctx
, cur
->info3
, ref
->info6
, config_file
);
382 COMPARE_STRING(tctx
, cur
->info3
, ref
->info6
, help_file
);
383 COMPARE_STRING_ARRAY(tctx
, cur
->info3
, ref
->info6
, dependent_files
);
384 COMPARE_STRING(tctx
, cur
->info3
, ref
->info6
, monitor_name
);
385 COMPARE_STRING(tctx
, cur
->info3
, ref
->info6
, default_datatype
);
388 COMPARE_UINT32(tctx
, cur
->info4
, ref
->info6
, version
);
389 COMPARE_STRING(tctx
, cur
->info4
, ref
->info6
, driver_name
);
390 COMPARE_STRING(tctx
, cur
->info4
, ref
->info6
, architecture
);
391 COMPARE_STRING(tctx
, cur
->info4
, ref
->info6
, driver_path
);
392 COMPARE_STRING(tctx
, cur
->info4
, ref
->info6
, data_file
);
393 COMPARE_STRING(tctx
, cur
->info4
, ref
->info6
, config_file
);
394 COMPARE_STRING(tctx
, cur
->info4
, ref
->info6
, help_file
);
395 COMPARE_STRING_ARRAY(tctx
, cur
->info4
, ref
->info6
, dependent_files
);
396 COMPARE_STRING(tctx
, cur
->info4
, ref
->info6
, monitor_name
);
397 COMPARE_STRING(tctx
, cur
->info4
, ref
->info6
, default_datatype
);
398 COMPARE_STRING_ARRAY(tctx
, cur
->info4
, ref
->info6
, previous_names
);
401 COMPARE_UINT32(tctx
, cur
->info5
, ref
->info6
, version
);
402 COMPARE_STRING(tctx
, cur
->info5
, ref
->info6
, driver_name
);
403 COMPARE_STRING(tctx
, cur
->info5
, ref
->info6
, architecture
);
404 COMPARE_STRING(tctx
, cur
->info5
, ref
->info6
, driver_path
);
405 COMPARE_STRING(tctx
, cur
->info5
, ref
->info6
, data_file
);
406 COMPARE_STRING(tctx
, cur
->info5
, ref
->info6
, config_file
);
407 /*COMPARE_UINT32(tctx, cur->info5, ref->info6, driver_attributes);*/
408 /*COMPARE_UINT32(tctx, cur->info5, ref->info6, config_version);*/
409 /*TODO: ! COMPARE_UINT32(tctx, cur->info5, ref->info6, driver_version); */
412 /* level 6 is our reference, and it makes no sense to compare it to itself */
421 static bool test_EnumMonitors(struct torture_context
*tctx
,
422 struct dcerpc_pipe
*p
,
423 struct test_spoolss_context
*ctx
)
426 struct spoolss_EnumMonitors r
;
427 uint16_t levels
[] = { 1, 2 };
430 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
431 int level
= levels
[i
];
435 union spoolss_MonitorInfo
*info
;
437 r
.in
.servername
= "";
441 r
.out
.needed
= &needed
;
442 r
.out
.count
= &count
;
445 torture_comment(tctx
, "Testing EnumMonitors level %u\n", r
.in
.level
);
447 status
= dcerpc_spoolss_EnumMonitors(p
, ctx
, &r
);
448 torture_assert_ntstatus_ok(tctx
, status
, "dcerpc_spoolss_EnumMonitors failed");
449 if (W_ERROR_IS_OK(r
.out
.result
)) {
450 /* TODO: do some more checks here */
453 torture_assert_werr_equal(tctx
, r
.out
.result
, WERR_INSUFFICIENT_BUFFER
,
454 "EnumMonitors failed");
456 blob
= data_blob_talloc(ctx
, NULL
, needed
);
457 data_blob_clear(&blob
);
459 r
.in
.offered
= needed
;
461 status
= dcerpc_spoolss_EnumMonitors(p
, ctx
, &r
);
462 torture_assert_ntstatus_ok(tctx
, status
, "dcerpc_spoolss_EnumMonitors failed");
464 torture_assert_werr_ok(tctx
, r
.out
.result
, "EnumMonitors failed");
466 ctx
->monitor_count
[level
] = count
;
467 ctx
->monitors
[level
] = info
;
470 for (i
=1;i
<ARRAY_SIZE(levels
);i
++) {
471 int level
= levels
[i
];
472 int old_level
= levels
[i
-1];
473 torture_assert_int_equal(tctx
, ctx
->monitor_count
[level
], ctx
->monitor_count
[old_level
],
474 "EnumMonitors invalid value");
477 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
478 int level
= levels
[i
];
479 for (j
=0;j
<ctx
->monitor_count
[level
];j
++) {
480 union spoolss_MonitorInfo
*cur
= &ctx
->monitors
[level
][j
];
481 union spoolss_MonitorInfo
*ref
= &ctx
->monitors
[2][j
];
484 COMPARE_STRING(tctx
, cur
->info1
, ref
->info2
, monitor_name
);
487 /* level 2 is our reference, and it makes no sense to compare it to itself */
496 static bool test_EnumPrintProcessors(struct torture_context
*tctx
,
497 struct dcerpc_pipe
*p
,
498 struct test_spoolss_context
*ctx
)
501 struct spoolss_EnumPrintProcessors r
;
502 uint16_t levels
[] = { 1 };
505 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
506 int level
= levels
[i
];
510 union spoolss_PrintProcessorInfo
*info
;
512 r
.in
.servername
= "";
513 r
.in
.environment
= "Windows NT x86";
517 r
.out
.needed
= &needed
;
518 r
.out
.count
= &count
;
521 torture_comment(tctx
, "Testing EnumPrintProcessors level %u\n", r
.in
.level
);
523 status
= dcerpc_spoolss_EnumPrintProcessors(p
, ctx
, &r
);
524 torture_assert_ntstatus_ok(tctx
, status
, "dcerpc_spoolss_EnumPrintProcessors failed");
525 if (W_ERROR_IS_OK(r
.out
.result
)) {
526 /* TODO: do some more checks here */
529 torture_assert_werr_equal(tctx
, r
.out
.result
, WERR_INSUFFICIENT_BUFFER
,
530 "EnumPrintProcessors unexpected return code");
532 blob
= data_blob_talloc(ctx
, NULL
, needed
);
533 data_blob_clear(&blob
);
535 r
.in
.offered
= needed
;
537 status
= dcerpc_spoolss_EnumPrintProcessors(p
, ctx
, &r
);
538 torture_assert_ntstatus_ok(tctx
, status
, "dcerpc_spoolss_EnumPrintProcessors failed");
540 torture_assert_werr_ok(tctx
, r
.out
.result
, "EnumPrintProcessors failed");
542 ctx
->print_processor_count
[level
] = count
;
543 ctx
->print_processors
[level
] = info
;
546 for (i
=1;i
<ARRAY_SIZE(levels
);i
++) {
547 int level
= levels
[i
];
548 int old_level
= levels
[i
-1];
549 torture_assert_int_equal(tctx
, ctx
->print_processor_count
[level
], ctx
->print_processor_count
[old_level
],
550 "EnumPrintProcessors failed");
553 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
554 int level
= levels
[i
];
555 for (j
=0;j
<ctx
->print_processor_count
[level
];j
++) {
557 union spoolss_PrintProcessorInfo
*cur
= &ctx
->print_processors
[level
][j
];
558 union spoolss_PrintProcessorInfo
*ref
= &ctx
->print_processors
[1][j
];
562 /* level 1 is our reference, and it makes no sense to compare it to itself */
571 static bool test_EnumPrintProcDataTypes(struct torture_context
*tctx
,
572 struct dcerpc_pipe
*p
,
573 struct test_spoolss_context
*ctx
)
576 struct spoolss_EnumPrintProcDataTypes r
;
577 uint16_t levels
[] = { 1 };
580 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
581 int level
= levels
[i
];
585 union spoolss_PrintProcDataTypesInfo
*info
;
587 r
.in
.servername
= "";
588 r
.in
.print_processor_name
= "winprint";
592 r
.out
.needed
= &needed
;
593 r
.out
.count
= &count
;
596 torture_comment(tctx
, "Testing EnumPrintProcDataTypes level %u\n", r
.in
.level
);
598 status
= dcerpc_spoolss_EnumPrintProcDataTypes(p
, ctx
, &r
);
599 torture_assert_ntstatus_ok(tctx
, status
, "dcerpc_spoolss_EnumPrintProcDataType failed");
600 if (W_ERROR_IS_OK(r
.out
.result
)) {
601 /* TODO: do some more checks here */
604 torture_assert_werr_equal(tctx
, r
.out
.result
, WERR_INSUFFICIENT_BUFFER
,
605 "EnumPrintProcDataTypes unexpected return code");
607 blob
= data_blob_talloc(ctx
, NULL
, needed
);
608 data_blob_clear(&blob
);
610 r
.in
.offered
= needed
;
612 status
= dcerpc_spoolss_EnumPrintProcDataTypes(p
, ctx
, &r
);
613 torture_assert_ntstatus_ok(tctx
, status
, "dcerpc_spoolss_EnumPrintProcDataTypes failed");
615 torture_assert_werr_ok(tctx
, r
.out
.result
, "EnumPrintProcDataTypes failed");
622 static bool test_EnumPrinters(struct torture_context
*tctx
,
623 struct dcerpc_pipe
*p
,
624 struct test_spoolss_context
*ctx
)
626 struct spoolss_EnumPrinters r
;
628 uint16_t levels
[] = { 0, 1, 2, 4, 5 };
631 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
632 int level
= levels
[i
];
636 union spoolss_PrinterInfo
*info
;
638 r
.in
.flags
= PRINTER_ENUM_LOCAL
;
643 r
.out
.needed
= &needed
;
644 r
.out
.count
= &count
;
647 torture_comment(tctx
, "Testing EnumPrinters level %u\n", r
.in
.level
);
649 status
= dcerpc_spoolss_EnumPrinters(p
, ctx
, &r
);
650 torture_assert_ntstatus_ok(tctx
, status
, "dcerpc_spoolss_EnumPrinters failed");
651 if (W_ERROR_IS_OK(r
.out
.result
)) {
652 /* TODO: do some more checks here */
655 torture_assert_werr_equal(tctx
, r
.out
.result
, WERR_INSUFFICIENT_BUFFER
,
656 "EnumPrinters unexpected return code");
658 blob
= data_blob_talloc(ctx
, NULL
, needed
);
659 data_blob_clear(&blob
);
661 r
.in
.offered
= needed
;
663 status
= dcerpc_spoolss_EnumPrinters(p
, ctx
, &r
);
664 torture_assert_ntstatus_ok(tctx
, status
, "dcerpc_spoolss_EnumPrinters failed");
666 torture_assert_werr_ok(tctx
, r
.out
.result
, "EnumPrinters failed");
668 ctx
->printer_count
[level
] = count
;
669 ctx
->printers
[level
] = info
;
672 for (i
=1;i
<ARRAY_SIZE(levels
);i
++) {
673 int level
= levels
[i
];
674 int old_level
= levels
[i
-1];
675 torture_assert_int_equal(tctx
, ctx
->printer_count
[level
], ctx
->printer_count
[old_level
],
676 "EnumPrinters invalid value");
679 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
680 int level
= levels
[i
];
681 for (j
=0;j
<ctx
->printer_count
[level
];j
++) {
682 union spoolss_PrinterInfo
*cur
= &ctx
->printers
[level
][j
];
683 union spoolss_PrinterInfo
*ref
= &ctx
->printers
[2][j
];
686 COMPARE_STRING(tctx
, cur
->info0
, ref
->info2
, printername
);
687 COMPARE_STRING(tctx
, cur
->info0
, ref
->info2
, servername
);
688 COMPARE_UINT32(tctx
, cur
->info0
, ref
->info2
, cjobs
);
689 /*COMPARE_UINT32(tctx, cur->info0, ref->info2, total_jobs);
690 COMPARE_UINT32(tctx, cur->info0, ref->info2, total_bytes);
691 COMPARE_SPOOLSS_TIME(cur->info0, ref->info2, spoolss_Time time);
692 COMPARE_UINT32(tctx, cur->info0, ref->info2, global_counter);
693 COMPARE_UINT32(tctx, cur->info0, ref->info2, total_pages);
694 COMPARE_UINT32(tctx, cur->info0, ref->info2, version);
695 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown10);
696 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown11);
697 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown12);
698 COMPARE_UINT32(tctx, cur->info0, ref->info2, session_counter);
699 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown14);
700 COMPARE_UINT32(tctx, cur->info0, ref->info2, printer_errors);
701 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown16);
702 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown17);
703 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown18);
704 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown19);
705 COMPARE_UINT32(tctx, cur->info0, ref->info2, change_id);
706 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown21);*/
707 COMPARE_UINT32(tctx
, cur
->info0
, ref
->info2
, status
);
708 /*COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown23);
709 COMPARE_UINT32(tctx, cur->info0, ref->info2, c_setprinter);
710 COMPARE_UINT16(cur->info0, ref->info2, unknown25);
711 COMPARE_UINT16(cur->info0, ref->info2, unknown26);
712 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown27);
713 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown28);
714 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown29);*/
717 /*COMPARE_UINT32(tctx, cur->info1, ref->info2, flags);*/
718 /*COMPARE_STRING(tctx, cur->info1, ref->info2, name);*/
719 /*COMPARE_STRING(tctx, cur->info1, ref->info2, description);*/
720 COMPARE_STRING(tctx
, cur
->info1
, ref
->info2
, comment
);
723 /* level 2 is our reference, and it makes no sense to compare it to itself */
726 COMPARE_STRING(tctx
, cur
->info4
, ref
->info2
, printername
);
727 COMPARE_STRING(tctx
, cur
->info4
, ref
->info2
, servername
);
728 COMPARE_UINT32(tctx
, cur
->info4
, ref
->info2
, attributes
);
731 COMPARE_STRING(tctx
, cur
->info5
, ref
->info2
, printername
);
732 COMPARE_STRING(tctx
, cur
->info5
, ref
->info2
, portname
);
733 COMPARE_UINT32(tctx
, cur
->info5
, ref
->info2
, attributes
);
734 /*COMPARE_UINT32(tctx, cur->info5, ref->info2, device_not_selected_timeout);
735 COMPARE_UINT32(tctx, cur->info5, ref->info2, transmission_retry_timeout);*/
742 * - verify that the port of a printer was in the list returned by EnumPorts
748 static bool test_GetPrinter(struct torture_context
*tctx
,
749 struct dcerpc_pipe
*p
,
750 struct policy_handle
*handle
)
753 struct spoolss_GetPrinter r
;
754 uint16_t levels
[] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
758 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
759 r
.in
.handle
= handle
;
760 r
.in
.level
= levels
[i
];
763 r
.out
.needed
= &needed
;
765 torture_comment(tctx
, "Testing GetPrinter level %u\n", r
.in
.level
);
767 status
= dcerpc_spoolss_GetPrinter(p
, tctx
, &r
);
768 torture_assert_ntstatus_ok(tctx
, status
, "GetPrinter failed");
770 if (W_ERROR_EQUAL(r
.out
.result
, WERR_INSUFFICIENT_BUFFER
)) {
771 DATA_BLOB blob
= data_blob_talloc(tctx
, NULL
, needed
);
772 data_blob_clear(&blob
);
774 r
.in
.offered
= needed
;
775 status
= dcerpc_spoolss_GetPrinter(p
, tctx
, &r
);
778 torture_assert_ntstatus_ok(tctx
, status
, "GetPrinter failed");
780 torture_assert_werr_ok(tctx
, r
.out
.result
, "GetPrinter failed");
787 static bool test_ClosePrinter(struct torture_context
*tctx
,
788 struct dcerpc_pipe
*p
,
789 struct policy_handle
*handle
)
792 struct spoolss_ClosePrinter r
;
794 r
.in
.handle
= handle
;
795 r
.out
.handle
= handle
;
797 torture_comment(tctx
, "Testing ClosePrinter\n");
799 status
= dcerpc_spoolss_ClosePrinter(p
, tctx
, &r
);
800 torture_assert_ntstatus_ok(tctx
, status
, "ClosePrinter failed");
805 static bool test_GetForm(struct torture_context
*tctx
,
806 struct dcerpc_pipe
*p
,
807 struct policy_handle
*handle
,
808 const char *form_name
,
812 struct spoolss_GetForm r
;
815 r
.in
.handle
= handle
;
816 r
.in
.form_name
= form_name
;
820 r
.out
.needed
= &needed
;
822 torture_comment(tctx
, "Testing GetForm level %d\n", r
.in
.level
);
824 status
= dcerpc_spoolss_GetForm(p
, tctx
, &r
);
825 torture_assert_ntstatus_ok(tctx
, status
, "GetForm failed");
827 if (W_ERROR_EQUAL(r
.out
.result
, WERR_INSUFFICIENT_BUFFER
)) {
828 DATA_BLOB blob
= data_blob_talloc(tctx
, NULL
, needed
);
829 data_blob_clear(&blob
);
831 r
.in
.offered
= needed
;
832 status
= dcerpc_spoolss_GetForm(p
, tctx
, &r
);
833 torture_assert_ntstatus_ok(tctx
, status
, "GetForm failed");
835 torture_assert_werr_ok(tctx
, r
.out
.result
, "GetForm failed");
837 torture_assert(tctx
, r
.out
.info
, "No form info returned");
840 torture_assert_werr_ok(tctx
, r
.out
.result
, "GetForm failed");
845 static bool test_EnumForms(struct torture_context
*tctx
,
846 struct dcerpc_pipe
*p
,
847 struct policy_handle
*handle
, bool print_server
)
850 struct spoolss_EnumForms r
;
854 uint32_t levels
[] = { 1, 2 };
857 for (i
=0; i
<ARRAY_SIZE(levels
); i
++) {
859 union spoolss_FormInfo
*info
;
861 r
.in
.handle
= handle
;
862 r
.in
.level
= levels
[i
];
865 r
.out
.needed
= &needed
;
866 r
.out
.count
= &count
;
869 torture_comment(tctx
, "Testing EnumForms level %d\n", levels
[i
]);
871 status
= dcerpc_spoolss_EnumForms(p
, tctx
, &r
);
872 torture_assert_ntstatus_ok(tctx
, status
, "EnumForms failed");
874 if ((r
.in
.level
== 2) && (W_ERROR_EQUAL(r
.out
.result
, WERR_UNKNOWN_LEVEL
))) {
878 if (print_server
&& W_ERROR_EQUAL(r
.out
.result
, WERR_BADFID
))
879 torture_fail(tctx
, "EnumForms on the PrintServer isn't supported by test server (NT4)");
881 if (W_ERROR_EQUAL(r
.out
.result
, WERR_INSUFFICIENT_BUFFER
)) {
883 DATA_BLOB blob
= data_blob_talloc(tctx
, NULL
, needed
);
884 data_blob_clear(&blob
);
886 r
.in
.offered
= needed
;
888 status
= dcerpc_spoolss_EnumForms(p
, tctx
, &r
);
890 torture_assert(tctx
, info
, "No forms returned");
892 for (j
= 0; j
< count
; j
++) {
894 ret
&= test_GetForm(tctx
, p
, handle
, info
[j
].info1
.form_name
, levels
[i
]);
898 torture_assert_ntstatus_ok(tctx
, status
, "EnumForms failed");
900 torture_assert_werr_ok(tctx
, r
.out
.result
, "EnumForms failed");
906 static bool test_DeleteForm(struct torture_context
*tctx
,
907 struct dcerpc_pipe
*p
,
908 struct policy_handle
*handle
,
909 const char *form_name
)
912 struct spoolss_DeleteForm r
;
914 r
.in
.handle
= handle
;
915 r
.in
.form_name
= form_name
;
917 status
= dcerpc_spoolss_DeleteForm(p
, tctx
, &r
);
919 torture_assert_ntstatus_ok(tctx
, status
, "DeleteForm failed");
921 torture_assert_werr_ok(tctx
, r
.out
.result
, "DeleteForm failed");
926 static bool test_AddForm(struct torture_context
*tctx
,
927 struct dcerpc_pipe
*p
,
928 struct policy_handle
*handle
, bool print_server
)
930 struct spoolss_AddForm r
;
931 struct spoolss_AddFormInfo1 addform
;
932 const char *form_name
= "testform3";
936 r
.in
.handle
= handle
;
938 r
.in
.info
.info1
= &addform
;
939 addform
.flags
= SPOOLSS_FORM_USER
;
940 addform
.form_name
= form_name
;
941 addform
.size
.width
= 50;
942 addform
.size
.height
= 25;
943 addform
.area
.left
= 5;
944 addform
.area
.top
= 10;
945 addform
.area
.right
= 45;
946 addform
.area
.bottom
= 15;
948 status
= dcerpc_spoolss_AddForm(p
, tctx
, &r
);
950 torture_assert_ntstatus_ok(tctx
, status
, "AddForm failed");
952 torture_assert_werr_ok(tctx
, r
.out
.result
, "AddForm failed");
954 if (!print_server
) ret
&= test_GetForm(tctx
, p
, handle
, form_name
, 1);
957 struct spoolss_SetForm sf
;
958 struct spoolss_AddFormInfo1 setform
;
960 sf
.in
.handle
= handle
;
961 sf
.in
.form_name
= form_name
;
963 sf
.in
.info
.info1
= &setform
;
964 setform
.flags
= addform
.flags
;
965 setform
.form_name
= addform
.form_name
;
966 setform
.size
= addform
.size
;
967 setform
.area
= addform
.area
;
969 setform
.size
.width
= 1234;
971 status
= dcerpc_spoolss_SetForm(p
, tctx
, &sf
);
973 torture_assert_ntstatus_ok(tctx
, status
, "SetForm failed");
975 torture_assert_werr_ok(tctx
, r
.out
.result
, "SetForm failed");
978 if (!print_server
) ret
&= test_GetForm(tctx
, p
, handle
, form_name
, 1);
980 if (!test_DeleteForm(tctx
, p
, handle
, form_name
)) {
987 static bool test_EnumPorts_old(struct torture_context
*tctx
,
988 struct dcerpc_pipe
*p
)
991 struct spoolss_EnumPorts r
;
994 union spoolss_PortInfo
*info
;
996 r
.in
.servername
= talloc_asprintf(tctx
, "\\\\%s",
997 dcerpc_server_name(p
));
1001 r
.out
.needed
= &needed
;
1002 r
.out
.count
= &count
;
1005 torture_comment(tctx
, "Testing EnumPorts\n");
1007 status
= dcerpc_spoolss_EnumPorts(p
, tctx
, &r
);
1009 torture_assert_ntstatus_ok(tctx
, status
, "EnumPorts failed");
1011 if (W_ERROR_EQUAL(r
.out
.result
, WERR_INSUFFICIENT_BUFFER
)) {
1012 DATA_BLOB blob
= data_blob_talloc(tctx
, NULL
, needed
);
1013 data_blob_clear(&blob
);
1014 r
.in
.buffer
= &blob
;
1015 r
.in
.offered
= needed
;
1017 status
= dcerpc_spoolss_EnumPorts(p
, tctx
, &r
);
1018 torture_assert_ntstatus_ok(tctx
, status
, "EnumPorts failed");
1020 torture_assert(tctx
, info
, "No ports returned");
1026 static bool test_AddPort(struct torture_context
*tctx
,
1027 struct dcerpc_pipe
*p
)
1030 struct spoolss_AddPort r
;
1032 r
.in
.server_name
= talloc_asprintf(tctx
, "\\\\%s",
1033 dcerpc_server_name(p
));
1035 r
.in
.monitor_name
= "foo";
1037 torture_comment(tctx
, "Testing AddPort\n");
1039 status
= dcerpc_spoolss_AddPort(p
, tctx
, &r
);
1041 torture_assert_ntstatus_ok(tctx
, status
, "AddPort failed");
1043 /* win2k3 returns WERR_NOT_SUPPORTED */
1047 if (!W_ERROR_IS_OK(r
.out
.result
)) {
1048 printf("AddPort failed - %s\n", win_errstr(r
.out
.result
));
1057 static bool test_GetJob(struct torture_context
*tctx
,
1058 struct dcerpc_pipe
*p
,
1059 struct policy_handle
*handle
, uint32_t job_id
)
1062 struct spoolss_GetJob r
;
1065 r
.in
.handle
= handle
;
1066 r
.in
.job_id
= job_id
;
1070 r
.out
.needed
= &needed
;
1072 torture_comment(tctx
, "Testing GetJob\n");
1074 status
= dcerpc_spoolss_GetJob(p
, tctx
, &r
);
1075 torture_assert_ntstatus_ok(tctx
, status
, "GetJob failed");
1077 if (W_ERROR_EQUAL(r
.out
.result
, WERR_INSUFFICIENT_BUFFER
)) {
1078 DATA_BLOB blob
= data_blob_talloc(tctx
, NULL
, needed
);
1079 data_blob_clear(&blob
);
1080 r
.in
.buffer
= &blob
;
1081 r
.in
.offered
= needed
;
1083 status
= dcerpc_spoolss_GetJob(p
, tctx
, &r
);
1085 torture_assert(tctx
, r
.out
.info
, "No job info returned");
1091 static bool test_SetJob(struct torture_context
*tctx
,
1092 struct dcerpc_pipe
*p
,
1093 struct policy_handle
*handle
, uint32_t job_id
,
1094 enum spoolss_JobControl command
)
1097 struct spoolss_SetJob r
;
1099 r
.in
.handle
= handle
;
1100 r
.in
.job_id
= job_id
;
1102 r
.in
.command
= command
;
1104 torture_comment(tctx
, "Testing SetJob\n");
1106 status
= dcerpc_spoolss_SetJob(p
, tctx
, &r
);
1107 torture_assert_ntstatus_ok(tctx
, status
, "SetJob failed");
1108 torture_assert_werr_ok(tctx
, r
.out
.result
, "SetJob failed");
1113 static bool test_AddJob(struct torture_context
*tctx
,
1114 struct dcerpc_pipe
*p
,
1115 struct policy_handle
*handle
)
1118 struct spoolss_AddJob r
;
1122 r
.in
.handle
= handle
;
1124 r
.out
.needed
= &needed
;
1125 r
.in
.buffer
= r
.out
.buffer
= NULL
;
1127 torture_comment(tctx
, "Testing AddJob\n");
1129 status
= dcerpc_spoolss_AddJob(p
, tctx
, &r
);
1130 torture_assert_werr_equal(tctx
, r
.out
.result
, WERR_UNKNOWN_LEVEL
, "AddJob failed");
1134 status
= dcerpc_spoolss_AddJob(p
, tctx
, &r
);
1135 torture_assert_werr_equal(tctx
, r
.out
.result
, WERR_INVALID_PARAM
, "AddJob failed");
1141 static bool test_EnumJobs(struct torture_context
*tctx
,
1142 struct dcerpc_pipe
*p
,
1143 struct policy_handle
*handle
)
1146 struct spoolss_EnumJobs r
;
1149 union spoolss_JobInfo
*info
;
1151 r
.in
.handle
= handle
;
1153 r
.in
.numjobs
= 0xffffffff;
1157 r
.out
.needed
= &needed
;
1158 r
.out
.count
= &count
;
1161 torture_comment(tctx
, "Testing EnumJobs\n");
1163 status
= dcerpc_spoolss_EnumJobs(p
, tctx
, &r
);
1165 torture_assert_ntstatus_ok(tctx
, status
, "EnumJobs failed");
1167 if (W_ERROR_EQUAL(r
.out
.result
, WERR_INSUFFICIENT_BUFFER
)) {
1169 DATA_BLOB blob
= data_blob_talloc(tctx
, NULL
, needed
);
1170 data_blob_clear(&blob
);
1171 r
.in
.buffer
= &blob
;
1172 r
.in
.offered
= needed
;
1174 status
= dcerpc_spoolss_EnumJobs(p
, tctx
, &r
);
1176 torture_assert(tctx
, info
, "No jobs returned");
1178 for (j
= 0; j
< count
; j
++) {
1180 test_GetJob(tctx
, p
, handle
, info
[j
].info1
.job_id
);
1181 test_SetJob(tctx
, p
, handle
, info
[j
].info1
.job_id
, SPOOLSS_JOB_CONTROL_PAUSE
);
1182 test_SetJob(tctx
, p
, handle
, info
[j
].info1
.job_id
, SPOOLSS_JOB_CONTROL_RESUME
);
1186 torture_assert_werr_ok(tctx
, r
.out
.result
, "EnumJobs failed");
1192 static bool test_DoPrintTest(struct torture_context
*tctx
,
1193 struct dcerpc_pipe
*p
,
1194 struct policy_handle
*handle
)
1198 struct spoolss_StartDocPrinter s
;
1199 struct spoolss_DocumentInfo1 info1
;
1200 struct spoolss_StartPagePrinter sp
;
1201 struct spoolss_WritePrinter w
;
1202 struct spoolss_EndPagePrinter ep
;
1203 struct spoolss_EndDocPrinter e
;
1206 uint32_t num_written
;
1208 torture_comment(tctx
, "Testing StartDocPrinter\n");
1210 s
.in
.handle
= handle
;
1212 s
.in
.info
.info1
= &info1
;
1213 s
.out
.job_id
= &job_id
;
1214 info1
.document_name
= "TorturePrintJob";
1215 info1
.output_file
= NULL
;
1216 info1
.datatype
= "RAW";
1218 status
= dcerpc_spoolss_StartDocPrinter(p
, tctx
, &s
);
1219 torture_assert_ntstatus_ok(tctx
, status
, "dcerpc_spoolss_StartDocPrinter failed");
1220 torture_assert_werr_ok(tctx
, s
.out
.result
, "StartDocPrinter failed");
1222 for (i
=1; i
< 4; i
++) {
1223 torture_comment(tctx
, "Testing StartPagePrinter: Page[%d]\n", i
);
1225 sp
.in
.handle
= handle
;
1227 status
= dcerpc_spoolss_StartPagePrinter(p
, tctx
, &sp
);
1228 torture_assert_ntstatus_ok(tctx
, status
,
1229 "dcerpc_spoolss_StartPagePrinter failed");
1230 torture_assert_werr_ok(tctx
, sp
.out
.result
, "StartPagePrinter failed");
1232 torture_comment(tctx
, "Testing WritePrinter: Page[%d]\n", i
);
1234 w
.in
.handle
= handle
;
1235 w
.in
.data
= data_blob_string_const(talloc_asprintf(tctx
,"TortureTestPage: %d\nData\n",i
));
1236 w
.out
.num_written
= &num_written
;
1238 status
= dcerpc_spoolss_WritePrinter(p
, tctx
, &w
);
1239 torture_assert_ntstatus_ok(tctx
, status
, "dcerpc_spoolss_WritePrinter failed");
1240 torture_assert_werr_ok(tctx
, w
.out
.result
, "WritePrinter failed");
1242 torture_comment(tctx
, "Testing EndPagePrinter: Page[%d]\n", i
);
1244 ep
.in
.handle
= handle
;
1246 status
= dcerpc_spoolss_EndPagePrinter(p
, tctx
, &ep
);
1247 torture_assert_ntstatus_ok(tctx
, status
, "dcerpc_spoolss_EndPagePrinter failed");
1248 torture_assert_werr_ok(tctx
, ep
.out
.result
, "EndPagePrinter failed");
1251 torture_comment(tctx
, "Testing EndDocPrinter\n");
1253 e
.in
.handle
= handle
;
1255 status
= dcerpc_spoolss_EndDocPrinter(p
, tctx
, &e
);
1256 torture_assert_ntstatus_ok(tctx
, status
, "dcerpc_spoolss_EndDocPrinter failed");
1257 torture_assert_werr_ok(tctx
, e
.out
.result
, "EndDocPrinter failed");
1259 ret
&= test_AddJob(tctx
, p
, handle
);
1260 ret
&= test_EnumJobs(tctx
, p
, handle
);
1262 ret
&= test_SetJob(tctx
, p
, handle
, job_id
, SPOOLSS_JOB_CONTROL_DELETE
);
1267 static bool test_PausePrinter(struct torture_context
*tctx
,
1268 struct dcerpc_pipe
*p
,
1269 struct policy_handle
*handle
)
1272 struct spoolss_SetPrinter r
;
1273 struct spoolss_SetPrinterInfoCtr info_ctr
;
1274 struct spoolss_DevmodeContainer devmode_ctr
;
1275 struct sec_desc_buf secdesc_ctr
;
1278 info_ctr
.info
.info0
= NULL
;
1280 ZERO_STRUCT(devmode_ctr
);
1281 ZERO_STRUCT(secdesc_ctr
);
1283 r
.in
.handle
= handle
;
1284 r
.in
.info_ctr
= &info_ctr
;
1285 r
.in
.devmode_ctr
= &devmode_ctr
;
1286 r
.in
.secdesc_ctr
= &secdesc_ctr
;
1287 r
.in
.command
= SPOOLSS_PRINTER_CONTROL_PAUSE
;
1289 torture_comment(tctx
, "Testing SetPrinter: SPOOLSS_PRINTER_CONTROL_PAUSE\n");
1291 status
= dcerpc_spoolss_SetPrinter(p
, tctx
, &r
);
1293 torture_assert_ntstatus_ok(tctx
, status
, "SetPrinter failed");
1295 torture_assert_werr_ok(tctx
, r
.out
.result
, "SetPrinter failed");
1300 static bool test_ResumePrinter(struct torture_context
*tctx
,
1301 struct dcerpc_pipe
*p
,
1302 struct policy_handle
*handle
)
1305 struct spoolss_SetPrinter r
;
1306 struct spoolss_SetPrinterInfoCtr info_ctr
;
1307 struct spoolss_DevmodeContainer devmode_ctr
;
1308 struct sec_desc_buf secdesc_ctr
;
1311 info_ctr
.info
.info0
= NULL
;
1313 ZERO_STRUCT(devmode_ctr
);
1314 ZERO_STRUCT(secdesc_ctr
);
1316 r
.in
.handle
= handle
;
1317 r
.in
.info_ctr
= &info_ctr
;
1318 r
.in
.devmode_ctr
= &devmode_ctr
;
1319 r
.in
.secdesc_ctr
= &secdesc_ctr
;
1320 r
.in
.command
= SPOOLSS_PRINTER_CONTROL_RESUME
;
1322 torture_comment(tctx
, "Testing SetPrinter: SPOOLSS_PRINTER_CONTROL_RESUME\n");
1324 status
= dcerpc_spoolss_SetPrinter(p
, tctx
, &r
);
1326 torture_assert_ntstatus_ok(tctx
, status
, "SetPrinter failed");
1328 torture_assert_werr_ok(tctx
, r
.out
.result
, "SetPrinter failed");
1333 static bool test_GetPrinterData(struct torture_context
*tctx
,
1334 struct dcerpc_pipe
*p
,
1335 struct policy_handle
*handle
,
1336 const char *value_name
)
1339 struct spoolss_GetPrinterData r
;
1341 enum winreg_Type type
;
1342 union spoolss_PrinterData data
;
1344 r
.in
.handle
= handle
;
1345 r
.in
.value_name
= value_name
;
1347 r
.out
.needed
= &needed
;
1351 torture_comment(tctx
, "Testing GetPrinterData\n");
1353 status
= dcerpc_spoolss_GetPrinterData(p
, tctx
, &r
);
1354 torture_assert_ntstatus_ok(tctx
, status
, "GetPrinterData failed");
1356 if (W_ERROR_EQUAL(r
.out
.result
, WERR_MORE_DATA
)) {
1357 r
.in
.offered
= needed
;
1359 status
= dcerpc_spoolss_GetPrinterData(p
, tctx
, &r
);
1360 torture_assert_ntstatus_ok(tctx
, status
, "GetPrinterData failed");
1362 torture_assert_werr_ok(tctx
, r
.out
.result
, "GetPrinterData failed");
1368 static bool test_GetPrinterDataEx(struct torture_context
*tctx
,
1369 struct dcerpc_pipe
*p
,
1370 struct policy_handle
*handle
,
1371 const char *key_name
,
1372 const char *value_name
)
1375 struct spoolss_GetPrinterDataEx r
;
1376 enum winreg_Type type
;
1379 r
.in
.handle
= handle
;
1380 r
.in
.key_name
= key_name
;
1381 r
.in
.value_name
= value_name
;
1384 r
.out
.needed
= &needed
;
1385 r
.out
.buffer
= NULL
;
1387 torture_comment(tctx
, "Testing GetPrinterDataEx\n");
1389 status
= dcerpc_spoolss_GetPrinterDataEx(p
, tctx
, &r
);
1390 if (!NT_STATUS_IS_OK(status
)) {
1391 if (NT_STATUS_EQUAL(status
,NT_STATUS_NET_WRITE_FAULT
) &&
1392 p
->last_fault_code
== DCERPC_FAULT_OP_RNG_ERROR
) {
1393 torture_skip(tctx
, "GetPrinterDataEx not supported by server\n");
1395 torture_assert_ntstatus_ok(tctx
, status
, "GetPrinterDataEx failed");
1398 if (W_ERROR_EQUAL(r
.out
.result
, WERR_MORE_DATA
)) {
1399 r
.in
.offered
= needed
;
1400 r
.out
.buffer
= talloc_array(tctx
, uint8_t, needed
);
1402 status
= dcerpc_spoolss_GetPrinterDataEx(p
, tctx
, &r
);
1403 torture_assert_ntstatus_ok(tctx
, status
, "GetPrinterDataEx failed");
1405 torture_assert_werr_ok(tctx
, r
.out
.result
, "GetPrinterDataEx failed");
1411 static bool test_EnumPrinterData(struct torture_context
*tctx
, struct dcerpc_pipe
*p
,
1412 struct policy_handle
*handle
)
1415 struct spoolss_EnumPrinterData r
;
1418 r
.in
.handle
= handle
;
1419 r
.in
.enum_index
= 0;
1422 uint32_t value_size
= 0;
1423 uint32_t data_size
= 0;
1424 enum winreg_Type type
= 0;
1426 r
.in
.value_offered
= value_size
;
1427 r
.out
.value_needed
= &value_size
;
1428 r
.in
.data_offered
= data_size
;
1429 r
.out
.data_needed
= &data_size
;
1432 r
.out
.data
= talloc_zero_array(tctx
, uint8_t, 0);
1434 torture_comment(tctx
, "Testing EnumPrinterData\n");
1436 status
= dcerpc_spoolss_EnumPrinterData(p
, tctx
, &r
);
1438 torture_assert_ntstatus_ok(tctx
, status
, "EnumPrinterData failed");
1440 r
.in
.value_offered
= value_size
;
1441 r
.out
.value_name
= talloc_zero_array(tctx
, const char, value_size
);
1442 r
.in
.data_offered
= data_size
;
1443 r
.out
.data
= talloc_zero_array(tctx
, uint8_t, data_size
);
1445 status
= dcerpc_spoolss_EnumPrinterData(p
, tctx
, &r
);
1447 torture_assert_ntstatus_ok(tctx
, status
, "EnumPrinterData failed");
1449 test_GetPrinterData(tctx
, p
, handle
, r
.out
.value_name
);
1451 test_GetPrinterDataEx(tctx
,
1452 p
, handle
, "PrinterDriverData",
1457 } while (W_ERROR_IS_OK(r
.out
.result
));
1462 static bool test_EnumPrinterDataEx(struct torture_context
*tctx
,
1463 struct dcerpc_pipe
*p
,
1464 struct policy_handle
*handle
)
1467 struct spoolss_EnumPrinterDataEx r
;
1468 struct spoolss_PrinterEnumValues
*info
;
1472 r
.in
.handle
= handle
;
1473 r
.in
.key_name
= "PrinterDriverData";
1475 r
.out
.needed
= &needed
;
1476 r
.out
.count
= &count
;
1479 torture_comment(tctx
, "Testing EnumPrinterDataEx\n");
1481 status
= dcerpc_spoolss_EnumPrinterDataEx(p
, tctx
, &r
);
1482 torture_assert_ntstatus_ok(tctx
, status
, "EnumPrinterDataEx failed");
1484 r
.in
.offered
= needed
;
1486 status
= dcerpc_spoolss_EnumPrinterDataEx(p
, tctx
, &r
);
1488 torture_assert_ntstatus_ok(tctx
, status
, "EnumPrinterDataEx failed");
1494 static bool test_DeletePrinterData(struct torture_context
*tctx
,
1495 struct dcerpc_pipe
*p
,
1496 struct policy_handle
*handle
,
1497 const char *value_name
)
1500 struct spoolss_DeletePrinterData r
;
1502 r
.in
.handle
= handle
;
1503 r
.in
.value_name
= value_name
;
1505 torture_comment(tctx
, "Testing DeletePrinterData\n");
1507 status
= dcerpc_spoolss_DeletePrinterData(p
, tctx
, &r
);
1509 torture_assert_ntstatus_ok(tctx
, status
, "DeletePrinterData failed");
1514 static bool test_SetPrinterData(struct torture_context
*tctx
,
1515 struct dcerpc_pipe
*p
,
1516 struct policy_handle
*handle
)
1519 struct spoolss_SetPrinterData r
;
1520 const char *value_name
= "spottyfoot";
1522 r
.in
.handle
= handle
;
1523 r
.in
.value_name
= value_name
;
1525 r
.in
.data
.string
= "dog";
1527 torture_comment(tctx
, "Testing SetPrinterData\n");
1529 status
= dcerpc_spoolss_SetPrinterData(p
, tctx
, &r
);
1531 torture_assert_ntstatus_ok(tctx
, status
, "SetPrinterData failed");
1533 if (!test_GetPrinterData(tctx
, p
, handle
, value_name
)) {
1537 if (!test_DeletePrinterData(tctx
, p
, handle
, value_name
)) {
1544 static bool test_SecondaryClosePrinter(struct torture_context
*tctx
,
1545 struct dcerpc_pipe
*p
,
1546 struct policy_handle
*handle
)
1549 struct dcerpc_binding
*b
;
1550 struct dcerpc_pipe
*p2
;
1551 struct spoolss_ClosePrinter cp
;
1553 /* only makes sense on SMB */
1554 if (p
->conn
->transport
.transport
!= NCACN_NP
) {
1558 torture_comment(tctx
, "testing close on secondary pipe\n");
1560 status
= dcerpc_parse_binding(tctx
, p
->conn
->binding_string
, &b
);
1561 torture_assert_ntstatus_ok(tctx
, status
, "Failed to parse dcerpc binding");
1563 status
= dcerpc_secondary_connection(p
, &p2
, b
);
1564 torture_assert_ntstatus_ok(tctx
, status
, "Failed to create secondary connection");
1566 status
= dcerpc_bind_auth_none(p2
, &ndr_table_spoolss
);
1567 torture_assert_ntstatus_ok(tctx
, status
, "Failed to create bind on secondary connection");
1569 cp
.in
.handle
= handle
;
1570 cp
.out
.handle
= handle
;
1572 status
= dcerpc_spoolss_ClosePrinter(p2
, tctx
, &cp
);
1573 torture_assert_ntstatus_equal(tctx
, status
, NT_STATUS_NET_WRITE_FAULT
,
1574 "ERROR: Allowed close on secondary connection");
1576 torture_assert_int_equal(tctx
, p2
->last_fault_code
, DCERPC_FAULT_CONTEXT_MISMATCH
,
1577 "Unexpected fault code");
1584 static bool test_OpenPrinter_badname(struct torture_context
*tctx
,
1585 struct dcerpc_pipe
*p
, const char *name
)
1588 struct spoolss_OpenPrinter op
;
1589 struct spoolss_OpenPrinterEx opEx
;
1590 struct policy_handle handle
;
1593 op
.in
.printername
= name
;
1594 op
.in
.datatype
= NULL
;
1595 op
.in
.devmode_ctr
.devmode
= NULL
;
1596 op
.in
.access_mask
= 0;
1597 op
.out
.handle
= &handle
;
1599 torture_comment(tctx
, "\nTesting OpenPrinter(%s) with bad name\n", op
.in
.printername
);
1601 status
= dcerpc_spoolss_OpenPrinter(p
, tctx
, &op
);
1602 torture_assert_ntstatus_ok(tctx
, status
, "OpenPrinter failed");
1603 if (!W_ERROR_EQUAL(WERR_INVALID_PRINTER_NAME
,op
.out
.result
)) {
1604 torture_comment(tctx
, "OpenPrinter(%s) unexpected result[%s] should be WERR_INVALID_PRINTER_NAME\n",
1605 name
, win_errstr(op
.out
.result
));
1608 if (W_ERROR_IS_OK(op
.out
.result
)) {
1609 ret
&=test_ClosePrinter(tctx
, p
, &handle
);
1612 opEx
.in
.printername
= name
;
1613 opEx
.in
.datatype
= NULL
;
1614 opEx
.in
.devmode_ctr
.devmode
= NULL
;
1615 opEx
.in
.access_mask
= 0;
1617 opEx
.in
.userlevel
.level1
= NULL
;
1618 opEx
.out
.handle
= &handle
;
1620 torture_comment(tctx
, "Testing OpenPrinterEx(%s) with bad name\n", opEx
.in
.printername
);
1622 status
= dcerpc_spoolss_OpenPrinterEx(p
, tctx
, &opEx
);
1623 torture_assert_ntstatus_ok(tctx
, status
, "OpenPrinterEx failed");
1624 if (!W_ERROR_EQUAL(WERR_INVALID_PARAM
,opEx
.out
.result
)) {
1625 torture_comment(tctx
, "OpenPrinterEx(%s) unexpected result[%s] should be WERR_INVALID_PARAM\n",
1626 name
, win_errstr(opEx
.out
.result
));
1629 if (W_ERROR_IS_OK(opEx
.out
.result
)) {
1630 ret
&=test_ClosePrinter(tctx
, p
, &handle
);
1636 static bool test_OpenPrinter(struct torture_context
*tctx
,
1637 struct dcerpc_pipe
*p
,
1641 struct spoolss_OpenPrinter r
;
1642 struct policy_handle handle
;
1645 r
.in
.printername
= talloc_asprintf(tctx
, "\\\\%s\\%s", dcerpc_server_name(p
), name
);
1646 r
.in
.datatype
= NULL
;
1647 r
.in
.devmode_ctr
.devmode
= NULL
;
1648 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1649 r
.out
.handle
= &handle
;
1651 torture_comment(tctx
, "Testing OpenPrinter(%s)\n", r
.in
.printername
);
1653 status
= dcerpc_spoolss_OpenPrinter(p
, tctx
, &r
);
1655 torture_assert_ntstatus_ok(tctx
, status
, "OpenPrinter failed");
1657 torture_assert_werr_ok(tctx
, r
.out
.result
, "OpenPrinter failed");
1659 if (!test_GetPrinter(tctx
, p
, &handle
)) {
1663 if (!torture_setting_bool(tctx
, "samba3", false)) {
1664 if (!test_SecondaryClosePrinter(tctx
, p
, &handle
)) {
1669 if (!test_ClosePrinter(tctx
, p
, &handle
)) {
1676 static bool call_OpenPrinterEx(struct torture_context
*tctx
,
1677 struct dcerpc_pipe
*p
,
1678 const char *name
, struct policy_handle
*handle
)
1680 struct spoolss_OpenPrinterEx r
;
1681 struct spoolss_UserLevel1 userlevel1
;
1684 if (name
&& name
[0]) {
1685 r
.in
.printername
= talloc_asprintf(tctx
, "\\\\%s\\%s",
1686 dcerpc_server_name(p
), name
);
1688 r
.in
.printername
= talloc_asprintf(tctx
, "\\\\%s",
1689 dcerpc_server_name(p
));
1692 r
.in
.datatype
= NULL
;
1693 r
.in
.devmode_ctr
.devmode
= NULL
;
1694 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1696 r
.in
.userlevel
.level1
= &userlevel1
;
1697 r
.out
.handle
= handle
;
1699 userlevel1
.size
= 1234;
1700 userlevel1
.client
= "hello";
1701 userlevel1
.user
= "spottyfoot!";
1702 userlevel1
.build
= 1;
1703 userlevel1
.major
= 2;
1704 userlevel1
.minor
= 3;
1705 userlevel1
.processor
= 4;
1707 torture_comment(tctx
, "Testing OpenPrinterEx(%s)\n", r
.in
.printername
);
1709 status
= dcerpc_spoolss_OpenPrinterEx(p
, tctx
, &r
);
1711 torture_assert_ntstatus_ok(tctx
, status
, "OpenPrinterEx failed");
1713 torture_assert_werr_ok(tctx
, r
.out
.result
, "OpenPrinterEx failed");
1718 static bool test_OpenPrinterEx(struct torture_context
*tctx
,
1719 struct dcerpc_pipe
*p
,
1722 struct policy_handle handle
;
1725 if (!call_OpenPrinterEx(tctx
, p
, name
, &handle
)) {
1729 if (!test_GetPrinter(tctx
, p
, &handle
)) {
1733 if (!test_EnumForms(tctx
, p
, &handle
, false)) {
1737 if (!test_AddForm(tctx
, p
, &handle
, false)) {
1741 if (!test_EnumPrinterData(tctx
, p
, &handle
)) {
1745 if (!test_EnumPrinterDataEx(tctx
, p
, &handle
)) {
1749 if (!test_PausePrinter(tctx
, p
, &handle
)) {
1753 if (!test_DoPrintTest(tctx
, p
, &handle
)) {
1757 if (!test_ResumePrinter(tctx
, p
, &handle
)) {
1761 if (!test_SetPrinterData(tctx
, p
, &handle
)) {
1765 if (!torture_setting_bool(tctx
, "samba3", false)) {
1766 if (!test_SecondaryClosePrinter(tctx
, p
, &handle
)) {
1771 if (!test_ClosePrinter(tctx
, p
, &handle
)) {
1778 static bool test_EnumPrinters_old(struct torture_context
*tctx
, struct dcerpc_pipe
*p
)
1780 struct spoolss_EnumPrinters r
;
1782 uint16_t levels
[] = {1, 2, 4, 5};
1786 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
1787 union spoolss_PrinterInfo
*info
;
1792 r
.in
.flags
= PRINTER_ENUM_LOCAL
;
1794 r
.in
.level
= levels
[i
];
1797 r
.out
.needed
= &needed
;
1798 r
.out
.count
= &count
;
1801 torture_comment(tctx
, "Testing EnumPrinters level %u\n", r
.in
.level
);
1803 status
= dcerpc_spoolss_EnumPrinters(p
, tctx
, &r
);
1804 torture_assert_ntstatus_ok(tctx
, status
, "EnumPrinters failed");
1806 if (W_ERROR_EQUAL(r
.out
.result
, WERR_INSUFFICIENT_BUFFER
)) {
1807 DATA_BLOB blob
= data_blob_talloc(tctx
, NULL
, needed
);
1808 data_blob_clear(&blob
);
1809 r
.in
.buffer
= &blob
;
1810 r
.in
.offered
= needed
;
1811 status
= dcerpc_spoolss_EnumPrinters(p
, tctx
, &r
);
1814 torture_assert_ntstatus_ok(tctx
, status
, "EnumPrinters failed");
1816 torture_assert_werr_ok(tctx
, r
.out
.result
, "EnumPrinters failed");
1819 torture_comment(tctx
, "No printers returned\n");
1823 for (j
=0;j
<count
;j
++) {
1824 if (r
.in
.level
== 1) {
1825 char *unc
= talloc_strdup(tctx
, info
[j
].info1
.name
);
1828 if (unc
[0] == '\\' && unc
[1] == '\\') {
1831 slash
= strchr(unc
, '\\');
1836 if (!test_OpenPrinter(tctx
, p
, name
)) {
1839 if (!test_OpenPrinterEx(tctx
, p
, name
)) {
1850 static bool test_GetPrinterDriver2(struct dcerpc_pipe
*p
,
1851 struct policy_handle
*handle
,
1852 const char *driver_name
)
1855 struct spoolss_GetPrinterDriver2 r
;
1857 uint32_t server_major_version
;
1858 uint32_t server_minor_version
;
1860 r
.in
.handle
= handle
;
1861 r
.in
.architecture
= "W32X86";
1865 r
.in
.client_major_version
= 0;
1866 r
.in
.client_minor_version
= 0;
1867 r
.out
.needed
= &needed
;
1868 r
.out
.server_major_version
= &server_major_version
;
1869 r
.out
.server_minor_version
= &server_minor_version
;
1871 printf("Testing GetPrinterDriver2\n");
1873 status
= dcerpc_spoolss_GetPrinterDriver2(p
, tctx
, &r
);
1874 if (!NT_STATUS_IS_OK(status
)) {
1875 printf("GetPrinterDriver2 failed - %s\n", nt_errstr(status
));
1879 if (W_ERROR_EQUAL(r
.out
.result
, WERR_INSUFFICIENT_BUFFER
)) {
1880 r
.in
.offered
= needed
;
1881 status
= dcerpc_spoolss_GetPrinterDriver2(p
, tctx
, &r
);
1884 if (!NT_STATUS_IS_OK(status
)) {
1885 printf("GetPrinterDriver2 failed - %s\n",
1890 if (!W_ERROR_IS_OK(r
.out
.result
)) {
1891 printf("GetPrinterDriver2 failed - %s\n",
1892 win_errstr(r
.out
.result
));
1900 static bool test_EnumPrinterDrivers_old(struct torture_context
*tctx
,
1901 struct dcerpc_pipe
*p
)
1903 struct spoolss_EnumPrinterDrivers r
;
1905 uint16_t levels
[] = {1, 2, 3, 4, 5, 6};
1908 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
1912 union spoolss_DriverInfo
*info
;
1914 r
.in
.server
= talloc_asprintf(tctx
, "\\\\%s", dcerpc_server_name(p
));
1915 r
.in
.environment
= "Windows NT x86";
1916 r
.in
.level
= levels
[i
];
1919 r
.out
.needed
= &needed
;
1920 r
.out
.count
= &count
;
1923 torture_comment(tctx
, "Testing EnumPrinterDrivers level %u\n", r
.in
.level
);
1925 status
= dcerpc_spoolss_EnumPrinterDrivers(p
, tctx
, &r
);
1927 torture_assert_ntstatus_ok(tctx
, status
, "EnumPrinterDrivers failed");
1929 if (W_ERROR_EQUAL(r
.out
.result
, WERR_INSUFFICIENT_BUFFER
)) {
1930 DATA_BLOB blob
= data_blob_talloc(tctx
, NULL
, needed
);
1931 data_blob_clear(&blob
);
1932 r
.in
.buffer
= &blob
;
1933 r
.in
.offered
= needed
;
1934 status
= dcerpc_spoolss_EnumPrinterDrivers(p
, tctx
, &r
);
1937 torture_assert_ntstatus_ok(tctx
, status
, "EnumPrinterDrivers failed");
1939 torture_assert_werr_ok(tctx
, r
.out
.result
, "EnumPrinterDrivers failed");
1942 torture_comment(tctx
, "No printer drivers returned\n");
1950 bool torture_rpc_spoolss(struct torture_context
*torture
)
1953 struct dcerpc_pipe
*p
;
1955 struct test_spoolss_context
*ctx
;
1957 status
= torture_rpc_connection(torture
, &p
, &ndr_table_spoolss
);
1958 if (!NT_STATUS_IS_OK(status
)) {
1962 ctx
= talloc_zero(torture
, struct test_spoolss_context
);
1964 ret
&= test_OpenPrinter_server(torture
, p
, ctx
);
1966 ret
&= test_GetPrinterData(torture
, p
, &ctx
->server_handle
, "W3SvcInstalled");
1967 ret
&= test_GetPrinterData(torture
, p
, &ctx
->server_handle
, "BeepEnabled");
1968 ret
&= test_GetPrinterData(torture
, p
, &ctx
->server_handle
, "EventLog");
1969 ret
&= test_GetPrinterData(torture
, p
, &ctx
->server_handle
, "NetPopup");
1970 ret
&= test_GetPrinterData(torture
, p
, &ctx
->server_handle
, "NetPopupToComputer");
1971 ret
&= test_GetPrinterData(torture
, p
, &ctx
->server_handle
, "MajorVersion");
1972 ret
&= test_GetPrinterData(torture
, p
, &ctx
->server_handle
, "MinorVersion");
1973 ret
&= test_GetPrinterData(torture
, p
, &ctx
->server_handle
, "DefaultSpoolDirectory");
1974 ret
&= test_GetPrinterData(torture
, p
, &ctx
->server_handle
, "Architecture");
1975 ret
&= test_GetPrinterData(torture
, p
, &ctx
->server_handle
, "DsPresent");
1976 ret
&= test_GetPrinterData(torture
, p
, &ctx
->server_handle
, "OSVersion");
1977 ret
&= test_GetPrinterData(torture
, p
, &ctx
->server_handle
, "OSVersionEx");
1978 ret
&= test_GetPrinterData(torture
, p
, &ctx
->server_handle
, "DNSMachineName");
1979 ret
&= test_EnumForms(torture
, p
, &ctx
->server_handle
, true);
1980 ret
&= test_AddForm(torture
, p
, &ctx
->server_handle
, true);
1981 ret
&= test_EnumPorts(torture
, p
, ctx
);
1982 ret
&= test_GetPrinterDriverDirectory(torture
, p
, ctx
);
1983 ret
&= test_GetPrintProcessorDirectory(torture
, p
, ctx
);
1984 ret
&= test_EnumPrinterDrivers(torture
, p
, ctx
);
1985 ret
&= test_EnumMonitors(torture
, p
, ctx
);
1986 ret
&= test_EnumPrintProcessors(torture
, p
, ctx
);
1987 ret
&= test_EnumPrintProcDataTypes(torture
, p
, ctx
);
1988 ret
&= test_EnumPrinters(torture
, p
, ctx
);
1989 ret
&= test_OpenPrinter_badname(torture
, p
, "__INVALID_PRINTER__");
1990 ret
&= test_OpenPrinter_badname(torture
, p
, "\\\\__INVALID_HOST__");
1991 ret
&= test_OpenPrinter_badname(torture
, p
, "");
1992 ret
&= test_OpenPrinter_badname(torture
, p
, "\\\\\\");
1993 ret
&= test_OpenPrinter_badname(torture
, p
, "\\\\\\__INVALID_PRINTER__");
1994 ret
&= test_OpenPrinter_badname(torture
, p
, talloc_asprintf(torture
, "\\\\%s\\", dcerpc_server_name(p
)));
1995 ret
&= test_OpenPrinter_badname(torture
, p
,
1996 talloc_asprintf(torture
, "\\\\%s\\__INVALID_PRINTER__", dcerpc_server_name(p
)));
1999 ret
&= test_AddPort(torture
, p
);
2000 ret
&= test_EnumPorts_old(torture
, p
);
2001 ret
&= test_EnumPrinters_old(torture
, p
);
2002 ret
&= test_EnumPrinterDrivers_old(torture
, p
);