Removed global_myworkgroup, global_myname, global_myscope. Added liberal
[ira/wip.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,const char *server)
635 {
636         int len_server = strlen(server);
637
638         init_uni_hdr(&u_5->hdr_server, len_server);
639
640         init_unistr2(&u_5->uni_server, server, len_server);
641 }
642
643 /*******************************************************************
644 reads or writes a structure.
645 ********************************************************************/
646
647 static BOOL sam_io_unk_info5(char *desc, SAM_UNK_INFO_5 * u_5,
648                              prs_struct *ps, int depth)
649 {
650         if (u_5 == NULL)
651                 return False;
652
653         prs_debug(ps, depth, desc, "sam_io_unk_info5");
654         depth++;
655
656         if(!smb_io_unihdr("hdr_server", &u_5->hdr_server, ps, depth))
657                 return False;
658
659         if(!smb_io_unistr2("uni_server", &u_5->uni_server, u_5->hdr_server.buffer, ps, depth))
660                 return False;
661
662         return True;
663 }
664
665 /*******************************************************************
666 inits a structure.
667 ********************************************************************/
668 void init_unk_info2(SAM_UNK_INFO_2 * u_2,
669                         const char *domain, const char *server,
670                         uint32 seq_num, uint32 num_users, uint32 num_groups, uint32 num_alias)
671 {
672         int len_domain = strlen(domain);
673         int len_server = strlen(server);
674
675         u_2->unknown_0 = 0x00000000;
676         u_2->unknown_1 = 0x80000000;
677         u_2->unknown_2 = 0x00000000;
678
679         u_2->ptr_0 = 1;
680         init_uni_hdr(&u_2->hdr_domain, len_domain);
681         init_uni_hdr(&u_2->hdr_server, len_server);
682
683         u_2->seq_num = seq_num;
684         u_2->unknown_3 = 0x00000000;
685
686         u_2->unknown_4 = 0x00000001;
687         u_2->unknown_5 = 0x00000003;
688         u_2->unknown_6 = 0x00000001;
689         u_2->num_domain_usrs = num_users;
690         u_2->num_domain_grps = num_groups;
691         u_2->num_local_grps = num_alias;
692
693         memset(u_2->padding, 0, sizeof(u_2->padding));  /* 12 bytes zeros */
694
695         init_unistr2(&u_2->uni_domain, domain, len_domain);
696         init_unistr2(&u_2->uni_server, server, len_server);
697 }
698
699 /*******************************************************************
700 reads or writes a structure.
701 ********************************************************************/
702
703 static BOOL sam_io_unk_info2(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         if (nt_time_is_zero(pass_must_change_time)) {
5474                 usr->passmustchange=PASS_MUST_CHANGE_AT_NEXT_LOGON;
5475         } else {
5476                 usr->passmustchange=0;
5477         }
5478
5479
5480         ZERO_STRUCT(usr->padding1);
5481         ZERO_STRUCT(usr->padding2);
5482
5483         usr->unknown_5 = unknown_5;     /* 0x0001 0000 */
5484
5485         memcpy(usr->pass, newpass, sizeof(usr->pass));
5486
5487         copy_unistr2(&usr->uni_user_name, user_name);
5488         copy_unistr2(&usr->uni_full_name, full_name);
5489         copy_unistr2(&usr->uni_home_dir, home_dir);
5490         copy_unistr2(&usr->uni_dir_drive, dir_drive);
5491         copy_unistr2(&usr->uni_logon_script, log_scr);
5492         copy_unistr2(&usr->uni_profile_path, prof_path);
5493         copy_unistr2(&usr->uni_acct_desc, desc);
5494         copy_unistr2(&usr->uni_workstations, wkstas);
5495         copy_unistr2(&usr->uni_unknown_str, unk_str);
5496         copy_unistr2(&usr->uni_munged_dial, mung_dial);
5497
5498         usr->unknown_6 = unknown_6;     /* 0x0000 04ec */
5499         usr->padding4 = 0;
5500
5501         memcpy(&usr->logon_hrs, hrs, sizeof(usr->logon_hrs));
5502 }
5503
5504 /*************************************************************************
5505  init_sam_user_info23
5506
5507  unknown_3 = 0x09f8 27fa
5508  unknown_5 = 0x0001 0000
5509  unknown_6 = 0x0000 04ec 
5510
5511  *************************************************************************/
5512
5513 void init_sam_user_info23A(SAM_USER_INFO_23 * usr, NTTIME * logon_time, /* all zeros */
5514                            NTTIME * logoff_time,        /* all zeros */
5515                            NTTIME * kickoff_time,       /* all zeros */
5516                            NTTIME * pass_last_set_time, /* all zeros */
5517                            NTTIME * pass_can_change_time,       /* all zeros */
5518                            NTTIME * pass_must_change_time,      /* all zeros */
5519                            char *user_name,     /* NULL */
5520                            char *full_name,
5521                            char *home_dir, char *dir_drive, char *log_scr,
5522                            char *prof_path, char *desc, char *wkstas,
5523                            char *unk_str, char *mung_dial, uint32 user_rid,     /* 0x0000 0000 */
5524                            uint32 group_rid, uint32 acb_info,
5525                            uint32 unknown_3, uint16 logon_divs,
5526                            LOGON_HRS * hrs, uint32 unknown_5,
5527                            char newpass[516], uint32 unknown_6)
5528 {
5529         int len_user_name = user_name != NULL ? strlen(user_name) : 0;
5530         int len_full_name = full_name != NULL ? strlen(full_name) : 0;
5531         int len_home_dir = home_dir != NULL ? strlen(home_dir) : 0;
5532         int len_dir_drive = dir_drive != NULL ? strlen(dir_drive) : 0;
5533         int len_logon_script = log_scr != NULL ? strlen(log_scr) : 0;
5534         int len_profile_path = prof_path != NULL ? strlen(prof_path) : 0;
5535         int len_description = desc != NULL ? strlen(desc) : 0;
5536         int len_workstations = wkstas != NULL ? strlen(wkstas) : 0;
5537         int len_unknown_str = unk_str != NULL ? strlen(unk_str) : 0;
5538         int len_munged_dial = mung_dial != NULL ? strlen(mung_dial) : 0;
5539
5540         usr->logon_time = *logon_time;  /* all zeros */
5541         usr->logoff_time = *logoff_time;        /* all zeros */
5542         usr->kickoff_time = *kickoff_time;      /* all zeros */
5543         usr->pass_last_set_time = *pass_last_set_time;  /* all zeros */
5544         usr->pass_can_change_time = *pass_can_change_time;      /* all zeros */
5545         usr->pass_must_change_time = *pass_must_change_time;    /* all zeros */
5546
5547         init_uni_hdr(&usr->hdr_user_name, len_user_name);       /* NULL */
5548         init_uni_hdr(&usr->hdr_full_name, len_full_name);
5549         init_uni_hdr(&usr->hdr_home_dir, len_home_dir);
5550         init_uni_hdr(&usr->hdr_dir_drive, len_dir_drive);
5551         init_uni_hdr(&usr->hdr_logon_script, len_logon_script);
5552         init_uni_hdr(&usr->hdr_profile_path, len_profile_path);
5553         init_uni_hdr(&usr->hdr_acct_desc, len_description);
5554         init_uni_hdr(&usr->hdr_workstations, len_workstations);
5555         init_uni_hdr(&usr->hdr_unknown_str, len_unknown_str);
5556         init_uni_hdr(&usr->hdr_munged_dial, len_munged_dial);
5557
5558         ZERO_STRUCT(usr->nt_pwd);
5559         ZERO_STRUCT(usr->lm_pwd);
5560
5561         usr->user_rid = user_rid;       /* 0x0000 0000 */
5562         usr->group_rid = group_rid;
5563         usr->acb_info = acb_info;
5564         usr->unknown_3 = unknown_3;     /* 09f8 27fa */
5565
5566         usr->logon_divs = logon_divs;   /* should be 168 (hours/week) */
5567         usr->ptr_logon_hrs = hrs ? 1 : 0;
5568
5569         if (nt_time_is_zero(pass_must_change_time)) {
5570                 usr->passmustchange=PASS_MUST_CHANGE_AT_NEXT_LOGON;
5571         } else {
5572                 usr->passmustchange=0;
5573         }
5574
5575         ZERO_STRUCT(usr->padding1);
5576         ZERO_STRUCT(usr->padding2);
5577
5578         usr->unknown_5 = unknown_5;     /* 0x0001 0000 */
5579
5580         memcpy(usr->pass, newpass, sizeof(usr->pass));
5581
5582         init_unistr2(&usr->uni_user_name, user_name, len_user_name);    /* NULL */
5583         init_unistr2(&usr->uni_full_name, full_name, len_full_name);
5584         init_unistr2(&usr->uni_home_dir, home_dir, len_home_dir);
5585         init_unistr2(&usr->uni_dir_drive, dir_drive, len_dir_drive);
5586         init_unistr2(&usr->uni_logon_script, log_scr, len_logon_script);
5587         init_unistr2(&usr->uni_profile_path, prof_path, len_profile_path);
5588         init_unistr2(&usr->uni_acct_desc, desc, len_description);
5589         init_unistr2(&usr->uni_workstations, wkstas, len_workstations);
5590         init_unistr2(&usr->uni_unknown_str, unk_str, len_unknown_str);
5591         init_unistr2(&usr->uni_munged_dial, mung_dial, len_munged_dial);
5592
5593         usr->unknown_6 = unknown_6;     /* 0x0000 04ec */
5594         usr->padding4 = 0;
5595
5596         memcpy(&usr->logon_hrs, hrs, sizeof(usr->logon_hrs));
5597 }
5598
5599 /*******************************************************************
5600 reads or writes a structure.
5601 ********************************************************************/
5602
5603 static BOOL sam_io_user_info23(char *desc, SAM_USER_INFO_23 * usr,
5604                                prs_struct *ps, int depth)
5605 {
5606         if (usr == NULL)
5607                 return False;
5608
5609         prs_debug(ps, depth, desc, "sam_io_user_info23");
5610         depth++;
5611
5612         if(!prs_align(ps))
5613                 return False;
5614
5615         if(!smb_io_time("logon_time           ", &usr->logon_time, ps, depth))
5616                 return False;
5617         if(!smb_io_time("logoff_time          ", &usr->logoff_time, ps, depth))
5618                 return False;
5619         if(!smb_io_time("kickoff_time         ", &usr->kickoff_time, ps, depth))
5620                 return False;
5621         if(!smb_io_time("pass_last_set_time   ", &usr->pass_last_set_time, ps, depth))
5622                 return False;
5623         if(!smb_io_time("pass_can_change_time ", &usr->pass_can_change_time, ps, depth))
5624                 return False;
5625         if(!smb_io_time("pass_must_change_time", &usr->pass_must_change_time, ps, depth))
5626                 return False;
5627
5628         if(!smb_io_unihdr("hdr_user_name   ", &usr->hdr_user_name, ps, depth))  /* username unicode string header */
5629                 return False;
5630         if(!smb_io_unihdr("hdr_full_name   ", &usr->hdr_full_name, ps, depth))  /* user's full name unicode string header */
5631                 return False;
5632         if(!smb_io_unihdr("hdr_home_dir    ", &usr->hdr_home_dir, ps, depth))   /* home directory unicode string header */
5633                 return False;
5634         if(!smb_io_unihdr("hdr_dir_drive   ", &usr->hdr_dir_drive, ps, depth))  /* home directory drive */
5635                 return False;
5636         if(!smb_io_unihdr("hdr_logon_script", &usr->hdr_logon_script, ps, depth))       /* logon script unicode string header */
5637                 return False;
5638         if(!smb_io_unihdr("hdr_profile_path", &usr->hdr_profile_path, ps, depth))       /* profile path unicode string header */
5639                 return False;
5640         if(!smb_io_unihdr("hdr_acct_desc   ", &usr->hdr_acct_desc, ps, depth))  /* account desc */
5641                 return False;
5642         if(!smb_io_unihdr("hdr_workstations", &usr->hdr_workstations, ps, depth))       /* wkstas user can log on from */
5643                 return False;
5644         if(!smb_io_unihdr("hdr_unknown_str ", &usr->hdr_unknown_str, ps, depth))        /* unknown string */
5645                 return False;
5646         if(!smb_io_unihdr("hdr_munged_dial ", &usr->hdr_munged_dial, ps, depth))        /* wkstas user can log on from */
5647                 return False;
5648
5649         if(!prs_uint8s(False, "lm_pwd        ", ps, depth, usr->lm_pwd, sizeof(usr->lm_pwd)))
5650                 return False;
5651         if(!prs_uint8s(False, "nt_pwd        ", ps, depth, usr->nt_pwd, sizeof(usr->nt_pwd)))
5652                 return False;
5653
5654         if(!prs_uint32("user_rid      ", ps, depth, &usr->user_rid))    /* User ID */
5655                 return False;
5656         if(!prs_uint32("group_rid     ", ps, depth, &usr->group_rid))   /* Group ID */
5657                 return False;
5658         if(!prs_uint32("acb_info      ", ps, depth, &usr->acb_info))
5659                 return False;
5660
5661         if(!prs_uint32("unknown_3     ", ps, depth, &usr->unknown_3))
5662                 return False;
5663         if(!prs_uint16("logon_divs    ", ps, depth, &usr->logon_divs))  /* logon divisions per week */
5664                 return False;
5665         if(!prs_align(ps))
5666                 return False;
5667         if(!prs_uint32("ptr_logon_hrs ", ps, depth, &usr->ptr_logon_hrs))
5668                 return False;
5669
5670         if(!prs_uint32("unknown_5     ", ps, depth, &usr->unknown_5))
5671                 return False;
5672
5673         if(!prs_uint8s(False, "padding1      ", ps, depth, usr->padding1, sizeof(usr->padding1)))
5674                 return False;
5675         if(!prs_uint8("passmustchange ", ps, depth, &usr->passmustchange))
5676                 return False;
5677         if(!prs_uint8("padding2       ", ps, depth, &usr->padding2))
5678                 return False;
5679
5680
5681         if(!prs_uint8s(False, "password      ", ps, depth, usr->pass, sizeof(usr->pass)))
5682                 return False;
5683
5684         /* here begins pointed-to data */
5685
5686         if(!smb_io_unistr2("uni_user_name   ", &usr->uni_user_name, usr->hdr_user_name.buffer, ps, depth))      /* username unicode string */
5687                 return False;
5688
5689         if(!smb_io_unistr2("uni_full_name   ", &usr->uni_full_name, usr->hdr_full_name.buffer, ps, depth))      /* user's full name unicode string */
5690                 return False;
5691
5692         if(!smb_io_unistr2("uni_home_dir    ", &usr->uni_home_dir, usr->hdr_home_dir.buffer, ps, depth))        /* home directory unicode string */
5693                 return False;
5694
5695         if(!smb_io_unistr2("uni_dir_drive   ", &usr->uni_dir_drive, usr->hdr_dir_drive.buffer, ps, depth))      /* home directory drive unicode string */
5696                 return False;
5697
5698         if(!smb_io_unistr2("uni_logon_script", &usr->uni_logon_script, usr->hdr_logon_script.buffer, ps, depth))        /* logon script unicode string */
5699                 return False;
5700
5701         if(!smb_io_unistr2("uni_profile_path", &usr->uni_profile_path, usr->hdr_profile_path.buffer, ps, depth))        /* profile path unicode string */
5702                 return False;
5703
5704         if(!smb_io_unistr2("uni_acct_desc   ", &usr->uni_acct_desc, usr->hdr_acct_desc.buffer, ps, depth))      /* user desc unicode string */
5705                 return False;
5706
5707         if(!smb_io_unistr2("uni_workstations", &usr->uni_workstations, usr->hdr_workstations.buffer, ps, depth))        /* worksations user can log on from */
5708                 return False;
5709
5710         if(!smb_io_unistr2("uni_unknown_str ", &usr->uni_unknown_str, usr->hdr_unknown_str.buffer, ps, depth))  /* unknown string */
5711                 return False;
5712
5713         if(!smb_io_unistr2("uni_munged_dial ", &usr->uni_munged_dial, usr->hdr_munged_dial.buffer, ps, depth))
5714                 return False;
5715
5716         /* ok, this is only guess-work (as usual) */
5717         if (usr->ptr_logon_hrs) {
5718                 if(!prs_uint32("unknown_6     ", ps, depth, &usr->unknown_6))
5719                         return False;
5720                 if(!prs_uint32("padding4      ", ps, depth, &usr->padding4))
5721                         return False;
5722                 if(!sam_io_logon_hrs("logon_hrs", &usr->logon_hrs, ps, depth))
5723                         return False;
5724         } else if (UNMARSHALLING(ps)) {
5725                 usr->unknown_6 = 0;
5726                 usr->padding4 = 0;
5727         }
5728
5729         return True;
5730 }
5731
5732 /*******************************************************************
5733  reads or writes a structure.
5734  NB. This structure is *definately* incorrect. It's my best guess
5735  currently for W2K SP2. The password field is encrypted in a different
5736  way than normal... And there are definately other problems. JRA.
5737 ********************************************************************/
5738
5739 static BOOL sam_io_user_info25(char *desc, SAM_USER_INFO_25 * usr, prs_struct *ps, int depth)
5740 {
5741         if (usr == NULL)
5742                 return False;
5743
5744         prs_debug(ps, depth, desc, "sam_io_user_info25");
5745         depth++;
5746
5747         if(!prs_align(ps))
5748                 return False;
5749
5750         if(!smb_io_time("logon_time           ", &usr->logon_time, ps, depth))
5751                 return False;
5752         if(!smb_io_time("logoff_time          ", &usr->logoff_time, ps, depth))
5753                 return False;
5754         if(!smb_io_time("kickoff_time         ", &usr->kickoff_time, ps, depth))
5755                 return False;
5756         if(!smb_io_time("pass_last_set_time   ", &usr->pass_last_set_time, ps, depth))
5757                 return False;
5758         if(!smb_io_time("pass_can_change_time ", &usr->pass_can_change_time, ps, depth))
5759                 return False;
5760         if(!smb_io_time("pass_must_change_time", &usr->pass_must_change_time, ps, depth))
5761                 return False;
5762
5763         if(!smb_io_unihdr("hdr_user_name   ", &usr->hdr_user_name, ps, depth))  /* username unicode string header */
5764                 return False;
5765         if(!smb_io_unihdr("hdr_full_name   ", &usr->hdr_full_name, ps, depth))  /* user's full name unicode string header */
5766                 return False;
5767         if(!smb_io_unihdr("hdr_home_dir    ", &usr->hdr_home_dir, ps, depth))   /* home directory unicode string header */
5768                 return False;
5769         if(!smb_io_unihdr("hdr_dir_drive   ", &usr->hdr_dir_drive, ps, depth))  /* home directory drive */
5770                 return False;
5771         if(!smb_io_unihdr("hdr_logon_script", &usr->hdr_logon_script, ps, depth))       /* logon script unicode string header */
5772                 return False;
5773         if(!smb_io_unihdr("hdr_profile_path", &usr->hdr_profile_path, ps, depth))       /* profile path unicode string header */
5774                 return False;
5775         if(!smb_io_unihdr("hdr_acct_desc   ", &usr->hdr_acct_desc, ps, depth))  /* account desc */
5776                 return False;
5777         if(!smb_io_unihdr("hdr_workstations", &usr->hdr_workstations, ps, depth))       /* wkstas user can log on from */
5778                 return False;
5779         if(!smb_io_unihdr("hdr_unknown_str ", &usr->hdr_unknown_str, ps, depth))        /* unknown string */
5780                 return False;
5781         if(!smb_io_unihdr("hdr_munged_dial ", &usr->hdr_munged_dial, ps, depth))        /* wkstas user can log on from */
5782                 return False;
5783
5784         if(!prs_uint8s(False, "lm_pwd        ", ps, depth, usr->lm_pwd, sizeof(usr->lm_pwd)))
5785                 return False;
5786         if(!prs_uint8s(False, "nt_pwd        ", ps, depth, usr->nt_pwd, sizeof(usr->nt_pwd)))
5787                 return False;
5788
5789         if(!prs_uint32("user_rid      ", ps, depth, &usr->user_rid))    /* User ID */
5790                 return False;
5791         if(!prs_uint32("group_rid     ", ps, depth, &usr->group_rid))   /* Group ID */
5792                 return False;
5793         if(!prs_uint32("acb_info      ", ps, depth, &usr->acb_info))
5794                 return False;
5795
5796         if(!prs_uint32s(False, "unknown_6      ", ps, depth, usr->unknown_6, 6))
5797                 return False;
5798
5799         if(!prs_uint8s(False, "password      ", ps, depth, usr->pass, sizeof(usr->pass)))
5800                 return False;
5801
5802         /* here begins pointed-to data */
5803
5804         if(!smb_io_unistr2("uni_user_name   ", &usr->uni_user_name, usr->hdr_user_name.buffer, ps, depth))      /* username unicode string */
5805                 return False;
5806
5807         if(!smb_io_unistr2("uni_full_name   ", &usr->uni_full_name, usr->hdr_full_name.buffer, ps, depth))      /* user's full name unicode string */
5808                 return False;
5809
5810         if(!smb_io_unistr2("uni_home_dir    ", &usr->uni_home_dir, usr->hdr_home_dir.buffer, ps, depth))        /* home directory unicode string */
5811                 return False;
5812
5813         if(!smb_io_unistr2("uni_dir_drive   ", &usr->uni_dir_drive, usr->hdr_dir_drive.buffer, ps, depth))      /* home directory drive unicode string */
5814                 return False;
5815
5816         if(!smb_io_unistr2("uni_logon_script", &usr->uni_logon_script, usr->hdr_logon_script.buffer, ps, depth))        /* logon script unicode string */
5817                 return False;
5818
5819         if(!smb_io_unistr2("uni_profile_path", &usr->uni_profile_path, usr->hdr_profile_path.buffer, ps, depth))        /* profile path unicode string */
5820                 return False;
5821
5822         if(!smb_io_unistr2("uni_acct_desc   ", &usr->uni_acct_desc, usr->hdr_acct_desc.buffer, ps, depth))      /* user desc unicode string */
5823                 return False;
5824
5825         if(!smb_io_unistr2("uni_workstations", &usr->uni_workstations, usr->hdr_workstations.buffer, ps, depth))        /* worksations user can log on from */
5826                 return False;
5827
5828         if(!smb_io_unistr2("uni_unknown_str ", &usr->uni_unknown_str, usr->hdr_unknown_str.buffer, ps, depth))  /* unknown string */
5829                 return False;
5830
5831         if(!smb_io_unistr2("uni_munged_dial ", &usr->uni_munged_dial, usr->hdr_munged_dial.buffer, ps, depth))
5832                 return False;
5833
5834 #if 0 /* JRA - unknown... */
5835         /* ok, this is only guess-work (as usual) */
5836         if (usr->ptr_logon_hrs) {
5837                 if(!prs_uint32("unknown_6     ", ps, depth, &usr->unknown_6))
5838                         return False;
5839                 if(!prs_uint32("padding4      ", ps, depth, &usr->padding4))
5840                         return False;
5841                 if(!sam_io_logon_hrs("logon_hrs", &usr->logon_hrs, ps, depth))
5842                         return False;
5843         } else if (UNMARSHALLING(ps)) {
5844                 usr->unknown_6 = 0;
5845                 usr->padding4 = 0;
5846         }
5847 #endif
5848
5849         return True;
5850 }
5851
5852
5853 /*************************************************************************
5854  init_sam_user_info21W
5855
5856  unknown_3 = 0x00ff ffff
5857  unknown_5 = 0x0002 0000
5858  unknown_6 = 0x0000 04ec 
5859
5860  *************************************************************************/
5861
5862 void init_sam_user_info21W(SAM_USER_INFO_21 * usr,
5863                            NTTIME * logon_time,
5864                            NTTIME * logoff_time,
5865                            NTTIME * kickoff_time,
5866                            NTTIME * pass_last_set_time,
5867                            NTTIME * pass_can_change_time,
5868                            NTTIME * pass_must_change_time,
5869                            UNISTR2 *user_name,
5870                            UNISTR2 *full_name,
5871                            UNISTR2 *home_dir,
5872                            UNISTR2 *dir_drive,
5873                            UNISTR2 *log_scr,
5874                            UNISTR2 *prof_path,
5875                            UNISTR2 *desc,
5876                            UNISTR2 *wkstas,
5877                            UNISTR2 *unk_str,
5878                            UNISTR2 *mung_dial,
5879                            uchar lm_pwd[16],
5880                            uchar nt_pwd[16],
5881                            uint32 user_rid,
5882                            uint32 group_rid,
5883                            uint32 acb_info,
5884                            uint32 unknown_3,
5885                            uint16 logon_divs,
5886                            LOGON_HRS * hrs,
5887                            uint32 unknown_5, uint32 unknown_6)
5888 {
5889         int len_user_name = user_name != NULL ? user_name->uni_str_len : 0;
5890         int len_full_name = full_name != NULL ? full_name->uni_str_len : 0;
5891         int len_home_dir = home_dir != NULL ? home_dir->uni_str_len : 0;
5892         int len_dir_drive = dir_drive != NULL ? dir_drive->uni_str_len : 0;
5893         int len_logon_script = log_scr != NULL ? log_scr->uni_str_len : 0;
5894         int len_profile_path = prof_path != NULL ? prof_path->uni_str_len : 0;
5895         int len_description = desc != NULL ? desc->uni_str_len : 0;
5896         int len_workstations = wkstas != NULL ? wkstas->uni_str_len : 0;
5897         int len_unknown_str = unk_str != NULL ? unk_str->uni_str_len : 0;
5898         int len_munged_dial = mung_dial != NULL ? mung_dial->uni_str_len : 0;
5899
5900         usr->logon_time = *logon_time;
5901         usr->logoff_time = *logoff_time;
5902         usr->kickoff_time = *kickoff_time;
5903         usr->pass_last_set_time = *pass_last_set_time;
5904         usr->pass_can_change_time = *pass_can_change_time;
5905         usr->pass_must_change_time = *pass_must_change_time;
5906
5907         init_uni_hdr(&usr->hdr_user_name, len_user_name);
5908         init_uni_hdr(&usr->hdr_full_name, len_full_name);
5909         init_uni_hdr(&usr->hdr_home_dir, len_home_dir);
5910         init_uni_hdr(&usr->hdr_dir_drive, len_dir_drive);
5911         init_uni_hdr(&usr->hdr_logon_script, len_logon_script);
5912         init_uni_hdr(&usr->hdr_profile_path, len_profile_path);
5913         init_uni_hdr(&usr->hdr_acct_desc, len_description);
5914         init_uni_hdr(&usr->hdr_workstations, len_workstations);
5915         init_uni_hdr(&usr->hdr_unknown_str, len_unknown_str);
5916         init_uni_hdr(&usr->hdr_munged_dial, len_munged_dial);
5917
5918         memcpy(usr->lm_pwd, lm_pwd, sizeof(usr->lm_pwd));
5919         memcpy(usr->nt_pwd, nt_pwd, sizeof(usr->nt_pwd));
5920
5921         usr->user_rid = user_rid;
5922         usr->group_rid = group_rid;
5923         usr->acb_info = acb_info;
5924         usr->unknown_3 = unknown_3;     /* 0x00ff ffff */
5925
5926         usr->logon_divs = logon_divs;   /* should be 168 (hours/week) */
5927         usr->ptr_logon_hrs = hrs ? 1 : 0;
5928         usr->unknown_5 = unknown_5;     /* 0x0002 0000 */
5929
5930         if (nt_time_is_zero(pass_must_change_time)) {
5931                 usr->passmustchange=PASS_MUST_CHANGE_AT_NEXT_LOGON;
5932         } else {
5933                 usr->passmustchange=0;
5934         }
5935
5936
5937         ZERO_STRUCT(usr->padding1);
5938         ZERO_STRUCT(usr->padding2);
5939
5940         copy_unistr2(&usr->uni_user_name, user_name);
5941         copy_unistr2(&usr->uni_full_name, full_name);
5942         copy_unistr2(&usr->uni_home_dir, home_dir);
5943         copy_unistr2(&usr->uni_dir_drive, dir_drive);
5944         copy_unistr2(&usr->uni_logon_script, log_scr);
5945         copy_unistr2(&usr->uni_profile_path, prof_path);
5946         copy_unistr2(&usr->uni_acct_desc, desc);
5947         copy_unistr2(&usr->uni_workstations, wkstas);
5948         copy_unistr2(&usr->uni_unknown_str, unk_str);
5949         copy_unistr2(&usr->uni_munged_dial, mung_dial);
5950
5951         usr->unknown_6 = unknown_6;     /* 0x0000 04ec */
5952         usr->padding4 = 0;
5953
5954         memcpy(&usr->logon_hrs, hrs, sizeof(usr->logon_hrs));
5955 }
5956
5957 /*************************************************************************
5958  init_sam_user_info21
5959
5960  unknown_3 = 0x00ff ffff
5961  unknown_5 = 0x0002 0000
5962  unknown_6 = 0x0000 04ec 
5963
5964  *************************************************************************/
5965
5966 NTSTATUS init_sam_user_info21A(SAM_USER_INFO_21 *usr, SAM_ACCOUNT *pw, DOM_SID *domain_sid)
5967 {
5968         NTTIME          logon_time, logoff_time, kickoff_time,
5969                         pass_last_set_time, pass_can_change_time,
5970                         pass_must_change_time;
5971
5972         int             len_user_name, len_full_name, len_home_dir,
5973                         len_dir_drive, len_logon_script, len_profile_path,
5974                         len_description, len_workstations, len_unknown_str,
5975                         len_munged_dial;
5976                         
5977         const char*             user_name = pdb_get_username(pw);
5978         const char*             full_name = pdb_get_fullname(pw);
5979         const char*             home_dir  = pdb_get_homedir(pw);
5980         const char*             dir_drive = pdb_get_dir_drive(pw);
5981         const char*             logon_script = pdb_get_logon_script(pw);
5982         const char*             profile_path = pdb_get_profile_path(pw);
5983         const char*             description = pdb_get_acct_desc(pw);
5984         const char*             workstations = pdb_get_workstations(pw);
5985         const char*             munged_dial = pdb_get_munged_dial(pw);
5986
5987         uint32 user_rid;
5988         const DOM_SID *user_sid;
5989
5990         uint32 group_rid;
5991         const DOM_SID *group_sid;
5992
5993         len_user_name    = user_name    != NULL ? strlen(user_name   )+1 : 0;
5994         len_full_name    = full_name    != NULL ? strlen(full_name   )+1 : 0;
5995         len_home_dir     = home_dir     != NULL ? strlen(home_dir    )+1 : 0;
5996         len_dir_drive    = dir_drive    != NULL ? strlen(dir_drive   )+1 : 0;
5997         len_logon_script = logon_script != NULL ? strlen(logon_script)+1 : 0;
5998         len_profile_path = profile_path != NULL ? strlen(profile_path)+1 : 0;
5999         len_description  = description  != NULL ? strlen(description )+1 : 0;
6000         len_workstations = workstations != NULL ? strlen(workstations)+1 : 0;
6001         len_unknown_str  = 0;
6002         len_munged_dial  = munged_dial  != NULL ? strlen(munged_dial )+1 : 0;
6003
6004
6005         /* Create NTTIME structs */
6006         unix_to_nt_time (&logon_time,           pdb_get_logon_time(pw));
6007         unix_to_nt_time (&logoff_time,          pdb_get_logoff_time(pw));
6008         unix_to_nt_time (&kickoff_time,         pdb_get_kickoff_time(pw));
6009         unix_to_nt_time (&pass_last_set_time,   pdb_get_pass_last_set_time(pw));
6010         unix_to_nt_time (&pass_can_change_time, pdb_get_pass_can_change_time(pw));
6011         unix_to_nt_time (&pass_must_change_time,pdb_get_pass_must_change_time(pw));
6012         
6013         /* structure assignment */
6014         usr->logon_time            = logon_time;
6015         usr->logoff_time           = logoff_time;
6016         usr->kickoff_time          = kickoff_time;
6017         usr->pass_last_set_time    = pass_last_set_time;
6018         usr->pass_can_change_time  = pass_can_change_time;
6019         usr->pass_must_change_time = pass_must_change_time;
6020
6021         init_uni_hdr(&usr->hdr_user_name, len_user_name);
6022         init_uni_hdr(&usr->hdr_full_name, len_full_name);
6023         init_uni_hdr(&usr->hdr_home_dir, len_home_dir);
6024         init_uni_hdr(&usr->hdr_dir_drive, len_dir_drive);
6025         init_uni_hdr(&usr->hdr_logon_script, len_logon_script);
6026         init_uni_hdr(&usr->hdr_profile_path, len_profile_path);
6027         init_uni_hdr(&usr->hdr_acct_desc, len_description);
6028         init_uni_hdr(&usr->hdr_workstations, len_workstations);
6029         init_uni_hdr(&usr->hdr_unknown_str, len_unknown_str);
6030         init_uni_hdr(&usr->hdr_munged_dial, len_munged_dial);
6031
6032         ZERO_STRUCT(usr->nt_pwd);
6033         ZERO_STRUCT(usr->lm_pwd);
6034
6035         user_sid = pdb_get_user_sid(pw);
6036         
6037         if (!sid_peek_check_rid(domain_sid, user_sid, &user_rid)) {
6038                 fstring user_sid_string;
6039                 fstring domain_sid_string;
6040                 DEBUG(0, ("init_sam_user_info_21A: User %s has SID %s, \nwhich conflicts with "
6041                           "the domain sid %s.  Failing operation.\n", 
6042                           user_name, 
6043                           sid_to_string(user_sid_string, user_sid),
6044                           sid_to_string(domain_sid_string, domain_sid)));
6045                 return NT_STATUS_UNSUCCESSFUL;
6046         }
6047
6048         group_sid = pdb_get_group_sid(pw);
6049         
6050         if (!sid_peek_check_rid(domain_sid, group_sid, &group_rid)) {
6051                 fstring group_sid_string;
6052                 fstring domain_sid_string;
6053                 DEBUG(0, ("init_sam_user_info_21A: User %s has Primary Group SID %s, \n"
6054                           "which conflicts with the domain sid %s.  Failing operation.\n", 
6055                           user_name, 
6056                           sid_to_string(group_sid_string, group_sid),
6057                           sid_to_string(domain_sid_string, domain_sid)));
6058                 return NT_STATUS_UNSUCCESSFUL;
6059         }
6060
6061         usr->user_rid  = user_rid;
6062         usr->group_rid = group_rid;
6063         usr->acb_info  = pdb_get_acct_ctrl(pw);
6064
6065         /*
6066           Look at a user on a real NT4 PDC with usrmgr, press
6067           'ok'. Then you will see that unknown_3 is set to
6068           0x08f827fa. Look at the user immediately after that again,
6069           and you will see that 0x00fffff is returned. This solves
6070           the problem that you get access denied after having looked
6071           at the user.
6072           -- Volker
6073         */
6074         usr->unknown_3 = 0x00ffffff;
6075
6076         usr->logon_divs = pdb_get_logon_divs(pw); 
6077         usr->ptr_logon_hrs = pdb_get_hours(pw) ? 1 : 0;
6078         usr->unknown_5 = pdb_get_unknown_5(pw); /* 0x0002 0000 */
6079
6080         if (pdb_get_pass_must_change_time(pw) == 0) {
6081                 usr->passmustchange=PASS_MUST_CHANGE_AT_NEXT_LOGON;
6082         } else {
6083                 usr->passmustchange=0;
6084         }
6085
6086
6087         ZERO_STRUCT(usr->padding1);
6088         ZERO_STRUCT(usr->padding2);
6089
6090         init_unistr2(&usr->uni_user_name, user_name, len_user_name);
6091         init_unistr2(&usr->uni_full_name, full_name, len_full_name);
6092         init_unistr2(&usr->uni_home_dir, home_dir, len_home_dir);
6093         init_unistr2(&usr->uni_dir_drive, dir_drive, len_dir_drive);
6094         init_unistr2(&usr->uni_logon_script, logon_script, len_logon_script);
6095         init_unistr2(&usr->uni_profile_path, profile_path, len_profile_path);
6096         init_unistr2(&usr->uni_acct_desc, description, len_description);
6097         init_unistr2(&usr->uni_workstations, workstations, len_workstations);
6098         init_unistr2(&usr->uni_unknown_str, NULL, len_unknown_str);
6099         init_unistr2(&usr->uni_munged_dial, munged_dial, len_munged_dial);
6100
6101         usr->unknown_6 = pdb_get_unknown_6(pw);
6102         usr->padding4 = 0;
6103
6104         if (pdb_get_hours(pw)) {
6105                 usr->logon_hrs.len = pdb_get_hours_len(pw);
6106                 memcpy(&usr->logon_hrs.hours, pdb_get_hours(pw), MAX_HOURS_LEN);
6107         } else
6108                 memset(&usr->logon_hrs, 0xff, sizeof(usr->logon_hrs));
6109
6110         return NT_STATUS_OK;
6111 }
6112
6113 /*******************************************************************
6114 reads or writes a structure.
6115 ********************************************************************/
6116
6117 static BOOL sam_io_user_info21(char *desc, SAM_USER_INFO_21 * usr,
6118                         prs_struct *ps, int depth)
6119 {
6120         if (usr == NULL)
6121                 return False;
6122
6123         prs_debug(ps, depth, desc, "sam_io_user_info21");
6124         depth++;
6125
6126         if(!prs_align(ps))
6127                 return False;
6128
6129         if(!smb_io_time("logon_time           ", &usr->logon_time, ps, depth))
6130                 return False;
6131         if(!smb_io_time("logoff_time          ", &usr->logoff_time, ps, depth))
6132                 return False;
6133         if(!smb_io_time("pass_last_set_time   ", &usr->pass_last_set_time, ps,depth))
6134                 return False;
6135         if(!smb_io_time("kickoff_time         ", &usr->kickoff_time, ps, depth))
6136                 return False;
6137         if(!smb_io_time("pass_can_change_time ", &usr->pass_can_change_time, ps,depth))
6138                 return False;
6139         if(!smb_io_time("pass_must_change_time", &usr->pass_must_change_time,  ps, depth))
6140                 return False;
6141
6142         if(!smb_io_unihdr("hdr_user_name   ", &usr->hdr_user_name, ps, depth))  /* username unicode string header */
6143                 return False;
6144         if(!smb_io_unihdr("hdr_full_name   ", &usr->hdr_full_name, ps, depth))  /* user's full name unicode string header */
6145                 return False;
6146         if(!smb_io_unihdr("hdr_home_dir    ", &usr->hdr_home_dir, ps, depth))   /* home directory unicode string header */
6147                 return False;
6148         if(!smb_io_unihdr("hdr_dir_drive   ", &usr->hdr_dir_drive, ps, depth))  /* home directory drive */
6149                 return False;
6150         if(!smb_io_unihdr("hdr_logon_script", &usr->hdr_logon_script, ps, depth))       /* logon script unicode string header */
6151                 return False;
6152         if(!smb_io_unihdr("hdr_profile_path", &usr->hdr_profile_path, ps, depth))       /* profile path unicode string header */
6153                 return False;
6154         if(!smb_io_unihdr("hdr_acct_desc   ", &usr->hdr_acct_desc, ps, depth))  /* account desc */
6155                 return False;
6156         if(!smb_io_unihdr("hdr_workstations", &usr->hdr_workstations, ps, depth))       /* wkstas user can log on from */
6157                 return False;
6158         if(!smb_io_unihdr("hdr_unknown_str ", &usr->hdr_unknown_str, ps, depth))        /* unknown string */
6159                 return False;
6160         if(!smb_io_unihdr("hdr_munged_dial ", &usr->hdr_munged_dial, ps, depth))        /* wkstas user can log on from */
6161                 return False;
6162
6163         if(!prs_uint8s(False, "lm_pwd        ", ps, depth, usr->lm_pwd, sizeof(usr->lm_pwd)))
6164                 return False;
6165         if(!prs_uint8s(False, "nt_pwd        ", ps, depth, usr->nt_pwd, sizeof(usr->nt_pwd)))
6166                 return False;
6167
6168         if(!prs_uint32("user_rid      ", ps, depth, &usr->user_rid))    /* User ID */
6169                 return False;
6170         if(!prs_uint32("group_rid     ", ps, depth, &usr->group_rid))   /* Group ID */
6171                 return False;
6172         if(!prs_uint32("acb_info      ", ps, depth, &usr->acb_info))
6173                 return False;
6174
6175         if(!prs_uint32("unknown_3     ", ps, depth, &usr->unknown_3))
6176                 return False;
6177         if(!prs_uint16("logon_divs    ", ps, depth, &usr->logon_divs))  /* logon divisions per week */
6178                 return False;
6179         if(!prs_align(ps))
6180                 return False;
6181         if(!prs_uint32("ptr_logon_hrs ", ps, depth, &usr->ptr_logon_hrs))
6182                 return False;
6183
6184         if(!prs_uint32("unknown_5     ", ps, depth, &usr->unknown_5))
6185                 return False;
6186
6187         if(!prs_uint8s(False, "padding1      ", ps, depth, usr->padding1, sizeof(usr->padding1)))
6188                 return False;
6189         if(!prs_uint8("passmustchange ", ps, depth, &usr->passmustchange))
6190                 return False;
6191         if(!prs_uint8("padding2       ", ps, depth, &usr->padding2))
6192                 return False;
6193
6194         /* here begins pointed-to data */
6195
6196         if(!smb_io_unistr2("uni_user_name   ", &usr->uni_user_name,usr->hdr_user_name.buffer, ps, depth))       /* username unicode string */
6197                 return False;
6198         if(!smb_io_unistr2("uni_full_name   ", &usr->uni_full_name, usr->hdr_full_name.buffer, ps, depth))      /* user's full name unicode string */
6199                 return False;
6200         if(!smb_io_unistr2("uni_home_dir    ", &usr->uni_home_dir, usr->hdr_home_dir.buffer, ps, depth))        /* home directory unicode string */
6201                 return False;
6202         if(!smb_io_unistr2("uni_dir_drive   ", &usr->uni_dir_drive, usr->hdr_dir_drive.buffer, ps, depth))      /* home directory drive unicode string */
6203                 return False;
6204         if(!smb_io_unistr2("uni_logon_script", &usr->uni_logon_script, usr->hdr_logon_script.buffer, ps, depth))        /* logon script unicode string */
6205                 return False;
6206         if(!smb_io_unistr2("uni_profile_path", &usr->uni_profile_path, usr->hdr_profile_path.buffer, ps, depth))        /* profile path unicode string */
6207                 return False;
6208         if(!smb_io_unistr2("uni_acct_desc   ", &usr->uni_acct_desc, usr->hdr_acct_desc.buffer, ps, depth))      /* user desc unicode string */
6209                 return False;
6210         if(!smb_io_unistr2("uni_workstations", &usr->uni_workstations, usr->hdr_workstations.buffer, ps, depth))        /* worksations user can log on from */
6211                 return False;
6212         if(!smb_io_unistr2("uni_unknown_str ", &usr->uni_unknown_str, usr->hdr_unknown_str.buffer, ps, depth))  /* unknown string */
6213                 return False;
6214         if(!smb_io_unistr2("uni_munged_dial ", &usr->uni_munged_dial,usr->hdr_munged_dial.buffer, ps, depth))   /* worksations user can log on from */
6215                 return False;
6216
6217         /* ok, this is only guess-work (as usual) */
6218         if (usr->ptr_logon_hrs) {
6219                 if(!prs_align(ps))
6220                         return False;
6221                 if(!prs_uint32("unknown_6     ", ps, depth, &usr->unknown_6))
6222                         return False;
6223                 if(!prs_uint32("padding4      ", ps, depth, &usr->padding4))
6224                         return False;
6225                 if(!sam_io_logon_hrs("logon_hrs", &usr->logon_hrs, ps, depth))
6226                         return False;
6227         } else if (UNMARSHALLING(ps)) {
6228                 usr->unknown_6 = 0;
6229                 usr->padding4 = 0;
6230         }
6231
6232         return True;
6233 }
6234
6235 void init_sam_user_info20A(SAM_USER_INFO_20 *usr, SAM_ACCOUNT *pw)
6236 {
6237         int             len_munged_dial;
6238         const char*             munged_dial = pdb_get_munged_dial(pw);
6239
6240         len_munged_dial  = munged_dial  != NULL ? strlen(munged_dial )+1 : 0;
6241         init_uni_hdr(&usr->hdr_munged_dial, len_munged_dial);
6242         init_unistr2(&usr->uni_munged_dial, munged_dial, len_munged_dial);
6243
6244 }
6245
6246 /*******************************************************************
6247 reads or writes a structure.
6248 ********************************************************************/
6249
6250 static BOOL sam_io_user_info20(char *desc, SAM_USER_INFO_20 *usr,
6251                         prs_struct *ps, int depth)
6252 {
6253         if (usr == NULL)
6254                 return False;
6255
6256         prs_debug(ps, depth, desc, "sam_io_user_info20");
6257         depth++;
6258
6259         if(!prs_align(ps))
6260                 return False;
6261
6262         if(!smb_io_unihdr("hdr_munged_dial ", &usr->hdr_munged_dial, ps, depth))        /* wkstas user can log on from */
6263                 return False;
6264
6265         if(!smb_io_unistr2("uni_munged_dial ", &usr->uni_munged_dial,usr->hdr_munged_dial.buffer, ps, depth))   /* worksations user can log on from */
6266                 return False;
6267
6268         return True;
6269 }
6270
6271 /*******************************************************************
6272 inits a SAM_USERINFO_CTR structure.
6273 ********************************************************************/
6274
6275 NTSTATUS make_samr_userinfo_ctr_usr21(TALLOC_CTX *ctx, SAM_USERINFO_CTR * ctr,
6276                                     uint16 switch_value,
6277                                     SAM_USER_INFO_21 * usr)
6278 {
6279         DEBUG(5, ("init_samr_userinfo_ctr\n"));
6280
6281         ctr->switch_value = switch_value;
6282         ctr->info.id = NULL;
6283
6284         switch (switch_value) {
6285         case 0x10:
6286                 ctr->info.id10 = (SAM_USER_INFO_10 *)talloc_zero(ctx,sizeof(SAM_USER_INFO_10));
6287                 if (ctr->info.id10 == NULL)
6288                         return NT_STATUS_NO_MEMORY;
6289
6290                 init_sam_user_info10(ctr->info.id10, usr->acb_info);
6291                 break;
6292 #if 0
6293 /* whoops - got this wrong.  i think.  or don't understand what's happening. */
6294         case 0x11:
6295                 {
6296                         NTTIME expire;
6297                         info = (void *)&id11;
6298
6299                         expire.low = 0xffffffff;
6300                         expire.high = 0x7fffffff;
6301
6302                         ctr->info.id = (SAM_USER_INFO_11 *) talloc_zero(ctx,sizeof(*ctr->info.id11));
6303                         init_sam_user_info11(ctr->info.id11, &expire,
6304                                              "BROOKFIELDS$",    /* name */
6305                                              0x03ef,    /* user rid */
6306                                              0x201,     /* group rid */
6307                                              0x0080);   /* acb info */
6308
6309                         break;
6310                 }
6311 #endif
6312         case 0x12:
6313                 ctr->info.id12 = (SAM_USER_INFO_12 *)talloc_zero(ctx,sizeof(SAM_USER_INFO_12));
6314                 if (ctr->info.id12 == NULL)
6315                         return NT_STATUS_NO_MEMORY;
6316
6317                 init_sam_user_info12(ctr->info.id12, usr->lm_pwd, usr->nt_pwd);
6318                 break;
6319         case 21:
6320                 {
6321                         SAM_USER_INFO_21 *cusr;
6322                         cusr = (SAM_USER_INFO_21 *)talloc_zero(ctx,sizeof(SAM_USER_INFO_21));
6323                         ctr->info.id21 = cusr;
6324                         if (ctr->info.id21 == NULL)
6325                                 return NT_STATUS_NO_MEMORY;
6326                         memcpy(cusr, usr, sizeof(*usr));
6327                         memset(cusr->lm_pwd, 0, sizeof(cusr->lm_pwd));
6328                         memset(cusr->nt_pwd, 0, sizeof(cusr->nt_pwd));
6329                         break;
6330                 }
6331         default:
6332                 DEBUG(4,("make_samr_userinfo_ctr: unsupported info\n"));
6333                 return NT_STATUS_INVALID_INFO_CLASS;
6334         }
6335
6336         return NT_STATUS_OK;
6337 }
6338
6339 /*******************************************************************
6340 inits a SAM_USERINFO_CTR structure.
6341 ********************************************************************/
6342
6343 void init_samr_userinfo_ctr(SAM_USERINFO_CTR * ctr, uchar * sess_key,
6344                             uint16 switch_value, void *info)
6345 {
6346         DEBUG(5, ("init_samr_userinfo_ctr\n"));
6347
6348         ctr->switch_value = switch_value;
6349         ctr->info.id = info;
6350
6351         switch (switch_value) {
6352         case 0x18:
6353                 SamOEMhash(ctr->info.id24->pass, sess_key, 516);
6354                 dump_data(100, (char *)sess_key, 16);
6355                 dump_data(100, (char *)ctr->info.id24->pass, 516);
6356                 break;
6357         case 0x17:
6358                 SamOEMhash(ctr->info.id23->pass, sess_key, 516);
6359                 dump_data(100, (char *)sess_key, 16);
6360                 dump_data(100, (char *)ctr->info.id23->pass, 516);
6361                 break;
6362         default:
6363                 DEBUG(4,("init_samr_userinfo_ctr: unsupported switch level\n"));
6364         }
6365 }
6366
6367 /*******************************************************************
6368 reads or writes a structure.
6369 ********************************************************************/
6370
6371 static BOOL samr_io_userinfo_ctr(char *desc, SAM_USERINFO_CTR **ppctr,
6372                                  prs_struct *ps, int depth)
6373 {
6374         BOOL ret;
6375         SAM_USERINFO_CTR *ctr;
6376
6377         prs_debug(ps, depth, desc, "samr_io_userinfo_ctr");
6378         depth++;
6379
6380         if (UNMARSHALLING(ps)) {
6381                 ctr = (SAM_USERINFO_CTR *)prs_alloc_mem(ps,sizeof(SAM_USERINFO_CTR));
6382                 if (ctr == NULL)
6383                         return False;
6384                 *ppctr = ctr;
6385         } else {
6386                 ctr = *ppctr;
6387         }
6388
6389         /* lkclXXXX DO NOT ALIGN BEFORE READING SWITCH VALUE! */
6390
6391         if(!prs_uint16("switch_value", ps, depth, &ctr->switch_value))
6392                 return False;
6393         if(!prs_align(ps))
6394                 return False;
6395
6396         ret = False;
6397
6398         switch (ctr->switch_value) {
6399         case 0x10:
6400                 if (UNMARSHALLING(ps))
6401                         ctr->info.id10 = (SAM_USER_INFO_10 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_10));
6402                 if (ctr->info.id10 == NULL) {
6403                         DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6404                         return False;
6405                 }
6406                 ret = sam_io_user_info10("", ctr->info.id10, ps, depth);
6407                 break;
6408         case 0x11:
6409                 if (UNMARSHALLING(ps))
6410                         ctr->info.id11 = (SAM_USER_INFO_11 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_11));
6411
6412                 if (ctr->info.id11 == NULL) {
6413                         DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6414                         return False;
6415                 }
6416                 ret = sam_io_user_info11("", ctr->info.id11, ps, depth);
6417                 break;
6418         case 0x12:
6419                 if (UNMARSHALLING(ps))
6420                         ctr->info.id12 = (SAM_USER_INFO_12 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_12));
6421
6422                 if (ctr->info.id12 == NULL) {
6423                         DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6424                         return False;
6425                 }
6426                 ret = sam_io_user_info12("", ctr->info.id12, ps, depth);
6427                 break;
6428         case 20:
6429                 if (UNMARSHALLING(ps))
6430                         ctr->info.id20 = (SAM_USER_INFO_20 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_20));
6431
6432                 if (ctr->info.id20 == NULL) {
6433                         DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6434                         return False;
6435                 }
6436                 ret = sam_io_user_info20("", ctr->info.id20, ps, depth);
6437                 break;
6438         case 21:
6439                 if (UNMARSHALLING(ps))
6440                         ctr->info.id21 = (SAM_USER_INFO_21 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_21));
6441
6442                 if (ctr->info.id21 == NULL) {
6443                         DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6444                         return False;
6445                 }
6446                 ret = sam_io_user_info21("", ctr->info.id21, ps, depth);
6447                 break;
6448         case 23:
6449                 if (UNMARSHALLING(ps))
6450                         ctr->info.id23 = (SAM_USER_INFO_23 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_23));
6451
6452                 if (ctr->info.id23 == NULL) {
6453                         DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6454                         return False;
6455                 }
6456                 ret = sam_io_user_info23("", ctr->info.id23, ps, depth);
6457                 break;
6458         case 24:
6459                 if (UNMARSHALLING(ps))
6460                         ctr->info.id24 = (SAM_USER_INFO_24 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_24));
6461
6462                 if (ctr->info.id24 == NULL) {
6463                         DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6464                         return False;
6465                 }
6466                 ret = sam_io_user_info24("", ctr->info.id24, ps,  depth);
6467                 break;
6468         case 25:
6469                 if (UNMARSHALLING(ps))
6470                         ctr->info.id25 = (SAM_USER_INFO_25 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_25));
6471
6472                 if (ctr->info.id25 == NULL) {
6473                         DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
6474                         return False;
6475                 }
6476                 ret = sam_io_user_info25("", ctr->info.id25, ps, depth);
6477                 break;
6478         default:
6479                 DEBUG(2, ("samr_io_userinfo_ctr: unknown switch level 0x%x\n", ctr->switch_value));
6480                 ret = False;
6481                 break;
6482         }
6483
6484         return ret;
6485 }
6486
6487 /*******************************************************************
6488 inits a SAMR_R_QUERY_USERINFO structure.
6489 ********************************************************************/
6490
6491 void init_samr_r_query_userinfo(SAMR_R_QUERY_USERINFO * r_u,
6492                                 SAM_USERINFO_CTR * ctr, NTSTATUS status)
6493 {
6494         DEBUG(5, ("init_samr_r_query_userinfo\n"));
6495
6496         r_u->ptr = 0;
6497         r_u->ctr = NULL;
6498
6499         if (NT_STATUS_IS_OK(status)) {
6500                 r_u->ptr = 1;
6501                 r_u->ctr = ctr;
6502         }
6503
6504         r_u->status = status;   /* return status */
6505 }
6506
6507 /*******************************************************************
6508 reads or writes a structure.
6509 ********************************************************************/
6510
6511 BOOL samr_io_r_query_userinfo(char *desc, SAMR_R_QUERY_USERINFO * r_u,
6512                               prs_struct *ps, int depth)
6513 {
6514         if (r_u == NULL)
6515                 return False;
6516
6517         prs_debug(ps, depth, desc, "samr_io_r_query_userinfo");
6518         depth++;
6519
6520         if(!prs_align(ps))
6521                 return False;
6522
6523         if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
6524                 return False;
6525
6526         if (r_u->ptr != 0) {
6527                 if(!samr_io_userinfo_ctr("ctr", &r_u->ctr, ps, depth))
6528                         return False;
6529         }
6530
6531         if(!prs_align(ps))
6532                 return False;
6533         if(!prs_ntstatus("status", ps, depth, &r_u->status))
6534                 return False;
6535
6536         return True;
6537 }
6538
6539 /*******************************************************************
6540 inits a SAMR_Q_SET_USERINFO structure.
6541 ********************************************************************/
6542
6543 void init_samr_q_set_userinfo(SAMR_Q_SET_USERINFO * q_u,
6544                               POLICY_HND *hnd,  unsigned char sess_key[16],
6545                               uint16 switch_value, void *info)
6546 {
6547         DEBUG(5, ("init_samr_q_set_userinfo\n"));
6548
6549         q_u->pol = *hnd;
6550         q_u->switch_value = switch_value;
6551         init_samr_userinfo_ctr(q_u->ctr, sess_key, switch_value, info);
6552 }
6553
6554 /*******************************************************************
6555 reads or writes a structure.
6556 ********************************************************************/
6557
6558 BOOL samr_io_q_set_userinfo(char *desc, SAMR_Q_SET_USERINFO * q_u,
6559                             prs_struct *ps, int depth)
6560 {
6561         if (q_u == NULL)
6562                 return False;
6563
6564         prs_debug(ps, depth, desc, "samr_io_q_set_userinfo");
6565         depth++;
6566
6567         if(!prs_align(ps))
6568                 return False;
6569
6570         smb_io_pol_hnd("pol", &(q_u->pol), ps, depth);
6571
6572         if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
6573                 return False;
6574         if(!samr_io_userinfo_ctr("ctr", &q_u->ctr, ps, depth))
6575                 return False;
6576
6577         return True;
6578 }
6579
6580 /*******************************************************************
6581 inits a SAMR_R_SET_USERINFO structure.
6582 ********************************************************************/
6583
6584 void init_samr_r_set_userinfo(SAMR_R_SET_USERINFO * r_u, NTSTATUS status)
6585 {
6586         DEBUG(5, ("init_samr_r_set_userinfo\n"));
6587
6588         r_u->status = status;   /* return status */
6589 }
6590
6591 /*******************************************************************
6592 reads or writes a structure.
6593 ********************************************************************/
6594
6595 BOOL samr_io_r_set_userinfo(char *desc, SAMR_R_SET_USERINFO * r_u,
6596                             prs_struct *ps, int depth)
6597 {
6598         if (r_u == NULL)
6599                 return False;
6600
6601         prs_debug(ps, depth, desc, "samr_io_r_set_userinfo");
6602         depth++;
6603
6604         if(!prs_align(ps))
6605                 return False;
6606
6607         if(!prs_ntstatus("status", ps, depth, &r_u->status))
6608                 return False;
6609
6610         return True;
6611 }
6612
6613 /*******************************************************************
6614 inits a SAMR_Q_SET_USERINFO2 structure.
6615 ********************************************************************/
6616
6617 void init_samr_q_set_userinfo2(SAMR_Q_SET_USERINFO2 * q_u,
6618                                POLICY_HND *hnd, unsigned char sess_key[16],
6619                                uint16 switch_value, SAM_USERINFO_CTR * ctr)
6620 {
6621         DEBUG(5, ("init_samr_q_set_userinfo2\n"));
6622
6623         q_u->pol = *hnd;
6624         q_u->switch_value = switch_value;
6625         q_u->ctr = ctr;
6626
6627         if (q_u->ctr != NULL)
6628                 q_u->ctr->switch_value = switch_value;
6629
6630         switch (switch_value) {
6631         case 0x12:
6632                 SamOEMhash(ctr->info.id12->lm_pwd, sess_key, 16);
6633                 SamOEMhash(ctr->info.id12->nt_pwd, sess_key, 16);
6634                 dump_data(100, (char *)sess_key, 16);
6635                 dump_data(100, (char *)ctr->info.id12->lm_pwd, 16);
6636                 dump_data(100, (char *)ctr->info.id12->nt_pwd, 16);
6637                 break;
6638         }
6639 }
6640
6641 /*******************************************************************
6642 reads or writes a structure.
6643 ********************************************************************/
6644
6645 BOOL samr_io_q_set_userinfo2(char *desc, SAMR_Q_SET_USERINFO2 * q_u,
6646                              prs_struct *ps, int depth)
6647 {
6648         if (q_u == NULL)
6649                 return False;
6650
6651         prs_debug(ps, depth, desc, "samr_io_q_set_userinfo2");
6652         depth++;
6653
6654         if(!prs_align(ps))
6655                 return False;
6656
6657         if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
6658                 return False;
6659
6660         if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
6661                 return False;
6662         if(!samr_io_userinfo_ctr("ctr", &q_u->ctr, ps, depth))
6663                 return False;
6664
6665         return True;
6666 }
6667
6668 /*******************************************************************
6669 inits a SAMR_R_SET_USERINFO2 structure.
6670 ********************************************************************/
6671
6672 void init_samr_r_set_userinfo2(SAMR_R_SET_USERINFO2 * r_u, NTSTATUS status)
6673 {
6674         DEBUG(5, ("init_samr_r_set_userinfo2\n"));
6675
6676         r_u->status = status;   /* return status */
6677 }
6678
6679 /*******************************************************************
6680 reads or writes a structure.
6681 ********************************************************************/
6682
6683 BOOL samr_io_r_set_userinfo2(char *desc, SAMR_R_SET_USERINFO2 * r_u,
6684                              prs_struct *ps, int depth)
6685 {
6686         if (r_u == NULL)
6687                 return False;
6688
6689         prs_debug(ps, depth, desc, "samr_io_r_set_userinfo2");
6690         depth++;
6691
6692         if(!prs_align(ps))
6693                 return False;
6694
6695         if(!prs_ntstatus("status", ps, depth, &r_u->status))
6696                 return False;
6697
6698         return True;
6699 }
6700
6701 /*******************************************************************
6702 inits a SAMR_Q_CONNECT structure.
6703 ********************************************************************/
6704
6705 void init_samr_q_connect(SAMR_Q_CONNECT * q_u,
6706                          char *srv_name, uint32 access_mask)
6707 {
6708         int len_srv_name = strlen(srv_name);
6709
6710         DEBUG(5, ("init_samr_q_connect\n"));
6711
6712         /* make PDC server name \\server */
6713         q_u->ptr_srv_name = len_srv_name > 0 ? 1 : 0;
6714         init_unistr2(&q_u->uni_srv_name, srv_name, len_srv_name + 1);
6715
6716         /* example values: 0x0000 0002 */
6717         q_u->access_mask = access_mask;
6718 }
6719
6720 /*******************************************************************
6721 reads or writes a structure.
6722 ********************************************************************/
6723
6724 BOOL samr_io_q_connect(char *desc, SAMR_Q_CONNECT * q_u,
6725                        prs_struct *ps, int depth)
6726 {
6727         if (q_u == NULL)
6728                 return False;
6729
6730         prs_debug(ps, depth, desc, "samr_io_q_connect");
6731         depth++;
6732
6733         if(!prs_align(ps))
6734                 return False;
6735
6736         if(!prs_uint32("ptr_srv_name", ps, depth, &q_u->ptr_srv_name))
6737                 return False;
6738         if(!smb_io_unistr2("", &q_u->uni_srv_name, q_u->ptr_srv_name, ps, depth))
6739                 return False;
6740
6741         if(!prs_align(ps))
6742                 return False;
6743         if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
6744                 return False;
6745
6746         return True;
6747 }
6748
6749 /*******************************************************************
6750 reads or writes a structure.
6751 ********************************************************************/
6752
6753 BOOL samr_io_r_connect(char *desc, SAMR_R_CONNECT * r_u,
6754                        prs_struct *ps, int depth)
6755 {
6756         if (r_u == NULL)
6757                 return False;
6758
6759         prs_debug(ps, depth, desc, "samr_io_r_connect");
6760         depth++;
6761
6762         if(!prs_align(ps))
6763                 return False;
6764
6765         if(!smb_io_pol_hnd("connect_pol", &r_u->connect_pol, ps, depth))
6766                 return False;
6767
6768         if(!prs_ntstatus("status", ps, depth, &r_u->status))
6769                 return False;
6770
6771         return True;
6772 }
6773
6774 /*******************************************************************
6775 inits a SAMR_Q_CONNECT4 structure.
6776 ********************************************************************/
6777
6778 void init_samr_q_connect4(SAMR_Q_CONNECT4 * q_u,
6779                           char *srv_name, uint32 access_mask)
6780 {
6781         int len_srv_name = strlen(srv_name);
6782
6783         DEBUG(5, ("init_samr_q_connect\n"));
6784
6785         /* make PDC server name \\server */
6786         q_u->ptr_srv_name = len_srv_name > 0 ? 1 : 0;
6787         init_unistr2(&q_u->uni_srv_name, srv_name, len_srv_name + 1);
6788
6789         /* Only value we've seen, possibly an address type ? */
6790         q_u->unk_0 = 2;
6791
6792         /* example values: 0x0000 0002 */
6793         q_u->access_mask = access_mask;
6794 }
6795
6796 /*******************************************************************
6797 reads or writes a structure.
6798 ********************************************************************/
6799
6800 BOOL samr_io_q_connect4(char *desc, SAMR_Q_CONNECT4 * q_u,
6801                         prs_struct *ps, int depth)
6802 {
6803         if (q_u == NULL)
6804                 return False;
6805
6806         prs_debug(ps, depth, desc, "samr_io_q_connect4");
6807         depth++;
6808
6809         if(!prs_align(ps))
6810                 return False;
6811
6812         if(!prs_uint32("ptr_srv_name", ps, depth, &q_u->ptr_srv_name))
6813                 return False;
6814         if(!smb_io_unistr2("", &q_u->uni_srv_name, q_u->ptr_srv_name, ps, depth))
6815                 return False;
6816
6817         if(!prs_align(ps))
6818                 return False;
6819         if(!prs_uint32("unk_0", ps, depth, &q_u->unk_0))
6820                 return False;
6821         if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
6822                 return False;
6823
6824         return True;
6825 }
6826
6827 /*******************************************************************
6828 reads or writes a structure.
6829 ********************************************************************/
6830
6831 BOOL samr_io_r_connect4(char *desc, SAMR_R_CONNECT4 * r_u,
6832                         prs_struct *ps, int depth)
6833 {
6834         if (r_u == NULL)
6835                 return False;
6836
6837         prs_debug(ps, depth, desc, "samr_io_r_connect4");
6838         depth++;
6839
6840         if(!prs_align(ps))
6841                 return False;
6842
6843         if(!smb_io_pol_hnd("connect_pol", &r_u->connect_pol, ps, depth))
6844                 return False;
6845
6846         if(!prs_ntstatus("status", ps, depth, &r_u->status))
6847                 return False;
6848
6849         return True;
6850 }
6851
6852 /*******************************************************************
6853 inits a SAMR_Q_CONNECT_ANON structure.
6854 ********************************************************************/
6855
6856 void init_samr_q_connect_anon(SAMR_Q_CONNECT_ANON * q_u)
6857 {
6858         DEBUG(5, ("init_samr_q_connect_anon\n"));
6859
6860         q_u->ptr = 1;
6861         q_u->unknown_0 = 0x5c;  /* server name (?!!) */
6862         q_u->unknown_1 = 0x01;
6863         q_u->access_mask = 0x20;
6864 }
6865
6866 /*******************************************************************
6867 reads or writes a structure.
6868 ********************************************************************/
6869
6870 BOOL samr_io_q_connect_anon(char *desc, SAMR_Q_CONNECT_ANON * q_u,
6871                             prs_struct *ps, int depth)
6872 {
6873         if (q_u == NULL)
6874                 return False;
6875
6876         prs_debug(ps, depth, desc, "samr_io_q_connect_anon");
6877         depth++;
6878
6879         if(!prs_align(ps))
6880                 return False;
6881
6882         if(!prs_uint32("ptr      ", ps, depth, &q_u->ptr))
6883                 return False;
6884         if(!prs_uint16("unknown_0", ps, depth, &q_u->unknown_0))
6885                 return False;
6886         if(!prs_uint16("unknown_1", ps, depth, &q_u->unknown_1))
6887                 return False;
6888         if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
6889                 return False;
6890
6891         return True;
6892 }
6893
6894 /*******************************************************************
6895 reads or writes a structure.
6896 ********************************************************************/
6897
6898 BOOL samr_io_r_connect_anon(char *desc, SAMR_R_CONNECT_ANON * r_u,
6899                             prs_struct *ps, int depth)
6900 {
6901         if (r_u == NULL)
6902                 return False;
6903
6904         prs_debug(ps, depth, desc, "samr_io_r_connect_anon");
6905         depth++;
6906
6907         if(!prs_align(ps))
6908                 return False;
6909
6910         if(!smb_io_pol_hnd("connect_pol", &r_u->connect_pol, ps, depth))
6911                 return False;
6912
6913         if(!prs_ntstatus("status", ps, depth, &r_u->status))
6914                 return False;
6915
6916         return True;
6917 }
6918
6919 /*******************************************************************
6920 inits a SAMR_Q_GET_DOM_PWINFO structure.
6921 ********************************************************************/
6922
6923 void init_samr_q_get_dom_pwinfo(SAMR_Q_GET_DOM_PWINFO * q_u,
6924                                 char *srv_name)
6925 {
6926         int len_srv_name = strlen(srv_name);
6927
6928         DEBUG(5, ("init_samr_q_get_dom_pwinfo\n"));
6929
6930         q_u->ptr = 1;
6931         init_uni_hdr(&q_u->hdr_srv_name, len_srv_name);
6932         init_unistr2(&q_u->uni_srv_name, srv_name, len_srv_name);
6933 }
6934
6935 /*******************************************************************
6936 reads or writes a structure.
6937 ********************************************************************/
6938
6939 BOOL samr_io_q_get_dom_pwinfo(char *desc, SAMR_Q_GET_DOM_PWINFO * q_u,
6940                               prs_struct *ps, int depth)
6941 {
6942         if (q_u == NULL)
6943                 return False;
6944
6945         prs_debug(ps, depth, desc, "samr_io_q_get_dom_pwinfo");
6946         depth++;
6947
6948         if(!prs_align(ps))
6949                 return False;
6950
6951         if(!prs_uint32("ptr", ps, depth, &q_u->ptr))
6952                 return False;
6953         if (q_u->ptr != 0) {
6954                 if(!smb_io_unihdr("", &q_u->hdr_srv_name, ps, depth))
6955                         return False;
6956                 if(!smb_io_unistr2("", &q_u->uni_srv_name, q_u->hdr_srv_name.buffer, ps, depth))
6957                         return False;
6958         }
6959
6960         return True;
6961 }
6962
6963 /*******************************************************************
6964 reads or writes a structure.
6965 ********************************************************************/
6966
6967 BOOL samr_io_r_get_dom_pwinfo(char *desc, SAMR_R_GET_DOM_PWINFO * r_u,
6968                               prs_struct *ps, int depth)
6969 {
6970         if (r_u == NULL)
6971                 return False;
6972
6973         prs_debug(ps, depth, desc, "samr_io_r_get_dom_pwinfo");
6974         depth++;
6975
6976         if(!prs_align(ps))
6977                 return False;
6978
6979         /*
6980          * We need 16 bytes here according to tests.  Don't know
6981          * what they are, but the length is important for the singing
6982         */
6983
6984         if(!prs_uint32("unk_0", ps, depth, &r_u->unk_0))
6985                 return False;
6986         if(!prs_uint32("unk_1", ps, depth, &r_u->unk_1))
6987                 return False;
6988         if(!prs_uint32("unk_2", ps, depth, &r_u->unk_2))
6989                 return False;
6990
6991         if(!prs_ntstatus("status", ps, depth, &r_u->status))
6992                 return False;
6993
6994         return True;
6995 }
6996
6997 /*******************************************************************
6998 make a SAMR_ENC_PASSWD structure.
6999 ********************************************************************/
7000
7001 void init_enc_passwd(SAMR_ENC_PASSWD * pwd, char pass[512])
7002 {
7003         ZERO_STRUCTP(pwd);
7004
7005         if (pass == NULL) {
7006                 pwd->ptr = 0;
7007         } else {
7008                 pwd->ptr = 1;
7009                 memcpy(pwd->pass, pass, sizeof(pwd->pass));
7010         }
7011 }
7012
7013 /*******************************************************************
7014 reads or writes a SAMR_ENC_PASSWD structure.
7015 ********************************************************************/
7016
7017 BOOL samr_io_enc_passwd(char *desc, SAMR_ENC_PASSWD * pwd,
7018                         prs_struct *ps, int depth)
7019 {
7020         if (pwd == NULL)
7021                 return False;
7022
7023         prs_debug(ps, depth, desc, "samr_io_enc_passwd");
7024         depth++;
7025
7026         if(!prs_align(ps))
7027                 return False;
7028
7029         if(!prs_uint32("ptr", ps, depth, &pwd->ptr))
7030                 return False;
7031
7032         if (pwd->ptr != 0) {
7033                 if(!prs_uint8s(False, "pwd", ps, depth, pwd->pass, sizeof(pwd->pass)))
7034                         return False;
7035         }
7036
7037         return True;
7038 }
7039
7040 /*******************************************************************
7041 inits a SAMR_ENC_HASH structure.
7042 ********************************************************************/
7043
7044 void init_enc_hash(SAMR_ENC_HASH * hsh, uchar hash[16])
7045 {
7046         ZERO_STRUCTP(hsh);
7047
7048         if (hash == NULL) {
7049                 hsh->ptr = 0;
7050         } else {
7051                 hsh->ptr = 1;
7052                 memcpy(hsh->hash, hash, sizeof(hsh->hash));
7053         }
7054 }
7055
7056 /*******************************************************************
7057 reads or writes a SAMR_ENC_HASH structure.
7058 ********************************************************************/
7059
7060 BOOL samr_io_enc_hash(char *desc, SAMR_ENC_HASH * hsh,
7061                       prs_struct *ps, int depth)
7062 {
7063         if (hsh == NULL)
7064                 return False;
7065
7066         prs_debug(ps, depth, desc, "samr_io_enc_hash");
7067         depth++;
7068
7069         if(!prs_align(ps))
7070                 return False;
7071
7072         if(!prs_uint32("ptr ", ps, depth, &hsh->ptr))
7073                 return False;
7074         if (hsh->ptr != 0) {
7075                 if(!prs_uint8s(False, "hash", ps, depth, hsh->hash,sizeof(hsh->hash)))
7076                         return False;
7077         }
7078
7079         return True;
7080 }
7081
7082 /*******************************************************************
7083 inits a SAMR_R_GET_DOM_PWINFO structure.
7084 ********************************************************************/
7085
7086 void init_samr_q_chgpasswd_user(SAMR_Q_CHGPASSWD_USER * q_u,
7087                                 char *dest_host, char *user_name,
7088                                 char nt_newpass[516],
7089                                 uchar nt_oldhash[16],
7090                                 char lm_newpass[516],
7091                                 uchar lm_oldhash[16])
7092 {
7093         int len_dest_host = strlen(dest_host);
7094         int len_user_name = strlen(user_name);
7095
7096         DEBUG(5, ("init_samr_q_chgpasswd_user\n"));
7097
7098         q_u->ptr_0 = 1;
7099         init_uni_hdr(&q_u->hdr_dest_host, len_dest_host);
7100         init_unistr2(&q_u->uni_dest_host, dest_host, len_dest_host);
7101         init_uni_hdr(&q_u->hdr_user_name, len_user_name);
7102         init_unistr2(&q_u->uni_user_name, user_name, len_user_name);
7103
7104         init_enc_passwd(&q_u->nt_newpass, nt_newpass);
7105         init_enc_hash(&q_u->nt_oldhash, nt_oldhash);
7106
7107         q_u->unknown = 0x01;
7108
7109         init_enc_passwd(&q_u->lm_newpass, lm_newpass);
7110         init_enc_hash(&q_u->lm_oldhash, lm_oldhash);
7111 }
7112
7113 /*******************************************************************
7114 reads or writes a structure.
7115 ********************************************************************/
7116
7117 BOOL samr_io_q_chgpasswd_user(char *desc, SAMR_Q_CHGPASSWD_USER * q_u,
7118                               prs_struct *ps, int depth)
7119 {
7120         if (q_u == NULL)
7121                 return False;
7122
7123         prs_debug(ps, depth, desc, "samr_io_q_chgpasswd_user");
7124         depth++;
7125
7126         if(!prs_align(ps))
7127                 return False;
7128
7129         if(!prs_uint32("ptr_0", ps, depth, &q_u->ptr_0))
7130                 return False;
7131
7132         if(!smb_io_unihdr("", &q_u->hdr_dest_host, ps, depth))
7133                 return False;
7134         if(!smb_io_unistr2("", &q_u->uni_dest_host, q_u->hdr_dest_host.buffer, ps, depth))
7135                 return False;
7136
7137         if(!prs_align(ps))
7138                 return False;
7139         if(!smb_io_unihdr("", &q_u->hdr_user_name, ps, depth))
7140                 return False;
7141         if(!smb_io_unistr2("", &q_u->uni_user_name, q_u->hdr_user_name.buffer,ps, depth))
7142                 return False;
7143
7144         if(!samr_io_enc_passwd("nt_newpass", &q_u->nt_newpass, ps, depth))
7145                 return False;
7146         if(!samr_io_enc_hash("nt_oldhash", &q_u->nt_oldhash, ps, depth))
7147                 return False;
7148
7149         if(!prs_uint32("unknown", ps, depth, &q_u->unknown))
7150                 return False;
7151
7152         if(!samr_io_enc_passwd("lm_newpass", &q_u->lm_newpass, ps, depth))
7153                 return False;
7154         if(!samr_io_enc_hash("lm_oldhash", &q_u->lm_oldhash, ps, depth))
7155                 return False;
7156
7157         return True;
7158 }
7159
7160 /*******************************************************************
7161 inits a SAMR_R_CHGPASSWD_USER structure.
7162 ********************************************************************/
7163
7164 void init_samr_r_chgpasswd_user(SAMR_R_CHGPASSWD_USER * r_u, NTSTATUS status)
7165 {
7166         DEBUG(5, ("init_r_chgpasswd_user\n"));
7167
7168         r_u->status = status;
7169 }
7170
7171 /*******************************************************************
7172 reads or writes a structure.
7173 ********************************************************************/
7174
7175 BOOL samr_io_r_chgpasswd_user(char *desc, SAMR_R_CHGPASSWD_USER * r_u,
7176                               prs_struct *ps, int depth)
7177 {
7178         if (r_u == NULL)
7179                 return False;
7180
7181         prs_debug(ps, depth, desc, "samr_io_r_chgpasswd_user");
7182         depth++;
7183
7184         if(!prs_align(ps))
7185                 return False;
7186
7187         if(!prs_ntstatus("status", ps, depth, &r_u->status))
7188                 return False;
7189
7190         return True;
7191 }
7192
7193 /*******************************************************************
7194 reads or writes a structure.
7195 ********************************************************************/
7196
7197 void init_samr_q_unknown_2e(SAMR_Q_UNKNOWN_2E *q_u,
7198                                 POLICY_HND *domain_pol, uint16 switch_value)
7199 {
7200         DEBUG(5, ("init_samr_q_unknown_2e\n"));
7201
7202         q_u->domain_pol = *domain_pol;
7203         q_u->switch_value = switch_value;
7204 }
7205
7206 /*******************************************************************
7207 reads or writes a structure.
7208 ********************************************************************/
7209
7210 BOOL samr_io_q_unknown_2e(char *desc, SAMR_Q_UNKNOWN_2E *q_u,
7211                               prs_struct *ps, int depth)
7212 {
7213         if (q_u == NULL)
7214                 return False;
7215
7216         prs_debug(ps, depth, desc, "samr_io_q_unknown_2e");
7217         depth++;
7218
7219         if(!prs_align(ps))
7220                 return False;
7221
7222         if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
7223                 return False;
7224
7225         if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
7226                 return False;
7227
7228         return True;
7229 }
7230
7231 /*******************************************************************
7232 inits a SAMR_R_QUERY_DOMAIN_INFO structure.
7233 ********************************************************************/
7234
7235 void init_samr_r_samr_unknown_2e(SAMR_R_UNKNOWN_2E * r_u,
7236                                 uint16 switch_value, SAM_UNK_CTR * ctr,
7237                                 NTSTATUS status)
7238 {
7239         DEBUG(5, ("init_samr_r_samr_unknown_2e\n"));
7240
7241         r_u->ptr_0 = 0;
7242         r_u->switch_value = 0;
7243         r_u->status = status;   /* return status */
7244
7245         if (NT_STATUS_IS_OK(status)) {
7246                 r_u->switch_value = switch_value;
7247                 r_u->ptr_0 = 1;
7248                 r_u->ctr = ctr;
7249         }
7250 }
7251
7252 /*******************************************************************
7253 reads or writes a structure.
7254 ********************************************************************/
7255
7256 BOOL samr_io_r_samr_unknown_2e(char *desc, SAMR_R_UNKNOWN_2E * r_u,
7257                               prs_struct *ps, int depth)
7258 {
7259         if (r_u == NULL)
7260                 return False;
7261
7262         prs_debug(ps, depth, desc, "samr_io_r_samr_unknown_2e");
7263         depth++;
7264
7265         if(!prs_align(ps))
7266                 return False;
7267
7268         if(!prs_uint32("ptr_0 ", ps, depth, &r_u->ptr_0))
7269                 return False;
7270
7271         if (r_u->ptr_0 != 0 && r_u->ctr != NULL) {
7272                 if(!prs_uint16("switch_value", ps, depth, &r_u->switch_value))
7273                         return False;
7274                 if(!prs_align(ps))
7275                         return False;
7276
7277                 switch (r_u->switch_value) {
7278                 case 0x0c:
7279                         if(!sam_io_unk_info12("unk_inf12", &r_u->ctr->info.inf12, ps, depth))
7280                                 return False;
7281                         break;
7282                 case 0x07:
7283                         if(!sam_io_unk_info7("unk_inf7",&r_u->ctr->info.inf7, ps,depth))
7284                                 return False;
7285                         break;
7286                 case 0x06:
7287                         if(!sam_io_unk_info6("unk_inf6",&r_u->ctr->info.inf6, ps,depth))
7288                                 return False;
7289                         break;
7290                 case 0x05:
7291                         if(!sam_io_unk_info5("unk_inf5",&r_u->ctr->info.inf5, ps,depth))
7292                                 return False;
7293                         break;
7294                 case 0x03:
7295                         if(!sam_io_unk_info3("unk_inf3",&r_u->ctr->info.inf3, ps,depth))
7296                                 return False;
7297                         break;
7298                 case 0x02:
7299                         if(!sam_io_unk_info2("unk_inf2",&r_u->ctr->info.inf2, ps,depth))
7300                                 return False;
7301                         break;
7302                 case 0x01:
7303                         if(!sam_io_unk_info1("unk_inf1",&r_u->ctr->info.inf1, ps,depth))
7304                                 return False;
7305                         break;
7306                 default:
7307                         DEBUG(0, ("samr_io_r_samr_unknown_2e: unknown switch level 0x%x\n",
7308                                 r_u->switch_value));
7309                         r_u->status = NT_STATUS_INVALID_INFO_CLASS;
7310                         return False;
7311                 }
7312         }
7313         
7314         if(!prs_align(ps))
7315                 return False;
7316
7317         if(!prs_ntstatus("status", ps, depth, &r_u->status))
7318                 return False;
7319         
7320         return True;
7321 }
7322
7323
7324 /*******************************************************************
7325 reads or writes a structure.
7326 ********************************************************************/
7327
7328 void init_samr_q_set_domain_info(SAMR_Q_SET_DOMAIN_INFO *q_u,
7329                                 POLICY_HND *domain_pol, uint16 switch_value, SAM_UNK_CTR *ctr)
7330 {
7331         DEBUG(5, ("init_samr_q_set_domain_info\n"));
7332
7333         q_u->domain_pol = *domain_pol;
7334         q_u->switch_value0 = switch_value;
7335
7336         q_u->switch_value = switch_value;
7337         q_u->ctr = ctr;
7338         
7339 }
7340
7341 /*******************************************************************
7342 reads or writes a structure.
7343 ********************************************************************/
7344
7345 BOOL samr_io_q_set_domain_info(char *desc, SAMR_Q_SET_DOMAIN_INFO *q_u,
7346                               prs_struct *ps, int depth)
7347 {
7348         if (q_u == NULL)
7349                 return False;
7350
7351         prs_debug(ps, depth, desc, "samr_io_q_set_domain_info");
7352         depth++;
7353
7354         if(!prs_align(ps))
7355                 return False;
7356
7357         if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
7358                 return False;
7359
7360         if(!prs_uint16("switch_value0", ps, depth, &q_u->switch_value0))
7361                 return False;
7362
7363         if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
7364                 return False;
7365
7366         if(!prs_align(ps))
7367                 return False;
7368
7369         if ((q_u->ctr = (SAM_UNK_CTR *)prs_alloc_mem(ps, sizeof(SAM_UNK_CTR))) == NULL)
7370                 return False;
7371         
7372         switch (q_u->switch_value) {
7373
7374         case 0x0c:
7375                 if(!sam_io_unk_info12("unk_inf12", &q_u->ctr->info.inf12, ps, depth))
7376                         return False;
7377                 break;
7378         case 0x07:
7379                 if(!sam_io_unk_info7("unk_inf7",&q_u->ctr->info.inf7, ps,depth))
7380                         return False;
7381                 break;
7382         case 0x06:
7383                 if(!sam_io_unk_info6("unk_inf6",&q_u->ctr->info.inf6, ps,depth))
7384                         return False;
7385                 break;
7386         case 0x05:
7387                 if(!sam_io_unk_info5("unk_inf5",&q_u->ctr->info.inf5, ps,depth))
7388                         return False;
7389                 break;
7390         case 0x03:
7391                 if(!sam_io_unk_info3("unk_inf3",&q_u->ctr->info.inf3, ps,depth))
7392                         return False;
7393                 break;
7394         case 0x02:
7395                 if(!sam_io_unk_info2("unk_inf2",&q_u->ctr->info.inf2, ps,depth))
7396                         return False;
7397                 break;
7398         case 0x01:
7399                 if(!sam_io_unk_info1("unk_inf1",&q_u->ctr->info.inf1, ps,depth))
7400                         return False;
7401                 break;
7402         default:
7403                 DEBUG(0, ("samr_io_r_samr_unknown_2e: unknown switch level 0x%x\n",
7404                         q_u->switch_value));
7405                 return False;
7406         }
7407
7408         return True;
7409 }
7410
7411 /*******************************************************************
7412 inits a SAMR_R_QUERY_DOMAIN_INFO structure.
7413 ********************************************************************/
7414
7415 void init_samr_r_set_domain_info(SAMR_R_SET_DOMAIN_INFO * r_u, NTSTATUS status)
7416 {
7417         DEBUG(5, ("init_samr_r_set_domain_info\n"));
7418
7419         r_u->status = status;   /* return status */
7420 }
7421
7422 /*******************************************************************
7423 reads or writes a structure.
7424 ********************************************************************/
7425
7426 BOOL samr_io_r_set_domain_info(char *desc, SAMR_R_SET_DOMAIN_INFO * r_u,
7427                               prs_struct *ps, int depth)
7428 {
7429         if (r_u == NULL)
7430                 return False;
7431
7432         prs_debug(ps, depth, desc, "samr_io_r_samr_unknown_2e");
7433         depth++;
7434
7435         if(!prs_align(ps))
7436                 return False;
7437
7438         if(!prs_ntstatus("status", ps, depth, &r_u->status))
7439                 return False;
7440         
7441         return True;
7442 }