2 Unix SMB/CIFS implementation.
4 fast routines for getting the wire size of security objects
6 Copyright (C) Andrew Tridgell 2003
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.
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.
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/>.
26 return the wire size of a dom_sid
28 size_t ndr_size_dom_sid(const struct dom_sid
*sid
, int flags
)
31 return 8 + 4*sid
->num_auths
;
34 size_t ndr_size_dom_sid28(const struct dom_sid
*sid
, int flags
)
36 struct dom_sid zero_sid
;
40 ZERO_STRUCT(zero_sid
);
42 if (memcmp(&zero_sid
, sid
, sizeof(zero_sid
)) == 0) {
46 return 8 + 4*sid
->num_auths
;
49 size_t ndr_size_dom_sid0(const struct dom_sid
*sid
, int flags
)
51 return ndr_size_dom_sid28(sid
, flags
);
54 enum ndr_err_code
ndr_pull_security_ace(struct ndr_pull
*ndr
, int ndr_flags
, struct security_ace
*r
)
56 if (ndr_flags
& NDR_SCALARS
) {
57 uint32_t start_ofs
= ndr
->offset
;
60 NDR_CHECK(ndr_pull_align(ndr
, 4));
61 NDR_CHECK(ndr_pull_security_ace_type(ndr
, NDR_SCALARS
, &r
->type
));
62 NDR_CHECK(ndr_pull_security_ace_flags(ndr
, NDR_SCALARS
, &r
->flags
));
63 NDR_CHECK(ndr_pull_uint16(ndr
, NDR_SCALARS
, &r
->size
));
64 NDR_CHECK(ndr_pull_uint32(ndr
, NDR_SCALARS
, &r
->access_mask
));
65 NDR_CHECK(ndr_pull_set_switch_value(ndr
, &r
->object
, r
->type
));
66 NDR_CHECK(ndr_pull_security_ace_object_ctr(ndr
, NDR_SCALARS
, &r
->object
));
67 NDR_CHECK(ndr_pull_dom_sid(ndr
, NDR_SCALARS
, &r
->trustee
));
68 size
= ndr
->offset
- start_ofs
;
70 return ndr_pull_error(ndr
, NDR_ERR_BUFSIZE
,
71 "ndr_pull_security_ace: r->size %u < size %u",
72 (unsigned)r
->size
, size
);
75 NDR_PULL_NEED_BYTES(ndr
, pad
);
78 if (ndr_flags
& NDR_BUFFERS
) {
79 NDR_CHECK(ndr_pull_security_ace_object_ctr(ndr
, NDR_BUFFERS
, &r
->object
));
81 return NDR_ERR_SUCCESS
;
85 return the wire size of a security_ace
87 size_t ndr_size_security_ace(const struct security_ace
*ace
, int flags
)
90 return 8 + ndr_size_dom_sid(&ace
->trustee
, flags
);
95 return the wire size of a security_acl
97 size_t ndr_size_security_acl(const struct security_acl
*acl
, int flags
)
103 for (i
=0;i
<acl
->num_aces
;i
++) {
104 ret
+= ndr_size_security_ace(&acl
->aces
[i
], flags
);
110 return the wire size of a security descriptor
112 size_t ndr_size_security_descriptor(const struct security_descriptor
*sd
, int flags
)
118 ret
+= ndr_size_dom_sid(sd
->owner_sid
, flags
);
119 ret
+= ndr_size_dom_sid(sd
->group_sid
, flags
);
120 ret
+= ndr_size_security_acl(sd
->dacl
, flags
);
121 ret
+= ndr_size_security_acl(sd
->sacl
, flags
);
128 void ndr_print_dom_sid(struct ndr_print
*ndr
, const char *name
, const struct dom_sid
*sid
)
130 ndr
->print(ndr
, "%-25s: %s", name
, dom_sid_string(ndr
, sid
));
133 void ndr_print_dom_sid2(struct ndr_print
*ndr
, const char *name
, const struct dom_sid
*sid
)
135 ndr_print_dom_sid(ndr
, name
, sid
);
138 void ndr_print_dom_sid28(struct ndr_print
*ndr
, const char *name
, const struct dom_sid
*sid
)
140 ndr_print_dom_sid(ndr
, name
, sid
);
143 void ndr_print_dom_sid0(struct ndr_print
*ndr
, const char *name
, const struct dom_sid
*sid
)
145 ndr_print_dom_sid(ndr
, name
, sid
);