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