s3/docs: Fix serveral typos.
[Samba.git] / source / librpc / ndr / ndr_sec_helper.c
blob6e8de7ce892186c6b303ae3e373cec38b3395e35
1 /*
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/>.
23 #include "includes.h"
24 #include "librpc/gen_ndr/security.h"
27 return the wire size of a dom_sid
29 size_t ndr_size_dom_sid(const struct dom_sid *sid, int flags)
31 if (!sid) return 0;
32 return 8 + 4*sid->num_auths;
35 size_t ndr_size_dom_sid28(const struct dom_sid *sid, int flags)
37 struct dom_sid zero_sid;
39 if (!sid) return 0;
41 ZERO_STRUCT(zero_sid);
43 if (memcmp(&zero_sid, sid, sizeof(zero_sid)) == 0) {
44 return 0;
47 return 8 + 4*sid->num_auths;
50 size_t ndr_size_dom_sid0(const struct dom_sid *sid, int flags)
52 return ndr_size_dom_sid28(sid, flags);
55 enum ndr_err_code ndr_pull_security_ace(struct ndr_pull *ndr, int ndr_flags, struct security_ace *r)
57 if (ndr_flags & NDR_SCALARS) {
58 uint32_t start_ofs = ndr->offset;
59 uint32_t size = 0;
60 uint32_t pad = 0;
61 NDR_CHECK(ndr_pull_align(ndr, 4));
62 NDR_CHECK(ndr_pull_security_ace_type(ndr, NDR_SCALARS, &r->type));
63 NDR_CHECK(ndr_pull_security_ace_flags(ndr, NDR_SCALARS, &r->flags));
64 NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &r->size));
65 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->access_mask));
66 NDR_CHECK(ndr_pull_set_switch_value(ndr, &r->object, r->type));
67 NDR_CHECK(ndr_pull_security_ace_object_ctr(ndr, NDR_SCALARS, &r->object));
68 NDR_CHECK(ndr_pull_dom_sid(ndr, NDR_SCALARS, &r->trustee));
69 size = ndr->offset - start_ofs;
70 if (r->size < size) {
71 return ndr_pull_error(ndr, NDR_ERR_BUFSIZE,
72 "ndr_pull_security_ace: r->size %u < size %u",
73 (unsigned)r->size, size);
75 pad = r->size - size;
76 NDR_PULL_NEED_BYTES(ndr, pad);
77 ndr->offset += pad;
79 if (ndr_flags & NDR_BUFFERS) {
80 NDR_CHECK(ndr_pull_security_ace_object_ctr(ndr, NDR_BUFFERS, &r->object));
82 return NDR_ERR_SUCCESS;
86 return the wire size of a security_ace
88 size_t ndr_size_security_ace(const struct security_ace *ace, int flags)
90 if (!ace) return 0;
91 return 8 + ndr_size_dom_sid(&ace->trustee, flags);
96 return the wire size of a security_acl
98 size_t ndr_size_security_acl(const struct security_acl *acl, int flags)
100 size_t ret;
101 int i;
102 if (!acl) return 0;
103 ret = 8;
104 for (i=0;i<acl->num_aces;i++) {
105 ret += ndr_size_security_ace(&acl->aces[i], flags);
107 return ret;
111 return the wire size of a security descriptor
113 size_t ndr_size_security_descriptor(const struct security_descriptor *sd, int flags)
115 size_t ret;
116 if (!sd) return 0;
118 ret = 20;
119 ret += ndr_size_dom_sid(sd->owner_sid, flags);
120 ret += ndr_size_dom_sid(sd->group_sid, flags);
121 ret += ndr_size_security_acl(sd->dacl, flags);
122 ret += ndr_size_security_acl(sd->sacl, flags);
123 return ret;
127 print a dom_sid
129 void ndr_print_dom_sid(struct ndr_print *ndr, const char *name, const struct dom_sid *sid)
131 ndr->print(ndr, "%-25s: %s", name, dom_sid_string(ndr, sid));
134 void ndr_print_dom_sid2(struct ndr_print *ndr, const char *name, const struct dom_sid *sid)
136 ndr_print_dom_sid(ndr, name, sid);
139 void ndr_print_dom_sid28(struct ndr_print *ndr, const char *name, const struct dom_sid *sid)
141 ndr_print_dom_sid(ndr, name, sid);
144 void ndr_print_dom_sid0(struct ndr_print *ndr, const char *name, const struct dom_sid *sid)
146 ndr_print_dom_sid(ndr, name, sid);