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_ACE structure.
32 ********************************************************************/
34 BOOL
sec_io_ace(const char *desc
, SEC_ACE
*psa
, prs_struct
*ps
, int depth
)
37 uint32 offset_ace_size
;
42 prs_debug(ps
, depth
, desc
, "sec_io_ace");
45 old_offset
= prs_offset(ps
);
47 if(!prs_uint8("type ", ps
, depth
, &psa
->type
))
50 if(!prs_uint8("flags", ps
, depth
, &psa
->flags
))
53 if(!prs_uint16_pre("size ", ps
, depth
, &psa
->size
, &offset_ace_size
))
56 if (!prs_uint32("access_mask", ps
, depth
, &psa
->access_mask
))
59 /* check whether object access is present */
60 if (!sec_ace_object(psa
->type
)) {
61 if (!smb_io_dom_sid("trustee ", &psa
->trustee
, ps
, depth
))
64 if (!prs_uint32("obj_flags", ps
, depth
, &psa
->obj_flags
))
67 if (psa
->obj_flags
& SEC_ACE_OBJECT_PRESENT
)
68 if (!smb_io_uuid("obj_guid", &psa
->obj_guid
, ps
,depth
))
71 if (psa
->obj_flags
& SEC_ACE_OBJECT_INHERITED_PRESENT
)
72 if (!smb_io_uuid("inh_guid", &psa
->inh_guid
, ps
,depth
))
75 if(!smb_io_dom_sid("trustee ", &psa
->trustee
, ps
, depth
))
79 /* Theorectically an ACE can have a size greater than the
80 sum of its components. When marshalling, pad with extra null bytes up to the
83 if (MARSHALLING(ps
) && (psa
->size
> prs_offset(ps
) - old_offset
)) {
84 uint32 extra_len
= psa
->size
- (prs_offset(ps
) - old_offset
);
88 for (i
= 0; i
< extra_len
; i
++) {
89 if (!prs_uint8("ace extra space", ps
, depth
, &c
))
94 if(!prs_uint16_post("size ", ps
, depth
, &psa
->size
, offset_ace_size
, old_offset
))
100 /*******************************************************************
101 Reads or writes a SEC_ACL structure.
103 First of the xx_io_xx functions that allocates its data structures
104 for you as it reads them.
105 ********************************************************************/
107 BOOL
sec_io_acl(const char *desc
, SEC_ACL
**ppsa
, prs_struct
*ps
, int depth
)
111 uint32 offset_acl_size
;
115 * Note that the size is always a multiple of 4 bytes due to the
116 * nature of the data structure. Therefore the prs_align() calls
117 * have been removed as they through us off when doing two-layer
118 * marshalling such as in the printing code (RPC_BUFFER). --jerry
126 if(UNMARSHALLING(ps
) && psa
== NULL
) {
128 * This is a read and we must allocate the stuct to read into.
130 if((psa
= PRS_ALLOC_MEM(ps
, SEC_ACL
, 1)) == NULL
)
135 prs_debug(ps
, depth
, desc
, "sec_io_acl");
138 old_offset
= prs_offset(ps
);
140 if(!prs_uint16("revision", ps
, depth
, &psa
->revision
))
143 if(!prs_uint16_pre("size ", ps
, depth
, &psa
->size
, &offset_acl_size
))
146 if(!prs_uint32("num_aces ", ps
, depth
, &psa
->num_aces
))
149 if (UNMARSHALLING(ps
)) {
151 if((psa
->aces
= PRS_ALLOC_MEM(ps
, SEC_ACE
, psa
->num_aces
)) == NULL
)
158 for (i
= 0; i
< psa
->num_aces
; i
++) {
160 slprintf(tmp
, sizeof(tmp
)-1, "ace_list[%02d]: ", i
);
161 if(!sec_io_ace(tmp
, &psa
->aces
[i
], ps
, depth
))
165 /* Theorectically an ACL can have a size greater than the
166 sum of its components. When marshalling, pad with extra null bytes up to the
169 if (MARSHALLING(ps
) && (psa
->size
> prs_offset(ps
) - old_offset
)) {
170 uint32 extra_len
= psa
->size
- (prs_offset(ps
) - old_offset
);
173 for (i
= 0; i
< extra_len
; i
++) {
174 if (!prs_uint8("acl extra space", ps
, depth
, &c
))
179 if(!prs_uint16_post("size ", ps
, depth
, &psa
->size
, offset_acl_size
, old_offset
))
185 /*******************************************************************
186 Reads or writes a SEC_DESC structure.
187 If reading and the *ppsd = NULL, allocates the structure.
188 ********************************************************************/
190 BOOL
sec_io_desc(const char *desc
, SEC_DESC
**ppsd
, prs_struct
*ps
, int depth
)
193 uint32 max_offset
= 0; /* after we're done, move offset to end */
194 uint32 tmp_offset
= 0;
204 if(UNMARSHALLING(ps
)) {
205 if((psd
= PRS_ALLOC_MEM(ps
,SEC_DESC
,1)) == NULL
)
209 /* Marshalling - just ignore. */
214 prs_debug(ps
, depth
, desc
, "sec_io_desc");
217 /* start of security descriptor stored for back-calc offset purposes */
218 old_offset
= prs_offset(ps
);
220 if(!prs_uint16("revision ", ps
, depth
, &psd
->revision
))
223 if(!prs_uint16("type ", ps
, depth
, &psd
->type
))
226 if (MARSHALLING(ps
)) {
227 uint32 offset
= SEC_DESC_HEADER_SIZE
;
230 * Work out the offsets here, as we write it out.
233 if (psd
->sacl
!= NULL
) {
234 psd
->off_sacl
= offset
;
235 offset
+= psd
->sacl
->size
;
240 if (psd
->dacl
!= NULL
) {
241 psd
->off_dacl
= offset
;
242 offset
+= psd
->dacl
->size
;
247 if (psd
->owner_sid
!= NULL
) {
248 psd
->off_owner_sid
= offset
;
249 offset
+= sid_size(psd
->owner_sid
);
251 psd
->off_owner_sid
= 0;
254 if (psd
->group_sid
!= NULL
) {
255 psd
->off_grp_sid
= offset
;
256 offset
+= sid_size(psd
->group_sid
);
258 psd
->off_grp_sid
= 0;
262 if(!prs_uint32("off_owner_sid", ps
, depth
, &psd
->off_owner_sid
))
265 if(!prs_uint32("off_grp_sid ", ps
, depth
, &psd
->off_grp_sid
))
268 if(!prs_uint32("off_sacl ", ps
, depth
, &psd
->off_sacl
))
271 if(!prs_uint32("off_dacl ", ps
, depth
, &psd
->off_dacl
))
274 max_offset
= MAX(max_offset
, prs_offset(ps
));
276 if (psd
->off_owner_sid
!= 0) {
278 tmp_offset
= prs_offset(ps
);
279 if(!prs_set_offset(ps
, old_offset
+ psd
->off_owner_sid
))
282 if (UNMARSHALLING(ps
)) {
284 if((psd
->owner_sid
= PRS_ALLOC_MEM(ps
,DOM_SID
,1)) == NULL
)
288 if(!smb_io_dom_sid("owner_sid ", psd
->owner_sid
, ps
, depth
))
291 max_offset
= MAX(max_offset
, prs_offset(ps
));
293 if (!prs_set_offset(ps
,tmp_offset
))
297 if (psd
->off_grp_sid
!= 0) {
299 tmp_offset
= prs_offset(ps
);
300 if(!prs_set_offset(ps
, old_offset
+ psd
->off_grp_sid
))
303 if (UNMARSHALLING(ps
)) {
305 if((psd
->group_sid
= PRS_ALLOC_MEM(ps
,DOM_SID
,1)) == NULL
)
309 if(!smb_io_dom_sid("group_sid", psd
->group_sid
, ps
, depth
))
312 max_offset
= MAX(max_offset
, prs_offset(ps
));
314 if (!prs_set_offset(ps
,tmp_offset
))
318 if ((psd
->type
& SEC_DESC_SACL_PRESENT
) && psd
->off_sacl
) {
319 tmp_offset
= prs_offset(ps
);
320 if(!prs_set_offset(ps
, old_offset
+ psd
->off_sacl
))
322 if(!sec_io_acl("sacl", &psd
->sacl
, ps
, depth
))
324 max_offset
= MAX(max_offset
, prs_offset(ps
));
325 if (!prs_set_offset(ps
,tmp_offset
))
329 if ((psd
->type
& SEC_DESC_DACL_PRESENT
) && psd
->off_dacl
!= 0) {
330 tmp_offset
= prs_offset(ps
);
331 if(!prs_set_offset(ps
, old_offset
+ psd
->off_dacl
))
333 if(!sec_io_acl("dacl", &psd
->dacl
, ps
, depth
))
335 max_offset
= MAX(max_offset
, prs_offset(ps
));
336 if (!prs_set_offset(ps
,tmp_offset
))
340 if(!prs_set_offset(ps
, max_offset
))
346 /*******************************************************************
347 Reads or writes a SEC_DESC_BUF structure.
348 ********************************************************************/
350 BOOL
sec_io_desc_buf(const char *desc
, SEC_DESC_BUF
**ppsdb
, prs_struct
*ps
, int depth
)
363 if (UNMARSHALLING(ps
) && psdb
== NULL
) {
364 if((psdb
= PRS_ALLOC_MEM(ps
,SEC_DESC_BUF
,1)) == NULL
)
369 prs_debug(ps
, depth
, desc
, "sec_io_desc_buf");
375 if(!prs_uint32_pre("max_len", ps
, depth
, &psdb
->max_len
, &off_max_len
))
378 if(!prs_uint32 ("ptr ", ps
, depth
, &psdb
->ptr
))
381 if(!prs_uint32_pre("len ", ps
, depth
, &psdb
->len
, &off_len
))
384 old_offset
= prs_offset(ps
);
386 /* reading, length is non-zero; writing, descriptor is non-NULL */
387 if ((UNMARSHALLING(ps
) && psdb
->len
!= 0) || (MARSHALLING(ps
) && psdb
->sec
!= NULL
)) {
388 if(!sec_io_desc("sec ", &psdb
->sec
, ps
, depth
))
395 size
= prs_offset(ps
) - old_offset
;
396 if(!prs_uint32_post("max_len", ps
, depth
, &psdb
->max_len
, off_max_len
, size
== 0 ? psdb
->max_len
: size
))
399 if(!prs_uint32_post("len ", ps
, depth
, &psdb
->len
, off_len
, size
))