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