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