3 * Unix SMB/Netbios implementation.
5 * RPC Pipe client / server routines
6 * Copyright (C) Andrew Tridgell 1992-1997,
7 * Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
8 * Copyright (C) Paul Ashton 1997.
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 extern int DEBUGLEVEL;
31 /*******************************************************************
32 reads or writes a structure.
33 ********************************************************************/
34 void sec_io_info(char *desc, SEC_INFO *t, prs_struct *ps, int depth)
36 if (t == NULL) return;
38 prs_debug(ps, depth, desc, "sec_io_info");
43 prs_uint32("perms", ps, depth, &(t->perms));
46 /*******************************************************************
47 reads or writes a structure.
48 ********************************************************************/
49 void sec_io_ace(char *desc, SEC_ACE *t, prs_struct *ps, int depth)
52 uint32 offset_ace_size;
53 if (t == NULL) return;
55 prs_debug(ps, depth, desc, "sec_io_ace");
60 old_offset = ps->offset;
62 prs_uint8 ("type ", ps, depth, &(t->type));
63 prs_uint8 ("flags", ps, depth, &(t->flags));
64 prs_uint16_pre("size ", ps, depth, &(t->size ), &offset_ace_size);
66 sec_io_info ("info ", &t->info, ps, depth);
68 smb_io_dom_sid("sid ", &t->sid , ps, depth);
70 prs_uint16_post("size ", ps, depth, &t->size, offset_ace_size, old_offset);
73 /*******************************************************************
74 reads or writes a structure. this is one of those retrospective jobs,
75 which i hate. why do we have to do this? what's it all about?
76 ********************************************************************/
77 void sec_io_acl(char *desc, SEC_ACL *t, prs_struct *ps, int depth)
81 uint32 offset_acl_size;
83 if (t == NULL) return;
85 prs_debug(ps, depth, desc, "sec_io_acl");
90 old_offset = ps->offset;
92 prs_uint16("revision", ps, depth, &(t->revision));
93 prs_uint16_pre("size ", ps, depth, &(t->size ), &offset_acl_size);
94 prs_uint32("num_aces ", ps, depth, &(t->num_aces ));
96 for (i = 0; i < MIN(t->num_aces, MAX_SEC_ACES); i++)
99 snprintf(tmp, sizeof(tmp), "ace[%02d]: ", i);
100 sec_io_ace(tmp, &t->ace[i], ps, depth);
105 prs_uint16_post("size ", ps, depth, &t->size , offset_acl_size, old_offset);
109 /*******************************************************************
110 reads or writes a structure.
111 ********************************************************************/
112 static void sec_io_desc(char *desc, SEC_DESC *t, prs_struct *ps, int depth)
114 uint32 off_owner_sid;
120 if (t == NULL) return;
122 prs_debug(ps, depth, desc, "sec_io_desc");
127 /* start of security descriptor stored for back-calc offset purposes */
128 old_offset = ps->offset;
130 prs_uint16("revision ", ps, depth, &(t->revision ));
131 prs_uint16("type ", ps, depth, &(t->type ));
133 prs_uint32_pre("off_owner_sid", ps, depth, &(t->off_owner_sid), &off_owner_sid);
134 prs_uint32_pre("off_grp_sid ", ps, depth, &(t->off_grp_sid ), &off_grp_sid );
135 prs_uint32_pre("off_sacl ", ps, depth, &(t->off_sacl ), &off_sacl );
136 prs_uint32_pre("off_dacl ", ps, depth, &(t->off_dacl ), &off_dacl );
138 if (IS_BITS_SET_ALL(t->type, SEC_DESC_DACL_PRESENT))
140 prs_uint32_post("off_dacl ", ps, depth, &(t->off_dacl ), off_dacl , ps->offset - old_offset);
141 ps->offset = old_offset + t->off_dacl;
142 sec_io_acl ("dacl" , &t->dacl , ps, depth);
147 prs_uint32_post("off_dacl ", ps, depth, &(t->off_dacl ), off_dacl , 0);
150 if (IS_BITS_SET_ALL(t->type, SEC_DESC_SACL_PRESENT))
152 prs_uint32_post("off_sacl ", ps, depth, &(t->off_sacl ), off_sacl , ps->offset - old_offset);
153 ps->offset = old_offset + t->off_sacl;
154 sec_io_acl ("sacl" , &t->sacl , ps, depth);
159 prs_uint32_post("off_sacl ", ps, depth, &(t->off_sacl ), off_sacl , 0);
162 prs_uint32_post("off_owner_sid", ps, depth, &(t->off_owner_sid), off_owner_sid, ps->offset - old_offset);
163 if (t->off_owner_sid != 0)
167 ps->offset = old_offset + t->off_owner_sid;
169 smb_io_dom_sid("owner_sid ", &t->owner_sid , ps, depth);
173 prs_uint32_post("off_grp_sid ", ps, depth, &(t->off_grp_sid ), off_grp_sid , ps->offset - old_offset);
174 if (t->off_grp_sid != 0)
178 ps->offset = old_offset + t->off_grp_sid;
180 smb_io_dom_sid("grp_sid", &t->grp_sid, ps, depth);
185 /*******************************************************************
186 creates a SEC_DESC_BUF structure.
187 ********************************************************************/
188 void make_sec_desc_buf(SEC_DESC_BUF *buf, int len, SEC_DESC *data)
192 /* max buffer size (allocated size) */
195 buf->len = data != NULL ? len : 0;
200 /*******************************************************************
201 reads or writes a SEC_DESC_BUF structure.
202 ********************************************************************/
203 void sec_io_desc_buf(char *desc, SEC_DESC_BUF *sec, prs_struct *ps, int depth)
210 if (sec == NULL) return;
212 prs_debug(ps, depth, desc, "sec_io_desc_buf");
217 prs_uint32_pre("max_len", ps, depth, &(sec->max_len), &off_max_len);
218 prs_uint32 ("undoc ", ps, depth, &(sec->undoc ));
219 prs_uint32_pre("len ", ps, depth, &(sec->len ), &off_len);
221 old_offset = ps->offset;
223 /* reading, length is non-zero; writing, descriptor is non-NULL */
224 if ((sec->len != 0 || (!ps->io)) && sec->sec != NULL)
226 sec_io_desc("sec ", sec->sec, ps, depth);
229 size = ps->offset - old_offset;
230 prs_uint32_post("max_len", ps, depth, &(sec->max_len), off_max_len, size == 0 ? sec->max_len : size);
231 prs_uint32_post("len ", ps, depth, &(sec->len ), off_len , size);