Initial import
[samba] / source / rpc_parse / parse_lsa.c
1 /* 
2  *  Unix SMB/CIFS implementation.
3  *  RPC Pipe client / server routines
4  *  Copyright (C) Andrew Tridgell              1992-1997,
5  *  Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
6  *  Copyright (C) Paul Ashton                       1997,
7  *  Copyright (C) Andrew Bartlett                   2002,
8  *  Copyright (C) Jim McDonough <jmcd@us.ibm.com>   2002.
9  *  Copyright (C) Gerald )Jerry) Carter             2005
10  *  
11  *  This program is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *  
16  *  This program is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *  
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  */
25
26 #include "includes.h"
27
28 #undef DBGC_CLASS
29 #define DBGC_CLASS DBGC_RPC_PARSE
30
31 static BOOL lsa_io_trans_names(const char *desc, LSA_TRANS_NAME_ENUM *trn, prs_struct *ps, int depth);
32
33 /*******************************************************************
34  Inits a LSA_TRANS_NAME structure.
35 ********************************************************************/
36
37 void init_lsa_trans_name(LSA_TRANS_NAME *trn, UNISTR2 *uni_name,
38                          uint16 sid_name_use, const char *name, uint32 idx)
39 {
40         trn->sid_name_use = sid_name_use;
41         init_unistr2(uni_name, name, UNI_FLAGS_NONE);
42         init_uni_hdr(&trn->hdr_name, uni_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(const 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(const char *desc, DOM_R_REF *dom, prs_struct *ps, int depth)
77 {
78         unsigned int i;
79
80         prs_debug(ps, depth, desc, "lsa_io_dom_r_ref");
81         depth++;
82
83         if(!prs_align(ps))
84                 return False;
85         
86         if(!prs_uint32("num_ref_doms_1", ps, depth, &dom->num_ref_doms_1)) /* num referenced domains? */
87                 return False;
88         if(!prs_uint32("ptr_ref_dom   ", ps, depth, &dom->ptr_ref_dom)) /* undocumented buffer pointer. */
89                 return False;
90         if(!prs_uint32("max_entries   ", ps, depth, &dom->max_entries)) /* 32 - max number of entries */
91                 return False;
92
93         SMB_ASSERT_ARRAY(dom->hdr_ref_dom, dom->num_ref_doms_1);
94
95         if (dom->ptr_ref_dom != 0) {
96
97                 if(!prs_uint32("num_ref_doms_2", ps, depth, &dom->num_ref_doms_2)) /* 4 - num referenced domains? */
98                         return False;
99
100                 SMB_ASSERT_ARRAY(dom->ref_dom, dom->num_ref_doms_2);
101
102                 for (i = 0; i < dom->num_ref_doms_1; i++) {
103                         fstring t;
104
105                         slprintf(t, sizeof(t) - 1, "dom_ref[%d] ", i);
106                         if(!smb_io_unihdr(t, &dom->hdr_ref_dom[i].hdr_dom_name, ps, depth))
107                                 return False;
108
109                         slprintf(t, sizeof(t) - 1, "sid_ptr[%d] ", i);
110                         if(!prs_uint32(t, ps, depth, &dom->hdr_ref_dom[i].ptr_dom_sid))
111                                 return False;
112                 }
113
114                 for (i = 0; i < dom->num_ref_doms_2; i++) {
115                         fstring t;
116
117                         if (dom->hdr_ref_dom[i].hdr_dom_name.buffer != 0) {
118                                 slprintf(t, sizeof(t) - 1, "dom_ref[%d] ", i);
119                                 if(!smb_io_unistr2(t, &dom->ref_dom[i].uni_dom_name, True, ps, depth)) /* domain name unicode string */
120                                         return False;
121                                 if(!prs_align(ps))
122                                         return False;
123                         }
124
125                         if (dom->hdr_ref_dom[i].ptr_dom_sid != 0) {
126                                 slprintf(t, sizeof(t) - 1, "sid_ptr[%d] ", i);
127                                 if(!smb_io_dom_sid2(t, &dom->ref_dom[i].ref_dom, ps, depth)) /* referenced domain SIDs */
128                                         return False;
129                         }
130                 }
131         }
132
133         return True;
134 }
135
136 /*******************************************************************
137  Inits an LSA_SEC_QOS structure.
138 ********************************************************************/
139
140 void init_lsa_sec_qos(LSA_SEC_QOS *qos, uint16 imp_lev, uint8 ctxt, uint8 eff)
141 {
142         DEBUG(5, ("init_lsa_sec_qos\n"));
143
144         qos->len = 0x0c; /* length of quality of service block, in bytes */
145         qos->sec_imp_level = imp_lev;
146         qos->sec_ctxt_mode = ctxt;
147         qos->effective_only = eff;
148 }
149
150 /*******************************************************************
151  Reads or writes an LSA_SEC_QOS structure.
152 ********************************************************************/
153
154 static BOOL lsa_io_sec_qos(const char *desc,  LSA_SEC_QOS *qos, prs_struct *ps, 
155                            int depth)
156 {
157         uint32 start;
158
159         prs_debug(ps, depth, desc, "lsa_io_obj_qos");
160         depth++;
161
162         if(!prs_align(ps))
163                 return False;
164         
165         start = prs_offset(ps);
166
167         /* these pointers had _better_ be zero, because we don't know
168            what they point to!
169          */
170         if(!prs_uint32("len           ", ps, depth, &qos->len)) /* 0x18 - length (in bytes) inc. the length field. */
171                 return False;
172         if(!prs_uint16("sec_imp_level ", ps, depth, &qos->sec_imp_level ))
173                 return False;
174         if(!prs_uint8 ("sec_ctxt_mode ", ps, depth, &qos->sec_ctxt_mode ))
175                 return False;
176         if(!prs_uint8 ("effective_only", ps, depth, &qos->effective_only))
177                 return False;
178
179         if (qos->len != prs_offset(ps) - start) {
180                 DEBUG(3,("lsa_io_sec_qos: length %x does not match size %x\n",
181                          qos->len, prs_offset(ps) - start));
182         }
183
184         return True;
185 }
186
187 /*******************************************************************
188  Inits an LSA_OBJ_ATTR structure.
189 ********************************************************************/
190
191 static void init_lsa_obj_attr(LSA_OBJ_ATTR *attr, uint32 attributes, LSA_SEC_QOS *qos)
192 {
193         DEBUG(5, ("init_lsa_obj_attr\n"));
194
195         attr->len = 0x18; /* length of object attribute block, in bytes */
196         attr->ptr_root_dir = 0;
197         attr->ptr_obj_name = 0;
198         attr->attributes = attributes;
199         attr->ptr_sec_desc = 0;
200         
201         if (qos != NULL) {
202                 attr->ptr_sec_qos = 1;
203                 attr->sec_qos = qos;
204         } else {
205                 attr->ptr_sec_qos = 0;
206                 attr->sec_qos = NULL;
207         }
208 }
209
210 /*******************************************************************
211  Reads or writes an LSA_OBJ_ATTR structure.
212 ********************************************************************/
213
214 static BOOL lsa_io_obj_attr(const char *desc, LSA_OBJ_ATTR *attr, prs_struct *ps, 
215                             int depth)
216 {
217         prs_debug(ps, depth, desc, "lsa_io_obj_attr");
218         depth++;
219
220         if(!prs_align(ps))
221                 return False;
222         
223         /* these pointers had _better_ be zero, because we don't know
224            what they point to!
225          */
226         if(!prs_uint32("len         ", ps, depth, &attr->len)) /* 0x18 - length (in bytes) inc. the length field. */
227                 return False;
228         if(!prs_uint32("ptr_root_dir", ps, depth, &attr->ptr_root_dir)) /* 0 - root directory (pointer) */
229                 return False;
230         if(!prs_uint32("ptr_obj_name", ps, depth, &attr->ptr_obj_name)) /* 0 - object name (pointer) */
231                 return False;
232         if(!prs_uint32("attributes  ", ps, depth, &attr->attributes)) /* 0 - attributes (undocumented) */
233                 return False;
234         if(!prs_uint32("ptr_sec_desc", ps, depth, &attr->ptr_sec_desc)) /* 0 - security descriptior (pointer) */
235                 return False;
236         if(!prs_uint32("ptr_sec_qos ", ps, depth, &attr->ptr_sec_qos )) /* security quality of service (pointer) */
237                 return False;
238
239         if (attr->ptr_sec_qos != 0) {
240                 if (UNMARSHALLING(ps))
241                         if (!(attr->sec_qos = PRS_ALLOC_MEM(ps,LSA_SEC_QOS,1)))
242                                 return False;
243
244                 if(!lsa_io_sec_qos("sec_qos", attr->sec_qos, ps, depth))
245                         return False;
246         }
247
248         return True;
249 }
250
251
252 /*******************************************************************
253  Inits an LSA_Q_OPEN_POL structure.
254 ********************************************************************/
255
256 void init_q_open_pol(LSA_Q_OPEN_POL *in, uint16 system_name,
257                      uint32 attributes, uint32 desired_access,
258                      LSA_SEC_QOS *qos)
259 {
260         DEBUG(5, ("init_open_pol: attr:%d da:%d\n", attributes, 
261                   desired_access));
262
263         in->ptr = 1; /* undocumented pointer */
264
265         in->des_access = desired_access;
266
267         in->system_name = system_name;
268         init_lsa_obj_attr(&in->attr, attributes, qos);
269 }
270
271 /*******************************************************************
272  Reads or writes an LSA_Q_OPEN_POL structure.
273 ********************************************************************/
274
275 BOOL lsa_io_q_open_pol(const char *desc, LSA_Q_OPEN_POL *in, prs_struct *ps, 
276                        int depth)
277 {
278         prs_debug(ps, depth, desc, "lsa_io_q_open_pol");
279         depth++;
280
281         if(!prs_uint32("ptr       ", ps, depth, &in->ptr))
282                 return False;
283         if(!prs_uint16("system_name", ps, depth, &in->system_name))
284                 return False;
285         if(!prs_align( ps ))
286                 return False;
287
288         if(!lsa_io_obj_attr("", &in->attr, ps, depth))
289                 return False;
290
291         if(!prs_uint32("des_access", ps, depth, &in->des_access))
292                 return False;
293
294         return True;
295 }
296
297 /*******************************************************************
298  Reads or writes an LSA_R_OPEN_POL structure.
299 ********************************************************************/
300
301 BOOL lsa_io_r_open_pol(const char *desc, LSA_R_OPEN_POL *out, prs_struct *ps, 
302                        int depth)
303 {
304         prs_debug(ps, depth, desc, "lsa_io_r_open_pol");
305         depth++;
306
307         if(!smb_io_pol_hnd("", &out->pol, ps, depth))
308                 return False;
309
310         if(!prs_ntstatus("status", ps, depth, &out->status))
311                 return False;
312
313         return True;
314 }
315
316 /*******************************************************************
317  Inits an LSA_Q_OPEN_POL2 structure.
318 ********************************************************************/
319
320 void init_q_open_pol2(LSA_Q_OPEN_POL2 *in, const char *server_name,
321                         uint32 attributes, uint32 desired_access,
322                         LSA_SEC_QOS *qos)
323 {
324         DEBUG(5, ("init_q_open_pol2: attr:%d da:%d\n", attributes, 
325                   desired_access));
326
327         in->ptr = 1; /* undocumented pointer */
328
329         in->des_access = desired_access;
330
331         init_unistr2(&in->uni_server_name, server_name, UNI_STR_TERMINATE);
332
333         init_lsa_obj_attr(&in->attr, attributes, qos);
334 }
335
336 /*******************************************************************
337  Reads or writes an LSA_Q_OPEN_POL2 structure.
338 ********************************************************************/
339
340 BOOL lsa_io_q_open_pol2(const char *desc, LSA_Q_OPEN_POL2 *in, prs_struct *ps, 
341                         int depth)
342 {
343         prs_debug(ps, depth, desc, "lsa_io_q_open_pol2");
344         depth++;
345
346         if(!prs_uint32("ptr       ", ps, depth, &in->ptr))
347                 return False;
348
349         if(!smb_io_unistr2 ("", &in->uni_server_name, in->ptr, ps, depth))
350                 return False;
351         if(!lsa_io_obj_attr("", &in->attr, ps, depth))
352                 return False;
353
354         if(!prs_uint32("des_access", ps, depth, &in->des_access))
355                 return False;
356
357         return True;
358 }
359
360 /*******************************************************************
361  Reads or writes an LSA_R_OPEN_POL2 structure.
362 ********************************************************************/
363
364 BOOL lsa_io_r_open_pol2(const char *desc, LSA_R_OPEN_POL2 *out, prs_struct *ps, 
365                         int depth)
366 {
367         prs_debug(ps, depth, desc, "lsa_io_r_open_pol2");
368         depth++;
369
370         if(!smb_io_pol_hnd("", &out->pol, ps, depth))
371                 return False;
372
373         if(!prs_ntstatus("status", ps, depth, &out->status))
374                 return False;
375
376         return True;
377 }
378
379 /*******************************************************************
380 makes an LSA_Q_QUERY_SEC_OBJ structure.
381 ********************************************************************/
382
383 void init_q_query_sec_obj(LSA_Q_QUERY_SEC_OBJ *in, const POLICY_HND *hnd, 
384                           uint32 sec_info)
385 {
386         DEBUG(5, ("init_q_query_sec_obj\n"));
387
388         in->pol = *hnd;
389         in->sec_info = sec_info;
390
391         return;
392 }
393
394 /*******************************************************************
395  Reads or writes an LSA_Q_QUERY_SEC_OBJ structure.
396 ********************************************************************/
397
398 BOOL lsa_io_q_query_sec_obj(const char *desc, LSA_Q_QUERY_SEC_OBJ *in, 
399                             prs_struct *ps, int depth)
400 {
401         prs_debug(ps, depth, desc, "lsa_io_q_query_sec_obj");
402         depth++;
403
404         if (!smb_io_pol_hnd("", &in->pol, ps, depth))
405                 return False;
406
407         if (!prs_uint32("sec_info", ps, depth, &in->sec_info))
408                 return False;
409
410         return True;
411
412
413 /*******************************************************************
414  Reads or writes a LSA_R_QUERY_SEC_OBJ structure.
415 ********************************************************************/
416
417 BOOL lsa_io_r_query_sec_obj(const char *desc, LSA_R_QUERY_SEC_OBJ *out, prs_struct *ps, int depth)
418 {
419         prs_debug(ps, depth, desc, "lsa_io_r_query_sec_obj");
420         depth++;
421
422         if (!prs_align(ps))
423                 return False;
424
425         if (!prs_uint32("ptr", ps, depth, &out->ptr))
426                 return False;
427
428         if (out->ptr != 0) {
429                 if (!sec_io_desc_buf("sec", &out->buf, ps, depth))
430                         return False;
431         }
432
433         if (!prs_ntstatus("status", ps, depth, &out->status))
434                 return False;
435
436         return True;
437 }
438
439 /*******************************************************************
440  Inits an LSA_Q_QUERY_INFO structure.
441 ********************************************************************/
442
443 void init_q_query(LSA_Q_QUERY_INFO *in, POLICY_HND *hnd, uint16 info_class)
444 {
445         DEBUG(5, ("init_q_query\n"));
446
447         memcpy(&in->pol, hnd, sizeof(in->pol));
448
449         in->info_class = info_class;
450 }
451
452 /*******************************************************************
453  Reads or writes an LSA_Q_QUERY_INFO structure.
454 ********************************************************************/
455
456 BOOL lsa_io_q_query(const char *desc, LSA_Q_QUERY_INFO *in, prs_struct *ps, 
457                     int depth)
458 {
459         prs_debug(ps, depth, desc, "lsa_io_q_query");
460         depth++;
461
462         if(!smb_io_pol_hnd("", &in->pol, ps, depth))
463                 return False;
464
465         if(!prs_uint16("info_class", ps, depth, &in->info_class))
466                 return False;
467
468         return True;
469 }
470
471 /*******************************************************************
472 makes an LSA_Q_ENUM_TRUST_DOM structure.
473 ********************************************************************/
474 BOOL init_q_enum_trust_dom(LSA_Q_ENUM_TRUST_DOM * q_e, POLICY_HND *pol,
475                            uint32 enum_context, uint32 preferred_len)
476 {
477         DEBUG(5, ("init_q_enum_trust_dom\n"));
478
479         q_e->pol = *pol;
480         q_e->enum_context = enum_context;
481         q_e->preferred_len = preferred_len;
482
483         return True;
484 }
485
486 /*******************************************************************
487  Reads or writes an LSA_Q_ENUM_TRUST_DOM structure.
488 ********************************************************************/
489
490 BOOL lsa_io_q_enum_trust_dom(const char *desc, LSA_Q_ENUM_TRUST_DOM *q_e, 
491                              prs_struct *ps, int depth)
492 {
493         prs_debug(ps, depth, desc, "lsa_io_q_enum_trust_dom");
494         depth++;
495
496         if(!smb_io_pol_hnd("", &q_e->pol, ps, depth))
497                 return False;
498
499         if(!prs_uint32("enum_context ", ps, depth, &q_e->enum_context))
500                 return False;
501         if(!prs_uint32("preferred_len", ps, depth, &q_e->preferred_len))
502                 return False;
503
504         return True;
505 }
506
507 /*******************************************************************
508  Inits an LSA_R_ENUM_TRUST_DOM structure.
509 ********************************************************************/
510
511 void init_r_enum_trust_dom(TALLOC_CTX *ctx, LSA_R_ENUM_TRUST_DOM *out, uint32 enum_context,
512                            uint32 req_num_domains, uint32 num_domains, TRUSTDOM **td)
513 {
514         unsigned int i;
515
516         DEBUG(5, ("init_r_enum_trust_dom\n"));
517         
518         out->enum_context  = enum_context;
519         out->count         = num_domains;
520                         
521         if ( num_domains != 0 ) {
522         
523                 /* allocate container memory */
524                 
525                 out->domlist = TALLOC_P( ctx, DOMAIN_LIST );
526                 out->domlist->domains = TALLOC_ARRAY( ctx, DOMAIN_INFO, out->count );
527                 
528                 if ( !out->domlist || !out->domlist->domains ) {
529                         out->status = NT_STATUS_NO_MEMORY;
530                         return;
531                 }
532                 
533                 out->domlist->count = out->count;
534                 
535                 /* initialize the list of domains and their sid */
536                 
537                 for (i = 0; i < num_domains; i++) {     
538                         if ( !(out->domlist->domains[i].sid = TALLOC_P(ctx, DOM_SID2)) ) {
539                                 out->status = NT_STATUS_NO_MEMORY;
540                                 return;
541                         }
542                                 
543                         init_dom_sid2(out->domlist->domains[i].sid, &(td[i])->sid);
544                         init_unistr4_w(ctx, &out->domlist->domains[i].name, (td[i])->name);     
545                 }
546         }
547
548 }
549
550 /*******************************************************************
551 ********************************************************************/
552
553 BOOL lsa_io_domain_list( const char *desc, prs_struct *ps, int depth, DOMAIN_LIST *domlist )
554 {
555         int i;
556         
557         prs_debug(ps, depth, desc, "lsa_io_domain_list");
558         depth++;
559
560         if(!prs_uint32("count", ps, depth, &domlist->count))
561                 return False;
562
563         if ( domlist->count == 0 )
564                 return True;
565                 
566         if ( UNMARSHALLING(ps) ) {
567                 if ( !(domlist->domains = PRS_ALLOC_MEM( ps, DOMAIN_INFO, domlist->count )) )
568                         return False;
569         }
570         
571         /* headers */
572         
573         for ( i=0; i<domlist->count; i++ ) {
574                 if ( !prs_unistr4_hdr("name_header", ps, depth, &domlist->domains[i].name) )
575                         return False;
576                 if ( !smb_io_dom_sid2_p("sid_header", ps, depth, &domlist->domains[i].sid) )
577                         return False;
578         }
579
580         /* data */
581         
582         for ( i=0; i<domlist->count; i++ ) {
583                 if ( !prs_unistr4_str("name", ps, depth, &domlist->domains[i].name) )
584                         return False;
585                 if( !smb_io_dom_sid2("sid", domlist->domains[i].sid, ps, depth) )
586                         return False;
587         }
588         
589         return True;
590 }
591
592 /*******************************************************************
593  Reads or writes an LSA_R_ENUM_TRUST_DOM structure.
594 ********************************************************************/
595
596 BOOL lsa_io_r_enum_trust_dom(const char *desc, LSA_R_ENUM_TRUST_DOM *out, 
597                              prs_struct *ps, int depth)
598 {
599         prs_debug(ps, depth, desc, "lsa_io_r_enum_trust_dom");
600         depth++;
601
602         if(!prs_uint32("enum_context", ps, depth, &out->enum_context))
603                 return False;
604
605         if(!prs_uint32("count", ps, depth, &out->count))
606                 return False;
607
608         if ( !prs_pointer("trusted_domains", ps, depth, (void**)&out->domlist, sizeof(DOMAIN_LIST), (PRS_POINTER_CAST)lsa_io_domain_list))
609                 return False;
610                 
611         if(!prs_ntstatus("status", ps, depth, &out->status))
612                 return False;
613
614         return True;
615 }
616
617 /*******************************************************************
618 reads or writes a dom query structure.
619 ********************************************************************/
620
621 static BOOL lsa_io_dom_query(const char *desc, DOM_QUERY *d_q, prs_struct *ps, int depth)
622 {
623         if (d_q == NULL)
624                 return False;
625
626         prs_debug(ps, depth, desc, "lsa_io_dom_query");
627         depth++;
628
629         if(!prs_align(ps))
630                 return False;
631
632         if(!prs_uint16("uni_dom_max_len", ps, depth, &d_q->uni_dom_max_len)) /* domain name string length * 2 */
633                 return False;
634         if(!prs_uint16("uni_dom_str_len", ps, depth, &d_q->uni_dom_str_len)) /* domain name string length * 2 */
635                 return False;
636
637         if(!prs_uint32("buffer_dom_name", ps, depth, &d_q->buffer_dom_name)) /* undocumented domain name string buffer pointer */
638                 return False;
639         if(!prs_uint32("buffer_dom_sid ", ps, depth, &d_q->buffer_dom_sid)) /* undocumented domain SID string buffer pointer */
640                 return False;
641
642         if(!smb_io_unistr2("unistr2", &d_q->uni_domain_name, d_q->buffer_dom_name, ps, depth)) /* domain name (unicode string) */
643                 return False;
644
645         if(!prs_align(ps))
646                 return False;
647
648         if (d_q->buffer_dom_sid != 0) {
649                 if(!smb_io_dom_sid2("", &d_q->dom_sid, ps, depth)) /* domain SID */
650                         return False;
651         } else {
652                 memset((char *)&d_q->dom_sid, '\0', sizeof(d_q->dom_sid));
653         }
654
655         return True;
656 }
657
658 /*******************************************************************
659 reads or writes a structure.
660 ********************************************************************/
661
662 static BOOL lsa_io_dom_query_2(const char *desc, DOM_QUERY_2 *d_q, prs_struct *ps, int depth)
663 {
664         uint32 ptr = 1;
665
666         if (d_q == NULL)
667                 return False;
668
669         prs_debug(ps, depth, desc, "lsa_io_dom_query_2");
670         depth++;
671
672         if (!prs_align(ps))
673                 return False;
674
675         if (!prs_uint32("auditing_enabled", ps, depth, &d_q->auditing_enabled))
676                 return False;
677         if (!prs_uint32("ptr   ", ps, depth, &ptr))
678                 return False;
679         if (!prs_uint32("count1", ps, depth, &d_q->count1))
680                 return False;
681         if (!prs_uint32("count2", ps, depth, &d_q->count2))
682                 return False;
683
684         if (UNMARSHALLING(ps)) {
685                 d_q->auditsettings = TALLOC_ZERO_ARRAY(ps->mem_ctx, uint32, d_q->count2);
686         }
687
688         if (d_q->auditsettings == NULL) {
689                 DEBUG(1, ("lsa_io_dom_query_2: NULL auditsettings!\n"));
690                 return False;
691         }
692
693         if (!prs_uint32s(False, "auditsettings", ps, depth, d_q->auditsettings, d_q->count2))
694                 return False;
695
696     return True;
697 }
698
699 /*******************************************************************
700  Reads or writes a dom query structure.
701 ********************************************************************/
702
703 static BOOL lsa_io_dom_query_3(const char *desc, DOM_QUERY_3 *d_q, prs_struct *ps, int depth)
704 {
705         return lsa_io_dom_query("", d_q, ps, depth);
706 }
707
708 /*******************************************************************
709  Reads or writes a dom query structure.
710 ********************************************************************/
711
712 static BOOL lsa_io_dom_query_5(const char *desc, DOM_QUERY_5 *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 static BOOL lsa_io_dom_query_6(const char *desc, DOM_QUERY_6 *d_q, prs_struct *ps, int depth)
722 {
723         if (d_q == NULL)
724                 return False;
725
726         prs_debug(ps, depth, desc, "lsa_io_dom_query_6");
727         depth++;
728
729         if (!prs_uint16("server_role", ps, depth, &d_q->server_role))
730                 return False;
731
732         return True;
733 }
734
735 /*******************************************************************
736  Reads or writes an LSA_R_QUERY_INFO structure.
737 ********************************************************************/
738
739 BOOL lsa_io_r_query(const char *desc, LSA_R_QUERY_INFO *out, prs_struct *ps, int depth)
740 {
741         prs_debug(ps, depth, desc, "lsa_io_r_query");
742         depth++;
743
744         if(!prs_uint32("undoc_buffer", ps, depth, &out->undoc_buffer))
745                 return False;
746
747         if (out->undoc_buffer != 0) {
748                 if(!prs_uint16("info_class", ps, depth, &out->info_class))
749                         return False;
750
751                 if(!prs_align(ps))
752                         return False;
753
754                 switch (out->info_class) {
755                 case 2:
756                         if(!lsa_io_dom_query_2("", &out->dom.id2, ps, depth))
757                                 return False;
758                         break;
759                 case 3:
760                         if(!lsa_io_dom_query_3("", &out->dom.id3, ps, depth))
761                                 return False;
762                         break;
763                 case 5:
764                         if(!lsa_io_dom_query_5("", &out->dom.id5, ps, depth))
765                                 return False;
766                         break;
767                 case 6:
768                         if(!lsa_io_dom_query_6("", &out->dom.id6, ps, depth))
769                                 return False;
770                         break;
771                 default:
772                         /* PANIC! */
773                         break;
774                 }
775         }
776
777         if(!prs_align(ps))
778                 return False;
779
780         if(!prs_ntstatus("status", ps, depth, &out->status))
781                 return False;
782
783         return True;
784 }
785
786 /*******************************************************************
787  Inits a LSA_SID_ENUM structure.
788 ********************************************************************/
789
790 static void init_lsa_sid_enum(TALLOC_CTX *mem_ctx, LSA_SID_ENUM *sen, 
791                        int num_entries, const DOM_SID *sids)
792 {
793         int i;
794
795         DEBUG(5, ("init_lsa_sid_enum\n"));
796
797         sen->num_entries  = num_entries;
798         sen->ptr_sid_enum = (num_entries != 0);
799         sen->num_entries2 = num_entries;
800
801         /* Allocate memory for sids and sid pointers */
802
803         if (num_entries == 0) return;
804
805         if ((sen->ptr_sid = TALLOC_ZERO_ARRAY(mem_ctx, uint32, num_entries )) == NULL) {
806                 DEBUG(3, ("init_lsa_sid_enum(): out of memory for ptr_sid\n"));
807                 return;
808         }
809
810         if ((sen->sid = TALLOC_ZERO_ARRAY(mem_ctx, DOM_SID2, num_entries)) == NULL) {
811                 DEBUG(3, ("init_lsa_sid_enum(): out of memory for sids\n"));
812                 return;
813         }
814
815         /* Copy across SIDs and SID pointers */
816
817         for (i = 0; i < num_entries; i++) {
818                 sen->ptr_sid[i] = 1;
819                 init_dom_sid2(&sen->sid[i], &sids[i]);
820         }
821 }
822
823 /*******************************************************************
824  Reads or writes a LSA_SID_ENUM structure.
825 ********************************************************************/
826
827 static BOOL lsa_io_sid_enum(const char *desc, LSA_SID_ENUM *sen, prs_struct *ps, 
828                             int depth)
829 {
830         unsigned int i;
831
832         prs_debug(ps, depth, desc, "lsa_io_sid_enum");
833         depth++;
834
835         if(!prs_align(ps))
836                 return False;
837         
838         if(!prs_uint32("num_entries ", ps, depth, &sen->num_entries))
839                 return False;
840         if(!prs_uint32("ptr_sid_enum", ps, depth, &sen->ptr_sid_enum))
841                 return False;
842
843         /*
844            if the ptr is NULL, leave here. checked from a real w2k trace.
845            JFM, 11/23/2001
846          */
847         
848         if (sen->ptr_sid_enum==0)
849                 return True;
850
851         if(!prs_uint32("num_entries2", ps, depth, &sen->num_entries2))
852                 return False;
853
854         /* Mallocate memory if we're unpacking from the wire */
855
856         if (UNMARSHALLING(ps)) {
857                 if ((sen->ptr_sid = PRS_ALLOC_MEM( ps, uint32, sen->num_entries)) == NULL) {
858                         DEBUG(3, ("init_lsa_sid_enum(): out of memory for "
859                                   "ptr_sid\n"));
860                         return False;
861                 }
862
863                 if ((sen->sid = PRS_ALLOC_MEM( ps, DOM_SID2, sen->num_entries)) == NULL) {
864                         DEBUG(3, ("init_lsa_sid_enum(): out of memory for "
865                                   "sids\n"));
866                         return False;
867                 }
868         }
869
870         for (i = 0; i < sen->num_entries; i++) {        
871                 fstring temp;
872
873                 slprintf(temp, sizeof(temp) - 1, "ptr_sid[%d]", i);
874                 if(!prs_uint32(temp, ps, depth, &sen->ptr_sid[i])) {
875                         return False;
876                 }
877         }
878
879         for (i = 0; i < sen->num_entries; i++) {
880                 fstring temp;
881
882                 slprintf(temp, sizeof(temp) - 1, "sid[%d]", i);
883                 if(!smb_io_dom_sid2(temp, &sen->sid[i], ps, depth)) {
884                         return False;
885                 }
886         }
887
888         return True;
889 }
890
891 /*******************************************************************
892  Inits an LSA_R_ENUM_TRUST_DOM structure.
893 ********************************************************************/
894
895 void init_q_lookup_sids(TALLOC_CTX *mem_ctx, LSA_Q_LOOKUP_SIDS *q_l, 
896                         POLICY_HND *hnd, int num_sids, const DOM_SID *sids,
897                         uint16 level)
898 {
899         DEBUG(5, ("init_q_lookup_sids\n"));
900
901         ZERO_STRUCTP(q_l);
902
903         memcpy(&q_l->pol, hnd, sizeof(q_l->pol));
904         init_lsa_sid_enum(mem_ctx, &q_l->sids, num_sids, sids);
905         
906         q_l->level = level;
907 }
908
909 /*******************************************************************
910  Reads or writes a LSA_Q_LOOKUP_SIDS structure.
911 ********************************************************************/
912
913 BOOL lsa_io_q_lookup_sids(const char *desc, LSA_Q_LOOKUP_SIDS *q_s, prs_struct *ps,
914                           int depth)
915 {
916         prs_debug(ps, depth, desc, "lsa_io_q_lookup_sids");
917         depth++;
918
919         if(!prs_align(ps))
920                 return False;
921         
922         if(!smb_io_pol_hnd("pol_hnd", &q_s->pol, ps, depth)) /* policy handle */
923                 return False;
924         if(!lsa_io_sid_enum("sids   ", &q_s->sids, ps, depth)) /* sids to be looked up */
925                 return False;
926         if(!lsa_io_trans_names("names  ", &q_s->names, ps, depth)) /* translated names */
927                 return False;
928
929         if(!prs_uint16("level", ps, depth, &q_s->level)) /* lookup level */
930                 return False;
931         if(!prs_align(ps))
932                 return False;
933
934         if(!prs_uint32("mapped_count", ps, depth, &q_s->mapped_count))
935                 return False;
936
937         return True;
938 }
939
940 /*******************************************************************
941  Reads or writes a structure.
942 ********************************************************************/
943
944 static BOOL lsa_io_trans_names(const char *desc, LSA_TRANS_NAME_ENUM *trn,
945                 prs_struct *ps, int depth)
946 {
947         unsigned int i;
948
949         prs_debug(ps, depth, desc, "lsa_io_trans_names");
950         depth++;
951
952         if(!prs_align(ps))
953                 return False;
954    
955         if(!prs_uint32("num_entries    ", ps, depth, &trn->num_entries))
956                 return False;
957         if(!prs_uint32("ptr_trans_names", ps, depth, &trn->ptr_trans_names))
958                 return False;
959
960         if (trn->ptr_trans_names != 0) {
961                 if(!prs_uint32("num_entries2   ", ps, depth, 
962                                &trn->num_entries2))
963                         return False;
964
965                 if (UNMARSHALLING(ps)) {
966                         if ((trn->name = PRS_ALLOC_MEM(ps, LSA_TRANS_NAME, trn->num_entries)) == NULL) {
967                                 return False;
968                         }
969
970                         if ((trn->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, trn->num_entries)) == NULL) {
971                                 return False;
972                         }
973                 }
974
975                 for (i = 0; i < trn->num_entries2; i++) {
976                         fstring t;
977                         slprintf(t, sizeof(t) - 1, "name[%d] ", i);
978
979                         if(!lsa_io_trans_name(t, &trn->name[i], ps, depth)) /* translated name */
980                                 return False;
981                 }
982
983                 for (i = 0; i < trn->num_entries2; i++) {
984                         fstring t;
985                         slprintf(t, sizeof(t) - 1, "name[%d] ", i);
986
987                         if(!smb_io_unistr2(t, &trn->uni_name[i], trn->name[i].hdr_name.buffer, ps, depth))
988                                 return False;
989                         if(!prs_align(ps))
990                                 return False;
991                 }
992         }
993
994         return True;
995 }
996
997 /*******************************************************************
998  Reads or writes a structure.
999 ********************************************************************/
1000
1001 BOOL lsa_io_r_lookup_sids(const char *desc, LSA_R_LOOKUP_SIDS *r_s, 
1002                           prs_struct *ps, int depth)
1003 {
1004         prs_debug(ps, depth, desc, "lsa_io_r_lookup_sids");
1005         depth++;
1006
1007         if(!prs_align(ps))
1008                 return False;
1009         
1010         if(!prs_uint32("ptr_dom_ref", ps, depth, &r_s->ptr_dom_ref))
1011                 return False;
1012
1013         if (r_s->ptr_dom_ref != 0)
1014                 if(!lsa_io_dom_r_ref ("dom_ref", r_s->dom_ref, ps, depth)) /* domain reference info */
1015                         return False;
1016
1017         if(!lsa_io_trans_names("names  ", r_s->names, ps, depth)) /* translated names */
1018                 return False;
1019
1020         if(!prs_align(ps))
1021                 return False;
1022
1023         if(!prs_uint32("mapped_count", ps, depth, &r_s->mapped_count))
1024                 return False;
1025
1026         if(!prs_ntstatus("status      ", ps, depth, &r_s->status))
1027                 return False;
1028
1029         return True;
1030 }
1031
1032 /*******************************************************************
1033 makes a structure.
1034 ********************************************************************/
1035
1036 void init_q_lookup_names(TALLOC_CTX *mem_ctx, LSA_Q_LOOKUP_NAMES *q_l, 
1037                          POLICY_HND *hnd, int num_names, const char **names)
1038 {
1039         unsigned int i;
1040
1041         DEBUG(5, ("init_q_lookup_names\n"));
1042
1043         ZERO_STRUCTP(q_l);
1044
1045         q_l->pol = *hnd;
1046         q_l->num_entries = num_names;
1047         q_l->num_entries2 = num_names;
1048         q_l->lookup_level = 1;
1049
1050         if ((q_l->uni_name = TALLOC_ZERO_ARRAY(mem_ctx, UNISTR2, num_names)) == NULL) {
1051                 DEBUG(3, ("init_q_lookup_names(): out of memory\n"));
1052                 return;
1053         }
1054
1055         if ((q_l->hdr_name = TALLOC_ZERO_ARRAY(mem_ctx, UNIHDR, num_names)) == NULL) {
1056                 DEBUG(3, ("init_q_lookup_names(): out of memory\n"));
1057                 return;
1058         }
1059
1060         for (i = 0; i < num_names; i++) {
1061                 init_unistr2(&q_l->uni_name[i], names[i], UNI_FLAGS_NONE);
1062                 init_uni_hdr(&q_l->hdr_name[i], &q_l->uni_name[i]);
1063         }
1064 }
1065
1066 /*******************************************************************
1067 reads or writes a structure.
1068 ********************************************************************/
1069
1070 BOOL lsa_io_q_lookup_names(const char *desc, LSA_Q_LOOKUP_NAMES *q_r, 
1071                            prs_struct *ps, int depth)
1072 {
1073         unsigned int i;
1074
1075         prs_debug(ps, depth, desc, "lsa_io_q_lookup_names");
1076         depth++;
1077
1078         if(!prs_align(ps))
1079                 return False;
1080
1081         if(!smb_io_pol_hnd("", &q_r->pol, ps, depth)) /* policy handle */
1082                 return False;
1083
1084         if(!prs_align(ps))
1085                 return False;
1086         if(!prs_uint32("num_entries    ", ps, depth, &q_r->num_entries))
1087                 return False;
1088         if(!prs_uint32("num_entries2   ", ps, depth, &q_r->num_entries2))
1089                 return False;
1090
1091         if (UNMARSHALLING(ps)) {
1092                 if (q_r->num_entries) {
1093                         if ((q_r->hdr_name = PRS_ALLOC_MEM(ps, UNIHDR, q_r->num_entries)) == NULL)
1094                                 return False;
1095                         if ((q_r->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, q_r->num_entries)) == NULL)
1096                                 return False;
1097                 }
1098         }
1099
1100         for (i = 0; i < q_r->num_entries; i++) {
1101                 if(!prs_align(ps))
1102                         return False;
1103                 if(!smb_io_unihdr("hdr_name", &q_r->hdr_name[i], ps, depth)) /* pointer names */
1104                         return False;
1105         }
1106
1107         for (i = 0; i < q_r->num_entries; i++) {
1108                 if(!prs_align(ps))
1109                         return False;
1110                 if(!smb_io_unistr2("dom_name", &q_r->uni_name[i], q_r->hdr_name[i].buffer, ps, depth)) /* names to be looked up */
1111                         return False;
1112         }
1113
1114         if(!prs_align(ps))
1115                 return False;
1116         if(!prs_uint32("num_trans_entries ", ps, depth, &q_r->num_trans_entries))
1117                 return False;
1118         if(!prs_uint32("ptr_trans_sids ", ps, depth, &q_r->ptr_trans_sids))
1119                 return False;
1120         if(!prs_uint32("lookup_level   ", ps, depth, &q_r->lookup_level))
1121                 return False;
1122         if(!prs_uint32("mapped_count   ", ps, depth, &q_r->mapped_count))
1123                 return False;
1124
1125         return True;
1126 }
1127
1128 /*******************************************************************
1129 reads or writes a structure.
1130 ********************************************************************/
1131
1132 BOOL lsa_io_r_lookup_names(const char *desc, LSA_R_LOOKUP_NAMES *out, prs_struct *ps, int depth)
1133 {
1134         unsigned int i;
1135
1136         prs_debug(ps, depth, desc, "lsa_io_r_lookup_names");
1137         depth++;
1138
1139         if(!prs_align(ps))
1140                 return False;
1141
1142         if(!prs_uint32("ptr_dom_ref", ps, depth, &out->ptr_dom_ref))
1143                 return False;
1144
1145         if (out->ptr_dom_ref != 0)
1146                 if(!lsa_io_dom_r_ref("", out->dom_ref, ps, depth))
1147                         return False;
1148
1149         if(!prs_uint32("num_entries", ps, depth, &out->num_entries))
1150                 return False;
1151         if(!prs_uint32("ptr_entries", ps, depth, &out->ptr_entries))
1152                 return False;
1153
1154         if (out->ptr_entries != 0) {
1155                 if(!prs_uint32("num_entries2", ps, depth, &out->num_entries2))
1156                         return False;
1157
1158                 if (out->num_entries2 != out->num_entries) {
1159                         /* RPC fault */
1160                         return False;
1161                 }
1162
1163                 if (UNMARSHALLING(ps)) {
1164                         if ((out->dom_rid = PRS_ALLOC_MEM(ps, DOM_RID2, out->num_entries2))
1165                             == NULL) {
1166                                 DEBUG(3, ("lsa_io_r_lookup_names(): out of memory\n"));
1167                                 return False;
1168                         }
1169                 }
1170
1171                 for (i = 0; i < out->num_entries2; i++)
1172                         if(!smb_io_dom_rid2("", &out->dom_rid[i], ps, depth)) /* domain RIDs being looked up */
1173                                 return False;
1174         }
1175
1176         if(!prs_uint32("mapped_count", ps, depth, &out->mapped_count))
1177                 return False;
1178
1179         if(!prs_ntstatus("status      ", ps, depth, &out->status))
1180                 return False;
1181
1182         return True;
1183 }
1184
1185
1186 /*******************************************************************
1187  Inits an LSA_Q_CLOSE structure.
1188 ********************************************************************/
1189
1190 void init_lsa_q_close(LSA_Q_CLOSE *in, POLICY_HND *hnd)
1191 {
1192         DEBUG(5, ("init_lsa_q_close\n"));
1193
1194         memcpy(&in->pol, hnd, sizeof(in->pol));
1195 }
1196
1197 /*******************************************************************
1198  Reads or writes an LSA_Q_CLOSE structure.
1199 ********************************************************************/
1200
1201 BOOL lsa_io_q_close(const char *desc, LSA_Q_CLOSE *in, prs_struct *ps, int depth)
1202 {
1203         prs_debug(ps, depth, desc, "lsa_io_q_close");
1204         depth++;
1205
1206         if(!smb_io_pol_hnd("", &in->pol, ps, depth))
1207                 return False;
1208
1209         return True;
1210 }
1211
1212 /*******************************************************************
1213  Reads or writes an LSA_R_CLOSE structure.
1214 ********************************************************************/
1215
1216 BOOL lsa_io_r_close(const char *desc,  LSA_R_CLOSE *out, prs_struct *ps, int depth)
1217 {
1218         prs_debug(ps, depth, desc, "lsa_io_r_close");
1219         depth++;
1220
1221         if(!smb_io_pol_hnd("", &out->pol, ps, depth))
1222                 return False;
1223
1224         if(!prs_ntstatus("status", ps, depth, &out->status))
1225                 return False;
1226
1227         return True;
1228 }
1229
1230 /*******************************************************************
1231  Reads or writes an LSA_Q_OPEN_SECRET structure.
1232 ********************************************************************/
1233
1234 BOOL lsa_io_q_open_secret(const char *desc, LSA_Q_OPEN_SECRET *in, prs_struct *ps, int depth)
1235 {
1236         prs_debug(ps, depth, desc, "lsa_io_q_open_secret");
1237         depth++;
1238
1239         if(!prs_align(ps))
1240                 return False;
1241
1242         if(!smb_io_pol_hnd("", &in->handle, ps, depth))
1243                 return False;
1244
1245         if(!prs_unistr4 ("secretname", ps, depth, &in->secretname))
1246                 return False;
1247         if(!prs_align(ps))
1248                 return False;
1249
1250         if(!prs_uint32("access", ps, depth, &in->access))
1251                 return False;
1252
1253         return True;
1254 }
1255
1256 /*******************************************************************
1257  Reads or writes an LSA_R_OPEN_SECRET structure.
1258 ********************************************************************/
1259
1260 BOOL lsa_io_r_open_secret(const char *desc, LSA_R_OPEN_SECRET *out, prs_struct *ps, int depth)
1261 {
1262         prs_debug(ps, depth, desc, "lsa_io_r_open_secret");
1263         depth++;
1264
1265         if(!prs_align(ps))
1266                 return False;
1267    
1268         if(!smb_io_pol_hnd("", &out->handle, ps, depth))
1269                 return False;
1270
1271         if(!prs_ntstatus("status", ps, depth, &out->status))
1272                 return False;
1273
1274         return True;
1275 }
1276
1277 /*******************************************************************
1278  Inits an LSA_Q_ENUM_PRIVS structure.
1279 ********************************************************************/
1280
1281 void init_q_enum_privs(LSA_Q_ENUM_PRIVS *in, POLICY_HND *hnd, uint32 enum_context, uint32 pref_max_length)
1282 {
1283         DEBUG(5, ("init_q_enum_privs\n"));
1284
1285         memcpy(&in->pol, hnd, sizeof(in->pol));
1286
1287         in->enum_context = enum_context;
1288         in->pref_max_length = pref_max_length;
1289 }
1290
1291 /*******************************************************************
1292 reads or writes a structure.
1293 ********************************************************************/
1294 BOOL lsa_io_q_enum_privs(const char *desc, LSA_Q_ENUM_PRIVS *in, prs_struct *ps, int depth)
1295 {
1296         if (in == NULL)
1297                 return False;
1298
1299         prs_debug(ps, depth, desc, "lsa_io_q_enum_privs");
1300         depth++;
1301
1302         if (!smb_io_pol_hnd("", &in->pol, ps, depth))
1303                 return False;
1304
1305         if(!prs_uint32("enum_context   ", ps, depth, &in->enum_context))
1306                 return False;
1307         if(!prs_uint32("pref_max_length", ps, depth, &in->pref_max_length))
1308                 return False;
1309
1310         return True;
1311 }
1312
1313 /*******************************************************************
1314 reads or writes a structure.
1315 ********************************************************************/
1316 static BOOL lsa_io_priv_entries(const char *desc, LSA_PRIV_ENTRY *entries, uint32 count, prs_struct *ps, int depth)
1317 {
1318         uint32 i;
1319
1320         if (entries == NULL)
1321                 return False;
1322
1323         prs_debug(ps, depth, desc, "lsa_io_priv_entries");
1324         depth++;
1325
1326         if(!prs_align(ps))
1327                 return False;
1328
1329         for (i = 0; i < count; i++) {
1330                 if (!smb_io_unihdr("", &entries[i].hdr_name, ps, depth))
1331                         return False;
1332                 if(!prs_uint32("luid_low ", ps, depth, &entries[i].luid_low))
1333                         return False;
1334                 if(!prs_uint32("luid_high", ps, depth, &entries[i].luid_high))
1335                         return False;
1336         }
1337
1338         for (i = 0; i < count; i++)
1339                 if (!smb_io_unistr2("", &entries[i].name, entries[i].hdr_name.buffer, ps, depth))
1340                         return False;
1341
1342         return True;
1343 }
1344
1345 /*******************************************************************
1346  Inits an LSA_R_ENUM_PRIVS structure.
1347 ********************************************************************/
1348
1349 void init_lsa_r_enum_privs(LSA_R_ENUM_PRIVS *out, uint32 enum_context,
1350                           uint32 count, LSA_PRIV_ENTRY *entries)
1351 {
1352         DEBUG(5, ("init_lsa_r_enum_privs\n"));
1353
1354         out->enum_context=enum_context;
1355         out->count=count;
1356         
1357         if (entries!=NULL) {
1358                 out->ptr=1;
1359                 out->count1=count;
1360                 out->privs=entries;
1361         } else {
1362                 out->ptr=0;
1363                 out->count1=0;
1364                 out->privs=NULL;
1365         }               
1366 }
1367
1368 /*******************************************************************
1369 reads or writes a structure.
1370 ********************************************************************/
1371 BOOL lsa_io_r_enum_privs(const char *desc, LSA_R_ENUM_PRIVS *out, prs_struct *ps, int depth)
1372 {
1373         if (out == NULL)
1374                 return False;
1375
1376         prs_debug(ps, depth, desc, "lsa_io_r_enum_privs");
1377         depth++;
1378
1379         if(!prs_align(ps))
1380                 return False;
1381
1382         if(!prs_uint32("enum_context", ps, depth, &out->enum_context))
1383                 return False;
1384         if(!prs_uint32("count", ps, depth, &out->count))
1385                 return False;
1386         if(!prs_uint32("ptr", ps, depth, &out->ptr))
1387                 return False;
1388
1389         if (out->ptr) {
1390                 if(!prs_uint32("count1", ps, depth, &out->count1))
1391                         return False;
1392
1393                 if (UNMARSHALLING(ps))
1394                         if (!(out->privs = PRS_ALLOC_MEM(ps, LSA_PRIV_ENTRY, out->count1)))
1395                                 return False;
1396
1397                 if (!lsa_io_priv_entries("", out->privs, out->count1, ps, depth))
1398                         return False;
1399         }
1400
1401         if(!prs_align(ps))
1402                 return False;
1403
1404         if(!prs_ntstatus("status", ps, depth, &out->status))
1405                 return False;
1406
1407         return True;
1408 }
1409
1410 void init_lsa_priv_get_dispname(LSA_Q_PRIV_GET_DISPNAME *trn, POLICY_HND *hnd, const char *name, uint16 lang_id, uint16 lang_id_sys)
1411 {
1412         memcpy(&trn->pol, hnd, sizeof(trn->pol));
1413
1414         init_unistr2(&trn->name, name, UNI_FLAGS_NONE);
1415         init_uni_hdr(&trn->hdr_name, &trn->name);
1416         trn->lang_id = lang_id;
1417         trn->lang_id_sys = lang_id_sys;
1418 }
1419
1420 /*******************************************************************
1421 reads or writes a structure.
1422 ********************************************************************/
1423 BOOL lsa_io_q_priv_get_dispname(const char *desc, LSA_Q_PRIV_GET_DISPNAME *in, prs_struct *ps, int depth)
1424 {
1425         if (in == NULL)
1426                 return False;
1427
1428         prs_debug(ps, depth, desc, "lsa_io_q_priv_get_dispname");
1429         depth++;
1430
1431         if(!prs_align(ps))
1432                 return False;
1433
1434         if (!smb_io_pol_hnd("", &in->pol, ps, depth))
1435                 return False;
1436
1437         if (!smb_io_unihdr("hdr_name", &in->hdr_name, ps, depth))
1438                 return False;
1439
1440         if (!smb_io_unistr2("name", &in->name, in->hdr_name.buffer, ps, depth))
1441                 return False;
1442
1443         if(!prs_uint16("lang_id    ", ps, depth, &in->lang_id))
1444                 return False;
1445         if(!prs_uint16("lang_id_sys", ps, depth, &in->lang_id_sys))
1446                 return False;
1447
1448         return True;
1449 }
1450
1451 /*******************************************************************
1452 reads or writes a structure.
1453 ********************************************************************/
1454 BOOL lsa_io_r_priv_get_dispname(const char *desc, LSA_R_PRIV_GET_DISPNAME *out, prs_struct *ps, int depth)
1455 {
1456         if (out == NULL)
1457                 return False;
1458
1459         prs_debug(ps, depth, desc, "lsa_io_r_priv_get_dispname");
1460         depth++;
1461
1462         if (!prs_align(ps))
1463                 return False;
1464
1465         if (!prs_uint32("ptr_info", ps, depth, &out->ptr_info))
1466                 return False;
1467
1468         if (out->ptr_info){
1469                 if (!smb_io_unihdr("hdr_name", &out->hdr_desc, ps, depth))
1470                         return False;
1471
1472                 if (!smb_io_unistr2("desc", &out->desc, out->hdr_desc.buffer, ps, depth))
1473                         return False;
1474         }
1475 /*
1476         if(!prs_align(ps))
1477                 return False;
1478 */
1479         if(!prs_uint16("lang_id", ps, depth, &out->lang_id))
1480                 return False;
1481
1482         if(!prs_align(ps))
1483                 return False;
1484         if(!prs_ntstatus("status", ps, depth, &out->status))
1485                 return False;
1486
1487         return True;
1488 }
1489
1490 /*
1491   initialise a LSA_Q_ENUM_ACCOUNTS structure
1492 */
1493 void init_lsa_q_enum_accounts(LSA_Q_ENUM_ACCOUNTS *trn, POLICY_HND *hnd, uint32 enum_context, uint32 pref_max_length)
1494 {
1495         memcpy(&trn->pol, hnd, sizeof(trn->pol));
1496
1497         trn->enum_context = enum_context;
1498         trn->pref_max_length = pref_max_length;
1499 }
1500
1501 /*******************************************************************
1502 reads or writes a structure.
1503 ********************************************************************/
1504 BOOL lsa_io_q_enum_accounts(const char *desc, LSA_Q_ENUM_ACCOUNTS *in, prs_struct *ps, int depth)
1505 {
1506         if (in == NULL)
1507                 return False;
1508
1509         prs_debug(ps, depth, desc, "lsa_io_q_enum_accounts");
1510         depth++;
1511
1512         if (!smb_io_pol_hnd("", &in->pol, ps, depth))
1513                 return False;
1514
1515         if(!prs_uint32("enum_context   ", ps, depth, &in->enum_context))
1516                 return False;
1517         if(!prs_uint32("pref_max_length", ps, depth, &in->pref_max_length))
1518                 return False;
1519
1520         return True;
1521 }
1522
1523
1524 /*******************************************************************
1525  Inits an LSA_R_ENUM_PRIVS structure.
1526 ********************************************************************/
1527
1528 void init_lsa_r_enum_accounts(LSA_R_ENUM_ACCOUNTS *out, uint32 enum_context)
1529 {
1530         DEBUG(5, ("init_lsa_r_enum_accounts\n"));
1531
1532         out->enum_context=enum_context;
1533         if (out->enum_context!=0) {
1534                 out->sids.num_entries=enum_context;
1535                 out->sids.ptr_sid_enum=1;
1536                 out->sids.num_entries2=enum_context;
1537         } else {
1538                 out->sids.num_entries=0;
1539                 out->sids.ptr_sid_enum=0;
1540                 out->sids.num_entries2=0;
1541         }
1542 }
1543
1544 /*******************************************************************
1545 reads or writes a structure.
1546 ********************************************************************/
1547 BOOL lsa_io_r_enum_accounts(const char *desc, LSA_R_ENUM_ACCOUNTS *out, prs_struct *ps, int depth)
1548 {
1549         if (out == NULL)
1550                 return False;
1551
1552         prs_debug(ps, depth, desc, "lsa_io_r_enum_accounts");
1553         depth++;
1554
1555         if (!prs_align(ps))
1556                 return False;
1557
1558         if(!prs_uint32("enum_context", ps, depth, &out->enum_context))
1559                 return False;
1560
1561         if (!lsa_io_sid_enum("sids", &out->sids, ps, depth))
1562                 return False;
1563
1564         if (!prs_align(ps))
1565                 return False;
1566
1567         if(!prs_ntstatus("status", ps, depth, &out->status))
1568                 return False;
1569
1570         return True;
1571 }
1572
1573
1574 /*******************************************************************
1575  Reads or writes an LSA_Q_UNK_GET_CONNUSER structure.
1576 ********************************************************************/
1577
1578 BOOL lsa_io_q_unk_get_connuser(const char *desc, LSA_Q_UNK_GET_CONNUSER *in, prs_struct *ps, int depth)
1579 {
1580         prs_debug(ps, depth, desc, "lsa_io_q_unk_get_connuser");
1581         depth++;
1582
1583         if(!prs_align(ps))
1584                 return False;
1585    
1586         if(!prs_uint32("ptr_srvname", ps, depth, &in->ptr_srvname))
1587                 return False;
1588
1589         if(!smb_io_unistr2("uni2_srvname", &in->uni2_srvname, in->ptr_srvname, ps, depth)) /* server name to be looked up */
1590                 return False;
1591
1592         if (!prs_align(ps))
1593           return False;
1594
1595         if(!prs_uint32("unk1", ps, depth, &in->unk1))
1596                 return False;
1597         if(!prs_uint32("unk2", ps, depth, &in->unk2))
1598                 return False;
1599         if(!prs_uint32("unk3", ps, depth, &in->unk3))
1600                 return False;
1601
1602         /* Don't bother to read or write at present... */
1603         return True;
1604 }
1605
1606 /*******************************************************************
1607  Reads or writes an LSA_R_UNK_GET_CONNUSER structure.
1608 ********************************************************************/
1609
1610 BOOL lsa_io_r_unk_get_connuser(const char *desc, LSA_R_UNK_GET_CONNUSER *out, prs_struct *ps, int depth)
1611 {
1612         prs_debug(ps, depth, desc, "lsa_io_r_unk_get_connuser");
1613         depth++;
1614
1615         if(!prs_align(ps))
1616                 return False;
1617    
1618         if(!prs_uint32("ptr_user_name", ps, depth, &out->ptr_user_name))
1619                 return False;
1620         if(!smb_io_unihdr("hdr_user_name", &out->hdr_user_name, ps, depth))
1621                 return False;
1622         if(!smb_io_unistr2("uni2_user_name", &out->uni2_user_name, out->ptr_user_name, ps, depth))
1623                 return False;
1624
1625         if (!prs_align(ps))
1626           return False;
1627         
1628         if(!prs_uint32("unk1", ps, depth, &out->unk1))
1629                 return False;
1630
1631         if(!prs_uint32("ptr_dom_name", ps, depth, &out->ptr_dom_name))
1632                 return False;
1633         if(!smb_io_unihdr("hdr_dom_name", &out->hdr_dom_name, ps, depth))
1634                 return False;
1635         if(!smb_io_unistr2("uni2_dom_name", &out->uni2_dom_name, out->ptr_dom_name, ps, depth))
1636                 return False;
1637
1638         if (!prs_align(ps))
1639           return False;
1640         
1641         if(!prs_ntstatus("status", ps, depth, &out->status))
1642                 return False;
1643
1644         return True;
1645 }
1646
1647 void init_lsa_q_create_account(LSA_Q_CREATEACCOUNT *trn, POLICY_HND *hnd, DOM_SID *sid, uint32 desired_access)
1648 {
1649         memcpy(&trn->pol, hnd, sizeof(trn->pol));
1650
1651         init_dom_sid2(&trn->sid, sid);
1652         trn->access = desired_access;
1653 }
1654
1655
1656 /*******************************************************************
1657  Reads or writes an LSA_Q_CREATEACCOUNT structure.
1658 ********************************************************************/
1659
1660 BOOL lsa_io_q_create_account(const char *desc, LSA_Q_CREATEACCOUNT *out, prs_struct *ps, int depth)
1661 {
1662         prs_debug(ps, depth, desc, "lsa_io_q_create_account");
1663         depth++;
1664
1665         if(!prs_align(ps))
1666                 return False;
1667  
1668         if(!smb_io_pol_hnd("pol", &out->pol, ps, depth))
1669                 return False;
1670
1671         if(!smb_io_dom_sid2("sid", &out->sid, ps, depth)) /* domain SID */
1672                 return False;
1673
1674         if(!prs_uint32("access", ps, depth, &out->access))
1675                 return False;
1676   
1677         return True;
1678 }
1679
1680 /*******************************************************************
1681  Reads or writes an LSA_R_CREATEACCOUNT structure.
1682 ********************************************************************/
1683
1684 BOOL lsa_io_r_create_account(const char *desc, LSA_R_CREATEACCOUNT  *out, prs_struct *ps, int depth)
1685 {
1686         prs_debug(ps, depth, desc, "lsa_io_r_open_account");
1687         depth++;
1688
1689         if(!prs_align(ps))
1690                 return False;
1691  
1692         if(!smb_io_pol_hnd("pol", &out->pol, ps, depth))
1693                 return False;
1694
1695         if(!prs_ntstatus("status", ps, depth, &out->status))
1696                 return False;
1697
1698         return True;
1699 }
1700
1701
1702 void init_lsa_q_open_account(LSA_Q_OPENACCOUNT *trn, POLICY_HND *hnd, DOM_SID *sid, uint32 desired_access)
1703 {
1704         memcpy(&trn->pol, hnd, sizeof(trn->pol));
1705
1706         init_dom_sid2(&trn->sid, sid);
1707         trn->access = desired_access;
1708 }
1709
1710 /*******************************************************************
1711  Reads or writes an LSA_Q_OPENACCOUNT structure.
1712 ********************************************************************/
1713
1714 BOOL lsa_io_q_open_account(const char *desc, LSA_Q_OPENACCOUNT *out, prs_struct *ps, int depth)
1715 {
1716         prs_debug(ps, depth, desc, "lsa_io_q_open_account");
1717         depth++;
1718
1719         if(!prs_align(ps))
1720                 return False;
1721  
1722         if(!smb_io_pol_hnd("pol", &out->pol, ps, depth))
1723                 return False;
1724
1725         if(!smb_io_dom_sid2("sid", &out->sid, ps, depth)) /* domain SID */
1726                 return False;
1727
1728         if(!prs_uint32("access", ps, depth, &out->access))
1729                 return False;
1730   
1731         return True;
1732 }
1733
1734 /*******************************************************************
1735  Reads or writes an LSA_R_OPENACCOUNT structure.
1736 ********************************************************************/
1737
1738 BOOL lsa_io_r_open_account(const char *desc, LSA_R_OPENACCOUNT  *out, prs_struct *ps, int depth)
1739 {
1740         prs_debug(ps, depth, desc, "lsa_io_r_open_account");
1741         depth++;
1742
1743         if(!prs_align(ps))
1744                 return False;
1745  
1746         if(!smb_io_pol_hnd("pol", &out->pol, ps, depth))
1747                 return False;
1748
1749         if(!prs_ntstatus("status", ps, depth, &out->status))
1750                 return False;
1751
1752         return True;
1753 }
1754
1755
1756 void init_lsa_q_enum_privsaccount(LSA_Q_ENUMPRIVSACCOUNT *trn, POLICY_HND *hnd)
1757 {
1758         memcpy(&trn->pol, hnd, sizeof(trn->pol));
1759
1760 }
1761
1762 /*******************************************************************
1763  Reads or writes an LSA_Q_ENUMPRIVSACCOUNT structure.
1764 ********************************************************************/
1765
1766 BOOL lsa_io_q_enum_privsaccount(const char *desc, LSA_Q_ENUMPRIVSACCOUNT *out, prs_struct *ps, int depth)
1767 {
1768         prs_debug(ps, depth, desc, "lsa_io_q_enum_privsaccount");
1769         depth++;
1770
1771         if(!prs_align(ps))
1772                 return False;
1773  
1774         if(!smb_io_pol_hnd("pol", &out->pol, ps, depth))
1775                 return False;
1776
1777         return True;
1778 }
1779
1780 /*******************************************************************
1781  Reads or writes an LUID structure.
1782 ********************************************************************/
1783
1784 static BOOL lsa_io_luid(const char *desc, LUID *out, prs_struct *ps, int depth)
1785 {
1786         prs_debug(ps, depth, desc, "lsa_io_luid");
1787         depth++;
1788
1789         if(!prs_align(ps))
1790                 return False;
1791  
1792         if(!prs_uint32("low", ps, depth, &out->low))
1793                 return False;
1794
1795         if(!prs_uint32("high", ps, depth, &out->high))
1796                 return False;
1797
1798         return True;
1799 }
1800
1801 /*******************************************************************
1802  Reads or writes an LUID_ATTR structure.
1803 ********************************************************************/
1804
1805 static BOOL lsa_io_luid_attr(const char *desc, LUID_ATTR *out, prs_struct *ps, int depth)
1806 {
1807         prs_debug(ps, depth, desc, "lsa_io_luid_attr");
1808         depth++;
1809
1810         if(!prs_align(ps))
1811                 return False;
1812  
1813         if (!lsa_io_luid(desc, &out->luid, ps, depth))
1814                 return False;
1815
1816         if(!prs_uint32("attr", ps, depth, &out->attr))
1817                 return False;
1818
1819         return True;
1820 }
1821
1822 /*******************************************************************
1823  Reads or writes an PRIVILEGE_SET structure.
1824 ********************************************************************/
1825
1826 static BOOL lsa_io_privilege_set(const char *desc, PRIVILEGE_SET *out, prs_struct *ps, int depth)
1827 {
1828         uint32 i;
1829
1830         prs_debug(ps, depth, desc, "lsa_io_privilege_set");
1831         depth++;
1832
1833         if(!prs_align(ps))
1834                 return False;
1835  
1836         if(!prs_uint32("count", ps, depth, &out->count))
1837                 return False;
1838         if(!prs_uint32("control", ps, depth, &out->control))
1839                 return False;
1840
1841         for (i=0; i<out->count; i++) {
1842                 if (!lsa_io_luid_attr(desc, &out->set[i], ps, depth))
1843                         return False;
1844         }
1845         
1846         return True;
1847 }
1848
1849 NTSTATUS init_lsa_r_enum_privsaccount(TALLOC_CTX *mem_ctx, LSA_R_ENUMPRIVSACCOUNT *out, LUID_ATTR *set, uint32 count, uint32 control)
1850 {
1851         NTSTATUS ret = NT_STATUS_OK;
1852
1853         out->ptr = 1;
1854         out->count = count;
1855
1856         if ( !NT_STATUS_IS_OK(ret = privilege_set_init_by_ctx(mem_ctx, &(out->set))) )
1857                 return ret;
1858         
1859         out->set.count = count;
1860         
1861         if (!NT_STATUS_IS_OK(ret = dup_luid_attr(out->set.mem_ctx, &(out->set.set), set, count)))
1862                 return ret;
1863
1864         DEBUG(10,("init_lsa_r_enum_privsaccount: %d privileges\n", out->count));
1865
1866         return ret;
1867 }
1868
1869 /*******************************************************************
1870  Reads or writes an LSA_R_ENUMPRIVSACCOUNT structure.
1871 ********************************************************************/
1872
1873 BOOL lsa_io_r_enum_privsaccount(const char *desc, LSA_R_ENUMPRIVSACCOUNT *out, prs_struct *ps, int depth)
1874 {
1875         prs_debug(ps, depth, desc, "lsa_io_r_enum_privsaccount");
1876         depth++;
1877
1878         if(!prs_align(ps))
1879                 return False;
1880  
1881         if(!prs_uint32("ptr", ps, depth, &out->ptr))
1882                 return False;
1883
1884         if (out->ptr!=0) {
1885                 if(!prs_uint32("count", ps, depth, &out->count))
1886                         return False;
1887
1888                 /* malloc memory if unmarshalling here */
1889
1890                 if (UNMARSHALLING(ps) && out->count != 0) {
1891                         if (!NT_STATUS_IS_OK(privilege_set_init_by_ctx(ps->mem_ctx, &(out->set))))
1892                                 return False;
1893
1894                         if (!(out->set.set = PRS_ALLOC_MEM(ps,LUID_ATTR,out->count)))
1895                                 return False;
1896
1897                 }
1898                 
1899                 if(!lsa_io_privilege_set(desc, &out->set, ps, depth))
1900                         return False;
1901         }
1902
1903         if(!prs_ntstatus("status", ps, depth, &out->status))
1904                 return False;
1905
1906         return True;
1907 }
1908
1909
1910
1911 /*******************************************************************
1912  Reads or writes an  LSA_Q_GETSYSTEMACCOUNTstructure.
1913 ********************************************************************/
1914
1915 BOOL lsa_io_q_getsystemaccount(const char *desc, LSA_Q_GETSYSTEMACCOUNT  *out, prs_struct *ps, int depth)
1916 {
1917         prs_debug(ps, depth, desc, "lsa_io_q_getsystemaccount");
1918         depth++;
1919
1920         if(!prs_align(ps))
1921                 return False;
1922  
1923         if(!smb_io_pol_hnd("pol", &out->pol, ps, depth))
1924                 return False;
1925
1926         return True;
1927 }
1928
1929 /*******************************************************************
1930  Reads or writes an  LSA_R_GETSYSTEMACCOUNTstructure.
1931 ********************************************************************/
1932
1933 BOOL lsa_io_r_getsystemaccount(const char *desc, LSA_R_GETSYSTEMACCOUNT  *out, prs_struct *ps, int depth)
1934 {
1935         prs_debug(ps, depth, desc, "lsa_io_r_getsystemaccount");
1936         depth++;
1937
1938         if(!prs_align(ps))
1939                 return False;
1940  
1941         if(!prs_uint32("access", ps, depth, &out->access))
1942                 return False;
1943
1944         if(!prs_ntstatus("status", ps, depth, &out->status))
1945                 return False;
1946
1947         return True;
1948 }
1949
1950
1951 /*******************************************************************
1952  Reads or writes an LSA_Q_SETSYSTEMACCOUNT structure.
1953 ********************************************************************/
1954
1955 BOOL lsa_io_q_setsystemaccount(const char *desc, LSA_Q_SETSYSTEMACCOUNT  *out, prs_struct *ps, int depth)
1956 {
1957         prs_debug(ps, depth, desc, "lsa_io_q_setsystemaccount");
1958         depth++;
1959
1960         if(!prs_align(ps))
1961                 return False;
1962  
1963         if(!smb_io_pol_hnd("pol", &out->pol, ps, depth))
1964                 return False;
1965
1966         if(!prs_uint32("access", ps, depth, &out->access))
1967                 return False;
1968
1969         return True;
1970 }
1971
1972 /*******************************************************************
1973  Reads or writes an LSA_R_SETSYSTEMACCOUNT structure.
1974 ********************************************************************/
1975
1976 BOOL lsa_io_r_setsystemaccount(const char *desc, LSA_R_SETSYSTEMACCOUNT  *out, prs_struct *ps, int depth)
1977 {
1978         prs_debug(ps, depth, desc, "lsa_io_r_setsystemaccount");
1979         depth++;
1980
1981         if(!prs_align(ps))
1982                 return False;
1983  
1984         if(!prs_ntstatus("status", ps, depth, &out->status))
1985                 return False;
1986
1987         return True;
1988 }
1989
1990
1991 static void init_lsa_string( LSA_STRING *uni, const char *string )
1992 {
1993         init_unistr2(&uni->unistring, string, UNI_FLAGS_NONE);
1994         init_uni_hdr(&uni->hdr, &uni->unistring);
1995 }
1996
1997 void init_lsa_q_lookup_priv_value(LSA_Q_LOOKUP_PRIV_VALUE *q_u, POLICY_HND *hnd, const char *name)
1998 {
1999         memcpy(&q_u->pol, hnd, sizeof(q_u->pol));
2000         init_lsa_string( &q_u->privname, name );
2001 }
2002
2003 BOOL smb_io_lsa_string( const char *desc, LSA_STRING *string, prs_struct *ps, int depth )
2004 {
2005         prs_debug(ps, depth, desc, "smb_io_lsa_string");
2006         depth++;
2007
2008         if(!smb_io_unihdr ("hdr", &string->hdr, ps, depth))
2009                 return False;
2010         if(!smb_io_unistr2("unistring", &string->unistring, string->hdr.buffer, ps, depth))
2011                 return False;
2012         
2013         return True;
2014 }
2015
2016 /*******************************************************************
2017  Reads or writes an LSA_Q_LOOKUP_PRIV_VALUE  structure.
2018 ********************************************************************/
2019
2020 BOOL lsa_io_q_lookup_priv_value(const char *desc, LSA_Q_LOOKUP_PRIV_VALUE  *out, prs_struct *ps, int depth)
2021 {
2022         prs_debug(ps, depth, desc, "lsa_io_q_lookup_priv_value");
2023         depth++;
2024
2025         if(!prs_align(ps))
2026                 return False;
2027  
2028         if(!smb_io_pol_hnd("pol", &out->pol, ps, depth))
2029                 return False;
2030         if(!smb_io_lsa_string("privname", &out->privname, ps, depth))
2031                 return False;
2032
2033         return True;
2034 }
2035
2036 /*******************************************************************
2037  Reads or writes an  LSA_R_LOOKUP_PRIV_VALUE structure.
2038 ********************************************************************/
2039
2040 BOOL lsa_io_r_lookup_priv_value(const char *desc, LSA_R_LOOKUP_PRIV_VALUE  *out, prs_struct *ps, int depth)
2041 {
2042         prs_debug(ps, depth, desc, "lsa_io_r_lookup_priv_value");
2043         depth++;
2044
2045         if(!prs_align(ps))
2046                 return False;
2047                 
2048         if(!lsa_io_luid("luid", &out->luid, ps, depth))
2049                 return False;
2050  
2051         if(!prs_ntstatus("status", ps, depth, &out->status))
2052                 return False;
2053
2054         return True;
2055 }
2056
2057
2058 /*******************************************************************
2059  Reads or writes an LSA_Q_ADDPRIVS structure.
2060 ********************************************************************/
2061
2062 BOOL lsa_io_q_addprivs(const char *desc, LSA_Q_ADDPRIVS *out, prs_struct *ps, int depth)
2063 {
2064         prs_debug(ps, depth, desc, "lsa_io_q_addprivs");
2065         depth++;
2066
2067         if(!prs_align(ps))
2068                 return False;
2069  
2070         if(!smb_io_pol_hnd("pol", &out->pol, ps, depth))
2071                 return False;
2072         
2073         if(!prs_uint32("count", ps, depth, &out->count))
2074                 return False;
2075
2076         if (UNMARSHALLING(ps) && out->count!=0) {
2077                 if (!NT_STATUS_IS_OK(privilege_set_init_by_ctx(ps->mem_ctx, &(out->set))))
2078                         return False;
2079                 
2080                 if (!(out->set.set = PRS_ALLOC_MEM(ps, LUID_ATTR, out->count)))
2081                         return False;
2082         }
2083         
2084         if(!lsa_io_privilege_set(desc, &out->set, ps, depth))
2085                 return False;
2086         
2087         return True;
2088 }
2089
2090 /*******************************************************************
2091  Reads or writes an LSA_R_ADDPRIVS structure.
2092 ********************************************************************/
2093
2094 BOOL lsa_io_r_addprivs(const char *desc, LSA_R_ADDPRIVS *out, prs_struct *ps, int depth)
2095 {
2096         prs_debug(ps, depth, desc, "lsa_io_r_addprivs");
2097         depth++;
2098
2099         if(!prs_align(ps))
2100                 return False;
2101  
2102         if(!prs_ntstatus("status", ps, depth, &out->status))
2103                 return False;
2104
2105         return True;
2106 }
2107
2108 /*******************************************************************
2109  Reads or writes an LSA_Q_REMOVEPRIVS structure.
2110 ********************************************************************/
2111
2112 BOOL lsa_io_q_removeprivs(const char *desc, LSA_Q_REMOVEPRIVS *out, prs_struct *ps, int depth)
2113 {
2114         prs_debug(ps, depth, desc, "lsa_io_q_removeprivs");
2115         depth++;
2116
2117         if(!prs_align(ps))
2118                 return False;
2119  
2120         if(!smb_io_pol_hnd("pol", &out->pol, ps, depth))
2121                 return False;
2122         
2123         if(!prs_uint32("allrights", ps, depth, &out->allrights))
2124                 return False;
2125
2126         if(!prs_uint32("ptr", ps, depth, &out->ptr))
2127                 return False;
2128
2129         /* 
2130          * JFM: I'm not sure at all if the count is inside the ptr
2131          * never seen one with ptr=0
2132          */
2133
2134         if (out->ptr!=0) {
2135                 if(!prs_uint32("count", ps, depth, &out->count))
2136                         return False;
2137
2138                 if (UNMARSHALLING(ps) && out->count!=0) {
2139                         if (!NT_STATUS_IS_OK(privilege_set_init_by_ctx(ps->mem_ctx, &(out->set))))
2140                                 return False;
2141
2142                         if (!(out->set.set = PRS_ALLOC_MEM(ps, LUID_ATTR, out->count)))
2143                                 return False;
2144                 }
2145
2146                 if(!lsa_io_privilege_set(desc, &out->set, ps, depth))
2147                         return False;
2148         }
2149
2150         return True;
2151 }
2152
2153 /*******************************************************************
2154  Reads or writes an LSA_R_REMOVEPRIVS structure.
2155 ********************************************************************/
2156
2157 BOOL lsa_io_r_removeprivs(const char *desc, LSA_R_REMOVEPRIVS *out, prs_struct *ps, int depth)
2158 {
2159         prs_debug(ps, depth, desc, "lsa_io_r_removeprivs");
2160         depth++;
2161
2162         if(!prs_align(ps))
2163                 return False;
2164  
2165         if(!prs_ntstatus("status", ps, depth, &out->status))
2166                 return False;
2167
2168         return True;
2169 }
2170
2171 BOOL policy_handle_is_valid(const POLICY_HND *hnd)
2172 {
2173         POLICY_HND zero_pol;
2174
2175         ZERO_STRUCT(zero_pol);
2176         return ((memcmp(&zero_pol, hnd, sizeof(POLICY_HND)) == 0) ? False : True );
2177 }
2178
2179 /*******************************************************************
2180  Reads or writes an LSA_DNS_DOM_INFO structure.
2181 ********************************************************************/
2182
2183 BOOL lsa_io_dns_dom_info(const char *desc, LSA_DNS_DOM_INFO *info,
2184                          prs_struct *ps, int depth)
2185 {
2186         prs_debug(ps, depth, desc, "lsa_io_dns_dom_info");
2187         depth++;
2188
2189         if(!prs_align(ps))
2190                 return False;
2191         if(!smb_io_unihdr("nb_name", &info->hdr_nb_dom_name, ps, depth))
2192                 return False;
2193         if(!smb_io_unihdr("dns_name", &info->hdr_dns_dom_name, ps, depth))
2194                 return False;
2195         if(!smb_io_unihdr("forest", &info->hdr_forest_name, ps, depth))
2196                 return False;
2197
2198         if(!prs_align(ps))
2199                 return False;
2200         if ( !smb_io_uuid("dom_guid", &info->dom_guid, ps, depth) )
2201                 return False;
2202
2203         if(!prs_align(ps))
2204                 return False;
2205         if(!prs_uint32("dom_sid", ps, depth, &info->ptr_dom_sid))
2206                 return False;
2207
2208         if(!smb_io_unistr2("nb_name", &info->uni_nb_dom_name,
2209                            info->hdr_nb_dom_name.buffer, ps, depth))
2210                 return False;
2211         if(!smb_io_unistr2("dns_name", &info->uni_dns_dom_name, 
2212                            info->hdr_dns_dom_name.buffer, ps, depth))
2213                 return False;
2214         if(!smb_io_unistr2("forest", &info->uni_forest_name, 
2215                            info->hdr_forest_name.buffer, ps, depth))
2216                 return False;
2217
2218         if(!smb_io_dom_sid2("dom_sid", &info->dom_sid, ps, depth))
2219                 return False;
2220
2221         return True;
2222         
2223 }
2224
2225 /*******************************************************************
2226  Inits an LSA_Q_QUERY_INFO2 structure.
2227 ********************************************************************/
2228
2229 void init_q_query2(LSA_Q_QUERY_INFO2 *in, POLICY_HND *hnd, uint16 info_class)
2230 {
2231         DEBUG(5, ("init_q_query2\n"));
2232
2233         memcpy(&in->pol, hnd, sizeof(in->pol));
2234
2235         in->info_class = info_class;
2236 }
2237
2238 /*******************************************************************
2239  Reads or writes an LSA_Q_QUERY_DNSDOMINFO structure.
2240 ********************************************************************/
2241
2242 BOOL lsa_io_q_query_info2(const char *desc, LSA_Q_QUERY_INFO2 *in, prs_struct *ps, int depth)
2243 {
2244         prs_debug(ps, depth, desc, "lsa_io_q_query_info2");
2245         depth++;
2246
2247         if(!prs_align(ps))
2248                 return False;
2249  
2250         if(!smb_io_pol_hnd("pol", &in->pol, ps, depth))
2251                 return False;
2252         
2253         if(!prs_uint16("info_class", ps, depth, &in->info_class))
2254                 return False;
2255
2256         return True;
2257 }
2258
2259 /*******************************************************************
2260  Reads or writes an LSA_R_QUERY_DNSDOMINFO structure.
2261 ********************************************************************/
2262
2263 BOOL lsa_io_r_query_info2(const char *desc, LSA_R_QUERY_INFO2 *out,
2264                           prs_struct *ps, int depth)
2265 {
2266         prs_debug(ps, depth, desc, "lsa_io_r_query_info2");
2267         depth++;
2268
2269         if(!prs_align(ps))
2270                 return False;
2271
2272         if(!prs_uint32("ptr", ps, depth, &out->ptr))
2273                 return False;
2274         if(!prs_uint16("info_class", ps, depth, &out->info_class))
2275                 return False;
2276         switch(out->info_class) {
2277         case 0x000c:
2278                 if (!lsa_io_dns_dom_info("info12", &out->info.dns_dom_info,
2279                                          ps, depth))
2280                         return False;
2281                 break;
2282         default:
2283                 DEBUG(0,("lsa_io_r_query_info2: unknown info class %d\n",
2284                          out->info_class));
2285                 return False;
2286         }
2287
2288         if(!prs_align(ps))
2289                 return False;
2290         if(!prs_ntstatus("status", ps, depth, &out->status))
2291                 return False;
2292
2293         return True;
2294 }
2295
2296 /*******************************************************************
2297  Inits an LSA_Q_ENUM_ACCT_RIGHTS structure.
2298 ********************************************************************/
2299 void init_q_enum_acct_rights(LSA_Q_ENUM_ACCT_RIGHTS *in, 
2300                              POLICY_HND *hnd, 
2301                              uint32 count, 
2302                              DOM_SID *sid)
2303 {
2304         DEBUG(5, ("init_q_enum_acct_rights\n"));
2305
2306         in->pol = *hnd;
2307         init_dom_sid2(&in->sid, sid);
2308 }
2309
2310 /*******************************************************************
2311 ********************************************************************/
2312 NTSTATUS init_r_enum_acct_rights( LSA_R_ENUM_ACCT_RIGHTS *out, PRIVILEGE_SET *privileges )
2313 {
2314         uint32 i;
2315         char *privname;
2316         const char **privname_array = NULL;
2317         int num_priv = 0;
2318
2319         for ( i=0; i<privileges->count; i++ ) {
2320                 privname = luid_to_privilege_name( &privileges->set[i].luid );
2321                 if ( privname ) {
2322                         if ( !add_string_to_array( get_talloc_ctx(), privname, &privname_array, &num_priv ) ) 
2323                                 return NT_STATUS_NO_MEMORY;
2324                 }
2325         }
2326
2327         if ( num_priv ) {
2328                 out->rights = TALLOC_P( get_talloc_ctx(), UNISTR4_ARRAY );
2329
2330                 if ( !init_unistr4_array( out->rights, num_priv, privname_array ) ) 
2331                         return NT_STATUS_NO_MEMORY;
2332
2333                 out->count = num_priv;
2334         }
2335
2336         return NT_STATUS_OK;
2337 }
2338
2339 /*******************************************************************
2340 reads or writes a LSA_Q_ENUM_ACCT_RIGHTS structure.
2341 ********************************************************************/
2342 BOOL lsa_io_q_enum_acct_rights(const char *desc, LSA_Q_ENUM_ACCT_RIGHTS *in, prs_struct *ps, int depth)
2343 {
2344         
2345         if (in == NULL)
2346                 return False;
2347
2348         prs_debug(ps, depth, desc, "lsa_io_q_enum_acct_rights");
2349         depth++;
2350
2351         if (!smb_io_pol_hnd("", &in->pol, ps, depth))
2352                 return False;
2353
2354         if(!smb_io_dom_sid2("sid", &in->sid, ps, depth))
2355                 return False;
2356
2357         return True;
2358 }
2359
2360
2361 /*******************************************************************
2362 reads or writes a LSA_R_ENUM_ACCT_RIGHTS structure.
2363 ********************************************************************/
2364 BOOL lsa_io_r_enum_acct_rights(const char *desc, LSA_R_ENUM_ACCT_RIGHTS *out, prs_struct *ps, int depth)
2365 {
2366         prs_debug(ps, depth, desc, "lsa_io_r_enum_acct_rights");
2367         depth++;
2368
2369         if(!prs_uint32("count   ", ps, depth, &out->count))
2370                 return False;
2371
2372         if ( !prs_pointer("rights", ps, depth, (void**)&out->rights, sizeof(UNISTR4_ARRAY), (PRS_POINTER_CAST)prs_unistr4_array) )
2373                 return False;
2374
2375         if(!prs_align(ps))
2376                 return False;
2377
2378         if(!prs_ntstatus("status", ps, depth, &out->status))
2379                 return False;
2380
2381         return True;
2382 }
2383
2384
2385 /*******************************************************************
2386  Inits an LSA_Q_ADD_ACCT_RIGHTS structure.
2387 ********************************************************************/
2388 void init_q_add_acct_rights( LSA_Q_ADD_ACCT_RIGHTS *in, POLICY_HND *hnd, 
2389                              DOM_SID *sid, uint32 count, const char **rights )
2390 {
2391         DEBUG(5, ("init_q_add_acct_rights\n"));
2392
2393         in->pol = *hnd;
2394         init_dom_sid2(&in->sid, sid);
2395         
2396         in->rights = TALLOC_P( get_talloc_ctx(), UNISTR4_ARRAY );
2397         init_unistr4_array( in->rights, count, rights );
2398         
2399         in->count = count;
2400 }
2401
2402
2403 /*******************************************************************
2404 reads or writes a LSA_Q_ADD_ACCT_RIGHTS structure.
2405 ********************************************************************/
2406 BOOL lsa_io_q_add_acct_rights(const char *desc, LSA_Q_ADD_ACCT_RIGHTS *in, prs_struct *ps, int depth)
2407 {
2408         prs_debug(ps, depth, desc, "lsa_io_q_add_acct_rights");
2409         depth++;
2410
2411         if (!smb_io_pol_hnd("", &in->pol, ps, depth))
2412                 return False;
2413
2414         if(!smb_io_dom_sid2("sid", &in->sid, ps, depth))
2415                 return False;
2416
2417         if(!prs_uint32("count", ps, depth, &in->count))
2418                 return False;
2419
2420         if ( !prs_pointer("rights", ps, depth, (void**)&in->rights, sizeof(UNISTR4_ARRAY), (PRS_POINTER_CAST)prs_unistr4_array) )
2421                 return False;
2422
2423         return True;
2424 }
2425
2426 /*******************************************************************
2427 reads or writes a LSA_R_ENUM_ACCT_RIGHTS structure.
2428 ********************************************************************/
2429 BOOL lsa_io_r_add_acct_rights(const char *desc, LSA_R_ADD_ACCT_RIGHTS *out, prs_struct *ps, int depth)
2430 {
2431         prs_debug(ps, depth, desc, "lsa_io_r_add_acct_rights");
2432         depth++;
2433
2434         if(!prs_ntstatus("status", ps, depth, &out->status))
2435                 return False;
2436
2437         return True;
2438 }
2439
2440
2441 /*******************************************************************
2442  Inits an LSA_Q_REMOVE_ACCT_RIGHTS structure.
2443 ********************************************************************/
2444 void init_q_remove_acct_rights(LSA_Q_REMOVE_ACCT_RIGHTS *in, 
2445                                POLICY_HND *hnd, 
2446                                DOM_SID *sid,
2447                                uint32 removeall,
2448                                uint32 count, 
2449                                const char **rights)
2450 {
2451         DEBUG(5, ("init_q_remove_acct_rights\n"));
2452
2453         in->pol = *hnd;
2454
2455         init_dom_sid2(&in->sid, sid);
2456
2457         in->removeall = removeall;
2458         in->count = count;
2459
2460         in->rights = TALLOC_P( get_talloc_ctx(), UNISTR4_ARRAY );
2461         init_unistr4_array( in->rights, count, rights );
2462 }
2463
2464
2465 /*******************************************************************
2466 reads or writes a LSA_Q_REMOVE_ACCT_RIGHTS structure.
2467 ********************************************************************/
2468 BOOL lsa_io_q_remove_acct_rights(const char *desc, LSA_Q_REMOVE_ACCT_RIGHTS *in, prs_struct *ps, int depth)
2469 {
2470         prs_debug(ps, depth, desc, "lsa_io_q_remove_acct_rights");
2471         depth++;
2472
2473         if (!smb_io_pol_hnd("", &in->pol, ps, depth))
2474                 return False;
2475
2476         if(!smb_io_dom_sid2("sid", &in->sid, ps, depth))
2477                 return False;
2478
2479         if(!prs_uint32("removeall", ps, depth, &in->removeall))
2480                 return False;
2481
2482         if(!prs_uint32("count", ps, depth, &in->count))
2483                 return False;
2484
2485         if ( !prs_pointer("rights", ps, depth, (void**)&in->rights, sizeof(UNISTR4_ARRAY), (PRS_POINTER_CAST)prs_unistr4_array) )
2486                 return False;
2487
2488         return True;
2489 }
2490
2491 /*******************************************************************
2492 reads or writes a LSA_R_ENUM_ACCT_RIGHTS structure.
2493 ********************************************************************/
2494 BOOL lsa_io_r_remove_acct_rights(const char *desc, LSA_R_REMOVE_ACCT_RIGHTS *out, prs_struct *ps, int depth)
2495 {
2496         prs_debug(ps, depth, desc, "lsa_io_r_remove_acct_rights");
2497         depth++;
2498
2499         if(!prs_ntstatus("status", ps, depth, &out->status))
2500                 return False;
2501
2502         return True;
2503 }
2504
2505 /*******************************************************************
2506  Inits an LSA_Q_OPEN_TRUSTED_DOMAIN structure.
2507 ********************************************************************/
2508
2509 void init_lsa_q_open_trusted_domain(LSA_Q_OPEN_TRUSTED_DOMAIN *q, POLICY_HND *hnd, DOM_SID *sid, uint32 desired_access)
2510 {
2511         memcpy(&q->pol, hnd, sizeof(q->pol));
2512
2513         init_dom_sid2(&q->sid, sid);
2514         q->access_mask = desired_access;
2515 }
2516
2517 /*******************************************************************
2518 ********************************************************************/
2519
2520 #if 0 /* jerry, I think this not correct - gd */
2521 BOOL lsa_io_q_open_trusted_domain(const char *desc, LSA_Q_OPEN_TRUSTED_DOMAIN *in, prs_struct *ps, int depth)
2522 {
2523         prs_debug(ps, depth, desc, "lsa_io_q_open_trusted_domain");
2524         depth++;
2525
2526         if(!prs_align(ps))
2527                 return False;
2528
2529         if (!smb_io_pol_hnd("", &in->handle, ps, depth))
2530                 return False;
2531
2532         if(!prs_uint32("count", ps, depth, &in->count))
2533                 return False;
2534
2535         if(!smb_io_dom_sid("sid", &in->sid, ps, depth))
2536                 return False;
2537
2538         return True;
2539 }
2540 #endif
2541
2542 /*******************************************************************
2543  Reads or writes an LSA_Q_OPEN_TRUSTED_DOMAIN structure.
2544 ********************************************************************/
2545
2546 BOOL lsa_io_q_open_trusted_domain(const char *desc, LSA_Q_OPEN_TRUSTED_DOMAIN *q_o, prs_struct *ps, int depth)
2547 {
2548         prs_debug(ps, depth, desc, "lsa_io_q_open_trusted_domain");
2549         depth++;
2550
2551         if(!prs_align(ps))
2552                 return False;
2553  
2554         if(!smb_io_pol_hnd("pol", &q_o->pol, ps, depth))
2555                 return False;
2556
2557         if(!smb_io_dom_sid2("sid", &q_o->sid, ps, depth))
2558                 return False;
2559
2560         if(!prs_uint32("access", ps, depth, &q_o->access_mask))
2561                 return False;
2562   
2563         return True;
2564 }
2565
2566 /*******************************************************************
2567  Reads or writes an LSA_R_OPEN_TRUSTED_DOMAIN structure.
2568 ********************************************************************/
2569
2570 BOOL lsa_io_r_open_trusted_domain(const char *desc, LSA_R_OPEN_TRUSTED_DOMAIN *out, prs_struct *ps, int depth)
2571 {
2572         prs_debug(ps, depth, desc, "lsa_io_r_open_trusted_domain");
2573         depth++;
2574
2575         if(!prs_align(ps))
2576                 return False;
2577
2578         if (!smb_io_pol_hnd("handle", &out->handle, ps, depth))
2579                 return False;
2580
2581         if(!prs_ntstatus("status", ps, depth, &out->status))
2582                 return False;
2583
2584         return True;
2585 }
2586
2587 /*******************************************************************
2588 ********************************************************************/
2589
2590 BOOL lsa_io_q_create_trusted_domain(const char *desc, LSA_Q_CREATE_TRUSTED_DOMAIN *in, prs_struct *ps, int depth)
2591 {
2592         prs_debug(ps, depth, desc, "lsa_io_q_create_trusted_domain");
2593         depth++;
2594
2595         if(!prs_align(ps))
2596                 return False;
2597
2598         if(!smb_io_pol_hnd("", &in->handle, ps, depth))
2599                 return False;
2600
2601         if(!prs_unistr4 ("secretname", ps, depth, &in->secretname))
2602                 return False;
2603         if(!prs_align(ps))
2604                 return False;
2605
2606         if(!prs_uint32("access", ps, depth, &in->access))
2607                 return False;
2608
2609         return True;
2610 }
2611
2612 /*******************************************************************
2613 ********************************************************************/
2614
2615 BOOL lsa_io_r_create_trusted_domain(const char *desc, LSA_R_CREATE_TRUSTED_DOMAIN *out, prs_struct *ps, int depth)
2616 {
2617         prs_debug(ps, depth, desc, "lsa_io_r_create_trusted_domain");
2618         depth++;
2619
2620         if(!prs_align(ps))
2621                 return False;
2622
2623         if (!smb_io_pol_hnd("", &out->handle, ps, depth))
2624                 return False;
2625
2626         if(!prs_ntstatus("status", ps, depth, &out->status))
2627                 return False;
2628
2629         return True;
2630 }
2631
2632 /*******************************************************************
2633 ********************************************************************/
2634
2635 BOOL lsa_io_q_create_secret(const char *desc, LSA_Q_CREATE_SECRET *in, prs_struct *ps, int depth)
2636 {
2637         prs_debug(ps, depth, desc, "lsa_io_q_create_secret");
2638         depth++;
2639
2640         if(!prs_align(ps))
2641                 return False;
2642
2643         if(!smb_io_pol_hnd("", &in->handle, ps, depth))
2644                 return False;
2645
2646         if(!prs_unistr4 ("secretname", ps, depth, &in->secretname))
2647                 return False;
2648         if(!prs_align(ps))
2649                 return False;
2650
2651         if(!prs_uint32("access", ps, depth, &in->access))
2652                 return False;
2653
2654         return True;
2655 }
2656
2657 /*******************************************************************
2658 ********************************************************************/
2659
2660 BOOL lsa_io_r_create_secret(const char *desc, LSA_R_CREATE_SECRET *out, prs_struct *ps, int depth)
2661 {
2662         prs_debug(ps, depth, desc, "lsa_io_r_create_secret");
2663         depth++;
2664
2665         if(!prs_align(ps))
2666                 return False;
2667
2668         if (!smb_io_pol_hnd("", &out->handle, ps, depth))
2669                 return False;
2670
2671         if(!prs_ntstatus("status", ps, depth, &out->status))
2672                 return False;
2673
2674         return True;
2675 }
2676
2677
2678
2679 /*******************************************************************
2680 ********************************************************************/
2681
2682 static BOOL lsa_io_data_blob( const char *desc, prs_struct *ps, int depth, LSA_DATA_BLOB *blob )
2683 {
2684         prs_debug(ps, depth, desc, "lsa_io_data_blob");
2685         depth++;
2686
2687         if ( !prs_uint32("size", ps, depth, &blob->size) )
2688                 return False;
2689         if ( !prs_uint32("size", ps, depth, &blob->size) )
2690                 return False;
2691
2692         if ( !prs_io_unistr2_p(desc, ps, depth, &blob->data) )
2693                 return False;
2694
2695         return True;
2696 }
2697
2698 /*******************************************************************
2699 ********************************************************************/
2700
2701 BOOL lsa_io_q_set_secret(const char *desc, LSA_Q_SET_SECRET *in, prs_struct *ps, int depth)
2702 {
2703         prs_debug(ps, depth, desc, "lsa_io_q_set_secret");
2704         depth++;
2705
2706         if ( !prs_align(ps) )
2707                 return False;
2708
2709         if ( !smb_io_pol_hnd("", &in->handle, ps, depth) )
2710                 return False;
2711
2712         if ( !prs_pointer( "old_value", ps, depth, (void*)&in->old_value, sizeof(LSA_DATA_BLOB), (PRS_POINTER_CAST)lsa_io_data_blob ))
2713                 return False;
2714
2715         if( !prs_align(ps) )
2716                 return False;
2717         if ( !prs_pointer( "old_value", ps, depth, (void*)&in->old_value, sizeof(LSA_DATA_BLOB), (PRS_POINTER_CAST)lsa_io_data_blob ))
2718                 return False;
2719
2720
2721         return True;
2722 }
2723
2724 /*******************************************************************
2725 ********************************************************************/
2726
2727 BOOL lsa_io_r_set_secret(const char *desc, LSA_R_SET_SECRET *out, prs_struct *ps, int depth)
2728 {
2729         prs_debug(ps, depth, desc, "lsa_io_r_set_secret");
2730         depth++;
2731
2732         if(!prs_ntstatus("status", ps, depth, &out->status))
2733                 return False;
2734
2735         return True;
2736 }
2737
2738 /*******************************************************************
2739 ********************************************************************/
2740
2741 BOOL lsa_io_q_delete_object(const char *desc, LSA_Q_DELETE_OBJECT *in, prs_struct *ps, int depth)
2742 {
2743         prs_debug(ps, depth, desc, "lsa_io_q_delete_object");
2744         depth++;
2745
2746         if(!prs_align(ps))
2747                 return False;
2748
2749         if(!smb_io_pol_hnd("", &in->handle, ps, depth))
2750                 return False;
2751
2752         return True;
2753 }
2754
2755 /*******************************************************************
2756 ********************************************************************/
2757
2758 BOOL lsa_io_r_delete_object(const char *desc, LSA_R_DELETE_OBJECT *out, prs_struct *ps, int depth)
2759 {
2760         prs_debug(ps, depth, desc, "lsa_io_r_delete_object");
2761         depth++;
2762
2763         if(!prs_ntstatus("status", ps, depth, &out->status))
2764                 return False;
2765
2766         return True;
2767 }
2768
2769 /*******************************************************************
2770  Inits an LSA_Q_QUERY_TRUSTED_DOMAIN_INFO structure.
2771 ********************************************************************/
2772
2773 void init_q_query_trusted_domain_info(LSA_Q_QUERY_TRUSTED_DOMAIN_INFO *q, 
2774                                       POLICY_HND *hnd, uint16 info_class) 
2775 {
2776         DEBUG(5, ("init_q_query_trusted_domain_info\n"));
2777         
2778         q->pol = *hnd;
2779         q->info_class = info_class;
2780 }
2781
2782 /*******************************************************************
2783  Inits an LSA_Q_QUERY_TRUSTED_DOMAIN_INFO_BY_NAME structure.
2784 ********************************************************************/
2785
2786 void init_q_query_trusted_domain_info_by_name(LSA_Q_QUERY_TRUSTED_DOMAIN_INFO_BY_NAME *q, 
2787                                               POLICY_HND *hnd, uint16 info_class, 
2788                                               const char *dom_name)
2789 {
2790         DEBUG(5, ("init_q_query_trusted_domain_info_by_name\n"));
2791         
2792         q->pol = *hnd;
2793         init_lsa_string(&q->domain_name, dom_name );
2794         q->info_class = info_class;
2795 }
2796
2797 /*******************************************************************
2798  Inits an LSA_Q_QUERY_TRUSTED_DOMAIN_INFO_BY_SID structure.
2799 ********************************************************************/
2800
2801 void init_q_query_trusted_domain_info_by_sid(LSA_Q_QUERY_TRUSTED_DOMAIN_INFO_BY_SID *q, 
2802                                              POLICY_HND *hnd, uint16 info_class, 
2803                                              DOM_SID *dom_sid)
2804 {
2805         DEBUG(5, ("init_q_query_trusted_domain_info_by_sid\n"));
2806         
2807         q->pol = *hnd;
2808         init_dom_sid2(&q->dom_sid, dom_sid);
2809         q->info_class = info_class;
2810 }
2811
2812 /*******************************************************************
2813  Reads or writes an LSA_Q_QUERY_TRUSTED_DOMAIN_INFO structure.
2814 ********************************************************************/
2815
2816 BOOL lsa_io_q_query_trusted_domain_info(const char *desc, 
2817                                         LSA_Q_QUERY_TRUSTED_DOMAIN_INFO *q_q,
2818                                         prs_struct *ps, int depth)
2819 {
2820         prs_debug(ps, depth, desc, "lsa_io_q_query_trusted_domain_info");
2821         depth++;
2822
2823         if(!prs_align(ps))
2824                 return False;
2825
2826         if(!smb_io_pol_hnd("pol", &q_q->pol, ps, depth))
2827                 return False;
2828
2829         if(!prs_uint16("info_class", ps, depth, &q_q->info_class))
2830                 return False;
2831
2832         return True;
2833 }
2834
2835
2836 /*******************************************************************
2837  Reads or writes an LSA_Q_QUERY_TRUSTED_DOMAIN_INFO_BY_SID structure.
2838 ********************************************************************/
2839
2840 BOOL lsa_io_q_query_trusted_domain_info_by_sid(const char *desc, 
2841                                                LSA_Q_QUERY_TRUSTED_DOMAIN_INFO_BY_SID *q_q,
2842                                                prs_struct *ps, int depth)
2843 {
2844         prs_debug(ps, depth, desc, "lsa_io_q_query_trusted_domain_info_by_sid");
2845         depth++;
2846
2847         if(!prs_align(ps))
2848                 return False;
2849
2850         if(!smb_io_pol_hnd("pol", &q_q->pol, ps, depth))
2851                 return False;
2852
2853         if(!prs_align(ps))
2854                 return False;
2855
2856         if(!smb_io_dom_sid2("dom_sid", &q_q->dom_sid, ps, depth))
2857                 return False;
2858
2859         if(!prs_uint16("info_class", ps, depth, &q_q->info_class))
2860                 return False;
2861
2862         return True;
2863 }
2864
2865 /*******************************************************************
2866  Reads or writes an LSA_Q_QUERY_TRUSTED_DOMAIN_INFO_BY_NAME structure.
2867 ********************************************************************/
2868
2869 BOOL lsa_io_q_query_trusted_domain_info_by_name(const char *desc, 
2870                                                 LSA_Q_QUERY_TRUSTED_DOMAIN_INFO_BY_NAME *q_q,
2871                                                 prs_struct *ps, int depth)
2872 {
2873         prs_debug(ps, depth, desc, "lsa_io_q_query_trusted_domain_info_by_name");
2874         depth++;
2875
2876         if(!prs_align(ps))
2877                 return False;
2878
2879         if(!smb_io_pol_hnd("pol", &q_q->pol, ps, depth))
2880                 return False;
2881
2882         if(!prs_align(ps))
2883                 return False;
2884
2885         if(!smb_io_lsa_string("domain_name", &q_q->domain_name, ps, depth))
2886                 return False;
2887
2888         if(!prs_uint16("info_class", ps, depth, &q_q->info_class))
2889                 return False;
2890
2891         return True;
2892 }
2893
2894 /*******************************************************************
2895 ********************************************************************/
2896
2897 static BOOL smb_io_lsa_data_buf_hdr(const char *desc, LSA_DATA_BUF_HDR *buf_hdr, 
2898                                     prs_struct *ps, int depth)
2899 {
2900         prs_debug(ps, depth, desc, "smb_io_lsa_data_buf_hdr");
2901         depth++;
2902
2903         if(!prs_align(ps))
2904                 return False;
2905
2906         if(!prs_uint32("length", ps, depth, &buf_hdr->length))
2907                 return False;
2908         
2909         if(!prs_uint32("size", ps, depth, &buf_hdr->size))
2910                 return False;
2911
2912         if (!prs_uint32("data_ptr", ps, depth, &buf_hdr->data_ptr))
2913                 return False;
2914
2915         return True;
2916 }
2917
2918 /*******************************************************************
2919 ********************************************************************/
2920
2921 static BOOL smb_io_lsa_data_buf(const char *desc, LSA_DATA_BUF *buf, 
2922                                 prs_struct *ps, int depth, int length, int size)
2923 {
2924         prs_debug(ps, depth, desc, "smb_io_lsa_data_buf");
2925         depth++;
2926
2927         if ( UNMARSHALLING(ps) ) {
2928                 if ( !(buf->data = PRS_ALLOC_MEM( ps, uint8, length )) )
2929                         return False;
2930         }
2931
2932         if (!prs_uint32("size", ps, depth, &buf->size))
2933                 return False;
2934
2935         if (!prs_uint32("offset", ps, depth, &buf->offset))
2936                 return False;
2937
2938         if (!prs_uint32("length", ps, depth, &buf->length))
2939                 return False;
2940
2941         if(!prs_uint8s(False, "data", ps, depth, buf->data, size))
2942                 return False;
2943
2944         return True;
2945 }
2946
2947 /*******************************************************************
2948 ********************************************************************/
2949
2950 static BOOL lsa_io_trustdom_query_1(const char *desc, TRUSTED_DOMAIN_INFO_NAME *name, 
2951                                     prs_struct *ps, int depth)
2952 {
2953         if (!smb_io_lsa_string("netbios_name", &name->netbios_name, ps, depth))
2954                 return False;
2955
2956         return True;
2957 }
2958
2959 /*******************************************************************
2960 ********************************************************************/
2961
2962 static BOOL lsa_io_trustdom_query_3(const char *desc, TRUSTED_DOMAIN_INFO_POSIX_OFFSET *posix, 
2963                                     prs_struct *ps, int depth)
2964 {
2965         if(!prs_uint32("posix_offset", ps, depth, &posix->posix_offset))
2966                 return False;
2967
2968         return True;
2969 }
2970
2971 /*******************************************************************
2972 ********************************************************************/
2973
2974 static BOOL lsa_io_trustdom_query_4(const char *desc, TRUSTED_DOMAIN_INFO_PASSWORD *password, 
2975                                     prs_struct *ps, int depth)
2976 {
2977         if(!prs_align(ps))
2978                 return False;
2979         
2980         if(!prs_uint32("ptr_password", ps, depth, &password->ptr_password))
2981                 return False;
2982
2983         if(!prs_uint32("ptr_old_password", ps, depth, &password->ptr_old_password))
2984                 return False;
2985
2986         if (&password->ptr_password) {
2987         
2988                 if (!smb_io_lsa_data_buf_hdr("password_hdr", &password->password_hdr, ps, depth))
2989                         return False;
2990
2991                 if (!smb_io_lsa_data_buf("password", &password->password, ps, depth, 
2992                                         password->password_hdr.length, password->password_hdr.size))
2993                         return False;
2994         }
2995
2996         if (&password->ptr_old_password) {
2997
2998                 if (!smb_io_lsa_data_buf_hdr("old_password_hdr", &password->old_password_hdr, ps, depth))
2999                         return False;
3000
3001                 if (!smb_io_lsa_data_buf("old_password", &password->old_password, ps, depth, 
3002                                         password->old_password_hdr.length, password->old_password_hdr.size))
3003                         return False;
3004         }
3005
3006         return True;
3007 }
3008
3009 /*******************************************************************
3010 ********************************************************************/
3011
3012 static BOOL lsa_io_trustdom_query_6(const char *desc, TRUSTED_DOMAIN_INFO_EX *info_ex, 
3013                                     prs_struct *ps, int depth)
3014 {
3015         uint32 dom_sid_ptr;
3016         
3017         if (!smb_io_unihdr("domain_name_hdr", &info_ex->domain_name.hdr, ps, depth))
3018                 return False;
3019                 
3020         if (!smb_io_unihdr("netbios_name_hdr", &info_ex->netbios_name.hdr, ps, depth))
3021                 return False;
3022
3023         if (!prs_uint32("dom_sid_ptr", ps, depth, &dom_sid_ptr))
3024                 return False;
3025
3026         if (!prs_uint32("trust_direction", ps, depth, &info_ex->trust_direction))
3027                 return False;
3028
3029         if (!prs_uint32("trust_type", ps, depth, &info_ex->trust_type))
3030                 return False;
3031
3032         if (!prs_uint32("trust_attributes", ps, depth, &info_ex->trust_attributes))
3033                 return False;
3034                 
3035         if (!smb_io_unistr2("domain_name_unistring", &info_ex->domain_name.unistring, info_ex->domain_name.hdr.buffer, ps, depth))
3036                 return False;
3037                 
3038         if (!smb_io_unistr2("netbios_name_unistring", &info_ex->netbios_name.unistring, info_ex->netbios_name.hdr.buffer, ps, depth))
3039                 return False;
3040
3041         if (!smb_io_dom_sid2("sid", &info_ex->sid, ps, depth))
3042                 return False;
3043
3044         return True;
3045 }
3046
3047 /*******************************************************************
3048 ********************************************************************/
3049
3050 static BOOL lsa_io_trustdom_query(const char *desc, prs_struct *ps, int depth, LSA_TRUSTED_DOMAIN_INFO *info)
3051 {
3052         prs_debug(ps, depth, desc, "lsa_io_trustdom_query");
3053         depth++;
3054
3055         if(!prs_uint16("info_class", ps, depth, &info->info_class))
3056                 return False;
3057
3058         if(!prs_align(ps))
3059                 return False;
3060
3061         switch (info->info_class) {
3062         case 1:
3063                 if(!lsa_io_trustdom_query_1("name", &info->name, ps, depth))
3064                         return False;
3065                 break;
3066         case 3:
3067                 if(!lsa_io_trustdom_query_3("posix_offset", &info->posix_offset, ps, depth))
3068                         return False;
3069                 break;
3070         case 4:
3071                 if(!lsa_io_trustdom_query_4("password", &info->password, ps, depth))
3072                         return False;
3073                 break;
3074         case 6:
3075                 if(!lsa_io_trustdom_query_6("info_ex", &info->info_ex, ps, depth))
3076                         return False;
3077                 break;
3078         default:
3079                 DEBUG(0,("unsupported info-level: %d\n", info->info_class));
3080                 return False;
3081         }
3082
3083         return True;
3084 }
3085
3086 /*******************************************************************
3087  Reads or writes an LSA_R_QUERY_TRUSTED_DOMAIN_INFO structure.
3088 ********************************************************************/
3089
3090 BOOL lsa_io_r_query_trusted_domain_info(const char *desc, 
3091                                         LSA_R_QUERY_TRUSTED_DOMAIN_INFO *r_q, 
3092                                         prs_struct *ps, int depth)
3093 {
3094         if (r_q == NULL)
3095                 return False;
3096
3097         prs_debug(ps, depth, desc, "lsa_io_r_query_trusted_domain_info");
3098         depth++;
3099
3100         if (!prs_pointer("trustdom", ps, depth, (void**)&r_q->info, 
3101                          sizeof(LSA_TRUSTED_DOMAIN_INFO), 
3102                          (PRS_POINTER_CAST)lsa_io_trustdom_query) )
3103                 return False;
3104
3105         if(!prs_align(ps))
3106                 return False;
3107
3108         if(!prs_ntstatus("status", ps, depth, &r_q->status))
3109                 return False;
3110
3111         return True;
3112 }
3113