r25068: Older samba3 DCs will return DCERPC_FAULT_OP_RNG_ERROR for every opcode on the
[Samba.git] / source / rpcclient / cmd_unixinfo.c
blob1725ce8bfe772f79dc773aa8757d7fdbc9922148
1 /*
2 Unix SMB/CIFS implementation.
3 RPC pipe client
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.
22 #include "includes.h"
23 #include "rpcclient.h"
25 static NTSTATUS cmd_unixinfo_uid2sid(struct rpc_pipe_client *cli,
26 TALLOC_CTX *mem_ctx,
27 int argc, const char **argv)
29 uid_t uid;
30 DOM_SID sid;
31 NTSTATUS result;
33 if (argc != 2) {
34 printf("Usage: %s uid\n", argv[0]);
35 return NT_STATUS_INVALID_PARAMETER;
38 uid = atoi(argv[1]);
39 result = rpccli_unixinfo_UidToSid(cli, mem_ctx, uid, &sid);
41 if (!NT_STATUS_IS_OK(result))
42 goto done;
44 printf("%s\n", sid_string_static(&sid));
46 done:
47 return result;
50 static NTSTATUS cmd_unixinfo_sid2uid(struct rpc_pipe_client *cli,
51 TALLOC_CTX *mem_ctx,
52 int argc, const char **argv)
54 uint64_t uid;
55 DOM_SID sid;
56 NTSTATUS result;
58 if (argc != 2) {
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;
65 goto done;
68 result = rpccli_unixinfo_SidToUid(cli, mem_ctx, sid, &uid);
70 if (!NT_STATUS_IS_OK(result))
71 goto done;
73 printf("%llu\n", (unsigned long long)uid);
75 done:
76 return result;
79 static NTSTATUS cmd_unixinfo_gid2sid(struct rpc_pipe_client *cli,
80 TALLOC_CTX *mem_ctx,
81 int argc, const char **argv)
83 gid_t gid;
84 DOM_SID sid;
85 NTSTATUS result;
87 if (argc != 2) {
88 printf("Usage: %s gid\n", argv[0]);
89 return NT_STATUS_INVALID_PARAMETER;
92 gid = atoi(argv[1]);
94 result = rpccli_unixinfo_GidToSid(cli, mem_ctx, gid, &sid);
96 if (!NT_STATUS_IS_OK(result))
97 goto done;
99 printf("%s\n", sid_string_static(&sid));
101 done:
102 return result;
105 static NTSTATUS cmd_unixinfo_sid2gid(struct rpc_pipe_client *cli,
106 TALLOC_CTX *mem_ctx,
107 int argc, const char **argv)
109 uint64_t gid;
110 DOM_SID sid;
111 NTSTATUS result;
113 if (argc != 2) {
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;
120 goto done;
123 result = rpccli_unixinfo_SidToGid(cli, mem_ctx, sid, &gid);
125 if (!NT_STATUS_IS_OK(result))
126 goto done;
128 printf("%llu\n", (unsigned long long)gid);
130 done:
131 return result;
134 static NTSTATUS cmd_unixinfo_getpwuid(struct rpc_pipe_client *cli,
135 TALLOC_CTX *mem_ctx,
136 int argc, const char **argv)
138 uint64_t *uids;
139 unsigned int i, num_uids;
140 struct unixinfo_GetPWUidInfo *info;
141 NTSTATUS result;
143 if (argc < 2) {
144 printf("Usage: %s uid [uid2 uid3 ...]\n", argv[0]);
145 return NT_STATUS_INVALID_PARAMETER;
148 num_uids = argc-1;
149 uids = TALLOC_ARRAY(mem_ctx, uint64_t, num_uids);
151 if (uids == NULL) {
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);
160 if (info == NULL) {
161 return NT_STATUS_NO_MEMORY;
165 result = rpccli_unixinfo_GetPWUid(cli, mem_ctx, &num_uids, uids,
166 info);
168 if (!NT_STATUS_IS_OK(result)) {
169 return 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);
176 } else {
177 printf("%llu:%s\n", (unsigned long long)uids[i],
178 nt_errstr(info[i].status));
182 return NT_STATUS_OK;
185 /* List of commands exported by this module */
187 struct cmd_set unixinfo_commands[] = {
189 { "UNIXINFO" },
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", "" },
201 { NULL }