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