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 "rpc_client/rpc_client.h"
27 #include "../librpc/gen_ndr/ndr_spoolss_c.h"
28 #include "rpc_client/cli_spoolss.h"
30 /**********************************************************************
31 convencience wrapper around rpccli_spoolss_OpenPrinterEx
32 **********************************************************************/
34 WERROR
rpccli_spoolss_openprinter_ex(struct rpc_pipe_client
*cli
,
36 const char *printername
,
37 uint32_t access_desired
,
38 struct policy_handle
*handle
)
42 struct spoolss_DevmodeContainer devmode_ctr
;
43 union spoolss_UserLevel userlevel
;
44 struct spoolss_UserLevel1 level1
;
45 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
47 ZERO_STRUCT(devmode_ctr
);
50 level1
.client
= talloc_asprintf(mem_ctx
, "\\\\%s", lp_netbios_name());
51 W_ERROR_HAVE_NO_MEMORY(level1
.client
);
52 level1
.user
= cli
->auth
->user_name
;
58 userlevel
.level1
= &level1
;
60 status
= dcerpc_spoolss_OpenPrinterEx(b
, mem_ctx
,
70 if (!NT_STATUS_IS_OK(status
)) {
71 return ntstatus_to_werror(status
);
74 if (!W_ERROR_IS_OK(werror
)) {
81 /**********************************************************************
82 convencience wrapper around rpccli_spoolss_GetPrinterDriver
83 **********************************************************************/
85 WERROR
rpccli_spoolss_getprinterdriver(struct rpc_pipe_client
*cli
,
87 struct policy_handle
*handle
,
88 const char *architecture
,
91 union spoolss_DriverInfo
*info
)
97 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
100 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
101 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
104 status
= dcerpc_spoolss_GetPrinterDriver(b
, mem_ctx
,
108 (offered
> 0) ? &buffer
: NULL
,
113 if (!NT_STATUS_IS_OK(status
)) {
114 return ntstatus_to_werror(status
);
116 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
118 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
119 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
121 status
= dcerpc_spoolss_GetPrinterDriver(b
, mem_ctx
,
131 if (!NT_STATUS_IS_OK(status
)) {
132 return ntstatus_to_werror(status
);
138 /**********************************************************************
139 convencience wrapper around rpccli_spoolss_GetPrinterDriver2
140 **********************************************************************/
142 WERROR
rpccli_spoolss_getprinterdriver2(struct rpc_pipe_client
*cli
,
144 struct policy_handle
*handle
,
145 const char *architecture
,
148 uint32_t client_major_version
,
149 uint32_t client_minor_version
,
150 union spoolss_DriverInfo
*info
,
151 uint32_t *server_major_version
,
152 uint32_t *server_minor_version
)
158 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
161 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
162 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
165 status
= dcerpc_spoolss_GetPrinterDriver2(b
, mem_ctx
,
169 (offered
> 0) ? &buffer
: NULL
,
171 client_major_version
,
172 client_minor_version
,
175 server_major_version
,
176 server_minor_version
,
178 if (!NT_STATUS_IS_OK(status
)) {
179 return ntstatus_to_werror(status
);
182 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
184 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
185 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
187 status
= dcerpc_spoolss_GetPrinterDriver2(b
, mem_ctx
,
193 client_major_version
,
194 client_minor_version
,
197 server_major_version
,
198 server_minor_version
,
201 if (!NT_STATUS_IS_OK(status
)) {
202 return ntstatus_to_werror(status
);
208 /**********************************************************************
209 convencience wrapper around rpccli_spoolss_AddPrinterEx
210 **********************************************************************/
212 WERROR
rpccli_spoolss_addprinterex(struct rpc_pipe_client
*cli
,
214 struct spoolss_SetPrinterInfoCtr
*info_ctr
)
218 struct spoolss_DevmodeContainer devmode_ctr
;
219 struct sec_desc_buf secdesc_ctr
;
220 struct spoolss_UserLevelCtr userlevel_ctr
;
221 struct spoolss_UserLevel1 level1
;
222 struct policy_handle handle
;
223 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
225 ZERO_STRUCT(devmode_ctr
);
226 ZERO_STRUCT(secdesc_ctr
);
232 level1
.processor
= 0;
233 level1
.client
= talloc_asprintf(mem_ctx
, "\\\\%s", lp_netbios_name());
234 W_ERROR_HAVE_NO_MEMORY(level1
.client
);
235 level1
.user
= cli
->auth
->user_name
;
237 userlevel_ctr
.level
= 1;
238 userlevel_ctr
.user_info
.level1
= &level1
;
240 status
= dcerpc_spoolss_AddPrinterEx(b
, mem_ctx
,
248 if (!NT_STATUS_IS_OK(status
)) {
249 return ntstatus_to_werror(status
);
255 /**********************************************************************
256 convencience wrapper around rpccli_spoolss_GetPrinter
257 **********************************************************************/
259 WERROR
rpccli_spoolss_getprinter(struct rpc_pipe_client
*cli
,
261 struct policy_handle
*handle
,
264 union spoolss_PrinterInfo
*info
)
270 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
273 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
274 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
277 status
= dcerpc_spoolss_GetPrinter(b
, mem_ctx
,
280 (offered
> 0) ? &buffer
: NULL
,
285 if (!NT_STATUS_IS_OK(status
)) {
286 return ntstatus_to_werror(status
);
289 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
292 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
293 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
295 status
= dcerpc_spoolss_GetPrinter(b
, mem_ctx
,
304 if (!NT_STATUS_IS_OK(status
)) {
305 return ntstatus_to_werror(status
);
311 /**********************************************************************
312 convencience wrapper around rpccli_spoolss_GetJob
313 **********************************************************************/
315 WERROR
rpccli_spoolss_getjob(struct rpc_pipe_client
*cli
,
317 struct policy_handle
*handle
,
321 union spoolss_JobInfo
*info
)
327 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
330 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
331 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
334 status
= dcerpc_spoolss_GetJob(b
, mem_ctx
,
338 (offered
> 0) ? &buffer
: NULL
,
343 if (!NT_STATUS_IS_OK(status
)) {
344 return ntstatus_to_werror(status
);
347 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
349 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
350 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
352 status
= dcerpc_spoolss_GetJob(b
, mem_ctx
,
362 if (!NT_STATUS_IS_OK(status
)) {
363 return ntstatus_to_werror(status
);
369 /**********************************************************************
370 convencience wrapper around rpccli_spoolss_EnumForms
371 **********************************************************************/
373 WERROR
rpccli_spoolss_enumforms(struct rpc_pipe_client
*cli
,
375 struct policy_handle
*handle
,
379 union spoolss_FormInfo
**info
)
385 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
388 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
389 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
392 status
= dcerpc_spoolss_EnumForms(b
, mem_ctx
,
395 (offered
> 0) ? &buffer
: NULL
,
401 if (!NT_STATUS_IS_OK(status
)) {
402 return ntstatus_to_werror(status
);
405 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
407 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
408 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
410 status
= dcerpc_spoolss_EnumForms(b
, mem_ctx
,
413 (offered
> 0) ? &buffer
: NULL
,
420 if (!NT_STATUS_IS_OK(status
)) {
421 return ntstatus_to_werror(status
);
427 /**********************************************************************
428 convencience wrapper around rpccli_spoolss_EnumPrintProcessors
429 **********************************************************************/
431 WERROR
rpccli_spoolss_enumprintprocessors(struct rpc_pipe_client
*cli
,
433 const char *servername
,
434 const char *environment
,
438 union spoolss_PrintProcessorInfo
**info
)
444 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
447 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
448 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
451 status
= dcerpc_spoolss_EnumPrintProcessors(b
, mem_ctx
,
455 (offered
> 0) ? &buffer
: NULL
,
461 if (!NT_STATUS_IS_OK(status
)) {
462 return ntstatus_to_werror(status
);
465 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
467 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
468 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
470 status
= dcerpc_spoolss_EnumPrintProcessors(b
, mem_ctx
,
474 (offered
> 0) ? &buffer
: NULL
,
481 if (!NT_STATUS_IS_OK(status
)) {
482 return ntstatus_to_werror(status
);
488 /**********************************************************************
489 convencience wrapper around rpccli_spoolss_EnumPrintProcDataTypes
490 **********************************************************************/
492 WERROR
rpccli_spoolss_enumprintprocessordatatypes(struct rpc_pipe_client
*cli
,
494 const char *servername
,
495 const char *print_processor_name
,
499 union spoolss_PrintProcDataTypesInfo
**info
)
505 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
508 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
509 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
512 status
= dcerpc_spoolss_EnumPrintProcDataTypes(b
, mem_ctx
,
514 print_processor_name
,
516 (offered
> 0) ? &buffer
: NULL
,
522 if (!NT_STATUS_IS_OK(status
)) {
523 return ntstatus_to_werror(status
);
526 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
528 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
529 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
531 status
= dcerpc_spoolss_EnumPrintProcDataTypes(b
, mem_ctx
,
533 print_processor_name
,
535 (offered
> 0) ? &buffer
: NULL
,
542 if (!NT_STATUS_IS_OK(status
)) {
543 return ntstatus_to_werror(status
);
549 /**********************************************************************
550 convencience wrapper around rpccli_spoolss_EnumPorts
551 **********************************************************************/
553 WERROR
rpccli_spoolss_enumports(struct rpc_pipe_client
*cli
,
555 const char *servername
,
559 union spoolss_PortInfo
**info
)
565 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
568 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
569 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
572 status
= dcerpc_spoolss_EnumPorts(b
, mem_ctx
,
575 (offered
> 0) ? &buffer
: NULL
,
581 if (!NT_STATUS_IS_OK(status
)) {
582 return ntstatus_to_werror(status
);
585 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
587 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
588 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
590 status
= dcerpc_spoolss_EnumPorts(b
, mem_ctx
,
593 (offered
> 0) ? &buffer
: NULL
,
600 if (!NT_STATUS_IS_OK(status
)) {
601 return ntstatus_to_werror(status
);
607 /**********************************************************************
608 convencience wrapper around rpccli_spoolss_EnumMonitors
609 **********************************************************************/
611 WERROR
rpccli_spoolss_enummonitors(struct rpc_pipe_client
*cli
,
613 const char *servername
,
617 union spoolss_MonitorInfo
**info
)
623 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
626 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
627 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
630 status
= dcerpc_spoolss_EnumMonitors(b
, mem_ctx
,
633 (offered
> 0) ? &buffer
: NULL
,
639 if (!NT_STATUS_IS_OK(status
)) {
640 return ntstatus_to_werror(status
);
643 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
645 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
646 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
648 status
= dcerpc_spoolss_EnumMonitors(b
, mem_ctx
,
651 (offered
> 0) ? &buffer
: NULL
,
658 if (!NT_STATUS_IS_OK(status
)) {
659 return ntstatus_to_werror(status
);
665 /**********************************************************************
666 convencience wrapper around rpccli_spoolss_EnumJobs
667 **********************************************************************/
669 WERROR
rpccli_spoolss_enumjobs(struct rpc_pipe_client
*cli
,
671 struct policy_handle
*handle
,
677 union spoolss_JobInfo
**info
)
683 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
686 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
687 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
690 status
= dcerpc_spoolss_EnumJobs(b
, mem_ctx
,
695 (offered
> 0) ? &buffer
: NULL
,
701 if (!NT_STATUS_IS_OK(status
)) {
702 return ntstatus_to_werror(status
);
705 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
707 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
708 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
710 status
= dcerpc_spoolss_EnumJobs(b
, mem_ctx
,
715 (offered
> 0) ? &buffer
: NULL
,
722 if (!NT_STATUS_IS_OK(status
)) {
723 return ntstatus_to_werror(status
);
729 /**********************************************************************
730 convencience wrapper around rpccli_spoolss_EnumPrinterDrivers
731 **********************************************************************/
733 WERROR
rpccli_spoolss_enumprinterdrivers(struct rpc_pipe_client
*cli
,
736 const char *environment
,
740 union spoolss_DriverInfo
**info
)
746 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
749 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
750 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
753 status
= dcerpc_spoolss_EnumPrinterDrivers(b
, mem_ctx
,
757 (offered
> 0) ? &buffer
: NULL
,
763 if (!NT_STATUS_IS_OK(status
)) {
764 return ntstatus_to_werror(status
);
767 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
769 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
770 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
772 status
= dcerpc_spoolss_EnumPrinterDrivers(b
, mem_ctx
,
776 (offered
> 0) ? &buffer
: NULL
,
783 if (!NT_STATUS_IS_OK(status
)) {
784 return ntstatus_to_werror(status
);
790 /**********************************************************************
791 convencience wrapper around rpccli_spoolss_EnumPrinters
792 **********************************************************************/
794 WERROR
rpccli_spoolss_enumprinters(struct rpc_pipe_client
*cli
,
801 union spoolss_PrinterInfo
**info
)
807 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
810 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
811 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
814 status
= dcerpc_spoolss_EnumPrinters(b
, mem_ctx
,
818 (offered
> 0) ? &buffer
: NULL
,
824 if (!NT_STATUS_IS_OK(status
)) {
825 return ntstatus_to_werror(status
);
828 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
830 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
831 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
833 status
= dcerpc_spoolss_EnumPrinters(b
, mem_ctx
,
837 (offered
> 0) ? &buffer
: NULL
,
844 if (!NT_STATUS_IS_OK(status
)) {
845 return ntstatus_to_werror(status
);
851 /**********************************************************************
852 convencience wrapper around rpccli_spoolss_GetPrinterData
853 **********************************************************************/
855 WERROR
rpccli_spoolss_getprinterdata(struct rpc_pipe_client
*cli
,
857 struct policy_handle
*handle
,
858 const char *value_name
,
860 enum winreg_Type
*type
,
868 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
870 data
= talloc_zero_array(mem_ctx
, uint8_t, offered
);
871 W_ERROR_HAVE_NO_MEMORY(data
);
873 status
= dcerpc_spoolss_GetPrinterData(b
, mem_ctx
,
881 if (!NT_STATUS_IS_OK(status
)) {
882 return ntstatus_to_werror(status
);
885 if (W_ERROR_EQUAL(werror
, WERR_MORE_DATA
)) {
887 data
= talloc_zero_array(mem_ctx
, uint8_t, offered
);
888 W_ERROR_HAVE_NO_MEMORY(data
);
890 status
= dcerpc_spoolss_GetPrinterData(b
, mem_ctx
,
899 if (!NT_STATUS_IS_OK(status
)) {
900 return ntstatus_to_werror(status
);
909 /**********************************************************************
910 convencience wrapper around rpccli_spoolss_EnumPrinterKey
911 **********************************************************************/
913 WERROR
rpccli_spoolss_enumprinterkey(struct rpc_pipe_client
*cli
,
915 struct policy_handle
*handle
,
916 const char *key_name
,
917 const char ***key_buffer
,
923 union spoolss_KeyNames _key_buffer
;
925 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
927 status
= dcerpc_spoolss_EnumPrinterKey(b
, mem_ctx
,
935 if (!NT_STATUS_IS_OK(status
)) {
936 return ntstatus_to_werror(status
);
939 if (W_ERROR_EQUAL(werror
, WERR_MORE_DATA
)) {
941 status
= dcerpc_spoolss_EnumPrinterKey(b
, mem_ctx
,
950 if (!NT_STATUS_IS_OK(status
)) {
951 return ntstatus_to_werror(status
);
954 *key_buffer
= _key_buffer
.string_array
;
959 /**********************************************************************
960 convencience wrapper around rpccli_spoolss_EnumPrinterDataEx
961 **********************************************************************/
963 WERROR
rpccli_spoolss_enumprinterdataex(struct rpc_pipe_client
*cli
,
965 struct policy_handle
*handle
,
966 const char *key_name
,
969 struct spoolss_PrinterEnumValues
**info
)
974 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
976 status
= dcerpc_spoolss_EnumPrinterDataEx(b
, mem_ctx
,
984 if (!NT_STATUS_IS_OK(status
)) {
985 return ntstatus_to_werror(status
);
988 if (W_ERROR_EQUAL(werror
, WERR_MORE_DATA
)) {
991 status
= dcerpc_spoolss_EnumPrinterDataEx(b
, mem_ctx
,
1000 if (!NT_STATUS_IS_OK(status
)) {
1001 return ntstatus_to_werror(status
);