e9888fdf858ead4b7577d76f7fde552f94ffb8ac
[sfrench/samba-autobuild/.git] / librpc / ndr / ndr_drsuapi.c
1 /*
2    Unix SMB/CIFS implementation.
3
4    routines for printing some linked list structs in DRSUAPI
5
6    Copyright (C) Stefan (metze) Metzmacher 2005
7
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.
12
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.
17
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/>.
20 */
21
22
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
30
31 void ndr_print_drsuapi_DsReplicaObjectListItem(struct ndr_print *ndr, const char *name,
32                                                const struct drsuapi_DsReplicaObjectListItem *r)
33 {
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);
41         }
42 }
43
44 void ndr_print_drsuapi_DsReplicaObjectListItemEx(struct ndr_print *ndr, const char *name, const struct drsuapi_DsReplicaObjectListItemEx *r)
45 {
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);
55         }
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);
61         }
62         ndr->depth--;
63         ndr->depth--;
64         if (r->next_object) {
65                 ndr_print_drsuapi_DsReplicaObjectListItemEx(ndr, "next_object", r->next_object);
66         }
67 }
68
69 _PUBLIC_ void ndr_print_drsuapi_DsReplicaOID(struct ndr_print *ndr, const char *name, const struct drsuapi_DsReplicaOID *r)
70 {
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, (const char **)&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);
85         }
86         ndr->depth--;
87 }
88
89 enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesMSZIPCtr1(struct ndr_push *ndr, int ndr_flags, const struct drsuapi_DsGetNCChangesMSZIPCtr1 *r)
90 {
91         if (ndr_flags & NDR_SCALARS) {
92                 uint32_t decompressed_length = 0;
93                 uint32_t compressed_length = 0;
94                 if (r->ts) {
95                         {
96                                 struct ndr_push *_ndr_ts;
97                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
98                                 {
99                                         struct ndr_push *_ndr_ts_compressed;
100                                         NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
101                                         NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr1TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
102                                         decompressed_length = _ndr_ts_compressed->offset;
103                                         NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
104                                 }
105                                 compressed_length = _ndr_ts->offset;
106                                 talloc_free(_ndr_ts);
107                         }
108                 }
109                 NDR_CHECK(ndr_push_align(ndr, 4));
110                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, decompressed_length));
111                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, compressed_length));
112                 NDR_CHECK(ndr_push_unique_ptr(ndr, r->ts));
113         }
114         if (ndr_flags & NDR_BUFFERS) {
115                 if (r->ts) {
116                         {
117                                 struct ndr_push *_ndr_ts;
118                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
119                                 {
120                                         struct ndr_push *_ndr_ts_compressed;
121                                         NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
122                                         NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr1TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
123                                         NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
124                                 }
125                                 NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_ts, 4, -1));
126                         }
127                 }
128         }
129         return NDR_ERR_SUCCESS;
130 }
131
132 enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesMSZIPCtr6(struct ndr_push *ndr, int ndr_flags, const struct drsuapi_DsGetNCChangesMSZIPCtr6 *r)
133 {
134         if (ndr_flags & NDR_SCALARS) {
135                 uint32_t decompressed_length = 0;
136                 uint32_t compressed_length = 0;
137                 if (r->ts) {
138                         {
139                                 struct ndr_push *_ndr_ts;
140                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
141                                 {
142                                         struct ndr_push *_ndr_ts_compressed;
143                                         NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
144                                         NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr6TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
145                                         decompressed_length = _ndr_ts_compressed->offset;
146                                         NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
147                                 }
148                                 compressed_length = _ndr_ts->offset;
149                                 talloc_free(_ndr_ts);
150                         }
151                 }
152                 NDR_CHECK(ndr_push_align(ndr, 4));
153                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, decompressed_length));
154                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, compressed_length));
155                 NDR_CHECK(ndr_push_unique_ptr(ndr, r->ts));
156         }
157         if (ndr_flags & NDR_BUFFERS) {
158                 if (r->ts) {
159                         {
160                                 struct ndr_push *_ndr_ts;
161                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
162                                 {
163                                         struct ndr_push *_ndr_ts_compressed;
164                                         NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
165                                         NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr6TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
166                                         NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
167                                 }
168                                 NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_ts, 4, -1));
169                         }
170                 }
171         }
172         return NDR_ERR_SUCCESS;
173 }
174
175 enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesXPRESSCtr1(struct ndr_push *ndr, int ndr_flags, const struct drsuapi_DsGetNCChangesXPRESSCtr1 *r)
176 {
177         if (ndr_flags & NDR_SCALARS) {
178                 uint32_t decompressed_length = 0;
179                 uint32_t compressed_length = 0;
180                 if (r->ts) {
181                         {
182                                 struct ndr_push *_ndr_ts;
183                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
184                                 {
185                                         struct ndr_push *_ndr_ts_compressed;
186                                         NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
187                                         NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr1TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
188                                         decompressed_length = _ndr_ts_compressed->offset;
189                                         NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
190                                 }
191                                 compressed_length = _ndr_ts->offset;
192                                 talloc_free(_ndr_ts);
193                         }
194                 }
195                 NDR_CHECK(ndr_push_align(ndr, 4));
196                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, decompressed_length));
197                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, compressed_length));
198                 NDR_CHECK(ndr_push_unique_ptr(ndr, r->ts));
199         }
200         if (ndr_flags & NDR_BUFFERS) {
201                 if (r->ts) {
202                         {
203                                 struct ndr_push *_ndr_ts;
204                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
205                                 {
206                                         struct ndr_push *_ndr_ts_compressed;
207                                         NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
208                                         NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr1TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
209                                         NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
210                                 }
211                                 NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_ts, 4, -1));
212                         }
213                 }
214         }
215         return NDR_ERR_SUCCESS;
216 }
217
218 enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesXPRESSCtr6(struct ndr_push *ndr, int ndr_flags, const struct drsuapi_DsGetNCChangesXPRESSCtr6 *r)
219 {
220         if (ndr_flags & NDR_SCALARS) {
221                 uint32_t decompressed_length = 0;
222                 uint32_t compressed_length = 0;
223                 if (r->ts) {
224                         {
225                                 struct ndr_push *_ndr_ts;
226                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
227                                 {
228                                         struct ndr_push *_ndr_ts_compressed;
229                                         NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
230                                         NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr6TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
231                                         decompressed_length = _ndr_ts_compressed->offset;
232                                         NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
233                                 }
234                                 compressed_length = _ndr_ts->offset;
235                                 talloc_free(_ndr_ts);
236                         }
237                 }
238                 NDR_CHECK(ndr_push_align(ndr, 4));
239                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, decompressed_length));
240                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, compressed_length));
241                 NDR_CHECK(ndr_push_unique_ptr(ndr, r->ts));
242         }
243         if (ndr_flags & NDR_BUFFERS) {
244                 if (r->ts) {
245                         {
246                                 struct ndr_push *_ndr_ts;
247                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
248                                 {
249                                         struct ndr_push *_ndr_ts_compressed;
250                                         NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
251                                         NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr6TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
252                                         NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
253                                 }
254                                 NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_ts, 4, -1));
255                         }
256                 }
257         }
258         return NDR_ERR_SUCCESS;
259 }
260
261 _PUBLIC_ size_t ndr_size_drsuapi_DsReplicaObjectIdentifier3Binary_without_Binary(const struct drsuapi_DsReplicaObjectIdentifier3Binary *r, struct smb_iconv_convenience *ic, int flags)
262 {
263         return ndr_size_struct((const struct drsuapi_DsReplicaObjectIdentifier3 *)r, flags, (ndr_push_flags_fn_t)ndr_push_drsuapi_DsReplicaObjectIdentifier3, ic);
264 }
265
266 _PUBLIC_ void ndr_print_drsuapi_SecBufferType(struct ndr_print *ndr, const char *name, enum drsuapi_SecBufferType r)
267 {
268         const char *val = NULL;
269
270         switch (r & 0x00000007) {
271                 case DRSUAPI_SECBUFFER_EMPTY: val = "DRSUAPI_SECBUFFER_EMPTY"; break;
272                 case DRSUAPI_SECBUFFER_DATA: val = "DRSUAPI_SECBUFFER_DATA"; break;
273                 case DRSUAPI_SECBUFFER_TOKEN: val = "DRSUAPI_SECBUFFER_TOKEN"; break;
274                 case DRSUAPI_SECBUFFER_PKG_PARAMS: val = "DRSUAPI_SECBUFFER_PKG_PARAMS"; break;
275                 case DRSUAPI_SECBUFFER_MISSING: val = "DRSUAPI_SECBUFFER_MISSING"; break;
276                 case DRSUAPI_SECBUFFER_EXTRA: val = "DRSUAPI_SECBUFFER_EXTRA"; break;
277                 case DRSUAPI_SECBUFFER_STREAM_TRAILER: val = "DRSUAPI_SECBUFFER_STREAM_TRAILER"; break;
278                 case DRSUAPI_SECBUFFER_STREAM_HEADER: val = "DRSUAPI_SECBUFFER_STREAM_HEADER"; break;
279         }
280
281         if (r & DRSUAPI_SECBUFFER_READONLY) {
282                 char *v = talloc_asprintf(ndr, "DRSUAPI_SECBUFFER_READONLY | %s", val);
283                 ndr_print_enum(ndr, name, "ENUM", v, r);
284         } else {
285                 ndr_print_enum(ndr, name, "ENUM", val, r);
286         }
287 }
288
289 _PUBLIC_ void ndr_print_drsuapi_DsAddEntry_AttrErrListItem_V1(struct ndr_print *ndr, const char *name, const struct drsuapi_DsAddEntry_AttrErrListItem_V1 *r)
290 {
291         ndr_print_struct(ndr, name, "drsuapi_DsAddEntry_AttrErrListItem_V1");
292         ndr->depth++;
293         ndr_print_ptr(ndr, "next", r->next);
294         ndr_print_drsuapi_DsAddEntry_AttrErr_V1(ndr, "err_data", &r->err_data);
295         ndr->depth--;
296         if (r->next) {
297                 ndr_print_drsuapi_DsAddEntry_AttrErrListItem_V1(ndr, "next", r->next);
298         }
299 }