r16945: Sync trunk -> 3.0 for 3.0.24 code. Still need
[vlendec/samba-autobuild/.git] / source3 / rpc_parse / parse_unixinfo.c
1 /* 
2  *  Unix SMB/CIFS implementation.
3  *
4  *  RPC Pipe client / server routines
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 #undef DBGC_CLASS
26 #define DBGC_CLASS DBGC_RPC_PARSE
27
28 void init_q_unixinfo_sid_to_uid(UNIXINFO_Q_SID_TO_UID *q_d, const DOM_SID *sid)
29 {
30         sid_copy(&q_d->sid, sid);
31 }
32
33 BOOL unixinfo_io_q_unixinfo_sid_to_uid(const char *desc, UNIXINFO_Q_SID_TO_UID *q_d,
34                                  prs_struct *ps, int depth)
35 {
36         return smb_io_dom_sid(desc, &q_d->sid, ps, depth);
37 }
38
39 BOOL unixinfo_io_r_unixinfo_sid_to_uid(const char *desc, UNIXINFO_R_SID_TO_UID *r_d,
40                                  prs_struct *ps, int depth)
41 {
42         if (!prs_uint64(desc, ps, depth, &r_d->uid))
43                 return False;
44
45         if (!prs_ntstatus(desc, ps, depth, &r_d->status))
46                 return False;
47
48         return True;
49 }
50
51 void init_q_unixinfo_uid_to_sid(UNIXINFO_Q_UID_TO_SID *q_d, UINT64_S uid)
52 {
53         q_d->uid = uid;
54 }
55
56 BOOL unixinfo_io_q_unixinfo_uid_to_sid(const char *desc, UNIXINFO_Q_UID_TO_SID *q_d,
57                                  prs_struct *ps, int depth)
58 {
59         return prs_uint64(desc, ps, depth, &q_d->uid);
60 }
61
62 void init_r_unixinfo_uid_to_sid(UNIXINFO_R_UID_TO_SID *r_d, DOM_SID *sid)
63 {
64         if (sid == NULL) {
65                 r_d->sidptr = 0;
66                 return;
67         }
68         r_d->sidptr = 1;
69         sid_copy(&r_d->sid, sid);
70 }
71
72 BOOL unixinfo_io_r_unixinfo_uid_to_sid(const char *desc, UNIXINFO_R_UID_TO_SID *r_d,
73                                  prs_struct *ps, int depth)
74 {
75         if (!prs_uint32("sidptr", ps, depth, &r_d->sidptr))
76                 return False;
77
78         if (r_d->sidptr != 0) {
79                 if (!smb_io_dom_sid(desc, &r_d->sid, ps, depth))
80                         return False;
81         }
82
83         if (!prs_ntstatus(desc, ps, depth, &r_d->status))
84                 return False;
85
86         return True;
87 }
88
89 void init_q_unixinfo_sid_to_gid(UNIXINFO_Q_SID_TO_GID *q_d, const DOM_SID *sid)
90 {
91         sid_copy(&q_d->sid, sid);
92 }
93
94 BOOL unixinfo_io_q_unixinfo_sid_to_gid(const char *desc, UNIXINFO_Q_SID_TO_GID *q_d,
95                                  prs_struct *ps, int depth)
96 {
97         return smb_io_dom_sid(desc, &q_d->sid, ps, depth);
98 }
99
100 void init_r_unixinfo_sid_to_gid(UNIXINFO_R_SID_TO_GID *r_d, UINT64_S gid)
101 {
102         r_d->gid = gid;
103         r_d->status = NT_STATUS_OK;
104 }
105
106 BOOL unixinfo_io_r_unixinfo_sid_to_gid(const char *desc, UNIXINFO_R_SID_TO_GID *r_d,
107                                  prs_struct *ps, int depth)
108 {
109         if (!prs_uint64(desc, ps, depth, &r_d->gid))
110                 return False;
111
112         if (!prs_ntstatus(desc, ps, depth, &r_d->status))
113                 return False;
114
115         return True;
116 }
117
118 void init_q_unixinfo_gid_to_sid(UNIXINFO_Q_GID_TO_SID *q_d, UINT64_S gid)
119 {
120         q_d->gid = gid;
121 }
122
123 BOOL unixinfo_io_q_unixinfo_gid_to_sid(const char *desc, UNIXINFO_Q_GID_TO_SID *q_d,
124                                  prs_struct *ps, int depth)
125 {
126         return prs_uint64(desc, ps, depth, &q_d->gid);
127 }
128
129 void init_r_unixinfo_gid_to_sid(UNIXINFO_R_GID_TO_SID *r_d, DOM_SID *sid)
130 {
131         if (sid == NULL) {
132                 r_d->sidptr = 0;
133                 return;
134         }
135         r_d->sidptr = 1;
136         sid_copy(&r_d->sid, sid);
137 }
138
139 BOOL unixinfo_io_r_unixinfo_gid_to_sid(const char *desc, UNIXINFO_R_GID_TO_SID *r_d,
140                                  prs_struct *ps, int depth)
141 {
142         if (!prs_uint32("sidptr", ps, depth, &r_d->sidptr))
143                 return False;
144
145         if (r_d->sidptr != 0) {
146                 if (!smb_io_dom_sid(desc, &r_d->sid, ps, depth))
147                         return False;
148         }
149
150         if (!prs_ntstatus(desc, ps, depth, &r_d->status))
151                 return False;
152
153         return True;
154 }
155
156 void init_q_unixinfo_getpwuid(UNIXINFO_Q_GETPWUID *r_d, int count,
157                               UINT64_S *uids)
158 {
159         r_d->count = count;
160         r_d->uid = uids;
161 }
162
163 BOOL unixinfo_io_q_unixinfo_getpwuid(const char *desc,
164                                      UNIXINFO_Q_GETPWUID *q_d,
165                                      prs_struct *ps, int depth)
166 {
167         uint32 arraysize;
168         int i;
169
170         if (!prs_uint32("count", ps, depth, &q_d->count))
171                 return False;
172
173         arraysize = q_d->count;
174
175         if (!prs_uint32("arraysize", ps, depth, &arraysize))
176                 return False;
177
178         if (arraysize != q_d->count) {
179                 DEBUG(10, ("count!=arraysize\n"));
180                 return False;
181         }
182
183         if (q_d->count > 1023) {
184                 DEBUG(10, ("Range exceeded\n"));
185                 return False;
186         }
187
188         if (UNMARSHALLING(ps)) {
189                 q_d->uid = PRS_ALLOC_MEM(ps, UINT64_S, q_d->count);
190                 if (q_d->uid == NULL) {
191                         return False;
192                 }
193         }
194
195         for (i=0; i<q_d->count; i++) {
196                 if (!prs_uint64(desc, ps, depth+1, &q_d->uid[i]))
197                         return False;
198         }
199
200         return True;
201 }
202
203 void init_r_unixinfo_getpwuid(UNIXINFO_R_GETPWUID *r_d, uint32 count,
204                               struct unixinfo_getpwuid *info)
205 {
206         r_d->count = count;
207         r_d->info = info;
208 }
209
210 BOOL unixinfo_io_r_unixinfo_getpwuid(const char *desc,
211                                      UNIXINFO_R_GETPWUID *r_d,
212                                      prs_struct *ps, int depth)
213 {
214         uint32 arraysize;
215         int i;
216
217         if (!prs_uint32("count", ps, depth, &r_d->count))
218                 return False;
219
220         arraysize = r_d->count;
221
222         if (!prs_uint32("arraysize", ps, depth, &arraysize))
223                 return False;
224
225         if (arraysize != r_d->count) {
226                 DEBUG(10, ("count!=arraysize\n"));
227                 return False;
228         }
229
230         if (r_d->count > 1023) {
231                 DEBUG(10, ("Range exceeded\n"));
232                 return False;
233         }
234
235         if (UNMARSHALLING(ps)) {
236                 r_d->info = PRS_ALLOC_MEM(ps, struct unixinfo_getpwuid,
237                                           r_d->count);
238                 if (r_d->info == NULL) {
239                         return False;
240                 }
241         }
242
243         for (i=0; i<r_d->count; i++) {
244                 if (!prs_align(ps))
245                         return False;
246
247                 if (!prs_ntstatus("status", ps, depth+1, &r_d->info[i].status))
248                         return False;
249
250                 if (!prs_string_alloc("homedir", ps, depth+1,
251                                       &r_d->info[i].homedir))
252                         return False;
253
254                 if (!prs_string_alloc("shell", ps, depth+1,
255                                       &r_d->info[i].shell))
256                         return False;
257         }
258
259         if (!prs_align(ps))
260                 return False;
261
262         if (!prs_ntstatus(desc, ps, depth, &r_d->status))
263                 return False;
264
265         return True;
266 }