clearing up security descriptor
[samba.git] / source3 / rpc_parse / parse_sec.c
1
2 /* 
3  *  Unix SMB/Netbios implementation.
4  *  Version 1.9.
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.
9  *  
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.
14  *  
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.
19  *  
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.
23  */
24
25
26 #include "includes.h"
27
28 extern int DEBUGLEVEL;
29
30
31 /*******************************************************************
32 reads or writes a structure.
33 ********************************************************************/
34 void sec_io_info(char *desc, SEC_INFO *t, prs_struct *ps, int depth)
35 {
36         if (t == NULL) return;
37
38         prs_debug(ps, depth, desc, "sec_io_info");
39         depth++;
40
41         prs_align(ps);
42         
43         prs_uint32("perms", ps, depth, &(t->perms));
44 }
45
46 /*******************************************************************
47 reads or writes a structure.
48 ********************************************************************/
49 void sec_io_ace(char *desc, SEC_ACE *t, prs_struct *ps, int depth)
50 {
51         uint32 old_offset;
52         uint32 offset_ace_size;
53         if (t == NULL) return;
54
55         prs_debug(ps, depth, desc, "sec_io_ace");
56         depth++;
57
58         prs_align(ps);
59         
60         old_offset = ps->offset;
61
62         prs_uint16("unknown_1", ps, depth, &(t->unknown_1));
63         prs_uint16_pre("ace_size ", ps, depth, &(t->ace_size ), &offset_ace_size);
64
65         sec_io_info   ("info", &t->info, ps, depth);
66         prs_align(ps);
67         smb_io_dom_sid("sid ", &t->sid , ps, depth);
68
69         prs_uint16_post("ace_size ", ps, depth, &t->ace_size, offset_ace_size, old_offset);
70 }
71
72 /*******************************************************************
73 reads or writes a structure.  this is one of those retrospective jobs,
74 which i hate.  why do we have to do this?  what's it all about?
75 ********************************************************************/
76 void sec_io_acl(char *desc, SEC_ACL *t, prs_struct *ps, int depth)
77 {
78         int i;
79         uint32 old_offset;
80         uint32 offset_acl_size;
81
82         if (t == NULL) return;
83
84         prs_debug(ps, depth, desc, "sec_io_acl");
85         depth++;
86
87         prs_align(ps);
88         
89         old_offset = ps->offset;
90
91         prs_uint16("unknown_1", ps, depth, &(t->unknown_1));
92         prs_uint16_pre("acl_size ", ps, depth, &(t->acl_size ), &offset_acl_size);
93         prs_uint32("num_aces ", ps, depth, &(t->num_aces ));
94
95         for (i = 0; i < MIN(t->num_aces, MAX_SEC_ACES); i++)
96         {
97                 fstring tmp;
98                 snprintf(tmp, sizeof(tmp), "ace[%02d]: ", i);
99                 sec_io_ace(tmp, &t->ace[i], ps, depth);
100         }
101
102         prs_align(ps);
103
104         prs_uint16_post("acl_size ", ps, depth, &t->acl_size, offset_acl_size, old_offset);
105 }
106
107
108 /*******************************************************************
109 reads or writes a structure.
110 ********************************************************************/
111 void sec_io_desc(char *desc, SEC_DESC *t, prs_struct *ps, int depth)
112 {
113         uint32 off_owner_sid;
114         uint32 off_pnt_sid  ;
115         uint32 off_unknown  ;
116         uint32 off_acl      ;
117         uint32 old_offset;
118
119         if (t == NULL) return;
120
121         prs_debug(ps, depth, desc, "sec_io_desc");
122         depth++;
123
124         prs_align(ps);
125         
126         /* start of security descriptor stored for back-calc offset purposes */
127         old_offset = ps->offset;
128
129         prs_uint32("unknown_1", ps, depth, &(t->unknown_1));
130
131         prs_uint32_pre("off_owner_sid", ps, depth, &(t->off_owner_sid), &off_owner_sid);
132         prs_uint32_pre("off_pnt_sid  ", ps, depth, &(t->off_pnt_sid  ), &off_pnt_sid  );
133         prs_uint32_pre("off_unknown  ", ps, depth, &(t->off_unknown  ), &off_unknown  );
134         prs_uint32_pre("off_acl      ", ps, depth, &(t->off_acl      ), &off_acl      );
135
136         prs_uint32_post("off_acl     ", ps, depth, &(t->off_acl      ), off_acl      , old_offset);
137         sec_io_acl    ("acl"       , &t->acl       , ps, depth);
138         prs_align(ps);
139
140         prs_uint32_post("off_unknown  ", ps, depth, &(t->off_unknown  ), off_unknown  , ps->offset);
141
142         prs_uint32_post("off_owner_sid", ps, depth, &(t->off_owner_sid), off_owner_sid, old_offset);
143         smb_io_dom_sid("owner_sid ", &t->owner_sid , ps, depth);
144         prs_align(ps);
145
146         prs_uint32_post("off_pnt_sid  ", ps, depth, &(t->off_pnt_sid  ), off_pnt_sid  , old_offset);
147         smb_io_dom_sid("parent_sid", &t->parent_sid, ps, depth);
148         prs_align(ps);
149 }
150
151 /*******************************************************************
152 reads or writes a SEC_DESC_BUF structure.
153 ********************************************************************/
154 void sec_io_desc_buf(char *desc, SEC_DESC_BUF *sec, prs_struct *ps, int depth)
155 {
156         uint32 off_len;
157         uint32 old_offset;
158
159         if (sec == NULL) return;
160
161         prs_debug(ps, depth, desc, "sec_io_desc_buf");
162         depth++;
163
164         prs_align(ps);
165         
166         prs_uint32    ("max_len", ps, depth, &(sec->max_len));
167         prs_uint32    ("undoc  ", ps, depth, &(sec->undoc  ));
168         prs_uint32_pre("len    ", ps, depth, &(sec->len    ), &off_len);
169
170         old_offset = ps->offset;
171
172         /* reading, length is non-zero; writing, descriptor is non-NULL */
173         if ((sec->len != 0 || (!ps->io)) && sec->sec != NULL)
174         {
175                 sec_io_desc("sec   ", sec->sec, ps, depth);
176         }
177
178         prs_uint32_post("len    ", ps, depth, &(sec->len    ), off_len    , old_offset);
179 }
180