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