s4: fix samba4.samba3sam.python test
[abartlet/samba.git/.git] / source3 / 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    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22
23 #include "includes.h"
24
25 /*
26   return the wire size of a dom_sid
27 */
28 size_t ndr_size_dom_sid(const struct dom_sid *sid, int flags)
29 {
30         if (!sid) return 0;
31         return 8 + 4*sid->num_auths;
32 }
33
34 size_t ndr_size_dom_sid28(const struct dom_sid *sid, int flags)
35 {
36         struct dom_sid zero_sid;
37
38         if (!sid) return 0;
39
40         ZERO_STRUCT(zero_sid);
41
42         if (memcmp(&zero_sid, sid, sizeof(zero_sid)) == 0) {
43                 return 0;
44         }
45
46         return 8 + 4*sid->num_auths;
47 }
48
49 size_t ndr_size_dom_sid0(const struct dom_sid *sid, int flags)
50 {
51         return ndr_size_dom_sid28(sid, flags);
52 }
53
54 /*
55   return the wire size of a security_ace
56 */
57 size_t ndr_size_security_ace(const struct security_ace *ace, int flags)
58 {
59         if (!ace) return 0;
60         return 8 + ndr_size_dom_sid(&ace->trustee, flags);
61 }
62
63
64 /*
65   return the wire size of a security_acl
66 */
67 size_t ndr_size_security_acl(const struct security_acl *acl, int flags)
68 {
69         size_t ret;
70         int i;
71         if (!acl) return 0;
72         ret = 8;
73         for (i=0;i<acl->num_aces;i++) {
74                 ret += ndr_size_security_ace(&acl->aces[i], flags);
75         }
76         return ret;
77 }
78
79 /*
80   return the wire size of a security descriptor
81 */
82 size_t ndr_size_security_descriptor(const struct security_descriptor *sd, int flags)
83 {
84         size_t ret;
85         if (!sd) return 0;
86         
87         ret = 20;
88         ret += ndr_size_dom_sid(sd->owner_sid, flags);
89         ret += ndr_size_dom_sid(sd->group_sid, flags);
90         ret += ndr_size_security_acl(sd->dacl, flags);
91         ret += ndr_size_security_acl(sd->sacl, flags);
92         return ret;
93 }
94
95 /*
96   print a dom_sid
97 */
98 void ndr_print_dom_sid(struct ndr_print *ndr, const char *name, const struct dom_sid *sid)
99 {
100         ndr->print(ndr, "%-25s: %s", name, dom_sid_string(ndr, sid));
101 }
102
103 void ndr_print_dom_sid2(struct ndr_print *ndr, const char *name, const struct dom_sid *sid)
104 {
105         ndr_print_dom_sid(ndr, name, sid);
106 }
107
108 void ndr_print_dom_sid28(struct ndr_print *ndr, const char *name, const struct dom_sid *sid)
109 {
110         ndr_print_dom_sid(ndr, name, sid);
111 }
112
113 void ndr_print_dom_sid0(struct ndr_print *ndr, const char *name, const struct dom_sid *sid)
114 {
115         ndr_print_dom_sid(ndr, name, sid);
116 }
117