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