2 Unix SMB/CIFS implementation.
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.
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.
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.
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/>.
26 #include "../librpc/gen_ndr/ndr_spoolss_c.h"
27 #include "rpc_client/cli_spoolss.h"
29 /**********************************************************************
30 convencience wrapper around rpccli_spoolss_OpenPrinterEx
31 **********************************************************************/
33 WERROR
rpccli_spoolss_openprinter_ex(struct rpc_pipe_client
*cli
,
35 const char *printername
,
36 uint32_t access_desired
,
37 struct policy_handle
*handle
)
41 struct spoolss_DevmodeContainer devmode_ctr
;
42 union spoolss_UserLevel userlevel
;
43 struct spoolss_UserLevel1 level1
;
44 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
46 ZERO_STRUCT(devmode_ctr
);
49 level1
.client
= talloc_asprintf(mem_ctx
, "\\\\%s", global_myname());
50 W_ERROR_HAVE_NO_MEMORY(level1
.client
);
51 level1
.user
= cli
->auth
->user_name
;
57 userlevel
.level1
= &level1
;
59 status
= dcerpc_spoolss_OpenPrinterEx(b
, mem_ctx
,
69 if (!NT_STATUS_IS_OK(status
)) {
70 return ntstatus_to_werror(status
);
73 if (!W_ERROR_IS_OK(werror
)) {
80 /**********************************************************************
81 convencience wrapper around rpccli_spoolss_GetPrinterDriver
82 **********************************************************************/
84 WERROR
rpccli_spoolss_getprinterdriver(struct rpc_pipe_client
*cli
,
86 struct policy_handle
*handle
,
87 const char *architecture
,
90 union spoolss_DriverInfo
*info
)
96 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
99 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
100 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
103 status
= dcerpc_spoolss_GetPrinterDriver(b
, mem_ctx
,
107 (offered
> 0) ? &buffer
: NULL
,
112 if (!NT_STATUS_IS_OK(status
)) {
113 return ntstatus_to_werror(status
);
115 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
117 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
118 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
120 status
= dcerpc_spoolss_GetPrinterDriver(b
, mem_ctx
,
130 if (!NT_STATUS_IS_OK(status
)) {
131 return ntstatus_to_werror(status
);
137 /**********************************************************************
138 convencience wrapper around rpccli_spoolss_GetPrinterDriver2
139 **********************************************************************/
141 WERROR
rpccli_spoolss_getprinterdriver2(struct rpc_pipe_client
*cli
,
143 struct policy_handle
*handle
,
144 const char *architecture
,
147 uint32_t client_major_version
,
148 uint32_t client_minor_version
,
149 union spoolss_DriverInfo
*info
,
150 uint32_t *server_major_version
,
151 uint32_t *server_minor_version
)
157 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
160 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
161 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
164 status
= dcerpc_spoolss_GetPrinterDriver2(b
, mem_ctx
,
168 (offered
> 0) ? &buffer
: NULL
,
170 client_major_version
,
171 client_minor_version
,
174 server_major_version
,
175 server_minor_version
,
177 if (!NT_STATUS_IS_OK(status
)) {
178 return ntstatus_to_werror(status
);
181 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
183 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
184 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
186 status
= dcerpc_spoolss_GetPrinterDriver2(b
, mem_ctx
,
192 client_major_version
,
193 client_minor_version
,
196 server_major_version
,
197 server_minor_version
,
200 if (!NT_STATUS_IS_OK(status
)) {
201 return ntstatus_to_werror(status
);
207 /**********************************************************************
208 convencience wrapper around rpccli_spoolss_AddPrinterEx
209 **********************************************************************/
211 WERROR
rpccli_spoolss_addprinterex(struct rpc_pipe_client
*cli
,
213 struct spoolss_SetPrinterInfoCtr
*info_ctr
)
217 struct spoolss_DevmodeContainer devmode_ctr
;
218 struct sec_desc_buf secdesc_ctr
;
219 struct spoolss_UserLevelCtr userlevel_ctr
;
220 struct spoolss_UserLevel1 level1
;
221 struct policy_handle handle
;
222 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
224 ZERO_STRUCT(devmode_ctr
);
225 ZERO_STRUCT(secdesc_ctr
);
231 level1
.processor
= 0;
232 level1
.client
= talloc_asprintf(mem_ctx
, "\\\\%s", global_myname());
233 W_ERROR_HAVE_NO_MEMORY(level1
.client
);
234 level1
.user
= cli
->auth
->user_name
;
236 userlevel_ctr
.level
= 1;
237 userlevel_ctr
.user_info
.level1
= &level1
;
239 status
= dcerpc_spoolss_AddPrinterEx(b
, mem_ctx
,
247 if (!NT_STATUS_IS_OK(status
)) {
248 return ntstatus_to_werror(status
);
254 /**********************************************************************
255 convencience wrapper around rpccli_spoolss_GetPrinter
256 **********************************************************************/
258 WERROR
rpccli_spoolss_getprinter(struct rpc_pipe_client
*cli
,
260 struct policy_handle
*handle
,
263 union spoolss_PrinterInfo
*info
)
269 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
272 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
273 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
276 status
= dcerpc_spoolss_GetPrinter(b
, mem_ctx
,
279 (offered
> 0) ? &buffer
: NULL
,
284 if (!NT_STATUS_IS_OK(status
)) {
285 return ntstatus_to_werror(status
);
288 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
291 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
292 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
294 status
= dcerpc_spoolss_GetPrinter(b
, mem_ctx
,
303 if (!NT_STATUS_IS_OK(status
)) {
304 return ntstatus_to_werror(status
);
310 /**********************************************************************
311 convencience wrapper around rpccli_spoolss_GetJob
312 **********************************************************************/
314 WERROR
rpccli_spoolss_getjob(struct rpc_pipe_client
*cli
,
316 struct policy_handle
*handle
,
320 union spoolss_JobInfo
*info
)
326 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
329 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
330 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
333 status
= dcerpc_spoolss_GetJob(b
, mem_ctx
,
337 (offered
> 0) ? &buffer
: NULL
,
342 if (!NT_STATUS_IS_OK(status
)) {
343 return ntstatus_to_werror(status
);
346 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
348 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
349 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
351 status
= dcerpc_spoolss_GetJob(b
, mem_ctx
,
361 if (!NT_STATUS_IS_OK(status
)) {
362 return ntstatus_to_werror(status
);
368 /**********************************************************************
369 convencience wrapper around rpccli_spoolss_EnumForms
370 **********************************************************************/
372 WERROR
rpccli_spoolss_enumforms(struct rpc_pipe_client
*cli
,
374 struct policy_handle
*handle
,
378 union spoolss_FormInfo
**info
)
384 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
387 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
388 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
391 status
= dcerpc_spoolss_EnumForms(b
, mem_ctx
,
394 (offered
> 0) ? &buffer
: NULL
,
400 if (!NT_STATUS_IS_OK(status
)) {
401 return ntstatus_to_werror(status
);
404 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
406 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
407 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
409 status
= dcerpc_spoolss_EnumForms(b
, mem_ctx
,
412 (offered
> 0) ? &buffer
: NULL
,
419 if (!NT_STATUS_IS_OK(status
)) {
420 return ntstatus_to_werror(status
);
426 /**********************************************************************
427 convencience wrapper around rpccli_spoolss_EnumPrintProcessors
428 **********************************************************************/
430 WERROR
rpccli_spoolss_enumprintprocessors(struct rpc_pipe_client
*cli
,
432 const char *servername
,
433 const char *environment
,
437 union spoolss_PrintProcessorInfo
**info
)
443 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
446 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
447 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
450 status
= dcerpc_spoolss_EnumPrintProcessors(b
, mem_ctx
,
454 (offered
> 0) ? &buffer
: NULL
,
460 if (!NT_STATUS_IS_OK(status
)) {
461 return ntstatus_to_werror(status
);
464 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
466 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
467 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
469 status
= dcerpc_spoolss_EnumPrintProcessors(b
, mem_ctx
,
473 (offered
> 0) ? &buffer
: NULL
,
480 if (!NT_STATUS_IS_OK(status
)) {
481 return ntstatus_to_werror(status
);
487 /**********************************************************************
488 convencience wrapper around rpccli_spoolss_EnumPrintProcDataTypes
489 **********************************************************************/
491 WERROR
rpccli_spoolss_enumprintprocessordatatypes(struct rpc_pipe_client
*cli
,
493 const char *servername
,
494 const char *print_processor_name
,
498 union spoolss_PrintProcDataTypesInfo
**info
)
504 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
507 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
508 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
511 status
= dcerpc_spoolss_EnumPrintProcDataTypes(b
, mem_ctx
,
513 print_processor_name
,
515 (offered
> 0) ? &buffer
: NULL
,
521 if (!NT_STATUS_IS_OK(status
)) {
522 return ntstatus_to_werror(status
);
525 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
527 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
528 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
530 status
= dcerpc_spoolss_EnumPrintProcDataTypes(b
, mem_ctx
,
532 print_processor_name
,
534 (offered
> 0) ? &buffer
: NULL
,
541 if (!NT_STATUS_IS_OK(status
)) {
542 return ntstatus_to_werror(status
);
548 /**********************************************************************
549 convencience wrapper around rpccli_spoolss_EnumPorts
550 **********************************************************************/
552 WERROR
rpccli_spoolss_enumports(struct rpc_pipe_client
*cli
,
554 const char *servername
,
558 union spoolss_PortInfo
**info
)
564 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
567 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
568 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
571 status
= dcerpc_spoolss_EnumPorts(b
, mem_ctx
,
574 (offered
> 0) ? &buffer
: NULL
,
580 if (!NT_STATUS_IS_OK(status
)) {
581 return ntstatus_to_werror(status
);
584 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
586 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
587 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
589 status
= dcerpc_spoolss_EnumPorts(b
, mem_ctx
,
592 (offered
> 0) ? &buffer
: NULL
,
599 if (!NT_STATUS_IS_OK(status
)) {
600 return ntstatus_to_werror(status
);
606 /**********************************************************************
607 convencience wrapper around rpccli_spoolss_EnumMonitors
608 **********************************************************************/
610 WERROR
rpccli_spoolss_enummonitors(struct rpc_pipe_client
*cli
,
612 const char *servername
,
616 union spoolss_MonitorInfo
**info
)
622 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
625 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
626 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
629 status
= dcerpc_spoolss_EnumMonitors(b
, mem_ctx
,
632 (offered
> 0) ? &buffer
: NULL
,
638 if (!NT_STATUS_IS_OK(status
)) {
639 return ntstatus_to_werror(status
);
642 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
644 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
645 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
647 status
= dcerpc_spoolss_EnumMonitors(b
, mem_ctx
,
650 (offered
> 0) ? &buffer
: NULL
,
657 if (!NT_STATUS_IS_OK(status
)) {
658 return ntstatus_to_werror(status
);
664 /**********************************************************************
665 convencience wrapper around rpccli_spoolss_EnumJobs
666 **********************************************************************/
668 WERROR
rpccli_spoolss_enumjobs(struct rpc_pipe_client
*cli
,
670 struct policy_handle
*handle
,
676 union spoolss_JobInfo
**info
)
682 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
685 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
686 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
689 status
= dcerpc_spoolss_EnumJobs(b
, mem_ctx
,
694 (offered
> 0) ? &buffer
: NULL
,
700 if (!NT_STATUS_IS_OK(status
)) {
701 return ntstatus_to_werror(status
);
704 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
706 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
707 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
709 status
= dcerpc_spoolss_EnumJobs(b
, mem_ctx
,
714 (offered
> 0) ? &buffer
: NULL
,
721 if (!NT_STATUS_IS_OK(status
)) {
722 return ntstatus_to_werror(status
);
728 /**********************************************************************
729 convencience wrapper around rpccli_spoolss_EnumPrinterDrivers
730 **********************************************************************/
732 WERROR
rpccli_spoolss_enumprinterdrivers(struct rpc_pipe_client
*cli
,
735 const char *environment
,
739 union spoolss_DriverInfo
**info
)
745 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
748 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
749 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
752 status
= dcerpc_spoolss_EnumPrinterDrivers(b
, mem_ctx
,
756 (offered
> 0) ? &buffer
: NULL
,
762 if (!NT_STATUS_IS_OK(status
)) {
763 return ntstatus_to_werror(status
);
766 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
768 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
769 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
771 status
= dcerpc_spoolss_EnumPrinterDrivers(b
, mem_ctx
,
775 (offered
> 0) ? &buffer
: NULL
,
782 if (!NT_STATUS_IS_OK(status
)) {
783 return ntstatus_to_werror(status
);
789 /**********************************************************************
790 convencience wrapper around rpccli_spoolss_EnumPrinters
791 **********************************************************************/
793 WERROR
rpccli_spoolss_enumprinters(struct rpc_pipe_client
*cli
,
800 union spoolss_PrinterInfo
**info
)
806 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
809 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
810 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
813 status
= dcerpc_spoolss_EnumPrinters(b
, mem_ctx
,
817 (offered
> 0) ? &buffer
: NULL
,
823 if (!NT_STATUS_IS_OK(status
)) {
824 return ntstatus_to_werror(status
);
827 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
829 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
830 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
832 status
= dcerpc_spoolss_EnumPrinters(b
, mem_ctx
,
836 (offered
> 0) ? &buffer
: NULL
,
843 if (!NT_STATUS_IS_OK(status
)) {
844 return ntstatus_to_werror(status
);
850 /**********************************************************************
851 convencience wrapper around rpccli_spoolss_GetPrinterData
852 **********************************************************************/
854 WERROR
rpccli_spoolss_getprinterdata(struct rpc_pipe_client
*cli
,
856 struct policy_handle
*handle
,
857 const char *value_name
,
859 enum winreg_Type
*type
,
867 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
869 data
= talloc_zero_array(mem_ctx
, uint8_t, offered
);
870 W_ERROR_HAVE_NO_MEMORY(data
);
872 status
= dcerpc_spoolss_GetPrinterData(b
, mem_ctx
,
880 if (!NT_STATUS_IS_OK(status
)) {
881 return ntstatus_to_werror(status
);
884 if (W_ERROR_EQUAL(werror
, WERR_MORE_DATA
)) {
886 data
= talloc_zero_array(mem_ctx
, uint8_t, offered
);
887 W_ERROR_HAVE_NO_MEMORY(data
);
889 status
= dcerpc_spoolss_GetPrinterData(b
, mem_ctx
,
898 if (!NT_STATUS_IS_OK(status
)) {
899 return ntstatus_to_werror(status
);
908 /**********************************************************************
909 convencience wrapper around rpccli_spoolss_EnumPrinterKey
910 **********************************************************************/
912 WERROR
rpccli_spoolss_enumprinterkey(struct rpc_pipe_client
*cli
,
914 struct policy_handle
*handle
,
915 const char *key_name
,
916 const char ***key_buffer
,
922 union spoolss_KeyNames _key_buffer
;
924 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
926 status
= dcerpc_spoolss_EnumPrinterKey(b
, mem_ctx
,
934 if (!NT_STATUS_IS_OK(status
)) {
935 return ntstatus_to_werror(status
);
938 if (W_ERROR_EQUAL(werror
, WERR_MORE_DATA
)) {
940 status
= dcerpc_spoolss_EnumPrinterKey(b
, mem_ctx
,
949 if (!NT_STATUS_IS_OK(status
)) {
950 return ntstatus_to_werror(status
);
953 *key_buffer
= _key_buffer
.string_array
;
958 /**********************************************************************
959 convencience wrapper around rpccli_spoolss_EnumPrinterDataEx
960 **********************************************************************/
962 WERROR
rpccli_spoolss_enumprinterdataex(struct rpc_pipe_client
*cli
,
964 struct policy_handle
*handle
,
965 const char *key_name
,
968 struct spoolss_PrinterEnumValues
**info
)
973 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
975 status
= dcerpc_spoolss_EnumPrinterDataEx(b
, mem_ctx
,
983 if (!NT_STATUS_IS_OK(status
)) {
984 return ntstatus_to_werror(status
);
987 if (W_ERROR_EQUAL(werror
, WERR_MORE_DATA
)) {
990 status
= dcerpc_spoolss_EnumPrinterDataEx(b
, mem_ctx
,
999 if (!NT_STATUS_IS_OK(status
)) {
1000 return ntstatus_to_werror(status
);