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