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];
110 r.in.servername = "";
115 torture_comment(tctx, "Testing EnumPorts level %u\n", r.in.level);
117 status = dcerpc_spoolss_EnumPorts(p, ctx, &r);
118 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPorts failed");
119 if (W_ERROR_IS_OK(r.out.result)) {
120 /* TODO: do some more checks here */
123 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
124 "EnumPorts unexpected return code");
126 blob = data_blob_talloc(ctx, NULL, r.out.needed);
127 data_blob_clear(&blob);
129 r.in.offered = r.out.needed;
131 status = dcerpc_spoolss_EnumPorts(p, ctx, &r);
132 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPorts failed");
134 torture_assert_werr_ok(tctx, r.out.result, "EnumPorts failed");
136 ctx->port_count[level] = r.out.count;
137 ctx->ports[level] = r.out.info;
140 for (i=1;i<ARRAY_SIZE(levels);i++) {
141 int level = levels[i];
142 int old_level = levels[i-1];
143 torture_assert_int_equal(tctx, ctx->port_count[level], ctx->port_count[old_level],
144 "EnumPorts invalid value");
146 /* if the array sizes are not the same we would maybe segfault in the following code */
148 for (i=0;i<ARRAY_SIZE(levels);i++) {
149 int level = levels[i];
150 for (j=0;j<ctx->port_count[level];j++) {
151 union spoolss_PortInfo *cur = &ctx->ports[level][j];
152 union spoolss_PortInfo *ref = &ctx->ports[2][j];
155 COMPARE_STRING(tctx, cur->info1, ref->info2, port_name);
158 /* level 2 is our reference, and it makes no sense to compare it to itself */
167 static bool test_GetPrinterDriverDirectory(struct torture_context *tctx,
168 struct dcerpc_pipe *p,
169 struct test_spoolss_context *ctx)
172 struct spoolss_GetPrinterDriverDirectory r;
187 .server = talloc_asprintf(ctx, "\\\\%s", dcerpc_server_name(p))
190 .server = talloc_asprintf(ctx, "\\\\%s", dcerpc_server_name(p))
195 for (i=0;i<ARRAY_SIZE(levels);i++) {
196 int level = levels[i].level;
199 r.in.server = levels[i].server;
200 r.in.environment = SPOOLSS_ARCHITECTURE_NT_X86;
205 torture_comment(tctx, "Testing GetPrinterDriverDirectory level %u\n", r.in.level);
207 status = dcerpc_spoolss_GetPrinterDriverDirectory(p, ctx, &r);
208 torture_assert_ntstatus_ok(tctx, status,
209 "dcerpc_spoolss_GetPrinterDriverDirectory failed");
210 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
211 "GetPrinterDriverDirectory unexpected return code");
213 blob = data_blob_talloc(ctx, NULL, r.out.needed);
214 data_blob_clear(&blob);
216 r.in.offered = r.out.needed;
218 status = dcerpc_spoolss_GetPrinterDriverDirectory(p, ctx, &r);
219 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_GetPrinterDriverDirectory failed");
221 torture_assert_werr_ok(tctx, r.out.result, "GetPrinterDriverDirectory failed");
227 static bool test_EnumPrinterDrivers(struct torture_context *tctx,
228 struct dcerpc_pipe *p,
229 struct test_spoolss_context *ctx)
232 struct spoolss_EnumPrinterDrivers r;
233 uint16_t levels[] = { 1, 2, 3, 4, 5, 6 };
236 for (i=0;i<ARRAY_SIZE(levels);i++) {
237 int level = levels[i];
241 r.in.environment = SPOOLSS_ARCHITECTURE_NT_X86;
246 torture_comment(tctx, "Testing EnumPrinterDrivers level %u\n", r.in.level);
248 status = dcerpc_spoolss_EnumPrinterDrivers(p, ctx, &r);
249 torture_assert_ntstatus_ok(tctx, status,
250 "dcerpc_spoolss_EnumPrinterDrivers failed");
251 if (W_ERROR_IS_OK(r.out.result)) {
252 /* TODO: do some more checks here */
255 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
256 "EnumPrinterDrivers failed");
258 blob = data_blob_talloc(ctx, NULL, r.out.needed);
259 data_blob_clear(&blob);
261 r.in.offered = r.out.needed;
263 status = dcerpc_spoolss_EnumPrinterDrivers(p, ctx, &r);
264 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrinterDrivers failed");
266 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinterDrivers failed");
268 ctx->driver_count[level] = r.out.count;
269 ctx->drivers[level] = r.out.info;
272 for (i=1;i<ARRAY_SIZE(levels);i++) {
273 int level = levels[i];
274 int old_level = levels[i-1];
275 torture_assert_int_equal(tctx, ctx->driver_count[level], ctx->driver_count[old_level],
276 "EnumPrinterDrivers invalid value");
279 for (i=0;i<ARRAY_SIZE(levels);i++) {
280 int level = levels[i];
281 for (j=0;j<ctx->driver_count[level];j++) {
282 union spoolss_DriverInfo *cur = &ctx->drivers[level][j];
283 union spoolss_DriverInfo *ref = &ctx->drivers[6][j];
286 COMPARE_STRING(tctx, cur->info1, ref->info6, driver_name);
289 COMPARE_UINT32(tctx, cur->info2, ref->info6, version);
290 COMPARE_STRING(tctx, cur->info2, ref->info6, driver_name);
291 COMPARE_STRING(tctx, cur->info2, ref->info6, architecture);
292 COMPARE_STRING(tctx, cur->info2, ref->info6, driver_path);
293 COMPARE_STRING(tctx, cur->info2, ref->info6, data_file);
294 COMPARE_STRING(tctx, cur->info2, ref->info6, config_file);
297 COMPARE_UINT32(tctx, cur->info3, ref->info6, version);
298 COMPARE_STRING(tctx, cur->info3, ref->info6, driver_name);
299 COMPARE_STRING(tctx, cur->info3, ref->info6, architecture);
300 COMPARE_STRING(tctx, cur->info3, ref->info6, driver_path);
301 COMPARE_STRING(tctx, cur->info3, ref->info6, data_file);
302 COMPARE_STRING(tctx, cur->info3, ref->info6, config_file);
303 COMPARE_STRING(tctx, cur->info3, ref->info6, help_file);
304 COMPARE_STRING_ARRAY(tctx, cur->info3, ref->info6, dependent_files);
305 COMPARE_STRING(tctx, cur->info3, ref->info6, monitor_name);
306 COMPARE_STRING(tctx, cur->info3, ref->info6, default_datatype);
309 COMPARE_UINT32(tctx, cur->info4, ref->info6, version);
310 COMPARE_STRING(tctx, cur->info4, ref->info6, driver_name);
311 COMPARE_STRING(tctx, cur->info4, ref->info6, architecture);
312 COMPARE_STRING(tctx, cur->info4, ref->info6, driver_path);
313 COMPARE_STRING(tctx, cur->info4, ref->info6, data_file);
314 COMPARE_STRING(tctx, cur->info4, ref->info6, config_file);
315 COMPARE_STRING(tctx, cur->info4, ref->info6, help_file);
316 COMPARE_STRING_ARRAY(tctx, cur->info4, ref->info6, dependent_files);
317 COMPARE_STRING(tctx, cur->info4, ref->info6, monitor_name);
318 COMPARE_STRING(tctx, cur->info4, ref->info6, default_datatype);
319 COMPARE_STRING_ARRAY(tctx, cur->info4, ref->info6, previous_names);
322 COMPARE_UINT32(tctx, cur->info5, ref->info6, version);
323 COMPARE_STRING(tctx, cur->info5, ref->info6, driver_name);
324 COMPARE_STRING(tctx, cur->info5, ref->info6, architecture);
325 COMPARE_STRING(tctx, cur->info5, ref->info6, driver_path);
326 COMPARE_STRING(tctx, cur->info5, ref->info6, data_file);
327 COMPARE_STRING(tctx, cur->info5, ref->info6, config_file);
328 /*COMPARE_UINT32(tctx, cur->info5, ref->info6, driver_attributes);*/
329 /*COMPARE_UINT32(tctx, cur->info5, ref->info6, config_version);*/
330 /*TODO: ! COMPARE_UINT32(tctx, cur->info5, ref->info6, driver_version); */
333 /* level 6 is our reference, and it makes no sense to compare it to itself */
342 static bool test_EnumMonitors(struct torture_context *tctx,
343 struct dcerpc_pipe *p,
344 struct test_spoolss_context *ctx)
347 struct spoolss_EnumMonitors r;
348 uint16_t levels[] = { 1, 2 };
351 for (i=0;i<ARRAY_SIZE(levels);i++) {
352 int level = levels[i];
355 r.in.servername = "";
360 torture_comment(tctx, "Testing EnumMonitors level %u\n", r.in.level);
362 status = dcerpc_spoolss_EnumMonitors(p, ctx, &r);
363 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumMonitors failed");
364 if (W_ERROR_IS_OK(r.out.result)) {
365 /* TODO: do some more checks here */
368 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
369 "EnumMonitors failed");
371 blob = data_blob_talloc(ctx, NULL, r.out.needed);
372 data_blob_clear(&blob);
374 r.in.offered = r.out.needed;
376 status = dcerpc_spoolss_EnumMonitors(p, ctx, &r);
377 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumMonitors failed");
379 torture_assert_werr_ok(tctx, r.out.result, "EnumMonitors failed");
381 ctx->monitor_count[level] = r.out.count;
382 ctx->monitors[level] = r.out.info;
385 for (i=1;i<ARRAY_SIZE(levels);i++) {
386 int level = levels[i];
387 int old_level = levels[i-1];
388 torture_assert_int_equal(tctx, ctx->monitor_count[level], ctx->monitor_count[old_level],
389 "EnumMonitors invalid value");
392 for (i=0;i<ARRAY_SIZE(levels);i++) {
393 int level = levels[i];
394 for (j=0;j<ctx->monitor_count[level];j++) {
395 union spoolss_MonitorInfo *cur = &ctx->monitors[level][j];
396 union spoolss_MonitorInfo *ref = &ctx->monitors[2][j];
399 COMPARE_STRING(tctx, cur->info1, ref->info2, monitor_name);
402 /* level 2 is our reference, and it makes no sense to compare it to itself */
411 static bool test_EnumPrintProcessors(struct torture_context *tctx,
412 struct dcerpc_pipe *p,
413 struct test_spoolss_context *ctx)
416 struct spoolss_EnumPrintProcessors r;
417 uint16_t levels[] = { 1 };
420 for (i=0;i<ARRAY_SIZE(levels);i++) {
421 int level = levels[i];
424 r.in.servername = "";
425 r.in.environment = "Windows NT x86";
430 torture_comment(tctx, "Testing EnumPrintProcessors level %u\n", r.in.level);
432 status = dcerpc_spoolss_EnumPrintProcessors(p, ctx, &r);
433 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrintProcessors failed");
434 if (W_ERROR_IS_OK(r.out.result)) {
435 /* TODO: do some more checks here */
438 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
439 "EnumPrintProcessors unexpected return code");
441 blob = data_blob_talloc(ctx, NULL, r.out.needed);
442 data_blob_clear(&blob);
444 r.in.offered = r.out.needed;
446 status = dcerpc_spoolss_EnumPrintProcessors(p, ctx, &r);
447 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrintProcessors failed");
449 torture_assert_werr_ok(tctx, r.out.result, "EnumPrintProcessors failed");
451 ctx->print_processor_count[level] = r.out.count;
452 ctx->print_processors[level] = r.out.info;
455 for (i=1;i<ARRAY_SIZE(levels);i++) {
456 int level = levels[i];
457 int old_level = levels[i-1];
458 torture_assert_int_equal(tctx, ctx->print_processor_count[level], ctx->print_processor_count[old_level],
459 "EnumPrintProcessors failed");
462 for (i=0;i<ARRAY_SIZE(levels);i++) {
463 int level = levels[i];
464 for (j=0;j<ctx->print_processor_count[level];j++) {
466 union spoolss_PrintProcessorInfo *cur = &ctx->print_processors[level][j];
467 union spoolss_PrintProcessorInfo *ref = &ctx->print_processors[1][j];
471 /* level 1 is our reference, and it makes no sense to compare it to itself */
480 static bool test_EnumPrinters(struct torture_context *tctx,
481 struct dcerpc_pipe *p,
482 struct test_spoolss_context *ctx)
484 struct spoolss_EnumPrinters r;
486 uint16_t levels[] = { 0, 1, 2, 4, 5 };
489 for (i=0;i<ARRAY_SIZE(levels);i++) {
490 int level = levels[i];
493 r.in.flags = PRINTER_ENUM_LOCAL;
499 torture_comment(tctx, "Testing EnumPrinters level %u\n", r.in.level);
501 status = dcerpc_spoolss_EnumPrinters(p, ctx, &r);
502 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrinters failed");
503 if (W_ERROR_IS_OK(r.out.result)) {
504 /* TODO: do some more checks here */
507 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
508 "EnumPrinters unexpected return code");
510 blob = data_blob_talloc(ctx, NULL, r.out.needed);
511 data_blob_clear(&blob);
513 r.in.offered = r.out.needed;
515 status = dcerpc_spoolss_EnumPrinters(p, ctx, &r);
516 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EnumPrinters failed");
518 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinters failed");
520 ctx->printer_count[level] = r.out.count;
521 ctx->printers[level] = r.out.info;
524 for (i=1;i<ARRAY_SIZE(levels);i++) {
525 int level = levels[i];
526 int old_level = levels[i-1];
527 torture_assert_int_equal(tctx, ctx->printer_count[level], ctx->printer_count[old_level],
528 "EnumPrinters invalid value");
531 for (i=0;i<ARRAY_SIZE(levels);i++) {
532 int level = levels[i];
533 for (j=0;j<ctx->printer_count[level];j++) {
534 union spoolss_PrinterInfo *cur = &ctx->printers[level][j];
535 union spoolss_PrinterInfo *ref = &ctx->printers[2][j];
538 COMPARE_STRING(tctx, cur->info0, ref->info2, printername);
539 COMPARE_STRING(tctx, cur->info0, ref->info2, servername);
540 COMPARE_UINT32(tctx, cur->info0, ref->info2, cjobs);
541 /*COMPARE_UINT32(tctx, cur->info0, ref->info2, total_jobs);
542 COMPARE_UINT32(tctx, cur->info0, ref->info2, total_bytes);
543 COMPARE_SPOOLSS_TIME(cur->info0, ref->info2, spoolss_Time time);
544 COMPARE_UINT32(tctx, cur->info0, ref->info2, global_counter);
545 COMPARE_UINT32(tctx, cur->info0, ref->info2, total_pages);
546 COMPARE_UINT32(tctx, cur->info0, ref->info2, version);
547 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown10);
548 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown11);
549 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown12);
550 COMPARE_UINT32(tctx, cur->info0, ref->info2, session_counter);
551 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown14);
552 COMPARE_UINT32(tctx, cur->info0, ref->info2, printer_errors);
553 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown16);
554 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown17);
555 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown18);
556 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown19);
557 COMPARE_UINT32(tctx, cur->info0, ref->info2, change_id);
558 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown21);*/
559 COMPARE_UINT32(tctx, cur->info0, ref->info2, status);
560 /*COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown23);
561 COMPARE_UINT32(tctx, cur->info0, ref->info2, c_setprinter);
562 COMPARE_UINT16(cur->info0, ref->info2, unknown25);
563 COMPARE_UINT16(cur->info0, ref->info2, unknown26);
564 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown27);
565 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown28);
566 COMPARE_UINT32(tctx, cur->info0, ref->info2, unknown29);*/
569 /*COMPARE_UINT32(tctx, cur->info1, ref->info2, flags);*/
570 /*COMPARE_STRING(tctx, cur->info1, ref->info2, name);*/
571 /*COMPARE_STRING(tctx, cur->info1, ref->info2, description);*/
572 COMPARE_STRING(tctx, cur->info1, ref->info2, comment);
575 /* level 2 is our reference, and it makes no sense to compare it to itself */
578 COMPARE_STRING(tctx, cur->info4, ref->info2, printername);
579 COMPARE_STRING(tctx, cur->info4, ref->info2, servername);
580 COMPARE_UINT32(tctx, cur->info4, ref->info2, attributes);
583 COMPARE_STRING(tctx, cur->info5, ref->info2, printername);
584 COMPARE_STRING(tctx, cur->info5, ref->info2, portname);
585 COMPARE_UINT32(tctx, cur->info5, ref->info2, attributes);
586 /*COMPARE_UINT32(tctx, cur->info5, ref->info2, device_not_selected_timeout);
587 COMPARE_UINT32(tctx, cur->info5, ref->info2, transmission_retry_timeout);*/
594 * - verify that the port of a printer was in the list returned by EnumPorts
600 static bool test_GetPrinter(struct torture_context *tctx,
601 struct dcerpc_pipe *p,
602 struct policy_handle *handle)
605 struct spoolss_GetPrinter r;
606 uint16_t levels[] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
609 for (i=0;i<ARRAY_SIZE(levels);i++) {
610 r.in.handle = handle;
611 r.in.level = levels[i];
615 torture_comment(tctx, "Testing GetPrinter level %u\n", r.in.level);
617 status = dcerpc_spoolss_GetPrinter(p, tctx, &r);
618 torture_assert_ntstatus_ok(tctx, status, "GetPrinter failed");
620 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
621 DATA_BLOB blob = data_blob_talloc(tctx, NULL, r.out.needed);
622 data_blob_clear(&blob);
624 r.in.offered = r.out.needed;
625 status = dcerpc_spoolss_GetPrinter(p, tctx, &r);
628 torture_assert_ntstatus_ok(tctx, status, "GetPrinter failed");
630 torture_assert_werr_ok(tctx, r.out.result, "GetPrinter failed");
637 static bool test_ClosePrinter(struct torture_context *tctx,
638 struct dcerpc_pipe *p,
639 struct policy_handle *handle)
642 struct spoolss_ClosePrinter r;
644 r.in.handle = handle;
645 r.out.handle = handle;
647 torture_comment(tctx, "Testing ClosePrinter\n");
649 status = dcerpc_spoolss_ClosePrinter(p, tctx, &r);
650 torture_assert_ntstatus_ok(tctx, status, "ClosePrinter failed");
655 static bool test_GetForm(struct torture_context *tctx,
656 struct dcerpc_pipe *p,
657 struct policy_handle *handle,
658 const char *form_name)
661 struct spoolss_GetForm r;
663 r.in.handle = handle;
664 r.in.form_name = form_name;
669 torture_comment(tctx, "Testing GetForm\n");
671 status = dcerpc_spoolss_GetForm(p, tctx, &r);
672 torture_assert_ntstatus_ok(tctx, status, "GetForm failed");
674 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
675 DATA_BLOB blob = data_blob_talloc(tctx, NULL, r.out.needed);
676 data_blob_clear(&blob);
678 r.in.offered = r.out.needed;
679 status = dcerpc_spoolss_GetForm(p, tctx, &r);
680 torture_assert_ntstatus_ok(tctx, status, "GetForm failed");
682 torture_assert_werr_ok(tctx, r.out.result, "GetForm failed");
684 torture_assert(tctx, r.out.info, "No form info returned");
687 torture_assert_werr_ok(tctx, r.out.result, "GetForm failed");
692 static bool test_EnumForms(struct torture_context *tctx,
693 struct dcerpc_pipe *p,
694 struct policy_handle *handle, bool print_server)
697 struct spoolss_EnumForms r;
700 r.in.handle = handle;
705 torture_comment(tctx, "Testing EnumForms\n");
707 status = dcerpc_spoolss_EnumForms(p, tctx, &r);
708 torture_assert_ntstatus_ok(tctx, status, "EnumForms failed");
710 if (print_server && W_ERROR_EQUAL(r.out.result, WERR_BADFID))
711 torture_fail(tctx, "EnumForms on the PrintServer isn't supported by test server (NT4)");
713 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
714 union spoolss_FormInfo *info;
716 DATA_BLOB blob = data_blob_talloc(tctx, NULL, r.out.needed);
717 data_blob_clear(&blob);
719 r.in.offered = r.out.needed;
721 status = dcerpc_spoolss_EnumForms(p, tctx, &r);
723 torture_assert(tctx, r.out.info, "No forms returned");
727 for (j = 0; j < r.out.count; j++) {
729 ret &= test_GetForm(tctx, p, handle, info[j].info1.form_name);
733 torture_assert_ntstatus_ok(tctx, status, "EnumForms failed");
735 torture_assert_werr_ok(tctx, r.out.result, "EnumForms failed");
740 static bool test_DeleteForm(struct torture_context *tctx,
741 struct dcerpc_pipe *p,
742 struct policy_handle *handle,
743 const char *form_name)
746 struct spoolss_DeleteForm r;
748 r.in.handle = handle;
749 r.in.form_name = form_name;
751 status = dcerpc_spoolss_DeleteForm(p, tctx, &r);
753 torture_assert_ntstatus_ok(tctx, status, "DeleteForm failed");
755 torture_assert_werr_ok(tctx, r.out.result, "DeleteForm failed");
760 static bool test_AddForm(struct torture_context *tctx,
761 struct dcerpc_pipe *p,
762 struct policy_handle *handle, bool print_server)
764 struct spoolss_AddForm r;
765 struct spoolss_AddFormInfo1 addform;
766 const char *form_name = "testform3";
770 r.in.handle = handle;
772 r.in.info.info1 = &addform;
773 addform.flags = SPOOLSS_FORM_USER;
774 addform.form_name = form_name;
775 addform.size.width = 50;
776 addform.size.height = 25;
777 addform.area.left = 5;
778 addform.area.top = 10;
779 addform.area.right = 45;
780 addform.area.bottom = 15;
782 status = dcerpc_spoolss_AddForm(p, tctx, &r);
784 torture_assert_ntstatus_ok(tctx, status, "AddForm failed");
786 torture_assert_werr_ok(tctx, r.out.result, "AddForm failed");
788 if (!print_server) ret &= test_GetForm(tctx, p, handle, form_name);
791 struct spoolss_SetForm sf;
792 struct spoolss_AddFormInfo1 setform;
794 sf.in.handle = handle;
795 sf.in.form_name = form_name;
797 sf.in.info.info1= &setform;
798 setform.flags = addform.flags;
799 setform.form_name = addform.form_name;
800 setform.size = addform.size;
801 setform.area = addform.area;
803 setform.size.width = 1234;
805 status = dcerpc_spoolss_SetForm(p, tctx, &sf);
807 torture_assert_ntstatus_ok(tctx, status, "SetForm failed");
809 torture_assert_werr_ok(tctx, r.out.result, "SetForm failed");
812 if (!print_server) ret &= test_GetForm(tctx, p, handle, form_name);
814 if (!test_DeleteForm(tctx, p, handle, form_name)) {
821 static bool test_EnumPorts_old(struct torture_context *tctx,
822 struct dcerpc_pipe *p)
825 struct spoolss_EnumPorts r;
827 r.in.servername = talloc_asprintf(tctx, "\\\\%s",
828 dcerpc_server_name(p));
833 torture_comment(tctx, "Testing EnumPorts\n");
835 status = dcerpc_spoolss_EnumPorts(p, tctx, &r);
837 torture_assert_ntstatus_ok(tctx, status, "EnumPorts failed");
839 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
840 DATA_BLOB blob = data_blob_talloc(tctx, NULL, r.out.needed);
841 data_blob_clear(&blob);
843 r.in.offered = r.out.needed;
845 status = dcerpc_spoolss_EnumPorts(p, tctx, &r);
846 torture_assert_ntstatus_ok(tctx, status, "EnumPorts failed");
848 torture_assert(tctx, r.out.info, "No ports returned");
854 static bool test_AddPort(struct torture_context *tctx,
855 struct dcerpc_pipe *p)
858 struct spoolss_AddPort r;
860 r.in.server_name = talloc_asprintf(tctx, "\\\\%s",
861 dcerpc_server_name(p));
863 r.in.monitor_name = "foo";
865 torture_comment(tctx, "Testing AddPort\n");
867 status = dcerpc_spoolss_AddPort(p, tctx, &r);
869 torture_assert_ntstatus_ok(tctx, status, "AddPort failed");
871 /* win2k3 returns WERR_NOT_SUPPORTED */
875 if (!W_ERROR_IS_OK(r.out.result)) {
876 printf("AddPort failed - %s\n", win_errstr(r.out.result));
885 static bool test_GetJob(struct torture_context *tctx,
886 struct dcerpc_pipe *p,
887 struct policy_handle *handle, uint32_t job_id)
890 struct spoolss_GetJob r;
893 r.in.handle = handle;
894 r.in.job_id = job_id;
898 r.out.needed = &needed;
900 torture_comment(tctx, "Testing GetJob\n");
902 status = dcerpc_spoolss_GetJob(p, tctx, &r);
903 torture_assert_ntstatus_ok(tctx, status, "GetJob failed");
905 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
906 DATA_BLOB blob = data_blob_talloc(tctx, NULL, needed);
907 data_blob_clear(&blob);
909 r.in.offered = needed;
911 status = dcerpc_spoolss_GetJob(p, tctx, &r);
913 torture_assert(tctx, r.out.info, "No job info returned");
919 static bool test_SetJob(struct torture_context *tctx,
920 struct dcerpc_pipe *p,
921 struct policy_handle *handle, uint32_t job_id,
922 enum spoolss_JobControl command)
925 struct spoolss_SetJob r;
927 r.in.handle = handle;
928 r.in.job_id = job_id;
930 r.in.command = command;
932 torture_comment(tctx, "Testing SetJob\n");
934 status = dcerpc_spoolss_SetJob(p, tctx, &r);
935 torture_assert_ntstatus_ok(tctx, status, "SetJob failed");
936 torture_assert_werr_ok(tctx, r.out.result, "SetJob failed");
941 static bool test_EnumJobs(struct torture_context *tctx,
942 struct dcerpc_pipe *p,
943 struct policy_handle *handle)
946 struct spoolss_EnumJobs r;
948 r.in.handle = handle;
950 r.in.numjobs = 0xffffffff;
955 torture_comment(tctx, "Testing EnumJobs\n");
957 status = dcerpc_spoolss_EnumJobs(p, tctx, &r);
959 torture_assert_ntstatus_ok(tctx, status, "EnumJobs failed");
961 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
962 union spoolss_JobInfo *info;
964 DATA_BLOB blob = data_blob_talloc(tctx, NULL, r.out.needed);
965 data_blob_clear(&blob);
967 r.in.offered = r.out.needed;
969 status = dcerpc_spoolss_EnumJobs(p, tctx, &r);
971 torture_assert(tctx, r.out.info, "No jobs returned");
975 for (j = 0; j < r.out.count; j++) {
976 test_GetJob(tctx, p, handle, info[j].info1.job_id);
977 test_SetJob(tctx, p, handle, info[j].info1.job_id, SPOOLSS_JOB_CONTROL_PAUSE);
978 test_SetJob(tctx, p, handle, info[j].info1.job_id, SPOOLSS_JOB_CONTROL_RESUME);
982 torture_assert_werr_ok(tctx, r.out.result, "EnumJobs failed");
988 static bool test_DoPrintTest(struct torture_context *tctx,
989 struct dcerpc_pipe *p,
990 struct policy_handle *handle)
994 struct spoolss_StartDocPrinter s;
995 struct spoolss_DocumentInfo1 info1;
996 struct spoolss_StartPagePrinter sp;
997 struct spoolss_WritePrinter w;
998 struct spoolss_EndPagePrinter ep;
999 struct spoolss_EndDocPrinter e;
1003 torture_comment(tctx, "Testing StartDocPrinter\n");
1005 s.in.handle = handle;
1007 s.in.info.info1 = &info1;
1008 info1.document_name = "TorturePrintJob";
1009 info1.output_file = NULL;
1010 info1.datatype = "RAW";
1012 status = dcerpc_spoolss_StartDocPrinter(p, tctx, &s);
1013 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_StartDocPrinter failed");
1014 torture_assert_werr_ok(tctx, s.out.result, "StartDocPrinter failed");
1016 job_id = s.out.job_id;
1018 for (i=1; i < 4; i++) {
1019 torture_comment(tctx, "Testing StartPagePrinter: Page[%d]\n", i);
1021 sp.in.handle = handle;
1023 status = dcerpc_spoolss_StartPagePrinter(p, tctx, &sp);
1024 torture_assert_ntstatus_ok(tctx, status,
1025 "dcerpc_spoolss_StartPagePrinter failed");
1026 torture_assert_werr_ok(tctx, sp.out.result, "StartPagePrinter failed");
1028 torture_comment(tctx, "Testing WritePrinter: Page[%d]\n", i);
1030 w.in.handle = handle;
1031 w.in.data = data_blob_string_const(talloc_asprintf(tctx,"TortureTestPage: %d\nData\n",i));
1033 status = dcerpc_spoolss_WritePrinter(p, tctx, &w);
1034 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_WritePrinter failed");
1035 torture_assert_werr_ok(tctx, w.out.result, "WritePrinter failed");
1037 torture_comment(tctx, "Testing EndPagePrinter: Page[%d]\n", i);
1039 ep.in.handle = handle;
1041 status = dcerpc_spoolss_EndPagePrinter(p, tctx, &ep);
1042 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EndPagePrinter failed");
1043 torture_assert_werr_ok(tctx, ep.out.result, "EndPagePrinter failed");
1046 torture_comment(tctx, "Testing EndDocPrinter\n");
1048 e.in.handle = handle;
1050 status = dcerpc_spoolss_EndDocPrinter(p, tctx, &e);
1051 torture_assert_ntstatus_ok(tctx, status, "dcerpc_spoolss_EndDocPrinter failed");
1052 torture_assert_werr_ok(tctx, e.out.result, "EndDocPrinter failed");
1054 ret &= test_EnumJobs(tctx, p, handle);
1056 ret &= test_SetJob(tctx, p, handle, job_id, SPOOLSS_JOB_CONTROL_DELETE);
1061 static bool test_PausePrinter(struct torture_context *tctx,
1062 struct dcerpc_pipe *p,
1063 struct policy_handle *handle)
1066 struct spoolss_SetPrinter r;
1068 r.in.handle = handle;
1070 r.in.info.info1 = NULL;
1071 r.in.devmode_ctr.devmode= NULL;
1072 r.in.secdesc_ctr.sd = NULL;
1073 r.in.command = SPOOLSS_PRINTER_CONTROL_PAUSE;
1075 torture_comment(tctx, "Testing SetPrinter: SPOOLSS_PRINTER_CONTROL_PAUSE\n");
1077 status = dcerpc_spoolss_SetPrinter(p, tctx, &r);
1079 torture_assert_ntstatus_ok(tctx, status, "SetPrinter failed");
1081 torture_assert_werr_ok(tctx, r.out.result, "SetPrinter failed");
1086 static bool test_ResumePrinter(struct torture_context *tctx,
1087 struct dcerpc_pipe *p,
1088 struct policy_handle *handle)
1091 struct spoolss_SetPrinter r;
1093 r.in.handle = handle;
1095 r.in.info.info1 = NULL;
1096 r.in.devmode_ctr.devmode= NULL;
1097 r.in.secdesc_ctr.sd = NULL;
1098 r.in.command = SPOOLSS_PRINTER_CONTROL_RESUME;
1100 torture_comment(tctx, "Testing SetPrinter: SPOOLSS_PRINTER_CONTROL_RESUME\n");
1102 status = dcerpc_spoolss_SetPrinter(p, tctx, &r);
1104 torture_assert_ntstatus_ok(tctx, status, "SetPrinter failed");
1106 torture_assert_werr_ok(tctx, r.out.result, "SetPrinter failed");
1111 static bool test_GetPrinterData(struct torture_context *tctx,
1112 struct dcerpc_pipe *p,
1113 struct policy_handle *handle,
1114 const char *value_name)
1117 struct spoolss_GetPrinterData r;
1119 r.in.handle = handle;
1120 r.in.value_name = value_name;
1123 torture_comment(tctx, "Testing GetPrinterData\n");
1125 status = dcerpc_spoolss_GetPrinterData(p, tctx, &r);
1126 torture_assert_ntstatus_ok(tctx, status, "GetPrinterData failed");
1128 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
1129 r.in.offered = r.out.needed;
1131 status = dcerpc_spoolss_GetPrinterData(p, tctx, &r);
1132 torture_assert_ntstatus_ok(tctx, status, "GetPrinterData failed");
1134 torture_assert_werr_ok(tctx, r.out.result, "GetPrinterData failed");
1140 static bool test_GetPrinterDataEx(struct torture_context *tctx,
1141 struct dcerpc_pipe *p,
1142 struct policy_handle *handle,
1143 const char *key_name,
1144 const char *value_name)
1147 struct spoolss_GetPrinterDataEx r;
1149 r.in.handle = handle;
1150 r.in.key_name = key_name;
1151 r.in.value_name = value_name;
1154 torture_comment(tctx, "Testing GetPrinterDataEx\n");
1156 status = dcerpc_spoolss_GetPrinterDataEx(p, tctx, &r);
1157 if (!NT_STATUS_IS_OK(status)) {
1158 if (NT_STATUS_EQUAL(status,NT_STATUS_NET_WRITE_FAULT) &&
1159 p->last_fault_code == DCERPC_FAULT_OP_RNG_ERROR) {
1160 torture_skip(tctx, "GetPrinterDataEx not supported by server\n");
1162 torture_assert_ntstatus_ok(tctx, status, "GetPrinterDataEx failed");
1165 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
1166 r.in.offered = r.out.needed;
1168 status = dcerpc_spoolss_GetPrinterDataEx(p, tctx, &r);
1169 torture_assert_ntstatus_ok(tctx, status, "GetPrinterDataEx failed");
1171 torture_assert_werr_ok(tctx, r.out.result, "GetPrinterDataEx failed");
1177 static bool test_EnumPrinterData(struct torture_context *tctx, struct dcerpc_pipe *p,
1178 struct policy_handle *handle)
1181 struct spoolss_EnumPrinterData r;
1184 r.in.handle = handle;
1185 r.in.enum_index = 0;
1188 uint32_t value_size = 0;
1189 uint32_t data_size = 0;
1190 uint32_t printerdata_type = 0;
1191 DATA_BLOB data = data_blob(NULL,0);
1193 r.in.value_offered = value_size;
1194 r.out.value_needed = &value_size;
1195 r.in.data_offered = data_size;
1196 r.out.data_needed = &data_size;
1198 r.out.printerdata_type = &printerdata_type;
1199 r.out.buffer = &data;
1201 torture_comment(tctx, "Testing EnumPrinterData\n");
1203 status = dcerpc_spoolss_EnumPrinterData(p, tctx, &r);
1205 torture_assert_ntstatus_ok(tctx, status, "EnumPrinterData failed");
1207 r.in.value_offered = value_size;
1208 r.in.data_offered = data_size;
1210 status = dcerpc_spoolss_EnumPrinterData(p, tctx, &r);
1212 torture_assert_ntstatus_ok(tctx, status, "EnumPrinterData failed");
1214 test_GetPrinterData(tctx, p, handle, r.out.value_name);
1216 test_GetPrinterDataEx(tctx,
1217 p, handle, "PrinterDriverData",
1222 } while (W_ERROR_IS_OK(r.out.result));
1227 static bool test_EnumPrinterDataEx(struct torture_context *tctx,
1228 struct dcerpc_pipe *p,
1229 struct policy_handle *handle)
1232 struct spoolss_EnumPrinterDataEx r;
1234 r.in.handle = handle;
1235 r.in.key_name = "PrinterDriverData";
1238 torture_comment(tctx, "Testing EnumPrinterDataEx\n");
1240 status = dcerpc_spoolss_EnumPrinterDataEx(p, tctx, &r);
1241 torture_assert_ntstatus_ok(tctx, status, "EnumPrinterDataEx failed");
1243 r.in.offered = r.out.needed;
1245 status = dcerpc_spoolss_EnumPrinterDataEx(p, tctx, &r);
1247 torture_assert_ntstatus_ok(tctx, status, "EnumPrinterDataEx failed");
1253 static bool test_DeletePrinterData(struct torture_context *tctx,
1254 struct dcerpc_pipe *p,
1255 struct policy_handle *handle,
1256 const char *value_name)
1259 struct spoolss_DeletePrinterData r;
1261 r.in.handle = handle;
1262 r.in.value_name = value_name;
1264 torture_comment(tctx, "Testing DeletePrinterData\n");
1266 status = dcerpc_spoolss_DeletePrinterData(p, tctx, &r);
1268 torture_assert_ntstatus_ok(tctx, status, "DeletePrinterData failed");
1273 static bool test_SetPrinterData(struct torture_context *tctx,
1274 struct dcerpc_pipe *p,
1275 struct policy_handle *handle)
1278 struct spoolss_SetPrinterData r;
1279 const char *value_name = "spottyfoot";
1281 r.in.handle = handle;
1282 r.in.value_name = value_name;
1283 r.in.type = SPOOLSS_PRINTER_DATA_TYPE_STRING;
1284 r.in.data.string = "dog";
1286 torture_comment(tctx, "Testing SetPrinterData\n");
1288 status = dcerpc_spoolss_SetPrinterData(p, tctx, &r);
1290 torture_assert_ntstatus_ok(tctx, status, "SetPrinterData failed");
1292 if (!test_GetPrinterData(tctx, p, handle, value_name)) {
1296 if (!test_DeletePrinterData(tctx, p, handle, value_name)) {
1303 static bool test_SecondaryClosePrinter(struct torture_context *tctx,
1304 struct dcerpc_pipe *p,
1305 struct policy_handle *handle)
1308 struct dcerpc_binding *b;
1309 struct dcerpc_pipe *p2;
1310 struct spoolss_ClosePrinter cp;
1312 /* only makes sense on SMB */
1313 if (p->conn->transport.transport != NCACN_NP) {
1317 torture_comment(tctx, "testing close on secondary pipe\n");
1319 status = dcerpc_parse_binding(tctx, p->conn->binding_string, &b);
1320 torture_assert_ntstatus_ok(tctx, status, "Failed to parse dcerpc binding");
1322 status = dcerpc_secondary_connection(p, &p2, b);
1323 torture_assert_ntstatus_ok(tctx, status, "Failed to create secondary connection");
1325 status = dcerpc_bind_auth_none(p2, &ndr_table_spoolss);
1326 torture_assert_ntstatus_ok(tctx, status, "Failed to create bind on secondary connection");
1328 cp.in.handle = handle;
1329 cp.out.handle = handle;
1331 status = dcerpc_spoolss_ClosePrinter(p2, tctx, &cp);
1332 torture_assert_ntstatus_equal(tctx, status, NT_STATUS_NET_WRITE_FAULT,
1333 "ERROR: Allowed close on secondary connection");
1335 torture_assert_int_equal(tctx, p2->last_fault_code, DCERPC_FAULT_CONTEXT_MISMATCH,
1336 "Unexpected fault code");
1343 static bool test_OpenPrinter_badname(struct torture_context *tctx,
1344 struct dcerpc_pipe *p, const char *name)
1347 struct spoolss_OpenPrinter op;
1348 struct spoolss_OpenPrinterEx opEx;
1349 struct policy_handle handle;
1352 op.in.printername = name;
1353 op.in.datatype = NULL;
1354 op.in.devmode_ctr.devmode= NULL;
1355 op.in.access_mask = 0;
1356 op.out.handle = &handle;
1358 torture_comment(tctx, "\nTesting OpenPrinter(%s) with bad name\n", op.in.printername);
1360 status = dcerpc_spoolss_OpenPrinter(p, tctx, &op);
1361 torture_assert_ntstatus_ok(tctx, status, "OpenPrinter failed");
1362 if (!W_ERROR_EQUAL(WERR_INVALID_PRINTER_NAME,op.out.result)) {
1363 torture_comment(tctx, "OpenPrinter(%s) unexpected result[%s] should be WERR_INVALID_PRINTER_NAME\n",
1364 name, win_errstr(op.out.result));
1367 if (W_ERROR_IS_OK(op.out.result)) {
1368 ret &=test_ClosePrinter(tctx, p, &handle);
1371 opEx.in.printername = name;
1372 opEx.in.datatype = NULL;
1373 opEx.in.devmode_ctr.devmode = NULL;
1374 opEx.in.access_mask = 0;
1376 opEx.in.userlevel.level1 = NULL;
1377 opEx.out.handle = &handle;
1379 torture_comment(tctx, "Testing OpenPrinterEx(%s) with bad name\n", opEx.in.printername);
1381 status = dcerpc_spoolss_OpenPrinterEx(p, tctx, &opEx);
1382 torture_assert_ntstatus_ok(tctx, status, "OpenPrinterEx failed");
1383 if (!W_ERROR_EQUAL(WERR_INVALID_PARAM,opEx.out.result)) {
1384 torture_comment(tctx, "OpenPrinterEx(%s) unexpected result[%s] should be WERR_INVALID_PARAM\n",
1385 name, win_errstr(opEx.out.result));
1388 if (W_ERROR_IS_OK(opEx.out.result)) {
1389 ret &=test_ClosePrinter(tctx, p, &handle);
1395 static bool test_OpenPrinter(struct torture_context *tctx,
1396 struct dcerpc_pipe *p,
1400 struct spoolss_OpenPrinter r;
1401 struct policy_handle handle;
1404 r.in.printername = talloc_asprintf(tctx, "\\\\%s\\%s", dcerpc_server_name(p), name);
1405 r.in.datatype = NULL;
1406 r.in.devmode_ctr.devmode= NULL;
1407 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1408 r.out.handle = &handle;
1410 torture_comment(tctx, "Testing OpenPrinter(%s)\n", r.in.printername);
1412 status = dcerpc_spoolss_OpenPrinter(p, tctx, &r);
1414 torture_assert_ntstatus_ok(tctx, status, "OpenPrinter failed");
1416 torture_assert_werr_ok(tctx, r.out.result, "OpenPrinter failed");
1418 if (!test_GetPrinter(tctx, p, &handle)) {
1422 if (!test_SecondaryClosePrinter(tctx, p, &handle)) {
1426 if (!test_ClosePrinter(tctx, p, &handle)) {
1433 static bool call_OpenPrinterEx(struct torture_context *tctx,
1434 struct dcerpc_pipe *p,
1435 const char *name, struct policy_handle *handle)
1437 struct spoolss_OpenPrinterEx r;
1438 struct spoolss_UserLevel1 userlevel1;
1441 if (name && name[0]) {
1442 r.in.printername = talloc_asprintf(tctx, "\\\\%s\\%s",
1443 dcerpc_server_name(p), name);
1445 r.in.printername = talloc_asprintf(tctx, "\\\\%s",
1446 dcerpc_server_name(p));
1449 r.in.datatype = NULL;
1450 r.in.devmode_ctr.devmode= NULL;
1451 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1453 r.in.userlevel.level1 = &userlevel1;
1454 r.out.handle = handle;
1456 userlevel1.size = 1234;
1457 userlevel1.client = "hello";
1458 userlevel1.user = "spottyfoot!";
1459 userlevel1.build = 1;
1460 userlevel1.major = 2;
1461 userlevel1.minor = 3;
1462 userlevel1.processor = 4;
1464 torture_comment(tctx, "Testing OpenPrinterEx(%s)\n", r.in.printername);
1466 status = dcerpc_spoolss_OpenPrinterEx(p, tctx, &r);
1468 torture_assert_ntstatus_ok(tctx, status, "OpenPrinterEx failed");
1470 torture_assert_werr_ok(tctx, r.out.result, "OpenPrinterEx failed");
1475 static bool test_OpenPrinterEx(struct torture_context *tctx,
1476 struct dcerpc_pipe *p,
1479 struct policy_handle handle;
1482 if (!call_OpenPrinterEx(tctx, p, name, &handle)) {
1486 if (!test_GetPrinter(tctx, p, &handle)) {
1490 if (!test_EnumForms(tctx, p, &handle, false)) {
1494 if (!test_AddForm(tctx, p, &handle, false)) {
1498 if (!test_EnumPrinterData(tctx, p, &handle)) {
1502 if (!test_EnumPrinterDataEx(tctx, p, &handle)) {
1506 if (!test_PausePrinter(tctx, p, &handle)) {
1510 if (!test_DoPrintTest(tctx, p, &handle)) {
1514 if (!test_ResumePrinter(tctx, p, &handle)) {
1518 if (!test_SetPrinterData(tctx, p, &handle)) {
1522 if (!test_SecondaryClosePrinter(tctx, p, &handle)) {
1526 if (!test_ClosePrinter(tctx, p, &handle)) {
1533 static bool test_EnumPrinters_old(struct torture_context *tctx, struct dcerpc_pipe *p)
1535 struct spoolss_EnumPrinters r;
1537 uint16_t levels[] = {1, 2, 4, 5};
1541 for (i=0;i<ARRAY_SIZE(levels);i++) {
1542 union spoolss_PrinterInfo *info;
1545 r.in.flags = PRINTER_ENUM_LOCAL;
1547 r.in.level = levels[i];
1551 torture_comment(tctx, "Testing EnumPrinters level %u\n", r.in.level);
1553 status = dcerpc_spoolss_EnumPrinters(p, tctx, &r);
1554 torture_assert_ntstatus_ok(tctx, status, "EnumPrinters failed");
1556 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
1557 DATA_BLOB blob = data_blob_talloc(tctx, NULL, r.out.needed);
1558 data_blob_clear(&blob);
1559 r.in.buffer = &blob;
1560 r.in.offered = r.out.needed;
1561 status = dcerpc_spoolss_EnumPrinters(p, tctx, &r);
1564 torture_assert_ntstatus_ok(tctx, status, "EnumPrinters failed");
1566 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinters failed");
1569 torture_comment(tctx, "No printers returned\n");
1575 for (j=0;j<r.out.count;j++) {
1576 if (r.in.level == 1) {
1577 /* the names appear to be comma-separated name lists? */
1578 char *name = talloc_strdup(tctx, info[j].info1.name);
1579 char *comma = strchr(name, ',');
1580 if (comma) *comma = 0;
1581 if (!test_OpenPrinter(tctx, p, name)) {
1584 if (!test_OpenPrinterEx(tctx, p, name)) {
1595 static bool test_GetPrinterDriver2(struct dcerpc_pipe *p,
1596 struct policy_handle *handle,
1597 const char *driver_name)
1600 struct spoolss_GetPrinterDriver2 r;
1602 r.in.handle = handle;
1603 r.in.architecture = "W32X86";
1607 r.in.client_major_version = 0;
1608 r.in.client_minor_version = 0;
1610 printf("Testing GetPrinterDriver2\n");
1612 status = dcerpc_spoolss_GetPrinterDriver2(p, tctx, &r);
1613 if (!NT_STATUS_IS_OK(status)) {
1614 printf("GetPrinterDriver2 failed - %s\n", nt_errstr(status));
1618 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
1619 r.in.offered = r.out.needed;
1620 status = dcerpc_spoolss_GetPrinterDriver2(p, tctx, &r);
1623 if (!NT_STATUS_IS_OK(status)) {
1624 printf("GetPrinterDriver2 failed - %s\n",
1629 if (!W_ERROR_IS_OK(r.out.result)) {
1630 printf("GetPrinterDriver2 failed - %s\n",
1631 win_errstr(r.out.result));
1639 static bool test_EnumPrinterDrivers_old(struct torture_context *tctx,
1640 struct dcerpc_pipe *p)
1642 struct spoolss_EnumPrinterDrivers r;
1644 uint16_t levels[] = {1, 2, 3, 4, 5, 6};
1647 for (i=0;i<ARRAY_SIZE(levels);i++) {
1649 r.in.server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
1650 r.in.environment = "Windows NT x86";
1651 r.in.level = levels[i];
1655 torture_comment(tctx, "Testing EnumPrinterDrivers level %u\n", r.in.level);
1657 status = dcerpc_spoolss_EnumPrinterDrivers(p, tctx, &r);
1659 torture_assert_ntstatus_ok(tctx, status, "EnumPrinterDrivers failed");
1661 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
1662 DATA_BLOB blob = data_blob_talloc(tctx, NULL, r.out.needed);
1663 data_blob_clear(&blob);
1664 r.in.buffer = &blob;
1665 r.in.offered = r.out.needed;
1666 status = dcerpc_spoolss_EnumPrinterDrivers(p, tctx, &r);
1669 torture_assert_ntstatus_ok(tctx, status, "EnumPrinterDrivers failed");
1671 torture_assert_werr_ok(tctx, r.out.result, "EnumPrinterDrivers failed");
1674 torture_comment(tctx, "No printer drivers returned\n");
1682 /** Test that makes sure that calling ReplyOpenPrinter()
1683 * on Samba 4 will cause an irpc broadcast call.
1685 static bool test_ReplyOpenPrinter(struct torture_context *tctx,
1686 struct dcerpc_pipe *pipe)
1688 struct spoolss_ReplyOpenPrinter r;
1689 struct spoolss_ReplyClosePrinter s;
1690 struct policy_handle h;
1692 r.in.server_name = "earth";
1693 r.in.printer_local = 2;
1694 r.in.type = REG_DWORD;
1699 torture_assert_ntstatus_ok(tctx,
1700 dcerpc_spoolss_ReplyOpenPrinter(pipe, tctx, &r),
1701 "spoolss_ReplyOpenPrinter call failed");
1703 torture_assert_werr_ok(tctx, r.out.result, "error return code");
1708 torture_assert_ntstatus_ok(tctx,
1709 dcerpc_spoolss_ReplyClosePrinter(pipe, tctx, &s),
1710 "spoolss_ReplyClosePrinter call failed");
1712 torture_assert_werr_ok(tctx, r.out.result, "error return code");
1717 bool torture_rpc_spoolss(struct torture_context *torture)
1720 struct dcerpc_pipe *p;
1722 struct test_spoolss_context *ctx;
1724 status = torture_rpc_connection(torture, &p, &ndr_table_spoolss);
1725 if (!NT_STATUS_IS_OK(status)) {
1729 ctx = talloc_zero(torture, struct test_spoolss_context);
1731 ret &= test_OpenPrinter_server(torture, p, ctx);
1733 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "W3SvcInstalled");
1734 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "BeepEnabled");
1735 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "EventLog");
1736 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "NetPopup");
1737 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "NetPopupToComputer");
1738 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "MajorVersion");
1739 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "MinorVersion");
1740 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "DefaultSpoolDirectory");
1741 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "Architecture");
1742 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "DsPresent");
1743 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "OSVersion");
1744 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "OSVersionEx");
1745 ret &= test_GetPrinterData(torture, p, &ctx->server_handle, "DNSMachineName");
1746 ret &= test_EnumForms(torture, p, &ctx->server_handle, true);
1747 ret &= test_AddForm(torture, p, &ctx->server_handle, true);
1748 ret &= test_EnumPorts(torture, p, ctx);
1749 ret &= test_GetPrinterDriverDirectory(torture, p, ctx);
1750 ret &= test_EnumPrinterDrivers(torture, p, ctx);
1751 ret &= test_EnumMonitors(torture, p, ctx);
1752 ret &= test_EnumPrintProcessors(torture, p, ctx);
1753 ret &= test_EnumPrinters(torture, p, ctx);
1754 ret &= test_OpenPrinter_badname(torture, p, "__INVALID_PRINTER__");
1755 ret &= test_OpenPrinter_badname(torture, p, "\\\\__INVALID_HOST__");
1756 ret &= test_OpenPrinter_badname(torture, p, "");
1757 ret &= test_OpenPrinter_badname(torture, p, "\\\\\\");
1758 ret &= test_OpenPrinter_badname(torture, p, "\\\\\\__INVALID_PRINTER__");
1759 ret &= test_OpenPrinter_badname(torture, p, talloc_asprintf(torture, "\\\\%s\\", dcerpc_server_name(p)));
1760 ret &= test_OpenPrinter_badname(torture, p,
1761 talloc_asprintf(torture, "\\\\%s\\__INVALID_PRINTER__", dcerpc_server_name(p)));
1764 ret &= test_AddPort(torture, p);
1765 ret &= test_EnumPorts_old(torture, p);
1766 ret &= test_EnumPrinters_old(torture, p);
1767 ret &= test_EnumPrinterDrivers_old(torture, p);
1768 ret &= test_ReplyOpenPrinter(torture, p);