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