r4746: add server support for lsa_enum_acct_rights(); last checkin for the night
[samba.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  *  
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation; either version 2 of the License, or
13  *  (at your option) any later version.
14  *  
15  *  This program is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU General Public License for more details.
19  *  
20  *  You should have received a copy of the GNU General Public License
21  *  along with this program; if not, write to the Free Software
22  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  */
24
25 #include "includes.h"
26
27 #undef DBGC_CLASS
28 #define DBGC_CLASS DBGC_RPC_PARSE
29
30 static BOOL lsa_io_trans_names(const char *desc, LSA_TRANS_NAME_ENUM *trn, prs_struct *ps, int depth);
31
32 /*******************************************************************
33  Inits a LSA_TRANS_NAME structure.
34 ********************************************************************/
35
36 void init_lsa_trans_name(LSA_TRANS_NAME *trn, UNISTR2 *uni_name,
37                          uint16 sid_name_use, const char *name, uint32 idx)
38 {
39         trn->sid_name_use = sid_name_use;
40         init_unistr2(uni_name, name, UNI_FLAGS_NONE);
41         init_uni_hdr(&trn->hdr_name, uni_name);
42         trn->domain_idx = idx;
43 }
44
45 /*******************************************************************
46  Reads or writes a LSA_TRANS_NAME structure.
47 ********************************************************************/
48
49 static BOOL lsa_io_trans_name(const char *desc, LSA_TRANS_NAME *trn, prs_struct *ps, 
50                               int depth)
51 {
52         prs_debug(ps, depth, desc, "lsa_io_trans_name");
53         depth++;
54
55         if(!prs_align(ps))
56                 return False;
57         
58         if(!prs_uint16("sid_name_use", ps, depth, &trn->sid_name_use))
59                 return False;
60         if(!prs_align(ps))
61                 return False;
62         
63         if(!smb_io_unihdr ("hdr_name", &trn->hdr_name, ps, depth))
64                 return False;
65         if(!prs_uint32("domain_idx  ", ps, depth, &trn->domain_idx))
66                 return False;
67
68         return True;
69 }
70
71 /*******************************************************************
72  Reads or writes a DOM_R_REF structure.
73 ********************************************************************/
74
75 static BOOL lsa_io_dom_r_ref(const char *desc, DOM_R_REF *r_r, prs_struct *ps, 
76                              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, &r_r->num_ref_doms_1)) /* num referenced domains? */
87                 return False;
88         if(!prs_uint32("ptr_ref_dom   ", ps, depth, &r_r->ptr_ref_dom)) /* undocumented buffer pointer. */
89                 return False;
90         if(!prs_uint32("max_entries   ", ps, depth, &r_r->max_entries)) /* 32 - max number of entries */
91                 return False;
92
93         SMB_ASSERT_ARRAY(r_r->hdr_ref_dom, r_r->num_ref_doms_1);
94
95         if (r_r->ptr_ref_dom != 0) {
96
97                 if(!prs_uint32("num_ref_doms_2", ps, depth, &r_r->num_ref_doms_2)) /* 4 - num referenced domains? */
98                         return False;
99
100                 SMB_ASSERT_ARRAY(r_r->ref_dom, r_r->num_ref_doms_2);
101
102                 for (i = 0; i < r_r->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, &r_r->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, &r_r->hdr_ref_dom[i].ptr_dom_sid))
111                                 return False;
112                 }
113
114                 for (i = 0; i < r_r->num_ref_doms_2; i++) {
115                         fstring t;
116
117                         if (r_r->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, &r_r->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 (r_r->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, &r_r->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         uint32 start;
218
219         prs_debug(ps, depth, desc, "lsa_io_obj_attr");
220         depth++;
221
222         if(!prs_align(ps))
223                 return False;
224         
225         start = prs_offset(ps);
226
227         /* these pointers had _better_ be zero, because we don't know
228            what they point to!
229          */
230         if(!prs_uint32("len         ", ps, depth, &attr->len)) /* 0x18 - length (in bytes) inc. the length field. */
231                 return False;
232         if(!prs_uint32("ptr_root_dir", ps, depth, &attr->ptr_root_dir)) /* 0 - root directory (pointer) */
233                 return False;
234         if(!prs_uint32("ptr_obj_name", ps, depth, &attr->ptr_obj_name)) /* 0 - object name (pointer) */
235                 return False;
236         if(!prs_uint32("attributes  ", ps, depth, &attr->attributes)) /* 0 - attributes (undocumented) */
237                 return False;
238         if(!prs_uint32("ptr_sec_desc", ps, depth, &attr->ptr_sec_desc)) /* 0 - security descriptior (pointer) */
239                 return False;
240         if(!prs_uint32("ptr_sec_qos ", ps, depth, &attr->ptr_sec_qos )) /* security quality of service (pointer) */
241                 return False;
242
243         /* code commented out as it's not necessary true (tested with hyena). JFM, 11/22/2001 */
244 #if 0
245         if (attr->len != prs_offset(ps) - start) {
246                 DEBUG(3,("lsa_io_obj_attr: length %x does not match size %x\n",
247                          attr->len, prs_offset(ps) - start));
248                 return False;
249         }
250 #endif
251
252         if (attr->ptr_sec_qos != 0) {
253                 if (UNMARSHALLING(ps))
254                         if (!(attr->sec_qos = PRS_ALLOC_MEM(ps,LSA_SEC_QOS,1)))
255                                 return False;
256
257                 if(!lsa_io_sec_qos("sec_qos", attr->sec_qos, ps, depth))
258                         return False;
259         }
260
261         return True;
262 }
263
264
265 /*******************************************************************
266  Inits an LSA_Q_OPEN_POL structure.
267 ********************************************************************/
268
269 void init_q_open_pol(LSA_Q_OPEN_POL *r_q, uint16 system_name,
270                      uint32 attributes, uint32 desired_access,
271                      LSA_SEC_QOS *qos)
272 {
273         DEBUG(5, ("init_open_pol: attr:%d da:%d\n", attributes, 
274                   desired_access));
275
276         r_q->ptr = 1; /* undocumented pointer */
277
278         r_q->des_access = desired_access;
279
280         r_q->system_name = system_name;
281         init_lsa_obj_attr(&r_q->attr, attributes, qos);
282 }
283
284 /*******************************************************************
285  Reads or writes an LSA_Q_OPEN_POL structure.
286 ********************************************************************/
287
288 BOOL lsa_io_q_open_pol(const char *desc, LSA_Q_OPEN_POL *r_q, prs_struct *ps, 
289                        int depth)
290 {
291         prs_debug(ps, depth, desc, "lsa_io_q_open_pol");
292         depth++;
293
294         if(!prs_uint32("ptr       ", ps, depth, &r_q->ptr))
295                 return False;
296         if(!prs_uint16("system_name", ps, depth, &r_q->system_name))
297                 return False;
298         if(!prs_align( ps ))
299                 return False;
300
301         if(!lsa_io_obj_attr("", &r_q->attr, ps, depth))
302                 return False;
303
304         if(!prs_uint32("des_access", ps, depth, &r_q->des_access))
305                 return False;
306
307         return True;
308 }
309
310 /*******************************************************************
311  Reads or writes an LSA_R_OPEN_POL structure.
312 ********************************************************************/
313
314 BOOL lsa_io_r_open_pol(const char *desc, LSA_R_OPEN_POL *r_p, prs_struct *ps, 
315                        int depth)
316 {
317         prs_debug(ps, depth, desc, "lsa_io_r_open_pol");
318         depth++;
319
320         if(!smb_io_pol_hnd("", &r_p->pol, ps, depth))
321                 return False;
322
323         if(!prs_ntstatus("status", ps, depth, &r_p->status))
324                 return False;
325
326         return True;
327 }
328
329 /*******************************************************************
330  Inits an LSA_Q_OPEN_POL2 structure.
331 ********************************************************************/
332
333 void init_q_open_pol2(LSA_Q_OPEN_POL2 *r_q, const char *server_name,
334                         uint32 attributes, uint32 desired_access,
335                         LSA_SEC_QOS *qos)
336 {
337         DEBUG(5, ("init_q_open_pol2: attr:%d da:%d\n", attributes, 
338                   desired_access));
339
340         r_q->ptr = 1; /* undocumented pointer */
341
342         r_q->des_access = desired_access;
343
344         init_unistr2(&r_q->uni_server_name, server_name, UNI_STR_TERMINATE);
345
346         init_lsa_obj_attr(&r_q->attr, attributes, qos);
347 }
348
349 /*******************************************************************
350  Reads or writes an LSA_Q_OPEN_POL2 structure.
351 ********************************************************************/
352
353 BOOL lsa_io_q_open_pol2(const char *desc, LSA_Q_OPEN_POL2 *r_q, prs_struct *ps, 
354                         int depth)
355 {
356         prs_debug(ps, depth, desc, "lsa_io_q_open_pol2");
357         depth++;
358
359         if(!prs_uint32("ptr       ", ps, depth, &r_q->ptr))
360                 return False;
361
362         if(!smb_io_unistr2 ("", &r_q->uni_server_name, r_q->ptr, ps, depth))
363                 return False;
364         if(!lsa_io_obj_attr("", &r_q->attr, ps, depth))
365                 return False;
366
367         if(!prs_uint32("des_access", ps, depth, &r_q->des_access))
368                 return False;
369
370         return True;
371 }
372
373 /*******************************************************************
374  Reads or writes an LSA_R_OPEN_POL2 structure.
375 ********************************************************************/
376
377 BOOL lsa_io_r_open_pol2(const char *desc, LSA_R_OPEN_POL2 *r_p, prs_struct *ps, 
378                         int depth)
379 {
380         prs_debug(ps, depth, desc, "lsa_io_r_open_pol2");
381         depth++;
382
383         if(!smb_io_pol_hnd("", &r_p->pol, ps, depth))
384                 return False;
385
386         if(!prs_ntstatus("status", ps, depth, &r_p->status))
387                 return False;
388
389         return True;
390 }
391
392 /*******************************************************************
393 makes an LSA_Q_QUERY_SEC_OBJ structure.
394 ********************************************************************/
395
396 void init_q_query_sec_obj(LSA_Q_QUERY_SEC_OBJ *q_q, const POLICY_HND *hnd, 
397                           uint32 sec_info)
398 {
399         DEBUG(5, ("init_q_query_sec_obj\n"));
400
401         q_q->pol = *hnd;
402         q_q->sec_info = sec_info;
403
404         return;
405 }
406
407 /*******************************************************************
408  Reads or writes an LSA_Q_QUERY_SEC_OBJ structure.
409 ********************************************************************/
410
411 BOOL lsa_io_q_query_sec_obj(const char *desc, LSA_Q_QUERY_SEC_OBJ *q_q, 
412                             prs_struct *ps, int depth)
413 {
414         prs_debug(ps, depth, desc, "lsa_io_q_query_sec_obj");
415         depth++;
416
417         if (!smb_io_pol_hnd("", &q_q->pol, ps, depth))
418                 return False;
419
420         if (!prs_uint32("sec_info", ps, depth, &q_q->sec_info))
421                 return False;
422
423         return True;
424
425
426 /*******************************************************************
427  Reads or writes a LSA_R_QUERY_SEC_OBJ structure.
428 ********************************************************************/
429
430 BOOL lsa_io_r_query_sec_obj(const char *desc, LSA_R_QUERY_SEC_OBJ *r_u, 
431                             prs_struct *ps, int depth)
432 {
433         prs_debug(ps, depth, desc, "lsa_io_r_query_sec_obj");
434         depth++;
435
436         if (!prs_align(ps))
437                 return False;
438
439         if (!prs_uint32("ptr", ps, depth, &r_u->ptr))
440                 return False;
441
442         if (r_u->ptr != 0) {
443                 if (!sec_io_desc_buf("sec", &r_u->buf, ps, depth))
444                         return False;
445         }
446
447         if (!prs_ntstatus("status", ps, depth, &r_u->status))
448                 return False;
449
450         return True;
451 }
452
453 /*******************************************************************
454  Inits an LSA_Q_QUERY_INFO structure.
455 ********************************************************************/
456
457 void init_q_query(LSA_Q_QUERY_INFO *q_q, POLICY_HND *hnd, uint16 info_class)
458 {
459         DEBUG(5, ("init_q_query\n"));
460
461         memcpy(&q_q->pol, hnd, sizeof(q_q->pol));
462
463         q_q->info_class = info_class;
464 }
465
466 /*******************************************************************
467  Reads or writes an LSA_Q_QUERY_INFO structure.
468 ********************************************************************/
469
470 BOOL lsa_io_q_query(const char *desc, LSA_Q_QUERY_INFO *q_q, prs_struct *ps, 
471                     int depth)
472 {
473         prs_debug(ps, depth, desc, "lsa_io_q_query");
474         depth++;
475
476         if(!smb_io_pol_hnd("", &q_q->pol, ps, depth))
477                 return False;
478
479         if(!prs_uint16("info_class", ps, depth, &q_q->info_class))
480                 return False;
481
482         return True;
483 }
484
485 /*******************************************************************
486 makes an LSA_Q_ENUM_TRUST_DOM structure.
487 ********************************************************************/
488 BOOL init_q_enum_trust_dom(LSA_Q_ENUM_TRUST_DOM * q_e, POLICY_HND *pol,
489                            uint32 enum_context, uint32 preferred_len)
490 {
491         DEBUG(5, ("init_q_enum_trust_dom\n"));
492
493         q_e->pol = *pol;
494         q_e->enum_context = enum_context;
495         q_e->preferred_len = preferred_len;
496
497         return True;
498 }
499
500 /*******************************************************************
501  Reads or writes an LSA_Q_ENUM_TRUST_DOM structure.
502 ********************************************************************/
503
504 BOOL lsa_io_q_enum_trust_dom(const char *desc, LSA_Q_ENUM_TRUST_DOM *q_e, 
505                              prs_struct *ps, int depth)
506 {
507         prs_debug(ps, depth, desc, "lsa_io_q_enum_trust_dom");
508         depth++;
509
510         if(!smb_io_pol_hnd("", &q_e->pol, ps, depth))
511                 return False;
512
513         if(!prs_uint32("enum_context ", ps, depth, &q_e->enum_context))
514                 return False;
515         if(!prs_uint32("preferred_len", ps, depth, &q_e->preferred_len))
516                 return False;
517
518         return True;
519 }
520
521 /*******************************************************************
522  Inits an LSA_R_ENUM_TRUST_DOM structure.
523 ********************************************************************/
524
525 void init_r_enum_trust_dom(TALLOC_CTX *ctx, LSA_R_ENUM_TRUST_DOM *r_e, uint32 enum_context,
526                            uint32 req_num_domains, uint32 num_domains, TRUSTDOM **td)
527 {
528         unsigned int i;
529
530         DEBUG(5, ("init_r_enum_trust_dom\n"));
531         
532         r_e->enum_context = enum_context;
533         r_e->num_domains = num_domains;
534         r_e->ptr_enum_domains = 0;
535         r_e->num_domains2 = num_domains;
536         
537         if (num_domains != 0) {
538         
539                 /* 
540                  * allocating empty arrays of unicode headers, strings
541                  * and sids of enumerated trusted domains
542                  */
543                 if (!(r_e->hdr_domain_name = TALLOC_ARRAY(ctx,UNIHDR2,num_domains))) {
544                         r_e->status = NT_STATUS_NO_MEMORY;
545                         return;
546                 }
547                 
548                 if (!(r_e->uni_domain_name = TALLOC_ARRAY(ctx,UNISTR2,num_domains))) {
549                         r_e->status = NT_STATUS_NO_MEMORY;
550                         return;
551                 }
552
553                 if (!(r_e->domain_sid = TALLOC_ARRAY(ctx,DOM_SID2,num_domains))) {
554                         r_e->status = NT_STATUS_NO_MEMORY;
555                         return;
556                 }
557                                 
558                 for (i = 0; i < num_domains; i++) {
559                         
560                         /* don't know what actually is this for */
561                         r_e->ptr_enum_domains = 1;
562                         
563                         init_dom_sid2(&r_e->domain_sid[i], &(td[i])->sid);
564                         
565                         init_unistr2_w(ctx, &r_e->uni_domain_name[i], (td[i])->name);
566                         init_uni_hdr2(&r_e->hdr_domain_name[i], &r_e->uni_domain_name[i]);
567                         
568                 };
569         }
570
571 }
572
573 /*******************************************************************
574  Reads or writes an LSA_R_ENUM_TRUST_DOM structure.
575 ********************************************************************/
576
577 BOOL lsa_io_r_enum_trust_dom(const char *desc, LSA_R_ENUM_TRUST_DOM *r_e, 
578                              prs_struct *ps, int depth)
579 {
580         prs_debug(ps, depth, desc, "lsa_io_r_enum_trust_dom");
581         depth++;
582
583         if(!prs_uint32("enum_context    ", ps, depth, &r_e->enum_context))
584                 return False;
585         if(!prs_uint32("num_domains     ", ps, depth, &r_e->num_domains))
586                 return False;
587         if(!prs_uint32("ptr_enum_domains", ps, depth, &r_e->ptr_enum_domains))
588                 return False;
589
590         if (r_e->ptr_enum_domains) {
591                 int i, num_domains;
592
593                 if(!prs_uint32("num_domains2", ps, depth, &r_e->num_domains2))
594                         return False;
595
596                 num_domains = r_e->num_domains2;
597
598                 if (UNMARSHALLING(ps)) {
599                         if (!(r_e->hdr_domain_name = PRS_ALLOC_MEM(ps,UNIHDR2,num_domains)))
600                                 return False;
601
602                         if (!(r_e->uni_domain_name = PRS_ALLOC_MEM(ps,UNISTR2,num_domains)))
603                                 return False;
604
605                         if (!(r_e->domain_sid = PRS_ALLOC_MEM(ps,DOM_SID2,num_domains)))
606                                 return False;
607                 }
608
609                 for (i = 0; i < num_domains; i++) {
610                         if(!smb_io_unihdr2 ("", &r_e->hdr_domain_name[i], ps, 
611                                             depth))
612                                 return False;
613                 }
614                 
615                 for (i = 0; i < num_domains; i++) {
616                         if(!smb_io_unistr2 ("", &r_e->uni_domain_name[i],
617                                             r_e->hdr_domain_name[i].buffer,
618                                             ps, depth))
619                                 return False;
620                         if(!smb_io_dom_sid2("", &r_e->domain_sid[i], ps, 
621                                             depth))
622                                 return False;
623                 }
624         }
625
626         if(!prs_ntstatus("status", ps, depth, &r_e->status))
627                 return False;
628
629         return True;
630 }
631
632 /*******************************************************************
633 reads or writes a dom query structure.
634 ********************************************************************/
635
636 static BOOL lsa_io_dom_query(const char *desc, DOM_QUERY *d_q, prs_struct *ps, int depth)
637 {
638         if (d_q == NULL)
639                 return False;
640
641         prs_debug(ps, depth, desc, "lsa_io_dom_query");
642         depth++;
643
644         if(!prs_align(ps))
645                 return False;
646
647         if(!prs_uint16("uni_dom_max_len", ps, depth, &d_q->uni_dom_max_len)) /* domain name string length * 2 */
648                 return False;
649         if(!prs_uint16("uni_dom_str_len", ps, depth, &d_q->uni_dom_str_len)) /* domain name string length * 2 */
650                 return False;
651
652         if(!prs_uint32("buffer_dom_name", ps, depth, &d_q->buffer_dom_name)) /* undocumented domain name string buffer pointer */
653                 return False;
654         if(!prs_uint32("buffer_dom_sid ", ps, depth, &d_q->buffer_dom_sid)) /* undocumented domain SID string buffer pointer */
655                 return False;
656
657         if(!smb_io_unistr2("unistr2", &d_q->uni_domain_name, d_q->buffer_dom_name, ps, depth)) /* domain name (unicode string) */
658                 return False;
659
660         if(!prs_align(ps))
661                 return False;
662
663         if (d_q->buffer_dom_sid != 0) {
664                 if(!smb_io_dom_sid2("", &d_q->dom_sid, ps, depth)) /* domain SID */
665                         return False;
666         } else {
667                 memset((char *)&d_q->dom_sid, '\0', sizeof(d_q->dom_sid));
668         }
669
670         return True;
671 }
672
673 /*******************************************************************
674 reads or writes a structure.
675 ********************************************************************/
676
677 static BOOL lsa_io_dom_query_2(const char *desc, DOM_QUERY_2 *d_q, prs_struct *ps, int depth)
678 {
679         uint32 ptr = 1;
680
681         if (d_q == NULL)
682                 return False;
683
684         prs_debug(ps, depth, desc, "lsa_io_dom_query_2");
685         depth++;
686
687         if (!prs_align(ps))
688                 return False;
689
690         if (!prs_uint32("auditing_enabled", ps, depth, &d_q->auditing_enabled))
691                 return False;
692         if (!prs_uint32("ptr   ", ps, depth, &ptr))
693                 return False;
694         if (!prs_uint32("count1", ps, depth, &d_q->count1))
695                 return False;
696         if (!prs_uint32("count2", ps, depth, &d_q->count2))
697                 return False;
698
699         if (UNMARSHALLING(ps)) {
700                 d_q->auditsettings = TALLOC_ZERO_ARRAY(ps->mem_ctx, uint32, d_q->count2);
701         }
702
703         if (d_q->auditsettings == NULL) {
704                 DEBUG(1, ("lsa_io_dom_query_2: NULL auditsettings!\n"));
705                 return False;
706         }
707
708         if (!prs_uint32s(False, "auditsettings", ps, depth, d_q->auditsettings, d_q->count2))
709                 return False;
710
711     return True;
712 }
713
714 /*******************************************************************
715  Reads or writes a dom query structure.
716 ********************************************************************/
717
718 static BOOL lsa_io_dom_query_3(const char *desc, DOM_QUERY_3 *d_q, prs_struct *ps, int depth)
719 {
720         return lsa_io_dom_query("", d_q, ps, depth);
721 }
722
723 /*******************************************************************
724  Reads or writes a dom query structure.
725 ********************************************************************/
726
727 static BOOL lsa_io_dom_query_5(const char *desc, DOM_QUERY_5 *d_q, prs_struct *ps, int depth)
728 {
729         return lsa_io_dom_query("", d_q, ps, depth);
730 }
731
732 /*******************************************************************
733  Reads or writes a dom query structure.
734 ********************************************************************/
735
736 static BOOL lsa_io_dom_query_6(const char *desc, DOM_QUERY_6 *d_q, prs_struct *ps, int depth)
737 {
738         if (d_q == NULL)
739                 return False;
740
741         prs_debug(ps, depth, desc, "lsa_io_dom_query_6");
742         depth++;
743
744         if (!prs_uint16("server_role", ps, depth, &d_q->server_role))
745                 return False;
746
747         return True;
748 }
749
750 /*******************************************************************
751  Reads or writes an LSA_R_QUERY_INFO structure.
752 ********************************************************************/
753
754 BOOL lsa_io_r_query(const char *desc, LSA_R_QUERY_INFO *r_q, prs_struct *ps,
755                     int depth)
756 {
757         prs_debug(ps, depth, desc, "lsa_io_r_query");
758         depth++;
759
760         if(!prs_uint32("undoc_buffer", ps, depth, &r_q->undoc_buffer))
761                 return False;
762
763         if (r_q->undoc_buffer != 0) {
764                 if(!prs_uint16("info_class", ps, depth, &r_q->info_class))
765                         return False;
766
767                 if(!prs_align(ps))
768                         return False;
769
770                 switch (r_q->info_class) {
771                 case 2:
772                         if(!lsa_io_dom_query_2("", &r_q->dom.id2, ps, depth))
773                                 return False;
774                         break;
775                 case 3:
776                         if(!lsa_io_dom_query_3("", &r_q->dom.id3, ps, depth))
777                                 return False;
778                         break;
779                 case 5:
780                         if(!lsa_io_dom_query_5("", &r_q->dom.id5, ps, depth))
781                                 return False;
782                         break;
783                 case 6:
784                         if(!lsa_io_dom_query_6("", &r_q->dom.id6, ps, depth))
785                                 return False;
786                         break;
787                 default:
788                         /* PANIC! */
789                         break;
790                 }
791         }
792
793         if(!prs_align(ps))
794                 return False;
795
796         if(!prs_ntstatus("status", ps, depth, &r_q->status))
797                 return False;
798
799         return True;
800 }
801
802 /*******************************************************************
803  Inits a LSA_SID_ENUM structure.
804 ********************************************************************/
805
806 static void init_lsa_sid_enum(TALLOC_CTX *mem_ctx, LSA_SID_ENUM *sen, 
807                        int num_entries, const DOM_SID *sids)
808 {
809         int i;
810
811         DEBUG(5, ("init_lsa_sid_enum\n"));
812
813         sen->num_entries  = num_entries;
814         sen->ptr_sid_enum = (num_entries != 0);
815         sen->num_entries2 = num_entries;
816
817         /* Allocate memory for sids and sid pointers */
818
819         if (num_entries == 0) return;
820
821         if ((sen->ptr_sid = TALLOC_ZERO_ARRAY(mem_ctx, uint32, num_entries )) == NULL) {
822                 DEBUG(3, ("init_lsa_sid_enum(): out of memory for ptr_sid\n"));
823                 return;
824         }
825
826         if ((sen->sid = TALLOC_ZERO_ARRAY(mem_ctx, DOM_SID2, num_entries)) == NULL) {
827                 DEBUG(3, ("init_lsa_sid_enum(): out of memory for sids\n"));
828                 return;
829         }
830
831         /* Copy across SIDs and SID pointers */
832
833         for (i = 0; i < num_entries; i++) {
834                 sen->ptr_sid[i] = 1;
835                 init_dom_sid2(&sen->sid[i], &sids[i]);
836         }
837 }
838
839 /*******************************************************************
840  Reads or writes a LSA_SID_ENUM structure.
841 ********************************************************************/
842
843 static BOOL lsa_io_sid_enum(const char *desc, LSA_SID_ENUM *sen, prs_struct *ps, 
844                             int depth)
845 {
846         unsigned int i;
847
848         prs_debug(ps, depth, desc, "lsa_io_sid_enum");
849         depth++;
850
851         if(!prs_align(ps))
852                 return False;
853         
854         if(!prs_uint32("num_entries ", ps, depth, &sen->num_entries))
855                 return False;
856         if(!prs_uint32("ptr_sid_enum", ps, depth, &sen->ptr_sid_enum))
857                 return False;
858
859         /*
860            if the ptr is NULL, leave here. checked from a real w2k trace.
861            JFM, 11/23/2001
862          */
863         
864         if (sen->ptr_sid_enum==0)
865                 return True;
866
867         if(!prs_uint32("num_entries2", ps, depth, &sen->num_entries2))
868                 return False;
869
870         /* Mallocate memory if we're unpacking from the wire */
871
872         if (UNMARSHALLING(ps)) {
873                 if ((sen->ptr_sid = PRS_ALLOC_MEM( ps, uint32, sen->num_entries)) == NULL) {
874                         DEBUG(3, ("init_lsa_sid_enum(): out of memory for "
875                                   "ptr_sid\n"));
876                         return False;
877                 }
878
879                 if ((sen->sid = PRS_ALLOC_MEM( ps, DOM_SID2, sen->num_entries)) == NULL) {
880                         DEBUG(3, ("init_lsa_sid_enum(): out of memory for "
881                                   "sids\n"));
882                         return False;
883                 }
884         }
885
886         for (i = 0; i < sen->num_entries; i++) {        
887                 fstring temp;
888
889                 slprintf(temp, sizeof(temp) - 1, "ptr_sid[%d]", i);
890                 if(!prs_uint32(temp, ps, depth, &sen->ptr_sid[i])) {
891                         return False;
892                 }
893         }
894
895         for (i = 0; i < sen->num_entries; i++) {
896                 fstring temp;
897
898                 slprintf(temp, sizeof(temp) - 1, "sid[%d]", i);
899                 if(!smb_io_dom_sid2(temp, &sen->sid[i], ps, depth)) {
900                         return False;
901                 }
902         }
903
904         return True;
905 }
906
907 /*******************************************************************
908  Inits an LSA_R_ENUM_TRUST_DOM structure.
909 ********************************************************************/
910
911 void init_q_lookup_sids(TALLOC_CTX *mem_ctx, LSA_Q_LOOKUP_SIDS *q_l, 
912                         POLICY_HND *hnd, int num_sids, const DOM_SID *sids,
913                         uint16 level)
914 {
915         DEBUG(5, ("init_q_lookup_sids\n"));
916
917         ZERO_STRUCTP(q_l);
918
919         memcpy(&q_l->pol, hnd, sizeof(q_l->pol));
920         init_lsa_sid_enum(mem_ctx, &q_l->sids, num_sids, sids);
921         
922         q_l->level.value = level;
923 }
924
925 /*******************************************************************
926  Reads or writes a LSA_Q_LOOKUP_SIDS structure.
927 ********************************************************************/
928
929 BOOL lsa_io_q_lookup_sids(const char *desc, LSA_Q_LOOKUP_SIDS *q_s, prs_struct *ps,
930                           int depth)
931 {
932         prs_debug(ps, depth, desc, "lsa_io_q_lookup_sids");
933         depth++;
934
935         if(!prs_align(ps))
936                 return False;
937         
938         if(!smb_io_pol_hnd("pol_hnd", &q_s->pol, ps, depth)) /* policy handle */
939                 return False;
940         if(!lsa_io_sid_enum("sids   ", &q_s->sids, ps, depth)) /* sids to be looked up */
941                 return False;
942         if(!lsa_io_trans_names("names  ", &q_s->names, ps, depth)) /* translated names */
943                 return False;
944         if(!smb_io_lookup_level("switch ", &q_s->level, ps, depth)) /* lookup level */
945                 return False;
946
947         if(!prs_uint32("mapped_count", ps, depth, &q_s->mapped_count))
948                 return False;
949
950         return True;
951 }
952
953 /*******************************************************************
954  Reads or writes a structure.
955 ********************************************************************/
956
957 static BOOL lsa_io_trans_names(const char *desc, LSA_TRANS_NAME_ENUM *trn,
958                 prs_struct *ps, int depth)
959 {
960         unsigned int i;
961
962         prs_debug(ps, depth, desc, "lsa_io_trans_names");
963         depth++;
964
965         if(!prs_align(ps))
966                 return False;
967    
968         if(!prs_uint32("num_entries    ", ps, depth, &trn->num_entries))
969                 return False;
970         if(!prs_uint32("ptr_trans_names", ps, depth, &trn->ptr_trans_names))
971                 return False;
972
973         if (trn->ptr_trans_names != 0) {
974                 if(!prs_uint32("num_entries2   ", ps, depth, 
975                                &trn->num_entries2))
976                         return False;
977
978                 if (UNMARSHALLING(ps)) {
979                         if ((trn->name = PRS_ALLOC_MEM(ps, LSA_TRANS_NAME, trn->num_entries)) == NULL) {
980                                 return False;
981                         }
982
983                         if ((trn->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, trn->num_entries)) == NULL) {
984                                 return False;
985                         }
986                 }
987
988                 for (i = 0; i < trn->num_entries2; i++) {
989                         fstring t;
990                         slprintf(t, sizeof(t) - 1, "name[%d] ", i);
991
992                         if(!lsa_io_trans_name(t, &trn->name[i], ps, depth)) /* translated name */
993                                 return False;
994                 }
995
996                 for (i = 0; i < trn->num_entries2; i++) {
997                         fstring t;
998                         slprintf(t, sizeof(t) - 1, "name[%d] ", i);
999
1000                         if(!smb_io_unistr2(t, &trn->uni_name[i], trn->name[i].hdr_name.buffer, ps, depth))
1001                                 return False;
1002                         if(!prs_align(ps))
1003                                 return False;
1004                 }
1005         }
1006
1007         return True;
1008 }
1009
1010 /*******************************************************************
1011  Reads or writes a structure.
1012 ********************************************************************/
1013
1014 BOOL lsa_io_r_lookup_sids(const char *desc, LSA_R_LOOKUP_SIDS *r_s, 
1015                           prs_struct *ps, int depth)
1016 {
1017         prs_debug(ps, depth, desc, "lsa_io_r_lookup_sids");
1018         depth++;
1019
1020         if(!prs_align(ps))
1021                 return False;
1022         
1023         if(!prs_uint32("ptr_dom_ref", ps, depth, &r_s->ptr_dom_ref))
1024                 return False;
1025
1026         if (r_s->ptr_dom_ref != 0)
1027                 if(!lsa_io_dom_r_ref ("dom_ref", r_s->dom_ref, ps, depth)) /* domain reference info */
1028                         return False;
1029
1030         if(!lsa_io_trans_names("names  ", r_s->names, ps, depth)) /* translated names */
1031                 return False;
1032
1033         if(!prs_align(ps))
1034                 return False;
1035
1036         if(!prs_uint32("mapped_count", ps, depth, &r_s->mapped_count))
1037                 return False;
1038
1039         if(!prs_ntstatus("status      ", ps, depth, &r_s->status))
1040                 return False;
1041
1042         return True;
1043 }
1044
1045 /*******************************************************************
1046 makes a structure.
1047 ********************************************************************/
1048
1049 void init_q_lookup_names(TALLOC_CTX *mem_ctx, LSA_Q_LOOKUP_NAMES *q_l, 
1050                          POLICY_HND *hnd, int num_names, const char **names)
1051 {
1052         unsigned int i;
1053
1054         DEBUG(5, ("init_q_lookup_names\n"));
1055
1056         ZERO_STRUCTP(q_l);
1057
1058         q_l->pol = *hnd;
1059         q_l->num_entries = num_names;
1060         q_l->num_entries2 = num_names;
1061         q_l->lookup_level = 1;
1062
1063         if ((q_l->uni_name = TALLOC_ZERO_ARRAY(mem_ctx, UNISTR2, num_names)) == NULL) {
1064                 DEBUG(3, ("init_q_lookup_names(): out of memory\n"));
1065                 return;
1066         }
1067
1068         if ((q_l->hdr_name = TALLOC_ZERO_ARRAY(mem_ctx, UNIHDR, num_names)) == NULL) {
1069                 DEBUG(3, ("init_q_lookup_names(): out of memory\n"));
1070                 return;
1071         }
1072
1073         for (i = 0; i < num_names; i++) {
1074                 init_unistr2(&q_l->uni_name[i], names[i], UNI_FLAGS_NONE);
1075                 init_uni_hdr(&q_l->hdr_name[i], &q_l->uni_name[i]);
1076         }
1077 }
1078
1079 /*******************************************************************
1080 reads or writes a structure.
1081 ********************************************************************/
1082
1083 BOOL lsa_io_q_lookup_names(const char *desc, LSA_Q_LOOKUP_NAMES *q_r, 
1084                            prs_struct *ps, int depth)
1085 {
1086         unsigned int i;
1087
1088         prs_debug(ps, depth, desc, "lsa_io_q_lookup_names");
1089         depth++;
1090
1091         if(!prs_align(ps))
1092                 return False;
1093
1094         if(!smb_io_pol_hnd("", &q_r->pol, ps, depth)) /* policy handle */
1095                 return False;
1096
1097         if(!prs_align(ps))
1098                 return False;
1099         if(!prs_uint32("num_entries    ", ps, depth, &q_r->num_entries))
1100                 return False;
1101         if(!prs_uint32("num_entries2   ", ps, depth, &q_r->num_entries2))
1102                 return False;
1103
1104         if (UNMARSHALLING(ps)) {
1105                 if (q_r->num_entries) {
1106                         if ((q_r->hdr_name = PRS_ALLOC_MEM(ps, UNIHDR, q_r->num_entries)) == NULL)
1107                                 return False;
1108                         if ((q_r->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, q_r->num_entries)) == NULL)
1109                                 return False;
1110                 }
1111         }
1112
1113         for (i = 0; i < q_r->num_entries; i++) {
1114                 if(!prs_align(ps))
1115                         return False;
1116                 if(!smb_io_unihdr("hdr_name", &q_r->hdr_name[i], ps, depth)) /* pointer names */
1117                         return False;
1118         }
1119
1120         for (i = 0; i < q_r->num_entries; i++) {
1121                 if(!prs_align(ps))
1122                         return False;
1123                 if(!smb_io_unistr2("dom_name", &q_r->uni_name[i], q_r->hdr_name[i].buffer, ps, depth)) /* names to be looked up */
1124                         return False;
1125         }
1126
1127         if(!prs_align(ps))
1128                 return False;
1129         if(!prs_uint32("num_trans_entries ", ps, depth, &q_r->num_trans_entries))
1130                 return False;
1131         if(!prs_uint32("ptr_trans_sids ", ps, depth, &q_r->ptr_trans_sids))
1132                 return False;
1133         if(!prs_uint32("lookup_level   ", ps, depth, &q_r->lookup_level))
1134                 return False;
1135         if(!prs_uint32("mapped_count   ", ps, depth, &q_r->mapped_count))
1136                 return False;
1137
1138         return True;
1139 }
1140
1141 /*******************************************************************
1142 reads or writes a structure.
1143 ********************************************************************/
1144
1145 BOOL lsa_io_r_lookup_names(const char *desc, LSA_R_LOOKUP_NAMES *r_r, 
1146                            prs_struct *ps, int depth)
1147 {
1148         unsigned int i;
1149
1150         prs_debug(ps, depth, desc, "lsa_io_r_lookup_names");
1151         depth++;
1152
1153         if(!prs_align(ps))
1154                 return False;
1155
1156         if(!prs_uint32("ptr_dom_ref", ps, depth, &r_r->ptr_dom_ref))
1157                 return False;
1158
1159         if (r_r->ptr_dom_ref != 0)
1160                 if(!lsa_io_dom_r_ref("", r_r->dom_ref, ps, depth))
1161                         return False;
1162
1163         if(!prs_uint32("num_entries", ps, depth, &r_r->num_entries))
1164                 return False;
1165         if(!prs_uint32("ptr_entries", ps, depth, &r_r->ptr_entries))
1166                 return False;
1167
1168         if (r_r->ptr_entries != 0) {
1169                 if(!prs_uint32("num_entries2", ps, depth, &r_r->num_entries2))
1170                         return False;
1171
1172                 if (r_r->num_entries2 != r_r->num_entries) {
1173                         /* RPC fault */
1174                         return False;
1175                 }
1176
1177                 if (UNMARSHALLING(ps)) {
1178                         if ((r_r->dom_rid = PRS_ALLOC_MEM(ps, DOM_RID2, r_r->num_entries2))
1179                             == NULL) {
1180                                 DEBUG(3, ("lsa_io_r_lookup_names(): out of memory\n"));
1181                                 return False;
1182                         }
1183                 }
1184
1185                 for (i = 0; i < r_r->num_entries2; i++)
1186                         if(!smb_io_dom_rid2("", &r_r->dom_rid[i], ps, depth)) /* domain RIDs being looked up */
1187                                 return False;
1188         }
1189
1190         if(!prs_uint32("mapped_count", ps, depth, &r_r->mapped_count))
1191                 return False;
1192
1193         if(!prs_ntstatus("status      ", ps, depth, &r_r->status))
1194                 return False;
1195
1196         return True;
1197 }
1198
1199
1200 /*******************************************************************
1201  Inits an LSA_Q_CLOSE structure.
1202 ********************************************************************/
1203
1204 void init_lsa_q_close(LSA_Q_CLOSE *q_c, POLICY_HND *hnd)
1205 {
1206         DEBUG(5, ("init_lsa_q_close\n"));
1207
1208         memcpy(&q_c->pol, hnd, sizeof(q_c->pol));
1209 }
1210
1211 /*******************************************************************
1212  Reads or writes an LSA_Q_CLOSE structure.
1213 ********************************************************************/
1214
1215 BOOL lsa_io_q_close(const char *desc, LSA_Q_CLOSE *q_c, prs_struct *ps, int depth)
1216 {
1217         prs_debug(ps, depth, desc, "lsa_io_q_close");
1218         depth++;
1219
1220         if(!smb_io_pol_hnd("", &q_c->pol, ps, depth))
1221                 return False;
1222
1223         return True;
1224 }
1225
1226 /*******************************************************************
1227  Reads or writes an LSA_R_CLOSE structure.
1228 ********************************************************************/
1229
1230 BOOL lsa_io_r_close(const char *desc,  LSA_R_CLOSE *r_c, prs_struct *ps, int depth)
1231 {
1232         prs_debug(ps, depth, desc, "lsa_io_r_close");
1233         depth++;
1234
1235         if(!smb_io_pol_hnd("", &r_c->pol, ps, depth))
1236                 return False;
1237
1238         if(!prs_ntstatus("status", ps, depth, &r_c->status))
1239                 return False;
1240
1241         return True;
1242 }
1243
1244 /*******************************************************************
1245  Reads or writes an LSA_Q_OPEN_SECRET structure.
1246 ********************************************************************/
1247
1248 BOOL lsa_io_q_open_secret(const char *desc, LSA_Q_OPEN_SECRET *q_c, prs_struct *ps, int depth)
1249 {
1250         prs_debug(ps, depth, desc, "lsa_io_q_open_secret");
1251         depth++;
1252
1253         /* Don't bother to read or write at present... */
1254         return True;
1255 }
1256
1257 /*******************************************************************
1258  Reads or writes an LSA_R_OPEN_SECRET structure.
1259 ********************************************************************/
1260
1261 BOOL lsa_io_r_open_secret(const char *desc, LSA_R_OPEN_SECRET *r_c, prs_struct *ps, int depth)
1262 {
1263         prs_debug(ps, depth, desc, "lsa_io_r_open_secret");
1264         depth++;
1265
1266         if(!prs_align(ps))
1267                 return False;
1268    
1269         if(!prs_uint32("dummy1", ps, depth, &r_c->dummy1))
1270                 return False;
1271         if(!prs_uint32("dummy2", ps, depth, &r_c->dummy2))
1272                 return False;
1273         if(!prs_uint32("dummy3", ps, depth, &r_c->dummy3))
1274                 return False;
1275         if(!prs_uint32("dummy4", ps, depth, &r_c->dummy4))
1276                 return False;
1277         if(!prs_ntstatus("status", ps, depth, &r_c->status))
1278                 return False;
1279
1280         return True;
1281 }
1282
1283 /*******************************************************************
1284  Inits an LSA_Q_ENUM_PRIVS structure.
1285 ********************************************************************/
1286
1287 void init_q_enum_privs(LSA_Q_ENUM_PRIVS *q_q, POLICY_HND *hnd, uint32 enum_context, uint32 pref_max_length)
1288 {
1289         DEBUG(5, ("init_q_enum_privs\n"));
1290
1291         memcpy(&q_q->pol, hnd, sizeof(q_q->pol));
1292
1293         q_q->enum_context = enum_context;
1294         q_q->pref_max_length = pref_max_length;
1295 }
1296
1297 /*******************************************************************
1298 reads or writes a structure.
1299 ********************************************************************/
1300 BOOL lsa_io_q_enum_privs(const char *desc, LSA_Q_ENUM_PRIVS *q_q, prs_struct *ps, int depth)
1301 {
1302         if (q_q == NULL)
1303                 return False;
1304
1305         prs_debug(ps, depth, desc, "lsa_io_q_enum_privs");
1306         depth++;
1307
1308         if (!smb_io_pol_hnd("", &q_q->pol, ps, depth))
1309                 return False;
1310
1311         if(!prs_uint32("enum_context   ", ps, depth, &q_q->enum_context))
1312                 return False;
1313         if(!prs_uint32("pref_max_length", ps, depth, &q_q->pref_max_length))
1314                 return False;
1315
1316         return True;
1317 }
1318
1319 /*******************************************************************
1320 reads or writes a structure.
1321 ********************************************************************/
1322 static BOOL lsa_io_priv_entries(const char *desc, LSA_PRIV_ENTRY *entries, uint32 count, prs_struct *ps, int depth)
1323 {
1324         uint32 i;
1325
1326         if (entries == NULL)
1327                 return False;
1328
1329         prs_debug(ps, depth, desc, "lsa_io_priv_entries");
1330         depth++;
1331
1332         if(!prs_align(ps))
1333                 return False;
1334
1335         for (i = 0; i < count; i++) {
1336                 if (!smb_io_unihdr("", &entries[i].hdr_name, ps, depth))
1337                         return False;
1338                 if(!prs_uint32("luid_low ", ps, depth, &entries[i].luid_low))
1339                         return False;
1340                 if(!prs_uint32("luid_high", ps, depth, &entries[i].luid_high))
1341                         return False;
1342         }
1343
1344         for (i = 0; i < count; i++)
1345                 if (!smb_io_unistr2("", &entries[i].name, entries[i].hdr_name.buffer, ps, depth))
1346                         return False;
1347
1348         return True;
1349 }
1350
1351 /*******************************************************************
1352  Inits an LSA_R_ENUM_PRIVS structure.
1353 ********************************************************************/
1354
1355 void init_lsa_r_enum_privs(LSA_R_ENUM_PRIVS *r_u, uint32 enum_context,
1356                           uint32 count, LSA_PRIV_ENTRY *entries)
1357 {
1358         DEBUG(5, ("init_lsa_r_enum_privs\n"));
1359
1360         r_u->enum_context=enum_context;
1361         r_u->count=count;
1362         
1363         if (entries!=NULL) {
1364                 r_u->ptr=1;
1365                 r_u->count1=count;
1366                 r_u->privs=entries;
1367         } else {
1368                 r_u->ptr=0;
1369                 r_u->count1=0;
1370                 r_u->privs=NULL;
1371         }               
1372 }
1373
1374 /*******************************************************************
1375 reads or writes a structure.
1376 ********************************************************************/
1377 BOOL lsa_io_r_enum_privs(const char *desc, LSA_R_ENUM_PRIVS *r_q, prs_struct *ps, int depth)
1378 {
1379         if (r_q == NULL)
1380                 return False;
1381
1382         prs_debug(ps, depth, desc, "lsa_io_r_enum_privs");
1383         depth++;
1384
1385         if(!prs_align(ps))
1386                 return False;
1387
1388         if(!prs_uint32("enum_context", ps, depth, &r_q->enum_context))
1389                 return False;
1390         if(!prs_uint32("count", ps, depth, &r_q->count))
1391                 return False;
1392         if(!prs_uint32("ptr", ps, depth, &r_q->ptr))
1393                 return False;
1394
1395         if (r_q->ptr) {
1396                 if(!prs_uint32("count1", ps, depth, &r_q->count1))
1397                         return False;
1398
1399                 if (UNMARSHALLING(ps))
1400                         if (!(r_q->privs = PRS_ALLOC_MEM(ps, LSA_PRIV_ENTRY, r_q->count1)))
1401                                 return False;
1402
1403                 if (!lsa_io_priv_entries("", r_q->privs, r_q->count1, ps, depth))
1404                         return False;
1405         }
1406
1407         if(!prs_align(ps))
1408                 return False;
1409
1410         if(!prs_ntstatus("status", ps, depth, &r_q->status))
1411                 return False;
1412
1413         return True;
1414 }
1415
1416 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)
1417 {
1418         memcpy(&trn->pol, hnd, sizeof(trn->pol));
1419
1420         init_unistr2(&trn->name, name, UNI_FLAGS_NONE);
1421         init_uni_hdr(&trn->hdr_name, &trn->name);
1422         trn->lang_id = lang_id;
1423         trn->lang_id_sys = lang_id_sys;
1424 }
1425
1426 /*******************************************************************
1427 reads or writes a structure.
1428 ********************************************************************/
1429 BOOL lsa_io_q_priv_get_dispname(const char *desc, LSA_Q_PRIV_GET_DISPNAME *q_q, prs_struct *ps, int depth)
1430 {
1431         if (q_q == NULL)
1432                 return False;
1433
1434         prs_debug(ps, depth, desc, "lsa_io_q_priv_get_dispname");
1435         depth++;
1436
1437         if(!prs_align(ps))
1438                 return False;
1439
1440         if (!smb_io_pol_hnd("", &q_q->pol, ps, depth))
1441                 return False;
1442
1443         if (!smb_io_unihdr("hdr_name", &q_q->hdr_name, ps, depth))
1444                 return False;
1445
1446         if (!smb_io_unistr2("name", &q_q->name, q_q->hdr_name.buffer, ps, depth))
1447                 return False;
1448
1449         if(!prs_uint16("lang_id    ", ps, depth, &q_q->lang_id))
1450                 return False;
1451         if(!prs_uint16("lang_id_sys", ps, depth, &q_q->lang_id_sys))
1452                 return False;
1453
1454         return True;
1455 }
1456
1457 /*******************************************************************
1458 reads or writes a structure.
1459 ********************************************************************/
1460 BOOL lsa_io_r_priv_get_dispname(const char *desc, LSA_R_PRIV_GET_DISPNAME *r_q, prs_struct *ps, int depth)
1461 {
1462         if (r_q == NULL)
1463                 return False;
1464
1465         prs_debug(ps, depth, desc, "lsa_io_r_priv_get_dispname");
1466         depth++;
1467
1468         if (!prs_align(ps))
1469                 return False;
1470
1471         if (!prs_uint32("ptr_info", ps, depth, &r_q->ptr_info))
1472                 return False;
1473
1474         if (r_q->ptr_info){
1475                 if (!smb_io_unihdr("hdr_name", &r_q->hdr_desc, ps, depth))
1476                         return False;
1477
1478                 if (!smb_io_unistr2("desc", &r_q->desc, r_q->hdr_desc.buffer, ps, depth))
1479                         return False;
1480         }
1481 /*
1482         if(!prs_align(ps))
1483                 return False;
1484 */
1485         if(!prs_uint16("lang_id", ps, depth, &r_q->lang_id))
1486                 return False;
1487
1488         if(!prs_align(ps))
1489                 return False;
1490         if(!prs_ntstatus("status", ps, depth, &r_q->status))
1491                 return False;
1492
1493         return True;
1494 }
1495
1496 /*
1497   initialise a LSA_Q_ENUM_ACCOUNTS structure
1498 */
1499 void init_lsa_q_enum_accounts(LSA_Q_ENUM_ACCOUNTS *trn, POLICY_HND *hnd, uint32 enum_context, uint32 pref_max_length)
1500 {
1501         memcpy(&trn->pol, hnd, sizeof(trn->pol));
1502
1503         trn->enum_context = enum_context;
1504         trn->pref_max_length = pref_max_length;
1505 }
1506
1507 /*******************************************************************
1508 reads or writes a structure.
1509 ********************************************************************/
1510 BOOL lsa_io_q_enum_accounts(const char *desc, LSA_Q_ENUM_ACCOUNTS *q_q, prs_struct *ps, int depth)
1511 {
1512         if (q_q == NULL)
1513                 return False;
1514
1515         prs_debug(ps, depth, desc, "lsa_io_q_enum_accounts");
1516         depth++;
1517
1518         if (!smb_io_pol_hnd("", &q_q->pol, ps, depth))
1519                 return False;
1520
1521         if(!prs_uint32("enum_context   ", ps, depth, &q_q->enum_context))
1522                 return False;
1523         if(!prs_uint32("pref_max_length", ps, depth, &q_q->pref_max_length))
1524                 return False;
1525
1526         return True;
1527 }
1528
1529
1530 /*******************************************************************
1531  Inits an LSA_R_ENUM_PRIVS structure.
1532 ********************************************************************/
1533
1534 void init_lsa_r_enum_accounts(LSA_R_ENUM_ACCOUNTS *r_u, uint32 enum_context)
1535 {
1536         DEBUG(5, ("init_lsa_r_enum_accounts\n"));
1537
1538         r_u->enum_context=enum_context;
1539         if (r_u->enum_context!=0) {
1540                 r_u->sids.num_entries=enum_context;
1541                 r_u->sids.ptr_sid_enum=1;
1542                 r_u->sids.num_entries2=enum_context;
1543         } else {
1544                 r_u->sids.num_entries=0;
1545                 r_u->sids.ptr_sid_enum=0;
1546                 r_u->sids.num_entries2=0;
1547         }
1548 }
1549
1550 /*******************************************************************
1551 reads or writes a structure.
1552 ********************************************************************/
1553 BOOL lsa_io_r_enum_accounts(const char *desc, LSA_R_ENUM_ACCOUNTS *r_q, prs_struct *ps, int depth)
1554 {
1555         if (r_q == NULL)
1556                 return False;
1557
1558         prs_debug(ps, depth, desc, "lsa_io_r_enum_accounts");
1559         depth++;
1560
1561         if (!prs_align(ps))
1562                 return False;
1563
1564         if(!prs_uint32("enum_context", ps, depth, &r_q->enum_context))
1565                 return False;
1566
1567         if (!lsa_io_sid_enum("sids", &r_q->sids, ps, depth))
1568                 return False;
1569
1570         if (!prs_align(ps))
1571                 return False;
1572
1573         if(!prs_ntstatus("status", ps, depth, &r_q->status))
1574                 return False;
1575
1576         return True;
1577 }
1578
1579
1580 /*******************************************************************
1581  Reads or writes an LSA_Q_UNK_GET_CONNUSER structure.
1582 ********************************************************************/
1583
1584 BOOL lsa_io_q_unk_get_connuser(const char *desc, LSA_Q_UNK_GET_CONNUSER *q_c, prs_struct *ps, int depth)
1585 {
1586         prs_debug(ps, depth, desc, "lsa_io_q_unk_get_connuser");
1587         depth++;
1588
1589         if(!prs_align(ps))
1590                 return False;
1591    
1592         if(!prs_uint32("ptr_srvname", ps, depth, &q_c->ptr_srvname))
1593                 return False;
1594
1595         if(!smb_io_unistr2("uni2_srvname", &q_c->uni2_srvname, q_c->ptr_srvname, ps, depth)) /* server name to be looked up */
1596                 return False;
1597
1598         if (!prs_align(ps))
1599           return False;
1600
1601         if(!prs_uint32("unk1", ps, depth, &q_c->unk1))
1602                 return False;
1603         if(!prs_uint32("unk2", ps, depth, &q_c->unk2))
1604                 return False;
1605         if(!prs_uint32("unk3", ps, depth, &q_c->unk3))
1606                 return False;
1607
1608         /* Don't bother to read or write at present... */
1609         return True;
1610 }
1611
1612 /*******************************************************************
1613  Reads or writes an LSA_R_UNK_GET_CONNUSER structure.
1614 ********************************************************************/
1615
1616 BOOL lsa_io_r_unk_get_connuser(const char *desc, LSA_R_UNK_GET_CONNUSER *r_c, prs_struct *ps, int depth)
1617 {
1618         prs_debug(ps, depth, desc, "lsa_io_r_unk_get_connuser");
1619         depth++;
1620
1621         if(!prs_align(ps))
1622                 return False;
1623    
1624         if(!prs_uint32("ptr_user_name", ps, depth, &r_c->ptr_user_name))
1625                 return False;
1626         if(!smb_io_unihdr("hdr_user_name", &r_c->hdr_user_name, ps, depth))
1627                 return False;
1628         if(!smb_io_unistr2("uni2_user_name", &r_c->uni2_user_name, r_c->ptr_user_name, ps, depth))
1629                 return False;
1630
1631         if (!prs_align(ps))
1632           return False;
1633         
1634         if(!prs_uint32("unk1", ps, depth, &r_c->unk1))
1635                 return False;
1636
1637         if(!prs_uint32("ptr_dom_name", ps, depth, &r_c->ptr_dom_name))
1638                 return False;
1639         if(!smb_io_unihdr("hdr_dom_name", &r_c->hdr_dom_name, ps, depth))
1640                 return False;
1641         if(!smb_io_unistr2("uni2_dom_name", &r_c->uni2_dom_name, r_c->ptr_dom_name, ps, depth))
1642                 return False;
1643
1644         if (!prs_align(ps))
1645           return False;
1646         
1647         if(!prs_ntstatus("status", ps, depth, &r_c->status))
1648                 return False;
1649
1650         return True;
1651 }
1652
1653 void init_lsa_q_create_account(LSA_Q_CREATEACCOUNT *trn, POLICY_HND *hnd, DOM_SID *sid, uint32 desired_access)
1654 {
1655         memcpy(&trn->pol, hnd, sizeof(trn->pol));
1656
1657         init_dom_sid2(&trn->sid, sid);
1658         trn->access = desired_access;
1659 }
1660
1661
1662 /*******************************************************************
1663  Reads or writes an LSA_Q_CREATEACCOUNT structure.
1664 ********************************************************************/
1665
1666 BOOL lsa_io_q_create_account(const char *desc, LSA_Q_CREATEACCOUNT *r_c, prs_struct *ps, int depth)
1667 {
1668         prs_debug(ps, depth, desc, "lsa_io_q_create_account");
1669         depth++;
1670
1671         if(!prs_align(ps))
1672                 return False;
1673  
1674         if(!smb_io_pol_hnd("pol", &r_c->pol, ps, depth))
1675                 return False;
1676
1677         if(!smb_io_dom_sid2("sid", &r_c->sid, ps, depth)) /* domain SID */
1678                 return False;
1679
1680         if(!prs_uint32("access", ps, depth, &r_c->access))
1681                 return False;
1682   
1683         return True;
1684 }
1685
1686 /*******************************************************************
1687  Reads or writes an LSA_R_CREATEACCOUNT structure.
1688 ********************************************************************/
1689
1690 BOOL lsa_io_r_create_account(const char *desc, LSA_R_CREATEACCOUNT  *r_c, prs_struct *ps, int depth)
1691 {
1692         prs_debug(ps, depth, desc, "lsa_io_r_open_account");
1693         depth++;
1694
1695         if(!prs_align(ps))
1696                 return False;
1697  
1698         if(!smb_io_pol_hnd("pol", &r_c->pol, ps, depth))
1699                 return False;
1700
1701         if(!prs_ntstatus("status", ps, depth, &r_c->status))
1702                 return False;
1703
1704         return True;
1705 }
1706
1707
1708 void init_lsa_q_open_account(LSA_Q_OPENACCOUNT *trn, POLICY_HND *hnd, DOM_SID *sid, uint32 desired_access)
1709 {
1710         memcpy(&trn->pol, hnd, sizeof(trn->pol));
1711
1712         init_dom_sid2(&trn->sid, sid);
1713         trn->access = desired_access;
1714 }
1715
1716 /*******************************************************************
1717  Reads or writes an LSA_Q_OPENACCOUNT structure.
1718 ********************************************************************/
1719
1720 BOOL lsa_io_q_open_account(const char *desc, LSA_Q_OPENACCOUNT *r_c, prs_struct *ps, int depth)
1721 {
1722         prs_debug(ps, depth, desc, "lsa_io_q_open_account");
1723         depth++;
1724
1725         if(!prs_align(ps))
1726                 return False;
1727  
1728         if(!smb_io_pol_hnd("pol", &r_c->pol, ps, depth))
1729                 return False;
1730
1731         if(!smb_io_dom_sid2("sid", &r_c->sid, ps, depth)) /* domain SID */
1732                 return False;
1733
1734         if(!prs_uint32("access", ps, depth, &r_c->access))
1735                 return False;
1736   
1737         return True;
1738 }
1739
1740 /*******************************************************************
1741  Reads or writes an LSA_R_OPENACCOUNT structure.
1742 ********************************************************************/
1743
1744 BOOL lsa_io_r_open_account(const char *desc, LSA_R_OPENACCOUNT  *r_c, prs_struct *ps, int depth)
1745 {
1746         prs_debug(ps, depth, desc, "lsa_io_r_open_account");
1747         depth++;
1748
1749         if(!prs_align(ps))
1750                 return False;
1751  
1752         if(!smb_io_pol_hnd("pol", &r_c->pol, ps, depth))
1753                 return False;
1754
1755         if(!prs_ntstatus("status", ps, depth, &r_c->status))
1756                 return False;
1757
1758         return True;
1759 }
1760
1761
1762 void init_lsa_q_enum_privsaccount(LSA_Q_ENUMPRIVSACCOUNT *trn, POLICY_HND *hnd)
1763 {
1764         memcpy(&trn->pol, hnd, sizeof(trn->pol));
1765
1766 }
1767
1768 /*******************************************************************
1769  Reads or writes an LSA_Q_ENUMPRIVSACCOUNT structure.
1770 ********************************************************************/
1771
1772 BOOL lsa_io_q_enum_privsaccount(const char *desc, LSA_Q_ENUMPRIVSACCOUNT *r_c, prs_struct *ps, int depth)
1773 {
1774         prs_debug(ps, depth, desc, "lsa_io_q_enum_privsaccount");
1775         depth++;
1776
1777         if(!prs_align(ps))
1778                 return False;
1779  
1780         if(!smb_io_pol_hnd("pol", &r_c->pol, ps, depth))
1781                 return False;
1782
1783         return True;
1784 }
1785
1786 /*******************************************************************
1787  Reads or writes an LUID structure.
1788 ********************************************************************/
1789
1790 static BOOL lsa_io_luid(const char *desc, LUID *r_c, prs_struct *ps, int depth)
1791 {
1792         prs_debug(ps, depth, desc, "lsa_io_luid");
1793         depth++;
1794
1795         if(!prs_align(ps))
1796                 return False;
1797  
1798         if(!prs_uint32("low", ps, depth, &r_c->low))
1799                 return False;
1800
1801         if(!prs_uint32("high", ps, depth, &r_c->high))
1802                 return False;
1803
1804         return True;
1805 }
1806
1807 /*******************************************************************
1808  Reads or writes an LUID_ATTR structure.
1809 ********************************************************************/
1810
1811 static BOOL lsa_io_luid_attr(const char *desc, LUID_ATTR *r_c, prs_struct *ps, int depth)
1812 {
1813         prs_debug(ps, depth, desc, "lsa_io_luid_attr");
1814         depth++;
1815
1816         if(!prs_align(ps))
1817                 return False;
1818  
1819         if (!lsa_io_luid(desc, &r_c->luid, ps, depth))
1820                 return False;
1821
1822         if(!prs_uint32("attr", ps, depth, &r_c->attr))
1823                 return False;
1824
1825         return True;
1826 }
1827
1828 /*******************************************************************
1829  Reads or writes an PRIVILEGE_SET structure.
1830 ********************************************************************/
1831
1832 static BOOL lsa_io_privilege_set(const char *desc, PRIVILEGE_SET *r_c, prs_struct *ps, int depth)
1833 {
1834         uint32 i;
1835
1836         prs_debug(ps, depth, desc, "lsa_io_privilege_set");
1837         depth++;
1838
1839         if(!prs_align(ps))
1840                 return False;
1841  
1842         if(!prs_uint32("count", ps, depth, &r_c->count))
1843                 return False;
1844         if(!prs_uint32("control", ps, depth, &r_c->control))
1845                 return False;
1846
1847         for (i=0; i<r_c->count; i++) {
1848                 if (!lsa_io_luid_attr(desc, &r_c->set[i], ps, depth))
1849                         return False;
1850         }
1851         
1852         return True;
1853 }
1854
1855 NTSTATUS init_lsa_r_enum_privsaccount(TALLOC_CTX *mem_ctx, LSA_R_ENUMPRIVSACCOUNT *r_u, LUID_ATTR *set, uint32 count, uint32 control)
1856 {
1857         NTSTATUS ret = NT_STATUS_OK;
1858
1859         r_u->ptr = 1;
1860         r_u->count = count;
1861
1862         if ( !NT_STATUS_IS_OK(ret = privilege_set_init_by_ctx(mem_ctx, &(r_u->set))) )
1863                 return ret;
1864         
1865         r_u->set.count = count;
1866         
1867         if (!NT_STATUS_IS_OK(ret = dup_luid_attr(r_u->set.mem_ctx, &(r_u->set.set), set, count)))
1868                 return ret;
1869
1870         DEBUG(10,("init_lsa_r_enum_privsaccount: %d privileges\n", r_u->count));
1871
1872         return ret;
1873 }
1874
1875 /*******************************************************************
1876  Reads or writes an LSA_R_ENUMPRIVSACCOUNT structure.
1877 ********************************************************************/
1878
1879 BOOL lsa_io_r_enum_privsaccount(const char *desc, LSA_R_ENUMPRIVSACCOUNT *r_c, prs_struct *ps, int depth)
1880 {
1881         prs_debug(ps, depth, desc, "lsa_io_r_enum_privsaccount");
1882         depth++;
1883
1884         if(!prs_align(ps))
1885                 return False;
1886  
1887         if(!prs_uint32("ptr", ps, depth, &r_c->ptr))
1888                 return False;
1889
1890         if (r_c->ptr!=0) {
1891                 if(!prs_uint32("count", ps, depth, &r_c->count))
1892                         return False;
1893
1894                 /* malloc memory if unmarshalling here */
1895
1896                 if (UNMARSHALLING(ps) && r_c->count != 0) {
1897                         if (!NT_STATUS_IS_OK(privilege_set_init_by_ctx(ps->mem_ctx, &(r_c->set))))
1898                                 return False;
1899
1900                         if (!(r_c->set.set = PRS_ALLOC_MEM(ps,LUID_ATTR,r_c->count)))
1901                                 return False;
1902
1903                 }
1904                 
1905                 if(!lsa_io_privilege_set(desc, &r_c->set, ps, depth))
1906                         return False;
1907         }
1908
1909         if(!prs_ntstatus("status", ps, depth, &r_c->status))
1910                 return False;
1911
1912         return True;
1913 }
1914
1915
1916
1917 /*******************************************************************
1918  Reads or writes an  LSA_Q_GETSYSTEMACCOUNTstructure.
1919 ********************************************************************/
1920
1921 BOOL lsa_io_q_getsystemaccount(const char *desc, LSA_Q_GETSYSTEMACCOUNT  *r_c, prs_struct *ps, int depth)
1922 {
1923         prs_debug(ps, depth, desc, "lsa_io_q_getsystemaccount");
1924         depth++;
1925
1926         if(!prs_align(ps))
1927                 return False;
1928  
1929         if(!smb_io_pol_hnd("pol", &r_c->pol, ps, depth))
1930                 return False;
1931
1932         return True;
1933 }
1934
1935 /*******************************************************************
1936  Reads or writes an  LSA_R_GETSYSTEMACCOUNTstructure.
1937 ********************************************************************/
1938
1939 BOOL lsa_io_r_getsystemaccount(const char *desc, LSA_R_GETSYSTEMACCOUNT  *r_c, prs_struct *ps, int depth)
1940 {
1941         prs_debug(ps, depth, desc, "lsa_io_r_getsystemaccount");
1942         depth++;
1943
1944         if(!prs_align(ps))
1945                 return False;
1946  
1947         if(!prs_uint32("access", ps, depth, &r_c->access))
1948                 return False;
1949
1950         if(!prs_ntstatus("status", ps, depth, &r_c->status))
1951                 return False;
1952
1953         return True;
1954 }
1955
1956
1957 /*******************************************************************
1958  Reads or writes an LSA_Q_SETSYSTEMACCOUNT structure.
1959 ********************************************************************/
1960
1961 BOOL lsa_io_q_setsystemaccount(const char *desc, LSA_Q_SETSYSTEMACCOUNT  *r_c, prs_struct *ps, int depth)
1962 {
1963         prs_debug(ps, depth, desc, "lsa_io_q_setsystemaccount");
1964         depth++;
1965
1966         if(!prs_align(ps))
1967                 return False;
1968  
1969         if(!smb_io_pol_hnd("pol", &r_c->pol, ps, depth))
1970                 return False;
1971
1972         if(!prs_uint32("access", ps, depth, &r_c->access))
1973                 return False;
1974
1975         return True;
1976 }
1977
1978 /*******************************************************************
1979  Reads or writes an LSA_R_SETSYSTEMACCOUNT structure.
1980 ********************************************************************/
1981
1982 BOOL lsa_io_r_setsystemaccount(const char *desc, LSA_R_SETSYSTEMACCOUNT  *r_c, prs_struct *ps, int depth)
1983 {
1984         prs_debug(ps, depth, desc, "lsa_io_r_setsystemaccount");
1985         depth++;
1986
1987         if(!prs_align(ps))
1988                 return False;
1989  
1990         if(!prs_ntstatus("status", ps, depth, &r_c->status))
1991                 return False;
1992
1993         return True;
1994 }
1995
1996
1997 void init_lsa_q_lookupprivvalue(LSA_Q_LOOKUPPRIVVALUE *trn, POLICY_HND *hnd, const char *name)
1998 {
1999         memcpy(&trn->pol, hnd, sizeof(trn->pol));
2000         init_unistr2(&trn->uni2_right, name, UNI_FLAGS_NONE);
2001         init_uni_hdr(&trn->hdr_right, &trn->uni2_right);
2002 }
2003
2004 /*******************************************************************
2005  Reads or writes an LSA_Q_LOOKUPPRIVVALUE  structure.
2006 ********************************************************************/
2007
2008 BOOL lsa_io_q_lookupprivvalue(const char *desc, LSA_Q_LOOKUPPRIVVALUE  *r_c, prs_struct *ps, int depth)
2009 {
2010         prs_debug(ps, depth, desc, "lsa_io_q_lookupprivvalue");
2011         depth++;
2012
2013         if(!prs_align(ps))
2014                 return False;
2015  
2016         if(!smb_io_pol_hnd("pol", &r_c->pol, ps, depth))
2017                 return False;
2018         if(!smb_io_unihdr ("hdr_name", &r_c->hdr_right, ps, depth))
2019                 return False;
2020         if(!smb_io_unistr2("uni2_right", &r_c->uni2_right, r_c->hdr_right.buffer, ps, depth))
2021                 return False;
2022
2023         return True;
2024 }
2025
2026 /*******************************************************************
2027  Reads or writes an  LSA_R_LOOKUPPRIVVALUE structure.
2028 ********************************************************************/
2029
2030 BOOL lsa_io_r_lookupprivvalue(const char *desc, LSA_R_LOOKUPPRIVVALUE  *r_c, prs_struct *ps, int depth)
2031 {
2032         prs_debug(ps, depth, desc, "lsa_io_r_lookupprivvalue");
2033         depth++;
2034
2035         if(!prs_align(ps))
2036                 return False;
2037                 
2038         if(!lsa_io_luid("luid", &r_c->luid, ps, depth))
2039                 return False;
2040  
2041         if(!prs_ntstatus("status", ps, depth, &r_c->status))
2042                 return False;
2043
2044         return True;
2045 }
2046
2047
2048 /*******************************************************************
2049  Reads or writes an LSA_Q_ADDPRIVS structure.
2050 ********************************************************************/
2051
2052 BOOL lsa_io_q_addprivs(const char *desc, LSA_Q_ADDPRIVS *r_c, prs_struct *ps, int depth)
2053 {
2054         prs_debug(ps, depth, desc, "lsa_io_q_addprivs");
2055         depth++;
2056
2057         if(!prs_align(ps))
2058                 return False;
2059  
2060         if(!smb_io_pol_hnd("pol", &r_c->pol, ps, depth))
2061                 return False;
2062         
2063         if(!prs_uint32("count", ps, depth, &r_c->count))
2064                 return False;
2065
2066         if (UNMARSHALLING(ps) && r_c->count!=0) {
2067                 if (!NT_STATUS_IS_OK(privilege_set_init_by_ctx(ps->mem_ctx, &(r_c->set))))
2068                         return False;
2069                 
2070                 if (!(r_c->set.set = PRS_ALLOC_MEM(ps, LUID_ATTR, r_c->count)))
2071                         return False;
2072         }
2073         
2074         if(!lsa_io_privilege_set(desc, &r_c->set, ps, depth))
2075                 return False;
2076         
2077         return True;
2078 }
2079
2080 /*******************************************************************
2081  Reads or writes an LSA_R_ADDPRIVS structure.
2082 ********************************************************************/
2083
2084 BOOL lsa_io_r_addprivs(const char *desc, LSA_R_ADDPRIVS *r_c, prs_struct *ps, int depth)
2085 {
2086         prs_debug(ps, depth, desc, "lsa_io_r_addprivs");
2087         depth++;
2088
2089         if(!prs_align(ps))
2090                 return False;
2091  
2092         if(!prs_ntstatus("status", ps, depth, &r_c->status))
2093                 return False;
2094
2095         return True;
2096 }
2097
2098 /*******************************************************************
2099  Reads or writes an LSA_Q_REMOVEPRIVS structure.
2100 ********************************************************************/
2101
2102 BOOL lsa_io_q_removeprivs(const char *desc, LSA_Q_REMOVEPRIVS *r_c, prs_struct *ps, int depth)
2103 {
2104         prs_debug(ps, depth, desc, "lsa_io_q_removeprivs");
2105         depth++;
2106
2107         if(!prs_align(ps))
2108                 return False;
2109  
2110         if(!smb_io_pol_hnd("pol", &r_c->pol, ps, depth))
2111                 return False;
2112         
2113         if(!prs_uint32("allrights", ps, depth, &r_c->allrights))
2114                 return False;
2115
2116         if(!prs_uint32("ptr", ps, depth, &r_c->ptr))
2117                 return False;
2118
2119         /* 
2120          * JFM: I'm not sure at all if the count is inside the ptr
2121          * never seen one with ptr=0
2122          */
2123
2124         if (r_c->ptr!=0) {
2125                 if(!prs_uint32("count", ps, depth, &r_c->count))
2126                         return False;
2127
2128                 if (UNMARSHALLING(ps) && r_c->count!=0) {
2129                         if (!NT_STATUS_IS_OK(privilege_set_init_by_ctx(ps->mem_ctx, &(r_c->set))))
2130                                 return False;
2131
2132                         if (!(r_c->set.set = PRS_ALLOC_MEM(ps, LUID_ATTR, r_c->count)))
2133                                 return False;
2134                 }
2135
2136                 if(!lsa_io_privilege_set(desc, &r_c->set, ps, depth))
2137                         return False;
2138         }
2139
2140         return True;
2141 }
2142
2143 /*******************************************************************
2144  Reads or writes an LSA_R_REMOVEPRIVS structure.
2145 ********************************************************************/
2146
2147 BOOL lsa_io_r_removeprivs(const char *desc, LSA_R_REMOVEPRIVS *r_c, prs_struct *ps, int depth)
2148 {
2149         prs_debug(ps, depth, desc, "lsa_io_r_removeprivs");
2150         depth++;
2151
2152         if(!prs_align(ps))
2153                 return False;
2154  
2155         if(!prs_ntstatus("status", ps, depth, &r_c->status))
2156                 return False;
2157
2158         return True;
2159 }
2160
2161 BOOL policy_handle_is_valid(const POLICY_HND *hnd)
2162 {
2163         POLICY_HND zero_pol;
2164
2165         ZERO_STRUCT(zero_pol);
2166         return ((memcmp(&zero_pol, hnd, sizeof(POLICY_HND)) == 0) ? False : True );
2167 }
2168
2169 /*******************************************************************
2170  Reads or writes an LSA_DNS_DOM_INFO structure.
2171 ********************************************************************/
2172
2173 BOOL lsa_io_dns_dom_info(const char *desc, LSA_DNS_DOM_INFO *info,
2174                          prs_struct *ps, int depth)
2175 {
2176         prs_debug(ps, depth, desc, "lsa_io_dns_dom_info");
2177         depth++;
2178
2179         if(!prs_align(ps))
2180                 return False;
2181         if(!smb_io_unihdr("nb_name", &info->hdr_nb_dom_name, ps, depth))
2182                 return False;
2183         if(!smb_io_unihdr("dns_name", &info->hdr_dns_dom_name, ps, depth))
2184                 return False;
2185         if(!smb_io_unihdr("forest", &info->hdr_forest_name, ps, depth))
2186                 return False;
2187
2188         if(!prs_align(ps))
2189                 return False;
2190         if ( !smb_io_uuid("dom_guid", &info->dom_guid, ps, depth) )
2191                 return False;
2192
2193         if(!prs_align(ps))
2194                 return False;
2195         if(!prs_uint32("dom_sid", ps, depth, &info->ptr_dom_sid))
2196                 return False;
2197
2198         if(!smb_io_unistr2("nb_name", &info->uni_nb_dom_name,
2199                            info->hdr_nb_dom_name.buffer, ps, depth))
2200                 return False;
2201         if(!smb_io_unistr2("dns_name", &info->uni_dns_dom_name, 
2202                            info->hdr_dns_dom_name.buffer, ps, depth))
2203                 return False;
2204         if(!smb_io_unistr2("forest", &info->uni_forest_name, 
2205                            info->hdr_forest_name.buffer, ps, depth))
2206                 return False;
2207
2208         if(!smb_io_dom_sid2("dom_sid", &info->dom_sid, ps, depth))
2209                 return False;
2210
2211         return True;
2212         
2213 }
2214
2215 /*******************************************************************
2216  Inits an LSA_Q_QUERY_INFO2 structure.
2217 ********************************************************************/
2218
2219 void init_q_query2(LSA_Q_QUERY_INFO2 *q_q, POLICY_HND *hnd, uint16 info_class)
2220 {
2221         DEBUG(5, ("init_q_query2\n"));
2222
2223         memcpy(&q_q->pol, hnd, sizeof(q_q->pol));
2224
2225         q_q->info_class = info_class;
2226 }
2227
2228 /*******************************************************************
2229  Reads or writes an LSA_Q_QUERY_DNSDOMINFO structure.
2230 ********************************************************************/
2231
2232 BOOL lsa_io_q_query_info2(const char *desc, LSA_Q_QUERY_INFO2 *q_c,
2233                           prs_struct *ps, int depth)
2234 {
2235         prs_debug(ps, depth, desc, "lsa_io_q_query_info2");
2236         depth++;
2237
2238         if(!prs_align(ps))
2239                 return False;
2240  
2241         if(!smb_io_pol_hnd("pol", &q_c->pol, ps, depth))
2242                 return False;
2243         
2244         if(!prs_uint16("info_class", ps, depth, &q_c->info_class))
2245                 return False;
2246
2247         return True;
2248 }
2249
2250 /*******************************************************************
2251  Reads or writes an LSA_R_QUERY_DNSDOMINFO structure.
2252 ********************************************************************/
2253
2254 BOOL lsa_io_r_query_info2(const char *desc, LSA_R_QUERY_INFO2 *r_c,
2255                           prs_struct *ps, int depth)
2256 {
2257         prs_debug(ps, depth, desc, "lsa_io_r_query_info2");
2258         depth++;
2259
2260         if(!prs_align(ps))
2261                 return False;
2262
2263         if(!prs_uint32("ptr", ps, depth, &r_c->ptr))
2264                 return False;
2265         if(!prs_uint16("info_class", ps, depth, &r_c->info_class))
2266                 return False;
2267         switch(r_c->info_class) {
2268         case 0x000c:
2269                 if (!lsa_io_dns_dom_info("info12", &r_c->info.dns_dom_info,
2270                                          ps, depth))
2271                         return False;
2272                 break;
2273         default:
2274                 DEBUG(0,("lsa_io_r_query_info2: unknown info class %d\n",
2275                          r_c->info_class));
2276                 return False;
2277         }
2278
2279         if(!prs_align(ps))
2280                 return False;
2281         if(!prs_ntstatus("status", ps, depth, &r_c->status))
2282                 return False;
2283
2284         return True;
2285 }
2286
2287
2288 /*******************************************************************
2289  Inits an LSA_Q_ENUM_ACCT_RIGHTS structure.
2290 ********************************************************************/
2291 void init_q_enum_acct_rights(LSA_Q_ENUM_ACCT_RIGHTS *q_q, 
2292                              POLICY_HND *hnd, 
2293                              uint32 count, 
2294                              DOM_SID *sid)
2295 {
2296         DEBUG(5, ("init_q_enum_acct_rights\n"));
2297
2298         q_q->pol = *hnd;
2299         init_dom_sid2(&q_q->sid, sid);
2300 }
2301
2302 /*******************************************************************
2303 ********************************************************************/
2304 NTSTATUS init_r_enum_acct_rights( LSA_R_ENUM_ACCT_RIGHTS *r_u, PRIVILEGE_SET *privileges )
2305 {
2306         uint32 i;
2307         char *privname;
2308         const char **privname_array = NULL;
2309         int num_priv = 0;
2310
2311         for ( i=0; i<privileges->count; i++ ) {
2312                 privname = luid_to_privilege_name( &privileges->set[i].luid );
2313                 if ( privname ) {
2314                         if ( !add_string_to_array( get_talloc_ctx(), privname, &privname_array, &num_priv ) ) 
2315                                 return NT_STATUS_NO_MEMORY;
2316                 }
2317         }
2318
2319         if ( num_priv ) {
2320                 if ( !init_unistr2_array( &r_u->rights, num_priv, privname_array ) ) 
2321                         return NT_STATUS_NO_MEMORY;
2322
2323                 r_u->count = num_priv;
2324         }
2325
2326         return NT_STATUS_OK;
2327 }
2328
2329 /*******************************************************************
2330 reads or writes a LSA_Q_ENUM_ACCT_RIGHTS structure.
2331 ********************************************************************/
2332 BOOL lsa_io_q_enum_acct_rights(const char *desc, LSA_Q_ENUM_ACCT_RIGHTS *q_q, prs_struct *ps, int depth)
2333 {
2334         
2335         if (q_q == NULL)
2336                 return False;
2337
2338         prs_debug(ps, depth, desc, "lsa_io_q_enum_acct_rights");
2339         depth++;
2340
2341         if (!smb_io_pol_hnd("", &q_q->pol, ps, depth))
2342                 return False;
2343
2344         if(!smb_io_dom_sid2("sid", &q_q->sid, ps, depth))
2345                 return False;
2346
2347         return True;
2348 }
2349
2350
2351 /*******************************************************************
2352 reads or writes a LSA_R_ENUM_ACCT_RIGHTS structure.
2353 ********************************************************************/
2354 BOOL lsa_io_r_enum_acct_rights(const char *desc, LSA_R_ENUM_ACCT_RIGHTS *r_c, prs_struct *ps, int depth)
2355 {
2356         prs_debug(ps, depth, desc, "lsa_io_r_enum_acct_rights");
2357         depth++;
2358
2359         if(!prs_uint32("count   ", ps, depth, &r_c->count))
2360                 return False;
2361
2362         if(!smb_io_unistr2_array("rights", &r_c->rights, ps, depth))
2363                 return False;
2364
2365         if(!prs_align(ps))
2366                 return False;
2367
2368         if(!prs_ntstatus("status", ps, depth, &r_c->status))
2369                 return False;
2370
2371         return True;
2372 }
2373
2374
2375 /*******************************************************************
2376  Inits an LSA_Q_ADD_ACCT_RIGHTS structure.
2377 ********************************************************************/
2378 void init_q_add_acct_rights(LSA_Q_ADD_ACCT_RIGHTS *q_q, 
2379                             POLICY_HND *hnd, 
2380                             DOM_SID *sid,
2381                             uint32 count, 
2382                             const char **rights)
2383 {
2384         DEBUG(5, ("init_q_add_acct_rights\n"));
2385
2386         q_q->pol = *hnd;
2387         init_dom_sid2(&q_q->sid, sid);
2388         init_unistr2_array(&q_q->rights, count, rights);
2389         q_q->count = count;
2390 }
2391
2392
2393 /*******************************************************************
2394 reads or writes a LSA_Q_ADD_ACCT_RIGHTS structure.
2395 ********************************************************************/
2396 BOOL lsa_io_q_add_acct_rights(const char *desc, LSA_Q_ADD_ACCT_RIGHTS *q_q, prs_struct *ps, int depth)
2397 {
2398         prs_debug(ps, depth, desc, "lsa_io_q_add_acct_rights");
2399         depth++;
2400
2401         if (!smb_io_pol_hnd("", &q_q->pol, ps, depth))
2402                 return False;
2403
2404         if(!smb_io_dom_sid2("sid", &q_q->sid, ps, depth))
2405                 return False;
2406
2407         if(!prs_uint32("count", ps, depth, &q_q->count))
2408                 return False;
2409
2410         if(!smb_io_unistr2_array("rights", &q_q->rights, ps, depth))
2411                 return False;
2412
2413         return True;
2414 }
2415
2416 /*******************************************************************
2417 reads or writes a LSA_R_ENUM_ACCT_RIGHTS structure.
2418 ********************************************************************/
2419 BOOL lsa_io_r_add_acct_rights(const char *desc, LSA_R_ADD_ACCT_RIGHTS *r_c, prs_struct *ps, int depth)
2420 {
2421         prs_debug(ps, depth, desc, "lsa_io_r_add_acct_rights");
2422         depth++;
2423
2424         if(!prs_ntstatus("status", ps, depth, &r_c->status))
2425                 return False;
2426
2427         return True;
2428 }
2429
2430
2431 /*******************************************************************
2432  Inits an LSA_Q_REMOVE_ACCT_RIGHTS structure.
2433 ********************************************************************/
2434 void init_q_remove_acct_rights(LSA_Q_REMOVE_ACCT_RIGHTS *q_q, 
2435                                POLICY_HND *hnd, 
2436                                DOM_SID *sid,
2437                                uint32 removeall,
2438                                uint32 count, 
2439                                const char **rights)
2440 {
2441         DEBUG(5, ("init_q_remove_acct_rights\n"));
2442
2443         q_q->pol = *hnd;
2444         init_dom_sid2(&q_q->sid, sid);
2445         q_q->removeall = removeall;
2446         init_unistr2_array(&q_q->rights, count, rights);
2447         q_q->count = count;
2448 }
2449
2450
2451 /*******************************************************************
2452 reads or writes a LSA_Q_REMOVE_ACCT_RIGHTS structure.
2453 ********************************************************************/
2454 BOOL lsa_io_q_remove_acct_rights(const char *desc, LSA_Q_REMOVE_ACCT_RIGHTS *q_q, prs_struct *ps, int depth)
2455 {
2456         prs_debug(ps, depth, desc, "lsa_io_q_remove_acct_rights");
2457         depth++;
2458
2459         if (!smb_io_pol_hnd("", &q_q->pol, ps, depth))
2460                 return False;
2461
2462         if(!smb_io_dom_sid2("sid", &q_q->sid, ps, depth))
2463                 return False;
2464
2465         if(!prs_uint32("removeall", ps, depth, &q_q->removeall))
2466                 return False;
2467
2468         if(!prs_uint32("count", ps, depth, &q_q->count))
2469                 return False;
2470
2471         if(!smb_io_unistr2_array("rights", &q_q->rights, ps, depth))
2472                 return False;
2473
2474         return True;
2475 }
2476
2477 /*******************************************************************
2478 reads or writes a LSA_R_ENUM_ACCT_RIGHTS structure.
2479 ********************************************************************/
2480 BOOL lsa_io_r_remove_acct_rights(const char *desc, LSA_R_REMOVE_ACCT_RIGHTS *r_c, prs_struct *ps, int depth)
2481 {
2482         prs_debug(ps, depth, desc, "lsa_io_r_remove_acct_rights");
2483         depth++;
2484
2485         if(!prs_ntstatus("status", ps, depth, &r_c->status))
2486                 return False;
2487
2488         return True;
2489 }