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