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