2 Unix SMB/CIFS implementation.
3 test suite for spoolss rpc operations
5 Copyright (C) Tim Potter 2003
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "librpc/gen_ndr/ndr_spoolss.h"
25 static BOOL test_GetPrinter(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
26 struct policy_handle *handle)
29 struct spoolss_GetPrinter r;
30 uint16_t levels[] = {1, 2, 3, 4, 5, 6, 7};
34 for (i=0;i<ARRAY_SIZE(levels);i++) {
35 uint32_t buf_size = 0;
37 r.in.level = levels[i];
39 r.in.buf_size = &buf_size;
40 r.out.buf_size = &buf_size;
42 printf("Testing GetPrinter level %u\n", r.in.level);
44 status = dcerpc_spoolss_GetPrinter(p, mem_ctx, &r);
45 if (!NT_STATUS_IS_OK(status)) {
46 printf("GetPrinter failed - %s\n", nt_errstr(status));
51 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
52 DATA_BLOB blob = data_blob_talloc(mem_ctx, NULL, buf_size);
53 data_blob_clear(&blob);
55 status = dcerpc_spoolss_GetPrinter(p, mem_ctx, &r);
58 if (!NT_STATUS_IS_OK(status) ||
59 !W_ERROR_IS_OK(r.out.result)) {
60 printf("GetPrinter failed - %s/%s\n",
61 nt_errstr(status), win_errstr(r.out.result));
71 static BOOL test_ClosePrinter(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
72 struct policy_handle *handle)
75 struct spoolss_ClosePrinter r;
78 r.out.handle = handle;
80 printf("Testing ClosePrinter\n");
82 status = dcerpc_spoolss_ClosePrinter(p, mem_ctx, &r);
83 if (!NT_STATUS_IS_OK(status)) {
84 printf("ClosePrinter failed - %s\n", nt_errstr(status));
91 static BOOL test_GetForm(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
92 struct policy_handle *handle,
96 struct spoolss_GetForm r;
100 r.in.formname = formname;
104 r.in.buf_size = r.out.buf_size = &buf_size;
106 printf("Testing GetForm\n");
108 status = dcerpc_spoolss_GetForm(p, mem_ctx, &r);
110 if (!NT_STATUS_IS_OK(status)) {
111 printf("GetForm failed - %s\n", nt_errstr(status));
115 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
116 DATA_BLOB blob = data_blob_talloc(mem_ctx, NULL, buf_size);
118 data_blob_clear(&blob);
121 status = dcerpc_spoolss_GetForm(p, mem_ctx, &r);
124 printf("No form info returned");
132 static BOOL test_EnumForms(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
133 struct policy_handle *handle)
136 struct spoolss_EnumForms r;
139 r.in.handle = handle;
143 r.in.buf_size = &buf_size;
144 r.out.buf_size = &buf_size;
146 printf("Testing EnumForms\n");
148 status = dcerpc_spoolss_EnumForms(p, mem_ctx, &r);
150 if (!NT_STATUS_IS_OK(status)) {
151 printf("EnumForms failed - %s\n", nt_errstr(status));
155 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
156 DATA_BLOB blob = data_blob_talloc(mem_ctx, NULL, buf_size);
157 union spoolss_FormInfo *info;
160 data_blob_clear(&blob);
163 status = dcerpc_spoolss_EnumForms(p, mem_ctx, &r);
166 printf("No forms returned");
172 for (j = 0; j < r.out.count; j++) {
173 test_GetForm(p, mem_ctx, handle, info[j].info1.formname);
177 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
178 printf("EnumForms failed - %s/%s\n",
179 nt_errstr(status), win_errstr(r.out.result));
186 static BOOL test_DeleteForm(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
187 struct policy_handle *handle,
188 const char *formname)
191 struct spoolss_DeleteForm r;
193 r.in.handle = handle;
194 r.in.formname = formname;
196 status = dcerpc_spoolss_DeleteForm(p, mem_ctx, &r);
198 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
199 printf("DeleteForm failed - %s/%s\n",
200 nt_errstr(status), win_errstr(r.out.result));
207 static BOOL test_AddForm(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
208 struct policy_handle *handle)
210 struct spoolss_AddForm r;
211 struct spoolss_AddFormInfo1 form;
213 const char *formname = "testform3";
216 r.in.handle = handle;
218 form.flags = 2; /* User form */
219 form.formname = formname;
226 r.in.info.info1 = &form;
228 status = dcerpc_spoolss_AddForm(p, mem_ctx, &r);
230 if (!NT_STATUS_IS_OK(status)) {
231 printf("AddForm failed - %s\n", nt_errstr(status));
235 if (!W_ERROR_IS_OK(r.out.result)) {
236 printf("AddForm failed - %s\n", nt_errstr(status));
241 struct spoolss_SetForm sf;
243 sf.in.handle = handle;
244 sf.in.formname = formname;
246 sf.in.info.info1 = &form;
249 status = dcerpc_spoolss_SetForm(p, mem_ctx, &sf);
251 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
252 printf("SetForm failed - %s/%s\n",
253 nt_errstr(status), win_errstr(r.out.result));
255 /* Fall through to delete */
260 if (!test_DeleteForm(p, mem_ctx, handle, formname)) {
261 printf("DeleteForm failed\n");
268 static BOOL test_EnumPorts(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
271 struct spoolss_EnumPorts r;
274 r.in.servername = talloc_asprintf(mem_ctx, "\\\\%s",
275 dcerpc_server_name(p));
279 r.in.buf_size = &buf_size;
280 r.out.buf_size = &buf_size;
282 printf("Testing EnumPorts\n");
284 status = dcerpc_spoolss_EnumPorts(p, mem_ctx, &r);
286 if (!NT_STATUS_IS_OK(status)) {
287 printf("EnumPorts failed -- %s\n", nt_errstr(status));
291 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
292 DATA_BLOB blob = data_blob_talloc(mem_ctx, NULL, buf_size);
294 data_blob_clear(&blob);
297 status = dcerpc_spoolss_EnumPorts(p, mem_ctx, &r);
299 if (!NT_STATUS_IS_OK(status)) {
300 printf("EnumPorts failed -- %s\n", nt_errstr(status));
305 printf("No ports returned");
313 static BOOL test_GetJob(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
314 struct policy_handle *handle, uint32_t job_id)
317 struct spoolss_GetJob r;
320 r.in.handle = handle;
321 r.in.job_id = job_id;
325 r.in.buf_size = r.out.buf_size = &buf_size;
327 printf("Testing GetJob\n");
329 status = dcerpc_spoolss_GetJob(p, mem_ctx, &r);
331 if (!NT_STATUS_IS_OK(status)) {
332 printf("GetJob failed - %s\n", nt_errstr(status));
336 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
337 DATA_BLOB blob = data_blob_talloc(mem_ctx, NULL, buf_size);
339 data_blob_clear(&blob);
342 status = dcerpc_spoolss_GetJob(p, mem_ctx, &r);
345 printf("No job info returned");
353 static BOOL test_SetJob(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
354 struct policy_handle *handle, uint32_t job_id, uint32_t command)
357 struct spoolss_SetJob r;
359 r.in.handle = handle;
360 r.in.job_id = job_id;
362 r.in.command = command;
364 printf("Testing SetJob\n");
366 status = dcerpc_spoolss_SetJob(p, mem_ctx, &r);
368 if (!NT_STATUS_IS_OK(status)) {
369 printf("SetJob failed - %s\n", nt_errstr(status));
376 static BOOL test_EnumJobs(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
377 struct policy_handle *handle)
380 struct spoolss_EnumJobs r;
383 r.in.handle = handle;
385 r.in.numjobs = 0xffffffff;
389 r.in.buf_size = &buf_size;
390 r.out.buf_size = &buf_size;
392 printf("Testing EnumJobs\n");
394 status = dcerpc_spoolss_EnumJobs(p, mem_ctx, &r);
396 if (!NT_STATUS_IS_OK(status)) {
397 printf("EnumJobs failed - %s\n", nt_errstr(status));
401 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
402 DATA_BLOB blob = data_blob_talloc(mem_ctx, NULL, buf_size);
403 union spoolss_JobInfo *info;
406 data_blob_clear(&blob);
409 status = dcerpc_spoolss_EnumJobs(p, mem_ctx, &r);
412 printf("No jobs returned");
418 for (j = 0; j < r.out.count; j++) {
419 test_GetJob(p, mem_ctx, handle, info[j].info1.job_id);
420 test_SetJob(p, mem_ctx, handle, info[j].info1.job_id, 1);
423 } else if (!W_ERROR_IS_OK(r.out.result)) {
424 printf("EnumJobs failed - %s\n", win_errstr(r.out.result));
431 static BOOL test_GetPrinterData(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
432 struct policy_handle *handle,
433 const char *value_name)
436 struct spoolss_GetPrinterData r;
439 r.in.handle = handle;
440 r.in.value_name = value_name;
442 r.in.buf_size = r.out.buf_size = &buf_size;
444 printf("Testing GetPrinterData\n");
446 status = dcerpc_spoolss_GetPrinterData(p, mem_ctx, &r);
448 if (!NT_STATUS_IS_OK(status)) {
449 printf("GetPrinterData failed - %s\n", nt_errstr(status));
453 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
455 status = dcerpc_spoolss_GetPrinterData(p, mem_ctx, &r);
457 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
458 printf("GetPrinterData failed - %s/%s\n",
459 nt_errstr(status), win_errstr(r.out.result));
467 static BOOL test_GetPrinterDataEx(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
468 struct policy_handle *handle,
469 const char *key_name,
470 const char *value_name)
473 struct spoolss_GetPrinterDataEx r;
476 r.in.handle = handle;
477 r.in.key_name = key_name;
478 r.in.value_name = value_name;
480 r.in.buf_size = r.out.buf_size = &buf_size;
482 printf("Testing GetPrinterDataEx\n");
484 status = dcerpc_spoolss_GetPrinterDataEx(p, mem_ctx, &r);
486 if (!NT_STATUS_IS_OK(status)) {
487 printf("GetPrinterDataEx failed - %s\n", nt_errstr(status));
491 if (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA)) {
493 status = dcerpc_spoolss_GetPrinterDataEx(p, mem_ctx, &r);
495 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
496 printf("GetPrinterDataEx failed - %s/%s\n",
497 nt_errstr(status), win_errstr(r.out.result));
505 static BOOL test_EnumPrinterData(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
506 struct policy_handle *handle)
509 struct spoolss_EnumPrinterData r;
511 r.in.handle = handle;
517 r.in.value_offered = 0;
519 r.in.data_size = &data_size;
520 r.out.data_size = &data_size;
522 printf("Testing EnumPrinterData\n");
524 status = dcerpc_spoolss_EnumPrinterData(p, mem_ctx, &r);
526 if (!NT_STATUS_IS_OK(status)) {
527 printf("EnumPrinterData failed - %s\n", nt_errstr(status));
531 r.in.value_offered = r.out.value_needed;
533 status = dcerpc_spoolss_EnumPrinterData(p, mem_ctx, &r);
535 if (!NT_STATUS_IS_OK(status)) {
536 printf("EnumPrinterData failed - %s\n", nt_errstr(status));
540 test_GetPrinterData(p, mem_ctx, handle, r.out.value_name);
542 test_GetPrinterDataEx(
543 p, mem_ctx, handle, "PrinterDriverData",
548 } while (W_ERROR_IS_OK(r.out.result));
553 static BOOL test_DeletePrinterData(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
554 struct policy_handle *handle,
555 const char *value_name)
558 struct spoolss_DeletePrinterData r;
560 r.in.handle = handle;
561 r.in.value_name = value_name;
563 printf("Testing DeletePrinterData\n");
565 status = dcerpc_spoolss_DeletePrinterData(p, mem_ctx, &r);
567 if (!NT_STATUS_IS_OK(status)) {
568 printf("DeletePrinterData failed - %s\n", nt_errstr(status));
575 static BOOL test_SetPrinterData(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
576 struct policy_handle *handle)
579 struct spoolss_SetPrinterData r;
580 const char *value_name = "spottyfoot";
582 r.in.handle = handle;
583 r.in.value_name = value_name;
585 r.in.buffer = data_blob_talloc(mem_ctx, "dog", 4);
588 printf("Testing SetPrinterData\n");
590 status = dcerpc_spoolss_SetPrinterData(p, mem_ctx, &r);
592 if (!NT_STATUS_IS_OK(status)) {
593 printf("SetPrinterData failed - %s\n", nt_errstr(status));
597 if (!test_DeletePrinterData(p, mem_ctx, handle, value_name)) {
604 static BOOL test_SecondaryClosePrinter(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
605 struct policy_handle *handle)
608 struct dcerpc_pipe *p2;
611 /* only makes sense on SMB */
612 if (p->conn->transport.transport != NCACN_NP) {
616 printf("testing close on secondary pipe\n");
618 status = dcerpc_secondary_connection(p, &p2,
621 DCERPC_SPOOLSS_VERSION);
622 if (!NT_STATUS_IS_OK(status)) {
623 printf("Failed to create secondary connection\n");
627 if (test_ClosePrinter(p2, mem_ctx, handle)) {
628 printf("ERROR: Allowed close on secondary connection!\n");
632 if (p2->last_fault_code != DCERPC_FAULT_CONTEXT_MISMATCH) {
633 printf("Unexpected fault code 0x%x - expected 0x%x\n",
634 p2->last_fault_code, DCERPC_FAULT_CONTEXT_MISMATCH);
638 dcerpc_pipe_close(p2);
643 static BOOL test_OpenPrinter_badname(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, const char *name)
646 struct spoolss_OpenPrinter op;
647 struct spoolss_OpenPrinterEx opEx;
648 struct policy_handle handle;
651 op.in.printername = name;
652 op.in.datatype = NULL;
653 op.in.devmode_ctr.size = 0;
654 op.in.devmode_ctr.devmode= NULL;
655 op.in.access_mask = 0;
656 op.out.handle = &handle;
658 printf("\nTesting OpenPrinter(%s) with bad name\n", op.in.printername);
660 status = dcerpc_spoolss_OpenPrinter(p, mem_ctx, &op);
661 if (!NT_STATUS_IS_OK(status)) {
662 printf("OpenPrinter failed - %s\n", nt_errstr(status));
665 if (!W_ERROR_EQUAL(WERR_INVALID_PRINTER_NAME,op.out.result)) {
666 printf("OpenPrinter(%s) unexpected result[%s] should be WERR_INVALID_PRINTER_NAME\n",
667 name, win_errstr(op.out.result));
670 if (W_ERROR_IS_OK(op.out.result)) {
671 ret &=test_ClosePrinter(p, mem_ctx, &handle);
674 opEx.in.printername = name;
675 opEx.in.datatype = NULL;
676 opEx.in.devmode_ctr.size = 0;
677 opEx.in.devmode_ctr.devmode = NULL;
678 opEx.in.access_mask = 0;
680 opEx.in.userlevel.level1 = NULL;
681 opEx.out.handle = &handle;
683 printf("\nTesting OpenPrinter(%s) with bad name\n", opEx.in.printername);
685 status = dcerpc_spoolss_OpenPrinterEx(p, mem_ctx, &opEx);
686 if (!NT_STATUS_IS_OK(status)) {
687 printf("OpenPrinter failed - %s\n", nt_errstr(status));
690 if (!W_ERROR_EQUAL(WERR_INVALID_PRINTER_NAME,opEx.out.result)) {
691 printf("OpenPrinterEx(%s) unexpected result[%s] should be WERR_INVALID_PRINTER_NAME\n",
692 name, win_errstr(opEx.out.result));
695 if (W_ERROR_IS_OK(opEx.out.result)) {
696 ret &=test_ClosePrinter(p, mem_ctx, &handle);
702 static BOOL test_OpenPrinter_badnames(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
707 ret &= test_OpenPrinter_badname(p, mem_ctx, "__INVALID_PRINTER__");
708 ret &= test_OpenPrinter_badname(p, mem_ctx, "\\\\127.0.0.1");
709 ret &= test_OpenPrinter_badname(p, mem_ctx, "\\\\localhost");
711 name = talloc_asprintf(mem_ctx, "\\\\%s\\", dcerpc_server_name(p));
712 ret &= test_OpenPrinter_badname(p, mem_ctx, name);
715 name = talloc_asprintf(mem_ctx, "\\\\%s\\__INVALID_PRINTER__", dcerpc_server_name(p));
716 ret &= test_OpenPrinter_badname(p, mem_ctx, name);
722 static BOOL test_OpenPrinter(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
726 struct spoolss_OpenPrinter r;
727 struct policy_handle handle;
730 r.in.printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s", dcerpc_server_name(p), name);
731 r.in.datatype = NULL;
732 r.in.devmode_ctr.size = 0;
733 r.in.devmode_ctr.devmode= NULL;
734 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
735 r.out.handle = &handle;
737 printf("\nTesting OpenPrinter(%s)\n", r.in.printername);
739 status = dcerpc_spoolss_OpenPrinter(p, mem_ctx, &r);
740 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
741 printf("OpenPrinter failed - %s/%s\n",
742 nt_errstr(status), win_errstr(r.out.result));
746 if (!test_GetPrinter(p, mem_ctx, &handle)) {
750 if (!test_SecondaryClosePrinter(p, mem_ctx, &handle)) {
754 if (!test_ClosePrinter(p, mem_ctx, &handle)) {
761 static BOOL call_OpenPrinterEx(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
762 const char *name, struct policy_handle *handle)
764 struct spoolss_OpenPrinterEx r;
765 struct spoolss_UserLevel1 userlevel1;
768 if (name && name[0]) {
769 r.in.printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
770 dcerpc_server_name(p), name);
772 r.in.printername = talloc_asprintf(mem_ctx, "\\\\%s",
773 dcerpc_server_name(p));
776 r.in.datatype = NULL;
777 r.in.devmode_ctr.size = 0;
778 r.in.devmode_ctr.devmode= NULL;
779 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
781 r.in.userlevel.level1 = &userlevel1;
782 r.out.handle = handle;
784 userlevel1.size = 1234;
785 userlevel1.client = "hello";
786 userlevel1.user = "spottyfoot!";
787 userlevel1.build = 1;
788 userlevel1.major = 2;
789 userlevel1.minor = 3;
790 userlevel1.processor = 4;
792 printf("Testing OpenPrinterEx(%s)\n", r.in.printername);
794 status = dcerpc_spoolss_OpenPrinterEx(p, mem_ctx, &r);
796 if (!NT_STATUS_IS_OK(status)) {
797 printf("OpenPrinterEx failed - %s\n", nt_errstr(status));
801 if (!W_ERROR_IS_OK(r.out.result)) {
802 printf("OpenPrinterEx failed - %s\n", win_errstr(r.out.result));
809 static BOOL test_OpenPrinterEx(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
812 struct policy_handle handle;
815 if (!call_OpenPrinterEx(p, mem_ctx, name, &handle)) {
819 if (!test_GetPrinter(p, mem_ctx, &handle)) {
823 if (!test_EnumForms(p, mem_ctx, &handle)) {
827 if (!test_AddForm(p, mem_ctx, &handle)) {
831 if (!test_EnumPrinterData(p, mem_ctx, &handle)) {
835 if (!test_EnumJobs(p, mem_ctx, &handle)) {
839 if (!test_SetPrinterData(p, mem_ctx, &handle)) {
843 if (!test_SecondaryClosePrinter(p, mem_ctx, &handle)) {
847 if (!test_ClosePrinter(p, mem_ctx, &handle)) {
854 static BOOL test_EnumPrinters(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
856 struct spoolss_EnumPrinters r;
858 uint16_t levels[] = {1, 2, 4, 5};
862 for (i=0;i<ARRAY_SIZE(levels);i++) {
863 uint32_t buf_size = 0;
864 union spoolss_PrinterInfo *info;
869 r.in.level = levels[i];
871 r.in.buf_size = &buf_size;
872 r.out.buf_size = &buf_size;
874 printf("\nTesting EnumPrinters level %u\n", r.in.level);
876 status = dcerpc_spoolss_EnumPrinters(p, mem_ctx, &r);
877 if (!NT_STATUS_IS_OK(status)) {
878 printf("EnumPrinters failed - %s\n", nt_errstr(status));
883 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
884 DATA_BLOB blob = data_blob_talloc(mem_ctx, NULL, buf_size);
885 data_blob_clear(&blob);
887 status = dcerpc_spoolss_EnumPrinters(p, mem_ctx, &r);
890 if (!NT_STATUS_IS_OK(status) ||
891 !W_ERROR_IS_OK(r.out.result)) {
892 printf("EnumPrinters failed - %s/%s\n",
893 nt_errstr(status), win_errstr(r.out.result));
898 printf("No printers returned");
904 for (j=0;j<r.out.count;j++) {
905 if (r.in.level == 1) {
906 /* the names appear to be comma-separated name lists? */
907 char *name = talloc_strdup(mem_ctx, info[j].info1.name);
908 char *comma = strchr(name, ',');
909 if (comma) *comma = 0;
910 if (!test_OpenPrinter(p, mem_ctx, name)) {
913 if (!test_OpenPrinterEx(p, mem_ctx, name)) {
923 static BOOL test_GetPrinterDriver2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
924 struct policy_handle *handle,
925 const char *driver_name)
928 struct spoolss_GetPrinterDriver2 r;
931 r.in.handle = handle;
932 r.in.architecture = "W32X86";
936 r.in.buf_size = r.out.buf_size = &buf_size;
937 r.in.client_major_version = 0;
938 r.in.client_minor_version = 0;
940 printf("Testing GetPrinterDriver2\n");
942 status = dcerpc_spoolss_GetPrinterDriver2(p, mem_ctx, &r);
944 if (!NT_STATUS_IS_OK(status)) {
945 printf("GetPrinterDriver2 failed - %s\n", nt_errstr(status));
949 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
950 status = dcerpc_spoolss_GetPrinterDriver2(p, mem_ctx, &r);
953 if (!NT_STATUS_IS_OK(status) ||
954 !W_ERROR_IS_OK(r.out.result)) {
955 printf("GetPrinterDriver2 failed - %s/%s\n",
956 nt_errstr(status), win_errstr(r.out.result));
963 static BOOL test_EnumPrinterDrivers(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
965 struct spoolss_EnumPrinterDrivers r;
967 uint16_t levels[] = {1, 2, 3};
971 for (i=0;i<ARRAY_SIZE(levels);i++) {
973 union spoolss_DriverInfo *info;
976 r.in.server = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
977 r.in.environment = "Windows NT x86";
978 r.in.level = levels[i];
981 r.in.buf_size = &buf_size;
982 r.out.buf_size = &buf_size;
984 printf("\nTesting EnumPrinterDrivers level %u\n", r.in.level);
986 status = dcerpc_spoolss_EnumPrinterDrivers(p, mem_ctx, &r);
988 if (!NT_STATUS_IS_OK(status)) {
989 printf("EnumPrinterDrivers failed - %s\n",
995 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
996 DATA_BLOB blob = data_blob_talloc(
997 mem_ctx, NULL, buf_size);
999 data_blob_clear(&blob);
1000 r.in.buffer = &blob;
1001 status = dcerpc_spoolss_EnumPrinterDrivers(p, mem_ctx, &r);
1004 if (!NT_STATUS_IS_OK(status) ||
1005 !W_ERROR_IS_OK(r.out.result)) {
1006 printf("EnumPrinterDrivers failed - %s/%s\n",
1007 nt_errstr(status), win_errstr(r.out.result));
1012 printf("No printer drivers returned");
1018 if (r.in.level != 1) continue;
1020 for (j=0;j<r.out.count;j++) {
1021 struct policy_handle handle;
1023 if (!call_OpenPrinterEx(p, mem_ctx, "",&handle)) {
1026 ret &=test_GetPrinterDriver2(p, mem_ctx, &handle, info[j].info1.driver_name);
1033 BOOL torture_rpc_spoolss(void)
1036 struct dcerpc_pipe *p;
1037 TALLOC_CTX *mem_ctx;
1040 status = torture_rpc_connection(&p,
1041 DCERPC_SPOOLSS_NAME,
1042 DCERPC_SPOOLSS_UUID,
1043 DCERPC_SPOOLSS_VERSION);
1044 if (!NT_STATUS_IS_OK(status)) {
1048 mem_ctx = talloc_init("torture_rpc_spoolss");
1050 ret &= test_OpenPrinter_badnames(p, mem_ctx);
1052 ret &= test_EnumPorts(p, mem_ctx);
1054 ret &= test_EnumPrinters(p, mem_ctx);
1056 ret &= test_EnumPrinterDrivers(p, mem_ctx);
1058 talloc_free(mem_ctx);
1060 torture_rpc_close(p);