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