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/cli_spoolss.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
;
45 ZERO_STRUCT(devmode_ctr
);
48 level1
.client
= talloc_asprintf(mem_ctx
, "\\\\%s", global_myname());
49 W_ERROR_HAVE_NO_MEMORY(level1
.client
);
50 level1
.user
= cli
->auth
->user_name
;
56 userlevel
.level1
= &level1
;
58 status
= rpccli_spoolss_OpenPrinterEx(cli
, mem_ctx
,
68 if (!W_ERROR_IS_OK(werror
)) {
72 if (!NT_STATUS_IS_OK(status
)) {
73 return ntstatus_to_werror(status
);
79 /**********************************************************************
80 convencience wrapper around rpccli_spoolss_GetPrinterDriver
81 **********************************************************************/
83 WERROR
rpccli_spoolss_getprinterdriver(struct rpc_pipe_client
*cli
,
85 struct policy_handle
*handle
,
86 const char *architecture
,
89 union spoolss_DriverInfo
*info
)
97 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
98 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
101 status
= rpccli_spoolss_GetPrinterDriver(cli
, mem_ctx
,
105 (offered
> 0) ? &buffer
: NULL
,
110 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
112 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
113 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
115 status
= rpccli_spoolss_GetPrinterDriver(cli
, mem_ctx
,
129 /**********************************************************************
130 convencience wrapper around rpccli_spoolss_GetPrinterDriver2
131 **********************************************************************/
133 WERROR
rpccli_spoolss_getprinterdriver2(struct rpc_pipe_client
*cli
,
135 struct policy_handle
*handle
,
136 const char *architecture
,
139 uint32_t client_major_version
,
140 uint32_t client_minor_version
,
141 union spoolss_DriverInfo
*info
,
142 uint32_t *server_major_version
,
143 uint32_t *server_minor_version
)
151 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
152 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
155 status
= rpccli_spoolss_GetPrinterDriver2(cli
, mem_ctx
,
159 (offered
> 0) ? &buffer
: NULL
,
161 client_major_version
,
162 client_minor_version
,
165 server_major_version
,
166 server_minor_version
,
168 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
170 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
171 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
173 status
= rpccli_spoolss_GetPrinterDriver2(cli
, mem_ctx
,
179 client_major_version
,
180 client_minor_version
,
183 server_major_version
,
184 server_minor_version
,
191 /**********************************************************************
192 convencience wrapper around rpccli_spoolss_AddPrinterEx
193 **********************************************************************/
195 WERROR
rpccli_spoolss_addprinterex(struct rpc_pipe_client
*cli
,
197 struct spoolss_SetPrinterInfoCtr
*info_ctr
)
201 struct spoolss_DevmodeContainer devmode_ctr
;
202 struct sec_desc_buf secdesc_ctr
;
203 struct spoolss_UserLevelCtr userlevel_ctr
;
204 struct spoolss_UserLevel1 level1
;
205 struct policy_handle handle
;
207 ZERO_STRUCT(devmode_ctr
);
208 ZERO_STRUCT(secdesc_ctr
);
214 level1
.processor
= 0;
215 level1
.client
= talloc_asprintf(mem_ctx
, "\\\\%s", global_myname());
216 W_ERROR_HAVE_NO_MEMORY(level1
.client
);
217 level1
.user
= cli
->auth
->user_name
;
219 userlevel_ctr
.level
= 1;
220 userlevel_ctr
.user_info
.level1
= &level1
;
222 status
= rpccli_spoolss_AddPrinterEx(cli
, mem_ctx
,
233 /**********************************************************************
234 convencience wrapper around rpccli_spoolss_GetPrinter
235 **********************************************************************/
237 WERROR
rpccli_spoolss_getprinter(struct rpc_pipe_client
*cli
,
239 struct policy_handle
*handle
,
242 union spoolss_PrinterInfo
*info
)
250 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
251 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
254 status
= rpccli_spoolss_GetPrinter(cli
, mem_ctx
,
257 (offered
> 0) ? &buffer
: NULL
,
263 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
266 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
267 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
269 status
= rpccli_spoolss_GetPrinter(cli
, mem_ctx
,
282 /**********************************************************************
283 convencience wrapper around rpccli_spoolss_GetJob
284 **********************************************************************/
286 WERROR
rpccli_spoolss_getjob(struct rpc_pipe_client
*cli
,
288 struct policy_handle
*handle
,
292 union spoolss_JobInfo
*info
)
300 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
301 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
304 status
= rpccli_spoolss_GetJob(cli
, mem_ctx
,
308 (offered
> 0) ? &buffer
: NULL
,
314 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
316 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
317 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
319 status
= rpccli_spoolss_GetJob(cli
, mem_ctx
,
333 /**********************************************************************
334 convencience wrapper around rpccli_spoolss_EnumForms
335 **********************************************************************/
337 WERROR
rpccli_spoolss_enumforms(struct rpc_pipe_client
*cli
,
339 struct policy_handle
*handle
,
343 union spoolss_FormInfo
**info
)
351 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
352 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
355 status
= rpccli_spoolss_EnumForms(cli
, mem_ctx
,
358 (offered
> 0) ? &buffer
: NULL
,
365 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
367 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
368 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
370 status
= rpccli_spoolss_EnumForms(cli
, mem_ctx
,
373 (offered
> 0) ? &buffer
: NULL
,
384 /**********************************************************************
385 convencience wrapper around rpccli_spoolss_EnumPrintProcessors
386 **********************************************************************/
388 WERROR
rpccli_spoolss_enumprintprocessors(struct rpc_pipe_client
*cli
,
390 const char *servername
,
391 const char *environment
,
395 union spoolss_PrintProcessorInfo
**info
)
403 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
404 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
407 status
= rpccli_spoolss_EnumPrintProcessors(cli
, mem_ctx
,
411 (offered
> 0) ? &buffer
: NULL
,
418 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
420 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
421 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
423 status
= rpccli_spoolss_EnumPrintProcessors(cli
, mem_ctx
,
427 (offered
> 0) ? &buffer
: NULL
,
438 /**********************************************************************
439 convencience wrapper around rpccli_spoolss_EnumPrintProcDataTypes
440 **********************************************************************/
442 WERROR
rpccli_spoolss_enumprintprocessordatatypes(struct rpc_pipe_client
*cli
,
444 const char *servername
,
445 const char *print_processor_name
,
449 union spoolss_PrintProcDataTypesInfo
**info
)
457 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
458 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
461 status
= rpccli_spoolss_EnumPrintProcDataTypes(cli
, mem_ctx
,
463 print_processor_name
,
465 (offered
> 0) ? &buffer
: NULL
,
472 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
474 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
475 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
477 status
= rpccli_spoolss_EnumPrintProcDataTypes(cli
, mem_ctx
,
479 print_processor_name
,
481 (offered
> 0) ? &buffer
: NULL
,
492 /**********************************************************************
493 convencience wrapper around rpccli_spoolss_EnumPorts
494 **********************************************************************/
496 WERROR
rpccli_spoolss_enumports(struct rpc_pipe_client
*cli
,
498 const char *servername
,
502 union spoolss_PortInfo
**info
)
510 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
511 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
514 status
= rpccli_spoolss_EnumPorts(cli
, mem_ctx
,
517 (offered
> 0) ? &buffer
: NULL
,
524 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
526 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
527 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
529 status
= rpccli_spoolss_EnumPorts(cli
, mem_ctx
,
532 (offered
> 0) ? &buffer
: NULL
,
543 /**********************************************************************
544 convencience wrapper around rpccli_spoolss_EnumMonitors
545 **********************************************************************/
547 WERROR
rpccli_spoolss_enummonitors(struct rpc_pipe_client
*cli
,
549 const char *servername
,
553 union spoolss_MonitorInfo
**info
)
561 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
562 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
565 status
= rpccli_spoolss_EnumMonitors(cli
, mem_ctx
,
568 (offered
> 0) ? &buffer
: NULL
,
575 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
577 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
578 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
580 status
= rpccli_spoolss_EnumMonitors(cli
, mem_ctx
,
583 (offered
> 0) ? &buffer
: NULL
,
594 /**********************************************************************
595 convencience wrapper around rpccli_spoolss_EnumJobs
596 **********************************************************************/
598 WERROR
rpccli_spoolss_enumjobs(struct rpc_pipe_client
*cli
,
600 struct policy_handle
*handle
,
606 union spoolss_JobInfo
**info
)
614 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
615 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
618 status
= rpccli_spoolss_EnumJobs(cli
, mem_ctx
,
623 (offered
> 0) ? &buffer
: NULL
,
630 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
632 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
633 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
635 status
= rpccli_spoolss_EnumJobs(cli
, mem_ctx
,
640 (offered
> 0) ? &buffer
: NULL
,
651 /**********************************************************************
652 convencience wrapper around rpccli_spoolss_EnumPrinterDrivers
653 **********************************************************************/
655 WERROR
rpccli_spoolss_enumprinterdrivers(struct rpc_pipe_client
*cli
,
658 const char *environment
,
662 union spoolss_DriverInfo
**info
)
670 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
671 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
674 status
= rpccli_spoolss_EnumPrinterDrivers(cli
, mem_ctx
,
678 (offered
> 0) ? &buffer
: NULL
,
685 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
687 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
688 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
690 status
= rpccli_spoolss_EnumPrinterDrivers(cli
, mem_ctx
,
694 (offered
> 0) ? &buffer
: NULL
,
705 /**********************************************************************
706 convencience wrapper around rpccli_spoolss_EnumPrinters
707 **********************************************************************/
709 WERROR
rpccli_spoolss_enumprinters(struct rpc_pipe_client
*cli
,
716 union spoolss_PrinterInfo
**info
)
724 buffer
= data_blob_talloc_zero(mem_ctx
, offered
);
725 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
728 status
= rpccli_spoolss_EnumPrinters(cli
, mem_ctx
,
732 (offered
> 0) ? &buffer
: NULL
,
739 if (W_ERROR_EQUAL(werror
, WERR_INSUFFICIENT_BUFFER
)) {
741 buffer
= data_blob_talloc_zero(mem_ctx
, needed
);
742 W_ERROR_HAVE_NO_MEMORY(buffer
.data
);
744 status
= rpccli_spoolss_EnumPrinters(cli
, mem_ctx
,
748 (offered
> 0) ? &buffer
: NULL
,
759 /**********************************************************************
760 convencience wrapper around rpccli_spoolss_GetPrinterData
761 **********************************************************************/
763 WERROR
rpccli_spoolss_getprinterdata(struct rpc_pipe_client
*cli
,
765 struct policy_handle
*handle
,
766 const char *value_name
,
768 enum winreg_Type
*type
,
777 data
= talloc_zero_array(mem_ctx
, uint8_t, offered
);
778 W_ERROR_HAVE_NO_MEMORY(data
);
780 status
= rpccli_spoolss_GetPrinterData(cli
, mem_ctx
,
789 if (W_ERROR_EQUAL(werror
, WERR_MORE_DATA
)) {
791 data
= talloc_zero_array(mem_ctx
, uint8_t, offered
);
792 W_ERROR_HAVE_NO_MEMORY(data
);
794 status
= rpccli_spoolss_GetPrinterData(cli
, mem_ctx
,
810 /**********************************************************************
811 convencience wrapper around rpccli_spoolss_EnumPrinterKey
812 **********************************************************************/
814 WERROR
rpccli_spoolss_enumprinterkey(struct rpc_pipe_client
*cli
,
816 struct policy_handle
*handle
,
817 const char *key_name
,
818 const char ***key_buffer
,
824 union spoolss_KeyNames _key_buffer
;
827 status
= rpccli_spoolss_EnumPrinterKey(cli
, mem_ctx
,
836 if (W_ERROR_EQUAL(werror
, WERR_MORE_DATA
)) {
838 status
= rpccli_spoolss_EnumPrinterKey(cli
, mem_ctx
,
848 *key_buffer
= _key_buffer
.string_array
;
853 /**********************************************************************
854 convencience wrapper around rpccli_spoolss_EnumPrinterDataEx
855 **********************************************************************/
857 WERROR
rpccli_spoolss_enumprinterdataex(struct rpc_pipe_client
*cli
,
859 struct policy_handle
*handle
,
860 const char *key_name
,
863 struct spoolss_PrinterEnumValues
**info
)
869 status
= rpccli_spoolss_EnumPrinterDataEx(cli
, mem_ctx
,
878 if (W_ERROR_EQUAL(werror
, WERR_MORE_DATA
)) {
881 status
= rpccli_spoolss_EnumPrinterDataEx(cli
, mem_ctx
,