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