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