Line data Source code
1 : /*
2 : Unix SMB/CIFS implementation.
3 : RPC pipe client
4 :
5 : Copyright (C) Gerald Carter 2001-2005,
6 : Copyright (C) Tim Potter 2000-2002,
7 : Copyright (C) Andrew Tridgell 1994-2000,
8 : Copyright (C) Jean-Francois Micouleau 1999-2000.
9 : Copyright (C) Jeremy Allison 2005.
10 :
11 : This program is free software; you can redistribute it and/or modify
12 : it under the terms of the GNU General Public License as published by
13 : the Free Software Foundation; either version 3 of the License, or
14 : (at your option) any later version.
15 :
16 : This program is distributed in the hope that it will be useful,
17 : but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : GNU General Public License for more details.
20 :
21 : You should have received a copy of the GNU General Public License
22 : along with this program. If not, see <http://www.gnu.org/licenses/>.
23 : */
24 :
25 : #include "includes.h"
26 : #include "rpc_client/rpc_client.h"
27 : #include "../librpc/gen_ndr/ndr_spoolss_c.h"
28 : #include "rpc_client/cli_spoolss.h"
29 : #include "auth/gensec/gensec.h"
30 : #include "auth/credentials/credentials.h"
31 : #include "rpc_client/init_spoolss.h"
32 :
33 : /**********************************************************************
34 : convenience wrapper around rpccli_spoolss_OpenPrinterEx
35 : **********************************************************************/
36 :
37 6 : WERROR rpccli_spoolss_openprinter_ex(struct rpc_pipe_client *cli,
38 : TALLOC_CTX *mem_ctx,
39 : const char *printername,
40 : uint32_t access_desired,
41 : struct policy_handle *handle)
42 : {
43 0 : NTSTATUS status;
44 0 : WERROR werror;
45 0 : struct spoolss_DevmodeContainer devmode_ctr;
46 0 : struct spoolss_UserLevelCtr userlevel_ctr;
47 0 : struct spoolss_UserLevel1 level1;
48 6 : struct dcerpc_binding_handle *b = cli->binding_handle;
49 6 : struct cli_credentials *creds = gensec_get_credentials(cli->auth->auth_ctx);
50 :
51 6 : ZERO_STRUCT(devmode_ctr);
52 :
53 6 : werror = spoolss_init_spoolss_UserLevel1(mem_ctx,
54 : cli_credentials_get_username(creds),
55 : &level1);
56 6 : if (!W_ERROR_IS_OK(werror)) {
57 0 : return werror;
58 : }
59 :
60 6 : userlevel_ctr.level = 1;
61 6 : userlevel_ctr.user_info.level1 = &level1;
62 :
63 6 : status = dcerpc_spoolss_OpenPrinterEx(b, mem_ctx,
64 : printername,
65 : NULL,
66 : devmode_ctr,
67 : access_desired,
68 : userlevel_ctr,
69 : handle,
70 : &werror);
71 :
72 6 : if (!NT_STATUS_IS_OK(status)) {
73 0 : return ntstatus_to_werror(status);
74 : }
75 :
76 6 : if (!W_ERROR_IS_OK(werror)) {
77 0 : return werror;
78 : }
79 :
80 6 : return WERR_OK;
81 : }
82 :
83 : /**********************************************************************
84 : convenience wrapper around rpccli_spoolss_GetPrinterDriver
85 : **********************************************************************/
86 :
87 0 : WERROR rpccli_spoolss_getprinterdriver(struct rpc_pipe_client *cli,
88 : TALLOC_CTX *mem_ctx,
89 : struct policy_handle *handle,
90 : const char *architecture,
91 : uint32_t level,
92 : uint32_t offered,
93 : union spoolss_DriverInfo *info)
94 : {
95 0 : NTSTATUS status;
96 0 : WERROR werror;
97 0 : uint32_t needed;
98 0 : DATA_BLOB buffer;
99 0 : struct dcerpc_binding_handle *b = cli->binding_handle;
100 :
101 0 : if (offered > 0) {
102 0 : buffer = data_blob_talloc_zero(mem_ctx, offered);
103 0 : W_ERROR_HAVE_NO_MEMORY(buffer.data);
104 : }
105 :
106 0 : status = dcerpc_spoolss_GetPrinterDriver(b, mem_ctx,
107 : handle,
108 : architecture,
109 : level,
110 : (offered > 0) ? &buffer : NULL,
111 : offered,
112 : info,
113 : &needed,
114 : &werror);
115 0 : if (!NT_STATUS_IS_OK(status)) {
116 0 : return ntstatus_to_werror(status);
117 : }
118 0 : if (W_ERROR_EQUAL(werror, WERR_INSUFFICIENT_BUFFER)) {
119 0 : offered = needed;
120 0 : buffer = data_blob_talloc_zero(mem_ctx, needed);
121 0 : W_ERROR_HAVE_NO_MEMORY(buffer.data);
122 :
123 0 : status = dcerpc_spoolss_GetPrinterDriver(b, mem_ctx,
124 : handle,
125 : architecture,
126 : level,
127 : &buffer,
128 : offered,
129 : info,
130 : &needed,
131 : &werror);
132 : }
133 0 : if (!NT_STATUS_IS_OK(status)) {
134 0 : return ntstatus_to_werror(status);
135 : }
136 :
137 0 : return werror;
138 : }
139 :
140 : /**********************************************************************
141 : convenience wrapper around rpccli_spoolss_GetPrinterDriver2
142 : **********************************************************************/
143 :
144 0 : WERROR rpccli_spoolss_getprinterdriver2(struct rpc_pipe_client *cli,
145 : TALLOC_CTX *mem_ctx,
146 : struct policy_handle *handle,
147 : const char *architecture,
148 : uint32_t level,
149 : uint32_t offered,
150 : uint32_t client_major_version,
151 : uint32_t client_minor_version,
152 : union spoolss_DriverInfo *info,
153 : uint32_t *server_major_version,
154 : uint32_t *server_minor_version)
155 : {
156 0 : NTSTATUS status;
157 0 : WERROR werror;
158 0 : uint32_t needed;
159 0 : DATA_BLOB buffer;
160 0 : struct dcerpc_binding_handle *b = cli->binding_handle;
161 :
162 0 : if (offered > 0) {
163 0 : buffer = data_blob_talloc_zero(mem_ctx, offered);
164 0 : W_ERROR_HAVE_NO_MEMORY(buffer.data);
165 : }
166 :
167 0 : status = dcerpc_spoolss_GetPrinterDriver2(b, mem_ctx,
168 : handle,
169 : architecture,
170 : level,
171 : (offered > 0) ? &buffer : NULL,
172 : offered,
173 : client_major_version,
174 : client_minor_version,
175 : info,
176 : &needed,
177 : server_major_version,
178 : server_minor_version,
179 : &werror);
180 0 : if (!NT_STATUS_IS_OK(status)) {
181 0 : return ntstatus_to_werror(status);
182 : }
183 :
184 0 : if (W_ERROR_EQUAL(werror, WERR_INSUFFICIENT_BUFFER)) {
185 0 : offered = needed;
186 0 : buffer = data_blob_talloc_zero(mem_ctx, needed);
187 0 : W_ERROR_HAVE_NO_MEMORY(buffer.data);
188 :
189 0 : status = dcerpc_spoolss_GetPrinterDriver2(b, mem_ctx,
190 : handle,
191 : architecture,
192 : level,
193 : &buffer,
194 : offered,
195 : client_major_version,
196 : client_minor_version,
197 : info,
198 : &needed,
199 : server_major_version,
200 : server_minor_version,
201 : &werror);
202 : }
203 0 : if (!NT_STATUS_IS_OK(status)) {
204 0 : return ntstatus_to_werror(status);
205 : }
206 :
207 0 : return werror;
208 : }
209 :
210 : /**********************************************************************
211 : convenience wrapper around rpccli_spoolss_AddPrinterEx
212 : **********************************************************************/
213 :
214 0 : WERROR rpccli_spoolss_addprinterex(struct rpc_pipe_client *cli,
215 : TALLOC_CTX *mem_ctx,
216 : struct spoolss_SetPrinterInfoCtr *info_ctr)
217 : {
218 0 : WERROR result;
219 0 : NTSTATUS status;
220 0 : struct spoolss_DevmodeContainer devmode_ctr;
221 0 : struct sec_desc_buf secdesc_ctr;
222 0 : struct spoolss_UserLevelCtr userlevel_ctr;
223 0 : struct spoolss_UserLevel1 level1;
224 0 : struct policy_handle handle;
225 0 : struct dcerpc_binding_handle *b = cli->binding_handle;
226 0 : struct cli_credentials *creds = gensec_get_credentials(cli->auth->auth_ctx);
227 :
228 0 : ZERO_STRUCT(devmode_ctr);
229 0 : ZERO_STRUCT(secdesc_ctr);
230 :
231 0 : result = spoolss_init_spoolss_UserLevel1(mem_ctx,
232 : cli_credentials_get_username(creds),
233 : &level1);
234 0 : if (!W_ERROR_IS_OK(result)) {
235 0 : return result;
236 : }
237 :
238 0 : userlevel_ctr.level = 1;
239 0 : userlevel_ctr.user_info.level1 = &level1;
240 :
241 0 : status = dcerpc_spoolss_AddPrinterEx(b, mem_ctx,
242 0 : cli->srv_name_slash,
243 : info_ctr,
244 : &devmode_ctr,
245 : &secdesc_ctr,
246 : &userlevel_ctr,
247 : &handle,
248 : &result);
249 0 : if (!NT_STATUS_IS_OK(status)) {
250 0 : return ntstatus_to_werror(status);
251 : }
252 :
253 0 : return result;
254 : }
255 :
256 : /**********************************************************************
257 : convenience wrapper around rpccli_spoolss_GetPrinter
258 : **********************************************************************/
259 :
260 0 : WERROR rpccli_spoolss_getprinter(struct rpc_pipe_client *cli,
261 : TALLOC_CTX *mem_ctx,
262 : struct policy_handle *handle,
263 : uint32_t level,
264 : uint32_t offered,
265 : union spoolss_PrinterInfo *info)
266 : {
267 0 : NTSTATUS status;
268 0 : WERROR werror;
269 0 : DATA_BLOB buffer;
270 0 : uint32_t needed;
271 0 : struct dcerpc_binding_handle *b = cli->binding_handle;
272 :
273 0 : if (offered > 0) {
274 0 : buffer = data_blob_talloc_zero(mem_ctx, offered);
275 0 : W_ERROR_HAVE_NO_MEMORY(buffer.data);
276 : }
277 :
278 0 : status = dcerpc_spoolss_GetPrinter(b, mem_ctx,
279 : handle,
280 : level,
281 : (offered > 0) ? &buffer : NULL,
282 : offered,
283 : info,
284 : &needed,
285 : &werror);
286 0 : if (!NT_STATUS_IS_OK(status)) {
287 0 : return ntstatus_to_werror(status);
288 : }
289 :
290 0 : if (W_ERROR_EQUAL(werror, WERR_INSUFFICIENT_BUFFER)) {
291 :
292 0 : offered = needed;
293 0 : buffer = data_blob_talloc_zero(mem_ctx, offered);
294 0 : W_ERROR_HAVE_NO_MEMORY(buffer.data);
295 :
296 0 : status = dcerpc_spoolss_GetPrinter(b, mem_ctx,
297 : handle,
298 : level,
299 : &buffer,
300 : offered,
301 : info,
302 : &needed,
303 : &werror);
304 : }
305 0 : if (!NT_STATUS_IS_OK(status)) {
306 0 : return ntstatus_to_werror(status);
307 : }
308 :
309 0 : return werror;
310 : }
311 :
312 : /**********************************************************************
313 : convenience wrapper around rpccli_spoolss_GetJob
314 : **********************************************************************/
315 :
316 0 : WERROR rpccli_spoolss_getjob(struct rpc_pipe_client *cli,
317 : TALLOC_CTX *mem_ctx,
318 : struct policy_handle *handle,
319 : uint32_t job_id,
320 : uint32_t level,
321 : uint32_t offered,
322 : union spoolss_JobInfo *info)
323 : {
324 0 : NTSTATUS status;
325 0 : WERROR werror;
326 0 : uint32_t needed;
327 0 : DATA_BLOB buffer;
328 0 : struct dcerpc_binding_handle *b = cli->binding_handle;
329 :
330 0 : if (offered > 0) {
331 0 : buffer = data_blob_talloc_zero(mem_ctx, offered);
332 0 : W_ERROR_HAVE_NO_MEMORY(buffer.data);
333 : }
334 :
335 0 : status = dcerpc_spoolss_GetJob(b, mem_ctx,
336 : handle,
337 : job_id,
338 : level,
339 : (offered > 0) ? &buffer : NULL,
340 : offered,
341 : info,
342 : &needed,
343 : &werror);
344 0 : if (!NT_STATUS_IS_OK(status)) {
345 0 : return ntstatus_to_werror(status);
346 : }
347 :
348 0 : if (W_ERROR_EQUAL(werror, WERR_INSUFFICIENT_BUFFER)) {
349 0 : offered = needed;
350 0 : buffer = data_blob_talloc_zero(mem_ctx, needed);
351 0 : W_ERROR_HAVE_NO_MEMORY(buffer.data);
352 :
353 0 : status = dcerpc_spoolss_GetJob(b, mem_ctx,
354 : handle,
355 : job_id,
356 : level,
357 : &buffer,
358 : offered,
359 : info,
360 : &needed,
361 : &werror);
362 : }
363 0 : if (!NT_STATUS_IS_OK(status)) {
364 0 : return ntstatus_to_werror(status);
365 : }
366 :
367 0 : return werror;
368 : }
369 :
370 : /**********************************************************************
371 : convenience wrapper around rpccli_spoolss_EnumForms
372 : **********************************************************************/
373 :
374 0 : WERROR rpccli_spoolss_enumforms(struct rpc_pipe_client *cli,
375 : TALLOC_CTX *mem_ctx,
376 : struct policy_handle *handle,
377 : uint32_t level,
378 : uint32_t offered,
379 : uint32_t *count,
380 : union spoolss_FormInfo **info)
381 : {
382 0 : NTSTATUS status;
383 0 : WERROR werror;
384 0 : uint32_t needed;
385 0 : DATA_BLOB buffer;
386 0 : struct dcerpc_binding_handle *b = cli->binding_handle;
387 :
388 0 : if (offered > 0) {
389 0 : buffer = data_blob_talloc_zero(mem_ctx, offered);
390 0 : W_ERROR_HAVE_NO_MEMORY(buffer.data);
391 : }
392 :
393 0 : status = dcerpc_spoolss_EnumForms(b, mem_ctx,
394 : handle,
395 : level,
396 : (offered > 0) ? &buffer : NULL,
397 : offered,
398 : count,
399 : info,
400 : &needed,
401 : &werror);
402 0 : if (!NT_STATUS_IS_OK(status)) {
403 0 : return ntstatus_to_werror(status);
404 : }
405 :
406 0 : if (W_ERROR_EQUAL(werror, WERR_INSUFFICIENT_BUFFER)) {
407 0 : offered = needed;
408 0 : buffer = data_blob_talloc_zero(mem_ctx, needed);
409 0 : W_ERROR_HAVE_NO_MEMORY(buffer.data);
410 :
411 0 : status = dcerpc_spoolss_EnumForms(b, mem_ctx,
412 : handle,
413 : level,
414 : (offered > 0) ? &buffer : NULL,
415 : offered,
416 : count,
417 : info,
418 : &needed,
419 : &werror);
420 : }
421 0 : if (!NT_STATUS_IS_OK(status)) {
422 0 : return ntstatus_to_werror(status);
423 : }
424 :
425 0 : return werror;
426 : }
427 :
428 : /**********************************************************************
429 : convenience wrapper around rpccli_spoolss_EnumPrintProcessors
430 : **********************************************************************/
431 :
432 0 : WERROR rpccli_spoolss_enumprintprocessors(struct rpc_pipe_client *cli,
433 : TALLOC_CTX *mem_ctx,
434 : const char *servername,
435 : const char *environment,
436 : uint32_t level,
437 : uint32_t offered,
438 : uint32_t *count,
439 : union spoolss_PrintProcessorInfo **info)
440 : {
441 0 : NTSTATUS status;
442 0 : WERROR werror;
443 0 : uint32_t needed;
444 0 : DATA_BLOB buffer;
445 0 : struct dcerpc_binding_handle *b = cli->binding_handle;
446 :
447 0 : if (offered > 0) {
448 0 : buffer = data_blob_talloc_zero(mem_ctx, offered);
449 0 : W_ERROR_HAVE_NO_MEMORY(buffer.data);
450 : }
451 :
452 0 : status = dcerpc_spoolss_EnumPrintProcessors(b, mem_ctx,
453 : servername,
454 : environment,
455 : level,
456 : (offered > 0) ? &buffer : NULL,
457 : offered,
458 : count,
459 : info,
460 : &needed,
461 : &werror);
462 0 : if (!NT_STATUS_IS_OK(status)) {
463 0 : return ntstatus_to_werror(status);
464 : }
465 :
466 0 : if (W_ERROR_EQUAL(werror, WERR_INSUFFICIENT_BUFFER)) {
467 0 : offered = needed;
468 0 : buffer = data_blob_talloc_zero(mem_ctx, needed);
469 0 : W_ERROR_HAVE_NO_MEMORY(buffer.data);
470 :
471 0 : status = dcerpc_spoolss_EnumPrintProcessors(b, mem_ctx,
472 : servername,
473 : environment,
474 : level,
475 : (offered > 0) ? &buffer : NULL,
476 : offered,
477 : count,
478 : info,
479 : &needed,
480 : &werror);
481 : }
482 0 : if (!NT_STATUS_IS_OK(status)) {
483 0 : return ntstatus_to_werror(status);
484 : }
485 :
486 0 : return werror;
487 : }
488 :
489 : /**********************************************************************
490 : convenience wrapper around rpccli_spoolss_EnumPrintProcessorDataTypes
491 : **********************************************************************/
492 :
493 0 : WERROR rpccli_spoolss_enumprintprocessordatatypes(struct rpc_pipe_client *cli,
494 : TALLOC_CTX *mem_ctx,
495 : const char *servername,
496 : const char *print_processor_name,
497 : uint32_t level,
498 : uint32_t offered,
499 : uint32_t *count,
500 : union spoolss_PrintProcDataTypesInfo **info)
501 : {
502 0 : NTSTATUS status;
503 0 : WERROR werror;
504 0 : uint32_t needed;
505 0 : DATA_BLOB buffer;
506 0 : struct dcerpc_binding_handle *b = cli->binding_handle;
507 :
508 0 : if (offered > 0) {
509 0 : buffer = data_blob_talloc_zero(mem_ctx, offered);
510 0 : W_ERROR_HAVE_NO_MEMORY(buffer.data);
511 : }
512 :
513 0 : status = dcerpc_spoolss_EnumPrintProcessorDataTypes(b, mem_ctx,
514 : servername,
515 : print_processor_name,
516 : level,
517 : (offered > 0) ? &buffer : NULL,
518 : offered,
519 : count,
520 : info,
521 : &needed,
522 : &werror);
523 0 : if (!NT_STATUS_IS_OK(status)) {
524 0 : return ntstatus_to_werror(status);
525 : }
526 :
527 0 : if (W_ERROR_EQUAL(werror, WERR_INSUFFICIENT_BUFFER)) {
528 0 : offered = needed;
529 0 : buffer = data_blob_talloc_zero(mem_ctx, needed);
530 0 : W_ERROR_HAVE_NO_MEMORY(buffer.data);
531 :
532 0 : status = dcerpc_spoolss_EnumPrintProcessorDataTypes(b, mem_ctx,
533 : servername,
534 : print_processor_name,
535 : level,
536 : (offered > 0) ? &buffer : NULL,
537 : offered,
538 : count,
539 : info,
540 : &needed,
541 : &werror);
542 : }
543 0 : if (!NT_STATUS_IS_OK(status)) {
544 0 : return ntstatus_to_werror(status);
545 : }
546 :
547 0 : return werror;
548 : }
549 :
550 : /**********************************************************************
551 : convenience wrapper around rpccli_spoolss_EnumPorts
552 : **********************************************************************/
553 :
554 0 : WERROR rpccli_spoolss_enumports(struct rpc_pipe_client *cli,
555 : TALLOC_CTX *mem_ctx,
556 : const char *servername,
557 : uint32_t level,
558 : uint32_t offered,
559 : uint32_t *count,
560 : union spoolss_PortInfo **info)
561 : {
562 0 : NTSTATUS status;
563 0 : WERROR werror;
564 0 : uint32_t needed;
565 0 : DATA_BLOB buffer;
566 0 : struct dcerpc_binding_handle *b = cli->binding_handle;
567 :
568 0 : if (offered > 0) {
569 0 : buffer = data_blob_talloc_zero(mem_ctx, offered);
570 0 : W_ERROR_HAVE_NO_MEMORY(buffer.data);
571 : }
572 :
573 0 : status = dcerpc_spoolss_EnumPorts(b, mem_ctx,
574 : servername,
575 : level,
576 : (offered > 0) ? &buffer : NULL,
577 : offered,
578 : count,
579 : info,
580 : &needed,
581 : &werror);
582 0 : if (!NT_STATUS_IS_OK(status)) {
583 0 : return ntstatus_to_werror(status);
584 : }
585 :
586 0 : if (W_ERROR_EQUAL(werror, WERR_INSUFFICIENT_BUFFER)) {
587 0 : offered = needed;
588 0 : buffer = data_blob_talloc_zero(mem_ctx, needed);
589 0 : W_ERROR_HAVE_NO_MEMORY(buffer.data);
590 :
591 0 : status = dcerpc_spoolss_EnumPorts(b, mem_ctx,
592 : servername,
593 : level,
594 : (offered > 0) ? &buffer : NULL,
595 : offered,
596 : count,
597 : info,
598 : &needed,
599 : &werror);
600 : }
601 0 : if (!NT_STATUS_IS_OK(status)) {
602 0 : return ntstatus_to_werror(status);
603 : }
604 :
605 0 : return werror;
606 : }
607 :
608 : /**********************************************************************
609 : convenience wrapper around rpccli_spoolss_EnumMonitors
610 : **********************************************************************/
611 :
612 0 : WERROR rpccli_spoolss_enummonitors(struct rpc_pipe_client *cli,
613 : TALLOC_CTX *mem_ctx,
614 : const char *servername,
615 : uint32_t level,
616 : uint32_t offered,
617 : uint32_t *count,
618 : union spoolss_MonitorInfo **info)
619 : {
620 0 : NTSTATUS status;
621 0 : WERROR werror;
622 0 : uint32_t needed;
623 0 : DATA_BLOB buffer;
624 0 : struct dcerpc_binding_handle *b = cli->binding_handle;
625 :
626 0 : if (offered > 0) {
627 0 : buffer = data_blob_talloc_zero(mem_ctx, offered);
628 0 : W_ERROR_HAVE_NO_MEMORY(buffer.data);
629 : }
630 :
631 0 : status = dcerpc_spoolss_EnumMonitors(b, mem_ctx,
632 : servername,
633 : level,
634 : (offered > 0) ? &buffer : NULL,
635 : offered,
636 : count,
637 : info,
638 : &needed,
639 : &werror);
640 0 : if (!NT_STATUS_IS_OK(status)) {
641 0 : return ntstatus_to_werror(status);
642 : }
643 :
644 0 : if (W_ERROR_EQUAL(werror, WERR_INSUFFICIENT_BUFFER)) {
645 0 : offered = needed;
646 0 : buffer = data_blob_talloc_zero(mem_ctx, needed);
647 0 : W_ERROR_HAVE_NO_MEMORY(buffer.data);
648 :
649 0 : status = dcerpc_spoolss_EnumMonitors(b, mem_ctx,
650 : servername,
651 : level,
652 : (offered > 0) ? &buffer : NULL,
653 : offered,
654 : count,
655 : info,
656 : &needed,
657 : &werror);
658 : }
659 0 : if (!NT_STATUS_IS_OK(status)) {
660 0 : return ntstatus_to_werror(status);
661 : }
662 :
663 0 : return werror;
664 : }
665 :
666 : /**********************************************************************
667 : convenience wrapper around rpccli_spoolss_EnumJobs
668 : **********************************************************************/
669 :
670 6 : WERROR rpccli_spoolss_enumjobs(struct rpc_pipe_client *cli,
671 : TALLOC_CTX *mem_ctx,
672 : struct policy_handle *handle,
673 : uint32_t firstjob,
674 : uint32_t numjobs,
675 : uint32_t level,
676 : uint32_t offered,
677 : uint32_t *count,
678 : union spoolss_JobInfo **info)
679 : {
680 0 : NTSTATUS status;
681 0 : WERROR werror;
682 0 : uint32_t needed;
683 0 : DATA_BLOB buffer;
684 6 : struct dcerpc_binding_handle *b = cli->binding_handle;
685 :
686 6 : if (offered > 0) {
687 0 : buffer = data_blob_talloc_zero(mem_ctx, offered);
688 0 : W_ERROR_HAVE_NO_MEMORY(buffer.data);
689 : }
690 :
691 6 : status = dcerpc_spoolss_EnumJobs(b, mem_ctx,
692 : handle,
693 : firstjob,
694 : numjobs,
695 : level,
696 : (offered > 0) ? &buffer : NULL,
697 : offered,
698 : count,
699 : info,
700 : &needed,
701 : &werror);
702 6 : if (!NT_STATUS_IS_OK(status)) {
703 0 : return ntstatus_to_werror(status);
704 : }
705 :
706 6 : if (W_ERROR_EQUAL(werror, WERR_INSUFFICIENT_BUFFER)) {
707 4 : offered = needed;
708 4 : buffer = data_blob_talloc_zero(mem_ctx, needed);
709 4 : W_ERROR_HAVE_NO_MEMORY(buffer.data);
710 :
711 4 : status = dcerpc_spoolss_EnumJobs(b, mem_ctx,
712 : handle,
713 : firstjob,
714 : numjobs,
715 : level,
716 : (offered > 0) ? &buffer : NULL,
717 : offered,
718 : count,
719 : info,
720 : &needed,
721 : &werror);
722 : }
723 6 : if (!NT_STATUS_IS_OK(status)) {
724 0 : return ntstatus_to_werror(status);
725 : }
726 :
727 6 : return werror;
728 : }
729 :
730 : /**********************************************************************
731 : convenience wrapper around rpccli_spoolss_EnumPrinterDrivers
732 : **********************************************************************/
733 :
734 0 : WERROR rpccli_spoolss_enumprinterdrivers(struct rpc_pipe_client *cli,
735 : TALLOC_CTX *mem_ctx,
736 : const char *server,
737 : const char *environment,
738 : uint32_t level,
739 : uint32_t offered,
740 : uint32_t *count,
741 : union spoolss_DriverInfo **info)
742 : {
743 0 : NTSTATUS status;
744 0 : WERROR werror;
745 0 : uint32_t needed;
746 0 : DATA_BLOB buffer;
747 0 : struct dcerpc_binding_handle *b = cli->binding_handle;
748 :
749 0 : if (offered > 0) {
750 0 : buffer = data_blob_talloc_zero(mem_ctx, offered);
751 0 : W_ERROR_HAVE_NO_MEMORY(buffer.data);
752 : }
753 :
754 0 : status = dcerpc_spoolss_EnumPrinterDrivers(b, mem_ctx,
755 : server,
756 : environment,
757 : level,
758 : (offered > 0) ? &buffer : NULL,
759 : offered,
760 : count,
761 : info,
762 : &needed,
763 : &werror);
764 0 : if (!NT_STATUS_IS_OK(status)) {
765 0 : return ntstatus_to_werror(status);
766 : }
767 :
768 0 : if (W_ERROR_EQUAL(werror, WERR_INSUFFICIENT_BUFFER)) {
769 0 : offered = needed;
770 0 : buffer = data_blob_talloc_zero(mem_ctx, needed);
771 0 : W_ERROR_HAVE_NO_MEMORY(buffer.data);
772 :
773 0 : status = dcerpc_spoolss_EnumPrinterDrivers(b, mem_ctx,
774 : server,
775 : environment,
776 : level,
777 : (offered > 0) ? &buffer : NULL,
778 : offered,
779 : count,
780 : info,
781 : &needed,
782 : &werror);
783 : }
784 0 : if (!NT_STATUS_IS_OK(status)) {
785 0 : return ntstatus_to_werror(status);
786 : }
787 :
788 0 : return werror;
789 : }
790 :
791 : /**********************************************************************
792 : convenience wrapper around rpccli_spoolss_EnumPrinters
793 : **********************************************************************/
794 :
795 0 : WERROR rpccli_spoolss_enumprinters(struct rpc_pipe_client *cli,
796 : TALLOC_CTX *mem_ctx,
797 : uint32_t flags,
798 : const char *server,
799 : uint32_t level,
800 : uint32_t offered,
801 : uint32_t *count,
802 : union spoolss_PrinterInfo **info)
803 : {
804 0 : NTSTATUS status;
805 0 : WERROR werror;
806 0 : uint32_t needed;
807 0 : DATA_BLOB buffer;
808 0 : struct dcerpc_binding_handle *b = cli->binding_handle;
809 :
810 0 : if (offered > 0) {
811 0 : buffer = data_blob_talloc_zero(mem_ctx, offered);
812 0 : W_ERROR_HAVE_NO_MEMORY(buffer.data);
813 : }
814 :
815 0 : status = dcerpc_spoolss_EnumPrinters(b, mem_ctx,
816 : flags,
817 : server,
818 : level,
819 : (offered > 0) ? &buffer : NULL,
820 : offered,
821 : count,
822 : info,
823 : &needed,
824 : &werror);
825 0 : if (!NT_STATUS_IS_OK(status)) {
826 0 : return ntstatus_to_werror(status);
827 : }
828 :
829 0 : if (W_ERROR_EQUAL(werror, WERR_INSUFFICIENT_BUFFER)) {
830 0 : offered = needed;
831 0 : buffer = data_blob_talloc_zero(mem_ctx, needed);
832 0 : W_ERROR_HAVE_NO_MEMORY(buffer.data);
833 :
834 0 : status = dcerpc_spoolss_EnumPrinters(b, mem_ctx,
835 : flags,
836 : server,
837 : level,
838 : (offered > 0) ? &buffer : NULL,
839 : offered,
840 : count,
841 : info,
842 : &needed,
843 : &werror);
844 : }
845 0 : if (!NT_STATUS_IS_OK(status)) {
846 0 : return ntstatus_to_werror(status);
847 : }
848 :
849 0 : return werror;
850 : }
851 :
852 : /**********************************************************************
853 : convenience wrapper around rpccli_spoolss_GetPrinterData
854 : **********************************************************************/
855 :
856 0 : WERROR rpccli_spoolss_getprinterdata(struct rpc_pipe_client *cli,
857 : TALLOC_CTX *mem_ctx,
858 : struct policy_handle *handle,
859 : const char *value_name,
860 : uint32_t offered,
861 : enum winreg_Type *type,
862 : uint32_t *needed_p,
863 : uint8_t **data_p)
864 : {
865 0 : NTSTATUS status;
866 0 : WERROR werror;
867 0 : uint32_t needed;
868 0 : uint8_t *data;
869 0 : struct dcerpc_binding_handle *b = cli->binding_handle;
870 :
871 0 : data = talloc_zero_array(mem_ctx, uint8_t, offered);
872 0 : W_ERROR_HAVE_NO_MEMORY(data);
873 :
874 0 : status = dcerpc_spoolss_GetPrinterData(b, mem_ctx,
875 : handle,
876 : value_name,
877 : type,
878 : data,
879 : offered,
880 : &needed,
881 : &werror);
882 0 : if (!NT_STATUS_IS_OK(status)) {
883 0 : return ntstatus_to_werror(status);
884 : }
885 :
886 0 : if (W_ERROR_EQUAL(werror, WERR_MORE_DATA)) {
887 0 : offered = needed;
888 0 : data = talloc_zero_array(mem_ctx, uint8_t, offered);
889 0 : W_ERROR_HAVE_NO_MEMORY(data);
890 :
891 0 : status = dcerpc_spoolss_GetPrinterData(b, mem_ctx,
892 : handle,
893 : value_name,
894 : type,
895 : data,
896 : offered,
897 : &needed,
898 : &werror);
899 : }
900 0 : if (!NT_STATUS_IS_OK(status)) {
901 0 : return ntstatus_to_werror(status);
902 : }
903 :
904 0 : *data_p = data;
905 0 : *needed_p = needed;
906 :
907 0 : return werror;
908 : }
909 :
910 : /**********************************************************************
911 : convenience wrapper around rpccli_spoolss_EnumPrinterKey
912 : **********************************************************************/
913 :
914 0 : WERROR rpccli_spoolss_enumprinterkey(struct rpc_pipe_client *cli,
915 : TALLOC_CTX *mem_ctx,
916 : struct policy_handle *handle,
917 : const char *key_name,
918 : const char ***key_buffer,
919 : uint32_t offered)
920 : {
921 0 : NTSTATUS status;
922 0 : WERROR werror;
923 0 : uint32_t needed;
924 0 : union spoolss_KeyNames _key_buffer;
925 0 : uint32_t _ndr_size;
926 0 : struct dcerpc_binding_handle *b = cli->binding_handle;
927 :
928 0 : status = dcerpc_spoolss_EnumPrinterKey(b, mem_ctx,
929 : handle,
930 : key_name,
931 : &_ndr_size,
932 : &_key_buffer,
933 : offered,
934 : &needed,
935 : &werror);
936 0 : if (!NT_STATUS_IS_OK(status)) {
937 0 : return ntstatus_to_werror(status);
938 : }
939 :
940 0 : if (W_ERROR_EQUAL(werror, WERR_MORE_DATA)) {
941 0 : offered = needed;
942 0 : status = dcerpc_spoolss_EnumPrinterKey(b, mem_ctx,
943 : handle,
944 : key_name,
945 : &_ndr_size,
946 : &_key_buffer,
947 : offered,
948 : &needed,
949 : &werror);
950 : }
951 0 : if (!NT_STATUS_IS_OK(status)) {
952 0 : return ntstatus_to_werror(status);
953 : }
954 :
955 0 : *key_buffer = _key_buffer.string_array;
956 :
957 0 : return werror;
958 : }
959 :
960 : /**********************************************************************
961 : convenience wrapper around rpccli_spoolss_EnumPrinterDataEx
962 : **********************************************************************/
963 :
964 0 : WERROR rpccli_spoolss_enumprinterdataex(struct rpc_pipe_client *cli,
965 : TALLOC_CTX *mem_ctx,
966 : struct policy_handle *handle,
967 : const char *key_name,
968 : uint32_t offered,
969 : uint32_t *count,
970 : struct spoolss_PrinterEnumValues **info)
971 : {
972 0 : NTSTATUS status;
973 0 : WERROR werror;
974 0 : uint32_t needed;
975 0 : struct dcerpc_binding_handle *b = cli->binding_handle;
976 :
977 0 : status = dcerpc_spoolss_EnumPrinterDataEx(b, mem_ctx,
978 : handle,
979 : key_name,
980 : offered,
981 : count,
982 : info,
983 : &needed,
984 : &werror);
985 0 : if (!NT_STATUS_IS_OK(status)) {
986 0 : return ntstatus_to_werror(status);
987 : }
988 :
989 0 : if (W_ERROR_EQUAL(werror, WERR_MORE_DATA)) {
990 0 : offered = needed;
991 :
992 0 : status = dcerpc_spoolss_EnumPrinterDataEx(b, mem_ctx,
993 : handle,
994 : key_name,
995 : offered,
996 : count,
997 : info,
998 : &needed,
999 : &werror);
1000 : }
1001 0 : if (!NT_STATUS_IS_OK(status)) {
1002 0 : return ntstatus_to_werror(status);
1003 : }
1004 :
1005 0 : return werror;
1006 : }
|