[GLUE] Rsync SAMBA_3_2_0 SVN r25598 in order to create the v3-2-test branch.
[sfrench/samba-autobuild/.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 3 of the License, or
15  *  (at your option) any later version.
16  *  
17  *  This program is distributed in the hope that it will be useful,
18  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  *  GNU General Public License for more details.
21  *  
22  *  You should have received a copy of the GNU General Public License
23  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
24  */
25
26 #include "includes.h"
27
28 #undef DBGC_CLASS
29 #define DBGC_CLASS DBGC_RPC_PARSE
30
31 /*******************************************************************
32 inits a SAMR_Q_CLOSE_HND structure.
33 ********************************************************************/
34
35 void init_samr_q_close_hnd(SAMR_Q_CLOSE_HND * q_c, POLICY_HND *hnd)
36 {
37         DEBUG(5, ("init_samr_q_close_hnd\n"));
38         
39         q_c->pol = *hnd;
40 }
41
42 /*******************************************************************
43 reads or writes a structure.
44 ********************************************************************/
45
46 BOOL samr_io_q_close_hnd(const char *desc, SAMR_Q_CLOSE_HND * q_u,
47                          prs_struct *ps, int depth)
48 {
49         if (q_u == NULL)
50                 return False;
51
52         prs_debug(ps, depth, desc, "samr_io_q_close_hnd");
53         depth++;
54
55         if(!prs_align(ps))
56                 return False;
57
58         return smb_io_pol_hnd("pol", &q_u->pol, ps, depth);
59 }
60
61 /*******************************************************************
62 reads or writes a structure.
63 ********************************************************************/
64
65 BOOL samr_io_r_close_hnd(const char *desc, SAMR_R_CLOSE_HND * r_u,
66                          prs_struct *ps, int depth)
67 {
68         if (r_u == NULL)
69                 return False;
70
71         prs_debug(ps, depth, desc, "samr_io_r_close_hnd");
72         depth++;
73
74         if(!prs_align(ps))
75                 return False;
76
77         if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
78                 return False;
79
80         if(!prs_ntstatus("status", ps, depth, &r_u->status))
81                 return False;
82
83         return True;
84 }
85
86 /*******************************************************************
87 inits a SAMR_Q_LOOKUP_DOMAIN structure.
88 ********************************************************************/
89
90 void init_samr_q_lookup_domain(SAMR_Q_LOOKUP_DOMAIN * q_u,
91                                POLICY_HND *pol, char *dom_name)
92 {
93         DEBUG(5, ("init_samr_q_lookup_domain\n"));
94
95         q_u->connect_pol = *pol;
96
97         init_unistr2(&q_u->uni_domain, dom_name, UNI_FLAGS_NONE);
98         init_uni_hdr(&q_u->hdr_domain, &q_u->uni_domain);
99 }
100
101 /*******************************************************************
102 reads or writes a structure.
103 ********************************************************************/
104 BOOL samr_io_q_lookup_domain(const char *desc, SAMR_Q_LOOKUP_DOMAIN * q_u,
105                              prs_struct *ps, int depth)
106 {
107         if (q_u == NULL)
108                 return False;
109
110         prs_debug(ps, depth, desc, "samr_io_q_lookup_domain");
111         depth++;
112
113         if(!prs_align(ps))
114                 return False;
115
116         if(!smb_io_pol_hnd("connect_pol", &q_u->connect_pol, ps, depth))
117                 return False;
118
119         if(!smb_io_unihdr("hdr_domain", &q_u->hdr_domain, ps, depth))
120                 return False;
121
122         if(!smb_io_unistr2("uni_domain", &q_u->uni_domain, q_u->hdr_domain.buffer, ps, depth))
123                 return False;
124
125         return True;
126 }
127
128 /*******************************************************************
129 inits a SAMR_R_LOOKUP_DOMAIN structure.
130 ********************************************************************/
131
132 void init_samr_r_lookup_domain(SAMR_R_LOOKUP_DOMAIN * r_u,
133                                DOM_SID *dom_sid, NTSTATUS status)
134 {
135         DEBUG(5, ("init_samr_r_lookup_domain\n"));
136
137         r_u->status = status;
138         r_u->ptr_sid = 0;
139         if (NT_STATUS_IS_OK(status)) {
140                 r_u->ptr_sid = 1;
141                 init_dom_sid2(&r_u->dom_sid, dom_sid);
142         }
143 }
144
145 /*******************************************************************
146 reads or writes a structure.
147 ********************************************************************/
148
149 BOOL samr_io_r_lookup_domain(const char *desc, SAMR_R_LOOKUP_DOMAIN * r_u,
150                              prs_struct *ps, int depth)
151 {
152         if (r_u == NULL)
153                 return False;
154
155         prs_debug(ps, depth, desc, "samr_io_r_lookup_domain");
156         depth++;
157
158         if(!prs_align(ps))
159                 return False;
160
161         if(!prs_uint32("ptr", ps, depth, &r_u->ptr_sid))
162                 return False;
163
164         if (r_u->ptr_sid != 0) {
165                 if(!smb_io_dom_sid2("sid", &r_u->dom_sid, ps, depth))
166                         return False;
167                 if(!prs_align(ps))
168                         return False;
169         }
170
171         if(!prs_ntstatus("status", ps, depth, &r_u->status))
172                 return False;
173
174         return True;
175 }
176
177 /*******************************************************************
178 reads or writes a structure.
179 ********************************************************************/
180
181 void init_samr_q_remove_sid_foreign_domain(SAMR_Q_REMOVE_SID_FOREIGN_DOMAIN * q_u, POLICY_HND *dom_pol, DOM_SID *sid)
182 {
183         DEBUG(5, ("samr_init_samr_q_remove_sid_foreign_domain\n"));
184
185         q_u->dom_pol = *dom_pol;
186         init_dom_sid2(&q_u->sid, sid);
187 }
188
189 /*******************************************************************
190 reads or writes a structure.
191 ********************************************************************/
192
193 BOOL samr_io_q_remove_sid_foreign_domain(const char *desc, SAMR_Q_REMOVE_SID_FOREIGN_DOMAIN * q_u,
194                           prs_struct *ps, int depth)
195 {
196         if (q_u == NULL)
197                 return False;
198
199         prs_debug(ps, depth, desc, "samr_io_q_remove_sid_foreign_domain");
200         depth++;
201
202         if(!prs_align(ps))
203                 return False;
204
205         if(!smb_io_pol_hnd("domain_pol", &q_u->dom_pol, ps, depth))
206                 return False;
207
208         if(!smb_io_dom_sid2("sid", &q_u->sid, ps, depth))
209                 return False;
210
211         if(!prs_align(ps))
212                 return False;
213
214         return True;
215 }
216
217 /*******************************************************************
218 reads or writes a structure.
219 ********************************************************************/
220
221 BOOL samr_io_r_remove_sid_foreign_domain(const char *desc, SAMR_R_REMOVE_SID_FOREIGN_DOMAIN * r_u,
222                           prs_struct *ps, int depth)
223 {
224         if (r_u == NULL)
225                 return False;
226
227         prs_debug(ps, depth, desc, "samr_io_r_remove_sid_foreign_domain");
228         depth++;
229
230         if(!prs_align(ps))
231                 return False;
232
233         if(!prs_ntstatus("status", ps, depth, &r_u->status))
234                 return False;
235
236         return True;
237 }
238
239 /*******************************************************************
240 reads or writes a structure.
241 ********************************************************************/
242
243 void init_samr_q_open_domain(SAMR_Q_OPEN_DOMAIN * q_u,
244                              POLICY_HND *pol, uint32 flags,
245                              const DOM_SID *sid)
246 {
247         DEBUG(5, ("samr_init_samr_q_open_domain\n"));
248
249         q_u->pol = *pol;
250         q_u->flags = flags;
251         init_dom_sid2(&q_u->dom_sid, sid);
252 }
253
254 /*******************************************************************
255 reads or writes a structure.
256 ********************************************************************/
257
258 BOOL samr_io_q_open_domain(const char *desc, SAMR_Q_OPEN_DOMAIN * q_u,
259                            prs_struct *ps, int depth)
260 {
261         if (q_u == NULL)
262                 return False;
263
264         prs_debug(ps, depth, desc, "samr_io_q_open_domain");
265         depth++;
266
267         if(!prs_align(ps))
268                 return False;
269
270         if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
271                 return False;
272
273         if(!prs_uint32("flags", ps, depth, &q_u->flags))
274                 return False;
275
276         if(!smb_io_dom_sid2("sid", &q_u->dom_sid, ps, depth))
277                 return False;
278
279         return True;
280 }
281
282 /*******************************************************************
283 reads or writes a structure.
284 ********************************************************************/
285
286 BOOL samr_io_r_open_domain(const char *desc, SAMR_R_OPEN_DOMAIN * r_u,
287                            prs_struct *ps, int depth)
288 {
289         if (r_u == NULL)
290                 return False;
291
292         prs_debug(ps, depth, desc, "samr_io_r_open_domain");
293         depth++;
294
295         if(!prs_align(ps))
296                 return False;
297
298         if(!smb_io_pol_hnd("domain_pol", &r_u->domain_pol, ps, depth))
299                 return False;
300
301         if(!prs_ntstatus("status", ps, depth, &r_u->status))
302                 return False;
303
304         return True;
305 }
306
307 /*******************************************************************
308 reads or writes a structure.
309 ********************************************************************/
310
311 void init_samr_q_get_usrdom_pwinfo(SAMR_Q_GET_USRDOM_PWINFO * q_u,
312                                    POLICY_HND *user_pol)
313 {
314         DEBUG(5, ("samr_init_samr_q_get_usrdom_pwinfo\n"));
315
316         q_u->user_pol = *user_pol;
317 }
318
319 /*******************************************************************
320 reads or writes a structure.
321 ********************************************************************/
322
323 BOOL samr_io_q_get_usrdom_pwinfo(const char *desc, SAMR_Q_GET_USRDOM_PWINFO * q_u,
324                                  prs_struct *ps, int depth)
325 {
326         if (q_u == NULL)
327                 return False;
328
329         prs_debug(ps, depth, desc, "samr_io_q_get_usrdom_pwinfo");
330         depth++;
331
332         if(!prs_align(ps))
333                 return False;
334
335         return smb_io_pol_hnd("user_pol", &q_u->user_pol, ps, depth);
336 }
337
338 /*******************************************************************
339  Init.
340 ********************************************************************/
341
342 void init_samr_r_get_usrdom_pwinfo(SAMR_R_GET_USRDOM_PWINFO *r_u, NTSTATUS status)
343 {
344         DEBUG(5, ("init_samr_r_get_usrdom_pwinfo\n"));
345         
346         r_u->min_pwd_length = 0x0000;
347
348         /*
349          * used to be   
350          * r_u->unknown_1 = 0x0015;
351          * but for trusts.
352          */
353         r_u->unknown_1 = 0x01D1;
354         r_u->unknown_1 = 0x0015;
355
356         r_u->password_properties = 0x00000000;
357
358         r_u->status = status;
359 }
360
361 /*******************************************************************
362 reads or writes a structure.
363 ********************************************************************/
364
365 BOOL samr_io_r_get_usrdom_pwinfo(const char *desc, SAMR_R_GET_USRDOM_PWINFO * r_u,
366                                  prs_struct *ps, int depth)
367 {
368         if (r_u == NULL)
369                 return False;
370
371         prs_debug(ps, depth, desc, "samr_io_r_get_usrdom_pwinfo");
372         depth++;
373
374         if(!prs_align(ps))
375                 return False;
376
377         if(!prs_uint16("min_pwd_length", ps, depth, &r_u->min_pwd_length))
378                 return False;
379         if(!prs_uint16("unknown_1", ps, depth, &r_u->unknown_1))
380                 return False;
381         if(!prs_uint32("password_properties", ps, depth, &r_u->password_properties))
382                 return False;
383
384         if(!prs_ntstatus("status   ", ps, depth, &r_u->status))
385                 return False;
386
387         return True;
388 }
389
390
391 /*******************************************************************
392 reads or writes a structure.
393 ********************************************************************/
394
395 BOOL samr_io_q_set_sec_obj(const char *desc, SAMR_Q_SET_SEC_OBJ * q_u,
396                              prs_struct *ps, int depth)
397 {
398         if (q_u == NULL)
399                 return False;
400
401         prs_debug(ps, depth, desc, "samr_io_q_set_sec_obj");
402         depth++;
403
404         if(!prs_align(ps))
405                 return False;
406
407         if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
408                 return False;
409
410         if(!prs_uint32("sec_info", ps, depth, &q_u->sec_info))
411                 return False;
412                 
413         if(!sec_io_desc_buf("sec_desc", &q_u->buf, ps, depth))
414                 return False;
415         
416         return True;
417 }
418
419
420 /*******************************************************************
421 reads or writes a structure.
422 ********************************************************************/
423
424 void init_samr_q_query_sec_obj(SAMR_Q_QUERY_SEC_OBJ * q_u,
425                                POLICY_HND *user_pol, uint32 sec_info)
426 {
427         DEBUG(5, ("samr_init_samr_q_query_sec_obj\n"));
428
429         q_u->user_pol = *user_pol;
430         q_u->sec_info = sec_info;
431 }
432
433
434 /*******************************************************************
435 reads or writes a structure.
436 ********************************************************************/
437
438 BOOL samr_io_q_query_sec_obj(const char *desc, SAMR_Q_QUERY_SEC_OBJ * q_u,
439                              prs_struct *ps, int depth)
440 {
441         if (q_u == NULL)
442                 return False;
443
444         prs_debug(ps, depth, desc, "samr_io_q_query_sec_obj");
445         depth++;
446
447         if(!prs_align(ps))
448                 return False;
449
450         if(!smb_io_pol_hnd("user_pol", &q_u->user_pol, ps, depth))
451                 return False;
452
453         if(!prs_uint32("sec_info", ps, depth, &q_u->sec_info))
454                 return False;
455
456         return True;
457 }
458
459 /*******************************************************************
460 reads or writes a structure.
461 ********************************************************************/
462
463 void init_samr_q_query_domain_info(SAMR_Q_QUERY_DOMAIN_INFO * q_u,
464                                    POLICY_HND *domain_pol, uint16 switch_value)
465 {
466         DEBUG(5, ("samr_init_samr_q_query_domain_info\n"));
467
468         q_u->domain_pol = *domain_pol;
469         q_u->switch_value = switch_value;
470 }
471
472 /*******************************************************************
473 reads or writes a structure.
474 ********************************************************************/
475
476 BOOL samr_io_q_query_domain_info(const char *desc, SAMR_Q_QUERY_DOMAIN_INFO * q_u,
477                                  prs_struct *ps, int depth)
478 {
479         if (q_u == NULL)
480                 return False;
481
482         prs_debug(ps, depth, desc, "samr_io_q_query_domain_info");
483         depth++;
484
485         if(!prs_align(ps))
486                 return False;
487
488         if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
489                 return False;
490
491         if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
492                 return False;
493
494         return True;
495 }
496
497 /*******************************************************************
498 inits a structure.
499 ********************************************************************/
500
501 void init_unk_info1(SAM_UNK_INFO_1 *u_1, uint16 min_pass_len, uint16 pass_hist, 
502                     uint32 password_properties, NTTIME nt_expire, NTTIME nt_min_age)
503 {
504         u_1->min_length_password = min_pass_len;
505         u_1->password_history = pass_hist;
506         
507         if (lp_check_password_script() && *lp_check_password_script()) {
508                 password_properties |= DOMAIN_PASSWORD_COMPLEX;
509         }
510         u_1->password_properties = password_properties;
511
512         /* password never expire */
513         u_1->expire = nt_expire;
514
515         /* can change the password now */
516         u_1->min_passwordage = nt_min_age;
517         
518 }
519
520 /*******************************************************************
521 reads or writes a structure.
522 ********************************************************************/
523
524 static BOOL sam_io_unk_info1(const char *desc, SAM_UNK_INFO_1 * u_1,
525                              prs_struct *ps, int depth)
526 {
527         if (u_1 == NULL)
528           return False;
529
530         prs_debug(ps, depth, desc, "sam_io_unk_info1");
531         depth++;
532
533         if(!prs_uint16("min_length_password", ps, depth, &u_1->min_length_password))
534                 return False;
535         if(!prs_uint16("password_history", ps, depth, &u_1->password_history))
536                 return False;
537         if(!prs_uint32("password_properties", ps, depth, &u_1->password_properties))
538                 return False;
539         if(!smb_io_time("expire", &u_1->expire, ps, depth))
540                 return False;
541         if(!smb_io_time("min_passwordage", &u_1->min_passwordage, ps, depth))
542                 return False;
543
544         return True;
545 }
546
547 /*******************************************************************
548 inits a structure.
549 ********************************************************************/
550
551 void init_unk_info2(SAM_UNK_INFO_2 * u_2,
552                         const char *comment, const char *domain, const char *server,
553                         uint32 seq_num, uint32 num_users, uint32 num_groups, uint32 num_alias, NTTIME nt_logout, uint32 server_role)
554 {
555         u_2->logout = nt_logout;
556
557         u_2->seq_num = seq_num;
558
559         
560         u_2->unknown_4 = 0x00000001;
561         u_2->server_role = server_role;
562         u_2->unknown_6 = 0x00000001;
563         u_2->num_domain_usrs = num_users;
564         u_2->num_domain_grps = num_groups;
565         u_2->num_local_grps = num_alias;
566
567         init_unistr2(&u_2->uni_comment, comment, UNI_FLAGS_NONE);
568         init_uni_hdr(&u_2->hdr_comment, &u_2->uni_comment);
569         init_unistr2(&u_2->uni_domain, domain, UNI_FLAGS_NONE);
570         init_uni_hdr(&u_2->hdr_domain, &u_2->uni_domain);
571         init_unistr2(&u_2->uni_server, server, UNI_FLAGS_NONE);
572         init_uni_hdr(&u_2->hdr_server, &u_2->uni_server);
573 }
574
575 /*******************************************************************
576 reads or writes a structure.
577 ********************************************************************/
578
579 static BOOL sam_io_unk_info2(const char *desc, SAM_UNK_INFO_2 * u_2,
580                              prs_struct *ps, int depth)
581 {
582         if (u_2 == NULL)
583                 return False;
584
585         prs_debug(ps, depth, desc, "sam_io_unk_info2");
586         depth++;
587
588         if(!smb_io_time("logout", &u_2->logout, ps, depth))
589                 return False;
590         if(!smb_io_unihdr("hdr_comment", &u_2->hdr_comment, ps, depth))
591                 return False;
592         if(!smb_io_unihdr("hdr_domain", &u_2->hdr_domain, ps, depth))
593                 return False;
594         if(!smb_io_unihdr("hdr_server", &u_2->hdr_server, ps, depth))
595                 return False;
596
597         /* put all the data in here, at the moment, including what the above
598            pointer is referring to
599          */
600
601         if(!prs_uint64("seq_num ", ps, depth, &u_2->seq_num))
602                 return False;
603
604         if(!prs_uint32("unknown_4 ", ps, depth, &u_2->unknown_4)) /* 0x0000 0001 */
605                 return False;
606         if(!prs_uint32("server_role ", ps, depth, &u_2->server_role))
607                 return False;
608         if(!prs_uint32("unknown_6 ", ps, depth, &u_2->unknown_6)) /* 0x0000 0001 */
609                 return False;
610         if(!prs_uint32("num_domain_usrs ", ps, depth, &u_2->num_domain_usrs))
611                 return False;
612         if(!prs_uint32("num_domain_grps", ps, depth, &u_2->num_domain_grps))
613                 return False;
614         if(!prs_uint32("num_local_grps", ps, depth, &u_2->num_local_grps))
615                 return False;
616
617         if(!smb_io_unistr2("uni_comment", &u_2->uni_comment, u_2->hdr_comment.buffer, ps, depth))
618                 return False;
619         if(!smb_io_unistr2("uni_domain", &u_2->uni_domain, u_2->hdr_domain.buffer, ps, depth))
620                 return False;
621         if(!smb_io_unistr2("uni_server", &u_2->uni_server, u_2->hdr_server.buffer, ps, depth))
622                 return False;
623
624         return True;
625 }
626
627 /*******************************************************************
628 inits a structure.
629 ********************************************************************/
630
631 void init_unk_info3(SAM_UNK_INFO_3 *u_3, NTTIME nt_logout)
632 {
633         u_3->logout = nt_logout;
634 }
635
636 /*******************************************************************
637 reads or writes a structure.
638 ********************************************************************/
639
640 static BOOL sam_io_unk_info3(const char *desc, SAM_UNK_INFO_3 * u_3,
641                              prs_struct *ps, int depth)
642 {
643         if (u_3 == NULL)
644                 return False;
645
646         prs_debug(ps, depth, desc, "sam_io_unk_info3");
647         depth++;
648
649         if(!smb_io_time("logout", &u_3->logout, ps, depth))
650                 return False;
651
652         return True;
653 }
654
655 /*******************************************************************
656 inits a structure.
657 ********************************************************************/
658
659 void init_unk_info4(SAM_UNK_INFO_4 * u_4,const char *comment)
660 {
661         init_unistr2(&u_4->uni_comment, comment, UNI_FLAGS_NONE);
662         init_uni_hdr(&u_4->hdr_comment, &u_4->uni_comment);
663 }
664
665 /*******************************************************************
666 reads or writes a structure.
667 ********************************************************************/
668
669 static BOOL sam_io_unk_info4(const char *desc, SAM_UNK_INFO_4 * u_4,
670                              prs_struct *ps, int depth)
671 {
672         if (u_4 == NULL)
673                 return False;
674
675         prs_debug(ps, depth, desc, "sam_io_unk_info4");
676         depth++;
677
678         if(!smb_io_unihdr("hdr_comment", &u_4->hdr_comment, ps, depth))
679                 return False;
680
681         if(!smb_io_unistr2("uni_comment", &u_4->uni_comment, u_4->hdr_comment.buffer, ps, depth))
682                 return False;
683
684         return True;
685 }
686
687 /*******************************************************************
688 inits a structure.
689 ********************************************************************/
690
691 void init_unk_info5(SAM_UNK_INFO_5 * u_5,const char *domain)
692 {
693         init_unistr2(&u_5->uni_domain, domain, UNI_FLAGS_NONE);
694         init_uni_hdr(&u_5->hdr_domain, &u_5->uni_domain);
695 }
696
697 /*******************************************************************
698 reads or writes a structure.
699 ********************************************************************/
700
701 static BOOL sam_io_unk_info5(const char *desc, SAM_UNK_INFO_5 * u_5,
702                              prs_struct *ps, int depth)
703 {
704         if (u_5 == NULL)
705                 return False;
706
707         prs_debug(ps, depth, desc, "sam_io_unk_info5");
708         depth++;
709
710         if(!smb_io_unihdr("hdr_domain", &u_5->hdr_domain, ps, depth))
711                 return False;
712
713         if(!smb_io_unistr2("uni_domain", &u_5->uni_domain, u_5->hdr_domain.buffer, ps, depth))
714                 return False;
715
716         return True;
717 }
718
719 /*******************************************************************
720 inits a structure.
721 ********************************************************************/
722
723 void init_unk_info6(SAM_UNK_INFO_6 * u_6, const char *server)
724 {
725         init_unistr2(&u_6->uni_server, server, UNI_FLAGS_NONE);
726         init_uni_hdr(&u_6->hdr_server, &u_6->uni_server);
727 }
728
729 /*******************************************************************
730 reads or writes a structure.
731 ********************************************************************/
732
733 static BOOL sam_io_unk_info6(const char *desc, SAM_UNK_INFO_6 * u_6,
734                              prs_struct *ps, int depth)
735 {
736         if (u_6 == NULL)
737                 return False;
738
739         prs_debug(ps, depth, desc, "sam_io_unk_info6");
740         depth++;
741
742         if(!smb_io_unihdr("hdr_server", &u_6->hdr_server, ps, depth))
743                 return False;
744
745         if(!smb_io_unistr2("uni_server", &u_6->uni_server, u_6->hdr_server.buffer, ps, depth))
746                 return False;
747
748         return True;
749 }
750
751 /*******************************************************************
752 inits a structure.
753 ********************************************************************/
754
755 void init_unk_info7(SAM_UNK_INFO_7 * u_7, uint32 server_role)
756 {
757         u_7->server_role = server_role;
758 }
759
760 /*******************************************************************
761 reads or writes a structure.
762 ********************************************************************/
763
764 static BOOL sam_io_unk_info7(const char *desc, SAM_UNK_INFO_7 * u_7,
765                              prs_struct *ps, int depth)
766 {
767         if (u_7 == NULL)
768                 return False;
769
770         prs_debug(ps, depth, desc, "sam_io_unk_info7");
771         depth++;
772
773         if(!prs_uint16("server_role", ps, depth, &u_7->server_role))
774                 return False;
775
776         return True;
777 }
778
779 /*******************************************************************
780 inits a structure.
781 ********************************************************************/
782
783 void init_unk_info8(SAM_UNK_INFO_8 * u_8, uint32 seq_num)
784 {
785         unix_to_nt_time(&u_8->domain_create_time, 0);
786         u_8->seq_num = seq_num;
787 }
788
789 /*******************************************************************
790 reads or writes a structure.
791 ********************************************************************/
792
793 static BOOL sam_io_unk_info8(const char *desc, SAM_UNK_INFO_8 * u_8,
794                              prs_struct *ps, int depth)
795 {
796         if (u_8 == NULL)
797                 return False;
798
799         prs_debug(ps, depth, desc, "sam_io_unk_info8");
800         depth++;
801
802         if (!prs_uint64("seq_num", ps, depth, &u_8->seq_num))
803                 return False;
804
805         if(!smb_io_time("domain_create_time", &u_8->domain_create_time, ps, depth))
806                 return False;
807
808         return True;
809 }
810
811 /*******************************************************************
812 inits a structure.
813 ********************************************************************/
814
815 void init_unk_info9(SAM_UNK_INFO_9 * u_9, uint32 unknown)
816 {
817         u_9->unknown = unknown;
818 }
819
820 /*******************************************************************
821 reads or writes a structure.
822 ********************************************************************/
823
824 static BOOL sam_io_unk_info9(const char *desc, SAM_UNK_INFO_9 * u_9,
825                              prs_struct *ps, int depth)
826 {
827         if (u_9 == NULL)
828                 return False;
829
830         prs_debug(ps, depth, desc, "sam_io_unk_info9");
831         depth++;
832
833         if (!prs_uint32("unknown", ps, depth, &u_9->unknown))
834                 return False;
835
836         return True;
837 }
838
839 /*******************************************************************
840 inits a structure.
841 ********************************************************************/
842
843 void init_unk_info12(SAM_UNK_INFO_12 * u_12, NTTIME nt_lock_duration, NTTIME nt_reset_time, uint16 lockout)
844 {
845         u_12->duration = nt_lock_duration;
846         u_12->reset_count = nt_reset_time;
847
848         u_12->bad_attempt_lockout = lockout;
849 }
850
851 /*******************************************************************
852 reads or writes a structure.
853 ********************************************************************/
854
855 static BOOL sam_io_unk_info12(const char *desc, SAM_UNK_INFO_12 * u_12,
856                               prs_struct *ps, int depth)
857 {
858         if (u_12 == NULL)
859                 return False;
860
861         prs_debug(ps, depth, desc, "sam_io_unk_info12");
862         depth++;
863
864         if(!smb_io_time("duration", &u_12->duration, ps, depth))
865                 return False;
866         if(!smb_io_time("reset_count", &u_12->reset_count, ps, depth))
867                 return False;
868         if(!prs_uint16("bad_attempt_lockout", ps, depth, &u_12->bad_attempt_lockout))
869                 return False;
870
871         return True;
872 }
873
874 /*******************************************************************
875 inits a structure.
876 ********************************************************************/
877
878 void init_unk_info13(SAM_UNK_INFO_13 * u_13, uint32 seq_num)
879 {
880         unix_to_nt_time(&u_13->domain_create_time, 0);
881         u_13->seq_num = seq_num;
882         u_13->unknown1 = 0;
883         u_13->unknown2 = 0;
884 }
885
886 /*******************************************************************
887 reads or writes a structure.
888 ********************************************************************/
889
890 static BOOL sam_io_unk_info13(const char *desc, SAM_UNK_INFO_13 * u_13,
891                              prs_struct *ps, int depth)
892 {
893         if (u_13 == NULL)
894                 return False;
895
896         prs_debug(ps, depth, desc, "sam_io_unk_info13");
897         depth++;
898
899         if (!prs_uint64("seq_num", ps, depth, &u_13->seq_num))
900                 return False;
901
902         if(!smb_io_time("domain_create_time", &u_13->domain_create_time, ps, depth))
903                 return False;
904
905         if (!prs_uint32("unknown1", ps, depth, &u_13->unknown1))
906                 return False;
907         if (!prs_uint32("unknown2", ps, depth, &u_13->unknown2))
908                 return False;
909
910         return True;
911 }
912
913 /*******************************************************************
914 inits a SAMR_R_QUERY_DOMAIN_INFO structure.
915 ********************************************************************/
916
917 void init_samr_r_query_domain_info(SAMR_R_QUERY_DOMAIN_INFO * r_u,
918                                    uint16 switch_value, SAM_UNK_CTR * ctr,
919                                    NTSTATUS status)
920 {
921         DEBUG(5, ("init_samr_r_query_domain_info\n"));
922
923         r_u->ptr_0 = 0;
924         r_u->switch_value = 0;
925         r_u->status = status;   /* return status */
926
927         if (NT_STATUS_IS_OK(status)) {
928                 r_u->switch_value = switch_value;
929                 r_u->ptr_0 = 1;
930                 r_u->ctr = ctr;
931         }
932 }
933
934 /*******************************************************************
935 reads or writes a structure.
936 ********************************************************************/
937
938 BOOL samr_io_r_query_domain_info(const char *desc, SAMR_R_QUERY_DOMAIN_INFO * r_u,
939                                  prs_struct *ps, int depth)
940 {
941         if (r_u == NULL)
942                 return False;
943
944         prs_debug(ps, depth, desc, "samr_io_r_query_domain_info");
945         depth++;
946
947         if(!prs_align(ps))
948                 return False;
949
950         if(!prs_uint32("ptr_0 ", ps, depth, &r_u->ptr_0))
951                 return False;
952
953         if (r_u->ptr_0 != 0 && r_u->ctr != NULL) {
954                 if(!prs_uint16("switch_value", ps, depth, &r_u->switch_value))
955                         return False;
956                 if(!prs_align(ps))
957                         return False;
958
959                 switch (r_u->switch_value) {
960                 case 0x0d:
961                         if(!sam_io_unk_info13("unk_inf13", &r_u->ctr->info.inf13, ps, depth))
962                                 return False;
963                         break;
964                 case 0x0c:
965                         if(!sam_io_unk_info12("unk_inf12", &r_u->ctr->info.inf12, ps, depth))
966                                 return False;
967                         break;
968                 case 0x09:
969                         if(!sam_io_unk_info9("unk_inf9",&r_u->ctr->info.inf9, ps,depth))
970                                 return False;
971                         break;
972                 case 0x08:
973                         if(!sam_io_unk_info8("unk_inf8",&r_u->ctr->info.inf8, ps,depth))
974                                 return False;
975                         break;
976                 case 0x07:
977                         if(!sam_io_unk_info7("unk_inf7",&r_u->ctr->info.inf7, ps,depth))
978                                 return False;
979                         break;
980                 case 0x06:
981                         if(!sam_io_unk_info6("unk_inf6",&r_u->ctr->info.inf6, ps,depth))
982                                 return False;
983                         break;
984                 case 0x05:
985                         if(!sam_io_unk_info5("unk_inf5",&r_u->ctr->info.inf5, ps,depth))
986                                 return False;
987                         break;
988                 case 0x04:
989                         if(!sam_io_unk_info4("unk_inf4",&r_u->ctr->info.inf4, ps,depth))
990                                 return False;
991                         break;
992                 case 0x03:
993                         if(!sam_io_unk_info3("unk_inf3",&r_u->ctr->info.inf3, ps,depth))
994                                 return False;
995                         break;
996                 case 0x02:
997                         if(!sam_io_unk_info2("unk_inf2",&r_u->ctr->info.inf2, ps,depth))
998                                 return False;
999                         break;
1000                 case 0x01:
1001                         if(!sam_io_unk_info1("unk_inf1",&r_u->ctr->info.inf1, ps,depth))
1002                                 return False;
1003                         break;
1004                 default:
1005                         DEBUG(0, ("samr_io_r_query_domain_info: unknown switch level 0x%x\n",
1006                                 r_u->switch_value));
1007                         r_u->status = NT_STATUS_INVALID_INFO_CLASS;
1008                         return False;
1009                 }
1010         }
1011         
1012         if(!prs_align(ps))
1013                 return False;
1014
1015         if(!prs_ntstatus("status", ps, depth, &r_u->status))
1016                 return False;
1017         
1018         return True;
1019 }
1020
1021 /*******************************************************************
1022 reads or writes a structure.
1023 ********************************************************************/
1024
1025 void init_samr_q_set_sec_obj(SAMR_Q_SET_SEC_OBJ * q_u,
1026                              POLICY_HND *pol, uint32 sec_info, SEC_DESC_BUF *buf)
1027 {
1028         DEBUG(5, ("samr_init_samr_q_set_sec_obj\n"));
1029
1030         q_u->pol = *pol;
1031         q_u->sec_info = sec_info;
1032         q_u->buf = buf;
1033 }
1034
1035
1036 /*******************************************************************
1037 reads or writes a SAMR_R_SET_SEC_OBJ structure.
1038 ********************************************************************/
1039
1040 BOOL samr_io_r_set_sec_obj(const char *desc, SAMR_R_SET_SEC_OBJ * r_u,
1041                              prs_struct *ps, int depth)
1042 {
1043         if (r_u == NULL)
1044                 return False;
1045   
1046         prs_debug(ps, depth, desc, "samr_io_r_set_sec_obj");
1047         depth++;
1048
1049         if(!prs_align(ps))
1050                 return False;
1051
1052         if(!prs_ntstatus("status", ps, depth, &r_u->status))
1053                 return False;
1054
1055         return True;
1056 }
1057
1058 /*******************************************************************
1059 reads or writes a SAMR_R_QUERY_SEC_OBJ structure.
1060 ********************************************************************/
1061
1062 BOOL samr_io_r_query_sec_obj(const char *desc, SAMR_R_QUERY_SEC_OBJ * r_u,
1063                              prs_struct *ps, int depth)
1064 {
1065         if (r_u == NULL)
1066                 return False;
1067   
1068         prs_debug(ps, depth, desc, "samr_io_r_query_sec_obj");
1069         depth++;
1070
1071         if(!prs_align(ps))
1072                 return False;
1073
1074         if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
1075                 return False;
1076         if (r_u->ptr != 0) {
1077                 if(!sec_io_desc_buf("sec", &r_u->buf, ps, depth))
1078                         return False;
1079         }
1080
1081         if(!prs_ntstatus("status", ps, depth, &r_u->status))
1082                 return False;
1083
1084         return True;
1085 }
1086
1087 /*******************************************************************
1088 reads or writes a SAM_STR1 structure.
1089 ********************************************************************/
1090
1091 static BOOL sam_io_sam_str1(const char *desc, SAM_STR1 * sam, uint32 acct_buf,
1092                             uint32 name_buf, uint32 desc_buf,
1093                             prs_struct *ps, int depth)
1094 {
1095         if (sam == NULL)
1096                 return False;
1097
1098         prs_debug(ps, depth, desc, "sam_io_sam_str1");
1099         depth++;
1100
1101         if(!prs_align(ps))
1102                 return False;
1103         if (!smb_io_unistr2("name", &sam->uni_acct_name, acct_buf, ps, depth))
1104                 return False;
1105
1106         if (!smb_io_unistr2("desc", &sam->uni_acct_desc, desc_buf, ps, depth))
1107                 return False;
1108
1109         if (!smb_io_unistr2("full", &sam->uni_full_name, name_buf, ps, depth))
1110                 return False;
1111
1112         return True;
1113 }
1114
1115 /*******************************************************************
1116 inits a SAM_ENTRY1 structure.
1117 ********************************************************************/
1118
1119 static void init_sam_entry1(SAM_ENTRY1 *sam, uint32 user_idx,
1120                             UNISTR2 *sam_name, UNISTR2 *sam_full,
1121                             UNISTR2 *sam_desc, uint32 rid_user,
1122                             uint32 acb_info)
1123 {
1124         DEBUG(5, ("init_sam_entry1\n"));
1125
1126         ZERO_STRUCTP(sam);
1127
1128         sam->user_idx = user_idx;
1129         sam->rid_user = rid_user;
1130         sam->acb_info = acb_info;
1131
1132         init_uni_hdr(&sam->hdr_acct_name, sam_name);
1133         init_uni_hdr(&sam->hdr_user_name, sam_full);
1134         init_uni_hdr(&sam->hdr_user_desc, sam_desc);
1135 }
1136
1137 /*******************************************************************
1138 reads or writes a SAM_ENTRY1 structure.
1139 ********************************************************************/
1140
1141 static BOOL sam_io_sam_entry1(const char *desc, SAM_ENTRY1 * sam,
1142                               prs_struct *ps, int depth)
1143 {
1144         if (sam == NULL)
1145                 return False;
1146
1147         prs_debug(ps, depth, desc, "sam_io_sam_entry1");
1148         depth++;
1149
1150         if(!prs_align(ps))
1151                 return False;
1152
1153         if(!prs_uint32("user_idx ", ps, depth, &sam->user_idx))
1154                 return False;
1155
1156         if(!prs_uint32("rid_user ", ps, depth, &sam->rid_user))
1157                 return False;
1158         if(!prs_uint32("acb_info ", ps, depth, &sam->acb_info))
1159                 return False;
1160
1161         if (!smb_io_unihdr("hdr_acct_name", &sam->hdr_acct_name, ps, depth))
1162                 return False;
1163         if (!smb_io_unihdr("hdr_user_desc", &sam->hdr_user_desc, ps, depth))
1164                 return False;
1165         if (!smb_io_unihdr("hdr_user_name", &sam->hdr_user_name, ps, depth))
1166                 return False;
1167
1168         return True;
1169 }
1170
1171 /*******************************************************************
1172 reads or writes a SAM_STR2 structure.
1173 ********************************************************************/
1174
1175 static BOOL sam_io_sam_str2(const char *desc, SAM_STR2 * sam, uint32 acct_buf,
1176                             uint32 desc_buf, prs_struct *ps, int depth)
1177 {
1178         if (sam == NULL)
1179                 return False;
1180
1181         prs_debug(ps, depth, desc, "sam_io_sam_str2");
1182         depth++;
1183
1184         if(!prs_align(ps))
1185                 return False;
1186
1187         if(!smb_io_unistr2("uni_srv_name", &sam->uni_srv_name, acct_buf, ps, depth)) /* account name unicode string */
1188                 return False;
1189         if(!smb_io_unistr2("uni_srv_desc", &sam->uni_srv_desc, desc_buf, ps, depth))    /* account desc unicode string */
1190                 return False;
1191
1192         return True;
1193 }
1194
1195 /*******************************************************************
1196 inits a SAM_ENTRY2 structure.
1197 ********************************************************************/
1198 static void init_sam_entry2(SAM_ENTRY2 * sam, uint32 user_idx,
1199                             UNISTR2 *sam_name, UNISTR2 *sam_desc,
1200                             uint32 rid_user, uint32 acb_info)
1201 {
1202         DEBUG(5, ("init_sam_entry2\n"));
1203
1204         sam->user_idx = user_idx;
1205         sam->rid_user = rid_user;
1206         sam->acb_info = acb_info;
1207
1208         init_uni_hdr(&sam->hdr_srv_name, sam_name);
1209         init_uni_hdr(&sam->hdr_srv_desc, sam_desc);
1210 }
1211
1212 /*******************************************************************
1213 reads or writes a SAM_ENTRY2 structure.
1214 ********************************************************************/
1215
1216 static BOOL sam_io_sam_entry2(const char *desc, SAM_ENTRY2 * sam,
1217                               prs_struct *ps, int depth)
1218 {
1219         if (sam == NULL)
1220                 return False;
1221
1222         prs_debug(ps, depth, desc, "sam_io_sam_entry2");
1223         depth++;
1224
1225         if(!prs_align(ps))
1226                 return False;
1227
1228         if(!prs_uint32("user_idx ", ps, depth, &sam->user_idx))
1229                 return False;
1230
1231         if(!prs_uint32("rid_user ", ps, depth, &sam->rid_user))
1232                 return False;
1233         if(!prs_uint32("acb_info ", ps, depth, &sam->acb_info))
1234                 return False;
1235
1236         if(!smb_io_unihdr("unihdr", &sam->hdr_srv_name, ps, depth))     /* account name unicode string header */
1237                 return False;
1238         if(!smb_io_unihdr("unihdr", &sam->hdr_srv_desc, ps, depth))     /* account name unicode string header */
1239                 return False;
1240
1241         return True;
1242 }
1243
1244 /*******************************************************************
1245 reads or writes a SAM_STR3 structure.
1246 ********************************************************************/
1247
1248 static BOOL sam_io_sam_str3(const char *desc, SAM_STR3 * sam, uint32 acct_buf,
1249                             uint32 desc_buf, prs_struct *ps, int depth)
1250 {
1251         if (sam == NULL)
1252                 return False;
1253
1254         prs_debug(ps, depth, desc, "sam_io_sam_str3");
1255         depth++;
1256
1257         if(!prs_align(ps))
1258                 return False;
1259
1260         if(!smb_io_unistr2("uni_grp_name", &sam->uni_grp_name, acct_buf, ps, depth))    /* account name unicode string */
1261                 return False;
1262         if(!smb_io_unistr2("uni_grp_desc", &sam->uni_grp_desc, desc_buf, ps, depth))    /* account desc unicode string */
1263                 return False;
1264
1265         return True;
1266 }
1267
1268 /*******************************************************************
1269 inits a SAM_ENTRY3 structure.
1270 ********************************************************************/
1271
1272 static void init_sam_entry3(SAM_ENTRY3 * sam, uint32 grp_idx,
1273                             UNISTR2 *grp_name, UNISTR2 *grp_desc,
1274                             uint32 rid_grp)
1275 {
1276         DEBUG(5, ("init_sam_entry3\n"));
1277
1278         sam->grp_idx = grp_idx;
1279         sam->rid_grp = rid_grp;
1280         sam->attr = 0x07;       /* group rid attributes - gets ignored by nt 4.0 */
1281
1282         init_uni_hdr(&sam->hdr_grp_name, grp_name);
1283         init_uni_hdr(&sam->hdr_grp_desc, grp_desc);
1284 }
1285
1286 /*******************************************************************
1287 reads or writes a SAM_ENTRY3 structure.
1288 ********************************************************************/
1289
1290 static BOOL sam_io_sam_entry3(const char *desc, SAM_ENTRY3 * sam,
1291                               prs_struct *ps, int depth)
1292 {
1293         if (sam == NULL)
1294                 return False;
1295
1296         prs_debug(ps, depth, desc, "sam_io_sam_entry3");
1297         depth++;
1298
1299         if(!prs_align(ps))
1300                 return False;
1301
1302         if(!prs_uint32("grp_idx", ps, depth, &sam->grp_idx))
1303                 return False;
1304
1305         if(!prs_uint32("rid_grp", ps, depth, &sam->rid_grp))
1306                 return False;
1307         if(!prs_uint32("attr   ", ps, depth, &sam->attr))
1308                 return False;
1309
1310         if(!smb_io_unihdr("unihdr", &sam->hdr_grp_name, ps, depth))     /* account name unicode string header */
1311                 return False;
1312         if(!smb_io_unihdr("unihdr", &sam->hdr_grp_desc, ps, depth))     /* account name unicode string header */
1313                 return False;
1314
1315         return True;
1316 }
1317
1318 /*******************************************************************
1319 inits a SAM_ENTRY4 structure.
1320 ********************************************************************/
1321
1322 static void init_sam_entry4(SAM_ENTRY4 * sam, uint32 user_idx,
1323                             uint32 len_acct_name)
1324 {
1325         DEBUG(5, ("init_sam_entry4\n"));
1326
1327         sam->user_idx = user_idx;
1328         init_str_hdr(&sam->hdr_acct_name, len_acct_name+1, len_acct_name, len_acct_name != 0);
1329 }
1330
1331 /*******************************************************************
1332 reads or writes a SAM_ENTRY4 structure.
1333 ********************************************************************/
1334
1335 static BOOL sam_io_sam_entry4(const char *desc, SAM_ENTRY4 * sam,
1336                               prs_struct *ps, int depth)
1337 {
1338         if (sam == NULL)
1339                 return False;
1340
1341         prs_debug(ps, depth, desc, "sam_io_sam_entry4");
1342         depth++;
1343
1344         if(!prs_align(ps))
1345                 return False;
1346
1347         if(!prs_uint32("user_idx", ps, depth, &sam->user_idx))
1348                 return False;
1349         if(!smb_io_strhdr("strhdr", &sam->hdr_acct_name, ps, depth))
1350                 return False;
1351
1352         return True;
1353 }
1354
1355 /*******************************************************************
1356 inits a SAM_ENTRY5 structure.
1357 ********************************************************************/
1358
1359 static void init_sam_entry5(SAM_ENTRY5 * sam, uint32 grp_idx,
1360                             uint32 len_grp_name)
1361 {
1362         DEBUG(5, ("init_sam_entry5\n"));
1363
1364         sam->grp_idx = grp_idx;
1365         init_str_hdr(&sam->hdr_grp_name, len_grp_name, len_grp_name,
1366                      len_grp_name != 0);
1367 }
1368
1369 /*******************************************************************
1370 reads or writes a SAM_ENTRY5 structure.
1371 ********************************************************************/
1372
1373 static BOOL sam_io_sam_entry5(const char *desc, SAM_ENTRY5 * sam,
1374                               prs_struct *ps, int depth)
1375 {
1376         if (sam == NULL)
1377                 return False;
1378
1379         prs_debug(ps, depth, desc, "sam_io_sam_entry5");
1380         depth++;
1381
1382         if(!prs_align(ps))
1383                 return False;
1384
1385         if(!prs_uint32("grp_idx", ps, depth, &sam->grp_idx))
1386                 return False;
1387         if(!smb_io_strhdr("strhdr", &sam->hdr_grp_name, ps, depth))
1388                 return False;
1389
1390         return True;
1391 }
1392
1393 /*******************************************************************
1394 inits a SAM_ENTRY structure.
1395 ********************************************************************/
1396
1397 void init_sam_entry(SAM_ENTRY *sam, UNISTR2 *uni2, uint32 rid)
1398 {
1399         DEBUG(10, ("init_sam_entry: %d\n", rid));
1400
1401         sam->rid = rid;
1402         init_uni_hdr(&sam->hdr_name, uni2);
1403 }
1404
1405 /*******************************************************************
1406 reads or writes a SAM_ENTRY structure.
1407 ********************************************************************/
1408
1409 static BOOL sam_io_sam_entry(const char *desc, SAM_ENTRY * sam,
1410                              prs_struct *ps, int depth)
1411 {
1412         if (sam == NULL)
1413                 return False;
1414
1415         prs_debug(ps, depth, desc, "sam_io_sam_entry");
1416         depth++;
1417
1418         if(!prs_align(ps))
1419                 return False;
1420         if(!prs_uint32("rid", ps, depth, &sam->rid))
1421                 return False;
1422         if(!smb_io_unihdr("unihdr", &sam->hdr_name, ps, depth)) /* account name unicode string header */
1423                 return False;
1424
1425         return True;
1426 }
1427
1428 /*******************************************************************
1429 inits a SAMR_Q_ENUM_DOM_USERS structure.
1430 ********************************************************************/
1431
1432 void init_samr_q_enum_dom_users(SAMR_Q_ENUM_DOM_USERS * q_e, POLICY_HND *pol,
1433                                 uint32 start_idx,
1434                                 uint32 acb_mask, uint32 size)
1435 {
1436         DEBUG(5, ("init_samr_q_enum_dom_users\n"));
1437
1438         q_e->pol = *pol;
1439
1440         q_e->start_idx = start_idx;     /* zero indicates lots */
1441         q_e->acb_mask = acb_mask;
1442         q_e->max_size = size;
1443 }
1444
1445 /*******************************************************************
1446 reads or writes a structure.
1447 ********************************************************************/
1448
1449 BOOL samr_io_q_enum_dom_users(const char *desc, SAMR_Q_ENUM_DOM_USERS * q_e,
1450                               prs_struct *ps, int depth)
1451 {
1452         if (q_e == NULL)
1453                 return False;
1454
1455         prs_debug(ps, depth, desc, "samr_io_q_enum_dom_users");
1456         depth++;
1457
1458         if(!prs_align(ps))
1459                 return False;
1460
1461         if(!smb_io_pol_hnd("domain_pol", &q_e->pol, ps, depth))
1462                 return False;
1463
1464         if(!prs_uint32("start_idx", ps, depth, &q_e->start_idx))
1465                 return False;
1466         if(!prs_uint32("acb_mask ", ps, depth, &q_e->acb_mask))
1467                 return False;
1468
1469         if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
1470                 return False;
1471
1472         return True;
1473 }
1474
1475
1476 /*******************************************************************
1477 inits a SAMR_R_ENUM_DOM_USERS structure.
1478 ********************************************************************/
1479
1480 void init_samr_r_enum_dom_users(SAMR_R_ENUM_DOM_USERS * r_u,
1481                                 uint32 next_idx, uint32 num_sam_entries)
1482 {
1483         DEBUG(5, ("init_samr_r_enum_dom_users\n"));
1484
1485         r_u->next_idx = next_idx;
1486
1487         if (num_sam_entries != 0) {
1488                 r_u->ptr_entries1 = 1;
1489                 r_u->ptr_entries2 = 1;
1490                 r_u->num_entries2 = num_sam_entries;
1491                 r_u->num_entries3 = num_sam_entries;
1492
1493                 r_u->num_entries4 = num_sam_entries;
1494         } else {
1495                 r_u->ptr_entries1 = 0;
1496                 r_u->num_entries2 = num_sam_entries;
1497                 r_u->ptr_entries2 = 1;
1498         }
1499 }
1500
1501 /*******************************************************************
1502 reads or writes a structure.
1503 ********************************************************************/
1504
1505 BOOL samr_io_r_enum_dom_users(const char *desc, SAMR_R_ENUM_DOM_USERS * r_u,
1506                               prs_struct *ps, int depth)
1507 {
1508         uint32 i;
1509
1510         if (r_u == NULL)
1511                 return False;
1512
1513         prs_debug(ps, depth, desc, "samr_io_r_enum_dom_users");
1514         depth++;
1515
1516         if(!prs_align(ps))
1517                 return False;
1518
1519         if(!prs_uint32("next_idx    ", ps, depth, &r_u->next_idx))
1520                 return False;
1521         if(!prs_uint32("ptr_entries1", ps, depth, &r_u->ptr_entries1))
1522                 return False;
1523
1524         if (r_u->ptr_entries1 != 0) {
1525                 if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
1526                         return False;
1527                 if(!prs_uint32("ptr_entries2", ps, depth, &r_u->ptr_entries2))
1528                         return False;
1529                 if(!prs_uint32("num_entries3", ps, depth, &r_u->num_entries3))
1530                         return False;
1531
1532                 if (UNMARSHALLING(ps) && (r_u->num_entries2 != 0)) {
1533                         r_u->sam = PRS_ALLOC_MEM(ps,SAM_ENTRY, r_u->num_entries2);
1534                         r_u->uni_acct_name = PRS_ALLOC_MEM(ps,UNISTR2, r_u->num_entries2);
1535                 }
1536
1537                 if ((r_u->sam == NULL || r_u->uni_acct_name == NULL) && r_u->num_entries2 != 0) {
1538                         DEBUG(0,("NULL pointers in SAMR_R_ENUM_DOM_USERS\n"));
1539                         r_u->num_entries4 = 0;
1540                         r_u->status = NT_STATUS_MEMORY_NOT_ALLOCATED;
1541                         return False;
1542                 }
1543
1544                 for (i = 0; i < r_u->num_entries2; i++) {
1545                         if(!sam_io_sam_entry("", &r_u->sam[i], ps, depth))
1546                                 return False;
1547                 }
1548
1549                 for (i = 0; i < r_u->num_entries2; i++) {
1550                         if(!smb_io_unistr2("", &r_u->uni_acct_name[i],r_u->sam[i].hdr_name.buffer, ps,depth))
1551                                 return False;
1552                 }
1553
1554         }
1555
1556         if(!prs_align(ps))
1557                 return False;
1558                 
1559         if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4))
1560                 return False;
1561         if(!prs_ntstatus("status", ps, depth, &r_u->status))
1562                 return False;
1563
1564         return True;
1565 }
1566
1567 /*******************************************************************
1568 inits a SAMR_Q_QUERY_DISPINFO structure.
1569 ********************************************************************/
1570
1571 void init_samr_q_query_dispinfo(SAMR_Q_QUERY_DISPINFO * q_e, POLICY_HND *pol,
1572                                 uint16 switch_level, uint32 start_idx,
1573                                 uint32 max_entries, uint32 max_size)
1574 {
1575         DEBUG(5, ("init_samr_q_query_dispinfo\n"));
1576
1577         q_e->domain_pol = *pol;
1578
1579         q_e->switch_level = switch_level;
1580
1581         q_e->start_idx = start_idx;
1582         q_e->max_entries = max_entries;
1583         q_e->max_size = max_size;
1584 }
1585
1586 /*******************************************************************
1587 reads or writes a structure.
1588 ********************************************************************/
1589
1590 BOOL samr_io_q_query_dispinfo(const char *desc, SAMR_Q_QUERY_DISPINFO * q_e,
1591                               prs_struct *ps, int depth)
1592 {
1593         if (q_e == NULL)
1594                 return False;
1595
1596         prs_debug(ps, depth, desc, "samr_io_q_query_dispinfo");
1597         depth++;
1598
1599         if(!prs_align(ps))
1600                 return False;
1601
1602         if(!smb_io_pol_hnd("domain_pol", &q_e->domain_pol, ps, depth))
1603                 return False;
1604
1605         if(!prs_uint16("switch_level", ps, depth, &q_e->switch_level))
1606                 return False;
1607         if(!prs_align(ps))
1608                 return False;
1609
1610         if(!prs_uint32("start_idx   ", ps, depth, &q_e->start_idx))
1611                 return False;
1612         if(!prs_uint32("max_entries ", ps, depth, &q_e->max_entries))
1613                 return False;
1614         if(!prs_uint32("max_size    ", ps, depth, &q_e->max_size))
1615                 return False;
1616
1617         return True;
1618 }
1619
1620 /*******************************************************************
1621 inits a SAM_DISPINFO_1 structure.
1622 ********************************************************************/
1623
1624 NTSTATUS init_sam_dispinfo_1(TALLOC_CTX *ctx, SAM_DISPINFO_1 **sam,
1625                              uint32 num_entries, uint32 start_idx,
1626                              struct samr_displayentry *entries)
1627 {
1628         uint32 i;
1629
1630         DEBUG(10, ("init_sam_dispinfo_1: num_entries: %d\n", num_entries));
1631
1632         if (num_entries==0)
1633                 return NT_STATUS_OK;
1634
1635         *sam = TALLOC_ZERO_ARRAY(ctx, SAM_DISPINFO_1, num_entries);
1636         if (*sam == NULL)
1637                 return NT_STATUS_NO_MEMORY;
1638
1639         (*sam)->sam=TALLOC_ARRAY(ctx, SAM_ENTRY1, num_entries);
1640         if ((*sam)->sam == NULL)
1641                 return NT_STATUS_NO_MEMORY;
1642
1643         (*sam)->str=TALLOC_ARRAY(ctx, SAM_STR1, num_entries);
1644         if ((*sam)->str == NULL)
1645                 return NT_STATUS_NO_MEMORY;
1646
1647         for (i = 0; i < num_entries ; i++) {
1648                 init_unistr2(&(*sam)->str[i].uni_acct_name,
1649                              entries[i].account_name, UNI_FLAGS_NONE);
1650                 init_unistr2(&(*sam)->str[i].uni_full_name,
1651                              entries[i].fullname, UNI_FLAGS_NONE);
1652                 init_unistr2(&(*sam)->str[i].uni_acct_desc,
1653                              entries[i].description, UNI_FLAGS_NONE);
1654
1655                 init_sam_entry1(&(*sam)->sam[i], start_idx+i+1,
1656                                 &(*sam)->str[i].uni_acct_name,
1657                                 &(*sam)->str[i].uni_full_name,
1658                                 &(*sam)->str[i].uni_acct_desc,
1659                                 entries[i].rid, entries[i].acct_flags);
1660         }
1661
1662         return NT_STATUS_OK;
1663 }
1664
1665 /*******************************************************************
1666 reads or writes a structure.
1667 ********************************************************************/
1668
1669 static BOOL sam_io_sam_dispinfo_1(const char *desc, SAM_DISPINFO_1 * sam,
1670                                   uint32 num_entries,
1671                                   prs_struct *ps, int depth)
1672 {
1673         uint32 i;
1674
1675         prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_1");
1676         depth++;
1677
1678         if(!prs_align(ps))
1679                 return False;
1680
1681         if (UNMARSHALLING(ps) && num_entries > 0) {
1682
1683                 if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY1, num_entries)) == NULL) {
1684                         DEBUG(0, ("out of memory allocating SAM_ENTRY1\n"));
1685                         return False;
1686                 }
1687
1688                 if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR1, num_entries)) == NULL) {
1689                         DEBUG(0, ("out of memory allocating SAM_STR1\n"));
1690                         return False;
1691                 }
1692         }
1693
1694         for (i = 0; i < num_entries; i++) {
1695                 if(!sam_io_sam_entry1("", &sam->sam[i], ps, depth))
1696                         return False;
1697         }
1698
1699         for (i = 0; i < num_entries; i++) {
1700                 if(!sam_io_sam_str1("", &sam->str[i],
1701                               sam->sam[i].hdr_acct_name.buffer,
1702                               sam->sam[i].hdr_user_name.buffer,
1703                               sam->sam[i].hdr_user_desc.buffer, ps, depth))
1704                         return False;
1705         }
1706
1707         return True;
1708 }
1709
1710 /*******************************************************************
1711 inits a SAM_DISPINFO_2 structure.
1712 ********************************************************************/
1713
1714 NTSTATUS init_sam_dispinfo_2(TALLOC_CTX *ctx, SAM_DISPINFO_2 **sam,
1715                              uint32 num_entries, uint32 start_idx,
1716                              struct samr_displayentry *entries)
1717 {
1718         uint32 i;
1719
1720         DEBUG(10, ("init_sam_dispinfo_2: num_entries: %d\n", num_entries));
1721
1722         if (num_entries==0)
1723                 return NT_STATUS_OK;
1724
1725         *sam = TALLOC_ZERO_ARRAY(ctx, SAM_DISPINFO_2, num_entries);
1726         if (*sam == NULL)
1727                 return NT_STATUS_NO_MEMORY;
1728
1729         (*sam)->sam = TALLOC_ARRAY(ctx, SAM_ENTRY2, num_entries);
1730         if ((*sam)->sam == NULL)
1731                 return NT_STATUS_NO_MEMORY;
1732
1733         (*sam)->str=TALLOC_ARRAY(ctx, SAM_STR2, num_entries);
1734         if ((*sam)->str == NULL)
1735                 return NT_STATUS_NO_MEMORY;
1736
1737         for (i = 0; i < num_entries; i++) {
1738                 init_unistr2(&(*sam)->str[i].uni_srv_name,
1739                              entries[i].account_name, UNI_FLAGS_NONE);
1740                 init_unistr2(&(*sam)->str[i].uni_srv_desc,
1741                              entries[i].description, UNI_FLAGS_NONE);
1742
1743                 init_sam_entry2(&(*sam)->sam[i], start_idx + i + 1,
1744                                 &(*sam)->str[i].uni_srv_name,
1745                                 &(*sam)->str[i].uni_srv_desc,
1746                                 entries[i].rid, entries[i].acct_flags);
1747         }
1748
1749         return NT_STATUS_OK;
1750 }
1751
1752 /*******************************************************************
1753 reads or writes a structure.
1754 ********************************************************************/
1755
1756 static BOOL sam_io_sam_dispinfo_2(const char *desc, SAM_DISPINFO_2 * sam,
1757                                   uint32 num_entries,
1758                                   prs_struct *ps, int depth)
1759 {
1760         uint32 i;
1761
1762         if (sam == NULL)
1763                 return False;
1764
1765         prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_2");
1766         depth++;
1767
1768         if(!prs_align(ps))
1769                 return False;
1770
1771         if (UNMARSHALLING(ps) && num_entries > 0) {
1772
1773                 if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY2, num_entries)) == NULL) {
1774                         DEBUG(0, ("out of memory allocating SAM_ENTRY2\n"));
1775                         return False;
1776                 }
1777
1778                 if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR2, num_entries)) == NULL) {
1779                         DEBUG(0, ("out of memory allocating SAM_STR2\n"));
1780                         return False;
1781                 }
1782         }
1783
1784         for (i = 0; i < num_entries; i++) {
1785                 if(!sam_io_sam_entry2("", &sam->sam[i], ps, depth))
1786                         return False;
1787         }
1788
1789         for (i = 0; i < num_entries; i++) {
1790                 if(!sam_io_sam_str2("", &sam->str[i],
1791                               sam->sam[i].hdr_srv_name.buffer,
1792                               sam->sam[i].hdr_srv_desc.buffer, ps, depth))
1793                         return False;
1794         }
1795
1796         return True;
1797 }
1798
1799 /*******************************************************************
1800 inits a SAM_DISPINFO_3 structure.
1801 ********************************************************************/
1802
1803 NTSTATUS init_sam_dispinfo_3(TALLOC_CTX *ctx, SAM_DISPINFO_3 **sam,
1804                              uint32 num_entries, uint32 start_idx,
1805                              struct samr_displayentry *entries)
1806 {
1807         uint32 i;
1808
1809         DEBUG(5, ("init_sam_dispinfo_3: num_entries: %d\n", num_entries));
1810
1811         if (num_entries==0)
1812                 return NT_STATUS_OK;
1813
1814         *sam = TALLOC_ZERO_ARRAY(ctx, SAM_DISPINFO_3, num_entries);
1815         if (*sam == NULL)
1816                 return NT_STATUS_NO_MEMORY;
1817
1818         if (!((*sam)->sam=TALLOC_ARRAY(ctx, SAM_ENTRY3, num_entries)))
1819                 return NT_STATUS_NO_MEMORY;
1820
1821         if (!((*sam)->str=TALLOC_ARRAY(ctx, SAM_STR3, num_entries)))
1822                 return NT_STATUS_NO_MEMORY;
1823
1824         for (i = 0; i < num_entries; i++) {
1825                 DEBUG(11, ("init_sam_dispinfo_3: entry: %d\n",i));
1826
1827                 init_unistr2(&(*sam)->str[i].uni_grp_name,
1828                              entries[i].account_name, UNI_FLAGS_NONE);
1829                 init_unistr2(&(*sam)->str[i].uni_grp_desc,
1830                              entries[i].description, UNI_FLAGS_NONE);
1831
1832                 init_sam_entry3(&(*sam)->sam[i], start_idx+i+1,
1833                                 &(*sam)->str[i].uni_grp_name,
1834                                 &(*sam)->str[i].uni_grp_desc,
1835                                 entries[i].rid);
1836         }
1837
1838         return NT_STATUS_OK;
1839 }
1840
1841 /*******************************************************************
1842 reads or writes a structure.
1843 ********************************************************************/
1844
1845 static BOOL sam_io_sam_dispinfo_3(const char *desc, SAM_DISPINFO_3 * sam,
1846                                   uint32 num_entries,
1847                                   prs_struct *ps, int depth)
1848 {
1849         uint32 i;
1850
1851         if (sam == NULL)
1852                 return False;
1853
1854         prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_3");
1855         depth++;
1856
1857         if(!prs_align(ps))
1858                 return False;
1859
1860         if (UNMARSHALLING(ps) && num_entries > 0) {
1861
1862                 if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY3, num_entries)) == NULL) {
1863                         DEBUG(0, ("out of memory allocating SAM_ENTRY3\n"));
1864                         return False;
1865                 }
1866
1867                 if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR3, num_entries)) == NULL) {
1868                         DEBUG(0, ("out of memory allocating SAM_STR3\n"));
1869                         return False;
1870                 }
1871         }
1872
1873         for (i = 0; i < num_entries; i++) {
1874                 if(!sam_io_sam_entry3("", &sam->sam[i], ps, depth))
1875                         return False;
1876         }
1877
1878         for (i = 0; i < num_entries; i++) {
1879                 if(!sam_io_sam_str3("", &sam->str[i],
1880                               sam->sam[i].hdr_grp_name.buffer,
1881                               sam->sam[i].hdr_grp_desc.buffer, ps, depth))
1882                         return False;
1883         }
1884
1885         return True;
1886 }
1887
1888 /*******************************************************************
1889 inits a SAM_DISPINFO_4 structure.
1890 ********************************************************************/
1891
1892 NTSTATUS init_sam_dispinfo_4(TALLOC_CTX *ctx, SAM_DISPINFO_4 **sam,
1893                              uint32 num_entries, uint32 start_idx,
1894                              struct samr_displayentry *entries)
1895 {
1896         uint32 i;
1897
1898         DEBUG(5, ("init_sam_dispinfo_4: num_entries: %d\n", num_entries));
1899
1900         if (num_entries==0)
1901                 return NT_STATUS_OK;
1902
1903         *sam = TALLOC_ZERO_ARRAY(ctx, SAM_DISPINFO_4, num_entries);
1904         if (*sam == NULL)
1905                 return NT_STATUS_NO_MEMORY;
1906
1907         (*sam)->sam = TALLOC_ARRAY(ctx, SAM_ENTRY4, num_entries);
1908         if ((*sam)->sam == NULL)
1909                 return NT_STATUS_NO_MEMORY;
1910
1911         (*sam)->str=TALLOC_ARRAY(ctx, SAM_STR4, num_entries);
1912         if ((*sam)->str == NULL)
1913                 return NT_STATUS_NO_MEMORY;
1914
1915         for (i = 0; i < num_entries; i++) {
1916                 size_t len_sam_name = strlen(entries[i].account_name);
1917
1918                 DEBUG(11, ("init_sam_dispinfo_2: entry: %d\n",i));
1919           
1920                 init_sam_entry4(&(*sam)->sam[i], start_idx + i + 1,
1921                                 len_sam_name);
1922
1923                 init_string2(&(*sam)->str[i].acct_name,
1924                              entries[i].account_name, len_sam_name+1,
1925                              len_sam_name);
1926         }
1927         
1928         return NT_STATUS_OK;
1929 }
1930
1931 /*******************************************************************
1932 reads or writes a structure.
1933 ********************************************************************/
1934
1935 static BOOL sam_io_sam_dispinfo_4(const char *desc, SAM_DISPINFO_4 * sam,
1936                                   uint32 num_entries,
1937                                   prs_struct *ps, int depth)
1938 {
1939         uint32 i;
1940
1941         if (sam == NULL)
1942                 return False;
1943
1944         prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_4");
1945         depth++;
1946
1947         if(!prs_align(ps))
1948                 return False;
1949
1950         if (UNMARSHALLING(ps) && num_entries > 0) {
1951
1952                 if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY4, num_entries)) == NULL) {
1953                         DEBUG(0, ("out of memory allocating SAM_ENTRY4\n"));
1954                         return False;
1955                 }
1956
1957                 if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR4, num_entries)) == NULL) {
1958                         DEBUG(0, ("out of memory allocating SAM_STR4\n"));
1959                         return False;
1960                 }
1961         }
1962
1963         for (i = 0; i < num_entries; i++) {
1964                 if(!sam_io_sam_entry4("", &sam->sam[i], ps, depth))
1965                         return False;
1966         }
1967
1968         for (i = 0; i < num_entries; i++) {
1969                 if(!smb_io_string2("acct_name", &sam->str[i].acct_name,
1970                              sam->sam[i].hdr_acct_name.buffer, ps, depth))
1971                         return False;
1972         }
1973
1974         return True;
1975 }
1976
1977 /*******************************************************************
1978 inits a SAM_DISPINFO_5 structure.
1979 ********************************************************************/
1980
1981 NTSTATUS init_sam_dispinfo_5(TALLOC_CTX *ctx, SAM_DISPINFO_5 **sam,
1982                              uint32 num_entries, uint32 start_idx,
1983                              struct samr_displayentry *entries)
1984 {
1985         uint32 len_sam_name;
1986         uint32 i;
1987
1988         DEBUG(5, ("init_sam_dispinfo_5: num_entries: %d\n", num_entries));
1989
1990         if (num_entries==0)
1991                 return NT_STATUS_OK;
1992
1993         *sam = TALLOC_ZERO_ARRAY(ctx, SAM_DISPINFO_5, num_entries);
1994         if (*sam == NULL)
1995                 return NT_STATUS_NO_MEMORY;
1996
1997         if (!((*sam)->sam=TALLOC_ARRAY(ctx, SAM_ENTRY5, num_entries)))
1998                 return NT_STATUS_NO_MEMORY;
1999
2000         if (!((*sam)->str=TALLOC_ARRAY(ctx, SAM_STR5, num_entries)))
2001                 return NT_STATUS_NO_MEMORY;
2002
2003         for (i = 0; i < num_entries; i++) {
2004                 DEBUG(11, ("init_sam_dispinfo_5: entry: %d\n",i));
2005
2006                 len_sam_name = strlen(entries[i].account_name);
2007           
2008                 init_sam_entry5(&(*sam)->sam[i], start_idx+i+1, len_sam_name);
2009                 init_string2(&(*sam)->str[i].grp_name, entries[i].account_name,
2010                              len_sam_name+1, len_sam_name);
2011         }
2012
2013         return NT_STATUS_OK;
2014 }
2015
2016 /*******************************************************************
2017 reads or writes a structure.
2018 ********************************************************************/
2019
2020 static BOOL sam_io_sam_dispinfo_5(const char *desc, SAM_DISPINFO_5 * sam,
2021                                   uint32 num_entries,
2022                                   prs_struct *ps, int depth)
2023 {
2024         uint32 i;
2025
2026         if (sam == NULL)
2027                 return False;
2028
2029         prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_5");
2030         depth++;
2031
2032         if(!prs_align(ps))
2033                 return False;
2034
2035         if (UNMARSHALLING(ps) && num_entries > 0) {
2036
2037                 if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY5, num_entries)) == NULL) {
2038                         DEBUG(0, ("out of memory allocating SAM_ENTRY5\n"));
2039                         return False;
2040                 }
2041
2042                 if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR5, num_entries)) == NULL) {
2043                         DEBUG(0, ("out of memory allocating SAM_STR5\n"));
2044                         return False;
2045                 }
2046         }
2047
2048         for (i = 0; i < num_entries; i++) {
2049                 if(!sam_io_sam_entry5("", &sam->sam[i], ps, depth))
2050                         return False;
2051         }
2052
2053         for (i = 0; i < num_entries; i++) {
2054                 if(!smb_io_string2("grp_name", &sam->str[i].grp_name,
2055                              sam->sam[i].hdr_grp_name.buffer, ps, depth))
2056                         return False;
2057         }
2058
2059         return True;
2060 }
2061
2062 /*******************************************************************
2063 inits a SAMR_R_QUERY_DISPINFO structure.
2064 ********************************************************************/
2065
2066 void init_samr_r_query_dispinfo(SAMR_R_QUERY_DISPINFO * r_u,
2067                                 uint32 num_entries, uint32 total_size, uint32 data_size,
2068                                 uint16 switch_level, SAM_DISPINFO_CTR * ctr,
2069                                 NTSTATUS status)
2070 {
2071         DEBUG(5, ("init_samr_r_query_dispinfo: level %d\n", switch_level));
2072
2073         r_u->total_size = total_size;
2074
2075         r_u->data_size = data_size;
2076
2077         r_u->switch_level = switch_level;
2078         r_u->num_entries = num_entries;
2079
2080         if (num_entries==0)
2081                 r_u->ptr_entries = 0;
2082         else
2083                 r_u->ptr_entries = 1;
2084
2085         r_u->num_entries2 = num_entries;
2086         r_u->ctr = ctr;
2087
2088         r_u->status = status;
2089 }
2090
2091 /*******************************************************************
2092 reads or writes a structure.
2093 ********************************************************************/
2094
2095 BOOL samr_io_r_query_dispinfo(const char *desc, SAMR_R_QUERY_DISPINFO * r_u,
2096                               prs_struct *ps, int depth)
2097 {
2098         if (r_u == NULL)
2099                 return False;
2100
2101         prs_debug(ps, depth, desc, "samr_io_r_query_dispinfo");
2102         depth++;
2103
2104         if(!prs_align(ps))
2105                 return False;
2106
2107         if(!prs_uint32("total_size  ", ps, depth, &r_u->total_size))
2108                 return False;
2109         if(!prs_uint32("data_size   ", ps, depth, &r_u->data_size))
2110                 return False;
2111         if(!prs_uint16("switch_level", ps, depth, &r_u->switch_level))
2112                 return False;
2113         if(!prs_align(ps))
2114                 return False;
2115
2116         if(!prs_uint32("num_entries ", ps, depth, &r_u->num_entries))
2117                 return False;
2118         if(!prs_uint32("ptr_entries ", ps, depth, &r_u->ptr_entries))
2119                 return False;
2120
2121         if (r_u->ptr_entries==0) {
2122                 if(!prs_align(ps))
2123                         return False;
2124                 if(!prs_ntstatus("status", ps, depth, &r_u->status))
2125                         return False;
2126
2127                 return True;
2128         }
2129
2130         if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
2131                 return False;
2132
2133         switch (r_u->switch_level) {
2134         case 0x1:
2135                 if(!sam_io_sam_dispinfo_1("users", r_u->ctr->sam.info1,
2136                                 r_u->num_entries, ps, depth))
2137                         return False;
2138                 break;
2139         case 0x2:
2140                 if(!sam_io_sam_dispinfo_2("servers", r_u->ctr->sam.info2,
2141                                 r_u->num_entries, ps, depth))
2142                         return False;
2143                 break;
2144         case 0x3:
2145                 if(!sam_io_sam_dispinfo_3("groups", r_u->ctr->sam.info3,
2146                                     r_u->num_entries, ps, depth))
2147                         return False;
2148                 break;
2149         case 0x4:
2150                 if(!sam_io_sam_dispinfo_4("user list",
2151                                     r_u->ctr->sam.info4,
2152                                     r_u->num_entries, ps, depth))
2153                         return False;
2154                 break;
2155         case 0x5:
2156                 if(!sam_io_sam_dispinfo_5("group list",
2157                                     r_u->ctr->sam.info5,
2158                                     r_u->num_entries, ps, depth))
2159                         return False;
2160                 break;
2161         default:
2162                 DEBUG(0,("samr_io_r_query_dispinfo: unknown switch value\n"));
2163                 break;
2164         }
2165         
2166         if(!prs_align(ps))
2167                 return False;
2168         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2169                 return False;
2170
2171         return True;
2172 }
2173
2174 /*******************************************************************
2175 inits a SAMR_Q_OPEN_GROUP structure.
2176 ********************************************************************/
2177
2178 void init_samr_q_open_group(SAMR_Q_OPEN_GROUP * q_c,
2179                             POLICY_HND *hnd,
2180                             uint32 access_mask, uint32 rid)
2181 {
2182         DEBUG(5, ("init_samr_q_open_group\n"));
2183
2184         q_c->domain_pol = *hnd;
2185         q_c->access_mask = access_mask;
2186         q_c->rid_group = rid;
2187 }
2188
2189 /*******************************************************************
2190 reads or writes a structure.
2191 ********************************************************************/
2192
2193 BOOL samr_io_q_open_group(const char *desc, SAMR_Q_OPEN_GROUP * q_u,
2194                           prs_struct *ps, int depth)
2195 {
2196         if (q_u == NULL)
2197                 return False;
2198
2199         prs_debug(ps, depth, desc, "samr_io_q_open_group");
2200         depth++;
2201
2202         if(!prs_align(ps))
2203                 return False;
2204
2205         if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
2206                 return False;
2207
2208         if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
2209                 return False;
2210         if(!prs_uint32("rid_group", ps, depth, &q_u->rid_group))
2211                 return False;
2212
2213         return True;
2214 }
2215
2216 /*******************************************************************
2217 reads or writes a structure.
2218 ********************************************************************/
2219
2220 BOOL samr_io_r_open_group(const char *desc, SAMR_R_OPEN_GROUP * r_u,
2221                           prs_struct *ps, int depth)
2222 {
2223         if (r_u == NULL)
2224                 return False;
2225
2226         prs_debug(ps, depth, desc, "samr_io_r_open_group");
2227         depth++;
2228
2229         if(!prs_align(ps))
2230                 return False;
2231
2232         if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
2233                 return False;
2234
2235         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2236                 return False;
2237
2238         return True;
2239 }
2240
2241 /*******************************************************************
2242 inits a GROUP_INFO1 structure.
2243 ********************************************************************/
2244
2245 void init_samr_group_info1(GROUP_INFO1 * gr1,
2246                            char *acct_name, char *acct_desc,
2247                            uint32 num_members)
2248 {
2249         DEBUG(5, ("init_samr_group_info1\n"));
2250
2251         gr1->group_attr = (SE_GROUP_MANDATORY|SE_GROUP_ENABLED_BY_DEFAULT); /* why not | SE_GROUP_ENABLED ? */
2252         gr1->num_members = num_members;
2253
2254         init_unistr2(&gr1->uni_acct_name, acct_name, UNI_FLAGS_NONE);
2255         init_uni_hdr(&gr1->hdr_acct_name, &gr1->uni_acct_name);
2256         init_unistr2(&gr1->uni_acct_desc, acct_desc, UNI_FLAGS_NONE);
2257         init_uni_hdr(&gr1->hdr_acct_desc, &gr1->uni_acct_desc);
2258 }
2259
2260 /*******************************************************************
2261 reads or writes a structure.
2262 ********************************************************************/
2263
2264 BOOL samr_io_group_info1(const char *desc, GROUP_INFO1 * gr1,
2265                          prs_struct *ps, int depth)
2266 {
2267         uint16 dummy = 1;
2268
2269         if (gr1 == NULL)
2270                 return False;
2271
2272         prs_debug(ps, depth, desc, "samr_io_group_info1");
2273         depth++;
2274
2275         if(!prs_uint16("level", ps, depth, &dummy))
2276                 return False;
2277
2278         if(!prs_align(ps))
2279                 return False;
2280
2281         if(!smb_io_unihdr("hdr_acct_name", &gr1->hdr_acct_name, ps, depth))
2282                 return False;
2283
2284         if(!prs_uint32("group_attr", ps, depth, &gr1->group_attr))
2285                 return False;
2286         if(!prs_uint32("num_members", ps, depth, &gr1->num_members))
2287                 return False;
2288
2289         if(!smb_io_unihdr("hdr_acct_desc", &gr1->hdr_acct_desc, ps, depth))
2290                 return False;
2291
2292         if(!smb_io_unistr2("uni_acct_name", &gr1->uni_acct_name,
2293                            gr1->hdr_acct_name.buffer, ps, depth))
2294                 return False;
2295
2296         if(!smb_io_unistr2("uni_acct_desc", &gr1->uni_acct_desc,
2297                            gr1->hdr_acct_desc.buffer, ps, depth))
2298                 return False;
2299
2300         return True;
2301 }
2302
2303 /*******************************************************************
2304 inits a GROUP_INFO2 structure.
2305 ********************************************************************/
2306
2307 void init_samr_group_info2(GROUP_INFO2 * gr2, const char *acct_name)
2308 {
2309         DEBUG(5, ("init_samr_group_info2\n"));
2310
2311         gr2->level = 2;
2312         init_unistr2(&gr2->uni_acct_name, acct_name, UNI_FLAGS_NONE);
2313         init_uni_hdr(&gr2->hdr_acct_name, &gr2->uni_acct_name);
2314 }
2315
2316 /*******************************************************************
2317 reads or writes a structure.
2318 ********************************************************************/
2319
2320 BOOL samr_io_group_info2(const char *desc, GROUP_INFO2 *gr2, prs_struct *ps, int depth)
2321 {
2322         if (gr2 == NULL)
2323                 return False;
2324
2325         prs_debug(ps, depth, desc, "samr_io_group_info2");
2326         depth++;
2327
2328         if(!prs_uint16("hdr_level", ps, depth, &gr2->level))
2329                 return False;
2330
2331         if(!smb_io_unihdr("hdr_acct_name", &gr2->hdr_acct_name, ps, depth))
2332                 return False;
2333         if(!smb_io_unistr2("uni_acct_name", &gr2->uni_acct_name,
2334                            gr2->hdr_acct_name.buffer, ps, depth))
2335                 return False;
2336
2337         return True;
2338 }
2339
2340 /*******************************************************************
2341 inits a GROUP_INFO3 structure.
2342 ********************************************************************/
2343
2344 void init_samr_group_info3(GROUP_INFO3 *gr3)
2345 {
2346         DEBUG(5, ("init_samr_group_info3\n"));
2347
2348         gr3->group_attr = (SE_GROUP_MANDATORY|SE_GROUP_ENABLED_BY_DEFAULT); /* why not | SE_GROUP_ENABLED ? */
2349 }
2350
2351 /*******************************************************************
2352 reads or writes a structure.
2353 ********************************************************************/
2354
2355 BOOL samr_io_group_info3(const char *desc, GROUP_INFO3 *gr3, prs_struct *ps, int depth)
2356 {
2357         if (gr3 == NULL)
2358                 return False;
2359
2360         prs_debug(ps, depth, desc, "samr_io_group_info3");
2361         depth++;
2362
2363         if(!prs_align(ps))
2364                 return False;
2365
2366         if(!prs_uint32("group_attr", ps, depth, &gr3->group_attr))
2367                 return False;
2368
2369         return True;
2370 }
2371
2372 /*******************************************************************
2373 inits a GROUP_INFO4 structure.
2374 ********************************************************************/
2375
2376 void init_samr_group_info4(GROUP_INFO4 * gr4, const char *acct_desc)
2377 {
2378         DEBUG(5, ("init_samr_group_info4\n"));
2379
2380         gr4->level = 4;
2381         init_unistr2(&gr4->uni_acct_desc, acct_desc, UNI_FLAGS_NONE);
2382         init_uni_hdr(&gr4->hdr_acct_desc, &gr4->uni_acct_desc);
2383 }
2384
2385 /*******************************************************************
2386 reads or writes a structure.
2387 ********************************************************************/
2388
2389 BOOL samr_io_group_info4(const char *desc, GROUP_INFO4 * gr4,
2390                          prs_struct *ps, int depth)
2391 {
2392         if (gr4 == NULL)
2393                 return False;
2394
2395         prs_debug(ps, depth, desc, "samr_io_group_info4");
2396         depth++;
2397
2398         if(!prs_uint16("hdr_level", ps, depth, &gr4->level))
2399                 return False;
2400         if(!smb_io_unihdr("hdr_acct_desc", &gr4->hdr_acct_desc, ps, depth))
2401                 return False;
2402         if(!smb_io_unistr2("uni_acct_desc", &gr4->uni_acct_desc,
2403                            gr4->hdr_acct_desc.buffer, ps, depth))
2404                 return False;
2405
2406         return True;
2407 }
2408
2409 /*******************************************************************
2410 inits a GROUP_INFO5 structure.
2411 ********************************************************************/
2412
2413 void init_samr_group_info5(GROUP_INFO5 * gr5,
2414                            char *acct_name, char *acct_desc,
2415                            uint32 num_members)
2416 {
2417         DEBUG(5, ("init_samr_group_info5\n"));
2418
2419         gr5->group_attr = (SE_GROUP_MANDATORY|SE_GROUP_ENABLED_BY_DEFAULT); /* why not | SE_GROUP_ENABLED ? */
2420         gr5->num_members = num_members;
2421
2422         init_unistr2(&gr5->uni_acct_name, acct_name, UNI_FLAGS_NONE);
2423         init_uni_hdr(&gr5->hdr_acct_name, &gr5->uni_acct_name);
2424         init_unistr2(&gr5->uni_acct_desc, acct_desc, UNI_FLAGS_NONE);
2425         init_uni_hdr(&gr5->hdr_acct_desc, &gr5->uni_acct_desc);
2426 }
2427
2428 /*******************************************************************
2429 reads or writes a structure.
2430 ********************************************************************/
2431
2432 BOOL samr_io_group_info5(const char *desc, GROUP_INFO5 * gr5,
2433                          prs_struct *ps, int depth)
2434 {
2435         uint16 dummy = 1;
2436
2437         if (gr5 == NULL)
2438                 return False;
2439
2440         prs_debug(ps, depth, desc, "samr_io_group_info5");
2441         depth++;
2442
2443         if(!prs_uint16("level", ps, depth, &dummy))
2444                 return False;
2445
2446         if(!prs_align(ps))
2447                 return False;
2448
2449         if(!smb_io_unihdr("hdr_acct_name", &gr5->hdr_acct_name, ps, depth))
2450                 return False;
2451
2452         if(!prs_uint32("group_attr", ps, depth, &gr5->group_attr))
2453                 return False;
2454         if(!prs_uint32("num_members", ps, depth, &gr5->num_members))
2455                 return False;
2456
2457         if(!smb_io_unihdr("hdr_acct_desc", &gr5->hdr_acct_desc, ps, depth))
2458                 return False;
2459
2460         if(!smb_io_unistr2("uni_acct_name", &gr5->uni_acct_name,
2461                            gr5->hdr_acct_name.buffer, ps, depth))
2462                 return False;
2463
2464         if(!smb_io_unistr2("uni_acct_desc", &gr5->uni_acct_desc,
2465                            gr5->hdr_acct_desc.buffer, ps, depth))
2466                 return False;
2467
2468         return True;
2469 }
2470
2471
2472 /*******************************************************************
2473 reads or writes a structure.
2474 ********************************************************************/
2475
2476 static BOOL samr_group_info_ctr(const char *desc, GROUP_INFO_CTR **ctr,
2477                                 prs_struct *ps, int depth)
2478 {
2479         if (UNMARSHALLING(ps))
2480                 *ctr = PRS_ALLOC_MEM(ps,GROUP_INFO_CTR,1);
2481
2482         if (*ctr == NULL)
2483                 return False;
2484
2485         prs_debug(ps, depth, desc, "samr_group_info_ctr");
2486         depth++;
2487
2488         if(!prs_uint16("switch_value1", ps, depth, &(*ctr)->switch_value1))
2489                 return False;
2490
2491         switch ((*ctr)->switch_value1) {
2492         case 1:
2493                 if(!samr_io_group_info1("group_info1", &(*ctr)->group.info1, ps, depth))
2494                         return False;
2495                 break;
2496         case 2:
2497                 if(!samr_io_group_info2("group_info2", &(*ctr)->group.info2, ps, depth))
2498                         return False;
2499                 break;
2500         case 3:
2501                 if(!samr_io_group_info3("group_info3", &(*ctr)->group.info3, ps, depth))
2502                         return False;
2503                 break;
2504         case 4:
2505                 if(!samr_io_group_info4("group_info4", &(*ctr)->group.info4, ps, depth))
2506                         return False;
2507                 break;
2508         case 5:
2509                 if(!samr_io_group_info5("group_info5", &(*ctr)->group.info5, ps, depth))
2510                         return False;
2511                 break;
2512         default:
2513                 DEBUG(0,("samr_group_info_ctr: unsupported switch level\n"));
2514                 break;
2515         }
2516
2517         return True;
2518 }
2519
2520 /*******************************************************************
2521 inits a SAMR_Q_CREATE_DOM_GROUP structure.
2522 ********************************************************************/
2523
2524 void init_samr_q_create_dom_group(SAMR_Q_CREATE_DOM_GROUP * q_e,
2525                                   POLICY_HND *pol, const char *acct_desc,
2526                                   uint32 access_mask)
2527 {
2528         DEBUG(5, ("init_samr_q_create_dom_group\n"));
2529
2530         q_e->pol = *pol;
2531
2532         init_unistr2(&q_e->uni_acct_desc, acct_desc, UNI_FLAGS_NONE);
2533         init_uni_hdr(&q_e->hdr_acct_desc, &q_e->uni_acct_desc);
2534
2535         q_e->access_mask = access_mask;
2536 }
2537
2538 /*******************************************************************
2539 reads or writes a structure.
2540 ********************************************************************/
2541
2542 BOOL samr_io_q_create_dom_group(const char *desc, SAMR_Q_CREATE_DOM_GROUP * q_e,
2543                                 prs_struct *ps, int depth)
2544 {
2545         if (q_e == NULL)
2546                 return False;
2547
2548         prs_debug(ps, depth, desc, "samr_io_q_create_dom_group");
2549         depth++;
2550
2551         if(!prs_align(ps))
2552                 return False;
2553
2554         if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
2555                 return False;
2556
2557         if(!smb_io_unihdr("hdr_acct_desc", &q_e->hdr_acct_desc, ps, depth))
2558                 return False;
2559         if(!smb_io_unistr2("uni_acct_desc", &q_e->uni_acct_desc,
2560                        q_e->hdr_acct_desc.buffer, ps, depth))
2561                 return False;
2562
2563         if(!prs_align(ps))
2564                 return False;
2565         if(!prs_uint32("access", ps, depth, &q_e->access_mask))
2566                 return False;
2567
2568         return True;
2569 }
2570
2571 /*******************************************************************
2572 reads or writes a structure.
2573 ********************************************************************/
2574
2575 BOOL samr_io_r_create_dom_group(const char *desc, SAMR_R_CREATE_DOM_GROUP * r_u,
2576                                 prs_struct *ps, int depth)
2577 {
2578         if (r_u == NULL)
2579                 return False;
2580
2581         prs_debug(ps, depth, desc, "samr_io_r_create_dom_group");
2582         depth++;
2583
2584         if(!prs_align(ps))
2585                 return False;
2586
2587         if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
2588                 return False;
2589
2590         if(!prs_uint32("rid   ", ps, depth, &r_u->rid))
2591                 return False;
2592         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2593                 return False;
2594
2595         return True;
2596 }
2597
2598 /*******************************************************************
2599 inits a SAMR_Q_DELETE_DOM_GROUP structure.
2600 ********************************************************************/
2601
2602 void init_samr_q_delete_dom_group(SAMR_Q_DELETE_DOM_GROUP * q_c,
2603                                   POLICY_HND *hnd)
2604 {
2605         DEBUG(5, ("init_samr_q_delete_dom_group\n"));
2606
2607         q_c->group_pol = *hnd;
2608 }
2609
2610 /*******************************************************************
2611 reads or writes a structure.
2612 ********************************************************************/
2613
2614 BOOL samr_io_q_delete_dom_group(const char *desc, SAMR_Q_DELETE_DOM_GROUP * q_u,
2615                                 prs_struct *ps, int depth)
2616 {
2617         if (q_u == NULL)
2618                 return False;
2619
2620         prs_debug(ps, depth, desc, "samr_io_q_delete_dom_group");
2621         depth++;
2622
2623         if(!prs_align(ps))
2624                 return False;
2625
2626         if(!smb_io_pol_hnd("group_pol", &q_u->group_pol, ps, depth))
2627                 return False;
2628
2629         return True;
2630 }
2631
2632 /*******************************************************************
2633 reads or writes a structure.
2634 ********************************************************************/
2635
2636 BOOL samr_io_r_delete_dom_group(const char *desc, SAMR_R_DELETE_DOM_GROUP * r_u,
2637                                 prs_struct *ps, int depth)
2638 {
2639         if (r_u == NULL)
2640                 return False;
2641
2642         prs_debug(ps, depth, desc, "samr_io_r_delete_dom_group");
2643         depth++;
2644
2645         if(!prs_align(ps))
2646                 return False;
2647
2648         if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
2649                 return False;
2650
2651         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2652                 return False;
2653
2654         return True;
2655 }
2656
2657 /*******************************************************************
2658 inits a SAMR_Q_DEL_GROUPMEM structure.
2659 ********************************************************************/
2660
2661 void init_samr_q_del_groupmem(SAMR_Q_DEL_GROUPMEM * q_e,
2662                               POLICY_HND *pol, uint32 rid)
2663 {
2664         DEBUG(5, ("init_samr_q_del_groupmem\n"));
2665
2666         q_e->pol = *pol;
2667         q_e->rid = rid;
2668 }
2669
2670 /*******************************************************************
2671 reads or writes a structure.
2672 ********************************************************************/
2673
2674 BOOL samr_io_q_del_groupmem(const char *desc, SAMR_Q_DEL_GROUPMEM * q_e,
2675                             prs_struct *ps, int depth)
2676 {
2677         if (q_e == NULL)
2678                 return False;
2679
2680         prs_debug(ps, depth, desc, "samr_io_q_del_groupmem");
2681         depth++;
2682
2683         if(!prs_align(ps))
2684                 return False;
2685
2686         if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
2687                 return False;
2688
2689         if(!prs_uint32("rid", ps, depth, &q_e->rid))
2690                 return False;
2691
2692         return True;
2693 }
2694
2695 /*******************************************************************
2696 inits a SAMR_R_DEL_GROUPMEM structure.
2697 ********************************************************************/
2698
2699 void init_samr_r_del_groupmem(SAMR_R_DEL_GROUPMEM * r_u, POLICY_HND *pol,
2700                               NTSTATUS status)
2701 {
2702         DEBUG(5, ("init_samr_r_del_groupmem\n"));
2703
2704         r_u->status = status;
2705 }
2706
2707 /*******************************************************************
2708 reads or writes a structure.
2709 ********************************************************************/
2710
2711 BOOL samr_io_r_del_groupmem(const char *desc, SAMR_R_DEL_GROUPMEM * r_u,
2712                             prs_struct *ps, int depth)
2713 {
2714         if (r_u == NULL)
2715                 return False;
2716
2717         prs_debug(ps, depth, desc, "samr_io_r_del_groupmem");
2718         depth++;
2719
2720         if(!prs_align(ps))
2721                 return False;
2722
2723         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2724                 return False;
2725
2726         return True;
2727 }
2728
2729 /*******************************************************************
2730 inits a SAMR_Q_ADD_GROUPMEM structure.
2731 ********************************************************************/
2732
2733 void init_samr_q_add_groupmem(SAMR_Q_ADD_GROUPMEM * q_e,
2734                               POLICY_HND *pol, uint32 rid)
2735 {
2736         DEBUG(5, ("init_samr_q_add_groupmem\n"));
2737
2738         q_e->pol = *pol;
2739         q_e->rid = rid;
2740         q_e->unknown = 0x0005;
2741 }
2742
2743 /*******************************************************************
2744 reads or writes a structure.
2745 ********************************************************************/
2746
2747 BOOL samr_io_q_add_groupmem(const char *desc, SAMR_Q_ADD_GROUPMEM * q_e,
2748                             prs_struct *ps, int depth)
2749 {
2750         if (q_e == NULL)
2751                 return False;
2752
2753         prs_debug(ps, depth, desc, "samr_io_q_add_groupmem");
2754         depth++;
2755
2756         if(!prs_align(ps))
2757                 return False;
2758
2759         if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
2760                 return False;
2761
2762         if(!prs_uint32("rid    ", ps, depth, &q_e->rid))
2763                 return False;
2764         if(!prs_uint32("unknown", ps, depth, &q_e->unknown))
2765                 return False;
2766
2767         return True;
2768 }
2769
2770 /*******************************************************************
2771 inits a SAMR_R_ADD_GROUPMEM structure.
2772 ********************************************************************/
2773
2774 void init_samr_r_add_groupmem(SAMR_R_ADD_GROUPMEM * r_u, POLICY_HND *pol,
2775                               NTSTATUS status)
2776 {
2777         DEBUG(5, ("init_samr_r_add_groupmem\n"));
2778
2779         r_u->status = status;
2780 }
2781
2782 /*******************************************************************
2783 reads or writes a structure.
2784 ********************************************************************/
2785
2786 BOOL samr_io_r_add_groupmem(const char *desc, SAMR_R_ADD_GROUPMEM * r_u,
2787                             prs_struct *ps, int depth)
2788 {
2789         if (r_u == NULL)
2790                 return False;
2791
2792         prs_debug(ps, depth, desc, "samr_io_r_add_groupmem");
2793         depth++;
2794
2795         if(!prs_align(ps))
2796                 return False;
2797
2798         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2799                 return False;
2800
2801         return True;
2802 }
2803
2804 /*******************************************************************
2805 inits a SAMR_Q_SET_GROUPINFO structure.
2806 ********************************************************************/
2807
2808 void init_samr_q_set_groupinfo(SAMR_Q_SET_GROUPINFO * q_e,
2809                                POLICY_HND *pol, GROUP_INFO_CTR * ctr)
2810 {
2811         DEBUG(5, ("init_samr_q_set_groupinfo\n"));
2812
2813         q_e->pol = *pol;
2814         q_e->ctr = ctr;
2815 }
2816
2817 /*******************************************************************
2818 reads or writes a structure.
2819 ********************************************************************/
2820
2821 BOOL samr_io_q_set_groupinfo(const char *desc, SAMR_Q_SET_GROUPINFO * q_e,
2822                              prs_struct *ps, int depth)
2823 {
2824         if (q_e == NULL)
2825                 return False;
2826
2827         prs_debug(ps, depth, desc, "samr_io_q_set_groupinfo");
2828         depth++;
2829
2830         if(!prs_align(ps))
2831                 return False;
2832
2833         if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
2834                 return False;
2835         
2836         if(!samr_group_info_ctr("ctr", &q_e->ctr, ps, depth))
2837                 return False;
2838
2839         return True;
2840 }
2841
2842 /*******************************************************************
2843 inits a SAMR_R_SET_GROUPINFO structure.
2844 ********************************************************************/
2845
2846 void init_samr_r_set_groupinfo(SAMR_R_SET_GROUPINFO * r_u, NTSTATUS status)
2847 {
2848         DEBUG(5, ("init_samr_r_set_groupinfo\n"));
2849
2850         r_u->status = status;
2851 }
2852
2853 /*******************************************************************
2854 reads or writes a structure.
2855 ********************************************************************/
2856
2857 BOOL samr_io_r_set_groupinfo(const char *desc, SAMR_R_SET_GROUPINFO * r_u,
2858                              prs_struct *ps, int depth)
2859 {
2860         if (r_u == NULL)
2861                 return False;
2862
2863         prs_debug(ps, depth, desc, "samr_io_r_set_groupinfo");
2864         depth++;
2865
2866         if(!prs_align(ps))
2867                 return False;
2868
2869         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2870                 return False;
2871
2872         return True;
2873 }
2874
2875 /*******************************************************************
2876 inits a SAMR_Q_QUERY_GROUPINFO structure.
2877 ********************************************************************/
2878
2879 void init_samr_q_query_groupinfo(SAMR_Q_QUERY_GROUPINFO * q_e,
2880                                  POLICY_HND *pol, uint16 switch_level)
2881 {
2882         DEBUG(5, ("init_samr_q_query_groupinfo\n"));
2883
2884         q_e->pol = *pol;
2885
2886         q_e->switch_level = switch_level;
2887 }
2888
2889 /*******************************************************************
2890 reads or writes a structure.
2891 ********************************************************************/
2892
2893 BOOL samr_io_q_query_groupinfo(const char *desc, SAMR_Q_QUERY_GROUPINFO * q_e,
2894                                prs_struct *ps, int depth)
2895 {
2896         if (q_e == NULL)
2897                 return False;
2898
2899         prs_debug(ps, depth, desc, "samr_io_q_query_groupinfo");
2900         depth++;
2901
2902         if(!prs_align(ps))
2903                 return False;
2904
2905         if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
2906                 return False;
2907
2908         if(!prs_uint16("switch_level", ps, depth, &q_e->switch_level))
2909                 return False;
2910
2911         return True;
2912 }
2913
2914 /*******************************************************************
2915 inits a SAMR_R_QUERY_GROUPINFO structure.
2916 ********************************************************************/
2917
2918 void init_samr_r_query_groupinfo(SAMR_R_QUERY_GROUPINFO * r_u,
2919                                  GROUP_INFO_CTR * ctr, NTSTATUS status)
2920 {
2921         DEBUG(5, ("init_samr_r_query_groupinfo\n"));
2922
2923         r_u->ptr = (NT_STATUS_IS_OK(status) && ctr != NULL) ? 1 : 0;
2924         r_u->ctr = ctr;
2925         r_u->status = status;
2926 }
2927
2928 /*******************************************************************
2929 reads or writes a structure.
2930 ********************************************************************/
2931
2932 BOOL samr_io_r_query_groupinfo(const char *desc, SAMR_R_QUERY_GROUPINFO * r_u,
2933                                prs_struct *ps, int depth)
2934 {
2935         if (r_u == NULL)
2936                 return False;
2937
2938         prs_debug(ps, depth, desc, "samr_io_r_query_groupinfo");
2939         depth++;
2940
2941         if(!prs_align(ps))
2942                 return False;
2943
2944         if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
2945                 return False;
2946
2947         if (r_u->ptr != 0) {
2948                 if(!samr_group_info_ctr("ctr", &r_u->ctr, ps, depth))
2949                         return False;
2950         }
2951
2952         if(!prs_align(ps))
2953                 return False;
2954         if(!prs_ntstatus("status", ps, depth, &r_u->status))
2955                 return False;
2956
2957         return True;
2958 }
2959
2960 /*******************************************************************
2961 inits a SAMR_Q_QUERY_GROUPMEM structure.
2962 ********************************************************************/
2963
2964 void init_samr_q_query_groupmem(SAMR_Q_QUERY_GROUPMEM * q_c, POLICY_HND *hnd)
2965 {
2966         DEBUG(5, ("init_samr_q_query_groupmem\n"));
2967
2968         q_c->group_pol = *hnd;
2969 }
2970
2971 /*******************************************************************
2972 reads or writes a structure.
2973 ********************************************************************/
2974
2975 BOOL samr_io_q_query_groupmem(const char *desc, SAMR_Q_QUERY_GROUPMEM * q_u,
2976                               prs_struct *ps, int depth)
2977 {
2978         if (q_u == NULL)
2979                 return False;
2980
2981         prs_debug(ps, depth, desc, "samr_io_q_query_groupmem");
2982         depth++;
2983
2984         if(!prs_align(ps))
2985                 return False;
2986
2987         if(!smb_io_pol_hnd("group_pol", &q_u->group_pol, ps, depth))
2988                 return False;
2989
2990         return True;
2991 }
2992
2993 /*******************************************************************
2994 inits a SAMR_R_QUERY_GROUPMEM structure.
2995 ********************************************************************/
2996
2997 void init_samr_r_query_groupmem(SAMR_R_QUERY_GROUPMEM * r_u,
2998                                 uint32 num_entries, uint32 *rid,
2999                                 uint32 *attr, NTSTATUS status)
3000 {
3001         DEBUG(5, ("init_samr_r_query_groupmem\n"));
3002
3003         if (NT_STATUS_IS_OK(status)) {
3004                 r_u->ptr = 1;
3005                 r_u->num_entries = num_entries;
3006
3007                 r_u->ptr_attrs = attr != NULL ? 1 : 0;
3008                 r_u->ptr_rids = rid != NULL ? 1 : 0;
3009
3010                 r_u->num_rids = num_entries;
3011                 r_u->rid = rid;
3012
3013                 r_u->num_attrs = num_entries;
3014                 r_u->attr = attr;
3015         } else {
3016                 r_u->ptr = 0;
3017                 r_u->num_entries = 0;
3018         }
3019
3020         r_u->status = status;
3021 }
3022
3023 /*******************************************************************
3024 reads or writes a structure.
3025 ********************************************************************/
3026
3027 BOOL samr_io_r_query_groupmem(const char *desc, SAMR_R_QUERY_GROUPMEM * r_u,
3028                               prs_struct *ps, int depth)
3029 {
3030         uint32 i;
3031
3032         if (r_u == NULL)
3033                 return False;
3034
3035         if (UNMARSHALLING(ps))
3036                 ZERO_STRUCTP(r_u);
3037
3038         prs_debug(ps, depth, desc, "samr_io_r_query_groupmem");
3039         depth++;
3040
3041         if(!prs_align(ps))
3042                 return False;
3043
3044         if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
3045                 return False;
3046         if(!prs_uint32("num_entries ", ps, depth, &r_u->num_entries))
3047                 return False;
3048
3049         if (r_u->ptr != 0) {
3050                 if(!prs_uint32("ptr_rids ", ps, depth, &r_u->ptr_rids))
3051                         return False;
3052                 if(!prs_uint32("ptr_attrs", ps, depth, &r_u->ptr_attrs))
3053                         return False;
3054
3055                 if (r_u->ptr_rids != 0) {
3056                         if(!prs_uint32("num_rids", ps, depth, &r_u->num_rids))
3057                                 return False;
3058                         if (UNMARSHALLING(ps) && r_u->num_rids != 0) {
3059                                 r_u->rid = PRS_ALLOC_MEM(ps,uint32,r_u->num_rids);
3060                                 if (r_u->rid == NULL)
3061                                         return False;
3062                         }
3063
3064                         for (i = 0; i < r_u->num_rids; i++) {
3065                                 if(!prs_uint32("", ps, depth, &r_u->rid[i]))
3066                                         return False;
3067                         }
3068                 }
3069
3070                 if (r_u->ptr_attrs != 0) {
3071                         if(!prs_uint32("num_attrs", ps, depth, &r_u->num_attrs))
3072                                 return False;
3073
3074                         if (UNMARSHALLING(ps) && r_u->num_attrs != 0) {
3075                                 r_u->attr = PRS_ALLOC_MEM(ps,uint32,r_u->num_attrs);
3076                                 if (r_u->attr == NULL)
3077                                         return False;
3078                         }
3079
3080                         for (i = 0; i < r_u->num_attrs; i++) {
3081                                 if(!prs_uint32("", ps, depth, &r_u->attr[i]))
3082                                         return False;
3083                         }
3084                 }
3085         }
3086
3087         if(!prs_ntstatus("status", ps, depth, &r_u->status))
3088                 return False;
3089
3090         return True;
3091 }
3092
3093 /*******************************************************************
3094 inits a SAMR_Q_QUERY_USERGROUPS structure.
3095 ********************************************************************/
3096
3097 void init_samr_q_query_usergroups(SAMR_Q_QUERY_USERGROUPS * q_u,
3098                                   POLICY_HND *hnd)
3099 {
3100         DEBUG(5, ("init_samr_q_query_usergroups\n"));
3101
3102         q_u->pol = *hnd;
3103 }
3104
3105 /*******************************************************************
3106 reads or writes a structure.
3107 ********************************************************************/
3108
3109 BOOL samr_io_q_query_usergroups(const char *desc, SAMR_Q_QUERY_USERGROUPS * q_u,
3110                                 prs_struct *ps, int depth)
3111 {
3112         if (q_u == NULL)
3113                 return False;
3114
3115         prs_debug(ps, depth, desc, "samr_io_q_query_usergroups");
3116         depth++;
3117
3118         if(!prs_align(ps))
3119                 return False;
3120
3121         if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
3122                 return False;
3123
3124         return True;
3125 }
3126
3127 /*******************************************************************
3128 inits a SAMR_R_QUERY_USERGROUPS structure.
3129 ********************************************************************/
3130
3131 void init_samr_r_query_usergroups(SAMR_R_QUERY_USERGROUPS * r_u,
3132                                   uint32 num_gids, DOM_GID * gid,
3133                                   NTSTATUS status)
3134 {
3135         DEBUG(5, ("init_samr_r_query_usergroups\n"));
3136
3137         if (NT_STATUS_IS_OK(status)) {
3138                 r_u->ptr_0 = 1;
3139                 r_u->num_entries = num_gids;
3140                 r_u->ptr_1 = (num_gids != 0) ? 1 : 0;
3141                 r_u->num_entries2 = num_gids;
3142
3143                 r_u->gid = gid;
3144         } else {
3145                 r_u->ptr_0 = 0;
3146                 r_u->num_entries = 0;
3147                 r_u->ptr_1 = 0;
3148                 r_u->gid = NULL;
3149         }
3150
3151         r_u->status = status;
3152 }
3153
3154 /*******************************************************************
3155 reads or writes a structure.
3156 ********************************************************************/
3157
3158 BOOL samr_io_gids(const char *desc, uint32 *num_gids, DOM_GID ** gid,
3159                   prs_struct *ps, int depth)
3160 {
3161         uint32 i;
3162         if (gid == NULL)
3163                 return False;
3164
3165         prs_debug(ps, depth, desc, "samr_io_gids");
3166         depth++;
3167
3168         if(!prs_align(ps))
3169                 return False;
3170
3171         if(!prs_uint32("num_gids", ps, depth, num_gids))
3172                 return False;
3173
3174         if ((*num_gids) != 0) {
3175                 if (UNMARSHALLING(ps)) {
3176                         (*gid) = PRS_ALLOC_MEM(ps,DOM_GID,*num_gids);
3177                 }
3178
3179                 if ((*gid) == NULL) {
3180                         return False;
3181                 }
3182
3183                 for (i = 0; i < (*num_gids); i++) {
3184                         if(!smb_io_gid("gids", &(*gid)[i], ps, depth))
3185                                 return False;
3186                 }
3187         }
3188
3189         return True;
3190 }
3191
3192 /*******************************************************************
3193 reads or writes a structure.
3194 ********************************************************************/
3195
3196 BOOL samr_io_r_query_usergroups(const char *desc, SAMR_R_QUERY_USERGROUPS * r_u,
3197                                 prs_struct *ps, int depth)
3198 {
3199         if (r_u == NULL)
3200                 return False;
3201
3202         prs_debug(ps, depth, desc, "samr_io_r_query_usergroups");
3203         depth++;
3204
3205         if(!prs_align(ps))
3206                 return False;
3207
3208         if(!prs_uint32("ptr_0       ", ps, depth, &r_u->ptr_0))
3209                 return False;
3210
3211         if (r_u->ptr_0 != 0) {
3212                 if(!prs_uint32("num_entries ", ps, depth, &r_u->num_entries))
3213                         return False;
3214                 if(!prs_uint32("ptr_1       ", ps, depth, &r_u->ptr_1))
3215                         return False;
3216
3217                 if (r_u->num_entries != 0 && r_u->ptr_1 != 0) {
3218                         if(!samr_io_gids("gids", &r_u->num_entries2, &r_u->gid, ps, depth))
3219                                 return False;
3220                 }
3221         }
3222
3223         if(!prs_align(ps))
3224                 return False;
3225         if(!prs_ntstatus("status", ps, depth, &r_u->status))
3226           return False;
3227
3228         return True;
3229 }
3230
3231 /*******************************************************************
3232 inits a SAMR_Q_ENUM_DOMAINS structure.
3233 ********************************************************************/
3234
3235 void init_samr_q_enum_domains(SAMR_Q_ENUM_DOMAINS * q_e,
3236                               POLICY_HND *pol,
3237                               uint32 start_idx, uint32 size)
3238 {
3239         DEBUG(5, ("init_samr_q_enum_domains\n"));