]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
rpcclient: Add unixinfo commands
authorVolker Lendecke <vl@samba.org>
Sat, 12 Jun 2021 08:03:16 +0000 (10:03 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 24 Aug 2021 18:22:56 +0000 (18:22 +0000)
The unixinfo pipe might go away in the future, but right now we have
it around. This code is simple and can go away again when unixinfo
dies.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Tue Aug 24 18:22:56 UTC 2021 on sn-devel-184

source3/rpcclient/cmd_unixinfo.c [new file with mode: 0644]
source3/rpcclient/rpcclient.c
source3/rpcclient/wscript_build

diff --git a/source3/rpcclient/cmd_unixinfo.c b/source3/rpcclient/cmd_unixinfo.c
new file mode 100644 (file)
index 0000000..16f13a2
--- /dev/null
@@ -0,0 +1,141 @@
+/*
+ * Unix SMB/CIFS implementation.
+ *
+ * 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_unixinfo_c.h"
+#include "libcli/security/dom_sid.h"
+
+static NTSTATUS cmd_unixinfo_uidtosid(
+       struct rpc_pipe_client *cli,
+       TALLOC_CTX *mem_ctx,
+       int argc,
+       const char **argv)
+{
+       struct dcerpc_binding_handle *b = cli->binding_handle;
+       uint64_t uid = 0;
+       struct dom_sid sid = { .sid_rev_num = 0, };
+       struct dom_sid_buf buf;
+       NTSTATUS status, result;
+
+       if (argc != 2) {
+               printf("Usage: %s [uid]\n", argv[0]);
+               return NT_STATUS_OK;
+       }
+       uid = atoi(argv[1]);
+
+       status = dcerpc_unixinfo_UidToSid(b, mem_ctx, uid, &sid, &result);
+       if (!NT_STATUS_IS_OK(status)) {
+               fprintf(stderr,
+                       "dcerpc_unixinfo_UidToSid failed: %s\n",
+                       nt_errstr(status));
+               goto done;
+       }
+       if (!NT_STATUS_IS_OK(result)) {
+               fprintf(stderr,
+                       "dcerpc_unixinfo_UidToSid returned: %s\n",
+                       nt_errstr(result));
+               status = result;
+               goto done;
+       }
+
+       printf("UidToSid(%"PRIu64")=%s\n",
+              uid,
+              dom_sid_str_buf(&sid, &buf));
+
+done:
+       return status;
+}
+
+static NTSTATUS cmd_unixinfo_getpwuid(
+       struct rpc_pipe_client *cli,
+       TALLOC_CTX *mem_ctx,
+       int argc,
+       const char **argv)
+{
+       struct dcerpc_binding_handle *b = cli->binding_handle;
+       uint32_t count = 1;
+       uint64_t uids = 0;
+       struct unixinfo_GetPWUidInfo infos = { .homedir = NULL, };
+       NTSTATUS status, result;
+
+       if (argc != 2) {
+               printf("Usage: %s [uid]\n", argv[0]);
+               return NT_STATUS_OK;
+       }
+       uids = atoi(argv[1]);
+
+       status = dcerpc_unixinfo_GetPWUid(
+               b, mem_ctx, &count, &uids, &infos, &result);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto done;
+       }
+
+       if (!NT_STATUS_IS_OK(status)) {
+               fprintf(stderr,
+                       "dcerpc_unixinfo_GetPWUid failed: %s\n",
+                       nt_errstr(status));
+               return status;
+       }
+       if (!NT_STATUS_IS_OK(result)) {
+               fprintf(stderr,
+                       "dcerpc_unixinfo_GetPWUid returned: %s\n",
+                       nt_errstr(result));
+               return result;
+       }
+
+       printf("status=%s, homedir=%s, shell=%s\n",
+              nt_errstr(infos.status),
+              infos.homedir,
+              infos.shell);
+
+done:
+       return status;
+}
+
+/* List of commands exported by this module */
+
+struct cmd_set unixinfo_commands[] = {
+
+       {
+               .name = "UNIXINFO",
+       },
+
+       {
+               .name               = "getpwuid",
+               .returntype         = RPC_RTYPE_NTSTATUS,
+               .ntfn               = cmd_unixinfo_getpwuid,
+               .wfn                = NULL,
+               .table              = &ndr_table_unixinfo,
+               .rpc_pipe           = NULL,
+               .description        = "Get shell and homedir",
+               .usage              = "",
+       },
+       {
+               .name               = "uidtosid",
+               .returntype         = RPC_RTYPE_NTSTATUS,
+               .ntfn               = cmd_unixinfo_uidtosid,
+               .wfn                = NULL,
+               .table              = &ndr_table_unixinfo,
+               .rpc_pipe           = NULL,
+               .description        = "Convert uid to sid",
+               .usage              = "",
+       },
+       {
+               .name = NULL
+       },
+};
index 92d200e94e4ff495851dcef91445306a29634f6b..7c9982b33e9b5a55c431118d22d8d636f9b95dd3 100644 (file)
@@ -785,6 +785,7 @@ extern struct cmd_set fss_commands[];
 extern struct cmd_set witness_commands[];
 extern struct cmd_set clusapi_commands[];
 extern struct cmd_set spotlight_commands[];
+extern struct cmd_set unixinfo_commands[];
 
 static struct cmd_set *rpcclient_command_list[] = {
        rpcclient_commands,
@@ -808,6 +809,7 @@ static struct cmd_set *rpcclient_command_list[] = {
        witness_commands,
        clusapi_commands,
        spotlight_commands,
+       unixinfo_commands,
        NULL
 };
 
index 75935755f1abc0e5c3954f105c84208afecad535..bb3a88cd4018a3943203f6d102ed813278f5fcb2 100644 (file)
@@ -22,6 +22,7 @@ bld.SAMBA3_BINARY('rpcclient',
                  cmd_witness.c
                 cmd_iremotewinspool.c
                  cmd_spotlight.c
+                 cmd_unixinfo.c
                 ''',
                  deps='''
                  talloc
@@ -56,4 +57,5 @@ bld.SAMBA3_BINARY('rpcclient',
                  RPC_NDR_WINSPOOL
                  mdssvc
                  RPC_NDR_MDSSVC
+                 RPC_NDR_UNIXINFO
                  ''')