autobuild: Run the samba-minimal-smbd build jobs with -j 2
[samba4-gss.git] / source3 / rpcclient / cmd_iremotewinspool.c
blob7162605696f0f155c5fb2998927ac074816b38f1
1 /*
2 Unix SMB/CIFS implementation.
3 RPC pipe client
5 Copyright (C) 2013-2016 Guenther Deschner <gd@samba.org>
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 3 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, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "rpcclient.h"
23 #include "../librpc/gen_ndr/ndr_winspool.h"
24 #include "libsmb/libsmb.h"
25 #include "auth/gensec/gensec.h"
26 #include "auth/credentials/credentials.h"
27 #include "rpc_client/init_spoolss.h"
29 /****************************************************************************
30 ****************************************************************************/
32 static WERROR cmd_iremotewinspool_async_open_printer(struct rpc_pipe_client *cli,
33 TALLOC_CTX *mem_ctx,
34 int argc, const char **argv)
36 NTSTATUS status;
37 WERROR werror;
38 struct policy_handle hnd;
39 struct spoolss_DevmodeContainer devmode_ctr;
40 struct spoolss_UserLevelCtr client_info_ctr;
41 struct spoolss_UserLevel1 level1;
42 uint32_t access_mask = PRINTER_ALL_ACCESS;
43 struct dcerpc_binding_handle *b = cli->binding_handle;
44 struct GUID uuid;
45 struct winspool_AsyncOpenPrinter r;
47 if (argc < 2) {
48 printf("Usage: %s <printername> [access_mask]\n", argv[0]);
49 return WERR_OK;
52 if (argc >= 3) {
53 sscanf(argv[2], "%x", &access_mask);
56 status = GUID_from_string(IREMOTEWINSPOOL_OBJECT_GUID, &uuid);
57 if (!NT_STATUS_IS_OK(status)) {
58 return WERR_NOT_ENOUGH_MEMORY;
61 ZERO_STRUCT(devmode_ctr);
63 werror = spoolss_init_spoolss_UserLevel1(mem_ctx,
64 cli->printer_username,
65 &level1);
66 if (!W_ERROR_IS_OK(werror)) {
67 return werror;
70 level1.processor = PROCESSOR_ARCHITECTURE_AMD64;
72 client_info_ctr.level = 1;
73 client_info_ctr.user_info.level1 = &level1;
75 r.in.pPrinterName = argv[1];
76 r.in.pDatatype = "RAW";
77 r.in.pDevModeContainer = &devmode_ctr;
78 r.in.AccessRequired = access_mask;
79 r.in.pClientInfo = &client_info_ctr;
80 r.out.pHandle = &hnd;
82 /* Open the printer handle */
84 status = dcerpc_binding_handle_call(b,
85 &uuid,
86 &ndr_table_iremotewinspool,
87 NDR_WINSPOOL_ASYNCOPENPRINTER,
88 mem_ctx,
89 &r);
90 if (!NT_STATUS_IS_OK(status)) {
91 return ntstatus_to_werror(status);
93 if (!W_ERROR_IS_OK(r.out.result)) {
94 return r.out.result;
97 printf("Printer %s opened successfully\n", argv[1]);
99 return WERR_OK;
102 static WERROR cmd_iremotewinspool_async_core_printer_driver_installed(struct rpc_pipe_client *cli,
103 TALLOC_CTX *mem_ctx,
104 int argc, const char **argv)
106 NTSTATUS status;
107 struct dcerpc_binding_handle *b = cli->binding_handle;
108 struct GUID uuid, core_printer_driver_guid;
109 struct winspool_AsyncCorePrinterDriverInstalled r;
110 const char *guid_str = SPOOLSS_CORE_PRINT_PACKAGE_FILES_XPSDRV;
111 const char *architecture = SPOOLSS_ARCHITECTURE_x64;
112 int32_t pbDriverInstalled;
114 if (argc > 4) {
115 printf("Usage: %s <CORE_PRINTER_DRIVER_GUID> [architecture]\n", argv[0]);
116 return WERR_OK;
119 if (argc >= 2) {
120 guid_str = argv[1];
123 if (argc >= 3) {
124 architecture = argv[2];
127 status = GUID_from_string(IREMOTEWINSPOOL_OBJECT_GUID, &uuid);
128 if (!NT_STATUS_IS_OK(status)) {
129 return WERR_NOT_ENOUGH_MEMORY;
131 status = GUID_from_string(guid_str, &core_printer_driver_guid);
132 if (!NT_STATUS_IS_OK(status)) {
133 return WERR_NOT_ENOUGH_MEMORY;
136 r.in.pszServer = NULL;
137 r.in.pszEnvironment = architecture;
138 r.in.CoreDriverGUID = core_printer_driver_guid;
139 r.in.ftDriverDate = 0;
140 r.in.dwlDriverVersion = 0;
141 r.out.pbDriverInstalled = &pbDriverInstalled;
143 status = dcerpc_binding_handle_call(b,
144 &uuid,
145 &ndr_table_iremotewinspool,
146 NDR_WINSPOOL_ASYNCCOREPRINTERDRIVERINSTALLED,
147 mem_ctx,
148 &r);
149 if (!NT_STATUS_IS_OK(status)) {
150 return ntstatus_to_werror(status);
152 if (!HRES_IS_OK(r.out.result)) {
153 return W_ERROR(WIN32_FROM_HRESULT(r.out.result));
156 printf("Core Printer Driver %s is%s installed\n", guid_str,
157 *r.out.pbDriverInstalled ? "" : " NOT");
159 return WERR_OK;
162 /* List of commands exported by this module */
163 struct cmd_set iremotewinspool_commands[] = {
166 .name = "IRemoteWinspool",
170 .name = "winspool_AsyncOpenPrinter",
171 .returntype = RPC_RTYPE_WERROR,
172 .ntfn = NULL,
173 .wfn = cmd_iremotewinspool_async_open_printer,
174 .table = &ndr_table_iremotewinspool,
175 .rpc_pipe = NULL,
176 .description = "Open printer handle",
177 .usage = "",
181 .name = "winspool_AsyncCorePrinterDriverInstalled",
182 .returntype = RPC_RTYPE_WERROR,
183 .ntfn = NULL,
184 .wfn = cmd_iremotewinspool_async_core_printer_driver_installed,
185 .table = &ndr_table_iremotewinspool,
186 .rpc_pipe = NULL,
187 .description = "Query Core Printer Driver Installed",
188 .usage = "",
192 .name = NULL,