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