rpcclient: add mgmt command support
authorDavid Disseldorp <ddiss@samba.org>
Thu, 25 Apr 2013 09:17:28 +0000 (11:17 +0200)
committerDavid Disseldorp <ddiss@samba.org>
Wed, 8 May 2013 10:21:36 +0000 (12:21 +0200)
mgmt_inq_server_princ_name is the only implemented RPC call so far.

source3/Makefile.in
source3/rpcclient/cmd_mgmt.c [new file with mode: 0644]
source3/rpcclient/rpcclient.c
source3/wscript_build

index a4aeebab98ad57a899091de6f0103380499f5416..52f76a60e2d967bae5b6118bf87a7995dda409f4 100644 (file)
@@ -373,6 +373,8 @@ LIBCLI_SVCCTL_OBJ = autoconf/librpc/gen_ndr/ndr_svcctl_c.o
 
 LIBCLI_WKSSVC_OBJ = autoconf/librpc/gen_ndr/ndr_wkssvc_c.o
 
+LIBCLI_MGMT_OBJ = autoconf/librpc/gen_ndr/ndr_mgmt_c.o
+
 LIBCLI_SRVSVC_OBJ = autoconf/librpc/gen_ndr/ndr_srvsvc_c.o
 
 LIBCLI_LSA_OBJ = autoconf/librpc/gen_ndr/ndr_lsa_c.o \
@@ -1122,6 +1124,7 @@ RPCCLIENT_OBJ1 = rpcclient/rpcclient.o rpcclient/cmd_lsarpc.o \
                 rpcclient/cmd_wkssvc.o rpcclient/cmd_ntsvcs.o \
                 rpcclient/cmd_drsuapi.o rpcclient/cmd_eventlog.o \
                 rpcclient/cmd_winreg.o rpcclient/cmd_fss.o \
+                rpcclient/cmd_mgmt.o \
                 $(DISPLAY_SEC_OBJ)
 
 RPCCLIENT_OBJ = $(RPCCLIENT_OBJ1) \
@@ -1138,6 +1141,7 @@ RPCCLIENT_OBJ = $(RPCCLIENT_OBJ1) \
             $(LIBCLI_ECHO_OBJ) \
             $(LIBCLI_DSSETUP_OBJ) \
             $(LIBCLI_WKSSVC_OBJ) \
+            $(LIBCLI_MGMT_OBJ) \
             $(LIBCLI_SRVSVC_OBJ) \
             $(LIBCLI_LSA_OBJ) \
             $(LIBCLI_SAMR_OBJ) \
diff --git a/source3/rpcclient/cmd_mgmt.c b/source3/rpcclient/cmd_mgmt.c
new file mode 100644 (file)
index 0000000..59cbb8e
--- /dev/null
@@ -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 }
+};
index 7b31e1547eefe73a929ac7f79abbdce5441a3399..18003045fe0d2818a3fe14e14fef483205d9f2a9 100644 (file)
@@ -621,6 +621,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,
@@ -641,6 +642,7 @@ static struct cmd_set *rpcclient_command_list[] = {
        eventlog_commands,
        winreg_commands,
        fss_commands,
+       mgmt_commands,
        NULL
 };
 
index 1cf6c0dc3feaa24f497a3ed71fb8871f7c6adfa3..45bb9cfa42884f721ccec736964632d4a441a376 100755 (executable)
@@ -453,7 +453,8 @@ RPCCLIENT_SRC1 = '''rpcclient/rpcclient.c rpcclient/cmd_lsarpc.c
                     rpcclient/cmd_shutdown.c rpcclient/cmd_test.c
                     rpcclient/cmd_wkssvc.c rpcclient/cmd_ntsvcs.c
                     rpcclient/cmd_drsuapi.c rpcclient/cmd_eventlog.c
-                    rpcclient/cmd_winreg.c rpcclient/cmd_fss.c'''
+                    rpcclient/cmd_winreg.c rpcclient/cmd_fss.c
+                   rpcclient/cmd_mgmt.c'''
 
 RPCCLIENT_SRC = '''${RPCCLIENT_SRC1}'''
 
@@ -1259,6 +1260,7 @@ bld.SAMBA3_BINARY('rpcclient/rpcclient',
                  libcli_lsa3
                  libcli_netlogon3
                  cli_spoolss
+                 RPC_NDR_MGMT
                  RPC_NDR_SRVSVC
                  RPC_NDR_WKSSVC
                  RPC_NDR_DSSETUP