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 if((psa
->aces
= PRS_ALLOC_MEM(ps
, SEC_ACE
, psa
->num_aces
)) == NULL
)
194 for (i
= 0; i
< psa
->num_aces
; i
++) {
196 slprintf(tmp
, sizeof(tmp
)-1, "ace_list[%02d]: ", i
);
197 if(!sec_io_ace(tmp
, &psa
->aces
[i
], ps
, depth
))
201 /* Theorectically an ACL can have a size greater than the
202 sum of its components. When marshalling, pad with extra null bytes up to the
205 if (MARSHALLING(ps
) && (psa
->size
> prs_offset(ps
) - old_offset
)) {
206 uint32 extra_len
= psa
->size
- (prs_offset(ps
) - old_offset
);
209 for (i
= 0; i
< extra_len
; i
++) {
210 if (!prs_uint8("acl extra space", ps
, depth
, &c
))
215 if(!prs_uint16_post("size ", ps
, depth
, &psa
->size
, offset_acl_size
, old_offset
))
221 /*******************************************************************
222 Reads or writes a SEC_DESC structure.
223 If reading and the *ppsd = NULL, allocates the structure.
224 ********************************************************************/
226 BOOL
sec_io_desc(const char *desc
, SEC_DESC
**ppsd
, prs_struct
*ps
, int depth
)
229 uint32 max_offset
= 0; /* after we're done, move offset to end */
230 uint32 tmp_offset
= 0;
231 uint32 off_sacl
, off_dacl
, off_owner_sid
, off_grp_sid
;
242 if(UNMARSHALLING(ps
)) {
243 if((psd
= PRS_ALLOC_MEM(ps
,SEC_DESC
,1)) == NULL
)
247 /* Marshalling - just ignore. */
252 prs_debug(ps
, depth
, desc
, "sec_io_desc");
255 /* start of security descriptor stored for back-calc offset purposes */
256 old_offset
= prs_offset(ps
);
258 if (MARSHALLING(ps
)) {
259 revision
= (uint16
)psd
->revision
;
262 if(!prs_uint16("revision", ps
, depth
, &revision
))
265 if (UNMARSHALLING(ps
)) {
266 psd
->revision
= (enum security_acl_revision
)revision
;
269 if(!prs_uint16("type ", ps
, depth
, &psd
->type
))
272 if (MARSHALLING(ps
)) {
273 uint32 offset
= SEC_DESC_HEADER_SIZE
;
276 * Work out the offsets here, as we write it out.
279 if (psd
->sacl
!= NULL
) {
281 offset
+= psd
->sacl
->size
;
286 if (psd
->dacl
!= NULL
) {
288 offset
+= psd
->dacl
->size
;
293 if (psd
->owner_sid
!= NULL
) {
294 off_owner_sid
= offset
;
295 offset
+= sid_size(psd
->owner_sid
);
300 if (psd
->group_sid
!= NULL
) {
301 off_grp_sid
= offset
;
302 offset
+= sid_size(psd
->group_sid
);
308 if(!prs_uint32("off_owner_sid", ps
, depth
, &off_owner_sid
))
311 if(!prs_uint32("off_grp_sid ", ps
, depth
, &off_grp_sid
))
314 if(!prs_uint32("off_sacl ", ps
, depth
, &off_sacl
))
317 if(!prs_uint32("off_dacl ", ps
, depth
, &off_dacl
))
320 max_offset
= MAX(max_offset
, prs_offset(ps
));
322 if (off_owner_sid
!= 0) {
324 tmp_offset
= prs_offset(ps
);
325 if(!prs_set_offset(ps
, old_offset
+ off_owner_sid
))
328 if (UNMARSHALLING(ps
)) {
330 if((psd
->owner_sid
= PRS_ALLOC_MEM(ps
,DOM_SID
,1)) == NULL
)
334 if(!smb_io_dom_sid("owner_sid ", psd
->owner_sid
, ps
, depth
))
337 max_offset
= MAX(max_offset
, prs_offset(ps
));
339 if (!prs_set_offset(ps
,tmp_offset
))
343 if (psd
->group_sid
!= 0) {
345 tmp_offset
= prs_offset(ps
);
346 if(!prs_set_offset(ps
, old_offset
+ off_grp_sid
))
349 if (UNMARSHALLING(ps
)) {
351 if((psd
->group_sid
= PRS_ALLOC_MEM(ps
,DOM_SID
,1)) == NULL
)
355 if(!smb_io_dom_sid("grp_sid", psd
->group_sid
, ps
, depth
))
358 max_offset
= MAX(max_offset
, prs_offset(ps
));
360 if (!prs_set_offset(ps
,tmp_offset
))
364 if ((psd
->type
& SEC_DESC_SACL_PRESENT
) && off_sacl
) {
365 tmp_offset
= prs_offset(ps
);
366 if(!prs_set_offset(ps
, old_offset
+ off_sacl
))
368 if(!sec_io_acl("sacl", &psd
->sacl
, ps
, depth
))
370 max_offset
= MAX(max_offset
, prs_offset(ps
));
371 if (!prs_set_offset(ps
,tmp_offset
))
375 if ((psd
->type
& SEC_DESC_DACL_PRESENT
) && off_dacl
!= 0) {
376 tmp_offset
= prs_offset(ps
);
377 if(!prs_set_offset(ps
, old_offset
+ off_dacl
))
379 if(!sec_io_acl("dacl", &psd
->dacl
, ps
, depth
))
381 max_offset
= MAX(max_offset
, prs_offset(ps
));
382 if (!prs_set_offset(ps
,tmp_offset
))
386 if(!prs_set_offset(ps
, max_offset
))
392 /*******************************************************************
393 Reads or writes a SEC_DESC_BUF structure.
394 ********************************************************************/
396 BOOL
sec_io_desc_buf(const char *desc
, SEC_DESC_BUF
**ppsdb
, prs_struct
*ps
, int depth
)
411 if (UNMARSHALLING(ps
) && psdb
== NULL
) {
412 if((psdb
= PRS_ALLOC_MEM(ps
,SEC_DESC_BUF
,1)) == NULL
)
417 prs_debug(ps
, depth
, desc
, "sec_io_desc_buf");
423 if(!prs_uint32_pre("max_len", ps
, depth
, &psdb
->sd_size
, &off_max_len
))
427 if(!prs_uint32 ("ptr ", ps
, depth
, &ptr
))
430 len
= sec_desc_size(psdb
->sd
);
431 if(!prs_uint32_pre("len ", ps
, depth
, &len
, &off_len
))
434 old_offset
= prs_offset(ps
);
436 /* reading, length is non-zero; writing, descriptor is non-NULL */
437 if ((UNMARSHALLING(ps
) && psdb
->sd_size
!= 0) || (MARSHALLING(ps
) && psdb
->sd
!= NULL
)) {
438 if(!sec_io_desc("sec ", &psdb
->sd
, ps
, depth
))
445 size
= prs_offset(ps
) - old_offset
;
446 if(!prs_uint32_post("max_len", ps
, depth
, &psdb
->sd_size
, off_max_len
, size
== 0 ? psdb
->sd_size
: size
))
449 if(!prs_uint32_post("len ", ps
, depth
, &len
, off_len
, size
))