lib/util Split data_blob_hex_string() into upper and lower
[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 /* 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 #define _OID_PUSH_CHECK(call) do { \
70         bool _status; \
71         _status = call; \
72         if (_status != true) { \
73                 return ndr_push_error(ndr, NDR_ERR_SUBCONTEXT, "OID Conversion Error: %s\n", __location__); \
74         } \
75 } while (0)
76
77 #define _OID_PULL_CHECK(call) do { \
78         bool _status; \
79         _status = call; \
80         if (_status != true) { \
81                 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "OID Conversion Error: %s\n", __location__); \
82         } \
83 } while (0)
84
85 _PUBLIC_ void ndr_print_drsuapi_DsReplicaOID(struct ndr_print *ndr, const char *name, const struct drsuapi_DsReplicaOID *r)
86 {
87         ndr_print_struct(ndr, name, "drsuapi_DsReplicaOID");
88         ndr->depth++;
89         ndr_print_uint32(ndr, "length", r->length);
90         ndr->print(ndr, "%-25s: length=%u", "oid", r->length);
91         if (r->binary_oid) {
92                 char *partial_oid = NULL;
93                 DATA_BLOB oid_blob = data_blob_const(r->binary_oid, r->length);
94                 char *hex_str = data_blob_hex_string_upper(ndr, &oid_blob);
95                 ber_read_partial_OID_String(ndr, oid_blob, (const char **)&partial_oid);
96                 ndr->depth++;
97                 ndr->print(ndr, "%-25s: 0x%s (%s)", "binary_oid", hex_str, partial_oid);
98                 ndr->depth--;
99                 talloc_free(hex_str);
100                 talloc_free(partial_oid);
101         }
102         ndr->depth--;
103 }
104
105 enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesMSZIPCtr1(struct ndr_push *ndr, int ndr_flags, const struct drsuapi_DsGetNCChangesMSZIPCtr1 *r)
106 {
107         if (ndr_flags & NDR_SCALARS) {
108                 uint32_t decompressed_length = 0;
109                 uint32_t compressed_length = 0;
110                 if (r->ts) {
111                         {
112                                 struct ndr_push *_ndr_ts;
113                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
114                                 {
115                                         struct ndr_push *_ndr_ts_compressed;
116                                         NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
117                                         NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr1TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
118                                         decompressed_length = _ndr_ts_compressed->offset;
119                                         NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
120                                 }
121                                 compressed_length = _ndr_ts->offset;
122                                 talloc_free(_ndr_ts);
123                         }
124                 }
125                 NDR_CHECK(ndr_push_align(ndr, 4));
126                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, decompressed_length));
127                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, compressed_length));
128                 NDR_CHECK(ndr_push_unique_ptr(ndr, r->ts));
129         }
130         if (ndr_flags & NDR_BUFFERS) {
131                 if (r->ts) {
132                         {
133                                 struct ndr_push *_ndr_ts;
134                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
135                                 {
136                                         struct ndr_push *_ndr_ts_compressed;
137                                         NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
138                                         NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr1TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
139                                         NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
140                                 }
141                                 NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_ts, 4, -1));
142                         }
143                 }
144         }
145         return NDR_ERR_SUCCESS;
146 }
147
148 enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesMSZIPCtr6(struct ndr_push *ndr, int ndr_flags, const struct drsuapi_DsGetNCChangesMSZIPCtr6 *r)
149 {
150         if (ndr_flags & NDR_SCALARS) {
151                 uint32_t decompressed_length = 0;
152                 uint32_t compressed_length = 0;
153                 if (r->ts) {
154                         {
155                                 struct ndr_push *_ndr_ts;
156                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
157                                 {
158                                         struct ndr_push *_ndr_ts_compressed;
159                                         NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
160                                         NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr6TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
161                                         decompressed_length = _ndr_ts_compressed->offset;
162                                         NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
163                                 }
164                                 compressed_length = _ndr_ts->offset;
165                                 talloc_free(_ndr_ts);
166                         }
167                 }
168                 NDR_CHECK(ndr_push_align(ndr, 4));
169                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, decompressed_length));
170                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, compressed_length));
171                 NDR_CHECK(ndr_push_unique_ptr(ndr, r->ts));
172         }
173         if (ndr_flags & NDR_BUFFERS) {
174                 if (r->ts) {
175                         {
176                                 struct ndr_push *_ndr_ts;
177                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
178                                 {
179                                         struct ndr_push *_ndr_ts_compressed;
180                                         NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
181                                         NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr6TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
182                                         NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_MSZIP, -1));
183                                 }
184                                 NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_ts, 4, -1));
185                         }
186                 }
187         }
188         return NDR_ERR_SUCCESS;
189 }
190
191 enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesXPRESSCtr1(struct ndr_push *ndr, int ndr_flags, const struct drsuapi_DsGetNCChangesXPRESSCtr1 *r)
192 {
193         if (ndr_flags & NDR_SCALARS) {
194                 uint32_t decompressed_length = 0;
195                 uint32_t compressed_length = 0;
196                 if (r->ts) {
197                         {
198                                 struct ndr_push *_ndr_ts;
199                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
200                                 {
201                                         struct ndr_push *_ndr_ts_compressed;
202                                         NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
203                                         NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr1TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
204                                         decompressed_length = _ndr_ts_compressed->offset;
205                                         NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
206                                 }
207                                 compressed_length = _ndr_ts->offset;
208                                 talloc_free(_ndr_ts);
209                         }
210                 }
211                 NDR_CHECK(ndr_push_align(ndr, 4));
212                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, decompressed_length));
213                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, compressed_length));
214                 NDR_CHECK(ndr_push_unique_ptr(ndr, r->ts));
215         }
216         if (ndr_flags & NDR_BUFFERS) {
217                 if (r->ts) {
218                         {
219                                 struct ndr_push *_ndr_ts;
220                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
221                                 {
222                                         struct ndr_push *_ndr_ts_compressed;
223                                         NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
224                                         NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr1TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
225                                         NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
226                                 }
227                                 NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_ts, 4, -1));
228                         }
229                 }
230         }
231         return NDR_ERR_SUCCESS;
232 }
233
234 enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesXPRESSCtr6(struct ndr_push *ndr, int ndr_flags, const struct drsuapi_DsGetNCChangesXPRESSCtr6 *r)
235 {
236         if (ndr_flags & NDR_SCALARS) {
237                 uint32_t decompressed_length = 0;
238                 uint32_t compressed_length = 0;
239                 if (r->ts) {
240                         {
241                                 struct ndr_push *_ndr_ts;
242                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
243                                 {
244                                         struct ndr_push *_ndr_ts_compressed;
245                                         NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
246                                         NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr6TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
247                                         decompressed_length = _ndr_ts_compressed->offset;
248                                         NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
249                                 }
250                                 compressed_length = _ndr_ts->offset;
251                                 talloc_free(_ndr_ts);
252                         }
253                 }
254                 NDR_CHECK(ndr_push_align(ndr, 4));
255                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, decompressed_length));
256                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, compressed_length));
257                 NDR_CHECK(ndr_push_unique_ptr(ndr, r->ts));
258         }
259         if (ndr_flags & NDR_BUFFERS) {
260                 if (r->ts) {
261                         {
262                                 struct ndr_push *_ndr_ts;
263                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_ts, 4, -1));
264                                 {
265                                         struct ndr_push *_ndr_ts_compressed;
266                                         NDR_CHECK(ndr_push_compression_start(_ndr_ts, &_ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
267                                         NDR_CHECK(ndr_push_drsuapi_DsGetNCChangesCtr6TS(_ndr_ts_compressed, NDR_SCALARS|NDR_BUFFERS, r->ts));
268                                         NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed, NDR_COMPRESSION_XPRESS, -1));
269                                 }
270                                 NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_ts, 4, -1));
271                         }
272                 }
273         }
274         return NDR_ERR_SUCCESS;
275 }