2 * Unix SMB/Netbios implementation.
4 * RPC Pipe client / server routines
5 * Copyright (C) Andrew Tridgell 1992-1998,
6 * Copyright (C) Jeremy R. Allison 1995-2005.
7 * Copyright (C) Luke Kenneth Casson Leighton 1996-1998,
8 * Copyright (C) Paul Ashton 1997-1998.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #define DBGC_CLASS DBGC_RPC_PARSE
30 /*******************************************************************
31 Reads or writes a SEC_ACCESS structure.
32 ********************************************************************/
34 BOOL sec_io_access(const char *desc, SEC_ACCESS *t, prs_struct *ps, int depth)
39 prs_debug(ps, depth, desc, "sec_io_access");
42 if(!prs_uint32("mask", ps, depth, t))
48 /*******************************************************************
49 Reads or writes a SEC_ACE structure.
50 ********************************************************************/
52 BOOL sec_io_ace(const char *desc, SEC_ACE *psa, prs_struct *ps, int depth)
55 uint32 offset_ace_size;
61 prs_debug(ps, depth, desc, "sec_io_ace");
64 old_offset = prs_offset(ps);
66 if (MARSHALLING(ps)) {
67 type = (uint8)psa->type;
70 if(!prs_uint8("type ", ps, depth, &type))
73 if (UNMARSHALLING(ps)) {
74 psa->type = (enum security_ace_type)type;
77 if(!prs_uint8("flags", ps, depth, &psa->flags))
80 if(!prs_uint16_pre("size ", ps, depth, &psa->size, &offset_ace_size))
83 if(!prs_uint32("access_mask", ps, depth, &psa->access_mask))
86 /* check whether object access is present */
87 if (!sec_ace_object(psa->type)) {
88 if (!smb_io_dom_sid("trustee ", &psa->trustee , ps, depth))
91 if (!prs_uint32("obj_flags", ps, depth, &psa->object.object.flags))
94 if (psa->object.object.flags & SEC_ACE_OBJECT_PRESENT)
95 if (!smb_io_uuid("obj_guid", &psa->object.object.type.type, ps,depth))
98 if (psa->object.object.flags & SEC_ACE_OBJECT_INHERITED_PRESENT)
99 if (!smb_io_uuid("inh_guid", &psa->object.object.inherited_type.inherited_type, ps,depth))
102 if(!smb_io_dom_sid("trustee ", &psa->trustee , ps, depth))
106 /* Theorectically an ACE can have a size greater than the
107 sum of its components. When marshalling, pad with extra null bytes up to the
110 if (MARSHALLING(ps) && (psa->size > prs_offset(ps) - old_offset)) {
111 uint32 extra_len = psa->size - (prs_offset(ps) - old_offset);
115 for (i = 0; i < extra_len; i++) {
116 if (!prs_uint8("ace extra space", ps, depth, &c))
121 if(!prs_uint16_post("size ", ps, depth, &psa->size, offset_ace_size, old_offset))
127 /*******************************************************************
128 Reads or writes a SEC_ACL structure.
130 First of the xx_io_xx functions that allocates its data structures
131 for you as it reads them.
132 ********************************************************************/
134 BOOL sec_io_acl(const char *desc, SEC_ACL **ppsa, prs_struct *ps, int depth)
138 uint32 offset_acl_size;
143 * Note that the size is always a multiple of 4 bytes due to the
144 * nature of the data structure. Therefore the prs_align() calls
145 * have been removed as they through us off when doing two-layer
146 * marshalling such as in the printing code (RPC_BUFFER). --jerry
154 if(UNMARSHALLING(ps) && psa == NULL) {
156 * This is a read and we must allocate the stuct to read into.
158 if((psa = PRS_ALLOC_MEM(ps, SEC_ACL, 1)) == NULL)
163 prs_debug(ps, depth, desc, "sec_io_acl");
166 old_offset = prs_offset(ps);
168 if (MARSHALLING(ps)) {
169 revision = (uint16)psa->revision;
172 if(!prs_uint16("revision", ps, depth, &revision))
175 if (UNMARSHALLING(ps)) {
176 psa->revision = (enum security_acl_revision)revision;
179 if(!prs_uint16_pre("size ", ps, depth, &psa->size, &offset_acl_size))
182 if(!prs_uint32("num_aces ", ps, depth, &psa->num_aces))
185 if (UNMARSHALLING(ps)) {
187 * Even if the num_aces is zero, allocate memory as there's a difference
188 * between a non-present DACL (allow all access) and a DACL with no ACE's
191 if((psa->aces = PRS_ALLOC_MEM(ps, SEC_ACE, psa->num_aces+1)) == NULL)
195 for (i = 0; i < psa->num_aces; i++) {
197 slprintf(tmp, sizeof(tmp)-1, "ace_list[%02d]: ", i);
198 if(!sec_io_ace(tmp, &psa->aces[i], ps, depth))
202 /* Theorectically an ACL can have a size greater than the
203 sum of its components. When marshalling, pad with extra null bytes up to the
206 if (MARSHALLING(ps) && (psa->size > prs_offset(ps) - old_offset)) {
207 uint32 extra_len = psa->size - (prs_offset(ps) - old_offset);
210 for (i = 0; i < extra_len; i++) {
211 if (!prs_uint8("acl extra space", ps, depth, &c))
216 if(!prs_uint16_post("size ", ps, depth, &psa->size, offset_acl_size, old_offset))
222 /*******************************************************************
223 Reads or writes a SEC_DESC structure.
224 If reading and the *ppsd = NULL, allocates the structure.
225 ********************************************************************/
227 BOOL sec_io_desc(const char *desc, SEC_DESC **ppsd, prs_struct *ps, int depth)
230 uint32 max_offset = 0; /* after we're done, move offset to end */
231 uint32 tmp_offset = 0;
232 uint32 off_sacl, off_dacl, off_owner_sid, off_grp_sid;
243 if(UNMARSHALLING(ps)) {
244 if((psd = PRS_ALLOC_MEM(ps,SEC_DESC,1)) == NULL)
248 /* Marshalling - just ignore. */
253 prs_debug(ps, depth, desc, "sec_io_desc");
256 /* start of security descriptor stored for back-calc offset purposes */
257 old_offset = prs_offset(ps);
259 if (MARSHALLING(ps)) {
260 revision = (uint16)psd->revision;
263 if(!prs_uint16("revision", ps, depth, &revision))
266 if (UNMARSHALLING(ps)) {
267 psd->revision = (enum security_acl_revision)revision;
270 if(!prs_uint16("type ", ps, depth, &psd->type))
273 if (MARSHALLING(ps)) {
274 uint32 offset = SEC_DESC_HEADER_SIZE;
277 * Work out the offsets here, as we write it out.
280 if (psd->sacl != NULL) {
282 offset += psd->sacl->size;
287 if (psd->dacl != NULL) {
289 offset += psd->dacl->size;
294 if (psd->owner_sid != NULL) {
295 off_owner_sid = offset;
296 offset += sid_size(psd->owner_sid);
301 if (psd->group_sid != NULL) {
302 off_grp_sid = offset;
303 offset += sid_size(psd->group_sid);
309 if(!prs_uint32("off_owner_sid", ps, depth, &off_owner_sid))
312 if(!prs_uint32("off_grp_sid ", ps, depth, &off_grp_sid))
315 if(!prs_uint32("off_sacl ", ps, depth, &off_sacl))
318 if(!prs_uint32("off_dacl ", ps, depth, &off_dacl))
321 max_offset = MAX(max_offset, prs_offset(ps));
323 if (off_owner_sid != 0) {
325 tmp_offset = prs_offset(ps);
326 if(!prs_set_offset(ps, old_offset + off_owner_sid))
329 if (UNMARSHALLING(ps)) {
331 if((psd->owner_sid = PRS_ALLOC_MEM(ps,DOM_SID,1)) == NULL)
335 if(!smb_io_dom_sid("owner_sid ", psd->owner_sid , ps, depth))
338 max_offset = MAX(max_offset, prs_offset(ps));
340 if (!prs_set_offset(ps,tmp_offset))
344 if (psd->group_sid != 0) {
346 tmp_offset = prs_offset(ps);
347 if(!prs_set_offset(ps, old_offset + off_grp_sid))
350 if (UNMARSHALLING(ps)) {
352 if((psd->group_sid = PRS_ALLOC_MEM(ps,DOM_SID,1)) == NULL)
356 if(!smb_io_dom_sid("grp_sid", psd->group_sid, ps, depth))
359 max_offset = MAX(max_offset, prs_offset(ps));
361 if (!prs_set_offset(ps,tmp_offset))
365 if ((psd->type & SEC_DESC_SACL_PRESENT) && off_sacl) {
366 tmp_offset = prs_offset(ps);
367 if(!prs_set_offset(ps, old_offset + off_sacl))
369 if(!sec_io_acl("sacl", &psd->sacl, ps, depth))
371 max_offset = MAX(max_offset, prs_offset(ps));
372 if (!prs_set_offset(ps,tmp_offset))
376 if ((psd->type & SEC_DESC_DACL_PRESENT) && off_dacl != 0) {
377 tmp_offset = prs_offset(ps);
378 if(!prs_set_offset(ps, old_offset + off_dacl))
380 if(!sec_io_acl("dacl", &psd->dacl, ps, depth))
382 max_offset = MAX(max_offset, prs_offset(ps));
383 if (!prs_set_offset(ps,tmp_offset))
387 if(!prs_set_offset(ps, max_offset))
393 /*******************************************************************
394 Reads or writes a SEC_DESC_BUF structure.
395 ********************************************************************/
397 BOOL sec_io_desc_buf(const char *desc, SEC_DESC_BUF **ppsdb, prs_struct *ps, int depth)
412 if (UNMARSHALLING(ps) && psdb == NULL) {
413 if((psdb = PRS_ALLOC_MEM(ps,SEC_DESC_BUF,1)) == NULL)
418 prs_debug(ps, depth, desc, "sec_io_desc_buf");
424 if(!prs_uint32_pre("max_len", ps, depth, &psdb->sd_size, &off_max_len))
428 if(!prs_uint32 ("ptr ", ps, depth, &ptr))
431 len = sec_desc_size(psdb->sd);
432 if(!prs_uint32_pre("len ", ps, depth, &len, &off_len))
435 old_offset = prs_offset(ps);
437 /* reading, length is non-zero; writing, descriptor is non-NULL */
438 if ((UNMARSHALLING(ps) && psdb->sd_size != 0) || (MARSHALLING(ps) && psdb->sd != NULL)) {
439 if(!sec_io_desc("sec ", &psdb->sd, ps, depth))
446 size = prs_offset(ps) - old_offset;
447 if(!prs_uint32_post("max_len", ps, depth, &psdb->sd_size, off_max_len, size == 0 ? psdb->sd_size : size))
450 if(!prs_uint32_post("len ", ps, depth, &len, off_len, size))