~vcs-imports/samba/main

« back to all changes in this revision

Viewing changes to source/rpc_client/cli_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
 
 
4
 
   RPC pipe client
5
 
 
6
 
   Copyright (C) Volker Lendecke 2005
7
 
   
8
 
   This program is free software; you can redistribute it and/or modify
9
 
   it under the terms of the GNU General Public License as published by
10
 
   the Free Software Foundation; either version 2 of the License, or
11
 
   (at your option) any later version.
12
 
   
13
 
   This program is distributed in the hope that it will be useful,
14
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
   GNU General Public License for more details.
17
 
   
18
 
   You should have received a copy of the GNU General Public License
19
 
   along with this program; if not, write to the Free Software
20
 
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
 
*/
22
 
 
23
 
#include "includes.h"
24
 
 
25
 
NTSTATUS rpccli_unixinfo_uid2sid(struct rpc_pipe_client *cli,
26
 
                                 TALLOC_CTX *mem_ctx, uid_t uid, DOM_SID *sid)
27
 
{
28
 
        prs_struct qbuf, rbuf;
29
 
        UNIXINFO_Q_UID_TO_SID q;
30
 
        UNIXINFO_R_UID_TO_SID r;
31
 
        NTSTATUS result = NT_STATUS_NET_WRITE_FAULT;
32
 
 
33
 
        ZERO_STRUCT(q);
34
 
        ZERO_STRUCT(r);
35
 
 
36
 
        /* Marshall data and send request */
37
 
        {
38
 
                UINT64_S uid64;
39
 
                uid64.high = 0;
40
 
                uid64.low = uid;
41
 
                init_q_unixinfo_uid_to_sid(&q, uid64);
42
 
        }
43
 
 
44
 
        CLI_DO_RPC(cli, mem_ctx, PI_UNIXINFO, UNIXINFO_UID_TO_SID,
45
 
                q, r,
46
 
                qbuf, rbuf,
47
 
                unixinfo_io_q_unixinfo_uid_to_sid,
48
 
                unixinfo_io_r_unixinfo_uid_to_sid,
49
 
                NT_STATUS_NET_WRITE_FAULT);
50
 
 
51
 
        if (NT_STATUS_IS_OK(r.status) && (sid != NULL)) {
52
 
                sid_copy(sid, &r.sid);
53
 
        }
54
 
 
55
 
        result = r.status;
56
 
        return result;
57
 
}
58
 
 
59
 
NTSTATUS rpccli_unixinfo_sid2uid(struct rpc_pipe_client *cli,
60
 
                                 TALLOC_CTX *mem_ctx,
61
 
                                 const DOM_SID *sid, uid_t *uid)
62
 
{
63
 
        prs_struct qbuf, rbuf;
64
 
        UNIXINFO_Q_SID_TO_UID q;
65
 
        UNIXINFO_R_SID_TO_UID r;
66
 
        NTSTATUS result = NT_STATUS_NET_WRITE_FAULT;
67
 
 
68
 
        ZERO_STRUCT(q);
69
 
        ZERO_STRUCT(r);
70
 
 
71
 
        /* Marshall data and send request */
72
 
        init_q_unixinfo_sid_to_uid(&q, sid);
73
 
 
74
 
        CLI_DO_RPC(cli, mem_ctx, PI_UNIXINFO, UNIXINFO_SID_TO_UID,
75
 
                q, r,
76
 
                qbuf, rbuf,
77
 
                unixinfo_io_q_unixinfo_sid_to_uid,
78
 
                unixinfo_io_r_unixinfo_sid_to_uid,
79
 
                NT_STATUS_NET_WRITE_FAULT);
80
 
 
81
 
        if (NT_STATUS_IS_OK(r.status)) {
82
 
                if (r.uid.high != 0) {
83
 
                        /* 64-Bit uid's not yet handled */
84
 
                        return NT_STATUS_INVALID_PARAMETER;
85
 
                }
86
 
                if (uid != NULL) {
87
 
                        *uid = r.uid.low;
88
 
                }
89
 
        }
90
 
 
91
 
        result = r.status;
92
 
        return result;
93
 
}
94
 
 
95
 
NTSTATUS rpccli_unixinfo_gid2sid(struct rpc_pipe_client *cli,
96
 
                                 TALLOC_CTX *mem_ctx, gid_t gid, DOM_SID *sid)
97
 
{
98
 
        prs_struct qbuf, rbuf;
99
 
        UNIXINFO_Q_GID_TO_SID q;
100
 
        UNIXINFO_R_GID_TO_SID r;
101
 
        NTSTATUS result = NT_STATUS_NET_WRITE_FAULT;
102
 
 
103
 
        ZERO_STRUCT(q);
104
 
        ZERO_STRUCT(r);
105
 
 
106
 
        /* Marshall data and send request */
107
 
        {
108
 
                UINT64_S gid64;
109
 
                gid64.high = 0;
110
 
                gid64.low = gid;
111
 
                init_q_unixinfo_gid_to_sid(&q, gid64);
112
 
        }
113
 
 
114
 
        CLI_DO_RPC(cli, mem_ctx, PI_UNIXINFO, UNIXINFO_GID_TO_SID,
115
 
                q, r,
116
 
                qbuf, rbuf,
117
 
                unixinfo_io_q_unixinfo_gid_to_sid,
118
 
                unixinfo_io_r_unixinfo_gid_to_sid,
119
 
                NT_STATUS_NET_WRITE_FAULT);
120
 
 
121
 
        if (NT_STATUS_IS_OK(r.status) && (sid != NULL)) {
122
 
                sid_copy(sid, &r.sid);
123
 
        }
124
 
 
125
 
        result = r.status;
126
 
        return result;
127
 
}
128
 
 
129
 
NTSTATUS rpccli_unixinfo_sid2gid(struct rpc_pipe_client *cli,
130
 
                                 TALLOC_CTX *mem_ctx,
131
 
                                 const DOM_SID *sid, gid_t *gid)
132
 
{
133
 
        prs_struct qbuf, rbuf;
134
 
        UNIXINFO_Q_SID_TO_GID q;
135
 
        UNIXINFO_R_SID_TO_GID r;
136
 
        NTSTATUS result = NT_STATUS_NET_WRITE_FAULT;
137
 
 
138
 
        ZERO_STRUCT(q);
139
 
        ZERO_STRUCT(r);
140
 
 
141
 
        /* Marshall data and send request */
142
 
        init_q_unixinfo_sid_to_gid(&q, sid);
143
 
 
144
 
        CLI_DO_RPC(cli, mem_ctx, PI_UNIXINFO, UNIXINFO_SID_TO_GID,
145
 
                q, r,
146
 
                qbuf, rbuf,
147
 
                unixinfo_io_q_unixinfo_sid_to_gid,
148
 
                unixinfo_io_r_unixinfo_sid_to_gid,
149
 
                NT_STATUS_NET_WRITE_FAULT);
150
 
 
151
 
        if (NT_STATUS_IS_OK(r.status)) {
152
 
                if (r.gid.high != 0) {
153
 
                        /* 64-Bit gid's not yet handled */
154
 
                        return NT_STATUS_INVALID_PARAMETER;
155
 
                }
156
 
                if (gid != NULL) {
157
 
                        *gid = r.gid.low;
158
 
                }
159
 
        }
160
 
 
161
 
        result = r.status;
162
 
        return result;
163
 
}
164
 
 
165
 
NTSTATUS rpccli_unixinfo_getpwuid(struct rpc_pipe_client *cli,
166
 
                                  TALLOC_CTX *mem_ctx,
167
 
                                  int count, uid_t *uids,
168
 
                                  struct unixinfo_getpwuid **info)
169
 
{
170
 
        prs_struct qbuf, rbuf;
171
 
        UNIXINFO_Q_GETPWUID q;
172
 
        UNIXINFO_R_GETPWUID r;
173
 
        NTSTATUS result = NT_STATUS_NET_WRITE_FAULT;
174
 
        int i;
175
 
        UINT64_S *uids64;
176
 
 
177
 
        ZERO_STRUCT(q);
178
 
        ZERO_STRUCT(r);
179
 
 
180
 
        /* Marshall data and send request */
181
 
 
182
 
        uids64 = TALLOC_ARRAY(mem_ctx, UINT64_S, count);
183
 
        if (uids64 == NULL) {
184
 
                return NT_STATUS_NO_MEMORY;
185
 
        }
186
 
 
187
 
        for (i=0; i<count; i++) {
188
 
                uids64[i].high = 0;
189
 
                uids64[i].low = uids[i];
190
 
        }
191
 
 
192
 
        init_q_unixinfo_getpwuid(&q, count, uids64);
193
 
 
194
 
        CLI_DO_RPC(cli, mem_ctx, PI_UNIXINFO, UNIXINFO_GETPWUID,
195
 
                q, r,
196
 
                qbuf, rbuf,
197
 
                unixinfo_io_q_unixinfo_getpwuid,
198
 
                unixinfo_io_r_unixinfo_getpwuid,
199
 
                NT_STATUS_NET_WRITE_FAULT);
200
 
 
201
 
        if (!NT_STATUS_IS_OK(r.status)) {
202
 
                result = r.status;
203
 
                *info = NULL;
204
 
                return result;
205
 
        }
206
 
 
207
 
        if (r.count != count) {
208
 
                DEBUG(0, ("Expected array size %d, got %d\n",
209
 
                          count, r.count));
210
 
                return NT_STATUS_INVALID_PARAMETER;
211
 
        }
212
 
 
213
 
        *info = TALLOC_ARRAY(mem_ctx, struct unixinfo_getpwuid, count);
214
 
        if (*info == NULL) {
215
 
                return NT_STATUS_NO_MEMORY;
216
 
        }
217
 
 
218
 
        for (i=0; i<count; i++) {
219
 
                (*info)[i].status = r.info[i].status;
220
 
                (*info)[i].homedir = talloc_strdup(mem_ctx, r.info[i].homedir);
221
 
                (*info)[i].shell = talloc_strdup(mem_ctx, r.info[i].shell);
222
 
        }
223
 
 
224
 
        result = r.status;
225
 
        return result;
226
 
}