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