[PATCH 3/5] s3-rpcclient: add mgmt command support

David Disseldorp ddiss at samba.org
Sun Jan 5 22:20:06 MST 2014


mgmt_inq_server_princ_name is the only implemented RPC call so far.

Signed-off-by: David Disseldorp <ddiss at samba.org>
---
 source3/rpcclient/cmd_mgmt.c  | 80 +++++++++++++++++++++++++++++++++++++++++++
 source3/rpcclient/rpcclient.c |  2 ++
 source3/wscript_build         |  4 ++-
 3 files changed, 85 insertions(+), 1 deletion(-)
 create mode 100644 source3/rpcclient/cmd_mgmt.c

diff --git a/source3/rpcclient/cmd_mgmt.c b/source3/rpcclient/cmd_mgmt.c
new file mode 100644
index 0000000..59cbb8e
--- /dev/null
+++ b/source3/rpcclient/cmd_mgmt.c
@@ -0,0 +1,80 @@
+/*
+ * Unix SMB/CIFS implementation.
+ *
+ * DCERPC mgmt client
+ *
+ * Copyright (C) David Disseldorp 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_mgmt.h"
+#include "../librpc/gen_ndr/ndr_mgmt_c.h"
+
+static void cmd_mgmt_inq_server_princ_name_usage(const char *script_name)
+{
+	printf("usage: %s <authn_svc>\n", script_name);
+}
+
+static NTSTATUS cmd_mgmt_inq_server_princ_name(struct rpc_pipe_client *cli,
+					       TALLOC_CTX *mem_ctx, int argc,
+					       const char **argv)
+{
+	NTSTATUS status;
+	struct mgmt_inq_princ_name r;
+	struct dcerpc_binding_handle *b = cli->binding_handle;
+
+	if (argc != 2) {
+		cmd_mgmt_inq_server_princ_name_usage(argv[0]);
+		return NT_STATUS_UNSUCCESSFUL;
+	}
+
+	ZERO_STRUCT(r);
+	r.in.authn_proto = atoi(argv[1]);
+	r.in.princ_name_size = 256;
+
+	status = dcerpc_mgmt_inq_princ_name_r(b, mem_ctx, &r);
+	if (!NT_STATUS_IS_OK(status)) {
+		DEBUG(0, ("inq_princ_name failed with authn_proto %d\n",
+			  (int)r.in.authn_proto));
+		return NT_STATUS_UNSUCCESSFUL;
+	} else if (!W_ERROR_IS_OK(r.out.result)) {
+		DEBUG(0, ("failed inq_princ_name response: %s\n",
+			  win_errstr(r.out.result)));
+		return NT_STATUS_UNSUCCESSFUL;
+	}
+	printf("Server principle name(%d): %s\n",
+	       r.in.authn_proto, r.out.princ_name);
+
+	return NT_STATUS_OK;
+}
+
+/* List of commands exported by this module */
+struct cmd_set mgmt_commands[] = {
+
+	{ "MGMT" },
+
+	{
+		.name = "mgmt_inq_server_princ_name",
+		.returntype = RPC_RTYPE_NTSTATUS,
+		.ntfn = cmd_mgmt_inq_server_princ_name,
+		.table = &ndr_table_mgmt,
+		.rpc_pipe = NULL,
+		.description = "get a server\'s principle name",
+		.usage = "",
+	},
+	{ NULL }
+};
diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c
index eae6bbd..78c1efe 100644
--- a/source3/rpcclient/rpcclient.c
+++ b/source3/rpcclient/rpcclient.c
@@ -622,6 +622,7 @@ extern struct cmd_set drsuapi_commands[];
 extern struct cmd_set eventlog_commands[];
 extern struct cmd_set winreg_commands[];
 extern struct cmd_set fss_commands[];
+extern struct cmd_set mgmt_commands[];
 
 static struct cmd_set *rpcclient_command_list[] = {
 	rpcclient_commands,
@@ -642,6 +643,7 @@ static struct cmd_set *rpcclient_command_list[] = {
 	eventlog_commands,
 	winreg_commands,
 	fss_commands,
+	mgmt_commands,
 	NULL
 };
 
diff --git a/source3/wscript_build b/source3/wscript_build
index d3eed3c..297c02a 100755
--- a/source3/wscript_build
+++ b/source3/wscript_build
@@ -960,7 +960,8 @@ bld.SAMBA3_BINARY('rpcclient/rpcclient',
                  rpcclient/cmd_drsuapi.c
                  rpcclient/cmd_eventlog.c
                  rpcclient/cmd_winreg.c
-                 rpcclient/cmd_fss.c''',
+                 rpcclient/cmd_fss.c
+                 rpcclient/cmd_mgmt.c''',
                  deps='''
                  talloc
                  popt_samba3
@@ -988,6 +989,7 @@ bld.SAMBA3_BINARY('rpcclient/rpcclient',
                  RPC_NDR_EVENTLOG
                  INIT_SAMR
                  RPC_NDR_FSRVP
+                 RPC_NDR_MGMT
                  ''')
 
 bld.SAMBA3_BINARY('client/smbclient',
-- 
1.8.1.4



More information about the samba-technical mailing list