[PATCHES] MS-PAR rpcclient

Günther Deschner gd at samba.org
Wed Nov 23 15:15:34 UTC 2016


Ops. incomplete patch. One hunk was missing.


On 23/11/16 16:04, Günther Deschner wrote:
> Hi,
> 
> attached some patches to create a basic iremotewinspool rpcclient tool.
> 
> Note that the object_uuid is set directly in the
> dcerpc_binding_handle_call() unlike our smbtorture4 client
> iremotewinspool code where we set the interface specific object_uuid via
> the binding handle (passing down the full binding in s3 rpc_client code
> would require some major restructuring which we would like to avoid for
> now).
> 
> Please review & push,
> 
> Thanks,
> Guenther
> 


-- 
Günther Deschner                    GPG-ID: 8EE11688
Red Hat                         gdeschner at redhat.com
Samba Team                              gd at samba.org
-------------- next part --------------
From ea5e78acb0d0c9df512d3295851c8c572b3e1266 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?G=C3=BCnther=20Deschner?= <gd at samba.org>
Date: Wed, 23 Jan 2013 10:34:12 +0100
Subject: [PATCH 1/3] s3-rpc_cli: support the use of the object_uuid in rpc_cli
 interfaces.

Guenther

Signed-off-by: Guenther Deschner <gd at samba.org>
---
 source3/rpc_client/cli_pipe.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/source3/rpc_client/cli_pipe.c b/source3/rpc_client/cli_pipe.c
index f288156..5418fbe 100644
--- a/source3/rpc_client/cli_pipe.c
+++ b/source3/rpc_client/cli_pipe.c
@@ -1286,6 +1286,7 @@ struct rpc_api_pipe_req_state {
 	uint8_t op_num;
 	uint32_t call_id;
 	const DATA_BLOB *req_data;
+	const struct GUID *object_uuid;
 	uint32_t req_data_sent;
 	DATA_BLOB req_trailer;
 	uint32_t req_trailer_sent;
@@ -1305,6 +1306,7 @@ static struct tevent_req *rpc_api_pipe_req_send(TALLOC_CTX *mem_ctx,
 					 struct tevent_context *ev,
 					 struct rpc_pipe_client *cli,
 					 uint8_t op_num,
+					 const struct GUID *object_uuid,
 					 const DATA_BLOB *req_data)
 {
 	struct tevent_req *req, *subreq;
@@ -1320,6 +1322,7 @@ static struct tevent_req *rpc_api_pipe_req_send(TALLOC_CTX *mem_ctx,
 	state->ev = ev;
 	state->cli = cli;
 	state->op_num = op_num;
+	state->object_uuid = object_uuid;
 	state->req_data = req_data;
 	state->req_data_sent = 0;
 	state->call_id = get_rpc_call_id();
@@ -1555,6 +1558,12 @@ static NTSTATUS prepare_next_frag(struct rpc_api_pipe_req_state *state,
 	u.request.context_id	= 0;
 	u.request.opnum		= state->op_num;
 
+	if (state->object_uuid) {
+		flags |= DCERPC_PFC_FLAG_OBJECT_UUID;
+		u.request.object.object = *state->object_uuid;
+		frag_len += ndr_size_GUID(state->object_uuid, 0);
+	}
+
 	status = dcerpc_push_ncacn_packet(state,
 					  DCERPC_PKT_REQUEST,
 					  flags,
@@ -2252,7 +2261,7 @@ static struct tevent_req *rpccli_bh_raw_call_send(TALLOC_CTX *mem_ctx,
 	}
 
 	subreq = rpc_api_pipe_req_send(state, ev, hs->rpc_cli,
-				       opnum, &state->in_data);
+				       opnum, object, &state->in_data);
 	if (tevent_req_nomem(subreq, req)) {
 		return tevent_req_post(req, ev);
 	}
-- 
2.7.4


From f7ca3778f2418d54edece4c29482432df08c4bbc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?G=C3=BCnther=20Deschner?= <gd at samba.org>
Date: Tue, 15 Jan 2013 15:22:43 +0100
Subject: [PATCH 2/3] s3-rpcclient: add rpcclient IRemoteWinspool commands.

Guenther

Signed-off-by: Guenther Deschner <gd at samba.org>
---
 source3/rpcclient/cmd_iremotewinspool.c | 109 ++++++++++++++++++++++++++++++++
 source3/rpcclient/rpcclient.c           |   2 +
 source3/rpcclient/wscript_build         |   2 +
 3 files changed, 113 insertions(+)
 create mode 100644 source3/rpcclient/cmd_iremotewinspool.c

diff --git a/source3/rpcclient/cmd_iremotewinspool.c b/source3/rpcclient/cmd_iremotewinspool.c
new file mode 100644
index 0000000..fece7af
--- /dev/null
+++ b/source3/rpcclient/cmd_iremotewinspool.c
@@ -0,0 +1,109 @@
+/*
+   Unix SMB/CIFS implementation.
+   RPC pipe client
+
+   Copyright (C) Guenther Deschner                 2013
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "rpcclient.h"
+#include "../librpc/gen_ndr/ndr_winspool.h"
+#include "libsmb/libsmb.h"
+#include "auth/gensec/gensec.h"
+#include "auth/credentials/credentials.h"
+
+/****************************************************************************
+****************************************************************************/
+
+static WERROR cmd_iremotewinspool_async_open_printer(struct rpc_pipe_client *cli,
+						     TALLOC_CTX *mem_ctx,
+						     int argc, const char **argv)
+{
+	NTSTATUS status;
+	struct policy_handle hnd;
+	struct spoolss_DevmodeContainer devmode_ctr;
+	struct spoolss_UserLevelCtr client_info_ctr;
+	struct spoolss_UserLevel1 level1;
+	uint32_t access_mask = PRINTER_ALL_ACCESS;
+	struct dcerpc_binding_handle *b = cli->binding_handle;
+	struct GUID uuid;
+	struct winspool_AsyncOpenPrinter r;
+	struct cli_credentials *creds = gensec_get_credentials(cli->auth->auth_ctx);
+
+	if (argc < 2) {
+		printf("Usage: %s <printername> [access_mask]\n", argv[0]);
+		return WERR_OK;
+	}
+
+	if (argc >= 3) {
+		sscanf(argv[2], "%x", &access_mask);
+	}
+
+	status = GUID_from_string(IREMOTEWINSPOOL_OBJECT_GUID, &uuid);
+	if (!NT_STATUS_IS_OK(status)) {
+		return WERR_NOT_ENOUGH_MEMORY;
+	}
+
+	ZERO_STRUCT(devmode_ctr);
+
+	level1.size	= 40;
+	level1.client	= talloc_asprintf(mem_ctx, "\\\\%s", lp_netbios_name());
+	W_ERROR_HAVE_NO_MEMORY(level1.client);
+	level1.user	= cli_credentials_get_username(creds);
+	level1.build	= 1381;
+	level1.major	= 3;
+	level1.minor	= 0;
+	level1.processor = PROCESSOR_ARCHITECTURE_AMD64;
+
+	client_info_ctr.level = 1;
+	client_info_ctr.user_info.level1 = &level1;
+
+	r.in.pPrinterName	= argv[1];
+	r.in.pDatatype		= "RAW";
+	r.in.pDevModeContainer	= &devmode_ctr;
+	r.in.AccessRequired	= access_mask;
+	r.in.pClientInfo	= &client_info_ctr;
+	r.out.pHandle		= &hnd;
+
+	/* Open the printer handle */
+
+	status = dcerpc_binding_handle_call(b,
+					    &uuid,
+					    &ndr_table_iremotewinspool,
+					    NDR_WINSPOOL_ASYNCOPENPRINTER,
+					    mem_ctx,
+					    &r);
+	if (!NT_STATUS_IS_OK(status)) {
+		return ntstatus_to_werror(status);
+	}
+	if (!W_ERROR_IS_OK(r.out.result)) {
+		return r.out.result;
+	}
+
+	printf("Printer %s opened successfully\n", argv[1]);
+
+	return WERR_OK;
+}
+
+/* List of commands exported by this module */
+struct cmd_set iremotewinspool_commands[] = {
+
+	{ "IRemoteWinspool"  },
+
+	{ "AsyncOpenPrinter",	RPC_RTYPE_WERROR, NULL, cmd_iremotewinspool_async_open_printer,	&ndr_table_iremotewinspool, NULL, "Open printer handle",                 "" },
+
+	{ NULL }
+};
diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c
index 35f17bb..138fdba 100644
--- a/source3/rpcclient/rpcclient.c
+++ b/source3/rpcclient/rpcclient.c
@@ -638,6 +638,7 @@ static struct cmd_set separator_command[] = {
 extern struct cmd_set lsarpc_commands[];
 extern struct cmd_set samr_commands[];
 extern struct cmd_set spoolss_commands[];
+extern struct cmd_set iremotewinspool_commands[];
 extern struct cmd_set netlogon_commands[];
 extern struct cmd_set srvsvc_commands[];
 extern struct cmd_set dfs_commands[];
@@ -661,6 +662,7 @@ static struct cmd_set *rpcclient_command_list[] = {
 	ds_commands,
 	samr_commands,
 	spoolss_commands,
+	iremotewinspool_commands,
 	netlogon_commands,
 	srvsvc_commands,
 	dfs_commands,
diff --git a/source3/rpcclient/wscript_build b/source3/rpcclient/wscript_build
index 3e8791d..7f13c10 100644
--- a/source3/rpcclient/wscript_build
+++ b/source3/rpcclient/wscript_build
@@ -21,6 +21,7 @@ bld.SAMBA3_BINARY('rpcclient',
                  cmd_fss.c
                  cmd_clusapi.c
                  cmd_witness.c
+		 cmd_iremotewinspool.c
 		 ''',
                  deps='''
                  talloc
@@ -51,4 +52,5 @@ bld.SAMBA3_BINARY('rpcclient',
                  RPC_NDR_FSRVP
                  RPC_NDR_CLUSAPI
                  RPC_NDR_WITNESS
+                 RPC_NDR_WINSPOOL
                  ''')
-- 
2.7.4


From 3b0f4f2be265a97d87e80296122aec3915a87c78 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?G=C3=BCnther=20Deschner?= <gd at samba.org>
Date: Tue, 22 Nov 2016 12:07:23 +0100
Subject: [PATCH 3/3] s3-rpcclient: add AsyncCorePrinterDriverInstalled command

Guenther

Signed-off-by: Guenther Deschner <gd at samba.org>
---
 source3/rpcclient/cmd_iremotewinspool.c | 61 +++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

diff --git a/source3/rpcclient/cmd_iremotewinspool.c b/source3/rpcclient/cmd_iremotewinspool.c
index fece7af..a7f8342 100644
--- a/source3/rpcclient/cmd_iremotewinspool.c
+++ b/source3/rpcclient/cmd_iremotewinspool.c
@@ -98,12 +98,73 @@ static WERROR cmd_iremotewinspool_async_open_printer(struct rpc_pipe_client *cli
 	return WERR_OK;
 }
 
+static WERROR cmd_iremotewinspool_async_core_printer_driver_installed(struct rpc_pipe_client *cli,
+								      TALLOC_CTX *mem_ctx,
+								      int argc, const char **argv)
+{
+	NTSTATUS status;
+	struct dcerpc_binding_handle *b = cli->binding_handle;
+	struct GUID uuid, core_printer_driver_guid;
+	struct winspool_AsyncCorePrinterDriverInstalled r;
+	const char *guid_str = SPOOLSS_CORE_PRINT_PACKAGE_FILES_XPSDRV;
+	const char *architecture = SPOOLSS_ARCHITECTURE_x64;
+	int32_t pbDriverInstalled;
+
+	if (argc > 4) {
+		printf("Usage: %s <CORE_PRINTER_DRIVER_GUID> [architecture]\n", argv[0]);
+		return WERR_OK;
+	}
+
+	if (argc >= 2) {
+		guid_str = argv[1];
+	}
+
+	if (argc >= 3) {
+		architecture = argv[2];
+	}
+
+	status = GUID_from_string(IREMOTEWINSPOOL_OBJECT_GUID, &uuid);
+	if (!NT_STATUS_IS_OK(status)) {
+		return WERR_NOT_ENOUGH_MEMORY;
+	}
+	status = GUID_from_string(guid_str, &core_printer_driver_guid);
+	if (!NT_STATUS_IS_OK(status)) {
+		return WERR_NOT_ENOUGH_MEMORY;
+	}
+
+	r.in.pszServer		= NULL;
+	r.in.pszEnvironment	= architecture;
+	r.in.CoreDriverGUID	= core_printer_driver_guid;
+	r.in.ftDriverDate	= 0;
+	r.in.dwlDriverVersion	= 0;
+	r.out.pbDriverInstalled	= &pbDriverInstalled;
+
+	status = dcerpc_binding_handle_call(b,
+					    &uuid,
+					    &ndr_table_iremotewinspool,
+					    NDR_WINSPOOL_ASYNCCOREPRINTERDRIVERINSTALLED,
+					    mem_ctx,
+					    &r);
+	if (!NT_STATUS_IS_OK(status)) {
+		return ntstatus_to_werror(status);
+	}
+	if (!HRES_IS_OK(r.out.result)) {
+		return W_ERROR(WIN32_FROM_HRESULT(r.out.result));
+	}
+
+	printf("Core Printer Driver %s is%s installed\n", guid_str,
+		*r.out.pbDriverInstalled ? "" : " NOT");
+
+	return WERR_OK;
+}
+
 /* List of commands exported by this module */
 struct cmd_set iremotewinspool_commands[] = {
 
 	{ "IRemoteWinspool"  },
 
 	{ "AsyncOpenPrinter",	RPC_RTYPE_WERROR, NULL, cmd_iremotewinspool_async_open_printer,	&ndr_table_iremotewinspool, NULL, "Open printer handle",                 "" },
+	{ "AsyncCorePrinterDriverInstalled",	RPC_RTYPE_WERROR, NULL, cmd_iremotewinspool_async_core_printer_driver_installed,	&ndr_table_iremotewinspool, NULL, "Query Core Printer Driver Installed",                 "" },
 
 	{ NULL }
 };
-- 
2.7.4

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 201 bytes
Desc: OpenPGP digital signature
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20161123/2a4ec669/signature.sig>


More information about the samba-technical mailing list