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