d031d139552df63824c0d8da83209364e5718a33
[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, DISP_USER_INFO *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].sam;
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, DISP_USER_INFO *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].sam;
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, DISP_GROUP_INFO *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].grp;
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, DISP_USER_INFO *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].sam;
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, DISP_GROUP_INFO *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].grp;
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         uint32 ptr_sid[MAX_LOOKUP_SIDS];
4602
4603         if (r_u == NULL)
4604                 return False;
4605
4606         prs_debug(ps, depth, desc, "samr_io_r_query_aliasmem");
4607         depth++;
4608
4609         if(!prs_align(ps))
4610                 return False;
4611
4612         if(!prs_uint32("num_sids ", ps, depth, &r_u->num_sids))
4613                 return False;
4614         if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
4615                 return False;
4616
4617         if (r_u->ptr != 0) {
4618                 SMB_ASSERT_ARRAY(ptr_sid, r_u->num_sids);
4619
4620                 if (r_u->num_sids != 0) {
4621                         if(!prs_uint32("num_sids1", ps, depth, &r_u->num_sids1))
4622                                 return False;
4623
4624                         for (i = 0; i < r_u->num_sids1; i++) {
4625                                 ptr_sid[i] = 1;
4626                                 if(!prs_uint32("", ps, depth, &ptr_sid[i]))
4627                                   return False;
4628                         }
4629
4630                         for (i = 0; i < r_u->num_sids1; i++) {
4631                                 if (ptr_sid[i] != 0) {
4632                                         if(!smb_io_dom_sid2("", &r_u->sid[i], ps, depth))
4633                                                 return False;
4634                                 }
4635                         }
4636                 }
4637         }
4638
4639         if(!prs_align(ps))
4640                 return False;
4641         if(!prs_ntstatus("status", ps, depth, &r_u->status))
4642                 return False;
4643
4644         return True;
4645 }
4646
4647 /*******************************************************************
4648 inits a SAMR_Q_LOOKUP_NAMES structure.
4649 ********************************************************************/
4650
4651 NTSTATUS init_samr_q_lookup_names(TALLOC_CTX *ctx, SAMR_Q_LOOKUP_NAMES * q_u,
4652                               POLICY_HND *pol, uint32 flags,
4653                               uint32 num_names, const char **name)
4654 {
4655         uint32 i;
4656
4657         DEBUG(5, ("init_samr_q_lookup_names\n"));
4658
4659         q_u->pol = *pol;
4660
4661         q_u->num_names1 = num_names;
4662         q_u->flags = flags;
4663         q_u->ptr = 0;
4664         q_u->num_names2 = num_names;
4665
4666         if (!(q_u->hdr_name = (UNIHDR *)talloc_zero(ctx, num_names * sizeof(UNIHDR))))
4667                 return NT_STATUS_NO_MEMORY;
4668
4669         if (!(q_u->uni_name = (UNISTR2 *)talloc_zero(ctx, num_names * sizeof(UNISTR2))))
4670                 return NT_STATUS_NO_MEMORY;
4671
4672         for (i = 0; i < num_names; i++) {
4673                 int len_name = name[i] != NULL ? strlen(name[i]) : 0;
4674                 init_uni_hdr(&q_u->hdr_name[i], len_name);      /* unicode header for user_name */
4675                 init_unistr2(&q_u->uni_name[i], name[i], len_name);     /* unicode string for machine account */
4676         }
4677
4678         return NT_STATUS_OK;
4679 }
4680
4681 /*******************************************************************
4682 reads or writes a structure.
4683 ********************************************************************/
4684
4685 BOOL samr_io_q_lookup_names(const char *desc, SAMR_Q_LOOKUP_NAMES * q_u,
4686                             prs_struct *ps, int depth)
4687 {
4688         uint32 i;
4689
4690         if (q_u == NULL)
4691                 return False;
4692
4693         prs_debug(ps, depth, desc, "samr_io_q_lookup_names");
4694         depth++;
4695
4696         if (UNMARSHALLING(ps))
4697                 ZERO_STRUCTP(q_u);
4698
4699         if(!prs_align(ps))
4700                 return False;
4701
4702         if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
4703                 return False;
4704
4705         if(!prs_uint32("num_names1", ps, depth, &q_u->num_names1))
4706                 return False;
4707         if(!prs_uint32("flags     ", ps, depth, &q_u->flags))
4708                 return False;
4709         if(!prs_uint32("ptr       ", ps, depth, &q_u->ptr))
4710                 return False;
4711         if(!prs_uint32("num_names2", ps, depth, &q_u->num_names2))
4712                 return False;
4713
4714         if (UNMARSHALLING(ps) && (q_u->num_names2 != 0)) {
4715                 q_u->hdr_name = (UNIHDR *)prs_alloc_mem(ps, sizeof(UNIHDR) *
4716                                                         q_u->num_names2);
4717                 q_u->uni_name = (UNISTR2 *)prs_alloc_mem(ps, sizeof(UNISTR2) *
4718                                                          q_u->num_names2);
4719                 if (!q_u->hdr_name || !q_u->uni_name)
4720                         return False;
4721         }
4722
4723         for (i = 0; i < q_u->num_names2; i++) {
4724                 if(!smb_io_unihdr("", &q_u->hdr_name[i], ps, depth))
4725                         return False;
4726         }
4727
4728         for (i = 0; i < q_u->num_names2; i++) {
4729                 if(!smb_io_unistr2("", &q_u->uni_name[i], q_u->hdr_name[i].buffer, ps, depth))
4730                         return False;
4731         }
4732
4733         return True;
4734 }
4735
4736 /*******************************************************************
4737 inits a SAMR_R_LOOKUP_NAMES structure.
4738 ********************************************************************/
4739
4740 NTSTATUS init_samr_r_lookup_names(TALLOC_CTX *ctx, SAMR_R_LOOKUP_NAMES * r_u,
4741                               uint32 num_rids,
4742                               uint32 *rid, uint32 *type,
4743                               NTSTATUS status)
4744 {
4745         DEBUG(5, ("init_samr_r_lookup_names\n"));
4746
4747         if (NT_STATUS_IS_OK(status) && (num_rids != 0)) {
4748                 uint32 i;
4749
4750                 r_u->num_types1 = num_rids;
4751                 r_u->ptr_types = 1;
4752                 r_u->num_types2 = num_rids;
4753
4754                 r_u->num_rids1 = num_rids;
4755                 r_u->ptr_rids = 1;
4756                 r_u->num_rids2 = num_rids;
4757
4758                 if (!(r_u->rids = (uint32 *)talloc_zero(ctx, sizeof(uint32)*num_rids)))
4759                         return NT_STATUS_NO_MEMORY;
4760                 if (!(r_u->types = (uint32 *)talloc_zero(ctx, sizeof(uint32)*num_rids)))
4761                         return NT_STATUS_NO_MEMORY;
4762
4763                 if (!r_u->rids || !r_u->types)
4764                         goto empty;
4765
4766                 for (i = 0; i < num_rids; i++) {
4767                         r_u->rids[i] = rid[i];
4768                         r_u->types[i] = type[i];
4769                 }
4770         } else {
4771
4772   empty:
4773                 r_u->num_types1 = 0;
4774                 r_u->ptr_types = 0;
4775                 r_u->num_types2 = 0;
4776
4777                 r_u->num_rids1 = 0;
4778                 r_u->ptr_rids = 0;
4779                 r_u->num_rids2 = 0;
4780
4781                 r_u->rids = NULL;
4782                 r_u->types = NULL;
4783         }
4784
4785         r_u->status = status;
4786
4787         return NT_STATUS_OK;
4788 }
4789
4790 /*******************************************************************
4791 reads or writes a structure.
4792 ********************************************************************/
4793
4794 BOOL samr_io_r_lookup_names(const char *desc, SAMR_R_LOOKUP_NAMES * r_u,
4795                             prs_struct *ps, int depth)
4796 {
4797         uint32 i;
4798         fstring tmp;
4799
4800         if (r_u == NULL)
4801                 return False;
4802
4803         prs_debug(ps, depth, desc, "samr_io_r_lookup_names");
4804         depth++;
4805
4806         if (UNMARSHALLING(ps))
4807                 ZERO_STRUCTP(r_u);
4808
4809         if(!prs_align(ps))
4810                 return False;
4811
4812         if(!prs_uint32("num_rids1", ps, depth, &r_u->num_rids1))
4813                 return False;
4814         if(!prs_uint32("ptr_rids ", ps, depth, &r_u->ptr_rids))
4815                 return False;
4816
4817         if (r_u->ptr_rids != 0) {
4818                 if(!prs_uint32("num_rids2", ps, depth, &r_u->num_rids2))
4819                         return False;
4820
4821                 if (r_u->num_rids2 != r_u->num_rids1) {
4822                         /* RPC fault */
4823                         return False;
4824                 }
4825
4826                 if (UNMARSHALLING(ps))
4827                         r_u->rids = (uint32 *)prs_alloc_mem(ps, sizeof(uint32)*r_u->num_rids2);
4828
4829                 if (!r_u->rids) {
4830                         DEBUG(0, ("NULL rids in samr_io_r_lookup_names\n"));
4831                         return False;
4832                 }
4833
4834                 for (i = 0; i < r_u->num_rids2; i++) {
4835                         slprintf(tmp, sizeof(tmp) - 1, "rid[%02d]  ", i);
4836                         if(!prs_uint32(tmp, ps, depth, &r_u->rids[i]))
4837                                 return False;
4838                 }
4839         }
4840
4841         if(!prs_uint32("num_types1", ps, depth, &r_u->num_types1))
4842                 return False;
4843         if(!prs_uint32("ptr_types ", ps, depth, &r_u->ptr_types))
4844                 return False;
4845
4846         if (r_u->ptr_types != 0) {
4847                 if(!prs_uint32("num_types2", ps, depth, &r_u->num_types2))
4848                         return False;
4849
4850                 if (r_u->num_types2 != r_u->num_types1) {
4851                         /* RPC fault */
4852                         return False;
4853                 }
4854
4855                 if (UNMARSHALLING(ps))
4856                         r_u->types = (uint32 *)prs_alloc_mem(ps, sizeof(uint32)*r_u->num_types2);
4857
4858                 if (!r_u->types) {
4859                         DEBUG(0, ("NULL types in samr_io_r_lookup_names\n"));
4860                         return False;
4861                 }
4862
4863                 for (i = 0; i < r_u->num_types2; i++) {
4864                         slprintf(tmp, sizeof(tmp) - 1, "type[%02d]  ", i);
4865                         if(!prs_uint32(tmp, ps, depth, &r_u->types[i]))
4866                                 return False;
4867                 }
4868         }
4869
4870         if(!prs_ntstatus("status", ps, depth, &r_u->status))
4871                 return False;
4872
4873         return True;
4874 }
4875
4876 /*******************************************************************
4877 inits a SAMR_Q_DELETE_DOM_USER structure.
4878 ********************************************************************/
4879
4880 void init_samr_q_delete_dom_user(SAMR_Q_DELETE_DOM_USER * q_c,
4881                                  POLICY_HND *hnd)
4882 {
4883         DEBUG(5, ("init_samr_q_delete_dom_user\n"));
4884
4885         q_c->user_pol = *hnd;
4886 }
4887
4888 /*******************************************************************
4889 reads or writes a structure.
4890 ********************************************************************/
4891
4892 BOOL samr_io_q_delete_dom_user(const char *desc, SAMR_Q_DELETE_DOM_USER * q_u,
4893                                prs_struct *ps, int depth)
4894 {
4895         if (q_u == NULL)
4896                 return False;
4897
4898         prs_debug(ps, depth, desc, "samr_io_q_delete_dom_user");
4899         depth++;
4900
4901         if(!prs_align(ps))
4902                 return False;
4903
4904         if(!smb_io_pol_hnd("user_pol", &q_u->user_pol, ps, depth))
4905                 return False;
4906
4907         return True;
4908 }
4909
4910 /*******************************************************************
4911 reads or writes a structure.
4912 ********************************************************************/
4913
4914 BOOL samr_io_r_delete_dom_user(const char *desc, SAMR_R_DELETE_DOM_USER * r_u,
4915                                prs_struct *ps, int depth)
4916 {
4917         if (r_u == NULL)
4918                 return False;
4919
4920         prs_debug(ps, depth, desc, "samr_io_r_delete_dom_user");
4921         depth++;
4922
4923         if(!prs_align(ps))
4924                 return False;
4925
4926         if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
4927                 return False;
4928         if(!prs_ntstatus("status", ps, depth, &r_u->status))
4929                 return False;
4930
4931         return True;
4932 }
4933
4934 /*******************************************************************
4935 reads or writes a structure.
4936 ********************************************************************/
4937
4938 void init_samr_q_open_user(SAMR_Q_OPEN_USER * q_u,
4939                            POLICY_HND *pol,
4940                            uint32 access_mask, uint32 rid)
4941 {
4942         DEBUG(5, ("samr_init_samr_q_open_user\n"));
4943
4944         q_u->domain_pol = *pol;
4945         q_u->access_mask = access_mask;
4946         q_u->user_rid = rid;
4947 }
4948
4949 /*******************************************************************
4950 reads or writes a structure.
4951 ********************************************************************/
4952
4953 BOOL samr_io_q_open_user(const char *desc, SAMR_Q_OPEN_USER * q_u,
4954                          prs_struct *ps, int depth)
4955 {
4956         if (q_u == NULL)
4957                 return False;
4958
4959         prs_debug(ps, depth, desc, "samr_io_q_open_user");
4960         depth++;
4961
4962         if(!prs_align(ps))
4963                 return False;
4964
4965         if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
4966                 return False;
4967
4968         if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
4969                 return False;
4970         if(!prs_uint32("user_rid ", ps, depth, &q_u->user_rid))
4971                 return False;
4972
4973         return True;
4974 }
4975
4976 /*******************************************************************
4977 reads or writes a structure.
4978 ********************************************************************/
4979
4980 BOOL samr_io_r_open_user(const char *desc, SAMR_R_OPEN_USER * r_u,
4981                          prs_struct *ps, int depth)
4982 {
4983         if (r_u == NULL)
4984                 return False;
4985
4986         prs_debug(ps, depth, desc, "samr_io_r_open_user");
4987         depth++;
4988
4989         if(!prs_align(ps))
4990                 return False;
4991
4992         if(!smb_io_pol_hnd("user_pol", &r_u->user_pol, ps, depth))
4993                 return False;
4994
4995         if(!prs_ntstatus("status", ps, depth, &r_u->status))
4996                 return False;
4997
4998         return True;
4999 }
5000
5001
5002 /*******************************************************************
5003 reads or writes a structure.
5004 ********************************************************************/
5005
5006 void init_samr_q_create_user(SAMR_Q_CREATE_USER * q_u,
5007                              POLICY_HND *pol,
5008                              const char *name,
5009                              uint32 acb_info, uint32 access_mask)
5010 {
5011         int len_name;
5012         len_name = strlen(name);
5013
5014         DEBUG(5, ("samr_init_samr_q_create_user\n"));
5015
5016         q_u->domain_pol = *pol;
5017
5018         init_uni_hdr(&q_u->hdr_name, len_name);
5019         init_unistr2(&q_u->uni_name, name, len_name);
5020
5021         q_u->acb_info = acb_info;
5022         q_u->access_mask = access_mask;
5023 }
5024
5025 /*******************************************************************
5026 reads or writes a structure.
5027 ********************************************************************/
5028
5029 BOOL samr_io_q_create_user(const char *desc, SAMR_Q_CREATE_USER * q_u,
5030                            prs_struct *ps, int depth)
5031 {
5032         if (q_u == NULL)
5033                 return False;
5034
5035         prs_debug(ps, depth, desc, "samr_io_q_create_user");
5036         depth++;
5037
5038         if(!prs_align(ps))
5039                 return False;
5040
5041         if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
5042                 return False;
5043
5044         if(!smb_io_unihdr("hdr_name", &q_u->hdr_name, ps, depth))
5045                 return False;
5046         if(!smb_io_unistr2("uni_name", &q_u->uni_name, q_u->hdr_name.buffer, ps, depth))
5047                 return False;
5048
5049         if(!prs_align(ps))
5050                 return False;
5051         if(!prs_uint32("acb_info   ", ps, depth, &q_u->acb_info))
5052                 return False;
5053         if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
5054                 return False;
5055
5056         return True;
5057 }
5058
5059 /*******************************************************************
5060 reads or writes a structure.
5061 ********************************************************************/
5062
5063 BOOL samr_io_r_create_user(const char *desc, SAMR_R_CREATE_USER * r_u,
5064                            prs_struct *ps, int depth)
5065 {
5066         if (r_u == NULL)
5067                 return False;
5068
5069         prs_debug(ps, depth, desc, "samr_io_r_create_user");
5070         depth++;
5071
5072         if(!prs_align(ps))
5073                 return False;
5074
5075         if(!smb_io_pol_hnd("user_pol", &r_u->user_pol, ps, depth))
5076                 return False;
5077
5078         if(!prs_uint32("access_granted", ps, depth, &r_u->access_granted))
5079                 return False;
5080         if(!prs_uint32("user_rid ", ps, depth, &r_u->user_rid))
5081                 return False;
5082         if(!prs_ntstatus("status", ps, depth, &r_u->status))
5083                 return False;
5084
5085         return True;
5086 }
5087
5088 /*******************************************************************
5089 inits a SAMR_Q_QUERY_USERINFO structure.
5090 ********************************************************************/
5091
5092 void init_samr_q_query_userinfo(SAMR_Q_QUERY_USERINFO * q_u,
5093                                 POLICY_HND *hnd, uint16 switch_value)
5094 {
5095         DEBUG(5, ("init_samr_q_query_userinfo\n"));
5096
5097         q_u->pol = *hnd;
5098         q_u->switch_value = switch_value;
5099 }
5100
5101 /*******************************************************************
5102 reads or writes a structure.
5103 ********************************************************************/
5104
5105 BOOL samr_io_q_query_userinfo(const char *desc, SAMR_Q_QUERY_USERINFO * q_u,
5106                               prs_struct *ps, int depth)
5107 {
5108         if (q_u == NULL)
5109                 return False;
5110
5111         prs_debug(ps, depth, desc, "samr_io_q_query_userinfo");
5112         depth++;
5113
5114         if(!prs_align(ps))
5115                 return False;
5116
5117         if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
5118                 return False;
5119
5120         if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value)) /* 0x0015 or 0x0011 */
5121                 return False;
5122
5123         return True;
5124 }
5125
5126 /*******************************************************************
5127 reads or writes a LOGON_HRS structure.
5128 ********************************************************************/
5129
5130 static BOOL sam_io_logon_hrs(const char *desc, LOGON_HRS * hrs,
5131                              prs_struct *ps, int depth)
5132 {
5133         if (hrs == NULL)
5134                 return False;
5135
5136         prs_debug(ps, depth, desc, "sam_io_logon_hrs");
5137         depth++;
5138
5139         if(!prs_align(ps))
5140                 return False;
5141
5142         if(!prs_uint32("len  ", ps, depth, &hrs->len))
5143                 return False;
5144
5145         if (hrs->len > sizeof(hrs->hours)) {
5146                 DEBUG(3, ("sam_io_logon_hrs: truncating length from %d\n", hrs->len));
5147                 hrs->len = sizeof(hrs->hours);
5148         }
5149
5150         if(!prs_uint8s(False, "hours", ps, depth, hrs->hours, hrs->len))
5151                 return False;
5152
5153         return True;
5154 }
5155
5156 /*******************************************************************
5157 inits a SAM_USER_INFO_12 structure.
5158 ********************************************************************/
5159
5160 void init_sam_user_info12(SAM_USER_INFO_12 * usr,
5161                           const uint8 lm_pwd[16], const uint8 nt_pwd[16])
5162 {
5163         DEBUG(5, ("init_sam_user_info12\n"));
5164
5165         usr->lm_pwd_active =
5166                 memcpy(usr->lm_pwd, lm_pwd, sizeof(usr->lm_pwd)) ? 1 : 0;
5167         usr->nt_pwd_active =
5168                 memcpy(usr->nt_pwd, nt_pwd, sizeof(usr->nt_pwd)) ? 1 : 0;
5169 }
5170
5171 /*******************************************************************
5172 reads or writes a structure.
5173 ********************************************************************/
5174
5175 static BOOL sam_io_user_info12(const char *desc, SAM_USER_INFO_12 * u,
5176                         prs_struct *ps, int depth)
5177 {
5178         if (u == NULL)
5179                 return False;
5180
5181         prs_debug(ps, depth, desc, "samr_io_r_user_info12");
5182         depth++;
5183
5184         if(!prs_align(ps))
5185                 return False;
5186
5187         if(!prs_uint8s(False, "lm_pwd", ps, depth, u->lm_pwd, sizeof(u->lm_pwd)))
5188                 return False;
5189         if(!prs_uint8s(False, "nt_pwd", ps, depth, u->nt_pwd, sizeof(u->nt_pwd)))
5190                 return False;
5191
5192         if(!prs_uint8("lm_pwd_active", ps, depth, &u->lm_pwd_active))
5193                 return False;
5194         if(!prs_uint8("nt_pwd_active", ps, depth, &u->nt_pwd_active))
5195                 return False;
5196
5197         return True;
5198 }
5199
5200 /*******************************************************************
5201 inits a SAM_USER_INFO_10 structure.
5202 ********************************************************************/
5203
5204 void init_sam_user_info10(SAM_USER_INFO_10 * usr, uint32 acb_info)
5205 {
5206         DEBUG(5, ("init_sam_user_info10\n"));
5207
5208         usr->acb_info = acb_info;
5209 }
5210
5211 /*******************************************************************
5212 reads or writes a structure.
5213 ********************************************************************/
5214
5215 static BOOL sam_io_user_info10(const char *desc, SAM_USER_INFO_10 * usr,
5216                         prs_struct *ps, int depth)
5217 {
5218         if (usr == NULL)
5219                 return False;
5220
5221         prs_debug(ps, depth, desc, "samr_io_r_user_info10");
5222         depth++;
5223
5224         if(!prs_align(ps))
5225                 return False;
5226
5227         if(!prs_uint32("acb_info", ps, depth, &usr->acb_info))
5228                 return False;
5229
5230         return True;
5231 }
5232
5233 /*******************************************************************
5234 inits a SAM_USER_INFO_11 structure.
5235 ********************************************************************/
5236
5237 void init_sam_user_info11(SAM_USER_INFO_11 * usr,
5238                           NTTIME * expiry,
5239                           char *mach_acct,
5240                           uint32 rid_user, uint32 rid_group, uint16 acct_ctrl)
5241 {
5242         int len_mach_acct;
5243
5244         DEBUG(5, ("init_sam_user_info11\n"));
5245
5246         len_mach_acct = strlen(mach_acct);
5247
5248         memcpy(&(usr->expiry), expiry, sizeof(usr->expiry));    /* expiry time or something? */
5249         ZERO_STRUCT(usr->padding_1);    /* 0 - padding 24 bytes */
5250
5251         init_uni_hdr(&usr->hdr_mach_acct, len_mach_acct);       /* unicode header for machine account */
5252         usr->padding_2 = 0;     /* 0 - padding 4 bytes */
5253
5254         usr->ptr_1 = 1;         /* pointer */
5255         ZERO_STRUCT(usr->padding_3);    /* 0 - padding 32 bytes */
5256         usr->padding_4 = 0;     /* 0 - padding 4 bytes */
5257
5258         usr->ptr_2 = 1;         /* pointer */
5259         usr->padding_5 = 0;     /* 0 - padding 4 bytes */
5260
5261         usr->ptr_3 = 1;         /* pointer */
5262         ZERO_STRUCT(usr->padding_6);    /* 0 - padding 32 bytes */
5263
5264         usr->rid_user = rid_user;
5265         usr->rid_group = rid_group;
5266
5267         usr->acct_ctrl = acct_ctrl;
5268         usr->unknown_3 = 0x0000;
5269
5270         usr->unknown_4 = 0x003f;        /* 0x003f      - 16 bit unknown */
5271         usr->unknown_5 = 0x003c;        /* 0x003c      - 16 bit unknown */
5272
5273         ZERO_STRUCT(usr->padding_7);    /* 0 - padding 16 bytes */
5274         usr->padding_8 = 0;     /* 0 - padding 4 bytes */
5275
5276         init_unistr2(&usr->uni_mach_acct, mach_acct, len_mach_acct);    /* unicode string for machine account */
5277 }
5278
5279 /*******************************************************************
5280 reads or writes a structure.
5281 ********************************************************************/
5282
5283 static BOOL sam_io_user_info11(const char *desc, SAM_USER_INFO_11 * usr,
5284                         prs_struct *ps, int depth)
5285 {
5286         if (usr == NULL)
5287                 return False;
5288
5289         prs_debug(ps, depth, desc, "samr_io_r_unknown_11");
5290         depth++;
5291
5292         if(!prs_align(ps))
5293                 return False;
5294
5295         if(!prs_uint8s(False, "padding_0", ps, depth, usr->padding_0, sizeof(usr->padding_0)))
5296                 return False;
5297
5298         if(!smb_io_time("time", &usr->expiry, ps, depth))
5299                 return False;
5300
5301         if(!prs_uint8s(False, "padding_1", ps, depth, usr->padding_1, sizeof(usr->padding_1)))
5302                 return False;
5303
5304         if(!smb_io_unihdr("unihdr", &usr->hdr_mach_acct, ps, depth))
5305                 return False;
5306
5307         if(!prs_uint32("padding_2", ps, depth, &usr->padding_2))
5308                 return False;
5309
5310         if(!prs_uint32("ptr_1    ", ps, depth, &usr->ptr_1))
5311                 return False;
5312         if(!prs_uint8s(False, "padding_3", ps, depth, usr->padding_3, sizeof(usr->padding_3)))
5313                 return False;
5314
5315         if(!prs_uint32("padding_4", ps, depth, &usr->padding_4))
5316                 return False;
5317
5318         if(!prs_uint32("ptr_2    ", ps, depth, &usr->ptr_2))
5319                 return False;
5320         if(!prs_uint32("padding_5", ps, depth, &usr->padding_5))
5321                 return False;
5322
5323         if(!prs_uint32("ptr_3    ", ps, depth, &usr->ptr_3))
5324                 return False;
5325         if(!prs_uint8s(False, "padding_6", ps, depth, usr->padding_6,sizeof(usr->padding_6)))
5326                 return False;
5327
5328         if(!prs_uint32("rid_user ", ps, depth, &usr->rid_user))
5329                 return False;
5330         if(!prs_uint32("rid_group", ps, depth, &usr->rid_group))
5331                 return False;
5332         if(!prs_uint16("acct_ctrl", ps, depth, &usr->acct_ctrl))
5333                 return False;
5334         if(!prs_uint16("unknown_3", ps, depth, &usr->unknown_3))
5335                 return False;
5336         if(!prs_uint16("unknown_4", ps, depth, &usr->unknown_4))
5337                 return False;
5338         if(!prs_uint16("unknown_5", ps, depth, &usr->unknown_5))
5339                 return False;
5340
5341         if(!prs_uint8s(False, "padding_7", ps, depth, usr->padding_7, sizeof(usr->padding_7)))
5342                 return False;
5343
5344         if(!prs_uint32("padding_8", ps, depth, &(usr->padding_8)))
5345                 return False;
5346
5347         if(!smb_io_unistr2("unistr2", &usr->uni_mach_acct, True, ps, depth))
5348                 return False;
5349
5350         if(!prs_align(ps))
5351                 return False;
5352
5353         if(!prs_uint8s(False, "padding_9", ps, depth, usr->padding_9, sizeof(usr->padding_9)))
5354                 return False;
5355
5356         return True;
5357 }
5358
5359 /*************************************************************************
5360  init_sam_user_infoa
5361
5362  unknown_3 = 0x09f8 27fa
5363  unknown_5 = 0x0001 0000
5364  unknown_6 = 0x0000 04ec 
5365
5366  *************************************************************************/
5367
5368 void init_sam_user_info24(SAM_USER_INFO_24 * usr, char newpass[516], uint16 pw_len)
5369 {
5370         DEBUG(10, ("init_sam_user_info24:\n"));
5371         memcpy(usr->pass, newpass, sizeof(usr->pass));
5372         usr->pw_len = pw_len;
5373 }
5374
5375 /*******************************************************************
5376 reads or writes a structure.
5377 ********************************************************************/
5378
5379 static BOOL sam_io_user_info24(const char *desc, SAM_USER_INFO_24 * usr,
5380                                prs_struct *ps, int depth)
5381 {
5382         if (usr == NULL)
5383                 return False;
5384
5385         prs_debug(ps, depth, desc, "sam_io_user_info24");
5386         depth++;
5387
5388         if(!prs_align(ps))
5389                 return False;
5390
5391         if(!prs_uint8s(False, "password", ps, depth, usr->pass, 
5392                        sizeof(usr->pass)))
5393                 return False;
5394         
5395         if (MARSHALLING(ps) && (usr->pw_len != 0)) {
5396                 if (!prs_uint16("pw_len", ps, depth, &usr->pw_len))
5397                         return False;
5398         }
5399         if(!prs_align(ps))
5400                 return False;
5401
5402         return True;
5403 }
5404
5405 /*************************************************************************
5406  init_sam_user_info23
5407
5408  unknown_3 = 0x09f8 27fa
5409  unknown_5 = 0x0001 0000
5410  unknown_6 = 0x0000 04ec 
5411
5412  *************************************************************************/
5413
5414 void init_sam_user_info23W(SAM_USER_INFO_23 * usr, NTTIME * logon_time, /* all zeros */
5415                         NTTIME * logoff_time,   /* all zeros */
5416                         NTTIME * kickoff_time,  /* all zeros */
5417                         NTTIME * pass_last_set_time,    /* all zeros */
5418                         NTTIME * pass_can_change_time,  /* all zeros */
5419                         NTTIME * pass_must_change_time, /* all zeros */
5420                         UNISTR2 *user_name,
5421                         UNISTR2 *full_name,
5422                         UNISTR2 *home_dir,
5423                         UNISTR2 *dir_drive,
5424                         UNISTR2 *log_scr,
5425                         UNISTR2 *prof_path,
5426                         UNISTR2 *desc,
5427                         UNISTR2 *wkstas,
5428                         UNISTR2 *unk_str,
5429                         UNISTR2 *mung_dial,
5430                         uint32 user_rid,        /* 0x0000 0000 */
5431                         uint32 group_rid,
5432                         uint32 acb_info,
5433                         uint32 unknown_3,
5434                         uint16 logon_divs,
5435                         LOGON_HRS * hrs,
5436                         uint32 unknown_5,
5437                         char newpass[516], uint32 unknown_6)
5438 {
5439         int len_user_name = user_name != NULL ? user_name->uni_str_len : 0;
5440         int len_full_name = full_name != NULL ? full_name->uni_str_len : 0;
5441         int len_home_dir = home_dir != NULL ? home_dir->uni_str_len : 0;
5442         int len_dir_drive = dir_drive != NULL ? dir_drive->uni_str_len : 0;
5443         int len_logon_script = log_scr != NULL ? log_scr->uni_str_len : 0;
5444         int len_profile_path = prof_path != NULL ? prof_path->uni_str_len : 0;
5445         int len_description = desc != NULL ? desc->uni_str_len : 0;
5446         int len_workstations = wkstas != NULL ? wkstas->uni_str_len : 0;
5447         int len_unknown_str = unk_str != NULL ? unk_str->uni_str_len : 0;
5448         int len_munged_dial = mung_dial != NULL ? mung_dial->uni_str_len : 0;
5449
5450         usr->logon_time = *logon_time;  /* all zeros */
5451         usr->logoff_time = *logoff_time;        /* all zeros */
5452         usr->kickoff_time = *kickoff_time;      /* all zeros */
5453         usr->pass_last_set_time = *pass_last_set_time;  /* all zeros */
5454         usr->pass_can_change_time = *pass_can_change_time;      /* all zeros */
5455         usr->pass_must_change_time = *pass_must_change_time;    /* all zeros */
5456
5457         init_uni_hdr(&usr->hdr_user_name, len_user_name);       /* NULL */
5458         init_uni_hdr(&usr->hdr_full_name, len_full_name);
5459         init_uni_hdr(&usr->hdr_home_dir, len_home_dir);
5460         init_uni_hdr(&usr->hdr_dir_drive, len_dir_drive);
5461         init_uni_hdr(&usr->hdr_logon_script, len_logon_script);
5462         init_uni_hdr(&usr->hdr_profile_path, len_profile_path);
5463         init_uni_hdr(&usr->hdr_acct_desc, len_description);
5464         init_uni_hdr(&usr->hdr_workstations, len_workstations);
5465         init_uni_hdr(&usr->hdr_unknown_str, len_unknown_str);
5466         init_uni_hdr(&usr->hdr_munged_dial, len_munged_dial);
5467
5468         ZERO_STRUCT(usr->nt_pwd);
5469         ZERO_STRUCT(usr->lm_pwd);
5470
5471         usr->user_rid = user_rid;       /* 0x0000 0000 */
5472         usr->group_rid = group_rid;
5473         usr->acb_info = acb_info;
5474         usr->unknown_3 = unknown_3;     /* 09f8 27fa */
5475
5476         usr->logon_divs = logon_divs;   /* should be 168 (hours/week) */
5477         usr->ptr_logon_hrs = hrs ? 1 : 0;
5478
5479         if (nt_time_is_zero(pass_must_change_time)) {
5480                 usr->passmustchange=PASS_MUST_CHANGE_AT_NEXT_LOGON;
5481         } else {
5482                 usr->passmustchange=0;
5483         }
5484
5485
5486         ZERO_STRUCT(usr->padding1);
5487         ZERO_STRUCT(usr->padding2);
5488
5489         usr->unknown_5 = unknown_5;     /* 0x0001 0000 */
5490
5491         memcpy(usr->pass, newpass, sizeof(usr->pass));
5492
5493         copy_unistr2(&usr->uni_user_name, user_name);
5494         copy_unistr2(&usr->uni_full_name, full_name);
5495         copy_unistr2(&usr->uni_home_dir, home_dir);
5496         copy_unistr2(&usr->uni_dir_drive, dir_drive);
5497         copy_unistr2(&usr->uni_logon_script, log_scr);
5498         copy_unistr2(&usr->uni_profile_path, prof_path);
5499         copy_unistr2(&usr->uni_acct_desc, desc);
5500         copy_unistr2(&usr->uni_workstations, wkstas);
5501         copy_unistr2(&usr->uni_unknown_str, unk_str);
5502         copy_unistr2(&usr->uni_munged_dial, mung_dial);
5503
5504         usr->unknown_6 = unknown_6;     /* 0x0000 04ec */
5505         usr->padding4 = 0;
5506
5507         memcpy(&usr->logon_hrs, hrs, sizeof(usr->logon_hrs));
5508 }
5509
5510 /*************************************************************************
5511  init_sam_user_info23
5512
5513  unknown_3 = 0x09f8 27fa
5514  unknown_5 = 0x0001 0000
5515  unknown_6 = 0x0000 04ec 
5516
5517  *************************************************************************/
5518
5519 void init_sam_user_info23A(SAM_USER_INFO_23 * usr, NTTIME * logon_time, /* all zeros */
5520                            NTTIME * logoff_time,        /* all zeros */
5521                            NTTIME * kickoff_time,       /* all zeros */
5522                            NTTIME * pass_last_set_time, /* all zeros */
5523                            NTTIME * pass_can_change_time,       /* all zeros */
5524                            NTTIME * pass_must_change_time,      /* all zeros */
5525                            char *user_name,     /* NULL */
5526                            char *full_name,
5527                            char *home_dir, char *dir_drive, char *log_scr,
5528                            char *prof_path, const char *desc, char *wkstas,
5529                            char *unk_str, char *mung_dial, uint32 user_rid,     /* 0x0000 0000 */
5530                            uint32 group_rid, uint32 acb_info,
5531                            uint32 unknown_3, uint16 logon_divs,
5532                            LOGON_HRS * hrs, uint32 unknown_5,
5533                            char newpass[516], uint32 unknown_6)
5534 {
5535         int len_user_name = user_name != NULL ? strlen(user_name) : 0;
5536         int len_full_name = full_name != NULL ? strlen(full_name) : 0;
5537         int len_home_dir = home_dir != NULL ? strlen(home_dir) : 0;
5538         int len_dir_drive = dir_drive != NULL ? strlen(dir_drive) : 0;
5539         int len_logon_script = log_scr != NULL ? strlen(log_scr) : 0;
5540         int len_profile_path = prof_path != NULL ? strlen(prof_path) : 0;
5541         int len_description = desc != NULL ? strlen(desc) : 0;
5542         int len_workstations = wkstas != NULL ? strlen(wkstas) : 0;
5543         int len_unknown_str = unk_str != NULL ? strlen(unk_str) : 0;
5544         int len_munged_dial = mung_dial != NULL ? strlen(mung_dial) : 0;
5545
5546         usr->logon_time = *logon_time;  /* all zeros */
5547         usr->logoff_time = *logoff_time;        /* all zeros */
5548         usr->kickoff_time = *kickoff_time;      /* all zeros */
5549         usr->pass_last_set_time = *pass_last_set_time;  /* all zeros */
5550         usr->pass_can_change_time = *pass_can_change_time;      /* all zeros */
5551         usr->pass_must_change_time = *pass_must_change_time;    /* all zeros */
5552
5553         init_uni_hdr(&usr->hdr_user_name, len_user_name);       /* NULL */
5554         init_uni_hdr(&usr->hdr_full_name, len_full_name);
5555         init_uni_hdr(&usr->hdr_home_dir, len_home_dir);
5556         init_uni_hdr(&usr->hdr_dir_drive, len_dir_drive);
5557         init_uni_hdr(&usr->hdr_logon_script, len_logon_script);
5558         init_uni_hdr(&usr->hdr_profile_path, len_profile_path);
5559         init_uni_hdr(&usr->hdr_acct_desc, len_description);
5560         init_uni_hdr(&usr->hdr_workstations, len_workstations);
5561         init_uni_hdr(&usr->hdr_unknown_str, len_unknown_str);
5562         init_uni_hdr(&usr->hdr_munged_dial, len_munged_dial);
5563
5564         ZERO_STRUCT(usr->nt_pwd);
5565         ZERO_STRUCT(usr->lm_pwd);
5566
5567         usr->user_rid = user_rid;       /* 0x0000 0000 */
5568         usr->group_rid = group_rid;
5569         usr->acb_info = acb_info;
5570         usr->unknown_3 = unknown_3;     /* 09f8 27fa */
5571
5572         usr->logon_divs = logon_divs;   /* should be 168 (hours/week) */
5573         usr->ptr_logon_hrs = hrs ? 1 : 0;
5574
5575         if (nt_time_is_zero(pass_must_change_time)) {
5576                 usr->passmustchange=PASS_MUST_CHANGE_AT_NEXT_LOGON;
5577         } else {
5578                 usr->passmustchange=0;
5579         }
5580
5581         ZERO_STRUCT(usr->padding1);
5582         ZERO_STRUCT(usr->padding2);
5583
5584         usr->unknown_5 = unknown_5;     /* 0x0001 0000 */
5585
5586         memcpy(usr->pass, newpass, sizeof(usr->pass));
5587
5588         init_unistr2(&usr->uni_user_name, user_name, len_user_name);    /* NULL */
5589         init_unistr2(&usr->uni_full_name, full_name, len_full_name);
5590         init_unistr2(&usr->uni_home_dir, home_dir, len_home_dir);
5591         init_unistr2(&usr->uni_dir_drive, dir_drive, len_dir_drive);
5592         init_unistr2(&usr->uni_logon_script, log_scr, len_logon_script);
5593         init_unistr2(&usr->uni_profile_path, prof_path, len_profile_path);
5594         init_unistr2(&usr->uni_acct_desc, desc, len_description);
5595         init_unistr2(&usr->uni_workstations, wkstas, len_workstations);
5596         init_unistr2(&usr->uni_unknown_str, unk_str, len_unknown_str);
5597         init_unistr2(&usr->uni_munged_dial, mung_dial, len_munged_dial);
5598
5599         usr->unknown_6 = unknown_6;     /* 0x0000 04ec */
5600         usr->padding4 = 0;
5601
5602         memcpy(&usr->logon_hrs, hrs, sizeof(usr->logon_hrs));
5603 }
5604
5605 /*******************************************************************
5606 reads or writes a structure.
5607 ********************************************************************/
5608
5609 static BOOL sam_io_user_info23(const char *desc, SAM_USER_INFO_23 * usr,
5610                                prs_struct *ps, int depth)
5611 {
5612         if (usr == NULL)
5613                 return False;
5614
5615         prs_debug(ps, depth, desc, "sam_io_user_info23");
5616         depth++;
5617
5618         if(!prs_align(ps))
5619                 return False;
5620
5621         if(!smb_io_time("logon_time           ", &usr->logon_time, ps, depth))
5622                 return False;
5623         if(!smb_io_time("logoff_time          ", &usr->logoff_time, ps, depth))
5624                 return False;
5625         if(!smb_io_time("kickoff_time         ", &usr->kickoff_time, ps, depth))
5626                 return False;
5627         if(!smb_io_time("pass_last_set_time   ", &usr->pass_last_set_time, ps, depth))
5628                 return False;
5629         if(!smb_io_time("pass_can_change_time ", &usr->pass_can_change_time, ps, depth))
5630                 return False;
5631         if(!smb_io_time("pass_must_change_time", &usr->pass_must_change_time, ps, depth))
5632                 return False;
5633
5634         if(!smb_io_unihdr("hdr_user_name   ", &usr->hdr_user_name, ps, depth))  /* username unicode string header */
5635                 return False;
5636         if(!smb_io_unihdr("hdr_full_name   ", &usr->hdr_full_name, ps, depth))  /* user's full name unicode string header */
5637                 return False;
5638         if(!smb_io_unihdr("hdr_home_dir    ", &usr->hdr_home_dir, ps, depth))   /* home directory unicode string header */
5639                 return False;
5640         if(!smb_io_unihdr("hdr_dir_drive   ", &usr->hdr_dir_drive, ps, depth))  /* home directory drive */
5641                 return False;
5642         if(!smb_io_unihdr("hdr_logon_script", &usr->hdr_logon_script, ps, depth))       /* logon script unicode string header */
5643                 return False;
5644         if(!smb_io_unihdr("hdr_profile_path", &usr->hdr_profile_path, ps, depth))       /* profile path unicode string header */
5645                 return False;
5646         if(!smb_io_unihdr("hdr_acct_desc   ", &usr->hdr_acct_desc, ps, depth))  /* account desc */
5647                 return False;
5648         if(!smb_io_unihdr("hdr_workstations", &usr->hdr_workstations, ps, depth))       /* wkstas user can log on from */
5649                 return False;
5650         if(!smb_io_unihdr("hdr_unknown_str ", &usr->hdr_unknown_str, ps, depth))        /* unknown string */
5651                 return False;
5652         if(!smb_io_unihdr("hdr_munged_dial ", &usr->hdr_munged_dial, ps, depth))        /* wkstas user can log on from */
5653                 return False;
5654
5655         if(!prs_uint8s(False, "lm_pwd        ", ps, depth, usr->lm_pwd, sizeof(usr->lm_pwd)))
5656                 return False;
5657         if(!prs_uint8s(False, "nt_pwd        ", ps, depth, usr->nt_pwd, sizeof(usr->nt_pwd)))
5658                 return False;
5659
5660         if(!prs_uint32("user_rid      ", ps, depth, &usr->user_rid))    /* User ID */
5661                 return False;
5662         if(!prs_uint32("group_rid     ", ps, depth, &usr->group_rid))   /* Group ID */
5663                 return False;
5664         if(!prs_uint32("acb_info      ", ps, depth, &usr->acb_info))
5665                 return False;
5666
5667         if(!prs_uint32("unknown_3     ", ps, depth, &usr->unknown_3))
5668                 return False;
5669         if(!prs_uint16("logon_divs    ", ps, depth, &usr->logon_divs))  /* logon divisions per week */
5670                 return False;
5671         if(!prs_align(ps))
5672                 return False;
5673         if(!prs_uint32("ptr_logon_hrs ", ps, depth, &usr->ptr_logon_hrs))
5674                 return False;
5675
5676         if(!prs_uint32("unknown_5     ", ps, depth, &usr->unknown_5))
5677                 return False;
5678
5679         if(!prs_uint8s(False, "padding1      ", ps, depth, usr->padding1, sizeof(usr->padding1)))
5680                 return False;
5681         if(!prs_uint8("passmustchange ", ps, depth, &usr->passmustchange))
5682                 return False;
5683         if(!prs_uint8("padding2       ", ps, depth, &usr->padding2))
5684                 return False;
5685
5686
5687         if(!prs_uint8s(False, "password      ", ps, depth, usr->pass, sizeof(usr->pass)))
5688                 return False;
5689
5690         /* here begins pointed-to data */
5691
5692         if(!smb_io_unistr2("uni_user_name   ", &usr->uni_user_name, usr->hdr_user_name.buffer, ps, depth))      /* username unicode string */
5693                 return False;
5694
5695         if(!smb_io_unistr2("uni_full_name   ", &usr->uni_full_name, usr->hdr_full_name.buffer, ps, depth))      /* user's full name unicode string */
5696                 return False;
5697
5698         if(!smb_io_unistr2("uni_home_dir    ", &usr->uni_home_dir, usr->hdr_home_dir.buffer, ps, depth))        /* home directory unicode string */
5699                 return False;
5700
5701         if(!smb_io_unistr2("uni_dir_drive   ", &usr->uni_dir_drive, usr->hdr_dir_drive.buffer, ps, depth))      /* home directory drive unicode string */
5702                 return False;
5703
5704         if(!smb_io_unistr2("uni_logon_script", &usr->uni_logon_script, usr->hdr_logon_script.buffer, ps, depth))        /* logon script unicode string */
5705                 return False;
5706
5707         if(!smb_io_unistr2("uni_profile_path", &usr->uni_profile_path, usr->hdr_profile_path.buffer, ps, depth))        /* profile path unicode string */
5708                 return False;
5709
5710         if(!smb_io_unistr2("uni_acct_desc   ", &usr->uni_acct_desc, usr->hdr_acct_desc.buffer, ps, depth))      /* user desc unicode string */
5711                 return False;
5712
5713         if(!smb_io_unistr2("uni_workstations", &usr->uni_workstations, usr->hdr_workstations.buffer, ps, depth))        /* worksations user can log on from */
5714                 return False;
5715
5716         if(!smb_io_unistr2("uni_unknown_str ", &usr->uni_unknown_str, usr->hdr_unknown_str.buffer, ps, depth))  /* unknown string */
5717                 return False;
5718
5719         if(!smb_io_unistr2("uni_munged_dial ", &usr->uni_munged_dial, usr->hdr_munged_dial.buffer, ps, depth))
5720                 return False;
5721
5722         /* ok, this is only guess-work (as usual) */
5723         if (usr->ptr_logon_hrs) {
5724                 if(!prs_uint32("unknown_6     ", ps, depth, &usr->unknown_6))
5725                         return False;
5726                 if(!prs_uint32("padding4      ", ps, depth, &usr->padding4))
5727                         return False;
5728                 if(!sam_io_logon_hrs("logon_hrs", &usr->logon_hrs, ps, depth))
5729                         return False;
5730         } else if (UNMARSHALLING(ps)) {
5731                 usr->unknown_6 = 0;
5732                 usr->padding4 = 0;
5733         }
5734
5735         return True;
5736 }
5737
5738 /*******************************************************************
5739  reads or writes a structure.
5740  NB. This structure is *definately* incorrect. It's my best guess
5741  currently for W2K SP2. The password field is encrypted in a different
5742  way than normal... And there are definately other problems. JRA.
5743 ********************************************************************/
5744
5745 static BOOL sam_io_user_info25(const char *desc, SAM_USER_INFO_25 * usr, prs_struct *ps, int depth)
5746 {
5747         if (usr == NULL)
5748                 return False;
5749
5750         prs_debug(ps, depth, desc, "sam_io_user_info25");
5751         depth++;
5752
5753         if(!prs_align(ps))
5754                 return False;
5755
5756         if(!smb_io_time("logon_time           ", &usr->logon_time, ps, depth))
5757                 return False;
5758         if(!smb_io_time("logoff_time          ", &usr->logoff_time, ps, depth))
5759                 return False;
5760         if(!smb_io_time("kickoff_time         ", &usr->kickoff_time, ps, depth))
5761                 return False;
5762         if(!smb_io_time("pass_last_set_time   ", &usr->pass_last_set_time, ps, depth))
5763                 return False;
5764         if(!smb_io_time("pass_can_change_time ", &usr->pass_can_change_time, ps, depth))
5765                 return False;
5766         if(!smb_io_time("pass_must_change_time", &usr->pass_must_change_time, ps, depth))
5767                 return False;
5768
5769         if(!smb_io_unihdr("hdr_user_name   ", &usr->hdr_user_name, ps, depth))  /* username unicode string header */
5770                 return False;
5771         if(!smb_io_unihdr("hdr_full_name   ", &usr->hdr_full_name, ps, depth))  /* user's full name unicode string header */
5772                 return False;
5773         if(!smb_io_unihdr("hdr_home_dir    ", &usr->hdr_home_dir, ps, depth))   /* home directory unicode string header */
5774                 return False;
5775         if(!smb_io_unihdr("hdr_dir_drive   ", &usr->hdr_dir_drive, ps, depth))  /* home directory drive */
5776                 return False;
5777         if(!smb_io_unihdr("hdr_logon_script", &usr->hdr_logon_script, ps, depth))       /* logon script unicode string header */
5778                 return False;
5779         if(!smb_io_unihdr("hdr_profile_path", &usr->hdr_profile_path, ps, depth))       /* profile path unicode string header */
5780                 return False;
5781         if(!smb_io_unihdr("hdr_acct_desc   ", &usr->hdr_acct_desc, ps, depth))  /* account desc */
5782                 return False;
5783         if(!smb_io_unihdr("hdr_workstations", &usr->hdr_workstations, ps, depth))       /* wkstas user can log on from */
5784                 return False;
5785         if(!smb_io_unihdr("hdr_unknown_str ", &usr->hdr_unknown_str, ps, depth))        /* unknown string */
5786                 return False;
5787         if(!smb_io_unihdr("hdr_munged_dial ", &usr->hdr_munged_dial, ps, depth))        /* wkstas user can log on from */
5788                 return False;
5789
5790         if(!prs_uint8s(False, "lm_pwd        ", ps, depth, usr->lm_pwd, sizeof(usr->lm_pwd)))
5791                 return False;
5792         if(!prs_uint8s(False, "nt_pwd        ", ps, depth, usr->nt_pwd, sizeof(usr->nt_pwd)))
5793                 return False;
5794
5795         if(!prs_uint32("user_rid      ", ps, depth, &usr->user_rid))    /* User ID */
5796                 return False;
5797         if(!prs_uint32("group_rid     ", ps, depth, &usr->group_rid))   /* Group ID */
5798                 return False;
5799         if(!prs_uint32("acb_info      ", ps, depth, &usr->acb_info))
5800                 return False;
5801
5802         if(!prs_uint32s(False, "unknown_6      ", ps, depth, usr->unknown_6, 6))
5803                 return False;
5804
5805         if(!prs_uint8s(False, "password      ", ps, depth, usr->pass, sizeof(usr->pass)))
5806                 return False;
5807
5808         /* here begins pointed-to data */
5809
5810         if(!smb_io_unistr2("uni_user_name   ", &usr->uni_user_name, usr->hdr_user_name.buffer, ps, depth))      /* username unicode string */
5811                 return False;
5812
5813         if(!smb_io_unistr2("uni_full_name   ", &usr->uni_full_name, usr->hdr_full_name.buffer, ps, depth))      /* user's full name unicode string */
5814                 return False;
5815
5816         if(!smb_io_unistr2("uni_home_dir    ", &usr->uni_home_dir, usr->hdr_home_dir.buffer, ps, depth))        /* home directory unicode string */
5817                 return False;
5818
5819         if(!smb_io_unistr2("uni_dir_drive   ", &usr->uni_dir_drive, usr->hdr_dir_drive.buffer, ps, depth))      /* home directory drive unicode string */
5820                 return False;
5821
5822         if(!smb_io_unistr2("uni_logon_script", &usr->uni_logon_script, usr->hdr_logon_script.buffer, ps, depth))        /* logon script unicode string */
5823                 return False;
5824
5825         if(!smb_io_unistr2("uni_profile_path", &usr->uni_profile_path, usr->hdr_profile_path.buffer, ps, depth))        /* profile path unicode string */
5826                 return False;
5827
5828         if(!smb_io_unistr2("uni_acct_desc   ", &usr->uni_acct_desc, usr->hdr_acct_desc.buffer, ps, depth))      /* user desc unicode string */
5829                 return False;
5830
5831         if(!smb_io_unistr2("uni_workstations", &usr->uni_workstations, usr->hdr_workstations.buffer, ps, depth))        /* worksations user can log on from */
5832                 return False;
5833
5834         if(!smb_io_unistr2("uni_unknown_str ", &usr->uni_unknown_str, usr->hdr_unknown_str.buffer, ps, depth))  /* unknown string */
5835                 return False;
5836
5837         if(!smb_io_unistr2("uni_munged_dial ", &usr->uni_munged_dial, usr->hdr_munged_dial.buffer, ps, depth))
5838                 return False;
5839
5840 #if 0 /* JRA - unknown... */
5841         /* ok, this is only guess-work (as usual) */
5842         if (usr->ptr_logon_hrs) {
5843                 if(!prs_uint32("unknown_6     ", ps, depth, &usr->unknown_6))
5844                         return False;
5845                 if(!prs_uint32("padding4      ", ps, depth, &usr->padding4))
5846                         return False;
5847                 if(!sam_io_logon_hrs("logon_hrs", &usr->logon_hrs, ps, depth))
5848                         return False;
5849         } else if (UNMARSHALLING(ps)) {
5850                 usr->unknown_6 = 0;
5851                 usr->padding4 = 0;
5852         }
5853 #endif
5854
5855         return True;
5856 }
5857
5858
5859 /*************************************************************************
5860  init_sam_user_info21W
5861
5862  unknown_3 = 0x00ff ffff
5863  unknown_5 = 0x0002 0000
5864  unknown_6 = 0x0000 04ec 
5865
5866  *************************************************************************/
5867
5868 void init_sam_user_info21W(SAM_USER_INFO_21 * usr,
5869                            NTTIME * logon_time,
5870                            NTTIME * logoff_time,
5871                            NTTIME * kickoff_time,
5872                            NTTIME * pass_last_set_time,
5873                            NTTIME * pass_can_change_time,
5874                            NTTIME * pass_must_change_time,
5875                            UNISTR2 *user_name,
5876                            UNISTR2 *full_name,
5877                            UNISTR2 *home_dir,
5878                            UNISTR2 *dir_drive,
5879                            UNISTR2 *log_scr,
5880                            UNISTR2 *prof_path,
5881                            UNISTR2 *desc,
5882                            UNISTR2 *wkstas,
5883                            UNISTR2 *unk_str,
5884                            UNISTR2 *mung_dial,
5885                            uchar lm_pwd[16],
5886                            uchar nt_pwd[16],
5887                            uint32 user_rid,
5888                            uint32 group_rid,
5889                            uint32 acb_info,
5890                            uint32 unknown_3,
5891                            uint16 logon_divs,
5892                            LOGON_HRS * hrs,
5893                            uint32 unknown_5, uint32 unknown_6)
5894 {
5895         int len_user_name = user_name != NULL ? user_name->uni_str_len : 0;
5896         int len_full_name = full_name != NULL ? full_name->uni_str_len : 0;
5897         int len_home_dir = home_dir != NULL ? home_dir->uni_str_len : 0;
5898         int len_dir_drive = dir_drive != NULL ? dir_drive->uni_str_len : 0;
5899         int len_logon_script = log_scr != NULL ? log_scr->uni_str_len : 0;
5900         int len_profile_path = prof_path != NULL ? prof_path->uni_str_len : 0;
5901         int len_description = desc != NULL ? desc->uni_str_len : 0;
5902         int len_workstations = wkstas != NULL ? wkstas->uni_str_len : 0;
5903         int len_unknown_str = unk_str != NULL ? unk_str->uni_str_len : 0;
5904         int len_munged_dial = mung_dial != NULL ? mung_dial->uni_str_len : 0;
5905
5906         usr->logon_time = *logon_time;
5907         usr->logoff_time = *logoff_time;
5908         usr->kickoff_time = *kickoff_time;
5909         usr->pass_last_set_time = *pass_last_set_time;
5910         usr->pass_can_change_time = *pass_can_change_time;
5911         usr->pass_must_change_time = *pass_must_change_time;
5912
5913         init_uni_hdr(&usr->hdr_user_name, len_user_name);
5914         init_uni_hdr(&usr->hdr_full_name, len_full_name);
5915         init_uni_hdr(&usr->hdr_home_dir, len_home_dir);
5916         init_uni_hdr(&usr->hdr_dir_drive, len_dir_drive);
5917         init_uni_hdr(&usr->hdr_logon_script, len_logon_script);
5918         init_uni_hdr(&usr->hdr_profile_path, len_profile_path);
5919         init_uni_hdr(&usr->hdr_acct_desc, len_description);
5920         init_uni_hdr(&usr->hdr_workstations, len_workstations);
5921         init_uni_hdr(&usr->hdr_unknown_str, len_unknown_str);
5922         init_uni_hdr(&usr->hdr_munged_dial, len_munged_dial);
5923
5924         memcpy(usr->lm_pwd, lm_pwd, sizeof(usr->lm_pwd));
5925         memcpy(usr->nt_pwd, nt_pwd, sizeof(usr->nt_pwd));
5926
5927         usr->user_rid = user_rid;
5928         usr->group_rid = group_rid;
5929         usr->acb_info = acb_info;
5930         usr->unknown_3 = unknown_3;     /* 0x00ff ffff */
5931
5932         usr->logon_divs = logon_divs;   /* should be 168 (hours/week) */
5933         usr->ptr_logon_hrs = hrs ? 1 : 0;
5934         usr->unknown_5 = unknown_5;     /* 0x0002 0000 */
5935
5936         if (nt_time_is_zero(pass_must_change_time)) {
5937                 usr->passmustchange=PASS_MUST_CHANGE_AT_NEXT_LOGON;
5938         } else {
5939                 usr->passmustchange=0;
5940         }
5941
5942
5943         ZERO_STRUCT(usr->padding1);
5944         ZERO_STRUCT(usr->padding2);
5945
5946         copy_unistr2(&usr->uni_user_name, user_name);
5947         copy_unistr2(&usr->uni_full_name, full_name);
5948         copy_unistr2(&usr->uni_home_dir, home_dir);
5949         copy_unistr2(&usr->uni_dir_drive, dir_drive);
5950         copy_unistr2(&usr->uni_logon_script, log_scr);
5951         copy_unistr2(&usr->uni_profile_path, prof_path);
5952         copy_unistr2(&usr->uni_acct_desc, desc);
5953         copy_unistr2(&usr->uni_workstations, wkstas);
5954         copy_unistr2(&usr->uni_unknown_str, unk_str);
5955         copy_unistr2(&usr->uni_munged_dial, mung_dial);
5956
5957         usr->unknown_6 = unknown_6;     /* 0x0000 04ec */
5958         usr->padding4 = 0;
5959
5960         memcpy(&usr->logon_hrs, hrs, sizeof(usr->logon_hrs));
5961 }
5962
5963 /*************************************************************************
5964  init_sam_user_info21
5965
5966  unknown_3 = 0x00ff ffff
5967  unknown_5 = 0x0002 0000
5968  unknown_6 = 0x0000 04ec 
5969
5970  *************************************************************************/
5971
5972 NTSTATUS init_sam_user_info21A(SAM_USER_INFO_21 *usr, SAM_ACCOUNT *pw, DOM_SID *domain_sid)
5973 {
5974         NTTIME          logon_time, logoff_time, kickoff_time,
5975                         pass_last_set_time, pass_can_change_time,
5976                         pass_must_change_time;
5977
5978         int             len_user_name, len_full_name, len_home_dir,
5979                         len_dir_drive, len_logon_script, len_profile_path,
5980                         len_description, len_workstations, len_unknown_str,
5981                         len_munged_dial;
5982                         
5983         const char*             user_name = pdb_get_username(pw);
5984         const char*             full_name = pdb_get_fullname(pw);
5985         const char*             home_dir  = pdb_get_homedir(pw);
5986         const char*             dir_drive = pdb_get_dir_drive(pw);
5987         const char*             logon_script = pdb_get_logon_script(pw);
5988         const char*             profile_path = pdb_get_profile_path(pw);
5989         const char*             description = pdb_get_acct_desc(pw);
5990         const char*             workstations = pdb_get_workstations(pw);
5991         const char*             munged_dial = pdb_get_munged_dial(pw);
5992
5993         uint32 user_rid;
5994         const DOM_SID *user_sid;
5995
5996         uint32 group_rid;
5997         const DOM_SID *group_sid;
5998
5999         len_user_name    = user_name    != NULL ? strlen(user_name   )+1 : 0;
6000         len_full_name    = full_name    != NULL ? strlen(full_name   )+1 : 0;
6001         len_home_dir     = home_dir     != NULL ? strlen(home_dir    )+1 : 0;
6002         len_dir_drive    = dir_drive    != NULL ? strlen(dir_drive   )+1 : 0;
6003         len_logon_script = logon_script != NULL ? strlen(logon_script)+1 : 0;
6004         len_profile_path = profile_path != NULL ? strlen(profile_path)+1 : 0;
6005         len_description  = description  != NULL ? strlen(description )+1 : 0;
6006         len_workstations = workstations != NULL ? strlen(workstations)+1 : 0;
6007         len_unknown_str  = 0;
6008         len_munged_dial  = munged_dial  != NULL ? strlen(munged_dial )+1 : 0;
6009
6010
6011         /* Create NTTIME structs */
6012         unix_to_nt_time (&logon_time,           pdb_get_logon_time(pw));
6013         unix_to_nt_time (&logoff_time,          pdb_get_logoff_time(pw));
6014         unix_to_nt_time (&kickoff_time,         pdb_get_kickoff_time(pw));
6015         unix_to_nt_time (&pass_last_set_time,   pdb_get_pass_last_set_time(pw));
6016         unix_to_nt_time (&pass_can_change_time, pdb_get_pass_can_change_time(pw));
6017         unix_to_nt_time (&pass_must_change_time,pdb_get_pass_must_change_time(pw));
6018         
6019         /* structure assignment */
6020         usr->logon_time            = logon_time;
6021         usr->logoff_time           = logoff_time;
6022         usr->kickoff_time          = kickoff_time;
6023         usr->pass_last_set_time    = pass_last_set_time;
6024         usr->pass_can_change_time  = pass_can_change_time;
6025         usr->pass_must_change_time = pass_must_change_time;
6026
6027         init_uni_hdr(&usr->hdr_user_name, len_user_name);
6028         init_uni_hdr(&usr->hdr_full_name, len_full_name);
6029         init_uni_hdr(&usr->hdr_home_dir, len_home_dir);
6030         init_uni_hdr(&usr->hdr_dir_drive, len_dir_drive);
6031         init_uni_hdr(&usr->hdr_logon_script, len_logon_script);
6032         init_uni_hdr(&usr->hdr_profile_path, len_profile_path);
6033         init_uni_hdr(&usr->hdr_acct_desc, len_description);
6034         init_uni_hdr(&usr->hdr_workstations, len_workstations);
6035         init_uni_hdr(&usr->hdr_unknown_str, len_unknown_str);
6036         init_uni_hdr(&usr->hdr_munged_dial, len_munged_dial);
6037
6038         ZERO_STRUCT(usr->nt_pwd);
6039         ZERO_STRUCT(usr->lm_pwd);
6040
6041         user_sid = pdb_get_user_sid(pw);
6042         
6043         if (!sid_peek_check_rid(domain_sid, user_sid, &user_rid)) {
6044                 fstring user_sid_string;
6045                 fstring domain_sid_string;
6046                 DEBUG(0, ("init_sam_user_info_21A: User %s has SID %s, \nwhich conflicts with "
6047                           "the domain sid %s.  Failing operation.\n", 
6048                           user_name, 
6049                           sid_to_string(user_sid_string, user_sid),
6050                           sid_to_string(domain_sid_string, domain_sid)));
6051                 return NT_STATUS_UNSUCCESSFUL;
6052         }
6053
6054         group_sid = pdb_get_group_sid(pw);
6055         
6056         if (!sid_peek_check_rid(domain_sid, group_sid, &group_rid)) {
6057                 fstring group_sid_string;
6058                 fstring domain_sid_string;
6059                 DEBUG(0, ("init_sam_user_info_21A: User %s has Primary Group SID %s, \n"
6060                           "which conflicts with the domain sid %s.  Failing operation.\n", 
6061                           user_name, 
6062                           sid_to_string(group_sid_string, group_sid),
6063                           sid_to_string(domain_sid_string, domain_sid)));
6064                 return NT_STATUS_UNSUCCESSFUL;
6065         }
6066
6067         usr->user_rid  = user_rid;
6068         usr->group_rid = group_rid;
6069         usr->acb_info  = pdb_get_acct_ctrl(pw);
6070
6071         /*
6072           Look at a user on a real NT4 PDC with usrmgr, press
6073           'ok'. Then you will see that unknown_3 is set to
6074           0x08f827fa. Look at the user immediately after that again,
6075           and you will see that 0x00fffff is returned. This solves
6076           the problem that you get access denied after having looked
6077           at the user.
6078           -- Volker
6079         */
6080         usr->unknown_3 = 0x00ffffff;
6081
6082         usr->logon_divs = pdb_get_logon_divs(pw); 
6083         usr->ptr_logon_hrs = pdb_get_hours(pw) ? 1 : 0;
6084         usr->unknown_5 = pdb_get_unknown_5(pw); /* 0x0002 0000 */
6085
6086         if (pdb_get_pass_must_change_time(pw) == 0) {
6087                 usr->passmustchange=PASS_MUST_CHANGE_AT_NEXT_LOGON;
6088         } else {
6089                 usr->passmustchange=0;
6090         }
6091
6092
6093         ZERO_STRUCT(usr->padding1);
6094         ZERO_STRUCT(usr->padding2);
6095
6096         init_unistr2(&usr->uni_user_name, user_name, len_user_name);
6097         init_unistr2(&usr->uni_full_name, full_name, len_full_name);
6098         init_unistr2(&usr->uni_home_dir, home_dir, len_home_dir);
6099         init_unistr2(&usr->uni_dir_drive, dir_drive, len_dir_drive);
6100         init_unistr2(&usr->uni_logon_script, logon_script, len_logon_script);
6101         init_unistr2(&usr->uni_profile_path, profile_path, len_profile_path);
6102         init_unistr2(&usr->uni_acct_desc, description, len_description);
6103         init_unistr2(&usr->uni_workstations, workstations, len_workstations);
6104         init_unistr2(&usr->uni_unknown_str, NULL, len_unknown_str);
6105         init_unistr2(&usr->uni_munged_dial, munged_dial, len_munged_dial);
6106
6107         usr->unknown_6 = pdb_get_unknown_6(pw);
6108         usr->padding4 = 0;
6109
6110         if (pdb_get_hours(pw)) {
6111                 usr->logon_hrs.len = pdb_get_hours_len(pw);
6112                 memcpy(&usr->logon_hrs.hours, pdb_get_hours(pw), MAX_HOURS_LEN);
6113         } else
6114                 memset(&usr->logon_hrs, 0xff, sizeof(usr->logon_hrs));
6115
6116         return NT_STATUS_OK;
6117 }
6118
6119 /*******************************************************************
6120 reads or writes a structure.
6121 ********************************************************************/
6122
6123 static BOOL sam_io_user_info21(const char *desc, SAM_USER_INFO_21 * usr,
6124                         prs_struct *ps, int depth)
6125 {
6126         if (usr == NULL)
6127                 return False;
6128
6129         prs_debug(ps, depth, desc, "sam_io_user_info21");
6130         depth++;
6131
6132         if(!prs_align(ps))
6133                 return False;
6134
6135         if(!smb_io_time("logon_time           ", &usr->logon_time, ps, depth))
6136                 return False;
6137         if(!smb_io_time("logoff_time          ", &usr->logoff_time, ps, depth))
6138                 return False;
6139         if(!smb_io_time("pass_last_set_time   ", &usr->pass_last_set_time, ps,depth))
6140                 return False;
6141         if(!smb_io_time("kickoff_time         ", &usr->kickoff_time, ps, depth))
6142                 return False;
6143         if(!smb_io_time("pass_can_change_time ", &usr->pass_can_change_time, ps,depth))
6144                 return False;
6145         if(!smb_io_time("pass_must_change_time", &usr->pass_must_change_time,  ps, depth))
6146                 return False;
6147
6148         if(!smb_io_unihdr("hdr_user_name   ", &usr->hdr_user_name, ps, depth))  /* username unicode string header */
6149                 return False;
6150         if(!smb_io_unihdr("hdr_full_name   ", &usr->hdr_full_name, ps, depth))  /* user's full name unicode string header */
6151                 return False;
6152         if(!smb_io_unihdr("hdr_home_dir    ", &usr->hdr_home_dir, ps, depth))   /* home directory unicode string header */
6153                 return False;
6154         if(!smb_io_unihdr("hdr_dir_drive   ", &usr->hdr_dir_drive, ps, depth))  /* home directory drive */
6155                 return False;
6156         if(!smb_io_unihdr("hdr_logon_script", &usr->hdr_logon_script, ps, depth))       /* logon script unicode string header */
6157                 return False;
6158         if(!smb_io_unihdr("hdr_profile_path", &usr->hdr_profile_path, ps, depth))       /* profile path unicode string header */
6159                 return False;
6160         if(!smb_io_unihdr("hdr_acct_desc   ", &usr->hdr_acct_desc, ps, depth))  /* account desc */
6161                 return False;
6162         if(!smb_io_unihdr("hdr_workstations", &usr->hdr_workstations, ps, depth))       /* wkstas user can log on from */
6163                 return False;
6164         if(!smb_io_unihdr("hdr_unknown_str ", &usr->hdr_unknown_str, ps, depth))        /* unknown string */
6165                 return False;
6166         if(!smb_io_unihdr("hdr_munged_dial ", &usr->hdr_munged_dial, ps, depth))        /* wkstas user can log on from */
6167                 return False;
6168
6169         if(!prs_uint8s(False, "lm_pwd        ", ps, depth, usr->lm_pwd, sizeof(usr->lm_pwd)))
6170                 return False;
6171         if(!prs_uint8s(False, "nt_pwd        ", ps, depth, usr->nt_pwd, sizeof(usr->nt_pwd)))
6172                 return False;
6173
6174         if(!prs_uint32("user_rid      ", ps, depth, &usr->user_rid))    /* User ID */
6175                 return False;
6176         if(!prs_uint32("group_rid     ", ps, depth, &usr->group_rid))   /* Group ID */
6177                 return False;
6178         if(!prs_uint32("acb_info      ", ps, depth, &usr->acb_info))
6179                 return False;
6180
6181         if(!prs_uint32("unknown_3     ", ps, depth, &usr->unknown_3))
6182                 return False;
6183         if(!prs_uint16("logon_divs    ", ps, depth, &usr->logon_divs))  /* logon divisions per week */
6184                 return False;
6185         if(!prs_align(ps))
6186                 return False;
6187         if(!prs_uint32("ptr_logon_hrs ", ps, depth, &usr->ptr_logon_hrs))
6188                 return False;
6189
6190         if(!prs_uint32("unknown_5     ", ps, depth, &usr->unknown_5))
6191                 return False;
6192
6193         if(!prs_uint8s(False, "padding1      ", ps, depth, usr->padding1, sizeof(usr->padding1)))
6194                 return False;
6195         if(!prs_uint8("passmustchange ", ps, depth, &usr->passmustchange))
6196                 return False;
6197         if(!prs_uint8("padding2       ", ps, depth, &usr->padding2))
6198                 return False;
6199
6200         /* here begins pointed-to data */
6201
6202         if(!smb_io_unistr2("uni_user_name   ", &usr->uni_user_name,usr->hdr_user_name.buffer, ps, depth))       /* username unicode string */
6203                 return False;
6204         if(!smb_io_unistr2("uni_full_name   ", &usr->uni_full_name, usr->hdr_full_name.buffer, ps, depth))      /* user's full name unicode string */
6205                 return False;
6206         if(!smb_io_unistr2("uni_home_dir    ", &usr->uni_home_dir, usr->hdr_home_dir.buffer, ps, depth))        /* home directory unicode string */
6207                 return False;
6208         if(!smb_io_unistr2("uni_dir_drive   ", &usr->uni_dir_drive, usr->hdr_dir_drive.buffer, ps, depth))      /* home directory drive unicode string */
6209                 return False;
6210         if(!smb_io_unistr2("uni_logon_script", &usr->uni_logon_script, usr->hdr_logon_script.buffer, ps, depth))        /* logon script unicode string */
6211                 return False;
6212         if(!smb_io_unistr2("uni_profile_path", &usr->uni_profile_path, usr->hdr_profile_path.buffer, ps, depth))        /* profile path unicode string */
6213                 return False;
6214         if(!smb_io_unistr2("uni_acct_desc   ", &usr->uni_acct_desc, usr->hdr_acct_desc.buffer, ps, depth))      /* user desc unicode string */
6215                 return False;
6216         if(!smb_io_unistr2("uni_workstations", &usr->uni_workstations, usr->hdr_workstations.buffer, ps, depth))        /* worksations user can log on from */
6217                 return False;
6218         if(!smb_io_unistr2("uni_unknown_str ", &usr->uni_unknown_str, usr->hdr_unknown_str.buffer, ps, depth))  /* unknown string */
6219                 return False;
6220         if(!smb_io_unistr2("uni_munged_dial ", &usr->uni_munged_dial,usr->hdr_munged_dial.buffer, ps, depth))   /* worksations user can log on from */
6221                 return False;
6222
6223         /* ok, this is only guess-work (as usual) */
6224         if (usr->ptr_logon_hrs) {
6225                 if(!prs_align(ps))
6226                         return False;
6227                 if(!prs_uint32("unknown_6     ", ps, depth, &usr->unknown_6))
6228                         return False;
6229                 if(!prs_uint32("padding4      ", ps, depth, &usr->padding4))
6230                         return False;
6231                 if(!sam_io_logon_hrs("logon_hrs", &usr->logon_hrs, ps, depth))
6232                         return False;
6233         } else if (UNMARSHALLING(ps)) {
6234                 usr->unknown_6 = 0;
6235                 usr->padding4 = 0;
6236         }
6237
6238         return True;
6239 }
6240
6241 void init_sam_user_info20A(SAM_USER_INFO_20 *usr, SAM_ACCOUNT *pw)
6242 {
6243         int             len_munged_dial;
6244         const char*             munged_dial = pdb_get_munged_dial(pw);
6245
6246         len_munged_dial  = munged_dial  != NULL ? strlen(munged_dial )+1 : 0;
6247         init_uni_hdr(&usr->hdr_munged_dial, len_munged_dial);
6248         init_unistr2(&usr->uni_munged_dial, munged_dial, len_munged_dial);
6249
6250 }
6251
6252 /*******************************************************************
6253 reads or writes a structure.
6254 ********************************************************************/
6255
6256 static BOOL sam_io_user_info20(const char *desc, SAM_USER_INFO_20 *usr,
6257                         prs_struct *ps, int depth)
6258 {
6259         if (usr == NULL)
6260                 return False;
6261
6262         prs_debug(ps, depth, desc, "sam_io_user_info20");
6263         depth++;
6264
6265         if(!prs_align(ps))
6266                 return False;
6267
6268         if(!smb_io_unihdr("hdr_munged_dial ", &usr->hdr_munged_dial, ps, depth))        /* wkstas user can log on from */
6269                 return False;
6270
6271         if(!smb_io_unistr2("uni_munged_dial ", &usr->uni_munged_dial,usr->hdr_munged_dial.buffer, ps, depth))   /* worksations user can log on from */
6272                 return False;
6273
6274         return True;
6275 }
6276
6277 /*******************************************************************
6278 inits a SAM_USERINFO_CTR structure.
6279 ********************************************************************/
6280
6281 NTSTATUS make_samr_userinfo_ctr_usr21(TALLOC_CTX *ctx, SAM_USERINFO_CTR * ctr,
6282                                     uint16 switch_value,
6283                                     SAM_USER_INFO_21 * usr)
6284 {
6285         DEBUG(5, ("init_samr_userinfo_ctr\n"));
6286
6287         ctr->switch_value = switch_value;
6288         ctr->info.id = NULL;
6289
6290         switch (switch_value) {
6291         case 0x10:
6292                 ctr->info.id10 = (SAM_USER_INFO_10 *)talloc_zero(ctx,sizeof(SAM_USER_INFO_10));
6293                 if (ctr->info.id10 == NULL)
6294                         return NT_STATUS_NO_MEMORY;
6295
6296                 init_sam_user_info10(ctr->info.id10, usr->acb_info);
6297                 break;
6298 #if 0
6299 /* whoops - got this wrong.  i think.  or don't understand what's happening. */
6300         case 0x11:
6301                 {
6302                         NTTIME expire;
6303                         info = (void *)&id11;
6304
6305                         expire.low = 0xffffffff;
6306                         expire.high = 0x7fffffff;
6307
6308                         ctr->info.id = (SAM_USER_INFO_11 *) talloc_zero(ctx,sizeof(*ctr->info.id11));
6309                         init_sam_user_info11(ctr->info.id11, &expire,
6310                                              "BROOKFIELDS$",    /* name */
6311                                              0x03ef,    /* user rid */
6312                                              0x201,     /* group rid */
6313                                              0x0080);   /* acb info */
6314
6315                         break;
6316                 }
6317 #endif
6318         case 0x12:
6319                 ctr->info.id12 = (SAM_USER_INFO_12 *)talloc_zero(ctx,sizeof(SAM_USER_INFO_12));
6320                 if (ctr->info.id12 == NULL)
6321                         return NT_STATUS_NO_MEMORY;
6322
6323                 init_sam_user_info12(ctr->info.id12, usr->lm_pwd, usr->nt_pwd);
6324                 break;
6325         case 21:
6326                 {
6327                         SAM_USER_INFO_21 *cusr;
6328                         cusr = (SAM_USER_INFO_21 *)talloc_zero(ctx,sizeof(SAM_USER_INFO_21));
6329                         ctr->info.id21 = cusr;
6330                         if (ctr->info.id21 == NULL)
6331                                 return NT_STATUS_NO_MEMORY;
6332                         memcpy(cusr, usr, sizeof(*usr));
6333                         memset(cusr->lm_pwd, 0, sizeof(cusr->lm_pwd));
6334                         memset(cusr->nt_pwd, 0, sizeof(cusr->nt_pwd));
6335                         break;
6336                 }
6337         default:
6338                 DEBUG(4,("make_samr_userinfo_ctr: unsupported info\n"));
6339                 return NT_STATUS_INVALID_INFO_CLASS;
6340         }
6341
6342         return NT_STATUS_OK;
6343 }
6344
6345 /*******************************************************************
6346 inits a SAM_USERINFO_CTR structure.
6347 ********************************************************************/
6348
6349 void init_samr_userinfo_ctr(SAM_USERINFO_CTR * ctr, uchar * sess_key,
6350                             uint16 switch_value, void *info)
6351 {
6352         DEBUG(5, ("init_samr_userinfo_ctr\n"));
6353
6354         ctr->switch_value = switch_value;
6355         ctr->info.id = info;
6356
6357         switch (switch_value) {
6358         case 0x18:
6359                 SamOEMhash(ctr->info.id24->pass, sess_key, 516);
6360                 dump_data(100, (char *)sess_key, 16);
6361                 dump_data(100, (char *)ctr->info.id24->pass, 516);
6362                 break;
6363         case 0x17:
6364                 SamOEMhash(ctr->info.id23->pass, sess_key, 516);
6365                 dump_data(100, (char *)sess_key, 16);
6366                 dump_data(100, (char *)ctr->info.id23->pass, 516);
6367                 break;
6368         default:
6369                 DEBUG(4,("init_samr_userinfo_ctr: unsupported switch level\n"));
6370         }
6371 }
6372
6373 /*******************************************************************
6374 reads or writes a structure.
6375 ********************************************************************/
6376
6377 static BOOL samr_io_userinfo_ctr(const char *desc, SAM_USERINFO_CTR **ppctr,
6378                                  prs_struct *ps, int depth)
6379 {
6380         BOOL ret;
6381         SAM_USERINFO_CTR *ctr;
6382
6383         prs_debug(ps, depth, desc, "samr_io_userinfo_ctr");
6384         depth++;
6385
6386         if (UNMARSHALLING(ps)) {
6387                 ctr = (SAM_USERINFO_CTR *)prs_alloc_mem(ps,sizeof(SAM_USERINFO_CTR));
6388                 if (ctr == NULL)
6389                         return False;
6390                 *ppctr = ctr;
6391         } else {
6392                 ctr = *ppctr;
6393         }
6394
6395         /* lkclXXXX DO NOT ALIGN BEFORE READING SWITCH VALUE! */
6396
6397         if(!prs_uint16("switch_value", ps, depth, &ctr->switch_value))
6398                 return False;
6399         if(!prs_align(ps))
6400                 return False;
6401
6402         ret = False;
6403
6404         switch (ctr->switch_value) {
6405         case 0x10:
6406                 if (UNMARSHALLING(ps))
6407                         ctr->info.id10 = (SAM_USER_INFO_10 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_10));
6408                 if (ctr->info.id10 == NULL) {
6409                         DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6410                         return False;
6411                 }
6412                 ret = sam_io_user_info10("", ctr->info.id10, ps, depth);
6413                 break;
6414         case 0x11:
6415                 if (UNMARSHALLING(ps))
6416                         ctr->info.id11 = (SAM_USER_INFO_11 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_11));
6417
6418                 if (ctr->info.id11 == NULL) {
6419                         DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6420                         return False;
6421                 }
6422                 ret = sam_io_user_info11("", ctr->info.id11, ps, depth);
6423                 break;
6424         case 0x12:
6425                 if (UNMARSHALLING(ps))
6426                         ctr->info.id12 = (SAM_USER_INFO_12 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_12));
6427
6428                 if (ctr->info.id12 == NULL) {
6429                         DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6430                         return False;
6431                 }
6432                 ret = sam_io_user_info12("", ctr->info.id12, ps, depth);
6433                 break;
6434         case 20:
6435                 if (UNMARSHALLING(ps))
6436                         ctr->info.id20 = (SAM_USER_INFO_20 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_20));
6437
6438                 if (ctr->info.id20 == NULL) {
6439                         DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6440                         return False;
6441                 }
6442                 ret = sam_io_user_info20("", ctr->info.id20, ps, depth);
6443                 break;
6444         case 21:
6445                 if (UNMARSHALLING(ps))
6446                         ctr->info.id21 = (SAM_USER_INFO_21 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_21));
6447
6448                 if (ctr->info.id21 == NULL) {
6449                         DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6450                         return False;
6451                 }
6452                 ret = sam_io_user_info21("", ctr->info.id21, ps, depth);
6453                 break;
6454         case 23:
6455                 if (UNMARSHALLING(ps))
6456                         ctr->info.id23 = (SAM_USER_INFO_23 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_23));
6457
6458                 if (ctr->info.id23 == NULL) {
6459                         DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6460                         return False;
6461                 }
6462                 ret = sam_io_user_info23("", ctr->info.id23, ps, depth);
6463                 break;
6464         case 24:
6465                 if (UNMARSHALLING(ps))
6466                         ctr->info.id24 = (SAM_USER_INFO_24 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_24));
6467
6468                 if (ctr->info.id24 == NULL) {
6469                         DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6470                         return False;
6471                 }
6472                 ret = sam_io_user_info24("", ctr->info.id24, ps,  depth);
6473                 break;
6474         case 25:
6475                 if (UNMARSHALLING(ps))
6476                         ctr->info.id25 = (SAM_USER_INFO_25 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_25));
6477
6478                 if (ctr->info.id25 == NULL) {
6479                         DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6480                         return False;
6481                 }
6482                 ret = sam_io_user_info25("", ctr->info.id25, ps, depth);
6483                 break;
6484         default:
6485                 DEBUG(2, ("samr_io_userinfo_ctr: unknown switch level 0x%x\n", ctr->switch_value));
6486                 ret = False;
6487                 break;
6488         }
6489
6490         return ret;
6491 }
6492
6493 /*******************************************************************
6494 inits a SAMR_R_QUERY_USERINFO structure.
6495 ********************************************************************/
6496
6497 void init_samr_r_query_userinfo(SAMR_R_QUERY_USERINFO * r_u,
6498                                 SAM_USERINFO_CTR * ctr, NTSTATUS status)
6499 {
6500         DEBUG(5, ("init_samr_r_query_userinfo\n"));
6501
6502         r_u->ptr = 0;
6503         r_u->ctr = NULL;
6504
6505         if (NT_STATUS_IS_OK(status)) {
6506                 r_u->ptr = 1;
6507                 r_u->ctr = ctr;
6508         }
6509
6510         r_u->status = status;   /* return status */
6511 }
6512
6513 /*******************************************************************
6514 reads or writes a structure.
6515 ********************************************************************/
6516
6517 BOOL samr_io_r_query_userinfo(const char *desc, SAMR_R_QUERY_USERINFO * r_u,
6518                               prs_struct *ps, int depth)
6519 {
6520         if (r_u == NULL)
6521                 return False;
6522
6523         prs_debug(ps, depth, desc, "samr_io_r_query_userinfo");
6524         depth++;
6525
6526         if(!prs_align(ps))
6527                 return False;
6528
6529         if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
6530                 return False;
6531
6532         if (r_u->ptr != 0) {
6533                 if(!samr_io_userinfo_ctr("ctr", &r_u->ctr, ps, depth))
6534                         return False;
6535         }
6536
6537         if(!prs_align(ps))
6538                 return False;
6539         if(!prs_ntstatus("status", ps, depth, &r_u->status))
6540                 return False;
6541
6542         return True;
6543 }
6544
6545 /*******************************************************************
6546 inits a SAMR_Q_SET_USERINFO structure.
6547 ********************************************************************/
6548
6549 void init_samr_q_set_userinfo(SAMR_Q_SET_USERINFO * q_u,
6550                               POLICY_HND *hnd,  unsigned char sess_key[16],
6551                               uint16 switch_value, void *info)
6552 {
6553         DEBUG(5, ("init_samr_q_set_userinfo\n"));
6554
6555         q_u->pol = *hnd;
6556         q_u->switch_value = switch_value;
6557         init_samr_userinfo_ctr(q_u->ctr, sess_key, switch_value, info);
6558 }
6559
6560 /*******************************************************************
6561 reads or writes a structure.
6562 ********************************************************************/
6563
6564 BOOL samr_io_q_set_userinfo(const char *desc, SAMR_Q_SET_USERINFO * q_u,
6565                             prs_struct *ps, int depth)
6566 {
6567         if (q_u == NULL)
6568                 return False;
6569
6570         prs_debug(ps, depth, desc, "samr_io_q_set_userinfo");
6571         depth++;
6572
6573         if(!prs_align(ps))
6574                 return False;
6575
6576         smb_io_pol_hnd("pol", &(q_u->pol), ps, depth);
6577
6578         if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
6579                 return False;
6580         if(!samr_io_userinfo_ctr("ctr", &q_u->ctr, ps, depth))
6581                 return False;
6582
6583         return True;
6584 }
6585
6586 /*******************************************************************
6587 inits a SAMR_R_SET_USERINFO structure.
6588 ********************************************************************/
6589
6590 void init_samr_r_set_userinfo(SAMR_R_SET_USERINFO * r_u, NTSTATUS status)
6591 {
6592         DEBUG(5, ("init_samr_r_set_userinfo\n"));
6593
6594         r_u->status = status;   /* return status */
6595 }
6596
6597 /*******************************************************************
6598 reads or writes a structure.
6599 ********************************************************************/
6600
6601 BOOL samr_io_r_set_userinfo(const char *desc, SAMR_R_SET_USERINFO * r_u,
6602                             prs_struct *ps, int depth)
6603 {
6604         if (r_u == NULL)
6605                 return False;
6606
6607         prs_debug(ps, depth, desc, "samr_io_r_set_userinfo");
6608         depth++;
6609
6610         if(!prs_align(ps))
6611                 return False;
6612
6613         if(!prs_ntstatus("status", ps, depth, &r_u->status))
6614                 return False;
6615
6616         return True;
6617 }
6618
6619 /*******************************************************************
6620 inits a SAMR_Q_SET_USERINFO2 structure.
6621 ********************************************************************/
6622
6623 void init_samr_q_set_userinfo2(SAMR_Q_SET_USERINFO2 * q_u,
6624                                POLICY_HND *hnd, unsigned char sess_key[16],
6625                                uint16 switch_value, SAM_USERINFO_CTR * ctr)
6626 {
6627         DEBUG(5, ("init_samr_q_set_userinfo2\n"));
6628
6629         q_u->pol = *hnd;
6630         q_u->switch_value = switch_value;
6631         q_u->ctr = ctr;
6632
6633         if (q_u->ctr != NULL)
6634                 q_u->ctr->switch_value = switch_value;
6635
6636         switch (switch_value) {
6637         case 0x12:
6638                 SamOEMhash(ctr->info.id12->lm_pwd, sess_key, 16);
6639                 SamOEMhash(ctr->info.id12->nt_pwd, sess_key, 16);
6640                 dump_data(100, (char *)sess_key, 16);
6641                 dump_data(100, (char *)ctr->info.id12->lm_pwd, 16);
6642                 dump_data(100, (char *)ctr->info.id12->nt_pwd, 16);
6643                 break;
6644         }
6645 }
6646
6647 /*******************************************************************
6648 reads or writes a structure.
6649 ********************************************************************/
6650
6651 BOOL samr_io_q_set_userinfo2(const char *desc, SAMR_Q_SET_USERINFO2 * q_u,
6652                              prs_struct *ps, int depth)
6653 {
6654         if (q_u == NULL)
6655                 return False;
6656
6657         prs_debug(ps, depth, desc, "samr_io_q_set_userinfo2");
6658         depth++;
6659
6660         if(!prs_align(ps))
6661                 return False;
6662
6663         if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
6664                 return False;
6665
6666         if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
6667                 return False;
6668         if(!samr_io_userinfo_ctr("ctr", &q_u->ctr, ps, depth))
6669                 return False;
6670
6671         return True;
6672 }
6673
6674 /*******************************************************************
6675 inits a SAMR_R_SET_USERINFO2 structure.
6676 ********************************************************************/
6677
6678 void init_samr_r_set_userinfo2(SAMR_R_SET_USERINFO2 * r_u, NTSTATUS status)
6679 {
6680         DEBUG(5, ("init_samr_r_set_userinfo2\n"));
6681
6682         r_u->status = status;   /* return status */
6683 }
6684
6685 /*******************************************************************
6686 reads or writes a structure.
6687 ********************************************************************/
6688
6689 BOOL samr_io_r_set_userinfo2(const char *desc, SAMR_R_SET_USERINFO2 * r_u,
6690                              prs_struct *ps, int depth)
6691 {
6692         if (r_u == NULL)
6693                 return False;
6694
6695         prs_debug(ps, depth, desc, "samr_io_r_set_userinfo2");
6696         depth++;
6697
6698         if(!prs_align(ps))
6699                 return False;
6700
6701         if(!prs_ntstatus("status", ps, depth, &r_u->status))
6702                 return False;
6703
6704         return True;
6705 }
6706
6707 /*******************************************************************
6708 inits a SAMR_Q_CONNECT structure.
6709 ********************************************************************/
6710
6711 void init_samr_q_connect(SAMR_Q_CONNECT * q_u,
6712                          char *srv_name, uint32 access_mask)
6713 {
6714         int len_srv_name = strlen(srv_name);
6715
6716         DEBUG(5, ("init_samr_q_connect\n"));
6717
6718         /* make PDC server name \\server */
6719         q_u->ptr_srv_name = len_srv_name > 0 ? 1 : 0;
6720         init_unistr2(&q_u->uni_srv_name, srv_name, len_srv_name + 1);
6721
6722         /* example values: 0x0000 0002 */
6723         q_u->access_mask = access_mask;
6724 }
6725
6726 /*******************************************************************
6727 reads or writes a structure.
6728 ********************************************************************/
6729
6730 BOOL samr_io_q_connect(const char *desc, SAMR_Q_CONNECT * q_u,
6731                        prs_struct *ps, int depth)
6732 {
6733         if (q_u == NULL)
6734                 return False;
6735
6736         prs_debug(ps, depth, desc, "samr_io_q_connect");
6737         depth++;
6738
6739         if(!prs_align(ps))
6740                 return False;
6741
6742         if(!prs_uint32("ptr_srv_name", ps, depth, &q_u->ptr_srv_name))
6743                 return False;
6744         if(!smb_io_unistr2("", &q_u->uni_srv_name, q_u->ptr_srv_name, ps, depth))
6745                 return False;
6746
6747         if(!prs_align(ps))
6748                 return False;
6749         if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
6750                 return False;
6751
6752         return True;
6753 }
6754
6755 /*******************************************************************
6756 reads or writes a structure.
6757 ********************************************************************/
6758
6759 BOOL samr_io_r_connect(const char *desc, SAMR_R_CONNECT * r_u,
6760                        prs_struct *ps, int depth)
6761 {
6762         if (r_u == NULL)
6763                 return False;
6764
6765         prs_debug(ps, depth, desc, "samr_io_r_connect");
6766         depth++;
6767
6768         if(!prs_align(ps))
6769                 return False;
6770
6771         if(!smb_io_pol_hnd("connect_pol", &r_u->connect_pol, ps, depth))
6772                 return False;
6773
6774         if(!prs_ntstatus("status", ps, depth, &r_u->status))
6775                 return False;
6776
6777         return True;
6778 }
6779
6780 /*******************************************************************
6781 inits a SAMR_Q_CONNECT4 structure.
6782 ********************************************************************/
6783
6784 void init_samr_q_connect4(SAMR_Q_CONNECT4 * q_u,
6785                           char *srv_name, uint32 access_mask)
6786 {
6787         int len_srv_name = strlen(srv_name);
6788
6789         DEBUG(5, ("init_samr_q_connect\n"));
6790
6791         /* make PDC server name \\server */
6792         q_u->ptr_srv_name = len_srv_name > 0 ? 1 : 0;
6793         init_unistr2(&q_u->uni_srv_name, srv_name, len_srv_name + 1);
6794
6795         /* Only value we've seen, possibly an address type ? */
6796         q_u->unk_0 = 2;
6797
6798         /* example values: 0x0000 0002 */
6799         q_u->access_mask = access_mask;
6800 }
6801
6802 /*******************************************************************
6803 reads or writes a structure.
6804 ********************************************************************/
6805
6806 BOOL samr_io_q_connect4(const char *desc, SAMR_Q_CONNECT4 * q_u,
6807                         prs_struct *ps, int depth)
6808 {
6809         if (q_u == NULL)
6810                 return False;
6811
6812         prs_debug(ps, depth, desc, "samr_io_q_connect4");
6813         depth++;
6814
6815         if(!prs_align(ps))
6816                 return False;
6817
6818         if(!prs_uint32("ptr_srv_name", ps, depth, &q_u->ptr_srv_name))
6819                 return False;
6820         if(!smb_io_unistr2("", &q_u->uni_srv_name, q_u->ptr_srv_name, ps, depth))
6821                 return False;
6822
6823         if(!prs_align(ps))
6824                 return False;
6825         if(!prs_uint32("unk_0", ps, depth, &q_u->unk_0))
6826                 return False;
6827         if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
6828                 return False;
6829
6830         return True;
6831 }
6832
6833 /*******************************************************************
6834 reads or writes a structure.
6835 ********************************************************************/
6836
6837 BOOL samr_io_r_connect4(const char *desc, SAMR_R_CONNECT4 * r_u,
6838                         prs_struct *ps, int depth)
6839 {
6840         if (r_u == NULL)
6841                 return False;
6842
6843         prs_debug(ps, depth, desc, "samr_io_r_connect4");
6844         depth++;
6845
6846         if(!prs_align(ps))
6847                 return False;
6848
6849         if(!smb_io_pol_hnd("connect_pol", &r_u->connect_pol, ps, depth))
6850                 return False;
6851
6852         if(!prs_ntstatus("status", ps, depth, &r_u->status))
6853                 return False;
6854
6855         return True;
6856 }
6857
6858 /*******************************************************************
6859 inits a SAMR_Q_CONNECT_ANON structure.
6860 ********************************************************************/
6861
6862 void init_samr_q_connect_anon(SAMR_Q_CONNECT_ANON * q_u)
6863 {
6864         DEBUG(5, ("init_samr_q_connect_anon\n"));
6865
6866         q_u->ptr = 1;
6867         q_u->unknown_0 = 0x5c;  /* server name (?!!) */
6868         q_u->unknown_1 = 0x01;
6869         q_u->access_mask = 0x20;
6870 }
6871
6872 /*******************************************************************
6873 reads or writes a structure.
6874 ********************************************************************/
6875
6876 BOOL samr_io_q_connect_anon(const char *desc, SAMR_Q_CONNECT_ANON * q_u,
6877                             prs_struct *ps, int depth)
6878 {
6879         if (q_u == NULL)
6880                 return False;
6881
6882         prs_debug(ps, depth, desc, "samr_io_q_connect_anon");
6883         depth++;
6884
6885         if(!prs_align(ps))
6886                 return False;
6887
6888         if(!prs_uint32("ptr      ", ps, depth, &q_u->ptr))
6889                 return False;
6890         if(!prs_uint16("unknown_0", ps, depth, &q_u->unknown_0))
6891                 return False;
6892         if(!prs_uint16("unknown_1", ps, depth, &q_u->unknown_1))
6893                 return False;
6894         if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
6895                 return False;
6896
6897         return True;
6898 }
6899
6900 /*******************************************************************
6901 reads or writes a structure.
6902 ********************************************************************/
6903
6904 BOOL samr_io_r_connect_anon(const char *desc, SAMR_R_CONNECT_ANON * r_u,
6905                             prs_struct *ps, int depth)
6906 {
6907         if (r_u == NULL)
6908                 return False;
6909
6910         prs_debug(ps, depth, desc, "samr_io_r_connect_anon");
6911         depth++;
6912
6913         if(!prs_align(ps))
6914                 return False;
6915
6916         if(!smb_io_pol_hnd("connect_pol", &r_u->connect_pol, ps, depth))
6917                 return False;
6918
6919         if(!prs_ntstatus("status", ps, depth, &r_u->status))
6920                 return False;
6921
6922         return True;
6923 }
6924
6925 /*******************************************************************
6926 inits a SAMR_Q_GET_DOM_PWINFO structure.
6927 ********************************************************************/
6928
6929 void init_samr_q_get_dom_pwinfo(SAMR_Q_GET_DOM_PWINFO * q_u,
6930                                 char *srv_name)
6931 {
6932         int len_srv_name = strlen(srv_name);
6933
6934         DEBUG(5, ("init_samr_q_get_dom_pwinfo\n"));
6935
6936         q_u->ptr = 1;
6937         init_uni_hdr(&q_u->hdr_srv_name, len_srv_name);
6938         init_unistr2(&q_u->uni_srv_name, srv_name, len_srv_name);
6939 }
6940
6941 /*******************************************************************
6942 reads or writes a structure.
6943 ********************************************************************/
6944
6945 BOOL samr_io_q_get_dom_pwinfo(const char *desc, SAMR_Q_GET_DOM_PWINFO * q_u,
6946                               prs_struct *ps, int depth)
6947 {
6948         if (q_u == NULL)
6949                 return False;
6950
6951         prs_debug(ps, depth, desc, "samr_io_q_get_dom_pwinfo");
6952         depth++;
6953
6954         if(!prs_align(ps))
6955                 return False;
6956
6957         if(!prs_uint32("ptr", ps, depth, &q_u->ptr))
6958                 return False;
6959         if (q_u->ptr != 0) {
6960                 if(!smb_io_unihdr("", &q_u->hdr_srv_name, ps, depth))
6961                         return False;
6962                 if(!smb_io_unistr2("", &q_u->uni_srv_name, q_u->hdr_srv_name.buffer, ps, depth))
6963                         return False;
6964         }
6965
6966         return True;
6967 }
6968
6969 /*******************************************************************
6970 reads or writes a structure.
6971 ********************************************************************/
6972
6973 BOOL samr_io_r_get_dom_pwinfo(const char *desc, SAMR_R_GET_DOM_PWINFO * r_u,
6974                               prs_struct *ps, int depth)
6975 {
6976         if (r_u == NULL)
6977                 return False;
6978
6979         prs_debug(ps, depth, desc, "samr_io_r_get_dom_pwinfo");
6980         depth++;
6981
6982         if(!prs_align(ps))
6983                 return False;
6984
6985         /*
6986          * We need 16 bytes here according to tests.  Don't know
6987          * what they are, but the length is important for the singing
6988         */
6989
6990         if(!prs_uint32("unk_0", ps, depth, &r_u->unk_0))
6991                 return False;
6992         if(!prs_uint32("unk_1", ps, depth, &r_u->unk_1))
6993                 return False;
6994         if(!prs_uint32("unk_2", ps, depth, &r_u->unk_2))
6995                 return False;
6996
6997         if(!prs_ntstatus("status", ps, depth, &r_u->status))
6998                 return False;
6999
7000         return True;
7001 }
7002
7003 /*******************************************************************
7004 make a SAMR_ENC_PASSWD structure.
7005 ********************************************************************/
7006
7007 void init_enc_passwd(SAMR_ENC_PASSWD * pwd, char pass[512])
7008 {
7009         ZERO_STRUCTP(pwd);
7010
7011         if (pass == NULL) {
7012                 pwd->ptr = 0;
7013         } else {
7014                 pwd->ptr = 1;
7015                 memcpy(pwd->pass, pass, sizeof(pwd->pass));
7016         }
7017 }
7018
7019 /*******************************************************************
7020 reads or writes a SAMR_ENC_PASSWD structure.
7021 ********************************************************************/
7022
7023 BOOL samr_io_enc_passwd(const char *desc, SAMR_ENC_PASSWD * pwd,
7024                         prs_struct *ps, int depth)
7025 {
7026         if (pwd == NULL)
7027                 return False;
7028
7029         prs_debug(ps, depth, desc, "samr_io_enc_passwd");
7030         depth++;
7031
7032         if(!prs_align(ps))
7033                 return False;
7034
7035         if(!prs_uint32("ptr", ps, depth, &pwd->ptr))
7036                 return False;
7037
7038         if (pwd->ptr != 0) {
7039                 if(!prs_uint8s(False, "pwd", ps, depth, pwd->pass, sizeof(pwd->pass)))
7040                         return False;
7041         }
7042
7043         return True;
7044 }
7045
7046 /*******************************************************************
7047 inits a SAMR_ENC_HASH structure.
7048 ********************************************************************/
7049
7050 void init_enc_hash(SAMR_ENC_HASH * hsh, uchar hash[16])
7051 {
7052         ZERO_STRUCTP(hsh);
7053
7054         if (hash == NULL) {
7055                 hsh->ptr = 0;
7056         } else {
7057                 hsh->ptr = 1;
7058                 memcpy(hsh->hash, hash, sizeof(hsh->hash));
7059         }
7060 }
7061
7062 /*******************************************************************
7063 reads or writes a SAMR_ENC_HASH structure.
7064 ********************************************************************/
7065
7066 BOOL samr_io_enc_hash(const char *desc, SAMR_ENC_HASH * hsh,
7067                       prs_struct *ps, int depth)
7068 {
7069         if (hsh == NULL)
7070                 return False;
7071
7072         prs_debug(ps, depth, desc, "samr_io_enc_hash");
7073         depth++;
7074
7075         if(!prs_align(ps))
7076                 return False;
7077
7078         if(!prs_uint32("ptr ", ps, depth, &hsh->ptr))
7079                 return False;
7080         if (hsh->ptr != 0) {
7081                 if(!prs_uint8s(False, "hash", ps, depth, hsh->hash,sizeof(hsh->hash)))
7082                         return False;
7083         }
7084
7085         return True;
7086 }
7087
7088 /*******************************************************************
7089 inits a SAMR_R_GET_DOM_PWINFO structure.
7090 ********************************************************************/
7091
7092 void init_samr_q_chgpasswd_user(SAMR_Q_CHGPASSWD_USER * q_u,
7093                                 char *dest_host, char *user_name,
7094                                 char nt_newpass[516],
7095                                 uchar nt_oldhash[16],
7096                                 char lm_newpass[516],
7097                                 uchar lm_oldhash[16])
7098 {
7099         int len_dest_host = strlen(dest_host);
7100         int len_user_name = strlen(user_name);
7101
7102         DEBUG(5, ("init_samr_q_chgpasswd_user\n"));
7103
7104         q_u->ptr_0 = 1;
7105         init_uni_hdr(&q_u->hdr_dest_host, len_dest_host);
7106         init_unistr2(&q_u->uni_dest_host, dest_host, len_dest_host);
7107         init_uni_hdr(&q_u->hdr_user_name, len_user_name);
7108         init_unistr2(&q_u->uni_user_name, user_name, len_user_name);
7109
7110         init_enc_passwd(&q_u->nt_newpass, nt_newpass);
7111         init_enc_hash(&q_u->nt_oldhash, nt_oldhash);
7112
7113         q_u->unknown = 0x01;
7114
7115         init_enc_passwd(&q_u->lm_newpass, lm_newpass);
7116         init_enc_hash(&q_u->lm_oldhash, lm_oldhash);
7117 }
7118
7119 /*******************************************************************
7120 reads or writes a structure.
7121 ********************************************************************/
7122
7123 BOOL samr_io_q_chgpasswd_user(const char *desc, SAMR_Q_CHGPASSWD_USER * q_u,
7124                               prs_struct *ps, int depth)
7125 {
7126         if (q_u == NULL)
7127                 return False;
7128
7129         prs_debug(ps, depth, desc, "samr_io_q_chgpasswd_user");
7130         depth++;
7131
7132         if(!prs_align(ps))
7133                 return False;
7134
7135         if(!prs_uint32("ptr_0", ps, depth, &q_u->ptr_0))
7136                 return False;
7137
7138         if(!smb_io_unihdr("", &q_u->hdr_dest_host, ps, depth))
7139                 return False;
7140         if(!smb_io_unistr2("", &q_u->uni_dest_host, q_u->hdr_dest_host.buffer, ps, depth))
7141                 return False;
7142
7143         if(!prs_align(ps))
7144                 return False;
7145         if(!smb_io_unihdr("", &q_u->hdr_user_name, ps, depth))
7146                 return False;
7147         if(!smb_io_unistr2("", &q_u->uni_user_name, q_u->hdr_user_name.buffer,ps, depth))
7148                 return False;
7149
7150         if(!samr_io_enc_passwd("nt_newpass", &q_u->nt_newpass, ps, depth))
7151                 return False;
7152         if(!samr_io_enc_hash("nt_oldhash", &q_u->nt_oldhash, ps, depth))
7153                 return False;
7154
7155         if(!prs_uint32("unknown", ps, depth, &q_u->unknown))
7156                 return False;
7157
7158         if(!samr_io_enc_passwd("lm_newpass", &q_u->lm_newpass, ps, depth))
7159                 return False;
7160         if(!samr_io_enc_hash("lm_oldhash", &q_u->lm_oldhash, ps, depth))
7161                 return False;
7162
7163         return True;
7164 }
7165
7166 /*******************************************************************
7167 inits a SAMR_R_CHGPASSWD_USER structure.
7168 ********************************************************************/
7169
7170 void init_samr_r_chgpasswd_user(SAMR_R_CHGPASSWD_USER * r_u, NTSTATUS status)
7171 {
7172         DEBUG(5, ("init_r_chgpasswd_user\n"));
7173
7174         r_u->status = status;
7175 }
7176
7177 /*******************************************************************
7178 reads or writes a structure.
7179 ********************************************************************/
7180
7181 BOOL samr_io_r_chgpasswd_user(const char *desc, SAMR_R_CHGPASSWD_USER * r_u,
7182                               prs_struct *ps, int depth)
7183 {
7184         if (r_u == NULL)
7185                 return False;
7186
7187         prs_debug(ps, depth, desc, "samr_io_r_chgpasswd_user");
7188         depth++;
7189
7190         if(!prs_align(ps))
7191                 return False;
7192
7193         if(!prs_ntstatus("status", ps, depth, &r_u->status))
7194                 return False;
7195
7196         return True;
7197 }
7198
7199 /*******************************************************************
7200 reads or writes a structure.
7201 ********************************************************************/
7202
7203 void init_samr_q_unknown_2e(SAMR_Q_UNKNOWN_2E *q_u,
7204                                 POLICY_HND *domain_pol, uint16 switch_value)
7205 {
7206         DEBUG(5, ("init_samr_q_unknown_2e\n"));
7207
7208         q_u->domain_pol = *domain_pol;
7209         q_u->switch_value = switch_value;
7210 }
7211
7212 /*******************************************************************
7213 reads or writes a structure.
7214 ********************************************************************/
7215
7216 BOOL samr_io_q_unknown_2e(const char *desc, SAMR_Q_UNKNOWN_2E *q_u,
7217                               prs_struct *ps, int depth)
7218 {
7219         if (q_u == NULL)
7220                 return False;
7221
7222         prs_debug(ps, depth, desc, "samr_io_q_unknown_2e");
7223         depth++;
7224
7225         if(!prs_align(ps))
7226                 return False;
7227
7228         if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
7229                 return False;
7230
7231         if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
7232                 return False;
7233
7234         return True;
7235 }
7236
7237 /*******************************************************************
7238 inits a SAMR_R_QUERY_DOMAIN_INFO structure.
7239 ********************************************************************/
7240
7241 void init_samr_r_samr_unknown_2e(SAMR_R_UNKNOWN_2E * r_u,
7242                                 uint16 switch_value, SAM_UNK_CTR * ctr,
7243                                 NTSTATUS status)
7244 {
7245         DEBUG(5, ("init_samr_r_samr_unknown_2e\n"));
7246
7247         r_u->ptr_0 = 0;
7248         r_u->switch_value = 0;
7249         r_u->status = status;   /* return status */
7250
7251         if (NT_STATUS_IS_OK(status)) {
7252                 r_u->switch_value = switch_value;
7253                 r_u->ptr_0 = 1;
7254                 r_u->ctr = ctr;
7255         }
7256 }
7257
7258 /*******************************************************************
7259 reads or writes a structure.
7260 ********************************************************************/
7261
7262 BOOL samr_io_r_samr_unknown_2e(const char *desc, SAMR_R_UNKNOWN_2E * r_u,
7263                               prs_struct *ps, int depth)
7264 {
7265         if (r_u == NULL)
7266                 return False;
7267
7268         prs_debug(ps, depth, desc, "samr_io_r_samr_unknown_2e");
7269         depth++;
7270
7271         if(!prs_align(ps))
7272                 return False;
7273
7274         if(!prs_uint32("ptr_0 ", ps, depth, &r_u->ptr_0))
7275                 return False;
7276
7277         if (r_u->ptr_0 != 0 && r_u->ctr != NULL) {
7278                 if(!prs_uint16("switch_value", ps, depth, &r_u->switch_value))
7279                         return False;
7280                 if(!prs_align(ps))
7281                         return False;
7282
7283                 switch (r_u->switch_value) {
7284                 case 0x0c:
7285                         if(!sam_io_unk_info12("unk_inf12", &r_u->ctr->info.inf12, ps, depth))
7286                                 return False;
7287                         break;
7288                 case 0x07:
7289                         if(!sam_io_unk_info7("unk_inf7",&r_u->ctr->info.inf7, ps,depth))
7290                                 return False;
7291                         break;
7292                 case 0x06:
7293                         if(!sam_io_unk_info6("unk_inf6",&r_u->ctr->info.inf6, ps,depth))
7294                                 return False;
7295                         break;
7296                 case 0x05:
7297                         if(!sam_io_unk_info5("unk_inf5",&r_u->ctr->info.inf5, ps,depth))
7298                                 return False;
7299                         break;
7300                 case 0x03:
7301                         if(!sam_io_unk_info3("unk_inf3",&r_u->ctr->info.inf3, ps,depth))
7302                                 return False;
7303                         break;
7304                 case 0x02:
7305                         if(!sam_io_unk_info2("unk_inf2",&r_u->ctr->info.inf2, ps,depth))
7306                                 return False;
7307                         break;
7308                 case 0x01:
7309                         if(!sam_io_unk_info1("unk_inf1",&r_u->ctr->info.inf1, ps,depth))
7310                                 return False;
7311                         break;
7312                 default:
7313                         DEBUG(0, ("samr_io_r_samr_unknown_2e: unknown switch level 0x%x\n",
7314                                 r_u->switch_value));
7315                         r_u->status = NT_STATUS_INVALID_INFO_CLASS;
7316                         return False;
7317                 }
7318         }
7319         
7320         if(!prs_align(ps))
7321                 return False;
7322
7323         if(!prs_ntstatus("status", ps, depth, &r_u->status))
7324                 return False;
7325         
7326         return True;
7327 }
7328
7329
7330 /*******************************************************************
7331 reads or writes a structure.
7332 ********************************************************************/
7333
7334 void init_samr_q_set_domain_info(SAMR_Q_SET_DOMAIN_INFO *q_u,
7335                                 POLICY_HND *domain_pol, uint16 switch_value, SAM_UNK_CTR *ctr)
7336 {
7337         DEBUG(5, ("init_samr_q_set_domain_info\n"));
7338
7339         q_u->domain_pol = *domain_pol;
7340         q_u->switch_value0 = switch_value;
7341
7342         q_u->switch_value = switch_value;
7343         q_u->ctr = ctr;
7344         
7345 }
7346
7347 /*******************************************************************
7348 reads or writes a structure.
7349 ********************************************************************/
7350
7351 BOOL samr_io_q_set_domain_info(const char *desc, SAMR_Q_SET_DOMAIN_INFO *q_u,
7352                               prs_struct *ps, int depth)
7353 {
7354         if (q_u == NULL)
7355                 return False;
7356
7357         prs_debug(ps, depth, desc, "samr_io_q_set_domain_info");
7358         depth++;
7359
7360         if(!prs_align(ps))
7361                 return False;
7362
7363         if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
7364                 return False;
7365
7366         if(!prs_uint16("switch_value0", ps, depth, &q_u->switch_value0))
7367                 return False;
7368
7369         if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
7370                 return False;
7371
7372         if(!prs_align(ps))
7373                 return False;
7374
7375         if ((q_u->ctr = (SAM_UNK_CTR *)prs_alloc_mem(ps, sizeof(SAM_UNK_CTR))) == NULL)
7376                 return False;
7377         
7378         switch (q_u->switch_value) {
7379
7380         case 0x0c:
7381                 if(!sam_io_unk_info12("unk_inf12", &q_u->ctr->info.inf12, ps, depth))
7382                         return False;
7383                 break;
7384         case 0x07:
7385                 if(!sam_io_unk_info7("unk_inf7",&q_u->ctr->info.inf7, ps,depth))
7386                         return False;
7387                 break;
7388         case 0x06:
7389                 if(!sam_io_unk_info6("unk_inf6",&q_u->ctr->info.inf6, ps,depth))
7390                         return False;
7391                 break;
7392         case 0x05:
7393                 if(!sam_io_unk_info5("unk_inf5",&q_u->ctr->info.inf5, ps,depth))
7394                         return False;
7395                 break;
7396         case 0x03:
7397                 if(!sam_io_unk_info3("unk_inf3",&q_u->ctr->info.inf3, ps,depth))
7398                         return False;
7399                 break;
7400         case 0x02:
7401                 if(!sam_io_unk_info2("unk_inf2",&q_u->ctr->info.inf2, ps,depth))
7402                         return False;
7403                 break;
7404         case 0x01:
7405                 if(!sam_io_unk_info1("unk_inf1",&q_u->ctr->info.inf1, ps,depth))
7406                         return False;
7407                 break;
7408         default:
7409                 DEBUG(0, ("samr_io_r_samr_unknown_2e: unknown switch level 0x%x\n",
7410                         q_u->switch_value));
7411                 return False;
7412         }
7413
7414         return True;
7415 }
7416
7417 /*******************************************************************
7418 inits a SAMR_R_QUERY_DOMAIN_INFO structure.
7419 ********************************************************************/
7420
7421 void init_samr_r_set_domain_info(SAMR_R_SET_DOMAIN_INFO * r_u, NTSTATUS status)
7422 {
7423         DEBUG(5, ("init_samr_r_set_domain_info\n"));
7424
7425         r_u->status = status;   /* return status */
7426 }
7427
7428 /*******************************************************************
7429 reads or writes a structure.
7430 ********************************************************************/
7431
7432 BOOL samr_io_r_set_domain_info(const char *desc, SAMR_R_SET_DOMAIN_INFO * r_u,
7433                               prs_struct *ps, int depth)
7434 {
7435         if (r_u == NULL)
7436                 return False;
7437
7438         prs_debug(ps, depth, desc, "samr_io_r_samr_unknown_2e");
7439         depth++;
7440
7441         if(!prs_align(ps))
7442                 return False;
7443
7444         if(!prs_ntstatus("status", ps, depth, &r_u->status))
7445                 return False;
7446         
7447         return True;
7448 }