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