2 Unix SMB/CIFS implementation.
5 Copyright (C) Volker Lendecke 2005
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "rpcclient.h"
25 static NTSTATUS
cmd_unixinfo_uid2sid(struct rpc_pipe_client
*cli
,
27 int argc
, const char **argv
)
34 printf("Usage: %s uid\n", argv
[0]);
35 return NT_STATUS_INVALID_PARAMETER
;
39 result
= rpccli_unixinfo_UidToSid(cli
, mem_ctx
, uid
, &sid
);
41 if (!NT_STATUS_IS_OK(result
))
44 printf("%s\n", sid_string_static(&sid
));
50 static NTSTATUS
cmd_unixinfo_sid2uid(struct rpc_pipe_client
*cli
,
52 int argc
, const char **argv
)
59 printf("Usage: %s sid\n", argv
[0]);
60 return NT_STATUS_INVALID_PARAMETER
;
63 if (!string_to_sid(&sid
, argv
[1])) {
64 result
= NT_STATUS_INVALID_SID
;
68 result
= rpccli_unixinfo_SidToUid(cli
, mem_ctx
, sid
, &uid
);
70 if (!NT_STATUS_IS_OK(result
))
73 printf("%llu\n", (unsigned long long)uid
);
79 static NTSTATUS
cmd_unixinfo_gid2sid(struct rpc_pipe_client
*cli
,
81 int argc
, const char **argv
)
88 printf("Usage: %s gid\n", argv
[0]);
89 return NT_STATUS_INVALID_PARAMETER
;
94 result
= rpccli_unixinfo_GidToSid(cli
, mem_ctx
, gid
, &sid
);
96 if (!NT_STATUS_IS_OK(result
))
99 printf("%s\n", sid_string_static(&sid
));
105 static NTSTATUS
cmd_unixinfo_sid2gid(struct rpc_pipe_client
*cli
,
107 int argc
, const char **argv
)
114 printf("Usage: %s sid\n", argv
[0]);
115 return NT_STATUS_INVALID_PARAMETER
;
118 if (!string_to_sid(&sid
, argv
[1])) {
119 result
= NT_STATUS_INVALID_SID
;
123 result
= rpccli_unixinfo_SidToGid(cli
, mem_ctx
, sid
, &gid
);
125 if (!NT_STATUS_IS_OK(result
))
128 printf("%llu\n", (unsigned long long)gid
);
134 static NTSTATUS
cmd_unixinfo_getpwuid(struct rpc_pipe_client
*cli
,
136 int argc
, const char **argv
)
139 unsigned int i
, num_uids
;
140 struct unixinfo_GetPWUidInfo
*info
;
144 printf("Usage: %s uid [uid2 uid3 ...]\n", argv
[0]);
145 return NT_STATUS_INVALID_PARAMETER
;
149 uids
= TALLOC_ARRAY(mem_ctx
, uint64_t, num_uids
);
152 return NT_STATUS_NO_MEMORY
;
155 for (i
=0; i
<num_uids
; i
++) {
156 uids
[i
] = atoi(argv
[i
+1]);
159 info
= TALLOC_ARRAY(mem_ctx
, struct unixinfo_GetPWUidInfo
, num_uids
);
161 return NT_STATUS_NO_MEMORY
;
165 result
= rpccli_unixinfo_GetPWUid(cli
, mem_ctx
, &num_uids
, uids
,
168 if (!NT_STATUS_IS_OK(result
)) {
172 for (i
=0; i
<num_uids
; i
++) {
173 if (NT_STATUS_IS_OK(info
[i
].status
)) {
174 printf("%llu:%s:%s\n", (unsigned long long)uids
[i
],
175 info
[i
].homedir
, info
[i
].shell
);
177 printf("%llu:%s\n", (unsigned long long)uids
[i
],
178 nt_errstr(info
[i
].status
));
185 /* List of commands exported by this module */
187 struct cmd_set unixinfo_commands
[] = {
191 { "uid2sid", RPC_RTYPE_NTSTATUS
, cmd_unixinfo_uid2sid
, NULL
,
192 PI_UNIXINFO
, NULL
, "Convert a uid to a sid", "" },
193 { "sid2uid", RPC_RTYPE_NTSTATUS
, cmd_unixinfo_sid2uid
, NULL
,
194 PI_UNIXINFO
, NULL
, "Convert a sid to a uid", "" },
195 { "gid2sid", RPC_RTYPE_NTSTATUS
, cmd_unixinfo_gid2sid
, NULL
,
196 PI_UNIXINFO
, NULL
, "Convert a gid to a sid", "" },
197 { "sid2gid", RPC_RTYPE_NTSTATUS
, cmd_unixinfo_sid2gid
, NULL
,
198 PI_UNIXINFO
, NULL
, "Convert a sid to a gid", "" },
199 { "getpwuid", RPC_RTYPE_NTSTATUS
, cmd_unixinfo_getpwuid
, NULL
,
200 PI_UNIXINFO
, NULL
, "Get passwd info", "" },