r18865: fixed some of the most obvious NTSTATUS/WERROR mixups in Samba3. It
[Samba/nascimento.git] / source3 / rpcclient / cmd_unixinfo.c
blob5d13955841f610cfea6bad7c26646bd22611ae92
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", 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", 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 result = rpccli_unixinfo_GetPWUid(cli, mem_ctx, &num_uids, uids, info);
161 if (!NT_STATUS_IS_OK(result)) {
162 return result;
165 for (i=0; i<num_uids; i++) {
166 if (NT_STATUS_IS_OK(info[i].status)) {
167 printf("%llu:%s:%s\n", uids[i], info[i].homedir,
168 info[i].shell);
169 } else {
170 printf("%llu:%s\n", uids[i], nt_errstr(info[i].status));
174 return NT_STATUS_OK;
177 /* List of commands exported by this module */
179 struct cmd_set unixinfo_commands[] = {
181 { "UNIXINFO" },
183 { "uid2sid", RPC_RTYPE_NTSTATUS, cmd_unixinfo_uid2sid, NULL,
184 PI_UNIXINFO, NULL, "Convert a uid to a sid", "" },
185 { "sid2uid", RPC_RTYPE_NTSTATUS, cmd_unixinfo_sid2uid, NULL,
186 PI_UNIXINFO, NULL, "Convert a sid to a uid", "" },
187 { "gid2sid", RPC_RTYPE_NTSTATUS, cmd_unixinfo_gid2sid, NULL,
188 PI_UNIXINFO, NULL, "Convert a gid to a sid", "" },
189 { "sid2gid", RPC_RTYPE_NTSTATUS, cmd_unixinfo_sid2gid, NULL,
190 PI_UNIXINFO, NULL, "Convert a sid to a gid", "" },
191 { "getpwuid", RPC_RTYPE_NTSTATUS, cmd_unixinfo_getpwuid, NULL,
192 PI_UNIXINFO, NULL, "Get passwd info", "" },
193 { NULL }