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;
31 union spoolss_PrinterInfo info;
32 uint16 levels[] = {1, 2, 3, 4, 5, 6, 7};
36 for (i=0;i<ARRAY_SIZE(levels);i++) {
38 r.in.level = levels[i];
40 r.in.buf_size = &buf_size;
41 r.out.buf_size = &buf_size;
43 printf("Testing GetPrinter level %u\n", r.in.level);
45 status = dcerpc_spoolss_GetPrinter(p, mem_ctx, &r);
46 if (!NT_STATUS_IS_OK(status)) {
47 printf("GetPrinter failed - %s\n", nt_errstr(status));
52 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
53 blob = data_blob_talloc(mem_ctx, NULL, buf_size);
54 data_blob_clear(&blob);
56 status = dcerpc_spoolss_GetPrinter(p, mem_ctx, &r);
59 if (!NT_STATUS_IS_OK(status) ||
60 !W_ERROR_IS_OK(r.out.result)) {
61 printf("GetPrinter failed - %s/%s\n",
62 nt_errstr(status), win_errstr(r.out.result));
67 status = ndr_pull_union_blob(r.out.buffer, mem_ctx, r.in.level, &info,
68 (ndr_pull_union_fn_t)ndr_pull_spoolss_PrinterInfo);
69 if (!NT_STATUS_IS_OK(status)) {
70 printf("PrinterInfo parse failed - %s\n", nt_errstr(status));
75 NDR_PRINT_UNION_DEBUG(spoolss_PrinterInfo, r.in.level, &info);
82 BOOL test_ClosePrinter(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
83 struct policy_handle *handle)
86 struct spoolss_ClosePrinter r;
89 r.out.handle = handle;
91 printf("Testing ClosePrinter\n");
93 status = dcerpc_spoolss_ClosePrinter(p, mem_ctx, &r);
94 if (!NT_STATUS_IS_OK(status)) {
95 printf("ClosePrinter failed - %s\n", nt_errstr(status));
102 static BOOL test_OpenPrinter(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
106 struct spoolss_OpenPrinter r;
107 struct policy_handle handle;
111 blob = data_blob(NULL, 0);
113 r.in.server = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
116 r.in.access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED;
117 r.out.handle = &handle;
119 printf("\nTesting OpenPrinter(\\\\%s\\%s)\n", r.in.server, r.in.printer);
121 status = dcerpc_spoolss_OpenPrinter(p, mem_ctx, &r);
122 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
123 printf("OpenPrinter failed - %s/%s\n",
124 nt_errstr(status), win_errstr(r.out.result));
129 if (!test_GetPrinter(p, mem_ctx, &handle)) {
133 if (!test_ClosePrinter(p, mem_ctx, &handle)) {
140 static BOOL test_OpenPrinterEx(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
143 struct policy_handle handle;
144 struct spoolss_OpenPrinterEx r;
145 struct spoolss_UserLevel1 userlevel1;
149 r.in.printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
150 dcerpc_server_name(p), name);
151 r.in.datatype = NULL;
152 r.in.devmode_ctr.size = 0;
153 r.in.devmode_ctr.devmode = NULL;
154 r.in.access_required = 0x02000000;
156 r.out.handle = &handle;
158 userlevel1.size = 1234;
159 userlevel1.client = "hello";
160 userlevel1.user = "spottyfoot!";
161 userlevel1.build = 1;
162 userlevel1.major = 2;
163 userlevel1.minor = 3;
164 userlevel1.processor = 4;
165 r.in.userlevel.level1 = &userlevel1;
167 printf("Testing OpenPrinterEx(%s)\n", r.in.printername);
169 status = dcerpc_spoolss_OpenPrinterEx(p, mem_ctx, &r);
171 if (!NT_STATUS_IS_OK(status)) {
172 printf("OpenPrinterEx failed - %s\n", nt_errstr(status));
176 if (!W_ERROR_IS_OK(r.out.result)) {
177 printf("OpenPrinterEx failed - %s\n", win_errstr(r.out.result));
181 if (!test_GetPrinter(p, mem_ctx, &handle)) {
185 if (!test_ClosePrinter(p, mem_ctx, &handle)) {
193 static BOOL test_EnumPrinters(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
195 struct spoolss_EnumPrinters r;
197 uint16 levels[] = {1, 2, 3, 4, 5, 6, 7};
201 for (i=0;i<ARRAY_SIZE(levels);i++) {
203 union spoolss_PrinterInfo *info;
208 r.in.level = levels[i];
210 r.in.buf_size = &buf_size;
211 r.out.buf_size = &buf_size;
213 printf("\nTesting EnumPrinters level %u\n", r.in.level);
215 status = dcerpc_spoolss_EnumPrinters(p, mem_ctx, &r);
216 if (!NT_STATUS_IS_OK(status)) {
217 printf("EnumPrinters failed - %s\n", nt_errstr(status));
222 if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
223 DATA_BLOB blob = data_blob_talloc(mem_ctx, NULL, buf_size);
224 data_blob_clear(&blob);
226 status = dcerpc_spoolss_EnumPrinters(p, mem_ctx, &r);
229 if (!NT_STATUS_IS_OK(status) ||
230 !W_ERROR_IS_OK(r.out.result)) {
231 printf("EnumPrinters failed - %s/%s\n",
232 nt_errstr(status), win_errstr(r.out.result));
236 status = pull_spoolss_PrinterInfoArray(r.out.buffer, mem_ctx, r.in.level, r.out.count, &info);
237 if (!NT_STATUS_IS_OK(status)) {
238 printf("EnumPrintersArray parse failed - %s\n", nt_errstr(status));
242 for (j=0;j<r.out.count;j++) {
243 printf("Printer %d\n", j);
244 NDR_PRINT_UNION_DEBUG(spoolss_PrinterInfo, r.in.level, &info[j]);
247 for (j=0;j<r.out.count;j++) {
248 if (r.in.level == 1) {
249 /* the names appear to be comma-separated name lists? */
250 char *name = talloc_strdup(mem_ctx, info[j].info1.name);
251 char *comma = strchr(name, ',');
252 if (comma) *comma = 0;
253 if (!test_OpenPrinter(p, mem_ctx, name)) {
257 if (!test_OpenPrinterEx(p, mem_ctx, name)) {
267 BOOL torture_rpc_spoolss(int dummy)
270 struct dcerpc_pipe *p;
274 mem_ctx = talloc_init("torture_rpc_spoolss");
276 status = torture_rpc_connection(&p, "spoolss");
277 if (!NT_STATUS_IS_OK(status)) {
281 if (!test_EnumPrinters(p, mem_ctx)) {
285 torture_rpc_close(p);