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