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