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