f4c17902541c2be00f4df69c36c519a084e000e2
[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                                 uint16 req_num_entries, uint16 unk_0,
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->req_num_entries = req_num_entries; /* zero indicates lots */
884         q_e->unknown_0 = unk_0; /* this gets returned in the response */
885         q_e->acb_mask  = acb_mask;
886         q_e->unknown_1 = unk_1;
887         q_e->max_size = size;
888 }
889
890 /*******************************************************************
891 reads or writes a structure.
892 ********************************************************************/
893 void samr_io_q_enum_dom_users(char *desc,  SAMR_Q_ENUM_DOM_USERS *q_e, prs_struct *ps, int depth)
894 {
895         if (q_e == NULL) return;
896
897         prs_debug(ps, depth, desc, "samr_io_q_enum_dom_users");
898         depth++;
899
900         prs_align(ps);
901
902         smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); 
903         prs_align(ps);
904
905         prs_uint16("req_num_entries", ps, depth, &(q_e->req_num_entries));
906         prs_uint16("unknown_0      ", ps, depth, &(q_e->unknown_0      ));
907
908         prs_uint16("acb_mask       ", ps, depth, &(q_e->acb_mask       ));
909         prs_uint16("unknown_1      ", ps, depth, &(q_e->unknown_1      ));
910
911         prs_uint32("max_size       ", ps, depth, &(q_e->max_size       ));
912
913         prs_align(ps);
914 }
915
916
917 /*******************************************************************
918 makes a SAMR_R_ENUM_DOM_USERS structure.
919 ********************************************************************/
920 void make_samr_r_enum_dom_users(SAMR_R_ENUM_DOM_USERS *r_u,
921                 uint32 unk_0,
922                 uint32 num_sam_entries, SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES], uint32 status)
923 {
924         int i;
925
926         if (r_u == NULL) return;
927
928         DEBUG(5,("make_samr_r_enum_dom_users\n"));
929
930         if (num_sam_entries >= MAX_SAM_ENTRIES)
931         {
932                 num_sam_entries = MAX_SAM_ENTRIES;
933                 DEBUG(5,("limiting number of entries to %d\n",
934                          num_sam_entries));
935         }
936
937         r_u->unknown_0 = unk_0;
938
939         if (num_sam_entries != 0)
940         {
941                 r_u->ptr_entries1 = 1;
942                 r_u->ptr_entries2 = 1;
943                 r_u->num_entries2 = num_sam_entries;
944                 r_u->num_entries3 = num_sam_entries;
945
946                 SMB_ASSERT_ARRAY(r_u->sam, num_sam_entries);
947                 SMB_ASSERT_ARRAY(r_u->uni_acct_name, num_sam_entries);
948
949                 for (i = 0; i < num_sam_entries; i++)
950                 {
951                         make_sam_entry(&(r_u->sam[i]),
952                                        pass[i].uni_user_name.uni_str_len,
953                                        pass[i].user_rid);
954
955                         copy_unistr2(&(r_u->uni_acct_name[i]), &(pass[i].uni_user_name));
956                 }
957
958                 r_u->num_entries4 = num_sam_entries;
959         }
960         else
961         {
962                 r_u->ptr_entries1 = 0;
963                 r_u->num_entries2 = num_sam_entries;
964                 r_u->ptr_entries2 = 1;
965         }
966
967         r_u->status = status;
968 }
969
970 /*******************************************************************
971 reads or writes a structure.
972 ********************************************************************/
973 void samr_io_r_enum_dom_users(char *desc,  SAMR_R_ENUM_DOM_USERS *r_u, prs_struct *ps, int depth)
974 {
975         int i;
976
977         if (r_u == NULL) return;
978
979         prs_debug(ps, depth, desc, "samr_io_r_enum_dom_users");
980         depth++;
981
982         prs_align(ps);
983
984         prs_uint32("unknown_0   ", ps, depth, &(r_u->unknown_0   ));
985         prs_uint32("ptr_entries1", ps, depth, &(r_u->ptr_entries1));
986
987         if (r_u->ptr_entries1 != 0)
988         {
989                 prs_uint32("num_entries2", ps, depth, &(r_u->num_entries2));
990                 prs_uint32("ptr_entries2", ps, depth, &(r_u->ptr_entries2));
991                 prs_uint32("num_entries3", ps, depth, &(r_u->num_entries3));
992
993                 SMB_ASSERT_ARRAY(r_u->sam, r_u->num_entries2);
994
995                 for (i = 0; i < r_u->num_entries2; i++)
996                 {
997                         prs_grow(ps);
998                         sam_io_sam_entry("", &(r_u->sam[i]), ps, depth);
999                 }
1000
1001                 SMB_ASSERT_ARRAY(r_u->uni_acct_name, r_u->num_entries2);
1002
1003                 for (i = 0; i < r_u->num_entries2; i++)
1004                 {
1005                         prs_grow(ps);
1006                         smb_io_unistr2("", &(r_u->uni_acct_name[i]), r_u->sam[i].hdr_name.buffer, ps, depth);
1007                 }
1008
1009                 prs_align(ps);
1010
1011                 prs_uint32("num_entries4", ps, depth, &(r_u->num_entries4));
1012         }
1013
1014         prs_uint32("status", ps, depth, &(r_u->status));
1015 }
1016
1017 /*******************************************************************
1018 makes a SAMR_Q_QUERY_DISPINFO structure.
1019 ********************************************************************/
1020 void make_samr_q_query_dispinfo(SAMR_Q_QUERY_DISPINFO *q_e, POLICY_HND *pol,
1021                                 uint16 switch_level, uint32 start_idx, uint32 size)
1022 {
1023         if (q_e == NULL || pol == NULL) return;
1024
1025         DEBUG(5,("make_samr_q_query_dispinfo\n"));
1026
1027         memcpy(&(q_e->pol), pol, sizeof(*pol));
1028
1029         q_e->switch_level = switch_level;
1030
1031         q_e->unknown_0 = 0;
1032         q_e->start_idx = start_idx;
1033         q_e->unknown_1 = 0x000007d0;
1034         q_e->max_size  = size;
1035 }
1036
1037 /*******************************************************************
1038 reads or writes a structure.
1039 ********************************************************************/
1040 void samr_io_q_query_dispinfo(char *desc,  SAMR_Q_QUERY_DISPINFO *q_e, prs_struct *ps, int depth)
1041 {
1042         if (q_e == NULL) return;
1043
1044         prs_debug(ps, depth, desc, "samr_io_q_query_dispinfo");
1045         depth++;
1046
1047         prs_align(ps);
1048
1049         smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); 
1050         prs_align(ps);
1051
1052         prs_uint16("switch_level", ps, depth, &(q_e->switch_level));
1053         prs_uint16("unknown_0   ", ps, depth, &(q_e->unknown_0   ));
1054         prs_uint32("start_idx   ", ps, depth, &(q_e->start_idx   ));
1055         prs_uint32("unknown_1   ", ps, depth, &(q_e->unknown_1   ));
1056         prs_uint32("max_size    ", ps, depth, &(q_e->max_size    ));
1057
1058         prs_align(ps);
1059 }
1060
1061
1062 /*******************************************************************
1063 makes a SAM_INFO_2 structure.
1064 ********************************************************************/
1065 void make_sam_info_2(SAM_INFO_2 *sam, uint32 acb_mask,
1066                 uint32 start_idx, uint32 num_sam_entries,
1067                 SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES])
1068 {
1069         int i;
1070         int entries_added;
1071
1072         if (sam == NULL) return;
1073
1074         DEBUG(5,("make_sam_info_2\n"));
1075
1076         if (num_sam_entries >= MAX_SAM_ENTRIES)
1077         {
1078                 num_sam_entries = MAX_SAM_ENTRIES;
1079                 DEBUG(5,("limiting number of entries to %d\n", 
1080                          num_sam_entries));
1081         }
1082
1083         for (i = start_idx, entries_added = 0; i < num_sam_entries; i++)
1084         {
1085                 if (IS_BITS_SET_ALL(pass[i].acb_info, acb_mask))
1086                 {
1087                         make_sam_entry2(&(sam->sam[entries_added]),
1088                                         start_idx + entries_added + 1,
1089                                         pass[i].uni_user_name.uni_str_len,
1090                                         pass[i].uni_acct_desc.uni_str_len,
1091                                         pass[i].user_rid,
1092                                         pass[i].acb_info);
1093
1094                         copy_unistr2(&(sam->str[entries_added].uni_srv_name), &(pass[i].uni_user_name));
1095                         copy_unistr2(&(sam->str[entries_added].uni_srv_desc), &(pass[i].uni_acct_desc));
1096
1097                         entries_added++;
1098                 }
1099
1100                 sam->num_entries   = entries_added;
1101                 sam->ptr_entries   = 1;
1102                 sam->num_entries2  = entries_added;
1103         }
1104 }
1105
1106 /*******************************************************************
1107 reads or writes a structure.
1108 ********************************************************************/
1109 static void sam_io_sam_info_2(char *desc,  SAM_INFO_2 *sam, prs_struct *ps, int depth)
1110 {
1111         int i;
1112
1113         if (sam == NULL) return;
1114
1115         prs_debug(ps, depth, desc, "sam_io_sam_info_2");
1116         depth++;
1117
1118         prs_align(ps);
1119
1120         prs_uint32("num_entries  ", ps, depth, &(sam->num_entries  ));
1121         prs_uint32("ptr_entries  ", ps, depth, &(sam->ptr_entries  ));
1122
1123         prs_uint32("num_entries2 ", ps, depth, &(sam->num_entries2 ));
1124
1125         SMB_ASSERT_ARRAY(sam->sam, sam->num_entries);
1126
1127         for (i = 0; i < sam->num_entries; i++)
1128         {
1129                 prs_grow(ps);
1130                 sam_io_sam_entry2("", &(sam->sam[i]), ps, depth);
1131         }
1132
1133         for (i = 0; i < sam->num_entries; i++)
1134         {
1135                 prs_grow(ps);
1136                 sam_io_sam_str2 ("", &(sam->str[i]),
1137                                                          sam->sam[i].hdr_srv_name.buffer,
1138                                                          sam->sam[i].hdr_srv_desc.buffer,
1139                                                          ps, depth);
1140         }
1141 }
1142
1143
1144 /*******************************************************************
1145 makes a SAM_INFO_1 structure.
1146 ********************************************************************/
1147 void make_sam_info_1(SAM_INFO_1 *sam, uint32 acb_mask,
1148                 uint32 start_idx, uint32 num_sam_entries,
1149                 SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES])
1150 {
1151         int i;
1152         int entries_added;
1153
1154         if (sam == NULL) return;
1155
1156         DEBUG(5,("make_sam_info_1\n"));
1157
1158         if (num_sam_entries >= MAX_SAM_ENTRIES)
1159         {
1160                 num_sam_entries = MAX_SAM_ENTRIES;
1161                 DEBUG(5,("limiting number of entries to %d\n", 
1162                          num_sam_entries));
1163         }
1164
1165         for (i = start_idx, entries_added = 0; i < num_sam_entries; i++)
1166         {
1167                 if (IS_BITS_SET_ALL(pass[i].acb_info, acb_mask))
1168                 {
1169                         make_sam_entry1(&(sam->sam[entries_added]),
1170                                                 start_idx + entries_added + 1,
1171                                                 pass[i].uni_user_name.uni_str_len,
1172                                                 pass[i].uni_full_name.uni_str_len, 
1173                                                 pass[i].uni_acct_desc.uni_str_len,
1174                                                 pass[i].user_rid,
1175                                                 pass[i].acb_info);
1176
1177                         copy_unistr2(&(sam->str[entries_added].uni_acct_name), &(pass[i].uni_user_name));
1178                         copy_unistr2(&(sam->str[entries_added].uni_full_name), &(pass[i].uni_full_name));
1179                         copy_unistr2(&(sam->str[entries_added].uni_acct_desc), &(pass[i].uni_acct_desc));
1180
1181                         entries_added++;
1182                 }
1183         }
1184
1185         sam->num_entries   = entries_added;
1186         sam->ptr_entries   = 1;
1187         sam->num_entries2  = entries_added;
1188 }
1189
1190
1191 /*******************************************************************
1192 reads or writes a structure.
1193 ********************************************************************/
1194 static void sam_io_sam_info_1(char *desc,  SAM_INFO_1 *sam, prs_struct *ps, int depth)
1195 {
1196         int i;
1197
1198         if (sam == NULL) return;
1199
1200         prs_debug(ps, depth, desc, "sam_io_sam_info_1");
1201         depth++;
1202
1203         prs_align(ps);
1204
1205         prs_uint32("num_entries  ", ps, depth, &(sam->num_entries  ));
1206         prs_uint32("ptr_entries  ", ps, depth, &(sam->ptr_entries  ));
1207
1208         prs_uint32("num_entries2 ", ps, depth, &(sam->num_entries2 ));
1209
1210         SMB_ASSERT_ARRAY(sam->sam, sam->num_entries);
1211
1212         for (i = 0; i < sam->num_entries; i++)
1213         {
1214                 prs_grow(ps);
1215                 sam_io_sam_entry1("", &(sam->sam[i]), ps, depth);
1216         }
1217
1218         for (i = 0; i < sam->num_entries; i++)
1219         {
1220                 prs_grow(ps);
1221                 sam_io_sam_str1 ("", &(sam->str[i]),
1222                                                          sam->sam[i].hdr_acct_name.buffer,
1223                                                          sam->sam[i].hdr_user_name.buffer,
1224                                                          sam->sam[i].hdr_user_desc.buffer,
1225                                                          ps, depth);
1226         }
1227 }
1228
1229
1230 /*******************************************************************
1231 makes a SAMR_R_QUERY_DISPINFO structure.
1232 ********************************************************************/
1233 void make_samr_r_query_dispinfo(SAMR_R_QUERY_DISPINFO *r_u,
1234                 uint16 switch_level, SAM_INFO_CTR *ctr, uint32 status)
1235 {
1236         if (r_u == NULL) return;
1237
1238         DEBUG(5,("make_samr_r_query_dispinfo\n"));
1239
1240         if (status == 0x0)
1241         {
1242                 r_u->unknown_0 = 0x0000001;
1243                 r_u->unknown_1 = 0x0000001;
1244         }
1245         else
1246         {
1247                 r_u->unknown_0 = 0x0;
1248                 r_u->unknown_1 = 0x0;
1249         }
1250
1251         r_u->switch_level = switch_level;
1252         r_u->ctr = ctr;
1253         r_u->status = status;
1254 }
1255
1256
1257 /*******************************************************************
1258 reads or writes a structure.
1259 ********************************************************************/
1260 void samr_io_r_query_dispinfo(char *desc,  SAMR_R_QUERY_DISPINFO *r_u, prs_struct *ps, int depth)
1261 {
1262         if (r_u == NULL) return;
1263
1264         prs_debug(ps, depth, desc, "samr_io_r_query_dispinfo");
1265         depth++;
1266
1267         prs_align(ps);
1268
1269         prs_uint32("unknown_0    ", ps, depth, &(r_u->unknown_0    ));
1270         prs_uint32("unknown_1    ", ps, depth, &(r_u->unknown_1    ));
1271         prs_uint16("switch_level ", ps, depth, &(r_u->switch_level ));
1272
1273         prs_align(ps);
1274
1275         switch (r_u->switch_level)
1276         {
1277                 case 0x1:
1278                 {
1279                         sam_io_sam_info_1("users", r_u->ctr->sam.info1, ps, depth);
1280                         break;
1281                 }
1282                 case 0x2:
1283                 {
1284                         sam_io_sam_info_2("servers", r_u->ctr->sam.info2, ps, depth);
1285                         break;
1286                 }
1287                 default:
1288                 {
1289                         DEBUG(5,("samr_io_r_query_dispinfo: unknown switch value\n"));
1290                         break;
1291                 }
1292         }
1293
1294         prs_uint32("status", ps, depth, &(r_u->status));
1295 }
1296
1297
1298 /*******************************************************************
1299 makes a SAMR_Q_OPEN_GROUP structure.
1300 ********************************************************************/
1301 void make_samr_q_open_group(SAMR_Q_OPEN_GROUP *q_c,
1302                                 POLICY_HND *hnd, uint32 unk, uint32 rid)
1303 {
1304         if (q_c == NULL || hnd == NULL) return;
1305
1306         DEBUG(5,("make_samr_q_open_group\n"));
1307
1308         memcpy(&(q_c->domain_pol), hnd, sizeof(q_c->domain_pol));
1309         q_c->unknown = unk;
1310         q_c->rid_group = rid;
1311 }
1312
1313 /*******************************************************************
1314 reads or writes a structure.
1315 ********************************************************************/
1316 void samr_io_q_open_group(char *desc,  SAMR_Q_OPEN_GROUP *q_u, prs_struct *ps, int depth)
1317 {
1318         if (q_u == NULL) return;
1319
1320         prs_debug(ps, depth, desc, "samr_io_q_open_group");
1321         depth++;
1322
1323         prs_align(ps);
1324
1325         smb_io_pol_hnd("domain_pol", &(q_u->domain_pol), ps, depth); 
1326
1327         prs_uint32("unknown  ", ps, depth, &(q_u->unknown  ));
1328         prs_uint32("rid_group", ps, depth, &(q_u->rid_group));
1329 }
1330
1331 /*******************************************************************
1332 reads or writes a structure.
1333 ********************************************************************/
1334 void samr_io_r_open_group(char *desc,  SAMR_R_OPEN_GROUP *r_u, prs_struct *ps, int depth)
1335 {
1336         if (r_u == NULL) return;
1337
1338         prs_debug(ps, depth, desc, "samr_io_r_open_group");
1339         depth++;
1340
1341         prs_align(ps);
1342
1343         smb_io_pol_hnd("pol", &(r_u->pol), ps, depth); 
1344         prs_align(ps);
1345
1346         prs_uint32("status", ps, depth, &(r_u->status));
1347 }
1348
1349
1350 /*******************************************************************
1351 makes a GROUP_INFO1 structure.
1352 ********************************************************************/
1353 void make_samr_group_info1(GROUP_INFO1 *gr1,
1354                                 char *acct_name, char *acct_desc)
1355 {
1356         int desc_len = acct_desc != NULL ? strlen(acct_desc) : 0;
1357         int acct_len = acct_name != NULL ? strlen(acct_name) : 0;
1358         if (gr1 == NULL) return;
1359
1360         DEBUG(5,("make_samr_group_info1\n"));
1361
1362         make_uni_hdr(&(gr1->hdr_acct_name), acct_len , acct_len, acct_name ? 1 : 0);
1363
1364         gr1->unknown_1 = 0x3;
1365         gr1->unknown_2 = 0x3;
1366
1367         make_uni_hdr(&(gr1->hdr_acct_desc), desc_len , desc_len, acct_desc ? 1 : 0);
1368
1369         make_unistr2(&(gr1->uni_acct_name), acct_name, acct_len);
1370         make_unistr2(&(gr1->uni_acct_desc), acct_desc, desc_len);
1371 }
1372
1373
1374 /*******************************************************************
1375 reads or writes a structure.
1376 ********************************************************************/
1377 void samr_io_group_info1(char *desc,  GROUP_INFO1 *gr1, prs_struct *ps, int depth)
1378 {
1379         if (gr1 == NULL) return;
1380
1381         prs_debug(ps, depth, desc, "samr_io_group_info1");
1382         depth++;
1383
1384         prs_align(ps);
1385
1386         smb_io_unihdr ("hdr_acct_name", &(gr1->hdr_acct_name) , ps, depth); 
1387
1388         prs_uint32("unknown_1", ps, depth, &(gr1->unknown_1));
1389         prs_uint32("unknown_2", ps, depth, &(gr1->unknown_2));
1390
1391         smb_io_unihdr ("hdr_acct_desc", &(gr1->hdr_acct_desc) , ps, depth); 
1392
1393         smb_io_unistr2("uni_acct_name", &(gr1->uni_acct_name), gr1->hdr_acct_name.buffer, ps, depth);
1394         prs_align(ps);
1395
1396         smb_io_unistr2("uni_acct_desc", &(gr1->uni_acct_desc), gr1->hdr_acct_desc.buffer, ps, depth);
1397 }
1398
1399 /*******************************************************************
1400 makes a GROUP_INFO4 structure.
1401 ********************************************************************/
1402 void make_samr_group_info4(GROUP_INFO4 *gr4, const char *acct_desc)
1403 {
1404         int acct_len = acct_desc != NULL ? strlen(acct_desc) : 0;
1405         if (gr4 == NULL) return;
1406
1407         DEBUG(5,("make_samr_group_info4\n"));
1408
1409         make_uni_hdr(&(gr4->hdr_acct_desc), acct_len , acct_len, acct_desc ? 1 : 0);
1410         make_unistr2(&(gr4->uni_acct_desc), acct_desc, acct_len);
1411 }
1412
1413
1414 /*******************************************************************
1415 reads or writes a structure.
1416 ********************************************************************/
1417 void samr_io_group_info4(char *desc,  GROUP_INFO4 *gr4, prs_struct *ps, int depth)
1418 {
1419         if (gr4 == NULL) return;
1420
1421         prs_debug(ps, depth, desc, "samr_io_group_info4");
1422         depth++;
1423
1424         prs_align(ps);
1425
1426         smb_io_unihdr ("hdr_acct_desc", &(gr4->hdr_acct_desc) , ps, depth); 
1427         smb_io_unistr2("uni_acct_desc", &(gr4->uni_acct_desc), gr4->hdr_acct_desc.buffer, ps, depth);
1428 }
1429
1430 /*******************************************************************
1431 reads or writes a structure.
1432 ********************************************************************/
1433 void samr_group_info_ctr(char *desc,  GROUP_INFO_CTR *ctr, prs_struct *ps, int depth)
1434 {
1435         if (ctr == NULL) return;
1436
1437         prs_debug(ps, depth, desc, "samr_group_info_ctr");
1438         depth++;
1439
1440         prs_uint16("switch_value1", ps, depth, &(ctr->switch_value1));
1441         prs_uint16("switch_value2", ps, depth, &(ctr->switch_value2));
1442
1443         switch (ctr->switch_value1)
1444         {
1445                 case 1:
1446                 {
1447                         samr_io_group_info1("group_info1", &(ctr->group.info1), ps, depth);
1448                         break;
1449                 }
1450                 case 4:
1451                 {
1452                         samr_io_group_info4("group_info4", &(ctr->group.info4), ps, depth);
1453                         break;
1454                 }
1455                 default:
1456                 {
1457                         DEBUG(4,("samr_group_info_ctr: unsupported switch level\n"));
1458                         break;
1459                 }
1460         }
1461
1462         prs_align(ps);
1463 }
1464
1465
1466 /*******************************************************************
1467 makes a SAMR_Q_CREATE_DOM_GROUP structure.
1468 ********************************************************************/
1469 void make_samr_q_create_dom_group(SAMR_Q_CREATE_DOM_GROUP *q_e,
1470                                 POLICY_HND *pol,
1471                                 const char *acct_desc)
1472 {
1473         int acct_len = acct_desc != NULL ? strlen(acct_desc) : 0;
1474         if (q_e == NULL || pol == NULL) return;
1475
1476         DEBUG(5,("make_samr_q_create_dom_group\n"));
1477
1478         memcpy(&(q_e->pol), pol, sizeof(*pol));
1479
1480         make_uni_hdr(&(q_e->hdr_acct_desc), acct_len , acct_len, acct_desc ? 1 : 0);
1481         make_unistr2(&(q_e->uni_acct_desc), acct_desc, acct_len);
1482
1483         q_e->unknown_1 = 0x0002;
1484         q_e->unknown_2 = 0x0001;
1485 }
1486
1487
1488 /*******************************************************************
1489 reads or writes a structure.
1490 ********************************************************************/
1491 void samr_io_q_create_dom_group(char *desc,  SAMR_Q_CREATE_DOM_GROUP *q_e, prs_struct *ps, int depth)
1492 {
1493         if (q_e == NULL) return;
1494
1495         prs_debug(ps, depth, desc, "samr_io_q_create_dom_group");
1496         depth++;
1497
1498         prs_align(ps);
1499
1500         smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); 
1501         prs_align(ps);
1502
1503         smb_io_unihdr ("hdr_acct_desc", &(q_e->hdr_acct_desc), ps, depth); 
1504         smb_io_unistr2("uni_acct_desc", &(q_e->uni_acct_desc), q_e->hdr_acct_desc.buffer, ps, depth);
1505         prs_align(ps);
1506
1507         prs_uint16("unknown_1", ps, depth, &(q_e->unknown_1));
1508         prs_uint16("unknown_2", ps, depth, &(q_e->unknown_2));
1509 }
1510
1511
1512 /*******************************************************************
1513 makes a SAMR_R_CREATE_DOM_GROUP structure.
1514 ********************************************************************/
1515 void make_samr_r_create_dom_group(SAMR_R_CREATE_DOM_GROUP *r_u, POLICY_HND *pol,
1516                 uint32 rid, uint32 status)
1517 {
1518         if (r_u == NULL) return;
1519
1520         DEBUG(5,("make_samr_r_create_dom_group\n"));
1521
1522         memcpy(&(r_u->pol), pol, sizeof(*pol));
1523
1524         r_u->rid    = rid   ;
1525         r_u->status = status;
1526 }
1527
1528
1529 /*******************************************************************
1530 reads or writes a structure.
1531 ********************************************************************/
1532 void samr_io_r_create_dom_group(char *desc,  SAMR_R_CREATE_DOM_GROUP *r_u, prs_struct *ps, int depth)
1533 {
1534         if (r_u == NULL) return;
1535
1536         prs_debug(ps, depth, desc, "samr_io_r_create_dom_group");
1537         depth++;
1538
1539         prs_align(ps);
1540
1541         smb_io_pol_hnd("pol", &(r_u->pol), ps, depth); 
1542         prs_align(ps);
1543
1544         prs_uint32("rid   ", ps, depth, &(r_u->rid   ));
1545         prs_uint32("status", ps, depth, &(r_u->status));
1546 }
1547
1548 /*******************************************************************
1549 makes a SAMR_Q_DELETE_DOM_GROUP structure.
1550 ********************************************************************/
1551 void make_samr_q_delete_dom_group(SAMR_Q_DELETE_DOM_GROUP *q_c, POLICY_HND *hnd)
1552 {
1553         if (q_c == NULL || hnd == NULL) return;
1554
1555         DEBUG(5,("make_samr_q_delete_dom_group\n"));
1556
1557         memcpy(&(q_c->group_pol), hnd, sizeof(q_c->group_pol));
1558 }
1559
1560 /*******************************************************************
1561 reads or writes a structure.
1562 ********************************************************************/
1563 void samr_io_q_delete_dom_group(char *desc,  SAMR_Q_DELETE_DOM_GROUP *q_u, prs_struct *ps, int depth)
1564 {
1565         if (q_u == NULL) return;
1566
1567         prs_debug(ps, depth, desc, "samr_io_q_delete_dom_group");
1568         depth++;
1569
1570         prs_align(ps);
1571
1572         smb_io_pol_hnd("group_pol", &(q_u->group_pol), ps, depth); 
1573 }
1574
1575 /*******************************************************************
1576 makes a SAMR_R_DELETE_DOM_GROUP structure.
1577 ********************************************************************/
1578 void make_samr_r_delete_dom_group(SAMR_R_DELETE_DOM_GROUP *r_u,
1579                 uint32 status)
1580 {
1581         if (r_u == NULL) return;
1582
1583         DEBUG(5,("make_samr_r_delete_dom_group\n"));
1584
1585         r_u->status = status;
1586 }
1587
1588 /*******************************************************************
1589 reads or writes a structure.
1590 ********************************************************************/
1591 void samr_io_r_delete_dom_group(char *desc,  SAMR_R_DELETE_DOM_GROUP *r_u, prs_struct *ps, int depth)
1592 {
1593         if (r_u == NULL) return;
1594
1595         prs_debug(ps, depth, desc, "samr_io_r_delete_dom_group");
1596         depth++;
1597
1598         prs_align(ps);
1599
1600         prs_uint32("status", ps, depth, &(r_u->status));
1601 }
1602
1603
1604
1605 /*******************************************************************
1606 makes a SAMR_Q_DEL_GROUPMEM structure.
1607 ********************************************************************/
1608 void make_samr_q_del_groupmem(SAMR_Q_DEL_GROUPMEM *q_e,
1609                                 POLICY_HND *pol,
1610                                 uint32 rid)
1611 {
1612         if (q_e == NULL || pol == NULL) return;
1613
1614         DEBUG(5,("make_samr_q_del_groupmem\n"));
1615
1616         memcpy(&(q_e->pol), pol, sizeof(*pol));
1617
1618         q_e->rid = rid;
1619 }
1620
1621
1622 /*******************************************************************
1623 reads or writes a structure.
1624 ********************************************************************/
1625 void samr_io_q_del_groupmem(char *desc,  SAMR_Q_DEL_GROUPMEM *q_e, prs_struct *ps, int depth)
1626 {
1627         if (q_e == NULL) return;
1628
1629         prs_debug(ps, depth, desc, "samr_io_q_del_groupmem");
1630         depth++;
1631
1632         prs_align(ps);
1633
1634         smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); 
1635         prs_align(ps);
1636
1637         prs_uint32("rid    ", ps, depth, &(q_e->rid));
1638 }
1639
1640
1641 /*******************************************************************
1642 makes a SAMR_R_DEL_GROUPMEM structure.
1643 ********************************************************************/
1644 void make_samr_r_del_groupmem(SAMR_R_DEL_GROUPMEM *r_u, POLICY_HND *pol,
1645                 uint32 status)
1646 {
1647         if (r_u == NULL) return;
1648
1649         DEBUG(5,("make_samr_r_del_groupmem\n"));
1650
1651         r_u->status = status;
1652 }
1653
1654
1655 /*******************************************************************
1656 reads or writes a structure.
1657 ********************************************************************/
1658 void samr_io_r_del_groupmem(char *desc,  SAMR_R_DEL_GROUPMEM *r_u, prs_struct *ps, int depth)
1659 {
1660         if (r_u == NULL) return;
1661
1662         prs_debug(ps, depth, desc, "samr_io_r_del_groupmem");
1663         depth++;
1664
1665         prs_align(ps);
1666
1667         prs_uint32("status", ps, depth, &(r_u->status));
1668 }
1669
1670
1671 /*******************************************************************
1672 makes a SAMR_Q_ADD_GROUPMEM structure.
1673 ********************************************************************/
1674 void make_samr_q_add_groupmem(SAMR_Q_ADD_GROUPMEM *q_e,
1675                                 POLICY_HND *pol,
1676                                 uint32 rid)
1677 {
1678         if (q_e == NULL || pol == NULL) return;
1679
1680         DEBUG(5,("make_samr_q_add_groupmem\n"));
1681
1682         memcpy(&(q_e->pol), pol, sizeof(*pol));
1683
1684         q_e->rid = rid;
1685         q_e->unknown = 0x0005;
1686 }
1687
1688
1689 /*******************************************************************
1690 reads or writes a structure.
1691 ********************************************************************/
1692 void samr_io_q_add_groupmem(char *desc,  SAMR_Q_ADD_GROUPMEM *q_e, prs_struct *ps, int depth)
1693 {
1694         if (q_e == NULL) return;
1695
1696         prs_debug(ps, depth, desc, "samr_io_q_add_groupmem");
1697         depth++;
1698
1699         prs_align(ps);
1700
1701         smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); 
1702         prs_align(ps);
1703
1704         prs_uint32("rid    ", ps, depth, &(q_e->rid));
1705         prs_uint32("unknown", ps, depth, &(q_e->unknown));
1706 }
1707
1708
1709 /*******************************************************************
1710 makes a SAMR_R_ADD_GROUPMEM structure.
1711 ********************************************************************/
1712 void make_samr_r_add_groupmem(SAMR_R_ADD_GROUPMEM *r_u, POLICY_HND *pol,
1713                 uint32 status)
1714 {
1715         if (r_u == NULL) return;
1716
1717         DEBUG(5,("make_samr_r_add_groupmem\n"));
1718
1719         r_u->status = status;
1720 }
1721
1722
1723 /*******************************************************************
1724 reads or writes a structure.
1725 ********************************************************************/
1726 void samr_io_r_add_groupmem(char *desc,  SAMR_R_ADD_GROUPMEM *r_u, prs_struct *ps, int depth)
1727 {
1728         if (r_u == NULL) return;
1729
1730         prs_debug(ps, depth, desc, "samr_io_r_add_groupmem");
1731         depth++;
1732
1733         prs_align(ps);
1734
1735         prs_uint32("status", ps, depth, &(r_u->status));
1736 }
1737
1738
1739 /*******************************************************************
1740 makes a SAMR_Q_SET_GROUPINFO structure.
1741 ********************************************************************/
1742 void make_samr_q_set_groupinfo(SAMR_Q_SET_GROUPINFO *q_e,
1743                                 POLICY_HND *pol, GROUP_INFO_CTR *ctr)
1744 {
1745         if (q_e == NULL || pol == NULL) return;
1746
1747         DEBUG(5,("make_samr_q_set_groupinfo\n"));
1748
1749         memcpy(&(q_e->pol), pol, sizeof(*pol));
1750         q_e->ctr = ctr;
1751 }
1752
1753
1754 /*******************************************************************
1755 reads or writes a structure.
1756 ********************************************************************/
1757 void samr_io_q_set_groupinfo(char *desc,  SAMR_Q_SET_GROUPINFO *q_e, prs_struct *ps, int depth)
1758 {
1759         if (q_e == NULL) return;
1760
1761         prs_debug(ps, depth, desc, "samr_io_q_set_groupinfo");
1762         depth++;
1763
1764         prs_align(ps);
1765
1766         smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); 
1767         prs_align(ps);
1768
1769         samr_group_info_ctr("ctr", q_e->ctr, ps, depth);
1770 }
1771
1772
1773 /*******************************************************************
1774 makes a SAMR_R_SET_GROUPINFO structure.
1775 ********************************************************************/
1776 void make_samr_r_set_groupinfo(SAMR_R_SET_GROUPINFO *r_u, 
1777                 uint32 status)
1778 {
1779         if (r_u == NULL) return;
1780
1781         DEBUG(5,("make_samr_r_set_groupinfo\n"));
1782
1783         r_u->status = status;
1784 }
1785
1786
1787 /*******************************************************************
1788 reads or writes a structure.
1789 ********************************************************************/
1790 void samr_io_r_set_groupinfo(char *desc,  SAMR_R_SET_GROUPINFO *r_u, prs_struct *ps, int depth)
1791 {
1792         if (r_u == NULL) return;
1793
1794         prs_debug(ps, depth, desc, "samr_io_r_set_groupinfo");
1795         depth++;
1796
1797         prs_align(ps);
1798
1799         prs_uint32("status", ps, depth, &(r_u->status));
1800 }
1801
1802 /*******************************************************************
1803 makes a SAMR_Q_QUERY_GROUPINFO structure.
1804 ********************************************************************/
1805 void make_samr_q_query_groupinfo(SAMR_Q_QUERY_GROUPINFO *q_e,
1806                                 POLICY_HND *pol,
1807                                 uint16 switch_level)
1808 {
1809         if (q_e == NULL || pol == NULL) return;
1810
1811         DEBUG(5,("make_samr_q_query_groupinfo\n"));
1812
1813         memcpy(&(q_e->pol), pol, sizeof(*pol));
1814
1815         q_e->switch_level = switch_level;
1816 }
1817
1818
1819 /*******************************************************************
1820 reads or writes a structure.
1821 ********************************************************************/
1822 void samr_io_q_query_groupinfo(char *desc,  SAMR_Q_QUERY_GROUPINFO *q_e, prs_struct *ps, int depth)
1823 {
1824         if (q_e == NULL) return;
1825
1826         prs_debug(ps, depth, desc, "samr_io_q_query_groupinfo");
1827         depth++;
1828
1829         prs_align(ps);
1830
1831         smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); 
1832         prs_align(ps);
1833
1834         prs_uint16("switch_level", ps, depth, &(q_e->switch_level));
1835 }
1836
1837
1838 /*******************************************************************
1839 makes a SAMR_R_QUERY_GROUPINFO structure.
1840 ********************************************************************/
1841 void make_samr_r_query_groupinfo(SAMR_R_QUERY_GROUPINFO *r_u, GROUP_INFO_CTR *ctr,
1842                 uint32 status)
1843 {
1844         if (r_u == NULL) return;
1845
1846         DEBUG(5,("make_samr_r_query_groupinfo\n"));
1847
1848         r_u->ptr = (status == 0x0 && ctr != NULL) ? 1 : 0;
1849         r_u->ctr = ctr;
1850         r_u->status = status;
1851 }
1852
1853
1854 /*******************************************************************
1855 reads or writes a structure.
1856 ********************************************************************/
1857 void samr_io_r_query_groupinfo(char *desc,  SAMR_R_QUERY_GROUPINFO *r_u, prs_struct *ps, int depth)
1858 {
1859         if (r_u == NULL) return;
1860
1861         prs_debug(ps, depth, desc, "samr_io_r_query_groupinfo");
1862         depth++;
1863
1864         prs_align(ps);
1865
1866         prs_uint32("ptr", ps, depth, &(r_u->ptr));
1867         
1868         if (r_u->ptr != 0)
1869         {
1870                 samr_group_info_ctr("ctr", r_u->ctr, ps, depth);
1871         }
1872
1873         prs_uint32("status", ps, depth, &(r_u->status));
1874 }
1875
1876
1877 /*******************************************************************
1878 makes a SAMR_Q_QUERY_GROUPMEM structure.
1879 ********************************************************************/
1880 void make_samr_q_query_groupmem(SAMR_Q_QUERY_GROUPMEM *q_c, POLICY_HND *hnd)
1881 {
1882         if (q_c == NULL || hnd == NULL) return;
1883
1884         DEBUG(5,("make_samr_q_query_groupmem\n"));
1885
1886         memcpy(&(q_c->group_pol), hnd, sizeof(q_c->group_pol));
1887 }
1888
1889 /*******************************************************************
1890 reads or writes a structure.
1891 ********************************************************************/
1892 void samr_io_q_query_groupmem(char *desc,  SAMR_Q_QUERY_GROUPMEM *q_u, prs_struct *ps, int depth)
1893 {
1894         if (q_u == NULL) return;
1895
1896         prs_debug(ps, depth, desc, "samr_io_q_query_groupmem");
1897         depth++;
1898
1899         prs_align(ps);
1900
1901         smb_io_pol_hnd("group_pol", &(q_u->group_pol), ps, depth); 
1902 }
1903
1904 /*******************************************************************
1905 makes a SAMR_R_QUERY_GROUPMEM structure.
1906 ********************************************************************/
1907 void make_samr_r_query_groupmem(SAMR_R_QUERY_GROUPMEM *r_u,
1908                 uint32 num_entries, uint32 *rid, uint32 *attr, uint32 status)
1909 {
1910         if (r_u == NULL) return;
1911
1912         DEBUG(5,("make_samr_r_query_groupmem\n"));
1913
1914         if (status == 0x0)
1915         {
1916                 r_u->ptr         = (num_entries != 0) ? 1 : 0;
1917                 r_u->num_entries = num_entries;
1918
1919                 r_u->ptr_attrs = attr != NULL ? 1 : 0;
1920                 r_u->ptr_rids = rid != NULL ? 1 : 0;
1921
1922                 r_u->num_rids = num_entries;
1923                 r_u->rid  = rid;
1924
1925                 r_u->num_attrs = num_entries;
1926                 r_u->attr = attr;
1927         }
1928         else
1929         {
1930                 r_u->ptr         = 0;
1931                 r_u->num_entries = 0;
1932         }
1933
1934         r_u->status = status;
1935 }
1936
1937 /*******************************************************************
1938 reads or writes a structure.
1939 ********************************************************************/
1940 void samr_io_r_query_groupmem(char *desc,  SAMR_R_QUERY_GROUPMEM *r_u, prs_struct *ps, int depth)
1941 {
1942         int i;
1943
1944         if (r_u == NULL) return;
1945
1946         prs_debug(ps, depth, desc, "samr_io_r_query_groupmem");
1947         depth++;
1948
1949         prs_align(ps);
1950
1951         prs_uint32("ptr", ps, depth, &(r_u->ptr));
1952         prs_uint32("num_entries ", ps, depth, &(r_u->num_entries));
1953
1954         if (r_u->ptr != 0)
1955         {
1956                 prs_uint32("ptr_rids ", ps, depth, &(r_u->ptr_rids ));
1957                 prs_uint32("ptr_attrs", ps, depth, &(r_u->ptr_attrs));
1958
1959                 if (r_u->ptr_rids != 0)
1960                 {
1961                         prs_uint32("num_rids", ps, depth, &(r_u->num_rids));
1962                         for (i = 0; i < r_u->num_rids; i++)
1963                         {
1964                                 prs_grow(ps);
1965                                 prs_uint32("", ps, depth, &(r_u->rid[i]));
1966                         }
1967                 }
1968
1969                 if (r_u->ptr_attrs != 0)
1970                 {
1971                         prs_uint32("num_attrs", ps, depth, &(r_u->num_attrs));
1972                         for (i = 0; i < r_u->num_attrs; i++)
1973                         {
1974                                 prs_grow(ps);
1975                                 prs_uint32("", ps, depth, &(r_u->attr[i]));
1976                         }
1977                 }
1978         }
1979
1980         prs_uint32("status", ps, depth, &(r_u->status));
1981 }
1982
1983
1984 /*******************************************************************
1985 makes a SAMR_Q_ENUM_DOM_GROUPS structure.
1986 ********************************************************************/
1987 void make_samr_q_enum_dom_groups(SAMR_Q_ENUM_DOM_GROUPS *q_e, POLICY_HND *pol,
1988                                 uint16 switch_level, uint32 start_idx, uint32 size)
1989 {
1990         if (q_e == NULL || pol == NULL) return;
1991
1992         DEBUG(5,("make_samr_q_enum_dom_groups\n"));
1993
1994         memcpy(&(q_e->pol), pol, sizeof(*pol));
1995
1996         q_e->switch_level = switch_level;
1997
1998         q_e->unknown_0 = 0;
1999         q_e->start_idx = start_idx;
2000         q_e->unknown_1 = 0x000007d0;
2001         q_e->max_size  = size;
2002 }
2003
2004
2005 /*******************************************************************
2006 reads or writes a structure.
2007 ********************************************************************/
2008 void samr_io_q_enum_dom_groups(char *desc,  SAMR_Q_ENUM_DOM_GROUPS *q_e, prs_struct *ps, int depth)
2009 {
2010         if (q_e == NULL) return;
2011
2012         prs_debug(ps, depth, desc, "samr_io_q_enum_dom_groups");
2013         depth++;
2014
2015         prs_align(ps);
2016
2017         smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); 
2018         prs_align(ps);
2019
2020         prs_uint16("switch_level", ps, depth, &(q_e->switch_level));
2021         prs_uint16("unknown_0   ", ps, depth, &(q_e->unknown_0   ));
2022         prs_uint32("start_idx   ", ps, depth, &(q_e->start_idx   ));
2023         prs_uint32("unknown_1   ", ps, depth, &(q_e->unknown_1   ));
2024         prs_uint32("max_size    ", ps, depth, &(q_e->max_size    ));
2025
2026         prs_align(ps);
2027 }
2028
2029
2030 /*******************************************************************
2031 makes a SAMR_R_ENUM_DOM_GROUPS structure.
2032 ********************************************************************/
2033 void make_samr_r_enum_dom_groups(SAMR_R_ENUM_DOM_GROUPS *r_u,
2034                 uint32 start_idx, uint32 num_sam_entries,
2035                 DOMAIN_GRP *grp,
2036                 uint32 status)
2037 {
2038         int i;
2039         int entries_added;
2040
2041         if (r_u == NULL) return;
2042
2043         DEBUG(5,("make_samr_r_enum_dom_groups\n"));
2044
2045         if (num_sam_entries >= MAX_SAM_ENTRIES)
2046         {
2047                 num_sam_entries = MAX_SAM_ENTRIES;
2048                 DEBUG(5,("limiting number of entries to %d\n", 
2049                          num_sam_entries));
2050         }
2051
2052         if (status == 0x0)
2053         {
2054                 for (i = start_idx, entries_added = 0; i < num_sam_entries; i++)
2055                 {
2056                         int acct_name_len = strlen(grp[i].name);
2057                         int acct_desc_len = strlen(grp[i].comment);
2058
2059                         make_sam_entry3(&(r_u->sam[entries_added]),
2060                                         start_idx + entries_added + 1,
2061                                         acct_name_len,
2062                                         acct_desc_len,
2063                                         grp[i].rid);
2064
2065                         make_unistr2(&(r_u->str[entries_added].uni_grp_name), grp[i].name   , acct_name_len);
2066                         make_unistr2(&(r_u->str[entries_added].uni_grp_desc), grp[i].comment, acct_desc_len);
2067
2068                         entries_added++;
2069                 }
2070
2071                 if (entries_added > 0)
2072                 {
2073                         r_u->unknown_0 = 0x0000492;
2074                         r_u->unknown_1 = 0x000049a;
2075                 }
2076                 else
2077                 {
2078                         r_u->unknown_0 = 0x0;
2079                         r_u->unknown_1 = 0x0;
2080                 }
2081                 r_u->switch_level  = 3;
2082                 r_u->num_entries   = entries_added;
2083                 r_u->ptr_entries   = 1;
2084                 r_u->num_entries2  = entries_added;
2085         }
2086         else
2087         {
2088                 r_u->switch_level = 0;
2089         }
2090
2091         r_u->status = status;
2092 }
2093
2094 /*******************************************************************
2095 reads or writes a structure.
2096 ********************************************************************/
2097 void samr_io_r_enum_dom_groups(char *desc,  SAMR_R_ENUM_DOM_GROUPS *r_u, prs_struct *ps, int depth)
2098 {
2099         int i;
2100
2101         if (r_u == NULL) return;
2102
2103         prs_debug(ps, depth, desc, "samr_io_r_enum_dom_groups");
2104         depth++;
2105
2106         prs_align(ps);
2107
2108         prs_uint32("unknown_0    ", ps, depth, &(r_u->unknown_0    ));
2109         prs_uint32("unknown_1    ", ps, depth, &(r_u->unknown_1    ));
2110         prs_uint32("switch_level ", ps, depth, &(r_u->switch_level ));
2111
2112         if (r_u->switch_level != 0)
2113         {
2114                 prs_uint32("num_entries  ", ps, depth, &(r_u->num_entries  ));
2115                 prs_uint32("ptr_entries  ", ps, depth, &(r_u->ptr_entries  ));
2116
2117                 prs_uint32("num_entries2 ", ps, depth, &(r_u->num_entries2 ));
2118
2119                 SMB_ASSERT_ARRAY(r_u->sam, r_u->num_entries);
2120
2121                 for (i = 0; i < r_u->num_entries; i++)
2122                 {
2123                         prs_grow(ps);
2124                         sam_io_sam_entry3("", &(r_u->sam[i]), ps, depth);
2125                 }
2126
2127                 for (i = 0; i < r_u->num_entries; i++)
2128                 {
2129                         prs_grow(ps);
2130                         sam_io_sam_str3 ("", &(r_u->str[i]),
2131                                              r_u->sam[i].hdr_grp_name.buffer,
2132                                              r_u->sam[i].hdr_grp_desc.buffer,
2133                                              ps, depth);
2134                 }
2135         }
2136
2137         prs_uint32("status", ps, depth, &(r_u->status));
2138 }
2139
2140 /*******************************************************************
2141 makes a SAMR_Q_QUERY_USERGROUPS structure.
2142 ********************************************************************/
2143 void make_samr_q_query_usergroups(SAMR_Q_QUERY_USERGROUPS *q_u,
2144                                 POLICY_HND *hnd)
2145 {
2146         if (q_u == NULL || hnd == NULL) return;
2147
2148         DEBUG(5,("make_samr_q_query_usergroups\n"));
2149
2150         memcpy(&(q_u->pol), hnd, sizeof(q_u->pol));
2151 }
2152
2153
2154 /*******************************************************************
2155 reads or writes a structure.
2156 ********************************************************************/
2157 void samr_io_q_query_usergroups(char *desc,  SAMR_Q_QUERY_USERGROUPS *q_u, prs_struct *ps, int depth)
2158 {
2159         if (q_u == NULL) return;
2160
2161         prs_debug(ps, depth, desc, "samr_io_q_query_usergroups");
2162         depth++;
2163
2164         prs_align(ps);
2165
2166         smb_io_pol_hnd("pol", &(q_u->pol), ps, depth); 
2167         prs_align(ps);
2168 }
2169
2170 /*******************************************************************
2171 makes a SAMR_R_QUERY_USERGROUPS structure.
2172 ********************************************************************/
2173 void make_samr_r_query_usergroups(SAMR_R_QUERY_USERGROUPS *r_u,
2174                 uint32 num_gids, DOM_GID *gid, uint32 status)
2175 {
2176         if (r_u == NULL) return;
2177
2178         DEBUG(5,("make_samr_r_query_usergroups\n"));
2179
2180         if (status == 0x0)
2181         {
2182                 r_u->ptr_0        = 1;
2183                 r_u->num_entries  = num_gids;
2184                 r_u->ptr_1        = (num_gids != 0) ? 1 : 0;
2185                 r_u->num_entries2 = num_gids;
2186
2187                 r_u->gid = gid;
2188         }
2189         else
2190         {
2191                 r_u->ptr_0       = 0;
2192                 r_u->num_entries = 0;
2193                 r_u->ptr_1       = 0;
2194         }
2195
2196         r_u->status = status;
2197 }
2198
2199 /*******************************************************************
2200 reads or writes a structure.
2201 ********************************************************************/
2202 void samr_io_r_query_usergroups(char *desc,  SAMR_R_QUERY_USERGROUPS *r_u, prs_struct *ps, int depth)
2203 {
2204         int i;
2205         if (r_u == NULL) return;
2206
2207         prs_debug(ps, depth, desc, "samr_io_r_query_usergroups");
2208         depth++;
2209
2210         prs_align(ps);
2211
2212         prs_uint32("ptr_0       ", ps, depth, &(r_u->ptr_0      ));
2213
2214         if (r_u->ptr_0 != 0)
2215         {
2216                 prs_uint32("num_entries ", ps, depth, &(r_u->num_entries));
2217                 prs_uint32("ptr_1       ", ps, depth, &(r_u->ptr_1      ));
2218
2219                 if (r_u->num_entries != 0)
2220                 {
2221                         prs_uint32("num_entries2", ps, depth, &(r_u->num_entries2));
2222
2223                         for (i = 0; i < r_u->num_entries2; i++)
2224                         {
2225                                 prs_grow(ps);
2226                                 smb_io_gid("", &(r_u->gid[i]), ps, depth);
2227                         }
2228                 }
2229         }
2230         prs_uint32("status", ps, depth, &(r_u->status));
2231 }
2232
2233
2234 /*******************************************************************
2235 makes a SAMR_Q_ENUM_DOM_ALIASES structure.
2236 ********************************************************************/
2237 void make_samr_q_enum_dom_aliases(SAMR_Q_ENUM_DOM_ALIASES *q_e, POLICY_HND *pol, uint32 size)
2238 {
2239         if (q_e == NULL || pol == NULL) return;
2240
2241         DEBUG(5,("make_samr_q_enum_dom_aliases\n"));
2242
2243         memcpy(&(q_e->pol), pol, sizeof(*pol));
2244
2245         q_e->unknown_0 = 0;
2246         q_e->max_size = size;
2247 }
2248
2249
2250 /*******************************************************************
2251 reads or writes a structure.
2252 ********************************************************************/
2253 void samr_io_q_enum_dom_aliases(char *desc,  SAMR_Q_ENUM_DOM_ALIASES *q_e, prs_struct *ps, int depth)
2254 {
2255         if (q_e == NULL) return;
2256
2257         prs_debug(ps, depth, desc, "samr_io_q_enum_dom_aliases");
2258         depth++;
2259
2260         prs_align(ps);
2261
2262         smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); 
2263         prs_align(ps);
2264
2265         prs_uint32("unknown_0", ps, depth, &(q_e->unknown_0));
2266         prs_uint32("max_size ", ps, depth, &(q_e->max_size ));
2267
2268         prs_align(ps);
2269 }
2270
2271
2272 /*******************************************************************
2273 makes a SAMR_R_ENUM_DOM_ALIASES structure.
2274 ********************************************************************/
2275 void make_samr_r_enum_dom_aliases(SAMR_R_ENUM_DOM_ALIASES *r_u,
2276                 uint32 num_sam_entries, LOCAL_GRP *alss,
2277                 uint32 status)
2278 {
2279         int i;
2280
2281         if (r_u == NULL) return;
2282
2283         DEBUG(5,("make_samr_r_enum_dom_aliases\n"));
2284
2285         if (num_sam_entries >= MAX_SAM_ENTRIES)
2286         {
2287                 num_sam_entries = MAX_SAM_ENTRIES;
2288                 DEBUG(5,("limiting number of entries to %d\n", 
2289                          num_sam_entries));
2290         }
2291
2292         r_u->num_entries  = num_sam_entries;
2293
2294         if (num_sam_entries > 0)
2295         {
2296                 r_u->ptr_entries  = 1;
2297                 r_u->num_entries2 = num_sam_entries;
2298                 r_u->ptr_entries2 = 1;
2299                 r_u->num_entries3 = num_sam_entries;
2300
2301                 SMB_ASSERT_ARRAY(r_u->sam, num_sam_entries);
2302
2303                 for (i = 0; i < num_sam_entries; i++)
2304                 {
2305                         int acct_name_len = strlen(alss[i].name);
2306
2307                         make_sam_entry(&(r_u->sam[i]),
2308                                         acct_name_len,
2309                                         alss[i].rid);
2310
2311                         make_unistr2(&(r_u->uni_grp_name[i]), alss[i].name   , acct_name_len);
2312                 }
2313
2314                 r_u->num_entries4 = num_sam_entries;
2315         }
2316         else
2317         {
2318                 r_u->ptr_entries = 0;
2319         }
2320
2321         r_u->status = status;
2322 }
2323
2324 /*******************************************************************
2325 reads or writes a structure.
2326 ********************************************************************/
2327 void samr_io_r_enum_dom_aliases(char *desc,  SAMR_R_ENUM_DOM_ALIASES *r_u, prs_struct *ps, int depth)
2328 {
2329         int i;
2330
2331         if (r_u == NULL) return;
2332
2333         prs_debug(ps, depth, desc, "samr_io_r_enum_dom_aliases");
2334         depth++;
2335
2336         prs_align(ps);
2337
2338         prs_uint32("num_entries", ps, depth, &(r_u->num_entries));
2339         prs_uint32("ptr_entries", ps, depth, &(r_u->ptr_entries));
2340         
2341         if (r_u->num_entries != 0 && r_u->ptr_entries != 0)
2342         {
2343                 prs_uint32("num_entries2", ps, depth, &(r_u->num_entries2));
2344                 prs_uint32("ptr_entries2", ps, depth, &(r_u->ptr_entries2));
2345                 prs_uint32("num_entries3", ps, depth, &(r_u->num_entries3));
2346
2347                 SMB_ASSERT_ARRAY(r_u->sam, r_u->num_entries);
2348
2349                 for (i = 0; i < r_u->num_entries; i++)
2350                 {
2351                         sam_io_sam_entry("", &(r_u->sam[i]), ps, depth);
2352                 }
2353
2354                 for (i = 0; i < r_u->num_entries; i++)
2355                 {
2356                         smb_io_unistr2("", &(r_u->uni_grp_name[i]), r_u->sam[i].hdr_name.buffer, ps, depth);
2357                 }
2358
2359                 prs_align(ps);
2360
2361                 prs_uint32("num_entries4", ps, depth, &(r_u->num_entries4));
2362         }
2363
2364         prs_uint32("status", ps, depth, &(r_u->status));
2365 }
2366
2367
2368 /*******************************************************************
2369 makes a ALIAS_INFO3 structure.
2370 ********************************************************************/
2371 void make_samr_alias_info3(ALIAS_INFO3 *al3, const char *acct_desc)
2372 {
2373         int acct_len = acct_desc != NULL ? strlen(acct_desc) : 0;
2374         if (al3 == NULL) return;
2375
2376         DEBUG(5,("make_samr_alias_info3\n"));
2377
2378         make_uni_hdr(&(al3->hdr_acct_desc), acct_len , acct_len, acct_desc ? 1 : 0);
2379         make_unistr2(&(al3->uni_acct_desc), acct_desc, acct_len);
2380 }
2381
2382
2383 /*******************************************************************
2384 reads or writes a structure.
2385 ********************************************************************/
2386 void samr_io_alias_info3(char *desc,  ALIAS_INFO3 *al3, prs_struct *ps, int depth)
2387 {
2388         if (al3 == NULL) return;
2389
2390         prs_debug(ps, depth, desc, "samr_io_alias_info3");
2391         depth++;
2392
2393         prs_align(ps);
2394
2395         smb_io_unihdr ("hdr_acct_desc", &(al3->hdr_acct_desc) , ps, depth); 
2396         smb_io_unistr2("uni_acct_desc", &(al3->uni_acct_desc), al3->hdr_acct_desc.buffer, ps, depth);
2397 }
2398
2399 /*******************************************************************
2400 reads or writes a structure.
2401 ********************************************************************/
2402 void samr_alias_info_ctr(char *desc,  ALIAS_INFO_CTR *ctr, prs_struct *ps, int depth)
2403 {
2404         if (ctr == NULL) return;
2405
2406         prs_debug(ps, depth, desc, "samr_alias_info_ctr");
2407         depth++;
2408
2409         prs_uint16("switch_value1", ps, depth, &(ctr->switch_value1));
2410         prs_uint16("switch_value2", ps, depth, &(ctr->switch_value2));
2411
2412         switch (ctr->switch_value1)
2413         {
2414                 case 3:
2415                 {
2416                         samr_io_alias_info3("alias_info3", &(ctr->alias.info3), ps, depth);
2417                         break;
2418                 }
2419                 default:
2420                 {
2421                         DEBUG(4,("samr_alias_info_ctr: unsupported switch level\n"));
2422                         break;
2423                 }
2424         }
2425
2426         prs_align(ps);
2427 }
2428
2429
2430 /*******************************************************************
2431 makes a SAMR_Q_QUERY_ALIASINFO structure.
2432 ********************************************************************/
2433 void make_samr_q_query_aliasinfo(SAMR_Q_QUERY_ALIASINFO *q_e,
2434                                 POLICY_HND *pol,
2435                                 uint16 switch_level)
2436 {
2437         if (q_e == NULL || pol == NULL) return;
2438
2439         DEBUG(5,("make_samr_q_query_aliasinfo\n"));
2440
2441         memcpy(&(q_e->pol), pol, sizeof(*pol));
2442
2443         q_e->switch_level = switch_level;
2444 }
2445
2446
2447 /*******************************************************************
2448 reads or writes a structure.
2449 ********************************************************************/
2450 void samr_io_q_query_aliasinfo(char *desc,  SAMR_Q_QUERY_ALIASINFO *q_e, prs_struct *ps, int depth)
2451 {
2452         if (q_e == NULL) return;
2453
2454         prs_debug(ps, depth, desc, "samr_io_q_query_aliasinfo");
2455         depth++;
2456
2457         prs_align(ps);
2458
2459         smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); 
2460         prs_align(ps);
2461
2462         prs_uint16("switch_level", ps, depth, &(q_e->switch_level));
2463 }
2464
2465
2466 /*******************************************************************
2467 makes a SAMR_R_QUERY_ALIASINFO structure.
2468 ********************************************************************/
2469 void make_samr_r_query_aliasinfo(SAMR_R_QUERY_ALIASINFO *r_u, ALIAS_INFO_CTR *ctr,
2470                 uint32 status)
2471 {
2472         if (r_u == NULL) return;
2473
2474         DEBUG(5,("make_samr_r_query_aliasinfo\n"));
2475
2476         r_u->ptr = (status == 0x0 && ctr != NULL) ? 1 : 0;
2477         r_u->ctr = ctr;
2478         r_u->status = status;
2479 }
2480
2481
2482 /*******************************************************************
2483 reads or writes a structure.
2484 ********************************************************************/
2485 void samr_io_r_query_aliasinfo(char *desc,  SAMR_R_QUERY_ALIASINFO *r_u, prs_struct *ps, int depth)
2486 {
2487         if (r_u == NULL) return;
2488
2489         prs_debug(ps, depth, desc, "samr_io_r_query_aliasinfo");
2490         depth++;
2491
2492         prs_align(ps);
2493
2494         prs_uint32("ptr", ps, depth, &(r_u->ptr));
2495         
2496         if (r_u->ptr != 0)
2497         {
2498                 samr_alias_info_ctr("ctr", r_u->ctr, ps, depth);
2499         }
2500
2501         prs_uint32("status", ps, depth, &(r_u->status));
2502 }
2503
2504
2505 /*******************************************************************
2506 makes a SAMR_Q_SET_ALIASINFO structure.
2507 ********************************************************************/
2508 void make_samr_q_set_aliasinfo(SAMR_Q_SET_ALIASINFO *q_u, POLICY_HND *hnd,
2509                                 ALIAS_INFO_CTR *ctr)
2510 {
2511         if (q_u == NULL) return;
2512
2513         DEBUG(5,("make_samr_q_set_aliasinfo\n"));
2514
2515         memcpy(&(q_u->alias_pol), hnd, sizeof(q_u->alias_pol));
2516         q_u->ctr = ctr;
2517 }
2518
2519
2520 /*******************************************************************
2521 reads or writes a structure.
2522 ********************************************************************/
2523 void samr_io_q_set_aliasinfo(char *desc,  SAMR_Q_SET_ALIASINFO *q_u, prs_struct *ps, int depth)
2524 {
2525         if (q_u == NULL) return;
2526
2527         prs_debug(ps, depth, desc, "samr_io_q_set_aliasinfo");
2528         depth++;
2529
2530         prs_align(ps);
2531
2532         smb_io_pol_hnd("alias_pol", &(q_u->alias_pol), ps, depth); 
2533         samr_alias_info_ctr("ctr", q_u->ctr, ps, depth);
2534 }
2535
2536 /*******************************************************************
2537 reads or writes a structure.
2538 ********************************************************************/
2539 void samr_io_r_set_aliasinfo(char *desc,  SAMR_R_SET_ALIASINFO *r_u, prs_struct *ps, int depth)
2540 {
2541         if (r_u == NULL) return;
2542
2543         prs_debug(ps, depth, desc, "samr_io_r_set_aliasinfo");
2544         depth++;
2545
2546         prs_align(ps);
2547         prs_uint32("status", ps, depth, &(r_u->status));
2548 }
2549
2550
2551
2552 /*******************************************************************
2553 makes a SAMR_Q_QUERY_USERALIASES structure.
2554 ********************************************************************/
2555 void make_samr_q_query_useraliases(SAMR_Q_QUERY_USERALIASES *q_u,
2556                                 POLICY_HND *hnd,
2557                                 DOM_SID *sid)
2558 {
2559         if (q_u == NULL || hnd == NULL) return;
2560
2561         DEBUG(5,("make_samr_q_query_useraliases\n"));
2562
2563         memcpy(&(q_u->pol), hnd, sizeof(q_u->pol));
2564
2565         q_u->num_sids1 = 1;
2566         q_u->ptr = 1;
2567         q_u->num_sids2 = 1;
2568
2569         {
2570                 q_u->ptr_sid[0] = 1;
2571                 make_dom_sid2(&q_u->sid[0], sid);
2572         }
2573 }
2574
2575 /*******************************************************************
2576 reads or writes a SAMR_Q_QUERY_USERALIASES structure.
2577 ********************************************************************/
2578 void samr_io_q_query_useraliases(char *desc,  SAMR_Q_QUERY_USERALIASES *q_u, prs_struct *ps, int depth)
2579 {
2580         fstring tmp;
2581         int i;
2582
2583         if (q_u == NULL) return;
2584
2585         prs_debug(ps, depth, desc, "samr_io_q_query_useraliases");
2586         depth++;
2587
2588         prs_align(ps);
2589
2590         smb_io_pol_hnd("pol", &(q_u->pol), ps, depth); 
2591         prs_align(ps);
2592
2593         prs_uint32("num_sids1", ps, depth, &(q_u->num_sids1));
2594         prs_uint32("ptr      ", ps, depth, &(q_u->ptr      ));
2595         prs_uint32("num_sids2", ps, depth, &(q_u->num_sids2));
2596
2597         SMB_ASSERT_ARRAY(q_u->ptr_sid, q_u->num_sids2);
2598
2599         for (i = 0; i < q_u->num_sids2; i++)
2600         {
2601                 slprintf(tmp, sizeof(tmp) - 1, "ptr[%02d]", i);
2602                 prs_uint32(tmp, ps, depth, &(q_u->ptr_sid[i]));
2603         }
2604
2605         for (i = 0; i < q_u->num_sids2; i++)
2606         {
2607                 if (q_u->ptr_sid[i] != 0)
2608                 {
2609                         prs_grow(ps);
2610                         slprintf(tmp, sizeof(tmp)-1, "sid[%02d]", i);
2611                         smb_io_dom_sid2(tmp, &(q_u->sid[i]), ps, depth); 
2612                 }
2613         }
2614
2615         prs_align(ps);
2616 }
2617
2618
2619 /*******************************************************************
2620 makes a SAMR_R_QUERY_USERALIASES structure.
2621 ********************************************************************/
2622 void make_samr_r_query_useraliases(SAMR_R_QUERY_USERALIASES *r_u,
2623                 uint32 num_rids, uint32 *rid, uint32 status)
2624 {
2625         if (r_u == NULL) return;
2626
2627         DEBUG(5,("make_samr_r_query_useraliases\n"));
2628
2629         if (status == 0x0)
2630         {
2631                 r_u->num_entries  = num_rids;
2632                 r_u->ptr = 1;
2633                 r_u->num_entries2 = num_rids;
2634
2635                 r_u->rid = rid;
2636         }
2637         else
2638         {
2639                 r_u->num_entries  = 0;
2640                 r_u->ptr = 0;
2641                 r_u->num_entries2 = 0;
2642         }
2643
2644         r_u->status = status;
2645 }
2646
2647 /*******************************************************************
2648 reads or writes a structure.
2649 ********************************************************************/
2650 void samr_io_r_query_useraliases(char *desc,  SAMR_R_QUERY_USERALIASES *r_u, prs_struct *ps, int depth)
2651 {
2652         fstring tmp;
2653         int i;
2654         if (r_u == NULL) return;
2655
2656         prs_debug(ps, depth, desc, "samr_io_r_query_useraliases");
2657         depth++;
2658
2659         prs_align(ps);
2660
2661         prs_uint32("num_entries", ps, depth, &(r_u->num_entries));
2662         prs_uint32("ptr        ", ps, depth, &(r_u->ptr        ));
2663         prs_uint32("num_entries2", ps, depth, &(r_u->num_entries2));
2664
2665         if (r_u->num_entries != 0)
2666         {
2667                 for (i = 0; i < r_u->num_entries2; i++)
2668                 {
2669                         slprintf(tmp, sizeof(tmp)-1, "rid[%02d]", i);
2670                         prs_uint32(tmp, ps, depth, &(r_u->rid[i]));
2671                 }
2672         }
2673
2674         prs_uint32("status", ps, depth, &(r_u->status));
2675 }
2676
2677 /*******************************************************************
2678 makes a SAMR_Q_OPEN_ALIAS structure.
2679 ********************************************************************/
2680 void make_samr_q_open_alias(SAMR_Q_OPEN_ALIAS *q_u, POLICY_HND *pol,
2681                                 uint32 unknown_0, uint32 rid)
2682 {
2683         if (q_u == NULL) return;
2684
2685         DEBUG(5,("make_samr_q_open_alias\n"));
2686
2687         memcpy(&(q_u->dom_pol), pol, sizeof(q_u->dom_pol));
2688
2689         /* example values: 0x0000 0008 */
2690         q_u->unknown_0 = unknown_0; 
2691
2692         q_u->rid_alias = rid; 
2693 }
2694
2695 /*******************************************************************
2696 reads or writes a structure.
2697 ********************************************************************/
2698 void samr_io_q_open_alias(char *desc,  SAMR_Q_OPEN_ALIAS *q_u, prs_struct *ps, int depth)
2699 {
2700         if (q_u == NULL) return;
2701
2702         prs_debug(ps, depth, desc, "samr_io_q_open_alias");
2703         depth++;
2704
2705         prs_align(ps);
2706
2707         smb_io_pol_hnd("dom_pol", &(q_u->dom_pol), ps, depth); 
2708
2709         prs_uint32("unknown_0", ps, depth, &(q_u->unknown_0));
2710         prs_uint32("rid_alias", ps, depth, &(q_u->rid_alias));
2711 }
2712
2713 /*******************************************************************
2714 reads or writes a structure.
2715 ********************************************************************/
2716 void samr_io_r_open_alias(char *desc,  SAMR_R_OPEN_ALIAS *r_u, prs_struct *ps, int depth)
2717 {
2718         if (r_u == NULL) return;
2719
2720         prs_debug(ps, depth, desc, "samr_io_r_open_alias");
2721         depth++;
2722
2723         prs_align(ps);
2724
2725         smb_io_pol_hnd("pol", &(r_u->pol), ps, depth); 
2726         prs_align(ps);
2727
2728         prs_uint32("status", ps, depth, &(r_u->status));
2729 }
2730
2731 /*******************************************************************
2732 makes a SAMR_Q_LOOKUP_RIDS structure.
2733 ********************************************************************/
2734 void make_samr_q_lookup_rids(SAMR_Q_LOOKUP_RIDS *q_u,
2735                 POLICY_HND *pol, uint32 flags,
2736                 uint32 num_rids, uint32 *rid)
2737 {
2738         int i;
2739         if (q_u == NULL) return;
2740
2741         DEBUG(5,("make_samr_r_unknwon_12\n"));
2742
2743         memcpy(&(q_u->pol), pol, sizeof(*pol));
2744
2745         q_u->num_rids1 = num_rids;
2746         q_u->flags     = flags;
2747         q_u->ptr       = 0;
2748         q_u->num_rids2 = num_rids;
2749
2750         for (i = 0; i < num_rids; i++)
2751         {
2752                 q_u->rid[i] = rid[i];
2753         }
2754 }
2755
2756 /*******************************************************************
2757 reads or writes a structure.
2758 ********************************************************************/
2759 void samr_io_q_lookup_rids(char *desc,  SAMR_Q_LOOKUP_RIDS *q_u, prs_struct *ps, int depth)
2760 {
2761         int i;
2762         fstring tmp;
2763
2764         if (q_u == NULL) return;
2765
2766         prs_debug(ps, depth, desc, "samr_io_q_lookup_rids");
2767         depth++;
2768
2769         prs_align(ps);
2770
2771         smb_io_pol_hnd("pol", &(q_u->pol), ps, depth); 
2772         prs_align(ps);
2773
2774         prs_uint32("num_rids1", ps, depth, &(q_u->num_rids1));
2775         prs_uint32("flags    ", ps, depth, &(q_u->flags    ));
2776         prs_uint32("ptr      ", ps, depth, &(q_u->ptr      ));
2777         prs_uint32("num_rids2", ps, depth, &(q_u->num_rids2));
2778
2779         SMB_ASSERT_ARRAY(q_u->rid, q_u->num_rids2);
2780
2781         for (i = 0; i < q_u->num_rids2; i++)
2782         {
2783                 prs_grow(ps);
2784                 slprintf(tmp, sizeof(tmp) - 1, "rid[%02d]  ", i);
2785                 prs_uint32(tmp, ps, depth, &(q_u->rid[i]));
2786         }
2787
2788         prs_align(ps);
2789 }
2790
2791
2792 /*******************************************************************
2793 makes a SAMR_R_LOOKUP_RIDS structure.
2794 ********************************************************************/
2795 void make_samr_r_lookup_rids(SAMR_R_LOOKUP_RIDS *r_u,
2796                 uint32 num_names, fstring *name, uint8 *type,
2797                 uint32 status)
2798 {
2799         int i;
2800         if (r_u == NULL || name == NULL || type == NULL) return;
2801
2802         DEBUG(5,("make_samr_r_lookup_rids\n"));
2803
2804         if (status == 0x0)
2805         {
2806                 r_u->num_names1 = num_names;
2807                 r_u->ptr_names  = 1;
2808                 r_u->num_names2 = num_names;
2809
2810                 r_u->num_types1 = num_names;
2811                 r_u->ptr_types  = 1;
2812                 r_u->num_types2 = num_names;
2813
2814                 SMB_ASSERT_ARRAY(r_u->hdr_name, num_names);
2815
2816                 for (i = 0; i < num_names; i++)
2817                 {
2818                         int len = name[i] != NULL ? strlen(name[i]) : 0;
2819                         make_uni_hdr(&(r_u->hdr_name[i]), len    , len, name[i] ? 1 : 0);
2820                         make_unistr2(&(r_u->uni_name[i]), name[i], len);
2821                         r_u->type[i] = type[i];
2822                 }
2823         }
2824         else
2825         {
2826                 r_u->num_names1 = num_names;
2827                 r_u->ptr_names  = 0;
2828                 r_u->num_names2 = num_names;
2829
2830                 r_u->num_types1 = num_names;
2831                 r_u->ptr_types  = 0;
2832                 r_u->num_types2 = num_names;
2833         }
2834
2835         r_u->status = status;
2836 }
2837
2838 /*******************************************************************
2839 reads or writes a structure.
2840 ********************************************************************/
2841 void samr_io_r_lookup_rids(char *desc,  SAMR_R_LOOKUP_RIDS *r_u, prs_struct *ps, int depth)
2842 {
2843         int i;
2844         fstring tmp;
2845         if (r_u == NULL) return;
2846
2847         prs_debug(ps, depth, desc, "samr_io_r_lookup_rids");
2848         depth++;
2849
2850         prs_align(ps);
2851
2852         prs_uint32("num_names1", ps, depth, &(r_u->num_names1));
2853         prs_uint32("ptr_names ", ps, depth, &(r_u->ptr_names ));
2854         prs_uint32("num_names2", ps, depth, &(r_u->num_names2));
2855
2856         if (r_u->ptr_names != 0 && r_u->num_names1 != 0)
2857         {
2858                 SMB_ASSERT_ARRAY(r_u->hdr_name, r_u->num_names2);
2859
2860                 for (i = 0; i < r_u->num_names2; i++)
2861                 {
2862                         prs_grow(ps);
2863                         slprintf(tmp, sizeof(tmp) - 1, "hdr[%02d]  ", i);
2864                         smb_io_unihdr ("", &(r_u->hdr_name[i]), ps, depth); 
2865                 }
2866                 for (i = 0; i < r_u->num_names2; i++)
2867                 {
2868                         prs_grow(ps);
2869                         slprintf(tmp, sizeof(tmp) - 1, "str[%02d]  ", i);
2870                         smb_io_unistr2("", &(r_u->uni_name[i]), r_u->hdr_name[i].buffer, ps, depth); 
2871                 }
2872         }
2873
2874         prs_align(ps);
2875
2876         prs_uint32("num_types1", ps, depth, &(r_u->num_types1));
2877         prs_uint32("ptr_types ", ps, depth, &(r_u->ptr_types ));
2878         prs_uint32("num_types2", ps, depth, &(r_u->num_types2));
2879
2880         if (r_u->ptr_types != 0 && r_u->num_types1 != 0)
2881         {
2882                 for (i = 0; i < r_u->num_types2; i++)
2883                 {
2884                         prs_grow(ps);
2885                         slprintf(tmp, sizeof(tmp) - 1, "type[%02d]  ", i);
2886                         prs_uint32(tmp, ps, depth, &(r_u->type[i]));
2887                 }
2888         }
2889
2890         prs_uint32("status", ps, depth, &(r_u->status));
2891 }
2892
2893 /*******************************************************************
2894 makes a SAMR_Q_OPEN_ALIAS structure.
2895 ********************************************************************/
2896 void make_samr_q_delete_alias(SAMR_Q_DELETE_DOM_ALIAS *q_u, POLICY_HND *hnd)
2897 {
2898         if (q_u == NULL) return;
2899
2900         DEBUG(5,("make_samr_q_delete_alias\n"));
2901
2902         memcpy(&(q_u->alias_pol), hnd, sizeof(q_u->alias_pol));
2903 }
2904
2905
2906 /*******************************************************************
2907 reads or writes a structure.
2908 ********************************************************************/
2909 void samr_io_q_delete_alias(char *desc,  SAMR_Q_DELETE_DOM_ALIAS *q_u, prs_struct *ps, int depth)
2910 {
2911         if (q_u == NULL) return;
2912
2913         prs_debug(ps, depth, desc, "samr_io_q_delete_alias");
2914         depth++;
2915
2916         prs_align(ps);
2917
2918         smb_io_pol_hnd("alias_pol", &(q_u->alias_pol), ps, depth); 
2919 }
2920
2921 /*******************************************************************
2922 reads or writes a structure.
2923 ********************************************************************/
2924 void samr_io_r_delete_alias(char *desc,  SAMR_R_DELETE_DOM_ALIAS *r_u, prs_struct *ps, int depth)
2925 {
2926         if (r_u == NULL) return;
2927
2928         prs_debug(ps, depth, desc, "samr_io_r_delete_alias");
2929         depth++;
2930
2931         prs_align(ps);
2932
2933         smb_io_pol_hnd("pol", &(r_u->pol), ps, depth); 
2934         prs_uint32("status", ps, depth, &(r_u->status));
2935 }
2936
2937
2938 /*******************************************************************
2939 makes a SAMR_Q_CREATE_DOM_ALIAS structure.
2940 ********************************************************************/
2941 void make_samr_q_create_dom_alias(SAMR_Q_CREATE_DOM_ALIAS *q_u, POLICY_HND *hnd,
2942                                 const char *acct_desc)
2943 {
2944         int acct_len = acct_desc != NULL ? strlen(acct_desc) : 0;
2945         if (q_u == NULL) return;
2946
2947         DEBUG(5,("make_samr_q_create_dom_alias\n"));
2948
2949         memcpy(&(q_u->dom_pol), hnd, sizeof(q_u->dom_pol));
2950
2951         make_uni_hdr(&(q_u->hdr_acct_desc), acct_len , acct_len, acct_desc ? 1 : 0);
2952         make_unistr2(&(q_u->uni_acct_desc), acct_desc, acct_len);
2953
2954         q_u->unknown_1 = 0x001f;
2955         q_u->unknown_2 = 0x000f;
2956 }
2957
2958
2959 /*******************************************************************
2960 reads or writes a structure.
2961 ********************************************************************/
2962 void samr_io_q_create_dom_alias(char *desc,  SAMR_Q_CREATE_DOM_ALIAS *q_u, prs_struct *ps, int depth)
2963 {
2964         if (q_u == NULL) return;
2965
2966         prs_debug(ps, depth, desc, "samr_io_q_create_dom_alias");
2967         depth++;
2968
2969         prs_align(ps);
2970
2971         smb_io_pol_hnd("dom_pol", &(q_u->dom_pol), ps, depth); 
2972
2973         smb_io_unihdr ("hdr_acct_desc", &(q_u->hdr_acct_desc) , ps, depth); 
2974         smb_io_unistr2("uni_acct_desc", &(q_u->uni_acct_desc), q_u->hdr_acct_desc.buffer, ps, depth);
2975
2976         prs_uint16("unknown_1", ps, depth, &(q_u->unknown_1));
2977         prs_uint16("unknown_2", ps, depth, &(q_u->unknown_2));
2978 }
2979
2980 /*******************************************************************
2981 makes a SAMR_R_CREATE_DOM_ALIAS structure.
2982 ********************************************************************/
2983 void make_samr_r_create_dom_alias(SAMR_R_CREATE_DOM_ALIAS *r_u, POLICY_HND *pol,
2984                 uint32 rid, uint32 status)
2985 {
2986         if (r_u == NULL) return;
2987
2988         DEBUG(5,("make_samr_r_create_dom_alias\n"));
2989
2990         memcpy(&(r_u->alias_pol), pol, sizeof(*pol));
2991         r_u->rid    = rid   ;
2992         r_u->status = status;
2993 }
2994
2995
2996 /*******************************************************************
2997 reads or writes a structure.
2998 ********************************************************************/
2999 void samr_io_r_create_dom_alias(char *desc,  SAMR_R_CREATE_DOM_ALIAS *r_u, prs_struct *ps, int depth)
3000 {
3001         if (r_u == NULL) return;
3002
3003         prs_debug(ps, depth, desc, "samr_io_r_create_dom_alias");
3004         depth++;
3005
3006         prs_align(ps);
3007
3008         smb_io_pol_hnd("alias_pol", &(r_u->alias_pol), ps, depth); 
3009         prs_uint32("rid", ps, depth, &(r_u->rid));
3010
3011         prs_uint32("status", ps, depth, &(r_u->status));
3012 }
3013
3014
3015
3016 /*******************************************************************
3017 makes a SAMR_Q_ADD_ALIASMEM structure.
3018 ********************************************************************/
3019 void make_samr_q_add_aliasmem(SAMR_Q_ADD_ALIASMEM *q_u, POLICY_HND *hnd,
3020                                 DOM_SID *sid)
3021 {
3022         if (q_u == NULL) return;
3023
3024         DEBUG(5,("make_samr_q_add_aliasmem\n"));
3025
3026         memcpy(&(q_u->alias_pol), hnd, sizeof(q_u->alias_pol));
3027         make_dom_sid2(&q_u->sid, sid);
3028 }
3029
3030
3031 /*******************************************************************
3032 reads or writes a structure.
3033 ********************************************************************/
3034 void samr_io_q_add_aliasmem(char *desc,  SAMR_Q_ADD_ALIASMEM *q_u, prs_struct *ps, int depth)
3035 {
3036         if (q_u == NULL) return;
3037
3038         prs_debug(ps, depth, desc, "samr_io_q_add_aliasmem");
3039         depth++;
3040
3041         prs_align(ps);
3042
3043         smb_io_pol_hnd ("alias_pol", &(q_u->alias_pol), ps, depth); 
3044         smb_io_dom_sid2("sid      ", &(q_u->sid      ), ps, depth); 
3045 }
3046
3047 /*******************************************************************
3048 reads or writes a structure.
3049 ********************************************************************/
3050 void samr_io_r_add_aliasmem(char *desc,  SAMR_R_ADD_ALIASMEM *r_u, prs_struct *ps, int depth)
3051 {
3052         if (r_u == NULL) return;
3053
3054         prs_debug(ps, depth, desc, "samr_io_r_add_aliasmem");
3055         depth++;
3056
3057         prs_align(ps);
3058
3059         prs_uint32("status", ps, depth, &(r_u->status));
3060 }
3061
3062
3063 /*******************************************************************
3064 makes a SAMR_Q_DEL_ALIASMEM structure.
3065 ********************************************************************/
3066 void make_samr_q_del_aliasmem(SAMR_Q_DEL_ALIASMEM *q_u, POLICY_HND *hnd,
3067                                 DOM_SID *sid)
3068 {
3069         if (q_u == NULL) return;
3070
3071         DEBUG(5,("make_samr_q_del_aliasmem\n"));
3072
3073         memcpy(&(q_u->alias_pol), hnd, sizeof(q_u->alias_pol));
3074         make_dom_sid2(&q_u->sid, sid);
3075 }
3076
3077
3078 /*******************************************************************
3079 reads or writes a structure.
3080 ********************************************************************/
3081 void samr_io_q_del_aliasmem(char *desc,  SAMR_Q_DEL_ALIASMEM *q_u, prs_struct *ps, int depth)
3082 {
3083         if (q_u == NULL) return;
3084
3085         prs_debug(ps, depth, desc, "samr_io_q_del_aliasmem");
3086         depth++;
3087
3088         prs_align(ps);
3089
3090         smb_io_pol_hnd("alias_pol", &(q_u->alias_pol), ps, depth); 
3091         smb_io_dom_sid2("sid      ", &(q_u->sid      ), ps, depth); 
3092 }
3093
3094 /*******************************************************************
3095 reads or writes a structure.
3096 ********************************************************************/
3097 void samr_io_r_del_aliasmem(char *desc,  SAMR_R_DEL_ALIASMEM *r_u, prs_struct *ps, int depth)
3098 {
3099         if (r_u == NULL) return;
3100
3101         prs_debug(ps, depth, desc, "samr_io_r_del_aliasmem");
3102         depth++;
3103
3104         prs_align(ps);
3105
3106         prs_uint32("status", ps, depth, &(r_u->status));
3107 }
3108
3109 /*******************************************************************
3110 makes a SAMR_Q_DELETE_DOM_ALIAS structure.
3111 ********************************************************************/
3112 void make_samr_q_delete_dom_alias(SAMR_Q_DELETE_DOM_ALIAS *q_c, POLICY_HND *hnd)
3113 {
3114         if (q_c == NULL || hnd == NULL) return;
3115
3116         DEBUG(5,("make_samr_q_delete_dom_alias\n"));
3117
3118         memcpy(&(q_c->alias_pol), hnd, sizeof(q_c->alias_pol));
3119 }
3120
3121 /*******************************************************************
3122 reads or writes a structure.
3123 ********************************************************************/
3124 void samr_io_q_delete_dom_alias(char *desc,  SAMR_Q_DELETE_DOM_ALIAS *q_u, prs_struct *ps, int depth)
3125 {
3126         if (q_u == NULL) return;
3127
3128         prs_debug(ps, depth, desc, "samr_io_q_delete_dom_alias");
3129         depth++;
3130
3131         prs_align(ps);
3132
3133         smb_io_pol_hnd("alias_pol", &(q_u->alias_pol), ps, depth); 
3134 }
3135
3136 /*******************************************************************
3137 makes a SAMR_R_DELETE_DOM_ALIAS structure.
3138 ********************************************************************/
3139 void make_samr_r_delete_dom_alias(SAMR_R_DELETE_DOM_ALIAS *r_u,
3140                 uint32 status)
3141 {
3142         if (r_u == NULL) return;
3143
3144         DEBUG(5,("make_samr_r_delete_dom_alias\n"));
3145
3146         r_u->status = status;
3147 }
3148
3149 /*******************************************************************
3150 reads or writes a structure.
3151 ********************************************************************/
3152 void samr_io_r_delete_dom_alias(char *desc,  SAMR_R_DELETE_DOM_ALIAS *r_u, prs_struct *ps, int depth)
3153 {
3154         if (r_u == NULL) return;
3155
3156         prs_debug(ps, depth, desc, "samr_io_r_delete_dom_alias");
3157         depth++;
3158
3159         prs_align(ps);
3160
3161         prs_uint32("status", ps, depth, &(r_u->status));
3162 }
3163
3164
3165 /*******************************************************************
3166 makes a SAMR_Q_QUERY_ALIASMEM structure.
3167 ********************************************************************/
3168 void make_samr_q_query_aliasmem(SAMR_Q_QUERY_ALIASMEM *q_c, POLICY_HND *hnd)
3169 {
3170         if (q_c == NULL || hnd == NULL) return;
3171
3172         DEBUG(5,("make_samr_q_query_aliasmem\n"));
3173
3174         memcpy(&(q_c->alias_pol), hnd, sizeof(q_c->alias_pol));
3175 }
3176
3177 /*******************************************************************
3178 reads or writes a structure.
3179 ********************************************************************/
3180 void samr_io_q_query_aliasmem(char *desc,  SAMR_Q_QUERY_ALIASMEM *q_u, prs_struct *ps, int depth)
3181 {
3182         if (q_u == NULL) return;
3183
3184         prs_debug(ps, depth, desc, "samr_io_q_query_aliasmem");
3185         depth++;
3186
3187         prs_align(ps);
3188
3189         smb_io_pol_hnd("alias_pol", &(q_u->alias_pol), ps, depth); 
3190 }
3191
3192 /*******************************************************************
3193 makes a SAMR_R_QUERY_ALIASMEM structure.
3194 ********************************************************************/
3195 void make_samr_r_query_aliasmem(SAMR_R_QUERY_ALIASMEM *r_u,
3196                 uint32 num_sids, DOM_SID2 *sid, uint32 status)
3197 {
3198         if (r_u == NULL) return;
3199
3200         DEBUG(5,("make_samr_r_query_aliasmem\n"));
3201
3202         if (status == 0x0)
3203         {
3204                 r_u->num_sids  = num_sids;
3205                 r_u->ptr       = (num_sids != 0) ? 1 : 0;
3206                 r_u->num_sids1 = num_sids;
3207
3208                 r_u->sid = sid;
3209         }
3210         else
3211         {
3212                 r_u->ptr      = 0;
3213                 r_u->num_sids = 0;
3214         }
3215
3216         r_u->status = status;
3217 }
3218
3219 /*******************************************************************
3220 reads or writes a structure.
3221 ********************************************************************/
3222 void samr_io_r_query_aliasmem(char *desc,  SAMR_R_QUERY_ALIASMEM *r_u, prs_struct *ps, int depth)
3223 {
3224         int i;
3225         uint32 ptr_sid[MAX_LOOKUP_SIDS];
3226
3227         if (r_u == NULL) return;
3228
3229         prs_debug(ps, depth, desc, "samr_io_r_query_aliasmem");
3230         depth++;
3231
3232         prs_align(ps);
3233
3234         prs_uint32("num_sids ", ps, depth, &(r_u->num_sids));
3235         prs_uint32("ptr", ps, depth, &(r_u->ptr));
3236
3237         if (r_u->ptr != 0)
3238         {
3239                 SMB_ASSERT_ARRAY(ptr_sid, r_u->num_sids);
3240
3241                 if (r_u->num_sids != 0)
3242                 {
3243                         prs_uint32("num_sids1", ps, depth, &(r_u->num_sids1));
3244
3245                         for (i = 0; i < r_u->num_sids1; i++)
3246                         {
3247                                 prs_grow(ps);
3248                                 ptr_sid[i] = 1;
3249                                 prs_uint32("", ps, depth, &(ptr_sid[i]));
3250                         }
3251                         for (i = 0; i < r_u->num_sids1; i++)
3252                         {
3253                                 prs_grow(ps);
3254                                 if (ptr_sid[i] != 0)
3255                                 {
3256                                         smb_io_dom_sid2("", &(r_u->sid[i]), ps, depth);
3257                                 }
3258                         }
3259                 }
3260         }
3261         prs_uint32("status", ps, depth, &(r_u->status));
3262 }
3263
3264 /*******************************************************************
3265 makes a SAMR_Q_LOOKUP_NAMES structure.
3266 ********************************************************************/
3267 void make_samr_q_lookup_names(SAMR_Q_LOOKUP_NAMES *q_u,
3268                 POLICY_HND *pol, uint32 flags,
3269                 uint32 num_names, const char **name)
3270 {
3271         int i;
3272         if (q_u == NULL) return;
3273
3274         DEBUG(5,("make_samr_q_lookup_names\n"));
3275
3276         memcpy(&(q_u->pol), pol, sizeof(*pol));
3277
3278         q_u->num_names1 = num_names;
3279         q_u->flags     = flags;
3280         q_u->ptr       = 0;
3281         q_u->num_names2 = num_names;
3282
3283         for (i = 0; i < num_names; i++)
3284         {
3285                 int len_name = name[i] != NULL ? strlen(name[i]) : 0;
3286                 make_uni_hdr(&(q_u->hdr_name[i]), len_name, len_name, name[i] != NULL);  /* unicode header for user_name */
3287                 make_unistr2(&(q_u->uni_name[i]), name[i], len_name);  /* unicode string for machine account */
3288         }
3289 }
3290
3291
3292 /*******************************************************************
3293 reads or writes a structure.
3294 ********************************************************************/
3295 void samr_io_q_lookup_names(char *desc,  SAMR_Q_LOOKUP_NAMES *q_u, prs_struct *ps, int depth)
3296 {
3297         int i;
3298
3299         if (q_u == NULL) return;
3300
3301         prs_debug(ps, depth, desc, "samr_io_q_lookup_names");
3302         depth++;
3303
3304         prs_align(ps);
3305
3306         smb_io_pol_hnd("pol", &(q_u->pol), ps, depth); 
3307         prs_align(ps);
3308
3309         prs_uint32("num_names1", ps, depth, &(q_u->num_names1));
3310         prs_uint32("flags     ", ps, depth, &(q_u->flags     ));
3311         prs_uint32("ptr      ", ps, depth, &(q_u->ptr      ));
3312         prs_uint32("num_names2", ps, depth, &(q_u->num_names2));
3313
3314         SMB_ASSERT_ARRAY(q_u->hdr_name, q_u->num_names2);
3315
3316         for (i = 0; i < q_u->num_names2; i++)
3317         {
3318                 prs_grow(ps);
3319                 smb_io_unihdr ("", &(q_u->hdr_name[i]), ps, depth); 
3320         }
3321         for (i = 0; i < q_u->num_names2; i++)
3322         {
3323                 prs_grow(ps);
3324                 smb_io_unistr2("", &(q_u->uni_name[i]), q_u->hdr_name[i].buffer, ps, depth); 
3325         }
3326
3327         prs_align(ps);
3328 }
3329
3330
3331 /*******************************************************************
3332 makes a SAMR_R_LOOKUP_NAMES structure.
3333 ********************************************************************/
3334 void make_samr_r_lookup_names(SAMR_R_LOOKUP_NAMES *r_u,
3335                 uint32 num_rids, uint32 *rid, uint8 *type, uint32 status)
3336 {
3337         int i;
3338         if (r_u == NULL) return;
3339
3340         DEBUG(5,("make_samr_r_lookup_names\n"));
3341
3342         if (status == 0x0)
3343         {
3344                 r_u->num_types1 = num_rids;
3345                 r_u->ptr_types  = 1;
3346                 r_u->num_types2 = num_rids;
3347
3348                 r_u->num_rids1 = num_rids;
3349                 r_u->ptr_rids  = 1;
3350                 r_u->num_rids2 = num_rids;
3351
3352                 SMB_ASSERT_ARRAY(r_u->rid, num_rids);
3353
3354                 for (i = 0; i < num_rids; i++)
3355                 {
3356                         r_u->rid [i] = rid [i];
3357                         r_u->type[i] = type[i];
3358                 }
3359         }
3360         else
3361         {
3362                 r_u->num_types1 = 0;
3363                 r_u->ptr_types  = 0;
3364                 r_u->num_types2 = 0;
3365
3366                 r_u->num_rids1 = 0;
3367                 r_u->ptr_rids  = 0;
3368                 r_u->num_rids2 = 0;
3369         }
3370
3371         r_u->status = status;
3372 }
3373
3374 /*******************************************************************
3375 reads or writes a structure.
3376 ********************************************************************/
3377 void samr_io_r_lookup_names(char *desc,  SAMR_R_LOOKUP_NAMES *r_u, prs_struct *ps, int depth)
3378 {
3379         int i;
3380         fstring tmp;
3381
3382         if (r_u == NULL) return;
3383
3384         prs_debug(ps, depth, desc, "samr_io_r_lookup_names");
3385         depth++;
3386
3387         prs_align(ps);
3388
3389         prs_uint32("num_rids1", ps, depth, &(r_u->num_rids1));
3390         prs_uint32("ptr_rids ", ps, depth, &(r_u->ptr_rids ));
3391         prs_uint32("num_rids2", ps, depth, &(r_u->num_rids2));
3392
3393         if (r_u->ptr_rids != 0 && r_u->num_rids1 != 0)
3394         {
3395                 for (i = 0; i < r_u->num_rids2; i++)
3396                 {
3397                         prs_grow(ps);
3398                         slprintf(tmp, sizeof(tmp) - 1, "rid[%02d]  ", i);
3399                         prs_uint32(tmp, ps, depth, &(r_u->rid[i]));
3400                 }
3401         }
3402
3403         prs_uint32("num_types1", ps, depth, &(r_u->num_types1));
3404         prs_uint32("ptr_types ", ps, depth, &(r_u->ptr_types ));
3405         prs_uint32("num_types2", ps, depth, &(r_u->num_types2));
3406
3407         if (r_u->ptr_types != 0 && r_u->num_types1 != 0)
3408         {
3409                 for (i = 0; i < r_u->num_types2; i++)
3410                 {
3411                         prs_grow(ps);
3412                         slprintf(tmp, sizeof(tmp) - 1, "type[%02d]  ", i);
3413                         prs_uint32(tmp, ps, depth, &(r_u->type[i]));
3414                 }
3415         }
3416
3417         prs_uint32("status", ps, depth, &(r_u->status));
3418 }
3419
3420
3421 /*******************************************************************
3422 reads or writes a structure.
3423 ********************************************************************/
3424 void make_samr_q_open_user(SAMR_Q_OPEN_USER *q_u,
3425                                 POLICY_HND *pol,
3426                                 uint32 unk_0, uint32 rid)
3427 {
3428         if (q_u == NULL) return;
3429
3430         DEBUG(5,("samr_make_samr_q_open_user\n"));
3431
3432         memcpy(&q_u->domain_pol, pol, sizeof(q_u->domain_pol));
3433         
3434         q_u->unknown_0 = unk_0;
3435         q_u->user_rid  = rid;
3436 }
3437
3438 /*******************************************************************
3439 reads or writes a structure.
3440 ********************************************************************/
3441 void samr_io_q_open_user(char *desc,  SAMR_Q_OPEN_USER *q_u, prs_struct *ps, int depth)
3442 {
3443         if (q_u == NULL) return;
3444
3445         prs_debug(ps, depth, desc, "samr_io_q_open_user");
3446         depth++;
3447
3448         prs_align(ps);
3449
3450         smb_io_pol_hnd("domain_pol", &(q_u->domain_pol), ps, depth); 
3451         prs_align(ps);
3452
3453         prs_uint32("unknown_0", ps, depth, &(q_u->unknown_0));
3454         prs_uint32("user_rid ", ps, depth, &(q_u->user_rid ));
3455
3456         prs_align(ps);
3457 }
3458
3459 /*******************************************************************
3460 reads or writes a structure.
3461 ********************************************************************/
3462 void samr_io_r_open_user(char *desc,  SAMR_R_OPEN_USER *r_u, prs_struct *ps, int depth)
3463 {
3464         if (r_u == NULL) return;
3465
3466         prs_debug(ps, depth, desc, "samr_io_r_open_user");
3467         depth++;
3468
3469         prs_align(ps);
3470
3471         smb_io_pol_hnd("user_pol", &(r_u->user_pol), ps, depth); 
3472         prs_align(ps);
3473
3474         prs_uint32("status", ps, depth, &(r_u->status));
3475 }
3476
3477 /*******************************************************************
3478 makes a SAMR_Q_QUERY_USERINFO structure.
3479 ********************************************************************/
3480 void make_samr_q_query_userinfo(SAMR_Q_QUERY_USERINFO *q_u,
3481                                 POLICY_HND *hnd, uint16 switch_value)
3482 {
3483         if (q_u == NULL || hnd == NULL) return;
3484
3485         DEBUG(5,("make_samr_q_query_userinfo\n"));
3486
3487         memcpy(&(q_u->pol), hnd, sizeof(q_u->pol));
3488         q_u->switch_value = switch_value;
3489 }
3490
3491
3492 /*******************************************************************
3493 reads or writes a structure.
3494 ********************************************************************/
3495 void samr_io_q_query_userinfo(char *desc,  SAMR_Q_QUERY_USERINFO *q_u, prs_struct *ps, int depth)
3496 {
3497         if (q_u == NULL) return;
3498
3499         prs_debug(ps, depth, desc, "samr_io_q_query_userinfo");
3500         depth++;
3501
3502         prs_align(ps);
3503
3504         smb_io_pol_hnd("pol", &(q_u->pol), ps, depth); 
3505         prs_align(ps);
3506
3507         prs_uint16("switch_value", ps, depth, &(q_u->switch_value)); /* 0x0015 or 0x0011 */
3508
3509         prs_align(ps);
3510 }
3511
3512 /*******************************************************************
3513 reads or writes a LOGON_HRS structure.
3514 ********************************************************************/
3515 static void sam_io_logon_hrs(char *desc,  LOGON_HRS *hrs, prs_struct *ps, int depth)
3516 {
3517         if (hrs == NULL) return;
3518
3519         prs_debug(ps, depth, desc, "sam_io_logon_hrs");
3520         depth++;
3521
3522         prs_align(ps);
3523         
3524         prs_uint32 (       "len  ", ps, depth, &(hrs->len ));
3525
3526         if (hrs->len > 64)
3527         {
3528                 DEBUG(5,("sam_io_logon_hrs: truncating length\n"));
3529                 hrs->len = 64;
3530         }
3531
3532         prs_uint8s (False, "hours", ps, depth, hrs->hours, hrs->len);
3533 }
3534
3535 /*******************************************************************
3536 makes a SAM_USER_INFO_10 structure.
3537 ********************************************************************/
3538 void make_sam_user_info10(SAM_USER_INFO_10 *usr,
3539                                 uint32 acb_info)
3540 {
3541         if (usr == NULL) return;
3542
3543         DEBUG(5,("make_sam_user_info10\n"));
3544
3545         usr->acb_info = acb_info;
3546 }
3547
3548 /*******************************************************************
3549 reads or writes a structure.
3550 ********************************************************************/
3551 void sam_io_user_info10(char *desc,  SAM_USER_INFO_10 *usr, prs_struct *ps, int depth)
3552 {
3553         if (usr == NULL) return;
3554
3555         prs_debug(ps, depth, desc, "samr_io_r_user_info10");
3556         depth++;
3557
3558         prs_align(ps);
3559
3560         prs_uint32("acb_info", ps, depth, &(usr->acb_info));
3561 }
3562
3563 /*******************************************************************
3564 makes a SAM_USER_INFO_11 structure.
3565 ********************************************************************/
3566 void make_sam_user_info11(SAM_USER_INFO_11 *usr,
3567                                 NTTIME *expiry,
3568                                 char *mach_acct,
3569                                 uint32 rid_user,
3570                                 uint32 rid_group,
3571                                 uint16 acct_ctrl)
3572                                 
3573 {
3574         int len_mach_acct;
3575         if (usr == NULL || expiry == NULL || mach_acct == NULL) return;
3576
3577         DEBUG(5,("make_sam_user_info11\n"));
3578
3579         len_mach_acct = strlen(mach_acct);
3580
3581         memcpy(&(usr->expiry),expiry, sizeof(usr->expiry)); /* expiry time or something? */
3582         bzero(usr->padding_1, sizeof(usr->padding_1)); /* 0 - padding 24 bytes */
3583
3584         make_uni_hdr(&(usr->hdr_mach_acct), len_mach_acct, len_mach_acct, 4);  /* unicode header for machine account */
3585         usr->padding_2 = 0;               /* 0 - padding 4 bytes */
3586
3587         usr->ptr_1        = 1;            /* pointer */
3588         bzero(usr->padding_3, sizeof(usr->padding_3)); /* 0 - padding 32 bytes */
3589         usr->padding_4    = 0;            /* 0 - padding 4 bytes */
3590
3591         usr->ptr_2        = 1;            /* pointer */
3592         usr->padding_5    = 0;            /* 0 - padding 4 bytes */
3593
3594         usr->ptr_3        = 1;          /* pointer */
3595         bzero(usr->padding_6, sizeof(usr->padding_6)); /* 0 - padding 32 bytes */
3596
3597         usr->rid_user     = rid_user; 
3598         usr->rid_group    = rid_group;
3599
3600         usr->acct_ctrl    = acct_ctrl;
3601         usr->unknown_3    = 0x0000;
3602
3603         usr->unknown_4    = 0x003f;       /* 0x003f      - 16 bit unknown */
3604         usr->unknown_5    = 0x003c;       /* 0x003c      - 16 bit unknown */
3605
3606         bzero(usr->padding_7, sizeof(usr->padding_7)); /* 0 - padding 16 bytes */
3607         usr->padding_8    = 0;            /* 0 - padding 4 bytes */
3608         
3609         make_unistr2(&(usr->uni_mach_acct), mach_acct, len_mach_acct);  /* unicode string for machine account */
3610 }
3611
3612 /*******************************************************************
3613 reads or writes a structure.
3614 ********************************************************************/
3615 void sam_io_user_info11(char *desc,  SAM_USER_INFO_11 *usr, prs_struct *ps, int depth)
3616 {
3617         if (usr == NULL) return;
3618
3619         prs_debug(ps, depth, desc, "samr_io_r_unknown_24");
3620         depth++;
3621
3622         prs_align(ps);
3623
3624         prs_uint8s (False, "padding_0", ps, depth, usr->padding_0, sizeof(usr->padding_0)); 
3625
3626         smb_io_time("time", &(usr->expiry), ps, depth); 
3627
3628         prs_uint8s (False, "padding_1", ps, depth, usr->padding_1, sizeof(usr->padding_1));
3629
3630         smb_io_unihdr ("unihdr", &(usr->hdr_mach_acct), ps, depth); 
3631         prs_uint32(        "padding_2", ps, depth, &(usr->padding_2));
3632
3633         prs_uint32(        "ptr_1    ", ps, depth, &(usr->ptr_1    ));
3634         prs_uint8s (False, "padding_3", ps, depth, usr->padding_3, sizeof(usr->padding_3));
3635         prs_uint32(        "padding_4", ps, depth, &(usr->padding_4));
3636
3637         prs_uint32(        "ptr_2    ", ps, depth, &(usr->ptr_2    ));
3638         prs_uint32(        "padding_5", ps, depth, &(usr->padding_5));
3639
3640         prs_uint32(        "ptr_3    ", ps, depth, &(usr->ptr_3    ));
3641         prs_uint8s (False, "padding_6", ps, depth, usr->padding_6, sizeof(usr->padding_6));
3642
3643         prs_uint32(        "rid_user ", ps, depth, &(usr->rid_user ));
3644         prs_uint32(        "rid_group", ps, depth, &(usr->rid_group));
3645         prs_uint16(        "acct_ctrl", ps, depth, &(usr->acct_ctrl));
3646         prs_uint16(        "unknown_3", ps, depth, &(usr->unknown_3));
3647         prs_uint16(        "unknown_4", ps, depth, &(usr->unknown_4));
3648         prs_uint16(        "unknown_5", ps, depth, &(usr->unknown_5));
3649
3650         prs_uint8s (False, "padding_7", ps, depth, usr->padding_7, sizeof(usr->padding_7));
3651         prs_uint32(        "padding_8", ps, depth, &(usr->padding_8));
3652         
3653         smb_io_unistr2("unistr2", &(usr->uni_mach_acct), True, ps, depth); 
3654         prs_align(ps);
3655
3656         prs_uint8s (False, "padding_9", ps, depth, usr->padding_9, sizeof(usr->padding_9));
3657 }
3658
3659 /*************************************************************************
3660  make_sam_user_info21
3661
3662  unknown_3 = 0x00ff ffff
3663  unknown_5 = 0x0002 0000
3664  unknown_6 = 0x0000 04ec 
3665
3666  *************************************************************************/
3667 void make_sam_user_info21(SAM_USER_INFO_21 *usr,
3668
3669         NTTIME *logon_time,
3670         NTTIME *logoff_time,
3671         NTTIME *kickoff_time,
3672         NTTIME *pass_last_set_time,
3673         NTTIME *pass_can_change_time,
3674         NTTIME *pass_must_change_time,
3675
3676         char *user_name,
3677         char *full_name,
3678         char *home_dir,
3679         char *dir_drive,
3680         char *logon_script,
3681         char *profile_path,
3682         char *description,
3683         char *workstations,
3684         char *unknown_str,
3685         char *munged_dial,
3686
3687         uint32 user_rid,
3688         uint32 group_rid,
3689         uint16 acb_info, 
3690
3691         uint32 unknown_3,
3692         uint16 logon_divs,
3693         LOGON_HRS *hrs,
3694         uint32 unknown_5,
3695         uint32 unknown_6)
3696 {
3697         int len_user_name    = user_name    != NULL ? strlen(user_name   ) : 0;
3698         int len_full_name    = full_name    != NULL ? strlen(full_name   ) : 0;
3699         int len_home_dir     = home_dir     != NULL ? strlen(home_dir    ) : 0;
3700         int len_dir_drive    = dir_drive    != NULL ? strlen(dir_drive   ) : 0;
3701         int len_logon_script = logon_script != NULL ? strlen(logon_script) : 0;
3702         int len_profile_path = profile_path != NULL ? strlen(profile_path) : 0;
3703         int len_description  = description  != NULL ? strlen(description ) : 0;
3704         int len_workstations = workstations != NULL ? strlen(workstations) : 0;
3705         int len_unknown_str  = unknown_str  != NULL ? strlen(unknown_str ) : 0;
3706         int len_munged_dial  = munged_dial  != NULL ? strlen(munged_dial ) : 0;
3707
3708         usr->logon_time            = *logon_time;
3709         usr->logoff_time           = *logoff_time;
3710         usr->kickoff_time          = *kickoff_time;
3711         usr->pass_last_set_time    = *pass_last_set_time;
3712         usr->pass_can_change_time  = *pass_can_change_time;
3713         usr->pass_must_change_time = *pass_must_change_time;
3714
3715         make_uni_hdr(&(usr->hdr_user_name   ), len_user_name   , len_user_name   , 1);
3716         make_uni_hdr(&(usr->hdr_full_name   ), len_full_name   , len_full_name   , 1);
3717         make_uni_hdr(&(usr->hdr_home_dir    ), len_home_dir    , len_home_dir    , 1);
3718         make_uni_hdr(&(usr->hdr_dir_drive   ), len_dir_drive   , len_dir_drive   , 1);
3719         make_uni_hdr(&(usr->hdr_logon_script), len_logon_script, len_logon_script, 1);
3720         make_uni_hdr(&(usr->hdr_profile_path), len_profile_path, len_profile_path, 1);
3721         make_uni_hdr(&(usr->hdr_acct_desc   ), len_description , len_description , 1);
3722         make_uni_hdr(&(usr->hdr_workstations), len_workstations, len_workstations, 1);
3723         make_uni_hdr(&(usr->hdr_unknown_str ), len_unknown_str , len_unknown_str , 1);
3724         make_uni_hdr(&(usr->hdr_munged_dial ), len_munged_dial , len_munged_dial , 1);
3725
3726         bzero(usr->nt_pwd, sizeof(usr->nt_pwd));
3727         bzero(usr->lm_pwd, sizeof(usr->lm_pwd));
3728
3729         usr->user_rid  = user_rid;
3730         usr->group_rid = group_rid;
3731         usr->acb_info = acb_info;
3732         usr->unknown_3 = unknown_3; /* 0x00ff ffff */
3733
3734         usr->logon_divs = logon_divs; /* should be 168 (hours/week) */
3735         usr->ptr_logon_hrs = hrs ? 1 : 0;
3736         usr->unknown_5 = unknown_5; /* 0x0002 0000 */
3737
3738         bzero(usr->padding1, sizeof(usr->padding1));
3739
3740         make_unistr2(&(usr->uni_user_name   ), user_name   , len_user_name   );
3741         make_unistr2(&(usr->uni_full_name   ), full_name   , len_full_name   );
3742         make_unistr2(&(usr->uni_home_dir    ), home_dir    , len_home_dir    );
3743         make_unistr2(&(usr->uni_dir_drive   ), dir_drive   , len_dir_drive   );
3744         make_unistr2(&(usr->uni_logon_script), logon_script, len_logon_script);
3745         make_unistr2(&(usr->uni_profile_path), profile_path, len_profile_path);
3746         make_unistr2(&(usr->uni_acct_desc ), description , len_description );
3747         make_unistr2(&(usr->uni_workstations), workstations, len_workstations);
3748         make_unistr2(&(usr->uni_unknown_str ), unknown_str , len_unknown_str );
3749         make_unistr2(&(usr->uni_munged_dial ), munged_dial , len_munged_dial );
3750
3751         usr->unknown_6 = unknown_6; /* 0x0000 04ec */
3752         usr->padding4 = 0;
3753
3754         if (hrs)
3755         {
3756                 memcpy(&(usr->logon_hrs), hrs, sizeof(usr->logon_hrs));
3757         }
3758         else
3759         {
3760                 memset(&(usr->logon_hrs), 0xff, sizeof(usr->logon_hrs));
3761         }
3762 }
3763
3764
3765 /*******************************************************************
3766 reads or writes a structure.
3767 ********************************************************************/
3768 static void sam_io_user_info21(char *desc,  SAM_USER_INFO_21 *usr, prs_struct *ps, int depth)
3769 {
3770         if (usr == NULL) return;
3771
3772         prs_debug(ps, depth, desc, "lsa_io_user_info");
3773         depth++;
3774
3775         prs_align(ps);
3776         
3777         smb_io_time("logon_time           ", &(usr->logon_time)           , ps, depth);
3778         smb_io_time("logoff_time          ", &(usr->logoff_time)          , ps, depth); 
3779         smb_io_time("kickoff_time         ", &(usr->kickoff_time)         , ps, depth); 
3780         smb_io_time("pass_last_set_time   ", &(usr->pass_last_set_time)   , ps, depth); 
3781         smb_io_time("pass_can_change_time ", &(usr->pass_can_change_time) , ps, depth); 
3782         smb_io_time("pass_must_change_time", &(usr->pass_must_change_time), ps, depth); 
3783
3784         smb_io_unihdr("hdr_user_name   ", &(usr->hdr_user_name)   , ps, depth); /* username unicode string header */
3785         smb_io_unihdr("hdr_full_name   ", &(usr->hdr_full_name)   , ps, depth); /* user's full name unicode string header */
3786         smb_io_unihdr("hdr_home_dir    ", &(usr->hdr_home_dir)    , ps, depth); /* home directory unicode string header */
3787         smb_io_unihdr("hdr_dir_drive   ", &(usr->hdr_dir_drive)   , ps, depth); /* home directory drive */
3788         smb_io_unihdr("hdr_logon_script", &(usr->hdr_logon_script), ps, depth); /* logon script unicode string header */
3789         smb_io_unihdr("hdr_profile_path", &(usr->hdr_profile_path), ps, depth); /* profile path unicode string header */
3790         smb_io_unihdr("hdr_acct_desc   ", &(usr->hdr_acct_desc  ) , ps, depth); /* account description */
3791         smb_io_unihdr("hdr_workstations", &(usr->hdr_workstations), ps, depth); /* workstations user can log on from */
3792         smb_io_unihdr("hdr_unknown_str ", &(usr->hdr_unknown_str ), ps, depth); /* unknown string */
3793         smb_io_unihdr("hdr_munged_dial ", &(usr->hdr_munged_dial ), ps, depth); /* workstations user can log on from */
3794
3795         prs_uint8s (False, "lm_pwd        ", ps, depth, usr->lm_pwd   , sizeof(usr->lm_pwd   ));
3796         prs_uint8s (False, "nt_pwd        ", ps, depth, usr->nt_pwd   , sizeof(usr->nt_pwd   ));
3797
3798         prs_uint32("user_rid      ", ps, depth, &(usr->user_rid     ));       /* User ID */
3799         prs_uint32("group_rid     ", ps, depth, &(usr->group_rid    ));      /* Group ID */
3800         prs_uint16("acb_info      ", ps, depth, &(usr->acb_info     ));      /* Group ID */
3801         prs_align(ps);
3802
3803         prs_uint32("unknown_3     ", ps, depth, &(usr->unknown_3    ));
3804         prs_uint16("logon_divs    ", ps, depth, &(usr->logon_divs   ));     /* logon divisions per week */
3805         prs_align(ps);
3806         prs_uint32("ptr_logon_hrs ", ps, depth, &(usr->ptr_logon_hrs));
3807         prs_uint32("unknown_5     ", ps, depth, &(usr->unknown_5    ));
3808
3809         prs_uint8s (False, "padding1      ", ps, depth, usr->padding1, sizeof(usr->padding1));
3810
3811         /* here begins pointed-to data */
3812
3813         smb_io_unistr2("uni_user_name   ", &(usr->uni_user_name)   , usr->hdr_user_name   .buffer, ps, depth); /* username unicode string */
3814         smb_io_unistr2("uni_full_name   ", &(usr->uni_full_name)   , usr->hdr_full_name   .buffer, ps, depth); /* user's full name unicode string */
3815         smb_io_unistr2("uni_home_dir    ", &(usr->uni_home_dir)    , usr->hdr_home_dir    .buffer, ps, depth); /* home directory unicode string */
3816         smb_io_unistr2("uni_dir_drive   ", &(usr->uni_dir_drive)   , usr->hdr_dir_drive   .buffer, ps, depth); /* home directory drive unicode string */
3817         smb_io_unistr2("uni_logon_script", &(usr->uni_logon_script), usr->hdr_logon_script.buffer, ps, depth); /* logon script unicode string */
3818         smb_io_unistr2("uni_profile_path", &(usr->uni_profile_path), usr->hdr_profile_path.buffer, ps, depth); /* profile path unicode string */
3819         smb_io_unistr2("uni_acct_desc   ", &(usr->uni_acct_desc   ), usr->hdr_acct_desc   .buffer, ps, depth); /* user description unicode string */
3820         smb_io_unistr2("uni_workstations", &(usr->uni_workstations), usr->hdr_workstations.buffer, ps, depth); /* worksations user can log on from */
3821         smb_io_unistr2("uni_unknown_str ", &(usr->uni_unknown_str ), usr->hdr_unknown_str .buffer, ps, depth); /* unknown string */
3822         smb_io_unistr2("uni_munged_dial ", &(usr->uni_munged_dial ), usr->hdr_munged_dial .buffer, ps, depth); /* worksations user can log on from */
3823
3824         prs_uint32("unknown_6     ", ps, depth, &(usr->unknown_6  ));
3825         prs_uint32("padding4      ", ps, depth, &(usr->padding4   ));
3826
3827         if (usr->ptr_logon_hrs)
3828         {
3829                 sam_io_logon_hrs("logon_hrs", &(usr->logon_hrs)   , ps, depth);
3830                 prs_align(ps);
3831         }
3832 }
3833
3834
3835 /*******************************************************************
3836 makes a SAMR_R_QUERY_USERINFO structure.
3837 ********************************************************************/
3838 void make_samr_r_query_userinfo(SAMR_R_QUERY_USERINFO *r_u,
3839                                 uint16 switch_value, void *info, uint32 status)
3840                                 
3841 {
3842         if (r_u == NULL || info == NULL) return;
3843
3844         DEBUG(5,("make_samr_r_query_userinfo\n"));
3845
3846         r_u->ptr = 0;
3847         r_u->switch_value = 0;
3848
3849         if (status == 0)
3850         {
3851                 r_u->switch_value = switch_value;
3852
3853                 switch (switch_value)
3854                 {
3855                         case 0x10:
3856                         {
3857                                 r_u->ptr = 1;
3858                                 r_u->info.id10 = (SAM_USER_INFO_10*)info;
3859
3860                                 break;
3861                         }
3862
3863                         case 0x11:
3864                         {
3865                                 r_u->ptr = 1;
3866                                 r_u->info.id11 = (SAM_USER_INFO_11*)info;
3867
3868                                 break;
3869                         }
3870
3871                         case 21:
3872                         {
3873                                 r_u->ptr = 1;
3874                                 r_u->info.id21 = (SAM_USER_INFO_21*)info;
3875
3876                                 break;
3877                         }
3878
3879                         default:
3880                         {
3881                                 DEBUG(4,("make_samr_r_query_userinfo: unsupported switch level\n"));
3882                                 break;
3883                         }
3884                 }
3885         }
3886
3887         r_u->status = status;         /* return status */
3888 }
3889
3890 /*******************************************************************
3891 reads or writes a structure.
3892 ********************************************************************/
3893 void samr_io_r_query_userinfo(char *desc,  SAMR_R_QUERY_USERINFO *r_u, prs_struct *ps, int depth)
3894 {
3895         if (r_u == NULL) return;
3896
3897         prs_debug(ps, depth, desc, "samr_io_r_query_userinfo");
3898         depth++;
3899
3900         prs_align(ps);
3901
3902         prs_uint32("ptr         ", ps, depth, &(r_u->ptr         ));
3903         prs_uint16("switch_value", ps, depth, &(r_u->switch_value));
3904         prs_align(ps);
3905
3906         if (r_u->ptr != 0 && r_u->switch_value != 0)
3907         {
3908                 switch (r_u->switch_value)
3909                 {
3910                         case 0x10:
3911                         {
3912                                 if (r_u->info.id10 != NULL)
3913                                 {
3914                                         sam_io_user_info10("", r_u->info.id10, ps, depth);
3915                                 }
3916                                 else
3917                                 {
3918                                         DEBUG(2,("samr_io_r_query_userinfo: info pointer not initialised\n"));
3919                                         return;
3920                                 }
3921                                 break;
3922                         }
3923 /*
3924                         case 0x11:
3925                         {
3926                                 if (r_u->info.id11 != NULL)
3927                                 {
3928                                         sam_io_user_info11("", r_u->info.id11, ps, depth);
3929                                 }
3930                                 else
3931                                 {
3932                                         DEBUG(2,("samr_io_r_query_userinfo: info pointer not initialised\n"));
3933                                         return;
3934                                 }
3935                                 break;
3936                         }
3937 */
3938                         case 21:
3939                         {
3940                                 if (r_u->info.id21 != NULL)
3941                                 {
3942                                         sam_io_user_info21("", r_u->info.id21, ps, depth);
3943                                 }
3944                                 else
3945                                 {
3946                                         DEBUG(2,("samr_io_r_query_userinfo: info pointer not initialised\n"));
3947                                         return;
3948                                 }
3949                                 break;
3950                         }
3951                         default:
3952                         {
3953                                 DEBUG(2,("samr_io_r_query_userinfo: unknown switch level\n"));
3954                                 break;
3955                         }
3956                                 
3957                 }
3958         }
3959
3960         prs_uint32("status", ps, depth, &(r_u->status));
3961 }
3962
3963 /*******************************************************************
3964 reads or writes a structure.
3965 ********************************************************************/
3966 void samr_io_q_unknown_32(char *desc,  SAMR_Q_UNKNOWN_32 *q_u, prs_struct *ps, int depth)
3967 {
3968         if (q_u == NULL) return;
3969
3970         prs_debug(ps, depth, desc, "samr_io_q_unknown_32");
3971         depth++;
3972
3973         prs_align(ps);
3974
3975         smb_io_pol_hnd("pol", &(q_u->pol), ps, depth); 
3976         prs_align(ps);
3977
3978         smb_io_unihdr ("", &(q_u->hdr_mach_acct), ps, depth); 
3979         smb_io_unistr2("", &(q_u->uni_mach_acct), q_u->hdr_mach_acct.buffer, ps, depth); 
3980
3981         prs_align(ps);
3982
3983         prs_uint32("acct_ctrl", ps, depth, &(q_u->acct_ctrl));
3984         prs_uint16("unknown_1", ps, depth, &(q_u->unknown_1));
3985         prs_uint16("unknown_2", ps, depth, &(q_u->unknown_2));
3986 }
3987
3988 /*******************************************************************
3989 reads or writes a structure.
3990 ********************************************************************/
3991 void samr_io_r_unknown_32(char *desc,  SAMR_R_UNKNOWN_32 *r_u, prs_struct *ps, int depth)
3992 {
3993         if (r_u == NULL) return;
3994
3995         prs_debug(ps, depth, desc, "samr_io_r_unknown_32");
3996         depth++;
3997
3998         prs_align(ps);
3999
4000         smb_io_pol_hnd("pol", &(r_u->pol), ps, depth); 
4001         prs_align(ps);
4002
4003         prs_uint32("status", ps, depth, &(r_u->status));
4004 }
4005
4006
4007 /*******************************************************************
4008 makes a SAMR_Q_CONNECT structure.
4009 ********************************************************************/
4010 void make_samr_q_connect(SAMR_Q_CONNECT *q_u,
4011                                 char *srv_name, uint32 unknown_0)
4012 {
4013         int len_srv_name = strlen(srv_name);
4014
4015         if (q_u == NULL) return;
4016
4017         DEBUG(5,("make_samr_q_connect\n"));
4018
4019         /* make PDC server name \\server */
4020         q_u->ptr_srv_name = len_srv_name > 0 ? 1 : 0; 
4021         make_unistr2(&(q_u->uni_srv_name), srv_name, len_srv_name+1);  
4022
4023         /* example values: 0x0000 0002 */
4024         q_u->unknown_0 = unknown_0; 
4025 }
4026
4027
4028 /*******************************************************************
4029 reads or writes a structure.
4030 ********************************************************************/
4031 void samr_io_q_connect(char *desc,  SAMR_Q_CONNECT *q_u, prs_struct *ps, int depth)
4032 {
4033         if (q_u == NULL) return;
4034
4035         prs_debug(ps, depth, desc, "samr_io_q_connect");
4036         depth++;
4037
4038         prs_align(ps);
4039
4040         prs_uint32("ptr_srv_name", ps, depth, &(q_u->ptr_srv_name));
4041         smb_io_unistr2("", &(q_u->uni_srv_name), q_u->ptr_srv_name, ps, depth); 
4042
4043         prs_align(ps);
4044
4045         prs_uint32("unknown_0   ", ps, depth, &(q_u->unknown_0   ));
4046 }
4047
4048 /*******************************************************************
4049 reads or writes a structure.
4050 ********************************************************************/
4051 void samr_io_r_connect(char *desc,  SAMR_R_CONNECT *r_u, prs_struct *ps, int depth)
4052 {
4053         if (r_u == NULL) return;
4054
4055         prs_debug(ps, depth, desc, "samr_io_r_connect");
4056         depth++;
4057
4058         prs_align(ps);
4059
4060         smb_io_pol_hnd("connect_pol", &(r_u->connect_pol), ps, depth); 
4061         prs_align(ps);
4062
4063         prs_uint32("status", ps, depth, &(r_u->status));
4064 }
4065
4066 /*******************************************************************
4067 makes a SAMR_Q_CONNECT_ANON structure.
4068 ********************************************************************/
4069 void make_samr_q_connect_anon(SAMR_Q_CONNECT_ANON *q_u)
4070 {
4071         if (q_u == NULL) return;
4072
4073         DEBUG(5,("make_samr_q_connect_anon\n"));
4074
4075         q_u->ptr       = 1;
4076         q_u->unknown_0 = 0x5c; /* server name (?!!) */
4077         q_u->unknown_1 = 0x01;
4078         q_u->unknown_2 = 0x20;
4079 }
4080
4081
4082 /*******************************************************************
4083 reads or writes a structure.
4084 ********************************************************************/
4085 void samr_io_q_connect_anon(char *desc,  SAMR_Q_CONNECT_ANON *q_u, prs_struct *ps, int depth)
4086 {
4087         if (q_u == NULL) return;
4088
4089         prs_debug(ps, depth, desc, "samr_io_q_connect_anon");
4090         depth++;
4091
4092         prs_align(ps);
4093
4094         prs_uint32("ptr      ", ps, depth, &(q_u->ptr      ));
4095         prs_uint16("unknown_0", ps, depth, &(q_u->unknown_0));
4096         prs_uint16("unknown_1", ps, depth, &(q_u->unknown_1));
4097         prs_uint32("unknown_2", ps, depth, &(q_u->unknown_2));
4098 }
4099
4100 /*******************************************************************
4101 reads or writes a structure.
4102 ********************************************************************/
4103 void samr_io_r_connect_anon(char *desc,  SAMR_R_CONNECT_ANON *r_u, prs_struct *ps, int depth)
4104 {
4105         if (r_u == NULL) return;
4106
4107         prs_debug(ps, depth, desc, "samr_io_r_connect_anon");
4108         depth++;
4109
4110         prs_align(ps);
4111
4112         smb_io_pol_hnd("connect_pol", &(r_u->connect_pol), ps, depth); 
4113         prs_align(ps);
4114
4115         prs_uint32("status", ps, depth, &(r_u->status));
4116 }
4117
4118 /*******************************************************************
4119 makes a SAMR_Q_UNKNOWN_38 structure.
4120 ********************************************************************/
4121 void make_samr_q_unknown_38(SAMR_Q_UNKNOWN_38 *q_u, char *srv_name)
4122 {
4123         int len_srv_name = strlen(srv_name);
4124
4125         if (q_u == NULL) return;
4126
4127         DEBUG(5,("make_samr_q_unknown_38\n"));
4128
4129         q_u->ptr = 1;
4130         make_uni_hdr(&(q_u->hdr_srv_name), len_srv_name, len_srv_name, len_srv_name != 0);
4131         make_unistr2(&(q_u->uni_srv_name), srv_name, len_srv_name);  
4132
4133 }
4134
4135 /*******************************************************************
4136 reads or writes a structure.
4137 ********************************************************************/
4138 void samr_io_q_unknown_38(char *desc,  SAMR_Q_UNKNOWN_38 *q_u, prs_struct *ps, int depth)
4139 {
4140         if (q_u == NULL) return;
4141
4142         prs_debug(ps, depth, desc, "samr_io_q_unknown_38");
4143         depth++;
4144
4145         prs_align(ps);
4146
4147         prs_uint32("ptr", ps, depth, &(q_u->ptr));
4148         if (q_u->ptr != 0)
4149         {
4150                 smb_io_unihdr ("", &(q_u->hdr_srv_name), ps, depth); 
4151                 smb_io_unistr2("", &(q_u->uni_srv_name), q_u->hdr_srv_name.buffer, ps, depth); 
4152         }
4153 }
4154
4155 /*******************************************************************
4156 makes a SAMR_R_UNKNOWN_38 structure.
4157 ********************************************************************/
4158 void make_samr_r_unknown_38(SAMR_R_UNKNOWN_38 *r_u)
4159 {
4160         if (r_u == NULL) return;
4161
4162         DEBUG(5,("make_r_unknown_38\n"));
4163
4164         r_u->unk_0 = 0;
4165         r_u->unk_1 = 0;
4166         r_u->unk_2 = 0;
4167         r_u->unk_3 = 0;
4168 }
4169
4170 /*******************************************************************
4171 reads or writes a structure.
4172 ********************************************************************/
4173 void samr_io_r_unknown_38(char *desc,  SAMR_R_UNKNOWN_38 *r_u, prs_struct *ps, int depth)
4174 {
4175         if (r_u == NULL) return;
4176
4177         prs_debug(ps, depth, desc, "samr_io_r_unknown_38");
4178         depth++;
4179
4180         prs_align(ps);
4181
4182         prs_uint16("unk_0", ps, depth, &(r_u->unk_0));
4183         prs_align(ps);
4184         prs_uint16("unk_1", ps, depth, &(r_u->unk_1));
4185         prs_align(ps);
4186         prs_uint16("unk_2", ps, depth, &(r_u->unk_2));
4187         prs_align(ps);
4188         prs_uint16("unk_3", ps, depth, &(r_u->unk_3));
4189         prs_align(ps);
4190 }
4191
4192 /*******************************************************************
4193 make a SAMR_ENC_PASSWD structure.
4194 ********************************************************************/
4195 void make_enc_passwd(SAMR_ENC_PASSWD *pwd, char pass[512])
4196 {
4197         if (pwd == NULL) return;
4198
4199         pwd->ptr = 1;
4200         memcpy(pwd->pass, pass, sizeof(pwd->pass)); 
4201 }
4202
4203 /*******************************************************************
4204 reads or writes a SAMR_ENC_PASSWD structure.
4205 ********************************************************************/
4206 void samr_io_enc_passwd(char *desc, SAMR_ENC_PASSWD *pwd, prs_struct *ps, int depth)