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