2 Unix SMB/CIFS implementation.
4 routines for printing some linked list structs in DRSUAPI
6 Copyright (C) Stefan (metze) Metzmacher 2005
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/>.
24 #include "librpc/gen_ndr/ndr_drsuapi.h"
25 #include "librpc/gen_ndr/ndr_misc.h"
26 #include "../lib/util/asn1.h"
27 #include "librpc/ndr/ndr_compression.h"
28 /* We don't need multibyte if we're just comparing to 'ff' */
31 void ndr_print_drsuapi_DsReplicaObjectListItem(struct ndr_print
*ndr
, const char *name
,
32 const struct drsuapi_DsReplicaObjectListItem
*r
)
34 ndr_print_struct(ndr
, name
, "drsuapi_DsReplicaObjectListItem");
36 ndr_print_ptr(ndr
, "next_object", r
->next_object
);
37 ndr_print_drsuapi_DsReplicaObject(ndr
, "object", &r
->object
);
40 ndr_print_drsuapi_DsReplicaObjectListItem(ndr
, "next_object", r
->next_object
);
44 void ndr_print_drsuapi_DsReplicaObjectListItemEx(struct ndr_print
*ndr
, const char *name
, const struct drsuapi_DsReplicaObjectListItemEx
*r
)
46 ndr_print_struct(ndr
, name
, "drsuapi_DsReplicaObjectListItemEx");
48 ndr_print_ptr(ndr
, "next_object", r
->next_object
);
49 ndr_print_drsuapi_DsReplicaObject(ndr
, "object", &r
->object
);
50 ndr_print_uint32(ndr
, "is_nc_prefix", r
->is_nc_prefix
);
51 ndr_print_ptr(ndr
, "parent_object_guid", r
->parent_object_guid
);
53 if (r
->parent_object_guid
) {
54 ndr_print_GUID(ndr
, "parent_object_guid", r
->parent_object_guid
);
57 ndr_print_ptr(ndr
, "meta_data_ctr", r
->meta_data_ctr
);
59 if (r
->meta_data_ctr
) {
60 ndr_print_drsuapi_DsReplicaMetaDataCtr(ndr
, "meta_data_ctr", r
->meta_data_ctr
);
65 ndr_print_drsuapi_DsReplicaObjectListItemEx(ndr
, "next_object", r
->next_object
);
69 #define _OID_PUSH_CHECK(call) do { \
72 if (_status != true) { \
73 return ndr_push_error(ndr, NDR_ERR_SUBCONTEXT, "OID Conversion Error: %s\n", __location__); \
77 #define _OID_PULL_CHECK(call) do { \
80 if (_status != true) { \
81 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "OID Conversion Error: %s\n", __location__); \
85 enum ndr_err_code
ndr_push_drsuapi_DsReplicaOID(struct ndr_push
*ndr
, int ndr_flags
, const struct drsuapi_DsReplicaOID
*r
)
87 if (ndr_flags
& NDR_SCALARS
) {
88 NDR_CHECK(ndr_push_align(ndr
, 4));
89 NDR_CHECK(ndr_push_uint32(ndr
, NDR_SCALARS
, ndr_size_drsuapi_DsReplicaOID_oid(r
->oid
, 0)));
90 NDR_CHECK(ndr_push_unique_ptr(ndr
, r
->oid
));
92 if (ndr_flags
& NDR_BUFFERS
) {
96 if (strncasecmp("ff", r
->oid
, 2) == 0) {
97 blob
= strhex_to_data_blob(ndr
, r
->oid
);
99 return ndr_push_error(ndr
, NDR_ERR_SUBCONTEXT
,
100 "HEX String Conversion Error: %s\n",
104 _OID_PUSH_CHECK(ber_write_OID_String(&blob
, r
->oid
));
105 talloc_steal(ndr
, blob
.data
);
108 NDR_CHECK(ndr_push_uint32(ndr
, NDR_SCALARS
, blob
.length
));
109 NDR_CHECK(ndr_push_array_uint8(ndr
, NDR_SCALARS
, blob
.data
, blob
.length
));
112 return NDR_ERR_SUCCESS
;
115 enum ndr_err_code
ndr_pull_drsuapi_DsReplicaOID(struct ndr_pull
*ndr
, int ndr_flags
, struct drsuapi_DsReplicaOID
*r
)
118 TALLOC_CTX
*_mem_save_oid_0
;
119 if (ndr_flags
& NDR_SCALARS
) {
120 NDR_CHECK(ndr_pull_align(ndr
, 4));
121 NDR_CHECK(ndr_pull_uint32(ndr
, NDR_SCALARS
, &r
->__ndr_size
));
122 if (r
->__ndr_size
< 0 || r
->__ndr_size
> 10000) {
123 return ndr_pull_error(ndr
, NDR_ERR_RANGE
, "value out of range");
125 NDR_CHECK(ndr_pull_generic_ptr(ndr
, &_ptr_oid
));
127 NDR_PULL_ALLOC(ndr
, r
->oid
);
132 if (ndr_flags
& NDR_BUFFERS
) {
134 DATA_BLOB _oid_array
;
137 _mem_save_oid_0
= NDR_PULL_GET_MEM_CTX(ndr
);
138 NDR_PULL_SET_MEM_CTX(ndr
, ndr
, 0);
139 NDR_CHECK(ndr_pull_array_size(ndr
, &r
->oid
));
140 _oid_array
.length
= ndr_get_array_size(ndr
, &r
->oid
);
141 NDR_PULL_ALLOC_N(ndr
, _oid_array
.data
, _oid_array
.length
);
142 NDR_CHECK(ndr_pull_array_uint8(ndr
, NDR_SCALARS
, _oid_array
.data
, _oid_array
.length
));
143 NDR_PULL_SET_MEM_CTX(ndr
, _mem_save_oid_0
, 0);
145 if (_oid_array
.length
&& _oid_array
.data
[0] == 0xFF) {
146 _oid
= data_blob_hex_string(ndr
, &_oid_array
);
147 NDR_ERR_HAVE_NO_MEMORY(_oid
);
149 _OID_PULL_CHECK(ber_read_OID_String(ndr
, _oid_array
, &_oid
));
151 data_blob_free(&_oid_array
);
152 talloc_steal(r
->oid
, _oid
);
156 NDR_CHECK(ndr_check_array_size(ndr
, (void*)&r
->oid
, r
->__ndr_size
));
159 return NDR_ERR_SUCCESS
;
162 size_t ndr_size_drsuapi_DsReplicaOID_oid(const char *oid
, int flags
)
169 if (strncasecmp("ff", oid
, 2) == 0) {
170 _blob
= strhex_to_data_blob(NULL
, oid
);
175 if (ber_write_OID_String(&_blob
, oid
)) {
179 data_blob_free(&_blob
);
183 enum ndr_err_code
ndr_push_drsuapi_DsGetNCChangesMSZIPCtr1(struct ndr_push
*ndr
, int ndr_flags
, const struct drsuapi_DsGetNCChangesMSZIPCtr1
*r
)
185 if (ndr_flags
& NDR_SCALARS
) {
186 uint32_t decompressed_length
= 0;
187 uint32_t compressed_length
= 0;
190 struct ndr_push
*_ndr_ts
;
191 NDR_CHECK(ndr_push_subcontext_start(ndr
, &_ndr_ts
, 4, -1));
193 struct ndr_push
*_ndr_ts_compressed
;
194 NDR_CHECK(ndr_push_compression_start(_ndr_ts
, &_ndr_ts_compressed
, NDR_COMPRESSION_MSZIP
, -1));
195 NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr1TS(_ndr_ts_compressed
, NDR_SCALARS
|NDR_BUFFERS
, r
->ts
));
196 decompressed_length
= _ndr_ts_compressed
->offset
;
197 NDR_CHECK(ndr_push_compression_end(_ndr_ts
, _ndr_ts_compressed
, NDR_COMPRESSION_MSZIP
, -1));
199 compressed_length
= _ndr_ts
->offset
;
200 talloc_free(_ndr_ts
);
203 NDR_CHECK(ndr_push_align(ndr
, 4));
204 NDR_CHECK(ndr_push_uint32(ndr
, NDR_SCALARS
, decompressed_length
));
205 NDR_CHECK(ndr_push_uint32(ndr
, NDR_SCALARS
, compressed_length
));
206 NDR_CHECK(ndr_push_unique_ptr(ndr
, r
->ts
));
208 if (ndr_flags
& NDR_BUFFERS
) {
211 struct ndr_push
*_ndr_ts
;
212 NDR_CHECK(ndr_push_subcontext_start(ndr
, &_ndr_ts
, 4, -1));
214 struct ndr_push
*_ndr_ts_compressed
;
215 NDR_CHECK(ndr_push_compression_start(_ndr_ts
, &_ndr_ts_compressed
, NDR_COMPRESSION_MSZIP
, -1));
216 NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr1TS(_ndr_ts_compressed
, NDR_SCALARS
|NDR_BUFFERS
, r
->ts
));
217 NDR_CHECK(ndr_push_compression_end(_ndr_ts
, _ndr_ts_compressed
, NDR_COMPRESSION_MSZIP
, -1));
219 NDR_CHECK(ndr_push_subcontext_end(ndr
, _ndr_ts
, 4, -1));
223 return NDR_ERR_SUCCESS
;
226 enum ndr_err_code
ndr_push_drsuapi_DsGetNCChangesMSZIPCtr6(struct ndr_push
*ndr
, int ndr_flags
, const struct drsuapi_DsGetNCChangesMSZIPCtr6
*r
)
228 if (ndr_flags
& NDR_SCALARS
) {
229 uint32_t decompressed_length
= 0;
230 uint32_t compressed_length
= 0;
233 struct ndr_push
*_ndr_ts
;
234 NDR_CHECK(ndr_push_subcontext_start(ndr
, &_ndr_ts
, 4, -1));
236 struct ndr_push
*_ndr_ts_compressed
;
237 NDR_CHECK(ndr_push_compression_start(_ndr_ts
, &_ndr_ts_compressed
, NDR_COMPRESSION_MSZIP
, -1));
238 NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr6TS(_ndr_ts_compressed
, NDR_SCALARS
|NDR_BUFFERS
, r
->ts
));
239 decompressed_length
= _ndr_ts_compressed
->offset
;
240 NDR_CHECK(ndr_push_compression_end(_ndr_ts
, _ndr_ts_compressed
, NDR_COMPRESSION_MSZIP
, -1));
242 compressed_length
= _ndr_ts
->offset
;
243 talloc_free(_ndr_ts
);
246 NDR_CHECK(ndr_push_align(ndr
, 4));
247 NDR_CHECK(ndr_push_uint32(ndr
, NDR_SCALARS
, decompressed_length
));
248 NDR_CHECK(ndr_push_uint32(ndr
, NDR_SCALARS
, compressed_length
));
249 NDR_CHECK(ndr_push_unique_ptr(ndr
, r
->ts
));
251 if (ndr_flags
& NDR_BUFFERS
) {
254 struct ndr_push
*_ndr_ts
;
255 NDR_CHECK(ndr_push_subcontext_start(ndr
, &_ndr_ts
, 4, -1));
257 struct ndr_push
*_ndr_ts_compressed
;
258 NDR_CHECK(ndr_push_compression_start(_ndr_ts
, &_ndr_ts_compressed
, NDR_COMPRESSION_MSZIP
, -1));
259 NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr6TS(_ndr_ts_compressed
, NDR_SCALARS
|NDR_BUFFERS
, r
->ts
));
260 NDR_CHECK(ndr_push_compression_end(_ndr_ts
, _ndr_ts_compressed
, NDR_COMPRESSION_MSZIP
, -1));
262 NDR_CHECK(ndr_push_subcontext_end(ndr
, _ndr_ts
, 4, -1));
266 return NDR_ERR_SUCCESS
;
269 enum ndr_err_code
ndr_push_drsuapi_DsGetNCChangesXPRESSCtr1(struct ndr_push
*ndr
, int ndr_flags
, const struct drsuapi_DsGetNCChangesXPRESSCtr1
*r
)
271 if (ndr_flags
& NDR_SCALARS
) {
272 uint32_t decompressed_length
= 0;
273 uint32_t compressed_length
= 0;
276 struct ndr_push
*_ndr_ts
;
277 NDR_CHECK(ndr_push_subcontext_start(ndr
, &_ndr_ts
, 4, -1));
279 struct ndr_push
*_ndr_ts_compressed
;
280 NDR_CHECK(ndr_push_compression_start(_ndr_ts
, &_ndr_ts_compressed
, NDR_COMPRESSION_XPRESS
, -1));
281 NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr1TS(_ndr_ts_compressed
, NDR_SCALARS
|NDR_BUFFERS
, r
->ts
));
282 decompressed_length
= _ndr_ts_compressed
->offset
;
283 NDR_CHECK(ndr_push_compression_end(_ndr_ts
, _ndr_ts_compressed
, NDR_COMPRESSION_XPRESS
, -1));
285 compressed_length
= _ndr_ts
->offset
;
286 talloc_free(_ndr_ts
);
289 NDR_CHECK(ndr_push_align(ndr
, 4));
290 NDR_CHECK(ndr_push_uint32(ndr
, NDR_SCALARS
, decompressed_length
));
291 NDR_CHECK(ndr_push_uint32(ndr
, NDR_SCALARS
, compressed_length
));
292 NDR_CHECK(ndr_push_unique_ptr(ndr
, r
->ts
));
294 if (ndr_flags
& NDR_BUFFERS
) {
297 struct ndr_push
*_ndr_ts
;
298 NDR_CHECK(ndr_push_subcontext_start(ndr
, &_ndr_ts
, 4, -1));
300 struct ndr_push
*_ndr_ts_compressed
;
301 NDR_CHECK(ndr_push_compression_start(_ndr_ts
, &_ndr_ts_compressed
, NDR_COMPRESSION_XPRESS
, -1));
302 NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr1TS(_ndr_ts_compressed
, NDR_SCALARS
|NDR_BUFFERS
, r
->ts
));
303 NDR_CHECK(ndr_push_compression_end(_ndr_ts
, _ndr_ts_compressed
, NDR_COMPRESSION_XPRESS
, -1));
305 NDR_CHECK(ndr_push_subcontext_end(ndr
, _ndr_ts
, 4, -1));
309 return NDR_ERR_SUCCESS
;
312 enum ndr_err_code
ndr_push_drsuapi_DsGetNCChangesXPRESSCtr6(struct ndr_push
*ndr
, int ndr_flags
, const struct drsuapi_DsGetNCChangesXPRESSCtr6
*r
)
314 if (ndr_flags
& NDR_SCALARS
) {
315 uint32_t decompressed_length
= 0;
316 uint32_t compressed_length
= 0;
319 struct ndr_push
*_ndr_ts
;
320 NDR_CHECK(ndr_push_subcontext_start(ndr
, &_ndr_ts
, 4, -1));
322 struct ndr_push
*_ndr_ts_compressed
;
323 NDR_CHECK(ndr_push_compression_start(_ndr_ts
, &_ndr_ts_compressed
, NDR_COMPRESSION_XPRESS
, -1));
324 NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr6TS(_ndr_ts_compressed
, NDR_SCALARS
|NDR_BUFFERS
, r
->ts
));
325 decompressed_length
= _ndr_ts_compressed
->offset
;
326 NDR_CHECK(ndr_push_compression_end(_ndr_ts
, _ndr_ts_compressed
, NDR_COMPRESSION_XPRESS
, -1));
328 compressed_length
= _ndr_ts
->offset
;
329 talloc_free(_ndr_ts
);
332 NDR_CHECK(ndr_push_align(ndr
, 4));
333 NDR_CHECK(ndr_push_uint32(ndr
, NDR_SCALARS
, decompressed_length
));
334 NDR_CHECK(ndr_push_uint32(ndr
, NDR_SCALARS
, compressed_length
));
335 NDR_CHECK(ndr_push_unique_ptr(ndr
, r
->ts
));
337 if (ndr_flags
& NDR_BUFFERS
) {
340 struct ndr_push
*_ndr_ts
;
341 NDR_CHECK(ndr_push_subcontext_start(ndr
, &_ndr_ts
, 4, -1));
343 struct ndr_push
*_ndr_ts_compressed
;
344 NDR_CHECK(ndr_push_compression_start(_ndr_ts
, &_ndr_ts_compressed
, NDR_COMPRESSION_XPRESS
, -1));
345 NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr6TS(_ndr_ts_compressed
, NDR_SCALARS
|NDR_BUFFERS
, r
->ts
));
346 NDR_CHECK(ndr_push_compression_end(_ndr_ts
, _ndr_ts_compressed
, NDR_COMPRESSION_XPRESS
, -1));
348 NDR_CHECK(ndr_push_subcontext_end(ndr
, _ndr_ts
, 4, -1));
352 return NDR_ERR_SUCCESS
;
355 _PUBLIC_
size_t ndr_size_drsuapi_DsReplicaObjectIdentifier3Binary_without_Binary(const struct drsuapi_DsReplicaObjectIdentifier3Binary
*r
, struct smb_iconv_convenience
*ic
, int flags
)
357 return ndr_size_struct((const struct drsuapi_DsReplicaObjectIdentifier3
*)r
, flags
, (ndr_push_flags_fn_t
)ndr_push_drsuapi_DsReplicaObjectIdentifier3
, ic
);