s4: ndr_sec_helper: remove unused include
[kai/samba.git] / source4 / librpc / ndr / ndr_sec_helper.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    fast routines for getting the wire size of security objects
5
6    Copyright (C) Andrew Tridgell 2003
7    Copyright (C) Stefan Metzmacher 2006-2008
8    
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 3 of the License, or
12    (at your option) any later version.
13    
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18    
19    You should have received a copy of the GNU General Public License
20    along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 */
22
23
24 #include "includes.h"
25 #include "librpc/gen_ndr/ndr_security.h"
26
27 /*
28   return the wire size of a security_ace
29 */
30 size_t ndr_size_security_ace(const struct security_ace *ace, int flags)
31 {
32         size_t ret;
33
34         if (!ace) return 0;
35
36         ret = 8 + ndr_size_dom_sid(&ace->trustee, flags);
37
38         switch (ace->type) {
39         case SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT:
40         case SEC_ACE_TYPE_ACCESS_DENIED_OBJECT:
41         case SEC_ACE_TYPE_SYSTEM_AUDIT_OBJECT:
42         case SEC_ACE_TYPE_SYSTEM_ALARM_OBJECT:
43                 ret += 4; /* uint32 bitmap ace->object.object.flags */
44                 if (ace->object.object.flags & SEC_ACE_OBJECT_TYPE_PRESENT) {
45                         ret += 16; /* GUID ace->object.object.type.type */
46                 }
47                 if (ace->object.object.flags & SEC_ACE_INHERITED_OBJECT_TYPE_PRESENT) {
48                         ret += 16; /* GUID ace->object.object.inherited_typeinherited_type */
49                 }
50                 break;
51         default:
52                 break;
53         }
54
55         return ret;
56 }
57
58 /*
59   return the wire size of a security_acl
60 */
61 size_t ndr_size_security_acl(const struct security_acl *acl, int flags)
62 {
63         size_t ret;
64         int i;
65         if (!acl) return 0;
66         ret = 8;
67         for (i=0;i<acl->num_aces;i++) {
68                 ret += ndr_size_security_ace(&acl->aces[i], flags);
69         }
70         return ret;
71 }
72
73 /*
74   return the wire size of a security descriptor
75 */
76 size_t ndr_size_security_descriptor(const struct security_descriptor *sd, int flags)
77 {
78         size_t ret;
79         if (!sd) return 0;
80         
81         ret = 20;
82         ret += ndr_size_dom_sid(sd->owner_sid, flags);
83         ret += ndr_size_dom_sid(sd->group_sid, flags);
84         ret += ndr_size_security_acl(sd->dacl, flags);
85         ret += ndr_size_security_acl(sd->sacl, flags);
86         return ret;
87 }
88