s3:libads: remove unused ads->auth.renewable
[Samba.git] / source3 / rpcclient / cmd_unixinfo.c
blob16f13a268269f473a93bd729417f38f3212a7894
1 /*
2 * Unix SMB/CIFS implementation.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "includes.h"
19 #include "rpcclient.h"
20 #include "../librpc/gen_ndr/ndr_unixinfo_c.h"
21 #include "libcli/security/dom_sid.h"
23 static NTSTATUS cmd_unixinfo_uidtosid(
24 struct rpc_pipe_client *cli,
25 TALLOC_CTX *mem_ctx,
26 int argc,
27 const char **argv)
29 struct dcerpc_binding_handle *b = cli->binding_handle;
30 uint64_t uid = 0;
31 struct dom_sid sid = { .sid_rev_num = 0, };
32 struct dom_sid_buf buf;
33 NTSTATUS status, result;
35 if (argc != 2) {
36 printf("Usage: %s [uid]\n", argv[0]);
37 return NT_STATUS_OK;
39 uid = atoi(argv[1]);
41 status = dcerpc_unixinfo_UidToSid(b, mem_ctx, uid, &sid, &result);
42 if (!NT_STATUS_IS_OK(status)) {
43 fprintf(stderr,
44 "dcerpc_unixinfo_UidToSid failed: %s\n",
45 nt_errstr(status));
46 goto done;
48 if (!NT_STATUS_IS_OK(result)) {
49 fprintf(stderr,
50 "dcerpc_unixinfo_UidToSid returned: %s\n",
51 nt_errstr(result));
52 status = result;
53 goto done;
56 printf("UidToSid(%"PRIu64")=%s\n",
57 uid,
58 dom_sid_str_buf(&sid, &buf));
60 done:
61 return status;
64 static NTSTATUS cmd_unixinfo_getpwuid(
65 struct rpc_pipe_client *cli,
66 TALLOC_CTX *mem_ctx,
67 int argc,
68 const char **argv)
70 struct dcerpc_binding_handle *b = cli->binding_handle;
71 uint32_t count = 1;
72 uint64_t uids = 0;
73 struct unixinfo_GetPWUidInfo infos = { .homedir = NULL, };
74 NTSTATUS status, result;
76 if (argc != 2) {
77 printf("Usage: %s [uid]\n", argv[0]);
78 return NT_STATUS_OK;
80 uids = atoi(argv[1]);
82 status = dcerpc_unixinfo_GetPWUid(
83 b, mem_ctx, &count, &uids, &infos, &result);
84 if (!NT_STATUS_IS_OK(status)) {
85 goto done;
88 if (!NT_STATUS_IS_OK(status)) {
89 fprintf(stderr,
90 "dcerpc_unixinfo_GetPWUid failed: %s\n",
91 nt_errstr(status));
92 return status;
94 if (!NT_STATUS_IS_OK(result)) {
95 fprintf(stderr,
96 "dcerpc_unixinfo_GetPWUid returned: %s\n",
97 nt_errstr(result));
98 return result;
101 printf("status=%s, homedir=%s, shell=%s\n",
102 nt_errstr(infos.status),
103 infos.homedir,
104 infos.shell);
106 done:
107 return status;
110 /* List of commands exported by this module */
112 struct cmd_set unixinfo_commands[] = {
115 .name = "UNIXINFO",
119 .name = "getpwuid",
120 .returntype = RPC_RTYPE_NTSTATUS,
121 .ntfn = cmd_unixinfo_getpwuid,
122 .wfn = NULL,
123 .table = &ndr_table_unixinfo,
124 .rpc_pipe = NULL,
125 .description = "Get shell and homedir",
126 .usage = "",
129 .name = "uidtosid",
130 .returntype = RPC_RTYPE_NTSTATUS,
131 .ntfn = cmd_unixinfo_uidtosid,
132 .wfn = NULL,
133 .table = &ndr_table_unixinfo,
134 .rpc_pipe = NULL,
135 .description = "Convert uid to sid",
136 .usage = "",
139 .name = NULL