ddae4bbdff9c4c081b00a7058a4b6cd2312034f1
[samba.git] / source3 / rpc_parse / parse_samr.c
1 /* 
2  *  Unix SMB/CIFS implementation.
3  *  RPC Pipe client / server routines
4  *  Copyright (C) Andrew Tridgell              1992-2000,
5  *  Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
6  *  Copyright (C) Paul Ashton                  1997-2000,
7  *  Copyright (C) Elrond                            2000,
8  *  Copyright (C) Jeremy Allison                    2001,
9  *  Copyright (C) Jean François Micouleau      1998-2001,
10  *  Copyright (C) Jim McDonough <jmcd@us.ibm.com>   2002.
11  *  
12  *  This program is free software; you can redistribute it and/or modify
13  *  it under the terms of the GNU General Public License as published by
14  *  the Free Software Foundation; either version 2 of the License, or
15  *  (at your option) any later version.
16  *  
17  *  This program is distributed in the hope that it will be useful,
18  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  *  GNU General Public License for more details.
21  *  
22  *  You should have received a copy of the GNU General Public License
23  *  along with this program; if not, write to the Free Software
24  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25  */
26
27 #include "includes.h"
28 #include "rpc_parse.h"
29 #include "nterr.h"
30
31 #undef DBGC_CLASS
32 #define DBGC_CLASS DBGC_RPC_PARSE
33
34 /*******************************************************************
35 inits a SAMR_Q_CLOSE_HND structure.
36 ********************************************************************/
37
38 void init_samr_q_close_hnd(SAMR_Q_CLOSE_HND * q_c, POLICY_HND *hnd)
39 {
40         DEBUG(5, ("init_samr_q_close_hnd\n"));
41         
42         q_c->pol = *hnd;
43 }
44
45 /*******************************************************************
46 reads or writes a structure.
47 ********************************************************************/
48
49 BOOL samr_io_q_close_hnd(const char *desc, SAMR_Q_CLOSE_HND * q_u,
50                          prs_struct *ps, int depth)
51 {
52         if (q_u == NULL)
53                 return False;
54
55         prs_debug(ps, depth, desc, "samr_io_q_close_hnd");
56         depth++;
57
58         if(!prs_align(ps))
59                 return False;
60
61         return smb_io_pol_hnd("pol", &q_u->pol, ps, depth);
62 }
63
64 /*******************************************************************
65 reads or writes a structure.
66 ********************************************************************/
67
68 BOOL samr_io_r_close_hnd(const char *desc, SAMR_R_CLOSE_HND * r_u,
69                          prs_struct *ps, int depth)
70 {
71         if (r_u == NULL)
72                 return False;
73
74         prs_debug(ps, depth, desc, "samr_io_r_close_hnd");
75         depth++;
76
77         if(!prs_align(ps))
78                 return False;
79
80         if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
81                 return False;
82
83         if(!prs_ntstatus("status", ps, depth, &r_u->status))
84                 return False;
85
86         return True;
87 }
88
89 /*******************************************************************
90 inits a SAMR_Q_LOOKUP_DOMAIN structure.
91 ********************************************************************/
92
93 void init_samr_q_lookup_domain(SAMR_Q_LOOKUP_DOMAIN * q_u,
94                                POLICY_HND *pol, char *dom_name)
95 {
96         DEBUG(5, ("init_samr_q_lookup_domain\n"));
97
98         q_u->connect_pol = *pol;
99
100         init_unistr2(&q_u->uni_domain, dom_name, UNI_FLAGS_NONE);
101         init_uni_hdr(&q_u->hdr_domain, &q_u->uni_domain);
102 }
103
104 /*******************************************************************
105 reads or writes a structure.
106 ********************************************************************/
107 BOOL samr_io_q_lookup_domain(const char *desc, SAMR_Q_LOOKUP_DOMAIN * q_u,
108                              prs_struct *ps, int depth)
109 {
110         if (q_u == NULL)
111                 return False;
112
113         prs_debug(ps, depth, desc, "samr_io_q_lookup_domain");
114         depth++;
115
116         if(!prs_align(ps))
117                 return False;
118
119         if(!smb_io_pol_hnd("connect_pol", &q_u->connect_pol, ps, depth))
120                 return False;
121
122         if(!smb_io_unihdr("hdr_domain", &q_u->hdr_domain, ps, depth))
123                 return False;
124
125         if(!smb_io_unistr2("uni_domain", &q_u->uni_domain, q_u->hdr_domain.buffer, ps, depth))
126                 return False;
127
128         return True;
129 }
130
131 /*******************************************************************
132 inits a SAMR_R_LOOKUP_DOMAIN structure.
133 ********************************************************************/
134
135 void init_samr_r_lookup_domain(SAMR_R_LOOKUP_DOMAIN * r_u,
136                                DOM_SID *dom_sid, NTSTATUS status)
137 {
138         DEBUG(5, ("init_samr_r_lookup_domain\n"));
139
140         r_u->status = status;
141         r_u->ptr_sid = 0;
142         if (NT_STATUS_IS_OK(status)) {
143                 r_u->ptr_sid = 1;
144                 init_dom_sid2(&r_u->dom_sid, dom_sid);
145         }
146 }
147
148 /*******************************************************************
149 reads or writes a structure.
150 ********************************************************************/
151
152 BOOL samr_io_r_lookup_domain(const char *desc, SAMR_R_LOOKUP_DOMAIN * r_u,
153                              prs_struct *ps, int depth)
154 {
155         if (r_u == NULL)
156                 return False;
157
158         prs_debug(ps, depth, desc, "samr_io_r_lookup_domain");
159         depth++;
160
161         if(!prs_align(ps))
162                 return False;
163
164         if(!prs_uint32("ptr", ps, depth, &r_u->ptr_sid))
165                 return False;
166
167         if (r_u->ptr_sid != 0) {
168                 if(!smb_io_dom_sid2("sid", &r_u->dom_sid, ps, depth))
169                         return False;
170                 if(!prs_align(ps))
171                         return False;
172         }
173
174         if(!prs_ntstatus("status", ps, depth, &r_u->status))
175                 return False;
176
177         return True;
178 }
179
180 /*******************************************************************
181 reads or writes a structure.
182 ********************************************************************/
183
184 void init_samr_q_remove_sid_foreign_domain(SAMR_Q_REMOVE_SID_FOREIGN_DOMAIN * q_u, POLICY_HND *dom_pol, DOM_SID *sid)
185 {
186         DEBUG(5, ("samr_init_samr_q_remove_sid_foreign_domain\n"));
187
188         q_u->dom_pol = *dom_pol;
189         init_dom_sid2(&q_u->sid, sid);
190 }
191
192 /*******************************************************************
193 reads or writes a structure.
194 ********************************************************************/
195
196 BOOL samr_io_q_remove_sid_foreign_domain(const char *desc, SAMR_Q_REMOVE_SID_FOREIGN_DOMAIN * q_u,
197                           prs_struct *ps, int depth)
198 {
199         if (q_u == NULL)
200                 return False;
201
202         prs_debug(ps, depth, desc, "samr_io_q_remove_sid_foreign_domain");
203         depth++;
204
205         if(!prs_align(ps))
206                 return False;
207
208         if(!smb_io_pol_hnd("domain_pol", &q_u->dom_pol, ps, depth))
209                 return False;
210
211         if(!smb_io_dom_sid2("sid", &q_u->sid, ps, depth))
212                 return False;
213
214         if(!prs_align(ps))
215                 return False;
216
217         return True;
218 }
219
220 /*******************************************************************
221 reads or writes a structure.
222 ********************************************************************/
223
224 BOOL samr_io_r_remove_sid_foreign_domain(const char *desc, SAMR_R_REMOVE_SID_FOREIGN_DOMAIN * r_u,
225                           prs_struct *ps, int depth)
226 {
227         if (r_u == NULL)
228                 return False;
229
230         prs_debug(ps, depth, desc, "samr_io_r_remove_sid_foreign_domain");
231         depth++;
232
233         if(!prs_align(ps))
234                 return False;
235
236         if(!prs_ntstatus("status", ps, depth, &r_u->status))
237                 return False;
238
239         return True;
240 }
241
242 /*******************************************************************
243 reads or writes a structure.
244 ********************************************************************/
245
246 void init_samr_q_open_domain(SAMR_Q_OPEN_DOMAIN * q_u,
247                              POLICY_HND *pol, uint32 flags,
248                              const DOM_SID *sid)
249 {
250         DEBUG(5, ("samr_init_samr_q_open_domain\n"));
251
252         q_u->pol = *pol;
253         q_u->flags = flags;
254         init_dom_sid2(&q_u->dom_sid, sid);
255 }
256
257 /*******************************************************************
258 reads or writes a structure.
259 ********************************************************************/
260
261 BOOL samr_io_q_open_domain(const char *desc, SAMR_Q_OPEN_DOMAIN * q_u,
262                            prs_struct *ps, int depth)
263 {
264         if (q_u == NULL)
265                 return False;
266
267         prs_debug(ps, depth, desc, "samr_io_q_open_domain");
268         depth++;
269
270         if(!prs_align(ps))
271                 return False;
272
273         if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
274                 return False;
275
276         if(!prs_uint32("flags", ps, depth, &q_u->flags))
277                 return False;
278
279         if(!smb_io_dom_sid2("sid", &q_u->dom_sid, ps, depth))
280                 return False;
281
282         return True;
283 }
284
285 /*******************************************************************
286 reads or writes a structure.
287 ********************************************************************/
288
289 BOOL samr_io_r_open_domain(const char *desc, SAMR_R_OPEN_DOMAIN * r_u,
290                            prs_struct *ps, int depth)
291 {
292         if (r_u == NULL)
293                 return False;
294
295         prs_debug(ps, depth, desc, "samr_io_r_open_domain");
296         depth++;
297
298         if(!prs_align(ps))
299                 return False;
300
301         if(!smb_io_pol_hnd("domain_pol", &r_u->domain_pol, ps, depth))
302                 return False;
303
304         if(!prs_ntstatus("status", ps, depth, &r_u->status))
305                 return False;
306
307         return True;
308 }
309
310 /*******************************************************************
311 reads or writes a structure.
312 ********************************************************************/
313
314 void init_samr_q_get_usrdom_pwinfo(SAMR_Q_GET_USRDOM_PWINFO * q_u,
315                                    POLICY_HND *user_pol)
316 {
317         DEBUG(5, ("samr_init_samr_q_get_usrdom_pwinfo\n"));
318
319         q_u->user_pol = *user_pol;
320 }
321
322 /*******************************************************************
323 reads or writes a structure.
324 ********************************************************************/
325
326 BOOL samr_io_q_get_usrdom_pwinfo(const char *desc, SAMR_Q_GET_USRDOM_PWINFO * q_u,
327                                  prs_struct *ps, int depth)
328 {
329         if (q_u == NULL)
330                 return False;
331
332         prs_debug(ps, depth, desc, "samr_io_q_get_usrdom_pwinfo");
333         depth++;
334
335         if(!prs_align(ps))
336                 return False;
337
338         return smb_io_pol_hnd("user_pol", &q_u->user_pol, ps, depth);
339 }
340
341 /*******************************************************************
342  Init.
343 ********************************************************************/
344
345 void init_samr_r_get_usrdom_pwinfo(SAMR_R_GET_USRDOM_PWINFO *r_u, NTSTATUS status)
346 {
347         DEBUG(5, ("init_samr_r_get_usrdom_pwinfo\n"));
348         
349         r_u->unknown_0 = 0x0000;
350
351         /*
352          * used to be   
353          * r_u->unknown_1 = 0x0015;
354          * but for trusts.
355          */
356         r_u->unknown_1 = 0x01D1;
357         r_u->unknown_1 = 0x0015;
358
359         r_u->unknown_2 = 0x00000000;
360
361         r_u->status = status;
362 }
363
364 /*******************************************************************
365 reads or writes a structure.
366 ********************************************************************/
367
368 BOOL samr_io_r_get_usrdom_pwinfo(const char *desc, SAMR_R_GET_USRDOM_PWINFO * r_u,
369                                  prs_struct *ps, int depth)
370 {
371         if (r_u == NULL)
372                 return False;
373
374         prs_debug(ps, depth, desc, "samr_io_r_get_usrdom_pwinfo");
375         depth++;
376
377         if(!prs_align(ps))
378                 return False;
379
380         if(!prs_uint16("unknown_0", ps, depth, &r_u->unknown_0))
381                 return False;
382         if(!prs_uint16("unknown_1", ps, depth, &r_u->unknown_1))
383                 return False;
384         if(!prs_uint32("unknown_2", ps, depth, &r_u->unknown_2))
385                 return False;
386         if(!prs_ntstatus("status   ", ps, depth, &r_u->status))
387                 return False;
388
389         return True;
390 }
391
392
393 /*******************************************************************
394 reads or writes a structure.
395 ********************************************************************/
396
397 BOOL samr_io_q_set_sec_obj(const char *desc, SAMR_Q_SET_SEC_OBJ * q_u,
398                              prs_struct *ps, int depth)
399 {
400         if (q_u == NULL)
401                 return False;
402
403         prs_debug(ps, depth, desc, "samr_io_q_set_sec_obj");
404         depth++;
405
406         if(!prs_align(ps))
407                 return False;
408
409         if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
410                 return False;
411
412         if(!prs_uint32("sec_info", ps, depth, &q_u->sec_info))
413                 return False;
414                 
415         if(!sec_io_desc_buf("sec_desc", &q_u->buf, ps, depth))
416                 return False;
417         
418         return True;
419 }
420
421
422 /*******************************************************************
423 reads or writes a structure.
424 ********************************************************************/
425
426 void init_samr_q_query_sec_obj(SAMR_Q_QUERY_SEC_OBJ * q_u,
427                                POLICY_HND *user_pol, uint32 sec_info)
428 {
429         DEBUG(5, ("samr_init_samr_q_query_sec_obj\n"));
430
431         q_u->user_pol = *user_pol;
432         q_u->sec_info = sec_info;
433 }
434
435
436 /*******************************************************************
437 reads or writes a structure.
438 ********************************************************************/
439
440 BOOL samr_io_q_query_sec_obj(const char *desc, SAMR_Q_QUERY_SEC_OBJ * q_u,
441                              prs_struct *ps, int depth)
442 {
443         if (q_u == NULL)
444                 return False;
445
446         prs_debug(ps, depth, desc, "samr_io_q_query_sec_obj");
447         depth++;
448
449         if(!prs_align(ps))
450                 return False;
451
452         if(!smb_io_pol_hnd("user_pol", &q_u->user_pol, ps, depth))
453                 return False;
454
455         if(!prs_uint32("sec_info", ps, depth, &q_u->sec_info))
456                 return False;
457
458         return True;
459 }
460
461 /*******************************************************************
462 reads or writes a structure.
463 ********************************************************************/
464
465 void init_samr_q_query_dom_info(SAMR_Q_QUERY_DOMAIN_INFO * q_u,
466                                 POLICY_HND *domain_pol, uint16 switch_value)
467 {
468         DEBUG(5, ("samr_init_samr_q_query_dom_info\n"));
469
470         q_u->domain_pol = *domain_pol;
471         q_u->switch_value = switch_value;
472 }
473
474 /*******************************************************************
475 reads or writes a structure.
476 ********************************************************************/
477
478 BOOL samr_io_q_query_dom_info(const char *desc, SAMR_Q_QUERY_DOMAIN_INFO * q_u,
479                               prs_struct *ps, int depth)
480 {
481         if (q_u == NULL)
482                 return False;
483
484         prs_debug(ps, depth, desc, "samr_io_q_query_dom_info");
485         depth++;
486
487         if(!prs_align(ps))
488                 return False;
489
490         if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
491                 return False;
492
493         if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
494                 return False;
495
496         return True;
497 }
498
499
500 /*******************************************************************
501 inits a structure.
502 ********************************************************************/
503
504 void init_unk_info3(SAM_UNK_INFO_3 *u_3, NTTIME nt_logout)
505 {
506         u_3->logout.low = nt_logout.low;
507         u_3->logout.high = nt_logout.high;
508 }
509
510 /*******************************************************************
511 reads or writes a structure.
512 ********************************************************************/
513
514 static BOOL sam_io_unk_info3(const char *desc, SAM_UNK_INFO_3 * u_3,
515                              prs_struct *ps, int depth)
516 {
517         if (u_3 == NULL)
518                 return False;
519
520         prs_debug(ps, depth, desc, "sam_io_unk_info3");
521         depth++;
522
523         if(!smb_io_time("logout", &u_3->logout, ps, depth))
524                 return False;
525
526         return True;
527 }
528
529 /*******************************************************************
530 inits a structure.
531 ********************************************************************/
532
533 void init_unk_info6(SAM_UNK_INFO_6 * u_6)
534 {
535         u_6->unknown_0 = 0x00000000;
536         u_6->ptr_0 = 1;
537         memset(u_6->padding, 0, sizeof(u_6->padding));  /* 12 bytes zeros */
538 }
539
540 /*******************************************************************
541 reads or writes a structure.
542 ********************************************************************/
543
544 static BOOL sam_io_unk_info6(const char *desc, SAM_UNK_INFO_6 * u_6,
545                              prs_struct *ps, int depth)
546 {
547         if (u_6 == NULL)
548                 return False;
549
550         prs_debug(ps, depth, desc, "sam_io_unk_info6");
551         depth++;
552
553         if(!prs_uint32("unknown_0", ps, depth, &u_6->unknown_0)) /* 0x0000 0000 */
554                 return False;
555         if(!prs_uint32("ptr_0", ps, depth, &u_6->ptr_0)) /* pointer to unknown structure */
556                 return False;
557         if(!prs_uint8s(False, "padding", ps, depth, u_6->padding, sizeof(u_6->padding)))        /* 12 bytes zeros */
558                 return False;
559
560         return True;
561 }
562
563 /*******************************************************************
564 inits a structure.
565 ********************************************************************/
566
567 void init_unk_info7(SAM_UNK_INFO_7 * u_7)
568 {
569         u_7->unknown_0 = 0x0003;
570 }
571
572 /*******************************************************************
573 reads or writes a structure.
574 ********************************************************************/
575
576 static BOOL sam_io_unk_info7(const char *desc, SAM_UNK_INFO_7 * u_7,
577                              prs_struct *ps, int depth)
578 {
579         if (u_7 == NULL)
580                 return False;
581
582         prs_debug(ps, depth, desc, "sam_io_unk_info7");
583         depth++;
584
585         if(!prs_uint16("unknown_0", ps, depth, &u_7->unknown_0)) /* 0x0003 */
586                 return False;
587
588         return True;
589 }
590
591 /*******************************************************************
592 inits a structure.
593 ********************************************************************/
594
595 void init_unk_info12(SAM_UNK_INFO_12 * u_12, NTTIME nt_lock_duration, NTTIME nt_reset_time, uint16 lockout)
596 {
597         u_12->duration.low = nt_lock_duration.low;
598         u_12->duration.high = nt_lock_duration.high;
599         u_12->reset_count.low = nt_reset_time.low;
600         u_12->reset_count.high = nt_reset_time.high;
601
602         u_12->bad_attempt_lockout = lockout;
603 }
604
605 /*******************************************************************
606 reads or writes a structure.
607 ********************************************************************/
608
609 static BOOL sam_io_unk_info12(const char *desc, SAM_UNK_INFO_12 * u_12,
610                               prs_struct *ps, int depth)
611 {
612         if (u_12 == NULL)
613                 return False;
614
615         prs_debug(ps, depth, desc, "sam_io_unk_info12");
616         depth++;
617
618         if(!smb_io_time("duration", &u_12->duration, ps, depth))
619                 return False;
620         if(!smb_io_time("reset_count", &u_12->reset_count, ps, depth))
621                 return False;
622         if(!prs_uint16("bad_attempt_lockout", ps, depth, &u_12->bad_attempt_lockout))
623                 return False;
624
625         return True;
626 }
627
628 /*******************************************************************
629 inits a structure.
630 ********************************************************************/
631
632 void init_unk_info5(SAM_UNK_INFO_5 * u_5,const char *server)
633 {
634         init_unistr2(&u_5->uni_server, server, UNI_FLAGS_NONE);
635         init_uni_hdr(&u_5->hdr_server, &u_5->uni_server);
636 }
637
638 /*******************************************************************
639 reads or writes a structure.
640 ********************************************************************/
641
642 static BOOL sam_io_unk_info5(const char *desc, SAM_UNK_INFO_5 * u_5,
643                              prs_struct *ps, int depth)
644 {
645         if (u_5 == NULL)
646                 return False;
647
648         prs_debug(ps, depth, desc, "sam_io_unk_info5");
649         depth++;
650
651         if(!smb_io_unihdr("hdr_server", &u_5->hdr_server, ps, depth))
652                 return False;
653
654         if(!smb_io_unistr2("uni_server", &u_5->uni_server, u_5->hdr_server.buffer, ps, depth))
655                 return False;
656
657         return True;
658 }
659
660 /*******************************************************************
661 inits a structure.
662 ********************************************************************/
663
664 void init_unk_info2(SAM_UNK_INFO_2 * u_2,
665                         const char *domain, const char *server,
666                         uint32 seq_num, uint32 num_users, uint32 num_groups, uint32 num_alias)
667 {
668         u_2->unknown_0 = 0x00000000;
669         u_2->unknown_1 = 0x80000000;
670         u_2->unknown_2 = 0x00000000;
671
672         u_2->ptr_0 = 1;
673
674         u_2->seq_num = seq_num;
675         u_2->unknown_3 = 0x00000000;
676
677         u_2->unknown_4 = 0x00000001;
678         u_2->unknown_5 = 0x00000003;
679         u_2->unknown_6 = 0x00000001;
680         u_2->num_domain_usrs = num_users;
681         u_2->num_domain_grps = num_groups;
682         u_2->num_local_grps = num_alias;
683
684         memset(u_2->padding, 0, sizeof(u_2->padding));  /* 12 bytes zeros */
685
686         init_unistr2(&u_2->uni_domain, domain, UNI_FLAGS_NONE);
687         init_uni_hdr(&u_2->hdr_domain, &u_2->uni_domain);
688         init_unistr2(&u_2->uni_server, server, UNI_FLAGS_NONE);
689         init_uni_hdr(&u_2->hdr_server, &u_2->uni_server);
690 }
691
692 /*******************************************************************
693 reads or writes a structure.
694 ********************************************************************/
695
696 static BOOL sam_io_unk_info2(const char *desc, SAM_UNK_INFO_2 * u_2,
697                              prs_struct *ps, int depth)
698 {
699         if (u_2 == NULL)
700                 return False;
701
702         prs_debug(ps, depth, desc, "sam_io_unk_info2");
703         depth++;
704
705         if(!prs_uint32("unknown_0", ps, depth, &u_2->unknown_0)) /* 0x0000 0000 */
706                 return False;
707         if(!prs_uint32("unknown_1", ps, depth, &u_2->unknown_1)) /* 0x8000 0000 */
708                 return False;
709         if(!prs_uint32("unknown_2", ps, depth, &u_2->unknown_2))        /* 0x0000 0000 */
710                 return False;
711
712         if(!prs_uint32("ptr_0", ps, depth, &u_2->ptr_0))
713                 return False;
714         if(!smb_io_unihdr("hdr_domain", &u_2->hdr_domain, ps, depth))
715                 return False;
716         if(!smb_io_unihdr("hdr_server", &u_2->hdr_server, ps, depth))
717                 return False;
718
719         /* put all the data in here, at the moment, including what the above
720            pointer is referring to
721          */
722
723         if(!prs_uint32("seq_num ", ps, depth, &u_2->seq_num))   /* 0x0000 0099 or 0x1000 0000 */
724                 return False;
725         if(!prs_uint32("unknown_3 ", ps, depth, &u_2->unknown_3))       /* 0x0000 0000 */
726                 return False;
727
728         if(!prs_uint32("unknown_4 ", ps, depth, &u_2->unknown_4)) /* 0x0000 0001 */
729                 return False;
730         if(!prs_uint32("unknown_5 ", ps, depth, &u_2->unknown_5)) /* 0x0000 0003 */
731                 return False;
732         if(!prs_uint32("unknown_6 ", ps, depth, &u_2->unknown_6)) /* 0x0000 0001 */
733                 return False;
734         if(!prs_uint32("num_domain_usrs ", ps, depth, &u_2->num_domain_usrs))
735                 return False;
736         if(!prs_uint32("num_domain_grps", ps, depth, &u_2->num_domain_grps))
737                 return False;
738         if(!prs_uint32("num_local_grps", ps, depth, &u_2->num_local_grps))
739                 return False;
740
741         if (u_2->ptr_0) {
742                 /* this was originally marked as 'padding'. It isn't
743                    padding, it is some sort of optional 12 byte
744                    structure. When it is present it contains zeros
745                    !? */
746                 if(!prs_uint8s(False, "unknown", ps, depth, u_2->padding,sizeof(u_2->padding)))
747                         return False;
748         }
749
750         if(!smb_io_unistr2("uni_domain", &u_2->uni_domain, u_2->hdr_domain.buffer, ps, depth))
751                 return False;
752         if(!smb_io_unistr2("uni_server", &u_2->uni_server, u_2->hdr_server.buffer, ps, depth))
753                 return False;
754
755         return True;
756 }
757
758 /*******************************************************************
759 inits a structure.
760 ********************************************************************/
761
762 void init_unk_info1(SAM_UNK_INFO_1 *u_1, uint16 min_pass_len, uint16 pass_hist, 
763                     uint32 flag, NTTIME nt_expire, NTTIME nt_min_age)
764 {
765         u_1->min_length_password = min_pass_len;
766         u_1->password_history = pass_hist;
767         u_1->flag = flag;
768         
769         /* password never expire */
770         u_1->expire.high = nt_expire.high;
771         u_1->expire.low = nt_expire.low;
772         
773         /* can change the password now */
774         u_1->min_passwordage.high = nt_min_age.high;
775         u_1->min_passwordage.low = nt_min_age.low;
776         
777 }
778
779 /*******************************************************************
780 reads or writes a structure.
781 ********************************************************************/
782
783 static BOOL sam_io_unk_info1(const char *desc, SAM_UNK_INFO_1 * u_1,
784                              prs_struct *ps, int depth)
785 {
786         if (u_1 == NULL)
787           return False;
788
789         prs_debug(ps, depth, desc, "sam_io_unk_info1");
790         depth++;
791
792         if(!prs_uint16("min_length_password", ps, depth, &u_1->min_length_password))
793                 return False;
794         if(!prs_uint16("password_history", ps, depth, &u_1->password_history))
795                 return False;
796         if(!prs_uint32("flag", ps, depth, &u_1->flag))
797                 return False;
798         if(!smb_io_time("expire", &u_1->expire, ps, depth))
799                 return False;
800         if(!smb_io_time("min_passwordage", &u_1->min_passwordage, ps, depth))
801                 return False;
802
803         return True;
804 }
805
806 /*******************************************************************
807 inits a SAMR_R_QUERY_DOMAIN_INFO structure.
808 ********************************************************************/
809
810 void init_samr_r_query_dom_info(SAMR_R_QUERY_DOMAIN_INFO * r_u,
811                                 uint16 switch_value, SAM_UNK_CTR * ctr,
812                                 NTSTATUS status)
813 {
814         DEBUG(5, ("init_samr_r_query_dom_info\n"));
815
816         r_u->ptr_0 = 0;
817         r_u->switch_value = 0;
818         r_u->status = status;   /* return status */
819
820         if (NT_STATUS_IS_OK(status)) {
821                 r_u->switch_value = switch_value;
822                 r_u->ptr_0 = 1;
823                 r_u->ctr = ctr;
824         }
825 }
826
827 /*******************************************************************
828 reads or writes a structure.
829 ********************************************************************/
830
831 BOOL samr_io_r_query_dom_info(const char *desc, SAMR_R_QUERY_DOMAIN_INFO * r_u,
832                               prs_struct *ps, int depth)
833 {
834         if (r_u == NULL)
835                 return False;
836
837         prs_debug(ps, depth, desc, "samr_io_r_query_dom_info");
838         depth++;
839
840         if(!prs_align(ps))
841                 return False;
842
843         if(!prs_uint32("ptr_0 ", ps, depth, &r_u->ptr_0))
844                 return False;
845
846         if (r_u->ptr_0 != 0 && r_u->ctr != NULL) {
847                 if(!prs_uint16("switch_value", ps, depth, &r_u->switch_value))
848                         return False;
849                 if(!prs_align(ps))
850                         return False;
851
852                 switch (r_u->switch_value) {
853                 case 0x0c:
854                         if(!sam_io_unk_info12("unk_inf12", &r_u->ctr->info.inf12, ps, depth))
855                                 return False;
856                         break;
857                 case 0x07:
858                         if(!sam_io_unk_info7("unk_inf7",&r_u->ctr->info.inf7, ps,depth))
859                                 return False;
860                         break;
861                 case 0x06:
862                         if(!sam_io_unk_info6("unk_inf6",&r_u->ctr->info.inf6, ps,depth))
863                                 return False;
864                         break;
865                 case 0x05:
866                         if(!sam_io_unk_info5("unk_inf5",&r_u->ctr->info.inf5, ps,depth))
867                                 return False;
868                         break;
869                 case 0x03:
870                         if(!sam_io_unk_info3("unk_inf3",&r_u->ctr->info.inf3, ps,depth))
871                                 return False;
872                         break;
873                 case 0x02:
874                         if(!sam_io_unk_info2("unk_inf2",&r_u->ctr->info.inf2, ps,depth))
875                                 return False;
876                         break;
877                 case 0x01:
878                         if(!sam_io_unk_info1("unk_inf1",&r_u->ctr->info.inf1, ps,depth))
879                                 return False;
880                         break;
881                 default:
882                         DEBUG(0, ("samr_io_r_query_dom_info: unknown switch level 0x%x\n",
883                                 r_u->switch_value));
884                         r_u->status = NT_STATUS_INVALID_INFO_CLASS;
885                         return False;
886                 }
887         }
888         
889         if(!prs_align(ps))
890                 return False;
891
892         if(!prs_ntstatus("status", ps, depth, &r_u->status))
893                 return False;
894         
895         return True;
896 }
897
898 /*******************************************************************
899 reads or writes a SAMR_R_SET_SEC_OBJ structure.
900 ********************************************************************/
901
902 BOOL samr_io_r_set_sec_obj(const char *desc, SAMR_R_SET_SEC_OBJ * r_u,
903                              prs_struct *ps, int depth)
904 {
905         if (r_u == NULL)
906                 return False;
907   
908         prs_debug(ps, depth, desc, "samr_io_r_set_sec_obj");
909         depth++;
910
911         if(!prs_align(ps))
912                 return False;
913
914         if(!prs_ntstatus("status", ps, depth, &r_u->status))
915                 return False;
916
917         return True;
918 }
919
920 /*******************************************************************
921 reads or writes a SAMR_R_QUERY_SEC_OBJ structure.
922 ********************************************************************/
923
924 BOOL samr_io_r_query_sec_obj(const char *desc, SAMR_R_QUERY_SEC_OBJ * r_u,
925                              prs_struct *ps, int depth)
926 {
927         if (r_u == NULL)
928                 return False;
929   
930         prs_debug(ps, depth, desc, "samr_io_r_query_sec_obj");
931         depth++;
932
933         if(!prs_align(ps))
934                 return False;
935
936         if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
937                 return False;
938         if (r_u->ptr != 0) {
939                 if(!sec_io_desc_buf("sec", &r_u->buf, ps, depth))
940                         return False;
941         }
942
943         if(!prs_ntstatus("status", ps, depth, &r_u->status))
944                 return False;
945
946         return True;
947 }
948
949 /*******************************************************************
950 reads or writes a SAM_STR1 structure.
951 ********************************************************************/
952
953 static BOOL sam_io_sam_str1(const char *desc, SAM_STR1 * sam, uint32 acct_buf,
954                             uint32 name_buf, uint32 desc_buf,
955                             prs_struct *ps, int depth)
956 {
957         if (sam == NULL)
958                 return False;
959
960         prs_debug(ps, depth, desc, "sam_io_sam_str1");
961         depth++;
962
963         if(!prs_align(ps))
964                 return False;
965         if (!smb_io_unistr2("name", &sam->uni_acct_name, acct_buf, ps, depth))
966                 return False;
967
968         if (!smb_io_unistr2("desc", &sam->uni_acct_desc, desc_buf, ps, depth))
969                 return False;
970
971         if (!smb_io_unistr2("full", &sam->uni_full_name, name_buf, ps, depth))
972                 return False;
973
974         return True;
975 }
976
977 /*******************************************************************
978 inits a SAM_ENTRY1 structure.
979 ********************************************************************/
980
981 static void init_sam_entry1(SAM_ENTRY1 *sam, uint32 user_idx,
982                             UNISTR2 *sam_name, UNISTR2 *sam_full,
983                             UNISTR2 *sam_desc, uint32 rid_user,
984                             uint16 acb_info)
985 {
986         DEBUG(5, ("init_sam_entry1\n"));
987
988         ZERO_STRUCTP(sam);
989
990         sam->user_idx = user_idx;
991         sam->rid_user = rid_user;
992         sam->acb_info = acb_info;
993
994         init_uni_hdr(&sam->hdr_acct_name, sam_name);
995         init_uni_hdr(&sam->hdr_user_name, sam_full);
996         init_uni_hdr(&sam->hdr_user_desc, sam_desc);
997 }
998
999 /*******************************************************************
1000 reads or writes a SAM_ENTRY1 structure.
1001 ********************************************************************/
1002
1003 static BOOL sam_io_sam_entry1(const char *desc, SAM_ENTRY1 * sam,
1004                               prs_struct *ps, int depth)
1005 {
1006         if (sam == NULL)
1007                 return False;
1008
1009         prs_debug(ps, depth, desc, "sam_io_sam_entry1");
1010         depth++;
1011
1012         if(!prs_align(ps))
1013                 return False;
1014
1015         if(!prs_uint32("user_idx ", ps, depth, &sam->user_idx))
1016                 return False;
1017
1018         if(!prs_uint32("rid_user ", ps, depth, &sam->rid_user))
1019                 return False;
1020         if(!prs_uint16("acb_info ", ps, depth, &sam->acb_info))
1021                 return False;
1022
1023         if(!prs_align(ps))
1024                 return False;
1025
1026         if (!smb_io_unihdr("hdr_acct_name", &sam->hdr_acct_name, ps, depth))
1027                 return False;
1028         if (!smb_io_unihdr("hdr_user_desc", &sam->hdr_user_desc, ps, depth))
1029                 return False;
1030         if (!smb_io_unihdr("hdr_user_name", &sam->hdr_user_name, ps, depth))
1031                 return False;
1032
1033         return True;
1034 }
1035
1036 /*******************************************************************
1037 reads or writes a SAM_STR2 structure.
1038 ********************************************************************/
1039
1040 static BOOL sam_io_sam_str2(const char *desc, SAM_STR2 * sam, uint32 acct_buf,
1041                             uint32 desc_buf, prs_struct *ps, int depth)
1042 {
1043         if (sam == NULL)
1044                 return False;
1045
1046         prs_debug(ps, depth, desc, "sam_io_sam_str2");
1047         depth++;
1048
1049         if(!prs_align(ps))
1050                 return False;
1051
1052         if(!smb_io_unistr2("uni_srv_name", &sam->uni_srv_name, acct_buf, ps, depth)) /* account name unicode string */
1053                 return False;
1054         if(!smb_io_unistr2("uni_srv_desc", &sam->uni_srv_desc, desc_buf, ps, depth))    /* account desc unicode string */
1055                 return False;
1056
1057         return True;
1058 }
1059
1060 /*******************************************************************
1061 inits a SAM_ENTRY2 structure.
1062 ********************************************************************/
1063 static void init_sam_entry2(SAM_ENTRY2 * sam, uint32 user_idx,
1064                             UNISTR2 *sam_name, UNISTR2 *sam_desc,
1065                             uint32 rid_user, uint16 acb_info)
1066 {
1067         DEBUG(5, ("init_sam_entry2\n"));
1068
1069         sam->user_idx = user_idx;
1070         sam->rid_user = rid_user;
1071         sam->acb_info = acb_info;
1072
1073         init_uni_hdr(&sam->hdr_srv_name, sam_name);
1074         init_uni_hdr(&sam->hdr_srv_desc, sam_desc);
1075 }
1076
1077 /*******************************************************************
1078 reads or writes a SAM_ENTRY2 structure.
1079 ********************************************************************/
1080
1081 static BOOL sam_io_sam_entry2(const char *desc, SAM_ENTRY2 * sam,
1082                               prs_struct *ps, int depth)
1083 {
1084         if (sam == NULL)
1085                 return False;
1086
1087         prs_debug(ps, depth, desc, "sam_io_sam_entry2");
1088         depth++;
1089
1090         if(!prs_align(ps))
1091                 return False;
1092
1093         if(!prs_uint32("user_idx ", ps, depth, &sam->user_idx))
1094                 return False;
1095
1096         if(!prs_uint32("rid_user ", ps, depth, &sam->rid_user))
1097                 return False;
1098         if(!prs_uint16("acb_info ", ps, depth, &sam->acb_info))
1099                 return False;
1100
1101         if(!prs_align(ps))
1102                 return False;
1103
1104         if(!smb_io_unihdr("unihdr", &sam->hdr_srv_name, ps, depth))     /* account name unicode string header */
1105                 return False;
1106         if(!smb_io_unihdr("unihdr", &sam->hdr_srv_desc, ps, depth))     /* account name unicode string header */
1107                 return False;
1108
1109         return True;
1110 }
1111
1112 /*******************************************************************
1113 reads or writes a SAM_STR3 structure.
1114 ********************************************************************/
1115
1116 static BOOL sam_io_sam_str3(const char *desc, SAM_STR3 * sam, uint32 acct_buf,
1117                             uint32 desc_buf, prs_struct *ps, int depth)
1118 {
1119         if (sam == NULL)
1120                 return False;
1121
1122         prs_debug(ps, depth, desc, "sam_io_sam_str3");
1123         depth++;
1124
1125         if(!prs_align(ps))
1126                 return False;
1127
1128         if(!smb_io_unistr2("uni_grp_name", &sam->uni_grp_name, acct_buf, ps, depth))    /* account name unicode string */
1129                 return False;
1130         if(!smb_io_unistr2("uni_grp_desc", &sam->uni_grp_desc, desc_buf, ps, depth))    /* account desc unicode string */
1131                 return False;
1132
1133         return True;
1134 }
1135
1136 /*******************************************************************
1137 inits a SAM_ENTRY3 structure.
1138 ********************************************************************/
1139
1140 static void init_sam_entry3(SAM_ENTRY3 * sam, uint32 grp_idx,
1141                             UNISTR2 *grp_name, UNISTR2 *grp_desc,
1142                             uint32 rid_grp)
1143 {
1144         DEBUG(5, ("init_sam_entry3\n"));
1145
1146         sam->grp_idx = grp_idx;
1147         sam->rid_grp = rid_grp;
1148         sam->attr = 0x07;       /* group rid attributes - gets ignored by nt 4.0 */
1149
1150         init_uni_hdr(&sam->hdr_grp_name, grp_name);
1151         init_uni_hdr(&sam->hdr_grp_desc, grp_desc);
1152 }
1153
1154 /*******************************************************************
1155 reads or writes a SAM_ENTRY3 structure.
1156 ********************************************************************/
1157
1158 static BOOL sam_io_sam_entry3(const char *desc, SAM_ENTRY3 * sam,
1159                               prs_struct *ps, int depth)
1160 {
1161         if (sam == NULL)
1162                 return False;
1163
1164         prs_debug(ps, depth, desc, "sam_io_sam_entry3");
1165         depth++;
1166
1167         if(!prs_align(ps))
1168                 return False;
1169
1170         if(!prs_uint32("grp_idx", ps, depth, &sam->grp_idx))
1171                 return False;
1172
1173         if(!prs_uint32("rid_grp", ps, depth, &sam->rid_grp))
1174                 return False;
1175         if(!prs_uint32("attr   ", ps, depth, &sam->attr))
1176                 return False;
1177
1178         if(!smb_io_unihdr("unihdr", &sam->hdr_grp_name, ps, depth))     /* account name unicode string header */
1179                 return False;
1180         if(!smb_io_unihdr("unihdr", &sam->hdr_grp_desc, ps, depth))     /* account name unicode string header */
1181                 return False;
1182
1183         return True;
1184 }
1185
1186 /*******************************************************************
1187 inits a SAM_ENTRY4 structure.
1188 ********************************************************************/
1189
1190 static void init_sam_entry4(SAM_ENTRY4 * sam, uint32 user_idx,
1191                             uint32 len_acct_name)
1192 {
1193         DEBUG(5, ("init_sam_entry4\n"));
1194
1195         sam->user_idx = user_idx;
1196         init_str_hdr(&sam->hdr_acct_name, len_acct_name+1, len_acct_name, len_acct_name != 0);
1197 }
1198
1199 /*******************************************************************
1200 reads or writes a SAM_ENTRY4 structure.
1201 ********************************************************************/
1202
1203 static BOOL sam_io_sam_entry4(const char *desc, SAM_ENTRY4 * sam,
1204                               prs_struct *ps, int depth)
1205 {
1206         if (sam == NULL)
1207                 return False;
1208
1209         prs_debug(ps, depth, desc, "sam_io_sam_entry4");
1210         depth++;
1211
1212         if(!prs_align(ps))
1213                 return False;
1214
1215         if(!prs_uint32("user_idx", ps, depth, &sam->user_idx))
1216                 return False;
1217         if(!smb_io_strhdr("strhdr", &sam->hdr_acct_name, ps, depth))
1218                 return False;
1219
1220         return True;
1221 }
1222
1223 /*******************************************************************
1224 inits a SAM_ENTRY5 structure.
1225 ********************************************************************/
1226
1227 static void init_sam_entry5(SAM_ENTRY5 * sam, uint32 grp_idx,
1228                             uint32 len_grp_name)
1229 {
1230         DEBUG(5, ("init_sam_entry5\n"));
1231
1232         sam->grp_idx = grp_idx;
1233         init_str_hdr(&sam->hdr_grp_name, len_grp_name, len_grp_name,
1234                      len_grp_name != 0);
1235 }
1236
1237 /*******************************************************************
1238 reads or writes a SAM_ENTRY5 structure.
1239 ********************************************************************/
1240
1241 static BOOL sam_io_sam_entry5(const char *desc, SAM_ENTRY5 * sam,
1242                               prs_struct *ps, int depth)
1243 {
1244         if (sam == NULL)
1245                 return False;
1246
1247         prs_debug(ps, depth, desc, "sam_io_sam_entry5");
1248         depth++;
1249
1250         if(!prs_align(ps))
1251                 return False;
1252
1253         if(!prs_uint32("grp_idx", ps, depth, &sam->grp_idx))
1254                 return False;
1255         if(!smb_io_strhdr("strhdr", &sam->hdr_grp_name, ps, depth))
1256                 return False;
1257
1258         return True;
1259 }
1260
1261 /*******************************************************************
1262 inits a SAM_ENTRY structure.
1263 ********************************************************************/
1264
1265 void init_sam_entry(SAM_ENTRY *sam, UNISTR2 *uni2, uint32 rid)
1266 {
1267         DEBUG(10, ("init_sam_entry: %d\n", rid));
1268
1269         sam->rid = rid;
1270         init_uni_hdr(&sam->hdr_name, uni2);
1271 }
1272
1273 /*******************************************************************
1274 reads or writes a SAM_ENTRY structure.
1275 ********************************************************************/
1276
1277 static BOOL sam_io_sam_entry(const char *desc, SAM_ENTRY * sam,
1278                              prs_struct *ps, int depth)
1279 {
1280         if (sam == NULL)
1281                 return False;
1282
1283         prs_debug(ps, depth, desc, "sam_io_sam_entry");
1284         depth++;
1285
1286         if(!prs_align(ps))
1287                 return False;
1288         if(!prs_uint32("rid", ps, depth, &sam->rid))
1289                 return False;
1290         if(!smb_io_unihdr("unihdr", &sam->hdr_name, ps, depth)) /* account name unicode string header */
1291                 return False;
1292
1293         return True;
1294 }
1295
1296 /*******************************************************************
1297 inits a SAMR_Q_ENUM_DOM_USERS structure.
1298 ********************************************************************/
1299
1300 void init_samr_q_enum_dom_users(SAMR_Q_ENUM_DOM_USERS * q_e, POLICY_HND *pol,
1301                                 uint32 start_idx,
1302                                 uint16 acb_mask, uint16 unk_1, uint32 size)
1303 {
1304         DEBUG(5, ("init_samr_q_enum_dom_users\n"));
1305
1306         q_e->pol = *pol;
1307
1308         q_e->start_idx = start_idx;     /* zero indicates lots */
1309         q_e->acb_mask = acb_mask;
1310         q_e->unknown_1 = unk_1;
1311         q_e->max_size = size;
1312 }
1313
1314 /*******************************************************************
1315 reads or writes a structure.
1316 ********************************************************************/
1317
1318 BOOL samr_io_q_enum_dom_users(const char *desc, SAMR_Q_ENUM_DOM_USERS * q_e,
1319                               prs_struct *ps, int depth)
1320 {
1321         if (q_e == NULL)
1322                 return False;
1323
1324         prs_debug(ps, depth, desc, "samr_io_q_enum_dom_users");
1325         depth++;
1326
1327         if(!prs_align(ps))
1328                 return False;
1329
1330         if(!smb_io_pol_hnd("domain_pol", &q_e->pol, ps, depth))
1331                 return False;
1332
1333         if(!prs_uint32("start_idx", ps, depth, &q_e->start_idx))
1334                 return False;
1335         if(!prs_uint16("acb_mask ", ps, depth, &q_e->acb_mask))
1336                 return False;
1337         if(!prs_uint16("unknown_1", ps, depth, &q_e->unknown_1))
1338                 return False;
1339
1340         if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
1341                 return False;
1342
1343         return True;
1344 }
1345
1346
1347 /*******************************************************************
1348 inits a SAMR_R_ENUM_DOM_USERS structure.
1349 ********************************************************************/
1350
1351 void init_samr_r_enum_dom_users(SAMR_R_ENUM_DOM_USERS * r_u,
1352                                 uint32 next_idx, uint32 num_sam_entries)
1353 {
1354         DEBUG(5, ("init_samr_r_enum_dom_users\n"));
1355
1356         r_u->next_idx = next_idx;
1357
1358         if (num_sam_entries != 0) {
1359                 r_u->ptr_entries1 = 1;
1360                 r_u->ptr_entries2 = 1;
1361                 r_u->num_entries2 = num_sam_entries;
1362                 r_u->num_entries3 = num_sam_entries;
1363
1364                 r_u->num_entries4 = num_sam_entries;
1365         } else {
1366                 r_u->ptr_entries1 = 0;
1367                 r_u->num_entries2 = num_sam_entries;
1368                 r_u->ptr_entries2 = 1;
1369         }
1370 }
1371
1372 /*******************************************************************
1373 reads or writes a structure.
1374 ********************************************************************/
1375
1376 BOOL samr_io_r_enum_dom_users(const char *desc, SAMR_R_ENUM_DOM_USERS * r_u,
1377                               prs_struct *ps, int depth)
1378 {
1379         uint32 i;
1380
1381         if (r_u == NULL)
1382                 return False;
1383
1384         prs_debug(ps, depth, desc, "samr_io_r_enum_dom_users");
1385         depth++;
1386
1387         if(!prs_align(ps))
1388                 return False;
1389
1390         if(!prs_uint32("next_idx    ", ps, depth, &r_u->next_idx))
1391                 return False;
1392         if(!prs_uint32("ptr_entries1", ps, depth, &r_u->ptr_entries1))
1393                 return False;
1394
1395         if (r_u->ptr_entries1 != 0) {
1396                 if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
1397                         return False;
1398                 if(!prs_uint32("ptr_entries2", ps, depth, &r_u->ptr_entries2))
1399                         return False;
1400                 if(!prs_uint32("num_entries3", ps, depth, &r_u->num_entries3))
1401                         return False;
1402
1403                 if (UNMARSHALLING(ps) && (r_u->num_entries2 != 0)) {
1404                         r_u->sam = (SAM_ENTRY *)prs_alloc_mem(ps,sizeof(SAM_ENTRY)*r_u->num_entries2);
1405                         r_u->uni_acct_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2)*r_u->num_entries2);
1406                 }
1407
1408                 if ((r_u->sam == NULL || r_u->uni_acct_name == NULL) && r_u->num_entries2 != 0) {
1409                         DEBUG(0,("NULL pointers in SAMR_R_ENUM_DOM_USERS\n"));
1410                         r_u->num_entries4 = 0;
1411                         r_u->status = NT_STATUS_MEMORY_NOT_ALLOCATED;
1412                         return False;
1413                 }
1414
1415                 for (i = 0; i < r_u->num_entries2; i++) {
1416                         if(!sam_io_sam_entry("", &r_u->sam[i], ps, depth))
1417                                 return False;
1418                 }
1419
1420                 for (i = 0; i < r_u->num_entries2; i++) {
1421                         if(!smb_io_unistr2("", &r_u->uni_acct_name[i],r_u->sam[i].hdr_name.buffer, ps,depth))
1422                                 return False;
1423                 }
1424
1425         }
1426
1427         if(!prs_align(ps))
1428                 return False;
1429                 
1430         if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4))
1431                 return False;
1432         if(!prs_ntstatus("status", ps, depth, &r_u->status))
1433                 return False;
1434
1435         return True;
1436 }
1437
1438 /*******************************************************************
1439 inits a SAMR_Q_QUERY_DISPINFO structure.
1440 ********************************************************************/
1441
1442 void init_samr_q_query_dispinfo(SAMR_Q_QUERY_DISPINFO * q_e, POLICY_HND *pol,
1443                                 uint16 switch_level, uint32 start_idx,
1444                                 uint32 max_entries, uint32 max_size)
1445 {
1446         DEBUG(5, ("init_samr_q_query_dispinfo\n"));
1447
1448         q_e->domain_pol = *pol;
1449
1450         q_e->switch_level = switch_level;
1451
1452         q_e->start_idx = start_idx;
1453         q_e->max_entries = max_entries;
1454         q_e->max_size = max_size;
1455 }
1456
1457 /*******************************************************************
1458 reads or writes a structure.
1459 ********************************************************************/
1460
1461 BOOL samr_io_q_query_dispinfo(const char *desc, SAMR_Q_QUERY_DISPINFO * q_e,
1462                               prs_struct *ps, int depth)
1463 {
1464         if (q_e == NULL)
1465                 return False;
1466
1467         prs_debug(ps, depth, desc, "samr_io_q_query_dispinfo");
1468         depth++;
1469
1470         if(!prs_align(ps))
1471                 return False;
1472
1473         if(!smb_io_pol_hnd("domain_pol", &q_e->domain_pol, ps, depth))
1474                 return False;
1475
1476         if(!prs_uint16("switch_level", ps, depth, &q_e->switch_level))
1477                 return False;
1478         if(!prs_align(ps))
1479                 return False;
1480
1481         if(!prs_uint32("start_idx   ", ps, depth, &q_e->start_idx))
1482                 return False;
1483         if(!prs_uint32("max_entries ", ps, depth, &q_e->max_entries))
1484                 return False;
1485         if(!prs_uint32("max_size    ", ps, depth, &q_e->max_size))
1486                 return False;
1487
1488         return True;
1489 }
1490
1491 /*******************************************************************
1492 inits a SAM_DISPINFO_1 structure.
1493 ********************************************************************/
1494
1495 NTSTATUS init_sam_dispinfo_1(TALLOC_CTX *ctx, SAM_DISPINFO_1 *sam, uint32 num_entries,
1496                              uint32 start_idx, SAM_ACCOUNT *disp_user_info,
1497                              DOM_SID *domain_sid)
1498 {
1499         uint32 i;
1500
1501         SAM_ACCOUNT *pwd = NULL;
1502         ZERO_STRUCTP(sam);
1503
1504         DEBUG(10, ("init_sam_dispinfo_1: num_entries: %d\n", num_entries));
1505
1506         if (num_entries==0)
1507                 return NT_STATUS_OK;
1508
1509         sam->sam=(SAM_ENTRY1 *)talloc(ctx, num_entries*sizeof(SAM_ENTRY1));
1510         if (!sam->sam)
1511                 return NT_STATUS_NO_MEMORY;
1512
1513         sam->str=(SAM_STR1 *)talloc(ctx, num_entries*sizeof(SAM_STR1));
1514         if (!sam->str)
1515                 return NT_STATUS_NO_MEMORY;
1516
1517         ZERO_STRUCTP(sam->sam);
1518         ZERO_STRUCTP(sam->str);
1519
1520         for (i = 0; i < num_entries ; i++) {
1521                 const char *username;
1522                 const char *fullname;
1523                 const char *acct_desc;
1524                 uint32 user_rid;
1525                 const DOM_SID *user_sid;
1526                 fstring user_sid_string, domain_sid_string;                     
1527
1528                 DEBUG(11, ("init_sam_dispinfo_1: entry: %d\n",i));
1529                 
1530                 pwd=&disp_user_info[i+start_idx];
1531                 
1532                 username = pdb_get_username(pwd);
1533                 fullname = pdb_get_fullname(pwd);
1534                 acct_desc = pdb_get_acct_desc(pwd);
1535                 
1536                 if (!username) 
1537                         username = "";
1538
1539                 if (!fullname) 
1540                         fullname = "";
1541                 
1542                 if (!acct_desc) 
1543                         acct_desc = "";
1544
1545                 user_sid = pdb_get_user_sid(pwd);
1546
1547                 if (!sid_peek_check_rid(domain_sid, user_sid, &user_rid)) {
1548                         DEBUG(0, ("init_sam_dispinfo_1: User %s has SID %s, which conflicts with "
1549                                   "the domain sid %s.  Failing operation.\n", 
1550                                   username, 
1551                                   sid_to_string(user_sid_string, user_sid),
1552                                   sid_to_string(domain_sid_string, domain_sid)));
1553                         return NT_STATUS_UNSUCCESSFUL;
1554                 }
1555                         
1556                 init_unistr2(&sam->str[i].uni_acct_name, pdb_get_username(pwd), UNI_FLAGS_NONE);
1557                 init_unistr2(&sam->str[i].uni_full_name, pdb_get_fullname(pwd), UNI_FLAGS_NONE);
1558                 init_unistr2(&sam->str[i].uni_acct_desc, pdb_get_acct_desc(pwd), UNI_FLAGS_NONE);
1559
1560                 init_sam_entry1(&sam->sam[i], start_idx + i + 1,
1561                                 &sam->str[i].uni_acct_name, &sam->str[i].uni_full_name, &sam->str[i].uni_acct_desc,
1562                                 user_rid, pdb_get_acct_ctrl(pwd));
1563                 
1564         }
1565
1566         return NT_STATUS_OK;
1567 }
1568
1569 /*******************************************************************
1570 reads or writes a structure.
1571 ********************************************************************/
1572
1573 static BOOL sam_io_sam_dispinfo_1(const char *desc, SAM_DISPINFO_1 * sam,
1574                                   uint32 num_entries,
1575                                   prs_struct *ps, int depth)
1576 {
1577         uint32 i;
1578
1579         prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_1");
1580         depth++;
1581
1582         if(!prs_align(ps))
1583                 return False;
1584
1585         if (UNMARSHALLING(ps) && num_entries > 0) {
1586
1587                 if ((sam->sam = (SAM_ENTRY1 *)
1588                      prs_alloc_mem(ps, sizeof(SAM_ENTRY1) *
1589                                    num_entries)) == NULL) {
1590                         DEBUG(0, ("out of memory allocating SAM_ENTRY1\n"));
1591                         return False;
1592                 }
1593
1594                 if ((sam->str = (SAM_STR1 *)
1595                      prs_alloc_mem(ps, sizeof(SAM_STR1) * 
1596                                    num_entries)) == NULL) {
1597                         DEBUG(0, ("out of memory allocating SAM_STR1\n"));
1598                         return False;
1599                 }
1600         }
1601
1602         for (i = 0; i < num_entries; i++) {
1603                 if(!sam_io_sam_entry1("", &sam->sam[i], ps, depth))
1604                         return False;
1605         }
1606
1607         for (i = 0; i < num_entries; i++) {
1608                 if(!sam_io_sam_str1("", &sam->str[i],
1609                               sam->sam[i].hdr_acct_name.buffer,
1610                               sam->sam[i].hdr_user_name.buffer,
1611                               sam->sam[i].hdr_user_desc.buffer, ps, depth))
1612                         return False;
1613         }
1614
1615         return True;
1616 }
1617
1618 /*******************************************************************
1619 inits a SAM_DISPINFO_2 structure.
1620 ********************************************************************/
1621
1622 NTSTATUS init_sam_dispinfo_2(TALLOC_CTX *ctx, SAM_DISPINFO_2 *sam, uint32 num_entries,
1623                              uint32 start_idx, SAM_ACCOUNT *disp_user_info, 
1624                              DOM_SID *domain_sid )
1625 {
1626         uint32 i;
1627
1628         SAM_ACCOUNT *pwd = NULL;
1629         ZERO_STRUCTP(sam);
1630
1631         DEBUG(10, ("init_sam_dispinfo_2: num_entries: %d\n", num_entries));
1632
1633         if (num_entries==0)
1634                 return NT_STATUS_OK;
1635
1636         if (!(sam->sam=(SAM_ENTRY2 *)talloc(ctx, num_entries*sizeof(SAM_ENTRY2))))
1637                 return NT_STATUS_NO_MEMORY;
1638
1639         if (!(sam->str=(SAM_STR2 *)talloc(ctx, num_entries*sizeof(SAM_STR2))))
1640                 return NT_STATUS_NO_MEMORY;
1641
1642         ZERO_STRUCTP(sam->sam);
1643         ZERO_STRUCTP(sam->str);
1644
1645         for (i = 0; i < num_entries; i++) {
1646                 uint32 user_rid;
1647                 const DOM_SID *user_sid;
1648                 const char *username;
1649                 const char *acct_desc;
1650                 fstring user_sid_string, domain_sid_string;                     
1651
1652                 DEBUG(11, ("init_sam_dispinfo_2: entry: %d\n",i));
1653                 pwd=&disp_user_info[i+start_idx];
1654
1655                 username = pdb_get_username(pwd);
1656                 acct_desc = pdb_get_acct_desc(pwd);
1657                 user_sid = pdb_get_user_sid(pwd);
1658
1659                 if (!sid_peek_check_rid(domain_sid, user_sid, &user_rid)) {
1660                         DEBUG(0, ("init_sam_dispinfo_2: User %s has SID %s, which conflicts with "
1661                                   "the domain sid %s.  Failing operation.\n", 
1662                                   username, 
1663                                   sid_to_string(user_sid_string, user_sid),
1664                                   sid_to_string(domain_sid_string, domain_sid)));
1665                         return NT_STATUS_UNSUCCESSFUL;
1666                 }
1667                         
1668                 init_unistr2(&sam->str[i].uni_srv_name, username, UNI_FLAGS_NONE);
1669                 init_unistr2(&sam->str[i].uni_srv_desc, acct_desc, UNI_FLAGS_NONE);
1670
1671                 init_sam_entry2(&sam->sam[i], start_idx + i + 1,
1672                           &sam->str[i].uni_srv_name, &sam->str[i].uni_srv_desc,
1673                           user_rid, pdb_get_acct_ctrl(pwd));
1674         }
1675
1676         return NT_STATUS_OK;
1677 }
1678
1679 /*******************************************************************
1680 reads or writes a structure.
1681 ********************************************************************/
1682
1683 static BOOL sam_io_sam_dispinfo_2(const char *desc, SAM_DISPINFO_2 * sam,
1684                                   uint32 num_entries,
1685                                   prs_struct *ps, int depth)
1686 {
1687         uint32 i;
1688
1689         if (sam == NULL)
1690                 return False;
1691
1692         prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_2");
1693         depth++;
1694
1695         if(!prs_align(ps))
1696                 return False;
1697
1698         if (UNMARSHALLING(ps) && num_entries > 0) {
1699
1700                 if ((sam->sam = (SAM_ENTRY2 *)
1701                      prs_alloc_mem(ps, sizeof(SAM_ENTRY2) *
1702                                    num_entries)) == NULL) {
1703                         DEBUG(0, ("out of memory allocating SAM_ENTRY2\n"));
1704                         return False;
1705                 }
1706
1707                 if ((sam->str = (SAM_STR2 *)
1708                      prs_alloc_mem(ps, sizeof(SAM_STR2) * 
1709                                    num_entries)) == NULL) {
1710                         DEBUG(0, ("out of memory allocating SAM_STR2\n"));
1711                         return False;
1712                 }
1713         }
1714
1715         for (i = 0; i < num_entries; i++) {
1716                 if(!sam_io_sam_entry2("", &sam->sam[i], ps, depth))
1717                         return False;
1718         }
1719
1720         for (i = 0; i < num_entries; i++) {
1721                 if(!sam_io_sam_str2("", &sam->str[i],
1722                               sam->sam[i].hdr_srv_name.buffer,
1723                               sam->sam[i].hdr_srv_desc.buffer, ps, depth))
1724                         return False;
1725         }
1726
1727         return True;
1728 }
1729
1730 /*******************************************************************
1731 inits a SAM_DISPINFO_3 structure.
1732 ********************************************************************/
1733
1734 NTSTATUS init_sam_dispinfo_3(TALLOC_CTX *ctx, SAM_DISPINFO_3 *sam, uint32 num_entries,
1735                          uint32 start_idx, DOMAIN_GRP *disp_group_info)
1736 {
1737         uint32 i;
1738
1739         ZERO_STRUCTP(sam);
1740
1741         DEBUG(5, ("init_sam_dispinfo_3: num_entries: %d\n", num_entries));
1742
1743         if (num_entries==0)
1744                 return NT_STATUS_OK;
1745
1746         if (!(sam->sam=(SAM_ENTRY3 *)talloc(ctx, num_entries*sizeof(SAM_ENTRY3))))
1747                 return NT_STATUS_NO_MEMORY;
1748
1749         if (!(sam->str=(SAM_STR3 *)talloc(ctx, num_entries*sizeof(SAM_STR3))))
1750                 return NT_STATUS_NO_MEMORY;
1751
1752         ZERO_STRUCTP(sam->sam);
1753         ZERO_STRUCTP(sam->str);
1754
1755         for (i = 0; i < num_entries; i++) {
1756                 DOMAIN_GRP *grp = &disp_group_info[i+start_idx];
1757
1758                 DEBUG(11, ("init_sam_dispinfo_3: entry: %d\n",i));
1759
1760                 init_unistr2(&sam->str[i].uni_grp_name, grp->name, UNI_FLAGS_NONE);
1761                 init_unistr2(&sam->str[i].uni_grp_desc, grp->comment, UNI_FLAGS_NONE);
1762
1763                 init_sam_entry3(&sam->sam[i], start_idx + i + 1, &sam->str[i].uni_grp_name,
1764                                 &sam->str[i].uni_grp_desc, grp->rid);
1765         }
1766
1767         return NT_STATUS_OK;
1768 }
1769
1770 /*******************************************************************
1771 reads or writes a structure.
1772 ********************************************************************/
1773
1774 static BOOL sam_io_sam_dispinfo_3(const char *desc, SAM_DISPINFO_3 * sam,
1775                                   uint32 num_entries,
1776                                   prs_struct *ps, int depth)
1777 {
1778         uint32 i;
1779
1780         if (sam == NULL)
1781                 return False;
1782
1783         prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_3");
1784         depth++;
1785
1786         if(!prs_align(ps))
1787                 return False;
1788
1789         if (UNMARSHALLING(ps) && num_entries > 0) {
1790
1791                 if ((sam->sam = (SAM_ENTRY3 *)
1792                      prs_alloc_mem(ps, sizeof(SAM_ENTRY3) *
1793                                    num_entries)) == NULL) {
1794                         DEBUG(0, ("out of memory allocating SAM_ENTRY3\n"));
1795                         return False;
1796                 }
1797
1798                 if ((sam->str = (SAM_STR3 *)
1799                      prs_alloc_mem(ps, sizeof(SAM_STR3) * 
1800                                    num_entries)) == NULL) {
1801                         DEBUG(0, ("out of memory allocating SAM_STR3\n"));
1802                         return False;
1803                 }
1804         }
1805
1806         for (i = 0; i < num_entries; i++) {
1807                 if(!sam_io_sam_entry3("", &sam->sam[i], ps, depth))
1808                         return False;
1809         }
1810
1811         for (i = 0; i < num_entries; i++) {
1812                 if(!sam_io_sam_str3("", &sam->str[i],
1813                               sam->sam[i].hdr_grp_name.buffer,
1814                               sam->sam[i].hdr_grp_desc.buffer, ps, depth))
1815                         return False;
1816         }
1817
1818         return True;
1819 }
1820
1821 /*******************************************************************
1822 inits a SAM_DISPINFO_4 structure.
1823 ********************************************************************/
1824
1825 NTSTATUS init_sam_dispinfo_4(TALLOC_CTX *ctx, SAM_DISPINFO_4 *sam, uint32 num_entries,
1826                          uint32 start_idx, SAM_ACCOUNT *disp_user_info)
1827 {
1828         uint32 len_sam_name;
1829         uint32 i;
1830
1831         SAM_ACCOUNT *pwd = NULL;
1832         ZERO_STRUCTP(sam);
1833
1834         DEBUG(5, ("init_sam_dispinfo_4: num_entries: %d\n", num_entries));
1835
1836         if (num_entries==0)
1837                 return NT_STATUS_OK;
1838
1839         if (!(sam->sam=(SAM_ENTRY4 *)talloc(ctx, num_entries*sizeof(SAM_ENTRY4))))
1840                 return NT_STATUS_NO_MEMORY;
1841
1842         if (!(sam->str=(SAM_STR4 *)talloc(ctx, num_entries*sizeof(SAM_STR4))))
1843                 return NT_STATUS_NO_MEMORY;
1844
1845         ZERO_STRUCTP(sam->sam);
1846         ZERO_STRUCTP(sam->str);
1847
1848         for (i = 0; i < num_entries; i++) {
1849                 DEBUG(11, ("init_sam_dispinfo_2: entry: %d\n",i));
1850                 pwd=&disp_user_info[i+start_idx];
1851
1852                 len_sam_name = strlen(pdb_get_username(pwd));
1853           
1854                 init_sam_entry4(&sam->sam[i], start_idx + i + 1, len_sam_name);
1855
1856                 init_string2(&sam->str[i].acct_name, pdb_get_username(pwd), len_sam_name+1, len_sam_name);
1857         }
1858         
1859         return NT_STATUS_OK;
1860 }
1861
1862 /*******************************************************************
1863 reads or writes a structure.
1864 ********************************************************************/
1865
1866 static BOOL sam_io_sam_dispinfo_4(const char *desc, SAM_DISPINFO_4 * sam,
1867                                   uint32 num_entries,
1868                                   prs_struct *ps, int depth)
1869 {
1870         uint32 i;
1871
1872         if (sam == NULL)
1873                 return False;
1874
1875         prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_4");
1876         depth++;
1877
1878         if(!prs_align(ps))
1879                 return False;
1880
1881         if (UNMARSHALLING(ps) && num_entries > 0) {
1882
1883                 if ((sam->sam = (SAM_ENTRY4 *)
1884                      prs_alloc_mem(ps, sizeof(SAM_ENTRY4) *
1885                                    num_entries)) == NULL) {
1886                         DEBUG(0, ("out of memory allocating SAM_ENTRY4\n"));
1887                         return False;
1888                 }
1889
1890                 if ((sam->str = (SAM_STR4 *)
1891                      prs_alloc_mem(ps, sizeof(SAM_STR4) * 
1892                                    num_entries)) == NULL) {
1893                         DEBUG(0, ("out of memory allocating SAM_STR4\n"));
1894                         return False;
1895                 }
1896         }
1897
1898         for (i = 0; i < num_entries; i++) {
1899                 if(!sam_io_sam_entry4("", &sam->sam[i], ps, depth))
1900                         return False;
1901         }
1902
1903         for (i = 0; i < num_entries; i++) {
1904                 if(!smb_io_string2("acct_name", &sam->str[i].acct_name,
1905                              sam->sam[i].hdr_acct_name.buffer, ps, depth))
1906                         return False;
1907         }
1908
1909         return True;
1910 }
1911
1912 /*******************************************************************
1913 inits a SAM_DISPINFO_5 structure.
1914 ********************************************************************/
1915
1916 NTSTATUS init_sam_dispinfo_5(TALLOC_CTX *ctx, SAM_DISPINFO_5 *sam, uint32 num_entries,
1917                          uint32 start_idx, DOMAIN_GRP *disp_group_info)
1918 {
1919         uint32 len_sam_name;
1920         uint32 i;
1921
1922         ZERO_STRUCTP(sam);
1923
1924         DEBUG(5, ("init_sam_dispinfo_5: num_entries: %d\n", num_entries));
1925
1926         if (num_entries==0)
1927                 return NT_STATUS_OK;
1928
1929         if (!(sam->sam=(SAM_ENTRY5 *)talloc(ctx, num_entries*sizeof(SAM_ENTRY5))))
1930                 return NT_STATUS_NO_MEMORY;
1931
1932         if (!(sam->str=(SAM_STR5 *)talloc(ctx, num_entries*sizeof(SAM_STR5))))
1933                 return NT_STATUS_NO_MEMORY;
1934
1935         ZERO_STRUCTP(sam->sam);
1936         ZERO_STRUCTP(sam->str);
1937
1938         for (i = 0; i < num_entries; i++) {
1939                 DOMAIN_GRP *grp = &disp_group_info[i+start_idx];
1940
1941                 DEBUG(11, ("init_sam_dispinfo_5: entry: %d\n",i));
1942
1943                 len_sam_name = strlen(grp->name);
1944           
1945                 init_sam_entry5(&sam->sam[i], start_idx + i + 1, len_sam_name);
1946                 init_string2(&sam->str[i].grp_name, grp->name, len_sam_name+1, len_sam_name);
1947         }
1948
1949         return NT_STATUS_OK;
1950 }
1951
1952 /*******************************************************************
1953 reads or writes a structure.
1954 ********************************************************************/
1955
1956 static BOOL sam_io_sam_dispinfo_5(const char *desc, SAM_DISPINFO_5 * sam,
1957                                   uint32 num_entries,
1958                                   prs_struct *ps, int depth)
1959 {
1960         uint32 i;
1961
1962         if (sam == NULL)
1963                 return False;
1964
1965         prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_5");
1966         depth++;
1967
1968         if(!prs_align(ps))
1969                 return False;
1970
1971         if (UNMARSHALLING(ps) && num_entries > 0) {
1972
1973                 if ((sam->sam = (SAM_ENTRY5 *)
1974                      prs_alloc_mem(ps, sizeof(SAM_ENTRY5) *
1975                                    num_entries)) == NULL) {
1976                         DEBUG(0, ("out of memory allocating SAM_ENTRY5\n"));
1977                         return False;
1978                 }
1979
1980                 if ((sam->str = (SAM_STR5 *)
1981                      prs_alloc_mem(ps, sizeof(SAM_STR5) * 
1982                                    num_entries)) == NULL) {
1983                         DEBUG(0, ("out of memory allocating SAM_STR5\n"));
1984                         return False;
1985                 }
1986         }
1987
1988         for (i = 0; i < num_entries; i++) {
1989                 if(!sam_io_sam_entry5("", &sam->sam[i], ps, depth))
1990                         return False;
1991         }
1992
1993         for (i = 0; i < num_entries; i++) {
1994                 if(!smb_io_string2("grp_name", &sam->str[i].grp_name,
1995                              sam->sam[i].hdr_grp_name.buffer, ps, depth))
1996                         return False;
1997         }
1998
1999         return True;
2000 }
2001
2002 /*******************************************************************
2003 inits a SAMR_R_QUERY_DISPINFO structure.
2004 ********************************************************************/
2005
2006 void init_samr_r_query_dispinfo(SAMR_R_QUERY_DISPINFO * r_u,
2007                                 uint32 num_entries, uint32 total_size, uint32 data_size,
2008                                 uint16 switch_level, SAM_DISPINFO_CTR * ctr,
2009                                 NTSTATUS status)
2010 {
2011         DEBUG(5, ("init_samr_r_query_dispinfo: level %d\n", switch_level));
2012
2013         r_u->total_size = total_size;
2014
2015         r_u->data_size = data_size;
2016
2017         r_u->switch_level = switch_level;
2018         r_u->num_entries = num_entries;
2019
2020         if (num_entries==0)
2021                 r_u->ptr_entries = 0;
2022         else
2023                 r_u->ptr_entries = 1;
2024
2025         r_u->num_entries2 = num_entries;
2026         r_u->ctr = ctr;
2027
2028         r_u->status = status;
2029 }
2030
2031 /*******************************************************************
2032 reads or writes a structure.
2033 ********************************************************************/
2034
2035 BOOL samr_io_r_query_dispinfo(const char *desc, SAMR_R_QUERY_DISPINFO * r_u,
2036                               prs_struct *ps, int depth)
2037 {
2038         if (r_u == NULL)
2039                 return False;
2040
2041         prs_debug(ps, depth, desc, "samr_io_r_query_dispinfo");
2042         depth++;
2043
2044         if(!prs_align(ps))
2045                 return False;
2046
2047         if(!prs_uint32("total_size  ", ps, depth, &r_u->total_size))
2048                 return False;
2049         if(!prs_uint32("data_size   ", ps, depth, &r_u->data_size))
2050                 return False;
2051         if(!prs_uint16("switch_level", ps, depth, &r_u->switch_level))
2052                 return False;
2053         if(!prs_align(ps))
2054                 return False;
2055
2056         if(!prs_uint32("num_entries ", ps, depth, &r_u->num_entries))
2057                 return False;
2058         if(!prs_uint32("ptr_entries ", ps, depth, &r_u->ptr_entries))
2059                 return False;
2060
2061         if (r_u->ptr_entries==0) {
2062                 if(!prs_align(ps))
2063                         return False;
2064                 if(!prs_ntstatus("status", ps, depth, &r_u->status))
2065                         return False;
2066
2067                 return True;
2068         }
2069
2070         if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
2071                 return False;
2072
2073         switch (r_u->switch_level) {
2074         case 0x1:
2075                 if(!sam_io_sam_dispinfo_1("users", r_u->ctr->sam.info1,
2076                                 r_u->num_entries, ps, depth))
2077                         return False;
2078                 break;
2079         case 0x2:
2080                 if(!sam_io_sam_dispinfo_2("servers", r_u->ctr->sam.info2,
2081                                 r_u->num_entries, ps, depth))
2082                         return False;
2083                 break;
2084         case 0x3:
2085                 if(!sam_io_sam_dispinfo_3("groups", r_u->ctr->sam.info3,
2086                                     r_u->num_entries, ps, depth))
2087                         return False;
2088                 break;
2089         case 0x4:
2090                 if(!sam_io_sam_dispinfo_4("user list",
2091                                     r_u->ctr->sam.info4,
2092                                     r_u->num_entries, ps, depth))
2093                         return False;
2094                 break;
2095         case 0x5:
2096                 if(!sam_io_sam_dispinfo_5("group list",
2097                                     r_u->ctr->sam.info5,
2098                                     r_u->num_entries, ps, depth))
2099                         return False;
2100                 break;
2101         default:
2102                 DEBUG(0,("samr_io_r_query_dispinfo: unknown switch value\n"));
2103                 break;
2104         }
2105         
2106         if(!prs_align(ps))
2107                 return False;
2108         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2109                 return False;
2110
2111         return True;
2112 }
2113
2114 /*******************************************************************
2115 inits a SAMR_Q_OPEN_GROUP structure.
2116 ********************************************************************/
2117
2118 void init_samr_q_open_group(SAMR_Q_OPEN_GROUP * q_c,
2119                             POLICY_HND *hnd,
2120                             uint32 access_mask, uint32 rid)
2121 {
2122         DEBUG(5, ("init_samr_q_open_group\n"));
2123
2124         q_c->domain_pol = *hnd;
2125         q_c->access_mask = access_mask;
2126         q_c->rid_group = rid;
2127 }
2128
2129 /*******************************************************************
2130 reads or writes a structure.
2131 ********************************************************************/
2132
2133 BOOL samr_io_q_open_group(const char *desc, SAMR_Q_OPEN_GROUP * q_u,
2134                           prs_struct *ps, int depth)
2135 {
2136         if (q_u == NULL)
2137                 return False;
2138
2139         prs_debug(ps, depth, desc, "samr_io_q_open_group");
2140         depth++;
2141
2142         if(!prs_align(ps))
2143                 return False;
2144
2145         if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
2146                 return False;
2147
2148         if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
2149                 return False;
2150         if(!prs_uint32("rid_group", ps, depth, &q_u->rid_group))
2151                 return False;
2152
2153         return True;
2154 }
2155
2156 /*******************************************************************
2157 reads or writes a structure.
2158 ********************************************************************/
2159
2160 BOOL samr_io_r_open_group(const char *desc, SAMR_R_OPEN_GROUP * r_u,
2161                           prs_struct *ps, int depth)
2162 {
2163         if (r_u == NULL)
2164                 return False;
2165
2166         prs_debug(ps, depth, desc, "samr_io_r_open_group");
2167         depth++;
2168
2169         if(!prs_align(ps))
2170                 return False;
2171
2172         if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
2173                 return False;
2174
2175         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2176                 return False;
2177
2178         return True;
2179 }
2180
2181 /*******************************************************************
2182 inits a GROUP_INFO1 structure.
2183 ********************************************************************/
2184
2185 void init_samr_group_info1(GROUP_INFO1 * gr1,
2186                            char *acct_name, char *acct_desc,
2187                            uint32 num_members)
2188 {
2189         DEBUG(5, ("init_samr_group_info1\n"));
2190
2191         gr1->unknown_1 = 0x3;
2192         gr1->num_members = num_members;
2193
2194         init_unistr2(&gr1->uni_acct_name, acct_name, UNI_FLAGS_NONE);
2195         init_uni_hdr(&gr1->hdr_acct_name, &gr1->uni_acct_name);
2196         init_unistr2(&gr1->uni_acct_desc, acct_desc, UNI_FLAGS_NONE);
2197         init_uni_hdr(&gr1->hdr_acct_desc, &gr1->uni_acct_desc);
2198 }
2199
2200 /*******************************************************************
2201 reads or writes a structure.
2202 ********************************************************************/
2203
2204 BOOL samr_io_group_info1(const char *desc, GROUP_INFO1 * gr1,
2205                          prs_struct *ps, int depth)
2206 {
2207         uint16 dummy = 1;
2208
2209         if (gr1 == NULL)
2210                 return False;
2211
2212         prs_debug(ps, depth, desc, "samr_io_group_info1");
2213         depth++;
2214
2215         if(!prs_uint16("level", ps, depth, &dummy))
2216                 return False;
2217
2218         if(!prs_align(ps))
2219                 return False;
2220
2221         if(!smb_io_unihdr("hdr_acct_name", &gr1->hdr_acct_name, ps, depth))
2222                 return False;
2223
2224         if(!prs_uint32("unknown_1", ps, depth, &gr1->unknown_1))
2225                 return False;
2226         if(!prs_uint32("num_members", ps, depth, &gr1->num_members))
2227                 return False;
2228
2229         if(!smb_io_unihdr("hdr_acct_desc", &gr1->hdr_acct_desc, ps, depth))
2230                 return False;
2231
2232         if(!smb_io_unistr2("uni_acct_name", &gr1->uni_acct_name,
2233                            gr1->hdr_acct_name.buffer, ps, depth))
2234                 return False;
2235
2236         if(!smb_io_unistr2("uni_acct_desc", &gr1->uni_acct_desc,
2237                            gr1->hdr_acct_desc.buffer, ps, depth))
2238                 return False;
2239
2240         return True;
2241 }
2242
2243 /*******************************************************************
2244 inits a GROUP_INFO2 structure.
2245 ********************************************************************/
2246
2247 void init_samr_group_info2(GROUP_INFO2 * gr2, const char *acct_name)
2248 {
2249         DEBUG(5, ("init_samr_group_info2\n"));
2250
2251         gr2->level = 2;
2252         init_unistr2(&gr2->uni_acct_name, acct_name, UNI_FLAGS_NONE);
2253         init_uni_hdr(&gr2->hdr_acct_name, &gr2->uni_acct_name);
2254 }
2255
2256 /*******************************************************************
2257 reads or writes a structure.
2258 ********************************************************************/
2259
2260 BOOL samr_io_group_info2(const char *desc, GROUP_INFO2 *gr2, prs_struct *ps, int depth)
2261 {
2262         if (gr2 == NULL)
2263                 return False;
2264
2265         prs_debug(ps, depth, desc, "samr_io_group_info2");
2266         depth++;
2267
2268         if(!prs_uint16("hdr_level", ps, depth, &gr2->level))
2269                 return False;
2270
2271         if(!smb_io_unihdr("hdr_acct_name", &gr2->hdr_acct_name, ps, depth))
2272                 return False;
2273         if(!smb_io_unistr2("uni_acct_name", &gr2->uni_acct_name,
2274                            gr2->hdr_acct_name.buffer, ps, depth))
2275                 return False;
2276
2277         return True;
2278 }
2279
2280 /*******************************************************************
2281 inits a GROUP_INFO3 structure.
2282 ********************************************************************/
2283
2284 void init_samr_group_info3(GROUP_INFO3 *gr3)
2285 {
2286         DEBUG(5, ("init_samr_group_info3\n"));
2287
2288         gr3->unknown_1 = 0x3;
2289 }
2290
2291 /*******************************************************************
2292 reads or writes a structure.
2293 ********************************************************************/
2294
2295 BOOL samr_io_group_info3(const char *desc, GROUP_INFO3 *gr3, prs_struct *ps, int depth)
2296 {
2297         if (gr3 == NULL)
2298                 return False;
2299
2300         prs_debug(ps, depth, desc, "samr_io_group_info3");
2301         depth++;
2302
2303         if(!prs_align(ps))
2304                 return False;
2305
2306         if(!prs_uint32("unknown_1", ps, depth, &gr3->unknown_1))
2307                 return False;
2308
2309         return True;
2310 }
2311
2312 /*******************************************************************
2313 inits a GROUP_INFO4 structure.
2314 ********************************************************************/
2315
2316 void init_samr_group_info4(GROUP_INFO4 * gr4, const char *acct_desc)
2317 {
2318         DEBUG(5, ("init_samr_group_info4\n"));
2319
2320         gr4->level = 4;
2321         init_unistr2(&gr4->uni_acct_desc, acct_desc, UNI_FLAGS_NONE);
2322         init_uni_hdr(&gr4->hdr_acct_desc, &gr4->uni_acct_desc);
2323 }
2324
2325 /*******************************************************************
2326 reads or writes a structure.
2327 ********************************************************************/
2328
2329 BOOL samr_io_group_info4(const char *desc, GROUP_INFO4 * gr4,
2330                          prs_struct *ps, int depth)
2331 {
2332         if (gr4 == NULL)
2333                 return False;
2334
2335         prs_debug(ps, depth, desc, "samr_io_group_info4");
2336         depth++;
2337
2338         if(!prs_uint16("hdr_level", ps, depth, &gr4->level))
2339                 return False;
2340         if(!smb_io_unihdr("hdr_acct_desc", &gr4->hdr_acct_desc, ps, depth))
2341                 return False;
2342         if(!smb_io_unistr2("uni_acct_desc", &gr4->uni_acct_desc,
2343                            gr4->hdr_acct_desc.buffer, ps, depth))
2344                 return False;
2345
2346         return True;
2347 }
2348
2349 /*******************************************************************
2350 reads or writes a structure.
2351 ********************************************************************/
2352
2353 static BOOL samr_group_info_ctr(const char *desc, GROUP_INFO_CTR **ctr,
2354                                 prs_struct *ps, int depth)
2355 {
2356         if (UNMARSHALLING(ps))
2357                 *ctr = (GROUP_INFO_CTR *)prs_alloc_mem(ps,sizeof(GROUP_INFO_CTR));
2358
2359         if (*ctr == NULL)
2360                 return False;
2361
2362         prs_debug(ps, depth, desc, "samr_group_info_ctr");
2363         depth++;
2364
2365         if(!prs_uint16("switch_value1", ps, depth, &(*ctr)->switch_value1))
2366                 return False;
2367
2368         switch ((*ctr)->switch_value1) {
2369         case 1:
2370                 if(!samr_io_group_info1("group_info1", &(*ctr)->group.info1, ps, depth))
2371                         return False;
2372                 break;
2373         case 2:
2374                 if(!samr_io_group_info2("group_info2", &(*ctr)->group.info2, ps, depth))
2375                         return False;
2376                 break;
2377         case 3:
2378                 if(!samr_io_group_info3("group_info3", &(*ctr)->group.info3, ps, depth))
2379                         return False;
2380                 break;
2381         case 4:
2382                 if(!samr_io_group_info4("group_info4", &(*ctr)->group.info4, ps, depth))
2383                         return False;
2384                 break;
2385         default:
2386                 DEBUG(0,("samr_group_info_ctr: unsupported switch level\n"));
2387                 break;
2388         }
2389
2390         return True;
2391 }
2392
2393 /*******************************************************************
2394 inits a SAMR_Q_CREATE_DOM_GROUP structure.
2395 ********************************************************************/
2396
2397 void init_samr_q_create_dom_group(SAMR_Q_CREATE_DOM_GROUP * q_e,
2398                                   POLICY_HND *pol, const char *acct_desc,
2399                                   uint32 access_mask)
2400 {
2401         DEBUG(5, ("init_samr_q_create_dom_group\n"));
2402
2403         q_e->pol = *pol;
2404
2405         init_unistr2(&q_e->uni_acct_desc, acct_desc, UNI_FLAGS_NONE);
2406         init_uni_hdr(&q_e->hdr_acct_desc, &q_e->uni_acct_desc);
2407
2408         q_e->access_mask = access_mask;
2409 }
2410
2411 /*******************************************************************
2412 reads or writes a structure.
2413 ********************************************************************/
2414
2415 BOOL samr_io_q_create_dom_group(const char *desc, SAMR_Q_CREATE_DOM_GROUP * q_e,
2416                                 prs_struct *ps, int depth)
2417 {
2418         if (q_e == NULL)
2419                 return False;
2420
2421         prs_debug(ps, depth, desc, "samr_io_q_create_dom_group");
2422         depth++;
2423
2424         if(!prs_align(ps))
2425                 return False;
2426
2427         if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
2428                 return False;
2429
2430         if(!smb_io_unihdr("hdr_acct_desc", &q_e->hdr_acct_desc, ps, depth))
2431                 return False;
2432         if(!smb_io_unistr2("uni_acct_desc", &q_e->uni_acct_desc,
2433                        q_e->hdr_acct_desc.buffer, ps, depth))
2434                 return False;
2435
2436         if(!prs_align(ps))
2437                 return False;
2438         if(!prs_uint32("access", ps, depth, &q_e->access_mask))
2439                 return False;
2440
2441         return True;
2442 }
2443
2444 /*******************************************************************
2445 reads or writes a structure.
2446 ********************************************************************/
2447
2448 BOOL samr_io_r_create_dom_group(const char *desc, SAMR_R_CREATE_DOM_GROUP * r_u,
2449                                 prs_struct *ps, int depth)
2450 {
2451         if (r_u == NULL)
2452                 return False;
2453
2454         prs_debug(ps, depth, desc, "samr_io_r_create_dom_group");
2455         depth++;
2456
2457         if(!prs_align(ps))
2458                 return False;
2459
2460         if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
2461                 return False;
2462
2463         if(!prs_uint32("rid   ", ps, depth, &r_u->rid))
2464                 return False;
2465         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2466                 return False;
2467
2468         return True;
2469 }
2470
2471 /*******************************************************************
2472 inits a SAMR_Q_DELETE_DOM_GROUP structure.
2473 ********************************************************************/
2474
2475 void init_samr_q_delete_dom_group(SAMR_Q_DELETE_DOM_GROUP * q_c,
2476                                   POLICY_HND *hnd)
2477 {
2478         DEBUG(5, ("init_samr_q_delete_dom_group\n"));
2479
2480         q_c->group_pol = *hnd;
2481 }
2482
2483 /*******************************************************************
2484 reads or writes a structure.
2485 ********************************************************************/
2486
2487 BOOL samr_io_q_delete_dom_group(const char *desc, SAMR_Q_DELETE_DOM_GROUP * q_u,
2488                                 prs_struct *ps, int depth)
2489 {
2490         if (q_u == NULL)
2491                 return False;
2492
2493         prs_debug(ps, depth, desc, "samr_io_q_delete_dom_group");
2494         depth++;
2495
2496         if(!prs_align(ps))
2497                 return False;
2498
2499         if(!smb_io_pol_hnd("group_pol", &q_u->group_pol, ps, depth))
2500                 return False;
2501
2502         return True;
2503 }
2504
2505 /*******************************************************************
2506 reads or writes a structure.
2507 ********************************************************************/
2508
2509 BOOL samr_io_r_delete_dom_group(const char *desc, SAMR_R_DELETE_DOM_GROUP * r_u,
2510                                 prs_struct *ps, int depth)
2511 {
2512         if (r_u == NULL)
2513                 return False;
2514
2515         prs_debug(ps, depth, desc, "samr_io_r_delete_dom_group");
2516         depth++;
2517
2518         if(!prs_align(ps))
2519                 return False;
2520
2521         if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
2522                 return False;
2523
2524         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2525                 return False;
2526
2527         return True;
2528 }
2529
2530 /*******************************************************************
2531 inits a SAMR_Q_DEL_GROUPMEM structure.
2532 ********************************************************************/
2533
2534 void init_samr_q_del_groupmem(SAMR_Q_DEL_GROUPMEM * q_e,
2535                               POLICY_HND *pol, uint32 rid)
2536 {
2537         DEBUG(5, ("init_samr_q_del_groupmem\n"));
2538
2539         q_e->pol = *pol;
2540         q_e->rid = rid;
2541 }
2542
2543 /*******************************************************************
2544 reads or writes a structure.
2545 ********************************************************************/
2546
2547 BOOL samr_io_q_del_groupmem(const char *desc, SAMR_Q_DEL_GROUPMEM * q_e,
2548                             prs_struct *ps, int depth)
2549 {
2550         if (q_e == NULL)
2551                 return False;
2552
2553         prs_debug(ps, depth, desc, "samr_io_q_del_groupmem");
2554         depth++;
2555
2556         if(!prs_align(ps))
2557                 return False;
2558
2559         if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
2560                 return False;
2561
2562         if(!prs_uint32("rid", ps, depth, &q_e->rid))
2563                 return False;
2564
2565         return True;
2566 }
2567
2568 /*******************************************************************
2569 inits a SAMR_R_DEL_GROUPMEM structure.
2570 ********************************************************************/
2571
2572 void init_samr_r_del_groupmem(SAMR_R_DEL_GROUPMEM * r_u, POLICY_HND *pol,
2573                               NTSTATUS status)
2574 {
2575         DEBUG(5, ("init_samr_r_del_groupmem\n"));
2576
2577         r_u->status = status;
2578 }
2579
2580 /*******************************************************************
2581 reads or writes a structure.
2582 ********************************************************************/
2583
2584 BOOL samr_io_r_del_groupmem(const char *desc, SAMR_R_DEL_GROUPMEM * r_u,
2585                             prs_struct *ps, int depth)
2586 {
2587         if (r_u == NULL)
2588                 return False;
2589
2590         prs_debug(ps, depth, desc, "samr_io_r_del_groupmem");
2591         depth++;
2592
2593         if(!prs_align(ps))
2594                 return False;
2595
2596         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2597                 return False;
2598
2599         return True;
2600 }
2601
2602 /*******************************************************************
2603 inits a SAMR_Q_ADD_GROUPMEM structure.
2604 ********************************************************************/
2605
2606 void init_samr_q_add_groupmem(SAMR_Q_ADD_GROUPMEM * q_e,
2607                               POLICY_HND *pol, uint32 rid)
2608 {
2609         DEBUG(5, ("init_samr_q_add_groupmem\n"));
2610
2611         q_e->pol = *pol;
2612         q_e->rid = rid;
2613         q_e->unknown = 0x0005;
2614 }
2615
2616 /*******************************************************************
2617 reads or writes a structure.
2618 ********************************************************************/
2619
2620 BOOL samr_io_q_add_groupmem(const char *desc, SAMR_Q_ADD_GROUPMEM * q_e,
2621                             prs_struct *ps, int depth)
2622 {
2623         if (q_e == NULL)
2624                 return False;
2625
2626         prs_debug(ps, depth, desc, "samr_io_q_add_groupmem");
2627         depth++;
2628
2629         if(!prs_align(ps))
2630                 return False;
2631
2632         if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
2633                 return False;
2634
2635         if(!prs_uint32("rid    ", ps, depth, &q_e->rid))
2636                 return False;
2637         if(!prs_uint32("unknown", ps, depth, &q_e->unknown))
2638                 return False;
2639
2640         return True;
2641 }
2642
2643 /*******************************************************************
2644 inits a SAMR_R_ADD_GROUPMEM structure.
2645 ********************************************************************/
2646
2647 void init_samr_r_add_groupmem(SAMR_R_ADD_GROUPMEM * r_u, POLICY_HND *pol,
2648                               NTSTATUS status)
2649 {
2650         DEBUG(5, ("init_samr_r_add_groupmem\n"));
2651
2652         r_u->status = status;
2653 }
2654
2655 /*******************************************************************
2656 reads or writes a structure.
2657 ********************************************************************/
2658
2659 BOOL samr_io_r_add_groupmem(const char *desc, SAMR_R_ADD_GROUPMEM * r_u,
2660                             prs_struct *ps, int depth)
2661 {
2662         if (r_u == NULL)
2663                 return False;
2664
2665         prs_debug(ps, depth, desc, "samr_io_r_add_groupmem");
2666         depth++;
2667
2668         if(!prs_align(ps))
2669                 return False;
2670
2671         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2672                 return False;
2673
2674         return True;
2675 }
2676
2677 /*******************************************************************
2678 inits a SAMR_Q_SET_GROUPINFO structure.
2679 ********************************************************************/
2680
2681 void init_samr_q_set_groupinfo(SAMR_Q_SET_GROUPINFO * q_e,
2682                                POLICY_HND *pol, GROUP_INFO_CTR * ctr)
2683 {
2684         DEBUG(5, ("init_samr_q_set_groupinfo\n"));
2685
2686         q_e->pol = *pol;
2687         q_e->ctr = ctr;
2688 }
2689
2690 /*******************************************************************
2691 reads or writes a structure.
2692 ********************************************************************/
2693
2694 BOOL samr_io_q_set_groupinfo(const char *desc, SAMR_Q_SET_GROUPINFO * q_e,
2695                              prs_struct *ps, int depth)
2696 {
2697         if (q_e == NULL)
2698                 return False;
2699
2700         prs_debug(ps, depth, desc, "samr_io_q_set_groupinfo");
2701         depth++;
2702
2703         if(!prs_align(ps))
2704                 return False;
2705
2706         if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
2707                 return False;
2708         
2709         if(!samr_group_info_ctr("ctr", &q_e->ctr, ps, depth))
2710                 return False;
2711
2712         return True;
2713 }
2714
2715 /*******************************************************************
2716 inits a SAMR_R_SET_GROUPINFO structure.
2717 ********************************************************************/
2718
2719 void init_samr_r_set_groupinfo(SAMR_R_SET_GROUPINFO * r_u, NTSTATUS status)
2720 {
2721         DEBUG(5, ("init_samr_r_set_groupinfo\n"));
2722
2723         r_u->status = status;
2724 }
2725
2726 /*******************************************************************
2727 reads or writes a structure.
2728 ********************************************************************/
2729
2730 BOOL samr_io_r_set_groupinfo(const char *desc, SAMR_R_SET_GROUPINFO * r_u,
2731                              prs_struct *ps, int depth)
2732 {
2733         if (r_u == NULL)
2734                 return False;
2735
2736         prs_debug(ps, depth, desc, "samr_io_r_set_groupinfo");
2737         depth++;
2738
2739         if(!prs_align(ps))
2740                 return False;
2741
2742         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2743                 return False;
2744
2745         return True;
2746 }
2747
2748 /*******************************************************************
2749 inits a SAMR_Q_QUERY_GROUPINFO structure.
2750 ********************************************************************/
2751
2752 void init_samr_q_query_groupinfo(SAMR_Q_QUERY_GROUPINFO * q_e,
2753                                  POLICY_HND *pol, uint16 switch_level)
2754 {
2755         DEBUG(5, ("init_samr_q_query_groupinfo\n"));
2756
2757         q_e->pol = *pol;
2758
2759         q_e->switch_level = switch_level;
2760 }
2761
2762 /*******************************************************************
2763 reads or writes a structure.
2764 ********************************************************************/
2765
2766 BOOL samr_io_q_query_groupinfo(const char *desc, SAMR_Q_QUERY_GROUPINFO * q_e,
2767                                prs_struct *ps, int depth)
2768 {
2769         if (q_e == NULL)
2770                 return False;
2771
2772         prs_debug(ps, depth, desc, "samr_io_q_query_groupinfo");
2773         depth++;
2774
2775         if(!prs_align(ps))
2776                 return False;
2777
2778         if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
2779                 return False;
2780
2781         if(!prs_uint16("switch_level", ps, depth, &q_e->switch_level))
2782                 return False;
2783
2784         return True;
2785 }
2786
2787 /*******************************************************************
2788 inits a SAMR_R_QUERY_GROUPINFO structure.
2789 ********************************************************************/
2790
2791 void init_samr_r_query_groupinfo(SAMR_R_QUERY_GROUPINFO * r_u,
2792                                  GROUP_INFO_CTR * ctr, NTSTATUS status)
2793 {
2794         DEBUG(5, ("init_samr_r_query_groupinfo\n"));
2795
2796         r_u->ptr = (NT_STATUS_IS_OK(status) && ctr != NULL) ? 1 : 0;
2797         r_u->ctr = ctr;
2798         r_u->status = status;
2799 }
2800
2801 /*******************************************************************
2802 reads or writes a structure.
2803 ********************************************************************/
2804
2805 BOOL samr_io_r_query_groupinfo(const char *desc, SAMR_R_QUERY_GROUPINFO * r_u,
2806                                prs_struct *ps, int depth)
2807 {
2808         if (r_u == NULL)
2809                 return False;
2810
2811         prs_debug(ps, depth, desc, "samr_io_r_query_groupinfo");
2812         depth++;
2813
2814         if(!prs_align(ps))
2815                 return False;
2816
2817         if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
2818                 return False;
2819
2820         if (r_u->ptr != 0) {
2821                 if(!samr_group_info_ctr("ctr", &r_u->ctr, ps, depth))
2822                         return False;
2823         }
2824
2825         if(!prs_align(ps))
2826                 return False;
2827         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2828                 return False;
2829
2830         return True;
2831 }
2832
2833 /*******************************************************************
2834 inits a SAMR_Q_QUERY_GROUPMEM structure.
2835 ********************************************************************/
2836
2837 void init_samr_q_query_groupmem(SAMR_Q_QUERY_GROUPMEM * q_c, POLICY_HND *hnd)
2838 {
2839         DEBUG(5, ("init_samr_q_query_groupmem\n"));
2840
2841         q_c->group_pol = *hnd;
2842 }
2843
2844 /*******************************************************************
2845 reads or writes a structure.
2846 ********************************************************************/
2847
2848 BOOL samr_io_q_query_groupmem(const char *desc, SAMR_Q_QUERY_GROUPMEM * q_u,
2849                               prs_struct *ps, int depth)
2850 {
2851         if (q_u == NULL)
2852                 return False;
2853
2854         prs_debug(ps, depth, desc, "samr_io_q_query_groupmem");
2855         depth++;
2856
2857         if(!prs_align(ps))
2858                 return False;
2859
2860         if(!smb_io_pol_hnd("group_pol", &q_u->group_pol, ps, depth))
2861                 return False;
2862
2863         return True;
2864 }
2865
2866 /*******************************************************************
2867 inits a SAMR_R_QUERY_GROUPMEM structure.
2868 ********************************************************************/
2869
2870 void init_samr_r_query_groupmem(SAMR_R_QUERY_GROUPMEM * r_u,
2871                                 uint32 num_entries, uint32 *rid,
2872                                 uint32 *attr, NTSTATUS status)
2873 {
2874         DEBUG(5, ("init_samr_r_query_groupmem\n"));
2875
2876         if (NT_STATUS_IS_OK(status)) {
2877                 r_u->ptr = 1;
2878                 r_u->num_entries = num_entries;
2879
2880                 r_u->ptr_attrs = attr != NULL ? 1 : 0;
2881                 r_u->ptr_rids = rid != NULL ? 1 : 0;
2882
2883                 r_u->num_rids = num_entries;
2884                 r_u->rid = rid;
2885
2886                 r_u->num_attrs = num_entries;
2887                 r_u->attr = attr;
2888         } else {
2889                 r_u->ptr = 0;
2890                 r_u->num_entries = 0;
2891         }
2892
2893         r_u->status = status;
2894 }
2895
2896 /*******************************************************************
2897 reads or writes a structure.
2898 ********************************************************************/
2899
2900 BOOL samr_io_r_query_groupmem(const char *desc, SAMR_R_QUERY_GROUPMEM * r_u,
2901                               prs_struct *ps, int depth)
2902 {
2903         uint32 i;
2904
2905         if (r_u == NULL)
2906                 return False;
2907
2908         if (UNMARSHALLING(ps))
2909                 ZERO_STRUCTP(r_u);
2910
2911         prs_debug(ps, depth, desc, "samr_io_r_query_groupmem");
2912         depth++;
2913
2914         if(!prs_align(ps))
2915                 return False;
2916
2917         if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
2918                 return False;
2919         if(!prs_uint32("num_entries ", ps, depth, &r_u->num_entries))
2920                 return False;
2921
2922         if (r_u->ptr != 0) {
2923                 if(!prs_uint32("ptr_rids ", ps, depth, &r_u->ptr_rids))
2924                         return False;
2925                 if(!prs_uint32("ptr_attrs", ps, depth, &r_u->ptr_attrs))
2926                         return False;
2927
2928                 if (r_u->ptr_rids != 0) {
2929                         if(!prs_uint32("num_rids", ps, depth, &r_u->num_rids))
2930                                 return False;
2931                         if (UNMARSHALLING(ps) && r_u->num_rids != 0) {
2932                                 r_u->rid = (uint32 *)prs_alloc_mem(ps,sizeof(r_u->rid[0])*r_u->num_rids);
2933                                 if (r_u->rid == NULL)
2934                                         return False;
2935                         }
2936
2937                         for (i = 0; i < r_u->num_rids; i++) {
2938                                 if(!prs_uint32("", ps, depth, &r_u->rid[i]))
2939                                         return False;
2940                         }
2941                 }
2942
2943                 if (r_u->ptr_attrs != 0) {
2944                         if(!prs_uint32("num_attrs", ps, depth, &r_u->num_attrs))
2945                                 return False;
2946
2947                         if (UNMARSHALLING(ps) && r_u->num_attrs != 0) {
2948                                 r_u->attr = (uint32 *)prs_alloc_mem(ps,sizeof(r_u->attr[0])*r_u->num_attrs);
2949                                 if (r_u->attr == NULL)
2950                                         return False;
2951                         }
2952
2953                         for (i = 0; i < r_u->num_attrs; i++) {
2954                                 if(!prs_uint32("", ps, depth, &r_u->attr[i]))
2955                                         return False;
2956                         }
2957                 }
2958         }
2959
2960         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2961                 return False;
2962
2963         return True;
2964 }
2965
2966 /*******************************************************************
2967 inits a SAMR_Q_QUERY_USERGROUPS structure.
2968 ********************************************************************/
2969
2970 void init_samr_q_query_usergroups(SAMR_Q_QUERY_USERGROUPS * q_u,
2971                                   POLICY_HND *hnd)
2972 {
2973         DEBUG(5, ("init_samr_q_query_usergroups\n"));
2974
2975         q_u->pol = *hnd;
2976 }
2977
2978 /*******************************************************************
2979 reads or writes a structure.
2980 ********************************************************************/
2981
2982 BOOL samr_io_q_query_usergroups(const char *desc, SAMR_Q_QUERY_USERGROUPS * q_u,
2983                                 prs_struct *ps, int depth)
2984 {
2985         if (q_u == NULL)
2986                 return False;
2987
2988         prs_debug(ps, depth, desc, "samr_io_q_query_usergroups");
2989         depth++;
2990
2991         if(!prs_align(ps))
2992                 return False;
2993
2994         if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
2995                 return False;
2996
2997         return True;
2998 }
2999
3000 /*******************************************************************
3001 inits a SAMR_R_QUERY_USERGROUPS structure.
3002 ********************************************************************/
3003
3004 void init_samr_r_query_usergroups(SAMR_R_QUERY_USERGROUPS * r_u,
3005                                   uint32 num_gids, DOM_GID * gid,
3006                                   NTSTATUS status)
3007 {
3008         DEBUG(5, ("init_samr_r_query_usergroups\n"));
3009
3010         if (NT_STATUS_IS_OK(status)) {
3011                 r_u->ptr_0 = 1;
3012                 r_u->num_entries = num_gids;
3013                 r_u->ptr_1 = (num_gids != 0) ? 1 : 0;
3014                 r_u->num_entries2 = num_gids;
3015
3016                 r_u->gid = gid;
3017         } else {
3018                 r_u->ptr_0 = 0;
3019                 r_u->num_entries = 0;
3020                 r_u->ptr_1 = 0;
3021                 r_u->gid = NULL;
3022         }
3023
3024         r_u->status = status;
3025 }
3026
3027 /*******************************************************************
3028 reads or writes a structure.
3029 ********************************************************************/
3030
3031 BOOL samr_io_gids(const char *desc, uint32 *num_gids, DOM_GID ** gid,
3032                   prs_struct *ps, int depth)
3033 {
3034         uint32 i;
3035         if (gid == NULL)
3036                 return False;
3037
3038         prs_debug(ps, depth, desc, "samr_io_gids");
3039         depth++;
3040
3041         if(!prs_align(ps))
3042                 return False;
3043
3044         if(!prs_uint32("num_gids", ps, depth, num_gids))
3045                 return False;
3046
3047         if ((*num_gids) != 0) {
3048                 if (UNMARSHALLING(ps)) {
3049                         (*gid) = (DOM_GID *)prs_alloc_mem(ps,sizeof(DOM_GID)*(*num_gids));
3050                 }
3051
3052                 if ((*gid) == NULL) {
3053                         return False;
3054                 }
3055
3056                 for (i = 0; i < (*num_gids); i++) {
3057                         if(!smb_io_gid("gids", &(*gid)[i], ps, depth))
3058                                 return False;
3059                 }
3060         }
3061
3062         return True;
3063 }
3064
3065 /*******************************************************************
3066 reads or writes a structure.
3067 ********************************************************************/
3068
3069 BOOL samr_io_r_query_usergroups(const char *desc, SAMR_R_QUERY_USERGROUPS * r_u,
3070                                 prs_struct *ps, int depth)
3071 {
3072         if (r_u == NULL)
3073                 return False;
3074
3075         prs_debug(ps, depth, desc, "samr_io_r_query_usergroups");
3076         depth++;
3077
3078         if(!prs_align(ps))
3079                 return False;
3080
3081         if(!prs_uint32("ptr_0       ", ps, depth, &r_u->ptr_0))
3082                 return False;
3083
3084         if (r_u->ptr_0 != 0) {
3085                 if(!prs_uint32("num_entries ", ps, depth, &r_u->num_entries))
3086                         return False;
3087                 if(!prs_uint32("ptr_1       ", ps, depth, &r_u->ptr_1))
3088                         return False;
3089
3090                 if (r_u->num_entries != 0 && r_u->ptr_1 != 0) {
3091                         if(!samr_io_gids("gids", &r_u->num_entries2, &r_u->gid, ps, depth))
3092                                 return False;
3093                 }
3094         }
3095
3096         if(!prs_align(ps))
3097                 return False;
3098         if(!prs_ntstatus("status", ps, depth, &r_u->status))
3099           return False;
3100
3101         return True;
3102 }
3103
3104 /*******************************************************************
3105 inits a SAMR_Q_ENUM_DOMAINS structure.
3106 ********************************************************************/
3107
3108 void init_samr_q_enum_domains(SAMR_Q_ENUM_DOMAINS * q_e,
3109                               POLICY_HND *pol,
3110                               uint32 start_idx, uint32 size)
3111 {
3112         DEBUG(5, ("init_samr_q_enum_domains\n"));
3113
3114         q_e->pol = *pol;
3115
3116         q_e->start_idx = start_idx;
3117         q_e->max_size = size;
3118 }
3119
3120 /*******************************************************************
3121 reads or writes a structure.
3122 ********************************************************************/
3123
3124 BOOL samr_io_q_enum_domains(const char *desc, SAMR_Q_ENUM_DOMAINS * q_e,
3125                             prs_struct *ps, int depth)
3126 {
3127         if (q_e == NULL)
3128                 return False;
3129
3130         prs_debug(ps, depth, desc, "samr_io_q_enum_domains");
3131         depth++;
3132
3133         if(!prs_align(ps))
3134                 return False;
3135
3136         if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
3137                 return False;
3138
3139         if(!prs_uint32("start_idx", ps, depth, &q_e->start_idx))
3140                 return False;
3141         if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
3142                 return False;
3143
3144         return True;
3145 }
3146
3147 /*******************************************************************
3148 inits a SAMR_R_ENUM_DOMAINS structure.
3149 ********************************************************************/
3150
3151 void init_samr_r_enum_domains(SAMR_R_ENUM_DOMAINS * r_u,
3152                               uint32 next_idx, uint32 num_sam_entries)
3153 {
3154         DEBUG(5, ("init_samr_r_enum_domains\n"));
3155
3156         r_u->next_idx = next_idx;
3157
3158         if (num_sam_entries != 0) {
3159                 r_u->ptr_entries1 = 1;
3160                 r_u->ptr_entries2 = 1;
3161                 r_u->num_entries2 = num_sam_entries;
3162                 r_u->num_entries3 = num_sam_entries;
3163
3164                 r_u->num_entries4 = num_sam_entries;
3165         } else {
3166                 r_u->ptr_entries1 = 0;
3167                 r_u->num_entries2 = num_sam_entries;
3168                 r_u->ptr_entries2 = 1;
3169         }
3170 }
3171
3172 /*******************************************************************
3173 reads or writes a structure.
3174 ********************************************************************/
3175
3176 BOOL samr_io_r_enum_domains(const char *desc, SAMR_R_ENUM_DOMAINS * r_u,
3177                             prs_struct *ps, int depth)
3178 {
3179         uint32 i;
3180
3181         if (r_u == NULL)
3182                 return False;
3183
3184         prs_debug(ps, depth, desc, "samr_io_r_enum_domains");
3185         depth++;
3186
3187         if(!prs_align(ps))
3188                 return False;
3189
3190         if(!prs_uint32("next_idx    ", ps, depth, &r_u->next_idx))
3191                 return False;
3192         if(!prs_uint32("ptr_entries1", ps, depth, &r_u->ptr_entries1))
3193                 return False;
3194
3195         if (r_u->ptr_entries1 != 0) {
3196                 if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
3197                         return False;
3198                 if(!prs_uint32("ptr_entries2", ps, depth, &r_u->ptr_entries2))
3199                         return False;
3200                 if(!prs_uint32("num_entries3", ps, depth, &r_u->num_entries3))
3201                         return False;
3202
3203                 if (UNMARSHALLING(ps)) {
3204                         r_u->sam = (SAM_ENTRY *)prs_alloc_mem(ps,sizeof(SAM_ENTRY)*r_u->num_entries2);
3205                         r_u->uni_dom_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2)*r_u->num_entries2);
3206                 }
3207
3208                 if ((r_u->sam == NULL || r_u->uni_dom_name == NULL) && r_u->num_entries2 != 0) {
3209                         DEBUG(0, ("NULL pointers in SAMR_R_ENUM_DOMAINS\n"));
3210                         r_u->num_entries4 = 0;
3211                         r_u->status = NT_STATUS_MEMORY_NOT_ALLOCATED;
3212                         return False;
3213                 }
3214
3215                 for (i = 0; i < r_u->num_entries2; i++) {
3216                         fstring tmp;
3217                         slprintf(tmp, sizeof(tmp) - 1, "dom[%d]", i);
3218                         if(!sam_io_sam_entry(tmp, &r_u->sam[i], ps, depth))
3219                                 return False;
3220                 }
3221
3222                 for (i = 0; i < r_u->num_entries2; i++) {
3223                         fstring tmp;
3224                         slprintf(tmp, sizeof(tmp) - 1, "dom[%d]", i);
3225                         if(!smb_io_unistr2(tmp, &r_u->uni_dom_name[i],
3226                                        r_u->sam[i].hdr_name.buffer, ps,
3227                                        depth))
3228                                 return False;
3229                 }
3230
3231         }
3232
3233         if(!prs_align(ps))
3234                 return False;
3235         if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4))
3236                 return False;
3237         if(!prs_ntstatus("status", ps, depth, &r_u->status))
3238                 return False;
3239
3240         return True;
3241 }
3242
3243 /*******************************************************************
3244 inits a SAMR_Q_ENUM_DOM_GROUPS structure.
3245 ********************************************************************/
3246
3247 void init_samr_q_enum_dom_groups(SAMR_Q_ENUM_DOM_GROUPS * q_e,
3248                                  POLICY_HND *pol,
3249                                  uint32 start_idx, uint32 size)
3250 {
3251         DEBUG(5, ("init_samr_q_enum_dom_groups\n"));
3252
3253         q_e->pol = *pol;
3254
3255         q_e->start_idx = start_idx;
3256         q_e->max_size = size;
3257 }
3258
3259 /*******************************************************************
3260 reads or writes a structure.
3261 ********************************************************************/
3262
3263 BOOL samr_io_q_enum_dom_groups(const char *desc, SAMR_Q_ENUM_DOM_GROUPS * q_e,
3264                                prs_struct *ps, int depth)
3265 {
3266         if (q_e == NULL)
3267                 return False;
3268
3269         prs_debug(ps, depth, desc, "samr_io_q_enum_dom_groups");
3270         depth++;
3271
3272         if(!prs_align(ps))
3273                 return False;
3274
3275         if(!smb_io_pol_hnd("pol", &(q_e->pol), ps, depth))
3276                 return False;
3277
3278         if(!prs_uint32("start_idx", ps, depth, &q_e->start_idx))
3279                 return False;
3280         if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
3281                 return False;
3282
3283         return True;
3284 }
3285
3286 /*******************************************************************
3287 inits a SAMR_R_ENUM_DOM_GROUPS structure.
3288 ********************************************************************/
3289
3290 void init_samr_r_enum_dom_groups(SAMR_R_ENUM_DOM_GROUPS * r_u,
3291                                  uint32 next_idx, uint32 num_sam_entries)
3292 {
3293         DEBUG(5, ("init_samr_r_enum_dom_groups\n"));
3294
3295         r_u->next_idx = next_idx;
3296
3297         if (num_sam_entries != 0) {
3298                 r_u->ptr_entries1 = 1;
3299                 r_u->ptr_entries2 = 1;
3300                 r_u->num_entries2 = num_sam_entries;
3301                 r_u->num_entries3 = num_sam_entries;
3302
3303                 r_u->num_entries4 = num_sam_entries;
3304         } else {
3305                 r_u->ptr_entries1 = 0;
3306                 r_u->num_entries2 = num_sam_entries;
3307                 r_u->ptr_entries2 = 1;
3308         }
3309 }
3310
3311 /*******************************************************************
3312 reads or writes a structure.
3313 ********************************************************************/
3314
3315 BOOL samr_io_r_enum_dom_groups(const char *desc, SAMR_R_ENUM_DOM_GROUPS * r_u,
3316                                prs_struct *ps, int depth)
3317 {
3318         uint32 i;
3319
3320         if (r_u == NULL)
3321                 return False;
3322
3323         prs_debug(ps, depth, desc, "samr_io_r_enum_dom_groups");
3324         depth++;
3325
3326         if(!prs_align(ps))
3327                 return False;
3328
3329         if(!prs_uint32("next_idx    ", ps, depth, &r_u->next_idx))
3330                 return False;
3331         if(!prs_uint32("ptr_entries1", ps, depth, &r_u->ptr_entries1))
3332                 return False;
3333
3334         if (r_u->ptr_entries1 != 0) {
3335                 if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
3336                         return False;
3337                 if(!prs_uint32("ptr_entries2", ps, depth, &r_u->ptr_entries2))
3338                         return False;
3339                 if(!prs_uint32("num_entries3", ps, depth, &r_u->num_entries3))
3340                         return False;
3341
3342                 if (UNMARSHALLING(ps)) {
3343                         r_u->sam = (SAM_ENTRY *)prs_alloc_mem(ps,sizeof(SAM_ENTRY)*r_u->num_entries2);
3344                         r_u->uni_grp_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2)*r_u->num_entries2);
3345                 }
3346
3347                 if ((r_u->sam == NULL || r_u->uni_grp_name == NULL) && r_u->num_entries2 != 0) {
3348                         DEBUG(0,
3349                               ("NULL pointers in SAMR_R_ENUM_DOM_GROUPS\n"));
3350                         r_u->num_entries4 = 0;
3351                         r_u->status = NT_STATUS_MEMORY_NOT_ALLOCATED;
3352                         return False;
3353                 }
3354
3355                 for (i = 0; i < r_u->num_entries2; i++) {
3356                         if(!sam_io_sam_entry("", &r_u->sam[i], ps, depth))
3357                                 return False;
3358                 }
3359
3360                 for (i = 0; i < r_u->num_entries2; i++) {
3361                         if(!smb_io_unistr2("", &r_u->uni_grp_name[i],
3362                                        r_u->sam[i].hdr_name.buffer, ps, depth))
3363                                 return False;
3364                 }
3365         }
3366
3367         if(!prs_align(ps))
3368                 return False;
3369         if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4))
3370                 return False;
3371         if(!prs_ntstatus("status", ps, depth, &r_u->status))
3372                 return False;
3373
3374         return True;
3375 }
3376
3377 /*******************************************************************
3378 inits a SAMR_Q_ENUM_DOM_ALIASES structure.
3379 ********************************************************************/
3380
3381 void init_samr_q_enum_dom_aliases(SAMR_Q_ENUM_DOM_ALIASES * q_e,
3382                                   POLICY_HND *pol, uint32 start_idx,
3383                                   uint32 size)
3384 {
3385         DEBUG(5, ("init_samr_q_enum_dom_aliases\n"));
3386
3387         q_e->pol = *pol;
3388
3389         q_e->start_idx = start_idx;
3390         q_e->max_size = size;
3391 }
3392
3393
3394 /*******************************************************************
3395 reads or writes a structure.
3396 ********************************************************************/
3397
3398 BOOL samr_io_q_enum_dom_aliases(const char *desc, SAMR_Q_ENUM_DOM_ALIASES * q_e,
3399                                 prs_struct *ps, int depth)
3400 {
3401         if (q_e == NULL)
3402                 return False;
3403
3404         prs_debug(ps, depth, desc, "samr_io_q_enum_dom_aliases");
3405         depth++;
3406
3407         if(!prs_align(ps))
3408                 return False;
3409
3410         if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
3411                 return False;
3412
3413         if(!prs_uint32("start_idx", ps, depth, &q_e->start_idx))
3414                 return False;
3415         if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
3416                 return False;
3417
3418         return True;
3419 }
3420
3421 /*******************************************************************
3422 inits a SAMR_R_ENUM_DOM_ALIASES structure.
3423 ********************************************************************/
3424
3425 void init_samr_r_enum_dom_aliases(SAMR_R_ENUM_DOM_ALIASES *r_u, uint32 next_idx, uint32 num_sam_entries)
3426 {
3427         DEBUG(5, ("init_samr_r_enum_dom_aliases\n"));
3428
3429         r_u->next_idx = next_idx;
3430
3431         if (num_sam_entries != 0) {
3432                 r_u->ptr_entries1 = 1;
3433                 r_u->ptr_entries2 = 1;
3434                 r_u->num_entries2 = num_sam_entries;
3435                 r_u->num_entries3 = num_sam_entries;
3436
3437                 r_u->num_entries4 = num_sam_entries;
3438         } else {
3439                 r_u->ptr_entries1 = 0;
3440                 r_u->num_entries2 = num_sam_entries;
3441                 r_u->ptr_entries2 = 1;
3442         }
3443 }
3444
3445 /*******************************************************************
3446 reads or writes a structure.
3447 ********************************************************************/
3448
3449 BOOL samr_io_r_enum_dom_aliases(const char *desc, SAMR_R_ENUM_DOM_ALIASES * r_u,
3450                                 prs_struct *ps, int depth)
3451 {
3452         uint32 i;
3453
3454         if (r_u == NULL)
3455                 return False;
3456
3457         prs_debug(ps, depth, desc, "samr_io_r_enum_dom_aliases");
3458         depth++;
3459
3460         if(!prs_align(ps))
3461                 return False;
3462
3463         if(!prs_uint32("next_idx    ", ps, depth, &r_u->next_idx))
3464                 return False;
3465         if(!prs_uint32("ptr_entries1", ps, depth, &r_u->ptr_entries1))
3466                 return False;
3467
3468         if (r_u->ptr_entries1 != 0) {
3469                 if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
3470                         return False;
3471                 if(!prs_uint32("ptr_entries2", ps, depth, &r_u->ptr_entries2))
3472                         return False;
3473                 if(!prs_uint32("num_entries3", ps, depth, &r_u->num_entries3))
3474                         return False;
3475
3476                 if (UNMARSHALLING(ps) && (r_u->num_entries2 > 0)) {
3477                         r_u->sam = (SAM_ENTRY *)prs_alloc_mem(ps,sizeof(SAM_ENTRY)*r_u->num_entries2);
3478                         r_u->uni_grp_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2)*r_u->num_entries2);
3479                 }
3480
3481                 if (r_u->num_entries2 != 0 && 
3482                     (r_u->sam == NULL || r_u->uni_grp_name == NULL)) {
3483                         DEBUG(0,("NULL pointers in SAMR_R_ENUM_DOM_ALIASES\n"));
3484                         r_u->num_entries4 = 0;
3485                         r_u->status = NT_STATUS_MEMORY_NOT_ALLOCATED;
3486                         return False;
3487                 }
3488
3489                 for (i = 0; i < r_u->num_entries2; i++) {
3490                         if(!sam_io_sam_entry("", &r_u->sam[i], ps, depth))
3491                                 return False;
3492                 }
3493
3494                 for (i = 0; i < r_u->num_entries2; i++) {
3495                         if(!smb_io_unistr2("", &r_u->uni_grp_name[i],
3496                                        r_u->sam[i].hdr_name.buffer, ps,
3497                                        depth))
3498                                 return False;
3499                 }
3500         }
3501
3502         if(!prs_align(ps))
3503                 return False;
3504         if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4))
3505                 return False;
3506         if(!prs_ntstatus("status", ps, depth, &r_u->status))
3507                 return False;
3508
3509         return True;
3510 }
3511
3512 /*******************************************************************
3513 inits a ALIAS_INFO1 structure.
3514 ********************************************************************/
3515
3516 void init_samr_alias_info1(ALIAS_INFO1 * al1, char *acct_name, uint32 num_member, char *acct_desc)
3517 {
3518         DEBUG(5, ("init_samr_alias_info1\n"));
3519
3520         init_unistr2(&al1->uni_acct_name, acct_name, UNI_FLAGS_NONE);
3521         init_uni_hdr(&al1->hdr_acct_name, &al1->uni_acct_name);
3522
3523         al1->num_member=num_member;
3524
3525         init_unistr2(&al1->uni_acct_desc, acct_desc, UNI_FLAGS_NONE);
3526         init_uni_hdr(&al1->hdr_acct_desc, &al1->uni_acct_name);
3527 }
3528
3529 /*******************************************************************
3530 reads or writes a structure.
3531 ********************************************************************/
3532
3533 BOOL samr_io_alias_info1(const char *desc, ALIAS_INFO1 * al1,
3534                          prs_struct *ps, int depth)
3535 {
3536         if (al1 == NULL)
3537                 return False;
3538
3539         prs_debug(ps, depth, desc, "samr_io_alias_info1");
3540         depth++;
3541
3542         if(!prs_align(ps))
3543                 return False;
3544
3545         if(!smb_io_unihdr("hdr_acct_name", &al1->hdr_acct_name, ps, depth))
3546                 return False;
3547         if(!prs_uint32("num_member", ps, depth, &al1->num_member))
3548                 return False;
3549         if(!smb_io_unihdr("hdr_acct_desc", &al1->hdr_acct_desc, ps, depth))
3550                 return False;
3551
3552         if(!smb_io_unistr2("uni_acct_name", &al1->uni_acct_name,
3553                        al1->hdr_acct_name.buffer, ps, depth))
3554                 return False;
3555
3556         if(!prs_align(ps))
3557                 return False;
3558
3559         if(!smb_io_unistr2("uni_acct_desc", &al1->uni_acct_desc,
3560                        al1->hdr_acct_desc.buffer, ps, depth))
3561                 return False;
3562
3563         return True;
3564 }
3565
3566 /*******************************************************************
3567 inits a ALIAS_INFO3 structure.
3568 ********************************************************************/
3569
3570 void init_samr_alias_info3(ALIAS_INFO3 * al3, const char *acct_desc)
3571 {
3572         DEBUG(5, ("init_samr_alias_info3\n"));
3573
3574         init_unistr2(&al3->uni_acct_desc, acct_desc, UNI_FLAGS_NONE);
3575         init_uni_hdr(&al3->hdr_acct_desc, &al3->uni_acct_desc);
3576 }
3577
3578 /*******************************************************************
3579 reads or writes a structure.
3580 ********************************************************************/
3581
3582 BOOL samr_io_alias_info3(const char *desc, ALIAS_INFO3 * al3,
3583                          prs_struct *ps, int depth)
3584 {
3585         if (al3 == NULL)
3586                 return False;
3587
3588         prs_debug(ps, depth, desc, "samr_io_alias_info3");
3589         depth++;
3590
3591         if(!prs_align(ps))
3592                 return False;
3593
3594         if(!smb_io_unihdr("hdr_acct_desc", &al3->hdr_acct_desc, ps, depth))
3595                 return False;
3596         if(!smb_io_unistr2("uni_acct_desc", &al3->uni_acct_desc,
3597                        al3->hdr_acct_desc.buffer, ps, depth))
3598                 return False;
3599
3600         return True;
3601 }
3602
3603 /*******************************************************************
3604 reads or writes a structure.
3605 ********************************************************************/
3606
3607 BOOL samr_alias_info_ctr(const char *desc, ALIAS_INFO_CTR * ctr,
3608                          prs_struct *ps, int depth)
3609 {
3610         if (ctr == NULL)
3611                 return False;
3612
3613         prs_debug(ps, depth, desc, "samr_alias_info_ctr");
3614         depth++;
3615
3616         if(!prs_uint16("switch_value1", ps, depth, &ctr->switch_value1))
3617                 return False;
3618         if(!prs_uint16("switch_value2", ps, depth, &ctr->switch_value2))
3619                 return False;
3620
3621         switch (ctr->switch_value1) {
3622         case 1: 
3623                 if(!samr_io_alias_info1("alias_info1", &ctr->alias.info1, ps, depth))
3624                         return False;
3625                 break;
3626         case 3: 
3627                 if(!samr_io_alias_info3("alias_info3", &ctr->alias.info3, ps, depth))
3628                         return False;
3629                 break;
3630         default:
3631                 DEBUG(0,("samr_alias_info_ctr: unsupported switch level\n"));
3632                 break;
3633         }
3634
3635         return True;
3636 }
3637
3638 /*******************************************************************
3639 inits a SAMR_Q_QUERY_ALIASINFO structure.
3640 ********************************************************************/
3641
3642 void init_samr_q_query_aliasinfo(SAMR_Q_QUERY_ALIASINFO * q_e,
3643                                  POLICY_HND *pol, uint16 switch_level)
3644 {
3645         DEBUG(5, ("init_samr_q_query_aliasinfo\n"));
3646
3647         q_e->pol = *pol;
3648         q_e->switch_level = switch_level;
3649 }
3650
3651 /*******************************************************************
3652 reads or writes a structure.
3653 ********************************************************************/
3654
3655 BOOL samr_io_q_query_aliasinfo(const char *desc, SAMR_Q_QUERY_ALIASINFO * q_e,
3656                                prs_struct *ps, int depth)
3657 {
3658         if (q_e == NULL)
3659                 return False;
3660
3661         prs_debug(ps, depth, desc, "samr_io_q_query_aliasinfo");
3662         depth++;
3663
3664         if(!prs_align(ps))
3665                 return False;
3666
3667         if(!smb_io_pol_hnd("pol", &(q_e->pol), ps, depth))
3668                 return False;
3669
3670         if(!prs_uint16("switch_level", ps, depth, &q_e->switch_level))
3671                 return False;
3672
3673         return True;
3674 }
3675
3676 /*******************************************************************
3677 inits a SAMR_R_QUERY_ALIASINFO structure.
3678 ********************************************************************/
3679
3680 void init_samr_r_query_aliasinfo(SAMR_R_QUERY_ALIASINFO * r_u,
3681                                  ALIAS_INFO_CTR * ctr, NTSTATUS status)
3682 {
3683         DEBUG(5, ("init_samr_r_query_aliasinfo\n"));
3684
3685         r_u->ptr = (NT_STATUS_IS_OK(status) && ctr != NULL) ? 1 : 0;
3686         r_u->ctr = *ctr;
3687         r_u->status = status;
3688 }
3689
3690 /*******************************************************************
3691 reads or writes a structure.
3692 ********************************************************************/
3693
3694 BOOL samr_io_r_query_aliasinfo(const char *desc, SAMR_R_QUERY_ALIASINFO * r_u,
3695                                prs_struct *ps, int depth)
3696 {
3697         if (r_u == NULL)
3698                 return False;
3699
3700         prs_debug(ps, depth, desc, "samr_io_r_query_aliasinfo");
3701         depth++;
3702
3703         if(!prs_align(ps))
3704                 return False;
3705
3706         if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
3707                 return False;
3708
3709         if (r_u->ptr != 0) {
3710                 if(!samr_alias_info_ctr("ctr", &r_u->ctr, ps, depth))
3711                         return False;
3712         }
3713
3714         if(!prs_align(ps))
3715                 return False;
3716         if(!prs_ntstatus("status", ps, depth, &r_u->status))
3717                 return False;
3718
3719         return True;
3720 }
3721
3722 /*******************************************************************
3723 inits a SAMR_Q_SET_ALIASINFO structure.
3724 ********************************************************************/
3725
3726 void init_samr_q_set_aliasinfo(SAMR_Q_SET_ALIASINFO * q_u,
3727                                POLICY_HND *hnd, ALIAS_INFO_CTR * ctr)
3728 {
3729         DEBUG(5, ("init_samr_q_set_aliasinfo\n"));
3730
3731         q_u->alias_pol = *hnd;
3732         q_u->ctr = *ctr;
3733 }
3734
3735 /*******************************************************************
3736 reads or writes a structure.
3737 ********************************************************************/
3738
3739 BOOL samr_io_q_set_aliasinfo(const char *desc, SAMR_Q_SET_ALIASINFO * q_u,
3740                              prs_struct *ps, int depth)
3741 {
3742         if (q_u == NULL)
3743                 return False;
3744
3745         prs_debug(ps, depth, desc, "samr_io_q_set_aliasinfo");
3746         depth++;
3747
3748         if(!prs_align(ps))
3749                 return False;
3750
3751         if(!smb_io_pol_hnd("alias_pol", &q_u->alias_pol, ps, depth))
3752                 return False;
3753         if(!samr_alias_info_ctr("ctr", &q_u->ctr, ps, depth))
3754                 return False;
3755
3756         return True;
3757 }
3758
3759 /*******************************************************************
3760 reads or writes a structure.
3761 ********************************************************************/
3762
3763 BOOL samr_io_r_set_aliasinfo(const char *desc, SAMR_R_SET_ALIASINFO * r_u,
3764                              prs_struct *ps, int depth)
3765 {
3766         if (r_u == NULL)
3767                 return False;
3768
3769         prs_debug(ps, depth, desc, "samr_io_r_set_aliasinfo");
3770         depth++;
3771
3772         if(!prs_align(ps))
3773                 return False;
3774         if(!prs_ntstatus("status", ps, depth, &r_u->status))
3775                 return False;
3776
3777         return True;
3778 }
3779
3780 /*******************************************************************
3781 inits a SAMR_Q_QUERY_USERALIASES structure.
3782 ********************************************************************/
3783
3784 void init_samr_q_query_useraliases(SAMR_Q_QUERY_USERALIASES * q_u,
3785                                    POLICY_HND *hnd,
3786                                    uint32 num_sids,
3787                                    uint32 *ptr_sid, DOM_SID2 * sid)
3788 {
3789         DEBUG(5, ("init_samr_q_query_useraliases\n"));
3790
3791         q_u->pol = *hnd;
3792
3793         q_u->num_sids1 = num_sids;
3794         q_u->ptr = 1;
3795         q_u->num_sids2 = num_sids;
3796
3797         q_u->ptr_sid = ptr_sid;
3798         q_u->sid = sid;
3799 }
3800
3801 /*******************************************************************
3802 reads or writes a SAMR_Q_QUERY_USERALIASES structure.
3803 ********************************************************************/
3804
3805 BOOL samr_io_q_query_useraliases(const char *desc, SAMR_Q_QUERY_USERALIASES * q_u,
3806                                  prs_struct *ps, int depth)
3807 {
3808         fstring tmp;
3809         uint32 i;
3810
3811         if (q_u == NULL)
3812                 return False;
3813
3814         prs_debug(ps, depth, desc, "samr_io_q_query_useraliases");
3815         depth++;
3816
3817         if(!prs_align(ps))
3818                 return False;
3819
3820         if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
3821                 return False;
3822
3823         if(!prs_uint32("num_sids1", ps, depth, &q_u->num_sids1))
3824                 return False;
3825         if(!prs_uint32("ptr      ", ps, depth, &q_u->ptr))
3826                 return False;
3827
3828         if (q_u->ptr==0)
3829                 return True;
3830
3831         if(!prs_uint32("num_sids2", ps, depth, &q_u->num_sids2))
3832                 return False;
3833
3834         if (UNMARSHALLING(ps) && (q_u->num_sids2 != 0)) {
3835                 q_u->ptr_sid = (uint32 *)prs_alloc_mem(ps,sizeof(q_u->ptr_sid[0])*q_u->num_sids2);
3836                 if (q_u->ptr_sid == NULL)
3837                         return False;
3838
3839                 q_u->sid = (DOM_SID2 *)prs_alloc_mem(ps, sizeof(q_u->sid[0]) * q_u->num_sids2);
3840                 if (q_u->sid == NULL)
3841                         return False;
3842         }
3843
3844         for (i = 0; i < q_u->num_sids2; i++) {
3845                 slprintf(tmp, sizeof(tmp) - 1, "ptr[%02d]", i);
3846                 if(!prs_uint32(tmp, ps, depth, &q_u->ptr_sid[i]))
3847                         return False;
3848         }
3849
3850         for (i = 0; i < q_u->num_sids2; i++) {
3851                 if (q_u->ptr_sid[i] != 0) {
3852                         slprintf(tmp, sizeof(tmp) - 1, "sid[%02d]", i);
3853                         if(!smb_io_dom_sid2(tmp, &q_u->sid[i], ps, depth))
3854                                 return False;
3855                 }
3856         }
3857
3858         return True;
3859 }
3860
3861 /*******************************************************************
3862 inits a SAMR_R_QUERY_USERALIASES structure.
3863 ********************************************************************/
3864
3865 void init_samr_r_query_useraliases(SAMR_R_QUERY_USERALIASES * r_u,
3866                                    uint32 num_rids, uint32 *rid,
3867                                    NTSTATUS status)
3868 {
3869         DEBUG(5, ("init_samr_r_query_useraliases\n"));
3870
3871         if (NT_STATUS_IS_OK(status)) {
3872                 r_u->num_entries = num_rids;
3873                 r_u->ptr = 1;
3874                 r_u->num_entries2 = num_rids;
3875
3876                 r_u->rid = rid;
3877         } else {
3878                 r_u->num_entries = 0;
3879                 r_u->ptr = 0;
3880                 r_u->num_entries2 = 0;
3881         }
3882
3883         r_u->status = status;
3884 }
3885
3886 /*******************************************************************
3887 reads or writes a structure.
3888 ********************************************************************/
3889
3890 BOOL samr_io_rids(const char *desc, uint32 *num_rids, uint32 **rid,
3891                   prs_struct *ps, int depth)
3892 {
3893         fstring tmp;
3894         uint32 i;
3895         if (rid == NULL)
3896                 return False;
3897
3898         prs_debug(ps, depth, desc, "samr_io_rids");
3899         depth++;
3900
3901         if(!prs_align(ps))
3902                 return False;
3903
3904         if(!prs_uint32("num_rids", ps, depth, num_rids))
3905                 return False;
3906
3907         if ((*num_rids) != 0) {
3908                 if (UNMARSHALLING(ps)) {
3909                         /* reading */
3910                         (*rid) = (uint32 *)prs_alloc_mem(ps,sizeof(uint32)*(*num_rids));
3911                 }
3912                 if ((*rid) == NULL)
3913                         return False;
3914
3915                 for (i = 0; i < (*num_rids); i++) {
3916                         slprintf(tmp, sizeof(tmp) - 1, "rid[%02d]", i);
3917                         if(!prs_uint32(tmp, ps, depth, &((*rid)[i])))
3918                                 return False;
3919                 }
3920         }
3921
3922         return True;
3923 }
3924
3925 /*******************************************************************
3926 reads or writes a structure.
3927 ********************************************************************/
3928
3929 BOOL samr_io_r_query_useraliases(const char *desc, SAMR_R_QUERY_USERALIASES * r_u,
3930                                  prs_struct *ps, int depth)
3931 {
3932         if (r_u == NULL)
3933                 return False;
3934
3935         prs_debug(ps, depth, desc, "samr_io_r_query_useraliases");
3936         depth++;
3937
3938         if(!prs_align(ps))
3939                 return False;
3940
3941         if(!prs_uint32("num_entries", ps, depth, &r_u->num_entries))
3942                 return False;
3943         if(!prs_uint32("ptr        ", ps, depth, &r_u->ptr))
3944                 return False;
3945
3946         if (r_u->ptr != 0) {
3947                 if(!samr_io_rids("rids", &r_u->num_entries2, &r_u->rid, ps, depth))
3948                         return False;
3949         }
3950
3951         if(!prs_align(ps))
3952                 return False;
3953         if(!prs_ntstatus("status", ps, depth, &r_u->status))
3954                 return False;
3955
3956         return True;
3957 }
3958
3959 /*******************************************************************
3960 inits a SAMR_Q_OPEN_ALIAS structure.
3961 ********************************************************************/
3962
3963 void init_samr_q_open_alias(SAMR_Q_OPEN_ALIAS * q_u, POLICY_HND *pol,
3964                             uint32 access_mask, uint32 rid)
3965 {
3966         DEBUG(5, ("init_samr_q_open_alias\n"));
3967
3968         q_u->dom_pol = *pol;
3969         q_u->access_mask = access_mask;
3970         q_u->rid_alias = rid;
3971 }
3972
3973 /*******************************************************************
3974 reads or writes a structure.
3975 ********************************************************************/
3976
3977 BOOL samr_io_q_open_alias(const char *desc, SAMR_Q_OPEN_ALIAS * q_u,
3978                           prs_struct *ps, int depth)
3979 {
3980         if (q_u == NULL)
3981                 return False;
3982
3983         prs_debug(ps, depth, desc, "samr_io_q_open_alias");
3984         depth++;
3985
3986         if(!prs_align(ps))
3987                 return False;
3988
3989         if(!smb_io_pol_hnd("domain_pol", &q_u->dom_pol, ps, depth))
3990                 return False;
3991
3992         if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
3993                 return False;
3994         if(!prs_uint32("rid_alias", ps, depth, &q_u->rid_alias))
3995                 return False;
3996
3997         return True;
3998 }
3999
4000 /*******************************************************************
4001 reads or writes a structure.
4002 ********************************************************************/
4003
4004 BOOL samr_io_r_open_alias(const char *desc, SAMR_R_OPEN_ALIAS * r_u,
4005                           prs_struct *ps, int depth)
4006 {
4007         if (r_u == NULL)
4008                 return False;
4009
4010         prs_debug(ps, depth, desc, "samr_io_r_open_alias");
4011         depth++;
4012
4013         if(!prs_align(ps))
4014                 return False;
4015
4016         if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
4017                 return False;
4018
4019         if(!prs_ntstatus("status", ps, depth, &r_u->status))
4020                 return False;
4021
4022         return True;
4023 }
4024
4025 /*******************************************************************
4026 inits a SAMR_Q_LOOKUP_RIDS structure.
4027 ********************************************************************/
4028
4029 void init_samr_q_lookup_rids(TALLOC_CTX *ctx, SAMR_Q_LOOKUP_RIDS * q_u,
4030                              POLICY_HND *pol, uint32 flags,
4031                              uint32 num_rids, uint32 *rid)
4032 {
4033         DEBUG(5, ("init_samr_q_lookup_rids\n"));
4034
4035         q_u->pol = *pol;
4036
4037         q_u->num_rids1 = num_rids;
4038         q_u->flags = flags;
4039         q_u->ptr = 0;
4040         q_u->num_rids2 = num_rids;
4041         q_u->rid = (uint32 *)talloc_zero(ctx, num_rids * sizeof(q_u->rid[0]));
4042         if (q_u->rid == NULL) {
4043                 q_u->num_rids1 = 0;
4044                 q_u->num_rids2 = 0;
4045         } else {
4046                 memcpy(q_u->rid, rid, num_rids * sizeof(q_u->rid[0]));
4047         }
4048 }
4049
4050 /*******************************************************************
4051 reads or writes a structure.
4052 ********************************************************************/
4053
4054 BOOL samr_io_q_lookup_rids(const char *desc, SAMR_Q_LOOKUP_RIDS * q_u,
4055                            prs_struct *ps, int depth)
4056 {
4057         uint32 i;
4058         fstring tmp;
4059
4060         if (q_u == NULL)
4061                 return False;
4062
4063         prs_debug(ps, depth, desc, "samr_io_q_lookup_rids");
4064         depth++;
4065
4066         if (UNMARSHALLING(ps))
4067                 ZERO_STRUCTP(q_u);
4068
4069         if(!prs_align(ps))
4070                 return False;
4071
4072         if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
4073                 return False;
4074
4075         if(!prs_uint32("num_rids1", ps, depth, &q_u->num_rids1))
4076                 return False;
4077         if(!prs_uint32("flags    ", ps, depth, &q_u->flags))
4078                 return False;
4079         if(!prs_uint32("ptr      ", ps, depth, &q_u->ptr))
4080                 return False;
4081         if(!prs_uint32("num_rids2", ps, depth, &q_u->num_rids2))
4082                 return False;
4083
4084         if (UNMARSHALLING(ps) && (q_u->num_rids2 != 0)) {
4085                 q_u->rid = (uint32 *)prs_alloc_mem(ps, sizeof(q_u->rid[0])*q_u->num_rids2);
4086                 if (q_u->rid == NULL)
4087                         return False;
4088         }
4089
4090         for (i = 0; i < q_u->num_rids2; i++) {
4091                 slprintf(tmp, sizeof(tmp) - 1, "rid[%02d]  ", i);
4092                 if(!prs_uint32(tmp, ps, depth, &q_u->rid[i]))
4093                         return False;
4094         }
4095
4096         return True;
4097 }
4098
4099 /*******************************************************************
4100 inits a SAMR_R_LOOKUP_RIDS structure.
4101 ********************************************************************/
4102
4103 void init_samr_r_lookup_rids(SAMR_R_LOOKUP_RIDS * r_u,
4104                              uint32 num_names, UNIHDR * hdr_name,
4105                              UNISTR2 *uni_name, uint32 *type)
4106 {
4107         DEBUG(5, ("init_samr_r_lookup_rids\n"));
4108
4109         r_u->hdr_name = NULL;
4110         r_u->uni_name = NULL;
4111         r_u->type = NULL;
4112
4113         if (num_names != 0) {
4114                 r_u->num_names1 = num_names;
4115                 r_u->ptr_names = 1;
4116                 r_u->num_names2 = num_names;
4117
4118                 r_u->num_types1 = num_names;
4119                 r_u->ptr_types = 1;
4120                 r_u->num_types2 = num_names;
4121
4122                 r_u->hdr_name = hdr_name;
4123                 r_u->uni_name = uni_name;
4124                 r_u->type = type;
4125         } else {
4126                 r_u->num_names1 = num_names;
4127                 r_u->ptr_names = 0;
4128                 r_u->num_names2 = num_names;
4129
4130                 r_u->num_types1 = num_names;
4131                 r_u->ptr_types = 0;
4132                 r_u->num_types2 = num_names;
4133         }
4134 }
4135
4136 /*******************************************************************
4137 reads or writes a structure.
4138 ********************************************************************/
4139
4140 BOOL samr_io_r_lookup_rids(const char *desc, SAMR_R_LOOKUP_RIDS * r_u,
4141                            prs_struct *ps, int depth)
4142 {
4143         uint32 i;
4144         fstring tmp;
4145         if (r_u == NULL)
4146                 return False;
4147
4148         prs_debug(ps, depth, desc, "samr_io_r_lookup_rids");
4149         depth++;
4150
4151         if(!prs_align(ps))
4152                 return False;
4153
4154         if(!prs_uint32("num_names1", ps, depth, &r_u->num_names1))
4155                 return False;
4156         if(!prs_uint32("ptr_names ", ps, depth, &r_u->ptr_names))
4157                 return False;
4158
4159         if (r_u->ptr_names != 0) {
4160
4161                 if(!prs_uint32("num_names2", ps, depth, &r_u->num_names2))
4162                         return False;
4163
4164
4165                 if (UNMARSHALLING(ps) && (r_u->num_names2 != 0)) {
4166                         r_u->hdr_name = (UNIHDR *) prs_alloc_mem(ps, r_u->num_names2 * sizeof(r_u->hdr_name[0]));
4167                         if (r_u->hdr_name == NULL)
4168                                 return False;
4169
4170                         r_u->uni_name = (UNISTR2 *)prs_alloc_mem(ps, r_u->num_names2 * sizeof(r_u->uni_name[0]));
4171                         if (r_u->uni_name == NULL)
4172                                 return False;
4173                 }
4174                 
4175                 for (i = 0; i < r_u->num_names2; i++) {
4176                         slprintf(tmp, sizeof(tmp) - 1, "hdr[%02d]  ", i);
4177                         if(!smb_io_unihdr("", &r_u->hdr_name[i], ps, depth))
4178                                 return False;
4179                 }
4180                 for (i = 0; i < r_u->num_names2; i++) {
4181                         slprintf(tmp, sizeof(tmp) - 1, "str[%02d]  ", i);
4182                         if(!smb_io_unistr2("", &r_u->uni_name[i], r_u->hdr_name[i].buffer, ps, depth))
4183                                 return False;
4184                 }
4185
4186         }
4187         
4188         if(!prs_align(ps))
4189                 return False;
4190         if(!prs_uint32("num_types1", ps, depth, &r_u->num_types1))
4191                 return False;
4192         if(!prs_uint32("ptr_types ", ps, depth, &r_u->ptr_types))
4193                 return False;
4194
4195         if (r_u->ptr_types != 0) {
4196
4197                 if(!prs_uint32("num_types2", ps, depth, &r_u->num_types2))
4198                         return False;
4199
4200                 if (UNMARSHALLING(ps) && (r_u->num_types2 != 0)) {
4201                         r_u->type = (uint32 *)prs_alloc_mem(ps, r_u->num_types2 * sizeof(r_u->type[0]));
4202                         if (r_u->type == NULL)
4203                                 return False;
4204                 }
4205
4206                 for (i = 0; i < r_u->num_types2; i++) {
4207                         slprintf(tmp, sizeof(tmp) - 1, "type[%02d]  ", i);
4208                         if(!prs_uint32(tmp, ps, depth, &r_u->type[i]))
4209                                 return False;
4210                 }
4211         }
4212
4213         if(!prs_ntstatus("status", ps, depth, &r_u->status))
4214                 return False;
4215
4216         return True;
4217 }
4218
4219 /*******************************************************************
4220 inits a SAMR_Q_OPEN_ALIAS structure.
4221 ********************************************************************/
4222
4223 void init_samr_q_delete_alias(SAMR_Q_DELETE_DOM_ALIAS * q_u, POLICY_HND *hnd)
4224 {
4225         DEBUG(5, ("init_samr_q_delete_alias\n"));
4226
4227         q_u->alias_pol = *hnd;
4228 }
4229
4230 /*******************************************************************
4231 reads or writes a structure.
4232 ********************************************************************/
4233
4234 BOOL samr_io_q_delete_alias(const char *desc, SAMR_Q_DELETE_DOM_ALIAS * q_u,
4235                             prs_struct *ps, int depth)
4236 {
4237         if (q_u == NULL)
4238                 return False;
4239
4240         prs_debug(ps, depth, desc, "samr_io_q_delete_alias");
4241         depth++;
4242
4243         if(!prs_align(ps))
4244                 return False;
4245
4246         if(!smb_io_pol_hnd("alias_pol", &q_u->alias_pol, ps, depth))
4247                 return False;
4248
4249         return True;
4250 }
4251
4252 /*******************************************************************
4253 reads or writes a structure.
4254 ********************************************************************/
4255
4256 BOOL samr_io_r_delete_alias(const char *desc, SAMR_R_DELETE_DOM_ALIAS * r_u,
4257                             prs_struct *ps, int depth)
4258 {
4259         if (r_u == NULL)
4260                 return False;
4261
4262         prs_debug(ps, depth, desc, "samr_io_r_delete_alias");
4263         depth++;
4264
4265         if(!prs_align(ps))
4266                 return False;
4267
4268         if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
4269                 return False;
4270         if(!prs_ntstatus("status", ps, depth, &r_u->status))
4271                 return False;
4272
4273         return True;
4274 }
4275
4276 /*******************************************************************
4277 inits a SAMR_Q_CREATE_DOM_ALIAS structure.
4278 ********************************************************************/
4279
4280 void init_samr_q_create_dom_alias(SAMR_Q_CREATE_DOM_ALIAS * q_u,
4281                                   POLICY_HND *hnd, const char *acct_desc)
4282 {
4283         DEBUG(5, ("init_samr_q_create_dom_alias\n"));
4284
4285         q_u->dom_pol = *hnd;
4286
4287         init_unistr2(&q_u->uni_acct_desc, acct_desc, UNI_FLAGS_NONE);
4288         init_uni_hdr(&q_u->hdr_acct_desc, &q_u->uni_acct_desc);
4289
4290         q_u->access_mask = MAXIMUM_ALLOWED_ACCESS;
4291 }
4292
4293 /*******************************************************************
4294 reads or writes a structure.
4295 ********************************************************************/
4296
4297 BOOL samr_io_q_create_dom_alias(const char *desc, SAMR_Q_CREATE_DOM_ALIAS * q_u,
4298                                 prs_struct *ps, int depth)
4299 {
4300         if (q_u == NULL)
4301                 return False;
4302
4303         prs_debug(ps, depth, desc, "samr_io_q_create_dom_alias");
4304         depth++;
4305
4306         if(!prs_align(ps))
4307                 return False;
4308
4309         if(!smb_io_pol_hnd("dom_pol", &q_u->dom_pol, ps, depth))
4310                 return False;
4311
4312         if(!smb_io_unihdr("hdr_acct_desc", &q_u->hdr_acct_desc, ps, depth))
4313                 return False;
4314         if(!smb_io_unistr2("uni_acct_desc", &q_u->uni_acct_desc,
4315                        q_u->hdr_acct_desc.buffer, ps, depth))
4316                 return False;
4317
4318         if(!prs_align(ps))
4319                 return False;
4320         if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
4321                 return False;
4322
4323         return True;
4324 }
4325
4326 /*******************************************************************
4327 reads or writes a structure.
4328 ********************************************************************/
4329
4330 BOOL samr_io_r_create_dom_alias(const char *desc, SAMR_R_CREATE_DOM_ALIAS * r_u,
4331                                 prs_struct *ps, int depth)
4332 {
4333         if (r_u == NULL)
4334                 return False;
4335
4336         prs_debug(ps, depth, desc, "samr_io_r_create_dom_alias");
4337         depth++;
4338
4339         if(!prs_align(ps))
4340                 return False;
4341
4342         if(!smb_io_pol_hnd("alias_pol", &r_u->alias_pol, ps, depth))
4343                 return False;
4344
4345         if(!prs_uint32("rid", ps, depth, &r_u->rid))
4346                 return False;
4347
4348         if(!prs_ntstatus("status", ps, depth, &r_u->status))
4349                 return False;
4350
4351         return True;
4352 }
4353
4354 /*******************************************************************
4355 inits a SAMR_Q_ADD_ALIASMEM structure.
4356 ********************************************************************/
4357
4358 void init_samr_q_add_aliasmem(SAMR_Q_ADD_ALIASMEM * q_u, POLICY_HND *hnd,
4359                               DOM_SID *sid)
4360 {
4361         DEBUG(5, ("init_samr_q_add_aliasmem\n"));
4362
4363         q_u->alias_pol = *hnd;
4364         init_dom_sid2(&q_u->sid, sid);
4365 }
4366
4367 /*******************************************************************
4368 reads or writes a structure.
4369 ********************************************************************/
4370
4371 BOOL samr_io_q_add_aliasmem(const char *desc, SAMR_Q_ADD_ALIASMEM * q_u,
4372                             prs_struct *ps, int depth)
4373 {
4374         if (q_u == NULL)
4375                 return False;
4376
4377         prs_debug(ps, depth, desc, "samr_io_q_add_aliasmem");
4378         depth++;
4379
4380         if(!prs_align(ps))
4381                 return False;
4382
4383         if(!smb_io_pol_hnd("alias_pol", &q_u->alias_pol, ps, depth))
4384                 return False;
4385         if(!smb_io_dom_sid2("sid      ", &q_u->sid, ps, depth))
4386                 return False;
4387
4388         return True;
4389 }
4390
4391 /*******************************************************************
4392 reads or writes a structure.
4393 ********************************************************************/
4394
4395 BOOL samr_io_r_add_aliasmem(const char *desc, SAMR_R_ADD_ALIASMEM * r_u,
4396                             prs_struct *ps, int depth)
4397 {
4398         if (r_u == NULL)
4399                 return False;
4400
4401         prs_debug(ps, depth, desc, "samr_io_r_add_aliasmem");
4402         depth++;
4403
4404         if(!prs_align(ps))
4405                 return False;
4406
4407         if(!prs_ntstatus("status", ps, depth, &r_u->status))
4408                 return False;
4409
4410         return True;
4411 }
4412
4413 /*******************************************************************
4414 inits a SAMR_Q_DEL_ALIASMEM structure.
4415 ********************************************************************/
4416
4417 void init_samr_q_del_aliasmem(SAMR_Q_DEL_ALIASMEM * q_u, POLICY_HND *hnd,
4418                               DOM_SID *sid)
4419 {
4420         DEBUG(5, ("init_samr_q_del_aliasmem\n"));
4421
4422         q_u->alias_pol = *hnd;
4423         init_dom_sid2(&q_u->sid, sid);
4424 }
4425
4426 /*******************************************************************
4427 reads or writes a structure.
4428 ********************************************************************/
4429
4430 BOOL samr_io_q_del_aliasmem(const char *desc, SAMR_Q_DEL_ALIASMEM * q_u,
4431                             prs_struct *ps, int depth)
4432 {
4433         if (q_u == NULL)
4434                 return False;
4435
4436         prs_debug(ps, depth, desc, "samr_io_q_del_aliasmem");
4437         depth++;
4438
4439         if(!prs_align(ps))
4440                 return False;
4441
4442         if(!smb_io_pol_hnd("alias_pol", &q_u->alias_pol, ps, depth))
4443                 return False;
4444         if(!smb_io_dom_sid2("sid      ", &q_u->sid, ps, depth))
4445                 return False;
4446
4447         return True;
4448 }
4449
4450 /*******************************************************************
4451 reads or writes a structure.
4452 ********************************************************************/
4453
4454 BOOL samr_io_r_del_aliasmem(const char *desc, SAMR_R_DEL_ALIASMEM * r_u,
4455                             prs_struct *ps, int depth)
4456 {
4457         if (r_u == NULL)
4458                 return False;
4459
4460         prs_debug(ps, depth, desc, "samr_io_r_del_aliasmem");
4461         depth++;
4462
4463         if(!prs_align(ps))
4464                 return False;
4465
4466         if(!prs_ntstatus("status", ps, depth, &r_u->status))
4467                 return False;
4468
4469         return True;
4470 }
4471
4472 /*******************************************************************
4473 inits a SAMR_Q_DELETE_DOM_ALIAS structure.
4474 ********************************************************************/
4475
4476 void init_samr_q_delete_dom_alias(SAMR_Q_DELETE_DOM_ALIAS * q_c,
4477                                   POLICY_HND *hnd)
4478 {
4479         DEBUG(5, ("init_samr_q_delete_dom_alias\n"));
4480
4481         q_c->alias_pol = *hnd;
4482 }
4483
4484 /*******************************************************************
4485 reads or writes a structure.
4486 ********************************************************************/
4487
4488 BOOL samr_io_q_delete_dom_alias(const char *desc, SAMR_Q_DELETE_DOM_ALIAS * q_u,
4489                                 prs_struct *ps, int depth)
4490 {
4491         if (q_u == NULL)
4492                 return False;
4493
4494         prs_debug(ps, depth, desc, "samr_io_q_delete_dom_alias");
4495         depth++;
4496
4497         if(!prs_align(ps))
4498                 return False;
4499
4500         if(!smb_io_pol_hnd("alias_pol", &q_u->alias_pol, ps, depth))
4501                 return False;
4502
4503         return True;
4504 }
4505
4506 /*******************************************************************
4507 inits a SAMR_R_DELETE_DOM_ALIAS structure.
4508 ********************************************************************/
4509
4510 void init_samr_r_delete_dom_alias(SAMR_R_DELETE_DOM_ALIAS * r_u,
4511                                   NTSTATUS status)
4512 {
4513         DEBUG(5, ("init_samr_r_delete_dom_alias\n"));
4514
4515         r_u->status = status;
4516 }
4517
4518 /*******************************************************************
4519 reads or writes a structure.
4520 ********************************************************************/
4521
4522 BOOL samr_io_r_delete_dom_alias(const char *desc, SAMR_R_DELETE_DOM_ALIAS * r_u,
4523                                 prs_struct *ps, int depth)
4524 {
4525         if (r_u == NULL)
4526                 return False;
4527
4528         prs_debug(ps, depth, desc, "samr_io_r_delete_dom_alias");
4529         depth++;
4530
4531         if(!prs_align(ps))
4532                 return False;
4533
4534         if(!prs_ntstatus("status", ps, depth, &r_u->status))
4535                 return False;
4536
4537         return True;
4538 }
4539
4540 /*******************************************************************
4541 inits a SAMR_Q_QUERY_ALIASMEM structure.
4542 ********************************************************************/
4543
4544 void init_samr_q_query_aliasmem(SAMR_Q_QUERY_ALIASMEM * q_c,
4545                                 POLICY_HND *hnd)
4546 {
4547         DEBUG(5, ("init_samr_q_query_aliasmem\n"));
4548
4549         q_c->alias_pol = *hnd;
4550 }
4551
4552 /*******************************************************************
4553 reads or writes a structure.
4554 ********************************************************************/
4555
4556 BOOL samr_io_q_query_aliasmem(const char *desc, SAMR_Q_QUERY_ALIASMEM * q_u,
4557                               prs_struct *ps, int depth)
4558 {
4559         if (q_u == NULL)
4560                 return False;
4561
4562         prs_debug(ps, depth, desc, "samr_io_q_query_aliasmem");
4563         depth++;
4564
4565         if(!prs_align(ps))
4566                 return False;
4567
4568         if(!smb_io_pol_hnd("alias_pol", &q_u->alias_pol, ps, depth))
4569                 return False;
4570
4571         return True;
4572 }
4573
4574 /*******************************************************************
4575 inits a SAMR_R_QUERY_ALIASMEM structure.
4576 ********************************************************************/
4577
4578 void init_samr_r_query_aliasmem(SAMR_R_QUERY_ALIASMEM * r_u,
4579                                 uint32 num_sids, DOM_SID2 * sid,
4580                                 NTSTATUS status)
4581 {
4582         DEBUG(5, ("init_samr_r_query_aliasmem\n"));
4583
4584         if (NT_STATUS_IS_OK(status)) {
4585                 r_u->num_sids = num_sids;
4586                 r_u->ptr = (num_sids != 0) ? 1 : 0;
4587                 r_u->num_sids1 = num_sids;
4588
4589                 r_u->sid = sid;
4590         } else {
4591                 r_u->ptr = 0;
4592                 r_u->num_sids = 0;
4593         }
4594
4595         r_u->status = status;
4596 }
4597
4598 /*******************************************************************
4599 reads or writes a structure.
4600 ********************************************************************/
4601
4602 BOOL samr_io_r_query_aliasmem(const char *desc, SAMR_R_QUERY_ALIASMEM * r_u,
4603                               prs_struct *ps, int depth)
4604 {
4605         uint32 i;
4606
4607         if (r_u == NULL)
4608                 return False;
4609
4610         prs_debug(ps, depth, desc, "samr_io_r_query_aliasmem");
4611         depth++;
4612
4613         if(!prs_align(ps))
4614                 return False;
4615
4616         if(!prs_uint32("num_sids ", ps, depth, &r_u->num_sids))
4617                 return False;
4618         if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
4619                 return False;
4620
4621         if (r_u->ptr != 0 && r_u->num_sids != 0) {
4622                 uint32 *ptr_sid = NULL;
4623
4624                 if(!prs_uint32("num_sids1", ps, depth, &r_u->num_sids1))
4625                         return False;
4626
4627                 ptr_sid = talloc(ps->mem_ctx, sizeof(uint32) * r_u->num_sids1);
4628                 if (!ptr_sid) {
4629                         return False;
4630                 }
4631                 
4632                 for (i = 0; i < r_u->num_sids1; i++) {
4633                         ptr_sid[i] = 1;
4634                         if(!prs_uint32("ptr_sid", ps, depth, &ptr_sid[i]))
4635                                 return False;
4636                 }
4637                 
4638                 if (UNMARSHALLING(ps)) {
4639                         r_u->sid = talloc(ps->mem_ctx, r_u->num_sids1 * sizeof(DOM_SID2));
4640                 }
4641                 
4642                 for (i = 0; i < r_u->num_sids1; i++) {
4643                         if (ptr_sid[i] != 0) {
4644                                 if(!smb_io_dom_sid2("sid", &r_u->sid[i], ps, depth))
4645                                         return False;
4646                         }
4647                 }
4648         }
4649
4650         if(!prs_align(ps))
4651                 return False;
4652         if(!prs_ntstatus("status", ps, depth, &r_u->status))
4653                 return False;
4654
4655         return True;
4656 }
4657
4658 /*******************************************************************
4659 inits a SAMR_Q_LOOKUP_NAMES structure.
4660 ********************************************************************/
4661
4662 NTSTATUS init_samr_q_lookup_names(TALLOC_CTX *ctx, SAMR_Q_LOOKUP_NAMES * q_u,
4663                               POLICY_HND *pol, uint32 flags,
4664                               uint32 num_names, const char **name)
4665 {
4666         uint32 i;
4667
4668         DEBUG(5, ("init_samr_q_lookup_names\n"));
4669
4670         q_u->pol = *pol;
4671
4672         q_u->num_names1 = num_names;
4673         q_u->flags = flags;
4674         q_u->ptr = 0;
4675         q_u->num_names2 = num_names;
4676
4677         if (!(q_u->hdr_name = (UNIHDR *)talloc_zero(ctx, num_names * sizeof(UNIHDR))))
4678                 return NT_STATUS_NO_MEMORY;
4679
4680         if (!(q_u->uni_name = (UNISTR2 *)talloc_zero(ctx, num_names * sizeof(UNISTR2))))
4681                 return NT_STATUS_NO_MEMORY;
4682
4683         for (i = 0; i < num_names; i++) {
4684                 init_unistr2(&q_u->uni_name[i], name[i], UNI_FLAGS_NONE);       /* unicode string for machine account */
4685                 init_uni_hdr(&q_u->hdr_name[i], &q_u->uni_name[i]);     /* unicode header for user_name */
4686         }
4687
4688         return NT_STATUS_OK;
4689 }
4690
4691 /*******************************************************************
4692 reads or writes a structure.
4693 ********************************************************************/
4694
4695 BOOL samr_io_q_lookup_names(const char *desc, SAMR_Q_LOOKUP_NAMES * q_u,
4696                             prs_struct *ps, int depth)
4697 {
4698         uint32 i;
4699
4700         if (q_u == NULL)
4701                 return False;
4702
4703         prs_debug(ps, depth, desc, "samr_io_q_lookup_names");
4704         depth++;
4705
4706         if (UNMARSHALLING(ps))
4707                 ZERO_STRUCTP(q_u);
4708
4709         if(!prs_align(ps))
4710                 return False;
4711
4712         if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
4713                 return False;
4714
4715         if(!prs_uint32("num_names1", ps, depth, &q_u->num_names1))
4716                 return False;
4717         if(!prs_uint32("flags     ", ps, depth, &q_u->flags))
4718                 return False;
4719         if(!prs_uint32("ptr       ", ps, depth, &q_u->ptr))
4720                 return False;
4721         if(!prs_uint32("num_names2", ps, depth, &q_u->num_names2))
4722                 return False;
4723
4724         if (UNMARSHALLING(ps) && (q_u->num_names2 != 0)) {
4725                 q_u->hdr_name = (UNIHDR *)prs_alloc_mem(ps, sizeof(UNIHDR) *
4726                                                         q_u->num_names2);
4727                 q_u->uni_name = (UNISTR2 *)prs_alloc_mem(ps, sizeof(UNISTR2) *
4728                                                          q_u->num_names2);
4729                 if (!q_u->hdr_name || !q_u->uni_name)
4730                         return False;
4731         }
4732
4733         for (i = 0; i < q_u->num_names2; i++) {
4734                 if(!smb_io_unihdr("", &q_u->hdr_name[i], ps, depth))
4735                         return False;
4736         }
4737
4738         for (i = 0; i < q_u->num_names2; i++) {
4739                 if(!smb_io_unistr2("", &q_u->uni_name[i], q_u->hdr_name[i].buffer, ps, depth))
4740                         return False;
4741         }
4742
4743         return True;
4744 }
4745
4746 /*******************************************************************
4747 inits a SAMR_R_LOOKUP_NAMES structure.
4748 ********************************************************************/
4749
4750 NTSTATUS init_samr_r_lookup_names(TALLOC_CTX *ctx, SAMR_R_LOOKUP_NAMES * r_u,
4751                               uint32 num_rids,
4752                               uint32 *rid, uint32 *type,
4753                               NTSTATUS status)
4754 {
4755         DEBUG(5, ("init_samr_r_lookup_names\n"));
4756
4757         if (NT_STATUS_IS_OK(status) && (num_rids != 0)) {
4758                 uint32 i;
4759
4760                 r_u->num_types1 = num_rids;
4761                 r_u->ptr_types = 1;
4762                 r_u->num_types2 = num_rids;
4763
4764                 r_u->num_rids1 = num_rids;
4765                 r_u->ptr_rids = 1;
4766                 r_u->num_rids2 = num_rids;
4767
4768                 if (!(r_u->rids = (uint32 *)talloc_zero(ctx, sizeof(uint32)*num_rids)))
4769                         return NT_STATUS_NO_MEMORY;
4770                 if (!(r_u->types = (uint32 *)talloc_zero(ctx, sizeof(uint32)*num_rids)))
4771                         return NT_STATUS_NO_MEMORY;
4772
4773                 if (!r_u->rids || !r_u->types)
4774                         goto empty;
4775
4776                 for (i = 0; i < num_rids; i++) {
4777                         r_u->rids[i] = rid[i];
4778                         r_u->types[i] = type[i];
4779                 }
4780         } else {
4781
4782   empty:
4783                 r_u->num_types1 = 0;
4784                 r_u->ptr_types = 0;
4785                 r_u->num_types2 = 0;
4786
4787                 r_u->num_rids1 = 0;
4788                 r_u->ptr_rids = 0;
4789                 r_u->num_rids2 = 0;
4790
4791                 r_u->rids = NULL;
4792                 r_u->types = NULL;
4793         }
4794
4795         r_u->status = status;
4796
4797         return NT_STATUS_OK;
4798 }
4799
4800 /*******************************************************************
4801 reads or writes a structure.
4802 ********************************************************************/
4803
4804 BOOL samr_io_r_lookup_names(const char *desc, SAMR_R_LOOKUP_NAMES * r_u,
4805                             prs_struct *ps, int depth)
4806 {
4807         uint32 i;
4808         fstring tmp;
4809
4810         if (r_u == NULL)
4811                 return False;
4812
4813         prs_debug(ps, depth, desc, "samr_io_r_lookup_names");
4814         depth++;
4815
4816         if (UNMARSHALLING(ps))
4817                 ZERO_STRUCTP(r_u);
4818
4819         if(!prs_align(ps))
4820                 return False;
4821
4822         if(!prs_uint32("num_rids1", ps, depth, &r_u->num_rids1))
4823                 return False;
4824         if(!prs_uint32("ptr_rids ", ps, depth, &r_u->ptr_rids))
4825                 return False;
4826
4827         if (r_u->ptr_rids != 0) {
4828                 if(!prs_uint32("num_rids2", ps, depth, &r_u->num_rids2))
4829                         return False;
4830
4831                 if (r_u->num_rids2 != r_u->num_rids1) {
4832                         /* RPC fault */
4833                         return False;
4834                 }
4835
4836                 if (UNMARSHALLING(ps))
4837                         r_u->rids = (uint32 *)prs_alloc_mem(ps, sizeof(uint32)*r_u->num_rids2);
4838
4839                 if (!r_u->rids) {
4840                         DEBUG(0, ("NULL rids in samr_io_r_lookup_names\n"));
4841                         return False;
4842                 }
4843
4844                 for (i = 0; i < r_u->num_rids2; i++) {
4845                         slprintf(tmp, sizeof(tmp) - 1, "rid[%02d]  ", i);
4846                         if(!prs_uint32(tmp, ps, depth, &r_u->rids[i]))
4847                                 return False;
4848                 }
4849         }
4850
4851         if(!prs_uint32("num_types1", ps, depth, &r_u->num_types1))
4852                 return False;
4853         if(!prs_uint32("ptr_types ", ps, depth, &r_u->ptr_types))
4854                 return False;
4855
4856         if (r_u->ptr_types != 0) {
4857                 if(!prs_uint32("num_types2", ps, depth, &r_u->num_types2))
4858                         return False;
4859
4860                 if (r_u->num_types2 != r_u->num_types1) {
4861                         /* RPC fault */
4862                         return False;
4863                 }
4864
4865                 if (UNMARSHALLING(ps))
4866                         r_u->types = (uint32 *)prs_alloc_mem(ps, sizeof(uint32)*r_u->num_types2);
4867
4868                 if (!r_u->types) {
4869                         DEBUG(0, ("NULL types in samr_io_r_lookup_names\n"));
4870                         return False;
4871                 }
4872
4873                 for (i = 0; i < r_u->num_types2; i++) {
4874                         slprintf(tmp, sizeof(tmp) - 1, "type[%02d]  ", i);
4875                         if(!prs_uint32(tmp, ps, depth, &r_u->types[i]))
4876                                 return False;
4877                 }
4878         }
4879
4880         if(!prs_ntstatus("status", ps, depth, &r_u->status))
4881                 return False;
4882
4883         return True;
4884 }
4885
4886 /*******************************************************************
4887 inits a SAMR_Q_DELETE_DOM_USER structure.
4888 ********************************************************************/
4889
4890 void init_samr_q_delete_dom_user(SAMR_Q_DELETE_DOM_USER * q_c,
4891                                  POLICY_HND *hnd)
4892 {
4893         DEBUG(5, ("init_samr_q_delete_dom_user\n"));
4894
4895         q_c->user_pol = *hnd;
4896 }
4897
4898 /*******************************************************************
4899 reads or writes a structure.
4900 ********************************************************************/
4901
4902 BOOL samr_io_q_delete_dom_user(const char *desc, SAMR_Q_DELETE_DOM_USER * q_u,
4903                                prs_struct *ps, int depth)
4904 {
4905         if (q_u == NULL)
4906                 return False;
4907
4908         prs_debug(ps, depth, desc, "samr_io_q_delete_dom_user");
4909         depth++;
4910
4911         if(!prs_align(ps))
4912                 return False;
4913
4914         if(!smb_io_pol_hnd("user_pol", &q_u->user_pol, ps, depth))
4915                 return False;
4916
4917         return True;
4918 }
4919
4920 /*******************************************************************
4921 reads or writes a structure.
4922 ********************************************************************/
4923
4924 BOOL samr_io_r_delete_dom_user(const char *desc, SAMR_R_DELETE_DOM_USER * r_u,
4925                                prs_struct *ps, int depth)
4926 {
4927         if (r_u == NULL)
4928                 return False;
4929
4930         prs_debug(ps, depth, desc, "samr_io_r_delete_dom_user");
4931         depth++;
4932
4933         if(!prs_align(ps))
4934                 return False;
4935
4936         if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
4937                 return False;
4938         if(!prs_ntstatus("status", ps, depth, &r_u->status))
4939                 return False;
4940
4941         return True;
4942 }
4943
4944 /*******************************************************************
4945 reads or writes a structure.
4946 ********************************************************************/
4947
4948 void init_samr_q_open_user(SAMR_Q_OPEN_USER * q_u,
4949                            POLICY_HND *pol,
4950                            uint32 access_mask, uint32 rid)
4951 {
4952         DEBUG(5, ("samr_init_samr_q_open_user\n"));
4953
4954         q_u->domain_pol = *pol;
4955         q_u->access_mask = access_mask;
4956         q_u->user_rid = rid;
4957 }
4958
4959 /*******************************************************************
4960 reads or writes a structure.
4961 ********************************************************************/
4962
4963 BOOL samr_io_q_open_user(const char *desc, SAMR_Q_OPEN_USER * q_u,
4964                          prs_struct *ps, int depth)
4965 {
4966         if (q_u == NULL)
4967                 return False;
4968
4969         prs_debug(ps, depth, desc, "samr_io_q_open_user");
4970         depth++;
4971
4972         if(!prs_align(ps))
4973                 return False;
4974
4975         if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
4976                 return False;
4977
4978         if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
4979                 return False;
4980         if(!prs_uint32("user_rid ", ps, depth, &q_u->user_rid))
4981                 return False;
4982
4983         return True;
4984 }
4985
4986 /*******************************************************************
4987 reads or writes a structure.
4988 ********************************************************************/
4989
4990 BOOL samr_io_r_open_user(const char *desc, SAMR_R_OPEN_USER * r_u,
4991                          prs_struct *ps, int depth)
4992 {
4993         if (r_u == NULL)
4994                 return False;
4995
4996         prs_debug(ps, depth, desc, "samr_io_r_open_user");
4997         depth++;
4998
4999         if(!prs_align(ps))
5000                 return False;
5001
5002         if(!smb_io_pol_hnd("user_pol", &r_u->user_pol, ps, depth))
5003                 return False;
5004
5005         if(!prs_ntstatus("status", ps, depth, &r_u->status))
5006                 return False;
5007
5008         return True;
5009 }
5010
5011
5012 /*******************************************************************
5013 reads or writes a structure.
5014 ********************************************************************/
5015
5016 void init_samr_q_create_user(SAMR_Q_CREATE_USER * q_u,
5017                              POLICY_HND *pol,
5018                              const char *name,
5019                              uint32 acb_info, uint32 access_mask)
5020 {
5021         DEBUG(5, ("samr_init_samr_q_create_user\n"));
5022
5023         q_u->domain_pol = *pol;
5024
5025         init_unistr2(&q_u->uni_name, name, UNI_FLAGS_NONE);
5026         init_uni_hdr(&q_u->hdr_name, &q_u->uni_name);
5027
5028         q_u->acb_info = acb_info;
5029         q_u->access_mask = access_mask;
5030 }
5031
5032 /*******************************************************************
5033 reads or writes a structure.
5034 ********************************************************************/
5035
5036 BOOL samr_io_q_create_user(const char *desc, SAMR_Q_CREATE_USER * q_u,
5037                            prs_struct *ps, int depth)
5038 {
5039         if (q_u == NULL)
5040                 return False;
5041
5042         prs_debug(ps, depth, desc, "samr_io_q_create_user");
5043         depth++;
5044
5045         if(!prs_align(ps))
5046                 return False;
5047
5048         if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
5049                 return False;
5050
5051         if(!smb_io_unihdr("hdr_name", &q_u->hdr_name, ps, depth))
5052                 return False;
5053         if(!smb_io_unistr2("uni_name", &q_u->uni_name, q_u->hdr_name.buffer, ps, depth))
5054                 return False;
5055
5056         if(!prs_align(ps))
5057                 return False;
5058         if(!prs_uint32("acb_info   ", ps, depth, &q_u->acb_info))
5059                 return False;
5060         if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
5061                 return False;
5062
5063         return True;
5064 }
5065
5066 /*******************************************************************
5067 reads or writes a structure.
5068 ********************************************************************/
5069
5070 BOOL samr_io_r_create_user(const char *desc, SAMR_R_CREATE_USER * r_u,
5071                            prs_struct *ps, int depth)
5072 {
5073         if (r_u == NULL)
5074                 return False;
5075
5076         prs_debug(ps, depth, desc, "samr_io_r_create_user");
5077         depth++;
5078
5079         if(!prs_align(ps))
5080                 return False;
5081
5082         if(!smb_io_pol_hnd("user_pol", &r_u->user_pol, ps, depth))
5083                 return False;
5084
5085         if(!prs_uint32("access_granted", ps, depth, &r_u->access_granted))
5086                 return False;
5087         if(!prs_uint32("user_rid ", ps, depth, &r_u->user_rid))
5088                 return False;
5089         if(!prs_ntstatus("status", ps, depth, &r_u->status))
5090                 return False;
5091
5092         return True;
5093 }
5094
5095 /*******************************************************************
5096 inits a SAMR_Q_QUERY_USERINFO structure.
5097 ********************************************************************/
5098
5099 void init_samr_q_query_userinfo(SAMR_Q_QUERY_USERINFO * q_u,
5100                                 POLICY_HND *hnd, uint16 switch_value)
5101 {
5102         DEBUG(5, ("init_samr_q_query_userinfo\n"));
5103
5104         q_u->pol = *hnd;
5105         q_u->switch_value = switch_value;
5106 }
5107
5108 /*******************************************************************
5109 reads or writes a structure.
5110 ********************************************************************/
5111
5112 BOOL samr_io_q_query_userinfo(const char *desc, SAMR_Q_QUERY_USERINFO * q_u,
5113                               prs_struct *ps, int depth)
5114 {
5115         if (q_u == NULL)
5116                 return False;
5117
5118         prs_debug(ps, depth, desc, "samr_io_q_query_userinfo");
5119         depth++;
5120
5121         if(!prs_align(ps))
5122                 return False;
5123
5124         if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
5125                 return False;
5126
5127         if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value)) /* 0x0015 or 0x0011 */
5128                 return False;
5129
5130         return True;
5131 }
5132
5133 /*******************************************************************
5134 reads or writes a LOGON_HRS structure.
5135 ********************************************************************/
5136
5137 static BOOL sam_io_logon_hrs(const char *desc, LOGON_HRS * hrs,
5138                              prs_struct *ps, int depth)
5139 {
5140         if (hrs == NULL)
5141                 return False;
5142
5143         prs_debug(ps, depth, desc, "sam_io_logon_hrs");
5144         depth++;
5145
5146         if(!prs_align(ps))
5147                 return False;
5148
5149         if(!prs_uint32("len  ", ps, depth, &hrs->len))
5150                 return False;
5151
5152         if (hrs->len > sizeof(hrs->hours)) {
5153                 DEBUG(3, ("sam_io_logon_hrs: truncating length from %d\n", hrs->len));
5154                 hrs->len = sizeof(hrs->hours);
5155         }
5156
5157         if(!prs_uint8s(False, "hours", ps, depth, hrs->hours, hrs->len))
5158                 return False;
5159
5160         return True;
5161 }
5162
5163 /*******************************************************************
5164 inits a SAM_USER_INFO_12 structure.
5165 ********************************************************************/
5166
5167 void init_sam_user_info12(SAM_USER_INFO_12 * usr,
5168                           const uint8 lm_pwd[16], const uint8 nt_pwd[16])
5169 {
5170         DEBUG(5, ("init_sam_user_info12\n"));
5171
5172         usr->lm_pwd_active =
5173                 memcpy(usr->lm_pwd, lm_pwd, sizeof(usr->lm_pwd)) ? 1 : 0;
5174         usr->nt_pwd_active =
5175                 memcpy(usr->nt_pwd, nt_pwd, sizeof(usr->nt_pwd)) ? 1 : 0;
5176 }
5177
5178 /*******************************************************************
5179 reads or writes a structure.
5180 ********************************************************************/
5181
5182 static BOOL sam_io_user_info12(const char *desc, SAM_USER_INFO_12 * u,
5183                         prs_struct *ps, int depth)
5184 {
5185         if (u == NULL)
5186                 return False;
5187
5188         prs_debug(ps, depth, desc, "samr_io_r_user_info12");
5189         depth++;
5190
5191         if(!prs_align(ps))
5192                 return False;
5193
5194         if(!prs_uint8s(False, "lm_pwd", ps, depth, u->lm_pwd, sizeof(u->lm_pwd)))
5195                 return False;
5196         if(!prs_uint8s(False, "nt_pwd", ps, depth, u->nt_pwd, sizeof(u->nt_pwd)))
5197                 return False;
5198
5199         if(!prs_uint8("lm_pwd_active", ps, depth, &u->lm_pwd_active))
5200                 return False;
5201         if(!prs_uint8("nt_pwd_active", ps, depth, &u->nt_pwd_active))
5202                 return False;
5203
5204         return True;
5205 }
5206
5207 /*******************************************************************
5208 inits a SAM_USER_INFO_10 structure.
5209 ********************************************************************/
5210
5211 void init_sam_user_info10(SAM_USER_INFO_10 * usr, uint32 acb_info)
5212 {
5213         DEBUG(5, ("init_sam_user_info10\n"));
5214
5215         usr->acb_info = acb_info;
5216 }
5217
5218 /*******************************************************************
5219 reads or writes a structure.
5220 ********************************************************************/
5221
5222 static BOOL sam_io_user_info10(const char *desc, SAM_USER_INFO_10 * usr,
5223                         prs_struct *ps, int depth)
5224 {
5225         if (usr == NULL)
5226                 return False;
5227
5228         prs_debug(ps, depth, desc, "samr_io_r_user_info10");
5229         depth++;
5230
5231         if(!prs_align(ps))
5232                 return False;
5233
5234         if(!prs_uint32("acb_info", ps, depth, &usr->acb_info))
5235                 return False;
5236
5237         return True;
5238 }
5239
5240 /*******************************************************************
5241 inits a SAM_USER_INFO_11 structure.
5242 ********************************************************************/
5243
5244 void init_sam_user_info11(SAM_USER_INFO_11 * usr,
5245                           NTTIME * expiry,
5246                           char *mach_acct,
5247                           uint32 rid_user, uint32 rid_group, uint16 acct_ctrl)
5248 {
5249         DEBUG(5, ("init_sam_user_info11\n"));
5250
5251         memcpy(&usr->expiry, expiry, sizeof(usr->expiry));      /* expiry time or something? */
5252         ZERO_STRUCT(usr->padding_1);    /* 0 - padding 24 bytes */
5253
5254         usr->padding_2 = 0;     /* 0 - padding 4 bytes */
5255
5256         usr->ptr_1 = 1;         /* pointer */
5257         ZERO_STRUCT(usr->padding_3);    /* 0 - padding 32 bytes */
5258         usr->padding_4 = 0;     /* 0 - padding 4 bytes */
5259
5260         usr->ptr_2 = 1;         /* pointer */
5261         usr->padding_5 = 0;     /* 0 - padding 4 bytes */
5262
5263         usr->ptr_3 = 1;         /* pointer */
5264         ZERO_STRUCT(usr->padding_6);    /* 0 - padding 32 bytes */
5265
5266         usr->rid_user = rid_user;
5267         usr->rid_group = rid_group;
5268
5269         usr->acct_ctrl = acct_ctrl;
5270         usr->unknown_3 = 0x0000;
5271
5272         usr->unknown_4 = 0x003f;        /* 0x003f      - 16 bit unknown */
5273         usr->unknown_5 = 0x003c;        /* 0x003c      - 16 bit unknown */
5274
5275         ZERO_STRUCT(usr->padding_7);    /* 0 - padding 16 bytes */
5276         usr->padding_8 = 0;     /* 0 - padding 4 bytes */
5277
5278         init_unistr2(&usr->uni_mach_acct, mach_acct, UNI_FLAGS_NONE);   /* unicode string for machine account */
5279         init_uni_hdr(&usr->hdr_mach_acct, &usr->uni_mach_acct); /* unicode header for machine account */
5280 }
5281
5282 /*******************************************************************
5283 reads or writes a structure.
5284 ********************************************************************/
5285
5286 static BOOL sam_io_user_info11(const char *desc, SAM_USER_INFO_11 * usr,
5287                         prs_struct *ps, int depth)
5288 {
5289         if (usr == NULL)
5290                 return False;
5291
5292         prs_debug(ps, depth, desc, "samr_io_r_unknown_11");
5293         depth++;
5294
5295         if(!prs_align(ps))
5296                 return False;
5297
5298         if(!prs_uint8s(False, "padding_0", ps, depth, usr->padding_0, sizeof(usr->padding_0)))
5299                 return False;
5300
5301         if(!smb_io_time("time", &usr->expiry, ps, depth))
5302                 return False;
5303
5304         if(!prs_uint8s(False, "padding_1", ps, depth, usr->padding_1, sizeof(usr->padding_1)))
5305                 return False;
5306
5307         if(!smb_io_unihdr("unihdr", &usr->hdr_mach_acct, ps, depth))
5308                 return False;
5309
5310         if(!prs_uint32("padding_2", ps, depth, &usr->padding_2))
5311                 return False;
5312
5313         if(!prs_uint32("ptr_1    ", ps, depth, &usr->ptr_1))
5314                 return False;
5315         if(!prs_uint8s(False, "padding_3", ps, depth, usr->padding_3, sizeof(usr->padding_3)))
5316                 return False;
5317
5318         if(!prs_uint32("padding_4", ps, depth, &usr->padding_4))
5319                 return False;
5320
5321         if(!prs_uint32("ptr_2    ", ps, depth, &usr->ptr_2))
5322                 return False;
5323         if(!prs_uint32("padding_5", ps, depth, &usr->padding_5))
5324                 return False;
5325
5326         if(!prs_uint32("ptr_3    ", ps, depth, &usr->ptr_3))
5327                 return False;
5328         if(!prs_uint8s(False, "padding_6", ps, depth, usr->padding_6,sizeof(usr->padding_6)))
5329                 return False;
5330
5331         if(!prs_uint32("rid_user ", ps, depth, &usr->rid_user))
5332                 return False;
5333         if(!prs_uint32("rid_group", ps, depth, &usr->rid_group))
5334                 return False;
5335         if(!prs_uint16("acct_ctrl", ps, depth, &usr->acct_ctrl))
5336                 return False;
5337         if(!prs_uint16("unknown_3", ps, depth, &usr->unknown_3))
5338                 return False;
5339         if(!prs_uint16("unknown_4", ps, depth, &usr->unknown_4))
5340                 return False;
5341         if(!prs_uint16("unknown_5", ps, depth, &usr->unknown_5))
5342                 return False;
5343
5344         if(!prs_uint8s(False, "padding_7", ps, depth, usr->padding_7, sizeof(usr->padding_7)))
5345                 return False;
5346
5347         if(!prs_uint32("padding_8", ps, depth, &(usr->padding_8)))
5348                 return False;
5349
5350         if(!smb_io_unistr2("unistr2", &usr->uni_mach_acct, True, ps, depth))
5351                 return False;
5352
5353         if(!prs_align(ps))
5354                 return False;
5355
5356         if(!prs_uint8s(False, "padding_9", ps, depth, usr->padding_9, sizeof(usr->padding_9)))
5357                 return False;
5358
5359         return True;
5360 }
5361
5362 /*************************************************************************
5363  init_sam_user_infoa
5364  *************************************************************************/
5365
5366 void init_sam_user_info24(SAM_USER_INFO_24 * usr, char newpass[516], uint16 pw_len)
5367 {
5368         DEBUG(10, ("init_sam_user_info24:\n"));
5369         memcpy(usr->pass, newpass, sizeof(usr->pass));
5370         usr->pw_len = pw_len;
5371 }
5372
5373 /*******************************************************************
5374 reads or writes a structure.
5375 ********************************************************************/
5376
5377 static BOOL sam_io_user_info24(const char *desc, SAM_USER_INFO_24 * usr,
5378                                prs_struct *ps, int depth)
5379 {
5380         if (usr == NULL)
5381                 return False;
5382
5383         prs_debug(ps, depth, desc, "sam_io_user_info24");
5384         depth++;
5385
5386         if(!prs_align(ps))
5387                 return False;
5388
5389         if(!prs_uint8s(False, "password", ps, depth, usr->pass, 
5390                        sizeof(usr->pass)))
5391                 return False;
5392         
5393         if (MARSHALLING(ps) && (usr->pw_len != 0)) {
5394                 if (!prs_uint16("pw_len", ps, depth, &usr->pw_len))
5395                         return False;
5396         }
5397         if(!prs_align(ps))
5398                 return False;
5399
5400         return True;
5401 }
5402
5403 /*************************************************************************
5404  init_sam_user_info23
5405
5406  unknown_6 = 0x0000 04ec 
5407
5408  *************************************************************************/
5409
5410 void init_sam_user_info23W(SAM_USER_INFO_23 * usr, NTTIME * logon_time, /* all zeros */
5411                         NTTIME * logoff_time,   /* all zeros */
5412                         NTTIME * kickoff_time,  /* all zeros */
5413                         NTTIME * pass_last_set_time,    /* all zeros */
5414                         NTTIME * pass_can_change_time,  /* all zeros */
5415                         NTTIME * pass_must_change_time, /* all zeros */
5416                         UNISTR2 *user_name,
5417                         UNISTR2 *full_name,
5418                         UNISTR2 *home_dir,
5419                         UNISTR2 *dir_drive,
5420                         UNISTR2 *log_scr,
5421                         UNISTR2 *prof_path,
5422                         UNISTR2 *desc,
5423                         UNISTR2 *wkstas,
5424                         UNISTR2 *unk_str,
5425                         UNISTR2 *mung_dial,
5426                         uint32 user_rid,        /* 0x0000 0000 */
5427                         uint32 group_rid,
5428                         uint32 acb_info,
5429                         uint32 fields_present,
5430                         uint16 logon_divs,
5431                         LOGON_HRS * hrs,
5432                         uint16 bad_password_count,
5433                         uint16 logon_count,
5434                         char newpass[516], uint32 unknown_6)
5435 {
5436         usr->logon_time = *logon_time;  /* all zeros */
5437         usr->logoff_time = *logoff_time;        /* all zeros */
5438         usr->kickoff_time = *kickoff_time;      /* all zeros */
5439         usr->pass_last_set_time = *pass_last_set_time;  /* all zeros */
5440         usr->pass_can_change_time = *pass_can_change_time;      /* all zeros */
5441         usr->pass_must_change_time = *pass_must_change_time;    /* all zeros */
5442
5443         ZERO_STRUCT(usr->nt_pwd);
5444         ZERO_STRUCT(usr->lm_pwd);
5445
5446         usr->user_rid = user_rid;       /* 0x0000 0000 */
5447         usr->group_rid = group_rid;
5448         usr->acb_info = acb_info;
5449         usr->fields_present = fields_present;   /* 09f8 27fa */
5450
5451         usr->logon_divs = logon_divs;   /* should be 168 (hours/week) */
5452         usr->ptr_logon_hrs = hrs ? 1 : 0;
5453
5454         if (nt_time_is_zero(pass_must_change_time)) {
5455                 usr->passmustchange=PASS_MUST_CHANGE_AT_NEXT_LOGON;
5456         } else {
5457                 usr->passmustchange=0;
5458         }
5459
5460         ZERO_STRUCT(usr->padding1);
5461         ZERO_STRUCT(usr->padding2);
5462
5463         usr->bad_password_count = bad_password_count;
5464         usr->logon_count = logon_count;
5465
5466         memcpy(usr->pass, newpass, sizeof(usr->pass));
5467
5468         copy_unistr2(&usr->uni_user_name, user_name);
5469         init_uni_hdr(&usr->hdr_user_name, &usr->uni_user_name);
5470
5471         copy_unistr2(&usr->uni_full_name, full_name);
5472         init_uni_hdr(&usr->hdr_full_name, &usr->uni_full_name);
5473
5474         copy_unistr2(&usr->uni_home_dir, home_dir);
5475         init_uni_hdr(&usr->hdr_home_dir, &usr->uni_home_dir);
5476
5477         copy_unistr2(&usr->uni_dir_drive, dir_drive);
5478         init_uni_hdr(&usr->hdr_dir_drive, &usr->uni_dir_drive);
5479
5480         copy_unistr2(&usr->uni_logon_script, log_scr);
5481         init_uni_hdr(&usr->hdr_logon_script, &usr->uni_logon_script);
5482
5483         copy_unistr2(&usr->uni_profile_path, prof_path);
5484         init_uni_hdr(&usr->hdr_profile_path, &usr->uni_profile_path);
5485
5486         copy_unistr2(&usr->uni_acct_desc, desc);
5487         init_uni_hdr(&usr->hdr_acct_desc, &usr->uni_acct_desc);
5488
5489         copy_unistr2(&usr->uni_workstations, wkstas);
5490         init_uni_hdr(&usr->hdr_workstations, &usr->uni_workstations);
5491
5492         copy_unistr2(&usr->uni_unknown_str, unk_str);
5493         init_uni_hdr(&usr->hdr_unknown_str, &usr->uni_unknown_str);
5494
5495         copy_unistr2(&usr->uni_munged_dial, mung_dial);
5496         init_uni_hdr(&usr->hdr_munged_dial, &usr->uni_munged_dial);
5497
5498         usr->unknown_6 = unknown_6;     /* 0x0000 04ec */
5499         usr->padding4 = 0;
5500
5501         memcpy(&usr->logon_hrs, hrs, sizeof(usr->logon_hrs));
5502 }
5503
5504 /*************************************************************************
5505  init_sam_user_info23
5506
5507  unknown_6 = 0x0000 04ec 
5508
5509  *************************************************************************/
5510
5511 void init_sam_user_info23A(SAM_USER_INFO_23 * usr, NTTIME * logon_time, /* all zeros */
5512                            NTTIME * logoff_time,        /* all zeros */
5513                            NTTIME * kickoff_time,       /* all zeros */
5514                            NTTIME * pass_last_set_time, /* all zeros */
5515                            NTTIME * pass_can_change_time,       /* all zeros */
5516                            NTTIME * pass_must_change_time,      /* all zeros */
5517                            char *user_name,     /* NULL */
5518                            char *full_name,
5519                            char *home_dir, char *dir_drive, char *log_scr,
5520                            char *prof_path, const char *desc, char *wkstas,
5521                            char *unk_str, char *mung_dial, uint32 user_rid,     /* 0x0000 0000 */
5522                            uint32 group_rid, uint32 acb_info,
5523                            uint32 fields_present, uint16 logon_divs,
5524                            LOGON_HRS * hrs, uint16 bad_password_count, uint16 logon_count,
5525                            char newpass[516], uint32 unknown_6)
5526 {
5527         DATA_BLOB blob = base64_decode_data_blob(mung_dial);
5528         
5529         usr->logon_time = *logon_time;  /* all zeros */
5530         usr->logoff_time = *logoff_time;        /* all zeros */
5531         usr->kickoff_time = *kickoff_time;      /* all zeros */
5532         usr->pass_last_set_time = *pass_last_set_time;  /* all zeros */
5533         usr->pass_can_change_time = *pass_can_change_time;      /* all zeros */
5534         usr->pass_must_change_time = *pass_must_change_time;    /* all zeros */
5535
5536         ZERO_STRUCT(usr->nt_pwd);
5537         ZERO_STRUCT(usr->lm_pwd);
5538
5539         usr->user_rid = user_rid;       /* 0x0000 0000 */
5540         usr->group_rid = group_rid;
5541         usr->acb_info = acb_info;
5542         usr->fields_present = fields_present;   /* 09f8 27fa */
5543
5544         usr->logon_divs = logon_divs;   /* should be 168 (hours/week) */
5545         usr->ptr_logon_hrs = hrs ? 1 : 0;
5546
5547         if (nt_time_is_zero(pass_must_change_time)) {
5548                 usr->passmustchange=PASS_MUST_CHANGE_AT_NEXT_LOGON;
5549         } else {
5550                 usr->passmustchange=0;
5551         }
5552
5553         ZERO_STRUCT(usr->padding1);
5554         ZERO_STRUCT(usr->padding2);
5555
5556         usr->bad_password_count = bad_password_count;
5557         usr->logon_count = logon_count;
5558
5559         memcpy(usr->pass, newpass, sizeof(usr->pass));
5560
5561         init_unistr2(&usr->uni_user_name, user_name, UNI_FLAGS_NONE);
5562         init_uni_hdr(&usr->hdr_user_name, &usr->uni_user_name);
5563
5564         init_unistr2(&usr->uni_full_name, full_name, UNI_FLAGS_NONE);
5565         init_uni_hdr(&usr->hdr_full_name, &usr->uni_full_name);
5566
5567         init_unistr2(&usr->uni_home_dir, home_dir, UNI_FLAGS_NONE);
5568         init_uni_hdr(&usr->hdr_home_dir, &usr->uni_home_dir);
5569
5570         init_unistr2(&usr->uni_dir_drive, dir_drive, UNI_FLAGS_NONE);
5571         init_uni_hdr(&usr->hdr_dir_drive, &usr->uni_dir_drive);
5572
5573         init_unistr2(&usr->uni_logon_script, log_scr, UNI_FLAGS_NONE);
5574         init_uni_hdr(&usr->hdr_logon_script, &usr->uni_logon_script);
5575
5576         init_unistr2(&usr->uni_profile_path, prof_path, UNI_FLAGS_NONE);
5577         init_uni_hdr(&usr->hdr_profile_path, &usr->uni_profile_path);
5578
5579         init_unistr2(&usr->uni_acct_desc, desc, UNI_FLAGS_NONE);
5580         init_uni_hdr(&usr->hdr_acct_desc, &usr->uni_acct_desc);
5581
5582         init_unistr2(&usr->uni_workstations, wkstas, UNI_FLAGS_NONE);
5583         init_uni_hdr(&usr->hdr_workstations, &usr->uni_workstations);
5584
5585         init_unistr2(&usr->uni_unknown_str, unk_str, UNI_FLAGS_NONE);
5586         init_uni_hdr(&usr->hdr_unknown_str, &usr->uni_unknown_str);
5587
5588         init_unistr2_from_datablob(&usr->uni_munged_dial, &blob);
5589         init_uni_hdr(&usr->hdr_munged_dial, &usr->uni_munged_dial);
5590
5591         data_blob_free(&blob);
5592         
5593         usr->unknown_6 = unknown_6;     /* 0x0000 04ec */
5594         usr->padding4 = 0;
5595
5596         memcpy(&usr->logon_hrs, hrs, sizeof(usr->logon_hrs));
5597 }
5598
5599 /*******************************************************************
5600 reads or writes a structure.
5601 ********************************************************************/
5602
5603 static BOOL sam_io_user_info23(const char *desc, SAM_USER_INFO_23 * usr,
5604                                prs_struct *ps, int depth)
5605 {
5606         if (usr == NULL)
5607                 return False;
5608
5609         prs_debug(ps, depth, desc, "sam_io_user_info23");
5610         depth++;
5611
5612         if(!prs_align(ps))
5613                 return False;
5614
5615         if(!smb_io_time("logon_time           ", &usr->logon_time, ps, depth))
5616                 return False;
5617         if(!smb_io_time("logoff_time          ", &usr->logoff_time, ps, depth))
5618                 return False;
5619         if(!smb_io_time("kickoff_time         ", &usr->kickoff_time, ps, depth))
5620                 return False;
5621         if(!smb_io_time("pass_last_set_time   ", &usr->pass_last_set_time, ps, depth))
5622                 return False;
5623         if(!smb_io_time("pass_can_change_time ", &usr->pass_can_change_time, ps, depth))
5624                 return False;
5625         if(!smb_io_time("pass_must_change_time", &usr->pass_must_change_time, ps, depth))
5626                 return False;
5627
5628         if(!smb_io_unihdr("hdr_user_name   ", &usr->hdr_user_name, ps, depth))  /* username unicode string header */
5629                 return False;
5630         if(!smb_io_unihdr("hdr_full_name   ", &usr->hdr_full_name, ps, depth))  /* user's full name unicode string header */
5631                 return False;
5632         if(!smb_io_unihdr("hdr_home_dir    ", &usr->hdr_home_dir, ps, depth))   /* home directory unicode string header */
5633                 return False;
5634         if(!smb_io_unihdr("hdr_dir_drive   ", &usr->hdr_dir_drive, ps, depth))  /* home directory drive */
5635                 return False;
5636         if(!smb_io_unihdr("hdr_logon_script", &usr->hdr_logon_script, ps, depth))       /* logon script unicode string header */
5637                 return False;
5638         if(!smb_io_unihdr("hdr_profile_path", &usr->hdr_profile_path, ps, depth))       /* profile path unicode string header */
5639                 return False;
5640         if(!smb_io_unihdr("hdr_acct_desc   ", &usr->hdr_acct_desc, ps, depth))  /* account desc */
5641                 return False;
5642         if(!smb_io_unihdr("hdr_workstations", &usr->hdr_workstations, ps, depth))       /* wkstas user can log on from */
5643                 return False;
5644         if(!smb_io_unihdr("hdr_unknown_str ", &usr->hdr_unknown_str, ps, depth))        /* unknown string */
5645                 return False;
5646         if(!smb_io_unihdr("hdr_munged_dial ", &usr->hdr_munged_dial, ps, depth))        /* wkstas user can log on from */
5647                 return False;
5648
5649         if(!prs_uint8s(False, "lm_pwd        ", ps, depth, usr->lm_pwd, sizeof(usr->lm_pwd)))
5650                 return False;
5651         if(!prs_uint8s(False, "nt_pwd        ", ps, depth, usr->nt_pwd, sizeof(usr->nt_pwd)))
5652                 return False;
5653
5654         if(!prs_uint32("user_rid      ", ps, depth, &usr->user_rid))    /* User ID */
5655                 return False;
5656         if(!prs_uint32("group_rid     ", ps, depth, &usr->group_rid))   /* Group ID */
5657                 return False;
5658         if(!prs_uint32("acb_info      ", ps, depth, &usr->acb_info))
5659                 return False;
5660
5661         if(!prs_uint32("fields_present ", ps, depth, &usr->fields_present))
5662                 return False;
5663         if(!prs_uint16("logon_divs    ", ps, depth, &usr->logon_divs))  /* logon divisions per week */
5664                 return False;
5665         if(!prs_align(ps))
5666                 return False;
5667         if(!prs_uint32("ptr_logon_hrs ", ps, depth, &usr->ptr_logon_hrs))
5668                 return False;
5669
5670         if(!prs_uint16("bad_password_count     ", ps, depth, &usr->bad_password_count))
5671                 return False;
5672         if(!prs_uint16("logon_count     ", ps, depth, &usr->logon_count))
5673                 return False;
5674
5675         if(!prs_uint8s(False, "padding1      ", ps, depth, usr->padding1, sizeof(usr->padding1)))
5676                 return False;
5677         if(!prs_uint8("passmustchange ", ps, depth, &usr->passmustchange))
5678                 return False;
5679         if(!prs_uint8("padding2       ", ps, depth, &usr->padding2))
5680                 return False;
5681
5682
5683         if(!prs_uint8s(False, "password      ", ps, depth, usr->pass, sizeof(usr->pass)))
5684                 return False;
5685
5686         /* here begins pointed-to data */
5687
5688         if(!smb_io_unistr2("uni_user_name   ", &usr->uni_user_name, usr->hdr_user_name.buffer, ps, depth))      /* username unicode string */
5689                 return False;
5690
5691         if(!smb_io_unistr2("uni_full_name   ", &usr->uni_full_name, usr->hdr_full_name.buffer, ps, depth))      /* user's full name unicode string */
5692                 return False;
5693
5694         if(!smb_io_unistr2("uni_home_dir    ", &usr->uni_home_dir, usr->hdr_home_dir.buffer, ps, depth))        /* home directory unicode string */
5695                 return False;
5696
5697         if(!smb_io_unistr2("uni_dir_drive   ", &usr->uni_dir_drive, usr->hdr_dir_drive.buffer, ps, depth))      /* home directory drive unicode string */
5698                 return False;
5699
5700         if(!smb_io_unistr2("uni_logon_script", &usr->uni_logon_script, usr->hdr_logon_script.buffer, ps, depth))        /* logon script unicode string */
5701                 return False;
5702
5703         if(!smb_io_unistr2("uni_profile_path", &usr->uni_profile_path, usr->hdr_profile_path.buffer, ps, depth))        /* profile path unicode string */
5704                 return False;
5705
5706         if(!smb_io_unistr2("uni_acct_desc   ", &usr->uni_acct_desc, usr->hdr_acct_desc.buffer, ps, depth))      /* user desc unicode string */
5707                 return False;
5708
5709         if(!smb_io_unistr2("uni_workstations", &usr->uni_workstations, usr->hdr_workstations.buffer, ps, depth))        /* worksations user can log on from */
5710                 return False;
5711
5712         if(!smb_io_unistr2("uni_unknown_str ", &usr->uni_unknown_str, usr->hdr_unknown_str.buffer, ps, depth))  /* unknown string */
5713                 return False;
5714
5715         if(!smb_io_unistr2("uni_munged_dial ", &usr->uni_munged_dial, usr->hdr_munged_dial.buffer, ps, depth))
5716                 return False;
5717
5718         /* ok, this is only guess-work (as usual) */
5719         if (usr->ptr_logon_hrs) {
5720                 if(!prs_uint32("unknown_6     ", ps, depth, &usr->unknown_6))
5721                         return False;
5722                 if(!prs_uint32("padding4      ", ps, depth, &usr->padding4))
5723                         return False;
5724                 if(!sam_io_logon_hrs("logon_hrs", &usr->logon_hrs, ps, depth))
5725                         return False;
5726         } else if (UNMARSHALLING(ps)) {
5727                 usr->unknown_6 = 0;
5728                 usr->padding4 = 0;
5729         }
5730
5731         return True;
5732 }
5733
5734 /*******************************************************************
5735  reads or writes a structure.
5736  NB. This structure is *definately* incorrect. It's my best guess
5737  currently for W2K SP2. The password field is encrypted in a different
5738  way than normal... And there are definately other problems. JRA.
5739 ********************************************************************/
5740
5741 static BOOL sam_io_user_info25(const char *desc, SAM_USER_INFO_25 * usr, prs_struct *ps, int depth)
5742 {
5743         if (usr == NULL)
5744                 return False;
5745
5746         prs_debug(ps, depth, desc, "sam_io_user_info25");
5747         depth++;
5748
5749         if(!prs_align(ps))
5750                 return False;
5751
5752         if(!smb_io_time("logon_time           ", &usr->logon_time, ps, depth))
5753                 return False;
5754         if(!smb_io_time("logoff_time          ", &usr->logoff_time, ps, depth))
5755                 return False;
5756         if(!smb_io_time("kickoff_time         ", &usr->kickoff_time, ps, depth))
5757                 return False;
5758         if(!smb_io_time("pass_last_set_time   ", &usr->pass_last_set_time, ps, depth))
5759                 return False;
5760         if(!smb_io_time("pass_can_change_time ", &usr->pass_can_change_time, ps, depth))
5761                 return False;
5762         if(!smb_io_time("pass_must_change_time", &usr->pass_must_change_time, ps, depth))
5763                 return False;
5764
5765         if(!smb_io_unihdr("hdr_user_name   ", &usr->hdr_user_name, ps, depth))  /* username unicode string header */
5766                 return False;
5767         if(!smb_io_unihdr("hdr_full_name   ", &usr->hdr_full_name, ps, depth))  /* user's full name unicode string header */
5768                 return False;
5769         if(!smb_io_unihdr("hdr_home_dir    ", &usr->hdr_home_dir, ps, depth))   /* home directory unicode string header */
5770                 return False;
5771         if(!smb_io_unihdr("hdr_dir_drive   ", &usr->hdr_dir_drive, ps, depth))  /* home directory drive */
5772                 return False;
5773         if(!smb_io_unihdr("hdr_logon_script", &usr->hdr_logon_script, ps, depth))       /* logon script unicode string header */
5774                 return False;
5775         if(!smb_io_unihdr("hdr_profile_path", &usr->hdr_profile_path, ps, depth))       /* profile path unicode string header */
5776                 return False;
5777         if(!smb_io_unihdr("hdr_acct_desc   ", &usr->hdr_acct_desc, ps, depth))  /* account desc */
5778                 return False;
5779         if(!smb_io_unihdr("hdr_workstations", &usr->hdr_workstations, ps, depth))       /* wkstas user can log on from */
5780                 return False;
5781         if(!smb_io_unihdr("hdr_unknown_str ", &usr->hdr_unknown_str, ps, depth))        /* unknown string */
5782                 return False;
5783         if(!smb_io_unihdr("hdr_munged_dial ", &usr->hdr_munged_dial, ps, depth))        /* wkstas user can log on from */
5784                 return False;
5785
5786         if(!prs_uint8s(False, "lm_pwd        ", ps, depth, usr->lm_pwd, sizeof(usr->lm_pwd)))
5787                 return False;
5788         if(!prs_uint8s(False, "nt_pwd        ", ps, depth, usr->nt_pwd, sizeof(usr->nt_pwd)))
5789                 return False;
5790
5791         if(!prs_uint32("user_rid      ", ps, depth, &usr->user_rid))    /* User ID */
5792                 return False;
5793         if(!prs_uint32("group_rid     ", ps, depth, &usr->group_rid))   /* Group ID */
5794                 return False;
5795         if(!prs_uint32("acb_info      ", ps, depth, &usr->acb_info))
5796                 return False;
5797
5798         if(!prs_uint32s(False, "unknown_6      ", ps, depth, usr->unknown_6, 6))
5799                 return False;
5800
5801         if(!prs_uint8s(False, "password      ", ps, depth, usr->pass, sizeof(usr->pass)))
5802                 return False;
5803
5804         /* here begins pointed-to data */
5805
5806         if(!smb_io_unistr2("uni_user_name   ", &usr->uni_user_name, usr->hdr_user_name.buffer, ps, depth))      /* username unicode string */
5807                 return False;
5808
5809         if(!smb_io_unistr2("uni_full_name   ", &usr->uni_full_name, usr->hdr_full_name.buffer, ps, depth))      /* user's full name unicode string */
5810                 return False;
5811
5812         if(!smb_io_unistr2("uni_home_dir    ", &usr->uni_home_dir, usr->hdr_home_dir.buffer, ps, depth))        /* home directory unicode string */
5813                 return False;
5814
5815         if(!smb_io_unistr2("uni_dir_drive   ", &usr->uni_dir_drive, usr->hdr_dir_drive.buffer, ps, depth))      /* home directory drive unicode string */
5816                 return False;
5817
5818         if(!smb_io_unistr2("uni_logon_script", &usr->uni_logon_script, usr->hdr_logon_script.buffer, ps, depth))        /* logon script unicode string */
5819                 return False;
5820
5821         if(!smb_io_unistr2("uni_profile_path", &usr->uni_profile_path, usr->hdr_profile_path.buffer, ps, depth))        /* profile path unicode string */
5822                 return False;
5823
5824         if(!smb_io_unistr2("uni_acct_desc   ", &usr->uni_acct_desc, usr->hdr_acct_desc.buffer, ps, depth))      /* user desc unicode string */
5825                 return False;
5826
5827         if(!smb_io_unistr2("uni_workstations", &usr->uni_workstations, usr->hdr_workstations.buffer, ps, depth))        /* worksations user can log on from */
5828                 return False;
5829
5830         if(!smb_io_unistr2("uni_unknown_str ", &usr->uni_unknown_str, usr->hdr_unknown_str.buffer, ps, depth))  /* unknown string */
5831                 return False;
5832
5833         if(!smb_io_unistr2("uni_munged_dial ", &usr->uni_munged_dial, usr->hdr_munged_dial.buffer, ps, depth))
5834                 return False;
5835
5836 #if 0 /* JRA - unknown... */
5837         /* ok, this is only guess-work (as usual) */
5838         if (usr->ptr_logon_hrs) {
5839                 if(!prs_uint32("unknown_6     ", ps, depth, &usr->unknown_6))
5840                         return False;
5841                 if(!prs_uint32("padding4      ", ps, depth, &usr->padding4))
5842                         return False;
5843                 if(!sam_io_logon_hrs("logon_hrs", &usr->logon_hrs, ps, depth))
5844                         return False;
5845         } else if (UNMARSHALLING(ps)) {
5846                 usr->unknown_6 = 0;
5847                 usr->padding4 = 0;
5848         }
5849 #endif
5850
5851         return True;
5852 }
5853
5854
5855 /*************************************************************************
5856  init_sam_user_info21W
5857
5858  unknown_6 = 0x0000 04ec 
5859
5860  *************************************************************************/
5861
5862 void init_sam_user_info21W(SAM_USER_INFO_21 * usr,
5863                            NTTIME * logon_time,
5864                            NTTIME * logoff_time,
5865                            NTTIME * kickoff_time,
5866                            NTTIME * pass_last_set_time,
5867                            NTTIME * pass_can_change_time,
5868                            NTTIME * pass_must_change_time,
5869                            UNISTR2 *user_name,
5870                            UNISTR2 *full_name,
5871                            UNISTR2 *home_dir,
5872                            UNISTR2 *dir_drive,
5873                            UNISTR2 *log_scr,
5874                            UNISTR2 *prof_path,
5875                            UNISTR2 *desc,
5876                            UNISTR2 *wkstas,
5877                            UNISTR2 *unk_str,
5878                            UNISTR2 *mung_dial,
5879                            uchar lm_pwd[16],
5880                            uchar nt_pwd[16],
5881                            uint32 user_rid,
5882                            uint32 group_rid,
5883                            uint32 acb_info,
5884                            uint32 fields_present,
5885                            uint16 logon_divs,
5886                            LOGON_HRS * hrs,
5887                            uint16 bad_password_count,
5888                            uint16 logon_count,
5889                            uint32 unknown_6)
5890 {
5891         usr->logon_time = *logon_time;
5892         usr->logoff_time = *logoff_time;
5893         usr->kickoff_time = *kickoff_time;
5894         usr->pass_last_set_time = *pass_last_set_time;
5895         usr->pass_can_change_time = *pass_can_change_time;
5896         usr->pass_must_change_time = *pass_must_change_time;
5897
5898         memcpy(usr->lm_pwd, lm_pwd, sizeof(usr->lm_pwd));
5899         memcpy(usr->nt_pwd, nt_pwd, sizeof(usr->nt_pwd));
5900
5901         usr->user_rid = user_rid;
5902         usr->group_rid = group_rid;
5903         usr->acb_info = acb_info;
5904         usr->fields_present = fields_present;   /* 0x00ff ffff */
5905
5906         usr->logon_divs = logon_divs;   /* should be 168 (hours/week) */
5907         usr->ptr_logon_hrs = hrs ? 1 : 0;
5908         usr->bad_password_count = bad_password_count;
5909         usr->logon_count = logon_count;
5910
5911         if (nt_time_is_zero(pass_must_change_time)) {
5912                 usr->passmustchange=PASS_MUST_CHANGE_AT_NEXT_LOGON;
5913         } else {
5914                 usr->passmustchange=0;
5915         }
5916
5917         ZERO_STRUCT(usr->padding1);
5918         ZERO_STRUCT(usr->padding2);
5919
5920         copy_unistr2(&usr->uni_user_name, user_name);
5921         init_uni_hdr(&usr->hdr_user_name, &usr->uni_user_name);
5922
5923         copy_unistr2(&usr->uni_full_name, full_name);
5924         init_uni_hdr(&usr->hdr_full_name, &usr->uni_full_name);
5925
5926         copy_unistr2(&usr->uni_home_dir, home_dir);
5927         init_uni_hdr(&usr->hdr_home_dir, &usr->uni_home_dir);
5928
5929         copy_unistr2(&usr->uni_dir_drive, dir_drive);
5930         init_uni_hdr(&usr->hdr_dir_drive, &usr->uni_dir_drive);
5931
5932         copy_unistr2(&usr->uni_logon_script, log_scr);
5933         init_uni_hdr(&usr->hdr_logon_script, &usr->uni_logon_script);
5934
5935         copy_unistr2(&usr->uni_profile_path, prof_path);
5936         init_uni_hdr(&usr->hdr_profile_path, &usr->uni_profile_path);
5937
5938         copy_unistr2(&usr->uni_acct_desc, desc);
5939         init_uni_hdr(&usr->hdr_acct_desc, &usr->uni_acct_desc);
5940
5941         copy_unistr2(&usr->uni_workstations, wkstas);
5942         init_uni_hdr(&usr->hdr_workstations, &usr->uni_workstations);
5943
5944         copy_unistr2(&usr->uni_unknown_str, unk_str);
5945         init_uni_hdr(&usr->hdr_unknown_str, &usr->uni_unknown_str);
5946
5947         copy_unistr2(&usr->uni_munged_dial, mung_dial);
5948         init_uni_hdr(&usr->hdr_munged_dial, &usr->uni_munged_dial);
5949
5950         usr->unknown_6 = unknown_6;     /* 0x0000 04ec */
5951         usr->padding4 = 0;
5952
5953         memcpy(&usr->logon_hrs, hrs, sizeof(usr->logon_hrs));
5954 }
5955
5956 /*************************************************************************
5957  init_sam_user_info21
5958
5959  unknown_6 = 0x0000 04ec 
5960
5961  *************************************************************************/
5962
5963 NTSTATUS init_sam_user_info21A(SAM_USER_INFO_21 *usr, SAM_ACCOUNT *pw, DOM_SID *domain_sid)
5964 {
5965         NTTIME          logon_time, logoff_time, kickoff_time,
5966                         pass_last_set_time, pass_can_change_time,
5967                         pass_must_change_time;
5968                         
5969         const char*             user_name = pdb_get_username(pw);
5970         const char*             full_name = pdb_get_fullname(pw);
5971         const char*             home_dir  = pdb_get_homedir(pw);
5972         const char*             dir_drive = pdb_get_dir_drive(pw);
5973         const char*             logon_script = pdb_get_logon_script(pw);
5974         const char*             profile_path = pdb_get_profile_path(pw);
5975         const char*             description = pdb_get_acct_desc(pw);
5976         const char*             workstations = pdb_get_workstations(pw);
5977         const char*             munged_dial = pdb_get_munged_dial(pw);
5978         DATA_BLOB               munged_dial_blob;
5979
5980         uint32 user_rid;
5981         const DOM_SID *user_sid;
5982
5983         uint32 group_rid;
5984         const DOM_SID *group_sid;
5985
5986         if (munged_dial) {
5987                 munged_dial_blob = base64_decode_data_blob(munged_dial);
5988         } else {
5989                 munged_dial_blob = data_blob(NULL, 0);
5990         }
5991
5992         /* Create NTTIME structs */
5993         unix_to_nt_time (&logon_time,           pdb_get_logon_time(pw));
5994         unix_to_nt_time (&logoff_time,          pdb_get_logoff_time(pw));
5995         unix_to_nt_time (&kickoff_time,         pdb_get_kickoff_time(pw));
5996         unix_to_nt_time (&pass_last_set_time,   pdb_get_pass_last_set_time(pw));
5997         unix_to_nt_time (&pass_can_change_time, pdb_get_pass_can_change_time(pw));
5998         unix_to_nt_time (&pass_must_change_time,pdb_get_pass_must_change_time(pw));
5999         
6000         /* structure assignment */
6001         usr->logon_time            = logon_time;
6002         usr->logoff_time           = logoff_time;
6003         usr->kickoff_time          = kickoff_time;
6004         usr->pass_last_set_time    = pass_last_set_time;
6005         usr->pass_can_change_time  = pass_can_change_time;
6006         usr->pass_must_change_time = pass_must_change_time;
6007
6008         ZERO_STRUCT(usr->nt_pwd);
6009         ZERO_STRUCT(usr->lm_pwd);
6010
6011         user_sid = pdb_get_user_sid(pw);
6012         
6013         if (!sid_peek_check_rid(domain_sid, user_sid, &user_rid)) {
6014                 fstring user_sid_string;
6015                 fstring domain_sid_string;
6016                 DEBUG(0, ("init_sam_user_info_21A: User %s has SID %s, \nwhich conflicts with "
6017                           "the domain sid %s.  Failing operation.\n", 
6018                           user_name, 
6019                           sid_to_string(user_sid_string, user_sid),
6020                           sid_to_string(domain_sid_string, domain_sid)));
6021                 data_blob_free(&munged_dial_blob);
6022                 return NT_STATUS_UNSUCCESSFUL;
6023         }
6024
6025         group_sid = pdb_get_group_sid(pw);
6026         
6027         if (!sid_peek_check_rid(domain_sid, group_sid, &group_rid)) {
6028                 fstring group_sid_string;
6029                 fstring domain_sid_string;
6030                 DEBUG(0, ("init_sam_user_info_21A: User %s has Primary Group SID %s, \n"
6031                           "which conflicts with the domain sid %s.  Failing operation.\n", 
6032                           user_name, 
6033                           sid_to_string(group_sid_string, group_sid),
6034                           sid_to_string(domain_sid_string, domain_sid)));
6035                 data_blob_free(&munged_dial_blob);
6036                 return NT_STATUS_UNSUCCESSFUL;
6037         }
6038
6039         usr->user_rid  = user_rid;
6040         usr->group_rid = group_rid;
6041         usr->acb_info  = pdb_get_acct_ctrl(pw);
6042
6043         /*
6044           Look at a user on a real NT4 PDC with usrmgr, press
6045           'ok'. Then you will see that fields_present is set to
6046           0x08f827fa. Look at the user immediately after that again,
6047           and you will see that 0x00fffff is returned. This solves
6048           the problem that you get access denied after having looked
6049           at the user.
6050           -- Volker
6051         */
6052         usr->fields_present = pdb_build_fields_present(pw);
6053
6054         usr->logon_divs = pdb_get_logon_divs(pw); 
6055         usr->ptr_logon_hrs = pdb_get_hours(pw) ? 1 : 0;
6056         usr->bad_password_count = pdb_get_bad_password_count(pw);
6057         usr->logon_count = pdb_get_logon_count(pw);
6058
6059         if (pdb_get_pass_must_change_time(pw) == 0) {
6060                 usr->passmustchange=PASS_MUST_CHANGE_AT_NEXT_LOGON;
6061         } else {
6062                 usr->passmustchange=0;
6063         }
6064
6065         ZERO_STRUCT(usr->padding1);
6066         ZERO_STRUCT(usr->padding2);
6067
6068         init_unistr2(&usr->uni_user_name, user_name, UNI_STR_TERMINATE);
6069         init_uni_hdr(&usr->hdr_user_name, &usr->uni_user_name);
6070
6071         init_unistr2(&usr->uni_full_name, full_name, UNI_STR_TERMINATE);
6072         init_uni_hdr(&usr->hdr_full_name, &usr->uni_full_name);
6073
6074         init_unistr2(&usr->uni_home_dir, home_dir, UNI_STR_TERMINATE);
6075         init_uni_hdr(&usr->hdr_home_dir, &usr->uni_home_dir);
6076
6077         init_unistr2(&usr->uni_dir_drive, dir_drive, UNI_STR_TERMINATE);
6078         init_uni_hdr(&usr->hdr_dir_drive, &usr->uni_dir_drive);
6079
6080         init_unistr2(&usr->uni_logon_script, logon_script, UNI_STR_TERMINATE);
6081         init_uni_hdr(&usr->hdr_logon_script, &usr->uni_logon_script);
6082
6083         init_unistr2(&usr->uni_profile_path, profile_path, UNI_STR_TERMINATE);
6084         init_uni_hdr(&usr->hdr_profile_path, &usr->uni_profile_path);
6085
6086         init_unistr2(&usr->uni_acct_desc, description, UNI_STR_TERMINATE);
6087         init_uni_hdr(&usr->hdr_acct_desc, &usr->uni_acct_desc);
6088
6089         init_unistr2(&usr->uni_workstations, workstations, UNI_STR_TERMINATE);
6090         init_uni_hdr(&usr->hdr_workstations, &usr->uni_workstations);
6091
6092         init_unistr2(&usr->uni_unknown_str, NULL, UNI_STR_TERMINATE);
6093         init_uni_hdr(&usr->hdr_unknown_str, &usr->uni_unknown_str);
6094
6095         init_unistr2_from_datablob(&usr->uni_munged_dial, &munged_dial_blob);
6096         init_uni_hdr(&usr->hdr_munged_dial, &usr->uni_munged_dial);
6097         data_blob_free(&munged_dial_blob);
6098
6099         usr->unknown_6 = pdb_get_unknown_6(pw);
6100         usr->padding4 = 0;
6101
6102         if (pdb_get_hours(pw)) {
6103                 usr->logon_hrs.len = pdb_get_hours_len(pw);
6104                 memcpy(&usr->logon_hrs.hours, pdb_get_hours(pw), MAX_HOURS_LEN);
6105         } else
6106                 memset(&usr->logon_hrs, 0xff, sizeof(usr->logon_hrs));
6107
6108         return NT_STATUS_OK;
6109 }
6110
6111 /*******************************************************************
6112 reads or writes a structure.
6113 ********************************************************************/
6114
6115 static BOOL sam_io_user_info21(const char *desc, SAM_USER_INFO_21 * usr,
6116                         prs_struct *ps, int depth)
6117 {
6118         if (usr == NULL)
6119                 return False;
6120
6121         prs_debug(ps, depth, desc, "sam_io_user_info21");
6122         depth++;
6123
6124         if(!prs_align(ps))
6125                 return False;
6126
6127         if(!smb_io_time("logon_time           ", &usr->logon_time, ps, depth))
6128                 return False;
6129         if(!smb_io_time("logoff_time          ", &usr->logoff_time, ps, depth))
6130                 return False;
6131         if(!smb_io_time("pass_last_set_time   ", &usr->pass_last_set_time, ps,depth))
6132                 return False;
6133         if(!smb_io_time("kickoff_time         ", &usr->kickoff_time, ps, depth))
6134                 return False;
6135         if(!smb_io_time("pass_can_change_time ", &usr->pass_can_change_time, ps,depth))
6136                 return False;
6137         if(!smb_io_time("pass_must_change_time", &usr->pass_must_change_time,  ps, depth))
6138                 return False;
6139
6140         if(!smb_io_unihdr("hdr_user_name   ", &usr->hdr_user_name, ps, depth))  /* username unicode string header */
6141                 return False;
6142         if(!smb_io_unihdr("hdr_full_name   ", &usr->hdr_full_name, ps, depth))  /* user's full name unicode string header */
6143                 return False;
6144         if(!smb_io_unihdr("hdr_home_dir    ", &usr->hdr_home_dir, ps, depth))   /* home directory unicode string header */
6145                 return False;
6146         if(!smb_io_unihdr("hdr_dir_drive   ", &usr->hdr_dir_drive, ps, depth))  /* home directory drive */
6147                 return False;
6148         if(!smb_io_unihdr("hdr_logon_script", &usr->hdr_logon_script, ps, depth))       /* logon script unicode string header */
6149                 return False;
6150         if(!smb_io_unihdr("hdr_profile_path", &usr->hdr_profile_path, ps, depth))       /* profile path unicode string header */
6151                 return False;
6152         if(!smb_io_unihdr("hdr_acct_desc   ", &usr->hdr_acct_desc, ps, depth))  /* account desc */
6153                 return False;
6154         if(!smb_io_unihdr("hdr_workstations", &usr->hdr_workstations, ps, depth))       /* wkstas user can log on from */
6155                 return False;
6156         if(!smb_io_unihdr("hdr_unknown_str ", &usr->hdr_unknown_str, ps, depth))        /* unknown string */
6157                 return False;
6158         if(!smb_io_unihdr("hdr_munged_dial ", &usr->hdr_munged_dial, ps, depth))        /* wkstas user can log on from */
6159                 return False;
6160
6161         if(!prs_uint8s(False, "lm_pwd        ", ps, depth, usr->lm_pwd, sizeof(usr->lm_pwd)))
6162                 return False;
6163         if(!prs_uint8s(False, "nt_pwd        ", ps, depth, usr->nt_pwd, sizeof(usr->nt_pwd)))
6164                 return False;
6165
6166         if(!prs_uint32("user_rid      ", ps, depth, &usr->user_rid))    /* User ID */
6167                 return False;
6168         if(!prs_uint32("group_rid     ", ps, depth, &usr->group_rid))   /* Group ID */
6169                 return False;
6170         if(!prs_uint32("acb_info      ", ps, depth, &usr->acb_info))
6171                 return False;
6172
6173         if(!prs_uint32("fields_present ", ps, depth, &usr->fields_present))
6174                 return False;
6175         if(!prs_uint16("logon_divs    ", ps, depth, &usr->logon_divs))  /* logon divisions per week */
6176                 return False;
6177         if(!prs_align(ps))
6178                 return False;
6179         if(!prs_uint32("ptr_logon_hrs ", ps, depth, &usr->ptr_logon_hrs))
6180                 return False;
6181
6182         if(!prs_uint16("bad_password_count     ", ps, depth, &usr->bad_password_count))
6183                 return False;
6184         if(!prs_uint16("logon_count     ", ps, depth, &usr->logon_count))
6185                 return False;
6186
6187         if(!prs_uint8s(False, "padding1      ", ps, depth, usr->padding1, sizeof(usr->padding1)))
6188                 return False;
6189         if(!prs_uint8("passmustchange ", ps, depth, &usr->passmustchange))
6190                 return False;
6191         if(!prs_uint8("padding2       ", ps, depth, &usr->padding2))
6192                 return False;
6193
6194         /* here begins pointed-to data */
6195
6196         if(!smb_io_unistr2("uni_user_name   ", &usr->uni_user_name,usr->hdr_user_name.buffer, ps, depth))       /* username unicode string */
6197                 return False;
6198         if(!smb_io_unistr2("uni_full_name   ", &usr->uni_full_name, usr->hdr_full_name.buffer, ps, depth))      /* user's full name unicode string */
6199                 return False;
6200         if(!smb_io_unistr2("uni_home_dir    ", &usr->uni_home_dir, usr->hdr_home_dir.buffer, ps, depth))        /* home directory unicode string */
6201                 return False;
6202         if(!smb_io_unistr2("uni_dir_drive   ", &usr->uni_dir_drive, usr->hdr_dir_drive.buffer, ps, depth))      /* home directory drive unicode string */
6203                 return False;
6204         if(!smb_io_unistr2("uni_logon_script", &usr->uni_logon_script, usr->hdr_logon_script.buffer, ps, depth))        /* logon script unicode string */
6205                 return False;
6206         if(!smb_io_unistr2("uni_profile_path", &usr->uni_profile_path, usr->hdr_profile_path.buffer, ps, depth))        /* profile path unicode string */
6207                 return False;
6208         if(!smb_io_unistr2("uni_acct_desc   ", &usr->uni_acct_desc, usr->hdr_acct_desc.buffer, ps, depth))      /* user desc unicode string */
6209                 return False;
6210         if(!smb_io_unistr2("uni_workstations", &usr->uni_workstations, usr->hdr_workstations.buffer, ps, depth))        /* worksations user can log on from */
6211                 return False;
6212         if(!smb_io_unistr2("uni_unknown_str ", &usr->uni_unknown_str, usr->hdr_unknown_str.buffer, ps, depth))  /* unknown string */
6213                 return False;
6214         if(!smb_io_unistr2("uni_munged_dial ", &usr->uni_munged_dial,usr->hdr_munged_dial.buffer, ps, depth))   /* worksations user can log on from */
6215                 return False;
6216
6217         /* ok, this is only guess-work (as usual) */
6218         if (usr->ptr_logon_hrs) {
6219                 if(!prs_align(ps))
6220                         return False;
6221                 if(!prs_uint32("unknown_6     ", ps, depth, &usr->unknown_6))
6222                         return False;
6223                 if(!prs_uint32("padding4      ", ps, depth, &usr->padding4))
6224                         return False;
6225                 if(!sam_io_logon_hrs("logon_hrs", &usr->logon_hrs, ps, depth))
6226                         return False;
6227         } else if (UNMARSHALLING(ps)) {
6228                 usr->unknown_6 = 0;
6229                 usr->padding4 = 0;
6230         }
6231
6232         return True;
6233 }
6234
6235 void init_sam_user_info20A(SAM_USER_INFO_20 *usr, SAM_ACCOUNT *pw)
6236 {
6237         const char *munged_dial = pdb_get_munged_dial(pw);
6238         DATA_BLOB blob = base64_decode_data_blob(munged_dial);
6239         
6240         init_unistr2_from_datablob(&usr->uni_munged_dial, &blob);
6241         init_uni_hdr(&usr->hdr_munged_dial, &usr->uni_munged_dial);
6242         data_blob_free(&blob);
6243 }
6244
6245 /*******************************************************************
6246 reads or writes a structure.
6247 ********************************************************************/
6248
6249 static BOOL sam_io_user_info20(const char *desc, SAM_USER_INFO_20 *usr,
6250                         prs_struct *ps, int depth)
6251 {
6252         if (usr == NULL)
6253                 return False;
6254
6255         prs_debug(ps, depth, desc, "sam_io_user_info20");
6256         depth++;
6257
6258         if(!prs_align(ps))
6259                 return False;
6260
6261         if(!smb_io_unihdr("hdr_munged_dial ", &usr->hdr_munged_dial, ps, depth))        /* wkstas user can log on from */
6262                 return False;
6263
6264         if(!smb_io_unistr2("uni_munged_dial ", &usr->uni_munged_dial,usr->hdr_munged_dial.buffer, ps, depth))   /* worksations user can log on from */
6265                 return False;
6266
6267         return True;
6268 }
6269
6270 /*******************************************************************
6271 inits a SAM_USERINFO_CTR structure.
6272 ********************************************************************/
6273
6274 NTSTATUS make_samr_userinfo_ctr_usr21(TALLOC_CTX *ctx, SAM_USERINFO_CTR * ctr,
6275                                     uint16 switch_value,
6276                                     SAM_USER_INFO_21 * usr)
6277 {
6278         DEBUG(5, ("init_samr_userinfo_ctr\n"));
6279
6280         ctr->switch_value = switch_value;
6281         ctr->info.id = NULL;
6282
6283         switch (switch_value) {
6284         case 0x10:
6285                 ctr->info.id10 = (SAM_USER_INFO_10 *)talloc_zero(ctx,sizeof(SAM_USER_INFO_10));
6286                 if (ctr->info.id10 == NULL)
6287                         return NT_STATUS_NO_MEMORY;
6288
6289                 init_sam_user_info10(ctr->info.id10, usr->acb_info);
6290                 break;
6291 #if 0
6292 /* whoops - got this wrong.  i think.  or don't understand what's happening. */
6293         case 0x11:
6294                 {
6295                         NTTIME expire;
6296                         info = (void *)&id11;
6297
6298                         expire.low = 0xffffffff;
6299                         expire.high = 0x7fffffff;
6300
6301                         ctr->info.id = (SAM_USER_INFO_11 *) talloc_zero(ctx,sizeof(*ctr->info.id11));
6302                         init_sam_user_info11(ctr->info.id11, &expire,
6303                                              "BROOKFIELDS$",    /* name */
6304                                              0x03ef,    /* user rid */
6305                                              0x201,     /* group rid */
6306                                              0x0080);   /* acb info */
6307
6308                         break;
6309                 }
6310 #endif
6311         case 0x12:
6312                 ctr->info.id12 = (SAM_USER_INFO_12 *)talloc_zero(ctx,sizeof(SAM_USER_INFO_12));
6313                 if (ctr->info.id12 == NULL)
6314                         return NT_STATUS_NO_MEMORY;
6315
6316                 init_sam_user_info12(ctr->info.id12, usr->lm_pwd, usr->nt_pwd);
6317                 break;
6318         case 21:
6319                 {
6320                         SAM_USER_INFO_21 *cusr;
6321                         cusr = (SAM_USER_INFO_21 *)talloc_zero(ctx,sizeof(SAM_USER_INFO_21));
6322                         ctr->info.id21 = cusr;
6323                         if (ctr->info.id21 == NULL)
6324                                 return NT_STATUS_NO_MEMORY;
6325                         memcpy(cusr, usr, sizeof(*usr));
6326                         memset(cusr->lm_pwd, 0, sizeof(cusr->lm_pwd));
6327                         memset(cusr->nt_pwd, 0, sizeof(cusr->nt_pwd));
6328                         break;
6329                 }
6330         default:
6331                 DEBUG(4,("make_samr_userinfo_ctr: unsupported info\n"));
6332                 return NT_STATUS_INVALID_INFO_CLASS;
6333         }
6334
6335         return NT_STATUS_OK;
6336 }
6337
6338 /*******************************************************************
6339 inits a SAM_USERINFO_CTR structure.
6340 ********************************************************************/
6341
6342 static void init_samr_userinfo_ctr(SAM_USERINFO_CTR * ctr, DATA_BLOB *sess_key,
6343                                    uint16 switch_value, void *info)
6344 {
6345         DEBUG(5, ("init_samr_userinfo_ctr\n"));
6346
6347         ctr->switch_value = switch_value;
6348         ctr->info.id = info;
6349
6350         switch (switch_value) {
6351         case 0x18:
6352                 SamOEMhashBlob(ctr->info.id24->pass, 516, sess_key);
6353                 dump_data(100, (char *)sess_key->data, sess_key->length);
6354                 dump_data(100, (char *)ctr->info.id24->pass, 516);
6355                 break;
6356         case 0x17:
6357                 SamOEMhashBlob(ctr->info.id23->pass, 516, sess_key);
6358                 dump_data(100, (char *)sess_key->data, sess_key->length);
6359                 dump_data(100, (char *)ctr->info.id23->pass, 516);
6360                 break;
6361         default:
6362                 DEBUG(4,("init_samr_userinfo_ctr: unsupported switch level\n"));
6363         }
6364 }
6365
6366 /*******************************************************************
6367 reads or writes a structure.
6368 ********************************************************************/
6369
6370 static BOOL samr_io_userinfo_ctr(const char *desc, SAM_USERINFO_CTR **ppctr,
6371                                  prs_struct *ps, int depth)
6372 {
6373         BOOL ret;
6374         SAM_USERINFO_CTR *ctr;
6375
6376         prs_debug(ps, depth, desc, "samr_io_userinfo_ctr");
6377         depth++;
6378
6379         if (UNMARSHALLING(ps)) {
6380                 ctr = (SAM_USERINFO_CTR *)prs_alloc_mem(ps,sizeof(SAM_USERINFO_CTR));
6381                 if (ctr == NULL)
6382                         return False;
6383                 *ppctr = ctr;
6384         } else {
6385                 ctr = *ppctr;
6386         }
6387
6388         /* lkclXXXX DO NOT ALIGN BEFORE READING SWITCH VALUE! */
6389
6390         if(!prs_uint16("switch_value", ps, depth, &ctr->switch_value))
6391                 return False;
6392         if(!prs_align(ps))
6393                 return False;
6394
6395         ret = False;
6396
6397         switch (ctr->switch_value) {
6398         case 0x10:
6399                 if (UNMARSHALLING(ps))
6400                         ctr->info.id10 = (SAM_USER_INFO_10 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_10));
6401                 if (ctr->info.id10 == NULL) {
6402                         DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6403                         return False;
6404                 }
6405                 ret = sam_io_user_info10("", ctr->info.id10, ps, depth);
6406                 break;
6407         case 0x11:
6408                 if (UNMARSHALLING(ps))
6409                         ctr->info.id11 = (SAM_USER_INFO_11 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_11));
6410
6411                 if (ctr->info.id11 == NULL) {
6412                         DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6413                         return False;
6414                 }
6415                 ret = sam_io_user_info11("", ctr->info.id11, ps, depth);
6416                 break;
6417         case 0x12:
6418                 if (UNMARSHALLING(ps))
6419                         ctr->info.id12 = (SAM_USER_INFO_12 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_12));
6420
6421                 if (ctr->info.id12 == NULL) {
6422                         DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6423                         return False;
6424                 }
6425                 ret = sam_io_user_info12("", ctr->info.id12, ps, depth);
6426                 break;
6427         case 20:
6428                 if (UNMARSHALLING(ps))
6429                         ctr->info.id20 = (SAM_USER_INFO_20 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_20));
6430
6431                 if (ctr->info.id20 == NULL) {
6432                         DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6433                         return False;
6434                 }
6435                 ret = sam_io_user_info20("", ctr->info.id20, ps, depth);
6436                 break;
6437         case 21:
6438                 if (UNMARSHALLING(ps))
6439                         ctr->info.id21 = (SAM_USER_INFO_21 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_21));
6440
6441                 if (ctr->info.id21 == NULL) {
6442                         DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6443                         return False;
6444                 }
6445                 ret = sam_io_user_info21("", ctr->info.id21, ps, depth);
6446                 break;
6447         case 23:
6448                 if (UNMARSHALLING(ps))
6449                         ctr->info.id23 = (SAM_USER_INFO_23 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_23));
6450
6451                 if (ctr->info.id23 == NULL) {
6452                         DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6453                         return False;
6454                 }
6455                 ret = sam_io_user_info23("", ctr->info.id23, ps, depth);
6456                 break;
6457         case 24:
6458                 if (UNMARSHALLING(ps))
6459                         ctr->info.id24 = (SAM_USER_INFO_24 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_24));
6460
6461                 if (ctr->info.id24 == NULL) {
6462                         DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6463                         return False;
6464                 }
6465                 ret = sam_io_user_info24("", ctr->info.id24, ps,  depth);
6466                 break;
6467         case 25:
6468                 if (UNMARSHALLING(ps))
6469                         ctr->info.id25 = (SAM_USER_INFO_25 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_25));
6470
6471                 if (ctr->info.id25 == NULL) {
6472                         DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6473                         return False;
6474                 }
6475                 ret = sam_io_user_info25("", ctr->info.id25, ps, depth);
6476                 break;
6477         default:
6478                 DEBUG(2, ("samr_io_userinfo_ctr: unknown switch level 0x%x\n", ctr->switch_value));
6479                 ret = False;
6480                 break;
6481         }
6482
6483         return ret;
6484 }
6485
6486 /*******************************************************************
6487 inits a SAMR_R_QUERY_USERINFO structure.
6488 ********************************************************************/
6489
6490 void init_samr_r_query_userinfo(SAMR_R_QUERY_USERINFO * r_u,
6491                                 SAM_USERINFO_CTR * ctr, NTSTATUS status)
6492 {
6493         DEBUG(5, ("init_samr_r_query_userinfo\n"));
6494
6495         r_u->ptr = 0;
6496         r_u->ctr = NULL;
6497
6498         if (NT_STATUS_IS_OK(status)) {
6499                 r_u->ptr = 1;
6500                 r_u->ctr = ctr;
6501         }
6502
6503         r_u->status = status;   /* return status */
6504 }
6505
6506 /*******************************************************************
6507 reads or writes a structure.
6508 ********************************************************************/
6509
6510 BOOL samr_io_r_query_userinfo(const char *desc, SAMR_R_QUERY_USERINFO * r_u,
6511                               prs_struct *ps, int depth)
6512 {
6513         if (r_u == NULL)
6514                 return False;
6515
6516         prs_debug(ps, depth, desc, "samr_io_r_query_userinfo");
6517         depth++;
6518
6519         if(!prs_align(ps))
6520                 return False;
6521
6522         if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
6523                 return False;
6524
6525         if (r_u->ptr != 0) {
6526                 if(!samr_io_userinfo_ctr("ctr", &r_u->ctr, ps, depth))
6527                         return False;
6528         }
6529
6530         if(!prs_align(ps))
6531                 return False;
6532         if(!prs_ntstatus("status", ps, depth, &r_u->status))
6533                 return False;
6534
6535         return True;
6536 }
6537
6538 /*******************************************************************
6539 inits a SAMR_Q_SET_USERINFO structure.
6540 ********************************************************************/
6541
6542 void init_samr_q_set_userinfo(SAMR_Q_SET_USERINFO * q_u,
6543                               POLICY_HND *hnd, DATA_BLOB *sess_key,
6544                               uint16 switch_value, void *info)
6545 {
6546         DEBUG(5, ("init_samr_q_set_userinfo\n"));
6547
6548         q_u->pol = *hnd;
6549         q_u->switch_value = switch_value;
6550         init_samr_userinfo_ctr(q_u->ctr, sess_key, switch_value, info);
6551 }
6552
6553 /*******************************************************************
6554 reads or writes a structure.
6555 ********************************************************************/
6556
6557 BOOL samr_io_q_set_userinfo(const char *desc, SAMR_Q_SET_USERINFO * q_u,
6558                             prs_struct *ps, int depth)
6559 {
6560         if (q_u == NULL)
6561                 return False;
6562
6563         prs_debug(ps, depth, desc, "samr_io_q_set_userinfo");
6564         depth++;
6565
6566         if(!prs_align(ps))
6567                 return False;
6568
6569         smb_io_pol_hnd("pol", &(q_u->pol), ps, depth);
6570
6571         if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
6572                 return False;
6573         if(!samr_io_userinfo_ctr("ctr", &q_u->ctr, ps, depth))
6574                 return False;
6575
6576         return True;
6577 }
6578
6579 /*******************************************************************
6580 inits a SAMR_R_SET_USERINFO structure.
6581 ********************************************************************/
6582
6583 void init_samr_r_set_userinfo(SAMR_R_SET_USERINFO * r_u, NTSTATUS status)
6584 {
6585         DEBUG(5, ("init_samr_r_set_userinfo\n"));
6586
6587         r_u->status = status;   /* return status */
6588 }
6589
6590 /*******************************************************************
6591 reads or writes a structure.
6592 ********************************************************************/
6593
6594 BOOL samr_io_r_set_userinfo(const char *desc, SAMR_R_SET_USERINFO * r_u,
6595                             prs_struct *ps, int depth)
6596 {
6597         if (r_u == NULL)
6598                 return False;
6599
6600         prs_debug(ps, depth, desc, "samr_io_r_set_userinfo");
6601         depth++;
6602
6603         if(!prs_align(ps))
6604                 return False;
6605
6606         if(!prs_ntstatus("status", ps, depth, &r_u->status))
6607                 return False;
6608
6609         return True;
6610 }
6611
6612 /*******************************************************************
6613 inits a SAMR_Q_SET_USERINFO2 structure.
6614 ********************************************************************/
6615
6616 void init_samr_q_set_userinfo2(SAMR_Q_SET_USERINFO2 * q_u,
6617                                POLICY_HND *hnd, DATA_BLOB *sess_key,
6618                                uint16 switch_value, SAM_USERINFO_CTR * ctr)
6619 {
6620         DEBUG(5, ("init_samr_q_set_userinfo2\n"));
6621
6622         q_u->pol = *hnd;
6623         q_u->switch_value = switch_value;
6624         q_u->ctr = ctr;
6625
6626         if (q_u->ctr != NULL)
6627                 q_u->ctr->switch_value = switch_value;
6628
6629         switch (switch_value) {
6630         case 0x12:
6631                 SamOEMhashBlob(ctr->info.id12->lm_pwd, 16, sess_key);
6632                 SamOEMhashBlob(ctr->info.id12->nt_pwd, 16, sess_key);
6633                 dump_data(100, (char *)sess_key->data, sess_key->length);
6634                 dump_data(100, (char *)ctr->info.id12->lm_pwd, 16);
6635                 dump_data(100, (char *)ctr->info.id12->nt_pwd, 16);
6636                 break;
6637         }
6638 }
6639
6640 /*******************************************************************
6641 reads or writes a structure.
6642 ********************************************************************/
6643
6644 BOOL samr_io_q_set_userinfo2(const char *desc, SAMR_Q_SET_USERINFO2 * q_u,
6645                              prs_struct *ps, int depth)
6646 {
6647         if (q_u == NULL)
6648                 return False;
6649
6650         prs_debug(ps, depth, desc, "samr_io_q_set_userinfo2");
6651         depth++;
6652
6653         if(!prs_align(ps))
6654                 return False;
6655
6656         if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
6657                 return False;
6658
6659         if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
6660                 return False;
6661         if(!samr_io_userinfo_ctr("ctr", &q_u->ctr, ps, depth))
6662                 return False;
6663
6664         return True;
6665 }
6666
6667 /*******************************************************************
6668 inits a SAMR_R_SET_USERINFO2 structure.
6669 ********************************************************************/
6670
6671 void init_samr_r_set_userinfo2(SAMR_R_SET_USERINFO2 * r_u, NTSTATUS status)
6672 {
6673         DEBUG(5, ("init_samr_r_set_userinfo2\n"));
6674
6675         r_u->status = status;   /* return status */
6676 }
6677
6678 /*******************************************************************
6679 reads or writes a structure.
6680 ********************************************************************/
6681
6682 BOOL samr_io_r_set_userinfo2(const char *desc, SAMR_R_SET_USERINFO2 * r_u,
6683                              prs_struct *ps, int depth)
6684 {
6685         if (r_u == NULL)
6686                 return False;
6687
6688         prs_debug(ps, depth, desc, "samr_io_r_set_userinfo2");
6689         depth++;
6690
6691         if(!prs_align(ps))
6692                 return False;
6693
6694         if(!prs_ntstatus("status", ps, depth, &r_u->status))
6695                 return False;
6696
6697         return True;
6698 }
6699
6700 /*******************************************************************
6701 inits a SAMR_Q_CONNECT structure.
6702 ********************************************************************/
6703
6704 void init_samr_q_connect(SAMR_Q_CONNECT * q_u,
6705                          char *srv_name, uint32 access_mask)
6706 {
6707         DEBUG(5, ("init_samr_q_connect\n"));
6708
6709         /* make PDC server name \\server */
6710         q_u->ptr_srv_name = (srv_name != NULL && *srv_name) ? 1 : 0;
6711         init_unistr2(&q_u->uni_srv_name, srv_name, UNI_STR_TERMINATE);
6712
6713         /* example values: 0x0000 0002 */
6714         q_u->access_mask = access_mask;
6715 }
6716
6717 /*******************************************************************
6718 reads or writes a structure.
6719 ********************************************************************/
6720
6721 BOOL samr_io_q_connect(const char *desc, SAMR_Q_CONNECT * q_u,
6722                        prs_struct *ps, int depth)
6723 {
6724         if (q_u == NULL)
6725                 return False;
6726
6727         prs_debug(ps, depth, desc, "samr_io_q_connect");
6728         depth++;
6729
6730         if(!prs_align(ps))
6731                 return False;
6732
6733         if(!prs_uint32("ptr_srv_name", ps, depth, &q_u->ptr_srv_name))
6734                 return False;
6735         if(!smb_io_unistr2("", &q_u->uni_srv_name, q_u->ptr_srv_name, ps, depth))
6736                 return False;
6737
6738         if(!prs_align(ps))
6739                 return False;
6740         if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
6741                 return False;
6742
6743         return True;
6744 }
6745
6746 /*******************************************************************
6747 reads or writes a structure.
6748 ********************************************************************/
6749
6750 BOOL samr_io_r_connect(const char *desc, SAMR_R_CONNECT * r_u,
6751                        prs_struct *ps, int depth)
6752 {
6753         if (r_u == NULL)
6754                 return False;
6755
6756         prs_debug(ps, depth, desc, "samr_io_r_connect");
6757         depth++;
6758
6759         if(!prs_align(ps))
6760                 return False;
6761
6762         if(!smb_io_pol_hnd("connect_pol", &r_u->connect_pol, ps, depth))
6763                 return False;
6764
6765         if(!prs_ntstatus("status", ps, depth, &r_u->status))
6766                 return False;
6767
6768         return True;
6769 }
6770
6771 /*******************************************************************
6772 inits a SAMR_Q_CONNECT4 structure.
6773 ********************************************************************/
6774
6775 void init_samr_q_connect4(SAMR_Q_CONNECT4 * q_u,
6776                           char *srv_name, uint32 access_mask)
6777 {
6778         DEBUG(5, ("init_samr_q_connect\n"));
6779
6780         /* make PDC server name \\server */
6781         q_u->ptr_srv_name = (srv_name != NULL && *srv_name) ? 1 : 0;
6782         init_unistr2(&q_u->uni_srv_name, srv_name, UNI_STR_TERMINATE);
6783
6784         /* Only value we've seen, possibly an address type ? */
6785         q_u->unk_0 = 2;
6786
6787         /* example values: 0x0000 0002 */
6788         q_u->access_mask = access_mask;
6789 }
6790
6791 /*******************************************************************
6792 reads or writes a structure.
6793 ********************************************************************/
6794
6795 BOOL samr_io_q_connect4(const char *desc, SAMR_Q_CONNECT4 * q_u,
6796                         prs_struct *ps, int depth)
6797 {
6798         if (q_u == NULL)
6799                 return False;
6800
6801         prs_debug(ps, depth, desc, "samr_io_q_connect4");
6802         depth++;
6803
6804         if(!prs_align(ps))
6805                 return False;
6806
6807         if(!prs_uint32("ptr_srv_name", ps, depth, &q_u->ptr_srv_name))
6808                 return False;
6809         if(!smb_io_unistr2("", &q_u->uni_srv_name, q_u->ptr_srv_name, ps, depth))
6810                 return False;
6811
6812         if(!prs_align(ps))
6813                 return False;
6814         if(!prs_uint32("unk_0", ps, depth, &q_u->unk_0))
6815                 return False;
6816         if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
6817                 return False;
6818
6819         return True;
6820 }
6821
6822 /*******************************************************************
6823 reads or writes a structure.
6824 ********************************************************************/
6825
6826 BOOL samr_io_r_connect4(const char *desc, SAMR_R_CONNECT4 * r_u,
6827                         prs_struct *ps, int depth)
6828 {
6829         if (r_u == NULL)
6830                 return False;
6831
6832         prs_debug(ps, depth, desc, "samr_io_r_connect4");
6833         depth++;
6834
6835         if(!prs_align(ps))
6836                 return False;
6837
6838         if(!smb_io_pol_hnd("connect_pol", &r_u->connect_pol, ps, depth))
6839                 return False;
6840
6841         if(!prs_ntstatus("status", ps, depth, &r_u->status))
6842                 return False;
6843
6844         return True;
6845 }
6846
6847 /*******************************************************************
6848 inits a SAMR_Q_CONNECT_ANON structure.
6849 ********************************************************************/
6850
6851 void init_samr_q_connect_anon(SAMR_Q_CONNECT_ANON * q_u)
6852 {
6853         DEBUG(5, ("init_samr_q_connect_anon\n"));
6854
6855         q_u->ptr = 1;
6856         q_u->unknown_0 = 0x5c;  /* server name (?!!) */
6857         q_u->unknown_1 = 0x01;
6858         q_u->access_mask = 0x20;
6859 }
6860
6861 /*******************************************************************
6862 reads or writes a structure.
6863 ********************************************************************/
6864
6865 BOOL samr_io_q_connect_anon(const char *desc, SAMR_Q_CONNECT_ANON * q_u,
6866                             prs_struct *ps, int depth)
6867 {
6868         if (q_u == NULL)
6869                 return False;
6870
6871         prs_debug(ps, depth, desc, "samr_io_q_connect_anon");
6872         depth++;
6873
6874         if(!prs_align(ps))
6875                 return False;
6876
6877         if(!prs_uint32("ptr      ", ps, depth, &q_u->ptr))
6878                 return False;
6879         if(!prs_uint16("unknown_0", ps, depth, &q_u->unknown_0))
6880                 return False;
6881         if(!prs_uint16("unknown_1", ps, depth, &q_u->unknown_1))
6882                 return False;
6883         if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
6884                 return False;
6885
6886         return True;
6887 }
6888
6889 /*******************************************************************
6890 reads or writes a structure.
6891 ********************************************************************/
6892
6893 BOOL samr_io_r_connect_anon(const char *desc, SAMR_R_CONNECT_ANON * r_u,
6894                             prs_struct *ps, int depth)
6895 {
6896         if (r_u == NULL)
6897                 return False;
6898
6899         prs_debug(ps, depth, desc, "samr_io_r_connect_anon");
6900         depth++;
6901
6902         if(!prs_align(ps))
6903                 return False;
6904
6905         if(!smb_io_pol_hnd("connect_pol", &r_u->connect_pol, ps, depth))
6906                 return False;
6907
6908         if(!prs_ntstatus("status", ps, depth, &r_u->status))
6909                 return False;
6910
6911         return True;
6912 }
6913
6914 /*******************************************************************
6915 inits a SAMR_Q_GET_DOM_PWINFO structure.
6916 ********************************************************************/
6917
6918 void init_samr_q_get_dom_pwinfo(SAMR_Q_GET_DOM_PWINFO * q_u,
6919                                 char *srv_name)
6920 {
6921         DEBUG(5, ("init_samr_q_get_dom_pwinfo\n"));
6922
6923         q_u->ptr = 1;
6924         init_unistr2(&q_u->uni_srv_name, srv_name, UNI_FLAGS_NONE);
6925         init_uni_hdr(&q_u->hdr_srv_name, &q_u->uni_srv_name);
6926 }
6927
6928 /*******************************************************************
6929 reads or writes a structure.
6930 ********************************************************************/
6931
6932 BOOL samr_io_q_get_dom_pwinfo(const char *desc, SAMR_Q_GET_DOM_PWINFO * q_u,
6933                               prs_struct *ps, int depth)
6934 {
6935         if (q_u == NULL)
6936                 return False;
6937
6938         prs_debug(ps, depth, desc, "samr_io_q_get_dom_pwinfo");
6939         depth++;
6940
6941         if(!prs_align(ps))
6942                 return False;
6943
6944         if(!prs_uint32("ptr", ps, depth, &q_u->ptr))
6945                 return False;
6946         if (q_u->ptr != 0) {
6947                 if(!smb_io_unihdr("", &q_u->hdr_srv_name, ps, depth))
6948                         return False;
6949                 if(!smb_io_unistr2("", &q_u->uni_srv_name, q_u->hdr_srv_name.buffer, ps, depth))
6950                         return False;
6951         }
6952
6953         return True;
6954 }
6955
6956 /*******************************************************************
6957 reads or writes a structure.
6958 ********************************************************************/
6959
6960 BOOL samr_io_r_get_dom_pwinfo(const char *desc, SAMR_R_GET_DOM_PWINFO * r_u,
6961                               prs_struct *ps, int depth)
6962 {
6963         if (r_u == NULL)
6964                 return False;
6965
6966         prs_debug(ps, depth, desc, "samr_io_r_get_dom_pwinfo");
6967         depth++;
6968
6969         if(!prs_align(ps))
6970                 return False;
6971
6972         /*
6973          * see the Samba4 IDL for what these actually are.
6974         */
6975
6976         if(!prs_uint16("unk_0", ps, depth, &r_u->unk_0))
6977                 return False;
6978         if(!prs_align(ps))
6979                 return False;
6980         if(!prs_uint32("unk_1", ps, depth, &r_u->unk_1))
6981                 return False;
6982
6983         if(!prs_ntstatus("status", ps, depth, &r_u->status))
6984                 return False;
6985
6986         return True;
6987 }
6988
6989 /*******************************************************************
6990 make a SAMR_ENC_PASSWD structure.
6991 ********************************************************************/
6992
6993 void init_enc_passwd(SAMR_ENC_PASSWD * pwd, const char pass[512])
6994 {
6995         ZERO_STRUCTP(pwd);
6996
6997         if (pass == NULL) {
6998                 pwd->ptr = 0;
6999         } else {
7000                 pwd->ptr = 1;
7001                 memcpy(pwd->pass, pass, sizeof(pwd->pass));
7002         }
7003 }
7004
7005 /*******************************************************************
7006 reads or writes a SAMR_ENC_PASSWD structure.
7007 ********************************************************************/
7008
7009 BOOL samr_io_enc_passwd(const char *desc, SAMR_ENC_PASSWD * pwd,
7010                         prs_struct *ps, int depth)
7011 {
7012         if (pwd == NULL)
7013                 return False;
7014
7015         prs_debug(ps, depth, desc, "samr_io_enc_passwd");
7016         depth++;
7017
7018         if(!prs_align(ps))
7019                 return False;
7020
7021         if(!prs_uint32("ptr", ps, depth, &pwd->ptr))
7022                 return False;
7023
7024         if (pwd->ptr != 0) {
7025                 if(!prs_uint8s(False, "pwd", ps, depth, pwd->pass, sizeof(pwd->pass)))
7026                         return False;
7027         }
7028
7029         return True;
7030 }
7031
7032 /*******************************************************************
7033 inits a SAMR_ENC_HASH structure.
7034 ********************************************************************/
7035
7036 void init_enc_hash(SAMR_ENC_HASH * hsh, const uchar hash[16])
7037 {
7038         ZERO_STRUCTP(hsh);
7039
7040         if (hash == NULL) {
7041                 hsh->ptr = 0;
7042         } else {
7043                 hsh->ptr = 1;
7044                 memcpy(hsh->hash, hash, sizeof(hsh->hash));
7045         }
7046 }
7047
7048 /*******************************************************************
7049 reads or writes a SAMR_ENC_HASH structure.
7050 ********************************************************************/
7051
7052 BOOL samr_io_enc_hash(const char *desc, SAMR_ENC_HASH * hsh,
7053                       prs_struct *ps, int depth)
7054 {
7055         if (hsh == NULL)
7056                 return False;
7057
7058         prs_debug(ps, depth, desc, "samr_io_enc_hash");
7059         depth++;
7060
7061         if(!prs_align(ps))
7062                 return False;
7063
7064         if(!prs_uint32("ptr ", ps, depth, &hsh->ptr))
7065                 return False;
7066         if (hsh->ptr != 0) {
7067                 if(!prs_uint8s(False, "hash", ps, depth, hsh->hash,sizeof(hsh->hash)))
7068                         return False;
7069         }
7070
7071         return True;
7072 }
7073
7074 /*******************************************************************
7075 inits a SAMR_R_GET_DOM_PWINFO structure.
7076 ********************************************************************/
7077
7078 void init_samr_q_chgpasswd_user(SAMR_Q_CHGPASSWD_USER * q_u,
7079                                 const char *dest_host, const char *user_name,
7080                                 const char nt_newpass[516],
7081                                 const uchar nt_oldhash[16],
7082                                 const char lm_newpass[516],
7083                                 const uchar lm_oldhash[16])
7084 {
7085         DEBUG(5, ("init_samr_q_chgpasswd_user\n"));
7086
7087         q_u->ptr_0 = 1;
7088         init_unistr2(&q_u->uni_dest_host, dest_host, UNI_FLAGS_NONE);
7089         init_uni_hdr(&q_u->hdr_dest_host, &q_u->uni_dest_host);
7090
7091         init_unistr2(&q_u->uni_user_name, user_name, UNI_FLAGS_NONE);
7092         init_uni_hdr(&q_u->hdr_user_name, &q_u->uni_user_name);
7093
7094         init_enc_passwd(&q_u->nt_newpass, nt_newpass);
7095         init_enc_hash(&q_u->nt_oldhash, nt_oldhash);
7096
7097         q_u->unknown = 0x01;
7098
7099         init_enc_passwd(&q_u->lm_newpass, lm_newpass);
7100         init_enc_hash(&q_u->lm_oldhash, lm_oldhash);
7101 }
7102
7103 /*******************************************************************
7104 reads or writes a structure.
7105 ********************************************************************/
7106
7107 BOOL samr_io_q_chgpasswd_user(const char *desc, SAMR_Q_CHGPASSWD_USER * q_u,
7108                               prs_struct *ps, int depth)
7109 {
7110         if (q_u == NULL)
7111                 return False;
7112
7113         prs_debug(ps, depth, desc, "samr_io_q_chgpasswd_user");
7114         depth++;
7115
7116         if(!prs_align(ps))
7117                 return False;
7118
7119         if(!prs_uint32("ptr_0", ps, depth, &q_u->ptr_0))
7120                 return False;
7121
7122         if(!smb_io_unihdr("", &q_u->hdr_dest_host, ps, depth))
7123                 return False;
7124         if(!smb_io_unistr2("", &q_u->uni_dest_host, q_u->hdr_dest_host.buffer, ps, depth))
7125                 return False;
7126
7127         if(!prs_align(ps))
7128                 return False;
7129         if(!smb_io_unihdr("", &q_u->hdr_user_name, ps, depth))
7130                 return False;
7131         if(!smb_io_unistr2("", &q_u->uni_user_name, q_u->hdr_user_name.buffer,ps, depth))
7132                 return False;
7133
7134         if(!samr_io_enc_passwd("nt_newpass", &q_u->nt_newpass, ps, depth))
7135                 return False;
7136         if(!samr_io_enc_hash("nt_oldhash", &q_u->nt_oldhash, ps, depth))
7137                 return False;
7138
7139         if(!prs_uint32("unknown", ps, depth, &q_u->unknown))
7140                 return False;
7141
7142         if(!samr_io_enc_passwd("lm_newpass", &q_u->lm_newpass, ps, depth))
7143                 return False;
7144         if(!samr_io_enc_hash("lm_oldhash", &q_u->lm_oldhash, ps, depth))
7145                 return False;
7146
7147         return True;
7148 }
7149
7150 /*******************************************************************
7151 inits a SAMR_R_CHGPASSWD_USER structure.
7152 ********************************************************************/
7153
7154 void init_samr_r_chgpasswd_user(SAMR_R_CHGPASSWD_USER * r_u, NTSTATUS status)
7155 {
7156         DEBUG(5, ("init_r_chgpasswd_user\n"));
7157
7158         r_u->status = status;
7159 }
7160
7161 /*******************************************************************
7162 reads or writes a structure.
7163 ********************************************************************/
7164
7165 BOOL samr_io_r_chgpasswd_user(const char *desc, SAMR_R_CHGPASSWD_USER * r_u,
7166                               prs_struct *ps, int depth)
7167 {
7168         if (r_u == NULL)
7169                 return False;
7170
7171         prs_debug(ps, depth, desc, "samr_io_r_chgpasswd_user");
7172         depth++;
7173
7174         if(!prs_align(ps))
7175                 return False;
7176
7177         if(!prs_ntstatus("status", ps, depth, &r_u->status))
7178                 return False;
7179
7180         return True;
7181 }
7182
7183 /*******************************************************************
7184 reads or writes a structure.
7185 ********************************************************************/
7186
7187 void init_samr_q_unknown_2e(SAMR_Q_UNKNOWN_2E *q_u,
7188                                 POLICY_HND *domain_pol, uint16 switch_value)
7189 {
7190         DEBUG(5, ("init_samr_q_unknown_2e\n"));
7191
7192         q_u->domain_pol = *domain_pol;
7193         q_u->switch_value = switch_value;
7194 }
7195
7196 /*******************************************************************
7197 reads or writes a structure.
7198 ********************************************************************/
7199
7200 BOOL samr_io_q_unknown_2e(const char *desc, SAMR_Q_UNKNOWN_2E *q_u,
7201                               prs_struct *ps, int depth)
7202 {
7203         if (q_u == NULL)
7204                 return False;
7205
7206         prs_debug(ps, depth, desc, "samr_io_q_unknown_2e");
7207         depth++;
7208
7209         if(!prs_align(ps))
7210                 return False;
7211
7212         if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
7213                 return False;
7214
7215         if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
7216                 return False;
7217
7218         return True;
7219 }
7220
7221 /*******************************************************************
7222 inits a SAMR_R_QUERY_DOMAIN_INFO structure.
7223 ********************************************************************/
7224
7225 void init_samr_r_samr_unknown_2e(SAMR_R_UNKNOWN_2E * r_u,
7226                                 uint16 switch_value, SAM_UNK_CTR * ctr,
7227                                 NTSTATUS status)
7228 {
7229         DEBUG(5, ("init_samr_r_samr_unknown_2e\n"));
7230
7231         r_u->ptr_0 = 0;
7232         r_u->switch_value = 0;
7233         r_u->status = status;   /* return status */
7234
7235         if (NT_STATUS_IS_OK(status)) {
7236                 r_u->switch_value = switch_value;
7237                 r_u->ptr_0 = 1;
7238                 r_u->ctr = ctr;
7239         }
7240 }
7241
7242 /*******************************************************************
7243 reads or writes a structure.
7244 ********************************************************************/
7245
7246 BOOL samr_io_r_samr_unknown_2e(const char *desc, SAMR_R_UNKNOWN_2E * r_u,
7247                               prs_struct *ps, int depth)
7248 {
7249         if (r_u == NULL)
7250                 return False;
7251
7252         prs_debug(ps, depth, desc, "samr_io_r_samr_unknown_2e");
7253         depth++;
7254
7255         if(!prs_align(ps))
7256                 return False;
7257
7258         if(!prs_uint32("ptr_0 ", ps, depth, &r_u->ptr_0))
7259                 return False;
7260
7261         if (r_u->ptr_0 != 0 && r_u->ctr != NULL) {
7262                 if(!prs_uint16("switch_value", ps, depth, &r_u->switch_value))
7263                         return False;
7264                 if(!prs_align(ps))
7265                         return False;
7266
7267                 switch (r_u->switch_value) {
7268                 case 0x0c:
7269                         if(!sam_io_unk_info12("unk_inf12", &r_u->ctr->info.inf12, ps, depth))
7270                                 return False;
7271                         break;
7272                 case 0x07:
7273                         if(!sam_io_unk_info7("unk_inf7",&r_u->ctr->info.inf7, ps,depth))
7274                                 return False;
7275                         break;
7276                 case 0x06:
7277                         if(!sam_io_unk_info6("unk_inf6",&r_u->ctr->info.inf6, ps,depth))
7278                                 return False;
7279                         break;
7280                 case 0x05:
7281                         if(!sam_io_unk_info5("unk_inf5",&r_u->ctr->info.inf5, ps,depth))
7282                                 return False;
7283                         break;
7284                 case 0x03:
7285                         if(!sam_io_unk_info3("unk_inf3",&r_u->ctr->info.inf3, ps,depth))
7286                                 return False;
7287                         break;
7288                 case 0x02:
7289                         if(!sam_io_unk_info2("unk_inf2",&r_u->ctr->info.inf2, ps,depth))
7290                                 return False;
7291                         break;
7292                 case 0x01:
7293                         if(!sam_io_unk_info1("unk_inf1",&r_u->ctr->info.inf1, ps,depth))
7294                                 return False;
7295                         break;
7296                 default:
7297                         DEBUG(0, ("samr_io_r_samr_unknown_2e: unknown switch level 0x%x\n",
7298                                 r_u->switch_value));
7299                         r_u->status = NT_STATUS_INVALID_INFO_CLASS;
7300                         return False;
7301                 }
7302         }
7303         
7304         if(!prs_align(ps))
7305                 return False;
7306
7307         if(!prs_ntstatus("status", ps, depth, &r_u->status))
7308                 return False;
7309         
7310         return True;
7311 }
7312
7313
7314 /*******************************************************************
7315 reads or writes a structure.
7316 ********************************************************************/
7317
7318 void init_samr_q_set_domain_info(SAMR_Q_SET_DOMAIN_INFO *q_u,
7319                                 POLICY_HND *domain_pol, uint16 switch_value, SAM_UNK_CTR *ctr)
7320 {
7321         DEBUG(5, ("init_samr_q_set_domain_info\n"));
7322
7323         q_u->domain_pol = *domain_pol;
7324         q_u->switch_value0 = switch_value;
7325
7326         q_u->switch_value = switch_value;
7327         q_u->ctr = ctr;
7328         
7329 }
7330
7331 /*******************************************************************
7332 reads or writes a structure.
7333 ********************************************************************/
7334
7335 BOOL samr_io_q_set_domain_info(const char *desc, SAMR_Q_SET_DOMAIN_INFO *q_u,
7336                               prs_struct *ps, int depth)
7337 {
7338         if (q_u == NULL)
7339                 return False;
7340
7341         prs_debug(ps, depth, desc, "samr_io_q_set_domain_info");
7342         depth++;
7343
7344         if(!prs_align(ps))
7345                 return False;
7346
7347         if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
7348                 return False;
7349
7350         if(!prs_uint16("switch_value0", ps, depth, &q_u->switch_value0))
7351                 return False;
7352
7353         if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
7354                 return False;
7355
7356         if(!prs_align(ps))
7357                 return False;
7358
7359         if ((q_u->ctr = (SAM_UNK_CTR *)prs_alloc_mem(ps, sizeof(SAM_UNK_CTR))) == NULL)
7360                 return False;
7361         
7362         switch (q_u->switch_value) {
7363
7364         case 0x0c:
7365                 if(!sam_io_unk_info12("unk_inf12", &q_u->ctr->info.inf12, ps, depth))
7366                         return False;
7367                 break;
7368         case 0x07:
7369                 if(!sam_io_unk_info7("unk_inf7",&q_u->ctr->info.inf7, ps,depth))
7370                         return False;
7371                 break;
7372         case 0x06:
7373                 if(!sam_io_unk_info6("unk_inf6",&q_u->ctr->info.inf6, ps,depth))
7374                         return False;
7375                 break;
7376         case 0x05:
7377                 if(!sam_io_unk_info5("unk_inf5",&q_u->ctr->info.inf5, ps,depth))
7378                         return False;
7379                 break;
7380         case 0x03:
7381                 if(!sam_io_unk_info3("unk_inf3",&q_u->ctr->info.inf3, ps,depth))
7382                         return False;
7383                 break;
7384         case 0x02:
7385                 if(!sam_io_unk_info2("unk_inf2",&q_u->ctr->info.inf2, ps,depth))
7386                         return False;
7387                 break;
7388         case 0x01:
7389                 if(!sam_io_unk_info1("unk_inf1",&q_u->ctr->info.inf1, ps,depth))
7390                         return False;
7391                 break;
7392         default:
7393                 DEBUG(0, ("samr_io_r_samr_unknown_2e: unknown switch level 0x%x\n",
7394                         q_u->switch_value));
7395                 return False;
7396         }
7397
7398         return True;
7399 }
7400
7401 /*******************************************************************
7402 inits a SAMR_R_QUERY_DOMAIN_INFO structure.
7403 ********************************************************************/
7404
7405 void init_samr_r_set_domain_info(SAMR_R_SET_DOMAIN_INFO * r_u, NTSTATUS status)
7406 {
7407         DEBUG(5, ("init_samr_r_set_domain_info\n"));
7408
7409         r_u->status = status;   /* return status */
7410 }
7411
7412 /*******************************************************************
7413 reads or writes a structure.
7414 ********************************************************************/
7415
7416 BOOL samr_io_r_set_domain_info(const char *desc, SAMR_R_SET_DOMAIN_INFO * r_u,
7417                               prs_struct *ps, int depth)
7418 {
7419         if (r_u == NULL)
7420                 return False;
7421
7422         prs_debug(ps, depth, desc, "samr_io_r_samr_unknown_2e");
7423         depth++;
7424
7425         if(!prs_align(ps))
7426                 return False;
7427
7428         if(!prs_ntstatus("status", ps, depth, &r_u->status))
7429                 return False;
7430         
7431         return True;
7432 }