CVE-2018-1057: s4:dsdb/tests: add a test for password change with empty delete
[Samba.git] / source3 / rpcclient / cmd_iremotewinspool.c
blobc6148ec02c740a0ef090a33df764f126a17eedb7
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"
28 /****************************************************************************
29 ****************************************************************************/
31 static WERROR cmd_iremotewinspool_async_open_printer(struct rpc_pipe_client *cli,
32 TALLOC_CTX *mem_ctx,
33 int argc, const char **argv)
35 NTSTATUS status;
36 struct policy_handle hnd;
37 struct spoolss_DevmodeContainer devmode_ctr;
38 struct spoolss_UserLevelCtr client_info_ctr;
39 struct spoolss_UserLevel1 level1;
40 uint32_t access_mask = PRINTER_ALL_ACCESS;
41 struct dcerpc_binding_handle *b = cli->binding_handle;
42 struct GUID uuid;
43 struct winspool_AsyncOpenPrinter r;
44 struct cli_credentials *creds = gensec_get_credentials(cli->auth->auth_ctx);
46 if (argc < 2) {
47 printf("Usage: %s <printername> [access_mask]\n", argv[0]);
48 return WERR_OK;
51 if (argc >= 3) {
52 sscanf(argv[2], "%x", &access_mask);
55 status = GUID_from_string(IREMOTEWINSPOOL_OBJECT_GUID, &uuid);
56 if (!NT_STATUS_IS_OK(status)) {
57 return WERR_NOT_ENOUGH_MEMORY;
60 ZERO_STRUCT(devmode_ctr);
62 level1.size = 40;
63 level1.client = talloc_asprintf(mem_ctx, "\\\\%s", lp_netbios_name());
64 W_ERROR_HAVE_NO_MEMORY(level1.client);
65 level1.user = cli_credentials_get_username(creds);
66 level1.build = 1381;
67 level1.major = 3;
68 level1.minor = 0;
69 level1.processor = PROCESSOR_ARCHITECTURE_AMD64;
71 client_info_ctr.level = 1;
72 client_info_ctr.user_info.level1 = &level1;
74 r.in.pPrinterName = argv[1];
75 r.in.pDatatype = "RAW";
76 r.in.pDevModeContainer = &devmode_ctr;
77 r.in.AccessRequired = access_mask;
78 r.in.pClientInfo = &client_info_ctr;
79 r.out.pHandle = &hnd;
81 /* Open the printer handle */
83 status = dcerpc_binding_handle_call(b,
84 &uuid,
85 &ndr_table_iremotewinspool,
86 NDR_WINSPOOL_ASYNCOPENPRINTER,
87 mem_ctx,
88 &r);
89 if (!NT_STATUS_IS_OK(status)) {
90 return ntstatus_to_werror(status);
92 if (!W_ERROR_IS_OK(r.out.result)) {
93 return r.out.result;
96 printf("Printer %s opened successfully\n", argv[1]);
98 return WERR_OK;
101 static WERROR cmd_iremotewinspool_async_core_printer_driver_installed(struct rpc_pipe_client *cli,
102 TALLOC_CTX *mem_ctx,
103 int argc, const char **argv)
105 NTSTATUS status;
106 struct dcerpc_binding_handle *b = cli->binding_handle;
107 struct GUID uuid, core_printer_driver_guid;
108 struct winspool_AsyncCorePrinterDriverInstalled r;
109 const char *guid_str = SPOOLSS_CORE_PRINT_PACKAGE_FILES_XPSDRV;
110 const char *architecture = SPOOLSS_ARCHITECTURE_x64;
111 int32_t pbDriverInstalled;
113 if (argc > 4) {
114 printf("Usage: %s <CORE_PRINTER_DRIVER_GUID> [architecture]\n", argv[0]);
115 return WERR_OK;
118 if (argc >= 2) {
119 guid_str = argv[1];
122 if (argc >= 3) {
123 architecture = argv[2];
126 status = GUID_from_string(IREMOTEWINSPOOL_OBJECT_GUID, &uuid);
127 if (!NT_STATUS_IS_OK(status)) {
128 return WERR_NOT_ENOUGH_MEMORY;
130 status = GUID_from_string(guid_str, &core_printer_driver_guid);
131 if (!NT_STATUS_IS_OK(status)) {
132 return WERR_NOT_ENOUGH_MEMORY;
135 r.in.pszServer = NULL;
136 r.in.pszEnvironment = architecture;
137 r.in.CoreDriverGUID = core_printer_driver_guid;
138 r.in.ftDriverDate = 0;
139 r.in.dwlDriverVersion = 0;
140 r.out.pbDriverInstalled = &pbDriverInstalled;
142 status = dcerpc_binding_handle_call(b,
143 &uuid,
144 &ndr_table_iremotewinspool,
145 NDR_WINSPOOL_ASYNCCOREPRINTERDRIVERINSTALLED,
146 mem_ctx,
147 &r);
148 if (!NT_STATUS_IS_OK(status)) {
149 return ntstatus_to_werror(status);
151 if (!HRES_IS_OK(r.out.result)) {
152 return W_ERROR(WIN32_FROM_HRESULT(r.out.result));
155 printf("Core Printer Driver %s is%s installed\n", guid_str,
156 *r.out.pbDriverInstalled ? "" : " NOT");
158 return WERR_OK;
161 /* List of commands exported by this module */
162 struct cmd_set iremotewinspool_commands[] = {
164 { "IRemoteWinspool" },
166 { "winspool_AsyncOpenPrinter", RPC_RTYPE_WERROR, NULL,
167 cmd_iremotewinspool_async_open_printer,
168 &ndr_table_iremotewinspool,
169 NULL, "Open printer handle", "" },
171 { "winspool_AsyncCorePrinterDriverInstalled", RPC_RTYPE_WERROR, NULL,
172 cmd_iremotewinspool_async_core_printer_driver_installed,
173 &ndr_table_iremotewinspool,
174 NULL, "Query Core Printer Driver Installed", "" },
176 { NULL }