Removed 'extern int DEBUGLEVEL' as it is now in the smb.h header.
[metze/samba/wip.git] / source3 / rpc_parse / parse_lsa.c
1 /* 
2  *  Unix SMB/Netbios implementation.
3  *  Version 1.9.
4  *  RPC Pipe client / server routines
5  *  Copyright (C) Andrew Tridgell              1992-1997,
6  *  Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
7  *  Copyright (C) Paul Ashton                       1997.
8  *  
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 2 of the License, or
12  *  (at your option) any later version.
13  *  
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *  
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, write to the Free Software
21  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  */
23
24 #include "includes.h"
25
26 static BOOL lsa_io_trans_names(char *desc, LSA_TRANS_NAME_ENUM *trn, prs_struct *ps, int depth);
27
28 /*******************************************************************
29  Inits a LSA_TRANS_NAME structure.
30 ********************************************************************/
31
32 void init_lsa_trans_name(LSA_TRANS_NAME *trn, UNISTR2 *uni_name,
33                          uint16 sid_name_use, char *name, uint32 idx)
34 {
35         int len_name = strlen(name);
36
37         if(len_name == 0)
38                 len_name = 1;
39
40         trn->sid_name_use = sid_name_use;
41         init_uni_hdr(&trn->hdr_name, len_name);
42         init_unistr2(uni_name, name, len_name);
43         trn->domain_idx = idx;
44 }
45
46 /*******************************************************************
47  Reads or writes a LSA_TRANS_NAME structure.
48 ********************************************************************/
49
50 static BOOL lsa_io_trans_name(char *desc, LSA_TRANS_NAME *trn, prs_struct *ps, 
51                               int depth)
52 {
53         prs_debug(ps, depth, desc, "lsa_io_trans_name");
54         depth++;
55
56         if(!prs_align(ps))
57                 return False;
58         
59         if(!prs_uint16("sid_name_use", ps, depth, &trn->sid_name_use))
60                 return False;
61         if(!prs_align(ps))
62                 return False;
63         
64         if(!smb_io_unihdr ("hdr_name", &trn->hdr_name, ps, depth))
65                 return False;
66         if(!prs_uint32("domain_idx  ", ps, depth, &trn->domain_idx))
67                 return False;
68
69         return True;
70 }
71
72 /*******************************************************************
73  Reads or writes a DOM_R_REF structure.
74 ********************************************************************/
75
76 static BOOL lsa_io_dom_r_ref(char *desc, DOM_R_REF *r_r, prs_struct *ps, 
77                              int depth)
78 {
79         int i;
80
81         prs_debug(ps, depth, desc, "lsa_io_dom_r_ref");
82         depth++;
83
84         if(!prs_align(ps))
85                 return False;
86         
87         if(!prs_uint32("num_ref_doms_1", ps, depth, &r_r->num_ref_doms_1)) /* num referenced domains? */
88                 return False;
89         if(!prs_uint32("ptr_ref_dom   ", ps, depth, &r_r->ptr_ref_dom)) /* undocumented buffer pointer. */
90                 return False;
91         if(!prs_uint32("max_entries   ", ps, depth, &r_r->max_entries)) /* 32 - max number of entries */
92                 return False;
93
94         SMB_ASSERT_ARRAY(r_r->hdr_ref_dom, r_r->num_ref_doms_1);
95
96         if (r_r->ptr_ref_dom != 0) {
97
98                 if(!prs_uint32("num_ref_doms_2", ps, depth, &r_r->num_ref_doms_2)) /* 4 - num referenced domains? */
99                         return False;
100
101                 SMB_ASSERT_ARRAY(r_r->ref_dom, r_r->num_ref_doms_2);
102
103                 for (i = 0; i < r_r->num_ref_doms_1; i++) {
104                         fstring t;
105
106                         slprintf(t, sizeof(t) - 1, "dom_ref[%d] ", i);
107                         if(!smb_io_unihdr(t, &r_r->hdr_ref_dom[i].hdr_dom_name, ps, depth))
108                                 return False;
109
110                         slprintf(t, sizeof(t) - 1, "sid_ptr[%d] ", i);
111                         if(!prs_uint32(t, ps, depth, &r_r->hdr_ref_dom[i].ptr_dom_sid))
112                                 return False;
113                 }
114
115                 for (i = 0; i < r_r->num_ref_doms_2; i++) {
116                         fstring t;
117
118                         if (r_r->hdr_ref_dom[i].hdr_dom_name.buffer != 0) {
119                                 slprintf(t, sizeof(t) - 1, "dom_ref[%d] ", i);
120                                 if(!smb_io_unistr2(t, &r_r->ref_dom[i].uni_dom_name, True, ps, depth)) /* domain name unicode string */
121                                         return False;
122                                 if(!prs_align(ps))
123                                         return False;
124                         }
125
126                         if (r_r->hdr_ref_dom[i].ptr_dom_sid != 0) {
127                                 slprintf(t, sizeof(t) - 1, "sid_ptr[%d] ", i);
128                                 if(!smb_io_dom_sid2(t, &r_r->ref_dom[i].ref_dom, ps, depth)) /* referenced domain SIDs */
129                                         return False;
130                         }
131                 }
132         }
133
134         return True;
135 }
136
137 /*******************************************************************
138  Inits an LSA_SEC_QOS structure.
139 ********************************************************************/
140
141 void init_lsa_sec_qos(LSA_SEC_QOS *qos, uint16 imp_lev, uint8 ctxt, uint8 eff,
142                       uint32 unknown)
143 {
144         DEBUG(5, ("init_lsa_sec_qos\n"));
145
146         qos->len = 0x0c; /* length of quality of service block, in bytes */
147         qos->sec_imp_level = imp_lev;
148         qos->sec_ctxt_mode = ctxt;
149         qos->effective_only = eff;
150         qos->unknown = unknown;
151 }
152
153 /*******************************************************************
154  Reads or writes an LSA_SEC_QOS structure.
155 ********************************************************************/
156
157 static BOOL lsa_io_sec_qos(char *desc,  LSA_SEC_QOS *qos, prs_struct *ps, 
158                            int depth)
159 {
160         uint32 start;
161
162         prs_debug(ps, depth, desc, "lsa_io_obj_qos");
163         depth++;
164
165         if(!prs_align(ps))
166                 return False;
167         
168         start = prs_offset(ps);
169
170         /* these pointers had _better_ be zero, because we don't know
171            what they point to!
172          */
173         if(!prs_uint32("len           ", ps, depth, &qos->len)) /* 0x18 - length (in bytes) inc. the length field. */
174                 return False;
175         if(!prs_uint16("sec_imp_level ", ps, depth, &qos->sec_imp_level ))
176                 return False;
177         if(!prs_uint8 ("sec_ctxt_mode ", ps, depth, &qos->sec_ctxt_mode ))
178                 return False;
179         if(!prs_uint8 ("effective_only", ps, depth, &qos->effective_only))
180                 return False;
181         if(!prs_uint32("unknown       ", ps, depth, &qos->unknown))
182                 return False;
183
184         if (qos->len != prs_offset(ps) - start) {
185                 DEBUG(3,("lsa_io_sec_qos: length %x does not match size %x\n",
186                          qos->len, prs_offset(ps) - start));
187                 return False;
188         }
189
190         return True;
191 }
192
193 /*******************************************************************
194  Inits an LSA_OBJ_ATTR structure.
195 ********************************************************************/
196
197 void init_lsa_obj_attr(LSA_OBJ_ATTR *attr, uint32 attributes, LSA_SEC_QOS *qos)
198 {
199         DEBUG(5, ("init_lsa_obj_attr\n"));
200
201         attr->len = 0x18; /* length of object attribute block, in bytes */
202         attr->ptr_root_dir = 0;
203         attr->ptr_obj_name = 0;
204         attr->attributes = attributes;
205         attr->ptr_sec_desc = 0;
206         
207         if (qos != NULL) {
208                 attr->ptr_sec_qos = 1;
209                 attr->sec_qos = qos;
210         } else {
211                 attr->ptr_sec_qos = 0;
212                 attr->sec_qos = NULL;
213         }
214 }
215
216 /*******************************************************************
217  Reads or writes an LSA_OBJ_ATTR structure.
218 ********************************************************************/
219
220 static BOOL lsa_io_obj_attr(char *desc, LSA_OBJ_ATTR *attr, prs_struct *ps, 
221                             int depth)
222 {
223         uint32 start;
224
225         prs_debug(ps, depth, desc, "lsa_io_obj_attr");
226         depth++;
227
228         if(!prs_align(ps))
229                 return False;
230         
231         start = prs_offset(ps);
232
233         /* these pointers had _better_ be zero, because we don't know
234            what they point to!
235          */
236         if(!prs_uint32("len         ", ps, depth, &attr->len)) /* 0x18 - length (in bytes) inc. the length field. */
237                 return False;
238         if(!prs_uint32("ptr_root_dir", ps, depth, &attr->ptr_root_dir)) /* 0 - root directory (pointer) */
239                 return False;
240         if(!prs_uint32("ptr_obj_name", ps, depth, &attr->ptr_obj_name)) /* 0 - object name (pointer) */
241                 return False;
242         if(!prs_uint32("attributes  ", ps, depth, &attr->attributes)) /* 0 - attributes (undocumented) */
243                 return False;
244         if(!prs_uint32("ptr_sec_desc", ps, depth, &attr->ptr_sec_desc)) /* 0 - security descriptior (pointer) */
245                 return False;
246         if(!prs_uint32("ptr_sec_qos ", ps, depth, &attr->ptr_sec_qos )) /* security quality of service (pointer) */
247                 return False;
248
249         if (attr->len != prs_offset(ps) - start) {
250                 DEBUG(3,("lsa_io_obj_attr: length %x does not match size %x\n",
251                          attr->len, prs_offset(ps) - start));
252                 return False;
253         }
254
255         if (attr->ptr_sec_qos != 0 && attr->sec_qos != NULL) {
256                 if(!lsa_io_sec_qos("sec_qos", attr->sec_qos, ps, depth))
257                         return False;
258         }
259
260         return True;
261 }
262
263
264 /*******************************************************************
265  Inits an LSA_Q_OPEN_POL structure.
266 ********************************************************************/
267
268 void init_q_open_pol(LSA_Q_OPEN_POL *r_q, uint16 system_name,
269                      uint32 attributes, uint32 desired_access,
270                      LSA_SEC_QOS *qos)
271 {
272         DEBUG(5, ("init_open_pol: attr:%d da:%d\n", attributes, 
273                   desired_access));
274
275         r_q->ptr = 1; /* undocumented pointer */
276
277         if (qos == NULL)
278                 r_q->des_access = desired_access;
279
280         r_q->system_name = system_name;
281         init_lsa_obj_attr(&r_q->attr, attributes, qos);
282 }
283
284 /*******************************************************************
285  Reads or writes an LSA_Q_OPEN_POL structure.
286 ********************************************************************/
287
288 BOOL lsa_io_q_open_pol(char *desc, LSA_Q_OPEN_POL *r_q, prs_struct *ps, 
289                        int depth)
290 {
291         prs_debug(ps, depth, desc, "lsa_io_q_open_pol");
292         depth++;
293
294         if(!prs_uint32("ptr       ", ps, depth, &r_q->ptr))
295                 return False;
296         if(!prs_uint16("system_name", ps, depth, &r_q->system_name))
297                 return False;
298         if(!prs_align( ps ))
299                 return False;
300
301         if(!lsa_io_obj_attr("", &r_q->attr, ps, depth))
302                 return False;
303
304         if (r_q->attr.ptr_sec_qos == 0) {
305                 if(!prs_uint32("des_access", ps, depth, &r_q->des_access))
306                         return False;
307         }
308
309         return True;
310 }
311
312 /*******************************************************************
313  Reads or writes an LSA_R_OPEN_POL structure.
314 ********************************************************************/
315
316 BOOL lsa_io_r_open_pol(char *desc, LSA_R_OPEN_POL *r_p, prs_struct *ps, 
317                        int depth)
318 {
319         prs_debug(ps, depth, desc, "lsa_io_r_open_pol");
320         depth++;
321
322         if(!smb_io_pol_hnd("", &r_p->pol, ps, depth))
323                 return False;
324
325         if(!prs_ntstatus("status", ps, depth, &r_p->status))
326                 return False;
327
328         return True;
329 }
330
331 /*******************************************************************
332  Inits an LSA_Q_OPEN_POL2 structure.
333 ********************************************************************/
334
335 void init_q_open_pol2(LSA_Q_OPEN_POL2 *r_q, char *server_name,
336                         uint32 attributes, uint32 desired_access,
337                         LSA_SEC_QOS *qos)
338 {
339         DEBUG(5, ("init_q_open_pol2: attr:%d da:%d\n", attributes, 
340                   desired_access));
341
342         r_q->ptr = 1; /* undocumented pointer */
343
344         if (qos == NULL)
345                 r_q->des_access = desired_access;
346
347         init_unistr2(&r_q->uni_server_name, server_name, 
348                      strlen(server_name) + 1);
349
350         init_lsa_obj_attr(&r_q->attr, attributes, qos);
351 }
352
353 /*******************************************************************
354  Reads or writes an LSA_Q_OPEN_POL2 structure.
355 ********************************************************************/
356
357 BOOL lsa_io_q_open_pol2(char *desc, LSA_Q_OPEN_POL2 *r_q, prs_struct *ps, 
358                         int depth)
359 {
360         prs_debug(ps, depth, desc, "lsa_io_q_open_pol2");
361         depth++;
362
363         if(!prs_uint32("ptr       ", ps, depth, &r_q->ptr))
364                 return False;
365
366         if(!smb_io_unistr2 ("", &r_q->uni_server_name, r_q->ptr, ps, depth))
367                 return False;
368         if(!lsa_io_obj_attr("", &r_q->attr, ps, depth))
369                 return False;
370
371         if (r_q->attr.ptr_sec_qos == 0) {
372                 if(!prs_uint32("des_access", ps, depth, &r_q->des_access))
373                         return False;
374         }
375
376         return True;
377 }
378
379 /*******************************************************************
380  Reads or writes an LSA_R_OPEN_POL2 structure.
381 ********************************************************************/
382
383 BOOL lsa_io_r_open_pol2(char *desc, LSA_R_OPEN_POL2 *r_p, prs_struct *ps, 
384                         int depth)
385 {
386         prs_debug(ps, depth, desc, "lsa_io_r_open_pol2");
387         depth++;
388
389         if(!smb_io_pol_hnd("", &r_p->pol, ps, depth))
390                 return False;
391
392         if(!prs_ntstatus("status", ps, depth, &r_p->status))
393                 return False;
394
395         return True;
396 }
397
398 /*******************************************************************
399 makes an LSA_Q_QUERY_SEC_OBJ structure.
400 ********************************************************************/
401
402 void init_q_query_sec_obj(LSA_Q_QUERY_SEC_OBJ *q_q, const POLICY_HND *hnd, 
403                           uint32 sec_info)
404 {
405         DEBUG(5, ("init_q_query_sec_obj\n"));
406
407         q_q->pol = *hnd;
408         q_q->sec_info = sec_info;
409
410         return;
411 }
412
413 /*******************************************************************
414  Reads or writes an LSA_Q_QUERY_SEC_OBJ structure.
415 ********************************************************************/
416
417 BOOL lsa_io_q_query_sec_obj(char *desc, LSA_Q_QUERY_SEC_OBJ *q_q, 
418                             prs_struct *ps, int depth)
419 {
420         prs_debug(ps, depth, desc, "lsa_io_q_query_sec_obj");
421         depth++;
422
423         if (!smb_io_pol_hnd("", &q_q->pol, ps, depth))
424                 return False;
425
426         if (!prs_uint32("sec_info", ps, depth, &q_q->sec_info))
427                 return False;
428
429         return True;
430
431
432 /*******************************************************************
433  Reads or writes a LSA_R_QUERY_SEC_OBJ structure.
434 ********************************************************************/
435
436 BOOL lsa_io_r_query_sec_obj(char *desc, LSA_R_QUERY_SEC_OBJ *r_u, 
437                             prs_struct *ps, int depth)
438 {
439         prs_debug(ps, depth, desc, "lsa_io_r_query_sec_obj");
440         depth++;
441
442         if (!prs_align(ps))
443                 return False;
444
445         if (!prs_uint32("ptr", ps, depth, &r_u->ptr))
446                 return False;
447
448         if (r_u->ptr != 0) {
449                 if (!sec_io_desc_buf("sec", &r_u->buf, ps, depth))
450                         return False;
451         }
452
453         if (!prs_ntstatus("status", ps, depth, &r_u->status))
454                 return False;
455
456         return True;
457 }
458
459 /*******************************************************************
460  Inits an LSA_Q_QUERY_INFO structure.
461 ********************************************************************/
462
463 void init_q_query(LSA_Q_QUERY_INFO *q_q, POLICY_HND *hnd, uint16 info_class)
464 {
465         DEBUG(5, ("init_q_query\n"));
466
467         memcpy(&q_q->pol, hnd, sizeof(q_q->pol));
468
469         q_q->info_class = info_class;
470 }
471
472 /*******************************************************************
473  Reads or writes an LSA_Q_QUERY_INFO structure.
474 ********************************************************************/
475
476 BOOL lsa_io_q_query(char *desc, LSA_Q_QUERY_INFO *q_q, prs_struct *ps, 
477                     int depth)
478 {
479         prs_debug(ps, depth, desc, "lsa_io_q_query");
480         depth++;
481
482         if(!smb_io_pol_hnd("", &q_q->pol, ps, depth))
483                 return False;
484
485         if(!prs_uint16("info_class", ps, depth, &q_q->info_class))
486                 return False;
487
488         return True;
489 }
490
491 /*******************************************************************
492 makes an LSA_Q_ENUM_TRUST_DOM structure.
493 ********************************************************************/
494 BOOL init_q_enum_trust_dom(LSA_Q_ENUM_TRUST_DOM * q_e, POLICY_HND *pol,
495                            uint32 enum_context, uint32 preferred_len)
496 {
497         DEBUG(5, ("init_q_enum_trust_dom\n"));
498
499         q_e->pol = *pol;
500         q_e->enum_context = enum_context;
501         q_e->preferred_len = preferred_len;
502
503         return True;
504 }
505
506 /*******************************************************************
507  Reads or writes an LSA_Q_ENUM_TRUST_DOM structure.
508 ********************************************************************/
509
510 BOOL lsa_io_q_enum_trust_dom(char *desc, LSA_Q_ENUM_TRUST_DOM *q_e, 
511                              prs_struct *ps, int depth)
512 {
513         prs_debug(ps, depth, desc, "lsa_io_q_enum_trust_dom");
514         depth++;
515
516         if(!smb_io_pol_hnd("", &q_e->pol, ps, depth))
517                 return False;
518
519         if(!prs_uint32("enum_context ", ps, depth, &q_e->enum_context))
520                 return False;
521         if(!prs_uint32("preferred_len", ps, depth, &q_e->preferred_len))
522                 return False;
523
524         return True;
525 }
526
527 /*******************************************************************
528  Inits an LSA_R_ENUM_TRUST_DOM structure.
529 ********************************************************************/
530
531 void init_r_enum_trust_dom(TALLOC_CTX *ctx, LSA_R_ENUM_TRUST_DOM *r_e, uint32 enum_context, 
532                            char *domain_name, DOM_SID *domain_sid,
533                            NTSTATUS status)
534 {
535         DEBUG(5, ("init_r_enum_trust_dom\n"));
536         
537         r_e->enum_context = enum_context;
538         
539         if (NT_STATUS_IS_OK(status)) {
540                 int len_domain_name = strlen(domain_name) + 1;
541                 
542                 r_e->num_domains  = 1;
543                 r_e->ptr_enum_domains = 1;
544                 r_e->num_domains2 = 1;
545                 
546                 if (!(r_e->hdr_domain_name = (UNIHDR2 *)talloc(ctx,sizeof(UNIHDR2))))
547                         return;
548
549                 if (!(r_e->uni_domain_name = (UNISTR2 *)talloc(ctx,sizeof(UNISTR2))))
550                         return;
551
552                 if (!(r_e->domain_sid = (DOM_SID2 *)talloc(ctx,sizeof(DOM_SID2))))
553                         return;
554
555                 init_uni_hdr2(&r_e->hdr_domain_name[0], len_domain_name);
556                 init_unistr2 (&r_e->uni_domain_name[0], domain_name, 
557                               len_domain_name);
558                 init_dom_sid2(&r_e->domain_sid[0], domain_sid);
559         } else {
560                 r_e->num_domains = 0;
561                 r_e->ptr_enum_domains = 0;
562         }
563         
564         r_e->status = status;
565 }
566
567 /*******************************************************************
568  Reads or writes an LSA_R_ENUM_TRUST_DOM structure.
569 ********************************************************************/
570
571 BOOL lsa_io_r_enum_trust_dom(char *desc, LSA_R_ENUM_TRUST_DOM *r_e, 
572                              prs_struct *ps, int depth)
573 {
574         prs_debug(ps, depth, desc, "lsa_io_r_enum_trust_dom");
575         depth++;
576
577         if(!prs_uint32("enum_context    ", ps, depth, &r_e->enum_context))
578                 return False;
579         if(!prs_uint32("num_domains     ", ps, depth, &r_e->num_domains))
580                 return False;
581         if(!prs_uint32("ptr_enum_domains", ps, depth, &r_e->ptr_enum_domains))
582                 return False;
583
584         if (r_e->ptr_enum_domains) {
585                 int i, num_domains;
586
587                 if(!prs_uint32("num_domains2", ps, depth, &r_e->num_domains2))
588                         return False;
589
590                 num_domains = r_e->num_domains2;
591
592                 if (UNMARSHALLING(ps)) {
593                         if (!(r_e->hdr_domain_name = (UNIHDR2 *)prs_alloc_mem(ps,sizeof(UNIHDR2) * num_domains)))
594                                 return False;
595
596                         if (!(r_e->uni_domain_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2) * num_domains)))
597                                 return False;
598
599                         if (!(r_e->domain_sid = (DOM_SID2 *)prs_alloc_mem(ps,sizeof(DOM_SID2) * num_domains)))
600                                 return False;
601                 }
602
603                 for (i = 0; i < num_domains; i++) {
604                         if(!smb_io_unihdr2 ("", &r_e->hdr_domain_name[i], ps, 
605                                             depth))
606                                 return False;
607                 }
608                 
609                 for (i = 0; i < num_domains; i++) {
610                         if(!smb_io_unistr2 ("", &r_e->uni_domain_name[i],
611                                             r_e->hdr_domain_name[i].buffer, 
612                                             ps, depth))
613                                 return False;
614                         if(!smb_io_dom_sid2("", &r_e->domain_sid[i], ps, 
615                                             depth))
616                                 return False;
617                 }
618         }
619
620         if(!prs_ntstatus("status", ps, depth, &r_e->status))
621                 return False;
622
623         return True;
624 }
625
626 /*******************************************************************
627 reads or writes a dom query structure.
628 ********************************************************************/
629
630 static BOOL lsa_io_dom_query(char *desc, DOM_QUERY *d_q, prs_struct *ps, int depth)
631 {
632         if (d_q == NULL)
633                 return False;
634
635         prs_debug(ps, depth, desc, "lsa_io_dom_query");
636         depth++;
637
638         if(!prs_align(ps))
639                 return False;
640
641         if(!prs_uint16("uni_dom_max_len", ps, depth, &d_q->uni_dom_max_len)) /* domain name string length * 2 */
642                 return False;
643         if(!prs_uint16("uni_dom_str_len", ps, depth, &d_q->uni_dom_str_len)) /* domain name string length * 2 */
644                 return False;
645
646         if(!prs_uint32("buffer_dom_name", ps, depth, &d_q->buffer_dom_name)) /* undocumented domain name string buffer pointer */
647                 return False;
648         if(!prs_uint32("buffer_dom_sid ", ps, depth, &d_q->buffer_dom_sid)) /* undocumented domain SID string buffer pointer */
649                 return False;
650
651         if(!smb_io_unistr2("unistr2", &d_q->uni_domain_name, d_q->buffer_dom_name, ps, depth)) /* domain name (unicode string) */
652                 return False;
653
654         if(!prs_align(ps))
655                 return False;
656
657         if (d_q->buffer_dom_sid != 0) {
658                 if(!smb_io_dom_sid2("", &d_q->dom_sid, ps, depth)) /* domain SID */
659                         return False;
660         } else {
661                 memset((char *)&d_q->dom_sid, '\0', sizeof(d_q->dom_sid));
662         }
663
664         return True;
665 }
666
667 /*******************************************************************
668 reads or writes a structure.
669 ********************************************************************/
670
671 static BOOL lsa_io_dom_query_2(char *desc, DOM_QUERY_2 *d_q, prs_struct *ps, int depth)
672 {
673         uint32 ptr = 1;
674
675         if (d_q == NULL)
676                 return False;
677
678         prs_debug(ps, depth, desc, "lsa_io_dom_query_2");
679         depth++;
680
681         if (!prs_align(ps))
682                 return False;
683
684         if (!prs_uint32("auditing_enabled", ps, depth, &d_q->auditing_enabled))
685                 return False;
686         if (!prs_uint32("ptr   ", ps, depth, &ptr))
687                 return False;
688         if (!prs_uint32("count1", ps, depth, &d_q->count1))
689                 return False;
690         if (!prs_uint32("count2", ps, depth, &d_q->count2))
691                 return False;
692
693         if (UNMARSHALLING(ps)) {
694                 d_q->auditsettings = (uint32 *)talloc_zero(ps->mem_ctx, d_q->count2 * sizeof(uint32));
695         }
696
697         if (d_q->auditsettings == NULL) {
698                 DEBUG(1, ("lsa_io_dom_query_2: NULL auditsettings!\n"));
699                 return False;
700         }
701
702         if (!prs_uint32s(False, "auditsettings", ps, depth, d_q->auditsettings, d_q->count2))
703                 return False;
704
705     return True;
706 }
707
708 /*******************************************************************
709  Reads or writes a dom query structure.
710 ********************************************************************/
711
712 static BOOL lsa_io_dom_query_3(char *desc, DOM_QUERY_3 *d_q, prs_struct *ps, int depth)
713 {
714         return lsa_io_dom_query("", d_q, ps, depth);
715 }
716
717 /*******************************************************************
718  Reads or writes a dom query structure.
719 ********************************************************************/
720
721 BOOL lsa_io_dom_query_5(char *desc, DOM_QUERY_5 *d_q, prs_struct *ps, int depth)
722 {
723         return lsa_io_dom_query("", d_q, ps, depth);
724 }
725
726 /*******************************************************************
727  Reads or writes a dom query structure.
728 ********************************************************************/
729
730 static BOOL lsa_io_dom_query_6(char *desc, DOM_QUERY_6 *d_q, prs_struct *ps, int depth)
731 {
732         if (d_q == NULL)
733                 return False;
734
735         prs_debug(ps, depth, desc, "lsa_io_dom_query_6");
736         depth++;
737
738         if (!prs_uint16("server_role", ps, depth, &d_q->server_role))
739                 return False;
740
741         return True;
742 }
743
744 /*******************************************************************
745  Reads or writes an LSA_R_QUERY_INFO structure.
746 ********************************************************************/
747
748 BOOL lsa_io_r_query(char *desc, LSA_R_QUERY_INFO *r_q, prs_struct *ps,
749                     int depth)
750 {
751         prs_debug(ps, depth, desc, "lsa_io_r_query");
752         depth++;
753
754         if(!prs_uint32("undoc_buffer", ps, depth, &r_q->undoc_buffer))
755                 return False;
756
757         if (r_q->undoc_buffer != 0) {
758                 if(!prs_uint16("info_class", ps, depth, &r_q->info_class))
759                         return False;
760
761                 if(!prs_align(ps))
762                         return False;
763
764                 switch (r_q->info_class) {
765                 case 2:
766                         if(!lsa_io_dom_query_2("", &r_q->dom.id2, ps, depth))
767                                 return False;
768                         break;
769                 case 3:
770                         if(!lsa_io_dom_query_3("", &r_q->dom.id3, ps, depth))
771                                 return False;
772                         break;
773                 case 5:
774                         if(!lsa_io_dom_query_5("", &r_q->dom.id5, ps, depth))
775                                 return False;
776                         break;
777                 case 6:
778                         if(!lsa_io_dom_query_6("", &r_q->dom.id6, ps, depth))
779                                 return False;
780                         break;
781                 default:
782                         /* PANIC! */
783                         break;
784                 }
785         }
786
787         if(!prs_align(ps))
788                 return False;
789
790         if(!prs_ntstatus("status", ps, depth, &r_q->status))
791                 return False;
792
793         return True;
794 }
795
796 /*******************************************************************
797  Inits a LSA_SID_ENUM structure.
798 ********************************************************************/
799
800 void init_lsa_sid_enum(TALLOC_CTX *mem_ctx, LSA_SID_ENUM *sen, 
801                        int num_entries, DOM_SID *sids)
802 {
803         int i;
804
805         DEBUG(5, ("init_lsa_sid_enum\n"));
806
807         sen->num_entries  = num_entries;
808         sen->ptr_sid_enum = (num_entries != 0);
809         sen->num_entries2 = num_entries;
810
811         /* Allocate memory for sids and sid pointers */
812
813         if (num_entries == 0) return;
814
815         if ((sen->ptr_sid = (uint32 *)talloc_zero(mem_ctx, num_entries * 
816                                              sizeof(uint32))) == NULL) {
817                 DEBUG(3, ("init_lsa_sid_enum(): out of memory for ptr_sid\n"));
818                 return;
819         }
820
821         if ((sen->sid = (DOM_SID2 *)talloc_zero(mem_ctx, num_entries * 
822                                            sizeof(DOM_SID2))) == NULL) {
823                 DEBUG(3, ("init_lsa_sid_enum(): out of memory for sids\n"));
824                 return;
825         }
826
827         /* Copy across SIDs and SID pointers */
828
829         for (i = 0; i < num_entries; i++) {
830                 sen->ptr_sid[i] = 1;
831                 init_dom_sid2(&sen->sid[i], &sids[i]);
832         }
833 }
834
835 /*******************************************************************
836  Reads or writes a LSA_SID_ENUM structure.
837 ********************************************************************/
838
839 static BOOL lsa_io_sid_enum(char *desc, LSA_SID_ENUM *sen, prs_struct *ps, 
840                             int depth)
841 {
842         int i;
843
844         prs_debug(ps, depth, desc, "lsa_io_sid_enum");
845         depth++;
846
847         if(!prs_align(ps))
848                 return False;
849         
850         if(!prs_uint32("num_entries ", ps, depth, &sen->num_entries))
851                 return False;
852         if(!prs_uint32("ptr_sid_enum", ps, depth, &sen->ptr_sid_enum))
853                 return False;
854         if(!prs_uint32("num_entries2", ps, depth, &sen->num_entries2))
855                 return False;
856
857         /* Mallocate memory if we're unpacking from the wire */
858
859         if (UNMARSHALLING(ps)) {
860                 if ((sen->ptr_sid = (uint32 *)prs_alloc_mem( ps,
861                         sen->num_entries * sizeof(uint32))) == NULL) {
862                         DEBUG(3, ("init_lsa_sid_enum(): out of memory for "
863                                   "ptr_sid\n"));
864                         return False;
865                 }
866
867                 if ((sen->sid = (DOM_SID2 *)prs_alloc_mem( ps,
868                         sen->num_entries * sizeof(DOM_SID2))) == NULL) {
869                         DEBUG(3, ("init_lsa_sid_enum(): out of memory for "
870                                   "sids\n"));
871                         return False;
872                 }
873         }
874
875         for (i = 0; i < sen->num_entries; i++) {        
876                 fstring temp;
877
878                 slprintf(temp, sizeof(temp) - 1, "ptr_sid[%d]", i);
879                 if(!prs_uint32(temp, ps, depth, &sen->ptr_sid[i])) {
880                         return False;
881                 }
882         }
883
884         for (i = 0; i < sen->num_entries; i++) {
885                 fstring temp;
886
887                 slprintf(temp, sizeof(temp) - 1, "sid[%d]", i);
888                 if(!smb_io_dom_sid2(temp, &sen->sid[i], ps, depth)) {
889                         return False;
890                 }
891         }
892
893         return True;
894 }
895
896 /*******************************************************************
897  Inits an LSA_R_ENUM_TRUST_DOM structure.
898 ********************************************************************/
899
900 void init_q_lookup_sids(TALLOC_CTX *mem_ctx, LSA_Q_LOOKUP_SIDS *q_l, 
901                         POLICY_HND *hnd, int num_sids, DOM_SID *sids,
902                         uint16 level)
903 {
904         DEBUG(5, ("init_r_enum_trust_dom\n"));
905
906         ZERO_STRUCTP(q_l);
907
908         memcpy(&q_l->pol, hnd, sizeof(q_l->pol));
909         init_lsa_sid_enum(mem_ctx, &q_l->sids, num_sids, sids);
910         
911         q_l->level.value = level;
912 }
913
914 /*******************************************************************
915  Reads or writes a LSA_Q_LOOKUP_SIDS structure.
916 ********************************************************************/
917
918 BOOL lsa_io_q_lookup_sids(char *desc, LSA_Q_LOOKUP_SIDS *q_s, prs_struct *ps,
919                           int depth)
920 {
921         prs_debug(ps, depth, desc, "lsa_io_q_lookup_sids");
922         depth++;
923
924         if(!prs_align(ps))
925                 return False;
926         
927         if(!smb_io_pol_hnd("pol_hnd", &q_s->pol, ps, depth)) /* policy handle */
928                 return False;
929         if(!lsa_io_sid_enum("sids   ", &q_s->sids, ps, depth)) /* sids to be looked up */
930                 return False;
931         if(!lsa_io_trans_names("names  ", &q_s->names, ps, depth)) /* translated names */
932                 return False;
933         if(!smb_io_lookup_level("switch ", &q_s->level, ps, depth)) /* lookup level */
934                 return False;
935
936         if(!prs_uint32("mapped_count", ps, depth, &q_s->mapped_count))
937                 return False;
938
939         return True;
940 }
941
942 /*******************************************************************
943  Reads or writes a structure.
944 ********************************************************************/
945
946 static BOOL lsa_io_trans_names(char *desc, LSA_TRANS_NAME_ENUM *trn,
947                 prs_struct *ps, int depth)
948 {
949         int i;
950
951         prs_debug(ps, depth, desc, "lsa_io_trans_names");
952         depth++;
953
954         if(!prs_align(ps))
955                 return False;
956    
957         if(!prs_uint32("num_entries    ", ps, depth, &trn->num_entries))
958                 return False;
959         if(!prs_uint32("ptr_trans_names", ps, depth, &trn->ptr_trans_names))
960                 return False;
961
962         if (trn->ptr_trans_names != 0) {
963                 if(!prs_uint32("num_entries2   ", ps, depth, 
964                                &trn->num_entries2))
965                         return False;
966
967                 if (UNMARSHALLING(ps)) {
968                         if ((trn->name = (LSA_TRANS_NAME *)
969                              prs_alloc_mem(ps, trn->num_entries * 
970                                     sizeof(LSA_TRANS_NAME))) == NULL) {
971                                 return False;
972                         }
973
974                         if ((trn->uni_name = (UNISTR2 *)
975                              prs_alloc_mem(ps, trn->num_entries *
976                                     sizeof(UNISTR2))) == NULL) {
977                                 return False;
978                         }
979                 }
980
981                 for (i = 0; i < trn->num_entries2; i++) {
982                         fstring t;
983                         slprintf(t, sizeof(t) - 1, "name[%d] ", i);
984
985                         if(!lsa_io_trans_name(t, &trn->name[i], ps, depth)) /* translated name */
986                                 return False;
987                 }
988
989                 for (i = 0; i < trn->num_entries2; i++) {
990                         fstring t;
991                         slprintf(t, sizeof(t) - 1, "name[%d] ", i);
992
993                         if(!smb_io_unistr2(t, &trn->uni_name[i], trn->name[i].hdr_name.buffer, ps, depth))
994                                 return False;
995                         if(!prs_align(ps))
996                                 return False;
997                 }
998         }
999
1000         return True;
1001 }
1002
1003 /*******************************************************************
1004  Reads or writes a structure.
1005 ********************************************************************/
1006
1007 BOOL lsa_io_r_lookup_sids(char *desc, LSA_R_LOOKUP_SIDS *r_s, 
1008                           prs_struct *ps, int depth)
1009 {
1010         prs_debug(ps, depth, desc, "lsa_io_r_lookup_sids");
1011         depth++;
1012
1013         if(!prs_align(ps))
1014                 return False;
1015         
1016         if(!prs_uint32("ptr_dom_ref", ps, depth, &r_s->ptr_dom_ref))
1017                 return False;
1018
1019         if (r_s->ptr_dom_ref != 0)
1020                 if(!lsa_io_dom_r_ref ("dom_ref", r_s->dom_ref, ps, depth)) /* domain reference info */
1021                         return False;
1022
1023         if(!lsa_io_trans_names("names  ", r_s->names, ps, depth)) /* translated names */
1024                 return False;
1025
1026         if(!prs_align(ps))
1027                 return False;
1028
1029         if(!prs_uint32("mapped_count", ps, depth, &r_s->mapped_count))
1030                 return False;
1031
1032         if(!prs_ntstatus("status      ", ps, depth, &r_s->status))
1033                 return False;
1034
1035         return True;
1036 }
1037
1038 /*******************************************************************
1039 makes a structure.
1040 ********************************************************************/
1041
1042 void init_q_lookup_names(TALLOC_CTX *mem_ctx, LSA_Q_LOOKUP_NAMES *q_l, 
1043                          POLICY_HND *hnd, int num_names, char **names)
1044 {
1045         int i;
1046
1047         DEBUG(5, ("init_q_lookup_names\n"));
1048
1049         ZERO_STRUCTP(q_l);
1050
1051         q_l->pol = *hnd;
1052         q_l->num_entries = num_names;
1053         q_l->num_entries2 = num_names;
1054         q_l->lookup_level = 1;
1055
1056         if ((q_l->uni_name = (UNISTR2 *)talloc_zero(
1057                 mem_ctx, num_names * sizeof(UNISTR2))) == NULL) {
1058                 DEBUG(3, ("init_q_lookup_names(): out of memory\n"));
1059                 return;
1060         }
1061
1062         if ((q_l->hdr_name = (UNIHDR *)talloc_zero(
1063                 mem_ctx, num_names * sizeof(UNIHDR))) == NULL) {
1064                 DEBUG(3, ("init_q_lookup_names(): out of memory\n"));
1065                 return;
1066         }
1067
1068         for (i = 0; i < num_names; i++) {
1069                 char* name = names[i];
1070                 int len = strlen(name);
1071
1072                 init_uni_hdr(&q_l->hdr_name[i], len);
1073                 init_unistr2(&q_l->uni_name[i], name, len);
1074         }
1075 }
1076
1077 /*******************************************************************
1078 reads or writes a structure.
1079 ********************************************************************/
1080
1081 BOOL lsa_io_q_lookup_names(char *desc, LSA_Q_LOOKUP_NAMES *q_r, 
1082                            prs_struct *ps, int depth)
1083 {
1084         int i;
1085
1086         prs_debug(ps, depth, desc, "lsa_io_q_lookup_names");
1087         depth++;
1088
1089         if(!prs_align(ps))
1090                 return False;
1091
1092         if(!smb_io_pol_hnd("", &q_r->pol, ps, depth)) /* policy handle */
1093                 return False;
1094
1095         if(!prs_align(ps))
1096                 return False;
1097         if(!prs_uint32("num_entries    ", ps, depth, &q_r->num_entries))
1098                 return False;
1099         if(!prs_uint32("num_entries2   ", ps, depth, &q_r->num_entries2))
1100                 return False;
1101
1102         if (UNMARSHALLING(ps)) {
1103                 if (q_r->num_entries) {
1104                         if ((q_r->hdr_name = (UNIHDR *)prs_alloc_mem(ps,
1105                                         q_r->num_entries * sizeof(UNIHDR))) == NULL)
1106                                 return False;
1107                         if ((q_r->uni_name = (UNISTR2 *)prs_alloc_mem(ps,
1108                                         q_r->num_entries * sizeof(UNISTR2))) == NULL)
1109                                 return False;
1110                 }
1111         }
1112
1113         for (i = 0; i < q_r->num_entries; i++) {
1114                 if(!prs_align(ps))
1115                         return False;
1116                 if(!smb_io_unihdr("hdr_name", &q_r->hdr_name[i], ps, depth)) /* pointer names */
1117                         return False;
1118         }
1119
1120         for (i = 0; i < q_r->num_entries; i++) {
1121                 if(!prs_align(ps))
1122                         return False;
1123                 if(!smb_io_unistr2("dom_name", &q_r->uni_name[i], q_r->hdr_name[i].buffer, ps, depth)) /* names to be looked up */
1124                         return False;
1125         }
1126
1127         if(!prs_align(ps))
1128                 return False;
1129         if(!prs_uint32("num_trans_entries ", ps, depth, &q_r->num_trans_entries))
1130                 return False;
1131         if(!prs_uint32("ptr_trans_sids ", ps, depth, &q_r->ptr_trans_sids))
1132                 return False;
1133         if(!prs_uint32("lookup_level   ", ps, depth, &q_r->lookup_level))
1134                 return False;
1135         if(!prs_uint32("mapped_count   ", ps, depth, &q_r->mapped_count))
1136                 return False;
1137
1138         return True;
1139 }
1140
1141 /*******************************************************************
1142 reads or writes a structure.
1143 ********************************************************************/
1144
1145 BOOL lsa_io_r_lookup_names(char *desc, LSA_R_LOOKUP_NAMES *r_r, 
1146                            prs_struct *ps, int depth)
1147 {
1148         int i;
1149
1150         prs_debug(ps, depth, desc, "lsa_io_r_lookup_names");
1151         depth++;
1152
1153         if(!prs_align(ps))
1154                 return False;
1155
1156         if(!prs_uint32("ptr_dom_ref", ps, depth, &r_r->ptr_dom_ref))
1157                 return False;
1158
1159         if (r_r->ptr_dom_ref != 0)
1160                 if(!lsa_io_dom_r_ref("", r_r->dom_ref, ps, depth))
1161                         return False;
1162
1163         if(!prs_uint32("num_entries", ps, depth, &r_r->num_entries))
1164                 return False;
1165         if(!prs_uint32("ptr_entries", ps, depth, &r_r->ptr_entries))
1166                 return False;
1167
1168         if (r_r->ptr_entries != 0) {
1169                 if(!prs_uint32("num_entries2", ps, depth, &r_r->num_entries2))
1170                         return False;
1171
1172                 if (r_r->num_entries2 != r_r->num_entries) {
1173                         /* RPC fault */
1174                         return False;
1175                 }
1176
1177                 if (UNMARSHALLING(ps)) {
1178                         if ((r_r->dom_rid = (DOM_RID2 *)prs_alloc_mem(ps, r_r->num_entries2 * sizeof(DOM_RID2)))
1179                             == NULL) {
1180                                 DEBUG(3, ("lsa_io_r_lookup_names(): out of memory\n"));
1181                                 return False;
1182                         }
1183                 }
1184
1185                 for (i = 0; i < r_r->num_entries2; i++)
1186                         if(!smb_io_dom_rid2("", &r_r->dom_rid[i], ps, depth)) /* domain RIDs being looked up */
1187                                 return False;
1188         }
1189
1190         if(!prs_uint32("mapped_count", ps, depth, &r_r->mapped_count))
1191                 return False;
1192
1193         if(!prs_ntstatus("status      ", ps, depth, &r_r->status))
1194                 return False;
1195
1196         return True;
1197 }
1198
1199
1200 /*******************************************************************
1201  Inits an LSA_Q_CLOSE structure.
1202 ********************************************************************/
1203
1204 void init_lsa_q_close(LSA_Q_CLOSE *q_c, POLICY_HND *hnd)
1205 {
1206         DEBUG(5, ("init_lsa_q_close\n"));
1207
1208         memcpy(&q_c->pol, hnd, sizeof(q_c->pol));
1209 }
1210
1211 /*******************************************************************
1212  Reads or writes an LSA_Q_CLOSE structure.
1213 ********************************************************************/
1214
1215 BOOL lsa_io_q_close(char *desc, LSA_Q_CLOSE *q_c, prs_struct *ps, int depth)
1216 {
1217         prs_debug(ps, depth, desc, "lsa_io_q_close");
1218         depth++;
1219
1220         if(!smb_io_pol_hnd("", &q_c->pol, ps, depth))
1221                 return False;
1222
1223         return True;
1224 }
1225
1226 /*******************************************************************
1227  Reads or writes an LSA_R_CLOSE structure.
1228 ********************************************************************/
1229
1230 BOOL lsa_io_r_close(char *desc,  LSA_R_CLOSE *r_c, prs_struct *ps, int depth)
1231 {
1232         prs_debug(ps, depth, desc, "lsa_io_r_close");
1233         depth++;
1234
1235         if(!smb_io_pol_hnd("", &r_c->pol, ps, depth))
1236                 return False;
1237
1238         if(!prs_ntstatus("status", ps, depth, &r_c->status))
1239                 return False;
1240
1241         return True;
1242 }
1243
1244 /*******************************************************************
1245  Reads or writes an LSA_Q_OPEN_SECRET structure.
1246 ********************************************************************/
1247
1248 BOOL lsa_io_q_open_secret(char *desc, LSA_Q_OPEN_SECRET *q_c, prs_struct *ps, int depth)
1249 {
1250         prs_debug(ps, depth, desc, "lsa_io_q_open_secret");
1251         depth++;
1252
1253         /* Don't bother to read or write at present... */
1254         return True;
1255 }
1256
1257 /*******************************************************************
1258  Reads or writes an LSA_R_OPEN_SECRET structure.
1259 ********************************************************************/
1260
1261 BOOL lsa_io_r_open_secret(char *desc, LSA_R_OPEN_SECRET *r_c, prs_struct *ps, int depth)
1262 {
1263         prs_debug(ps, depth, desc, "lsa_io_r_open_secret");
1264         depth++;
1265
1266         if(!prs_align(ps))
1267                 return False;
1268    
1269         if(!prs_uint32("dummy1", ps, depth, &r_c->dummy1))
1270                 return False;
1271         if(!prs_uint32("dummy2", ps, depth, &r_c->dummy2))
1272                 return False;
1273         if(!prs_uint32("dummy3", ps, depth, &r_c->dummy3))
1274                 return False;
1275         if(!prs_uint32("dummy4", ps, depth, &r_c->dummy4))
1276                 return False;
1277         if(!prs_ntstatus("status", ps, depth, &r_c->status))
1278                 return False;
1279
1280         return True;
1281 }
1282
1283 /*******************************************************************
1284 reads or writes a structure.
1285 ********************************************************************/
1286 BOOL lsa_io_q_enum_privs(char *desc, LSA_Q_ENUM_PRIVS *q_q, prs_struct *ps, int depth)
1287 {
1288         if (q_q == NULL)
1289                 return False;
1290
1291         prs_debug(ps, depth, desc, "lsa_io_q_enum_privs");
1292         depth++;
1293
1294         if (!smb_io_pol_hnd("", &q_q->pol, ps, depth))
1295                 return False;
1296
1297         if(!prs_uint32("enum_context   ", ps, depth, &q_q->enum_context))
1298                 return False;
1299         if(!prs_uint32("pref_max_length", ps, depth, &q_q->pref_max_length))
1300                 return False;
1301
1302         return True;
1303 }
1304
1305 /*******************************************************************
1306 reads or writes a structure.
1307 ********************************************************************/
1308 static BOOL lsa_io_priv_entries(char *desc, LSA_PRIV_ENTRY *entries, uint32 count, prs_struct *ps, int depth)
1309 {
1310         uint32 i;
1311
1312         if (entries == NULL)
1313                 return False;
1314
1315         prs_debug(ps, depth, desc, "lsa_io_priv_entries");
1316         depth++;
1317
1318         if(!prs_align(ps))
1319                 return False;
1320
1321         for (i = 0; i < count; i++) {
1322                 if (!smb_io_unihdr("", &entries[i].hdr_name, ps, depth))
1323                         return False;
1324                 if(!prs_uint32("luid_low ", ps, depth, &entries[i].luid_low))
1325                         return False;
1326                 if(!prs_uint32("luid_high", ps, depth, &entries[i].luid_high))
1327                         return False;
1328         }
1329
1330         for (i = 0; i < count; i++)
1331                 if (!smb_io_unistr2("", &entries[i].name, entries[i].hdr_name.buffer, ps, depth))
1332                         return False;
1333
1334         return True;
1335 }
1336
1337 /*******************************************************************
1338  Inits an LSA_R_ENUM_PRIVS structure.
1339 ********************************************************************/
1340
1341 void init_lsa_r_enum_privs(LSA_R_ENUM_PRIVS *r_u, uint32 enum_context,
1342                           uint32 count, LSA_PRIV_ENTRY *entries)
1343 {
1344         DEBUG(5, ("init_lsa_r_enum_privs\n"));
1345
1346         r_u->enum_context=enum_context;
1347         r_u->count=count;
1348         
1349         if (entries!=NULL) {
1350                 r_u->ptr=1;
1351                 r_u->count1=count;
1352                 r_u->privs=entries;
1353         } else {
1354                 r_u->ptr=0;
1355                 r_u->count1=0;
1356                 r_u->privs=NULL;
1357         }               
1358 }
1359
1360 /*******************************************************************
1361 reads or writes a structure.
1362 ********************************************************************/
1363 BOOL lsa_io_r_enum_privs(char *desc, LSA_R_ENUM_PRIVS *r_q, prs_struct *ps, int depth)
1364 {
1365         if (r_q == NULL)
1366                 return False;
1367
1368         prs_debug(ps, depth, desc, "lsa_io_r_enum_privs");
1369         depth++;
1370
1371         if(!prs_align(ps))
1372                 return False;
1373
1374         if(!prs_uint32("enum_context", ps, depth, &r_q->enum_context))
1375                 return False;
1376         if(!prs_uint32("count", ps, depth, &r_q->count))
1377                 return False;
1378         if(!prs_uint32("ptr", ps, depth, &r_q->ptr))
1379                 return False;
1380
1381         if (r_q->ptr) {
1382                 if(!prs_uint32("count1", ps, depth, &r_q->count1))
1383                         return False;
1384
1385                 if (!lsa_io_priv_entries("", r_q->privs, r_q->count1, ps, depth))
1386                         return False;
1387         }
1388
1389         if(!prs_align(ps))
1390                 return False;
1391
1392         if(!prs_ntstatus("status", ps, depth, &r_q->status))
1393                 return False;
1394
1395         return True;
1396 }
1397
1398 /*******************************************************************
1399 reads or writes a structure.
1400 ********************************************************************/
1401 BOOL lsa_io_q_priv_get_dispname(char *desc, LSA_Q_PRIV_GET_DISPNAME *q_q, prs_struct *ps, int depth)
1402 {
1403         if (q_q == NULL)
1404                 return False;
1405
1406         prs_debug(ps, depth, desc, "lsa_io_q_priv_get_dispname");
1407         depth++;
1408
1409         if(!prs_align(ps))
1410                 return False;
1411
1412         if (!smb_io_pol_hnd("", &q_q->pol, ps, depth))
1413                 return False;
1414
1415         if (!smb_io_unihdr("hdr_name", &q_q->hdr_name, ps, depth))
1416                 return False;
1417
1418         if (!smb_io_unistr2("name", &q_q->name, q_q->hdr_name.buffer, ps, depth))
1419                 return False;
1420
1421         if(!prs_uint16("lang_id    ", ps, depth, &q_q->lang_id))
1422                 return False;
1423         if(!prs_uint16("lang_id_sys", ps, depth, &q_q->lang_id_sys))
1424                 return False;
1425
1426         return True;
1427 }
1428
1429 /*******************************************************************
1430 reads or writes a structure.
1431 ********************************************************************/
1432 BOOL lsa_io_r_priv_get_dispname(char *desc, LSA_R_PRIV_GET_DISPNAME *r_q, prs_struct *ps, int depth)
1433 {
1434         if (r_q == NULL)
1435                 return False;
1436
1437         prs_debug(ps, depth, desc, "lsa_io_r_priv_get_dispname");
1438         depth++;
1439
1440         if (!prs_align(ps))
1441                 return False;
1442
1443         if (!prs_uint32("ptr_info", ps, depth, &r_q->ptr_info))
1444                 return False;
1445
1446         if (r_q->ptr_info){
1447                 if (!smb_io_unihdr("hdr_name", &r_q->hdr_desc, ps, depth))
1448                         return False;
1449
1450                 if (!smb_io_unistr2("desc", &r_q->desc, r_q->hdr_desc.buffer, ps, depth))
1451                         return False;
1452         }
1453 /*
1454         if(!prs_align(ps))
1455                 return False;
1456 */
1457         if(!prs_uint16("lang_id", ps, depth, &r_q->lang_id))
1458                 return False;
1459
1460         if(!prs_align(ps))
1461                 return False;
1462         if(!prs_ntstatus("status", ps, depth, &r_q->status))
1463                 return False;
1464
1465         return True;
1466 }
1467
1468 /*******************************************************************
1469 reads or writes a structure.
1470 ********************************************************************/
1471 BOOL lsa_io_q_enum_accounts(char *desc, LSA_Q_ENUM_ACCOUNTS *q_q, prs_struct *ps, int depth)
1472 {
1473         if (q_q == NULL)
1474                 return False;
1475
1476         prs_debug(ps, depth, desc, "lsa_io_q_enum_accounts");
1477         depth++;
1478
1479         if (!smb_io_pol_hnd("", &q_q->pol, ps, depth))
1480                 return False;
1481
1482         if(!prs_uint32("enum_context   ", ps, depth, &q_q->enum_context))
1483                 return False;
1484         if(!prs_uint32("pref_max_length", ps, depth, &q_q->pref_max_length))
1485                 return False;
1486
1487         return True;
1488 }
1489
1490 /*******************************************************************
1491  Inits an LSA_R_ENUM_PRIVS structure.
1492 ********************************************************************/
1493
1494 void init_lsa_r_enum_accounts(LSA_R_ENUM_ACCOUNTS *r_u, uint32 enum_context)
1495 {
1496         DEBUG(5, ("init_lsa_r_enum_accounts\n"));
1497
1498         r_u->enum_context=enum_context;
1499         if (r_u->enum_context!=0) {
1500                 r_u->sids.num_entries=enum_context;
1501                 r_u->sids.ptr_sid_enum=1;
1502                 r_u->sids.num_entries2=enum_context;
1503         } else {
1504                 r_u->sids.num_entries=0;
1505                 r_u->sids.ptr_sid_enum=0;
1506                 r_u->sids.num_entries2=0;
1507         }
1508 }
1509
1510 /*******************************************************************
1511 reads or writes a structure.
1512 ********************************************************************/
1513 BOOL lsa_io_r_enum_accounts(char *desc, LSA_R_ENUM_ACCOUNTS *r_q, prs_struct *ps, int depth)
1514 {
1515         if (r_q == NULL)
1516                 return False;
1517
1518         prs_debug(ps, depth, desc, "lsa_io_r_enum_accounts");
1519         depth++;
1520
1521         if (!prs_align(ps))
1522                 return False;
1523
1524         if(!prs_uint32("enum_context", ps, depth, &r_q->enum_context))
1525                 return False;
1526
1527         if (!lsa_io_sid_enum("sids", &r_q->sids, ps, depth))
1528                 return False;
1529
1530         if (!prs_align(ps))
1531                 return False;
1532
1533         if(!prs_ntstatus("status", ps, depth, &r_q->status))
1534                 return False;
1535
1536         return True;
1537 }
1538
1539
1540 /*******************************************************************
1541  Reads or writes an LSA_Q_UNK_GET_CONNUSER structure.
1542 ********************************************************************/
1543
1544 BOOL lsa_io_q_unk_get_connuser(char *desc, LSA_Q_UNK_GET_CONNUSER *q_c, prs_struct *ps, int depth)
1545 {
1546         prs_debug(ps, depth, desc, "lsa_io_q_unk_get_connuser");
1547         depth++;
1548
1549         if(!prs_align(ps))
1550                 return False;
1551    
1552         if(!prs_uint32("ptr_srvname", ps, depth, &q_c->ptr_srvname))
1553                 return False;
1554
1555         if(!smb_io_unistr2("uni2_srvname", &q_c->uni2_srvname, q_c->ptr_srvname, ps, depth)) /* server name to be looked up */
1556                 return False;
1557
1558         if(!prs_uint32("unk1", ps, depth, &q_c->unk1))
1559                 return False;
1560         if(!prs_uint32("unk2", ps, depth, &q_c->unk2))
1561                 return False;
1562         if(!prs_uint32("unk3", ps, depth, &q_c->unk3))
1563                 return False;
1564
1565         /* Don't bother to read or write at present... */
1566         return True;
1567 }
1568
1569 /*******************************************************************
1570  Reads or writes an LSA_R_UNK_GET_CONNUSER structure.
1571 ********************************************************************/
1572
1573 BOOL lsa_io_r_unk_get_connuser(char *desc, LSA_R_UNK_GET_CONNUSER *r_c, prs_struct *ps, int depth)
1574 {
1575         prs_debug(ps, depth, desc, "lsa_io_r_unk_get_connuser");
1576         depth++;
1577
1578         if(!prs_align(ps))
1579                 return False;
1580    
1581         if(!prs_uint32("ptr_user_name", ps, depth, &r_c->ptr_user_name))
1582                 return False;
1583         if(!smb_io_unihdr("hdr_user_name", &r_c->hdr_user_name, ps, depth))
1584                 return False;
1585         if(!smb_io_unistr2("uni2_user_name", &r_c->uni2_user_name, r_c->ptr_user_name, ps, depth))
1586                 return False;
1587
1588         if (!prs_align(ps))
1589           return False;
1590         
1591         if(!prs_uint32("unk1", ps, depth, &r_c->unk1))
1592                 return False;
1593
1594         if(!prs_uint32("ptr_dom_name", ps, depth, &r_c->ptr_dom_name))
1595                 return False;
1596         if(!smb_io_unihdr("hdr_dom_name", &r_c->hdr_dom_name, ps, depth))
1597                 return False;
1598         if(!smb_io_unistr2("uni2_dom_name", &r_c->uni2_dom_name, r_c->ptr_dom_name, ps, depth))
1599                 return False;
1600
1601         if (!prs_align(ps))
1602           return False;
1603         
1604         if(!prs_ntstatus("status", ps, depth, &r_c->status))
1605                 return False;
1606
1607         return True;
1608 }
1609
1610 /*******************************************************************
1611  Reads or writes an LSA_Q_OPENACCOUNT structure.
1612 ********************************************************************/
1613
1614 BOOL lsa_io_q_open_account(char *desc, LSA_Q_OPENACCOUNT *r_c, prs_struct *ps, int depth)
1615 {
1616         prs_debug(ps, depth, desc, "lsa_io_q_open_account");
1617         depth++;
1618
1619         if(!prs_align(ps))
1620                 return False;
1621  
1622         if(!smb_io_pol_hnd("pol", &r_c->pol, ps, depth))
1623                 return False;
1624
1625         if(!smb_io_dom_sid2("", &r_c->sid, ps, depth)) /* domain SID */
1626                 return False;
1627
1628         if(!prs_uint32("access", ps, depth, &r_c->access))
1629                 return False;
1630   
1631         return True;
1632 }
1633
1634 /*******************************************************************
1635  Reads or writes an LSA_R_OPENACCOUNT structure.
1636 ********************************************************************/
1637
1638 BOOL lsa_io_r_open_account(char *desc, LSA_R_OPENACCOUNT  *r_c, prs_struct *ps, int depth)
1639 {
1640         prs_debug(ps, depth, desc, "lsa_io_r_open_account");
1641         depth++;
1642
1643         if(!prs_align(ps))
1644                 return False;
1645  
1646         if(!smb_io_pol_hnd("pol", &r_c->pol, ps, depth))
1647                 return False;
1648
1649         if(!prs_ntstatus("status", ps, depth, &r_c->status))
1650                 return False;
1651
1652         return True;
1653 }
1654
1655
1656 /*******************************************************************
1657  Reads or writes an LSA_Q_ENUMPRIVSACCOUNT structure.
1658 ********************************************************************/
1659
1660 BOOL lsa_io_q_enum_privsaccount(char *desc, LSA_Q_ENUMPRIVSACCOUNT *r_c, prs_struct *ps, int depth)
1661 {
1662         prs_debug(ps, depth, desc, "lsa_io_q_enum_privsaccount");
1663         depth++;
1664
1665         if(!prs_align(ps))
1666                 return False;
1667  
1668         if(!smb_io_pol_hnd("pol", &r_c->pol, ps, depth))
1669                 return False;
1670
1671         return True;
1672 }
1673
1674 /*******************************************************************
1675  Reads or writes an LUID structure.
1676 ********************************************************************/
1677
1678 BOOL lsa_io_luid(char *desc, LUID *r_c, prs_struct *ps, int depth)
1679 {
1680         prs_debug(ps, depth, desc, "lsa_io_luid");
1681         depth++;
1682
1683         if(!prs_align(ps))
1684                 return False;
1685  
1686         if(!prs_uint32("low", ps, depth, &r_c->low))
1687                 return False;
1688
1689         if(!prs_uint32("high", ps, depth, &r_c->high))
1690                 return False;
1691
1692         return True;
1693 }
1694
1695 /*******************************************************************
1696  Reads or writes an LUID_ATTR structure.
1697 ********************************************************************/
1698
1699 BOOL lsa_io_luid_attr(char *desc, LUID_ATTR *r_c, prs_struct *ps, int depth)
1700 {
1701         prs_debug(ps, depth, desc, "lsa_io_luid_attr");
1702         depth++;
1703
1704         if(!prs_align(ps))
1705                 return False;
1706  
1707         if (!lsa_io_luid(desc, &r_c->luid, ps, depth))
1708                 return False;
1709
1710         if(!prs_uint32("attr", ps, depth, &r_c->attr))
1711                 return False;
1712
1713         return True;
1714 }
1715
1716 /*******************************************************************
1717  Reads or writes an PRIVILEGE_SET structure.
1718 ********************************************************************/
1719
1720 BOOL lsa_io_privilege_set(char *desc, PRIVILEGE_SET *r_c, prs_struct *ps, int depth)
1721 {
1722         uint32 i;
1723
1724         prs_debug(ps, depth, desc, "lsa_io_privilege_set");
1725         depth++;
1726
1727         if(!prs_align(ps))
1728                 return False;
1729  
1730         if(!prs_uint32("count", ps, depth, &r_c->count))
1731                 return False;
1732         if(!prs_uint32("control", ps, depth, &r_c->control))
1733                 return False;
1734
1735         for (i=0; i<r_c->count; i++) {
1736                 if (!lsa_io_luid_attr(desc, &r_c->set[i], ps, depth))
1737                         return False;
1738         }
1739         
1740         return True;
1741 }
1742
1743 void init_lsa_r_enum_privsaccount(LSA_R_ENUMPRIVSACCOUNT *r_u, LUID_ATTR *set, uint32 count, uint32 control)
1744 {
1745         r_u->ptr=1;
1746         r_u->count=count;
1747         r_u->set.set=set;
1748         r_u->set.count=count;
1749         r_u->set.control=control;
1750 }
1751
1752 /*******************************************************************
1753  Reads or writes an LSA_R_ENUMPRIVSACCOUNT structure.
1754 ********************************************************************/
1755
1756 BOOL lsa_io_r_enum_privsaccount(char *desc, LSA_R_ENUMPRIVSACCOUNT *r_c, prs_struct *ps, int depth)
1757 {
1758         prs_debug(ps, depth, desc, "lsa_io_r_enum_privsaccount");
1759         depth++;
1760
1761         if(!prs_align(ps))
1762                 return False;
1763  
1764         if(!prs_uint32("ptr", ps, depth, &r_c->ptr))
1765                 return False;
1766
1767         if (r_c->ptr!=0) {
1768                 if(!prs_uint32("count", ps, depth, &r_c->count))
1769                         return False;
1770
1771                 /* malloc memory if unmarshalling here */
1772                 
1773                 if(!lsa_io_privilege_set(desc, &r_c->set, ps, depth))
1774                         return False;
1775         }
1776
1777         if(!prs_ntstatus("status", ps, depth, &r_c->status))
1778                 return False;
1779
1780         return True;
1781 }
1782
1783
1784
1785 /*******************************************************************
1786  Reads or writes an  LSA_Q_GETSYSTEMACCOUNTstructure.
1787 ********************************************************************/
1788
1789 BOOL lsa_io_q_getsystemaccount(char *desc, LSA_Q_GETSYSTEMACCOUNT  *r_c, prs_struct *ps, int depth)
1790 {
1791         prs_debug(ps, depth, desc, "lsa_io_q_getsystemaccount");
1792         depth++;
1793
1794         if(!prs_align(ps))
1795                 return False;
1796  
1797         if(!smb_io_pol_hnd("pol", &r_c->pol, ps, depth))
1798                 return False;
1799
1800         return True;
1801 }
1802
1803 /*******************************************************************
1804  Reads or writes an  LSA_R_GETSYSTEMACCOUNTstructure.
1805 ********************************************************************/
1806
1807 BOOL lsa_io_r_getsystemaccount(char *desc, LSA_R_GETSYSTEMACCOUNT  *r_c, prs_struct *ps, int depth)
1808 {
1809         prs_debug(ps, depth, desc, "lsa_io_r_getsystemaccount");
1810         depth++;
1811
1812         if(!prs_align(ps))
1813                 return False;
1814  
1815         if(!prs_uint32("access", ps, depth, &r_c->access))
1816                 return False;
1817
1818         if(!prs_ntstatus("status", ps, depth, &r_c->status))
1819                 return False;
1820
1821         return True;
1822 }