2 Unix SMB/CIFS implementation.
4 fast routines for getting the wire size of security objects
6 Copyright (C) Andrew Tridgell 2003
7 Copyright (C) Stefan Metzmacher 2006-2008
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.
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.
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/>.
25 #include "librpc/gen_ndr/ndr_security.h"
26 #include "libcli/security/security.h"
29 return the wire size of a dom_sid
31 size_t ndr_size_dom_sid(const struct dom_sid *sid, int flags)
34 return 8 + 4*sid->num_auths;
37 size_t ndr_size_dom_sid28(const struct dom_sid *sid, int flags)
39 struct dom_sid zero_sid;
43 ZERO_STRUCT(zero_sid);
45 if (memcmp(&zero_sid, sid, sizeof(zero_sid)) == 0) {
49 return 8 + 4*sid->num_auths;
52 size_t ndr_size_dom_sid0(const struct dom_sid *sid, int flags)
54 return ndr_size_dom_sid28(sid, flags);
60 void ndr_print_dom_sid(struct ndr_print *ndr, const char *name, const struct dom_sid *sid)
62 ndr->print(ndr, "%-25s: %s", name, dom_sid_string(ndr, sid));
65 void ndr_print_dom_sid2(struct ndr_print *ndr, const char *name, const struct dom_sid *sid)
67 ndr_print_dom_sid(ndr, name, sid);
70 void ndr_print_dom_sid28(struct ndr_print *ndr, const char *name, const struct dom_sid *sid)
72 ndr_print_dom_sid(ndr, name, sid);
75 void ndr_print_dom_sid0(struct ndr_print *ndr, const char *name, const struct dom_sid *sid)
77 ndr_print_dom_sid(ndr, name, sid);
82 parse a dom_sid2 - this is a dom_sid but with an extra copy of the num_auths field
84 enum ndr_err_code ndr_pull_dom_sid2(struct ndr_pull *ndr, int ndr_flags, struct dom_sid *sid)
87 if (!(ndr_flags & NDR_SCALARS)) {
88 return NDR_ERR_SUCCESS;
90 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &num_auths));
91 NDR_CHECK(ndr_pull_dom_sid(ndr, ndr_flags, sid));
92 if (sid->num_auths != num_auths) {
93 return ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE,
94 "Bad array size %u should exceed %u",
95 num_auths, sid->num_auths);
97 return NDR_ERR_SUCCESS;
101 parse a dom_sid2 - this is a dom_sid but with an extra copy of the num_auths field
103 enum ndr_err_code ndr_push_dom_sid2(struct ndr_push *ndr, int ndr_flags, const struct dom_sid *sid)
105 if (!(ndr_flags & NDR_SCALARS)) {
106 return NDR_ERR_SUCCESS;
108 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, sid->num_auths));
109 return ndr_push_dom_sid(ndr, ndr_flags, sid);
113 parse a dom_sid28 - this is a dom_sid in a fixed 28 byte buffer, so we need to ensure there are only upto 5 sub_auth
115 enum ndr_err_code ndr_pull_dom_sid28(struct ndr_pull *ndr, int ndr_flags, struct dom_sid *sid)
117 enum ndr_err_code status;
118 struct ndr_pull *subndr;
120 if (!(ndr_flags & NDR_SCALARS)) {
121 return NDR_ERR_SUCCESS;
124 subndr = talloc_zero(ndr, struct ndr_pull);
125 NDR_ERR_HAVE_NO_MEMORY(subndr);
126 subndr->flags = ndr->flags;
127 subndr->current_mem_ctx = ndr->current_mem_ctx;
129 subndr->data = ndr->data + ndr->offset;
130 subndr->data_size = 28;
133 NDR_CHECK(ndr_pull_advance(ndr, 28));
135 status = ndr_pull_dom_sid(subndr, ndr_flags, sid);
136 if (!NDR_ERR_CODE_IS_SUCCESS(status)) {
137 /* handle a w2k bug which send random data in the buffer */
139 } else if (sid->num_auths == 0 && sid->sub_auths) {
140 talloc_free(sid->sub_auths);
141 sid->sub_auths = NULL;
144 return NDR_ERR_SUCCESS;
148 push a dom_sid28 - this is a dom_sid in a 28 byte fixed buffer
150 enum ndr_err_code ndr_push_dom_sid28(struct ndr_push *ndr, int ndr_flags, const struct dom_sid *sid)
155 if (!(ndr_flags & NDR_SCALARS)) {
156 return NDR_ERR_SUCCESS;
159 if (sid->num_auths > 5) {
160 return ndr_push_error(ndr, NDR_ERR_RANGE,
161 "dom_sid28 allows only upto 5 sub auth [%u]",
165 old_offset = ndr->offset;
166 NDR_CHECK(ndr_push_dom_sid(ndr, ndr_flags, sid));
168 padding = 28 - (ndr->offset - old_offset);
171 NDR_CHECK(ndr_push_zero(ndr, padding));
174 return NDR_ERR_SUCCESS;
178 parse a dom_sid0 - this is a dom_sid in a variable byte buffer, which is maybe empty
180 enum ndr_err_code ndr_pull_dom_sid0(struct ndr_pull *ndr, int ndr_flags, struct dom_sid *sid)
182 if (!(ndr_flags & NDR_SCALARS)) {
183 return NDR_ERR_SUCCESS;
186 if (ndr->data_size == ndr->offset) {
188 return NDR_ERR_SUCCESS;
191 return ndr_pull_dom_sid(ndr, ndr_flags, sid);
195 push a dom_sid0 - this is a dom_sid in a variable byte buffer, which is maybe empty
197 enum ndr_err_code ndr_push_dom_sid0(struct ndr_push *ndr, int ndr_flags, const struct dom_sid *sid)
199 struct dom_sid zero_sid;
201 if (!(ndr_flags & NDR_SCALARS)) {
202 return NDR_ERR_SUCCESS;
206 return NDR_ERR_SUCCESS;
209 ZERO_STRUCT(zero_sid);
211 if (memcmp(&zero_sid, sid, sizeof(zero_sid)) == 0) {
212 return NDR_ERR_SUCCESS;
215 return ndr_push_dom_sid(ndr, ndr_flags, sid);