fc4d7a3ab36dd67ea283d17541dad552afe931e2
[ira/wip.git] / source3 / rpc_parse / parse_samr.c
1 /* 
2  *  Unix SMB/CIFS implementation.
3  *  RPC Pipe client / server routines
4  *  Copyright (C) Andrew Tridgell              1992-2000,
5  *  Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
6  *  Copyright (C) Paul Ashton                  1997-2000,
7  *  Copyright (C) Elrond                            2000,
8  *  Copyright (C) Jeremy Allison                    2001,
9  *  Copyright (C) Jean François Micouleau      1998-2001,
10  *  Copyright (C) Jim McDonough <jmcd@us.ibm.com>   2002.
11  *  
12  *  This program is free software; you can redistribute it and/or modify
13  *  it under the terms of the GNU General Public License as published by
14  *  the Free Software Foundation; either version 2 of the License, or
15  *  (at your option) any later version.
16  *  
17  *  This program is distributed in the hope that it will be useful,
18  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  *  GNU General Public License for more details.
21  *  
22  *  You should have received a copy of the GNU General Public License
23  *  along with this program; if not, write to the Free Software
24  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25  */
26
27 #include "includes.h"
28
29 #undef DBGC_CLASS
30 #define DBGC_CLASS DBGC_RPC_PARSE
31
32 /*******************************************************************
33 inits a SAMR_Q_CLOSE_HND structure.
34 ********************************************************************/
35
36 void init_samr_q_close_hnd(SAMR_Q_CLOSE_HND * q_c, POLICY_HND *hnd)
37 {
38         DEBUG(5, ("init_samr_q_close_hnd\n"));
39         
40         q_c->pol = *hnd;
41 }
42
43 /*******************************************************************
44 reads or writes a structure.
45 ********************************************************************/
46
47 BOOL samr_io_q_close_hnd(const char *desc, SAMR_Q_CLOSE_HND * q_u,
48                          prs_struct *ps, int depth)
49 {
50         if (q_u == NULL)
51                 return False;
52
53         prs_debug(ps, depth, desc, "samr_io_q_close_hnd");
54         depth++;
55
56         if(!prs_align(ps))
57                 return False;
58
59         return smb_io_pol_hnd("pol", &q_u->pol, ps, depth);
60 }
61
62 /*******************************************************************
63 reads or writes a structure.
64 ********************************************************************/
65
66 BOOL samr_io_r_close_hnd(const char *desc, SAMR_R_CLOSE_HND * r_u,
67                          prs_struct *ps, int depth)
68 {
69         if (r_u == NULL)
70                 return False;
71
72         prs_debug(ps, depth, desc, "samr_io_r_close_hnd");
73         depth++;
74
75         if(!prs_align(ps))
76                 return False;
77
78         if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
79                 return False;
80
81         if(!prs_ntstatus("status", ps, depth, &r_u->status))
82                 return False;
83
84         return True;
85 }
86
87 /*******************************************************************
88 inits a SAMR_Q_LOOKUP_DOMAIN structure.
89 ********************************************************************/
90
91 void init_samr_q_lookup_domain(SAMR_Q_LOOKUP_DOMAIN * q_u,
92                                POLICY_HND *pol, char *dom_name)
93 {
94         DEBUG(5, ("init_samr_q_lookup_domain\n"));
95
96         q_u->connect_pol = *pol;
97
98         init_unistr2(&q_u->uni_domain, dom_name, UNI_FLAGS_NONE);
99         init_uni_hdr(&q_u->hdr_domain, &q_u->uni_domain);
100 }
101
102 /*******************************************************************
103 reads or writes a structure.
104 ********************************************************************/
105 BOOL samr_io_q_lookup_domain(const char *desc, SAMR_Q_LOOKUP_DOMAIN * q_u,
106                              prs_struct *ps, int depth)
107 {
108         if (q_u == NULL)
109                 return False;
110
111         prs_debug(ps, depth, desc, "samr_io_q_lookup_domain");
112         depth++;
113
114         if(!prs_align(ps))
115                 return False;
116
117         if(!smb_io_pol_hnd("connect_pol", &q_u->connect_pol, ps, depth))
118                 return False;
119
120         if(!smb_io_unihdr("hdr_domain", &q_u->hdr_domain, ps, depth))
121                 return False;
122
123         if(!smb_io_unistr2("uni_domain", &q_u->uni_domain, q_u->hdr_domain.buffer, ps, depth))
124                 return False;
125
126         return True;
127 }
128
129 /*******************************************************************
130 inits a SAMR_R_LOOKUP_DOMAIN structure.
131 ********************************************************************/
132
133 void init_samr_r_lookup_domain(SAMR_R_LOOKUP_DOMAIN * r_u,
134                                DOM_SID *dom_sid, NTSTATUS status)
135 {
136         DEBUG(5, ("init_samr_r_lookup_domain\n"));
137
138         r_u->status = status;
139         r_u->ptr_sid = 0;
140         if (NT_STATUS_IS_OK(status)) {
141                 r_u->ptr_sid = 1;
142                 init_dom_sid2(&r_u->dom_sid, dom_sid);
143         }
144 }
145
146 /*******************************************************************
147 reads or writes a structure.
148 ********************************************************************/
149
150 BOOL samr_io_r_lookup_domain(const char *desc, SAMR_R_LOOKUP_DOMAIN * r_u,
151                              prs_struct *ps, int depth)
152 {
153         if (r_u == NULL)
154                 return False;
155
156         prs_debug(ps, depth, desc, "samr_io_r_lookup_domain");
157         depth++;
158
159         if(!prs_align(ps))
160                 return False;
161
162         if(!prs_uint32("ptr", ps, depth, &r_u->ptr_sid))
163                 return False;
164
165         if (r_u->ptr_sid != 0) {
166                 if(!smb_io_dom_sid2("sid", &r_u->dom_sid, ps, depth))
167                         return False;
168                 if(!prs_align(ps))
169                         return False;
170         }
171
172         if(!prs_ntstatus("status", ps, depth, &r_u->status))
173                 return False;
174
175         return True;
176 }
177
178 /*******************************************************************
179 reads or writes a structure.
180 ********************************************************************/
181
182 void init_samr_q_remove_sid_foreign_domain(SAMR_Q_REMOVE_SID_FOREIGN_DOMAIN * q_u, POLICY_HND *dom_pol, DOM_SID *sid)
183 {
184         DEBUG(5, ("samr_init_samr_q_remove_sid_foreign_domain\n"));
185
186         q_u->dom_pol = *dom_pol;
187         init_dom_sid2(&q_u->sid, sid);
188 }
189
190 /*******************************************************************
191 reads or writes a structure.
192 ********************************************************************/
193
194 BOOL samr_io_q_remove_sid_foreign_domain(const char *desc, SAMR_Q_REMOVE_SID_FOREIGN_DOMAIN * q_u,
195                           prs_struct *ps, int depth)
196 {
197         if (q_u == NULL)
198                 return False;
199
200         prs_debug(ps, depth, desc, "samr_io_q_remove_sid_foreign_domain");
201         depth++;
202
203         if(!prs_align(ps))
204                 return False;
205
206         if(!smb_io_pol_hnd("domain_pol", &q_u->dom_pol, ps, depth))
207                 return False;
208
209         if(!smb_io_dom_sid2("sid", &q_u->sid, ps, depth))
210                 return False;
211
212         if(!prs_align(ps))
213                 return False;
214
215         return True;
216 }
217
218 /*******************************************************************
219 reads or writes a structure.
220 ********************************************************************/
221
222 BOOL samr_io_r_remove_sid_foreign_domain(const char *desc, SAMR_R_REMOVE_SID_FOREIGN_DOMAIN * r_u,
223                           prs_struct *ps, int depth)
224 {
225         if (r_u == NULL)
226                 return False;
227
228         prs_debug(ps, depth, desc, "samr_io_r_remove_sid_foreign_domain");
229         depth++;
230
231         if(!prs_align(ps))
232                 return False;
233
234         if(!prs_ntstatus("status", ps, depth, &r_u->status))
235                 return False;
236
237         return True;
238 }
239
240 /*******************************************************************
241 reads or writes a structure.
242 ********************************************************************/
243
244 void init_samr_q_open_domain(SAMR_Q_OPEN_DOMAIN * q_u,
245                              POLICY_HND *pol, uint32 flags,
246                              const DOM_SID *sid)
247 {
248         DEBUG(5, ("samr_init_samr_q_open_domain\n"));
249
250         q_u->pol = *pol;
251         q_u->flags = flags;
252         init_dom_sid2(&q_u->dom_sid, sid);
253 }
254
255 /*******************************************************************
256 reads or writes a structure.
257 ********************************************************************/
258
259 BOOL samr_io_q_open_domain(const char *desc, SAMR_Q_OPEN_DOMAIN * q_u,
260                            prs_struct *ps, int depth)
261 {
262         if (q_u == NULL)
263                 return False;
264
265         prs_debug(ps, depth, desc, "samr_io_q_open_domain");
266         depth++;
267
268         if(!prs_align(ps))
269                 return False;
270
271         if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
272                 return False;
273
274         if(!prs_uint32("flags", ps, depth, &q_u->flags))
275                 return False;
276
277         if(!smb_io_dom_sid2("sid", &q_u->dom_sid, ps, depth))
278                 return False;
279
280         return True;
281 }
282
283 /*******************************************************************
284 reads or writes a structure.
285 ********************************************************************/
286
287 BOOL samr_io_r_open_domain(const char *desc, SAMR_R_OPEN_DOMAIN * r_u,
288                            prs_struct *ps, int depth)
289 {
290         if (r_u == NULL)
291                 return False;
292
293         prs_debug(ps, depth, desc, "samr_io_r_open_domain");
294         depth++;
295
296         if(!prs_align(ps))
297                 return False;
298
299         if(!smb_io_pol_hnd("domain_pol", &r_u->domain_pol, ps, depth))
300                 return False;
301
302         if(!prs_ntstatus("status", ps, depth, &r_u->status))
303                 return False;
304
305         return True;
306 }
307
308 /*******************************************************************
309 reads or writes a structure.
310 ********************************************************************/
311
312 void init_samr_q_get_usrdom_pwinfo(SAMR_Q_GET_USRDOM_PWINFO * q_u,
313                                    POLICY_HND *user_pol)
314 {
315         DEBUG(5, ("samr_init_samr_q_get_usrdom_pwinfo\n"));
316
317         q_u->user_pol = *user_pol;
318 }
319
320 /*******************************************************************
321 reads or writes a structure.
322 ********************************************************************/
323
324 BOOL samr_io_q_get_usrdom_pwinfo(const char *desc, SAMR_Q_GET_USRDOM_PWINFO * q_u,
325                                  prs_struct *ps, int depth)
326 {
327         if (q_u == NULL)
328                 return False;
329
330         prs_debug(ps, depth, desc, "samr_io_q_get_usrdom_pwinfo");
331         depth++;
332
333         if(!prs_align(ps))
334                 return False;
335
336         return smb_io_pol_hnd("user_pol", &q_u->user_pol, ps, depth);
337 }
338
339 /*******************************************************************
340  Init.
341 ********************************************************************/
342
343 void init_samr_r_get_usrdom_pwinfo(SAMR_R_GET_USRDOM_PWINFO *r_u, NTSTATUS status)
344 {
345         DEBUG(5, ("init_samr_r_get_usrdom_pwinfo\n"));
346         
347         r_u->min_pwd_length = 0x0000;
348
349         /*
350          * used to be   
351          * r_u->unknown_1 = 0x0015;
352          * but for trusts.
353          */
354         r_u->unknown_1 = 0x01D1;
355         r_u->unknown_1 = 0x0015;
356
357         r_u->password_properties = 0x00000000;
358
359         r_u->status = status;
360 }
361
362 /*******************************************************************
363 reads or writes a structure.
364 ********************************************************************/
365
366 BOOL samr_io_r_get_usrdom_pwinfo(const char *desc, SAMR_R_GET_USRDOM_PWINFO * r_u,
367                                  prs_struct *ps, int depth)
368 {
369         if (r_u == NULL)
370                 return False;
371
372         prs_debug(ps, depth, desc, "samr_io_r_get_usrdom_pwinfo");
373         depth++;
374
375         if(!prs_align(ps))
376                 return False;
377
378         if(!prs_uint16("min_pwd_length", ps, depth, &r_u->min_pwd_length))
379                 return False;
380         if(!prs_uint16("unknown_1", ps, depth, &r_u->unknown_1))
381                 return False;
382         if(!prs_uint32("password_properties", ps, depth, &r_u->password_properties))
383                 return False;
384
385         if(!prs_ntstatus("status   ", ps, depth, &r_u->status))
386                 return False;
387
388         return True;
389 }
390
391
392 /*******************************************************************
393 reads or writes a structure.
394 ********************************************************************/
395
396 BOOL samr_io_q_set_sec_obj(const char *desc, SAMR_Q_SET_SEC_OBJ * q_u,
397                              prs_struct *ps, int depth)
398 {
399         if (q_u == NULL)
400                 return False;
401
402         prs_debug(ps, depth, desc, "samr_io_q_set_sec_obj");
403         depth++;
404
405         if(!prs_align(ps))
406                 return False;
407
408         if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
409                 return False;
410
411         if(!prs_uint32("sec_info", ps, depth, &q_u->sec_info))
412                 return False;
413                 
414         if(!sec_io_desc_buf("sec_desc", &q_u->buf, ps, depth))
415                 return False;
416         
417         return True;
418 }
419
420
421 /*******************************************************************
422 reads or writes a structure.
423 ********************************************************************/
424
425 void init_samr_q_query_sec_obj(SAMR_Q_QUERY_SEC_OBJ * q_u,
426                                POLICY_HND *user_pol, uint32 sec_info)
427 {
428         DEBUG(5, ("samr_init_samr_q_query_sec_obj\n"));
429
430         q_u->user_pol = *user_pol;
431         q_u->sec_info = sec_info;
432 }
433
434
435 /*******************************************************************
436 reads or writes a structure.
437 ********************************************************************/
438
439 BOOL samr_io_q_query_sec_obj(const char *desc, SAMR_Q_QUERY_SEC_OBJ * q_u,
440                              prs_struct *ps, int depth)
441 {
442         if (q_u == NULL)
443                 return False;
444
445         prs_debug(ps, depth, desc, "samr_io_q_query_sec_obj");
446         depth++;
447
448         if(!prs_align(ps))
449                 return False;
450
451         if(!smb_io_pol_hnd("user_pol", &q_u->user_pol, ps, depth))
452                 return False;
453
454         if(!prs_uint32("sec_info", ps, depth, &q_u->sec_info))
455                 return False;
456
457         return True;
458 }
459
460 /*******************************************************************
461 reads or writes a structure.
462 ********************************************************************/
463
464 void init_samr_q_query_dom_info(SAMR_Q_QUERY_DOMAIN_INFO * q_u,
465                                 POLICY_HND *domain_pol, uint16 switch_value)
466 {
467         DEBUG(5, ("samr_init_samr_q_query_dom_info\n"));
468
469         q_u->domain_pol = *domain_pol;
470         q_u->switch_value = switch_value;
471 }
472
473 /*******************************************************************
474 reads or writes a structure.
475 ********************************************************************/
476
477 BOOL samr_io_q_query_dom_info(const char *desc, SAMR_Q_QUERY_DOMAIN_INFO * q_u,
478                               prs_struct *ps, int depth)
479 {
480         if (q_u == NULL)
481                 return False;
482
483         prs_debug(ps, depth, desc, "samr_io_q_query_dom_info");
484         depth++;
485
486         if(!prs_align(ps))
487                 return False;
488
489         if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
490                 return False;
491
492         if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
493                 return False;
494
495         return True;
496 }
497
498
499 /*******************************************************************
500 inits a structure.
501 ********************************************************************/
502
503 void init_unk_info3(SAM_UNK_INFO_3 *u_3, NTTIME nt_logout)
504 {
505         u_3->logout.low = nt_logout.low;
506         u_3->logout.high = nt_logout.high;
507 }
508
509 /*******************************************************************
510 reads or writes a structure.
511 ********************************************************************/
512
513 static BOOL sam_io_unk_info3(const char *desc, SAM_UNK_INFO_3 * u_3,
514                              prs_struct *ps, int depth)
515 {
516         if (u_3 == NULL)
517                 return False;
518
519         prs_debug(ps, depth, desc, "sam_io_unk_info3");
520         depth++;
521
522         if(!smb_io_time("logout", &u_3->logout, ps, depth))
523                 return False;
524
525         return True;
526 }
527
528 /*******************************************************************
529 inits a structure.
530 ********************************************************************/
531
532 void init_unk_info6(SAM_UNK_INFO_6 * u_6)
533 {
534         u_6->unknown_0 = 0x00000000;
535         u_6->ptr_0 = 1;
536         memset(u_6->padding, 0, sizeof(u_6->padding));  /* 12 bytes zeros */
537 }
538
539 /*******************************************************************
540 reads or writes a structure.
541 ********************************************************************/
542
543 static BOOL sam_io_unk_info6(const char *desc, SAM_UNK_INFO_6 * u_6,
544                              prs_struct *ps, int depth)
545 {
546         if (u_6 == NULL)
547                 return False;
548
549         prs_debug(ps, depth, desc, "sam_io_unk_info6");
550         depth++;
551
552         if(!prs_uint32("unknown_0", ps, depth, &u_6->unknown_0)) /* 0x0000 0000 */
553                 return False;
554         if(!prs_uint32("ptr_0", ps, depth, &u_6->ptr_0)) /* pointer to unknown structure */
555                 return False;
556         if(!prs_uint8s(False, "padding", ps, depth, u_6->padding, sizeof(u_6->padding)))        /* 12 bytes zeros */
557                 return False;
558
559         return True;
560 }
561
562 /*******************************************************************
563 inits a structure.
564 ********************************************************************/
565
566 void init_unk_info7(SAM_UNK_INFO_7 * u_7, uint32 server_role)
567 {
568         u_7->server_role = server_role;
569 }
570
571 /*******************************************************************
572 reads or writes a structure.
573 ********************************************************************/
574
575 static BOOL sam_io_unk_info7(const char *desc, SAM_UNK_INFO_7 * u_7,
576                              prs_struct *ps, int depth)
577 {
578         if (u_7 == NULL)
579                 return False;
580
581         prs_debug(ps, depth, desc, "sam_io_unk_info7");
582         depth++;
583
584         if(!prs_uint16("server_role", ps, depth, &u_7->server_role))
585                 return False;
586
587         return True;
588 }
589
590 /*******************************************************************
591 inits a structure.
592 ********************************************************************/
593
594 void init_unk_info8(SAM_UNK_INFO_8 * u_8, uint32 seq_num)
595 {
596         unix_to_nt_time(&u_8->domain_create_time, 0);
597         u_8->seq_num.low = seq_num;
598         u_8->seq_num.high = 0x0000;
599 }
600
601 /*******************************************************************
602 reads or writes a structure.
603 ********************************************************************/
604
605 static BOOL sam_io_unk_info8(const char *desc, SAM_UNK_INFO_8 * u_8,
606                              prs_struct *ps, int depth)
607 {
608         if (u_8 == NULL)
609                 return False;
610
611         prs_debug(ps, depth, desc, "sam_io_unk_info8");
612         depth++;
613
614         if (!prs_uint64("seq_num", ps, depth, &u_8->seq_num))
615                 return False;
616
617         if(!smb_io_time("domain_create_time", &u_8->domain_create_time, ps, depth))
618                 return False;
619
620         return True;
621 }
622
623
624 /*******************************************************************
625 inits a structure.
626 ********************************************************************/
627
628 void init_unk_info12(SAM_UNK_INFO_12 * u_12, NTTIME nt_lock_duration, NTTIME nt_reset_time, uint16 lockout)
629 {
630         u_12->duration.low = nt_lock_duration.low;
631         u_12->duration.high = nt_lock_duration.high;
632         u_12->reset_count.low = nt_reset_time.low;
633         u_12->reset_count.high = nt_reset_time.high;
634
635         u_12->bad_attempt_lockout = lockout;
636 }
637
638 /*******************************************************************
639 reads or writes a structure.
640 ********************************************************************/
641
642 static BOOL sam_io_unk_info12(const char *desc, SAM_UNK_INFO_12 * u_12,
643                               prs_struct *ps, int depth)
644 {
645         if (u_12 == NULL)
646                 return False;
647
648         prs_debug(ps, depth, desc, "sam_io_unk_info12");
649         depth++;
650
651         if(!smb_io_time("duration", &u_12->duration, ps, depth))
652                 return False;
653         if(!smb_io_time("reset_count", &u_12->reset_count, ps, depth))
654                 return False;
655         if(!prs_uint16("bad_attempt_lockout", ps, depth, &u_12->bad_attempt_lockout))
656                 return False;
657
658         return True;
659 }
660
661 /*******************************************************************
662 inits a structure.
663 ********************************************************************/
664
665 void init_unk_info5(SAM_UNK_INFO_5 * u_5,const char *server)
666 {
667         init_unistr2(&u_5->uni_server, server, UNI_FLAGS_NONE);
668         init_uni_hdr(&u_5->hdr_server, &u_5->uni_server);
669 }
670
671 /*******************************************************************
672 reads or writes a structure.
673 ********************************************************************/
674
675 static BOOL sam_io_unk_info5(const char *desc, SAM_UNK_INFO_5 * u_5,
676                              prs_struct *ps, int depth)
677 {
678         if (u_5 == NULL)
679                 return False;
680
681         prs_debug(ps, depth, desc, "sam_io_unk_info5");
682         depth++;
683
684         if(!smb_io_unihdr("hdr_server", &u_5->hdr_server, ps, depth))
685                 return False;
686
687         if(!smb_io_unistr2("uni_server", &u_5->uni_server, u_5->hdr_server.buffer, ps, depth))
688                 return False;
689
690         return True;
691 }
692
693 /*******************************************************************
694 inits a structure.
695 ********************************************************************/
696
697 void init_unk_info2(SAM_UNK_INFO_2 * u_2,
698                         const char *comment, const char *domain, const char *server,
699                         uint32 seq_num, uint32 num_users, uint32 num_groups, uint32 num_alias, NTTIME nt_logout, uint32 server_role)
700 {
701         u_2->logout.low = nt_logout.low;
702         u_2->logout.high = nt_logout.high;
703
704         u_2->seq_num.low = seq_num;
705         u_2->seq_num.high = 0x00000000;
706
707
708         u_2->unknown_4 = 0x00000001;
709         u_2->server_role = server_role;
710         u_2->unknown_6 = 0x00000001;
711         u_2->num_domain_usrs = num_users;
712         u_2->num_domain_grps = num_groups;
713         u_2->num_local_grps = num_alias;
714
715         memset(u_2->padding, 0, sizeof(u_2->padding));  /* 12 bytes zeros */
716
717         init_unistr2(&u_2->uni_comment, comment, UNI_FLAGS_NONE);
718         init_uni_hdr(&u_2->hdr_comment, &u_2->uni_comment);
719         init_unistr2(&u_2->uni_domain, domain, UNI_FLAGS_NONE);
720         init_uni_hdr(&u_2->hdr_domain, &u_2->uni_domain);
721         init_unistr2(&u_2->uni_server, server, UNI_FLAGS_NONE);
722         init_uni_hdr(&u_2->hdr_server, &u_2->uni_server);
723 }
724
725 /*******************************************************************
726 reads or writes a structure.
727 ********************************************************************/
728
729 static BOOL sam_io_unk_info2(const char *desc, SAM_UNK_INFO_2 * u_2,
730                              prs_struct *ps, int depth)
731 {
732         if (u_2 == NULL)
733                 return False;
734
735         prs_debug(ps, depth, desc, "sam_io_unk_info2");
736         depth++;
737
738         if(!smb_io_time("logout", &u_2->logout, ps, depth))
739                 return False;
740         if(!smb_io_unihdr("hdr_comment", &u_2->hdr_comment, ps, depth))
741                 return False;
742         if(!smb_io_unihdr("hdr_domain", &u_2->hdr_domain, ps, depth))
743                 return False;
744         if(!smb_io_unihdr("hdr_server", &u_2->hdr_server, ps, depth))
745                 return False;
746
747         /* put all the data in here, at the moment, including what the above
748            pointer is referring to
749          */
750
751         if(!prs_uint64("seq_num ", ps, depth, &u_2->seq_num))
752                 return False;
753
754         if(!prs_uint32("unknown_4 ", ps, depth, &u_2->unknown_4)) /* 0x0000 0001 */
755                 return False;
756         if(!prs_uint32("server_role ", ps, depth, &u_2->server_role))
757                 return False;
758         if(!prs_uint32("unknown_6 ", ps, depth, &u_2->unknown_6)) /* 0x0000 0001 */
759                 return False;
760         if(!prs_uint32("num_domain_usrs ", ps, depth, &u_2->num_domain_usrs))
761                 return False;
762         if(!prs_uint32("num_domain_grps", ps, depth, &u_2->num_domain_grps))
763                 return False;
764         if(!prs_uint32("num_local_grps", ps, depth, &u_2->num_local_grps))
765                 return False;
766
767         if(!smb_io_unistr2("uni_comment", &u_2->uni_comment, u_2->hdr_comment.buffer, ps, depth))
768                 return False;
769         if(!smb_io_unistr2("uni_domain", &u_2->uni_domain, u_2->hdr_domain.buffer, ps, depth))
770                 return False;
771         if(!smb_io_unistr2("uni_server", &u_2->uni_server, u_2->hdr_server.buffer, ps, depth))
772                 return False;
773
774         return True;
775 }
776
777 /*******************************************************************
778 inits a structure.
779 ********************************************************************/
780
781 void init_unk_info1(SAM_UNK_INFO_1 *u_1, uint16 min_pass_len, uint16 pass_hist, 
782                     uint32 password_properties, NTTIME nt_expire, NTTIME nt_min_age)
783 {
784         u_1->min_length_password = min_pass_len;
785         u_1->password_history = pass_hist;
786         u_1->password_properties = password_properties;
787         
788         /* password never expire */
789         u_1->expire.high = nt_expire.high;
790         u_1->expire.low = nt_expire.low;
791         
792         /* can change the password now */
793         u_1->min_passwordage.high = nt_min_age.high;
794         u_1->min_passwordage.low = nt_min_age.low;
795         
796 }
797
798 /*******************************************************************
799 reads or writes a structure.
800 ********************************************************************/
801
802 static BOOL sam_io_unk_info1(const char *desc, SAM_UNK_INFO_1 * u_1,
803                              prs_struct *ps, int depth)
804 {
805         if (u_1 == NULL)
806           return False;
807
808         prs_debug(ps, depth, desc, "sam_io_unk_info1");
809         depth++;
810
811         if(!prs_uint16("min_length_password", ps, depth, &u_1->min_length_password))
812                 return False;
813         if(!prs_uint16("password_history", ps, depth, &u_1->password_history))
814                 return False;
815         if(!prs_uint32("password_properties", ps, depth, &u_1->password_properties))
816                 return False;
817         if(!smb_io_time("expire", &u_1->expire, ps, depth))
818                 return False;
819         if(!smb_io_time("min_passwordage", &u_1->min_passwordage, ps, depth))
820                 return False;
821
822         return True;
823 }
824
825 /*******************************************************************
826 inits a SAMR_R_QUERY_DOMAIN_INFO structure.
827 ********************************************************************/
828
829 void init_samr_r_query_dom_info(SAMR_R_QUERY_DOMAIN_INFO * r_u,
830                                 uint16 switch_value, SAM_UNK_CTR * ctr,
831                                 NTSTATUS status)
832 {
833         DEBUG(5, ("init_samr_r_query_dom_info\n"));
834
835         r_u->ptr_0 = 0;
836         r_u->switch_value = 0;
837         r_u->status = status;   /* return status */
838
839         if (NT_STATUS_IS_OK(status)) {
840                 r_u->switch_value = switch_value;
841                 r_u->ptr_0 = 1;
842                 r_u->ctr = ctr;
843         }
844 }
845
846 /*******************************************************************
847 reads or writes a structure.
848 ********************************************************************/
849
850 BOOL samr_io_r_query_dom_info(const char *desc, SAMR_R_QUERY_DOMAIN_INFO * r_u,
851                               prs_struct *ps, int depth)
852 {
853         if (r_u == NULL)
854                 return False;
855
856         prs_debug(ps, depth, desc, "samr_io_r_query_dom_info");
857         depth++;
858
859         if(!prs_align(ps))
860                 return False;
861
862         if(!prs_uint32("ptr_0 ", ps, depth, &r_u->ptr_0))
863                 return False;
864
865         if (r_u->ptr_0 != 0 && r_u->ctr != NULL) {
866                 if(!prs_uint16("switch_value", ps, depth, &r_u->switch_value))
867                         return False;
868                 if(!prs_align(ps))
869                         return False;
870
871                 switch (r_u->switch_value) {
872                 case 0x0c:
873                         if(!sam_io_unk_info12("unk_inf12", &r_u->ctr->info.inf12, ps, depth))
874                                 return False;
875                         break;
876                 case 0x08:
877                         if(!sam_io_unk_info8("unk_inf8",&r_u->ctr->info.inf8, ps,depth))
878                                 return False;
879                         break;
880                 case 0x07:
881                         if(!sam_io_unk_info7("unk_inf7",&r_u->ctr->info.inf7, ps,depth))
882                                 return False;
883                         break;
884                 case 0x06:
885                         if(!sam_io_unk_info6("unk_inf6",&r_u->ctr->info.inf6, ps,depth))
886                                 return False;
887                         break;
888                 case 0x05:
889                         if(!sam_io_unk_info5("unk_inf5",&r_u->ctr->info.inf5, ps,depth))
890                                 return False;
891                         break;
892                 case 0x03:
893                         if(!sam_io_unk_info3("unk_inf3",&r_u->ctr->info.inf3, ps,depth))
894                                 return False;
895                         break;
896                 case 0x02:
897                         if(!sam_io_unk_info2("unk_inf2",&r_u->ctr->info.inf2, ps,depth))
898                                 return False;
899                         break;
900                 case 0x01:
901                         if(!sam_io_unk_info1("unk_inf1",&r_u->ctr->info.inf1, ps,depth))
902                                 return False;
903                         break;
904                 default:
905                         DEBUG(0, ("samr_io_r_query_dom_info: unknown switch level 0x%x\n",
906                                 r_u->switch_value));
907                         r_u->status = NT_STATUS_INVALID_INFO_CLASS;
908                         return False;
909                 }
910         }
911         
912         if(!prs_align(ps))
913                 return False;
914
915         if(!prs_ntstatus("status", ps, depth, &r_u->status))
916                 return False;
917         
918         return True;
919 }
920
921 /*******************************************************************
922 reads or writes a SAMR_R_SET_SEC_OBJ structure.
923 ********************************************************************/
924
925 BOOL samr_io_r_set_sec_obj(const char *desc, SAMR_R_SET_SEC_OBJ * r_u,
926                              prs_struct *ps, int depth)
927 {
928         if (r_u == NULL)
929                 return False;
930   
931         prs_debug(ps, depth, desc, "samr_io_r_set_sec_obj");
932         depth++;
933
934         if(!prs_align(ps))
935                 return False;
936
937         if(!prs_ntstatus("status", ps, depth, &r_u->status))
938                 return False;
939
940         return True;
941 }
942
943 /*******************************************************************
944 reads or writes a SAMR_R_QUERY_SEC_OBJ structure.
945 ********************************************************************/
946
947 BOOL samr_io_r_query_sec_obj(const char *desc, SAMR_R_QUERY_SEC_OBJ * r_u,
948                              prs_struct *ps, int depth)
949 {
950         if (r_u == NULL)
951                 return False;
952   
953         prs_debug(ps, depth, desc, "samr_io_r_query_sec_obj");
954         depth++;
955
956         if(!prs_align(ps))
957                 return False;
958
959         if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
960                 return False;
961         if (r_u->ptr != 0) {
962                 if(!sec_io_desc_buf("sec", &r_u->buf, ps, depth))
963                         return False;
964         }
965
966         if(!prs_ntstatus("status", ps, depth, &r_u->status))
967                 return False;
968
969         return True;
970 }
971
972 /*******************************************************************
973 reads or writes a SAM_STR1 structure.
974 ********************************************************************/
975
976 static BOOL sam_io_sam_str1(const char *desc, SAM_STR1 * sam, uint32 acct_buf,
977                             uint32 name_buf, uint32 desc_buf,
978                             prs_struct *ps, int depth)
979 {
980         if (sam == NULL)
981                 return False;
982
983         prs_debug(ps, depth, desc, "sam_io_sam_str1");
984         depth++;
985
986         if(!prs_align(ps))
987                 return False;
988         if (!smb_io_unistr2("name", &sam->uni_acct_name, acct_buf, ps, depth))
989                 return False;
990
991         if (!smb_io_unistr2("desc", &sam->uni_acct_desc, desc_buf, ps, depth))
992                 return False;
993
994         if (!smb_io_unistr2("full", &sam->uni_full_name, name_buf, ps, depth))
995                 return False;
996
997         return True;
998 }
999
1000 /*******************************************************************
1001 inits a SAM_ENTRY1 structure.
1002 ********************************************************************/
1003
1004 static void init_sam_entry1(SAM_ENTRY1 *sam, uint32 user_idx,
1005                             UNISTR2 *sam_name, UNISTR2 *sam_full,
1006                             UNISTR2 *sam_desc, uint32 rid_user,
1007                             uint16 acb_info)
1008 {
1009         DEBUG(5, ("init_sam_entry1\n"));
1010
1011         ZERO_STRUCTP(sam);
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_acct_name, sam_name);
1018         init_uni_hdr(&sam->hdr_user_name, sam_full);
1019         init_uni_hdr(&sam->hdr_user_desc, sam_desc);
1020 }
1021
1022 /*******************************************************************
1023 reads or writes a SAM_ENTRY1 structure.
1024 ********************************************************************/
1025
1026 static BOOL sam_io_sam_entry1(const char *desc, SAM_ENTRY1 * sam,
1027                               prs_struct *ps, int depth)
1028 {
1029         if (sam == NULL)
1030                 return False;
1031
1032         prs_debug(ps, depth, desc, "sam_io_sam_entry1");
1033         depth++;
1034
1035         if(!prs_align(ps))
1036                 return False;
1037
1038         if(!prs_uint32("user_idx ", ps, depth, &sam->user_idx))
1039                 return False;
1040
1041         if(!prs_uint32("rid_user ", ps, depth, &sam->rid_user))
1042                 return False;
1043         if(!prs_uint16("acb_info ", ps, depth, &sam->acb_info))
1044                 return False;
1045
1046         if(!prs_align(ps))
1047                 return False;
1048
1049         if (!smb_io_unihdr("hdr_acct_name", &sam->hdr_acct_name, ps, depth))
1050                 return False;
1051         if (!smb_io_unihdr("hdr_user_desc", &sam->hdr_user_desc, ps, depth))
1052                 return False;
1053         if (!smb_io_unihdr("hdr_user_name", &sam->hdr_user_name, ps, depth))
1054                 return False;
1055
1056         return True;
1057 }
1058
1059 /*******************************************************************
1060 reads or writes a SAM_STR2 structure.
1061 ********************************************************************/
1062
1063 static BOOL sam_io_sam_str2(const char *desc, SAM_STR2 * sam, uint32 acct_buf,
1064                             uint32 desc_buf, prs_struct *ps, int depth)
1065 {
1066         if (sam == NULL)
1067                 return False;
1068
1069         prs_debug(ps, depth, desc, "sam_io_sam_str2");
1070         depth++;
1071
1072         if(!prs_align(ps))
1073                 return False;
1074
1075         if(!smb_io_unistr2("uni_srv_name", &sam->uni_srv_name, acct_buf, ps, depth)) /* account name unicode string */
1076                 return False;
1077         if(!smb_io_unistr2("uni_srv_desc", &sam->uni_srv_desc, desc_buf, ps, depth))    /* account desc unicode string */
1078                 return False;
1079
1080         return True;
1081 }
1082
1083 /*******************************************************************
1084 inits a SAM_ENTRY2 structure.
1085 ********************************************************************/
1086 static void init_sam_entry2(SAM_ENTRY2 * sam, uint32 user_idx,
1087                             UNISTR2 *sam_name, UNISTR2 *sam_desc,
1088                             uint32 rid_user, uint16 acb_info)
1089 {
1090         DEBUG(5, ("init_sam_entry2\n"));
1091
1092         sam->user_idx = user_idx;
1093         sam->rid_user = rid_user;
1094         sam->acb_info = acb_info;
1095
1096         init_uni_hdr(&sam->hdr_srv_name, sam_name);
1097         init_uni_hdr(&sam->hdr_srv_desc, sam_desc);
1098 }
1099
1100 /*******************************************************************
1101 reads or writes a SAM_ENTRY2 structure.
1102 ********************************************************************/
1103
1104 static BOOL sam_io_sam_entry2(const char *desc, SAM_ENTRY2 * sam,
1105                               prs_struct *ps, int depth)
1106 {
1107         if (sam == NULL)
1108                 return False;
1109
1110         prs_debug(ps, depth, desc, "sam_io_sam_entry2");
1111         depth++;
1112
1113         if(!prs_align(ps))
1114                 return False;
1115
1116         if(!prs_uint32("user_idx ", ps, depth, &sam->user_idx))
1117                 return False;
1118
1119         if(!prs_uint32("rid_user ", ps, depth, &sam->rid_user))
1120                 return False;
1121         if(!prs_uint16("acb_info ", ps, depth, &sam->acb_info))
1122                 return False;
1123
1124         if(!prs_align(ps))
1125                 return False;
1126
1127         if(!smb_io_unihdr("unihdr", &sam->hdr_srv_name, ps, depth))     /* account name unicode string header */
1128                 return False;
1129         if(!smb_io_unihdr("unihdr", &sam->hdr_srv_desc, ps, depth))     /* account name unicode string header */
1130                 return False;
1131
1132         return True;
1133 }
1134
1135 /*******************************************************************
1136 reads or writes a SAM_STR3 structure.
1137 ********************************************************************/
1138
1139 static BOOL sam_io_sam_str3(const char *desc, SAM_STR3 * sam, uint32 acct_buf,
1140                             uint32 desc_buf, prs_struct *ps, int depth)
1141 {
1142         if (sam == NULL)
1143                 return False;
1144
1145         prs_debug(ps, depth, desc, "sam_io_sam_str3");
1146         depth++;
1147
1148         if(!prs_align(ps))
1149                 return False;
1150
1151         if(!smb_io_unistr2("uni_grp_name", &sam->uni_grp_name, acct_buf, ps, depth))    /* account name unicode string */
1152                 return False;
1153         if(!smb_io_unistr2("uni_grp_desc", &sam->uni_grp_desc, desc_buf, ps, depth))    /* account desc unicode string */
1154                 return False;
1155
1156         return True;
1157 }
1158
1159 /*******************************************************************
1160 inits a SAM_ENTRY3 structure.
1161 ********************************************************************/
1162
1163 static void init_sam_entry3(SAM_ENTRY3 * sam, uint32 grp_idx,
1164                             UNISTR2 *grp_name, UNISTR2 *grp_desc,
1165                             uint32 rid_grp)
1166 {
1167         DEBUG(5, ("init_sam_entry3\n"));
1168
1169         sam->grp_idx = grp_idx;
1170         sam->rid_grp = rid_grp;
1171         sam->attr = 0x07;       /* group rid attributes - gets ignored by nt 4.0 */
1172
1173         init_uni_hdr(&sam->hdr_grp_name, grp_name);
1174         init_uni_hdr(&sam->hdr_grp_desc, grp_desc);
1175 }
1176
1177 /*******************************************************************
1178 reads or writes a SAM_ENTRY3 structure.
1179 ********************************************************************/
1180
1181 static BOOL sam_io_sam_entry3(const char *desc, SAM_ENTRY3 * sam,
1182                               prs_struct *ps, int depth)
1183 {
1184         if (sam == NULL)
1185                 return False;
1186
1187         prs_debug(ps, depth, desc, "sam_io_sam_entry3");
1188         depth++;
1189
1190         if(!prs_align(ps))
1191                 return False;
1192
1193         if(!prs_uint32("grp_idx", ps, depth, &sam->grp_idx))
1194                 return False;
1195
1196         if(!prs_uint32("rid_grp", ps, depth, &sam->rid_grp))
1197                 return False;
1198         if(!prs_uint32("attr   ", ps, depth, &sam->attr))
1199                 return False;
1200
1201         if(!smb_io_unihdr("unihdr", &sam->hdr_grp_name, ps, depth))     /* account name unicode string header */
1202                 return False;
1203         if(!smb_io_unihdr("unihdr", &sam->hdr_grp_desc, ps, depth))     /* account name unicode string header */
1204                 return False;
1205
1206         return True;
1207 }
1208
1209 /*******************************************************************
1210 inits a SAM_ENTRY4 structure.
1211 ********************************************************************/
1212
1213 static void init_sam_entry4(SAM_ENTRY4 * sam, uint32 user_idx,
1214                             uint32 len_acct_name)
1215 {
1216         DEBUG(5, ("init_sam_entry4\n"));
1217
1218         sam->user_idx = user_idx;
1219         init_str_hdr(&sam->hdr_acct_name, len_acct_name+1, len_acct_name, len_acct_name != 0);
1220 }
1221
1222 /*******************************************************************
1223 reads or writes a SAM_ENTRY4 structure.
1224 ********************************************************************/
1225
1226 static BOOL sam_io_sam_entry4(const char *desc, SAM_ENTRY4 * sam,
1227                               prs_struct *ps, int depth)
1228 {
1229         if (sam == NULL)
1230                 return False;
1231
1232         prs_debug(ps, depth, desc, "sam_io_sam_entry4");
1233         depth++;
1234
1235         if(!prs_align(ps))
1236                 return False;
1237
1238         if(!prs_uint32("user_idx", ps, depth, &sam->user_idx))
1239                 return False;
1240         if(!smb_io_strhdr("strhdr", &sam->hdr_acct_name, ps, depth))
1241                 return False;
1242
1243         return True;
1244 }
1245
1246 /*******************************************************************
1247 inits a SAM_ENTRY5 structure.
1248 ********************************************************************/
1249
1250 static void init_sam_entry5(SAM_ENTRY5 * sam, uint32 grp_idx,
1251                             uint32 len_grp_name)
1252 {
1253         DEBUG(5, ("init_sam_entry5\n"));
1254
1255         sam->grp_idx = grp_idx;
1256         init_str_hdr(&sam->hdr_grp_name, len_grp_name, len_grp_name,
1257                      len_grp_name != 0);
1258 }
1259
1260 /*******************************************************************
1261 reads or writes a SAM_ENTRY5 structure.
1262 ********************************************************************/
1263
1264 static BOOL sam_io_sam_entry5(const char *desc, SAM_ENTRY5 * sam,
1265                               prs_struct *ps, int depth)
1266 {
1267         if (sam == NULL)
1268                 return False;
1269
1270         prs_debug(ps, depth, desc, "sam_io_sam_entry5");
1271         depth++;
1272
1273         if(!prs_align(ps))
1274                 return False;
1275
1276         if(!prs_uint32("grp_idx", ps, depth, &sam->grp_idx))
1277                 return False;
1278         if(!smb_io_strhdr("strhdr", &sam->hdr_grp_name, ps, depth))
1279                 return False;
1280
1281         return True;
1282 }
1283
1284 /*******************************************************************
1285 inits a SAM_ENTRY structure.
1286 ********************************************************************/
1287
1288 void init_sam_entry(SAM_ENTRY *sam, UNISTR2 *uni2, uint32 rid)
1289 {
1290         DEBUG(10, ("init_sam_entry: %d\n", rid));
1291
1292         sam->rid = rid;
1293         init_uni_hdr(&sam->hdr_name, uni2);
1294 }
1295
1296 /*******************************************************************
1297 reads or writes a SAM_ENTRY structure.
1298 ********************************************************************/
1299
1300 static BOOL sam_io_sam_entry(const char *desc, SAM_ENTRY * sam,
1301                              prs_struct *ps, int depth)
1302 {
1303         if (sam == NULL)
1304                 return False;
1305
1306         prs_debug(ps, depth, desc, "sam_io_sam_entry");
1307         depth++;
1308
1309         if(!prs_align(ps))
1310                 return False;
1311         if(!prs_uint32("rid", ps, depth, &sam->rid))
1312                 return False;
1313         if(!smb_io_unihdr("unihdr", &sam->hdr_name, ps, depth)) /* account name unicode string header */
1314                 return False;
1315
1316         return True;
1317 }
1318
1319 /*******************************************************************
1320 inits a SAMR_Q_ENUM_DOM_USERS structure.
1321 ********************************************************************/
1322
1323 void init_samr_q_enum_dom_users(SAMR_Q_ENUM_DOM_USERS * q_e, POLICY_HND *pol,
1324                                 uint32 start_idx,
1325                                 uint16 acb_mask, uint16 unk_1, uint32 size)
1326 {
1327         DEBUG(5, ("init_samr_q_enum_dom_users\n"));
1328
1329         q_e->pol = *pol;
1330
1331         q_e->start_idx = start_idx;     /* zero indicates lots */
1332         q_e->acb_mask = acb_mask;
1333         q_e->unknown_1 = unk_1;
1334         q_e->max_size = size;
1335 }
1336
1337 /*******************************************************************
1338 reads or writes a structure.
1339 ********************************************************************/
1340
1341 BOOL samr_io_q_enum_dom_users(const char *desc, SAMR_Q_ENUM_DOM_USERS * q_e,
1342                               prs_struct *ps, int depth)
1343 {
1344         if (q_e == NULL)
1345                 return False;
1346
1347         prs_debug(ps, depth, desc, "samr_io_q_enum_dom_users");
1348         depth++;
1349
1350         if(!prs_align(ps))
1351                 return False;
1352
1353         if(!smb_io_pol_hnd("domain_pol", &q_e->pol, ps, depth))
1354                 return False;
1355
1356         if(!prs_uint32("start_idx", ps, depth, &q_e->start_idx))
1357                 return False;
1358         if(!prs_uint16("acb_mask ", ps, depth, &q_e->acb_mask))
1359                 return False;
1360         if(!prs_uint16("unknown_1", ps, depth, &q_e->unknown_1))
1361                 return False;
1362
1363         if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
1364                 return False;
1365
1366         return True;
1367 }
1368
1369
1370 /*******************************************************************
1371 inits a SAMR_R_ENUM_DOM_USERS structure.
1372 ********************************************************************/
1373
1374 void init_samr_r_enum_dom_users(SAMR_R_ENUM_DOM_USERS * r_u,
1375                                 uint32 next_idx, uint32 num_sam_entries)
1376 {
1377         DEBUG(5, ("init_samr_r_enum_dom_users\n"));
1378
1379         r_u->next_idx = next_idx;
1380
1381         if (num_sam_entries != 0) {
1382                 r_u->ptr_entries1 = 1;
1383                 r_u->ptr_entries2 = 1;
1384                 r_u->num_entries2 = num_sam_entries;
1385                 r_u->num_entries3 = num_sam_entries;
1386
1387                 r_u->num_entries4 = num_sam_entries;
1388         } else {
1389                 r_u->ptr_entries1 = 0;
1390                 r_u->num_entries2 = num_sam_entries;
1391                 r_u->ptr_entries2 = 1;
1392         }
1393 }
1394
1395 /*******************************************************************
1396 reads or writes a structure.
1397 ********************************************************************/
1398
1399 BOOL samr_io_r_enum_dom_users(const char *desc, SAMR_R_ENUM_DOM_USERS * r_u,
1400                               prs_struct *ps, int depth)
1401 {
1402         uint32 i;
1403
1404         if (r_u == NULL)
1405                 return False;
1406
1407         prs_debug(ps, depth, desc, "samr_io_r_enum_dom_users");
1408         depth++;
1409
1410         if(!prs_align(ps))
1411                 return False;
1412
1413         if(!prs_uint32("next_idx    ", ps, depth, &r_u->next_idx))
1414                 return False;
1415         if(!prs_uint32("ptr_entries1", ps, depth, &r_u->ptr_entries1))
1416                 return False;
1417
1418         if (r_u->ptr_entries1 != 0) {
1419                 if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
1420                         return False;
1421                 if(!prs_uint32("ptr_entries2", ps, depth, &r_u->ptr_entries2))
1422                         return False;
1423                 if(!prs_uint32("num_entries3", ps, depth, &r_u->num_entries3))
1424                         return False;
1425
1426                 if (UNMARSHALLING(ps) && (r_u->num_entries2 != 0)) {
1427                         r_u->sam = PRS_ALLOC_MEM(ps,SAM_ENTRY, r_u->num_entries2);
1428                         r_u->uni_acct_name = PRS_ALLOC_MEM(ps,UNISTR2, r_u->num_entries2);
1429                 }
1430
1431                 if ((r_u->sam == NULL || r_u->uni_acct_name == NULL) && r_u->num_entries2 != 0) {
1432                         DEBUG(0,("NULL pointers in SAMR_R_ENUM_DOM_USERS\n"));
1433                         r_u->num_entries4 = 0;
1434                         r_u->status = NT_STATUS_MEMORY_NOT_ALLOCATED;
1435                         return False;
1436                 }
1437
1438                 for (i = 0; i < r_u->num_entries2; i++) {
1439                         if(!sam_io_sam_entry("", &r_u->sam[i], ps, depth))
1440                                 return False;
1441                 }
1442
1443                 for (i = 0; i < r_u->num_entries2; i++) {
1444                         if(!smb_io_unistr2("", &r_u->uni_acct_name[i],r_u->sam[i].hdr_name.buffer, ps,depth))
1445                                 return False;
1446                 }
1447
1448         }
1449
1450         if(!prs_align(ps))
1451                 return False;
1452                 
1453         if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4))
1454                 return False;
1455         if(!prs_ntstatus("status", ps, depth, &r_u->status))
1456                 return False;
1457
1458         return True;
1459 }
1460
1461 /*******************************************************************
1462 inits a SAMR_Q_QUERY_DISPINFO structure.
1463 ********************************************************************/
1464
1465 void init_samr_q_query_dispinfo(SAMR_Q_QUERY_DISPINFO * q_e, POLICY_HND *pol,
1466                                 uint16 switch_level, uint32 start_idx,
1467                                 uint32 max_entries, uint32 max_size)
1468 {
1469         DEBUG(5, ("init_samr_q_query_dispinfo\n"));
1470
1471         q_e->domain_pol = *pol;
1472
1473         q_e->switch_level = switch_level;
1474
1475         q_e->start_idx = start_idx;
1476         q_e->max_entries = max_entries;
1477         q_e->max_size = max_size;
1478 }
1479
1480 /*******************************************************************
1481 reads or writes a structure.
1482 ********************************************************************/
1483
1484 BOOL samr_io_q_query_dispinfo(const char *desc, SAMR_Q_QUERY_DISPINFO * q_e,
1485                               prs_struct *ps, int depth)
1486 {
1487         if (q_e == NULL)
1488                 return False;
1489
1490         prs_debug(ps, depth, desc, "samr_io_q_query_dispinfo");
1491         depth++;
1492
1493         if(!prs_align(ps))
1494                 return False;
1495
1496         if(!smb_io_pol_hnd("domain_pol", &q_e->domain_pol, ps, depth))
1497                 return False;
1498
1499         if(!prs_uint16("switch_level", ps, depth, &q_e->switch_level))
1500                 return False;
1501         if(!prs_align(ps))
1502                 return False;
1503
1504         if(!prs_uint32("start_idx   ", ps, depth, &q_e->start_idx))
1505                 return False;
1506         if(!prs_uint32("max_entries ", ps, depth, &q_e->max_entries))
1507                 return False;
1508         if(!prs_uint32("max_size    ", ps, depth, &q_e->max_size))
1509                 return False;
1510
1511         return True;
1512 }
1513
1514 /*******************************************************************
1515 inits a SAM_DISPINFO_1 structure.
1516 ********************************************************************/
1517
1518 NTSTATUS init_sam_dispinfo_1(TALLOC_CTX *ctx, SAM_DISPINFO_1 **sam,
1519                              uint32 num_entries, uint32 start_idx,
1520                              struct samr_displayentry *entries)
1521 {
1522         uint32 i;
1523
1524         DEBUG(10, ("init_sam_dispinfo_1: num_entries: %d\n", num_entries));
1525
1526         if (num_entries==0)
1527                 return NT_STATUS_OK;
1528
1529         *sam = TALLOC_ZERO_ARRAY(ctx, SAM_DISPINFO_1, num_entries);
1530         if (*sam == NULL)
1531                 return NT_STATUS_NO_MEMORY;
1532
1533         (*sam)->sam=TALLOC_ARRAY(ctx, SAM_ENTRY1, num_entries);
1534         if ((*sam)->sam == NULL)
1535                 return NT_STATUS_NO_MEMORY;
1536
1537         (*sam)->str=TALLOC_ARRAY(ctx, SAM_STR1, num_entries);
1538         if ((*sam)->str == NULL)
1539                 return NT_STATUS_NO_MEMORY;
1540
1541         for (i = 0; i < num_entries ; i++) {
1542                 init_unistr2(&(*sam)->str[i].uni_acct_name,
1543                              entries[i].account_name, UNI_FLAGS_NONE);
1544                 init_unistr2(&(*sam)->str[i].uni_full_name,
1545                              entries[i].fullname, UNI_FLAGS_NONE);
1546                 init_unistr2(&(*sam)->str[i].uni_acct_desc,
1547                              entries[i].description, UNI_FLAGS_NONE);
1548
1549                 init_sam_entry1(&(*sam)->sam[i], start_idx+i+1,
1550                                 &(*sam)->str[i].uni_acct_name,
1551                                 &(*sam)->str[i].uni_full_name,
1552                                 &(*sam)->str[i].uni_acct_desc,
1553                                 entries[i].rid, entries[i].acct_flags);
1554         }
1555
1556         return NT_STATUS_OK;
1557 }
1558
1559 /*******************************************************************
1560 reads or writes a structure.
1561 ********************************************************************/
1562
1563 static BOOL sam_io_sam_dispinfo_1(const char *desc, SAM_DISPINFO_1 * sam,
1564                                   uint32 num_entries,
1565                                   prs_struct *ps, int depth)
1566 {
1567         uint32 i;
1568
1569         prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_1");
1570         depth++;
1571
1572         if(!prs_align(ps))
1573                 return False;
1574
1575         if (UNMARSHALLING(ps) && num_entries > 0) {
1576
1577                 if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY1, num_entries)) == NULL) {
1578                         DEBUG(0, ("out of memory allocating SAM_ENTRY1\n"));
1579                         return False;
1580                 }
1581
1582                 if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR1, num_entries)) == NULL) {
1583                         DEBUG(0, ("out of memory allocating SAM_STR1\n"));
1584                         return False;
1585                 }
1586         }
1587
1588         for (i = 0; i < num_entries; i++) {
1589                 if(!sam_io_sam_entry1("", &sam->sam[i], ps, depth))
1590                         return False;
1591         }
1592
1593         for (i = 0; i < num_entries; i++) {
1594                 if(!sam_io_sam_str1("", &sam->str[i],
1595                               sam->sam[i].hdr_acct_name.buffer,
1596                               sam->sam[i].hdr_user_name.buffer,
1597                               sam->sam[i].hdr_user_desc.buffer, ps, depth))
1598                         return False;
1599         }
1600
1601         return True;
1602 }
1603
1604 /*******************************************************************
1605 inits a SAM_DISPINFO_2 structure.
1606 ********************************************************************/
1607
1608 NTSTATUS init_sam_dispinfo_2(TALLOC_CTX *ctx, SAM_DISPINFO_2 **sam,
1609                              uint32 num_entries, uint32 start_idx,
1610                              struct samr_displayentry *entries)
1611 {
1612         uint32 i;
1613
1614         DEBUG(10, ("init_sam_dispinfo_2: num_entries: %d\n", num_entries));
1615
1616         if (num_entries==0)
1617                 return NT_STATUS_OK;
1618
1619         *sam = TALLOC_ZERO_ARRAY(ctx, SAM_DISPINFO_2, num_entries);
1620         if (*sam == NULL)
1621                 return NT_STATUS_NO_MEMORY;
1622
1623         (*sam)->sam = TALLOC_ARRAY(ctx, SAM_ENTRY2, num_entries);
1624         if ((*sam)->sam == NULL)
1625                 return NT_STATUS_NO_MEMORY;
1626
1627         (*sam)->str=TALLOC_ARRAY(ctx, SAM_STR2, num_entries);
1628         if ((*sam)->str == NULL)
1629                 return NT_STATUS_NO_MEMORY;
1630
1631         for (i = 0; i < num_entries; i++) {
1632                 init_unistr2(&(*sam)->str[i].uni_srv_name,
1633                              entries[i].account_name, UNI_FLAGS_NONE);
1634                 init_unistr2(&(*sam)->str[i].uni_srv_desc,
1635                              entries[i].description, UNI_FLAGS_NONE);
1636
1637                 init_sam_entry2(&(*sam)->sam[i], start_idx + i + 1,
1638                                 &(*sam)->str[i].uni_srv_name,
1639                                 &(*sam)->str[i].uni_srv_desc,
1640                                 entries[i].rid, entries[i].acct_flags);
1641         }
1642
1643         return NT_STATUS_OK;
1644 }
1645
1646 /*******************************************************************
1647 reads or writes a structure.
1648 ********************************************************************/
1649
1650 static BOOL sam_io_sam_dispinfo_2(const char *desc, SAM_DISPINFO_2 * sam,
1651                                   uint32 num_entries,
1652                                   prs_struct *ps, int depth)
1653 {
1654         uint32 i;
1655
1656         if (sam == NULL)
1657                 return False;
1658
1659         prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_2");
1660         depth++;
1661
1662         if(!prs_align(ps))
1663                 return False;
1664
1665         if (UNMARSHALLING(ps) && num_entries > 0) {
1666
1667                 if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY2, num_entries)) == NULL) {
1668                         DEBUG(0, ("out of memory allocating SAM_ENTRY2\n"));
1669                         return False;
1670                 }
1671
1672                 if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR2, num_entries)) == NULL) {
1673                         DEBUG(0, ("out of memory allocating SAM_STR2\n"));
1674                         return False;
1675                 }
1676         }
1677
1678         for (i = 0; i < num_entries; i++) {
1679                 if(!sam_io_sam_entry2("", &sam->sam[i], ps, depth))
1680                         return False;
1681         }
1682
1683         for (i = 0; i < num_entries; i++) {
1684                 if(!sam_io_sam_str2("", &sam->str[i],
1685                               sam->sam[i].hdr_srv_name.buffer,
1686                               sam->sam[i].hdr_srv_desc.buffer, ps, depth))
1687                         return False;
1688         }
1689
1690         return True;
1691 }
1692
1693 /*******************************************************************
1694 inits a SAM_DISPINFO_3 structure.
1695 ********************************************************************/
1696
1697 NTSTATUS init_sam_dispinfo_3(TALLOC_CTX *ctx, SAM_DISPINFO_3 **sam,
1698                              uint32 num_entries, uint32 start_idx,
1699                              struct samr_displayentry *entries)
1700 {
1701         uint32 i;
1702
1703         DEBUG(5, ("init_sam_dispinfo_3: num_entries: %d\n", num_entries));
1704
1705         if (num_entries==0)
1706                 return NT_STATUS_OK;
1707
1708         *sam = TALLOC_ZERO_ARRAY(ctx, SAM_DISPINFO_3, num_entries);
1709         if (*sam == NULL)
1710                 return NT_STATUS_NO_MEMORY;
1711
1712         if (!((*sam)->sam=TALLOC_ARRAY(ctx, SAM_ENTRY3, num_entries)))
1713                 return NT_STATUS_NO_MEMORY;
1714
1715         if (!((*sam)->str=TALLOC_ARRAY(ctx, SAM_STR3, num_entries)))
1716                 return NT_STATUS_NO_MEMORY;
1717
1718         for (i = 0; i < num_entries; i++) {
1719                 DEBUG(11, ("init_sam_dispinfo_3: entry: %d\n",i));
1720
1721                 init_unistr2(&(*sam)->str[i].uni_grp_name,
1722                              entries[i].account_name, UNI_FLAGS_NONE);
1723                 init_unistr2(&(*sam)->str[i].uni_grp_desc,
1724                              entries[i].description, UNI_FLAGS_NONE);
1725
1726                 init_sam_entry3(&(*sam)->sam[i], start_idx+i+1,
1727                                 &(*sam)->str[i].uni_grp_name,
1728                                 &(*sam)->str[i].uni_grp_desc,
1729                                 entries[i].rid);
1730         }
1731
1732         return NT_STATUS_OK;
1733 }
1734
1735 /*******************************************************************
1736 reads or writes a structure.
1737 ********************************************************************/
1738
1739 static BOOL sam_io_sam_dispinfo_3(const char *desc, SAM_DISPINFO_3 * sam,
1740                                   uint32 num_entries,
1741                                   prs_struct *ps, int depth)
1742 {
1743         uint32 i;
1744
1745         if (sam == NULL)
1746                 return False;
1747
1748         prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_3");
1749         depth++;
1750
1751         if(!prs_align(ps))
1752                 return False;
1753
1754         if (UNMARSHALLING(ps) && num_entries > 0) {
1755
1756                 if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY3, num_entries)) == NULL) {
1757                         DEBUG(0, ("out of memory allocating SAM_ENTRY3\n"));
1758                         return False;
1759                 }
1760
1761                 if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR3, num_entries)) == NULL) {
1762                         DEBUG(0, ("out of memory allocating SAM_STR3\n"));
1763                         return False;
1764                 }
1765         }
1766
1767         for (i = 0; i < num_entries; i++) {
1768                 if(!sam_io_sam_entry3("", &sam->sam[i], ps, depth))
1769                         return False;
1770         }
1771
1772         for (i = 0; i < num_entries; i++) {
1773                 if(!sam_io_sam_str3("", &sam->str[i],
1774                               sam->sam[i].hdr_grp_name.buffer,
1775                               sam->sam[i].hdr_grp_desc.buffer, ps, depth))
1776                         return False;
1777         }
1778
1779         return True;
1780 }
1781
1782 /*******************************************************************
1783 inits a SAM_DISPINFO_4 structure.
1784 ********************************************************************/
1785
1786 NTSTATUS init_sam_dispinfo_4(TALLOC_CTX *ctx, SAM_DISPINFO_4 **sam,
1787                              uint32 num_entries, uint32 start_idx,
1788                              struct samr_displayentry *entries)
1789 {
1790         uint32 i;
1791
1792         DEBUG(5, ("init_sam_dispinfo_4: num_entries: %d\n", num_entries));
1793
1794         if (num_entries==0)
1795                 return NT_STATUS_OK;
1796
1797         *sam = TALLOC_ZERO_ARRAY(ctx, SAM_DISPINFO_4, num_entries);
1798         if (*sam == NULL)
1799                 return NT_STATUS_NO_MEMORY;
1800
1801         (*sam)->sam = TALLOC_ARRAY(ctx, SAM_ENTRY4, num_entries);
1802         if ((*sam)->sam == NULL)
1803                 return NT_STATUS_NO_MEMORY;
1804
1805         (*sam)->str=TALLOC_ARRAY(ctx, SAM_STR4, num_entries);
1806         if ((*sam)->str == NULL)
1807                 return NT_STATUS_NO_MEMORY;
1808
1809         for (i = 0; i < num_entries; i++) {
1810                 size_t len_sam_name = strlen(entries[i].account_name);
1811
1812                 DEBUG(11, ("init_sam_dispinfo_2: entry: %d\n",i));
1813           
1814                 init_sam_entry4(&(*sam)->sam[i], start_idx + i + 1,
1815                                 len_sam_name);
1816
1817                 init_string2(&(*sam)->str[i].acct_name,
1818                              entries[i].account_name, len_sam_name+1,
1819                              len_sam_name);
1820         }
1821         
1822         return NT_STATUS_OK;
1823 }
1824
1825 /*******************************************************************
1826 reads or writes a structure.
1827 ********************************************************************/
1828
1829 static BOOL sam_io_sam_dispinfo_4(const char *desc, SAM_DISPINFO_4 * sam,
1830                                   uint32 num_entries,
1831                                   prs_struct *ps, int depth)
1832 {
1833         uint32 i;
1834
1835         if (sam == NULL)
1836                 return False;
1837
1838         prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_4");
1839         depth++;
1840
1841         if(!prs_align(ps))
1842                 return False;
1843
1844         if (UNMARSHALLING(ps) && num_entries > 0) {
1845
1846                 if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY4, num_entries)) == NULL) {
1847                         DEBUG(0, ("out of memory allocating SAM_ENTRY4\n"));
1848                         return False;
1849                 }
1850
1851                 if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR4, num_entries)) == NULL) {
1852                         DEBUG(0, ("out of memory allocating SAM_STR4\n"));
1853                         return False;
1854                 }
1855         }
1856
1857         for (i = 0; i < num_entries; i++) {
1858                 if(!sam_io_sam_entry4("", &sam->sam[i], ps, depth))
1859                         return False;
1860         }
1861
1862         for (i = 0; i < num_entries; i++) {
1863                 if(!smb_io_string2("acct_name", &sam->str[i].acct_name,
1864                              sam->sam[i].hdr_acct_name.buffer, ps, depth))
1865                         return False;
1866         }
1867
1868         return True;
1869 }
1870
1871 /*******************************************************************
1872 inits a SAM_DISPINFO_5 structure.
1873 ********************************************************************/
1874
1875 NTSTATUS init_sam_dispinfo_5(TALLOC_CTX *ctx, SAM_DISPINFO_5 **sam,
1876                              uint32 num_entries, uint32 start_idx,
1877                              struct samr_displayentry *entries)
1878 {
1879         uint32 len_sam_name;
1880         uint32 i;
1881
1882         DEBUG(5, ("init_sam_dispinfo_5: num_entries: %d\n", num_entries));
1883
1884         if (num_entries==0)
1885                 return NT_STATUS_OK;
1886
1887         *sam = TALLOC_ZERO_ARRAY(ctx, SAM_DISPINFO_5, num_entries);
1888         if (*sam == NULL)
1889                 return NT_STATUS_NO_MEMORY;
1890
1891         if (!((*sam)->sam=TALLOC_ARRAY(ctx, SAM_ENTRY5, num_entries)))
1892                 return NT_STATUS_NO_MEMORY;
1893
1894         if (!((*sam)->str=TALLOC_ARRAY(ctx, SAM_STR5, num_entries)))
1895                 return NT_STATUS_NO_MEMORY;
1896
1897         for (i = 0; i < num_entries; i++) {
1898                 DEBUG(11, ("init_sam_dispinfo_5: entry: %d\n",i));
1899
1900                 len_sam_name = strlen(entries[i].account_name);
1901           
1902                 init_sam_entry5(&(*sam)->sam[i], start_idx+i+1, len_sam_name);
1903                 init_string2(&(*sam)->str[i].grp_name, entries[i].account_name,
1904                              len_sam_name+1, len_sam_name);
1905         }
1906
1907         return NT_STATUS_OK;
1908 }
1909
1910 /*******************************************************************
1911 reads or writes a structure.
1912 ********************************************************************/
1913
1914 static BOOL sam_io_sam_dispinfo_5(const char *desc, SAM_DISPINFO_5 * sam,
1915                                   uint32 num_entries,
1916                                   prs_struct *ps, int depth)
1917 {
1918         uint32 i;
1919
1920         if (sam == NULL)
1921                 return False;
1922
1923         prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_5");
1924         depth++;
1925
1926         if(!prs_align(ps))
1927                 return False;
1928
1929         if (UNMARSHALLING(ps) && num_entries > 0) {
1930
1931                 if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY5, num_entries)) == NULL) {
1932                         DEBUG(0, ("out of memory allocating SAM_ENTRY5\n"));
1933                         return False;
1934                 }
1935
1936                 if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR5, num_entries)) == NULL) {
1937                         DEBUG(0, ("out of memory allocating SAM_STR5\n"));
1938                         return False;
1939                 }
1940         }
1941
1942         for (i = 0; i < num_entries; i++) {
1943                 if(!sam_io_sam_entry5("", &sam->sam[i], ps, depth))
1944                         return False;
1945         }
1946
1947         for (i = 0; i < num_entries; i++) {
1948                 if(!smb_io_string2("grp_name", &sam->str[i].grp_name,
1949                              sam->sam[i].hdr_grp_name.buffer, ps, depth))
1950                         return False;
1951         }
1952
1953         return True;
1954 }
1955
1956 /*******************************************************************
1957 inits a SAMR_R_QUERY_DISPINFO structure.
1958 ********************************************************************/
1959
1960 void init_samr_r_query_dispinfo(SAMR_R_QUERY_DISPINFO * r_u,
1961                                 uint32 num_entries, uint32 total_size, uint32 data_size,
1962                                 uint16 switch_level, SAM_DISPINFO_CTR * ctr,
1963                                 NTSTATUS status)
1964 {
1965         DEBUG(5, ("init_samr_r_query_dispinfo: level %d\n", switch_level));
1966
1967         r_u->total_size = total_size;
1968
1969         r_u->data_size = data_size;
1970
1971         r_u->switch_level = switch_level;
1972         r_u->num_entries = num_entries;
1973
1974         if (num_entries==0)
1975                 r_u->ptr_entries = 0;
1976         else
1977                 r_u->ptr_entries = 1;
1978
1979         r_u->num_entries2 = num_entries;
1980         r_u->ctr = ctr;
1981
1982         r_u->status = status;
1983 }
1984
1985 /*******************************************************************
1986 reads or writes a structure.
1987 ********************************************************************/
1988
1989 BOOL samr_io_r_query_dispinfo(const char *desc, SAMR_R_QUERY_DISPINFO * r_u,
1990                               prs_struct *ps, int depth)
1991 {
1992         if (r_u == NULL)
1993                 return False;
1994
1995         prs_debug(ps, depth, desc, "samr_io_r_query_dispinfo");
1996         depth++;
1997
1998         if(!prs_align(ps))
1999                 return False;
2000
2001         if(!prs_uint32("total_size  ", ps, depth, &r_u->total_size))
2002                 return False;
2003         if(!prs_uint32("data_size   ", ps, depth, &r_u->data_size))
2004                 return False;
2005         if(!prs_uint16("switch_level", ps, depth, &r_u->switch_level))
2006                 return False;
2007         if(!prs_align(ps))
2008                 return False;
2009
2010         if(!prs_uint32("num_entries ", ps, depth, &r_u->num_entries))
2011                 return False;
2012         if(!prs_uint32("ptr_entries ", ps, depth, &r_u->ptr_entries))
2013                 return False;
2014
2015         if (r_u->ptr_entries==0) {
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         if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
2025                 return False;
2026
2027         switch (r_u->switch_level) {
2028         case 0x1:
2029                 if(!sam_io_sam_dispinfo_1("users", r_u->ctr->sam.info1,
2030                                 r_u->num_entries, ps, depth))
2031                         return False;
2032                 break;
2033         case 0x2:
2034                 if(!sam_io_sam_dispinfo_2("servers", r_u->ctr->sam.info2,
2035                                 r_u->num_entries, ps, depth))
2036                         return False;
2037                 break;
2038         case 0x3:
2039                 if(!sam_io_sam_dispinfo_3("groups", r_u->ctr->sam.info3,
2040                                     r_u->num_entries, ps, depth))
2041                         return False;
2042                 break;
2043         case 0x4:
2044                 if(!sam_io_sam_dispinfo_4("user list",
2045                                     r_u->ctr->sam.info4,
2046                                     r_u->num_entries, ps, depth))
2047                         return False;
2048                 break;
2049         case 0x5:
2050                 if(!sam_io_sam_dispinfo_5("group list",
2051                                     r_u->ctr->sam.info5,
2052                                     r_u->num_entries, ps, depth))
2053                         return False;
2054                 break;
2055         default:
2056                 DEBUG(0,("samr_io_r_query_dispinfo: unknown switch value\n"));
2057                 break;
2058         }
2059         
2060         if(!prs_align(ps))
2061                 return False;
2062         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2063                 return False;
2064
2065         return True;
2066 }
2067
2068 /*******************************************************************
2069 inits a SAMR_Q_OPEN_GROUP structure.
2070 ********************************************************************/
2071
2072 void init_samr_q_open_group(SAMR_Q_OPEN_GROUP * q_c,
2073                             POLICY_HND *hnd,
2074                             uint32 access_mask, uint32 rid)
2075 {
2076         DEBUG(5, ("init_samr_q_open_group\n"));
2077
2078         q_c->domain_pol = *hnd;
2079         q_c->access_mask = access_mask;
2080         q_c->rid_group = rid;
2081 }
2082
2083 /*******************************************************************
2084 reads or writes a structure.
2085 ********************************************************************/
2086
2087 BOOL samr_io_q_open_group(const char *desc, SAMR_Q_OPEN_GROUP * q_u,
2088                           prs_struct *ps, int depth)
2089 {
2090         if (q_u == NULL)
2091                 return False;
2092
2093         prs_debug(ps, depth, desc, "samr_io_q_open_group");
2094         depth++;
2095
2096         if(!prs_align(ps))
2097                 return False;
2098
2099         if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
2100                 return False;
2101
2102         if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
2103                 return False;
2104         if(!prs_uint32("rid_group", ps, depth, &q_u->rid_group))
2105                 return False;
2106
2107         return True;
2108 }
2109
2110 /*******************************************************************
2111 reads or writes a structure.
2112 ********************************************************************/
2113
2114 BOOL samr_io_r_open_group(const char *desc, SAMR_R_OPEN_GROUP * r_u,
2115                           prs_struct *ps, int depth)
2116 {
2117         if (r_u == NULL)
2118                 return False;
2119
2120         prs_debug(ps, depth, desc, "samr_io_r_open_group");
2121         depth++;
2122
2123         if(!prs_align(ps))
2124                 return False;
2125
2126         if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
2127                 return False;
2128
2129         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2130                 return False;
2131
2132         return True;
2133 }
2134
2135 /*******************************************************************
2136 inits a GROUP_INFO1 structure.
2137 ********************************************************************/
2138
2139 void init_samr_group_info1(GROUP_INFO1 * gr1,
2140                            char *acct_name, char *acct_desc,
2141                            uint32 num_members)
2142 {
2143         DEBUG(5, ("init_samr_group_info1\n"));
2144
2145         gr1->group_attr = (SE_GROUP_MANDATORY|SE_GROUP_ENABLED_BY_DEFAULT); /* why not | SE_GROUP_ENABLED ? */
2146         gr1->num_members = num_members;
2147
2148         init_unistr2(&gr1->uni_acct_name, acct_name, UNI_FLAGS_NONE);
2149         init_uni_hdr(&gr1->hdr_acct_name, &gr1->uni_acct_name);
2150         init_unistr2(&gr1->uni_acct_desc, acct_desc, UNI_FLAGS_NONE);
2151         init_uni_hdr(&gr1->hdr_acct_desc, &gr1->uni_acct_desc);
2152 }
2153
2154 /*******************************************************************
2155 reads or writes a structure.
2156 ********************************************************************/
2157
2158 BOOL samr_io_group_info1(const char *desc, GROUP_INFO1 * gr1,
2159                          prs_struct *ps, int depth)
2160 {
2161         uint16 dummy = 1;
2162
2163         if (gr1 == NULL)
2164                 return False;
2165
2166         prs_debug(ps, depth, desc, "samr_io_group_info1");
2167         depth++;
2168
2169         if(!prs_uint16("level", ps, depth, &dummy))
2170                 return False;
2171
2172         if(!prs_align(ps))
2173                 return False;
2174
2175         if(!smb_io_unihdr("hdr_acct_name", &gr1->hdr_acct_name, ps, depth))
2176                 return False;
2177
2178         if(!prs_uint32("group_attr", ps, depth, &gr1->group_attr))
2179                 return False;
2180         if(!prs_uint32("num_members", ps, depth, &gr1->num_members))
2181                 return False;
2182
2183         if(!smb_io_unihdr("hdr_acct_desc", &gr1->hdr_acct_desc, ps, depth))
2184                 return False;
2185
2186         if(!smb_io_unistr2("uni_acct_name", &gr1->uni_acct_name,
2187                            gr1->hdr_acct_name.buffer, ps, depth))
2188                 return False;
2189
2190         if(!smb_io_unistr2("uni_acct_desc", &gr1->uni_acct_desc,
2191                            gr1->hdr_acct_desc.buffer, ps, depth))
2192                 return False;
2193
2194         return True;
2195 }
2196
2197 /*******************************************************************
2198 inits a GROUP_INFO2 structure.
2199 ********************************************************************/
2200
2201 void init_samr_group_info2(GROUP_INFO2 * gr2, const char *acct_name)
2202 {
2203         DEBUG(5, ("init_samr_group_info2\n"));
2204
2205         gr2->level = 2;
2206         init_unistr2(&gr2->uni_acct_name, acct_name, UNI_FLAGS_NONE);
2207         init_uni_hdr(&gr2->hdr_acct_name, &gr2->uni_acct_name);
2208 }
2209
2210 /*******************************************************************
2211 reads or writes a structure.
2212 ********************************************************************/
2213
2214 BOOL samr_io_group_info2(const char *desc, GROUP_INFO2 *gr2, prs_struct *ps, int depth)
2215 {
2216         if (gr2 == NULL)
2217                 return False;
2218
2219         prs_debug(ps, depth, desc, "samr_io_group_info2");
2220         depth++;
2221
2222         if(!prs_uint16("hdr_level", ps, depth, &gr2->level))
2223                 return False;
2224
2225         if(!smb_io_unihdr("hdr_acct_name", &gr2->hdr_acct_name, ps, depth))
2226                 return False;
2227         if(!smb_io_unistr2("uni_acct_name", &gr2->uni_acct_name,
2228                            gr2->hdr_acct_name.buffer, ps, depth))
2229                 return False;
2230
2231         return True;
2232 }
2233
2234 /*******************************************************************
2235 inits a GROUP_INFO3 structure.
2236 ********************************************************************/
2237
2238 void init_samr_group_info3(GROUP_INFO3 *gr3)
2239 {
2240         DEBUG(5, ("init_samr_group_info3\n"));
2241
2242         gr3->group_attr = (SE_GROUP_MANDATORY|SE_GROUP_ENABLED_BY_DEFAULT); /* why not | SE_GROUP_ENABLED ? */
2243 }
2244
2245 /*******************************************************************
2246 reads or writes a structure.
2247 ********************************************************************/
2248
2249 BOOL samr_io_group_info3(const char *desc, GROUP_INFO3 *gr3, prs_struct *ps, int depth)
2250 {
2251         if (gr3 == NULL)
2252                 return False;
2253
2254         prs_debug(ps, depth, desc, "samr_io_group_info3");
2255         depth++;
2256
2257         if(!prs_align(ps))
2258                 return False;
2259
2260         if(!prs_uint32("group_attr", ps, depth, &gr3->group_attr))
2261                 return False;
2262
2263         return True;
2264 }
2265
2266 /*******************************************************************
2267 inits a GROUP_INFO4 structure.
2268 ********************************************************************/
2269
2270 void init_samr_group_info4(GROUP_INFO4 * gr4, const char *acct_desc)
2271 {
2272         DEBUG(5, ("init_samr_group_info4\n"));
2273
2274         gr4->level = 4;
2275         init_unistr2(&gr4->uni_acct_desc, acct_desc, UNI_FLAGS_NONE);
2276         init_uni_hdr(&gr4->hdr_acct_desc, &gr4->uni_acct_desc);
2277 }
2278
2279 /*******************************************************************
2280 reads or writes a structure.
2281 ********************************************************************/
2282
2283 BOOL samr_io_group_info4(const char *desc, GROUP_INFO4 * gr4,
2284                          prs_struct *ps, int depth)
2285 {
2286         if (gr4 == NULL)
2287                 return False;
2288
2289         prs_debug(ps, depth, desc, "samr_io_group_info4");
2290         depth++;
2291
2292         if(!prs_uint16("hdr_level", ps, depth, &gr4->level))
2293                 return False;
2294         if(!smb_io_unihdr("hdr_acct_desc", &gr4->hdr_acct_desc, ps, depth))
2295                 return False;
2296         if(!smb_io_unistr2("uni_acct_desc", &gr4->uni_acct_desc,
2297                            gr4->hdr_acct_desc.buffer, ps, depth))
2298                 return False;
2299
2300         return True;
2301 }
2302
2303 /*******************************************************************
2304 reads or writes a structure.
2305 ********************************************************************/
2306
2307 static BOOL samr_group_info_ctr(const char *desc, GROUP_INFO_CTR **ctr,
2308                                 prs_struct *ps, int depth)
2309 {
2310         if (UNMARSHALLING(ps))
2311                 *ctr = PRS_ALLOC_MEM(ps,GROUP_INFO_CTR,1);
2312
2313         if (*ctr == NULL)
2314                 return False;
2315
2316         prs_debug(ps, depth, desc, "samr_group_info_ctr");
2317         depth++;
2318
2319         if(!prs_uint16("switch_value1", ps, depth, &(*ctr)->switch_value1))
2320                 return False;
2321
2322         switch ((*ctr)->switch_value1) {
2323         case 1:
2324                 if(!samr_io_group_info1("group_info1", &(*ctr)->group.info1, ps, depth))
2325                         return False;
2326                 break;
2327         case 2:
2328                 if(!samr_io_group_info2("group_info2", &(*ctr)->group.info2, ps, depth))
2329                         return False;
2330                 break;
2331         case 3:
2332                 if(!samr_io_group_info3("group_info3", &(*ctr)->group.info3, ps, depth))
2333                         return False;
2334                 break;
2335         case 4:
2336                 if(!samr_io_group_info4("group_info4", &(*ctr)->group.info4, ps, depth))
2337                         return False;
2338                 break;
2339         default:
2340                 DEBUG(0,("samr_group_info_ctr: unsupported switch level\n"));
2341                 break;
2342         }
2343
2344         return True;
2345 }
2346
2347 /*******************************************************************
2348 inits a SAMR_Q_CREATE_DOM_GROUP structure.
2349 ********************************************************************/
2350
2351 void init_samr_q_create_dom_group(SAMR_Q_CREATE_DOM_GROUP * q_e,
2352                                   POLICY_HND *pol, const char *acct_desc,
2353                                   uint32 access_mask)
2354 {
2355         DEBUG(5, ("init_samr_q_create_dom_group\n"));
2356
2357         q_e->pol = *pol;
2358
2359         init_unistr2(&q_e->uni_acct_desc, acct_desc, UNI_FLAGS_NONE);
2360         init_uni_hdr(&q_e->hdr_acct_desc, &q_e->uni_acct_desc);
2361
2362         q_e->access_mask = access_mask;
2363 }
2364
2365 /*******************************************************************
2366 reads or writes a structure.
2367 ********************************************************************/
2368
2369 BOOL samr_io_q_create_dom_group(const char *desc, SAMR_Q_CREATE_DOM_GROUP * q_e,
2370                                 prs_struct *ps, int depth)
2371 {
2372         if (q_e == NULL)
2373                 return False;
2374
2375         prs_debug(ps, depth, desc, "samr_io_q_create_dom_group");
2376         depth++;
2377
2378         if(!prs_align(ps))
2379                 return False;
2380
2381         if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
2382                 return False;
2383
2384         if(!smb_io_unihdr("hdr_acct_desc", &q_e->hdr_acct_desc, ps, depth))
2385                 return False;
2386         if(!smb_io_unistr2("uni_acct_desc", &q_e->uni_acct_desc,
2387                        q_e->hdr_acct_desc.buffer, ps, depth))
2388                 return False;
2389
2390         if(!prs_align(ps))
2391                 return False;
2392         if(!prs_uint32("access", ps, depth, &q_e->access_mask))
2393                 return False;
2394
2395         return True;
2396 }
2397
2398 /*******************************************************************
2399 reads or writes a structure.
2400 ********************************************************************/
2401
2402 BOOL samr_io_r_create_dom_group(const char *desc, SAMR_R_CREATE_DOM_GROUP * r_u,
2403                                 prs_struct *ps, int depth)
2404 {
2405         if (r_u == NULL)
2406                 return False;
2407
2408         prs_debug(ps, depth, desc, "samr_io_r_create_dom_group");
2409         depth++;
2410
2411         if(!prs_align(ps))
2412                 return False;
2413
2414         if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
2415                 return False;
2416
2417         if(!prs_uint32("rid   ", ps, depth, &r_u->rid))
2418                 return False;
2419         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2420                 return False;
2421
2422         return True;
2423 }
2424
2425 /*******************************************************************
2426 inits a SAMR_Q_DELETE_DOM_GROUP structure.
2427 ********************************************************************/
2428
2429 void init_samr_q_delete_dom_group(SAMR_Q_DELETE_DOM_GROUP * q_c,
2430                                   POLICY_HND *hnd)
2431 {
2432         DEBUG(5, ("init_samr_q_delete_dom_group\n"));
2433
2434         q_c->group_pol = *hnd;
2435 }
2436
2437 /*******************************************************************
2438 reads or writes a structure.
2439 ********************************************************************/
2440
2441 BOOL samr_io_q_delete_dom_group(const char *desc, SAMR_Q_DELETE_DOM_GROUP * q_u,
2442                                 prs_struct *ps, int depth)
2443 {
2444         if (q_u == NULL)
2445                 return False;
2446
2447         prs_debug(ps, depth, desc, "samr_io_q_delete_dom_group");
2448         depth++;
2449
2450         if(!prs_align(ps))
2451                 return False;
2452
2453         if(!smb_io_pol_hnd("group_pol", &q_u->group_pol, ps, depth))
2454                 return False;
2455
2456         return True;
2457 }
2458
2459 /*******************************************************************
2460 reads or writes a structure.
2461 ********************************************************************/
2462
2463 BOOL samr_io_r_delete_dom_group(const char *desc, SAMR_R_DELETE_DOM_GROUP * r_u,
2464                                 prs_struct *ps, int depth)
2465 {
2466         if (r_u == NULL)
2467                 return False;
2468
2469         prs_debug(ps, depth, desc, "samr_io_r_delete_dom_group");
2470         depth++;
2471
2472         if(!prs_align(ps))
2473                 return False;
2474
2475         if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
2476                 return False;
2477
2478         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2479                 return False;
2480
2481         return True;
2482 }
2483
2484 /*******************************************************************
2485 inits a SAMR_Q_DEL_GROUPMEM structure.
2486 ********************************************************************/
2487
2488 void init_samr_q_del_groupmem(SAMR_Q_DEL_GROUPMEM * q_e,
2489                               POLICY_HND *pol, uint32 rid)
2490 {
2491         DEBUG(5, ("init_samr_q_del_groupmem\n"));
2492
2493         q_e->pol = *pol;
2494         q_e->rid = rid;
2495 }
2496
2497 /*******************************************************************
2498 reads or writes a structure.
2499 ********************************************************************/
2500
2501 BOOL samr_io_q_del_groupmem(const char *desc, SAMR_Q_DEL_GROUPMEM * q_e,
2502                             prs_struct *ps, int depth)
2503 {
2504         if (q_e == NULL)
2505                 return False;
2506
2507         prs_debug(ps, depth, desc, "samr_io_q_del_groupmem");
2508         depth++;
2509
2510         if(!prs_align(ps))
2511                 return False;
2512
2513         if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
2514                 return False;
2515
2516         if(!prs_uint32("rid", ps, depth, &q_e->rid))
2517                 return False;
2518
2519         return True;
2520 }
2521
2522 /*******************************************************************
2523 inits a SAMR_R_DEL_GROUPMEM structure.
2524 ********************************************************************/
2525
2526 void init_samr_r_del_groupmem(SAMR_R_DEL_GROUPMEM * r_u, POLICY_HND *pol,
2527                               NTSTATUS status)
2528 {
2529         DEBUG(5, ("init_samr_r_del_groupmem\n"));
2530
2531         r_u->status = status;
2532 }
2533
2534 /*******************************************************************
2535 reads or writes a structure.
2536 ********************************************************************/
2537
2538 BOOL samr_io_r_del_groupmem(const char *desc, SAMR_R_DEL_GROUPMEM * r_u,
2539                             prs_struct *ps, int depth)
2540 {
2541         if (r_u == NULL)
2542                 return False;
2543
2544         prs_debug(ps, depth, desc, "samr_io_r_del_groupmem");
2545         depth++;
2546
2547         if(!prs_align(ps))
2548                 return False;
2549
2550         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2551                 return False;
2552
2553         return True;
2554 }
2555
2556 /*******************************************************************
2557 inits a SAMR_Q_ADD_GROUPMEM structure.
2558 ********************************************************************/
2559
2560 void init_samr_q_add_groupmem(SAMR_Q_ADD_GROUPMEM * q_e,
2561                               POLICY_HND *pol, uint32 rid)
2562 {
2563         DEBUG(5, ("init_samr_q_add_groupmem\n"));
2564
2565         q_e->pol = *pol;
2566         q_e->rid = rid;
2567         q_e->unknown = 0x0005;
2568 }
2569
2570 /*******************************************************************
2571 reads or writes a structure.
2572 ********************************************************************/
2573
2574 BOOL samr_io_q_add_groupmem(const char *desc, SAMR_Q_ADD_GROUPMEM * q_e,
2575                             prs_struct *ps, int depth)
2576 {
2577         if (q_e == NULL)
2578                 return False;
2579
2580         prs_debug(ps, depth, desc, "samr_io_q_add_groupmem");
2581         depth++;
2582
2583         if(!prs_align(ps))
2584                 return False;
2585
2586         if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
2587                 return False;
2588
2589         if(!prs_uint32("rid    ", ps, depth, &q_e->rid))
2590                 return False;
2591         if(!prs_uint32("unknown", ps, depth, &q_e->unknown))
2592                 return False;
2593
2594         return True;
2595 }
2596
2597 /*******************************************************************
2598 inits a SAMR_R_ADD_GROUPMEM structure.
2599 ********************************************************************/
2600
2601 void init_samr_r_add_groupmem(SAMR_R_ADD_GROUPMEM * r_u, POLICY_HND *pol,
2602                               NTSTATUS status)
2603 {
2604         DEBUG(5, ("init_samr_r_add_groupmem\n"));
2605
2606         r_u->status = status;
2607 }
2608
2609 /*******************************************************************
2610 reads or writes a structure.
2611 ********************************************************************/
2612
2613 BOOL samr_io_r_add_groupmem(const char *desc, SAMR_R_ADD_GROUPMEM * r_u,
2614                             prs_struct *ps, int depth)
2615 {
2616         if (r_u == NULL)
2617                 return False;
2618
2619         prs_debug(ps, depth, desc, "samr_io_r_add_groupmem");
2620         depth++;
2621
2622         if(!prs_align(ps))
2623                 return False;
2624
2625         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2626                 return False;
2627
2628         return True;
2629 }
2630
2631 /*******************************************************************
2632 inits a SAMR_Q_SET_GROUPINFO structure.
2633 ********************************************************************/
2634
2635 void init_samr_q_set_groupinfo(SAMR_Q_SET_GROUPINFO * q_e,
2636                                POLICY_HND *pol, GROUP_INFO_CTR * ctr)
2637 {
2638         DEBUG(5, ("init_samr_q_set_groupinfo\n"));
2639
2640         q_e->pol = *pol;
2641         q_e->ctr = ctr;
2642 }
2643
2644 /*******************************************************************
2645 reads or writes a structure.
2646 ********************************************************************/
2647
2648 BOOL samr_io_q_set_groupinfo(const char *desc, SAMR_Q_SET_GROUPINFO * q_e,
2649                              prs_struct *ps, int depth)
2650 {
2651         if (q_e == NULL)
2652                 return False;
2653
2654         prs_debug(ps, depth, desc, "samr_io_q_set_groupinfo");
2655         depth++;
2656
2657         if(!prs_align(ps))
2658                 return False;
2659
2660         if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
2661                 return False;
2662         
2663         if(!samr_group_info_ctr("ctr", &q_e->ctr, ps, depth))
2664                 return False;
2665
2666         return True;
2667 }
2668
2669 /*******************************************************************
2670 inits a SAMR_R_SET_GROUPINFO structure.
2671 ********************************************************************/
2672
2673 void init_samr_r_set_groupinfo(SAMR_R_SET_GROUPINFO * r_u, NTSTATUS status)
2674 {
2675         DEBUG(5, ("init_samr_r_set_groupinfo\n"));
2676
2677         r_u->status = status;
2678 }
2679
2680 /*******************************************************************
2681 reads or writes a structure.
2682 ********************************************************************/
2683
2684 BOOL samr_io_r_set_groupinfo(const char *desc, SAMR_R_SET_GROUPINFO * r_u,
2685                              prs_struct *ps, int depth)
2686 {
2687         if (r_u == NULL)
2688                 return False;
2689
2690         prs_debug(ps, depth, desc, "samr_io_r_set_groupinfo");
2691         depth++;
2692
2693         if(!prs_align(ps))
2694                 return False;
2695
2696         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2697                 return False;
2698
2699         return True;
2700 }
2701
2702 /*******************************************************************
2703 inits a SAMR_Q_QUERY_GROUPINFO structure.
2704 ********************************************************************/
2705
2706 void init_samr_q_query_groupinfo(SAMR_Q_QUERY_GROUPINFO * q_e,
2707                                  POLICY_HND *pol, uint16 switch_level)
2708 {
2709         DEBUG(5, ("init_samr_q_query_groupinfo\n"));
2710
2711         q_e->pol = *pol;
2712
2713         q_e->switch_level = switch_level;
2714 }
2715
2716 /*******************************************************************
2717 reads or writes a structure.
2718 ********************************************************************/
2719
2720 BOOL samr_io_q_query_groupinfo(const char *desc, SAMR_Q_QUERY_GROUPINFO * q_e,
2721                                prs_struct *ps, int depth)
2722 {
2723         if (q_e == NULL)
2724                 return False;
2725
2726         prs_debug(ps, depth, desc, "samr_io_q_query_groupinfo");
2727         depth++;
2728
2729         if(!prs_align(ps))
2730                 return False;
2731
2732         if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
2733                 return False;
2734
2735         if(!prs_uint16("switch_level", ps, depth, &q_e->switch_level))
2736                 return False;
2737
2738         return True;
2739 }
2740
2741 /*******************************************************************
2742 inits a SAMR_R_QUERY_GROUPINFO structure.
2743 ********************************************************************/
2744
2745 void init_samr_r_query_groupinfo(SAMR_R_QUERY_GROUPINFO * r_u,
2746                                  GROUP_INFO_CTR * ctr, NTSTATUS status)
2747 {
2748         DEBUG(5, ("init_samr_r_query_groupinfo\n"));
2749
2750         r_u->ptr = (NT_STATUS_IS_OK(status) && ctr != NULL) ? 1 : 0;
2751         r_u->ctr = ctr;
2752         r_u->status = status;
2753 }
2754
2755 /*******************************************************************
2756 reads or writes a structure.
2757 ********************************************************************/
2758
2759 BOOL samr_io_r_query_groupinfo(const char *desc, SAMR_R_QUERY_GROUPINFO * r_u,
2760                                prs_struct *ps, int depth)
2761 {
2762         if (r_u == NULL)
2763                 return False;
2764
2765         prs_debug(ps, depth, desc, "samr_io_r_query_groupinfo");
2766         depth++;
2767
2768         if(!prs_align(ps))
2769                 return False;
2770
2771         if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
2772                 return False;
2773
2774         if (r_u->ptr != 0) {
2775                 if(!samr_group_info_ctr("ctr", &r_u->ctr, ps, depth))
2776                         return False;
2777         }
2778
2779         if(!prs_align(ps))
2780                 return False;
2781         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2782                 return False;
2783
2784         return True;
2785 }
2786
2787 /*******************************************************************
2788 inits a SAMR_Q_QUERY_GROUPMEM structure.
2789 ********************************************************************/
2790
2791 void init_samr_q_query_groupmem(SAMR_Q_QUERY_GROUPMEM * q_c, POLICY_HND *hnd)
2792 {
2793         DEBUG(5, ("init_samr_q_query_groupmem\n"));
2794
2795         q_c->group_pol = *hnd;
2796 }
2797
2798 /*******************************************************************
2799 reads or writes a structure.
2800 ********************************************************************/
2801
2802 BOOL samr_io_q_query_groupmem(const char *desc, SAMR_Q_QUERY_GROUPMEM * q_u,
2803                               prs_struct *ps, int depth)
2804 {
2805         if (q_u == NULL)
2806                 return False;
2807
2808         prs_debug(ps, depth, desc, "samr_io_q_query_groupmem");
2809         depth++;
2810
2811         if(!prs_align(ps))
2812                 return False;
2813
2814         if(!smb_io_pol_hnd("group_pol", &q_u->group_pol, ps, depth))
2815                 return False;
2816
2817         return True;
2818 }
2819
2820 /*******************************************************************
2821 inits a SAMR_R_QUERY_GROUPMEM structure.
2822 ********************************************************************/
2823
2824 void init_samr_r_query_groupmem(SAMR_R_QUERY_GROUPMEM * r_u,
2825                                 uint32 num_entries, uint32 *rid,
2826                                 uint32 *attr, NTSTATUS status)
2827 {
2828         DEBUG(5, ("init_samr_r_query_groupmem\n"));
2829
2830         if (NT_STATUS_IS_OK(status)) {
2831                 r_u->ptr = 1;
2832                 r_u->num_entries = num_entries;
2833
2834                 r_u->ptr_attrs = attr != NULL ? 1 : 0;
2835                 r_u->ptr_rids = rid != NULL ? 1 : 0;
2836
2837                 r_u->num_rids = num_entries;
2838                 r_u->rid = rid;
2839
2840                 r_u->num_attrs = num_entries;
2841                 r_u->attr = attr;
2842         } else {
2843                 r_u->ptr = 0;
2844                 r_u->num_entries = 0;
2845         }
2846
2847         r_u->status = status;
2848 }
2849
2850 /*******************************************************************
2851 reads or writes a structure.
2852 ********************************************************************/
2853
2854 BOOL samr_io_r_query_groupmem(const char *desc, SAMR_R_QUERY_GROUPMEM * r_u,
2855                               prs_struct *ps, int depth)
2856 {
2857         uint32 i;
2858
2859         if (r_u == NULL)
2860                 return False;
2861
2862         if (UNMARSHALLING(ps))
2863                 ZERO_STRUCTP(r_u);
2864
2865         prs_debug(ps, depth, desc, "samr_io_r_query_groupmem");
2866         depth++;
2867
2868         if(!prs_align(ps))
2869                 return False;
2870
2871         if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
2872                 return False;
2873         if(!prs_uint32("num_entries ", ps, depth, &r_u->num_entries))
2874                 return False;
2875
2876         if (r_u->ptr != 0) {
2877                 if(!prs_uint32("ptr_rids ", ps, depth, &r_u->ptr_rids))
2878                         return False;
2879                 if(!prs_uint32("ptr_attrs", ps, depth, &r_u->ptr_attrs))
2880                         return False;
2881
2882                 if (r_u->ptr_rids != 0) {
2883                         if(!prs_uint32("num_rids", ps, depth, &r_u->num_rids))
2884                                 return False;
2885                         if (UNMARSHALLING(ps) && r_u->num_rids != 0) {
2886                                 r_u->rid = PRS_ALLOC_MEM(ps,uint32,r_u->num_rids);
2887                                 if (r_u->rid == NULL)
2888                                         return False;
2889                         }
2890
2891                         for (i = 0; i < r_u->num_rids; i++) {
2892                                 if(!prs_uint32("", ps, depth, &r_u->rid[i]))
2893                                         return False;
2894                         }
2895                 }
2896
2897                 if (r_u->ptr_attrs != 0) {
2898                         if(!prs_uint32("num_attrs", ps, depth, &r_u->num_attrs))
2899                                 return False;
2900
2901                         if (UNMARSHALLING(ps) && r_u->num_attrs != 0) {
2902                                 r_u->attr = PRS_ALLOC_MEM(ps,uint32,r_u->num_attrs);
2903                                 if (r_u->attr == NULL)
2904                                         return False;
2905                         }
2906
2907                         for (i = 0; i < r_u->num_attrs; i++) {
2908                                 if(!prs_uint32("", ps, depth, &r_u->attr[i]))
2909                                         return False;
2910                         }
2911                 }
2912         }
2913
2914         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2915                 return False;
2916
2917         return True;
2918 }
2919
2920 /*******************************************************************
2921 inits a SAMR_Q_QUERY_USERGROUPS structure.
2922 ********************************************************************/
2923
2924 void init_samr_q_query_usergroups(SAMR_Q_QUERY_USERGROUPS * q_u,
2925                                   POLICY_HND *hnd)
2926 {
2927         DEBUG(5, ("init_samr_q_query_usergroups\n"));
2928
2929         q_u->pol = *hnd;
2930 }
2931
2932 /*******************************************************************
2933 reads or writes a structure.
2934 ********************************************************************/
2935
2936 BOOL samr_io_q_query_usergroups(const char *desc, SAMR_Q_QUERY_USERGROUPS * q_u,
2937                                 prs_struct *ps, int depth)
2938 {
2939         if (q_u == NULL)
2940                 return False;
2941
2942         prs_debug(ps, depth, desc, "samr_io_q_query_usergroups");
2943         depth++;
2944
2945         if(!prs_align(ps))
2946                 return False;
2947
2948         if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
2949                 return False;
2950
2951         return True;
2952 }
2953
2954 /*******************************************************************
2955 inits a SAMR_R_QUERY_USERGROUPS structure.
2956 ********************************************************************/
2957
2958 void init_samr_r_query_usergroups(SAMR_R_QUERY_USERGROUPS * r_u,
2959                                   uint32 num_gids, DOM_GID * gid,
2960                                   NTSTATUS status)
2961 {
2962         DEBUG(5, ("init_samr_r_query_usergroups\n"));
2963
2964         if (NT_STATUS_IS_OK(status)) {
2965                 r_u->ptr_0 = 1;
2966                 r_u->num_entries = num_gids;
2967                 r_u->ptr_1 = (num_gids != 0) ? 1 : 0;
2968                 r_u->num_entries2 = num_gids;
2969
2970                 r_u->gid = gid;
2971         } else {
2972                 r_u->ptr_0 = 0;
2973                 r_u->num_entries = 0;
2974                 r_u->ptr_1 = 0;
2975                 r_u->gid = NULL;
2976         }
2977
2978         r_u->status = status;
2979 }
2980
2981 /*******************************************************************
2982 reads or writes a structure.
2983 ********************************************************************/
2984
2985 BOOL samr_io_gids(const char *desc, uint32 *num_gids, DOM_GID ** gid,
2986                   prs_struct *ps, int depth)
2987 {
2988         uint32 i;
2989         if (gid == NULL)
2990                 return False;
2991
2992         prs_debug(ps, depth, desc, "samr_io_gids");
2993         depth++;
2994
2995         if(!prs_align(ps))
2996                 return False;
2997
2998         if(!prs_uint32("num_gids", ps, depth, num_gids))
2999                 return False;
3000
3001         if ((*num_gids) != 0) {
3002                 if (UNMARSHALLING(ps)) {
3003                         (*gid) = PRS_ALLOC_MEM(ps,DOM_GID,*num_gids);
3004                 }
3005
3006                 if ((*gid) == NULL) {
3007                         return False;
3008                 }
3009
3010                 for (i = 0; i < (*num_gids); i++) {
3011                         if(!smb_io_gid("gids", &(*gid)[i], ps, depth))
3012                                 return False;
3013                 }
3014         }
3015
3016         return True;
3017 }
3018
3019 /*******************************************************************
3020 reads or writes a structure.
3021 ********************************************************************/
3022
3023 BOOL samr_io_r_query_usergroups(const char *desc, SAMR_R_QUERY_USERGROUPS * r_u,
3024                                 prs_struct *ps, int depth)
3025 {
3026         if (r_u == NULL)
3027                 return False;
3028
3029         prs_debug(ps, depth, desc, "samr_io_r_query_usergroups");
3030         depth++;
3031
3032         if(!prs_align(ps))
3033                 return False;
3034
3035         if(!prs_uint32("ptr_0       ", ps, depth, &r_u->ptr_0))
3036                 return False;
3037
3038         if (r_u->ptr_0 != 0) {
3039                 if(!prs_uint32("num_entries ", ps, depth, &r_u->num_entries))
3040                         return False;
3041                 if(!prs_uint32("ptr_1       ", ps, depth, &r_u->ptr_1))
3042                         return False;
3043
3044                 if (r_u->num_entries != 0 && r_u->ptr_1 != 0) {
3045                         if(!samr_io_gids("gids", &r_u->num_entries2, &r_u->gid, ps, depth))
3046                                 return False;
3047                 }
3048         }
3049
3050         if(!prs_align(ps))
3051                 return False;
3052         if(!prs_ntstatus("status", ps, depth, &r_u->status))
3053           return False;
3054
3055         return True;
3056 }
3057
3058 /*******************************************************************
3059 inits a SAMR_Q_ENUM_DOMAINS structure.
3060 ********************************************************************/
3061
3062 void init_samr_q_enum_domains(SAMR_Q_ENUM_DOMAINS * q_e,
3063                               POLICY_HND *pol,
3064                               uint32 start_idx, uint32 size)
3065 {
3066         DEBUG(5, ("init_samr_q_enum_domains\n"));
3067
3068         q_e->pol = *pol;
3069
3070         q_e->start_idx = start_idx;
3071         q_e->max_size = size;
3072 }
3073
3074 /*******************************************************************
3075 reads or writes a structure.
3076 ********************************************************************/
3077
3078 BOOL samr_io_q_enum_domains(const char *desc, SAMR_Q_ENUM_DOMAINS * q_e,
3079                             prs_struct *ps, int depth)
3080 {
3081         if (q_e == NULL)
3082                 return False;
3083
3084         prs_debug(ps, depth, desc, "samr_io_q_enum_domains");
3085         depth++;
3086
3087         if(!prs_align(ps))
3088                 return False;
3089
3090         if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
3091                 return False;
3092
3093         if(!prs_uint32("start_idx", ps, depth, &q_e->start_idx))
3094                 return False;
3095         if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
3096                 return False;
3097
3098         return True;
3099 }
3100
3101 /*******************************************************************
3102 inits a SAMR_R_ENUM_DOMAINS structure.
3103 ********************************************************************/
3104
3105 void init_samr_r_enum_domains(SAMR_R_ENUM_DOMAINS * r_u,
3106                               uint32 next_idx, uint32 num_sam_entries)
3107 {
3108         DEBUG(5, ("init_samr_r_enum_domains\n"));
3109
3110         r_u->next_idx = next_idx;
3111
3112         if (num_sam_entries != 0) {
3113                 r_u->ptr_entries1 = 1;
3114                 r_u->ptr_entries2 = 1;
3115                 r_u->num_entries2 = num_sam_entries;
3116                 r_u->num_entries3 = num_sam_entries;
3117
3118                 r_u->num_entries4 = num_sam_entries;
3119         } else {
3120                 r_u->ptr_entries1 = 0;
3121                 r_u->num_entries2 = num_sam_entries;
3122                 r_u->ptr_entries2 = 1;
3123         }
3124 }
3125
3126 /*******************************************************************
3127 reads or writes a structure.
3128 ********************************************************************/
3129
3130 BOOL samr_io_r_enum_domains(const char *desc, SAMR_R_ENUM_DOMAINS * r_u,
3131                             prs_struct *ps, int depth)
3132 {
3133         uint32 i;
3134
3135         if (r_u == NULL)
3136                 return False;
3137
3138         prs_debug(ps, depth, desc, "samr_io_r_enum_domains");
3139         depth++;
3140
3141         if(!prs_align(ps))
3142                 return False;
3143
3144         if(!prs_uint32("next_idx    ", ps, depth, &r_u->next_idx))
3145                 return False;
3146         if(!prs_uint32("ptr_entries1", ps, depth, &r_u->ptr_entries1))
3147                 return False;
3148
3149         if (r_u->ptr_entries1 != 0) {
3150                 if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
3151                         return False;
3152                 if(!prs_uint32("ptr_entries2", ps, depth, &r_u->ptr_entries2))
3153                         return False;
3154                 if(!prs_uint32("num_entries3", ps, depth, &r_u->num_entries3))
3155                         return False;
3156
3157                 if (UNMARSHALLING(ps)) {
3158                         r_u->sam = PRS_ALLOC_MEM(ps,SAM_ENTRY,r_u->num_entries2);
3159                         r_u->uni_dom_name = PRS_ALLOC_MEM(ps,UNISTR2,r_u->num_entries2);
3160                 }
3161
3162                 if ((r_u->sam == NULL || r_u->uni_dom_name == NULL) && r_u->num_entries2 != 0) {
3163                         DEBUG(0, ("NULL pointers in SAMR_R_ENUM_DOMAINS\n"));
3164                         r_u->num_entries4 = 0;
3165                         r_u->status = NT_STATUS_MEMORY_NOT_ALLOCATED;
3166                         return False;
3167                 }
3168
3169                 for (i = 0; i < r_u->num_entries2; i++) {
3170                         fstring tmp;
3171                         slprintf(tmp, sizeof(tmp) - 1, "dom[%d]", i);
3172                         if(!sam_io_sam_entry(tmp, &r_u->sam[i], ps, depth))
3173                                 return False;
3174                 }
3175
3176                 for (i = 0; i < r_u->num_entries2; i++) {
3177                         fstring tmp;
3178                         slprintf(tmp, sizeof(tmp) - 1, "dom[%d]", i);
3179                         if(!smb_io_unistr2(tmp, &r_u->uni_dom_name[i],
3180                                        r_u->sam[i].hdr_name.buffer, ps,
3181                                        depth))
3182                                 return False;
3183                 }
3184
3185         }
3186
3187         if(!prs_align(ps))
3188                 return False;
3189         if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4))
3190                 return False;
3191         if(!prs_ntstatus("status", ps, depth, &r_u->status))
3192                 return False;
3193
3194         return True;
3195 }
3196
3197 /*******************************************************************
3198 inits a SAMR_Q_ENUM_DOM_GROUPS structure.
3199 ********************************************************************/
3200
3201 void init_samr_q_enum_dom_groups(SAMR_Q_ENUM_DOM_GROUPS * q_e,
3202                                  POLICY_HND *pol,
3203                                  uint32 start_idx, uint32 size)
3204 {
3205         DEBUG(5, ("init_samr_q_enum_dom_groups\n"));
3206
3207         q_e->pol = *pol;
3208
3209         q_e->start_idx = start_idx;
3210         q_e->max_size = size;
3211 }
3212
3213 /*******************************************************************
3214 reads or writes a structure.
3215 ********************************************************************/
3216
3217 BOOL samr_io_q_enum_dom_groups(const char *desc, SAMR_Q_ENUM_DOM_GROUPS * q_e,
3218                                prs_struct *ps, int depth)
3219 {
3220         if (q_e == NULL)
3221                 return False;
3222
3223         prs_debug(ps, depth, desc, "samr_io_q_enum_dom_groups");
3224         depth++;
3225
3226         if(!prs_align(ps))
3227                 return False;
3228
3229         if(!smb_io_pol_hnd("pol", &(q_e->pol), ps, depth))
3230                 return False;
3231
3232         if(!prs_uint32("start_idx", ps, depth, &q_e->start_idx))
3233                 return False;
3234         if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
3235                 return False;
3236
3237         return True;
3238 }
3239
3240 /*******************************************************************
3241 inits a SAMR_R_ENUM_DOM_GROUPS structure.
3242 ********************************************************************/
3243
3244 void init_samr_r_enum_dom_groups(SAMR_R_ENUM_DOM_GROUPS * r_u,
3245                                  uint32 next_idx, uint32 num_sam_entries)
3246 {
3247         DEBUG(5, ("init_samr_r_enum_dom_groups\n"));
3248
3249         r_u->next_idx = next_idx;
3250
3251         if (num_sam_entries != 0) {
3252                 r_u->ptr_entries1 = 1;
3253                 r_u->ptr_entries2 = 1;
3254                 r_u->num_entries2 = num_sam_entries;
3255                 r_u->num_entries3 = num_sam_entries;
3256
3257                 r_u->num_entries4 = num_sam_entries;
3258         } else {
3259                 r_u->ptr_entries1 = 0;
3260                 r_u->num_entries2 = num_sam_entries;
3261                 r_u->ptr_entries2 = 1;
3262         }
3263 }
3264
3265 /*******************************************************************
3266 reads or writes a structure.
3267 ********************************************************************/
3268
3269 BOOL samr_io_r_enum_dom_groups(const char *desc, SAMR_R_ENUM_DOM_GROUPS * r_u,
3270                                prs_struct *ps, int depth)
3271 {
3272         uint32 i;
3273
3274         if (r_u == NULL)
3275                 return False;
3276
3277         prs_debug(ps, depth, desc, "samr_io_r_enum_dom_groups");
3278         depth++;
3279
3280         if(!prs_align(ps))
3281                 return False;
3282
3283         if(!prs_uint32("next_idx    ", ps, depth, &r_u->next_idx))
3284                 return False;
3285         if(!prs_uint32("ptr_entries1", ps, depth, &r_u->ptr_entries1))
3286                 return False;
3287
3288         if (r_u->ptr_entries1 != 0) {
3289                 if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
3290                         return False;
3291                 if(!prs_uint32("ptr_entries2", ps, depth, &r_u->ptr_entries2))
3292                         return False;
3293                 if(!prs_uint32("num_entries3", ps, depth, &r_u->num_entries3))
3294                         return False;
3295
3296                 if (UNMARSHALLING(ps)) {
3297                         r_u->sam = PRS_ALLOC_MEM(ps,SAM_ENTRY,r_u->num_entries2);
3298                         r_u->uni_grp_name = PRS_ALLOC_MEM(ps,UNISTR2,r_u->num_entries2);
3299                 }
3300
3301                 if ((r_u->sam == NULL || r_u->uni_grp_name == NULL) && r_u->num_entries2 != 0) {
3302                         DEBUG(0,
3303                               ("NULL pointers in SAMR_R_ENUM_DOM_GROUPS\n"));
3304                         r_u->num_entries4 = 0;
3305                         r_u->status = NT_STATUS_MEMORY_NOT_ALLOCATED;
3306                         return False;
3307                 }
3308
3309                 for (i = 0; i < r_u->num_entries2; i++) {
3310                         if(!sam_io_sam_entry("", &r_u->sam[i], ps, depth))
3311                                 return False;
3312                 }
3313
3314                 for (i = 0; i < r_u->num_entries2; i++) {
3315                         if(!smb_io_unistr2("", &r_u->uni_grp_name[i],
3316                                        r_u->sam[i].hdr_name.buffer, ps, depth))
3317                                 return False;
3318                 }
3319         }
3320
3321         if(!prs_align(ps))
3322                 return False;
3323         if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4))
3324                 return False;
3325         if(!prs_ntstatus("status", ps, depth, &r_u->status))
3326                 return False;
3327
3328         return True;
3329 }
3330
3331 /*******************************************************************
3332 inits a SAMR_Q_ENUM_DOM_ALIASES structure.
3333 ********************************************************************/
3334
3335 void init_samr_q_enum_dom_aliases(SAMR_Q_ENUM_DOM_ALIASES * q_e,
3336                                   POLICY_HND *pol, uint32 start_idx,
3337                                   uint32 size)
3338 {
3339         DEBUG(5, ("init_samr_q_enum_dom_aliases\n"));
3340
3341         q_e->pol = *pol;
3342
3343         q_e->start_idx = start_idx;
3344         q_e->max_size = size;
3345 }
3346
3347
3348 /*******************************************************************
3349 reads or writes a structure.
3350 ********************************************************************/
3351
3352 BOOL samr_io_q_enum_dom_aliases(const char *desc, SAMR_Q_ENUM_DOM_ALIASES * q_e,
3353                                 prs_struct *ps, int depth)
3354 {
3355         if (q_e == NULL)
3356                 return False;
3357
3358         prs_debug(ps, depth, desc, "samr_io_q_enum_dom_aliases");
3359         depth++;
3360
3361         if(!prs_align(ps))
3362                 return False;
3363
3364         if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
3365                 return False;
3366
3367         if(!prs_uint32("start_idx", ps, depth, &q_e->start_idx))
3368                 return False;
3369         if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
3370                 return False;
3371
3372         return True;
3373 }
3374
3375 /*******************************************************************
3376 inits a SAMR_R_ENUM_DOM_ALIASES structure.
3377 ********************************************************************/
3378
3379 void init_samr_r_enum_dom_aliases(SAMR_R_ENUM_DOM_ALIASES *r_u, uint32 next_idx, uint32 num_sam_entries)
3380 {
3381         DEBUG(5, ("init_samr_r_enum_dom_aliases\n"));
3382
3383         r_u->next_idx = next_idx;
3384
3385         if (num_sam_entries != 0) {
3386                 r_u->ptr_entries1 = 1;
3387                 r_u->ptr_entries2 = 1;
3388                 r_u->num_entries2 = num_sam_entries;
3389                 r_u->num_entries3 = num_sam_entries;
3390
3391                 r_u->num_entries4 = num_sam_entries;
3392         } else {
3393                 r_u->ptr_entries1 = 0;
3394                 r_u->num_entries2 = num_sam_entries;
3395                 r_u->ptr_entries2 = 1;
3396         }
3397 }
3398
3399 /*******************************************************************
3400 reads or writes a structure.
3401 ********************************************************************/
3402
3403 BOOL samr_io_r_enum_dom_aliases(const char *desc, SAMR_R_ENUM_DOM_ALIASES * r_u,
3404                                 prs_struct *ps, int depth)
3405 {
3406         uint32 i;
3407
3408         if (r_u == NULL)
3409                 return False;
3410
3411         prs_debug(ps, depth, desc, "samr_io_r_enum_dom_aliases");
3412         depth++;
3413
3414         if(!prs_align(ps))
3415                 return False;
3416
3417         if(!prs_uint32("next_idx    ", ps, depth, &r_u->next_idx))
3418                 return False;
3419         if(!prs_uint32("ptr_entries1", ps, depth, &r_u->ptr_entries1))
3420                 return False;
3421
3422         if (r_u->ptr_entries1 != 0) {
3423                 if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
3424                         return False;
3425                 if(!prs_uint32("ptr_entries2", ps, depth, &r_u->ptr_entries2))
3426                         return False;
3427                 if(!prs_uint32("num_entries3", ps, depth, &r_u->num_entries3))
3428                         return False;
3429
3430                 if (UNMARSHALLING(ps) && (r_u->num_entries2 > 0)) {
3431                         r_u->sam = PRS_ALLOC_MEM(ps,SAM_ENTRY,r_u->num_entries2);
3432                         r_u->uni_grp_name = PRS_ALLOC_MEM(ps,UNISTR2,r_u->num_entries2);
3433                 }
3434
3435                 if (r_u->num_entries2 != 0 && 
3436                     (r_u->sam == NULL || r_u->uni_grp_name == NULL)) {
3437                         DEBUG(0,("NULL pointers in SAMR_R_ENUM_DOM_ALIASES\n"));
3438                         r_u->num_entries4 = 0;
3439                         r_u->status = NT_STATUS_MEMORY_NOT_ALLOCATED;
3440                         return False;
3441                 }
3442
3443                 for (i = 0; i < r_u->num_entries2; i++) {
3444                         if(!sam_io_sam_entry("", &r_u->sam[i], ps, depth))
3445                                 return False;
3446                 }
3447
3448                 for (i = 0; i < r_u->num_entries2; i++) {
3449                         if(!smb_io_unistr2("", &r_u->uni_grp_name[i],
3450                                        r_u->sam[i].hdr_name.buffer, ps,
3451                                        depth))
3452                                 return False;
3453                 }
3454         }
3455
3456         if(!prs_align(ps))
3457                 return False;
3458         if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4))
3459                 return False;
3460         if(!prs_ntstatus("status", ps, depth, &r_u->status))
3461                 return False;
3462
3463         return True;
3464 }
3465
3466 /*******************************************************************
3467 inits a ALIAS_INFO1 structure.
3468 ********************************************************************/
3469
3470 void init_samr_alias_info1(ALIAS_INFO1 * al1, char *acct_name, uint32 num_member, char *acct_desc)
3471 {
3472         DEBUG(5, ("init_samr_alias_info1\n"));
3473
3474         init_unistr4(&al1->name, acct_name, UNI_FLAGS_NONE);
3475         al1->num_member = num_member;
3476         init_unistr4(&al1->description, acct_desc, UNI_FLAGS_NONE);
3477 }
3478
3479 /*******************************************************************
3480 reads or writes a structure.
3481 ********************************************************************/
3482
3483 BOOL samr_io_alias_info1(const char *desc, ALIAS_INFO1 * al1,
3484                          prs_struct *ps, int depth)
3485 {
3486         if (al1 == NULL)
3487                 return False;
3488
3489         prs_debug(ps, depth, desc, "samr_io_alias_info1");
3490         depth++;
3491
3492         if(!prs_align(ps))
3493                 return False;
3494
3495         if ( !prs_unistr4_hdr("name", ps, depth, &al1->name) )
3496                 return False;
3497         if ( !prs_uint32("num_member", ps, depth, &al1->num_member) )
3498                 return False;
3499         if ( !prs_unistr4_hdr("description", ps, depth, &al1->description) )
3500                 return False;
3501
3502         if ( !prs_unistr4_str("name", ps, depth, &al1->name) )
3503                 return False;
3504         if ( !prs_align(ps) )
3505                 return False;
3506         if ( !prs_unistr4_str("description", ps, depth, &al1->description) )
3507                 return False;
3508         if ( !prs_align(ps) )
3509                 return False;
3510
3511         return True;
3512 }
3513
3514 /*******************************************************************
3515 inits a ALIAS_INFO3 structure.
3516 ********************************************************************/
3517
3518 void init_samr_alias_info3(ALIAS_INFO3 * al3, const char *acct_desc)
3519 {
3520         DEBUG(5, ("init_samr_alias_info3\n"));
3521
3522         init_unistr4(&al3->description, acct_desc, UNI_FLAGS_NONE);
3523 }
3524
3525 /*******************************************************************
3526 reads or writes a structure.
3527 ********************************************************************/
3528
3529 BOOL samr_io_alias_info3(const char *desc, ALIAS_INFO3 *al3,
3530                          prs_struct *ps, int depth)
3531 {
3532         if (al3 == NULL)
3533                 return False;
3534
3535         prs_debug(ps, depth, desc, "samr_io_alias_info3");
3536         depth++;
3537
3538         if(!prs_align(ps))
3539                 return False;
3540
3541         if (!prs_unistr4("description", ps, depth, &al3->description))
3542                 return False;
3543
3544         return True;
3545 }
3546
3547 /*******************************************************************
3548 reads or writes a structure.
3549 ********************************************************************/
3550
3551 BOOL samr_alias_info_ctr(const char *desc, prs_struct *ps, int depth, ALIAS_INFO_CTR * ctr)
3552 {
3553         if ( !ctr )
3554                 return False;
3555
3556         prs_debug(ps, depth, desc, "samr_alias_info_ctr");
3557         depth++;
3558
3559         if ( !prs_uint16("level", ps, depth, &ctr->level) )
3560                 return False;
3561
3562         if(!prs_align(ps))
3563                 return False;
3564         switch (ctr->level) {
3565         case 1: 
3566                 if(!samr_io_alias_info1("alias_info1", &ctr->alias.info1, ps, depth))
3567                         return False;
3568                 break;
3569         case 3: 
3570                 if(!samr_io_alias_info3("alias_info3", &ctr->alias.info3, ps, depth))
3571                         return False;
3572                 break;
3573         default:
3574                 DEBUG(0,("samr_alias_info_ctr: unsupported switch level\n"));
3575                 break;
3576         }
3577
3578         return True;
3579 }
3580
3581 /*******************************************************************
3582 inits a SAMR_Q_QUERY_ALIASINFO structure.
3583 ********************************************************************/
3584
3585 void init_samr_q_query_aliasinfo(SAMR_Q_QUERY_ALIASINFO * q_e,
3586                                  POLICY_HND *pol, uint32 switch_level)
3587 {
3588         DEBUG(5, ("init_samr_q_query_aliasinfo\n"));
3589
3590         q_e->pol = *pol;
3591         q_e->level = switch_level;
3592 }
3593
3594 /*******************************************************************
3595 reads or writes a structure.
3596 ********************************************************************/
3597
3598 BOOL samr_io_q_query_aliasinfo(const char *desc, SAMR_Q_QUERY_ALIASINFO *in,
3599                                prs_struct *ps, int depth)
3600 {
3601         if ( !in )
3602                 return False;
3603
3604         prs_debug(ps, depth, desc, "samr_io_q_query_aliasinfo");
3605         depth++;
3606
3607         if(!prs_align(ps))
3608                 return False;
3609
3610         if ( !smb_io_pol_hnd("pol", &(in->pol), ps, depth) )
3611                 return False;
3612
3613         if ( !prs_uint16("level", ps, depth, &in->level) )
3614                 return False;
3615
3616         return True;
3617 }
3618
3619 /*******************************************************************
3620 inits a SAMR_R_QUERY_ALIASINFO structure.
3621 ********************************************************************/
3622
3623 void init_samr_r_query_aliasinfo(SAMR_R_QUERY_ALIASINFO *out,
3624                                  ALIAS_INFO_CTR * ctr, NTSTATUS status)
3625 {
3626         DEBUG(5, ("init_samr_r_query_aliasinfo\n"));
3627
3628         out->ctr = ctr;
3629         out->status = status;
3630 }
3631
3632 /*******************************************************************
3633 reads or writes a structure.
3634 ********************************************************************/
3635
3636 BOOL samr_io_r_query_aliasinfo(const char *desc, SAMR_R_QUERY_ALIASINFO *out,
3637                                prs_struct *ps, int depth)
3638 {
3639         if ( !out )
3640                 return False;
3641
3642         prs_debug(ps, depth, desc, "samr_io_r_query_aliasinfo");
3643         depth++;
3644
3645         if(!prs_align(ps))
3646                 return False;
3647
3648         if ( !prs_pointer("alias", ps, depth, (void**)&out->ctr, sizeof(ALIAS_INFO_CTR), (PRS_POINTER_CAST)samr_alias_info_ctr))
3649                 return False;
3650         if(!prs_align(ps))
3651                 return False;
3652
3653         if(!prs_ntstatus("status", ps, depth, &out->status))
3654                 return False;
3655
3656         return True;
3657 }
3658
3659 /*******************************************************************
3660 inits a SAMR_Q_SET_ALIASINFO structure.
3661 ********************************************************************/
3662
3663 void init_samr_q_set_aliasinfo(SAMR_Q_SET_ALIASINFO * q_u,
3664                                POLICY_HND *hnd, ALIAS_INFO_CTR * ctr)
3665 {
3666         DEBUG(5, ("init_samr_q_set_aliasinfo\n"));
3667
3668         q_u->alias_pol = *hnd;
3669         q_u->ctr = *ctr;
3670 }
3671
3672 /*******************************************************************
3673 reads or writes a structure.
3674 ********************************************************************/
3675
3676 BOOL samr_io_q_set_aliasinfo(const char *desc, SAMR_Q_SET_ALIASINFO * q_u,
3677                              prs_struct *ps, int depth)
3678 {
3679         if (q_u == NULL)
3680                 return False;
3681
3682         prs_debug(ps, depth, desc, "samr_io_q_set_aliasinfo");
3683         depth++;
3684
3685         if(!prs_align(ps))
3686                 return False;
3687
3688         if(!smb_io_pol_hnd("alias_pol", &q_u->alias_pol, ps, depth))
3689                 return False;
3690         if(!samr_alias_info_ctr("ctr", ps, depth, &q_u->ctr))
3691                 return False;
3692
3693         return True;
3694 }
3695
3696 /*******************************************************************
3697 reads or writes a structure.
3698 ********************************************************************/
3699
3700 BOOL samr_io_r_set_aliasinfo(const char *desc, SAMR_R_SET_ALIASINFO * r_u,
3701                              prs_struct *ps, int depth)
3702 {
3703         if (r_u == NULL)
3704                 return False;
3705
3706         prs_debug(ps, depth, desc, "samr_io_r_set_aliasinfo");
3707         depth++;
3708
3709         if(!prs_align(ps))
3710                 return False;
3711         if(!prs_ntstatus("status", ps, depth, &r_u->status))
3712                 return False;
3713
3714         return True;
3715 }
3716
3717 /*******************************************************************
3718 inits a SAMR_Q_QUERY_USERALIASES structure.
3719 ********************************************************************/
3720
3721 void init_samr_q_query_useraliases(SAMR_Q_QUERY_USERALIASES * q_u,
3722                                    POLICY_HND *hnd,
3723                                    uint32 num_sids,
3724                                    uint32 *ptr_sid, DOM_SID2 * sid)
3725 {
3726         DEBUG(5, ("init_samr_q_query_useraliases\n"));
3727
3728         q_u->pol = *hnd;
3729
3730         q_u->num_sids1 = num_sids;
3731         q_u->ptr = 1;
3732         q_u->num_sids2 = num_sids;
3733
3734         q_u->ptr_sid = ptr_sid;
3735         q_u->sid = sid;
3736 }
3737
3738 /*******************************************************************
3739 reads or writes a SAMR_Q_QUERY_USERALIASES structure.
3740 ********************************************************************/
3741
3742 BOOL samr_io_q_query_useraliases(const char *desc, SAMR_Q_QUERY_USERALIASES * q_u,
3743                                  prs_struct *ps, int depth)
3744 {
3745         fstring tmp;
3746         uint32 i;
3747
3748         if (q_u == NULL)
3749                 return False;
3750
3751         prs_debug(ps, depth, desc, "samr_io_q_query_useraliases");
3752         depth++;
3753
3754         if(!prs_align(ps))
3755                 return False;
3756
3757         if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
3758                 return False;
3759
3760         if(!prs_uint32("num_sids1", ps, depth, &q_u->num_sids1))
3761                 return False;
3762         if(!prs_uint32("ptr      ", ps, depth, &q_u->ptr))
3763                 return False;
3764
3765         if (q_u->ptr==0)
3766                 return True;
3767
3768         if(!prs_uint32("num_sids2", ps, depth, &q_u->num_sids2))
3769                 return False;
3770
3771         if (UNMARSHALLING(ps) && (q_u->num_sids2 != 0)) {
3772                 q_u->ptr_sid = PRS_ALLOC_MEM(ps,uint32,q_u->num_sids2);
3773                 if (q_u->ptr_sid == NULL)
3774                         return False;
3775
3776                 q_u->sid = PRS_ALLOC_MEM(ps, DOM_SID2, q_u->num_sids2);
3777                 if (q_u->sid == NULL)
3778                         return False;
3779         }
3780
3781         for (i = 0; i < q_u->num_sids2; i++) {
3782                 slprintf(tmp, sizeof(tmp) - 1, "ptr[%02d]", i);
3783                 if(!prs_uint32(tmp, ps, depth, &q_u->ptr_sid[i]))
3784                         return False;
3785         }
3786
3787         for (i = 0; i < q_u->num_sids2; i++) {
3788                 if (q_u->ptr_sid[i] != 0) {
3789                         slprintf(tmp, sizeof(tmp) - 1, "sid[%02d]", i);
3790                         if(!smb_io_dom_sid2(tmp, &q_u->sid[i], ps, depth))
3791                                 return False;
3792                 }
3793         }
3794
3795         return True;
3796 }
3797
3798 /*******************************************************************
3799 inits a SAMR_R_QUERY_USERALIASES structure.
3800 ********************************************************************/
3801
3802 void init_samr_r_query_useraliases(SAMR_R_QUERY_USERALIASES * r_u,
3803                                    uint32 num_rids, uint32 *rid,
3804                                    NTSTATUS status)
3805 {
3806         DEBUG(5, ("init_samr_r_query_useraliases\n"));
3807
3808         if (NT_STATUS_IS_OK(status)) {
3809                 r_u->num_entries = num_rids;
3810                 r_u->ptr = 1;
3811                 r_u->num_entries2 = num_rids;
3812
3813                 r_u->rid = rid;
3814         } else {
3815                 r_u->num_entries = 0;
3816                 r_u->ptr = 0;
3817                 r_u->num_entries2 = 0;
3818         }
3819
3820         r_u->status = status;
3821 }
3822
3823 /*******************************************************************
3824 reads or writes a structure.
3825 ********************************************************************/
3826
3827 BOOL samr_io_rids(const char *desc, uint32 *num_rids, uint32 **rid,
3828                   prs_struct *ps, int depth)
3829 {
3830         fstring tmp;
3831         uint32 i;
3832         if (rid == NULL)
3833                 return False;
3834
3835         prs_debug(ps, depth, desc, "samr_io_rids");
3836         depth++;
3837
3838         if(!prs_align(ps))
3839                 return False;
3840
3841         if(!prs_uint32("num_rids", ps, depth, num_rids))
3842                 return False;
3843
3844         if ((*num_rids) != 0) {
3845                 if (UNMARSHALLING(ps)) {
3846                         /* reading */
3847                         (*rid) = PRS_ALLOC_MEM(ps,uint32, *num_rids);
3848                 }
3849                 if ((*rid) == NULL)
3850                         return False;
3851
3852                 for (i = 0; i < (*num_rids); i++) {
3853                         slprintf(tmp, sizeof(tmp) - 1, "rid[%02d]", i);
3854                         if(!prs_uint32(tmp, ps, depth, &((*rid)[i])))
3855                                 return False;
3856                 }
3857         }
3858
3859         return True;
3860 }
3861
3862 /*******************************************************************
3863 reads or writes a structure.
3864 ********************************************************************/
3865
3866 BOOL samr_io_r_query_useraliases(const char *desc, SAMR_R_QUERY_USERALIASES * r_u,
3867                                  prs_struct *ps, int depth)
3868 {
3869         if (r_u == NULL)
3870                 return False;
3871
3872         prs_debug(ps, depth, desc, "samr_io_r_query_useraliases");
3873         depth++;
3874
3875         if(!prs_align(ps))
3876                 return False;
3877
3878         if(!prs_uint32("num_entries", ps, depth, &r_u->num_entries))
3879                 return False;
3880         if(!prs_uint32("ptr        ", ps, depth, &r_u->ptr))
3881                 return False;
3882
3883         if (r_u->ptr != 0) {
3884                 if(!samr_io_rids("rids", &r_u->num_entries2, &r_u->rid, ps, depth))
3885                         return False;
3886         }
3887
3888         if(!prs_align(ps))
3889                 return False;
3890         if(!prs_ntstatus("status", ps, depth, &r_u->status))
3891                 return False;
3892
3893         return True;
3894 }
3895
3896 /*******************************************************************
3897 inits a SAMR_Q_OPEN_ALIAS structure.
3898 ********************************************************************/
3899
3900 void init_samr_q_open_alias(SAMR_Q_OPEN_ALIAS * q_u, POLICY_HND *pol,
3901                             uint32 access_mask, uint32 rid)
3902 {
3903         DEBUG(5, ("init_samr_q_open_alias\n"));
3904
3905         q_u->dom_pol = *pol;
3906         q_u->access_mask = access_mask;
3907         q_u->rid_alias = rid;
3908 }
3909
3910 /*******************************************************************
3911 reads or writes a structure.
3912 ********************************************************************/
3913
3914 BOOL samr_io_q_open_alias(const char *desc, SAMR_Q_OPEN_ALIAS * q_u,
3915                           prs_struct *ps, int depth)
3916 {
3917         if (q_u == NULL)
3918                 return False;
3919
3920         prs_debug(ps, depth, desc, "samr_io_q_open_alias");
3921         depth++;
3922
3923         if(!prs_align(ps))
3924                 return False;
3925
3926         if(!smb_io_pol_hnd("domain_pol", &q_u->dom_pol, ps, depth))
3927                 return False;
3928
3929         if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
3930                 return False;
3931         if(!prs_uint32("rid_alias", ps, depth, &q_u->rid_alias))
3932                 return False;
3933
3934         return True;
3935 }
3936
3937 /*******************************************************************
3938 reads or writes a structure.
3939 ********************************************************************/
3940
3941 BOOL samr_io_r_open_alias(const char *desc, SAMR_R_OPEN_ALIAS * r_u,
3942                           prs_struct *ps, int depth)
3943 {
3944         if (r_u == NULL)
3945                 return False;
3946
3947         prs_debug(ps, depth, desc, "samr_io_r_open_alias");
3948         depth++;
3949
3950         if(!prs_align(ps))
3951                 return False;
3952
3953         if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
3954                 return False;
3955
3956         if(!prs_ntstatus("status", ps, depth, &r_u->status))
3957                 return False;
3958
3959         return True;
3960 }
3961
3962 /*******************************************************************
3963 inits a SAMR_Q_LOOKUP_RIDS structure.
3964 ********************************************************************/
3965
3966 void init_samr_q_lookup_rids(TALLOC_CTX *ctx, SAMR_Q_LOOKUP_RIDS * q_u,
3967                              POLICY_HND *pol, uint32 flags,
3968                              uint32 num_rids, uint32 *rid)
3969 {
3970         DEBUG(5, ("init_samr_q_lookup_rids\n"));
3971
3972         q_u->pol = *pol;
3973
3974         q_u->num_rids1 = num_rids;
3975         q_u->flags = flags;
3976         q_u->ptr = 0;
3977         q_u->num_rids2 = num_rids;
3978         q_u->rid = TALLOC_ZERO_ARRAY(ctx, uint32, num_rids );
3979         if (q_u->rid == NULL) {
3980                 q_u->num_rids1 = 0;
3981                 q_u->num_rids2 = 0;
3982         } else {
3983