Use local includes rather than installed ones for libexchange2ical
[jelmer/openchange.git] / ndr_mapi.c
1 /* 
2    OpenChange implementation.
3
4    libndr mapi support
5
6    Copyright (C) Julien Kerihuel 2005-2009
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 #include <libmapi/libmapi.h>
23 #include <ndr.h>
24 #include <gen_ndr/ndr_exchange.h>
25
26
27 static void obfuscate_data(uint8_t *data, uint32_t size, uint8_t salt)
28 {
29         uint32_t i;
30
31         for (i=0; i<size; i++) {
32                 data[i] ^= salt;
33         }
34 }
35
36 ssize_t lzxpress_decompress(const uint8_t *input,
37                             uint32_t input_size,
38                             uint8_t *output,
39                             uint32_t max_output_size);
40
41 static enum ndr_err_code ndr_pull_lxpress_chunk(struct ndr_pull *ndrpull,
42                                                 struct ndr_push *ndrpush,
43                                                 ssize_t decompressed_len)
44 {
45         DATA_BLOB       comp_chunk;
46         DATA_BLOB       plain_chunk;
47         int             ret;
48
49         /* Step 1. Retrieve the compressed buf */
50         comp_chunk.length = ndrpull->data_size;
51         comp_chunk.data = ndrpull->data;
52
53         plain_chunk.length = decompressed_len;
54         plain_chunk.data = ndrpush->data;
55
56         ret = lzxpress_decompress(comp_chunk.data,
57                                   comp_chunk.length,
58                                   plain_chunk.data,
59                                   plain_chunk.length);
60         if (ret < 0) {
61                 return ndr_pull_error(ndrpull, NDR_ERR_COMPRESSION,
62                                       "XPRESS lzxpress_decompress() returned %d\n",
63                                       (int)ret);
64         }
65         plain_chunk.length = ret;
66         ndrpush->offset = ret;
67
68         return NDR_ERR_SUCCESS;
69 }
70
71 static enum ndr_err_code ndr_pull_lzxpress_decompress(struct ndr_pull *subndr,
72                                                       struct ndr_pull **_comndr,
73                                                       ssize_t decompressed_len)
74 {
75         struct ndr_push *ndrpush;
76         struct ndr_pull *comndr;
77         DATA_BLOB uncompressed;
78
79         ndrpush = ndr_push_init_ctx(subndr, subndr->iconv_convenience);
80         NDR_ERR_HAVE_NO_MEMORY(ndrpush);
81
82         NDR_CHECK(ndr_pull_lxpress_chunk(subndr, ndrpush, decompressed_len));
83
84         uncompressed = ndr_push_blob(ndrpush);
85         if (uncompressed.length != decompressed_len) {
86                 return ndr_pull_error(subndr, NDR_ERR_COMPRESSION,
87                                       "Bad uncompressed_len [%u] != [%u](0x%08X) (PULL)",
88                                       (int)uncompressed.length,
89                                       (int)decompressed_len,
90                                       (int)decompressed_len);
91         }
92
93         comndr = talloc_zero(subndr, struct ndr_pull);
94         NDR_ERR_HAVE_NO_MEMORY(comndr);
95         comndr->flags = subndr->flags;
96         comndr->current_mem_ctx = subndr->current_mem_ctx;
97         comndr->data = uncompressed.data;
98         comndr->data_size = uncompressed.length;
99         comndr->offset = 0;
100
101         comndr->iconv_convenience = talloc_reference(comndr, subndr->iconv_convenience);
102         *_comndr = comndr;
103         return NDR_ERR_SUCCESS;
104 }
105
106
107 _PUBLIC_ enum ndr_err_code ndr_pull_mapi2k7_request(struct ndr_pull *ndr, int ndr_flags, struct mapi2k7_request *r)
108 {
109         if (ndr_flags & NDR_SCALARS) {
110                 NDR_CHECK(ndr_pull_align(ndr, 4));
111                 NDR_CHECK(ndr_pull_RPC_HEADER_EXT(ndr, NDR_SCALARS, &r->header));
112                 {
113                         uint32_t _flags_save_mapi_request = ndr->flags;
114                         ndr_set_flags(&ndr->flags, LIBNDR_FLAG_REMAINING|LIBNDR_FLAG_NOALIGN);
115                         {
116                                 struct ndr_pull *_ndr_buffer;
117
118                                 if (ndr->flags & LIBNDR_FLAG_REF_ALLOC) {
119                                         NDR_PULL_ALLOC(ndr, r->mapi_request);
120                                 }
121
122                                 NDR_CHECK(ndr_pull_subcontext_start(ndr, &_ndr_buffer, 0, -1));
123                                 {
124                                         if (r->header.Flags & RHEF_Compressed) {
125                                                 struct ndr_pull *_ndr_data_compressed = NULL;
126
127                                                 NDR_CHECK(ndr_pull_lzxpress_decompress(_ndr_buffer, &_ndr_data_compressed, r->header.SizeActual));
128                                                 NDR_CHECK(ndr_pull_mapi_request(_ndr_data_compressed, NDR_SCALARS|NDR_BUFFERS, r->mapi_request));
129                                         } else if (r->header.Flags & RHEF_XorMagic) {
130                                                 obfuscate_data(_ndr_buffer->data, _ndr_buffer->data_size, 0xA5);
131                                                 NDR_CHECK(ndr_pull_mapi_request(_ndr_buffer, NDR_SCALARS|NDR_BUFFERS, r->mapi_request));
132                                         }
133                                 }
134                                 NDR_CHECK(ndr_pull_subcontext_end(ndr, _ndr_buffer, 0, -1));
135                         }
136                         ndr->flags = _flags_save_mapi_request;
137                 }
138         }
139
140         return NDR_ERR_SUCCESS;
141 }
142
143
144 _PUBLIC_ enum ndr_err_code ndr_pull_mapi2k7_response(struct ndr_pull *ndr, int ndr_flags, struct mapi2k7_response *r)
145 {
146         if (ndr_flags & NDR_SCALARS) {
147                 NDR_CHECK(ndr_pull_RPC_HEADER_EXT(ndr, NDR_SCALARS, &r->header));
148                 {
149                         uint32_t _flags_save_mapi_response = ndr->flags;
150                         ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN|LIBNDR_FLAG_REMAINING);
151                         {
152                                 struct ndr_pull *_ndr_buffer;
153                                 
154                                 if (ndr->flags & LIBNDR_FLAG_REF_ALLOC) {
155                                         NDR_PULL_ALLOC(ndr, r->mapi_response);
156                                 }
157                                 
158                                 NDR_CHECK((ndr_pull_subcontext_start(ndr, &_ndr_buffer, 0, -1)));
159                                 {
160                                         if (r->header.Flags & RHEF_Compressed) {
161                                                 struct ndr_pull *_ndr_data_compressed = NULL;
162                                                 
163                                                 NDR_CHECK(ndr_pull_lzxpress_decompress(_ndr_buffer, &_ndr_data_compressed, r->header.SizeActual));
164                                                 NDR_CHECK(ndr_pull_mapi_response(_ndr_data_compressed, NDR_SCALARS|NDR_BUFFERS, r->mapi_response));
165                                         } else if (r->header.Flags & RHEF_XorMagic) {
166                                                 obfuscate_data(_ndr_buffer->data, _ndr_buffer->data_size, 0xA5);
167                                                 NDR_CHECK(ndr_pull_mapi_response(_ndr_buffer, NDR_SCALARS|NDR_BUFFERS, r->mapi_response));
168                                         }
169                                 }
170                                 NDR_CHECK(ndr_pull_subcontext_end(ndr, _ndr_buffer, 0, -1));
171                         }
172                         ndr->flags = _flags_save_mapi_response;
173                 }
174         }
175
176         return NDR_ERR_SUCCESS;
177 }
178
179
180 _PUBLIC_ void ndr_print_AUX_HEADER(struct ndr_print *ndr, const char *name, const struct AUX_HEADER *r)
181 {
182         ndr_print_struct(ndr, name, "AUX_HEADER");
183         {
184                 uint32_t _flags_save_STRUCT = ndr->flags;
185                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
186                 ndr->depth++;
187                 ndr_print_uint16(ndr, "Size", r->Size);
188                 ndr_print_AUX_VERSION(ndr, "Version", r->Version);
189
190                 switch (r->Version) {
191                 case AUX_VERSION_1:
192                         ndr_print_AUX_HEADER_TYPE_1(ndr, "Type", (enum AUX_HEADER_TYPE_1) r->Type);
193                         ndr_print_set_switch_value(ndr, &r->Payload_1, r->Type);
194                         ndr_print_AUX_HEADER_TYPE_UNION_1(ndr, "Payload", &r->Payload_1);
195                         break;
196                 case AUX_VERSION_2:
197                         ndr_print_AUX_HEADER_TYPE_2(ndr, "Type", (enum AUX_HEADER_TYPE_2) r->Type);
198                         ndr_print_set_switch_value(ndr, &r->Payload_2, r->Type);
199                         ndr_print_AUX_HEADER_TYPE_UNION_2(ndr, "Payload", &r->Payload_2);
200                 }
201                 ndr->depth--;
202                 ndr->flags = _flags_save_STRUCT;
203         }
204 }
205
206
207 _PUBLIC_ enum ndr_err_code ndr_pull_AUX_HEADER(struct ndr_pull *ndr, int ndr_flags, struct AUX_HEADER *r)
208 {
209         {
210                 uint32_t _flags_save_STRUCT = ndr->flags;
211                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
212                 if (ndr_flags & NDR_SCALARS) {
213                         NDR_CHECK(ndr_pull_align(ndr, 4));
214                         NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &r->Size));
215                         NDR_CHECK(ndr_pull_AUX_VERSION(ndr, NDR_SCALARS, &r->Version));
216                         NDR_CHECK(ndr_pull_uint8(ndr, NDR_SCALARS, &r->Type));
217                         switch (r->Version) {
218                         case AUX_VERSION_1:
219                                 NDR_CHECK(ndr_pull_set_switch_value(ndr, &r->Payload_1, r->Type));
220                                 NDR_CHECK(ndr_pull_AUX_HEADER_TYPE_UNION_1(ndr, NDR_SCALARS, &r->Payload_1));
221                                 break;
222                         case AUX_VERSION_2:
223                                 NDR_CHECK(ndr_pull_set_switch_value(ndr, &r->Payload_2, r->Type));
224                                 NDR_CHECK(ndr_pull_AUX_HEADER_TYPE_UNION_2(ndr, NDR_SCALARS, &r->Payload_2));
225                                 break;
226                         }
227                 }
228                 if (ndr_flags & NDR_BUFFERS) {
229                 }
230                 ndr->flags = _flags_save_STRUCT;
231         }
232         return NDR_ERR_SUCCESS;
233 }
234
235
236 _PUBLIC_ void ndr_print_mapi2k7_AuxInfo(struct ndr_print *ndr, const char *name, const struct mapi2k7_AuxInfo *r)
237 {
238         uint32_t        i;
239
240         if (r && r->AUX_HEADER) {
241                 ndr_print_struct(ndr, name, "mapi2k7_AuxInfo");
242                 ndr->depth++;
243                 ndr_print_RPC_HEADER_EXT(ndr, "RPC_HEADER_EXT", &r->RPC_HEADER_EXT);
244                 for (i = 0; r->AUX_HEADER[i].Size; i++) {
245                         ndr_print_AUX_HEADER(ndr, "AUX_HEADER", &r->AUX_HEADER[i]);
246                 }
247                 ndr->depth--;
248         } else {
249                 ndr_print_pointer(ndr, "mapi2k7_AuxInfo", NULL);
250         }
251 }
252
253
254 _PUBLIC_ enum ndr_err_code ndr_pull_mapi2k7_AuxInfo(struct ndr_pull *ndr, int ndr_flags, struct mapi2k7_AuxInfo *r)
255 {
256         if (ndr_flags & NDR_SCALARS) {
257
258                 /* Sanity Checks */
259                 if (!ndr->data_size) {
260                         r->AUX_HEADER = NULL;
261                         return NDR_ERR_SUCCESS;
262                 }
263
264                 NDR_CHECK(ndr_pull_align(ndr, 4));
265                 NDR_CHECK(ndr_pull_RPC_HEADER_EXT(ndr, NDR_SCALARS, &r->RPC_HEADER_EXT));
266                 {
267                         uint32_t _flags_save_DATA_BLOB = ndr->flags;
268                         ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN|LIBNDR_FLAG_REMAINING);
269                         if (r->RPC_HEADER_EXT.Size) {
270                                 struct ndr_pull *_ndr_buffer;
271                                 TALLOC_CTX      *_mem_save_AUX_HEADER_0;
272                                 uint32_t        cntr_AUX_HEADER_0 = 0;
273
274                                 _mem_save_AUX_HEADER_0 = NDR_PULL_GET_MEM_CTX(ndr);
275
276                                 NDR_CHECK(ndr_pull_subcontext_start(ndr, &_ndr_buffer, 0, r->RPC_HEADER_EXT.Size));
277                                 {
278                                         r->AUX_HEADER = talloc_array(_mem_save_AUX_HEADER_0, struct AUX_HEADER, 2);
279
280                                         if (r->RPC_HEADER_EXT.Flags & RHEF_Compressed) {
281                                                 struct ndr_pull *_ndr_data_compressed = NULL;
282
283                                                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
284                                                 NDR_CHECK(ndr_pull_lzxpress_decompress(_ndr_buffer, &_ndr_data_compressed, r->RPC_HEADER_EXT.SizeActual));
285                                                 
286                                                 for (cntr_AUX_HEADER_0 = 0; _ndr_data_compressed->offset < _ndr_data_compressed->data_size; cntr_AUX_HEADER_0++) {
287                                                         NDR_CHECK(ndr_pull_AUX_HEADER(_ndr_data_compressed, NDR_SCALARS, &r->AUX_HEADER[cntr_AUX_HEADER_0]));
288                                                         r->AUX_HEADER = talloc_realloc(_mem_save_AUX_HEADER_0, r->AUX_HEADER, struct AUX_HEADER, cntr_AUX_HEADER_0 + 2);
289                                                 }
290                                                 r->AUX_HEADER = talloc_realloc(_mem_save_AUX_HEADER_0, r->AUX_HEADER, struct AUX_HEADER, cntr_AUX_HEADER_0 + 2);
291                                                 r->AUX_HEADER[cntr_AUX_HEADER_0].Size = 0;
292                                                 
293                                         } else if (r->RPC_HEADER_EXT.Flags & RHEF_XorMagic) {
294                                                 obfuscate_data(_ndr_buffer->data, _ndr_buffer->data_size, 0xA5);
295
296                                                 for (cntr_AUX_HEADER_0 = 0; _ndr_buffer->offset < _ndr_buffer->data_size; cntr_AUX_HEADER_0++) {
297                                                         NDR_CHECK(ndr_pull_AUX_HEADER(_ndr_buffer, NDR_SCALARS, &r->AUX_HEADER[cntr_AUX_HEADER_0]));
298                                                         r->AUX_HEADER = talloc_realloc(_mem_save_AUX_HEADER_0, r->AUX_HEADER, struct AUX_HEADER, cntr_AUX_HEADER_0 + 2);
299                                                 }
300                                                 r->AUX_HEADER = talloc_realloc(_mem_save_AUX_HEADER_0, r->AUX_HEADER, struct AUX_HEADER, cntr_AUX_HEADER_0 + 2);
301                                                 r->AUX_HEADER[cntr_AUX_HEADER_0].Size = 0;
302                                         }
303                                 }
304                                 NDR_CHECK(ndr_pull_subcontext_end(ndr, _ndr_buffer, 0, -1));
305                         } 
306                         ndr->flags = _flags_save_DATA_BLOB;
307                 }
308         }
309         if (ndr_flags & NDR_BUFFERS) {
310         }
311         return NDR_ERR_SUCCESS;
312 }
313
314 /*
315   print mapi_request / mapi_response structures
316  */
317
318 void ndr_print_mapi_request(struct ndr_print *ndr, const char *name, const struct mapi_request *r)
319 {
320         uint32_t        rlength;
321
322         rlength = r->mapi_len - r->length;
323
324         ndr_print_uint32(ndr, "mapi_len", r->mapi_len);
325         if (r->length && r->length > sizeof(uint16_t)) {
326                 uint32_t cntr_mapi_req_0;
327
328                 ndr_print_uint16(ndr, "length", r->length);
329                 ndr->depth++;
330                 for (cntr_mapi_req_0=0; r->mapi_req[cntr_mapi_req_0].opnum; cntr_mapi_req_0++) {
331                         char    *idx_0 = NULL;
332                         int     ret;
333
334                         ret = asprintf(&idx_0, "[%u]", cntr_mapi_req_0);
335                         if (ret != -1 && idx_0) {
336                                 ndr_print_EcDoRpc_MAPI_REQ(ndr, "mapi_request", &r->mapi_req[cntr_mapi_req_0]);
337                                 free(idx_0);
338                         } 
339                 }
340                 ndr->depth--;
341         }
342
343         if (rlength) {
344                 uint32_t i;
345
346                 ndr->depth++;
347                 ndr->print(ndr, "%-25s: (handles) number=%u", name, rlength / 4);
348                 ndr->depth++;
349                 for (i = 0; i < (rlength / 4); i++) {
350                         ndr_print_uint32(ndr, "handle", r->handles[i]);
351                 }
352                 ndr->depth--;
353         }
354 }
355
356 void ndr_print_mapi_response(struct ndr_print *ndr, const char *name, const struct mapi_response *r)
357 {
358         uint32_t        rlength;
359
360         rlength = r->mapi_len - r->length;
361
362         ndr->print(ndr, "%-25s: length=%u", name, r->length);
363         if (r->length && r->length > sizeof(uint16_t)) {
364                 uint32_t cntr_mapi_repl_0;
365
366                 ndr->print(ndr, "%s: ARRAY(%d)", name, r->length - 2);
367                 ndr->depth++;
368                 for (cntr_mapi_repl_0=0; r->mapi_repl[cntr_mapi_repl_0].opnum; cntr_mapi_repl_0++) {
369                         ndr_print_EcDoRpc_MAPI_REPL(ndr, "mapi_repl", &r->mapi_repl[cntr_mapi_repl_0]);
370                 }
371                 ndr->depth--;
372         }
373
374         ndr->print(ndr, "%-25s: (handles) number=%u", name, rlength / 4);
375         
376         if (rlength) {
377                 uint32_t i;
378
379                 ndr->depth++;
380
381                 for (i = 0; i < (rlength / 4); i++) {
382                         ndr_print_uint32(ndr, "handle id", r->handles[i]);
383                 }
384                 ndr->depth--;
385         }
386 }
387
388
389 /*
390   push mapi_request / mapi_response onto the wire.  
391
392   MAPI length field includes length bytes. 
393   But these bytes do not belong to the mapi content in the user
394   context. We have to add them when pushing mapi content length
395   (uint16_t) and next subtract when pushing the content blob
396 */
397
398 enum ndr_err_code ndr_push_mapi_request(struct ndr_push *ndr, int ndr_flags, const struct mapi_request *r)
399 {
400         uint32_t                cntr_mapi_req_0;
401         uint32_t                count;
402
403         ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
404         NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, r->length));
405
406         for (count = 0; ndr->offset < r->length - 2; count++) {
407                 NDR_CHECK(ndr_push_EcDoRpc_MAPI_REQ(ndr, NDR_SCALARS, &r->mapi_req[count]));
408         }
409
410         count = (r->mapi_len - r->length) / sizeof(uint32_t);
411         for (cntr_mapi_req_0=0; cntr_mapi_req_0 < count; cntr_mapi_req_0++) {
412                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->handles[cntr_mapi_req_0]));
413         }
414
415         return NDR_ERR_SUCCESS;
416 }
417
418 enum ndr_err_code ndr_push_mapi_response(struct ndr_push *ndr, int ndr_flags, const struct mapi_response *r)
419 {
420         uint32_t        cntr_mapi_repl_0;
421         uint32_t        count;
422
423         ndr_set_flags(&ndr->flags, LIBNDR_FLAG_REMAINING);
424         NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, r->length));
425
426         if (r->length > sizeof (uint16_t)) {
427                 for (count = 0; ndr->offset < r->length - 2; count++) {
428                         NDR_CHECK(ndr_push_EcDoRpc_MAPI_REPL(ndr, NDR_SCALARS, &r->mapi_repl[count]));
429                 }
430         }
431
432         count = (r->mapi_len - r->length) / sizeof (uint32_t);
433         for (cntr_mapi_repl_0 = 0; cntr_mapi_repl_0 <count; cntr_mapi_repl_0++) {
434                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->handles[cntr_mapi_repl_0]));
435         }
436
437         return NDR_ERR_SUCCESS;
438 }
439
440 /*
441   pull mapi_request / mapi_response from the wire
442 */
443
444 enum ndr_err_code ndr_pull_mapi_request(struct ndr_pull *ndr, int ndr_flags, struct mapi_request *r)
445 {
446         uint32_t length,count;
447         uint32_t cntr_mapi_req_0;
448         TALLOC_CTX *_mem_save_mapi_req_0;
449         TALLOC_CTX *_mem_save_handles_0;
450         struct ndr_pull *_ndr_mapi_req;
451
452         if (ndr->flags & LIBNDR_FLAG_REMAINING) {
453                 length = ndr->data_size - ndr->offset;
454         } else {
455                 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &length));
456         }
457         r->mapi_len = length;
458
459         NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &r->length));
460
461         /* If length equals length field then skipping subcontext */
462         if (r->length > sizeof (uint16_t)) {
463                 NDR_CHECK(ndr_pull_subcontext_start(ndr, &_ndr_mapi_req, 0, r->length - 2));
464                 _mem_save_mapi_req_0 = NDR_PULL_GET_MEM_CTX(_ndr_mapi_req);
465                 r->mapi_req = talloc_zero(_mem_save_mapi_req_0, struct EcDoRpc_MAPI_REQ);
466                 for (cntr_mapi_req_0 = 0; _ndr_mapi_req->offset < _ndr_mapi_req->data_size - 2; cntr_mapi_req_0++) {
467                         NDR_CHECK(ndr_pull_EcDoRpc_MAPI_REQ(_ndr_mapi_req, NDR_SCALARS, &r->mapi_req[cntr_mapi_req_0]));
468                         r->mapi_req = talloc_realloc(_mem_save_mapi_req_0, r->mapi_req, struct EcDoRpc_MAPI_REQ, cntr_mapi_req_0 + 2);
469                 }
470                 r->mapi_req = talloc_realloc(_mem_save_mapi_req_0, r->mapi_req, struct EcDoRpc_MAPI_REQ, cntr_mapi_req_0 + 2);
471                 r->mapi_req[cntr_mapi_req_0].opnum = 0;
472                 
473                 if (_ndr_mapi_req->offset != r->length - 2) {
474                         return NDR_ERR_BUFSIZE;
475                 }
476                 NDR_CHECK(ndr_pull_subcontext_end(ndr, _ndr_mapi_req, 4, -1));
477         
478                 _mem_save_handles_0 = NDR_PULL_GET_MEM_CTX(ndr);
479                 count = (r->mapi_len - r->length) / sizeof(uint32_t);
480                 r->handles = talloc_array(_mem_save_handles_0, uint32_t, count + 1);
481                 for (cntr_mapi_req_0=0; cntr_mapi_req_0 < count; cntr_mapi_req_0++) {
482                         NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->handles[cntr_mapi_req_0]));
483                 }
484         } else {
485                 r->handles = NULL;
486         }
487
488         return NDR_ERR_SUCCESS;
489 }
490
491 enum ndr_err_code ndr_pull_mapi_response(struct ndr_pull *ndr, int ndr_flags, struct mapi_response *r)
492 {
493         uint32_t length,count;
494         uint32_t cntr_mapi_repl_0;
495         TALLOC_CTX *_mem_save_mapi_repl_0;
496         TALLOC_CTX *_mem_save_handles_0;
497         struct ndr_pull *_ndr_mapi_repl;
498
499         if (ndr->flags & LIBNDR_FLAG_REMAINING) {
500                 length = ndr->data_size - ndr->offset;
501         } else {
502                 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &length));
503         }
504         r->mapi_len = length;
505
506         NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &r->length));
507         
508         /* If length equals length field then skipping subcontext */
509         if (r->length > sizeof (uint16_t)) {
510                 _mem_save_mapi_repl_0 = NDR_PULL_GET_MEM_CTX(ndr);
511                 r->mapi_repl = talloc_array(_mem_save_mapi_repl_0, struct EcDoRpc_MAPI_REPL, 2);
512                 NDR_CHECK(ndr_pull_subcontext_start(ndr, &_ndr_mapi_repl, 0, r->length - 2));
513                 for (cntr_mapi_repl_0 = 0; _ndr_mapi_repl->offset < _ndr_mapi_repl->data_size - 2; cntr_mapi_repl_0++) {
514                         NDR_CHECK(ndr_pull_EcDoRpc_MAPI_REPL(_ndr_mapi_repl, NDR_SCALARS, &r->mapi_repl[cntr_mapi_repl_0]));
515                         r->mapi_repl = talloc_realloc(_ndr_mapi_repl, r->mapi_repl, struct EcDoRpc_MAPI_REPL, cntr_mapi_repl_0 + 2);
516                 }
517                 r->mapi_repl[cntr_mapi_repl_0].opnum = 0;
518                 NDR_CHECK(ndr_pull_subcontext_end(ndr, _ndr_mapi_repl, 4, -1));
519                 talloc_free(_ndr_mapi_repl);
520         }
521
522         _mem_save_handles_0 = NDR_PULL_GET_MEM_CTX(ndr);
523         count = (r->mapi_len - r->length) / sizeof(uint32_t);
524         NDR_PULL_ALLOC_N(ndr, r->handles, count + 1);
525
526         for (cntr_mapi_repl_0=0; cntr_mapi_repl_0 < count; cntr_mapi_repl_0++) {
527                 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->handles[cntr_mapi_repl_0]));
528         }
529         NDR_PULL_SET_MEM_CTX(ndr, _mem_save_handles_0, LIBNDR_FLAG_REF_ALLOC);
530
531         return NDR_ERR_SUCCESS;
532 }
533
534 /*
535   We stop processing the IDL if MAPISTATUS is different from MAPI_E_SUCCESS
536  */
537
538 _PUBLIC_ enum ndr_err_code ndr_push_EcDoRpc_MAPI_REPL(struct ndr_push *ndr, int ndr_flags, const struct EcDoRpc_MAPI_REPL *r)
539 {
540         if (r->opnum != op_MAPI_Release)
541         {
542                 uint32_t _flags_save_STRUCT = ndr->flags;
543                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
544                 if (ndr_flags & NDR_SCALARS) {
545                         NDR_CHECK(ndr_push_align(ndr, 8));
546                         NDR_CHECK(ndr_push_uint8(ndr, NDR_SCALARS, r->opnum));
547                         if ((r->opnum == op_MAPI_Notify) || (r->opnum == op_MAPI_Pending)) {
548                                 NDR_CHECK(ndr_push_set_switch_value(ndr, &r->u, r->opnum));
549                                 NDR_CHECK(ndr_push_EcDoRpc_MAPI_REPL_UNION(ndr, NDR_SCALARS, &r->u));                           
550                         } else {
551                                 NDR_CHECK(ndr_push_uint8(ndr, NDR_SCALARS, r->handle_idx));
552                                 NDR_CHECK(ndr_push_MAPISTATUS(ndr, NDR_SCALARS, r->error_code));
553                                 if (r->error_code == MAPI_E_SUCCESS) {
554                                         NDR_CHECK(ndr_push_set_switch_value(ndr, &r->u, r->opnum));
555                                         NDR_CHECK(ndr_push_EcDoRpc_MAPI_REPL_UNION(ndr, NDR_SCALARS, &r->u));
556                                 } else {
557                                         switch (r->opnum) {
558                                         case op_MAPI_Logon: {
559                                                 if (r->error_code == ecWrongServer) {
560                                                         NDR_CHECK(ndr_push_Logon_redirect(ndr, NDR_SCALARS, &(r->us.mapi_Logon)));
561                                                 }
562                                                 break; }
563                                         default:
564                                                 break;
565                                         }
566                                 }
567                         }
568                 }
569                 if (ndr_flags & NDR_BUFFERS) {
570                         NDR_CHECK(ndr_push_EcDoRpc_MAPI_REPL_UNION(ndr, NDR_BUFFERS, &r->u));
571                 }
572                 ndr->flags = _flags_save_STRUCT;
573         }
574         return NDR_ERR_SUCCESS;
575 }
576
577 enum ndr_err_code ndr_pull_EcDoRpc_MAPI_REPL(struct ndr_pull *ndr, int ndr_flags, struct EcDoRpc_MAPI_REPL *r)
578 {
579         {
580                 uint32_t _flags_save_STRUCT = ndr->flags;
581                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
582                 if (ndr_flags & NDR_SCALARS) {
583                         NDR_CHECK(ndr_pull_align(ndr, 8));
584                         NDR_CHECK(ndr_pull_uint8(ndr, NDR_SCALARS, &r->opnum));
585                         if ((r->opnum == op_MAPI_Notify) || (r->opnum == op_MAPI_Pending)) {
586                                 NDR_CHECK(ndr_pull_set_switch_value(ndr, &r->u, r->opnum));
587                                 NDR_CHECK(ndr_pull_EcDoRpc_MAPI_REPL_UNION(ndr, NDR_SCALARS, &r->u));
588                         } else {
589                                 NDR_CHECK(ndr_pull_uint8(ndr, NDR_SCALARS, &r->handle_idx));
590                                 NDR_CHECK(ndr_pull_MAPISTATUS(ndr, NDR_SCALARS, &r->error_code));
591                                 if ( r->error_code == MAPI_E_SUCCESS) {
592                                         NDR_CHECK(ndr_pull_set_switch_value(ndr, &r->u, r->opnum));
593                                         NDR_CHECK(ndr_pull_EcDoRpc_MAPI_REPL_UNION(ndr, NDR_SCALARS, &r->u));
594                                 } else {
595                                         switch (r->opnum) {
596                                         case op_MAPI_Logon: {
597                                                 if (r->error_code == ecWrongServer) {
598                                                         NDR_CHECK(ndr_pull_Logon_redirect(ndr, NDR_SCALARS, &(r->us.mapi_Logon)));
599                                                 }
600                                                 break;}
601                                         default:
602                                                 break;
603                                         }
604                                 }
605                         }
606                 }
607                 if (ndr_flags & NDR_BUFFERS) {
608                         ndr->flags = _flags_save_STRUCT;
609                 }
610         }
611         return NDR_ERR_SUCCESS;
612 }
613
614 void ndr_print_EcDoRpc_MAPI_REPL(struct ndr_print *ndr, const char *name, const struct EcDoRpc_MAPI_REPL *r)
615 {
616         ndr_print_struct(ndr, name, "EcDoRpc_MAPI_REPL");
617         {
618                 uint32_t _flags_save_STRUCT = ndr->flags;
619                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
620                 ndr->depth++;
621                 ndr_print_uint8(ndr, "opnum", r->opnum);
622                 if ((r->opnum != op_MAPI_Notify) && (r->opnum != op_MAPI_Pending)) {
623                         ndr_print_uint8(ndr, "handle_idx", r->handle_idx);
624                         ndr_print_MAPISTATUS(ndr, "error_code", r->error_code);
625                         if (r->error_code == MAPI_E_SUCCESS) {
626                                 ndr_print_set_switch_value(ndr, &r->u, r->opnum);
627                                 ndr_print_EcDoRpc_MAPI_REPL_UNION(ndr, "u", &r->u);
628                         } else {
629                                 switch (r->opnum) {
630                                 case op_MAPI_Logon: {
631                                         if (r->error_code == ecWrongServer) {
632                                                 ndr_print_set_switch_value(ndr, &r->us, r->opnum);
633                                                 ndr_print_EcDoRpc_MAPI_REPL_UNION_SPECIAL(ndr, "us", &r->us);
634                                         }
635                                         break;}
636                                 default:
637                                         break;
638                                 }
639                         }
640                 } else {
641                         ndr_print_set_switch_value(ndr, &r->u, r->opnum);
642                         ndr_print_EcDoRpc_MAPI_REPL_UNION(ndr, "u", &r->u);
643                 }
644                 ndr->depth--;
645                 ndr->flags = _flags_save_STRUCT;
646         }
647 }
648
649
650 _PUBLIC_ enum ndr_err_code ndr_pull_EcDoRpc(struct ndr_pull *ndr, int flags, struct EcDoRpc *r)
651 {
652         TALLOC_CTX *_mem_save_handle_0;
653         TALLOC_CTX *_mem_save_mapi_request_0;
654         TALLOC_CTX *_mem_save_mapi_response_0;
655         TALLOC_CTX *_mem_save_length_0;
656
657         if (flags & NDR_IN) {
658                 ZERO_STRUCT(r->out);
659
660                 if (ndr->flags & LIBNDR_FLAG_REF_ALLOC) {
661                         NDR_PULL_ALLOC(ndr, r->in.handle);
662                 }
663                 _mem_save_handle_0 = NDR_PULL_GET_MEM_CTX(ndr);
664                 NDR_PULL_SET_MEM_CTX(ndr, r->in.handle, LIBNDR_FLAG_REF_ALLOC);
665                 NDR_CHECK(ndr_pull_policy_handle(ndr, NDR_SCALARS|NDR_BUFFERS, r->in.handle));
666                 NDR_PULL_SET_MEM_CTX(ndr, _mem_save_handle_0, LIBNDR_FLAG_REF_ALLOC);
667                 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->in.size));
668                 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->in.offset));
669                 {
670                         uint32_t _flags_save_mapi_request = ndr->flags;
671                         ndr_set_flags(&ndr->flags, LIBNDR_FLAG_REMAINING|LIBNDR_FLAG_NOALIGN);
672                         if (ndr->flags & LIBNDR_FLAG_REF_ALLOC) {
673                                 NDR_PULL_ALLOC(ndr, r->in.mapi_request);
674                         }
675                         _mem_save_mapi_request_0 = NDR_PULL_GET_MEM_CTX(ndr);
676                         NDR_PULL_SET_MEM_CTX(ndr, r->in.mapi_request, LIBNDR_FLAG_REF_ALLOC);
677                         {
678                                 struct ndr_pull *_ndr_mapi_request;
679                                 NDR_CHECK(ndr_pull_subcontext_start(ndr, &_ndr_mapi_request, 4, -1));
680                                 obfuscate_data(_ndr_mapi_request->data, _ndr_mapi_request->data_size, 0xA5);
681                                 NDR_CHECK(ndr_pull_mapi_request(_ndr_mapi_request, NDR_SCALARS|NDR_BUFFERS, r->in.mapi_request));
682                                 NDR_CHECK(ndr_pull_subcontext_end(ndr, _ndr_mapi_request, 4, -1));
683                         }
684                         NDR_PULL_SET_MEM_CTX(ndr, _mem_save_mapi_request_0, LIBNDR_FLAG_REF_ALLOC);
685                         ndr->flags = _flags_save_mapi_request;
686                 }
687                 if (ndr->flags & LIBNDR_FLAG_REF_ALLOC) {
688                         NDR_PULL_ALLOC(ndr, r->in.length);
689                 }
690                 _mem_save_length_0 = NDR_PULL_GET_MEM_CTX(ndr);
691                 NDR_PULL_SET_MEM_CTX(ndr, r->in.length, LIBNDR_FLAG_REF_ALLOC);
692                 NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, r->in.length));
693                 NDR_PULL_SET_MEM_CTX(ndr, _mem_save_length_0, LIBNDR_FLAG_REF_ALLOC);
694                 NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &r->in.max_data));
695                 NDR_PULL_ALLOC(ndr, r->out.handle);
696                 *r->out.handle = *r->in.handle;
697                 NDR_PULL_ALLOC(ndr, r->out.mapi_response);
698                 ZERO_STRUCTP(r->out.mapi_response);
699                 NDR_PULL_ALLOC(ndr, r->out.length);
700                 *r->out.length = *r->in.length;
701         }
702         if (flags & NDR_OUT) {
703                 if (ndr->flags & LIBNDR_FLAG_REF_ALLOC) {
704                         NDR_PULL_ALLOC(ndr, r->out.handle);
705                 }
706                 _mem_save_handle_0 = NDR_PULL_GET_MEM_CTX(ndr);
707                 NDR_PULL_SET_MEM_CTX(ndr, r->out.handle, LIBNDR_FLAG_REF_ALLOC);
708                 NDR_CHECK(ndr_pull_policy_handle(ndr, NDR_SCALARS|NDR_BUFFERS, r->out.handle));
709                 NDR_PULL_SET_MEM_CTX(ndr, _mem_save_handle_0, LIBNDR_FLAG_REF_ALLOC);
710                 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->out.size));
711                 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->out.offset));
712                 {
713                         uint32_t _flags_save_mapi_response = ndr->flags;
714                         ndr_set_flags(&ndr->flags, LIBNDR_FLAG_REMAINING|LIBNDR_FLAG_NOALIGN);
715                         if (ndr->flags & LIBNDR_FLAG_REF_ALLOC) {
716                                 NDR_PULL_ALLOC(ndr, r->out.mapi_response);
717                         }
718                         _mem_save_mapi_response_0 = NDR_PULL_GET_MEM_CTX(ndr);
719                         NDR_PULL_SET_MEM_CTX(ndr, r->out.mapi_response, LIBNDR_FLAG_REF_ALLOC);
720                         {
721                                 struct ndr_pull *_ndr_mapi_response;
722                                 NDR_CHECK(ndr_pull_subcontext_start(ndr, &_ndr_mapi_response, 4, -1));
723                                 obfuscate_data(_ndr_mapi_response->data, _ndr_mapi_response->data_size, 0xA5);
724                                 NDR_CHECK(ndr_pull_mapi_response(_ndr_mapi_response, NDR_SCALARS|NDR_BUFFERS, r->out.mapi_response));
725                                 NDR_CHECK(ndr_pull_subcontext_end(ndr, _ndr_mapi_response, 4, -1));
726                         }
727                         NDR_PULL_SET_MEM_CTX(ndr, _mem_save_mapi_response_0, LIBNDR_FLAG_REF_ALLOC);
728                         ndr->flags = _flags_save_mapi_response;
729                 }
730                 if (ndr->flags & LIBNDR_FLAG_REF_ALLOC) {
731                         NDR_PULL_ALLOC(ndr, r->out.length);
732                 }
733                 _mem_save_length_0 = NDR_PULL_GET_MEM_CTX(ndr);
734                 NDR_PULL_SET_MEM_CTX(ndr, r->out.length, LIBNDR_FLAG_REF_ALLOC);
735                 NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, r->out.length));
736                 NDR_PULL_SET_MEM_CTX(ndr, _mem_save_length_0, LIBNDR_FLAG_REF_ALLOC);
737                 NDR_CHECK(ndr_pull_MAPISTATUS(ndr, NDR_SCALARS, &r->out.result));
738         }
739         return NDR_ERR_SUCCESS;
740 }
741
742
743 _PUBLIC_ enum ndr_err_code ndr_push_EcDoRpc(struct ndr_push *ndr, int flags, const struct EcDoRpc *r)
744 {
745         if (flags & NDR_IN) {
746                 if (r->in.handle == NULL) {
747                         return ndr_push_error(ndr, NDR_ERR_INVALID_POINTER, "NULL [ref] pointer");
748                 }
749                 NDR_CHECK(ndr_push_policy_handle(ndr, NDR_SCALARS|NDR_BUFFERS, r->in.handle));
750                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->in.size));
751                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->in.offset));
752                 {
753                         uint32_t _flags_save_mapi_request = ndr->flags;
754                         ndr_set_flags(&ndr->flags, LIBNDR_FLAG_REMAINING|LIBNDR_FLAG_NOALIGN);
755                         if (r->in.mapi_request == NULL) {
756                                 return ndr_push_error(ndr, NDR_ERR_INVALID_POINTER, "NULL [ref] pointer");
757                         }
758                         {
759                                 struct ndr_push *_ndr_mapi_request;
760                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_mapi_request, 4, -1));
761                                 NDR_CHECK(ndr_push_mapi_request(_ndr_mapi_request, NDR_SCALARS|NDR_BUFFERS, r->in.mapi_request));
762                                 obfuscate_data(_ndr_mapi_request->data, _ndr_mapi_request->offset, 0xA5);
763                                 NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_mapi_request, 4, -1));
764                         }
765                         ndr->flags = _flags_save_mapi_request;
766                 }
767                 if (r->in.length == NULL) {
768                         return ndr_push_error(ndr, NDR_ERR_INVALID_POINTER, "NULL [ref] pointer");
769                 }
770                 NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, *r->in.length));
771                 NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, r->in.max_data));
772         }
773         if (flags & NDR_OUT) {
774                 if (r->out.handle == NULL) {
775                         return ndr_push_error(ndr, NDR_ERR_INVALID_POINTER, "NULL [ref] pointer");
776                 }
777                 NDR_CHECK(ndr_push_policy_handle(ndr, NDR_SCALARS|NDR_BUFFERS, r->out.handle));
778                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->out.size));
779                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->out.offset));
780                 {
781                         uint32_t _flags_save_mapi_response = ndr->flags;
782                         ndr_set_flags(&ndr->flags, LIBNDR_FLAG_REMAINING|LIBNDR_FLAG_NOALIGN);
783                         if (r->out.mapi_response == NULL) {
784                                 return ndr_push_error(ndr, NDR_ERR_INVALID_POINTER, "NULL [ref] pointer");
785                         }
786                         {
787                                 struct ndr_push *_ndr_mapi_response;
788                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_mapi_response, 4, -1));
789                                 NDR_CHECK(ndr_push_mapi_response(_ndr_mapi_response, NDR_SCALARS|NDR_BUFFERS, r->out.mapi_response));
790                                 obfuscate_data(_ndr_mapi_response->data, _ndr_mapi_response->alloc_size, 0xA5);
791                                 NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_mapi_response, 4, -1));
792                         }
793                         ndr->flags = _flags_save_mapi_response;
794                 }
795                 if (r->out.length == NULL) {
796                         return ndr_push_error(ndr, NDR_ERR_INVALID_POINTER, "NULL [ref] pointer");
797                 }
798                 NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, *r->out.length));
799                 NDR_CHECK(ndr_push_MAPISTATUS(ndr, NDR_SCALARS, r->out.result));
800         }
801         return NDR_ERR_SUCCESS;
802 }
803
804
805
806 /*
807   We need to pull QueryRows replies on our own:
808   If we have no results, do not push/pull the DATA_BLOB
809 */
810
811 enum ndr_err_code ndr_push_QueryRows_repl(struct ndr_push *ndr, int ndr_flags, const struct QueryRows_repl *r)
812 {
813         {
814                 uint32_t _flags_save_STRUCT = ndr->flags;
815                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
816                 if (ndr_flags & NDR_SCALARS) {
817                         NDR_CHECK(ndr_push_align(ndr, 4));
818                         NDR_CHECK(ndr_push_uint8(ndr, NDR_SCALARS, r->Origin));
819                         NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, r->RowCount));
820
821                         if (r->RowCount) {
822                                 uint32_t _flags_save_DATA_BLOB = ndr->flags;
823                                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_REMAINING);
824                                 NDR_CHECK(ndr_push_DATA_BLOB(ndr, NDR_SCALARS, r->RowData));
825                                 ndr->flags = _flags_save_DATA_BLOB;
826                         }
827                 }
828                 if (ndr_flags & NDR_BUFFERS) {
829                 }
830                 ndr->flags = _flags_save_STRUCT;
831         }
832         return NDR_ERR_SUCCESS;
833 }
834
835 enum ndr_err_code ndr_pull_QueryRows_repl(struct ndr_pull *ndr, int ndr_flags, struct QueryRows_repl *r)
836 {
837         {
838                 uint32_t _flags_save_STRUCT = ndr->flags;
839                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
840                 if (ndr_flags & NDR_SCALARS) {
841                         NDR_CHECK(ndr_pull_align(ndr, 4));
842                         NDR_CHECK(ndr_pull_uint8(ndr, NDR_SCALARS, &r->Origin));
843                         NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &r->RowCount));
844
845                         if (r->RowCount)
846                         {
847                                 uint32_t _flags_save_DATA_BLOB = ndr->flags;
848
849                                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_REMAINING);
850                                 NDR_CHECK(ndr_pull_DATA_BLOB(ndr, NDR_SCALARS, &r->RowData));
851                                 ndr->flags = _flags_save_DATA_BLOB;
852                         } else {
853                                 r->RowData.length = 0;
854                                 r->RowData.data = NULL;
855                         }
856                 }
857                 if (ndr_flags & NDR_BUFFERS) {
858                 }
859                 ndr->flags = _flags_save_STRUCT;
860         }
861         return NDR_ERR_SUCCESS;
862 }
863
864
865 enum ndr_err_code ndr_push_Logon_req(struct ndr_push *ndr, int ndr_flags, const struct Logon_req *r)
866 {
867         {
868                 uint32_t _flags_save_STRUCT = ndr->flags;
869                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
870                 if (ndr_flags & NDR_SCALARS) {
871                         NDR_CHECK(ndr_push_align(ndr, 4));
872                         NDR_CHECK(ndr_push_LogonFlags(ndr, NDR_SCALARS, r->LogonFlags));
873                         NDR_CHECK(ndr_push_OpenFlags(ndr, NDR_SCALARS, r->OpenFlags));
874                         NDR_CHECK(ndr_push_StoreState(ndr, NDR_SCALARS, r->StoreState));
875                         if (r->EssDN && r->EssDN[0] != '\0') {
876                                 uint32_t _flags_save_string = ndr->flags;
877                                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_STR_ASCII|LIBNDR_FLAG_STR_SIZE2);
878                                 NDR_CHECK(ndr_push_string(ndr, NDR_SCALARS, r->EssDN));
879                                 ndr->flags = _flags_save_string;
880                         } else {
881                                 NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, 0));
882                         }
883                 }
884                 if (ndr_flags & NDR_BUFFERS) {
885                 }
886                 ndr->flags = _flags_save_STRUCT;
887         }
888         return NDR_ERR_SUCCESS;
889 }
890
891
892 _PUBLIC_ void ndr_print_SBinary_short(struct ndr_print *ndr, const char *name, const struct SBinary_short *r)
893 {
894         ndr->print(ndr, "%-25s: SBinary_short cb=%u", name, (unsigned)r->cb);
895         {
896                 uint32_t _flags_save_STRUCT = ndr->flags;
897                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
898                 ndr->depth++;
899                 dump_data(0, r->lpb, r->cb);
900                 ndr->depth--;
901                 ndr->flags = _flags_save_STRUCT;
902         }
903 }
904
905
906 _PUBLIC_ void ndr_print_fuzzyLevel(struct ndr_print *ndr, const char *name, uint32_t r)
907 {
908         ndr_print_uint32(ndr, name, r);
909         ndr->depth++;
910         switch ((r & 0x0000FFFF)) {
911         case FL_FULLSTRING:
912                 ndr->print(ndr, "%-25s: FL_FULLSTRING", "lower  16 bits");
913                 break;
914         case FL_SUBSTRING:
915                 ndr->print(ndr, "%-25s: FL_SUBSTRING", "lower  16 bits");
916                 break;
917         case FL_PREFIX:
918                 ndr->print(ndr, "%-25s: FL_PREFIX", "lower  16 bits");
919                 break;
920         }
921         ndr->print(ndr, "%-25s", "higher 16 bits");
922         ndr_print_bitmap_flag(ndr, sizeof(uint32_t), "FL_IGNORECASE", FL_IGNORECASE, r);
923         ndr_print_bitmap_flag(ndr, sizeof(uint32_t), "FL_IGNORENONSPACE", FL_IGNORENONSPACE, r);
924         ndr_print_bitmap_flag(ndr, sizeof(uint32_t), "FL_LOOSE", FL_LOOSE, r);
925         ndr->depth--;
926 }
927
928 /*
929  * Fake wrapper over mapi_SRestriction. Workaround the no-pointer deep
930  * recursion problem in pidl
931  */
932 enum ndr_err_code ndr_push_mapi_SRestriction_wrap(struct ndr_push *ndr, int ndr_flags, const struct mapi_SRestriction_wrap *r)
933 {
934         return ndr_push_mapi_SRestriction(ndr, NDR_SCALARS, (const struct mapi_SRestriction *)r);
935 }
936
937
938 enum ndr_err_code ndr_pull_mapi_SRestriction_wrap(struct ndr_pull *ndr, int ndr_flags, struct mapi_SRestriction_wrap *r)
939 {
940         return ndr_pull_mapi_SRestriction(ndr, NDR_SCALARS|NDR_BUFFERS, (struct mapi_SRestriction *)r);
941 }
942
943 void ndr_print_mapi_SRestriction_wrap(struct ndr_print *ndr, const char *name, const struct mapi_SRestriction_wrap *r)
944 {
945         ndr_print_mapi_SRestriction(ndr, name, (const struct mapi_SRestriction *)r);
946 }
947
948 /*
949  * Fake wrapper over mapi_SPropValue. Workaround the no-pointer deep
950  * recursion problem in pidl
951  */
952 enum ndr_err_code ndr_push_mapi_SPropValue_wrap(struct ndr_push *ndr, int ndr_flags, const struct mapi_SPropValue_wrap *r)
953 {
954         NDR_CHECK(ndr_push_align(ndr, 8));
955         return ndr_push_mapi_SPropValue(ndr, NDR_SCALARS, (const struct mapi_SPropValue *)r);
956 }
957
958 enum ndr_err_code ndr_pull_mapi_SPropValue_wrap(struct ndr_pull *ndr, int ndr_flags, struct mapi_SPropValue_wrap *r)
959 {
960         return ndr_pull_mapi_SPropValue(ndr, NDR_SCALARS, (struct mapi_SPropValue *)r);
961 }
962
963 void ndr_print_mapi_SPropValue_wrap(struct ndr_print *ndr, const char *name, const struct mapi_SPropValue_wrap *r)
964 {
965         ndr_print_mapi_SPropValue(ndr, name, (const struct mapi_SPropValue *)r);
966 }
967
968
969 /*
970  * Fake wrapper over mapi_SPropValue_array. Workaround the no-pointer deep
971  * recursion problem in pidl
972  */
973 enum ndr_err_code ndr_push_mapi_SPropValue_array_wrap(struct ndr_push *ndr, int ndr_flags, const struct mapi_SPropValue_array_wrap *r)
974 {
975         NDR_CHECK(ndr_push_align(ndr, 8));
976         return ndr_push_mapi_SPropValue_array(ndr, NDR_SCALARS, (const struct mapi_SPropValue_array *)r);
977 }
978
979 enum ndr_err_code ndr_pull_mapi_SPropValue_array_wrap(struct ndr_pull *ndr, int ndr_flags, struct mapi_SPropValue_array_wrap *r)
980 {
981         return ndr_pull_mapi_SPropValue_array(ndr, NDR_SCALARS, (struct mapi_SPropValue_array *)r);
982 }
983
984 void ndr_print_mapi_SPropValue_array_wrap(struct ndr_print *ndr, const char *name, const struct mapi_SPropValue_array_wrap *r)
985 {
986         ndr_print_mapi_SPropValue_array(ndr, name, (const struct mapi_SPropValue_array *)r);
987 }
988
989 enum ndr_err_code ndr_push_RestrictionVariable(struct ndr_push *ndr, int ndr_flags, const union RestrictionVariable *r)
990 {
991         {
992                 uint32_t _flags_save_STRUCT = ndr->flags;
993                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
994                 if (ndr_flags & NDR_SCALARS) {
995                         int level = ndr_push_get_switch_value(ndr, r);
996                         switch (level) {
997                                 case 0x0: {
998                                         break; }
999
1000                                 case 0x1: {
1001                                         NDR_CHECK(ndr_push_mapi_SRestriction_comment(ndr, NDR_SCALARS, &r->res[0]));
1002                                 break; }
1003
1004                                 default:
1005                                         return ndr_push_error(ndr, NDR_ERR_BAD_SWITCH, "Bad switch value %u", level);
1006                         }
1007                 }
1008                 if (ndr_flags & NDR_BUFFERS) {
1009                         int level = ndr_push_get_switch_value(ndr, r);
1010                         switch (level) {
1011                                 case 0x0:
1012                                 break;
1013
1014                                 case 0x1:
1015                                         if (r->res) {
1016                                                 NDR_CHECK(ndr_push_mapi_SRestriction_comment(ndr, NDR_BUFFERS, &r->res[0]));
1017                                         }
1018                                 break;
1019
1020                                 default:
1021                                         return ndr_push_error(ndr, NDR_ERR_BAD_SWITCH, "Bad switch value %u", level);
1022                         }
1023                 }
1024                 ndr->flags = _flags_save_STRUCT;
1025         }
1026         return NDR_ERR_SUCCESS;
1027 }
1028
1029 enum ndr_err_code  ndr_pull_RestrictionVariable(struct ndr_pull *ndr, int ndr_flags, union RestrictionVariable *r)
1030 {
1031         int level;
1032         TALLOC_CTX *_mem_save_res_0;
1033         level = ndr_pull_get_switch_value(ndr, r);
1034         {
1035                 uint32_t _flags_save_STRUCT = ndr->flags;
1036                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
1037
1038                 if (ndr_flags & NDR_SCALARS) {
1039                         switch (level) {
1040                                 case 0x0: {
1041                                 break; }
1042
1043                                 case 0x1: {
1044                                         NDR_CHECK(ndr_pull_align(ndr, 4));
1045                                         NDR_PULL_ALLOC_N(ndr, r->res, 1);
1046                                         _mem_save_res_0 = NDR_PULL_GET_MEM_CTX(ndr);
1047                                         NDR_PULL_SET_MEM_CTX(ndr, r->res, 0);
1048                                         NDR_CHECK(ndr_pull_mapi_SRestriction_comment(ndr, NDR_SCALARS, &r->res[0]));
1049                                         NDR_PULL_SET_MEM_CTX(ndr, _mem_save_res_0, 0);
1050                                 break; }
1051
1052                                 default:
1053                                         return ndr_pull_error(ndr, NDR_ERR_BAD_SWITCH, "Bad switch value %u", level);
1054                         }
1055                 }
1056                 if (ndr_flags & NDR_BUFFERS) {
1057                         switch (level) {
1058                                 case 0x0:
1059                                 break;
1060
1061                                 case 0x1:
1062                                         if (r->res) {
1063                                                 _mem_save_res_0 = NDR_PULL_GET_MEM_CTX(ndr);
1064                                                 NDR_PULL_SET_MEM_CTX(ndr, r->res, 0);
1065                                                 NDR_CHECK(ndr_pull_mapi_SRestriction_comment(ndr, NDR_BUFFERS, &r->res[0]));
1066                                                 NDR_PULL_SET_MEM_CTX(ndr, _mem_save_res_0, 0);
1067                                 break; }
1068
1069                                 default:
1070                                         return ndr_pull_error(ndr, NDR_ERR_BAD_SWITCH, "Bad switch value %u", level);
1071                         }
1072                 }
1073                 ndr->flags = _flags_save_STRUCT;
1074         }
1075         return NDR_ERR_SUCCESS;
1076 }
1077
1078
1079 _PUBLIC_ void ndr_print_RestrictionVariable(struct ndr_print *ndr, const char *name, const union RestrictionVariable *r)
1080 {
1081         int level;
1082         level = ndr_print_get_switch_value(ndr, r);
1083         ndr_print_union(ndr, name, level, "RestrictionVariable");
1084         switch (level) {
1085                 case 0x0:
1086                 break;
1087
1088                 case 0x1:
1089                         ndr_print_ptr(ndr, "res", r->res);
1090                         ndr->depth++;
1091                         if (r->res) {
1092                                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
1093                                 ndr_print_mapi_SRestriction_comment(ndr, "res", &r->res[0]);
1094                         }
1095                         ndr->depth--;
1096                 break;
1097         }
1098 }
1099
1100 enum ndr_err_code ndr_push_Release_req(struct ndr_push *ndr, int ndr_flags, const struct Release_req *r)
1101 {
1102         return NDR_ERR_SUCCESS;
1103 }
1104
1105 enum ndr_err_code ndr_pull_Release_req(struct ndr_pull *ndr, int ndr_flags, struct Release_req *r)
1106 {
1107         return NDR_ERR_SUCCESS;
1108 }
1109
1110 enum ndr_err_code ndr_push_Release_repl(struct ndr_push *ndr, int ndr_flags, const struct Release_repl *r)
1111 {
1112         return NDR_ERR_SUCCESS;
1113 }
1114
1115 enum ndr_err_code ndr_pull_Release_repl(struct ndr_pull *ndr, int ndr_flags, struct Release_repl *r)
1116 {
1117         return NDR_ERR_SUCCESS;
1118 }
1119
1120
1121 enum ndr_err_code ndr_push_GetSearchCriteria_repl(struct ndr_push *ndr, int ndr_flags, const struct GetSearchCriteria_repl *r)
1122 {
1123         uint32_t cntr_FolderIds_0;
1124         {
1125                 uint32_t _flags_save_STRUCT = ndr->flags;
1126                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
1127                 if (ndr_flags & NDR_SCALARS) {
1128                         NDR_CHECK(ndr_push_align(ndr, 8));
1129                         NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, r->RestrictionDataSize));
1130                         if (r->RestrictionDataSize) {
1131                                 struct ndr_push *_ndr_RestrictionData;
1132                                 NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_RestrictionData, 0, r->RestrictionDataSize));
1133                                 NDR_CHECK(ndr_push_mapi_SRestriction(_ndr_RestrictionData, NDR_SCALARS|NDR_BUFFERS, &r->RestrictionData));
1134                                 NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_RestrictionData, 0, r->RestrictionDataSize));
1135                         }
1136                         NDR_CHECK(ndr_push_uint8(ndr, NDR_SCALARS, r->LogonId));
1137                         NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, r->FolderIdCount));
1138                         for (cntr_FolderIds_0 = 0; cntr_FolderIds_0 < r->FolderIdCount; cntr_FolderIds_0++) {
1139                                 NDR_CHECK(ndr_push_hyper(ndr, NDR_SCALARS, r->FolderIds[cntr_FolderIds_0]));
1140                         }
1141                         NDR_CHECK(ndr_push_SearchFlags(ndr, NDR_SCALARS, r->SearchFlags));
1142                         NDR_CHECK(ndr_push_trailer_align(ndr, 8));
1143                 }
1144                 if (ndr_flags & NDR_BUFFERS) {
1145                 }
1146                 ndr->flags = _flags_save_STRUCT;
1147         }
1148         return NDR_ERR_SUCCESS;
1149 }
1150
1151
1152 enum ndr_err_code ndr_pull_GetSearchCriteria_repl(struct ndr_pull *ndr, int ndr_flags, struct GetSearchCriteria_repl *r)
1153 {
1154         uint32_t cntr_FolderIds_0;
1155         TALLOC_CTX *_mem_save_FolderIds_0;
1156         {
1157                 uint32_t _flags_save_STRUCT = ndr->flags;
1158                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
1159                 if (ndr_flags & NDR_SCALARS) {
1160                         NDR_CHECK(ndr_pull_align(ndr, 8));
1161                         NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &r->RestrictionDataSize));
1162                         if (r->RestrictionDataSize) {
1163                                 struct ndr_pull *_ndr_RestrictionData;
1164                                 NDR_CHECK(ndr_pull_subcontext_start(ndr, &_ndr_RestrictionData, 0, r->RestrictionDataSize));
1165                                 NDR_CHECK(ndr_pull_mapi_SRestriction(_ndr_RestrictionData, NDR_SCALARS|NDR_BUFFERS, &r->RestrictionData));
1166                                 NDR_CHECK(ndr_pull_subcontext_end(ndr, _ndr_RestrictionData, 0, r->RestrictionDataSize));
1167                         }
1168                         NDR_CHECK(ndr_pull_uint8(ndr, NDR_SCALARS, &r->LogonId));
1169                         NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &r->FolderIdCount));
1170                         NDR_PULL_ALLOC_N(ndr, r->FolderIds, r->FolderIdCount);
1171                         _mem_save_FolderIds_0 = NDR_PULL_GET_MEM_CTX(ndr);
1172                         NDR_PULL_SET_MEM_CTX(ndr, r->FolderIds, 0);
1173                         for (cntr_FolderIds_0 = 0; cntr_FolderIds_0 < r->FolderIdCount; cntr_FolderIds_0++) {
1174                                 NDR_CHECK(ndr_pull_hyper(ndr, NDR_SCALARS, &r->FolderIds[cntr_FolderIds_0]));
1175                         }
1176                         NDR_PULL_SET_MEM_CTX(ndr, _mem_save_FolderIds_0, 0);
1177                         NDR_CHECK(ndr_pull_SearchFlags(ndr, NDR_SCALARS, &r->SearchFlags));
1178                         NDR_CHECK(ndr_pull_trailer_align(ndr, 8));
1179                 }
1180                 if (ndr_flags & NDR_BUFFERS) {
1181                 }
1182                 ndr->flags = _flags_save_STRUCT;
1183         }
1184         return NDR_ERR_SUCCESS;
1185 }
1186
1187
1188 void ndr_print_GetSearchCriteria_repl(struct ndr_print *ndr, const char *name, const struct GetSearchCriteria_repl *r)
1189 {
1190         uint32_t cntr_FolderIds_0;
1191         ndr_print_struct(ndr, name, "GetSearchCriteria_repl");
1192         {
1193                 uint32_t _flags_save_STRUCT = ndr->flags;
1194                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
1195                 ndr->depth++;
1196                 ndr_print_uint16(ndr, "RestrictionDataSize", r->RestrictionDataSize);
1197                 if (r->RestrictionDataSize) {
1198                         ndr_print_mapi_SRestriction(ndr, "RestrictionData", &r->RestrictionData);
1199                 } else {
1200                         ndr_print_uint8(ndr, "RestrictionData", 0);
1201                 }
1202                 ndr_print_uint8(ndr, "LogonId", r->LogonId);
1203                 ndr_print_uint16(ndr, "FolderIdCount", r->FolderIdCount);
1204                 ndr->print(ndr, "%s: ARRAY(%d)", "FolderIds", (int)r->FolderIdCount);
1205                 ndr->depth++;
1206                 for (cntr_FolderIds_0=0;cntr_FolderIds_0<r->FolderIdCount;cntr_FolderIds_0++) {
1207                         char *idx_0=NULL;
1208                         if (asprintf(&idx_0, "[%d]", cntr_FolderIds_0) != -1) {
1209                                 ndr_print_hyper(ndr, "FolderIds", r->FolderIds[cntr_FolderIds_0]);
1210                                 free(idx_0);
1211                         }
1212                 }
1213                 ndr->depth--;
1214                 ndr_print_SearchFlags(ndr, "SearchFlags", r->SearchFlags);
1215                 ndr->depth--;
1216                 ndr->flags = _flags_save_STRUCT;
1217         }
1218 }