- Add GetStoreState (0x7b) IDL, implementation and mapitest unit
[jelmer/openchange.git] / ndr_mapi.c
1 /* 
2    OpenChange implementation.
3
4    libndr mapi support
5
6    Copyright (C) Julien Kerihuel 2005-2007
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 /*
37   print mapi_request / mapi_response structures
38  */
39
40 void ndr_print_mapi_request(struct ndr_print *ndr, const char *name, const struct mapi_request *r)
41 {
42         uint32_t        rlength;
43
44         rlength = r->mapi_len - r->length;
45
46         ndr_print_uint32(ndr, "mapi_len", r->mapi_len);
47         if (r->length && r->length > sizeof(uint16_t)) {
48                 uint32_t cntr_mapi_req_0;
49
50                 ndr_print_uint16(ndr, "length", r->length);
51                 ndr->depth++;
52                 for (cntr_mapi_req_0=0; r->mapi_req[cntr_mapi_req_0].opnum; cntr_mapi_req_0++) {
53                         char *idx_0=NULL;
54                         asprintf(&idx_0, "[%d]", cntr_mapi_req_0);
55                         if (idx_0) {
56                                 ndr_print_EcDoRpc_MAPI_REQ(ndr, "mapi_request", &r->mapi_req[cntr_mapi_req_0]);
57                                 free(idx_0);
58                         } 
59                 }
60                 ndr->depth--;
61         }
62
63         if (rlength) {
64                 uint32_t i;
65
66                 ndr->depth++;
67                 ndr->print(ndr, "%-25s: (handles) number=%u", name, rlength / 4);
68                 ndr->depth++;
69                 for (i = 0; i < (rlength / 4); i++) {
70                         ndr_print_uint32(ndr, "handle", r->handles[i]);
71                 }
72                 ndr->depth--;
73         }
74 }
75
76 void ndr_print_mapi_response(struct ndr_print *ndr, const char *name, const struct mapi_response *r)
77 {
78         uint32_t        rlength;
79
80         rlength = r->mapi_len - r->length;
81
82         ndr->print(ndr, "%-25s: length=%u", name, r->length);
83         if (r->length && r->length > sizeof(uint16_t)) {
84                 uint32_t cntr_mapi_repl_0;
85
86                 ndr->print(ndr, "%s: ARRAY(%d)", name, r->length - 2);
87                 ndr->depth++;
88                 for (cntr_mapi_repl_0=0; r->mapi_repl[cntr_mapi_repl_0].opnum; cntr_mapi_repl_0++) {
89                         ndr_print_EcDoRpc_MAPI_REPL(ndr, "mapi_repl", &r->mapi_repl[cntr_mapi_repl_0]);
90                 }
91                 ndr->depth--;
92         }
93
94         ndr->print(ndr, "%-25s: (handles) number=%u", name, rlength / 4);
95         
96         if (rlength) {
97                 uint32_t i;
98
99                 ndr->depth++;
100
101                 for (i = 0; i < (rlength / 4); i++) {
102                         ndr_print_uint32(ndr, "handle id", r->handles[i]);
103                 }
104                 ndr->depth--;
105         }
106 }
107
108
109 /*
110   push mapi_request / mapi_response onto the wire.  
111
112   MAPI length field includes length bytes. 
113   But these bytes do not belong to the mapi content in the user
114   context. We have to add them when pushing mapi content length
115   (uint16_t) and next substract when pushing the content blob
116 */
117
118 enum ndr_err_code ndr_push_mapi_request(struct ndr_push *ndr, int ndr_flags, const struct mapi_request *r)
119 {
120         uint32_t                cntr_mapi_req_0;
121         uint32_t                count;
122
123         ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
124         NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, r->length));
125
126         for (count = 0; ndr->offset < r->length - 2; count++) {
127                 NDR_CHECK(ndr_push_EcDoRpc_MAPI_REQ(ndr, NDR_SCALARS, &r->mapi_req[count]));
128         }
129
130         count = (r->mapi_len - r->length) / sizeof(uint32_t);
131         for (cntr_mapi_req_0=0; cntr_mapi_req_0 < count; cntr_mapi_req_0++) {
132                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->handles[cntr_mapi_req_0]));
133         }
134
135         obfuscate_data(ndr->data, ndr->offset, 0xA5);
136
137         return NDR_ERR_SUCCESS;
138 }
139
140 enum ndr_err_code ndr_push_mapi_response(struct ndr_push *ndr, int ndr_flags, const struct mapi_response *r)
141 {
142         uint32_t        cntr_mapi_repl_0;
143         uint32_t        count;
144
145         ndr_set_flags(&ndr->flags, LIBNDR_FLAG_REMAINING);
146         NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, r->length));
147
148         if (r->length > sizeof (uint16_t)) {
149                 for (count = 0; ndr->offset < r->length - 2; count++) {
150                         NDR_CHECK(ndr_push_EcDoRpc_MAPI_REPL(ndr, NDR_SCALARS, &r->mapi_repl[count]));
151                 }
152
153                 /* hack adding padding bytes */
154                 count = r->length - ndr->offset;
155                 if (count > 0) {
156                         for (cntr_mapi_repl_0 =0; cntr_mapi_repl_0 < count; cntr_mapi_repl_0++) {
157                                 NDR_CHECK(ndr_push_uint8(ndr, NDR_SCALARS, 0));
158                         }
159                 }
160         }
161
162         count = (r->mapi_len - r->length) / sizeof (uint32_t);
163         for (cntr_mapi_repl_0 = 0; cntr_mapi_repl_0 <count; cntr_mapi_repl_0++) {
164                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->handles[cntr_mapi_repl_0]));
165         }
166
167         obfuscate_data(ndr->data, ndr->alloc_size, 0xA5);
168
169         return NDR_ERR_SUCCESS;
170 }
171
172 /*
173   pull mapi_request / mapi_response from the wire
174 */
175
176 enum ndr_err_code ndr_pull_mapi_request(struct ndr_pull *ndr, int ndr_flags, struct mapi_request *r)
177 {
178         uint32_t length,count;
179         uint32_t cntr_mapi_req_0;
180         TALLOC_CTX *_mem_save_mapi_req_0;
181         TALLOC_CTX *_mem_save_handles_0;
182         struct ndr_pull *_ndr_mapi_req;
183
184         obfuscate_data(ndr->data, ndr->data_size, 0xA5);
185
186         if (ndr->flags & LIBNDR_FLAG_REMAINING) {
187                 length = ndr->data_size - ndr->offset;
188         } else {
189                 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &length));
190         }
191         r->mapi_len = length;
192
193         NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &r->length));
194
195         /* If length equals length field then skipping subcontext */
196         if (r->length > sizeof (uint16_t)) {
197                 NDR_CHECK(ndr_pull_subcontext_start(ndr, &_ndr_mapi_req, 0, r->length - 2));
198                 _mem_save_mapi_req_0 = NDR_PULL_GET_MEM_CTX(_ndr_mapi_req);
199                 r->mapi_req = talloc_zero(_mem_save_mapi_req_0, struct EcDoRpc_MAPI_REQ);
200                 for (cntr_mapi_req_0 = 0; _ndr_mapi_req->offset < _ndr_mapi_req->data_size - 2; cntr_mapi_req_0++) {
201                         NDR_CHECK(ndr_pull_EcDoRpc_MAPI_REQ(_ndr_mapi_req, NDR_SCALARS, &r->mapi_req[cntr_mapi_req_0]));
202                         r->mapi_req = talloc_realloc(_mem_save_mapi_req_0, r->mapi_req, struct EcDoRpc_MAPI_REQ, cntr_mapi_req_0 + 2);
203                 }
204                 r->mapi_req = talloc_realloc(_mem_save_mapi_req_0, r->mapi_req, struct EcDoRpc_MAPI_REQ, cntr_mapi_req_0 + 2);
205                 r->mapi_req[cntr_mapi_req_0].opnum = 0;
206                 
207                 if (_ndr_mapi_req->offset != r->length - 2) {
208                         return NDR_ERR_BUFSIZE;
209                 }
210                 NDR_CHECK(ndr_pull_subcontext_end(ndr, _ndr_mapi_req, 4, -1));
211         
212                 _mem_save_handles_0 = NDR_PULL_GET_MEM_CTX(ndr);
213                 count = (r->mapi_len - r->length) / sizeof(uint32_t);
214                 r->handles = talloc_array(_mem_save_handles_0, uint32_t, count + 1);
215                 for (cntr_mapi_req_0=0; cntr_mapi_req_0 < count; cntr_mapi_req_0++) {
216                         NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->handles[cntr_mapi_req_0]));
217                 }
218         } else {
219                 r->handles = NULL;
220         }
221
222         return NDR_ERR_SUCCESS;
223 }
224
225 enum ndr_err_code ndr_pull_mapi_response(struct ndr_pull *ndr, int ndr_flags, struct mapi_response *r)
226 {
227         uint32_t length,count;
228         uint32_t cntr_mapi_repl_0;
229         TALLOC_CTX *_mem_save_mapi_repl_0;
230         TALLOC_CTX *_mem_save_handles_0;
231         struct ndr_pull *_ndr_mapi_repl;
232
233         obfuscate_data(ndr->data, ndr->data_size, 0xA5);
234
235         if (ndr->flags & LIBNDR_FLAG_REMAINING) {
236                 length = ndr->data_size - ndr->offset;
237         } else {
238                 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &length));
239         }
240         r->mapi_len = length;
241
242         NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &r->length));
243         
244         /* If length equals length field then skipping subcontext */
245         if (r->length > sizeof (uint16_t)) {
246                 NDR_CHECK(ndr_pull_subcontext_start(ndr, &_ndr_mapi_repl, 0, r->length - 2));
247                 _mem_save_mapi_repl_0 = NDR_PULL_GET_MEM_CTX(_ndr_mapi_repl);
248                 r->mapi_repl = talloc_zero(_mem_save_mapi_repl_0, struct EcDoRpc_MAPI_REPL);
249                 for (cntr_mapi_repl_0 = 0; _ndr_mapi_repl->offset < _ndr_mapi_repl->data_size - 2; cntr_mapi_repl_0++) {
250                         NDR_CHECK(ndr_pull_EcDoRpc_MAPI_REPL(_ndr_mapi_repl, NDR_SCALARS, &r->mapi_repl[cntr_mapi_repl_0]));
251                         r->mapi_repl = talloc_realloc(_mem_save_mapi_repl_0, r->mapi_repl, struct EcDoRpc_MAPI_REPL, cntr_mapi_repl_0 + 2);
252                 }
253                 r->mapi_repl = talloc_realloc(_mem_save_mapi_repl_0, r->mapi_repl, struct EcDoRpc_MAPI_REPL, cntr_mapi_repl_0 + 2);
254                 r->mapi_repl[cntr_mapi_repl_0].opnum = 0;
255                 NDR_CHECK(ndr_pull_subcontext_end(ndr, _ndr_mapi_repl, 4, -1));
256         }
257
258         _mem_save_handles_0 = NDR_PULL_GET_MEM_CTX(ndr);
259         count = (r->mapi_len - r->length) / sizeof(uint32_t);
260         r->handles = talloc_array(_mem_save_handles_0, uint32_t, count + 1);
261         for (cntr_mapi_repl_0=0; cntr_mapi_repl_0 < count; cntr_mapi_repl_0++) {
262                 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->handles[cntr_mapi_repl_0]));
263         }
264
265         return NDR_ERR_SUCCESS;
266 }
267
268 /*
269   We stop processing the IDL if MAPISTATUS is different from MAPI_E_SUCCESS
270  */
271
272 _PUBLIC_ enum ndr_err_code ndr_push_EcDoRpc_MAPI_REPL(struct ndr_push *ndr, int ndr_flags, const struct EcDoRpc_MAPI_REPL *r)
273 {
274         if (r->opnum != op_MAPI_Release)
275         {
276                 uint32_t _flags_save_STRUCT = ndr->flags;
277                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
278                 if (ndr_flags & NDR_SCALARS) {
279                         NDR_CHECK(ndr_push_align(ndr, 8));
280                         NDR_CHECK(ndr_push_uint8(ndr, NDR_SCALARS, r->opnum));
281                         if ((r->opnum == op_MAPI_Notify) || (r->opnum == op_MAPI_Pending)) {
282                                 NDR_CHECK(ndr_push_set_switch_value(ndr, &r->u, r->opnum));
283                                 NDR_CHECK(ndr_push_EcDoRpc_MAPI_REPL_UNION(ndr, NDR_SCALARS, &r->u));                           
284                         } else {
285                                 NDR_CHECK(ndr_push_uint8(ndr, NDR_SCALARS, r->handle_idx));
286                                 NDR_CHECK(ndr_push_MAPISTATUS(ndr, NDR_SCALARS, r->error_code));
287                                 if (r->error_code == MAPI_E_SUCCESS) {
288                                         NDR_CHECK(ndr_push_set_switch_value(ndr, &r->u, r->opnum));
289                                         NDR_CHECK(ndr_push_EcDoRpc_MAPI_REPL_UNION(ndr, NDR_SCALARS, &r->u));
290                                 }
291                         }
292                 }
293                 if (ndr_flags & NDR_BUFFERS) {
294                         NDR_CHECK(ndr_push_EcDoRpc_MAPI_REPL_UNION(ndr, NDR_BUFFERS, &r->u));
295                 }
296                 ndr->flags = _flags_save_STRUCT;
297         }
298         return NDR_ERR_SUCCESS;
299 }
300
301 enum ndr_err_code ndr_pull_EcDoRpc_MAPI_REPL(struct ndr_pull *ndr, int ndr_flags, struct EcDoRpc_MAPI_REPL *r)
302 {
303         {
304                 uint32_t _flags_save_STRUCT = ndr->flags;
305                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
306                 if (ndr_flags & NDR_SCALARS) {
307                         NDR_CHECK(ndr_pull_align(ndr, 8));
308                         NDR_CHECK(ndr_pull_uint8(ndr, NDR_SCALARS, &r->opnum));
309                         if ((r->opnum == op_MAPI_Notify) || (r->opnum == op_MAPI_Pending)) {
310                                 NDR_CHECK(ndr_pull_set_switch_value(ndr, &r->u, r->opnum));
311                                 NDR_CHECK(ndr_pull_EcDoRpc_MAPI_REPL_UNION(ndr, NDR_SCALARS, &r->u));
312                         } else {
313                                 NDR_CHECK(ndr_pull_uint8(ndr, NDR_SCALARS, &r->handle_idx));
314                                 NDR_CHECK(ndr_pull_MAPISTATUS(ndr, NDR_SCALARS, &r->error_code));
315                                 if ( r->error_code == MAPI_E_SUCCESS) {
316                                         NDR_CHECK(ndr_pull_set_switch_value(ndr, &r->u, r->opnum));
317                                         NDR_CHECK(ndr_pull_EcDoRpc_MAPI_REPL_UNION(ndr, NDR_SCALARS, &r->u));
318                                 }
319                         }
320                 }
321                 if (ndr_flags & NDR_BUFFERS) {
322                         ndr->flags = _flags_save_STRUCT;
323                 }
324         }
325         return NDR_ERR_SUCCESS;
326 }
327
328 void ndr_print_EcDoRpc_MAPI_REPL(struct ndr_print *ndr, const char *name, const struct EcDoRpc_MAPI_REPL *r)
329 {
330         ndr_print_struct(ndr, name, "EcDoRpc_MAPI_REPL");
331         {
332                 uint32_t _flags_save_STRUCT = ndr->flags;
333                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
334                 ndr->depth++;
335                 ndr_print_uint8(ndr, "opnum", r->opnum);
336                 if ((r->opnum != op_MAPI_Notify) && (r->opnum != op_MAPI_Pending)) {
337                         ndr_print_uint8(ndr, "handle_idx", r->handle_idx);
338                         ndr_print_MAPISTATUS(ndr, "error_code", r->error_code);
339                         if (r->error_code == MAPI_E_SUCCESS) {
340                                 ndr_print_set_switch_value(ndr, &r->u, r->opnum);
341                                 ndr_print_EcDoRpc_MAPI_REPL_UNION(ndr, "u", &r->u);
342                         }
343                 } else {
344                         ndr_print_set_switch_value(ndr, &r->u, r->opnum);
345                         ndr_print_EcDoRpc_MAPI_REPL_UNION(ndr, "u", &r->u);
346                 }
347                 ndr->depth--;
348                 ndr->flags = _flags_save_STRUCT;
349         }
350 }
351
352 /*
353   We need to pull QueryRows replies on our own:
354   If we have no results, do not push/pull the DATA_BLOB
355 */
356
357 enum ndr_err_code ndr_push_QueryRows_repl(struct ndr_push *ndr, int ndr_flags, const struct QueryRows_repl *r)
358 {
359         {
360                 uint32_t _flags_save_STRUCT = ndr->flags;
361                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
362                 if (ndr_flags & NDR_SCALARS) {
363                         NDR_CHECK(ndr_push_align(ndr, 4));
364                         NDR_CHECK(ndr_push_uint8(ndr, NDR_SCALARS, r->Origin));
365                         NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, r->RowCount));
366
367                         if (r->RowCount) {
368                                 uint32_t _flags_save_DATA_BLOB = ndr->flags;
369                                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_REMAINING);
370                                 NDR_CHECK(ndr_push_DATA_BLOB(ndr, NDR_SCALARS, r->RowData));
371                                 ndr->flags = _flags_save_DATA_BLOB;
372                         }
373                 }
374                 if (ndr_flags & NDR_BUFFERS) {
375                 }
376                 ndr->flags = _flags_save_STRUCT;
377         }
378         return NDR_ERR_SUCCESS;
379 }
380
381 enum ndr_err_code ndr_pull_QueryRows_repl(struct ndr_pull *ndr, int ndr_flags, struct QueryRows_repl *r)
382 {
383         {
384                 uint32_t _flags_save_STRUCT = ndr->flags;
385                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
386                 if (ndr_flags & NDR_SCALARS) {
387                         NDR_CHECK(ndr_pull_align(ndr, 4));
388                         NDR_CHECK(ndr_pull_uint8(ndr, NDR_SCALARS, &r->Origin));
389                         NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &r->RowCount));
390
391                         if (r->RowCount)
392                         {
393                                 uint32_t _flags_save_DATA_BLOB = ndr->flags;
394
395                                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_REMAINING);
396                                 NDR_CHECK(ndr_pull_DATA_BLOB(ndr, NDR_SCALARS, &r->RowData));
397                                 ndr->flags = _flags_save_DATA_BLOB;
398                         }
399                 }
400                 if (ndr_flags & NDR_BUFFERS) {
401                 }
402                 ndr->flags = _flags_save_STRUCT;
403         }
404         return NDR_ERR_SUCCESS;
405 }
406
407
408 enum ndr_err_code ndr_push_Logon_req(struct ndr_push *ndr, int ndr_flags, const struct Logon_req *r)
409 {
410         {
411                 uint32_t _flags_save_STRUCT = ndr->flags;
412                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
413                 if (ndr_flags & NDR_SCALARS) {
414                         NDR_CHECK(ndr_push_align(ndr, 4));
415                         NDR_CHECK(ndr_push_LogonFlags(ndr, NDR_SCALARS, r->LogonFlags));
416                         NDR_CHECK(ndr_push_OpenFlags(ndr, NDR_SCALARS, r->OpenFlags));
417                         NDR_CHECK(ndr_push_StoreState(ndr, NDR_SCALARS, r->StoreState));
418                         if (r->LegacyDN && r->LegacyDN[0] != '\0') {
419                                 uint32_t _flags_save_string = ndr->flags;
420                                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_STR_ASCII|LIBNDR_FLAG_STR_SIZE2);
421                                 NDR_CHECK(ndr_push_string(ndr, NDR_SCALARS, r->LegacyDN));
422                                 ndr->flags = _flags_save_string;
423                         } else {
424                                 NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, 0));
425                         }
426                 }
427                 if (ndr_flags & NDR_BUFFERS) {
428                 }
429                 ndr->flags = _flags_save_STRUCT;
430         }
431         return NDR_ERR_SUCCESS;
432 }
433
434
435 _PUBLIC_ void ndr_print_SBinary_short(struct ndr_print *ndr, const char *name, const struct SBinary_short *r)
436 {
437         ndr->print(ndr, "%-25s: SBinary_short cb=%u", name, (unsigned)r->cb);
438         {
439                 uint32_t _flags_save_STRUCT = ndr->flags;
440                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
441                 ndr->depth++;
442                 dump_data(0, r->lpb, r->cb);
443                 ndr->depth--;
444                 ndr->flags = _flags_save_STRUCT;
445         }
446 }
447
448
449 _PUBLIC_ void ndr_print_fuzzyLevel(struct ndr_print *ndr, const char *name, uint32_t r)
450 {
451         ndr_print_uint32(ndr, name, r);
452         ndr->depth++;
453         switch ((r & 0x0000FFFF)) {
454         case FL_FULLSTRING:
455                 ndr->print(ndr, "%-25s: FL_FULLSTRING", "lower  16 bits");
456                 break;
457         case FL_SUBSTRING:
458                 ndr->print(ndr, "%-25s: FL_SUBSTRING", "lower  16 bits");
459                 break;
460         case FL_PREFIX:
461                 ndr->print(ndr, "%-25s: FL_PREFIX", "lower  16 bits");
462                 break;
463         }
464         ndr->print(ndr, "%-25s", "higher 16 bits");
465         ndr_print_bitmap_flag(ndr, sizeof(uint32_t), "FL_IGNORECASE", FL_IGNORECASE, r);
466         ndr_print_bitmap_flag(ndr, sizeof(uint32_t), "FL_IGNORENONSPACE", FL_IGNORENONSPACE, r);
467         ndr_print_bitmap_flag(ndr, sizeof(uint32_t), "FL_LOOSE", FL_LOOSE, r);
468         ndr->depth--;
469 }
470
471 /*
472  * Fake wrapper over mapi_SRestriction. Workaround the no-pointer deep
473  * recursion problem in pidl
474  */
475 enum ndr_err_code ndr_push_mapi_SRestriction_wrap(struct ndr_push *ndr, int ndr_flags, const struct mapi_SRestriction_wrap *r)
476 {
477         return ndr_push_mapi_SRestriction(ndr, NDR_SCALARS, (const struct mapi_SRestriction *)r);
478 }
479
480
481 enum ndr_err_code ndr_pull_mapi_SRestriction_wrap(struct ndr_pull *ndr, int ndr_flags, struct mapi_SRestriction_wrap *r)
482 {
483         return ndr_pull_mapi_SRestriction(ndr, NDR_SCALARS|NDR_BUFFERS, (struct mapi_SRestriction *)r);
484 }
485
486 void ndr_print_mapi_SRestriction_wrap(struct ndr_print *ndr, const char *name, const struct mapi_SRestriction_wrap *r)
487 {
488         ndr_print_mapi_SRestriction(ndr, name, (const struct mapi_SRestriction *)r);
489 }
490
491 /*
492  * Fake wrapper over mapi_SPropValue. Workaround the no-pointer deep
493  * recursion problem in pidl
494  */
495 enum ndr_err_code ndr_push_mapi_SPropValue_wrap(struct ndr_push *ndr, int ndr_flags, const struct mapi_SPropValue_wrap *r)
496 {
497         NDR_CHECK(ndr_push_align(ndr, 8));
498         return ndr_push_mapi_SPropValue(ndr, NDR_SCALARS, (const struct mapi_SPropValue *)r);
499 }
500
501 enum ndr_err_code ndr_pull_mapi_SPropValue_wrap(struct ndr_pull *ndr, int ndr_flags, struct mapi_SPropValue_wrap *r)
502 {
503         return ndr_pull_mapi_SPropValue(ndr, NDR_SCALARS, (struct mapi_SPropValue *)r);
504 }
505
506 void ndr_print_mapi_SPropValue_wrap(struct ndr_print *ndr, const char *name, const struct mapi_SPropValue_wrap *r)
507 {
508         return ndr_print_mapi_SPropValue(ndr, name, (const struct mapi_SPropValue *)r);
509 }
510
511
512 /*
513  * Fake wrapper over mapi_SPropValue_array. Workaround the no-pointer deep
514  * recursion problem in pidl
515  */
516 enum ndr_err_code ndr_push_mapi_SPropValue_array_wrap(struct ndr_push *ndr, int ndr_flags, const struct mapi_SPropValue_array_wrap *r)
517 {
518         NDR_CHECK(ndr_push_align(ndr, 8));
519         return ndr_push_mapi_SPropValue_array(ndr, NDR_SCALARS, (const struct mapi_SPropValue_array *)r);
520 }
521
522 enum ndr_err_code ndr_pull_mapi_SPropValue_array_wrap(struct ndr_pull *ndr, int ndr_flags, struct mapi_SPropValue_array_wrap *r)
523 {
524         return ndr_pull_mapi_SPropValue_array(ndr, NDR_SCALARS, (struct mapi_SPropValue_array *)r);
525 }
526
527 void ndr_print_mapi_SPropValue_array_wrap(struct ndr_print *ndr, const char *name, const struct mapi_SPropValue_array_wrap *r)
528 {
529         return ndr_print_mapi_SPropValue_array(ndr, name, (const struct mapi_SPropValue_array *)r);
530 }
531
532 enum ndr_err_code ndr_push_RestrictionVariable(struct ndr_push *ndr, int ndr_flags, const union RestrictionVariable *r)
533 {
534         {
535                 uint32_t _flags_save_STRUCT = ndr->flags;
536                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
537                 if (ndr_flags & NDR_SCALARS) {
538                         int level = ndr_push_get_switch_value(ndr, r);
539                         switch (level) {
540                                 case 0x0: {
541                                         break; }
542
543                                 case 0x1: {
544                                         NDR_CHECK(ndr_push_mapi_SRestriction_comment(ndr, NDR_SCALARS, &r->res[0]));
545                                 break; }
546
547                                 default:
548                                         return ndr_push_error(ndr, NDR_ERR_BAD_SWITCH, "Bad switch value %u", level);
549                         }
550                 }
551                 if (ndr_flags & NDR_BUFFERS) {
552                         int level = ndr_push_get_switch_value(ndr, r);
553                         switch (level) {
554                                 case 0x0:
555                                 break;
556
557                                 case 0x1:
558                                         if (r->res) {
559                                                 NDR_CHECK(ndr_push_mapi_SRestriction_comment(ndr, NDR_BUFFERS, &r->res[0]));
560                                         }
561                                 break;
562
563                                 default:
564                                         return ndr_push_error(ndr, NDR_ERR_BAD_SWITCH, "Bad switch value %u", level);
565                         }
566                 }
567                 ndr->flags = _flags_save_STRUCT;
568         }
569         return NDR_ERR_SUCCESS;
570 }
571
572 enum ndr_err_code  ndr_pull_RestrictionVariable(struct ndr_pull *ndr, int ndr_flags, union RestrictionVariable *r)
573 {
574         int level;
575         TALLOC_CTX *_mem_save_res_0;
576         level = ndr_pull_get_switch_value(ndr, r);
577         {
578                 uint32_t _flags_save_STRUCT = ndr->flags;
579                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
580
581                 if (ndr_flags & NDR_SCALARS) {
582                         switch (level) {
583                                 case 0x0: {
584                                 break; }
585
586                                 case 0x1: {
587                                         NDR_CHECK(ndr_pull_align(ndr, 4));
588                                         NDR_PULL_ALLOC_N(ndr, r->res, 1);
589                                         _mem_save_res_0 = NDR_PULL_GET_MEM_CTX(ndr);
590                                         NDR_PULL_SET_MEM_CTX(ndr, r->res, 0);
591                                         NDR_CHECK(ndr_pull_mapi_SRestriction_comment(ndr, NDR_SCALARS, &r->res[0]));
592                                         NDR_PULL_SET_MEM_CTX(ndr, _mem_save_res_0, 0);
593                                 break; }
594
595                                 default:
596                                         return ndr_pull_error(ndr, NDR_ERR_BAD_SWITCH, "Bad switch value %u", level);
597                         }
598                 }
599                 if (ndr_flags & NDR_BUFFERS) {
600                         switch (level) {
601                                 case 0x0:
602                                 break;
603
604                                 case 0x1:
605                                         if (r->res) {
606                                                 _mem_save_res_0 = NDR_PULL_GET_MEM_CTX(ndr);
607                                                 NDR_PULL_SET_MEM_CTX(ndr, r->res, 0);
608                                                 NDR_CHECK(ndr_pull_mapi_SRestriction_comment(ndr, NDR_BUFFERS, &r->res[0]));
609                                                 NDR_PULL_SET_MEM_CTX(ndr, _mem_save_res_0, 0);
610                                 break; }
611
612                                 default:
613                                         return ndr_pull_error(ndr, NDR_ERR_BAD_SWITCH, "Bad switch value %u", level);
614                         }
615                 }
616                 ndr->flags = _flags_save_STRUCT;
617         }
618         return NDR_ERR_SUCCESS;
619 }
620
621
622 _PUBLIC_ void ndr_print_RestrictionVariable(struct ndr_print *ndr, const char *name, const union RestrictionVariable *r)
623 {
624         int level;
625         level = ndr_print_get_switch_value(ndr, r);
626         ndr_print_union(ndr, name, level, "RestrictionVariable");
627         switch (level) {
628                 case 0x0:
629                 break;
630
631                 case 0x1:
632                         ndr_print_ptr(ndr, "res", r->res);
633                         ndr->depth++;
634                         if (r->res) {
635                                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
636                                 ndr_print_mapi_SRestriction_comment(ndr, "res", &r->res[0]);
637                         }
638                         ndr->depth--;
639                 break;
640         }
641 }
642
643 enum ndr_err_code ndr_push_Release_req(struct ndr_push *ndr, int ndr_flags, const struct Release_req *r)
644 {
645         return NDR_ERR_SUCCESS;
646 }
647
648 enum ndr_err_code ndr_pull_Release_req(struct ndr_pull *ndr, int ndr_flags, struct Release_req *r)
649 {
650         return NDR_ERR_SUCCESS;
651 }
652
653 enum ndr_err_code ndr_push_Release_repl(struct ndr_push *ndr, int ndr_flags, const struct Release_repl *r)
654 {
655         return NDR_ERR_SUCCESS;
656 }
657
658 enum ndr_err_code ndr_pull_Release_repl(struct ndr_pull *ndr, int ndr_flags, struct Release_repl *r)
659 {
660         return NDR_ERR_SUCCESS;
661 }