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