drsuapi: fix the drsuapi helper build for samba3.
[ira/wip.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
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 (_SAMBA_BUILD_ == 3)
95                         if (StrnCaseCmp("ff", r->oid, 2) == 0) {
96 #else
97                         if (strncasecmp("ff", r->oid, 2) == 0) {
98 #endif
99                                 blob = strhex_to_data_blob(ndr, r->oid);
100                                 if (!blob.data) {
101                                         return ndr_push_error(ndr, NDR_ERR_SUBCONTEXT,
102                                                               "HEX String Conversion Error: %s\n",
103                                                               __location__);
104                                 }
105                         } else {
106                                 _OID_PUSH_CHECK(ber_write_OID_String(&blob, r->oid));
107                         }
108
109                         NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, blob.length));
110                         NDR_CHECK(ndr_push_array_uint8(ndr, NDR_SCALARS, blob.data, blob.length));
111                 }
112         }
113         return NDR_ERR_SUCCESS;
114 }
115
116 enum ndr_err_code ndr_pull_drsuapi_DsReplicaOID(struct ndr_pull *ndr, int ndr_flags, struct drsuapi_DsReplicaOID *r)
117 {
118         uint32_t _ptr_oid;
119         TALLOC_CTX *_mem_save_oid_0;
120         if (ndr_flags & NDR_SCALARS) {
121                 NDR_CHECK(ndr_pull_align(ndr, 4));
122                 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->__ndr_size));
123                 if (r->__ndr_size < 0 || r->__ndr_size > 10000) {
124                         return ndr_pull_error(ndr, NDR_ERR_RANGE, "value out of range");
125                 }
126                 NDR_CHECK(ndr_pull_generic_ptr(ndr, &_ptr_oid));
127                 if (_ptr_oid) {
128                         NDR_PULL_ALLOC(ndr, r->oid);
129                 } else {
130                         r->oid = NULL;
131                 }
132         }
133         if (ndr_flags & NDR_BUFFERS) {
134                 if (r->oid) {
135                         DATA_BLOB _oid_array;
136                         const char *_oid;
137
138                         _mem_save_oid_0 = NDR_PULL_GET_MEM_CTX(ndr);
139                         NDR_PULL_SET_MEM_CTX(ndr, ndr, 0);
140                         NDR_CHECK(ndr_pull_array_size(ndr, &r->oid));
141                         _oid_array.length = ndr_get_array_size(ndr, &r->oid);
142                         NDR_PULL_ALLOC_N(ndr, _oid_array.data, _oid_array.length);
143                         NDR_CHECK(ndr_pull_array_uint8(ndr, NDR_SCALARS, _oid_array.data, _oid_array.length));
144                         NDR_PULL_SET_MEM_CTX(ndr, _mem_save_oid_0, 0);
145
146                         if (_oid_array.length && _oid_array.data[0] == 0xFF) {
147                                 _oid = data_blob_hex_string(ndr, &_oid_array);
148                                 NDR_ERR_HAVE_NO_MEMORY(_oid);
149                         } else {
150                                 _OID_PULL_CHECK(ber_read_OID_String(ndr, _oid_array, &_oid));
151                         }
152                         data_blob_free(&_oid_array);
153                         talloc_steal(r->oid, _oid);
154                         r->oid = _oid;
155                 }
156                 if (r->oid) {
157                         NDR_CHECK(ndr_check_array_size(ndr, (void*)&r->oid, r->__ndr_size));
158                 }
159         }
160         return NDR_ERR_SUCCESS;
161 }
162
163 size_t ndr_size_drsuapi_DsReplicaOID_oid(const char *oid, int flags)
164 {
165         DATA_BLOB _blob;
166         size_t ret = 0;
167
168         if (!oid) return 0;
169
170 #if (_SAMBA_BUILD_ == 3)
171         if (StrnCaseCmp("ff", oid, 2) == 0) {
172 #else
173         if (strncasecmp("ff", oid, 2) == 0) {
174 #endif
175                 _blob = strhex_to_data_blob(NULL, oid);
176                 if (_blob.data) {
177                         ret = _blob.length;
178                 }
179         } else {
180                 if (ber_write_OID_String(&_blob, oid)) {
181                         ret = _blob.length;
182                 }
183         }
184         data_blob_free(&_blob);
185         return ret;
186 }
187
188 enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesMSZIPCtr1(struct ndr_push *ndr, int ndr_flags, const struct drsuapi_DsGetNCChangesMSZIPCtr1 *r)
189 {
190         if (ndr_flags & NDR_SCALARS) {
191                 uint32_t decompressed_length = 0;
192                 uint32_t compressed_length = 0;
193                 if (r->ts) {
194                         {
195                                 struct ndr_push *_ndr_ts;
196                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
197                                 {
198                                         struct ndr_push *_ndr_ts_compressed;
199                                         NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
200                                         NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr1TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
201                                         decompressed_length = _ndr_ts_compressed->offset;
202                                         NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
203                                 }
204                                 compressed_length = _ndr_ts->offset;
205                                 talloc_free(_ndr_ts);
206                         }
207                 }
208                 NDR_CHECK(ndr_push_align(ndr, 4));
209                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, decompressed_length));
210                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, compressed_length));
211                 NDR_CHECK(ndr_push_unique_ptr(ndr, r->ts));
212         }
213         if (ndr_flags & NDR_BUFFERS) {
214                 if (r->ts) {
215                         {
216                                 struct ndr_push *_ndr_ts;
217                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
218                                 {
219                                         struct ndr_push *_ndr_ts_compressed;
220                                         NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
221                                         NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr1TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
222                                         NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
223                                 }
224                                 NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_ts, 4, -1));
225                         }
226                 }
227         }
228         return NDR_ERR_SUCCESS;
229 }
230
231 enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesMSZIPCtr6(struct ndr_push *ndr, int ndr_flags, const struct drsuapi_DsGetNCChangesMSZIPCtr6 *r)
232 {
233         if (ndr_flags & NDR_SCALARS) {
234                 uint32_t decompressed_length = 0;
235                 uint32_t compressed_length = 0;
236                 if (r->ts) {
237                         {
238                                 struct ndr_push *_ndr_ts;
239                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
240                                 {
241                                         struct ndr_push *_ndr_ts_compressed;
242                                         NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
243                                         NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr6TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
244                                         decompressed_length = _ndr_ts_compressed->offset;
245                                         NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
246                                 }
247                                 compressed_length = _ndr_ts->offset;
248                                 talloc_free(_ndr_ts);
249                         }
250                 }
251                 NDR_CHECK(ndr_push_align(ndr, 4));
252                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, decompressed_length));
253                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, compressed_length));
254                 NDR_CHECK(ndr_push_unique_ptr(ndr, r->ts));
255         }
256         if (ndr_flags & NDR_BUFFERS) {
257                 if (r->ts) {
258                         {
259                                 struct ndr_push *_ndr_ts;
260                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
261                                 {
262                                         struct ndr_push *_ndr_ts_compressed;
263                                         NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
264                                         NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr6TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
265                                         NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
266                                 }
267                                 NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_ts, 4, -1));
268                         }
269                 }
270         }
271         return NDR_ERR_SUCCESS;
272 }
273
274 enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesXPRESSCtr1(struct ndr_push *ndr, int ndr_flags, const struct drsuapi_DsGetNCChangesXPRESSCtr1 *r)
275 {
276         if (ndr_flags & NDR_SCALARS) {
277                 uint32_t decompressed_length = 0;
278                 uint32_t compressed_length = 0;
279                 if (r->ts) {
280                         {
281                                 struct ndr_push *_ndr_ts;
282                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
283                                 {
284                                         struct ndr_push *_ndr_ts_compressed;
285                                         NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
286                                         NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr1TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
287                                         decompressed_length = _ndr_ts_compressed->offset;
288                                         NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
289                                 }
290                                 compressed_length = _ndr_ts->offset;
291                                 talloc_free(_ndr_ts);
292                         }
293                 }
294                 NDR_CHECK(ndr_push_align(ndr, 4));
295                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, decompressed_length));
296                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, compressed_length));
297                 NDR_CHECK(ndr_push_unique_ptr(ndr, r->ts));
298         }
299         if (ndr_flags & NDR_BUFFERS) {
300                 if (r->ts) {
301                         {
302                                 struct ndr_push *_ndr_ts;
303                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
304                                 {
305                                         struct ndr_push *_ndr_ts_compressed;
306                                         NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
307                                         NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr1TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
308                                         NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
309                                 }
310                                 NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_ts, 4, -1));
311                         }
312                 }
313         }
314         return NDR_ERR_SUCCESS;
315 }
316
317 enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesXPRESSCtr6(struct ndr_push *ndr, int ndr_flags, const struct drsuapi_DsGetNCChangesXPRESSCtr6 *r)
318 {
319         if (ndr_flags & NDR_SCALARS) {
320                 uint32_t decompressed_length = 0;
321                 uint32_t compressed_length = 0;
322                 if (r->ts) {
323                         {
324                                 struct ndr_push *_ndr_ts;
325                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
326                                 {
327                                         struct ndr_push *_ndr_ts_compressed;
328                                         NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
329                                         NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr6TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
330                                         decompressed_length = _ndr_ts_compressed->offset;
331                                         NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
332                                 }
333                                 compressed_length = _ndr_ts->offset;
334                                 talloc_free(_ndr_ts);
335                         }
336                 }
337                 NDR_CHECK(ndr_push_align(ndr, 4));
338                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, decompressed_length));
339                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, compressed_length));
340                 NDR_CHECK(ndr_push_unique_ptr(ndr, r->ts));
341         }
342         if (ndr_flags & NDR_BUFFERS) {
343                 if (r->ts) {
344                         {
345                                 struct ndr_push *_ndr_ts;
346                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
347                                 {
348                                         struct ndr_push *_ndr_ts_compressed;
349                                         NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
350                                         NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr6TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
351                                         NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
352                                 }
353                                 NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_ts, 4, -1));
354                         }
355                 }
356         }
357         return NDR_ERR_SUCCESS;
358 }