e77ab54071eae0f3511d51741c06400e97b9660b
[bbaumbach/samba-autobuild/.git] / source4 / 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
29 void ndr_print_drsuapi_DsReplicaObjectListItem(struct ndr_print *ndr, const char *name, 
30                                                const struct drsuapi_DsReplicaObjectListItem *r)
31 {
32         ndr_print_struct(ndr, name, "drsuapi_DsReplicaObjectListItem");
33         ndr->depth++;
34         ndr_print_ptr(ndr, "next_object", r->next_object);
35         ndr_print_drsuapi_DsReplicaObject(ndr, "object", &r->object);
36         ndr->depth--;
37         if (r->next_object) {
38                 ndr_print_drsuapi_DsReplicaObjectListItem(ndr, "next_object", r->next_object);
39         }
40 }
41
42 void ndr_print_drsuapi_DsReplicaObjectListItemEx(struct ndr_print *ndr, const char *name, const struct drsuapi_DsReplicaObjectListItemEx *r)
43 {
44         ndr_print_struct(ndr, name, "drsuapi_DsReplicaObjectListItemEx");
45         ndr->depth++;
46         ndr_print_ptr(ndr, "next_object", r->next_object);
47         ndr_print_drsuapi_DsReplicaObject(ndr, "object", &r->object);
48         ndr_print_uint32(ndr, "is_nc_prefix", r->is_nc_prefix);
49         ndr_print_ptr(ndr, "parent_object_guid", r->parent_object_guid);
50         ndr->depth++;
51         if (r->parent_object_guid) {
52                 ndr_print_GUID(ndr, "parent_object_guid", r->parent_object_guid);
53         }
54         ndr->depth--;
55         ndr_print_ptr(ndr, "meta_data_ctr", r->meta_data_ctr);
56         ndr->depth++;
57         if (r->meta_data_ctr) {
58                 ndr_print_drsuapi_DsReplicaMetaDataCtr(ndr, "meta_data_ctr", r->meta_data_ctr);
59         }
60         ndr->depth--;
61         ndr->depth--;
62         if (r->next_object) {
63                 ndr_print_drsuapi_DsReplicaObjectListItemEx(ndr, "next_object", r->next_object);
64         }
65 }
66
67 #define _OID_PUSH_CHECK(call) do { \
68         bool _status; \
69         _status = call; \
70         if (_status != true) { \
71                 return ndr_push_error(ndr, NDR_ERR_SUBCONTEXT, "OID Conversion Error: %s\n", __location__); \
72         } \
73 } while (0)
74
75 #define _OID_PULL_CHECK(call) do { \
76         bool _status; \
77         _status = call; \
78         if (_status != true) { \
79                 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "OID Conversion Error: %s\n", __location__); \
80         } \
81 } while (0)
82
83 enum ndr_err_code ndr_push_drsuapi_DsReplicaOID(struct ndr_push *ndr, int ndr_flags, const struct drsuapi_DsReplicaOID *r)
84 {
85         if (ndr_flags & NDR_SCALARS) {
86                 NDR_CHECK(ndr_push_align(ndr, 4));
87                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, ndr_size_drsuapi_DsReplicaOID_oid(r->oid, 0)));
88                 NDR_CHECK(ndr_push_unique_ptr(ndr, r->oid));
89         }
90         if (ndr_flags & NDR_BUFFERS) {
91                 if (r->oid) {
92                         DATA_BLOB blob;
93
94                         if (strncasecmp("ff", r->oid, 2) == 0) {
95                                 blob = strhex_to_data_blob(r->oid);
96                                 if (!blob.data) {
97                                         return ndr_push_error(ndr, NDR_ERR_SUBCONTEXT,
98                                                               "HEX String Conversion Error: %s\n",
99                                                               __location__);
100                                 }
101                         } else {
102                                 _OID_PUSH_CHECK(ber_write_OID_String(&blob, r->oid));
103                         }
104                         talloc_steal(ndr, blob.data);
105
106                         NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, blob.length));
107                         NDR_CHECK(ndr_push_array_uint8(ndr, NDR_SCALARS, blob.data, blob.length));
108                 }
109         }
110         return NDR_ERR_SUCCESS;
111 }
112
113 enum ndr_err_code ndr_pull_drsuapi_DsReplicaOID(struct ndr_pull *ndr, int ndr_flags, struct drsuapi_DsReplicaOID *r)
114 {
115         uint32_t _ptr_oid;
116         TALLOC_CTX *_mem_save_oid_0;
117         if (ndr_flags & NDR_SCALARS) {
118                 NDR_CHECK(ndr_pull_align(ndr, 4));
119                 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->__ndr_size));
120                 if (r->__ndr_size < 0 || r->__ndr_size > 10000) {
121                         return ndr_pull_error(ndr, NDR_ERR_RANGE, "value out of range");
122                 }
123                 NDR_CHECK(ndr_pull_generic_ptr(ndr, &_ptr_oid));
124                 if (_ptr_oid) {
125                         NDR_PULL_ALLOC(ndr, r->oid);
126                 } else {
127                         r->oid = NULL;
128                 }
129         }
130         if (ndr_flags & NDR_BUFFERS) {
131                 if (r->oid) {
132                         DATA_BLOB _oid_array;
133                         const char *_oid;
134
135                         _mem_save_oid_0 = NDR_PULL_GET_MEM_CTX(ndr);
136                         NDR_PULL_SET_MEM_CTX(ndr, ndr, 0);
137                         NDR_CHECK(ndr_pull_array_size(ndr, &r->oid));
138                         _oid_array.length = ndr_get_array_size(ndr, &r->oid);
139                         NDR_PULL_ALLOC_N(ndr, _oid_array.data, _oid_array.length);
140                         NDR_CHECK(ndr_pull_array_uint8(ndr, NDR_SCALARS, _oid_array.data, _oid_array.length));
141                         NDR_PULL_SET_MEM_CTX(ndr, _mem_save_oid_0, 0);
142
143                         if (_oid_array.length && _oid_array.data[0] == 0xFF) {
144                                 _oid = data_blob_hex_string(ndr, &_oid_array);
145                                 NDR_ERR_HAVE_NO_MEMORY(_oid);
146                         } else {
147                                 _OID_PULL_CHECK(ber_read_OID_String(ndr, _oid_array, &_oid));
148                         }
149                         data_blob_free(&_oid_array);
150                         talloc_steal(r->oid, _oid);
151                         r->oid = _oid;
152                 }
153                 if (r->oid) {
154                         NDR_CHECK(ndr_check_array_size(ndr, (void*)&r->oid, r->__ndr_size));
155                 }
156         }
157         return NDR_ERR_SUCCESS;
158 }
159
160 size_t ndr_size_drsuapi_DsReplicaOID_oid(const char *oid, int flags)
161 {
162         DATA_BLOB _blob;
163         size_t ret = 0;
164
165         if (!oid) return 0;
166
167         if (strncasecmp("ff", oid, 2) == 0) {
168                 _blob = strhex_to_data_blob(oid);
169                 if (_blob.data) {
170                         ret = _blob.length;
171                 }
172         } else {
173                 if (ber_write_OID_String(&_blob, oid)) {
174                         ret = _blob.length;
175                 }
176         }
177         data_blob_free(&_blob);
178         return ret;
179 }
180
181 enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesMSZIPCtr1(struct ndr_push *ndr, int ndr_flags, const struct drsuapi_DsGetNCChangesMSZIPCtr1 *r)
182 {
183         if (ndr_flags & NDR_SCALARS) {
184                 uint32_t decompressed_length = 0;
185                 uint32_t compressed_length = 0;
186                 if (r->ts) {
187                         {
188                                 struct ndr_push *_ndr_ts;
189                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
190                                 {
191                                         struct ndr_push *_ndr_ts_compressed;
192                                         NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
193                                         NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr1TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
194                                         decompressed_length = _ndr_ts_compressed->offset;
195                                         NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
196                                 }
197                                 compressed_length = _ndr_ts->offset;
198                                 talloc_free(_ndr_ts);
199                         }
200                 }
201                 NDR_CHECK(ndr_push_align(ndr, 4));
202                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, decompressed_length));
203                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, compressed_length));
204                 NDR_CHECK(ndr_push_unique_ptr(ndr, r->ts));
205         }
206         if (ndr_flags & NDR_BUFFERS) {
207                 if (r->ts) {
208                         {
209                                 struct ndr_push *_ndr_ts;
210                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
211                                 {
212                                         struct ndr_push *_ndr_ts_compressed;
213                                         NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
214                                         NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr1TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
215                                         NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
216                                 }
217                                 NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_ts, 4, -1));
218                         }
219                 }
220         }
221         return NDR_ERR_SUCCESS;
222 }
223
224 enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesMSZIPCtr6(struct ndr_push *ndr, int ndr_flags, const struct drsuapi_DsGetNCChangesMSZIPCtr6 *r)
225 {
226         if (ndr_flags & NDR_SCALARS) {
227                 uint32_t decompressed_length = 0;
228                 uint32_t compressed_length = 0;
229                 if (r->ts) {
230                         {
231                                 struct ndr_push *_ndr_ts;
232                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
233                                 {
234                                         struct ndr_push *_ndr_ts_compressed;
235                                         NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
236                                         NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr6TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
237                                         decompressed_length = _ndr_ts_compressed->offset;
238                                         NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
239                                 }
240                                 compressed_length = _ndr_ts->offset;
241                                 talloc_free(_ndr_ts);
242                         }
243                 }
244                 NDR_CHECK(ndr_push_align(ndr, 4));
245                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, decompressed_length));
246                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, compressed_length));
247                 NDR_CHECK(ndr_push_unique_ptr(ndr, r->ts));
248         }
249         if (ndr_flags & NDR_BUFFERS) {
250                 if (r->ts) {
251                         {
252                                 struct ndr_push *_ndr_ts;
253                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
254                                 {
255                                         struct ndr_push *_ndr_ts_compressed;
256                                         NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
257                                         NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr6TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
258                                         NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
259                                 }
260                                 NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_ts, 4, -1));
261                         }
262                 }
263         }
264         return NDR_ERR_SUCCESS;
265 }
266
267 enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesXPRESSCtr1(struct ndr_push *ndr, int ndr_flags, const struct drsuapi_DsGetNCChangesXPRESSCtr1 *r)
268 {
269         if (ndr_flags & NDR_SCALARS) {
270                 uint32_t decompressed_length = 0;
271                 uint32_t compressed_length = 0;
272                 if (r->ts) {
273                         {
274                                 struct ndr_push *_ndr_ts;
275                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
276                                 {
277                                         struct ndr_push *_ndr_ts_compressed;
278                                         NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
279                                         NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr1TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
280                                         decompressed_length = _ndr_ts_compressed->offset;
281                                         NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
282                                 }
283                                 compressed_length = _ndr_ts->offset;
284                                 talloc_free(_ndr_ts);
285                         }
286                 }
287                 NDR_CHECK(ndr_push_align(ndr, 4));
288                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, decompressed_length));
289                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, compressed_length));
290                 NDR_CHECK(ndr_push_unique_ptr(ndr, r->ts));
291         }
292         if (ndr_flags & NDR_BUFFERS) {
293                 if (r->ts) {
294                         {
295                                 struct ndr_push *_ndr_ts;
296                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
297                                 {
298                                         struct ndr_push *_ndr_ts_compressed;
299                                         NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
300                                         NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr1TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
301                                         NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
302                                 }
303                                 NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_ts, 4, -1));
304                         }
305                 }
306         }
307         return NDR_ERR_SUCCESS;
308 }
309
310 enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesXPRESSCtr6(struct ndr_push *ndr, int ndr_flags, const struct drsuapi_DsGetNCChangesXPRESSCtr6 *r)
311 {
312         if (ndr_flags & NDR_SCALARS) {
313                 uint32_t decompressed_length = 0;
314                 uint32_t compressed_length = 0;
315                 if (r->ts) {
316                         {
317                                 struct ndr_push *_ndr_ts;
318                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
319                                 {
320                                         struct ndr_push *_ndr_ts_compressed;
321                                         NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
322                                         NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr6TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
323                                         decompressed_length = _ndr_ts_compressed->offset;
324                                         NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
325                                 }
326                                 compressed_length = _ndr_ts->offset;
327                                 talloc_free(_ndr_ts);
328                         }
329                 }
330                 NDR_CHECK(ndr_push_align(ndr, 4));
331                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, decompressed_length));
332                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, compressed_length));
333                 NDR_CHECK(ndr_push_unique_ptr(ndr, r->ts));
334         }
335         if (ndr_flags & NDR_BUFFERS) {
336                 if (r->ts) {
337                         {
338                                 struct ndr_push *_ndr_ts;
339                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
340                                 {
341                                         struct ndr_push *_ndr_ts_compressed;
342                                         NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
343                                         NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr6TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
344                                         NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
345                                 }
346                                 NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_ts, 4, -1));
347                         }
348                 }
349         }
350         return NDR_ERR_SUCCESS;
351 }