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