2 Unix SMB/CIFS implementation.
4 Manually parsed structures found in the DRS protocol
6 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2008
7 Copyright (C) Guenther Deschner <gd@samba.org> 2010
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/>.
24 #include "librpc/gen_ndr/ndr_drsblobs.h"
25 #include "../lib/util/asn1.h"
27 _PUBLIC_
enum ndr_err_code
ndr_push_AuthenticationInformationArray(struct ndr_push
*ndr
, int ndr_flags
, const struct AuthenticationInformationArray
*r
)
29 uint32_t cntr_array_0
;
30 if (ndr_flags
& NDR_SCALARS
) {
31 NDR_CHECK(ndr_push_align(ndr
, 4));
32 for (cntr_array_0
= 0; cntr_array_0
< r
->count
; cntr_array_0
++) {
33 NDR_CHECK(ndr_push_AuthenticationInformation(ndr
, NDR_SCALARS
, &r
->array
[cntr_array_0
]));
35 NDR_CHECK(ndr_push_align(ndr
, 4));
37 if (ndr_flags
& NDR_BUFFERS
) {
39 return NDR_ERR_SUCCESS
;
42 _PUBLIC_
enum ndr_err_code
ndr_pull_AuthenticationInformationArray(struct ndr_pull
*ndr
, int ndr_flags
, struct AuthenticationInformationArray
*r
)
44 if (ndr_flags
& NDR_SCALARS
) {
46 NDR_PULL_ALLOC_N(ndr
, r
->array
, r
->count
);
47 /* entry is at least 16 bytes large */
48 while (ndr
->offset
+ 16 <= ndr
->data_size
) {
49 r
->array
= talloc_realloc(ndr
, r
->array
, struct AuthenticationInformation
, r
->count
+ 1);
50 NDR_ERR_HAVE_NO_MEMORY(r
->array
);
51 NDR_CHECK(ndr_pull_AuthenticationInformation(ndr
, NDR_SCALARS
, &r
->array
[r
->count
]));
54 NDR_CHECK(ndr_pull_align(ndr
, 4));
56 if (ndr_flags
& NDR_BUFFERS
) {
58 return NDR_ERR_SUCCESS
;
61 _PUBLIC_
enum ndr_err_code
ndr_push_trustAuthInOutBlob(struct ndr_push
*ndr
, int ndr_flags
, const struct trustAuthInOutBlob
*r
)
63 if (ndr_flags
& NDR_SCALARS
) {
64 NDR_CHECK(ndr_push_align(ndr
, 4));
65 NDR_CHECK(ndr_push_uint32(ndr
, NDR_SCALARS
, r
->count
));
66 NDR_CHECK(ndr_push_uint32(ndr
, NDR_SCALARS
, (r
->count
> 0)?12:0));
67 NDR_CHECK(ndr_push_uint32(ndr
, NDR_SCALARS
, (r
->count
> 0)?12 + ndr_size_AuthenticationInformationArray(&r
->current
, 0):0));
69 struct ndr_push
*_ndr_current
;
70 NDR_CHECK(ndr_push_subcontext_start(ndr
, &_ndr_current
, 0, ((r
->count
> 0)?12 + ndr_size_AuthenticationInformationArray(&r
->current
, 0):0) - ((r
->count
> 0)?12:0)));
71 NDR_CHECK(ndr_push_AuthenticationInformationArray(_ndr_current
, NDR_SCALARS
, &r
->current
));
72 NDR_CHECK(ndr_push_subcontext_end(ndr
, _ndr_current
, 0, ((r
->count
> 0)?12 + ndr_size_AuthenticationInformationArray(&r
->current
, 0):0) - ((r
->count
> 0)?12:0)));
75 uint32_t _flags_save_AuthenticationInformationArray
= ndr
->flags
;
76 ndr_set_flags(&ndr
->flags
, LIBNDR_FLAG_REMAINING
);
78 struct ndr_push
*_ndr_previous
;
79 NDR_CHECK(ndr_push_subcontext_start(ndr
, &_ndr_previous
, 0, -1));
80 NDR_CHECK(ndr_push_AuthenticationInformationArray(_ndr_previous
, NDR_SCALARS
, &r
->previous
));
81 NDR_CHECK(ndr_push_subcontext_end(ndr
, _ndr_previous
, 0, -1));
83 ndr
->flags
= _flags_save_AuthenticationInformationArray
;
85 NDR_CHECK(ndr_push_trailer_align(ndr
, 4));
87 if (ndr_flags
& NDR_BUFFERS
) {
89 return NDR_ERR_SUCCESS
;
93 _PUBLIC_
enum ndr_err_code
ndr_pull_trustDomainPasswords(struct ndr_pull
*ndr
, int ndr_flags
, struct trustDomainPasswords
*r
)
95 if (ndr_flags
& NDR_SCALARS
) {
97 NDR_PULL_ALIGN(ndr
, 4);
98 NDR_PULL_NEED_BYTES(ndr
, 8);
100 offset
= ndr
->offset
;
101 ndr
->offset
= ndr
->data_size
- 8;
103 NDR_CHECK(ndr_pull_uint32(ndr
, NDR_SCALARS
, &r
->outgoing_size
));
104 NDR_CHECK(ndr_pull_uint32(ndr
, NDR_SCALARS
, &r
->incoming_size
));
106 ndr
->offset
= offset
;
107 NDR_CHECK(ndr_pull_array_uint8(ndr
, NDR_SCALARS
, r
->confounder
, 512));
109 struct ndr_pull
*_ndr_outgoing
;
110 NDR_CHECK(ndr_pull_subcontext_start(ndr
, &_ndr_outgoing
, 0, r
->outgoing_size
));
111 NDR_CHECK(ndr_pull_trustAuthInOutBlob(_ndr_outgoing
, NDR_SCALARS
|NDR_BUFFERS
, &r
->outgoing
));
112 NDR_CHECK(ndr_pull_subcontext_end(ndr
, _ndr_outgoing
, 0, r
->outgoing_size
));
115 struct ndr_pull
*_ndr_incoming
;
116 NDR_CHECK(ndr_pull_subcontext_start(ndr
, &_ndr_incoming
, 0, r
->incoming_size
));
117 NDR_CHECK(ndr_pull_trustAuthInOutBlob(_ndr_incoming
, NDR_SCALARS
|NDR_BUFFERS
, &r
->incoming
));
118 NDR_CHECK(ndr_pull_subcontext_end(ndr
, _ndr_incoming
, 0, r
->incoming_size
));
120 NDR_CHECK(ndr_pull_uint32(ndr
, NDR_SCALARS
, &r
->outgoing_size
));
121 NDR_CHECK(ndr_pull_uint32(ndr
, NDR_SCALARS
, &r
->incoming_size
));
123 if (ndr_flags
& NDR_BUFFERS
) {
125 return NDR_ERR_SUCCESS
;
128 _PUBLIC_
void ndr_print_drsuapi_MSPrefixMap_Entry(struct ndr_print
*ndr
, const char *name
, const struct drsuapi_MSPrefixMap_Entry
*r
)
130 ndr_print_struct(ndr
, name
, "drsuapi_MSPrefixMap_Entry");
132 uint32_t _flags_save_STRUCT
= ndr
->flags
;
133 ndr_set_flags(&ndr
->flags
, LIBNDR_FLAG_NOALIGN
);
135 ndr_print_uint16(ndr
, "entryID", r
->entryID
);
136 ndr
->print(ndr
, "%-25s: length=%u", "oid", r
->length
);
138 char *partial_oid
= NULL
;
139 DATA_BLOB oid_blob
= data_blob_const(r
->binary_oid
, r
->length
);
140 char *hex_str
= data_blob_hex_string_upper(ndr
, &oid_blob
);
141 ber_read_partial_OID_String(ndr
, oid_blob
, &partial_oid
);
143 ndr
->print(ndr
, "%-25s: 0x%s (%s)", "binary_oid", hex_str
, partial_oid
);
145 talloc_free(hex_str
);
146 talloc_free(partial_oid
);
149 ndr
->flags
= _flags_save_STRUCT
;
153 _PUBLIC_
enum ndr_err_code
ndr_push_supplementalCredentialsSubBlob(struct ndr_push
*ndr
, int ndr_flags
, const struct supplementalCredentialsSubBlob
*r
)
155 uint32_t cntr_packages_0
;
156 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
157 if (ndr_flags
& NDR_SCALARS
) {
158 if ((r
->signature
!= SUPPLEMENTAL_CREDENTIALS_SIGNATURE
)
159 && (r
->num_packages
== 0)) {
160 return NDR_ERR_SUCCESS
;
162 NDR_CHECK(ndr_push_align(ndr
, 3));
163 NDR_CHECK(ndr_push_charset(ndr
, NDR_SCALARS
, SUPPLEMENTAL_CREDENTIALS_PREFIX
, 0x30, sizeof(uint16_t), CH_UTF16
));
164 NDR_CHECK(ndr_push_supplementalCredentialsSignature(ndr
, NDR_SCALARS
, SUPPLEMENTAL_CREDENTIALS_SIGNATURE
));
165 if (r
->num_packages
> 0) {
166 NDR_CHECK(ndr_push_uint16(ndr
, NDR_SCALARS
, r
->num_packages
));
168 for (cntr_packages_0
= 0; cntr_packages_0
< (r
->num_packages
); cntr_packages_0
++) {
169 NDR_CHECK(ndr_push_supplementalCredentialsPackage(ndr
, NDR_SCALARS
, &r
->packages
[cntr_packages_0
]));
171 NDR_CHECK(ndr_push_trailer_align(ndr
, 3));
173 if (ndr_flags
& NDR_BUFFERS
) {
175 return NDR_ERR_SUCCESS
;
178 _PUBLIC_
enum ndr_err_code
ndr_pull_supplementalCredentialsSubBlob(struct ndr_pull
*ndr
, int ndr_flags
, struct supplementalCredentialsSubBlob
*r
)
180 uint32_t size_prefix_0
= 0;
181 uint32_t size_packages_0
= 0;
182 uint32_t cntr_packages_0
;
183 TALLOC_CTX
*_mem_save_packages_0
= NULL
;
184 NDR_PULL_CHECK_FLAGS(ndr
, ndr_flags
);
185 if (ndr_flags
& NDR_SCALARS
) {
186 uint32_t remaining
= 0;
187 NDR_CHECK(ndr_pull_align(ndr
, 3));
188 size_prefix_0
= 0x30;
189 remaining
= ndr
->data_size
- ndr
->offset
;
190 if (remaining
>= size_prefix_0
) {
191 NDR_CHECK(ndr_pull_charset(ndr
, NDR_SCALARS
, &r
->prefix
, size_prefix_0
, sizeof(uint16_t), CH_UTF16
));
195 remaining
= ndr
->data_size
- ndr
->offset
;
196 if (remaining
>= 2) {
197 NDR_CHECK(ndr_pull_supplementalCredentialsSignature(ndr
, NDR_SCALARS
, &r
->signature
));
201 remaining
= ndr
->data_size
- ndr
->offset
;
203 NDR_CHECK(ndr_pull_uint16(ndr
, NDR_SCALARS
, &r
->num_packages
));
207 size_packages_0
= r
->num_packages
;
208 NDR_PULL_ALLOC_N(ndr
, r
->packages
, size_packages_0
);
209 _mem_save_packages_0
= NDR_PULL_GET_MEM_CTX(ndr
);
210 NDR_PULL_SET_MEM_CTX(ndr
, r
->packages
, 0);
211 for (cntr_packages_0
= 0; cntr_packages_0
< (size_packages_0
); cntr_packages_0
++) {
212 NDR_CHECK(ndr_pull_supplementalCredentialsPackage(ndr
, NDR_SCALARS
, &r
->packages
[cntr_packages_0
]));
214 NDR_PULL_SET_MEM_CTX(ndr
, _mem_save_packages_0
, 0);
215 NDR_CHECK(ndr_pull_trailer_align(ndr
, 3));
217 if (ndr_flags
& NDR_BUFFERS
) {
219 return NDR_ERR_SUCCESS
;