~vcs-imports/samba/main

« back to all changes in this revision

Viewing changes to source/rpcclient/cmd_unixinfo.c

  • Committer: jerry
  • Date: 2006-07-14 21:48:39 UTC
  • Revision ID: vcs-imports@canonical.com-20060714214839-586d8c489a8fcead
gutting trunk to move to svn:externals

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* 
2
 
   Unix SMB/CIFS implementation.
3
 
   RPC pipe client
4
 
 
5
 
   Copyright (C) Volker Lendecke 2005
6
 
 
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.
11
 
   
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.
16
 
   
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.
20
 
*/
21
 
 
22
 
#include "includes.h"
23
 
#include "rpcclient.h"
24
 
 
25
 
static NTSTATUS cmd_unixinfo_uid2sid(struct rpc_pipe_client *cli,
26
 
                                     TALLOC_CTX *mem_ctx,
27
 
                                     int argc, const char **argv)
28
 
{
29
 
        uid_t uid;
30
 
        DOM_SID sid;
31
 
        NTSTATUS result;
32
 
 
33
 
        if (argc != 2) {
34
 
                printf("Usage: %s uid\n", argv[0]);
35
 
                return NT_STATUS_INVALID_PARAMETER;
36
 
        }
37
 
 
38
 
        uid = atoi(argv[1]);
39
 
 
40
 
        result = rpccli_unixinfo_uid2sid(cli, mem_ctx, uid, &sid);
41
 
 
42
 
        if (!NT_STATUS_IS_OK(result))
43
 
                goto done;
44
 
 
45
 
        printf("%s\n", sid_string_static(&sid));
46
 
 
47
 
done:
48
 
        return result;
49
 
}
50
 
 
51
 
static NTSTATUS cmd_unixinfo_sid2uid(struct rpc_pipe_client *cli,
52
 
                                     TALLOC_CTX *mem_ctx,
53
 
                                     int argc, const char **argv)
54
 
{
55
 
        uid_t uid;
56
 
        DOM_SID sid;
57
 
        NTSTATUS result;
58
 
 
59
 
        if (argc != 2) {
60
 
                printf("Usage: %s sid\n", argv[0]);
61
 
                return NT_STATUS_INVALID_PARAMETER;
62
 
        }
63
 
 
64
 
        if (!string_to_sid(&sid, argv[1])) {
65
 
                result = NT_STATUS_INVALID_SID;
66
 
                goto done;
67
 
        }
68
 
 
69
 
        result = rpccli_unixinfo_sid2uid(cli, mem_ctx, &sid, &uid);
70
 
 
71
 
        if (!NT_STATUS_IS_OK(result))
72
 
                goto done;
73
 
 
74
 
        printf("%u\n", uid);
75
 
 
76
 
done:
77
 
        return result;
78
 
}
79
 
 
80
 
static NTSTATUS cmd_unixinfo_gid2sid(struct rpc_pipe_client *cli,
81
 
                                     TALLOC_CTX *mem_ctx,
82
 
                                     int argc, const char **argv)
83
 
{
84
 
        gid_t gid;
85
 
        DOM_SID sid;
86
 
        NTSTATUS result;
87
 
 
88
 
        if (argc != 2) {
89
 
                printf("Usage: %s gid\n", argv[0]);
90
 
                return NT_STATUS_INVALID_PARAMETER;
91
 
        }
92
 
 
93
 
        gid = atoi(argv[1]);
94
 
 
95
 
        result = rpccli_unixinfo_gid2sid(cli, mem_ctx, gid, &sid);
96
 
 
97
 
        if (!NT_STATUS_IS_OK(result))
98
 
                goto done;
99
 
 
100
 
        printf("%s\n", sid_string_static(&sid));
101
 
 
102
 
done:
103
 
        return result;
104
 
}
105
 
 
106
 
static NTSTATUS cmd_unixinfo_sid2gid(struct rpc_pipe_client *cli,
107
 
                                     TALLOC_CTX *mem_ctx,
108
 
                                     int argc, const char **argv)
109
 
{
110
 
        gid_t gid;
111
 
        DOM_SID sid;
112
 
        NTSTATUS result;
113
 
 
114
 
        if (argc != 2) {
115
 
                printf("Usage: %s sid\n", argv[0]);
116
 
                return NT_STATUS_INVALID_PARAMETER;
117
 
        }
118
 
 
119
 
        if (!string_to_sid(&sid, argv[1])) {
120
 
                result = NT_STATUS_INVALID_SID;
121
 
                goto done;
122
 
        }
123
 
 
124
 
        result = rpccli_unixinfo_sid2gid(cli, mem_ctx, &sid, &gid);
125
 
 
126
 
        if (!NT_STATUS_IS_OK(result))
127
 
                goto done;
128
 
 
129
 
        printf("%u\n", gid);
130
 
 
131
 
done:
132
 
        return result;
133
 
}
134
 
 
135
 
static NTSTATUS cmd_unixinfo_getpwuid(struct rpc_pipe_client *cli,
136
 
                                      TALLOC_CTX *mem_ctx,
137
 
                                      int argc, const char **argv)
138
 
{
139
 
        uid_t *uids;
140
 
        int i, num_uids;
141
 
        struct unixinfo_getpwuid *info;
142
 
        NTSTATUS result;
143
 
 
144
 
        if (argc < 2) {
145
 
                printf("Usage: %s uid [uid2 uid3 ...]\n", argv[0]);
146
 
                return NT_STATUS_INVALID_PARAMETER;
147
 
        }
148
 
 
149
 
        num_uids = argc-1;
150
 
        uids = TALLOC_ARRAY(mem_ctx, uid_t, num_uids);
151
 
 
152
 
        if (uids == NULL) {
153
 
                return NT_STATUS_NO_MEMORY;
154
 
        }
155
 
 
156
 
        for (i=0; i<num_uids; i++) {
157
 
                uids[i] = atoi(argv[i+1]);
158
 
        }
159
 
 
160
 
        result = rpccli_unixinfo_getpwuid(cli, mem_ctx, num_uids, uids, &info);
161
 
 
162
 
        if (!NT_STATUS_IS_OK(result)) {
163
 
                return result;
164
 
        }
165
 
 
166
 
        for (i=0; i<num_uids; i++) {
167
 
                if (NT_STATUS_IS_OK(info[i].status)) {
168
 
                        printf("%d:%s:%s\n", uids[i], info[i].homedir,
169
 
                               info[i].shell);
170
 
                } else {
171
 
                        printf("%d:%s\n", uids[i], nt_errstr(info[i].status));
172
 
                }
173
 
        }
174
 
 
175
 
        return NT_STATUS_OK;
176
 
}
177
 
 
178
 
/* List of commands exported by this module */
179
 
 
180
 
struct cmd_set unixinfo_commands[] = {
181
 
 
182
 
        { "UNIXINFO" },
183
 
 
184
 
        { "uid2sid", RPC_RTYPE_NTSTATUS, cmd_unixinfo_uid2sid, NULL,
185
 
          PI_UNIXINFO, NULL, "Convert a uid to a sid", "" },
186
 
        { "sid2uid", RPC_RTYPE_NTSTATUS, cmd_unixinfo_sid2uid, NULL,
187
 
          PI_UNIXINFO, NULL, "Convert a sid to a uid", "" },
188
 
        { "gid2sid", RPC_RTYPE_NTSTATUS, cmd_unixinfo_gid2sid, NULL,
189
 
          PI_UNIXINFO, NULL, "Convert a gid to a sid", "" },
190
 
        { "sid2gid", RPC_RTYPE_NTSTATUS, cmd_unixinfo_sid2gid, NULL,
191
 
          PI_UNIXINFO, NULL, "Convert a sid to a gid", "" },
192
 
        { "getpwuid", RPC_RTYPE_NTSTATUS, cmd_unixinfo_getpwuid, NULL,
193
 
          PI_UNIXINFO, NULL, "Get passwd info", "" },
194
 
        { NULL }
195
 
};