r13711: * Correctly handle acb_info/acct_flags as uint32 not as uint16.
[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                             uint32 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_uint32("acb_info ", ps, depth, &sam->acb_info))
1044                 return False;
1045
1046         if (!smb_io_unihdr("hdr_acct_name", &sam->hdr_acct_name, ps, depth))
1047                 return False;
1048         if (!smb_io_unihdr("hdr_user_desc", &sam->hdr_user_desc, ps, depth))
1049                 return False;
1050         if (!smb_io_unihdr("hdr_user_name", &sam->hdr_user_name, ps, depth))
1051                 return False;
1052
1053         return True;
1054 }
1055
1056 /*******************************************************************
1057 reads or writes a SAM_STR2 structure.
1058 ********************************************************************/
1059
1060 static BOOL sam_io_sam_str2(const char *desc, SAM_STR2 * sam, uint32 acct_buf,
1061                             uint32 desc_buf, prs_struct *ps, int depth)
1062 {
1063         if (sam == NULL)
1064                 return False;
1065
1066         prs_debug(ps, depth, desc, "sam_io_sam_str2");
1067         depth++;
1068
1069         if(!prs_align(ps))
1070                 return False;
1071
1072         if(!smb_io_unistr2("uni_srv_name", &sam->uni_srv_name, acct_buf, ps, depth)) /* account name unicode string */
1073                 return False;
1074         if(!smb_io_unistr2("uni_srv_desc", &sam->uni_srv_desc, desc_buf, ps, depth))    /* account desc unicode string */
1075                 return False;
1076
1077         return True;
1078 }
1079
1080 /*******************************************************************
1081 inits a SAM_ENTRY2 structure.
1082 ********************************************************************/
1083 static void init_sam_entry2(SAM_ENTRY2 * sam, uint32 user_idx,
1084                             UNISTR2 *sam_name, UNISTR2 *sam_desc,
1085                             uint32 rid_user, uint32 acb_info)
1086 {
1087         DEBUG(5, ("init_sam_entry2\n"));
1088
1089         sam->user_idx = user_idx;
1090         sam->rid_user = rid_user;
1091         sam->acb_info = acb_info;
1092
1093         init_uni_hdr(&sam->hdr_srv_name, sam_name);
1094         init_uni_hdr(&sam->hdr_srv_desc, sam_desc);
1095 }
1096
1097 /*******************************************************************
1098 reads or writes a SAM_ENTRY2 structure.
1099 ********************************************************************/
1100
1101 static BOOL sam_io_sam_entry2(const char *desc, SAM_ENTRY2 * sam,
1102                               prs_struct *ps, int depth)
1103 {
1104         if (sam == NULL)
1105                 return False;
1106
1107         prs_debug(ps, depth, desc, "sam_io_sam_entry2");
1108         depth++;
1109
1110         if(!prs_align(ps))
1111                 return False;
1112
1113         if(!prs_uint32("user_idx ", ps, depth, &sam->user_idx))
1114                 return False;
1115
1116         if(!prs_uint32("rid_user ", ps, depth, &sam->rid_user))
1117                 return False;
1118         if(!prs_uint32("acb_info ", ps, depth, &sam->acb_info))
1119                 return False;
1120
1121         if(!smb_io_unihdr("unihdr", &sam->hdr_srv_name, ps, depth))     /* account name unicode string header */
1122                 return False;
1123         if(!smb_io_unihdr("unihdr", &sam->hdr_srv_desc, ps, depth))     /* account name unicode string header */
1124                 return False;
1125
1126         return True;
1127 }
1128
1129 /*******************************************************************
1130 reads or writes a SAM_STR3 structure.
1131 ********************************************************************/
1132
1133 static BOOL sam_io_sam_str3(const char *desc, SAM_STR3 * sam, uint32 acct_buf,
1134                             uint32 desc_buf, prs_struct *ps, int depth)
1135 {
1136         if (sam == NULL)
1137                 return False;
1138
1139         prs_debug(ps, depth, desc, "sam_io_sam_str3");
1140         depth++;
1141
1142         if(!prs_align(ps))
1143                 return False;
1144
1145         if(!smb_io_unistr2("uni_grp_name", &sam->uni_grp_name, acct_buf, ps, depth))    /* account name unicode string */
1146                 return False;
1147         if(!smb_io_unistr2("uni_grp_desc", &sam->uni_grp_desc, desc_buf, ps, depth))    /* account desc unicode string */
1148                 return False;
1149
1150         return True;
1151 }
1152
1153 /*******************************************************************
1154 inits a SAM_ENTRY3 structure.
1155 ********************************************************************/
1156
1157 static void init_sam_entry3(SAM_ENTRY3 * sam, uint32 grp_idx,
1158                             UNISTR2 *grp_name, UNISTR2 *grp_desc,
1159                             uint32 rid_grp)
1160 {
1161         DEBUG(5, ("init_sam_entry3\n"));
1162
1163         sam->grp_idx = grp_idx;
1164         sam->rid_grp = rid_grp;
1165         sam->attr = 0x07;       /* group rid attributes - gets ignored by nt 4.0 */
1166
1167         init_uni_hdr(&sam->hdr_grp_name, grp_name);
1168         init_uni_hdr(&sam->hdr_grp_desc, grp_desc);
1169 }
1170
1171 /*******************************************************************
1172 reads or writes a SAM_ENTRY3 structure.
1173 ********************************************************************/
1174
1175 static BOOL sam_io_sam_entry3(const char *desc, SAM_ENTRY3 * sam,
1176                               prs_struct *ps, int depth)
1177 {
1178         if (sam == NULL)
1179                 return False;
1180
1181         prs_debug(ps, depth, desc, "sam_io_sam_entry3");
1182         depth++;
1183
1184         if(!prs_align(ps))
1185                 return False;
1186
1187         if(!prs_uint32("grp_idx", ps, depth, &sam->grp_idx))
1188                 return False;
1189
1190         if(!prs_uint32("rid_grp", ps, depth, &sam->rid_grp))
1191                 return False;
1192         if(!prs_uint32("attr   ", ps, depth, &sam->attr))
1193                 return False;
1194
1195         if(!smb_io_unihdr("unihdr", &sam->hdr_grp_name, ps, depth))     /* account name unicode string header */
1196                 return False;
1197         if(!smb_io_unihdr("unihdr", &sam->hdr_grp_desc, ps, depth))     /* account name unicode string header */
1198                 return False;
1199
1200         return True;
1201 }
1202
1203 /*******************************************************************
1204 inits a SAM_ENTRY4 structure.
1205 ********************************************************************/
1206
1207 static void init_sam_entry4(SAM_ENTRY4 * sam, uint32 user_idx,
1208                             uint32 len_acct_name)
1209 {
1210         DEBUG(5, ("init_sam_entry4\n"));
1211
1212         sam->user_idx = user_idx;
1213         init_str_hdr(&sam->hdr_acct_name, len_acct_name+1, len_acct_name, len_acct_name != 0);
1214 }
1215
1216 /*******************************************************************
1217 reads or writes a SAM_ENTRY4 structure.
1218 ********************************************************************/
1219
1220 static BOOL sam_io_sam_entry4(const char *desc, SAM_ENTRY4 * sam,
1221                               prs_struct *ps, int depth)
1222 {
1223         if (sam == NULL)
1224                 return False;
1225
1226         prs_debug(ps, depth, desc, "sam_io_sam_entry4");
1227         depth++;
1228
1229         if(!prs_align(ps))
1230                 return False;
1231
1232         if(!prs_uint32("user_idx", ps, depth, &sam->user_idx))
1233                 return False;
1234         if(!smb_io_strhdr("strhdr", &sam->hdr_acct_name, ps, depth))
1235                 return False;
1236
1237         return True;
1238 }
1239
1240 /*******************************************************************
1241 inits a SAM_ENTRY5 structure.
1242 ********************************************************************/
1243
1244 static void init_sam_entry5(SAM_ENTRY5 * sam, uint32 grp_idx,
1245                             uint32 len_grp_name)
1246 {
1247         DEBUG(5, ("init_sam_entry5\n"));
1248
1249         sam->grp_idx = grp_idx;
1250         init_str_hdr(&sam->hdr_grp_name, len_grp_name, len_grp_name,
1251                      len_grp_name != 0);
1252 }
1253
1254 /*******************************************************************
1255 reads or writes a SAM_ENTRY5 structure.
1256 ********************************************************************/
1257
1258 static BOOL sam_io_sam_entry5(const char *desc, SAM_ENTRY5 * sam,
1259                               prs_struct *ps, int depth)
1260 {
1261         if (sam == NULL)
1262                 return False;
1263
1264         prs_debug(ps, depth, desc, "sam_io_sam_entry5");
1265         depth++;
1266
1267         if(!prs_align(ps))
1268                 return False;
1269
1270         if(!prs_uint32("grp_idx", ps, depth, &sam->grp_idx))
1271                 return False;
1272         if(!smb_io_strhdr("strhdr", &sam->hdr_grp_name, ps, depth))
1273                 return False;
1274
1275         return True;
1276 }
1277
1278 /*******************************************************************
1279 inits a SAM_ENTRY structure.
1280 ********************************************************************/
1281
1282 void init_sam_entry(SAM_ENTRY *sam, UNISTR2 *uni2, uint32 rid)
1283 {
1284         DEBUG(10, ("init_sam_entry: %d\n", rid));
1285
1286         sam->rid = rid;
1287         init_uni_hdr(&sam->hdr_name, uni2);
1288 }
1289
1290 /*******************************************************************
1291 reads or writes a SAM_ENTRY structure.
1292 ********************************************************************/
1293
1294 static BOOL sam_io_sam_entry(const char *desc, SAM_ENTRY * sam,
1295                              prs_struct *ps, int depth)
1296 {
1297         if (sam == NULL)
1298                 return False;
1299
1300         prs_debug(ps, depth, desc, "sam_io_sam_entry");
1301         depth++;
1302
1303         if(!prs_align(ps))
1304                 return False;
1305         if(!prs_uint32("rid", ps, depth, &sam->rid))
1306                 return False;
1307         if(!smb_io_unihdr("unihdr", &sam->hdr_name, ps, depth)) /* account name unicode string header */
1308                 return False;
1309
1310         return True;
1311 }
1312
1313 /*******************************************************************
1314 inits a SAMR_Q_ENUM_DOM_USERS structure.
1315 ********************************************************************/
1316
1317 void init_samr_q_enum_dom_users(SAMR_Q_ENUM_DOM_USERS * q_e, POLICY_HND *pol,
1318                                 uint32 start_idx,
1319                                 uint32 acb_mask, uint32 size)
1320 {
1321         DEBUG(5, ("init_samr_q_enum_dom_users\n"));
1322
1323         q_e->pol = *pol;
1324
1325         q_e->start_idx = start_idx;     /* zero indicates lots */
1326         q_e->acb_mask = acb_mask;
1327         q_e->max_size = size;
1328 }
1329
1330 /*******************************************************************
1331 reads or writes a structure.
1332 ********************************************************************/
1333
1334 BOOL samr_io_q_enum_dom_users(const char *desc, SAMR_Q_ENUM_DOM_USERS * q_e,
1335                               prs_struct *ps, int depth)
1336 {
1337         if (q_e == NULL)
1338                 return False;
1339
1340         prs_debug(ps, depth, desc, "samr_io_q_enum_dom_users");
1341         depth++;
1342
1343         if(!prs_align(ps))
1344                 return False;
1345
1346         if(!smb_io_pol_hnd("domain_pol", &q_e->pol, ps, depth))
1347                 return False;
1348
1349         if(!prs_uint32("start_idx", ps, depth, &q_e->start_idx))
1350                 return False;
1351         if(!prs_uint32("acb_mask ", ps, depth, &q_e->acb_mask))
1352                 return False;
1353
1354         if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
1355                 return False;
1356
1357         return True;
1358 }
1359
1360
1361 /*******************************************************************
1362 inits a SAMR_R_ENUM_DOM_USERS structure.
1363 ********************************************************************/
1364
1365 void init_samr_r_enum_dom_users(SAMR_R_ENUM_DOM_USERS * r_u,
1366                                 uint32 next_idx, uint32 num_sam_entries)
1367 {
1368         DEBUG(5, ("init_samr_r_enum_dom_users\n"));
1369
1370         r_u->next_idx = next_idx;
1371
1372         if (num_sam_entries != 0) {
1373                 r_u->ptr_entries1 = 1;
1374                 r_u->ptr_entries2 = 1;
1375                 r_u->num_entries2 = num_sam_entries;
1376                 r_u->num_entries3 = num_sam_entries;
1377
1378                 r_u->num_entries4 = num_sam_entries;
1379         } else {
1380                 r_u->ptr_entries1 = 0;
1381                 r_u->num_entries2 = num_sam_entries;
1382                 r_u->ptr_entries2 = 1;
1383         }
1384 }
1385
1386 /*******************************************************************
1387 reads or writes a structure.
1388 ********************************************************************/
1389
1390 BOOL samr_io_r_enum_dom_users(const char *desc, SAMR_R_ENUM_DOM_USERS * r_u,
1391                               prs_struct *ps, int depth)
1392 {
1393         uint32 i;
1394
1395         if (r_u == NULL)
1396                 return False;
1397
1398         prs_debug(ps, depth, desc, "samr_io_r_enum_dom_users");
1399         depth++;
1400
1401         if(!prs_align(ps))
1402                 return False;
1403
1404         if(!prs_uint32("next_idx    ", ps, depth, &r_u->next_idx))
1405                 return False;
1406         if(!prs_uint32("ptr_entries1", ps, depth, &r_u->ptr_entries1))
1407                 return False;
1408
1409         if (r_u->ptr_entries1 != 0) {
1410                 if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
1411                         return False;
1412                 if(!prs_uint32("ptr_entries2", ps, depth, &r_u->ptr_entries2))
1413                         return False;
1414                 if(!prs_uint32("num_entries3", ps, depth, &r_u->num_entries3))
1415                         return False;
1416
1417                 if (UNMARSHALLING(ps) && (r_u->num_entries2 != 0)) {
1418                         r_u->sam = PRS_ALLOC_MEM(ps,SAM_ENTRY, r_u->num_entries2);
1419                         r_u->uni_acct_name = PRS_ALLOC_MEM(ps,UNISTR2, r_u->num_entries2);
1420                 }
1421
1422                 if ((r_u->sam == NULL || r_u->uni_acct_name == NULL) && r_u->num_entries2 != 0) {
1423                         DEBUG(0,("NULL pointers in SAMR_R_ENUM_DOM_USERS\n"));
1424                         r_u->num_entries4 = 0;
1425                         r_u->status = NT_STATUS_MEMORY_NOT_ALLOCATED;
1426                         return False;
1427                 }
1428
1429                 for (i = 0; i < r_u->num_entries2; i++) {
1430                         if(!sam_io_sam_entry("", &r_u->sam[i], ps, depth))
1431                                 return False;
1432                 }
1433
1434                 for (i = 0; i < r_u->num_entries2; i++) {
1435                         if(!smb_io_unistr2("", &r_u->uni_acct_name[i],r_u->sam[i].hdr_name.buffer, ps,depth))
1436                                 return False;
1437                 }
1438
1439         }
1440
1441         if(!prs_align(ps))
1442                 return False;
1443                 
1444         if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4))
1445                 return False;
1446         if(!prs_ntstatus("status", ps, depth, &r_u->status))
1447                 return False;
1448
1449         return True;
1450 }
1451
1452 /*******************************************************************
1453 inits a SAMR_Q_QUERY_DISPINFO structure.
1454 ********************************************************************/
1455
1456 void init_samr_q_query_dispinfo(SAMR_Q_QUERY_DISPINFO * q_e, POLICY_HND *pol,
1457                                 uint16 switch_level, uint32 start_idx,
1458                                 uint32 max_entries, uint32 max_size)
1459 {
1460         DEBUG(5, ("init_samr_q_query_dispinfo\n"));
1461
1462         q_e->domain_pol = *pol;
1463
1464         q_e->switch_level = switch_level;
1465
1466         q_e->start_idx = start_idx;
1467         q_e->max_entries = max_entries;
1468         q_e->max_size = max_size;
1469 }
1470
1471 /*******************************************************************
1472 reads or writes a structure.
1473 ********************************************************************/
1474
1475 BOOL samr_io_q_query_dispinfo(const char *desc, SAMR_Q_QUERY_DISPINFO * q_e,
1476                               prs_struct *ps, int depth)
1477 {
1478         if (q_e == NULL)
1479                 return False;
1480
1481         prs_debug(ps, depth, desc, "samr_io_q_query_dispinfo");
1482         depth++;
1483
1484         if(!prs_align(ps))
1485                 return False;
1486
1487         if(!smb_io_pol_hnd("domain_pol", &q_e->domain_pol, ps, depth))
1488                 return False;
1489
1490         if(!prs_uint16("switch_level", ps, depth, &q_e->switch_level))
1491                 return False;
1492         if(!prs_align(ps))
1493                 return False;
1494
1495         if(!prs_uint32("start_idx   ", ps, depth, &q_e->start_idx))
1496                 return False;
1497         if(!prs_uint32("max_entries ", ps, depth, &q_e->max_entries))
1498                 return False;
1499         if(!prs_uint32("max_size    ", ps, depth, &q_e->max_size))
1500                 return False;
1501
1502         return True;
1503 }
1504
1505 /*******************************************************************
1506 inits a SAM_DISPINFO_1 structure.
1507 ********************************************************************/
1508
1509 NTSTATUS init_sam_dispinfo_1(TALLOC_CTX *ctx, SAM_DISPINFO_1 **sam,
1510                              uint32 num_entries, uint32 start_idx,
1511                              struct samr_displayentry *entries)
1512 {
1513         uint32 i;
1514
1515         DEBUG(10, ("init_sam_dispinfo_1: num_entries: %d\n", num_entries));
1516
1517         if (num_entries==0)
1518                 return NT_STATUS_OK;
1519
1520         *sam = TALLOC_ZERO_ARRAY(ctx, SAM_DISPINFO_1, num_entries);
1521         if (*sam == NULL)
1522                 return NT_STATUS_NO_MEMORY;
1523
1524         (*sam)->sam=TALLOC_ARRAY(ctx, SAM_ENTRY1, num_entries);
1525         if ((*sam)->sam == NULL)
1526                 return NT_STATUS_NO_MEMORY;
1527
1528         (*sam)->str=TALLOC_ARRAY(ctx, SAM_STR1, num_entries);
1529         if ((*sam)->str == NULL)
1530                 return NT_STATUS_NO_MEMORY;
1531
1532         for (i = 0; i < num_entries ; i++) {
1533                 init_unistr2(&(*sam)->str[i].uni_acct_name,
1534                              entries[i].account_name, UNI_FLAGS_NONE);
1535                 init_unistr2(&(*sam)->str[i].uni_full_name,
1536                              entries[i].fullname, UNI_FLAGS_NONE);
1537                 init_unistr2(&(*sam)->str[i].uni_acct_desc,
1538                              entries[i].description, UNI_FLAGS_NONE);
1539
1540                 init_sam_entry1(&(*sam)->sam[i], start_idx+i+1,
1541                                 &(*sam)->str[i].uni_acct_name,
1542                                 &(*sam)->str[i].uni_full_name,
1543                                 &(*sam)->str[i].uni_acct_desc,
1544                                 entries[i].rid, entries[i].acct_flags);
1545         }
1546
1547         return NT_STATUS_OK;
1548 }
1549
1550 /*******************************************************************
1551 reads or writes a structure.
1552 ********************************************************************/
1553
1554 static BOOL sam_io_sam_dispinfo_1(const char *desc, SAM_DISPINFO_1 * sam,
1555                                   uint32 num_entries,
1556                                   prs_struct *ps, int depth)
1557 {
1558         uint32 i;
1559
1560         prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_1");
1561         depth++;
1562
1563         if(!prs_align(ps))
1564                 return False;
1565
1566         if (UNMARSHALLING(ps) && num_entries > 0) {
1567
1568                 if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY1, num_entries)) == NULL) {
1569                         DEBUG(0, ("out of memory allocating SAM_ENTRY1\n"));
1570                         return False;
1571                 }
1572
1573                 if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR1, num_entries)) == NULL) {
1574                         DEBUG(0, ("out of memory allocating SAM_STR1\n"));
1575                         return False;
1576                 }
1577         }
1578
1579         for (i = 0; i < num_entries; i++) {
1580                 if(!sam_io_sam_entry1("", &sam->sam[i], ps, depth))
1581                         return False;
1582         }
1583
1584         for (i = 0; i < num_entries; i++) {
1585                 if(!sam_io_sam_str1("", &sam->str[i],
1586                               sam->sam[i].hdr_acct_name.buffer,
1587                               sam->sam[i].hdr_user_name.buffer,
1588                               sam->sam[i].hdr_user_desc.buffer, ps, depth))
1589                         return False;
1590         }
1591
1592         return True;
1593 }
1594
1595 /*******************************************************************
1596 inits a SAM_DISPINFO_2 structure.
1597 ********************************************************************/
1598
1599 NTSTATUS init_sam_dispinfo_2(TALLOC_CTX *ctx, SAM_DISPINFO_2 **sam,
1600                              uint32 num_entries, uint32 start_idx,
1601                              struct samr_displayentry *entries)
1602 {
1603         uint32 i;
1604
1605         DEBUG(10, ("init_sam_dispinfo_2: num_entries: %d\n", num_entries));
1606
1607         if (num_entries==0)
1608                 return NT_STATUS_OK;
1609
1610         *sam = TALLOC_ZERO_ARRAY(ctx, SAM_DISPINFO_2, num_entries);
1611         if (*sam == NULL)
1612                 return NT_STATUS_NO_MEMORY;
1613
1614         (*sam)->sam = TALLOC_ARRAY(ctx, SAM_ENTRY2, num_entries);
1615         if ((*sam)->sam == NULL)
1616                 return NT_STATUS_NO_MEMORY;
1617
1618         (*sam)->str=TALLOC_ARRAY(ctx, SAM_STR2, num_entries);
1619         if ((*sam)->str == NULL)
1620                 return NT_STATUS_NO_MEMORY;
1621
1622         for (i = 0; i < num_entries; i++) {
1623                 init_unistr2(&(*sam)->str[i].uni_srv_name,
1624                              entries[i].account_name, UNI_FLAGS_NONE);
1625                 init_unistr2(&(*sam)->str[i].uni_srv_desc,
1626                              entries[i].description, UNI_FLAGS_NONE);
1627
1628                 init_sam_entry2(&(*sam)->sam[i], start_idx + i + 1,
1629                                 &(*sam)->str[i].uni_srv_name,
1630                                 &(*sam)->str[i].uni_srv_desc,
1631                                 entries[i].rid, entries[i].acct_flags);
1632         }
1633
1634         return NT_STATUS_OK;
1635 }
1636
1637 /*******************************************************************
1638 reads or writes a structure.
1639 ********************************************************************/
1640
1641 static BOOL sam_io_sam_dispinfo_2(const char *desc, SAM_DISPINFO_2 * sam,
1642                                   uint32 num_entries,
1643                                   prs_struct *ps, int depth)
1644 {
1645         uint32 i;
1646
1647         if (sam == NULL)
1648                 return False;
1649
1650         prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_2");
1651         depth++;
1652
1653         if(!prs_align(ps))
1654                 return False;
1655
1656         if (UNMARSHALLING(ps) && num_entries > 0) {
1657
1658                 if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY2, num_entries)) == NULL) {
1659                         DEBUG(0, ("out of memory allocating SAM_ENTRY2\n"));
1660                         return False;
1661                 }
1662
1663                 if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR2, num_entries)) == NULL) {
1664                         DEBUG(0, ("out of memory allocating SAM_STR2\n"));
1665                         return False;
1666                 }
1667         }
1668
1669         for (i = 0; i < num_entries; i++) {
1670                 if(!sam_io_sam_entry2("", &sam->sam[i], ps, depth))
1671                         return False;
1672         }
1673
1674         for (i = 0; i < num_entries; i++) {
1675                 if(!sam_io_sam_str2("", &sam->str[i],
1676                               sam->sam[i].hdr_srv_name.buffer,
1677                               sam->sam[i].hdr_srv_desc.buffer, ps, depth))
1678                         return False;
1679         }
1680
1681         return True;
1682 }
1683
1684 /*******************************************************************
1685 inits a SAM_DISPINFO_3 structure.
1686 ********************************************************************/
1687
1688 NTSTATUS init_sam_dispinfo_3(TALLOC_CTX *ctx, SAM_DISPINFO_3 **sam,
1689                              uint32 num_entries, uint32 start_idx,
1690                              struct samr_displayentry *entries)
1691 {
1692         uint32 i;
1693
1694         DEBUG(5, ("init_sam_dispinfo_3: num_entries: %d\n", num_entries));
1695
1696         if (num_entries==0)
1697                 return NT_STATUS_OK;
1698
1699         *sam = TALLOC_ZERO_ARRAY(ctx, SAM_DISPINFO_3, num_entries);
1700         if (*sam == NULL)
1701                 return NT_STATUS_NO_MEMORY;
1702
1703         if (!((*sam)->sam=TALLOC_ARRAY(ctx, SAM_ENTRY3, num_entries)))
1704                 return NT_STATUS_NO_MEMORY;
1705
1706         if (!((*sam)->str=TALLOC_ARRAY(ctx, SAM_STR3, num_entries)))
1707                 return NT_STATUS_NO_MEMORY;
1708
1709         for (i = 0; i < num_entries; i++) {
1710                 DEBUG(11, ("init_sam_dispinfo_3: entry: %d\n",i));
1711
1712                 init_unistr2(&(*sam)->str[i].uni_grp_name,
1713                              entries[i].account_name, UNI_FLAGS_NONE);
1714                 init_unistr2(&(*sam)->str[i].uni_grp_desc,
1715                              entries[i].description, UNI_FLAGS_NONE);
1716
1717                 init_sam_entry3(&(*sam)->sam[i], start_idx+i+1,
1718                                 &(*sam)->str[i].uni_grp_name,
1719                                 &(*sam)->str[i].uni_grp_desc,
1720                                 entries[i].rid);
1721         }
1722
1723         return NT_STATUS_OK;
1724 }
1725
1726 /*******************************************************************
1727 reads or writes a structure.
1728 ********************************************************************/
1729
1730 static BOOL sam_io_sam_dispinfo_3(const char *desc, SAM_DISPINFO_3 * sam,
1731                                   uint32 num_entries,
1732                                   prs_struct *ps, int depth)
1733 {
1734         uint32 i;
1735
1736         if (sam == NULL)
1737                 return False;
1738
1739         prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_3");
1740         depth++;
1741
1742         if(!prs_align(ps))
1743                 return False;
1744
1745         if (UNMARSHALLING(ps) && num_entries > 0) {
1746
1747                 if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY3, num_entries)) == NULL) {
1748                         DEBUG(0, ("out of memory allocating SAM_ENTRY3\n"));
1749                         return False;
1750                 }
1751
1752                 if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR3, num_entries)) == NULL) {
1753                         DEBUG(0, ("out of memory allocating SAM_STR3\n"));
1754                         return False;
1755                 }
1756         }
1757
1758         for (i = 0; i < num_entries; i++) {
1759                 if(!sam_io_sam_entry3("", &sam->sam[i], ps, depth))
1760                         return False;
1761         }
1762
1763         for (i = 0; i < num_entries; i++) {
1764                 if(!sam_io_sam_str3("", &sam->str[i],
1765                               sam->sam[i].hdr_grp_name.buffer,
1766                               sam->sam[i].hdr_grp_desc.buffer, ps, depth))
1767                         return False;
1768         }
1769
1770         return True;
1771 }
1772
1773 /*******************************************************************
1774 inits a SAM_DISPINFO_4 structure.
1775 ********************************************************************/
1776
1777 NTSTATUS init_sam_dispinfo_4(TALLOC_CTX *ctx, SAM_DISPINFO_4 **sam,
1778                              uint32 num_entries, uint32 start_idx,
1779                              struct samr_displayentry *entries)
1780 {
1781         uint32 i;
1782
1783         DEBUG(5, ("init_sam_dispinfo_4: num_entries: %d\n", num_entries));
1784
1785         if (num_entries==0)
1786                 return NT_STATUS_OK;
1787
1788         *sam = TALLOC_ZERO_ARRAY(ctx, SAM_DISPINFO_4, num_entries);
1789         if (*sam == NULL)
1790                 return NT_STATUS_NO_MEMORY;
1791
1792         (*sam)->sam = TALLOC_ARRAY(ctx, SAM_ENTRY4, num_entries);
1793         if ((*sam)->sam == NULL)
1794                 return NT_STATUS_NO_MEMORY;
1795
1796         (*sam)->str=TALLOC_ARRAY(ctx, SAM_STR4, num_entries);
1797         if ((*sam)->str == NULL)
1798                 return NT_STATUS_NO_MEMORY;
1799
1800         for (i = 0; i < num_entries; i++) {
1801                 size_t len_sam_name = strlen(entries[i].account_name);
1802
1803                 DEBUG(11, ("init_sam_dispinfo_2: entry: %d\n",i));
1804           
1805                 init_sam_entry4(&(*sam)->sam[i], start_idx + i + 1,
1806                                 len_sam_name);
1807
1808                 init_string2(&(*sam)->str[i].acct_name,
1809                              entries[i].account_name, len_sam_name+1,
1810                              len_sam_name);
1811         }
1812         
1813         return NT_STATUS_OK;
1814 }
1815
1816 /*******************************************************************
1817 reads or writes a structure.
1818 ********************************************************************/
1819
1820 static BOOL sam_io_sam_dispinfo_4(const char *desc, SAM_DISPINFO_4 * sam,
1821                                   uint32 num_entries,
1822                                   prs_struct *ps, int depth)
1823 {
1824         uint32 i;
1825
1826         if (sam == NULL)
1827                 return False;
1828
1829         prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_4");
1830         depth++;
1831
1832         if(!prs_align(ps))
1833                 return False;
1834
1835         if (UNMARSHALLING(ps) && num_entries > 0) {
1836
1837                 if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY4, num_entries)) == NULL) {
1838                         DEBUG(0, ("out of memory allocating SAM_ENTRY4\n"));
1839                         return False;
1840                 }
1841
1842                 if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR4, num_entries)) == NULL) {
1843                         DEBUG(0, ("out of memory allocating SAM_STR4\n"));
1844                         return False;
1845                 }
1846         }
1847
1848         for (i = 0; i < num_entries; i++) {
1849                 if(!sam_io_sam_entry4("", &sam->sam[i], ps, depth))
1850                         return False;
1851         }
1852
1853         for (i = 0; i < num_entries; i++) {
1854                 if(!smb_io_string2("acct_name", &sam->str[i].acct_name,
1855                              sam->sam[i].hdr_acct_name.buffer, ps, depth))
1856                         return False;
1857         }
1858
1859         return True;
1860 }
1861
1862 /*******************************************************************
1863 inits a SAM_DISPINFO_5 structure.
1864 ********************************************************************/
1865
1866 NTSTATUS init_sam_dispinfo_5(TALLOC_CTX *ctx, SAM_DISPINFO_5 **sam,
1867                              uint32 num_entries, uint32 start_idx,
1868                              struct samr_displayentry *entries)
1869 {
1870         uint32 len_sam_name;
1871         uint32 i;
1872
1873         DEBUG(5, ("init_sam_dispinfo_5: num_entries: %d\n", num_entries));
1874
1875         if (num_entries==0)
1876                 return NT_STATUS_OK;
1877
1878         *sam = TALLOC_ZERO_ARRAY(ctx, SAM_DISPINFO_5, num_entries);
1879         if (*sam == NULL)
1880                 return NT_STATUS_NO_MEMORY;
1881
1882         if (!((*sam)->sam=TALLOC_ARRAY(ctx, SAM_ENTRY5, num_entries)))
1883                 return NT_STATUS_NO_MEMORY;
1884
1885         if (!((*sam)->str=TALLOC_ARRAY(ctx, SAM_STR5, num_entries)))
1886                 return NT_STATUS_NO_MEMORY;
1887
1888         for (i = 0; i < num_entries; i++) {
1889                 DEBUG(11, ("init_sam_dispinfo_5: entry: %d\n",i));
1890
1891                 len_sam_name = strlen(entries[i].account_name);
1892           
1893                 init_sam_entry5(&(*sam)->sam[i], start_idx+i+1, len_sam_name);
1894                 init_string2(&(*sam)->str[i].grp_name, entries[i].account_name,
1895                              len_sam_name+1, len_sam_name);
1896         }
1897
1898         return NT_STATUS_OK;
1899 }
1900
1901 /*******************************************************************
1902 reads or writes a structure.
1903 ********************************************************************/
1904
1905 static BOOL sam_io_sam_dispinfo_5(const char *desc, SAM_DISPINFO_5 * sam,
1906                                   uint32 num_entries,
1907                                   prs_struct *ps, int depth)
1908 {
1909         uint32 i;
1910
1911         if (sam == NULL)
1912                 return False;
1913
1914         prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_5");
1915         depth++;
1916
1917         if(!prs_align(ps))
1918                 return False;
1919
1920         if (UNMARSHALLING(ps) && num_entries > 0) {
1921
1922                 if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY5, num_entries)) == NULL) {
1923                         DEBUG(0, ("out of memory allocating SAM_ENTRY5\n"));
1924                         return False;
1925                 }
1926
1927                 if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR5, num_entries)) == NULL) {
1928                         DEBUG(0, ("out of memory allocating SAM_STR5\n"));
1929                         return False;
1930                 }
1931         }
1932
1933         for (i = 0; i < num_entries; i++) {
1934                 if(!sam_io_sam_entry5("", &sam->sam[i], ps, depth))
1935                         return False;
1936         }
1937
1938         for (i = 0; i < num_entries; i++) {
1939                 if(!smb_io_string2("grp_name", &sam->str[i].grp_name,
1940                              sam->sam[i].hdr_grp_name.buffer, ps, depth))
1941                         return False;
1942         }
1943
1944         return True;
1945 }
1946
1947 /*******************************************************************
1948 inits a SAMR_R_QUERY_DISPINFO structure.
1949 ********************************************************************/
1950
1951 void init_samr_r_query_dispinfo(SAMR_R_QUERY_DISPINFO * r_u,
1952                                 uint32 num_entries, uint32 total_size, uint32 data_size,
1953                                 uint16 switch_level, SAM_DISPINFO_CTR * ctr,
1954                                 NTSTATUS status)
1955 {
1956         DEBUG(5, ("init_samr_r_query_dispinfo: level %d\n", switch_level));
1957
1958         r_u->total_size = total_size;
1959
1960         r_u->data_size = data_size;
1961
1962         r_u->switch_level = switch_level;
1963         r_u->num_entries = num_entries;
1964
1965         if (num_entries==0)
1966                 r_u->ptr_entries = 0;
1967         else
1968                 r_u->ptr_entries = 1;
1969
1970         r_u->num_entries2 = num_entries;
1971         r_u->ctr = ctr;
1972
1973         r_u->status = status;
1974 }
1975
1976 /*******************************************************************
1977 reads or writes a structure.
1978 ********************************************************************/
1979
1980 BOOL samr_io_r_query_dispinfo(const char *desc, SAMR_R_QUERY_DISPINFO * r_u,
1981                               prs_struct *ps, int depth)
1982 {
1983         if (r_u == NULL)
1984                 return False;
1985
1986         prs_debug(ps, depth, desc, "samr_io_r_query_dispinfo");
1987         depth++;
1988
1989         if(!prs_align(ps))
1990                 return False;
1991
1992         if(!prs_uint32("total_size  ", ps, depth, &r_u->total_size))
1993                 return False;
1994         if(!prs_uint32("data_size   ", ps, depth, &r_u->data_size))
1995                 return False;
1996         if(!prs_uint16("switch_level", ps, depth, &r_u->switch_level))
1997                 return False;
1998         if(!prs_align(ps))
1999                 return False;
2000
2001         if(!prs_uint32("num_entries ", ps, depth, &r_u->num_entries))
2002                 return False;
2003         if(!prs_uint32("ptr_entries ", ps, depth, &r_u->ptr_entries))
2004                 return False;
2005
2006         if (r_u->ptr_entries==0) {
2007                 if(!prs_align(ps))
2008                         return False;
2009                 if(!prs_ntstatus("status", ps, depth, &r_u->status))
2010                         return False;
2011
2012                 return True;
2013         }
2014
2015         if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
2016                 return False;
2017
2018         switch (r_u->switch_level) {
2019         case 0x1:
2020                 if(!sam_io_sam_dispinfo_1("users", r_u->ctr->sam.info1,
2021                                 r_u->num_entries, ps, depth))
2022                         return False;
2023                 break;
2024         case 0x2:
2025                 if(!sam_io_sam_dispinfo_2("servers", r_u->ctr->sam.info2,
2026                                 r_u->num_entries, ps, depth))
2027                         return False;
2028                 break;
2029         case 0x3:
2030                 if(!sam_io_sam_dispinfo_3("groups", r_u->ctr->sam.info3,
2031                                     r_u->num_entries, ps, depth))
2032                         return False;
2033                 break;
2034         case 0x4:
2035                 if(!sam_io_sam_dispinfo_4("user list",
2036                                     r_u->ctr->sam.info4,
2037                                     r_u->num_entries, ps, depth))
2038                         return False;
2039                 break;
2040         case 0x5:
2041                 if(!sam_io_sam_dispinfo_5("group list",
2042                                     r_u->ctr->sam.info5,
2043                                     r_u->num_entries, ps, depth))
2044                         return False;
2045                 break;
2046         default:
2047                 DEBUG(0,("samr_io_r_query_dispinfo: unknown switch value\n"));
2048                 break;
2049         }
2050         
2051         if(!prs_align(ps))
2052                 return False;
2053         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2054                 return False;
2055
2056         return True;
2057 }
2058
2059 /*******************************************************************
2060 inits a SAMR_Q_OPEN_GROUP structure.
2061 ********************************************************************/
2062
2063 void init_samr_q_open_group(SAMR_Q_OPEN_GROUP * q_c,
2064                             POLICY_HND *hnd,
2065                             uint32 access_mask, uint32 rid)
2066 {
2067         DEBUG(5, ("init_samr_q_open_group\n"));
2068
2069         q_c->domain_pol = *hnd;
2070         q_c->access_mask = access_mask;
2071         q_c->rid_group = rid;
2072 }
2073
2074 /*******************************************************************
2075 reads or writes a structure.
2076 ********************************************************************/
2077
2078 BOOL samr_io_q_open_group(const char *desc, SAMR_Q_OPEN_GROUP * q_u,
2079                           prs_struct *ps, int depth)
2080 {
2081         if (q_u == NULL)
2082                 return False;
2083
2084         prs_debug(ps, depth, desc, "samr_io_q_open_group");
2085         depth++;
2086
2087         if(!prs_align(ps))
2088                 return False;
2089
2090         if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
2091                 return False;
2092
2093         if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
2094                 return False;
2095         if(!prs_uint32("rid_group", ps, depth, &q_u->rid_group))
2096                 return False;
2097
2098         return True;
2099 }
2100
2101 /*******************************************************************
2102 reads or writes a structure.
2103 ********************************************************************/
2104
2105 BOOL samr_io_r_open_group(const char *desc, SAMR_R_OPEN_GROUP * r_u,
2106                           prs_struct *ps, int depth)
2107 {
2108         if (r_u == NULL)
2109                 return False;
2110
2111         prs_debug(ps, depth, desc, "samr_io_r_open_group");
2112         depth++;
2113
2114         if(!prs_align(ps))
2115                 return False;
2116
2117         if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
2118                 return False;
2119
2120         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2121                 return False;
2122
2123         return True;
2124 }
2125
2126 /*******************************************************************
2127 inits a GROUP_INFO1 structure.
2128 ********************************************************************/
2129
2130 void init_samr_group_info1(GROUP_INFO1 * gr1,
2131                            char *acct_name, char *acct_desc,
2132                            uint32 num_members)
2133 {
2134         DEBUG(5, ("init_samr_group_info1\n"));
2135
2136         gr1->group_attr = (SE_GROUP_MANDATORY|SE_GROUP_ENABLED_BY_DEFAULT); /* why not | SE_GROUP_ENABLED ? */
2137         gr1->num_members = num_members;
2138
2139         init_unistr2(&gr1->uni_acct_name, acct_name, UNI_FLAGS_NONE);
2140         init_uni_hdr(&gr1->hdr_acct_name, &gr1->uni_acct_name);
2141         init_unistr2(&gr1->uni_acct_desc, acct_desc, UNI_FLAGS_NONE);
2142         init_uni_hdr(&gr1->hdr_acct_desc, &gr1->uni_acct_desc);
2143 }
2144
2145 /*******************************************************************
2146 reads or writes a structure.
2147 ********************************************************************/
2148
2149 BOOL samr_io_group_info1(const char *desc, GROUP_INFO1 * gr1,
2150                          prs_struct *ps, int depth)
2151 {
2152         uint16 dummy = 1;
2153
2154         if (gr1 == NULL)
2155                 return False;
2156
2157         prs_debug(ps, depth, desc, "samr_io_group_info1");
2158         depth++;
2159
2160         if(!prs_uint16("level", ps, depth, &dummy))
2161                 return False;
2162
2163         if(!prs_align(ps))
2164                 return False;
2165
2166         if(!smb_io_unihdr("hdr_acct_name", &gr1->hdr_acct_name, ps, depth))
2167                 return False;
2168
2169         if(!prs_uint32("group_attr", ps, depth, &gr1->group_attr))
2170                 return False;
2171         if(!prs_uint32("num_members", ps, depth, &gr1->num_members))
2172                 return False;
2173
2174         if(!smb_io_unihdr("hdr_acct_desc", &gr1->hdr_acct_desc, ps, depth))
2175                 return False;
2176
2177         if(!smb_io_unistr2("uni_acct_name", &gr1->uni_acct_name,
2178                            gr1->hdr_acct_name.buffer, ps, depth))
2179                 return False;
2180
2181         if(!smb_io_unistr2("uni_acct_desc", &gr1->uni_acct_desc,
2182                            gr1->hdr_acct_desc.buffer, ps, depth))
2183                 return False;
2184
2185         return True;
2186 }
2187
2188 /*******************************************************************
2189 inits a GROUP_INFO2 structure.
2190 ********************************************************************/
2191
2192 void init_samr_group_info2(GROUP_INFO2 * gr2, const char *acct_name)
2193 {
2194         DEBUG(5, ("init_samr_group_info2\n"));
2195
2196         gr2->level = 2;
2197         init_unistr2(&gr2->uni_acct_name, acct_name, UNI_FLAGS_NONE);
2198         init_uni_hdr(&gr2->hdr_acct_name, &gr2->uni_acct_name);
2199 }
2200
2201 /*******************************************************************
2202 reads or writes a structure.
2203 ********************************************************************/
2204
2205 BOOL samr_io_group_info2(const char *desc, GROUP_INFO2 *gr2, prs_struct *ps, int depth)
2206 {
2207         if (gr2 == NULL)
2208                 return False;
2209
2210         prs_debug(ps, depth, desc, "samr_io_group_info2");
2211         depth++;
2212
2213         if(!prs_uint16("hdr_level", ps, depth, &gr2->level))
2214                 return False;
2215
2216         if(!smb_io_unihdr("hdr_acct_name", &gr2->hdr_acct_name, ps, depth))
2217                 return False;
2218         if(!smb_io_unistr2("uni_acct_name", &gr2->uni_acct_name,
2219                            gr2->hdr_acct_name.buffer, ps, depth))
2220                 return False;
2221
2222         return True;
2223 }
2224
2225 /*******************************************************************
2226 inits a GROUP_INFO3 structure.
2227 ********************************************************************/
2228
2229 void init_samr_group_info3(GROUP_INFO3 *gr3)
2230 {
2231         DEBUG(5, ("init_samr_group_info3\n"));
2232
2233         gr3->group_attr = (SE_GROUP_MANDATORY|SE_GROUP_ENABLED_BY_DEFAULT); /* why not | SE_GROUP_ENABLED ? */
2234 }
2235
2236 /*******************************************************************
2237 reads or writes a structure.
2238 ********************************************************************/
2239
2240 BOOL samr_io_group_info3(const char *desc, GROUP_INFO3 *gr3, prs_struct *ps, int depth)
2241 {
2242         if (gr3 == NULL)
2243                 return False;
2244
2245         prs_debug(ps, depth, desc, "samr_io_group_info3");
2246         depth++;
2247
2248         if(!prs_align(ps))
2249                 return False;
2250
2251         if(!prs_uint32("group_attr", ps, depth, &gr3->group_attr))
2252                 return False;
2253
2254         return True;
2255 }
2256
2257 /*******************************************************************
2258 inits a GROUP_INFO4 structure.
2259 ********************************************************************/
2260
2261 void init_samr_group_info4(GROUP_INFO4 * gr4, const char *acct_desc)
2262 {
2263         DEBUG(5, ("init_samr_group_info4\n"));
2264
2265         gr4->level = 4;
2266         init_unistr2(&gr4->uni_acct_desc, acct_desc, UNI_FLAGS_NONE);
2267         init_uni_hdr(&gr4->hdr_acct_desc, &gr4->uni_acct_desc);
2268 }
2269
2270 /*******************************************************************
2271 reads or writes a structure.
2272 ********************************************************************/
2273
2274 BOOL samr_io_group_info4(const char *desc, GROUP_INFO4 * gr4,
2275                          prs_struct *ps, int depth)
2276 {
2277         if (gr4 == NULL)
2278                 return False;
2279
2280         prs_debug(ps, depth, desc, "samr_io_group_info4");
2281         depth++;
2282
2283         if(!prs_uint16("hdr_level", ps, depth, &gr4->level))
2284                 return False;
2285         if(!smb_io_unihdr("hdr_acct_desc", &gr4->hdr_acct_desc, ps, depth))
2286                 return False;
2287         if(!smb_io_unistr2("uni_acct_desc", &gr4->uni_acct_desc,
2288                            gr4->hdr_acct_desc.buffer, ps, depth))
2289                 return False;
2290
2291         return True;
2292 }
2293
2294 /*******************************************************************
2295 reads or writes a structure.
2296 ********************************************************************/
2297
2298 static BOOL samr_group_info_ctr(const char *desc, GROUP_INFO_CTR **ctr,
2299                                 prs_struct *ps, int depth)
2300 {
2301         if (UNMARSHALLING(ps))
2302                 *ctr = PRS_ALLOC_MEM(ps,GROUP_INFO_CTR,1);
2303
2304         if (*ctr == NULL)
2305                 return False;
2306
2307         prs_debug(ps, depth, desc, "samr_group_info_ctr");
2308         depth++;
2309
2310         if(!prs_uint16("switch_value1", ps, depth, &(*ctr)->switch_value1))
2311                 return False;
2312
2313         switch ((*ctr)->switch_value1) {
2314         case 1:
2315                 if(!samr_io_group_info1("group_info1", &(*ctr)->group.info1, ps, depth))
2316                         return False;
2317                 break;
2318         case 2:
2319                 if(!samr_io_group_info2("group_info2", &(*ctr)->group.info2, ps, depth))
2320                         return False;
2321                 break;
2322         case 3:
2323                 if(!samr_io_group_info3("group_info3", &(*ctr)->group.info3, ps, depth))
2324                         return False;
2325                 break;
2326         case 4:
2327                 if(!samr_io_group_info4("group_info4", &(*ctr)->group.info4, ps, depth))
2328                         return False;
2329                 break;
2330         default:
2331                 DEBUG(0,("samr_group_info_ctr: unsupported switch level\n"));
2332                 break;
2333         }
2334
2335         return True;
2336 }
2337
2338 /*******************************************************************
2339 inits a SAMR_Q_CREATE_DOM_GROUP structure.
2340 ********************************************************************/
2341
2342 void init_samr_q_create_dom_group(SAMR_Q_CREATE_DOM_GROUP * q_e,
2343                                   POLICY_HND *pol, const char *acct_desc,
2344                                   uint32 access_mask)
2345 {
2346         DEBUG(5, ("init_samr_q_create_dom_group\n"));
2347
2348         q_e->pol = *pol;
2349
2350         init_unistr2(&q_e->uni_acct_desc, acct_desc, UNI_FLAGS_NONE);
2351         init_uni_hdr(&q_e->hdr_acct_desc, &q_e->uni_acct_desc);
2352
2353         q_e->access_mask = access_mask;
2354 }
2355
2356 /*******************************************************************
2357 reads or writes a structure.
2358 ********************************************************************/
2359
2360 BOOL samr_io_q_create_dom_group(const char *desc, SAMR_Q_CREATE_DOM_GROUP * q_e,
2361                                 prs_struct *ps, int depth)
2362 {
2363         if (q_e == NULL)
2364                 return False;
2365
2366         prs_debug(ps, depth, desc, "samr_io_q_create_dom_group");
2367         depth++;
2368
2369         if(!prs_align(ps))
2370                 return False;
2371
2372         if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
2373                 return False;
2374
2375         if(!smb_io_unihdr("hdr_acct_desc", &q_e->hdr_acct_desc, ps, depth))
2376                 return False;
2377         if(!smb_io_unistr2("uni_acct_desc", &q_e->uni_acct_desc,
2378                        q_e->hdr_acct_desc.buffer, ps, depth))
2379                 return False;
2380
2381         if(!prs_align(ps))
2382                 return False;
2383         if(!prs_uint32("access", ps, depth, &q_e->access_mask))
2384                 return False;
2385
2386         return True;
2387 }
2388
2389 /*******************************************************************
2390 reads or writes a structure.
2391 ********************************************************************/
2392
2393 BOOL samr_io_r_create_dom_group(const char *desc, SAMR_R_CREATE_DOM_GROUP * r_u,
2394                                 prs_struct *ps, int depth)
2395 {
2396         if (r_u == NULL)
2397                 return False;
2398
2399         prs_debug(ps, depth, desc, "samr_io_r_create_dom_group");
2400         depth++;
2401
2402         if(!prs_align(ps))
2403                 return False;
2404
2405         if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
2406                 return False;
2407
2408         if(!prs_uint32("rid   ", ps, depth, &r_u->rid))
2409                 return False;
2410         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2411                 return False;
2412
2413         return True;
2414 }
2415
2416 /*******************************************************************
2417 inits a SAMR_Q_DELETE_DOM_GROUP structure.
2418 ********************************************************************/
2419
2420 void init_samr_q_delete_dom_group(SAMR_Q_DELETE_DOM_GROUP * q_c,
2421                                   POLICY_HND *hnd)
2422 {
2423         DEBUG(5, ("init_samr_q_delete_dom_group\n"));
2424
2425         q_c->group_pol = *hnd;
2426 }
2427
2428 /*******************************************************************
2429 reads or writes a structure.
2430 ********************************************************************/
2431
2432 BOOL samr_io_q_delete_dom_group(const char *desc, SAMR_Q_DELETE_DOM_GROUP * q_u,
2433                                 prs_struct *ps, int depth)
2434 {
2435         if (q_u == NULL)
2436                 return False;
2437
2438         prs_debug(ps, depth, desc, "samr_io_q_delete_dom_group");
2439         depth++;
2440
2441         if(!prs_align(ps))
2442                 return False;
2443
2444         if(!smb_io_pol_hnd("group_pol", &q_u->group_pol, ps, depth))
2445                 return False;
2446
2447         return True;
2448 }
2449
2450 /*******************************************************************
2451 reads or writes a structure.
2452 ********************************************************************/
2453
2454 BOOL samr_io_r_delete_dom_group(const char *desc, SAMR_R_DELETE_DOM_GROUP * r_u,
2455                                 prs_struct *ps, int depth)
2456 {
2457         if (r_u == NULL)
2458                 return False;
2459
2460         prs_debug(ps, depth, desc, "samr_io_r_delete_dom_group");
2461         depth++;
2462
2463         if(!prs_align(ps))
2464                 return False;
2465
2466         if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
2467                 return False;
2468
2469         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2470                 return False;
2471
2472         return True;
2473 }
2474
2475 /*******************************************************************
2476 inits a SAMR_Q_DEL_GROUPMEM structure.
2477 ********************************************************************/
2478
2479 void init_samr_q_del_groupmem(SAMR_Q_DEL_GROUPMEM * q_e,
2480                               POLICY_HND *pol, uint32 rid)
2481 {
2482         DEBUG(5, ("init_samr_q_del_groupmem\n"));
2483
2484         q_e->pol = *pol;
2485         q_e->rid = rid;
2486 }
2487
2488 /*******************************************************************
2489 reads or writes a structure.
2490 ********************************************************************/
2491
2492 BOOL samr_io_q_del_groupmem(const char *desc, SAMR_Q_DEL_GROUPMEM * q_e,
2493                             prs_struct *ps, int depth)
2494 {
2495         if (q_e == NULL)
2496                 return False;
2497
2498         prs_debug(ps, depth, desc, "samr_io_q_del_groupmem");
2499         depth++;
2500
2501         if(!prs_align(ps))
2502                 return False;
2503
2504         if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
2505                 return False;
2506
2507         if(!prs_uint32("rid", ps, depth, &q_e->rid))
2508                 return False;
2509
2510         return True;
2511 }
2512
2513 /*******************************************************************
2514 inits a SAMR_R_DEL_GROUPMEM structure.
2515 ********************************************************************/
2516
2517 void init_samr_r_del_groupmem(SAMR_R_DEL_GROUPMEM * r_u, POLICY_HND *pol,
2518                               NTSTATUS status)
2519 {
2520         DEBUG(5, ("init_samr_r_del_groupmem\n"));
2521
2522         r_u->status = status;
2523 }
2524
2525 /*******************************************************************
2526 reads or writes a structure.
2527 ********************************************************************/
2528
2529 BOOL samr_io_r_del_groupmem(const char *desc, SAMR_R_DEL_GROUPMEM * r_u,
2530                             prs_struct *ps, int depth)
2531 {
2532         if (r_u == NULL)
2533                 return False;
2534
2535         prs_debug(ps, depth, desc, "samr_io_r_del_groupmem");
2536         depth++;
2537
2538         if(!prs_align(ps))
2539                 return False;
2540
2541         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2542                 return False;
2543
2544         return True;
2545 }
2546
2547 /*******************************************************************
2548 inits a SAMR_Q_ADD_GROUPMEM structure.
2549 ********************************************************************/
2550
2551 void init_samr_q_add_groupmem(SAMR_Q_ADD_GROUPMEM * q_e,
2552                               POLICY_HND *pol, uint32 rid)
2553 {
2554         DEBUG(5, ("init_samr_q_add_groupmem\n"));
2555
2556         q_e->pol = *pol;
2557         q_e->rid = rid;
2558         q_e->unknown = 0x0005;
2559 }
2560
2561 /*******************************************************************
2562 reads or writes a structure.
2563 ********************************************************************/
2564
2565 BOOL samr_io_q_add_groupmem(const char *desc, SAMR_Q_ADD_GROUPMEM * q_e,
2566                             prs_struct *ps, int depth)
2567 {
2568         if (q_e == NULL)
2569                 return False;
2570
2571         prs_debug(ps, depth, desc, "samr_io_q_add_groupmem");
2572         depth++;
2573
2574         if(!prs_align(ps))
2575                 return False;
2576
2577         if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
2578                 return False;
2579
2580         if(!prs_uint32("rid    ", ps, depth, &q_e->rid))
2581                 return False;
2582         if(!prs_uint32("unknown", ps, depth, &q_e->unknown))
2583                 return False;
2584
2585         return True;
2586 }
2587
2588 /*******************************************************************
2589 inits a SAMR_R_ADD_GROUPMEM structure.
2590 ********************************************************************/
2591
2592 void init_samr_r_add_groupmem(SAMR_R_ADD_GROUPMEM * r_u, POLICY_HND *pol,
2593                               NTSTATUS status)
2594 {
2595         DEBUG(5, ("init_samr_r_add_groupmem\n"));
2596
2597         r_u->status = status;
2598 }
2599
2600 /*******************************************************************
2601 reads or writes a structure.
2602 ********************************************************************/
2603
2604 BOOL samr_io_r_add_groupmem(const char *desc, SAMR_R_ADD_GROUPMEM * r_u,
2605                             prs_struct *ps, int depth)
2606 {
2607         if (r_u == NULL)
2608                 return False;
2609
2610         prs_debug(ps, depth, desc, "samr_io_r_add_groupmem");
2611         depth++;
2612
2613         if(!prs_align(ps))
2614                 return False;
2615
2616         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2617                 return False;
2618
2619         return True;
2620 }
2621
2622 /*******************************************************************
2623 inits a SAMR_Q_SET_GROUPINFO structure.
2624 ********************************************************************/
2625
2626 void init_samr_q_set_groupinfo(SAMR_Q_SET_GROUPINFO * q_e,
2627                                POLICY_HND *pol, GROUP_INFO_CTR * ctr)
2628 {
2629         DEBUG(5, ("init_samr_q_set_groupinfo\n"));
2630
2631         q_e->pol = *pol;
2632         q_e->ctr = ctr;
2633 }
2634
2635 /*******************************************************************
2636 reads or writes a structure.
2637 ********************************************************************/
2638
2639 BOOL samr_io_q_set_groupinfo(const char *desc, SAMR_Q_SET_GROUPINFO * q_e,
2640                              prs_struct *ps, int depth)
2641 {
2642         if (q_e == NULL)
2643                 return False;
2644
2645         prs_debug(ps, depth, desc, "samr_io_q_set_groupinfo");
2646         depth++;
2647
2648         if(!prs_align(ps))
2649                 return False;
2650
2651         if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
2652                 return False;
2653         
2654         if(!samr_group_info_ctr("ctr", &q_e->ctr, ps, depth))
2655                 return False;
2656
2657         return True;
2658 }
2659
2660 /*******************************************************************
2661 inits a SAMR_R_SET_GROUPINFO structure.
2662 ********************************************************************/
2663
2664 void init_samr_r_set_groupinfo(SAMR_R_SET_GROUPINFO * r_u, NTSTATUS status)
2665 {
2666         DEBUG(5, ("init_samr_r_set_groupinfo\n"));
2667
2668         r_u->status = status;
2669 }
2670
2671 /*******************************************************************
2672 reads or writes a structure.
2673 ********************************************************************/
2674
2675 BOOL samr_io_r_set_groupinfo(const char *desc, SAMR_R_SET_GROUPINFO * r_u,
2676                              prs_struct *ps, int depth)
2677 {
2678         if (r_u == NULL)
2679                 return False;
2680
2681         prs_debug(ps, depth, desc, "samr_io_r_set_groupinfo");
2682         depth++;
2683
2684         if(!prs_align(ps))
2685                 return False;
2686
2687         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2688                 return False;
2689
2690         return True;
2691 }
2692
2693 /*******************************************************************
2694 inits a SAMR_Q_QUERY_GROUPINFO structure.
2695 ********************************************************************/
2696
2697 void init_samr_q_query_groupinfo(SAMR_Q_QUERY_GROUPINFO * q_e,
2698                                  POLICY_HND *pol, uint16 switch_level)
2699 {
2700         DEBUG(5, ("init_samr_q_query_groupinfo\n"));
2701
2702         q_e->pol = *pol;
2703
2704         q_e->switch_level = switch_level;
2705 }
2706
2707 /*******************************************************************
2708 reads or writes a structure.
2709 ********************************************************************/
2710
2711 BOOL samr_io_q_query_groupinfo(const char *desc, SAMR_Q_QUERY_GROUPINFO * q_e,
2712                                prs_struct *ps, int depth)
2713 {
2714         if (q_e == NULL)
2715                 return False;
2716
2717         prs_debug(ps, depth, desc, "samr_io_q_query_groupinfo");
2718         depth++;
2719
2720         if(!prs_align(ps))
2721                 return False;
2722
2723         if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
2724                 return False;
2725
2726         if(!prs_uint16("switch_level", ps, depth, &q_e->switch_level))
2727                 return False;
2728
2729         return True;
2730 }
2731
2732 /*******************************************************************
2733 inits a SAMR_R_QUERY_GROUPINFO structure.
2734 ********************************************************************/
2735
2736 void init_samr_r_query_groupinfo(SAMR_R_QUERY_GROUPINFO * r_u,
2737                                  GROUP_INFO_CTR * ctr, NTSTATUS status)
2738 {
2739         DEBUG(5, ("init_samr_r_query_groupinfo\n"));
2740
2741         r_u->ptr = (NT_STATUS_IS_OK(status) && ctr != NULL) ? 1 : 0;
2742         r_u->ctr = ctr;
2743         r_u->status = status;
2744 }
2745
2746 /*******************************************************************
2747 reads or writes a structure.
2748 ********************************************************************/
2749
2750 BOOL samr_io_r_query_groupinfo(const char *desc, SAMR_R_QUERY_GROUPINFO * r_u,
2751                                prs_struct *ps, int depth)
2752 {
2753         if (r_u == NULL)
2754                 return False;
2755
2756         prs_debug(ps, depth, desc, "samr_io_r_query_groupinfo");
2757         depth++;
2758
2759         if(!prs_align(ps))
2760                 return False;
2761
2762         if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
2763                 return False;
2764
2765         if (r_u->ptr != 0) {
2766                 if(!samr_group_info_ctr("ctr", &r_u->ctr, ps, depth))
2767                         return False;
2768         }
2769
2770         if(!prs_align(ps))
2771                 return False;
2772         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2773                 return False;
2774
2775         return True;
2776 }
2777
2778 /*******************************************************************
2779 inits a SAMR_Q_QUERY_GROUPMEM structure.
2780 ********************************************************************/
2781
2782 void init_samr_q_query_groupmem(SAMR_Q_QUERY_GROUPMEM * q_c, POLICY_HND *hnd)
2783 {
2784         DEBUG(5, ("init_samr_q_query_groupmem\n"));
2785
2786         q_c->group_pol = *hnd;
2787 }
2788
2789 /*******************************************************************
2790 reads or writes a structure.
2791 ********************************************************************/
2792
2793 BOOL samr_io_q_query_groupmem(const char *desc, SAMR_Q_QUERY_GROUPMEM * q_u,
2794                               prs_struct *ps, int depth)
2795 {
2796         if (q_u == NULL)
2797                 return False;
2798
2799         prs_debug(ps, depth, desc, "samr_io_q_query_groupmem");
2800         depth++;
2801
2802         if(!prs_align(ps))
2803                 return False;
2804
2805         if(!smb_io_pol_hnd("group_pol", &q_u->group_pol, ps, depth))
2806                 return False;
2807
2808         return True;
2809 }
2810
2811 /*******************************************************************
2812 inits a SAMR_R_QUERY_GROUPMEM structure.
2813 ********************************************************************/
2814
2815 void init_samr_r_query_groupmem(SAMR_R_QUERY_GROUPMEM * r_u,
2816                                 uint32 num_entries, uint32 *rid,
2817                                 uint32 *attr, NTSTATUS status)
2818 {
2819         DEBUG(5, ("init_samr_r_query_groupmem\n"));
2820
2821         if (NT_STATUS_IS_OK(status)) {
2822                 r_u->ptr = 1;
2823                 r_u->num_entries = num_entries;
2824
2825                 r_u->ptr_attrs = attr != NULL ? 1 : 0;
2826                 r_u->ptr_rids = rid != NULL ? 1 : 0;
2827
2828                 r_u->num_rids = num_entries;
2829                 r_u->rid = rid;
2830
2831                 r_u->num_attrs = num_entries;
2832                 r_u->attr = attr;
2833         } else {
2834                 r_u->ptr = 0;
2835                 r_u->num_entries = 0;
2836         }
2837
2838         r_u->status = status;
2839 }
2840
2841 /*******************************************************************
2842 reads or writes a structure.
2843 ********************************************************************/
2844
2845 BOOL samr_io_r_query_groupmem(const char *desc, SAMR_R_QUERY_GROUPMEM * r_u,
2846                               prs_struct *ps, int depth)
2847 {
2848         uint32 i;
2849
2850         if (r_u == NULL)
2851                 return False;
2852
2853         if (UNMARSHALLING(ps))
2854                 ZERO_STRUCTP(r_u);
2855
2856         prs_debug(ps, depth, desc, "samr_io_r_query_groupmem");
2857         depth++;
2858
2859         if(!prs_align(ps))
2860                 return False;
2861
2862         if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
2863                 return False;
2864         if(!prs_uint32("num_entries ", ps, depth, &r_u->num_entries))
2865                 return False;
2866
2867         if (r_u->ptr != 0) {
2868                 if(!prs_uint32("ptr_rids ", ps, depth, &r_u->ptr_rids))
2869                         return False;
2870                 if(!prs_uint32("ptr_attrs", ps, depth, &r_u->ptr_attrs))
2871                         return False;
2872
2873                 if (r_u->ptr_rids != 0) {
2874                         if(!prs_uint32("num_rids", ps, depth, &r_u->num_rids))
2875                                 return False;
2876                         if (UNMARSHALLING(ps) && r_u->num_rids != 0) {
2877                                 r_u->rid = PRS_ALLOC_MEM(ps,uint32,r_u->num_rids);
2878                                 if (r_u->rid == NULL)
2879                                         return False;
2880                         }
2881
2882                         for (i = 0; i < r_u->num_rids; i++) {
2883                                 if(!prs_uint32("", ps, depth, &r_u->rid[i]))
2884                                         return False;
2885                         }
2886                 }
2887
2888                 if (r_u->ptr_attrs != 0) {
2889                         if(!prs_uint32("num_attrs", ps, depth, &r_u->num_attrs))
2890                                 return False;
2891
2892                         if (UNMARSHALLING(ps) && r_u->num_attrs != 0) {
2893                                 r_u->attr = PRS_ALLOC_MEM(ps,uint32,r_u->num_attrs);
2894                                 if (r_u->attr == NULL)
2895                                         return False;
2896                         }
2897
2898                         for (i = 0; i < r_u->num_attrs; i++) {
2899                                 if(!prs_uint32("", ps, depth, &r_u->attr[i]))
2900                                         return False;
2901                         }
2902                 }
2903         }
2904
2905         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2906                 return False;
2907
2908         return True;
2909 }
2910
2911 /*******************************************************************
2912 inits a SAMR_Q_QUERY_USERGROUPS structure.
2913 ********************************************************************/
2914
2915 void init_samr_q_query_usergroups(SAMR_Q_QUERY_USERGROUPS * q_u,
2916                                   POLICY_HND *hnd)
2917 {
2918         DEBUG(5, ("init_samr_q_query_usergroups\n"));
2919
2920         q_u->pol = *hnd;
2921 }
2922
2923 /*******************************************************************
2924 reads or writes a structure.
2925 ********************************************************************/
2926
2927 BOOL samr_io_q_query_usergroups(const char *desc, SAMR_Q_QUERY_USERGROUPS * q_u,
2928                                 prs_struct *ps, int depth)
2929 {
2930         if (q_u == NULL)
2931                 return False;
2932
2933         prs_debug(ps, depth, desc, "samr_io_q_query_usergroups");
2934         depth++;
2935
2936         if(!prs_align(ps))
2937                 return False;
2938
2939         if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
2940                 return False;
2941
2942         return True;
2943 }
2944
2945 /*******************************************************************
2946 inits a SAMR_R_QUERY_USERGROUPS structure.
2947 ********************************************************************/
2948
2949 void init_samr_r_query_usergroups(SAMR_R_QUERY_USERGROUPS * r_u,
2950                                   uint32 num_gids, DOM_GID * gid,
2951                                   NTSTATUS status)
2952 {
2953         DEBUG(5, ("init_samr_r_query_usergroups\n"));
2954
2955         if (NT_STATUS_IS_OK(status)) {
2956                 r_u->ptr_0 = 1;
2957                 r_u->num_entries = num_gids;
2958                 r_u->ptr_1 = (num_gids != 0) ? 1 : 0;
2959                 r_u->num_entries2 = num_gids;
2960
2961                 r_u->gid = gid;
2962         } else {
2963                 r_u->ptr_0 = 0;
2964                 r_u->num_entries = 0;
2965                 r_u->ptr_1 = 0;
2966                 r_u->gid = NULL;
2967         }
2968
2969         r_u->status = status;
2970 }
2971
2972 /*******************************************************************
2973 reads or writes a structure.
2974 ********************************************************************/
2975
2976 BOOL samr_io_gids(const char *desc, uint32 *num_gids, DOM_GID ** gid,
2977                   prs_struct *ps, int depth)
2978 {
2979         uint32 i;
2980         if (gid == NULL)
2981                 return False;
2982
2983         prs_debug(ps, depth, desc, "samr_io_gids");
2984         depth++;
2985
2986         if(!prs_align(ps))
2987                 return False;
2988
2989         if(!prs_uint32("num_gids", ps, depth, num_gids))
2990                 return False;
2991
2992         if ((*num_gids) != 0) {
2993                 if (UNMARSHALLING(ps)) {
2994                         (*gid) = PRS_ALLOC_MEM(ps,DOM_GID,*num_gids);
2995                 }
2996
2997                 if ((*gid) == NULL) {
2998                         return False;
2999                 }
3000
3001                 for (i = 0; i < (*num_gids); i++) {
3002                         if(!smb_io_gid("gids", &(*gid)[i], ps, depth))
3003                                 return False;
3004                 }
3005         }
3006
3007         return True;
3008 }
3009
3010 /*******************************************************************
3011 reads or writes a structure.
3012 ********************************************************************/
3013
3014 BOOL samr_io_r_query_usergroups(const char *desc, SAMR_R_QUERY_USERGROUPS * r_u,
3015                                 prs_struct *ps, int depth)
3016 {
3017         if (r_u == NULL)
3018                 return False;
3019
3020         prs_debug(ps, depth, desc, "samr_io_r_query_usergroups");
3021         depth++;
3022
3023         if(!prs_align(ps))
3024                 return False;
3025
3026         if(!prs_uint32("ptr_0       ", ps, depth, &r_u->ptr_0))
3027                 return False;
3028
3029         if (r_u->ptr_0 != 0) {
3030                 if(!prs_uint32("num_entries ", ps, depth, &r_u->num_entries))
3031                         return False;
3032                 if(!prs_uint32("ptr_1       ", ps, depth, &r_u->ptr_1))
3033                         return False;
3034
3035                 if (r_u->num_entries != 0 && r_u->ptr_1 != 0) {
3036                         if(!samr_io_gids("gids", &r_u->num_entries2, &r_u->gid, ps, depth))
3037                                 return False;
3038                 }
3039         }
3040
3041         if(!prs_align(ps))
3042                 return False;
3043         if(!prs_ntstatus("status", ps, depth, &r_u->status))
3044           return False;
3045
3046         return True;
3047 }
3048
3049 /*******************************************************************
3050 inits a SAMR_Q_ENUM_DOMAINS structure.
3051 ********************************************************************/
3052
3053 void init_samr_q_enum_domains(SAMR_Q_ENUM_DOMAINS * q_e,
3054                               POLICY_HND *pol,
3055                               uint32 start_idx, uint32 size)
3056 {
3057         DEBUG(5, ("init_samr_q_enum_domains\n"));
3058
3059         q_e->pol = *pol;
3060
3061         q_e->start_idx = start_idx;
3062         q_e->max_size = size;
3063 }
3064
3065 /*******************************************************************
3066 reads or writes a structure.
3067 ********************************************************************/
3068
3069 BOOL samr_io_q_enum_domains(const char *desc, SAMR_Q_ENUM_DOMAINS * q_e,
3070                             prs_struct *ps, int depth)
3071 {
3072         if (q_e == NULL)
3073                 return False;
3074
3075         prs_debug(ps, depth, desc, "samr_io_q_enum_domains");
3076         depth++;
3077
3078         if(!prs_align(ps))
3079                 return False;
3080
3081         if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
3082                 return False;
3083
3084         if(!prs_uint32("start_idx", ps, depth, &q_e->start_idx))
3085                 return False;
3086         if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
3087                 return False;
3088
3089         return True;
3090 }
3091
3092 /*******************************************************************
3093 inits a SAMR_R_ENUM_DOMAINS structure.
3094 ********************************************************************/
3095
3096 void init_samr_r_enum_domains(SAMR_R_ENUM_DOMAINS * r_u,
3097                               uint32 next_idx, uint32 num_sam_entries)
3098 {
3099         DEBUG(5, ("init_samr_r_enum_domains\n"));
3100
3101         r_u->next_idx = next_idx;
3102
3103         if (num_sam_entries != 0) {
3104                 r_u->ptr_entries1 = 1;
3105                 r_u->ptr_entries2 = 1;
3106                 r_u->num_entries2 = num_sam_entries;
3107                 r_u->num_entries3 = num_sam_entries;
3108
3109                 r_u->num_entries4 = num_sam_entries;
3110         } else {
3111                 r_u->ptr_entries1 = 0;
3112                 r_u->num_entries2 = num_sam_entries;
3113                 r_u->ptr_entries2 = 1;
3114         }
3115 }
3116
3117 /*******************************************************************
3118 reads or writes a structure.
3119 ********************************************************************/
3120
3121 BOOL samr_io_r_enum_domains(const char *desc, SAMR_R_ENUM_DOMAINS * r_u,
3122                             prs_struct *ps, int depth)
3123 {
3124         uint32 i;
3125
3126         if (r_u == NULL)
3127                 return False;
3128
3129         prs_debug(ps, depth, desc, "samr_io_r_enum_domains");
3130         depth++;
3131
3132         if(!prs_align(ps))
3133                 return False;
3134
3135         if(!prs_uint32("next_idx    ", ps, depth, &r_u->next_idx))
3136                 return False;
3137         if(!prs_uint32("ptr_entries1", ps, depth, &r_u->ptr_entries1))
3138                 return False;
3139
3140         if (r_u->ptr_entries1 != 0) {
3141                 if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
3142                         return False;
3143                 if(!prs_uint32("ptr_entries2", ps, depth, &r_u->ptr_entries2))
3144                         return False;
3145                 if(!prs_uint32("num_entries3", ps, depth, &r_u->num_entries3))
3146                         return False;
3147
3148                 if (UNMARSHALLING(ps)) {
3149                         r_u->sam = PRS_ALLOC_MEM(ps,SAM_ENTRY,r_u->num_entries2);
3150                         r_u->uni_dom_name = PRS_ALLOC_MEM(ps,UNISTR2,r_u->num_entries2);
3151                 }
3152
3153                 if ((r_u->sam == NULL || r_u->uni_dom_name == NULL) && r_u->num_entries2 != 0) {
3154                         DEBUG(0, ("NULL pointers in SAMR_R_ENUM_DOMAINS\n"));
3155                         r_u->num_entries4 = 0;
3156                         r_u->status = NT_STATUS_MEMORY_NOT_ALLOCATED;
3157                         return False;
3158                 }
3159
3160                 for (i = 0; i < r_u->num_entries2; i++) {
3161                         fstring tmp;
3162                         slprintf(tmp, sizeof(tmp) - 1, "dom[%d]", i);
3163                         if(!sam_io_sam_entry(tmp, &r_u->sam[i], ps, depth))
3164                                 return False;
3165                 }
3166
3167                 for (i = 0; i < r_u->num_entries2; i++) {
3168                         fstring tmp;
3169                         slprintf(tmp, sizeof(tmp) - 1, "dom[%d]", i);
3170                         if(!smb_io_unistr2(tmp, &r_u->uni_dom_name[i],
3171                                        r_u->sam[i].hdr_name.buffer, ps,
3172                                        depth))
3173                                 return False;
3174                 }
3175
3176         }
3177
3178         if(!prs_align(ps))
3179                 return False;
3180         if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4))
3181                 return False;
3182         if(!prs_ntstatus("status", ps, depth, &r_u->status))
3183                 return False;
3184
3185         return True;
3186 }
3187
3188 /*******************************************************************
3189 inits a SAMR_Q_ENUM_DOM_GROUPS structure.
3190 ********************************************************************/
3191
3192 void init_samr_q_enum_dom_groups(SAMR_Q_ENUM_DOM_GROUPS * q_e,
3193                                  POLICY_HND *pol,
3194                                  uint32 start_idx, uint32 size)
3195 {
3196         DEBUG(5, ("init_samr_q_enum_dom_groups\n"));
3197
3198         q_e->pol = *pol;
3199
3200         q_e->start_idx = start_idx;
3201         q_e->max_size = size;
3202 }
3203
3204 /*******************************************************************
3205 reads or writes a structure.
3206 ********************************************************************/
3207
3208 BOOL samr_io_q_enum_dom_groups(const char *desc, SAMR_Q_ENUM_DOM_GROUPS * q_e,
3209                                prs_struct *ps, int depth)
3210 {
3211         if (q_e == NULL)
3212                 return False;
3213
3214         prs_debug(ps, depth, desc, "samr_io_q_enum_dom_groups");
3215         depth++;
3216
3217         if(!prs_align(ps))
3218                 return False;
3219
3220         if(!smb_io_pol_hnd("pol", &(q_e->pol), ps, depth))
3221                 return False;
3222
3223         if(!prs_uint32("start_idx", ps, depth, &q_e->start_idx))
3224                 return False;
3225         if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
3226                 return False;
3227
3228         return True;
3229 }
3230
3231 /*******************************************************************
3232 inits a SAMR_R_ENUM_DOM_GROUPS structure.
3233 ********************************************************************/
3234
3235 void init_samr_r_enum_dom_groups(SAMR_R_ENUM_DOM_GROUPS * r_u,
3236                                  uint32 next_idx, uint32 num_sam_entries)
3237 {
3238         DEBUG(5, ("init_samr_r_enum_dom_groups\n"));
3239
3240         r_u->next_idx = next_idx;
3241
3242         if (num_sam_entries != 0) {
3243                 r_u->ptr_entries1 = 1;
3244                 r_u->ptr_entries2 = 1;
3245                 r_u->num_entries2 = num_sam_entries;
3246                 r_u->num_entries3 = num_sam_entries;
3247
3248                 r_u->num_entries4 = num_sam_entries;
3249         } else {
3250                 r_u->ptr_entries1 = 0;
3251                 r_u->num_entries2 = num_sam_entries;
3252                 r_u->ptr_entries2 = 1;
3253         }
3254 }
3255
3256 /*******************************************************************
3257 reads or writes a structure.
3258 ********************************************************************/
3259
3260 BOOL samr_io_r_enum_dom_groups(const char *desc, SAMR_R_ENUM_DOM_GROUPS * r_u,
3261                                prs_struct *ps, int depth)
3262 {
3263         uint32 i;
3264
3265         if (r_u == NULL)
3266                 return False;
3267
3268         prs_debug(ps, depth, desc, "samr_io_r_enum_dom_groups");
3269         depth++;
3270
3271         if(!prs_align(ps))
3272                 return False;
3273
3274         if(!prs_uint32("next_idx    ", ps, depth, &r_u->next_idx))
3275                 return False;
3276         if(!prs_uint32("ptr_entries1", ps, depth, &r_u->ptr_entries1))
3277                 return False;
3278
3279         if (r_u->ptr_entries1 != 0) {
3280                 if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
3281                         return False;
3282                 if(!prs_uint32("ptr_entries2", ps, depth, &r_u->ptr_entries2))
3283                         return False;
3284                 if(!prs_uint32("num_entries3", ps, depth, &r_u->num_entries3))
3285                         return False;
3286
3287                 if (UNMARSHALLING(ps)) {
3288                         r_u->sam = PRS_ALLOC_MEM(ps,SAM_ENTRY,r_u->num_entries2);
3289                         r_u->uni_grp_name = PRS_ALLOC_MEM(ps,UNISTR2,r_u->num_entries2);
3290                 }
3291
3292                 if ((r_u->sam == NULL || r_u->uni_grp_name == NULL) && r_u->num_entries2 != 0) {
3293                         DEBUG(0,
3294                               ("NULL pointers in SAMR_R_ENUM_DOM_GROUPS\n"));
3295                         r_u->num_entries4 = 0;
3296                         r_u->status = NT_STATUS_MEMORY_NOT_ALLOCATED;
3297                         return False;
3298                 }
3299
3300                 for (i = 0; i < r_u->num_entries2; i++) {
3301                         if(!sam_io_sam_entry("", &r_u->sam[i], ps, depth))
3302                                 return False;
3303                 }
3304
3305                 for (i = 0; i < r_u->num_entries2; i++) {
3306                         if(!smb_io_unistr2("", &r_u->uni_grp_name[i],
3307                                        r_u->sam[i].hdr_name.buffer, ps, depth))
3308                                 return False;
3309                 }
3310         }
3311
3312         if(!prs_align(ps))
3313                 return False;
3314         if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4))
3315                 return False;
3316         if(!prs_ntstatus("status", ps, depth, &r_u->status))
3317                 return False;
3318
3319         return True;
3320 }
3321
3322 /*******************************************************************
3323 inits a SAMR_Q_ENUM_DOM_ALIASES structure.
3324 ********************************************************************/
3325
3326 void init_samr_q_enum_dom_aliases(SAMR_Q_ENUM_DOM_ALIASES * q_e,
3327                                   POLICY_HND *pol, uint32 start_idx,
3328                                   uint32 size)
3329 {
3330         DEBUG(5, ("init_samr_q_enum_dom_aliases\n"));
3331
3332         q_e->pol = *pol;
3333
3334         q_e->start_idx = start_idx;
3335         q_e->max_size = size;
3336 }
3337
3338
3339 /*******************************************************************
3340 reads or writes a structure.
3341 ********************************************************************/
3342
3343 BOOL samr_io_q_enum_dom_aliases(const char *desc, SAMR_Q_ENUM_DOM_ALIASES * q_e,
3344                                 prs_struct *ps, int depth)
3345 {
3346         if (q_e == NULL)
3347                 return False;
3348
3349         prs_debug(ps, depth, desc, "samr_io_q_enum_dom_aliases");
3350         depth++;
3351
3352         if(!prs_align(ps))
3353                 return False;
3354
3355         if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
3356                 return False;
3357
3358         if(!prs_uint32("start_idx", ps, depth, &q_e->start_idx))
3359                 return False;
3360         if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
3361                 return False;
3362
3363         return True;
3364 }
3365
3366 /*******************************************************************
3367 inits a SAMR_R_ENUM_DOM_ALIASES structure.
3368 ********************************************************************/
3369
3370 void init_samr_r_enum_dom_aliases(SAMR_R_ENUM_DOM_ALIASES *r_u, uint32 next_idx, uint32 num_sam_entries)
3371 {
3372         DEBUG(5, ("init_samr_r_enum_dom_aliases\n"));
3373
3374         r_u->next_idx = next_idx;
3375
3376         if (num_sam_entries != 0) {
3377                 r_u->ptr_entries1 = 1;
3378                 r_u->ptr_entries2 = 1;
3379                 r_u->num_entries2 = num_sam_entries;
3380                 r_u->num_entries3 = num_sam_entries;
3381
3382                 r_u->num_entries4 = num_sam_entries;
3383         } else {
3384                 r_u->ptr_entries1 = 0;
3385                 r_u->num_entries2 = num_sam_entries;
3386                 r_u->ptr_entries2 = 1;
3387         }
3388 }
3389
3390 /*******************************************************************
3391 reads or writes a structure.
3392 ********************************************************************/
3393
3394 BOOL samr_io_r_enum_dom_aliases(const char *desc, SAMR_R_ENUM_DOM_ALIASES * r_u,
3395                                 prs_struct *ps, int depth)
3396 {
3397         uint32 i;
3398
3399         if (r_u == NULL)
3400                 return False;
3401
3402         prs_debug(ps, depth, desc, "samr_io_r_enum_dom_aliases");
3403         depth++;
3404
3405         if(!prs_align(ps))
3406                 return False;
3407