s3-utils: Fix scanf format in smbacls.
[Samba.git] / librpc / ndr / ndr_drsuapi.c
blobf7125e6e5542156081fd8802e8e8e1bf40f6a40c
1 /*
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/>.
23 #include "includes.h"
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' */
29 #undef strncasecmp
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");
35 ndr->depth++;
36 ndr_print_ptr(ndr, "next_object", r->next_object);
37 ndr_print_drsuapi_DsReplicaObject(ndr, "object", &r->object);
38 ndr->depth--;
39 if (r->next_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");
47 ndr->depth++;
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);
52 ndr->depth++;
53 if (r->parent_object_guid) {
54 ndr_print_GUID(ndr, "parent_object_guid", r->parent_object_guid);
56 ndr->depth--;
57 ndr_print_ptr(ndr, "meta_data_ctr", r->meta_data_ctr);
58 ndr->depth++;
59 if (r->meta_data_ctr) {
60 ndr_print_drsuapi_DsReplicaMetaDataCtr(ndr, "meta_data_ctr", r->meta_data_ctr);
62 ndr->depth--;
63 ndr->depth--;
64 if (r->next_object) {
65 ndr_print_drsuapi_DsReplicaObjectListItemEx(ndr, "next_object", r->next_object);
69 _PUBLIC_ void ndr_print_drsuapi_DsReplicaOID(struct ndr_print *ndr, const char *name, const struct drsuapi_DsReplicaOID *r)
71 ndr_print_struct(ndr, name, "drsuapi_DsReplicaOID");
72 ndr->depth++;
73 ndr_print_uint32(ndr, "length", r->length);
74 ndr->print(ndr, "%-25s: length=%u", "oid", r->length);
75 if (r->binary_oid) {
76 char *partial_oid = NULL;
77 DATA_BLOB oid_blob = data_blob_const(r->binary_oid, r->length);
78 char *hex_str = data_blob_hex_string_upper(ndr, &oid_blob);
79 ber_read_partial_OID_String(ndr, oid_blob, &partial_oid);
80 ndr->depth++;
81 ndr->print(ndr, "%-25s: 0x%s (%s)", "binary_oid", hex_str, partial_oid);
82 ndr->depth--;
83 talloc_free(hex_str);
84 talloc_free(partial_oid);
86 ndr->depth--;
89 static void _print_drsuapi_DsAttributeValue_attid(struct ndr_print *ndr, const char *name,
90 const struct drsuapi_DsAttributeValue *r)
92 uint32_t v;
94 ndr_print_struct(ndr, name, "drsuapi_DsAttributeValue");
95 ndr->depth++;
96 v = IVAL(r->blob->data, 0);
97 ndr_print_uint32(ndr, "attid", v);
98 ndr->depth--;
101 static void _print_drsuapi_DsAttributeValue_str(struct ndr_print *ndr, const char *name,
102 const struct drsuapi_DsAttributeValue *r)
104 void *p;
105 size_t converted_size = 0;
107 ndr_print_struct(ndr, name, "drsuapi_DsAttributeValue");
108 ndr->depth++;
109 if (!convert_string_talloc(ndr,
110 CH_UTF16, CH_UNIX,
111 r->blob->data,
112 r->blob->length,
113 &p, &converted_size)) {
114 ndr_print_string(ndr, "string", "INVALID CONVERSION");
115 } else {
116 char *str = (char *)p;
117 ndr_print_string(ndr, "string", str);
118 talloc_free(str);
120 ndr->depth--;
123 static void _print_drsuapi_DsAttributeValueCtr(struct ndr_print *ndr,
124 const char *name,
125 const struct drsuapi_DsAttributeValueCtr *r,
126 void (*print_val_fn)(struct ndr_print *ndr, const char *name, const struct drsuapi_DsAttributeValue *r))
128 uint32_t cntr_values_1;
129 ndr_print_struct(ndr, name, "drsuapi_DsAttributeValueCtr");
130 ndr->depth++;
131 ndr_print_uint32(ndr, "num_values", r->num_values);
132 ndr_print_ptr(ndr, "values", r->values);
133 ndr->depth++;
134 if (r->values) {
135 ndr->print(ndr, "%s: ARRAY(%d)", "values", (int)r->num_values);
136 ndr->depth++;
137 for (cntr_values_1=0;cntr_values_1<r->num_values;cntr_values_1++) {
138 char *idx_1=NULL;
139 if (asprintf(&idx_1, "[%d]", cntr_values_1) != -1) {
140 //ndr_print_drsuapi_DsAttributeValue(ndr, "values", &r->values[cntr_values_1]);
141 print_val_fn(ndr, "values", &r->values[cntr_values_1]);
142 free(idx_1);
145 ndr->depth--;
147 ndr->depth--;
148 ndr->depth--;
151 _PUBLIC_ void ndr_print_drsuapi_DsReplicaAttribute(struct ndr_print *ndr,
152 const char *name,
153 const struct drsuapi_DsReplicaAttribute *r)
155 ndr_print_struct(ndr, name, "drsuapi_DsReplicaAttribute");
156 ndr->depth++;
157 ndr_print_drsuapi_DsAttributeId(ndr, "attid", r->attid);
158 switch (r->attid) {
159 case DRSUAPI_ATTID_objectClass:
160 case DRSUAPI_ATTID_possSuperiors:
161 case DRSUAPI_ATTID_subClassOf:
162 case DRSUAPI_ATTID_governsID:
163 case DRSUAPI_ATTID_mustContain:
164 case DRSUAPI_ATTID_mayContain:
165 case DRSUAPI_ATTID_rDNAttId:
166 case DRSUAPI_ATTID_attributeID:
167 case DRSUAPI_ATTID_attributeSyntax:
168 case DRSUAPI_ATTID_auxiliaryClass:
169 case DRSUAPI_ATTID_systemPossSuperiors:
170 case DRSUAPI_ATTID_systemMayContain:
171 case DRSUAPI_ATTID_systemMustContain:
172 case DRSUAPI_ATTID_systemAuxiliaryClass:
173 case DRSUAPI_ATTID_transportAddressAttribute:
174 /* ATTIDs for classSchema and attributeSchema */
175 _print_drsuapi_DsAttributeValueCtr(ndr, "value_ctr", &r->value_ctr,
176 _print_drsuapi_DsAttributeValue_attid);
177 break;
178 case DRSUAPI_ATTID_cn:
179 case DRSUAPI_ATTID_ou:
180 case DRSUAPI_ATTID_description:
181 case DRSUAPI_ATTID_displayName:
182 case DRSUAPI_ATTID_dMDLocation:
183 case DRSUAPI_ATTID_adminDisplayName:
184 case DRSUAPI_ATTID_adminDescription:
185 case DRSUAPI_ATTID_lDAPDisplayName:
186 case DRSUAPI_ATTID_name:
187 _print_drsuapi_DsAttributeValueCtr(ndr, "value_ctr", &r->value_ctr,
188 _print_drsuapi_DsAttributeValue_str);
189 break;
190 default:
191 _print_drsuapi_DsAttributeValueCtr(ndr, "value_ctr", &r->value_ctr,
192 ndr_print_drsuapi_DsAttributeValue);
193 break;
195 ndr->depth--;
198 enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesMSZIPCtr1(struct ndr_push *ndr, int ndr_flags, const struct drsuapi_DsGetNCChangesMSZIPCtr1 *r)
200 if (ndr_flags & NDR_SCALARS) {
201 uint32_t decompressed_length = 0;
202 uint32_t compressed_length = 0;
203 if (r->ts) {
205 struct ndr_push *_ndr_ts;
206 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
208 struct ndr_push *_ndr_ts_compressed;
209 NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
210 NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr1TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
211 decompressed_length = _ndr_ts_compressed->offset;
212 NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
214 compressed_length = _ndr_ts->offset;
215 talloc_free(_ndr_ts);
218 NDR_CHECK(ndr_push_align(ndr, 4));
219 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, decompressed_length));
220 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, compressed_length));
221 NDR_CHECK(ndr_push_unique_ptr(ndr, r->ts));
223 if (ndr_flags & NDR_BUFFERS) {
224 if (r->ts) {
226 struct ndr_push *_ndr_ts;
227 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
229 struct ndr_push *_ndr_ts_compressed;
230 NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
231 NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr1TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
232 NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
234 NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_ts, 4, -1));
238 return NDR_ERR_SUCCESS;
241 enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesMSZIPCtr6(struct ndr_push *ndr, int ndr_flags, const struct drsuapi_DsGetNCChangesMSZIPCtr6 *r)
243 if (ndr_flags & NDR_SCALARS) {
244 uint32_t decompressed_length = 0;
245 uint32_t compressed_length = 0;
246 if (r->ts) {
248 struct ndr_push *_ndr_ts;
249 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
251 struct ndr_push *_ndr_ts_compressed;
252 NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
253 NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr6TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
254 decompressed_length = _ndr_ts_compressed->offset;
255 NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
257 compressed_length = _ndr_ts->offset;
258 talloc_free(_ndr_ts);
261 NDR_CHECK(ndr_push_align(ndr, 4));
262 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, decompressed_length));
263 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, compressed_length));
264 NDR_CHECK(ndr_push_unique_ptr(ndr, r->ts));
266 if (ndr_flags & NDR_BUFFERS) {
267 if (r->ts) {
269 struct ndr_push *_ndr_ts;
270 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
272 struct ndr_push *_ndr_ts_compressed;
273 NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
274 NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr6TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
275 NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
277 NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_ts, 4, -1));
281 return NDR_ERR_SUCCESS;
284 enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesXPRESSCtr1(struct ndr_push *ndr, int ndr_flags, const struct drsuapi_DsGetNCChangesXPRESSCtr1 *r)
286 if (ndr_flags & NDR_SCALARS) {
287 uint32_t decompressed_length = 0;
288 uint32_t compressed_length = 0;
289 if (r->ts) {
291 struct ndr_push *_ndr_ts;
292 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
294 struct ndr_push *_ndr_ts_compressed;
295 NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
296 NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr1TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
297 decompressed_length = _ndr_ts_compressed->offset;
298 NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
300 compressed_length = _ndr_ts->offset;
301 talloc_free(_ndr_ts);
304 NDR_CHECK(ndr_push_align(ndr, 4));
305 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, decompressed_length));
306 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, compressed_length));
307 NDR_CHECK(ndr_push_unique_ptr(ndr, r->ts));
309 if (ndr_flags & NDR_BUFFERS) {
310 if (r->ts) {
312 struct ndr_push *_ndr_ts;
313 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
315 struct ndr_push *_ndr_ts_compressed;
316 NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
317 NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr1TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
318 NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
320 NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_ts, 4, -1));
324 return NDR_ERR_SUCCESS;
327 enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesXPRESSCtr6(struct ndr_push *ndr, int ndr_flags, const struct drsuapi_DsGetNCChangesXPRESSCtr6 *r)
329 if (ndr_flags & NDR_SCALARS) {
330 uint32_t decompressed_length = 0;
331 uint32_t compressed_length = 0;
332 if (r->ts) {
334 struct ndr_push *_ndr_ts;
335 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
337 struct ndr_push *_ndr_ts_compressed;
338 NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
339 NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr6TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
340 decompressed_length = _ndr_ts_compressed->offset;
341 NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
343 compressed_length = _ndr_ts->offset;
344 talloc_free(_ndr_ts);
347 NDR_CHECK(ndr_push_align(ndr, 4));
348 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, decompressed_length));
349 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, compressed_length));
350 NDR_CHECK(ndr_push_unique_ptr(ndr, r->ts));
352 if (ndr_flags & NDR_BUFFERS) {
353 if (r->ts) {
355 struct ndr_push *_ndr_ts;
356 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
358 struct ndr_push *_ndr_ts_compressed;
359 NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
360 NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr6TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
361 NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
363 NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_ts, 4, -1));
367 return NDR_ERR_SUCCESS;
370 _PUBLIC_ size_t ndr_size_drsuapi_DsReplicaObjectIdentifier3Binary_without_Binary(const struct drsuapi_DsReplicaObjectIdentifier3Binary *r, int flags)
372 return ndr_size_struct((const struct drsuapi_DsReplicaObjectIdentifier3 *)r, flags, (ndr_push_flags_fn_t)ndr_push_drsuapi_DsReplicaObjectIdentifier3);
375 _PUBLIC_ void ndr_print_drsuapi_SecBufferType(struct ndr_print *ndr, const char *name, enum drsuapi_SecBufferType r)
377 const char *val = NULL;
379 switch (r & 0x00000007) {
380 case DRSUAPI_SECBUFFER_EMPTY: val = "DRSUAPI_SECBUFFER_EMPTY"; break;
381 case DRSUAPI_SECBUFFER_DATA: val = "DRSUAPI_SECBUFFER_DATA"; break;
382 case DRSUAPI_SECBUFFER_TOKEN: val = "DRSUAPI_SECBUFFER_TOKEN"; break;
383 case DRSUAPI_SECBUFFER_PKG_PARAMS: val = "DRSUAPI_SECBUFFER_PKG_PARAMS"; break;
384 case DRSUAPI_SECBUFFER_MISSING: val = "DRSUAPI_SECBUFFER_MISSING"; break;
385 case DRSUAPI_SECBUFFER_EXTRA: val = "DRSUAPI_SECBUFFER_EXTRA"; break;
386 case DRSUAPI_SECBUFFER_STREAM_TRAILER: val = "DRSUAPI_SECBUFFER_STREAM_TRAILER"; break;
387 case DRSUAPI_SECBUFFER_STREAM_HEADER: val = "DRSUAPI_SECBUFFER_STREAM_HEADER"; break;
390 if (r & DRSUAPI_SECBUFFER_READONLY) {
391 char *v = talloc_asprintf(ndr, "DRSUAPI_SECBUFFER_READONLY | %s", val);
392 ndr_print_enum(ndr, name, "ENUM", v, r);
393 } else {
394 ndr_print_enum(ndr, name, "ENUM", val, r);
398 _PUBLIC_ void ndr_print_drsuapi_DsAddEntry_AttrErrListItem_V1(struct ndr_print *ndr, const char *name, const struct drsuapi_DsAddEntry_AttrErrListItem_V1 *r)
400 ndr_print_struct(ndr, name, "drsuapi_DsAddEntry_AttrErrListItem_V1");
401 ndr->depth++;
402 ndr_print_ptr(ndr, "next", r->next);
403 ndr_print_drsuapi_DsAddEntry_AttrErr_V1(ndr, "err_data", &r->err_data);
404 ndr->depth--;
405 if (r->next) {
406 ndr_print_drsuapi_DsAddEntry_AttrErrListItem_V1(ndr, "next", r->next);