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.
24 BOOL test_GetPrinter(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
25 struct policy_handle *handle)
28 struct spoolss_GetPrinter r;
29 uint16 levels[] = {1, 2, 3, 4, 5, 6, 7};
33 for (i=0;i<ARRAY_SIZE(levels);i++) {
36 r.in.level = levels[i];
38 r.in.buf_size = &buf_size;
39 r.out.buf_size = &buf_size;
41 printf("Testing GetPrinter level %u\n", r.in.level);
43 status = dcerpc_spoolss_GetPrinter(p, mem_ctx, &r);
44 if (!NT_STATUS_IS_OK(status)) {
45 printf("GetPrinter failed - %s\n", nt_errstr(status));
50 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
51 DATA_BLOB blob = data_blob_talloc(mem_ctx, NULL, buf_size);
52 data_blob_clear(&blob);
54 status = dcerpc_spoolss_GetPrinter(p, mem_ctx, &r);
57 if (!NT_STATUS_IS_OK(status) ||
58 !W_ERROR_IS_OK(r.out.result)) {
59 printf("GetPrinter failed - %s/%s\n",
60 nt_errstr(status), win_errstr(r.out.result));
70 BOOL test_ClosePrinter(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
71 struct policy_handle *handle)
74 struct spoolss_ClosePrinter r;
77 r.out.handle = handle;
79 printf("Testing ClosePrinter\n");
81 status = dcerpc_spoolss_ClosePrinter(p, mem_ctx, &r);
82 if (!NT_STATUS_IS_OK(status)) {
83 printf("ClosePrinter failed - %s\n", nt_errstr(status));
90 static BOOL test_OpenPrinter(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
94 struct spoolss_OpenPrinter r;
95 struct policy_handle handle;
99 blob = data_blob(NULL, 0);
101 r.in.server = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
104 r.in.access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED;
105 r.out.handle = &handle;
107 printf("\nTesting OpenPrinter(\\\\%s\\%s)\n", r.in.server, r.in.printer);
109 status = dcerpc_spoolss_OpenPrinter(p, mem_ctx, &r);
110 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
111 printf("OpenPrinter failed - %s/%s\n",
112 nt_errstr(status), win_errstr(r.out.result));
117 if (!test_GetPrinter(p, mem_ctx, &handle)) {
121 if (!test_ClosePrinter(p, mem_ctx, &handle)) {
128 static BOOL test_OpenPrinterEx(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
131 struct policy_handle handle;
132 struct spoolss_OpenPrinterEx r;
133 struct spoolss_UserLevel1 userlevel1;
137 r.in.printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
138 dcerpc_server_name(p), name);
139 r.in.datatype = NULL;
140 r.in.devmode_ctr.size = 0;
141 r.in.devmode_ctr.devmode = NULL;
142 r.in.access_required = 0x02000000;
144 r.out.handle = &handle;
146 userlevel1.size = 1234;
147 userlevel1.client = "hello";
148 userlevel1.user = "spottyfoot!";
149 userlevel1.build = 1;
150 userlevel1.major = 2;
151 userlevel1.minor = 3;
152 userlevel1.processor = 4;
153 r.in.userlevel.level1 = &userlevel1;
155 printf("Testing OpenPrinterEx(%s)\n", r.in.printername);
157 status = dcerpc_spoolss_OpenPrinterEx(p, mem_ctx, &r);
159 if (!NT_STATUS_IS_OK(status)) {
160 printf("OpenPrinterEx failed - %s\n", nt_errstr(status));
164 if (!W_ERROR_IS_OK(r.out.result)) {
165 printf("OpenPrinterEx failed - %s\n", win_errstr(r.out.result));
169 if (!test_GetPrinter(p, mem_ctx, &handle)) {
173 if (!test_ClosePrinter(p, mem_ctx, &handle)) {
181 static BOOL test_EnumPrinters(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
183 struct spoolss_EnumPrinters r;
185 uint16 levels[] = {1, 2, 4, 5};
189 for (i=0;i<ARRAY_SIZE(levels);i++) {
191 union spoolss_PrinterInfo *info;
196 r.in.level = levels[i];
198 r.in.buf_size = &buf_size;
199 r.out.buf_size = &buf_size;
201 printf("\nTesting EnumPrinters level %u\n", r.in.level);
203 status = dcerpc_spoolss_EnumPrinters(p, mem_ctx, &r);
204 if (!NT_STATUS_IS_OK(status)) {
205 printf("EnumPrinters failed - %s\n", nt_errstr(status));
210 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
211 DATA_BLOB blob = data_blob_talloc(mem_ctx, NULL, buf_size);
212 data_blob_clear(&blob);
214 status = dcerpc_spoolss_EnumPrinters(p, mem_ctx, &r);
217 if (!NT_STATUS_IS_OK(status) ||
218 !W_ERROR_IS_OK(r.out.result)) {
219 printf("EnumPrinters failed - %s/%s\n",
220 nt_errstr(status), win_errstr(r.out.result));
224 status = pull_spoolss_PrinterInfoArray(r.out.buffer, mem_ctx, r.in.level, r.out.count, &info);
225 if (!NT_STATUS_IS_OK(status)) {
226 printf("EnumPrintersArray parse failed - %s\n", nt_errstr(status));
230 for (j=0;j<r.out.count;j++) {
231 printf("Printer %d\n", j);
232 NDR_PRINT_UNION_DEBUG(spoolss_PrinterInfo, r.in.level, &info[j]);
235 for (j=0;j<r.out.count;j++) {
236 if (r.in.level == 1) {
237 /* the names appear to be comma-separated name lists? */
238 char *name = talloc_strdup(mem_ctx, info[j].info1.name);
239 char *comma = strchr(name, ',');
240 if (comma) *comma = 0;
241 if (!test_OpenPrinter(p, mem_ctx, name)) {
245 if (!test_OpenPrinterEx(p, mem_ctx, name)) {
255 BOOL torture_rpc_spoolss(int dummy)
258 struct dcerpc_pipe *p;
262 mem_ctx = talloc_init("torture_rpc_spoolss");
264 status = torture_rpc_connection(&p,
267 DCERPC_SPOOLSS_VERSION);
268 if (!NT_STATUS_IS_OK(status)) {
272 p->flags |= DCERPC_DEBUG_PRINT_BOTH;
274 if (!test_EnumPrinters(p, mem_ctx)) {
278 torture_rpc_close(p);