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