r13316: Let the carnage begin....
[sfrench/samba-autobuild/.git] / 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,
512                            uint32 enum_context, uint32 num_domains,
513                            struct trustdom_info **td)
514 {
515         unsigned int i;
516
517         DEBUG(5, ("init_r_enum_trust_dom\n"));
518         
519         out->enum_context  = enum_context;
520         out->count         = num_domains;
521                         
522         if ( num_domains != 0 ) {
523         
524                 /* allocate container memory */
525                 
526                 out->domlist = TALLOC_P( ctx, DOMAIN_LIST );
527                 out->domlist->domains = TALLOC_ARRAY( ctx, DOMAIN_INFO,
528                                                       out->count );
529                 
530                 if ( !out->domlist || !out->domlist->domains ) {
531                         out->status = NT_STATUS_NO_MEMORY;
532                         return;
533                 }
534                 
535                 out->domlist->count = out->count;
536                 
537                 /* initialize the list of domains and their sid */
538                 
539                 for (i = 0; i < num_domains; i++) {     
540                         smb_ucs2_t *name;
541                         if ( !(out->domlist->domains[i].sid =
542                                TALLOC_P(ctx, DOM_SID2)) ) {
543                                 out->status = NT_STATUS_NO_MEMORY;
544                                 return;
545                         }
546                                 
547                         init_dom_sid2(out->domlist->domains[i].sid,
548                                       &(td[i])->sid);
549                         if (push_ucs2_talloc(ctx, &name, (td[i])->name) < 0){
550                                 out->status = NT_STATUS_NO_MEMORY;
551                                 return;
552                         }
553                         init_unistr4_w(ctx, &out->domlist->domains[i].name,
554                                        name);
555                 }
556         }
557
558 }
559
560 /*******************************************************************
561 ********************************************************************/
562
563 BOOL lsa_io_domain_list( const char *desc, prs_struct *ps, int depth, DOMAIN_LIST *domlist )
564 {
565         int i;
566         
567         prs_debug(ps, depth, desc, "lsa_io_domain_list");
568         depth++;
569
570         if(!prs_uint32("count", ps, depth, &domlist->count))
571                 return False;
572
573         if ( domlist->count == 0 )
574                 return True;
575                 
576         if ( UNMARSHALLING(ps) ) {
577                 if ( !(domlist->domains = PRS_ALLOC_MEM( ps, DOMAIN_INFO, domlist->count )) )
578                         return False;
579         }
580         
581         /* headers */
582         
583         for ( i=0; i<domlist->count; i++ ) {
584                 if ( !prs_unistr4_hdr("name_header", ps, depth, &domlist->domains[i].name) )
585                         return False;
586                 if ( !smb_io_dom_sid2_p("sid_header", ps, depth, &domlist->domains[i].sid) )
587                         return False;
588         }
589
590         /* data */
591         
592         for ( i=0; i<domlist->count; i++ ) {
593                 if ( !prs_unistr4_str("name", ps, depth, &domlist->domains[i].name) )
594                         return False;
595                 if( !smb_io_dom_sid2("sid", domlist->domains[i].sid, ps, depth) )
596                         return False;
597         }
598         
599         return True;
600 }
601
602 /*******************************************************************
603  Reads or writes an LSA_R_ENUM_TRUST_DOM structure.
604 ********************************************************************/
605
606 BOOL lsa_io_r_enum_trust_dom(const char *desc, LSA_R_ENUM_TRUST_DOM *out, 
607                              prs_struct *ps, int depth)
608 {
609         prs_debug(ps, depth, desc, "lsa_io_r_enum_trust_dom");
610         depth++;
611
612         if(!prs_uint32("enum_context", ps, depth, &out->enum_context))
613                 return False;
614
615         if(!prs_uint32("count", ps, depth, &out->count))
616                 return False;
617
618         if ( !prs_pointer("trusted_domains", ps, depth, (void**)&out->domlist, sizeof(DOMAIN_LIST), (PRS_POINTER_CAST)lsa_io_domain_list))
619                 return False;
620                 
621         if(!prs_ntstatus("status", ps, depth, &out->status))
622                 return False;
623
624         return True;
625 }
626
627 /*******************************************************************
628 reads or writes a dom query structure.
629 ********************************************************************/
630
631 static BOOL lsa_io_dom_query(const char *desc, DOM_QUERY *d_q, prs_struct *ps, int depth)
632 {
633         if (d_q == NULL)
634                 return False;
635
636         prs_debug(ps, depth, desc, "lsa_io_dom_query");
637         depth++;
638
639         if(!prs_align(ps))
640                 return False;
641
642         if(!prs_uint16("uni_dom_max_len", ps, depth, &d_q->uni_dom_max_len)) /* domain name string length * 2 */
643                 return False;
644         if(!prs_uint16("uni_dom_str_len", ps, depth, &d_q->uni_dom_str_len)) /* domain name string length * 2 */
645                 return False;
646
647         if(!prs_uint32("buffer_dom_name", ps, depth, &d_q->buffer_dom_name)) /* undocumented domain name string buffer pointer */
648                 return False;
649         if(!prs_uint32("buffer_dom_sid ", ps, depth, &d_q->buffer_dom_sid)) /* undocumented domain SID string buffer pointer */
650                 return False;
651
652         if(!smb_io_unistr2("unistr2", &d_q->uni_domain_name, d_q->buffer_dom_name, ps, depth)) /* domain name (unicode string) */
653                 return False;
654
655         if(!prs_align(ps))
656                 return False;
657
658         if (d_q->buffer_dom_sid != 0) {
659                 if(!smb_io_dom_sid2("", &d_q->dom_sid, ps, depth)) /* domain SID */
660                         return False;
661         } else {
662                 memset((char *)&d_q->dom_sid, '\0', sizeof(d_q->dom_sid));
663         }
664
665         return True;
666 }
667
668 /*******************************************************************
669 reads or writes a structure.
670 ********************************************************************/
671
672 static BOOL lsa_io_dom_query_2(const char *desc, DOM_QUERY_2 *d_q, prs_struct *ps, int depth)
673 {
674         uint32 ptr = 1;
675
676         if (d_q == NULL)
677                 return False;
678
679         prs_debug(ps, depth, desc, "lsa_io_dom_query_2");
680         depth++;
681
682         if (!prs_align(ps))
683                 return False;
684
685         if (!prs_uint32("auditing_enabled", ps, depth, &d_q->auditing_enabled))
686                 return False;
687         if (!prs_uint32("ptr   ", ps, depth, &ptr))
688                 return False;
689         if (!prs_uint32("count1", ps, depth, &d_q->count1))
690                 return False;
691         if (!prs_uint32("count2", ps, depth, &d_q->count2))
692                 return False;
693
694         if (UNMARSHALLING(ps)) {
695                 d_q->auditsettings = TALLOC_ZERO_ARRAY(ps->mem_ctx, uint32, d_q->count2);
696         }
697
698         if (d_q->auditsettings == NULL) {
699                 DEBUG(1, ("lsa_io_dom_query_2: NULL auditsettings!\n"));
700                 return False;
701         }
702
703         if (!prs_uint32s(False, "auditsettings", ps, depth, d_q->auditsettings, d_q->count2))
704                 return False;
705
706     return True;
707 }
708
709 /*******************************************************************
710  Reads or writes a dom query structure.
711 ********************************************************************/
712
713 static BOOL lsa_io_dom_query_3(const char *desc, DOM_QUERY_3 *d_q, prs_struct *ps, int depth)
714 {
715         return lsa_io_dom_query("", d_q, ps, depth);
716 }
717
718 /*******************************************************************
719  Reads or writes a dom query structure.
720 ********************************************************************/
721
722 static BOOL lsa_io_dom_query_5(const char *desc, DOM_QUERY_5 *d_q, prs_struct *ps, int depth)
723 {
724         return lsa_io_dom_query("", d_q, ps, depth);
725 }
726
727 /*******************************************************************
728  Reads or writes a dom query structure.
729 ********************************************************************/
730
731 static BOOL lsa_io_dom_query_6(const char *desc, DOM_QUERY_6 *d_q, prs_struct *ps, int depth)
732 {
733         if (d_q == NULL)
734                 return False;
735
736         prs_debug(ps, depth, desc, "lsa_io_dom_query_6");
737         depth++;
738
739         if (!prs_uint16("server_role", ps, depth, &d_q->server_role))
740                 return False;
741
742         return True;
743 }
744
745 /*******************************************************************
746  Reads or writes an LSA_R_QUERY_INFO structure.
747 ********************************************************************/
748
749 BOOL lsa_io_r_query(const char *desc, LSA_R_QUERY_INFO *out, prs_struct *ps, int depth)
750 {
751         prs_debug(ps, depth, desc, "lsa_io_r_query");
752         depth++;
753
754         if(!prs_uint32("undoc_buffer", ps, depth, &out->undoc_buffer))
755                 return False;
756
757         if (out->undoc_buffer != 0) {
758                 if(!prs_uint16("info_class", ps, depth, &out->info_class))
759                         return False;
760
761                 if(!prs_align(ps))
762                         return False;
763
764                 switch (out->info_class) {
765                 case 2:
766                         if(!lsa_io_dom_query_2("", &out->dom.id2, ps, depth))
767                                 return False;
768                         break;
769                 case 3:
770                         if(!lsa_io_dom_query_3("", &out->dom.id3, ps, depth))
771                                 return False;
772                         break;
773                 case 5:
774                         if(!lsa_io_dom_query_5("", &out->dom.id5, ps, depth))
775                                 return False;
776                         break;
777                 case 6:
778                         if(!lsa_io_dom_query_6("", &out->dom.id6, ps, depth))
779                                 return False;
780                         break;
781                 default:
782                         /* PANIC! */
783                         break;
784                 }
785         }
786
787         if(!prs_align(ps))
788                 return False;
789
790         if(!prs_ntstatus("status", ps, depth, &out->status))
791                 return False;
792
793         return True;
794 }
795
796 /*******************************************************************
797  Inits a LSA_SID_ENUM structure.
798 ********************************************************************/
799
800 static void init_lsa_sid_enum(TALLOC_CTX *mem_ctx, LSA_SID_ENUM *sen, 
801                        int num_entries, const DOM_SID *sids)
802 {
803         int i;
804
805         DEBUG(5, ("init_lsa_sid_enum\n"));
806
807         sen->num_entries  = num_entries;
808         sen->ptr_sid_enum = (num_entries != 0);
809         sen->num_entries2 = num_entries;
810
811         /* Allocate memory for sids and sid pointers */
812
813         if (num_entries == 0) return;
814
815         if ((sen->ptr_sid = TALLOC_ZERO_ARRAY(mem_ctx, uint32, num_entries )) == NULL) {
816                 DEBUG(3, ("init_lsa_sid_enum(): out of memory for ptr_sid\n"));
817                 return;
818         }
819
820         if ((sen->sid = TALLOC_ZERO_ARRAY(mem_ctx, DOM_SID2, num_entries)) == NULL) {
821                 DEBUG(3, ("init_lsa_sid_enum(): out of memory for sids\n"));
822                 return;
823         }
824
825         /* Copy across SIDs and SID pointers */
826
827         for (i = 0; i < num_entries; i++) {
828                 sen->ptr_sid[i] = 1;
829                 init_dom_sid2(&sen->sid[i], &sids[i]);
830         }
831 }
832
833 /*******************************************************************
834  Reads or writes a LSA_SID_ENUM structure.
835 ********************************************************************/
836
837 static BOOL lsa_io_sid_enum(const char *desc, LSA_SID_ENUM *sen, prs_struct *ps, 
838                             int depth)
839 {
840         unsigned int i;
841
842         prs_debug(ps, depth, desc, "lsa_io_sid_enum");
843         depth++;
844
845         if(!prs_align(ps))
846                 return False;
847         
848         if(!prs_uint32("num_entries ", ps, depth, &sen->num_entries))
849                 return False;
850         if(!prs_uint32("ptr_sid_enum", ps, depth, &sen->ptr_sid_enum))
851                 return False;
852
853         /*
854            if the ptr is NULL, leave here. checked from a real w2k trace.
855            JFM, 11/23/2001
856          */
857         
858         if (sen->ptr_sid_enum==0)
859                 return True;
860
861         if(!prs_uint32("num_entries2", ps, depth, &sen->num_entries2))
862                 return False;
863
864         /* Mallocate memory if we're unpacking from the wire */
865
866         if (UNMARSHALLING(ps)) {
867                 if ((sen->ptr_sid = PRS_ALLOC_MEM( ps, uint32, sen->num_entries)) == NULL) {
868                         DEBUG(3, ("init_lsa_sid_enum(): out of memory for "
869                                   "ptr_sid\n"));
870                         return False;
871                 }
872
873                 if ((sen->sid = PRS_ALLOC_MEM( ps, DOM_SID2, sen->num_entries)) == NULL) {
874                         DEBUG(3, ("init_lsa_sid_enum(): out of memory for "
875                                   "sids\n"));
876                         return False;
877                 }
878         }
879
880         for (i = 0; i < sen->num_entries; i++) {        
881                 fstring temp;
882
883                 slprintf(temp, sizeof(temp) - 1, "ptr_sid[%d]", i);
884                 if(!prs_uint32(temp, ps, depth, &sen->ptr_sid[i])) {
885                         return False;
886                 }
887         }
888
889         for (i = 0; i < sen->num_entries; i++) {
890                 fstring temp;
891
892                 slprintf(temp, sizeof(temp) - 1, "sid[%d]", i);
893                 if(!smb_io_dom_sid2(temp, &sen->sid[i], ps, depth)) {
894                         return False;
895                 }
896         }
897
898         return True;
899 }
900
901 /*******************************************************************
902  Inits an LSA_R_ENUM_TRUST_DOM structure.
903 ********************************************************************/
904
905 void init_q_lookup_sids(TALLOC_CTX *mem_ctx, LSA_Q_LOOKUP_SIDS *q_l, 
906                         POLICY_HND *hnd, int num_sids, const DOM_SID *sids,
907                         uint16 level)
908 {
909         DEBUG(5, ("init_q_lookup_sids\n"));
910
911         ZERO_STRUCTP(q_l);
912
913         memcpy(&q_l->pol, hnd, sizeof(q_l->pol));
914         init_lsa_sid_enum(mem_ctx, &q_l->sids, num_sids, sids);
915         
916         q_l->level = level;
917 }
918
919 /*******************************************************************
920  Reads or writes a LSA_Q_LOOKUP_SIDS structure.
921 ********************************************************************/
922
923 BOOL lsa_io_q_lookup_sids(const char *desc, LSA_Q_LOOKUP_SIDS *q_s, prs_struct *ps,
924                           int depth)
925 {
926         prs_debug(ps, depth, desc, "lsa_io_q_lookup_sids");
927         depth++;
928
929         if(!prs_align(ps))
930                 return False;
931         
932         if(!smb_io_pol_hnd("pol_hnd", &q_s->pol, ps, depth)) /* policy handle */
933                 return False;
934         if(!lsa_io_sid_enum("sids   ", &q_s->sids, ps, depth)) /* sids to be looked up */
935                 return False;
936         if(!lsa_io_trans_names("names  ", &q_s->names, ps, depth)) /* translated names */
937                 return False;
938
939         if(!prs_uint16("level", ps, depth, &q_s->level)) /* lookup level */
940                 return False;
941         if(!prs_align(ps))
942                 return False;
943
944         if(!prs_uint32("mapped_count", ps, depth, &q_s->mapped_count))
945                 return False;
946
947         return True;
948 }
949
950 /*******************************************************************
951  Reads or writes a structure.
952 ********************************************************************/
953
954 static BOOL lsa_io_trans_names(const char *desc, LSA_TRANS_NAME_ENUM *trn,
955                 prs_struct *ps, int depth)
956 {
957         unsigned int i;
958
959         prs_debug(ps, depth, desc, "lsa_io_trans_names");
960         depth++;
961
962         if(!prs_align(ps))
963                 return False;
964    
965         if(!prs_uint32("num_entries    ", ps, depth, &trn->num_entries))
966                 return False;
967         if(!prs_uint32("ptr_trans_names", ps, depth, &trn->ptr_trans_names))
968                 return False;
969
970         if (trn->ptr_trans_names != 0) {
971                 if(!prs_uint32("num_entries2   ", ps, depth, 
972                                &trn->num_entries2))
973                         return False;
974
975                 if (UNMARSHALLING(ps)) {
976                         if ((trn->name = PRS_ALLOC_MEM(ps, LSA_TRANS_NAME, trn->num_entries)) == NULL) {
977                                 return False;
978                         }
979
980                         if ((trn->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, trn->num_entries)) == NULL) {
981                                 return False;
982                         }
983                 }
984
985                 for (i = 0; i < trn->num_entries2; i++) {
986                         fstring t;
987                         slprintf(t, sizeof(t) - 1, "name[%d] ", i);
988
989                         if(!lsa_io_trans_name(t, &trn->name[i], ps, depth)) /* translated name */
990                                 return False;
991                 }
992
993                 for (i = 0; i < trn->num_entries2; i++) {
994                         fstring t;
995                         slprintf(t, sizeof(t) - 1, "name[%d] ", i);
996
997                         if(!smb_io_unistr2(t, &trn->uni_name[i], trn->name[i].hdr_name.buffer, ps, depth))
998                                 return False;
999                         if(!prs_align(ps))
1000                                 return False;
1001                 }
1002         }
1003
1004         return True;
1005 }
1006
1007 /*******************************************************************
1008  Reads or writes a structure.
1009 ********************************************************************/
1010
1011 BOOL lsa_io_r_lookup_sids(const char *desc, LSA_R_LOOKUP_SIDS *r_s, 
1012                           prs_struct *ps, int depth)
1013 {
1014         prs_debug(ps, depth, desc, "lsa_io_r_lookup_sids");
1015         depth++;
1016
1017         if(!prs_align(ps))
1018                 return False;
1019         
1020         if(!prs_uint32("ptr_dom_ref", ps, depth, &r_s->ptr_dom_ref))
1021                 return False;
1022
1023         if (r_s->ptr_dom_ref != 0)
1024                 if(!lsa_io_dom_r_ref ("dom_ref", r_s->dom_ref, ps, depth)) /* domain reference info */
1025                         return False;
1026
1027         if(!lsa_io_trans_names("names  ", r_s->names, ps, depth)) /* translated names */
1028                 return False;
1029
1030         if(!prs_align(ps))
1031                 return False;
1032
1033         if(!prs_uint32("mapped_count", ps, depth, &r_s->mapped_count))
1034                 return False;
1035
1036         if(!prs_ntstatus("status      ", ps, depth, &r_s->status))
1037                 return False;
1038
1039         return True;
1040 }
1041
1042 /*******************************************************************
1043 makes a structure.
1044 ********************************************************************/
1045
1046 void init_q_lookup_names(TALLOC_CTX *mem_ctx, LSA_Q_LOOKUP_NAMES *q_l, 
1047                          POLICY_HND *hnd, int num_names, const char **names)
1048 {
1049         unsigned int i;
1050
1051         DEBUG(5, ("init_q_lookup_names\n"));
1052
1053         ZERO_STRUCTP(q_l);
1054
1055         q_l->pol = *hnd;
1056         q_l->num_entries = num_names;
1057         q_l->num_entries2 = num_names;
1058         q_l->lookup_level = 1;
1059
1060         if ((q_l->uni_name = TALLOC_ZERO_ARRAY(mem_ctx, UNISTR2, num_names)) == NULL) {
1061                 DEBUG(3, ("init_q_lookup_names(): out of memory\n"));
1062                 return;
1063         }
1064
1065         if ((q_l->hdr_name = TALLOC_ZERO_ARRAY(mem_ctx, UNIHDR, num_names)) == NULL) {
1066                 DEBUG(3, ("init_q_lookup_names(): out of memory\n"));
1067                 return;
1068         }
1069
1070         for (i = 0; i < num_names; i++) {
1071                 init_unistr2(&q_l->uni_name[i], names[i], UNI_FLAGS_NONE);
1072                 init_uni_hdr(&q_l->hdr_name[i], &q_l->uni_name[i]);
1073         }
1074 }
1075
1076 /*******************************************************************
1077 reads or writes a structure.
1078 ********************************************************************/
1079
1080 BOOL lsa_io_q_lookup_names(const char *desc, LSA_Q_LOOKUP_NAMES *q_r, 
1081                            prs_struct *ps, int depth)
1082 {
1083         unsigned int i;
1084
1085         prs_debug(ps, depth, desc, "lsa_io_q_lookup_names");
1086         depth++;
1087
1088         if(!prs_align(ps))
1089                 return False;
1090
1091         if(!smb_io_pol_hnd("", &q_r->pol, ps, depth)) /* policy handle */
1092                 return False;
1093
1094         if(!prs_align(ps))
1095                 return False;
1096         if(!prs_uint32("num_entries    ", ps, depth, &q_r->num_entries))
1097                 return False;
1098         if(!prs_uint32("num_entries2   ", ps, depth, &q_r->num_entries2))
1099                 return False;
1100
1101         if (UNMARSHALLING(ps)) {
1102                 if (q_r->num_entries) {
1103                         if ((q_r->hdr_name = PRS_ALLOC_MEM(ps, UNIHDR, q_r->num_entries)) == NULL)
1104                                 return False;
1105                         if ((q_r->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, q_r->num_entries)) == NULL)
1106                                 return False;
1107                 }
1108         }
1109
1110         for (i = 0; i < q_r->num_entries; i++) {
1111                 if(!prs_align(ps))
1112                         return False;
1113                 if(!smb_io_unihdr("hdr_name", &q_r->hdr_name[i], ps, depth)) /* pointer names */
1114                         return False;
1115         }
1116
1117         for (i = 0; i < q_r->num_entries; i++) {
1118                 if(!prs_align(ps))
1119                         return False;
1120                 if(!smb_io_unistr2("dom_name", &q_r->uni_name[i], q_r->hdr_name[i].buffer, ps, depth)) /* names to be looked up */
1121                         return False;
1122         }
1123
1124         if(!prs_align(ps))
1125                 return False;
1126         if(!prs_uint32("num_trans_entries ", ps, depth, &q_r->num_trans_entries))
1127                 return False;
1128         if(!prs_uint32("ptr_trans_sids ", ps, depth, &q_r->ptr_trans_sids))
1129                 return False;
1130         if(!prs_uint32("lookup_level   ", ps, depth, &q_r->lookup_level))
1131                 return False;
1132         if(!prs_uint32("mapped_count   ", ps, depth, &q_r->mapped_count))
1133                 return False;
1134
1135         return True;
1136 }
1137
1138 /*******************************************************************
1139 reads or writes a structure.
1140 ********************************************************************/
1141
1142 BOOL lsa_io_r_lookup_names(const char *desc, LSA_R_LOOKUP_NAMES *out, prs_struct *ps, int depth)
1143 {
1144         unsigned int i;
1145
1146         prs_debug(ps, depth, desc, "lsa_io_r_lookup_names");
1147         depth++;
1148
1149         if(!prs_align(ps))
1150                 return False;
1151
1152         if(!prs_uint32("ptr_dom_ref", ps, depth, &out->ptr_dom_ref))
1153                 return False;
1154
1155         if (out->ptr_dom_ref != 0)
1156                 if(!lsa_io_dom_r_ref("", out->dom_ref, ps, depth))
1157                         return False;
1158
1159         if(!prs_uint32("num_entries", ps, depth, &out->num_entries))
1160                 return False;
1161         if(!prs_uint32("ptr_entries", ps, depth, &out->ptr_entries))
1162                 return False;
1163
1164         if (out->ptr_entries != 0) {
1165                 if(!prs_uint32("num_entries2", ps, depth, &out->num_entries2))
1166                         return False;
1167
1168                 if (out->num_entries2 != out->num_entries) {
1169                         /* RPC fault */
1170                         return False;
1171                 }
1172
1173                 if (UNMARSHALLING(ps)) {
1174                         if ((out->dom_rid = PRS_ALLOC_MEM(ps, DOM_RID2, out->num_entries2))
1175                             == NULL) {
1176                                 DEBUG(3, ("lsa_io_r_lookup_names(): out of memory\n"));
1177                                 return False;
1178                         }
1179                 }
1180
1181                 for (i = 0; i < out->num_entries2; i++)
1182                         if(!smb_io_dom_rid2("", &out->dom_rid[i], ps, depth)) /* domain RIDs being looked up */
1183                                 return False;
1184         }
1185
1186         if(!prs_uint32("mapped_count", ps, depth, &out->mapped_count))
1187                 return False;
1188
1189         if(!prs_ntstatus("status      ", ps, depth, &out->status))
1190                 return False;
1191
1192         return True;
1193 }
1194
1195
1196 /*******************************************************************
1197  Inits an LSA_Q_CLOSE structure.
1198 ********************************************************************/
1199
1200 void init_lsa_q_close(LSA_Q_CLOSE *in, POLICY_HND *hnd)
1201 {
1202         DEBUG(5, ("init_lsa_q_close\n"));
1203
1204         memcpy(&in->pol, hnd, sizeof(in->pol));
1205 }
1206
1207 /*******************************************************************
1208  Reads or writes an LSA_Q_CLOSE structure.
1209 ********************************************************************/
1210
1211 BOOL lsa_io_q_close(const char *desc, LSA_Q_CLOSE *in, prs_struct *ps, int depth)
1212 {
1213         prs_debug(ps, depth, desc, "lsa_io_q_close");
1214         depth++;
1215
1216         if(!smb_io_pol_hnd("", &in->pol, ps, depth))
1217                 return False;
1218
1219         return True;
1220 }
1221
1222 /*******************************************************************
1223  Reads or writes an LSA_R_CLOSE structure.
1224 ********************************************************************/
1225
1226 BOOL lsa_io_r_close(const char *desc,  LSA_R_CLOSE *out, prs_struct *ps, int depth)
1227 {
1228         prs_debug(ps, depth, desc, "lsa_io_r_close");
1229         depth++;
1230
1231         if(!smb_io_pol_hnd("", &out->pol, ps, depth))
1232                 return False;
1233
1234         if(!prs_ntstatus("status", ps, depth, &out->status))
1235                 return False;
1236
1237         return True;
1238 }
1239
1240 /*******************************************************************
1241  Reads or writes an LSA_Q_OPEN_SECRET structure.
1242 ********************************************************************/
1243
1244 BOOL lsa_io_q_open_secret(const char *desc, LSA_Q_OPEN_SECRET *in, prs_struct *ps, int depth)
1245 {
1246         prs_debug(ps, depth, desc, "lsa_io_q_open_secret");
1247         depth++;
1248
1249         if(!prs_align(ps))
1250                 return False;
1251
1252         if(!smb_io_pol_hnd("", &in->handle, ps, depth))
1253                 return False;
1254
1255         if(!prs_unistr4 ("secretname", ps, depth, &in->secretname))
1256                 return False;
1257         if(!prs_align(ps))
1258                 return False;
1259
1260         if(!prs_uint32("access", ps, depth, &in->access))
1261                 return False;
1262
1263         return True;
1264 }
1265
1266 /*******************************************************************
1267  Reads or writes an LSA_R_OPEN_SECRET structure.
1268 ********************************************************************/
1269
1270 BOOL lsa_io_r_open_secret(const char *desc, LSA_R_OPEN_SECRET *out, prs_struct *ps, int depth)
1271 {
1272         prs_debug(ps, depth, desc, "lsa_io_r_open_secret");
1273         depth++;
1274
1275         if(!prs_align(ps))
1276                 return False;
1277    
1278         if(!smb_io_pol_hnd("", &out->handle, ps, depth))
1279                 return False;
1280
1281         if(!prs_ntstatus("status", ps, depth, &out->status))
1282                 return False;
1283
1284         return True;
1285 }
1286
1287 /*******************************************************************
1288  Inits an LSA_Q_ENUM_PRIVS structure.
1289 ********************************************************************/
1290
1291 void init_q_enum_privs(LSA_Q_ENUM_PRIVS *in, POLICY_HND *hnd, uint32 enum_context, uint32 pref_max_length)
1292 {
1293         DEBUG(5, ("init_q_enum_privs\n"));
1294
1295         memcpy(&in->pol, hnd, sizeof(in->pol));
1296
1297         in->enum_context = enum_context;
1298         in->pref_max_length = pref_max_length;
1299 }
1300
1301 /*******************************************************************
1302 reads or writes a structure.
1303 ********************************************************************/
1304 BOOL lsa_io_q_enum_privs(const char *desc, LSA_Q_ENUM_PRIVS *in, prs_struct *ps, int depth)
1305 {
1306         if (in == NULL)
1307                 return False;
1308
1309         prs_debug(ps, depth, desc, "lsa_io_q_enum_privs");
1310         depth++;
1311
1312         if (!smb_io_pol_hnd("", &in->pol, ps, depth))
1313                 return False;
1314
1315         if(!prs_uint32("enum_context   ", ps, depth, &in->enum_context))
1316                 return False;
1317         if(!prs_uint32("pref_max_length", ps, depth, &in->pref_max_length))
1318                 return False;
1319
1320         return True;
1321 }
1322
1323 /*******************************************************************
1324 reads or writes a structure.
1325 ********************************************************************/
1326 static BOOL lsa_io_priv_entries(const char *desc, LSA_PRIV_ENTRY *entries, uint32 count, prs_struct *ps, int depth)
1327 {
1328         uint32 i;
1329
1330         if (entries == NULL)
1331                 return False;
1332
1333         prs_debug(ps, depth, desc, "lsa_io_priv_entries");
1334         depth++;
1335
1336         if(!prs_align(ps))
1337                 return False;
1338
1339         for (i = 0; i < count; i++) {
1340                 if (!smb_io_unihdr("", &entries[i].hdr_name, ps, depth))
1341                         return False;
1342                 if(!prs_uint32("luid_low ", ps, depth, &entries[i].luid_low))
1343                         return False;
1344                 if(!prs_uint32("luid_high", ps, depth, &entries[i].luid_high))
1345                         return False;
1346         }
1347
1348         for (i = 0; i < count; i++)
1349                 if (!smb_io_unistr2("", &entries[i].name, entries[i].hdr_name.buffer, ps, depth))
1350                         return False;
1351
1352         return True;
1353 }
1354
1355 /*******************************************************************
1356  Inits an LSA_R_ENUM_PRIVS structure.
1357 ********************************************************************/
1358
1359 void init_lsa_r_enum_privs(LSA_R_ENUM_PRIVS *out, uint32 enum_context,
1360                           uint32 count, LSA_PRIV_ENTRY *entries)
1361 {
1362         DEBUG(5, ("init_lsa_r_enum_privs\n"));
1363
1364         out->enum_context=enum_context;
1365         out->count=count;
1366         
1367         if (entries!=NULL) {
1368                 out->ptr=1;
1369                 out->count1=count;
1370                 out->privs=entries;
1371         } else {
1372                 out->ptr=0;
1373                 out->count1=0;
1374                 out->privs=NULL;
1375         }               
1376 }
1377
1378 /*******************************************************************
1379 reads or writes a structure.
1380 ********************************************************************/
1381 BOOL lsa_io_r_enum_privs(const char *desc, LSA_R_ENUM_PRIVS *out, prs_struct *ps, int depth)
1382 {
1383         if (out == NULL)
1384                 return False;
1385
1386         prs_debug(ps, depth, desc, "lsa_io_r_enum_privs");
1387         depth++;
1388
1389         if(!prs_align(ps))
1390                 return False;
1391
1392         if(!prs_uint32("enum_context", ps, depth, &out->enum_context))
1393                 return False;
1394         if(!prs_uint32("count", ps, depth, &out->count))
1395                 return False;
1396         if(!prs_uint32("ptr", ps, depth, &out->ptr))
1397                 return False;
1398
1399         if (out->ptr) {
1400                 if(!prs_uint32("count1", ps, depth, &out->count1))
1401                         return False;
1402
1403                 if (UNMARSHALLING(ps))
1404                         if (!(out->privs = PRS_ALLOC_MEM(ps, LSA_PRIV_ENTRY, out->count1)))
1405                                 return False;
1406
1407                 if (!lsa_io_priv_entries("", out->privs, out->count1, ps, depth))
1408                         return False;
1409         }
1410
1411         if(!prs_align(ps))
1412                 return False;
1413
1414         if(!prs_ntstatus("status", ps, depth, &out->status))
1415                 return False;
1416
1417         return True;
1418 }
1419
1420 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)
1421 {
1422         memcpy(&trn->pol, hnd, sizeof(trn->pol));
1423
1424         init_unistr2(&trn->name, name, UNI_FLAGS_NONE);
1425         init_uni_hdr(&trn->hdr_name, &trn->name);
1426         trn->lang_id = lang_id;
1427         trn->lang_id_sys = lang_id_sys;
1428 }
1429
1430 /*******************************************************************
1431 reads or writes a structure.
1432 ********************************************************************/
1433 BOOL lsa_io_q_priv_get_dispname(const char *desc, LSA_Q_PRIV_GET_DISPNAME *in, prs_struct *ps, int depth)
1434 {
1435         if (in == NULL)
1436                 return False;
1437
1438         prs_debug(ps, depth, desc, "lsa_io_q_priv_get_dispname");
1439         depth++;
1440
1441         if(!prs_align(ps))
1442                 return False;
1443
1444         if (!smb_io_pol_hnd("", &in->pol, ps, depth))
1445                 return False;
1446
1447         if (!smb_io_unihdr("hdr_name", &in->hdr_name, ps, depth))
1448                 return False;
1449
1450         if (!smb_io_unistr2("name", &in->name, in->hdr_name.buffer, ps, depth))
1451                 return False;
1452
1453         if(!prs_uint16("lang_id    ", ps, depth, &in->lang_id))
1454                 return False;
1455         if(!prs_uint16("lang_id_sys", ps, depth, &in->lang_id_sys))
1456                 return False;
1457
1458         return True;
1459 }
1460
1461 /*******************************************************************
1462 reads or writes a structure.
1463 ********************************************************************/
1464 BOOL lsa_io_r_priv_get_dispname(const char *desc, LSA_R_PRIV_GET_DISPNAME *out, prs_struct *ps, int depth)
1465 {
1466         if (out == NULL)
1467                 return False;
1468
1469         prs_debug(ps, depth, desc, "lsa_io_r_priv_get_dispname");
1470         depth++;
1471
1472         if (!prs_align(ps))
1473                 return False;
1474
1475         if (!prs_uint32("ptr_info", ps, depth, &out->ptr_info))
1476                 return False;
1477
1478         if (out->ptr_info){
1479                 if (!smb_io_unihdr("hdr_name", &out->hdr_desc, ps, depth))
1480                         return False;
1481
1482                 if (!smb_io_unistr2("desc", &out->desc, out->hdr_desc.buffer, ps, depth))
1483                         return False;
1484         }
1485 /*
1486         if(!prs_align(ps))
1487                 return False;
1488 */
1489         if(!prs_uint16("lang_id", ps, depth, &out->lang_id))
1490                 return False;
1491
1492         if(!prs_align(ps))
1493                 return False;
1494         if(!prs_ntstatus("status", ps, depth, &out->status))
1495                 return False;
1496
1497         return True;
1498 }
1499
1500 /*
1501   initialise a LSA_Q_ENUM_ACCOUNTS structure
1502 */
1503 void init_lsa_q_enum_accounts(LSA_Q_ENUM_ACCOUNTS *trn, POLICY_HND *hnd, uint32 enum_context, uint32 pref_max_length)
1504 {
1505         memcpy(&trn->pol, hnd, sizeof(trn->pol));
1506
1507         trn->enum_context = enum_context;
1508         trn->pref_max_length = pref_max_length;
1509 }
1510
1511 /*******************************************************************
1512 reads or writes a structure.
1513 ********************************************************************/
1514 BOOL lsa_io_q_enum_accounts(const char *desc, LSA_Q_ENUM_ACCOUNTS *in, prs_struct *ps, int depth)
1515 {
1516         if (in == NULL)
1517                 return False;
1518
1519         prs_debug(ps, depth, desc, "lsa_io_q_enum_accounts");
1520         depth++;
1521
1522         if (!smb_io_pol_hnd("", &in->pol, ps, depth))
1523                 return False;
1524
1525         if(!prs_uint32("enum_context   ", ps, depth, &in->enum_context))
1526                 return False;
1527         if(!prs_uint32("pref_max_length", ps, depth, &in->pref_max_length))
1528                 return False;
1529
1530         return True;
1531 }
1532
1533
1534 /*******************************************************************
1535  Inits an LSA_R_ENUM_PRIVS structure.
1536 ********************************************************************/
1537
1538 void init_lsa_r_enum_accounts(LSA_R_ENUM_ACCOUNTS *out, uint32 enum_context)
1539 {
1540         DEBUG(5, ("init_lsa_r_enum_accounts\n"));
1541
1542         out->enum_context=enum_context;
1543         if (out->enum_context!=0) {
1544                 out->sids.num_entries=enum_context;
1545                 out->sids.ptr_sid_enum=1;
1546                 out->sids.num_entries2=enum_context;
1547         } else {
1548                 out->sids.num_entries=0;
1549                 out->sids.ptr_sid_enum=0;
1550                 out->sids.num_entries2=0;
1551         }
1552 }
1553
1554 /*******************************************************************
1555 reads or writes a structure.
1556 ********************************************************************/
1557 BOOL lsa_io_r_enum_accounts(const char *desc, LSA_R_ENUM_ACCOUNTS *out, prs_struct *ps, int depth)
1558 {
1559         if (out == NULL)
1560                 return False;
1561
1562         prs_debug(ps, depth, desc, "lsa_io_r_enum_accounts");
1563         depth++;
1564
1565         if (!prs_align(ps))
1566                 return False;
1567
1568         if(!prs_uint32("enum_context", ps, depth, &out->enum_context))
1569                 return False;
1570
1571         if (!lsa_io_sid_enum("sids", &out->sids, ps, depth))
1572                 return False;
1573
1574         if (!prs_align(ps))
1575                 return False;
1576
1577         if(!prs_ntstatus("status", ps, depth, &out->status))
1578                 return False;
1579
1580         return True;
1581 }
1582
1583
1584 /*******************************************************************
1585  Reads or writes an LSA_Q_UNK_GET_CONNUSER structure.
1586 ********************************************************************/
1587
1588 BOOL lsa_io_q_unk_get_connuser(const char *desc, LSA_Q_UNK_GET_CONNUSER *in, prs_struct *ps, int depth)
1589 {
1590         prs_debug(ps, depth, desc, "lsa_io_q_unk_get_connuser");
1591         depth++;
1592
1593         if(!prs_align(ps))
1594                 return False;
1595    
1596         if(!prs_uint32("ptr_srvname", ps, depth, &in->ptr_srvname))
1597                 return False;
1598
1599         if(!smb_io_unistr2("uni2_srvname", &in->uni2_srvname, in->ptr_srvname, ps, depth)) /* server name to be looked up */
1600                 return False;
1601
1602         if (!prs_align(ps))
1603           return False;
1604
1605         if(!prs_uint32("unk1", ps, depth, &in->unk1))
1606                 return False;
1607         if(!prs_uint32("unk2", ps, depth, &in->unk2))
1608                 return False;
1609         if(!prs_uint32("unk3", ps, depth, &in->unk3))
1610                 return False;
1611
1612         /* Don't bother to read or write at present... */
1613         return True;
1614 }
1615
1616 /*******************************************************************
1617  Reads or writes an LSA_R_UNK_GET_CONNUSER structure.
1618 ********************************************************************/
1619
1620 BOOL lsa_io_r_unk_get_connuser(const char *desc, LSA_R_UNK_GET_CONNUSER *out, prs_struct *ps, int depth)
1621 {
1622         prs_debug(ps, depth, desc, "lsa_io_r_unk_get_connuser");
1623         depth++;
1624
1625         if(!prs_align(ps))
1626                 return False;
1627    
1628         if(!prs_uint32("ptr_user_name", ps, depth, &out->ptr_user_name))
1629                 return False;
1630         if(!smb_io_unihdr("hdr_user_name", &out->hdr_user_name, ps, depth))
1631                 return False;
1632         if(!smb_io_unistr2("uni2_user_name", &out->uni2_user_name, out->ptr_user_name, ps, depth))
1633                 return False;
1634
1635         if (!prs_align(ps))
1636           return False;
1637         
1638         if(!prs_uint32("unk1", ps, depth, &out->unk1))
1639                 return False;
1640
1641         if(!prs_uint32("ptr_dom_name", ps, depth, &out->ptr_dom_name))
1642                 return False;
1643         if(!smb_io_unihdr("hdr_dom_name", &out->hdr_dom_name, ps, depth))
1644                 return False;
1645         if(!smb_io_unistr2("uni2_dom_name", &out->uni2_dom_name, out->ptr_dom_name, ps, depth))
1646                 return False;
1647
1648         if (!prs_align(ps))
1649           return False;
1650         
1651         if(!prs_ntstatus("status", ps, depth, &out->status))
1652                 return False;
1653
1654         return True;
1655 }
1656
1657 void init_lsa_q_create_account(LSA_Q_CREATEACCOUNT *trn, POLICY_HND *hnd, DOM_SID *sid, uint32 desired_access)
1658 {
1659         memcpy(&trn->pol, hnd, sizeof(trn->pol));
1660
1661         init_dom_sid2(&trn->sid, sid);
1662         trn->access = desired_access;
1663 }
1664
1665
1666 /*******************************************************************
1667  Reads or writes an LSA_Q_CREATEACCOUNT structure.
1668 ********************************************************************/
1669
1670 BOOL lsa_io_q_create_account(const char *desc, LSA_Q_CREATEACCOUNT *out, prs_struct *ps, int depth)
1671 {
1672         prs_debug(ps, depth, desc, "lsa_io_q_create_account");
1673         depth++;
1674
1675         if(!prs_align(ps))
1676                 return False;
1677  
1678         if(!smb_io_pol_hnd("pol", &out->pol, ps, depth))
1679                 return False;
1680
1681         if(!smb_io_dom_sid2("sid", &out->sid, ps, depth)) /* domain SID */
1682                 return False;
1683
1684         if(!prs_uint32("access", ps, depth, &out->access))
1685                 return False;
1686   
1687         return True;
1688 }
1689
1690 /*******************************************************************
1691  Reads or writes an LSA_R_CREATEACCOUNT structure.
1692 ********************************************************************/
1693
1694 BOOL lsa_io_r_create_account(const char *desc, LSA_R_CREATEACCOUNT  *out, prs_struct *ps, int depth)
1695 {
1696         prs_debug(ps, depth, desc, "lsa_io_r_open_account");
1697         depth++;
1698
1699         if(!prs_align(ps))
1700                 return False;
1701  
1702         if(!smb_io_pol_hnd("pol", &out->pol, ps, depth))
1703                 return False;
1704
1705         if(!prs_ntstatus("status", ps, depth, &out->status))
1706                 return False;
1707
1708         return True;
1709 }
1710
1711
1712 void init_lsa_q_open_account(LSA_Q_OPENACCOUNT *trn, POLICY_HND *hnd, DOM_SID *sid, uint32 desired_access)
1713 {
1714         memcpy(&trn->pol, hnd, sizeof(trn->pol));
1715
1716         init_dom_sid2(&trn->sid, sid);
1717         trn->access = desired_access;
1718 }
1719
1720 /*******************************************************************
1721  Reads or writes an LSA_Q_OPENACCOUNT structure.
1722 ********************************************************************/
1723
1724 BOOL lsa_io_q_open_account(const char *desc, LSA_Q_OPENACCOUNT *out, prs_struct *ps, int depth)
1725 {
1726         prs_debug(ps, depth, desc, "lsa_io_q_open_account");
1727         depth++;
1728
1729         if(!prs_align(ps))
1730                 return False;
1731  
1732         if(!smb_io_pol_hnd("pol", &out->pol, ps, depth))
1733                 return False;
1734
1735         if(!smb_io_dom_sid2("sid", &out->sid, ps, depth)) /* domain SID */
1736                 return False;
1737
1738         if(!prs_uint32("access", ps, depth, &out->access))
1739                 return False;
1740   
1741         return True;
1742 }
1743
1744 /*******************************************************************
1745  Reads or writes an LSA_R_OPENACCOUNT structure.
1746 ********************************************************************/
1747
1748 BOOL lsa_io_r_open_account(const char *desc, LSA_R_OPENACCOUNT  *out, prs_struct *ps, int depth)
1749 {
1750         prs_debug(ps, depth, desc, "lsa_io_r_open_account");
1751         depth++;
1752
1753         if(!prs_align(ps))
1754                 return False;
1755  
1756         if(!smb_io_pol_hnd("pol", &out->pol, ps, depth))
1757                 return False;
1758
1759         if(!prs_ntstatus("status", ps, depth, &out->status))
1760                 return False;
1761
1762         return True;
1763 }
1764
1765
1766 void init_lsa_q_enum_privsaccount(LSA_Q_ENUMPRIVSACCOUNT *trn, POLICY_HND *hnd)
1767 {
1768         memcpy(&trn->pol, hnd, sizeof(trn->pol));
1769
1770 }
1771
1772 /*******************************************************************
1773  Reads or writes an LSA_Q_ENUMPRIVSACCOUNT structure.
1774 ********************************************************************/
1775
1776 BOOL lsa_io_q_enum_privsaccount(const char *desc, LSA_Q_ENUMPRIVSACCOUNT *out, prs_struct *ps, int depth)
1777 {
1778         prs_debug(ps, depth, desc, "lsa_io_q_enum_privsaccount");
1779         depth++;
1780
1781         if(!prs_align(ps))
1782                 return False;
1783  
1784         if(!smb_io_pol_hnd("pol", &out->pol, ps, depth))
1785                 return False;
1786
1787         return True;
1788 }
1789
1790 /*******************************************************************
1791  Reads or writes an LUID structure.
1792 ********************************************************************/
1793
1794 static BOOL lsa_io_luid(const char *desc, LUID *out, prs_struct *ps, int depth)
1795 {
1796         prs_debug(ps, depth, desc, "lsa_io_luid");
1797         depth++;
1798
1799         if(!prs_align(ps))
1800                 return False;
1801  
1802         if(!prs_uint32("low", ps, depth, &out->low))
1803                 return False;
1804
1805         if(!prs_uint32("high", ps, depth, &out->high))
1806                 return False;
1807
1808         return True;
1809 }
1810
1811 /*******************************************************************
1812  Reads or writes an LUID_ATTR structure.
1813 ********************************************************************/
1814
1815 static BOOL lsa_io_luid_attr(const char *desc, LUID_ATTR *out, prs_struct *ps, int depth)
1816 {
1817         prs_debug(ps, depth, desc, "lsa_io_luid_attr");
1818         depth++;
1819
1820         if(!prs_align(ps))
1821                 return False;
1822  
1823         if (!lsa_io_luid(desc, &out->luid, ps, depth))
1824                 return False;
1825
1826         if(!prs_uint32("attr", ps, depth, &out->attr))
1827                 return False;
1828
1829         return True;
1830 }
1831
1832 /*******************************************************************
1833  Reads or writes an PRIVILEGE_SET structure.
1834 ********************************************************************/
1835
1836 static BOOL lsa_io_privilege_set(const char *desc, PRIVILEGE_SET *out, prs_struct *ps, int depth)
1837 {
1838         uint32 i;
1839
1840         prs_debug(ps, depth, desc, "lsa_io_privilege_set");
1841         depth++;
1842
1843         if(!prs_align(ps))
1844                 return False;
1845  
1846         if(!prs_uint32("count", ps, depth, &out->count))
1847                 return False;
1848         if(!prs_uint32("control", ps, depth, &out->control))
1849                 return False;
1850
1851         for (i=0; i<out->count; i++) {
1852                 if (!lsa_io_luid_attr(desc, &out->set[i], ps, depth))
1853                         return False;
1854         }
1855         
1856         return True;
1857 }
1858
1859 NTSTATUS init_lsa_r_enum_privsaccount(TALLOC_CTX *mem_ctx, LSA_R_ENUMPRIVSACCOUNT *out, LUID_ATTR *set, uint32 count, uint32 control)
1860 {
1861         NTSTATUS ret = NT_STATUS_OK;
1862
1863         out->ptr = 1;
1864         out->count = count;
1865
1866         if ( !NT_STATUS_IS_OK(ret = privilege_set_init_by_ctx(mem_ctx, &(out->set))) )
1867                 return ret;
1868         
1869         out->set.count = count;
1870         
1871         if (!NT_STATUS_IS_OK(ret = dup_luid_attr(out->set.mem_ctx, &(out->set.set), set, count)))
1872                 return ret;
1873
1874         DEBUG(10,("init_lsa_r_enum_privsaccount: %d privileges\n", out->count));
1875
1876         return ret;
1877 }
1878
1879 /*******************************************************************
1880  Reads or writes an LSA_R_ENUMPRIVSACCOUNT structure.
1881 ********************************************************************/
1882
1883 BOOL lsa_io_r_enum_privsaccount(const char *desc, LSA_R_ENUMPRIVSACCOUNT *out, prs_struct *ps, int depth)
1884 {
1885         prs_debug(ps, depth, desc, "lsa_io_r_enum_privsaccount");
1886         depth++;
1887
1888         if(!prs_align(ps))
1889                 return False;
1890  
1891         if(!prs_uint32("ptr", ps, depth, &out->ptr))
1892                 return False;
1893
1894         if (out->ptr!=0) {
1895                 if(!prs_uint32("count", ps, depth, &out->count))
1896                         return False;
1897
1898                 /* malloc memory if unmarshalling here */
1899
1900                 if (UNMARSHALLING(ps) && out->count != 0) {
1901                         if (!NT_STATUS_IS_OK(privilege_set_init_by_ctx(ps->mem_ctx, &(out->set))))
1902                                 return False;
1903
1904                         if (!(out->set.set = PRS_ALLOC_MEM(ps,LUID_ATTR,out->count)))
1905                                 return False;
1906
1907                 }
1908                 
1909                 if(!lsa_io_privilege_set(desc, &out->set, ps, depth))
1910                         return False;
1911         }
1912
1913         if(!prs_ntstatus("status", ps, depth, &out->status))
1914                 return False;
1915
1916         return True;
1917 }
1918
1919
1920
1921 /*******************************************************************
1922  Reads or writes an  LSA_Q_GETSYSTEMACCOUNTstructure.
1923 ********************************************************************/
1924
1925 BOOL lsa_io_q_getsystemaccount(const char *desc, LSA_Q_GETSYSTEMACCOUNT  *out, prs_struct *ps, int depth)
1926 {
1927         prs_debug(ps, depth, desc, "lsa_io_q_getsystemaccount");
1928         depth++;
1929
1930         if(!prs_align(ps))
1931                 return False;
1932  
1933         if(!smb_io_pol_hnd("pol", &out->pol, ps, depth))
1934                 return False;
1935
1936         return True;
1937 }
1938
1939 /*******************************************************************
1940  Reads or writes an  LSA_R_GETSYSTEMACCOUNTstructure.
1941 ********************************************************************/
1942
1943 BOOL lsa_io_r_getsystemaccount(const char *desc, LSA_R_GETSYSTEMACCOUNT  *out, prs_struct *ps, int depth)
1944 {
1945         prs_debug(ps, depth, desc, "lsa_io_r_getsystemaccount");
1946         depth++;
1947
1948         if(!prs_align(ps))
1949                 return False;
1950  
1951         if(!prs_uint32("access", ps, depth, &out->access))
1952                 return False;
1953
1954         if(!prs_ntstatus("status", ps, depth, &out->status))
1955                 return False;
1956
1957         return True;
1958 }
1959
1960
1961 /*******************************************************************
1962  Reads or writes an LSA_Q_SETSYSTEMACCOUNT structure.
1963 ********************************************************************/
1964
1965 BOOL lsa_io_q_setsystemaccount(const char *desc, LSA_Q_SETSYSTEMACCOUNT  *out, prs_struct *ps, int depth)
1966 {
1967         prs_debug(ps, depth, desc, "lsa_io_q_setsystemaccount");
1968         depth++;
1969
1970         if(!prs_align(ps))
1971                 return False;
1972  
1973         if(!smb_io_pol_hnd("pol", &out->pol, ps, depth))
1974                 return False;
1975
1976         if(!prs_uint32("access", ps, depth, &out->access))
1977                 return False;
1978
1979         return True;
1980 }
1981
1982 /*******************************************************************
1983  Reads or writes an LSA_R_SETSYSTEMACCOUNT structure.
1984 ********************************************************************/
1985
1986 BOOL lsa_io_r_setsystemaccount(const char *desc, LSA_R_SETSYSTEMACCOUNT  *out, prs_struct *ps, int depth)
1987 {
1988         prs_debug(ps, depth, desc, "lsa_io_r_setsystemaccount");
1989         depth++;
1990
1991         if(!prs_align(ps))
1992                 return False;
1993  
1994         if(!prs_ntstatus("status", ps, depth, &out->status))
1995                 return False;
1996
1997         return True;
1998 }
1999
2000
2001 static void init_lsa_string( LSA_STRING *uni, const char *string )
2002 {
2003         init_unistr2(&uni->unistring, string, UNI_FLAGS_NONE);
2004         init_uni_hdr(&uni->hdr, &uni->unistring);
2005 }
2006
2007 void init_lsa_q_lookup_priv_value(LSA_Q_LOOKUP_PRIV_VALUE *q_u, POLICY_HND *hnd, const char *name)
2008 {
2009         memcpy(&q_u->pol, hnd, sizeof(q_u->pol));
2010         init_lsa_string( &q_u->privname, name );
2011 }
2012
2013 BOOL smb_io_lsa_string( const char *desc, LSA_STRING *string, prs_struct *ps, int depth )
2014 {
2015         prs_debug(ps, depth, desc, "smb_io_lsa_string");
2016         depth++;
2017
2018         if(!smb_io_unihdr ("hdr", &string->hdr, ps, depth))
2019                 return False;
2020         if(!smb_io_unistr2("unistring", &string->unistring, string->hdr.buffer, ps, depth))
2021                 return False;
2022         
2023         return True;
2024 }
2025
2026 /*******************************************************************
2027  Reads or writes an LSA_Q_LOOKUP_PRIV_VALUE  structure.
2028 ********************************************************************/
2029
2030 BOOL lsa_io_q_lookup_priv_value(const char *desc, LSA_Q_LOOKUP_PRIV_VALUE  *out, prs_struct *ps, int depth)
2031 {
2032         prs_debug(ps, depth, desc, "lsa_io_q_lookup_priv_value");
2033         depth++;
2034
2035         if(!prs_align(ps))
2036                 return False;
2037  
2038         if(!smb_io_pol_hnd("pol", &out->pol, ps, depth))
2039                 return False;
2040         if(!smb_io_lsa_string("privname", &out->privname, ps, depth))
2041                 return False;
2042
2043         return True;
2044 }
2045
2046 /*******************************************************************
2047  Reads or writes an  LSA_R_LOOKUP_PRIV_VALUE structure.
2048 ********************************************************************/
2049
2050 BOOL lsa_io_r_lookup_priv_value(const char *desc, LSA_R_LOOKUP_PRIV_VALUE  *out, prs_struct *ps, int depth)
2051 {
2052         prs_debug(ps, depth, desc, "lsa_io_r_lookup_priv_value");
2053         depth++;
2054
2055         if(!prs_align(ps))
2056                 return False;
2057                 
2058         if(!lsa_io_luid("luid", &out->luid, ps, depth))
2059                 return False;
2060  
2061         if(!prs_ntstatus("status", ps, depth, &out->status))
2062                 return False;
2063
2064         return True;
2065 }
2066
2067
2068 /*******************************************************************
2069  Reads or writes an LSA_Q_ADDPRIVS structure.
2070 ********************************************************************/
2071
2072 BOOL lsa_io_q_addprivs(const char *desc, LSA_Q_ADDPRIVS *out, prs_struct *ps, int depth)
2073 {
2074         prs_debug(ps, depth, desc, "lsa_io_q_addprivs");
2075         depth++;
2076
2077         if(!prs_align(ps))
2078                 return False;
2079  
2080         if(!smb_io_pol_hnd("pol", &out->pol, ps, depth))
2081                 return False;
2082         
2083         if(!prs_uint32("count", ps, depth, &out->count))
2084                 return False;
2085
2086         if (UNMARSHALLING(ps) && out->count!=0) {
2087                 if (!NT_STATUS_IS_OK(privilege_set_init_by_ctx(ps->mem_ctx, &(out->set))))
2088                         return False;
2089                 
2090                 if (!(out->set.set = PRS_ALLOC_MEM(ps, LUID_ATTR, out->count)))
2091                         return False;
2092         }
2093         
2094         if(!lsa_io_privilege_set(desc, &out->set, ps, depth))
2095                 return False;
2096         
2097         return True;
2098 }
2099
2100 /*******************************************************************
2101  Reads or writes an LSA_R_ADDPRIVS structure.
2102 ********************************************************************/
2103
2104 BOOL lsa_io_r_addprivs(const char *desc, LSA_R_ADDPRIVS *out, prs_struct *ps, int depth)
2105 {
2106         prs_debug(ps, depth, desc, "lsa_io_r_addprivs");
2107         depth++;
2108
2109         if(!prs_align(ps))
2110                 return False;
2111  
2112         if(!prs_ntstatus("status", ps, depth, &out->status))
2113                 return False;
2114
2115         return True;
2116 }
2117
2118 /*******************************************************************
2119  Reads or writes an LSA_Q_REMOVEPRIVS structure.
2120 ********************************************************************/
2121
2122 BOOL lsa_io_q_removeprivs(const char *desc, LSA_Q_REMOVEPRIVS *out, prs_struct *ps, int depth)
2123 {
2124         prs_debug(ps, depth, desc, "lsa_io_q_removeprivs");
2125         depth++;
2126
2127         if(!prs_align(ps))
2128                 return False;
2129  
2130         if(!smb_io_pol_hnd("pol", &out->pol, ps, depth))
2131                 return False;
2132         
2133         if(!prs_uint32("allrights", ps, depth, &out->allrights))
2134                 return False;
2135
2136         if(!prs_uint32("ptr", ps, depth, &out->ptr))
2137                 return False;
2138
2139         /* 
2140          * JFM: I'm not sure at all if the count is inside the ptr
2141          * never seen one with ptr=0
2142          */
2143
2144         if (out->ptr!=0) {
2145                 if(!prs_uint32("count", ps, depth, &out->count))
2146                         return False;
2147
2148                 if (UNMARSHALLING(ps) && out->count!=0) {
2149                         if (!NT_STATUS_IS_OK(privilege_set_init_by_ctx(ps->mem_ctx, &(out->set))))
2150                                 return False;
2151
2152                         if (!(out->set.set = PRS_ALLOC_MEM(ps, LUID_ATTR, out->count)))
2153                                 return False;
2154                 }
2155
2156                 if(!lsa_io_privilege_set(desc, &out->set, ps, depth))
2157                         return False;
2158         }
2159
2160         return True;
2161 }
2162
2163 /*******************************************************************
2164  Reads or writes an LSA_R_REMOVEPRIVS structure.
2165 ********************************************************************/
2166
2167 BOOL lsa_io_r_removeprivs(const char *desc, LSA_R_REMOVEPRIVS *out, prs_struct *ps, int depth)
2168 {
2169         prs_debug(ps, depth, desc, "lsa_io_r_removeprivs");
2170         depth++;
2171
2172         if(!prs_align(ps))
2173                 return False;
2174  
2175         if(!prs_ntstatus("status", ps, depth, &out->status))
2176                 return False;
2177
2178         return True;
2179 }
2180
2181 BOOL policy_handle_is_valid(const POLICY_HND *hnd)
2182 {
2183         POLICY_HND zero_pol;
2184
2185         ZERO_STRUCT(zero_pol);
2186         return ((memcmp(&zero_pol, hnd, sizeof(POLICY_HND)) == 0) ? False : True );
2187 }
2188
2189 /*******************************************************************
2190  Reads or writes an LSA_DNS_DOM_INFO structure.
2191 ********************************************************************/
2192
2193 BOOL lsa_io_dns_dom_info(const char *desc, LSA_DNS_DOM_INFO *info,
2194                          prs_struct *ps, int depth)
2195 {
2196         prs_debug(ps, depth, desc, "lsa_io_dns_dom_info");
2197         depth++;
2198
2199         if(!prs_align(ps))
2200                 return False;
2201         if(!smb_io_unihdr("nb_name", &info->hdr_nb_dom_name, ps, depth))
2202                 return False;
2203         if(!smb_io_unihdr("dns_name", &info->hdr_dns_dom_name, ps, depth))
2204                 return False;
2205         if(!smb_io_unihdr("forest", &info->hdr_forest_name, ps, depth))
2206                 return False;
2207
2208         if(!prs_align(ps))
2209                 return False;
2210         if ( !smb_io_uuid("dom_guid", &info->dom_guid, ps, depth) )
2211                 return False;
2212
2213         if(!prs_align(ps))
2214                 return False;
2215         if(!prs_uint32("dom_sid", ps, depth, &info->ptr_dom_sid))
2216                 return False;
2217
2218         if(!smb_io_unistr2("nb_name", &info->uni_nb_dom_name,
2219                            info->hdr_nb_dom_name.buffer, ps, depth))
2220                 return False;
2221         if(!smb_io_unistr2("dns_name", &info->uni_dns_dom_name, 
2222                            info->hdr_dns_dom_name.buffer, ps, depth))
2223                 return False;
2224         if(!smb_io_unistr2("forest", &info->uni_forest_name, 
2225                            info->hdr_forest_name.buffer, ps, depth))
2226                 return False;
2227
2228         if(!smb_io_dom_sid2("dom_sid", &info->dom_sid, ps, depth))
2229                 return False;
2230
2231         return True;
2232         
2233 }
2234
2235 /*******************************************************************
2236  Inits an LSA_Q_QUERY_INFO2 structure.
2237 ********************************************************************/
2238
2239 void init_q_query2(LSA_Q_QUERY_INFO2 *in, POLICY_HND *hnd, uint16 info_class)
2240 {
2241         DEBUG(5, ("init_q_query2\n"));
2242
2243         memcpy(&in->pol, hnd, sizeof(in->pol));
2244
2245         in->info_class = info_class;
2246 }
2247
2248 /*******************************************************************
2249  Reads or writes an LSA_Q_QUERY_DNSDOMINFO structure.
2250 ********************************************************************/
2251
2252 BOOL lsa_io_q_query_info2(const char *desc, LSA_Q_QUERY_INFO2 *in, prs_struct *ps, int depth)
2253 {
2254         prs_debug(ps, depth, desc, "lsa_io_q_query_info2");
2255         depth++;
2256
2257         if(!prs_align(ps))
2258                 return False;
2259  
2260         if(!smb_io_pol_hnd("pol", &in->pol, ps, depth))
2261                 return False;
2262         
2263         if(!prs_uint16("info_class", ps, depth, &in->info_class))
2264                 return False;
2265
2266         return True;
2267 }
2268
2269 /*******************************************************************
2270  Reads or writes an LSA_R_QUERY_DNSDOMINFO structure.
2271 ********************************************************************/
2272
2273 BOOL lsa_io_r_query_info2(const char *desc, LSA_R_QUERY_INFO2 *out,
2274                           prs_struct *ps, int depth)
2275 {
2276         prs_debug(ps, depth, desc, "lsa_io_r_query_info2");
2277         depth++;
2278
2279         if(!prs_align(ps))
2280                 return False;
2281
2282         if(!prs_uint32("ptr", ps, depth, &out->ptr))
2283                 return False;
2284         if(!prs_uint16("info_class", ps, depth, &out->info_class))
2285                 return False;
2286         switch(out->info_class) {
2287         case 0x000c:
2288                 if (!lsa_io_dns_dom_info("info12", &out->info.dns_dom_info,
2289                                          ps, depth))
2290                         return False;
2291                 break;
2292         default:
2293                 DEBUG(0,("lsa_io_r_query_info2: unknown info class %d\n",
2294                          out->info_class));
2295                 return False;
2296         }
2297
2298         if(!prs_align(ps))
2299                 return False;
2300         if(!prs_ntstatus("status", ps, depth, &out->status))
2301                 return False;
2302
2303         return True;
2304 }
2305
2306 /*******************************************************************
2307  Inits an LSA_Q_ENUM_ACCT_RIGHTS structure.
2308 ********************************************************************/
2309 void init_q_enum_acct_rights(LSA_Q_ENUM_ACCT_RIGHTS *in, 
2310                              POLICY_HND *hnd, 
2311                              uint32 count, 
2312                              DOM_SID *sid)
2313 {
2314         DEBUG(5, ("init_q_enum_acct_rights\n"));
2315
2316         in->pol = *hnd;
2317         init_dom_sid2(&in->sid, sid);
2318 }
2319
2320 /*******************************************************************
2321 ********************************************************************/
2322 NTSTATUS init_r_enum_acct_rights( LSA_R_ENUM_ACCT_RIGHTS *out, PRIVILEGE_SET *privileges )
2323 {
2324         uint32 i;
2325         char *privname;
2326         const char **privname_array = NULL;
2327         int num_priv = 0;
2328
2329         for ( i=0; i<privileges->count; i++ ) {
2330                 privname = luid_to_privilege_name( &privileges->set[i].luid );
2331                 if ( privname ) {
2332                         if ( !add_string_to_array( get_talloc_ctx(), privname, &privname_array, &num_priv ) ) 
2333                                 return NT_STATUS_NO_MEMORY;
2334                 }
2335         }
2336
2337         if ( num_priv ) {
2338                 out->rights = TALLOC_P( get_talloc_ctx(), UNISTR4_ARRAY );
2339
2340                 if ( !init_unistr4_array( out->rights, num_priv, privname_array ) ) 
2341                         return NT_STATUS_NO_MEMORY;
2342
2343                 out->count = num_priv;
2344         }
2345
2346         return NT_STATUS_OK;
2347 }
2348
2349 /*******************************************************************
2350 reads or writes a LSA_Q_ENUM_ACCT_RIGHTS structure.
2351 ********************************************************************/
2352 BOOL lsa_io_q_enum_acct_rights(const char *desc, LSA_Q_ENUM_ACCT_RIGHTS *in, prs_struct *ps, int depth)
2353 {
2354         
2355         if (in == NULL)
2356                 return False;
2357
2358         prs_debug(ps, depth, desc, "lsa_io_q_enum_acct_rights");
2359         depth++;
2360
2361         if (!smb_io_pol_hnd("", &in->pol, ps, depth))
2362                 return False;
2363
2364         if(!smb_io_dom_sid2("sid", &in->sid, ps, depth))
2365                 return False;
2366
2367         return True;
2368 }
2369
2370
2371 /*******************************************************************
2372 reads or writes a LSA_R_ENUM_ACCT_RIGHTS structure.
2373 ********************************************************************/
2374 BOOL lsa_io_r_enum_acct_rights(const char *desc, LSA_R_ENUM_ACCT_RIGHTS *out, prs_struct *ps, int depth)
2375 {
2376         prs_debug(ps, depth, desc, "lsa_io_r_enum_acct_rights");
2377         depth++;
2378
2379         if(!prs_uint32("count   ", ps, depth, &out->count))
2380                 return False;
2381
2382         if ( !prs_pointer("rights", ps, depth, (void**)&out->rights, sizeof(UNISTR4_ARRAY), (PRS_POINTER_CAST)prs_unistr4_array) )
2383                 return False;
2384
2385         if(!prs_align(ps))
2386                 return False;
2387
2388         if(!prs_ntstatus("status", ps, depth, &out->status))
2389                 return False;
2390
2391         return True;
2392 }
2393
2394
2395 /*******************************************************************
2396  Inits an LSA_Q_ADD_ACCT_RIGHTS structure.
2397 ********************************************************************/
2398 void init_q_add_acct_rights( LSA_Q_ADD_ACCT_RIGHTS *in, POLICY_HND *hnd, 
2399                              DOM_SID *sid, uint32 count, const char **rights )
2400 {
2401         DEBUG(5, ("init_q_add_acct_rights\n"));
2402
2403         in->pol = *hnd;
2404         init_dom_sid2(&in->sid, sid);
2405         
2406         in->rights = TALLOC_P( get_talloc_ctx(), UNISTR4_ARRAY );
2407         init_unistr4_array( in->rights, count, rights );
2408         
2409         in->count = count;
2410 }
2411
2412
2413 /*******************************************************************
2414 reads or writes a LSA_Q_ADD_ACCT_RIGHTS structure.
2415 ********************************************************************/
2416 BOOL lsa_io_q_add_acct_rights(const char *desc, LSA_Q_ADD_ACCT_RIGHTS *in, prs_struct *ps, int depth)
2417 {
2418         prs_debug(ps, depth, desc, "lsa_io_q_add_acct_rights");
2419         depth++;
2420
2421         if (!smb_io_pol_hnd("", &in->pol, ps, depth))
2422                 return False;
2423
2424         if(!smb_io_dom_sid2("sid", &in->sid, ps, depth))
2425                 return False;
2426
2427         if(!prs_uint32("count", ps, depth, &in->count))
2428                 return False;
2429
2430         if ( !prs_pointer("rights", ps, depth, (void**)&in->rights, sizeof(UNISTR4_ARRAY), (PRS_POINTER_CAST)prs_unistr4_array) )
2431                 return False;
2432
2433         return True;
2434 }
2435
2436 /*******************************************************************
2437 reads or writes a LSA_R_ENUM_ACCT_RIGHTS structure.
2438 ********************************************************************/
2439 BOOL lsa_io_r_add_acct_rights(const char *desc, LSA_R_ADD_ACCT_RIGHTS *out, prs_struct *ps, int depth)
2440 {
2441         prs_debug(ps, depth, desc, "lsa_io_r_add_acct_rights");
2442         depth++;
2443
2444         if(!prs_ntstatus("status", ps, depth, &out->status))
2445                 return False;
2446
2447         return True;
2448 }
2449
2450
2451 /*******************************************************************
2452  Inits an LSA_Q_REMOVE_ACCT_RIGHTS structure.
2453 ********************************************************************/
2454 void init_q_remove_acct_rights(LSA_Q_REMOVE_ACCT_RIGHTS *in, 
2455                                POLICY_HND *hnd, 
2456                                DOM_SID *sid,
2457                                uint32 removeall,
2458                                uint32 count, 
2459                                const char **rights)
2460 {
2461         DEBUG(5, ("init_q_remove_acct_rights\n"));
2462
2463         in->pol = *hnd;
2464
2465         init_dom_sid2(&in->sid, sid);
2466
2467         in->removeall = removeall;
2468         in->count = count;
2469
2470         in->rights = TALLOC_P( get_talloc_ctx(), UNISTR4_ARRAY );
2471         init_unistr4_array( in->rights, count, rights );
2472 }
2473
2474
2475 /*******************************************************************
2476 reads or writes a LSA_Q_REMOVE_ACCT_RIGHTS structure.
2477 ********************************************************************/
2478 BOOL lsa_io_q_remove_acct_rights(const char *desc, LSA_Q_REMOVE_ACCT_RIGHTS *in, prs_struct *ps, int depth)
2479 {
2480         prs_debug(ps, depth, desc, "lsa_io_q_remove_acct_rights");
2481         depth++;
2482
2483         if (!smb_io_pol_hnd("", &in->pol, ps, depth))
2484                 return False;
2485
2486         if(!smb_io_dom_sid2("sid", &in->sid, ps, depth))
2487                 return False;
2488
2489         if(!prs_uint32("removeall", ps, depth, &in->removeall))
2490                 return False;
2491
2492         if(!prs_uint32("count", ps, depth, &in->count))
2493                 return False;
2494
2495         if ( !prs_pointer("rights", ps, depth, (void**)&in->rights, sizeof(UNISTR4_ARRAY), (PRS_POINTER_CAST)prs_unistr4_array) )
2496                 return False;
2497
2498         return True;
2499 }
2500
2501 /*******************************************************************
2502 reads or writes a LSA_R_ENUM_ACCT_RIGHTS structure.
2503 ********************************************************************/
2504 BOOL lsa_io_r_remove_acct_rights(const char *desc, LSA_R_REMOVE_ACCT_RIGHTS *out, prs_struct *ps, int depth)
2505 {
2506         prs_debug(ps, depth, desc, "lsa_io_r_remove_acct_rights");
2507         depth++;
2508
2509         if(!prs_ntstatus("status", ps, depth, &out->status))
2510                 return False;
2511
2512         return True;
2513 }
2514
2515 /*******************************************************************
2516  Inits an LSA_Q_OPEN_TRUSTED_DOMAIN structure.
2517 ********************************************************************/
2518
2519 void init_lsa_q_open_trusted_domain(LSA_Q_OPEN_TRUSTED_DOMAIN *q, POLICY_HND *hnd, DOM_SID *sid, uint32 desired_access)
2520 {
2521         memcpy(&q->pol, hnd, sizeof(q->pol));
2522
2523         init_dom_sid2(&q->sid, sid);
2524         q->access_mask = desired_access;
2525 }
2526
2527 /*******************************************************************
2528 ********************************************************************/
2529
2530 #if 0 /* jerry, I think this not correct - gd */
2531 BOOL lsa_io_q_open_trusted_domain(const char *desc, LSA_Q_OPEN_TRUSTED_DOMAIN *in, prs_struct *ps, int depth)
2532 {
2533         prs_debug(ps, depth, desc, "lsa_io_q_open_trusted_domain");
2534         depth++;
2535
2536         if(!prs_align(ps))
2537                 return False;
2538
2539         if (!smb_io_pol_hnd("", &in->handle, ps, depth))
2540                 return False;
2541
2542         if(!prs_uint32("count", ps, depth, &in->count))
2543                 return False;
2544
2545         if(!smb_io_dom_sid("sid", &in->sid, ps, depth))
2546                 return False;
2547
2548         return True;
2549 }
2550 #endif
2551
2552
2553 /*******************************************************************
2554  Inits an LSA_Q_OPEN_TRUSTED_DOMAIN_BY_NAME structure.
2555 ********************************************************************/
2556
2557 void init_lsa_q_open_trusted_domain_by_name(LSA_Q_OPEN_TRUSTED_DOMAIN_BY_NAME *q, 
2558                                             POLICY_HND *hnd, 
2559                                             const char *name, 
2560                                             uint32 desired_access)
2561 {
2562         memcpy(&q->pol, hnd, sizeof(q->pol));
2563
2564         init_lsa_string(&q->name, name);
2565         q->access_mask = desired_access;
2566 }
2567
2568 /*******************************************************************
2569 ********************************************************************/
2570
2571
2572 /*******************************************************************
2573  Reads or writes an LSA_Q_OPEN_TRUSTED_DOMAIN_BY_NAME structure.
2574 ********************************************************************/
2575
2576 BOOL lsa_io_q_open_trusted_domain_by_name(const char *desc, LSA_Q_OPEN_TRUSTED_DOMAIN_BY_NAME *q_o, prs_struct *ps, int depth)
2577 {
2578         prs_debug(ps, depth, desc, "lsa_io_q_open_trusted_domain_by_name");
2579         depth++;
2580
2581         if(!prs_align(ps))
2582                 return False;
2583  
2584         if(!smb_io_pol_hnd("pol", &q_o->pol, ps, depth))
2585                 return False;
2586
2587         if(!prs_align(ps))
2588                 return False;
2589
2590         if(!smb_io_lsa_string("name", &q_o->name, ps, depth))
2591                 return False;
2592
2593         if(!prs_align(ps))
2594                 return False;
2595
2596         if(!prs_uint32("access", ps, depth, &q_o->access_mask))
2597                 return False;
2598
2599         return True;
2600 }
2601
2602 /*******************************************************************
2603  Reads or writes an LSA_R_OPEN_TRUSTED_DOMAIN_BY_NAME structure.
2604 ********************************************************************/
2605
2606 BOOL lsa_io_r_open_trusted_domain_by_name(const char *desc, LSA_R_OPEN_TRUSTED_DOMAIN_BY_NAME *out, prs_struct *ps, int depth)
2607 {
2608         prs_debug(ps, depth, desc, "lsa_io_r_open_trusted_domain_by_name");
2609         depth++;
2610
2611         if(!prs_align(ps))
2612                 return False;
2613
2614         if (!smb_io_pol_hnd("handle", &out->handle, ps, depth))
2615                 return False;
2616
2617         if(!prs_ntstatus("status", ps, depth, &out->status))
2618                 return False;
2619
2620         return True;
2621 }
2622
2623 /*******************************************************************
2624 ********************************************************************/
2625
2626 BOOL lsa_io_q_open_trusted_domain(const char *desc, LSA_Q_OPEN_TRUSTED_DOMAIN *q_o, prs_struct *ps, int depth)
2627 {
2628         prs_debug(ps, depth, desc, "lsa_io_q_open_trusted_domain");
2629         depth++;
2630
2631         if(!prs_align(ps))
2632                 return False;
2633  
2634         if(!smb_io_pol_hnd("pol", &q_o->pol, ps, depth))
2635                 return False;
2636
2637         if(!smb_io_dom_sid2("sid", &q_o->sid, ps, depth))
2638                 return False;
2639
2640         if(!prs_uint32("access", ps, depth, &q_o->access_mask))
2641                 return False;
2642   
2643         return True;
2644 }
2645
2646 /*******************************************************************
2647  Reads or writes an LSA_R_OPEN_TRUSTED_DOMAIN structure.
2648 ********************************************************************/
2649
2650 BOOL lsa_io_r_open_trusted_domain(const char *desc, LSA_R_OPEN_TRUSTED_DOMAIN *out, prs_struct *ps, int depth)
2651 {
2652         prs_debug(ps, depth, desc, "lsa_io_r_open_trusted_domain");
2653         depth++;
2654
2655         if(!prs_align(ps))
2656                 return False;
2657
2658         if (!smb_io_pol_hnd("handle", &out->handle, ps, depth))
2659                 return False;
2660
2661         if(!prs_ntstatus("status", ps, depth, &out->status))
2662                 return False;
2663
2664         return True;
2665 }
2666
2667 /*******************************************************************
2668 ********************************************************************/
2669
2670 BOOL lsa_io_q_create_trusted_domain(const char *desc, LSA_Q_CREATE_TRUSTED_DOMAIN *in, prs_struct *ps, int depth)
2671 {
2672         prs_debug(ps, depth, desc, "lsa_io_q_create_trusted_domain");
2673         depth++;
2674
2675         if(!prs_align(ps))
2676                 return False;
2677
2678         if(!smb_io_pol_hnd("", &in->handle, ps, depth))
2679                 return False;
2680
2681         if(!prs_unistr4 ("secretname", ps, depth, &in->secretname))
2682                 return False;
2683         if(!prs_align(ps))
2684                 return False;
2685
2686         if(!prs_uint32("access", ps, depth, &in->access))
2687                 return False;
2688
2689         return True;
2690 }
2691
2692 /*******************************************************************
2693 ********************************************************************/
2694
2695 BOOL lsa_io_r_create_trusted_domain(const char *desc, LSA_R_CREATE_TRUSTED_DOMAIN *out, prs_struct *ps, int depth)
2696 {
2697         prs_debug(ps, depth, desc, "lsa_io_r_create_trusted_domain");
2698         depth++;
2699
2700         if(!prs_align(ps))
2701                 return False;
2702
2703         if (!smb_io_pol_hnd("", &out->handle, ps, depth))
2704                 return False;
2705
2706         if(!prs_ntstatus("status", ps, depth, &out->status))
2707                 return False;
2708
2709         return True;
2710 }
2711
2712 /*******************************************************************
2713 ********************************************************************/
2714
2715 BOOL lsa_io_q_create_secret(const char *desc, LSA_Q_CREATE_SECRET *in, prs_struct *ps, int depth)
2716 {
2717         prs_debug(ps, depth, desc, "lsa_io_q_create_secret");
2718         depth++;
2719
2720         if(!prs_align(ps))
2721                 return False;
2722
2723         if(!smb_io_pol_hnd("", &in->handle, ps, depth))
2724                 return False;
2725
2726         if(!prs_unistr4 ("secretname", ps, depth, &in->secretname))
2727                 return False;
2728         if(!prs_align(ps))
2729                 return False;
2730
2731         if(!prs_uint32("access", ps, depth, &in->access))
2732                 return False;
2733
2734         return True;
2735 }
2736
2737 /*******************************************************************
2738 ********************************************************************/
2739
2740 BOOL lsa_io_r_create_secret(const char *desc, LSA_R_CREATE_SECRET *out, prs_struct *ps, int depth)
2741 {
2742         prs_debug(ps, depth, desc, "lsa_io_r_create_secret");
2743         depth++;
2744
2745         if(!prs_align(ps))
2746                 return False;
2747
2748         if (!smb_io_pol_hnd("", &out->handle, ps, depth))
2749                 return False;
2750
2751         if(!prs_ntstatus("status", ps, depth, &out->status))
2752                 return False;
2753
2754         return True;
2755 }
2756
2757
2758
2759 /*******************************************************************
2760 ********************************************************************/
2761
2762 static BOOL lsa_io_data_blob( const char *desc, prs_struct *ps, int depth, LSA_DATA_BLOB *blob )
2763 {
2764         prs_debug(ps, depth, desc, "lsa_io_data_blob");
2765         depth++;
2766
2767         if ( !prs_uint32("size", ps, depth, &blob->size) )
2768                 return False;
2769         if ( !prs_uint32("size", ps, depth, &blob->size) )
2770                 return False;
2771
2772         if ( !prs_io_unistr2_p(desc, ps, depth, &blob->data) )
2773                 return False;
2774
2775         return True;
2776 }
2777
2778 /*******************************************************************
2779 ********************************************************************/
2780
2781 BOOL lsa_io_q_set_secret(const char *desc, LSA_Q_SET_SECRET *in, prs_struct *ps, int depth)
2782 {
2783         prs_debug(ps, depth, desc, "lsa_io_q_set_secret");
2784         depth++;
2785
2786         if ( !prs_align(ps) )
2787                 return False;
2788
2789         if ( !smb_io_pol_hnd("", &in->handle, ps, depth) )
2790                 return False;
2791
2792         if ( !prs_pointer( "old_value", ps, depth, (void*)&in->old_value, sizeof(LSA_DATA_BLOB), (PRS_POINTER_CAST)lsa_io_data_blob ))
2793                 return False;
2794
2795         if( !prs_align(ps) )
2796                 return False;
2797         if ( !prs_pointer( "old_value", ps, depth, (void*)&in->old_value, sizeof(LSA_DATA_BLOB), (PRS_POINTER_CAST)lsa_io_data_blob ))
2798                 return False;
2799
2800
2801         return True;
2802 }
2803
2804 /*******************************************************************
2805 ********************************************************************/
2806
2807 BOOL lsa_io_r_set_secret(const char *desc, LSA_R_SET_SECRET *out, prs_struct *ps, int depth)
2808 {
2809         prs_debug(ps, depth, desc, "lsa_io_r_set_secret");
2810         depth++;
2811
2812         if(!prs_ntstatus("status", ps, depth, &out->status))
2813                 return False;
2814
2815         return True;
2816 }
2817
2818 /*******************************************************************
2819 ********************************************************************/
2820
2821 BOOL lsa_io_q_delete_object(const char *desc, LSA_Q_DELETE_OBJECT *in, prs_struct *ps, int depth)
2822 {
2823         prs_debug(ps, depth, desc, "lsa_io_q_delete_object");
2824         depth++;
2825
2826         if(!prs_align(ps))
2827                 return False;
2828
2829         if(!smb_io_pol_hnd("", &in->handle, ps, depth))
2830                 return False;
2831
2832         return True;
2833 }
2834
2835 /*******************************************************************
2836 ********************************************************************/
2837
2838 BOOL lsa_io_r_delete_object(const char *desc, LSA_R_DELETE_OBJECT *out, prs_struct *ps, int depth)
2839 {
2840         prs_debug(ps, depth, desc, "lsa_io_r_delete_object");
2841         depth++;
2842
2843         if(!prs_ntstatus("status", ps, depth, &out->status))
2844                 return False;
2845
2846         return True;
2847 }
2848
2849 /*******************************************************************
2850  Inits an LSA_Q_QUERY_TRUSTED_DOMAIN_INFO structure.
2851 ********************************************************************/
2852
2853 void init_q_query_trusted_domain_info(LSA_Q_QUERY_TRUSTED_DOMAIN_INFO *q, 
2854                                       POLICY_HND *hnd, uint16 info_class) 
2855 {
2856         DEBUG(5, ("init_q_query_trusted_domain_info\n"));
2857         
2858         q->pol = *hnd;
2859         q->info_class = info_class;
2860 }
2861
2862 /*******************************************************************
2863  Inits an LSA_Q_QUERY_TRUSTED_DOMAIN_INFO_BY_NAME structure.
2864 ********************************************************************/
2865
2866 void init_q_query_trusted_domain_info_by_name(LSA_Q_QUERY_TRUSTED_DOMAIN_INFO_BY_NAME *q, 
2867                                               POLICY_HND *hnd, uint16 info_class, 
2868                                               const char *dom_name)
2869 {
2870         DEBUG(5, ("init_q_query_trusted_domain_info_by_name\n"));
2871         
2872         q->pol = *hnd;
2873         init_lsa_string(&q->domain_name, dom_name );
2874         q->info_class = info_class;
2875 }
2876
2877 /*******************************************************************
2878  Inits an LSA_Q_QUERY_TRUSTED_DOMAIN_INFO_BY_SID structure.
2879 ********************************************************************/
2880
2881 void init_q_query_trusted_domain_info_by_sid(LSA_Q_QUERY_TRUSTED_DOMAIN_INFO_BY_SID *q, 
2882                                              POLICY_HND *hnd, uint16 info_class, 
2883                                              DOM_SID *dom_sid)
2884 {
2885         DEBUG(5, ("init_q_query_trusted_domain_info_by_sid\n"));
2886         
2887         q->pol = *hnd;
2888         init_dom_sid2(&q->dom_sid, dom_sid);
2889         q->info_class = info_class;
2890 }
2891
2892 /*******************************************************************
2893  Reads or writes an LSA_Q_QUERY_TRUSTED_DOMAIN_INFO structure.
2894 ********************************************************************/
2895
2896 BOOL lsa_io_q_query_trusted_domain_info(const char *desc, 
2897                                         LSA_Q_QUERY_TRUSTED_DOMAIN_INFO *q_q,
2898                                         prs_struct *ps, int depth)
2899 {
2900         prs_debug(ps, depth, desc, "lsa_io_q_query_trusted_domain_info");
2901         depth++;
2902
2903         if(!prs_align(ps))
2904                 return False;
2905
2906         if(!smb_io_pol_hnd("pol", &q_q->pol, ps, depth))
2907                 return False;
2908
2909         if(!prs_uint16("info_class", ps, depth, &q_q->info_class))
2910                 return False;
2911
2912         return True;
2913 }
2914
2915
2916 /*******************************************************************
2917  Reads or writes an LSA_Q_QUERY_TRUSTED_DOMAIN_INFO_BY_SID structure.
2918 ********************************************************************/
2919
2920 BOOL lsa_io_q_query_trusted_domain_info_by_sid(const char *desc, 
2921                                                LSA_Q_QUERY_TRUSTED_DOMAIN_INFO_BY_SID *q_q,
2922                                                prs_struct *ps, int depth)
2923 {
2924         prs_debug(ps, depth, desc, "lsa_io_q_query_trusted_domain_info_by_sid");
2925         depth++;
2926
2927         if(!prs_align(ps))
2928                 return False;
2929
2930         if(!smb_io_pol_hnd("pol", &q_q->pol, ps, depth))
2931                 return False;
2932
2933         if(!prs_align(ps))
2934                 return False;
2935
2936         if(!smb_io_dom_sid2("dom_sid", &q_q->dom_sid, ps, depth))
2937                 return False;
2938
2939         if(!prs_uint16("info_class", ps, depth, &q_q->info_class))
2940                 return False;
2941
2942         return True;
2943 }
2944
2945 /*******************************************************************
2946  Reads or writes an LSA_Q_QUERY_TRUSTED_DOMAIN_INFO_BY_NAME structure.
2947 ********************************************************************/
2948
2949 BOOL lsa_io_q_query_trusted_domain_info_by_name(const char *desc, 
2950                                                 LSA_Q_QUERY_TRUSTED_DOMAIN_INFO_BY_NAME *q_q,
2951                                                 prs_struct *ps, int depth)
2952 {
2953         prs_debug(ps, depth, desc, "lsa_io_q_query_trusted_domain_info_by_name");
2954         depth++;
2955
2956         if(!prs_align(ps))
2957                 return False;
2958
2959         if(!smb_io_pol_hnd("pol", &q_q->pol, ps, depth))
2960                 return False;
2961
2962         if(!prs_align(ps))
2963                 return False;
2964
2965         if(!smb_io_lsa_string("domain_name", &q_q->domain_name, ps, depth))
2966                 return False;
2967
2968         if(!prs_uint16("info_class", ps, depth, &q_q->info_class))
2969                 return False;
2970
2971         return True;
2972 }
2973
2974 /*******************************************************************
2975 ********************************************************************/
2976
2977 static BOOL smb_io_lsa_data_buf_hdr(const char *desc, LSA_DATA_BUF_HDR *buf_hdr, 
2978                                     prs_struct *ps, int depth)
2979 {
2980         prs_debug(ps, depth, desc, "smb_io_lsa_data_buf_hdr");
2981         depth++;
2982
2983         if(!prs_align(ps))
2984                 return False;
2985
2986         if(!prs_uint32("length", ps, depth, &buf_hdr->length))
2987                 return False;
2988         
2989         if(!prs_uint32("size", ps, depth, &buf_hdr->size))
2990                 return False;
2991
2992         if (!prs_uint32("data_ptr", ps, depth, &buf_hdr->data_ptr))
2993                 return False;
2994
2995         return True;
2996 }
2997
2998 /*******************************************************************
2999 ********************************************************************/
3000
3001 static BOOL smb_io_lsa_data_buf(const char *desc, LSA_DATA_BUF *buf, 
3002                                 prs_struct *ps, int depth, int length, int size)
3003 {
3004         prs_debug(ps, depth, desc, "smb_io_lsa_data_buf");
3005         depth++;
3006
3007         if ( UNMARSHALLING(ps) ) {
3008                 if ( !(buf->data = PRS_ALLOC_MEM( ps, uint8, length )) )
3009                         return False;
3010         }
3011
3012         if (!prs_uint32("size", ps, depth, &buf->size))
3013                 return False;
3014
3015         if (!prs_uint32("offset", ps, depth, &buf->offset))
3016                 return False;
3017
3018         if (!prs_uint32("length", ps, depth, &buf->length))
3019                 return False;
3020
3021         if(!prs_uint8s(False, "data", ps, depth, buf->data, size))
3022                 return False;
3023
3024         return True;
3025 }
3026
3027 /*******************************************************************
3028 ********************************************************************/
3029
3030 static BOOL lsa_io_trustdom_query_1(const char *desc, TRUSTED_DOMAIN_INFO_NAME *name, 
3031                                     prs_struct *ps, int depth)
3032 {
3033         if (!smb_io_lsa_string("netbios_name", &name->netbios_name, ps, depth))
3034                 return False;
3035
3036         return True;
3037 }
3038
3039 /*******************************************************************
3040 ********************************************************************/
3041
3042 static BOOL lsa_io_trustdom_query_3(const char *desc, TRUSTED_DOMAIN_INFO_POSIX_OFFSET *posix, 
3043                                     prs_struct *ps, int depth)
3044 {
3045         if(!prs_uint32("posix_offset", ps, depth, &posix->posix_offset))
3046                 return False;
3047
3048         return True;
3049 }
3050
3051 /*******************************************************************
3052 ********************************************************************/
3053
3054 static BOOL lsa_io_trustdom_query_4(const char *desc, TRUSTED_DOMAIN_INFO_PASSWORD *password, 
3055                                     prs_struct *ps, int depth)
3056 {
3057         if(!prs_align(ps))
3058                 return False;
3059         
3060         if(!prs_uint32("ptr_password", ps, depth, &password->ptr_password))
3061                 return False;
3062
3063         if(!prs_uint32("ptr_old_password", ps, depth, &password->ptr_old_password))
3064                 return False;
3065
3066         if (&password->ptr_password) {
3067         
3068                 if (!smb_io_lsa_data_buf_hdr("password_hdr", &password->password_hdr, ps, depth))
3069                         return False;
3070
3071                 if (!smb_io_lsa_data_buf("password", &password->password, ps, depth, 
3072                                         password->password_hdr.length, password->password_hdr.size))
3073                         return False;
3074         }
3075
3076         if (&password->ptr_old_password) {
3077
3078                 if (!smb_io_lsa_data_buf_hdr("old_password_hdr", &password->old_password_hdr, ps, depth))
3079                         return False;
3080
3081                 if (!smb_io_lsa_data_buf("old_password", &password->old_password, ps, depth, 
3082                                         password->old_password_hdr.length, password->old_password_hdr.size))
3083                         return False;
3084         }
3085
3086         return True;
3087 }
3088
3089 /*******************************************************************
3090 ********************************************************************/
3091
3092 static BOOL lsa_io_trustdom_query_6(const char *desc, TRUSTED_DOMAIN_INFO_EX *info_ex, 
3093                                     prs_struct *ps, int depth)
3094 {
3095         uint32 dom_sid_ptr;
3096         
3097         if (!smb_io_unihdr("domain_name_hdr", &info_ex->domain_name.hdr, ps, depth))
3098                 return False;
3099                 
3100         if (!smb_io_unihdr("netbios_name_hdr", &info_ex->netbios_name.hdr, ps, depth))
3101                 return False;
3102
3103         if (!prs_uint32("dom_sid_ptr", ps, depth, &dom_sid_ptr))
3104                 return False;
3105
3106         if (!prs_uint32("trust_direction", ps, depth, &info_ex->trust_direction))
3107                 return False;
3108
3109         if (!prs_uint32("trust_type", ps, depth, &info_ex->trust_type))
3110                 return False;
3111
3112         if (!prs_uint32("trust_attributes", ps, depth, &info_ex->trust_attributes))
3113                 return False;
3114                 
3115         if (!smb_io_unistr2("domain_name_unistring", &info_ex->domain_name.unistring, info_ex->domain_name.hdr.buffer, ps, depth))
3116                 return False;
3117                 
3118         if (!smb_io_unistr2("netbios_name_unistring", &info_ex->netbios_name.unistring, info_ex->netbios_name.hdr.buffer, ps, depth))
3119                 return False;
3120
3121         if (!smb_io_dom_sid2("sid", &info_ex->sid, ps, depth))
3122                 return False;
3123
3124         return True;
3125 }
3126
3127 /*******************************************************************
3128 ********************************************************************/
3129
3130 static BOOL lsa_io_trustdom_query(const char *desc, prs_struct *ps, int depth, LSA_TRUSTED_DOMAIN_INFO *info)
3131 {
3132         prs_debug(ps, depth, desc, "lsa_io_trustdom_query");
3133         depth++;
3134
3135         if(!prs_uint16("info_class", ps, depth, &info->info_class))
3136                 return False;
3137
3138         if(!prs_align(ps))
3139                 return False;
3140
3141         switch (info->info_class) {
3142         case 1:
3143                 if(!lsa_io_trustdom_query_1("name", &info->name, ps, depth))
3144                         return False;
3145                 break;
3146         case 3:
3147                 if(!lsa_io_trustdom_query_3("posix_offset", &info->posix_offset, ps, depth))
3148                         return False;
3149                 break;
3150         case 4:
3151                 if(!lsa_io_trustdom_query_4("password", &info->password, ps, depth))
3152                         return False;
3153                 break;
3154         case 6:
3155                 if(!lsa_io_trustdom_query_6("info_ex", &info->info_ex, ps, depth))
3156                         return False;
3157                 break;
3158         default:
3159                 DEBUG(0,("unsupported info-level: %d\n", info->info_class));
3160                 return False;
3161         }
3162
3163         return True;
3164 }
3165
3166 /*******************************************************************
3167  Reads or writes an LSA_R_QUERY_TRUSTED_DOMAIN_INFO structure.
3168 ********************************************************************/
3169
3170 BOOL lsa_io_r_query_trusted_domain_info(const char *desc, 
3171                                         LSA_R_QUERY_TRUSTED_DOMAIN_INFO *r_q, 
3172                                         prs_struct *ps, int depth)
3173 {
3174         if (r_q == NULL)
3175                 return False;
3176
3177         prs_debug(ps, depth, desc, "lsa_io_r_query_trusted_domain_info");
3178         depth++;
3179
3180         if (!prs_pointer("trustdom", ps, depth, (void**)&r_q->info, 
3181                          sizeof(LSA_TRUSTED_DOMAIN_INFO), 
3182                          (PRS_POINTER_CAST)lsa_io_trustdom_query) )
3183                 return False;
3184
3185         if(!prs_align(ps))
3186                 return False;
3187
3188         if(!prs_ntstatus("status", ps, depth, &r_q->status))
3189                 return False;
3190
3191         return True;
3192 }
3193
3194 /*******************************************************************
3195  Inits an LSA_Q_QUERY_DOM_INFO_POLICY structure.
3196 ********************************************************************/
3197
3198 void init_q_query_dom_info(LSA_Q_QUERY_DOM_INFO_POLICY *in, POLICY_HND *hnd, uint16 info_class)
3199 {
3200         DEBUG(5, ("init_q_query_dom_info\n"));
3201
3202         memcpy(&in->pol, hnd, sizeof(in->pol));
3203
3204         in->info_class = info_class;
3205 }
3206
3207 /*******************************************************************
3208  Reads or writes an LSA_Q_QUERY_DOM_INFO_POLICY structure.
3209 ********************************************************************/
3210
3211 BOOL lsa_io_q_query_dom_info(const char *desc, LSA_Q_QUERY_DOM_INFO_POLICY *in, prs_struct *ps, int depth)
3212 {
3213         prs_debug(ps, depth, desc, "lsa_io_q_query_dom_info");
3214         depth++;
3215
3216         if(!prs_align(ps))
3217                 return False;
3218  
3219         if(!smb_io_pol_hnd("pol", &in->pol, ps, depth))
3220                 return False;
3221         
3222         if(!prs_uint16("info_class", ps, depth, &in->info_class))
3223                 return False;
3224
3225         return True;
3226 }
3227
3228 /*******************************************************************
3229  Reads or writes an LSA_R_QUERY_DOM_INFO_POLICY structure.
3230 ********************************************************************/
3231
3232 static BOOL lsa_io_dominfo_query_3(const char *desc, LSA_DOM_INFO_POLICY_KERBEROS *krb_policy, 
3233                                    prs_struct *ps, int depth)
3234 {
3235         if (!prs_align_uint64(ps))
3236                 return False;
3237
3238         if (!prs_align(ps))
3239                 return False;
3240
3241         if (!prs_uint32("enforce_restrictions", ps, depth, &krb_policy->enforce_restrictions))
3242                 return False;
3243
3244         if (!prs_align_uint64(ps))
3245                 return False;
3246
3247         if (!smb_io_nttime("service_tkt_lifetime", ps, depth, &krb_policy->service_tkt_lifetime))
3248                 return False;
3249
3250         if (!prs_align_uint64(ps))
3251                 return False;
3252         
3253         if (!smb_io_nttime("user_tkt_lifetime", ps, depth, &krb_policy->user_tkt_lifetime))
3254                 return False;
3255
3256         if (!prs_align_uint64(ps))
3257                 return False;
3258         
3259         if (!smb_io_nttime("user_tkt_renewaltime", ps, depth, &krb_policy->user_tkt_renewaltime))
3260                 return False;
3261
3262         if (!prs_align_uint64(ps))
3263                 return False;
3264         
3265         if (!smb_io_nttime("clock_skew", ps, depth, &krb_policy->clock_skew))
3266                 return False;
3267
3268         if (!prs_align_uint64(ps))
3269                 return False;
3270         
3271         if (!smb_io_nttime("unknown6", ps, depth, &krb_policy->unknown6))
3272                 return False;
3273
3274         return True;
3275 }
3276
3277 static BOOL lsa_io_dom_info_query(const char *desc, prs_struct *ps, int depth, LSA_DOM_INFO_UNION *info)
3278 {
3279         prs_debug(ps, depth, desc, "lsa_io_dom_info_query");
3280         depth++;
3281
3282         if(!prs_align_uint16(ps))
3283                 return False;
3284
3285         if(!prs_uint16("info_class", ps, depth, &info->info_class))
3286                 return False;
3287
3288         switch (info->info_class) {
3289         case 3: 
3290                 if (!lsa_io_dominfo_query_3("krb_policy", &info->krb_policy, ps, depth))
3291                         return False;
3292                 break;
3293         default:
3294                 DEBUG(0,("unsupported info-level: %d\n", info->info_class));
3295                 return False;
3296                 break;
3297         }
3298
3299         return True;
3300 }
3301
3302
3303 BOOL lsa_io_r_query_dom_info(const char *desc, LSA_R_QUERY_DOM_INFO_POLICY *out,
3304                              prs_struct *ps, int depth)
3305 {
3306         prs_debug(ps, depth, desc, "lsa_io_r_query_dom_info");
3307         depth++;
3308
3309         if (!prs_pointer("dominfo", ps, depth, (void**)&out->info, 
3310                          sizeof(LSA_DOM_INFO_UNION), 
3311                          (PRS_POINTER_CAST)lsa_io_dom_info_query) )
3312                 return False;
3313         
3314         if(!prs_ntstatus("status", ps, depth, &out->status))
3315                 return False;
3316
3317         return True;
3318 }
3319
3320