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