added rid and sid_name_use to DOMAIN_GRP_MEMBER, for use in group member
[samba.git] / source3 / rpc_parse / parse_samr.c
1 /* 
2  *  Unix SMB/Netbios implementation.
3  *  Version 1.9.
4  *  RPC Pipe client / server routines
5  *  Copyright (C) Andrew Tridgell              1992-1997,
6  *  Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
7  *  Copyright (C) Paul Ashton                       1997.
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 rid,
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->rid = rid;
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("rid", ps, depth, &(q_u->rid));
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                 uint16 total_num_entries, uint16 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->total_num_entries = total_num_entries;
873         r_u->unknown_0         = unk_0;
874
875         if (total_num_entries > 0)
876         {
877                 r_u->ptr_entries1 = 1;
878                 r_u->ptr_entries2 = 1;
879                 r_u->num_entries2 = num_sam_entries;
880                 r_u->num_entries3 = num_sam_entries;
881
882                 SMB_ASSERT_ARRAY(r_u->sam, num_sam_entries);
883                 SMB_ASSERT_ARRAY(r_u->uni_acct_name, num_sam_entries);
884
885                 for (i = 0; i < num_sam_entries; i++)
886                 {
887                         make_sam_entry(&(r_u->sam[i]),
888                                        pass[i].uni_user_name.uni_str_len,
889                                        pass[i].user_rid);
890
891                         copy_unistr2(&(r_u->uni_acct_name[i]), &(pass[i].uni_user_name));
892                 }
893
894                 r_u->num_entries4 = num_sam_entries;
895         }
896         else
897         {
898                 r_u->ptr_entries1 = 0;
899                 r_u->num_entries2 = num_sam_entries;
900                 r_u->ptr_entries2 = 1;
901         }
902
903         r_u->status = status;
904 }
905
906 /*******************************************************************
907 reads or writes a structure.
908 ********************************************************************/
909 void samr_io_r_enum_dom_users(char *desc,  SAMR_R_ENUM_DOM_USERS *r_u, prs_struct *ps, int depth)
910 {
911         int i;
912
913         if (r_u == NULL) return;
914
915         prs_debug(ps, depth, desc, "samr_io_r_enum_dom_users");
916         depth++;
917
918         prs_align(ps);
919
920         prs_uint16("total_num_entries", ps, depth, &(r_u->total_num_entries));
921         prs_uint16("unknown_0        ", ps, depth, &(r_u->unknown_0        ));
922         prs_uint32("ptr_entries1", ps, depth, &(r_u->ptr_entries1));
923
924         if (r_u->total_num_entries != 0 && r_u->ptr_entries1 != 0)
925         {
926                 prs_uint32("num_entries2", ps, depth, &(r_u->num_entries2));
927                 prs_uint32("ptr_entries2", ps, depth, &(r_u->ptr_entries2));
928                 prs_uint32("num_entries3", ps, depth, &(r_u->num_entries3));
929
930                 SMB_ASSERT_ARRAY(r_u->sam, r_u->num_entries2);
931
932                 for (i = 0; i < r_u->num_entries2; i++)
933                 {
934                         prs_grow(ps);
935                         sam_io_sam_entry("", &(r_u->sam[i]), ps, depth);
936                 }
937
938                 SMB_ASSERT_ARRAY(r_u->uni_acct_name, r_u->num_entries2);
939
940                 for (i = 0; i < r_u->num_entries2; i++)
941                 {
942                         prs_grow(ps);
943                         smb_io_unistr2("", &(r_u->uni_acct_name[i]), r_u->sam[i].hdr_name.buffer, ps, depth);
944                 }
945
946                 prs_align(ps);
947
948                 prs_uint32("num_entries4", ps, depth, &(r_u->num_entries4));
949         }
950
951         prs_uint32("status", ps, depth, &(r_u->status));
952 }
953
954 /*******************************************************************
955 makes a SAMR_Q_QUERY_DISPINFO structure.
956 ********************************************************************/
957 void make_samr_q_query_dispinfo(SAMR_Q_QUERY_DISPINFO *q_e, POLICY_HND *pol,
958                                 uint16 switch_level, uint32 start_idx, uint32 size)
959 {
960         if (q_e == NULL || pol == NULL) return;
961
962         DEBUG(5,("make_samr_q_query_dispinfo\n"));
963
964         memcpy(&(q_e->pol), pol, sizeof(*pol));
965
966         q_e->switch_level = switch_level;
967
968         q_e->unknown_0 = 0;
969         q_e->start_idx = start_idx;
970         q_e->unknown_1 = 0x000007d0;
971         q_e->max_size  = size;
972 }
973
974 /*******************************************************************
975 reads or writes a structure.
976 ********************************************************************/
977 void samr_io_q_query_dispinfo(char *desc,  SAMR_Q_QUERY_DISPINFO *q_e, prs_struct *ps, int depth)
978 {
979         if (q_e == NULL) return;
980
981         prs_debug(ps, depth, desc, "samr_io_q_query_dispinfo");
982         depth++;
983
984         prs_align(ps);
985
986         smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); 
987         prs_align(ps);
988
989         prs_uint16("switch_level", ps, depth, &(q_e->switch_level));
990         prs_uint16("unknown_0   ", ps, depth, &(q_e->unknown_0   ));
991         prs_uint32("start_idx   ", ps, depth, &(q_e->start_idx   ));
992         prs_uint32("unknown_1   ", ps, depth, &(q_e->unknown_1   ));
993         prs_uint32("max_size    ", ps, depth, &(q_e->max_size    ));
994
995         prs_align(ps);
996 }
997
998
999 /*******************************************************************
1000 makes a SAM_INFO_2 structure.
1001 ********************************************************************/
1002 void make_sam_info_2(SAM_INFO_2 *sam, uint32 acb_mask,
1003                 uint32 start_idx, uint32 num_sam_entries,
1004                 SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES])
1005 {
1006         int i;
1007         int entries_added;
1008
1009         if (sam == NULL) return;
1010
1011         DEBUG(5,("make_sam_info_2\n"));
1012
1013         if (num_sam_entries >= MAX_SAM_ENTRIES)
1014         {
1015                 num_sam_entries = MAX_SAM_ENTRIES;
1016                 DEBUG(5,("limiting number of entries to %d\n", 
1017                          num_sam_entries));
1018         }
1019
1020         for (i = start_idx, entries_added = 0; i < num_sam_entries; i++)
1021         {
1022                 if (IS_BITS_SET_ALL(pass[i].acb_info, acb_mask))
1023                 {
1024                         make_sam_entry2(&(sam->sam[entries_added]),
1025                                         start_idx + entries_added + 1,
1026                                         pass[i].uni_user_name.uni_str_len,
1027                                         pass[i].uni_acct_desc.uni_str_len,
1028                                         pass[i].user_rid,
1029                                         pass[i].acb_info);
1030
1031                         copy_unistr2(&(sam->str[entries_added].uni_srv_name), &(pass[i].uni_user_name));
1032                         copy_unistr2(&(sam->str[entries_added].uni_srv_desc), &(pass[i].uni_acct_desc));
1033
1034                         entries_added++;
1035                 }
1036
1037                 sam->num_entries   = entries_added;
1038                 sam->ptr_entries   = 1;
1039                 sam->num_entries2  = entries_added;
1040         }
1041 }
1042
1043 /*******************************************************************
1044 reads or writes a structure.
1045 ********************************************************************/
1046 static void sam_io_sam_info_2(char *desc,  SAM_INFO_2 *sam, prs_struct *ps, int depth)
1047 {
1048         int i;
1049
1050         if (sam == NULL) return;
1051
1052         prs_debug(ps, depth, desc, "sam_io_sam_info_2");
1053         depth++;
1054
1055         prs_align(ps);
1056
1057         prs_uint32("num_entries  ", ps, depth, &(sam->num_entries  ));
1058         prs_uint32("ptr_entries  ", ps, depth, &(sam->ptr_entries  ));
1059
1060         prs_uint32("num_entries2 ", ps, depth, &(sam->num_entries2 ));
1061
1062         SMB_ASSERT_ARRAY(sam->sam, sam->num_entries);
1063
1064         for (i = 0; i < sam->num_entries; i++)
1065         {
1066                 prs_grow(ps);
1067                 sam_io_sam_entry2("", &(sam->sam[i]), ps, depth);
1068         }
1069
1070         for (i = 0; i < sam->num_entries; i++)
1071         {
1072                 prs_grow(ps);
1073                 sam_io_sam_str2 ("", &(sam->str[i]),
1074                                                          sam->sam[i].hdr_srv_name.buffer,
1075                                                          sam->sam[i].hdr_srv_desc.buffer,
1076                                                          ps, depth);
1077         }
1078 }
1079
1080
1081 /*******************************************************************
1082 makes a SAM_INFO_1 structure.
1083 ********************************************************************/
1084 void make_sam_info_1(SAM_INFO_1 *sam, uint32 acb_mask,
1085                 uint32 start_idx, uint32 num_sam_entries,
1086                 SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES])
1087 {
1088         int i;
1089         int entries_added;
1090
1091         if (sam == NULL) return;
1092
1093         DEBUG(5,("make_sam_info_1\n"));
1094
1095         if (num_sam_entries >= MAX_SAM_ENTRIES)
1096         {
1097                 num_sam_entries = MAX_SAM_ENTRIES;
1098                 DEBUG(5,("limiting number of entries to %d\n", 
1099                          num_sam_entries));
1100         }
1101
1102         for (i = start_idx, entries_added = 0; i < num_sam_entries; i++)
1103         {
1104                 if (IS_BITS_SET_ALL(pass[i].acb_info, acb_mask))
1105                 {
1106                         make_sam_entry1(&(sam->sam[entries_added]),
1107                                                 start_idx + entries_added + 1,
1108                                                 pass[i].uni_user_name.uni_str_len,
1109                                                 pass[i].uni_full_name.uni_str_len, 
1110                                                 pass[i].uni_acct_desc.uni_str_len,
1111                                                 pass[i].user_rid,
1112                                                 pass[i].acb_info);
1113
1114                         copy_unistr2(&(sam->str[entries_added].uni_acct_name), &(pass[i].uni_user_name));
1115                         copy_unistr2(&(sam->str[entries_added].uni_full_name), &(pass[i].uni_full_name));
1116                         copy_unistr2(&(sam->str[entries_added].uni_acct_desc), &(pass[i].uni_acct_desc));
1117
1118                         entries_added++;
1119                 }
1120         }
1121
1122         sam->num_entries   = entries_added;
1123         sam->ptr_entries   = 1;
1124         sam->num_entries2  = entries_added;
1125 }
1126
1127
1128 /*******************************************************************
1129 reads or writes a structure.
1130 ********************************************************************/
1131 static void sam_io_sam_info_1(char *desc,  SAM_INFO_1 *sam, prs_struct *ps, int depth)
1132 {
1133         int i;
1134
1135         if (sam == NULL) return;
1136
1137         prs_debug(ps, depth, desc, "sam_io_sam_info_1");
1138         depth++;
1139
1140         prs_align(ps);
1141
1142         prs_uint32("num_entries  ", ps, depth, &(sam->num_entries  ));
1143         prs_uint32("ptr_entries  ", ps, depth, &(sam->ptr_entries  ));
1144
1145         prs_uint32("num_entries2 ", ps, depth, &(sam->num_entries2 ));
1146
1147         SMB_ASSERT_ARRAY(sam->sam, sam->num_entries);
1148
1149         for (i = 0; i < sam->num_entries; i++)
1150         {
1151                 prs_grow(ps);
1152                 sam_io_sam_entry1("", &(sam->sam[i]), ps, depth);
1153         }
1154
1155         for (i = 0; i < sam->num_entries; i++)
1156         {
1157                 prs_grow(ps);
1158                 sam_io_sam_str1 ("", &(sam->str[i]),
1159                                                          sam->sam[i].hdr_acct_name.buffer,
1160                                                          sam->sam[i].hdr_user_name.buffer,
1161                                                          sam->sam[i].hdr_user_desc.buffer,
1162                                                          ps, depth);
1163         }
1164 }
1165
1166
1167 /*******************************************************************
1168 makes a SAMR_R_QUERY_DISPINFO structure.
1169 ********************************************************************/
1170 void make_samr_r_query_dispinfo(SAMR_R_QUERY_DISPINFO *r_u,
1171                 uint16 switch_level, SAM_INFO_CTR *ctr, uint32 status)
1172 {
1173         if (r_u == NULL) return;
1174
1175         DEBUG(5,("make_samr_r_query_dispinfo\n"));
1176
1177         if (status == 0x0)
1178         {
1179                 r_u->unknown_0 = 0x0000001;
1180                 r_u->unknown_1 = 0x0000001;
1181         }
1182         else
1183         {
1184                 r_u->unknown_0 = 0x0;
1185                 r_u->unknown_1 = 0x0;
1186         }
1187
1188         r_u->switch_level = switch_level;
1189         r_u->ctr = ctr;
1190         r_u->status = status;
1191 }
1192
1193
1194 /*******************************************************************
1195 reads or writes a structure.
1196 ********************************************************************/
1197 void samr_io_r_query_dispinfo(char *desc,  SAMR_R_QUERY_DISPINFO *r_u, prs_struct *ps, int depth)
1198 {
1199         if (r_u == NULL) return;
1200
1201         prs_debug(ps, depth, desc, "samr_io_r_query_dispinfo");
1202         depth++;
1203
1204         prs_align(ps);
1205
1206         prs_uint32("unknown_0    ", ps, depth, &(r_u->unknown_0    ));
1207         prs_uint32("unknown_1    ", ps, depth, &(r_u->unknown_1    ));
1208         prs_uint16("switch_level ", ps, depth, &(r_u->switch_level ));
1209
1210         prs_align(ps);
1211
1212         switch (r_u->switch_level)
1213         {
1214                 case 0x1:
1215                 {
1216                         sam_io_sam_info_1("users", r_u->ctr->sam.info1, ps, depth);
1217                         break;
1218                 }
1219                 case 0x2:
1220                 {
1221                         sam_io_sam_info_2("servers", r_u->ctr->sam.info2, ps, depth);
1222                         break;
1223                 }
1224                 default:
1225                 {
1226                         DEBUG(5,("samr_io_r_query_dispinfo: unknown switch value\n"));
1227                         break;
1228                 }
1229         }
1230
1231         prs_uint32("status", ps, depth, &(r_u->status));
1232 }
1233
1234
1235 /*******************************************************************
1236 makes a SAMR_Q_OPEN_GROUP structure.
1237 ********************************************************************/
1238 void make_samr_q_open_group(SAMR_Q_OPEN_GROUP *q_c,
1239                                 POLICY_HND *hnd, uint32 unk, uint32 rid)
1240 {
1241         if (q_c == NULL || hnd == NULL) return;
1242
1243         DEBUG(5,("make_samr_q_open_group\n"));
1244
1245         memcpy(&(q_c->domain_pol), hnd, sizeof(q_c->domain_pol));
1246         q_c->unknown = unk;
1247         q_c->rid_group = rid;
1248 }
1249
1250 /*******************************************************************
1251 reads or writes a structure.
1252 ********************************************************************/
1253 void samr_io_q_open_group(char *desc,  SAMR_Q_OPEN_GROUP *q_u, prs_struct *ps, int depth)
1254 {
1255         if (q_u == NULL) return;
1256
1257         prs_debug(ps, depth, desc, "samr_io_q_open_group");
1258         depth++;
1259
1260         prs_align(ps);
1261
1262         smb_io_pol_hnd("domain_pol", &(q_u->domain_pol), ps, depth); 
1263
1264         prs_uint32("unknown  ", ps, depth, &(q_u->unknown  ));
1265         prs_uint32("rid_group", ps, depth, &(q_u->rid_group));
1266 }
1267
1268 /*******************************************************************
1269 reads or writes a structure.
1270 ********************************************************************/
1271 void samr_io_r_open_group(char *desc,  SAMR_R_OPEN_GROUP *r_u, prs_struct *ps, int depth)
1272 {
1273         if (r_u == NULL) return;
1274
1275         prs_debug(ps, depth, desc, "samr_io_r_open_group");
1276         depth++;
1277
1278         prs_align(ps);
1279
1280         smb_io_pol_hnd("pol", &(r_u->pol), ps, depth); 
1281         prs_align(ps);
1282
1283         prs_uint32("status", ps, depth, &(r_u->status));
1284 }
1285
1286
1287 #if 0
1288 /* SAMR_Q_CREATE_DOM_GROUP - SAM create group */
1289 typedef struct q_samr_create_dom_group_info
1290 {
1291         POLICY_HND pol;        /* policy handle */
1292
1293         UNIHDR hdr_acct_desc;
1294         UNISTR2 uni_acct_desc;
1295
1296         uint16 unknown_1;    /* 0x0002 */
1297         uint16 unknown_2;    /* 0x0001 */
1298
1299 } SAMR_Q_CREATE_DOM_GROUP;
1300
1301 /* SAMR_R_CREATE_DOM_GROUP - SAM create group */
1302 typedef struct r_samr_create_dom_group_info
1303 {
1304         POLICY_HND pol;        /* policy handle */
1305
1306         uint32 rid;    
1307         uint32 status;    
1308
1309 } SAMR_R_CREATE_DOM_GROUP;
1310
1311
1312 /* SAMR_Q_SET_GROUPINFO - SAM Group Info */
1313 typedef struct q_samr_set_group_info
1314 {
1315         POLICY_HND pol;        /* policy handle */
1316         uint16 switch_value1;     /* 0x0004 seen */
1317         uint16 switch_value2;     /* 0x0004 seen */
1318
1319         union
1320         {
1321                 GROUP_INFO4 info4;
1322
1323         } group;
1324
1325 } SAMR_Q_SET_GROUPINFO;
1326
1327 /* SAMR_R_SET_GROUPINFO - SAM Group Info */
1328 typedef struct r_samr_set_group_info
1329 {
1330         uint32 status;
1331
1332 } SAMR_R_SET_GROUPINFO;
1333
1334
1335 /* SAMR_Q_ADD_GROUPMEM - probably an add group member */
1336 typedef struct q_samr_add_group_mem_info
1337 {
1338         POLICY_HND pol;       /* policy handle */
1339
1340         uint32 rid;         /* rid */
1341         uint32 unknown;     /* 0x0000 0005 */
1342
1343 } SAMR_Q_ADD_GROUPMEM;
1344
1345
1346 /* SAMR_R_ADD_GROUPMEM - probably an add group member */
1347 typedef struct r_samr_add_group_mem_info
1348 {
1349         uint32 status;         /* return status */
1350
1351 } SAMR_R_ADD_GROUPMEM;
1352
1353
1354 /* SAMR_Q_OPEN_GROUP - probably an open */
1355 typedef struct q_samr_open_group_info
1356 {
1357         POLICY_HND domain_pol;
1358         uint32 unknown;         /* 0x0000 0001, 0x0000 0003, 0x0000 001f */
1359         uint32 rid_group;        /* rid */
1360
1361 } SAMR_Q_OPEN_GROUP;
1362
1363
1364 /* SAMR_R_OPEN_GROUP - probably an open */
1365 typedef struct r_samr_open_group_info
1366 {
1367         POLICY_HND pol;       /* policy handle */
1368         uint32 status;         /* return status */
1369
1370 } SAMR_R_OPEN_GROUP;
1371 #endif
1372
1373
1374 /*******************************************************************
1375 makes a GROUP_INFO1 structure.
1376 ********************************************************************/
1377 void make_samr_group_info1(GROUP_INFO1 *gr1,
1378                                 char *acct_name, char *acct_desc)
1379 {
1380         int desc_len = acct_desc != NULL ? strlen(acct_desc) : 0;
1381         int acct_len = acct_name != NULL ? strlen(acct_name) : 0;
1382         if (gr1 == NULL) return;
1383
1384         DEBUG(5,("make_samr_group_info1\n"));
1385
1386         make_uni_hdr(&(gr1->hdr_acct_name), acct_len , acct_len, acct_name ? 1 : 0);
1387         make_uni_hdr(&(gr1->hdr_acct_desc), desc_len , desc_len, acct_desc ? 1 : 0);
1388
1389         gr1->unknown_1 = 0x3;
1390         gr1->unknown_2 = 0x3;
1391
1392         make_unistr2(&(gr1->uni_acct_name), acct_name, acct_len);
1393         make_unistr2(&(gr1->uni_acct_desc), acct_desc, desc_len);
1394 }
1395
1396
1397 /*******************************************************************
1398 reads or writes a structure.
1399 ********************************************************************/
1400 void samr_io_group_info1(char *desc,  GROUP_INFO1 *gr1, prs_struct *ps, int depth)
1401 {
1402         if (gr1 == NULL) return;
1403
1404         prs_debug(ps, depth, desc, "samr_io_group_info1");
1405         depth++;
1406
1407         prs_align(ps);
1408
1409         smb_io_unihdr ("hdr_acct_name", &(gr1->hdr_acct_name) , ps, depth); 
1410         smb_io_unihdr ("hdr_acct_desc", &(gr1->hdr_acct_desc) , ps, depth); 
1411
1412         prs_uint32("unknown_1", ps, depth, &(gr1->unknown_1));
1413         prs_uint32("unknown_2", ps, depth, &(gr1->unknown_2));
1414
1415         smb_io_unistr2("uni_acct_name", &(gr1->uni_acct_name), gr1->hdr_acct_name.buffer, ps, depth);
1416         prs_align(ps);
1417
1418         smb_io_unistr2("uni_acct_desc", &(gr1->uni_acct_desc), gr1->hdr_acct_desc.buffer, ps, depth);
1419 }
1420
1421 /*******************************************************************
1422 makes a GROUP_INFO4 structure.
1423 ********************************************************************/
1424 void make_samr_group_info4(GROUP_INFO4 *gr4, char *acct_desc)
1425 {
1426         int acct_len = acct_desc != NULL ? strlen(acct_desc) : 0;
1427         if (gr4 == NULL) return;
1428
1429         DEBUG(5,("make_samr_group_info4\n"));
1430
1431         make_uni_hdr(&(gr4->hdr_acct_desc), acct_len , acct_len, acct_desc ? 1 : 0);
1432         make_unistr2(&(gr4->uni_acct_desc), acct_desc, acct_len);
1433 }
1434
1435
1436 /*******************************************************************
1437 reads or writes a structure.
1438 ********************************************************************/
1439 void samr_io_group_info4(char *desc,  GROUP_INFO4 *gr4, prs_struct *ps, int depth)
1440 {
1441         if (gr4 == NULL) return;
1442
1443         prs_debug(ps, depth, desc, "samr_io_group_info4");
1444         depth++;
1445
1446         prs_align(ps);
1447
1448         smb_io_unihdr ("hdr_acct_desc", &(gr4->hdr_acct_desc) , ps, depth); 
1449         smb_io_unistr2("uni_acct_desc", &(gr4->uni_acct_desc), gr4->hdr_acct_desc.buffer, ps, depth);
1450 }
1451
1452 /*******************************************************************
1453 reads or writes a structure.
1454 ********************************************************************/
1455 void samr_group_info_ctr(char *desc,  GROUP_INFO_CTR *ctr, prs_struct *ps, int depth)
1456 {
1457         if (ctr == NULL) return;
1458
1459         prs_debug(ps, depth, desc, "samr_group_info_ctr");
1460         depth++;
1461
1462         prs_uint16("switch_value", ps, depth, &(ctr->switch_value));
1463         prs_align(ps);
1464
1465         switch (ctr->switch_value)
1466         {
1467                 case 1:
1468                 {
1469                         samr_io_group_info1("group_info1", &(ctr->group.info1), ps, depth);
1470                         break;
1471                 }
1472                 case 4:
1473                 {
1474                         samr_io_group_info4("group_info4", &(ctr->group.info4), ps, depth);
1475                         break;
1476                 }
1477                 default:
1478                 {
1479                         DEBUG(4,("samr_group_info_ctr: unsupported switch level\n"));
1480                         break;
1481                 }
1482         }
1483
1484         prs_align(ps);
1485 }
1486
1487
1488 /*******************************************************************
1489 makes a SAMR_Q_QUERY_GROUPINFO structure.
1490 ********************************************************************/
1491 void make_samr_q_query_groupinfo(SAMR_Q_QUERY_GROUPINFO *q_e,
1492                                 POLICY_HND *pol,
1493                                 uint16 switch_level)
1494 {
1495         if (q_e == NULL || pol == NULL) return;
1496
1497         DEBUG(5,("make_samr_q_query_groupinfo\n"));
1498
1499         memcpy(&(q_e->pol), pol, sizeof(*pol));
1500
1501         q_e->switch_level = switch_level;
1502 }
1503
1504
1505 /*******************************************************************
1506 reads or writes a structure.
1507 ********************************************************************/
1508 void samr_io_q_query_groupinfo(char *desc,  SAMR_Q_QUERY_GROUPINFO *q_e, prs_struct *ps, int depth)
1509 {
1510         if (q_e == NULL) return;
1511
1512         prs_debug(ps, depth, desc, "samr_io_q_query_groupinfo");
1513         depth++;
1514
1515         prs_align(ps);
1516
1517         smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); 
1518         prs_align(ps);
1519
1520         prs_uint16("switch_level", ps, depth, &(q_e->switch_level));
1521 }
1522
1523
1524 /*******************************************************************
1525 makes a SAMR_R_QUERY_GROUPINFO structure.
1526 ********************************************************************/
1527 void make_samr_r_query_groupinfo(SAMR_R_QUERY_GROUPINFO *r_u, GROUP_INFO_CTR *ctr,
1528                 uint32 status)
1529 {
1530         if (r_u == NULL) return;
1531
1532         DEBUG(5,("make_samr_r_query_groupinfo\n"));
1533
1534         r_u->ptr = (status == 0x0 && ctr != NULL) ? 1 : 0;
1535         r_u->ctr = ctr;
1536         r_u->status = status;
1537 }
1538
1539
1540 /*******************************************************************
1541 reads or writes a structure.
1542 ********************************************************************/
1543 void samr_io_r_query_groupinfo(char *desc,  SAMR_R_QUERY_GROUPINFO *r_u, prs_struct *ps, int depth)
1544 {
1545         if (r_u == NULL) return;
1546
1547         prs_debug(ps, depth, desc, "samr_io_r_query_groupinfo");
1548         depth++;
1549
1550         prs_align(ps);
1551
1552         prs_uint32("ptr", ps, depth, &(r_u->ptr));
1553         
1554         if (r_u->ptr != 0)
1555         {
1556                 samr_group_info_ctr("ctr", r_u->ctr, ps, depth);
1557         }
1558
1559         prs_uint32("status", ps, depth, &(r_u->status));
1560 }
1561
1562
1563 /*******************************************************************
1564 makes a SAMR_Q_QUERY_GROUPMEM structure.
1565 ********************************************************************/
1566 void make_samr_q_query_groupmem(SAMR_Q_QUERY_GROUPMEM *q_c, POLICY_HND *hnd)
1567 {
1568         if (q_c == NULL || hnd == NULL) return;
1569
1570         DEBUG(5,("make_samr_q_query_groupmem\n"));
1571
1572         memcpy(&(q_c->group_pol), hnd, sizeof(q_c->group_pol));
1573 }
1574
1575 /*******************************************************************
1576 reads or writes a structure.
1577 ********************************************************************/
1578 void samr_io_q_query_groupmem(char *desc,  SAMR_Q_QUERY_GROUPMEM *q_u, prs_struct *ps, int depth)
1579 {
1580         if (q_u == NULL) return;
1581
1582         prs_debug(ps, depth, desc, "samr_io_q_query_groupmem");
1583         depth++;
1584
1585         prs_align(ps);
1586
1587         smb_io_pol_hnd("group_pol", &(q_u->group_pol), ps, depth); 
1588 }
1589
1590 /*******************************************************************
1591 makes a SAMR_R_QUERY_GROUPMEM structure.
1592 ********************************************************************/
1593 void make_samr_r_query_groupmem(SAMR_R_QUERY_GROUPMEM *r_u,
1594                 uint32 num_entries, uint32 *rid, uint32 *attr, uint32 status)
1595 {
1596         if (r_u == NULL) return;
1597
1598         DEBUG(5,("make_samr_r_query_groupmem\n"));
1599
1600         if (status == 0x0)
1601         {
1602                 r_u->ptr         = (num_entries != 0) ? 1 : 0;
1603                 r_u->num_entries = num_entries;
1604
1605                 r_u->ptr_attrs = attr != NULL ? 1 : 0;
1606                 r_u->ptr_rids = rid != NULL ? 1 : 0;
1607
1608                 r_u->num_rids = num_entries;
1609                 r_u->rid  = rid;
1610
1611                 r_u->num_attrs = num_entries;
1612                 r_u->attr = attr;
1613         }
1614         else
1615         {
1616                 r_u->ptr         = 0;
1617                 r_u->num_entries = 0;
1618         }
1619
1620         r_u->status = status;
1621 }
1622
1623 /*******************************************************************
1624 reads or writes a structure.
1625 ********************************************************************/
1626 void samr_io_r_query_groupmem(char *desc,  SAMR_R_QUERY_GROUPMEM *r_u, prs_struct *ps, int depth)
1627 {
1628         int i;
1629
1630         if (r_u == NULL) return;
1631
1632         prs_debug(ps, depth, desc, "samr_io_r_query_groupmem");
1633         depth++;
1634
1635         prs_align(ps);
1636
1637         prs_uint32("ptr", ps, depth, &(r_u->ptr));
1638         prs_uint32("num_entries ", ps, depth, &(r_u->num_entries));
1639
1640         if (r_u->ptr != 0)
1641         {
1642                 prs_uint32("ptr_rids ", ps, depth, &(r_u->ptr_rids ));
1643                 prs_uint32("ptr_attrs", ps, depth, &(r_u->ptr_attrs));
1644
1645                 if (r_u->ptr_rids != 0)
1646                 {
1647                         prs_uint32("num_rids", ps, depth, &(r_u->num_rids));
1648                         for (i = 0; i < r_u->num_rids; i++)
1649                         {
1650                                 prs_grow(ps);
1651                                 prs_uint32("", ps, depth, &(r_u->rid[i]));
1652                         }
1653                 }
1654
1655                 if (r_u->ptr_attrs != 0)
1656                 {
1657                         prs_uint32("num_attrs", ps, depth, &(r_u->num_attrs));
1658                         for (i = 0; i < r_u->num_attrs; i++)
1659                         {
1660                                 prs_grow(ps);
1661                                 prs_uint32("", ps, depth, &(r_u->attr[i]));
1662                         }
1663                 }
1664         }
1665
1666         prs_uint32("status", ps, depth, &(r_u->status));
1667 }
1668
1669
1670 /*******************************************************************
1671 makes a SAMR_Q_ENUM_DOM_GROUPS structure.
1672 ********************************************************************/
1673 void make_samr_q_enum_dom_groups(SAMR_Q_ENUM_DOM_GROUPS *q_e, POLICY_HND *pol,
1674                                 uint16 switch_level, uint32 start_idx, uint32 size)
1675 {
1676         if (q_e == NULL || pol == NULL) return;
1677
1678         DEBUG(5,("make_samr_q_enum_dom_groups\n"));
1679
1680         memcpy(&(q_e->pol), pol, sizeof(*pol));
1681
1682         q_e->switch_level = switch_level;
1683
1684         q_e->unknown_0 = 0;
1685         q_e->start_idx = start_idx;
1686         q_e->unknown_1 = 0x000007d0;
1687         q_e->max_size  = size;
1688 }
1689
1690
1691 /*******************************************************************
1692 reads or writes a structure.
1693 ********************************************************************/
1694 void samr_io_q_enum_dom_groups(char *desc,  SAMR_Q_ENUM_DOM_GROUPS *q_e, prs_struct *ps, int depth)
1695 {
1696         if (q_e == NULL) return;
1697
1698         prs_debug(ps, depth, desc, "samr_io_q_enum_dom_groups");
1699         depth++;
1700
1701         prs_align(ps);
1702
1703         smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); 
1704         prs_align(ps);
1705
1706         prs_uint16("switch_level", ps, depth, &(q_e->switch_level));
1707         prs_uint16("unknown_0   ", ps, depth, &(q_e->unknown_0   ));
1708         prs_uint32("start_idx   ", ps, depth, &(q_e->start_idx   ));
1709         prs_uint32("unknown_1   ", ps, depth, &(q_e->unknown_1   ));
1710         prs_uint32("max_size    ", ps, depth, &(q_e->max_size    ));
1711
1712         prs_align(ps);
1713 }
1714
1715
1716 /*******************************************************************
1717 makes a SAMR_R_ENUM_DOM_GROUPS structure.
1718 ********************************************************************/
1719 void make_samr_r_enum_dom_groups(SAMR_R_ENUM_DOM_GROUPS *r_u,
1720                 uint32 start_idx, uint32 num_sam_entries,
1721                 DOMAIN_GRP *grp,
1722                 uint32 status)
1723 {
1724         int i;
1725         int entries_added;
1726
1727         if (r_u == NULL) return;
1728
1729         DEBUG(5,("make_samr_r_enum_dom_groups\n"));
1730
1731         if (num_sam_entries >= MAX_SAM_ENTRIES)
1732         {
1733                 num_sam_entries = MAX_SAM_ENTRIES;
1734                 DEBUG(5,("limiting number of entries to %d\n", 
1735                          num_sam_entries));
1736         }
1737
1738         if (status == 0x0)
1739         {
1740                 for (i = start_idx, entries_added = 0; i < num_sam_entries; i++)
1741                 {
1742                         int acct_name_len = strlen(grp[i].name);
1743                         int acct_desc_len = strlen(grp[i].comment);
1744
1745                         make_sam_entry3(&(r_u->sam[entries_added]),
1746                                         start_idx + entries_added + 1,
1747                                         acct_name_len,
1748                                         acct_desc_len,
1749                                         grp[i].rid);
1750
1751                         make_unistr2(&(r_u->str[entries_added].uni_grp_name), grp[i].name   , acct_name_len);
1752                         make_unistr2(&(r_u->str[entries_added].uni_grp_desc), grp[i].comment, acct_desc_len);
1753
1754                         entries_added++;
1755                 }
1756
1757                 if (entries_added > 0)
1758                 {
1759                         r_u->unknown_0 = 0x0000492;
1760                         r_u->unknown_1 = 0x000049a;
1761                 }
1762                 else
1763                 {
1764                         r_u->unknown_0 = 0x0;
1765                         r_u->unknown_1 = 0x0;
1766                 }
1767                 r_u->switch_level  = 3;
1768                 r_u->num_entries   = entries_added;
1769                 r_u->ptr_entries   = 1;
1770                 r_u->num_entries2  = entries_added;
1771         }
1772         else
1773         {
1774                 r_u->switch_level = 0;
1775         }
1776
1777         r_u->status = status;
1778 }
1779
1780 /*******************************************************************
1781 reads or writes a structure.
1782 ********************************************************************/
1783 void samr_io_r_enum_dom_groups(char *desc,  SAMR_R_ENUM_DOM_GROUPS *r_u, prs_struct *ps, int depth)
1784 {
1785         int i;
1786
1787         if (r_u == NULL) return;
1788
1789         prs_debug(ps, depth, desc, "samr_io_r_enum_dom_groups");
1790         depth++;
1791
1792         prs_align(ps);
1793
1794         prs_uint32("unknown_0    ", ps, depth, &(r_u->unknown_0    ));
1795         prs_uint32("unknown_1    ", ps, depth, &(r_u->unknown_1    ));
1796         prs_uint32("switch_level ", ps, depth, &(r_u->switch_level ));
1797
1798         if (r_u->switch_level != 0)
1799         {
1800                 prs_uint32("num_entries  ", ps, depth, &(r_u->num_entries  ));
1801                 prs_uint32("ptr_entries  ", ps, depth, &(r_u->ptr_entries  ));
1802
1803                 prs_uint32("num_entries2 ", ps, depth, &(r_u->num_entries2 ));
1804
1805                 SMB_ASSERT_ARRAY(r_u->sam, r_u->num_entries);
1806
1807                 for (i = 0; i < r_u->num_entries; i++)
1808                 {
1809                         prs_grow(ps);
1810                         sam_io_sam_entry3("", &(r_u->sam[i]), ps, depth);
1811                 }
1812
1813                 for (i = 0; i < r_u->num_entries; i++)
1814                 {
1815                         prs_grow(ps);
1816                         sam_io_sam_str3 ("", &(r_u->str[i]),
1817                                              r_u->sam[i].hdr_grp_name.buffer,
1818                                              r_u->sam[i].hdr_grp_desc.buffer,
1819                                              ps, depth);
1820                 }
1821         }
1822
1823         prs_uint32("status", ps, depth, &(r_u->status));
1824 }
1825
1826 /*******************************************************************
1827 makes a SAMR_Q_QUERY_USERGROUPS structure.
1828 ********************************************************************/
1829 void make_samr_q_query_usergroups(SAMR_Q_QUERY_USERGROUPS *q_u,
1830                                 POLICY_HND *hnd)
1831 {
1832         if (q_u == NULL || hnd == NULL) return;
1833
1834         DEBUG(5,("make_samr_q_query_usergroups\n"));
1835
1836         memcpy(&(q_u->pol), hnd, sizeof(q_u->pol));
1837 }
1838
1839
1840 /*******************************************************************
1841 reads or writes a structure.
1842 ********************************************************************/
1843 void samr_io_q_query_usergroups(char *desc,  SAMR_Q_QUERY_USERGROUPS *q_u, prs_struct *ps, int depth)
1844 {
1845         if (q_u == NULL) return;
1846
1847         prs_debug(ps, depth, desc, "samr_io_q_query_usergroups");
1848         depth++;
1849
1850         prs_align(ps);
1851
1852         smb_io_pol_hnd("pol", &(q_u->pol), ps, depth); 
1853         prs_align(ps);
1854 }
1855
1856 /*******************************************************************
1857 makes a SAMR_R_QUERY_USERGROUPS structure.
1858 ********************************************************************/
1859 void make_samr_r_query_usergroups(SAMR_R_QUERY_USERGROUPS *r_u,
1860                 uint32 num_gids, DOM_GID *gid, uint32 status)
1861 {
1862         if (r_u == NULL) return;
1863
1864         DEBUG(5,("make_samr_r_query_usergroups\n"));
1865
1866         if (status == 0x0)
1867         {
1868                 r_u->ptr_0        = 1;
1869                 r_u->num_entries  = num_gids;
1870                 r_u->ptr_1        = (num_gids != 0) ? 1 : 0;
1871                 r_u->num_entries2 = num_gids;
1872
1873                 r_u->gid = gid;
1874         }
1875         else
1876         {
1877                 r_u->ptr_0       = 0;
1878                 r_u->num_entries = 0;
1879                 r_u->ptr_1       = 0;
1880         }
1881
1882         r_u->status = status;
1883 }
1884
1885 /*******************************************************************
1886 reads or writes a structure.
1887 ********************************************************************/
1888 void samr_io_r_query_usergroups(char *desc,  SAMR_R_QUERY_USERGROUPS *r_u, prs_struct *ps, int depth)
1889 {
1890         int i;
1891         if (r_u == NULL) return;
1892
1893         prs_debug(ps, depth, desc, "samr_io_r_query_usergroups");
1894         depth++;
1895
1896         prs_align(ps);
1897
1898         prs_uint32("ptr_0       ", ps, depth, &(r_u->ptr_0      ));
1899
1900         if (r_u->ptr_0 != 0)
1901         {
1902                 prs_uint32("num_entries ", ps, depth, &(r_u->num_entries));
1903                 prs_uint32("ptr_1       ", ps, depth, &(r_u->ptr_1      ));
1904
1905                 if (r_u->num_entries != 0)
1906                 {
1907                         prs_uint32("num_entries2", ps, depth, &(r_u->num_entries2));
1908
1909                         for (i = 0; i < r_u->num_entries2; i++)
1910                         {
1911                                 prs_grow(ps);
1912                                 smb_io_gid("", &(r_u->gid[i]), ps, depth);
1913                         }
1914                 }
1915         }
1916         prs_uint32("status", ps, depth, &(r_u->status));
1917 }
1918
1919
1920 /*******************************************************************
1921 makes a SAMR_Q_ENUM_DOM_ALIASES structure.
1922 ********************************************************************/
1923 void make_samr_q_enum_dom_aliases(SAMR_Q_ENUM_DOM_ALIASES *q_e, POLICY_HND *pol, uint32 size)
1924 {
1925         if (q_e == NULL || pol == NULL) return;
1926
1927         DEBUG(5,("make_samr_q_enum_dom_aliases\n"));
1928
1929         memcpy(&(q_e->pol), pol, sizeof(*pol));
1930
1931         q_e->unknown_0 = 0;
1932         q_e->max_size = size;
1933 }
1934
1935
1936 /*******************************************************************
1937 reads or writes a structure.
1938 ********************************************************************/
1939 void samr_io_q_enum_dom_aliases(char *desc,  SAMR_Q_ENUM_DOM_ALIASES *q_e, prs_struct *ps, int depth)
1940 {
1941         if (q_e == NULL) return;
1942
1943         prs_debug(ps, depth, desc, "samr_io_q_enum_dom_aliases");
1944         depth++;
1945
1946         prs_align(ps);
1947
1948         smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); 
1949         prs_align(ps);
1950
1951         prs_uint32("unknown_0", ps, depth, &(q_e->unknown_0));
1952         prs_uint32("max_size ", ps, depth, &(q_e->max_size ));
1953
1954         prs_align(ps);
1955 }
1956
1957
1958 /*******************************************************************
1959 makes a SAMR_R_ENUM_DOM_ALIASES structure.
1960 ********************************************************************/
1961 void make_samr_r_enum_dom_aliases(SAMR_R_ENUM_DOM_ALIASES *r_u,
1962                 uint32 num_sam_entries, LOCAL_GRP *alss,
1963                 uint32 status)
1964 {
1965         int i;
1966
1967         if (r_u == NULL) return;
1968
1969         DEBUG(5,("make_samr_r_enum_dom_aliases\n"));
1970
1971         if (num_sam_entries >= MAX_SAM_ENTRIES)
1972         {
1973                 num_sam_entries = MAX_SAM_ENTRIES;
1974                 DEBUG(5,("limiting number of entries to %d\n", 
1975                          num_sam_entries));
1976         }
1977
1978         r_u->num_entries  = num_sam_entries;
1979
1980         if (num_sam_entries > 0)
1981         {
1982                 r_u->ptr_entries  = 1;
1983                 r_u->num_entries2 = num_sam_entries;
1984                 r_u->ptr_entries2 = 1;
1985                 r_u->num_entries3 = num_sam_entries;
1986
1987                 SMB_ASSERT_ARRAY(r_u->sam, num_sam_entries);
1988
1989                 for (i = 0; i < num_sam_entries; i++)
1990                 {
1991                         int acct_name_len = strlen(alss[i].name);
1992
1993                         make_sam_entry(&(r_u->sam[i]),
1994                                         acct_name_len,
1995                                         alss[i].rid);
1996
1997                         make_unistr2(&(r_u->uni_grp_name[i]), alss[i].name   , acct_name_len);
1998                 }
1999
2000                 r_u->num_entries4 = num_sam_entries;
2001         }
2002         else
2003         {
2004                 r_u->ptr_entries = 0;
2005         }
2006
2007         r_u->status = status;
2008 }
2009
2010 /*******************************************************************
2011 reads or writes a structure.
2012 ********************************************************************/
2013 void samr_io_r_enum_dom_aliases(char *desc,  SAMR_R_ENUM_DOM_ALIASES *r_u, prs_struct *ps, int depth)
2014 {
2015         int i;
2016
2017         if (r_u == NULL) return;
2018
2019         prs_debug(ps, depth, desc, "samr_io_r_enum_dom_aliases");
2020         depth++;
2021
2022         prs_align(ps);
2023
2024         prs_uint32("num_entries", ps, depth, &(r_u->num_entries));
2025         prs_uint32("ptr_entries", ps, depth, &(r_u->ptr_entries));
2026         
2027         if (r_u->num_entries != 0 && r_u->ptr_entries != 0)
2028         {
2029                 prs_uint32("num_entries2", ps, depth, &(r_u->num_entries2));
2030                 prs_uint32("ptr_entries2", ps, depth, &(r_u->ptr_entries2));
2031                 prs_uint32("num_entries3", ps, depth, &(r_u->num_entries3));
2032
2033                 SMB_ASSERT_ARRAY(r_u->sam, r_u->num_entries);
2034
2035                 for (i = 0; i < r_u->num_entries; i++)
2036                 {
2037                         sam_io_sam_entry("", &(r_u->sam[i]), ps, depth);
2038                 }
2039
2040                 for (i = 0; i < r_u->num_entries; i++)
2041                 {
2042                         smb_io_unistr2("", &(r_u->uni_grp_name[i]), r_u->sam[i].hdr_name.buffer, ps, depth);
2043                 }
2044
2045                 prs_align(ps);
2046
2047                 prs_uint32("num_entries4", ps, depth, &(r_u->num_entries4));
2048         }
2049
2050         prs_uint32("status", ps, depth, &(r_u->status));
2051 }
2052
2053
2054 /*******************************************************************
2055 makes a ALIAS_INFO3 structure.
2056 ********************************************************************/
2057 void make_samr_alias_info3(ALIAS_INFO3 *al3, char *acct_desc)
2058 {
2059         int acct_len = acct_desc != NULL ? strlen(acct_desc) : 0;
2060         if (al3 == NULL) return;
2061
2062         DEBUG(5,("make_samr_alias_info3\n"));
2063
2064         make_uni_hdr(&(al3->hdr_acct_desc), acct_len , acct_len, acct_desc ? 1 : 0);
2065         make_unistr2(&(al3->uni_acct_desc), acct_desc, acct_len);
2066 }
2067
2068
2069 /*******************************************************************
2070 reads or writes a structure.
2071 ********************************************************************/
2072 void samr_io_alias_info3(char *desc,  ALIAS_INFO3 *al3, prs_struct *ps, int depth)
2073 {
2074         if (al3 == NULL) return;
2075
2076         prs_debug(ps, depth, desc, "samr_io_alias_info3");
2077         depth++;
2078
2079         prs_align(ps);
2080
2081         smb_io_unihdr ("hdr_acct_desc", &(al3->hdr_acct_desc) , ps, depth); 
2082         smb_io_unistr2("uni_acct_desc", &(al3->uni_acct_desc), al3->hdr_acct_desc.buffer, ps, depth);
2083 }
2084
2085 /*******************************************************************
2086 reads or writes a structure.
2087 ********************************************************************/
2088 void samr_alias_info_ctr(char *desc,  ALIAS_INFO_CTR *ctr, prs_struct *ps, int depth)
2089 {
2090         if (ctr == NULL) return;
2091
2092         prs_debug(ps, depth, desc, "samr_alias_info_ctr");
2093         depth++;
2094
2095         prs_uint16("switch_value", ps, depth, &(ctr->switch_value));
2096         prs_align(ps);
2097
2098         if (ctr->switch_value != 0)
2099         {
2100                 switch (ctr->switch_value)
2101                 {
2102                         case 3:
2103                         {
2104                                 samr_io_alias_info3("alias_info3", &(ctr->alias.info3), ps, depth);
2105                                 break;
2106                         }
2107                         default:
2108                         {
2109                                 DEBUG(4,("samr_alias_info_ctr: unsupported switch level\n"));
2110                                 break;
2111                         }
2112                 }
2113         }
2114
2115         prs_align(ps);
2116 }
2117
2118
2119 /*******************************************************************
2120 makes a SAMR_Q_QUERY_ALIASINFO structure.
2121 ********************************************************************/
2122 void make_samr_q_query_aliasinfo(SAMR_Q_QUERY_ALIASINFO *q_e,
2123                                 POLICY_HND *pol,
2124                                 uint16 switch_level)
2125 {
2126         if (q_e == NULL || pol == NULL) return;
2127
2128         DEBUG(5,("make_samr_q_query_aliasinfo\n"));
2129
2130         memcpy(&(q_e->pol), pol, sizeof(*pol));
2131
2132         q_e->switch_level = switch_level;
2133 }
2134
2135
2136 /*******************************************************************
2137 reads or writes a structure.
2138 ********************************************************************/
2139 void samr_io_q_query_aliasinfo(char *desc,  SAMR_Q_QUERY_ALIASINFO *q_e, prs_struct *ps, int depth)
2140 {
2141         if (q_e == NULL) return;
2142
2143         prs_debug(ps, depth, desc, "samr_io_q_query_aliasinfo");
2144         depth++;
2145
2146         prs_align(ps);
2147
2148         smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); 
2149         prs_align(ps);
2150
2151         prs_uint16("switch_level", ps, depth, &(q_e->switch_level));
2152 }
2153
2154
2155 /*******************************************************************
2156 makes a SAMR_R_QUERY_ALIASINFO structure.
2157 ********************************************************************/
2158 void make_samr_r_query_aliasinfo(SAMR_R_QUERY_ALIASINFO *r_u, ALIAS_INFO_CTR *ctr,
2159                 uint32 status)
2160 {
2161         if (r_u == NULL) return;
2162
2163         DEBUG(5,("make_samr_r_query_aliasinfo\n"));
2164
2165         r_u->ptr = (status == 0x0 && ctr != NULL) ? 1 : 0;
2166         r_u->ctr = ctr;
2167         r_u->status = status;
2168 }
2169
2170
2171 /*******************************************************************
2172 reads or writes a structure.
2173 ********************************************************************/
2174 void samr_io_r_query_aliasinfo(char *desc,  SAMR_R_QUERY_ALIASINFO *r_u, prs_struct *ps, int depth)
2175 {
2176         if (r_u == NULL) return;
2177
2178         prs_debug(ps, depth, desc, "samr_io_r_query_aliasinfo");
2179         depth++;
2180
2181         prs_align(ps);
2182
2183         prs_uint32("ptr", ps, depth, &(r_u->ptr));
2184         
2185         if (r_u->ptr != 0)
2186         {
2187                 samr_alias_info_ctr("ctr", r_u->ctr, ps, depth);
2188         }
2189
2190         prs_uint32("status", ps, depth, &(r_u->status));
2191 }
2192
2193
2194 /*******************************************************************
2195 makes a SAMR_Q_SET_ALIASINFO structure.
2196 ********************************************************************/
2197 void make_samr_q_set_aliasinfo(SAMR_Q_SET_ALIASINFO *q_u, POLICY_HND *hnd,
2198                                 ALIAS_INFO_CTR *ctr)
2199 {
2200         if (q_u == NULL) return;
2201
2202         DEBUG(5,("make_samr_q_set_aliasinfo\n"));
2203
2204         memcpy(&(q_u->alias_pol), hnd, sizeof(q_u->alias_pol));
2205         q_u->ctr = ctr;
2206 }
2207
2208
2209 /*******************************************************************
2210 reads or writes a structure.
2211 ********************************************************************/
2212 void samr_io_q_set_aliasinfo(char *desc,  SAMR_Q_SET_ALIASINFO *q_u, prs_struct *ps, int depth)
2213 {
2214         if (q_u == NULL) return;
2215
2216         prs_debug(ps, depth, desc, "samr_io_q_set_aliasinfo");
2217         depth++;
2218
2219         prs_align(ps);
2220
2221         smb_io_pol_hnd("alias_pol", &(q_u->alias_pol), ps, depth); 
2222         samr_alias_info_ctr("ctr", q_u->ctr, ps, depth);
2223 }
2224
2225 /*******************************************************************
2226 reads or writes a structure.
2227 ********************************************************************/
2228 void samr_io_r_set_aliasinfo(char *desc,  SAMR_R_SET_ALIASINFO *r_u, prs_struct *ps, int depth)
2229 {
2230         if (r_u == NULL) return;
2231
2232         prs_debug(ps, depth, desc, "samr_io_r_set_aliasinfo");
2233         depth++;
2234
2235         prs_align(ps);
2236         prs_uint32("status", ps, depth, &(r_u->status));
2237 }
2238
2239
2240
2241 /*******************************************************************
2242 makes a SAMR_Q_QUERY_USERALIASES structure.
2243 ********************************************************************/
2244 void make_samr_q_query_useraliases(SAMR_Q_QUERY_USERALIASES *q_u,
2245                                 POLICY_HND *hnd,
2246                                 DOM_SID *sid)
2247 {
2248         if (q_u == NULL || hnd == NULL) return;
2249
2250         DEBUG(5,("make_samr_q_query_useraliases\n"));
2251
2252         memcpy(&(q_u->pol), hnd, sizeof(q_u->pol));
2253
2254         q_u->num_sids1 = 1;
2255         q_u->ptr = 0;
2256         q_u->num_sids2 = 1;
2257
2258         {
2259                 q_u->ptr_sid[0] = 1;
2260                 make_dom_sid2(&q_u->sid[0], sid);
2261         }
2262 }
2263
2264 /*******************************************************************
2265 reads or writes a SAMR_Q_QUERY_USERALIASES structure.
2266 ********************************************************************/
2267 void samr_io_q_query_useraliases(char *desc,  SAMR_Q_QUERY_USERALIASES *q_u, prs_struct *ps, int depth)
2268 {
2269         fstring tmp;
2270         int i;
2271
2272         if (q_u == NULL) return;
2273
2274         prs_debug(ps, depth, desc, "samr_io_q_query_useraliases");
2275         depth++;
2276
2277         prs_align(ps);
2278
2279         smb_io_pol_hnd("pol", &(q_u->pol), ps, depth); 
2280         prs_align(ps);
2281
2282         prs_uint32("num_sids1", ps, depth, &(q_u->num_sids1));
2283         prs_uint32("ptr      ", ps, depth, &(q_u->ptr      ));
2284         prs_uint32("num_sids2", ps, depth, &(q_u->num_sids2));
2285
2286         SMB_ASSERT_ARRAY(q_u->ptr_sid, q_u->num_sids2);
2287
2288         for (i = 0; i < q_u->num_sids2; i++)
2289         {
2290                 slprintf(tmp, sizeof(tmp) - 1, "ptr[%02d]", i);
2291                 prs_uint32(tmp, ps, depth, &(q_u->ptr_sid[i]));
2292         }
2293
2294         for (i = 0; i < q_u->num_sids2; i++)
2295         {
2296                 if (q_u->ptr_sid[i] != 0)
2297                 {
2298                         prs_grow(ps);
2299                         slprintf(tmp, sizeof(tmp)-1, "sid[%02d]", i);
2300                         smb_io_dom_sid2(tmp, &(q_u->sid[i]), ps, depth); 
2301                 }
2302         }
2303
2304         prs_align(ps);
2305 }
2306
2307
2308 /*******************************************************************
2309 makes a SAMR_R_QUERY_USERALIASES structure.
2310 ********************************************************************/
2311 void make_samr_r_query_useraliases(SAMR_R_QUERY_USERALIASES *r_u,
2312                 uint32 num_rids, uint32 *rid, uint32 status)
2313 {
2314         if (r_u == NULL) return;
2315
2316         DEBUG(5,("make_samr_r_query_useraliases\n"));
2317
2318         if (status == 0x0)
2319         {
2320                 r_u->num_entries  = num_rids;
2321                 r_u->ptr = 1;
2322                 r_u->num_entries2 = num_rids;
2323
2324                 r_u->rid = rid;
2325         }
2326         else
2327         {
2328                 r_u->num_entries  = 0;
2329                 r_u->ptr = 0;
2330                 r_u->num_entries2 = 0;
2331         }
2332
2333         r_u->status = status;
2334 }
2335
2336 /*******************************************************************
2337 reads or writes a structure.
2338 ********************************************************************/
2339 void samr_io_r_query_useraliases(char *desc,  SAMR_R_QUERY_USERALIASES *r_u, prs_struct *ps, int depth)
2340 {
2341         fstring tmp;
2342         int i;
2343         if (r_u == NULL) return;
2344
2345         prs_debug(ps, depth, desc, "samr_io_r_query_useraliases");
2346         depth++;
2347
2348         prs_align(ps);
2349
2350         prs_uint32("num_entries", ps, depth, &(r_u->num_entries));
2351         prs_uint32("ptr        ", ps, depth, &(r_u->ptr        ));
2352         prs_uint32("num_entries2", ps, depth, &(r_u->num_entries2));
2353
2354         if (r_u->num_entries != 0)
2355         {
2356                 for (i = 0; i < r_u->num_entries2; i++)
2357                 {
2358                         slprintf(tmp, sizeof(tmp)-1, "rid[%02d]", i);
2359                         prs_uint32(tmp, ps, depth, &(r_u->rid[i]));
2360                 }
2361         }
2362
2363         prs_uint32("status", ps, depth, &(r_u->status));
2364 }
2365
2366 /*******************************************************************
2367 makes a SAMR_Q_OPEN_ALIAS structure.
2368 ********************************************************************/
2369 void make_samr_q_open_alias(SAMR_Q_OPEN_ALIAS *q_u, POLICY_HND *pol,
2370                                 uint32 unknown_0, uint32 rid)
2371 {
2372         if (q_u == NULL) return;
2373
2374         DEBUG(5,("make_samr_q_open_alias\n"));
2375
2376         memcpy(&(q_u->dom_pol), pol, sizeof(q_u->dom_pol));
2377
2378         /* example values: 0x0000 0008 */
2379         q_u->unknown_0 = unknown_0; 
2380
2381         q_u->rid_alias = rid; 
2382 }
2383
2384 /*******************************************************************
2385 reads or writes a structure.
2386 ********************************************************************/
2387 void samr_io_q_open_alias(char *desc,  SAMR_Q_OPEN_ALIAS *q_u, prs_struct *ps, int depth)
2388 {
2389         if (q_u == NULL) return;
2390
2391         prs_debug(ps, depth, desc, "samr_io_q_open_alias");
2392         depth++;
2393
2394         prs_align(ps);
2395
2396         smb_io_pol_hnd("dom_pol", &(q_u->dom_pol), ps, depth); 
2397
2398         prs_uint32("unknown_0", ps, depth, &(q_u->unknown_0));
2399         prs_uint32("rid_alias", ps, depth, &(q_u->rid_alias));
2400 }
2401
2402 /*******************************************************************
2403 reads or writes a structure.
2404 ********************************************************************/
2405 void samr_io_r_open_alias(char *desc,  SAMR_R_OPEN_ALIAS *r_u, prs_struct *ps, int depth)
2406 {
2407         if (r_u == NULL) return;
2408
2409         prs_debug(ps, depth, desc, "samr_io_r_open_alias");
2410         depth++;
2411
2412         prs_align(ps);
2413
2414         smb_io_pol_hnd("pol", &(r_u->pol), ps, depth); 
2415         prs_align(ps);
2416
2417         prs_uint32("status", ps, depth, &(r_u->status));
2418 }
2419
2420 /*******************************************************************
2421 makes a SAMR_Q_UNKNOWN_12 structure.
2422 ********************************************************************/
2423 void make_samr_q_unknown_12(SAMR_Q_UNKNOWN_12 *q_u,
2424                 POLICY_HND *pol, uint32 rid,
2425                 uint32 num_gids, uint32 *gid)
2426 {
2427         int i;
2428         if (q_u == NULL) return;
2429
2430         DEBUG(5,("make_samr_r_unknwon_12\n"));
2431
2432         memcpy(&(q_u->pol), pol, sizeof(*pol));
2433
2434         q_u->num_gids1 = num_gids;
2435         q_u->rid       = rid;
2436         q_u->ptr       = 0;
2437         q_u->num_gids2 = num_gids;
2438
2439         for (i = 0; i < num_gids; i++)
2440         {
2441                 q_u->gid[i] = gid[i];
2442         }
2443 }
2444
2445 /*******************************************************************
2446 reads or writes a structure.
2447 ********************************************************************/
2448 void samr_io_q_unknown_12(char *desc,  SAMR_Q_UNKNOWN_12 *q_u, prs_struct *ps, int depth)
2449 {
2450         int i;
2451         fstring tmp;
2452
2453         if (q_u == NULL) return;
2454
2455         prs_debug(ps, depth, desc, "samr_io_q_unknown_12");
2456         depth++;
2457
2458         prs_align(ps);
2459
2460         smb_io_pol_hnd("pol", &(q_u->pol), ps, depth); 
2461         prs_align(ps);
2462
2463         prs_uint32("num_gids1", ps, depth, &(q_u->num_gids1));
2464         prs_uint32("rid      ", ps, depth, &(q_u->rid      ));
2465         prs_uint32("ptr      ", ps, depth, &(q_u->ptr      ));
2466         prs_uint32("num_gids2", ps, depth, &(q_u->num_gids2));
2467
2468         SMB_ASSERT_ARRAY(q_u->gid, q_u->num_gids2);
2469
2470         for (i = 0; i < q_u->num_gids2; i++)
2471         {
2472                 prs_grow(ps);
2473                 slprintf(tmp, sizeof(tmp) - 1, "gid[%02d]  ", i);
2474                 prs_uint32(tmp, ps, depth, &(q_u->gid[i]));
2475         }
2476
2477         prs_align(ps);
2478 }
2479
2480
2481 /*******************************************************************
2482 makes a SAMR_R_UNKNOWN_12 structure.
2483 ********************************************************************/
2484 void make_samr_r_unknown_12(SAMR_R_UNKNOWN_12 *r_u,
2485                 uint32 num_names, fstring *name, uint8 *type,
2486                 uint32 status)
2487 {
2488         int i;
2489         if (r_u == NULL || name == NULL || type == NULL) return;
2490
2491         DEBUG(5,("make_samr_r_unknown_12\n"));
2492
2493         if (status == 0x0)
2494         {
2495                 r_u->num_names1 = num_names;
2496                 r_u->ptr_names  = 1;
2497                 r_u->num_names2 = num_names;
2498
2499                 r_u->num_types1 = num_names;
2500                 r_u->ptr_types  = 1;
2501                 r_u->num_types2 = num_names;
2502
2503                 SMB_ASSERT_ARRAY(r_u->hdr_name, num_names);
2504
2505                 for (i = 0; i < num_names; i++)
2506                 {
2507                         int len = name[i] != NULL ? strlen(name[i]) : 0;
2508                         make_uni_hdr(&(r_u->hdr_name[i]), len    , len, name[i] ? 1 : 0);
2509                         make_unistr2(&(r_u->uni_name[i]), name[i], len);
2510                         r_u->type[i] = type[i];
2511                 }
2512         }
2513         else
2514         {
2515                 r_u->num_names1 = num_names;
2516                 r_u->ptr_names  = 0;
2517                 r_u->num_names2 = num_names;
2518
2519                 r_u->num_types1 = num_names;
2520                 r_u->ptr_types  = 0;
2521                 r_u->num_types2 = num_names;
2522         }
2523
2524         r_u->status = status;
2525 }
2526
2527 /*******************************************************************
2528 reads or writes a structure.
2529 ********************************************************************/
2530 void samr_io_r_unknown_12(char *desc,  SAMR_R_UNKNOWN_12 *r_u, prs_struct *ps, int depth)
2531 {
2532         int i;
2533         fstring tmp;
2534         if (r_u == NULL) return;
2535
2536         prs_debug(ps, depth, desc, "samr_io_r_unknown_12");
2537         depth++;
2538
2539         prs_align(ps);
2540
2541         prs_uint32("num_names1", ps, depth, &(r_u->num_names1));
2542         prs_uint32("ptr_names ", ps, depth, &(r_u->ptr_names ));
2543         prs_uint32("num_names2", ps, depth, &(r_u->num_names2));
2544
2545         if (r_u->ptr_names != 0 && r_u->num_names1 != 0)
2546         {
2547                 SMB_ASSERT_ARRAY(r_u->hdr_name, r_u->num_names2);
2548
2549                 for (i = 0; i < r_u->num_names2; i++)
2550                 {
2551                         prs_grow(ps);
2552                         slprintf(tmp, sizeof(tmp) - 1, "hdr[%02d]  ", i);
2553                         smb_io_unihdr ("", &(r_u->hdr_name[i]), ps, depth); 
2554                 }
2555                 for (i = 0; i < r_u->num_names2; i++)
2556                 {
2557                         prs_grow(ps);
2558                         slprintf(tmp, sizeof(tmp) - 1, "str[%02d]  ", i);
2559                         smb_io_unistr2("", &(r_u->uni_name[i]), r_u->hdr_name[i].buffer, ps, depth); 
2560                 }
2561         }
2562
2563         prs_align(ps);
2564
2565         prs_uint32("num_types1", ps, depth, &(r_u->num_types1));
2566         prs_uint32("ptr_types ", ps, depth, &(r_u->ptr_types ));
2567         prs_uint32("num_types2", ps, depth, &(r_u->num_types2));
2568
2569         if (r_u->ptr_types != 0 && r_u->num_types1 != 0)
2570         {
2571                 for (i = 0; i < r_u->num_types2; i++)
2572                 {
2573                         prs_grow(ps);
2574                         slprintf(tmp, sizeof(tmp) - 1, "type[%02d]  ", i);
2575                         prs_uint32(tmp, ps, depth, &(r_u->type[i]));
2576                 }
2577         }
2578
2579         prs_uint32("status", ps, depth, &(r_u->status));
2580 }
2581
2582 /*******************************************************************
2583 makes a SAMR_Q_OPEN_ALIAS structure.
2584 ********************************************************************/
2585 void make_samr_q_delete_alias(SAMR_Q_DELETE_DOM_ALIAS *q_u, POLICY_HND *hnd)
2586 {
2587         if (q_u == NULL) return;
2588
2589         DEBUG(5,("make_samr_q_delete_alias\n"));
2590
2591         memcpy(&(q_u->alias_pol), hnd, sizeof(q_u->alias_pol));
2592 }
2593
2594
2595 /*******************************************************************
2596 reads or writes a structure.
2597 ********************************************************************/
2598 void samr_io_q_delete_alias(char *desc,  SAMR_Q_DELETE_DOM_ALIAS *q_u, prs_struct *ps, int depth)
2599 {
2600         if (q_u == NULL) return;
2601
2602         prs_debug(ps, depth, desc, "samr_io_q_delete_alias");
2603         depth++;
2604
2605         prs_align(ps);
2606
2607         smb_io_pol_hnd("alias_pol", &(q_u->alias_pol), ps, depth); 
2608 }
2609
2610 /*******************************************************************
2611 reads or writes a structure.
2612 ********************************************************************/
2613 void samr_io_r_delete_alias(char *desc,  SAMR_R_DELETE_DOM_ALIAS *r_u, prs_struct *ps, int depth)
2614 {
2615         if (r_u == NULL) return;
2616
2617         prs_debug(ps, depth, desc, "samr_io_r_delete_alias");
2618         depth++;
2619
2620         prs_align(ps);
2621
2622         smb_io_pol_hnd("pol", &(r_u->pol), ps, depth); 
2623         prs_uint32("status", ps, depth, &(r_u->status));
2624 }
2625
2626
2627 /*******************************************************************
2628 makes a SAMR_Q_CREATE_DOM_ALIAS structure.
2629 ********************************************************************/
2630 void make_samr_q_create_dom_alias(SAMR_Q_CREATE_DOM_ALIAS *q_u, POLICY_HND *hnd,
2631                                 char *acct_desc)
2632 {
2633         int acct_len = acct_desc != NULL ? strlen(acct_desc) : 0;
2634         if (q_u == NULL) return;
2635
2636         DEBUG(5,("make_samr_q_create_dom_alias\n"));
2637
2638         memcpy(&(q_u->dom_pol), hnd, sizeof(q_u->dom_pol));
2639
2640         make_uni_hdr(&(q_u->hdr_acct_desc), acct_len , acct_len, acct_desc ? 1 : 0);
2641         make_unistr2(&(q_u->uni_acct_desc), acct_desc, acct_len);
2642
2643         q_u->unknown_1 = 0x001f;
2644         q_u->unknown_2 = 0x000f;
2645 }
2646
2647
2648 /*******************************************************************
2649 reads or writes a structure.
2650 ********************************************************************/
2651 void samr_io_q_create_dom_alias(char *desc,  SAMR_Q_CREATE_DOM_ALIAS *q_u, prs_struct *ps, int depth)
2652 {
2653         if (q_u == NULL) return;
2654
2655         prs_debug(ps, depth, desc, "samr_io_q_create_dom_alias");
2656         depth++;
2657
2658         prs_align(ps);
2659
2660         smb_io_pol_hnd("dom_pol", &(q_u->dom_pol), ps, depth); 
2661
2662         smb_io_unihdr ("hdr_acct_desc", &(q_u->hdr_acct_desc) , ps, depth); 
2663         smb_io_unistr2("uni_acct_desc", &(q_u->uni_acct_desc), q_u->hdr_acct_desc.buffer, ps, depth);
2664
2665         prs_uint16("unknown_1", ps, depth, &(q_u->unknown_1));
2666         prs_uint16("unknown_2", ps, depth, &(q_u->unknown_2));
2667 }
2668
2669 /*******************************************************************
2670 reads or writes a structure.
2671 ********************************************************************/
2672 void samr_io_r_create_dom_alias(char *desc,  SAMR_R_CREATE_DOM_ALIAS *r_u, prs_struct *ps, int depth)
2673 {
2674         if (r_u == NULL) return;
2675
2676         prs_debug(ps, depth, desc, "samr_io_r_create_dom_alias");
2677         depth++;
2678
2679         prs_align(ps);
2680
2681         smb_io_pol_hnd("alias_pol", &(r_u->alias_pol), ps, depth); 
2682         prs_uint32("rid", ps, depth, &(r_u->rid));
2683
2684         prs_uint32("status", ps, depth, &(r_u->status));
2685         }
2686
2687
2688
2689 /*******************************************************************
2690 makes a SAMR_Q_UNK_ALIASMEM structure.
2691 ********************************************************************/
2692 void make_samr_q_unk_aliasmem(SAMR_Q_UNK_ALIASMEM *q_u, POLICY_HND *hnd,
2693                                 DOM_SID *sid)
2694 {
2695         if (q_u == NULL) return;
2696
2697         DEBUG(5,("make_samr_q_unk_aliasmem\n"));
2698
2699         memcpy(&(q_u->alias_pol), hnd, sizeof(q_u->alias_pol));
2700         sid_copy(&q_u->sid, sid);
2701 }
2702
2703
2704 /*******************************************************************
2705 reads or writes a structure.
2706 ********************************************************************/
2707 void samr_io_q_unk_aliasmem(char *desc,  SAMR_Q_UNK_ALIASMEM *q_u, prs_struct *ps, int depth)
2708 {
2709         if (q_u == NULL) return;
2710
2711         prs_debug(ps, depth, desc, "samr_io_q_unk_aliasmem");
2712         depth++;
2713
2714         prs_align(ps);
2715
2716         smb_io_pol_hnd("alias_pol", &(q_u->alias_pol), ps, depth); 
2717         smb_io_dom_sid("sid      ", &(q_u->sid      ), ps, depth); 
2718 }
2719
2720 /*******************************************************************
2721 reads or writes a structure.
2722 ********************************************************************/
2723 void samr_io_r_unk_aliasmem(char *desc,  SAMR_R_UNK_ALIASMEM *r_u, prs_struct *ps, int depth)
2724 {
2725         if (r_u == NULL) return;
2726
2727         prs_debug(ps, depth, desc, "samr_io_r_unk_aliasmem");
2728         depth++;
2729
2730         prs_align(ps);
2731
2732         prs_uint32("status", ps, depth, &(r_u->status));
2733 }
2734
2735
2736 /*******************************************************************
2737 makes a SAMR_Q_ADD_ALIASMEM structure.
2738 ********************************************************************/
2739 void make_samr_q_add_aliasmem(SAMR_Q_ADD_ALIASMEM *q_u, POLICY_HND *hnd,
2740                                 DOM_SID *sid)
2741 {
2742         if (q_u == NULL) return;
2743
2744         DEBUG(5,("make_samr_q_add_aliasmem\n"));
2745
2746         memcpy(&(q_u->alias_pol), hnd, sizeof(q_u->alias_pol));
2747         sid_copy(&q_u->sid, sid);
2748 }
2749
2750
2751 /*******************************************************************
2752 reads or writes a structure.
2753 ********************************************************************/
2754 void samr_io_q_add_aliasmem(char *desc,  SAMR_Q_ADD_ALIASMEM *q_u, prs_struct *ps, int depth)
2755 {
2756         if (q_u == NULL) return;
2757
2758         prs_debug(ps, depth, desc, "samr_io_q_add_aliasmem");
2759         depth++;
2760
2761         prs_align(ps);
2762
2763         smb_io_pol_hnd("alias_pol", &(q_u->alias_pol), ps, depth); 
2764         smb_io_dom_sid("sid      ", &(q_u->sid      ), ps, depth); 
2765 }
2766
2767 /*******************************************************************
2768 reads or writes a structure.
2769 ********************************************************************/
2770 void samr_io_r_add_aliasmem(char *desc,  SAMR_R_ADD_ALIASMEM *r_u, prs_struct *ps, int depth)
2771 {
2772         if (r_u == NULL) return;
2773
2774         prs_debug(ps, depth, desc, "samr_io_r_add_aliasmem");
2775         depth++;
2776
2777         prs_align(ps);
2778
2779         prs_uint32("status", ps, depth, &(r_u->status));
2780 }
2781
2782 /*******************************************************************
2783 makes a SAMR_Q_QUERY_ALIASMEM structure.
2784 ********************************************************************/
2785 void make_samr_q_query_aliasmem(SAMR_Q_QUERY_ALIASMEM *q_c, POLICY_HND *hnd)
2786 {
2787         if (q_c == NULL || hnd == NULL) return;
2788
2789         DEBUG(5,("make_samr_q_query_aliasmem\n"));
2790
2791         memcpy(&(q_c->alias_pol), hnd, sizeof(q_c->alias_pol));
2792 }
2793
2794 /*******************************************************************
2795 reads or writes a structure.
2796 ********************************************************************/
2797 void samr_io_q_query_aliasmem(char *desc,  SAMR_Q_QUERY_ALIASMEM *q_u, prs_struct *ps, int depth)
2798 {
2799         if (q_u == NULL) return;
2800
2801         prs_debug(ps, depth, desc, "samr_io_q_query_aliasmem");
2802         depth++;
2803
2804         prs_align(ps);
2805
2806         smb_io_pol_hnd("alias_pol", &(q_u->alias_pol), ps, depth); 
2807 }
2808
2809 /*******************************************************************
2810 makes a SAMR_R_QUERY_ALIASMEM structure.
2811 ********************************************************************/
2812 void make_samr_r_query_aliasmem(SAMR_R_QUERY_ALIASMEM *r_u,
2813                 uint32 num_sids, DOM_SID2 *sid, uint32 status)
2814 {
2815         if (r_u == NULL) return;
2816
2817         DEBUG(5,("make_samr_r_query_aliasmem\n"));
2818
2819         if (status == 0x0)
2820         {
2821                 r_u->num_sids  = num_sids;
2822                 r_u->ptr       = (num_sids != 0) ? 1 : 0;
2823                 r_u->num_sids1 = num_sids;
2824
2825                 r_u->sid = sid;
2826         }
2827         else
2828         {
2829                 r_u->ptr      = 0;
2830                 r_u->num_sids = 0;
2831         }
2832
2833         r_u->status = status;
2834 }
2835
2836 /*******************************************************************
2837 reads or writes a structure.
2838 ********************************************************************/
2839 void samr_io_r_query_aliasmem(char *desc,  SAMR_R_QUERY_ALIASMEM *r_u, prs_struct *ps, int depth)
2840 {
2841         int i;
2842         uint32 ptr_sid[MAX_LOOKUP_SIDS];
2843
2844         if (r_u == NULL) return;
2845
2846         prs_debug(ps, depth, desc, "samr_io_r_query_aliasmem");
2847         depth++;
2848
2849         prs_align(ps);
2850
2851         prs_uint32("num_sids ", ps, depth, &(r_u->num_sids));
2852         prs_uint32("ptr", ps, depth, &(r_u->ptr));
2853
2854         if (r_u->ptr != 0)
2855         {
2856                 SMB_ASSERT_ARRAY(ptr_sid, r_u->num_sids);
2857
2858                 if (r_u->num_sids != 0)
2859                 {
2860                         prs_uint32("num_sids1", ps, depth, &(r_u->num_sids1));
2861
2862                         for (i = 0; i < r_u->num_sids1; i++)
2863                         {
2864                                 prs_grow(ps);
2865                                 ptr_sid[i] = 1;
2866                                 prs_uint32("", ps, depth, &(ptr_sid[i]));
2867                         }
2868                         for (i = 0; i < r_u->num_sids1; i++)
2869                         {
2870                                 prs_grow(ps);
2871                                 if (ptr_sid[i] != 0)
2872                                 {
2873                                         smb_io_dom_sid2("", &(r_u->sid[i]), ps, depth);
2874                                 }
2875                         }
2876                 }
2877         }
2878         prs_uint32("status", ps, depth, &(r_u->status));
2879 }
2880
2881
2882 /*******************************************************************
2883 reads or writes a structure.
2884 ********************************************************************/
2885 void samr_io_q_lookup_names(char *desc,  SAMR_Q_LOOKUP_NAMES *q_u, prs_struct *ps, int depth)
2886 {
2887         int i;
2888
2889         if (q_u == NULL) return;
2890
2891         prs_debug(ps, depth, desc, "samr_io_q_lookup_names");
2892         depth++;
2893
2894         prs_align(ps);
2895
2896         smb_io_pol_hnd("pol", &(q_u->pol), ps, depth); 
2897         prs_align(ps);
2898
2899         prs_uint32("num_rids1", ps, depth, &(q_u->num_rids1));
2900         prs_uint32("rid      ", ps, depth, &(q_u->rid      ));
2901         prs_uint32("ptr      ", ps, depth, &(q_u->ptr      ));
2902         prs_uint32("num_rids2", ps, depth, &(q_u->num_rids2));
2903
2904         SMB_ASSERT_ARRAY(q_u->hdr_user_name, q_u->num_rids2);
2905
2906         for (i = 0; i < q_u->num_rids2; i++)
2907         {
2908                 prs_grow(ps);
2909                 smb_io_unihdr ("", &(q_u->hdr_user_name[i]), ps, depth); 
2910         }
2911         for (i = 0; i < q_u->num_rids2; i++)
2912         {
2913                 prs_grow(ps);
2914                 smb_io_unistr2("", &(q_u->uni_user_name[i]), q_u->hdr_user_name[i].buffer, ps, depth); 
2915         }
2916
2917         prs_align(ps);
2918 }
2919
2920
2921 /*******************************************************************
2922 makes a SAMR_R_LOOKUP_NAMES structure.
2923 ********************************************************************/
2924 void make_samr_r_lookup_names(SAMR_R_LOOKUP_NAMES *r_u,
2925                 uint32 num_rids, uint32 *rid, uint8 *type, uint32 status)
2926 {
2927         int i;
2928         if (r_u == NULL) return;
2929
2930         DEBUG(5,("make_samr_r_lookup_names\n"));
2931
2932         if (status == 0x0)
2933         {
2934                 r_u->num_entries  = num_rids;
2935                 r_u->undoc_buffer = 1;
2936                 r_u->num_entries2 = num_rids;
2937
2938                 SMB_ASSERT_ARRAY(r_u->dom_rid, num_rids);
2939
2940                 for (i = 0; i < num_rids; i++)
2941                 {
2942                         make_dom_rid3(&(r_u->dom_rid[i]), rid[i], type[i]);
2943                 }
2944         }
2945         else
2946         {
2947                 r_u->num_entries  = 0;
2948                 r_u->undoc_buffer = 0;
2949                 r_u->num_entries2 = 0;
2950         }
2951
2952         r_u->status = status;
2953 }
2954
2955 /*******************************************************************
2956 reads or writes a structure.
2957 ********************************************************************/
2958 void samr_io_r_lookup_names(char *desc,  SAMR_R_LOOKUP_NAMES *r_u, prs_struct *ps, int depth)
2959 {
2960         int i;
2961         if (r_u == NULL) return;
2962
2963         prs_debug(ps, depth, desc, "samr_io_r_lookup_names");
2964         depth++;
2965
2966         prs_align(ps);
2967
2968         prs_uint32("num_entries ", ps, depth, &(r_u->num_entries ));
2969         prs_uint32("undoc_buffer", ps, depth, &(r_u->undoc_buffer));
2970         prs_uint32("num_entries2", ps, depth, &(r_u->num_entries2));
2971
2972         if (r_u->num_entries != 0)
2973         {
2974                 SMB_ASSERT_ARRAY(r_u->dom_rid, r_u->num_entries2);
2975
2976                 for (i = 0; i < r_u->num_entries2; i++)
2977                 {
2978                         prs_grow(ps);
2979                         smb_io_dom_rid3("", &(r_u->dom_rid[i]), ps, depth);
2980         }
2981
2982         }
2983
2984         prs_uint32("status", ps, depth, &(r_u->status));
2985 }
2986
2987
2988 /*******************************************************************
2989 reads or writes a structure.
2990 ********************************************************************/
2991 void make_samr_q_open_user(SAMR_Q_OPEN_USER *q_u,
2992                                 POLICY_HND *pol,
2993                                 uint32 unk_0, uint32 rid)
2994 {
2995         if (q_u == NULL) return;
2996
2997         DEBUG(5,("samr_make_samr_q_open_user\n"));
2998
2999         memcpy(&q_u->domain_pol, pol, sizeof(q_u->domain_pol));
3000         
3001         q_u->unknown_0 = unk_0;
3002         q_u->user_rid  = rid;
3003 }
3004
3005 /*******************************************************************
3006 reads or writes a structure.
3007 ********************************************************************/
3008 void samr_io_q_open_user(char *desc,  SAMR_Q_OPEN_USER *q_u, prs_struct *ps, int depth)
3009 {
3010         if (q_u == NULL) return;
3011
3012         prs_debug(ps, depth, desc, "samr_io_q_open_user");
3013         depth++;
3014
3015         prs_align(ps);
3016
3017         smb_io_pol_hnd("domain_pol", &(q_u->domain_pol), ps, depth); 
3018         prs_align(ps);
3019
3020         prs_uint32("unknown_0", ps, depth, &(q_u->unknown_0));
3021         prs_uint32("user_rid ", ps, depth, &(q_u->user_rid ));
3022
3023         prs_align(ps);
3024 }
3025
3026 /*******************************************************************
3027 reads or writes a structure.
3028 ********************************************************************/
3029 void samr_io_r_open_user(char *desc,  SAMR_R_OPEN_USER *r_u, prs_struct *ps, int depth)
3030 {
3031         if (r_u == NULL) return;
3032
3033         prs_debug(ps, depth, desc, "samr_io_r_open_user");
3034         depth++;
3035
3036         prs_align(ps);
3037
3038         smb_io_pol_hnd("user_pol", &(r_u->user_pol), ps, depth); 
3039         prs_align(ps);
3040
3041         prs_uint32("status", ps, depth, &(r_u->status));
3042 }
3043
3044 /*******************************************************************
3045 makes a SAMR_Q_QUERY_USERINFO structure.
3046 ********************************************************************/
3047 void make_samr_q_query_userinfo(SAMR_Q_QUERY_USERINFO *q_u,
3048                                 POLICY_HND *hnd, uint16 switch_value)
3049 {
3050         if (q_u == NULL || hnd == NULL) return;
3051
3052         DEBUG(5,("make_samr_q_query_userinfo\n"));
3053
3054         memcpy(&(q_u->pol), hnd, sizeof(q_u->pol));
3055         q_u->switch_value = switch_value;
3056 }
3057
3058
3059 /*******************************************************************
3060 reads or writes a structure.
3061 ********************************************************************/
3062 void samr_io_q_query_userinfo(char *desc,  SAMR_Q_QUERY_USERINFO *q_u, prs_struct *ps, int depth)
3063 {
3064         if (q_u == NULL) return;
3065
3066         prs_debug(ps, depth, desc, "samr_io_q_query_userinfo");
3067         depth++;
3068
3069         prs_align(ps);
3070
3071         smb_io_pol_hnd("pol", &(q_u->pol), ps, depth); 
3072         prs_align(ps);
3073
3074         prs_uint16("switch_value", ps, depth, &(q_u->switch_value)); /* 0x0015 or 0x0011 */
3075
3076         prs_align(ps);
3077 }
3078
3079 /*******************************************************************
3080 reads or writes a LOGON_HRS structure.
3081 ********************************************************************/
3082 static void sam_io_logon_hrs(char *desc,  LOGON_HRS *hrs, prs_struct *ps, int depth)
3083 {
3084         if (hrs == NULL) return;
3085
3086         prs_debug(ps, depth, desc, "sam_io_logon_hrs");
3087         depth++;
3088
3089         prs_align(ps);
3090         
3091         prs_uint32 (       "len  ", ps, depth, &(hrs->len ));
3092
3093         if (hrs->len > 64)
3094         {
3095                 DEBUG(5,("sam_io_logon_hrs: truncating length\n"));
3096                 hrs->len = 64;
3097         }
3098
3099         prs_uint8s (False, "hours", ps, depth, hrs->hours, hrs->len);
3100 }
3101
3102 /*******************************************************************
3103 makes a SAM_USER_INFO_10 structure.
3104 ********************************************************************/
3105 void make_sam_user_info10(SAM_USER_INFO_10 *usr,
3106                                 uint32 acb_info)
3107 {
3108         if (usr == NULL) return;
3109
3110         DEBUG(5,("make_sam_user_info10\n"));
3111
3112         usr->acb_info = acb_info;
3113 }
3114
3115 /*******************************************************************
3116 reads or writes a structure.
3117 ********************************************************************/
3118 void sam_io_user_info10(char *desc,  SAM_USER_INFO_10 *usr, prs_struct *ps, int depth)
3119 {
3120         if (usr == NULL) return;
3121
3122         prs_debug(ps, depth, desc, "samr_io_r_user_info10");
3123         depth++;
3124
3125         prs_align(ps);
3126
3127         prs_uint32("acb_info", ps, depth, &(usr->acb_info));
3128 }
3129
3130 /*******************************************************************
3131 makes a SAM_USER_INFO_11 structure.
3132 ********************************************************************/
3133 void make_sam_user_info11(SAM_USER_INFO_11 *usr,
3134                                 NTTIME *expiry,
3135                                 char *mach_acct,
3136                                 uint32 rid_user,
3137                                 uint32 rid_group,
3138                                 uint16 acct_ctrl)
3139                                 
3140 {
3141         int len_mach_acct;
3142         if (usr == NULL || expiry == NULL || mach_acct == NULL) return;
3143
3144         DEBUG(5,("make_sam_user_info11\n"));
3145
3146         len_mach_acct = strlen(mach_acct);
3147
3148         memcpy(&(usr->expiry),expiry, sizeof(usr->expiry)); /* expiry time or something? */
3149         bzero(usr->padding_1, sizeof(usr->padding_1)); /* 0 - padding 24 bytes */
3150
3151         make_uni_hdr(&(usr->hdr_mach_acct), len_mach_acct, len_mach_acct, 4);  /* unicode header for machine account */
3152         usr->padding_2 = 0;               /* 0 - padding 4 bytes */
3153
3154         usr->ptr_1        = 1;            /* pointer */
3155         bzero(usr->padding_3, sizeof(usr->padding_3)); /* 0 - padding 32 bytes */
3156         usr->padding_4    = 0;            /* 0 - padding 4 bytes */
3157
3158         usr->ptr_2        = 1;            /* pointer */
3159         usr->padding_5    = 0;            /* 0 - padding 4 bytes */
3160
3161         usr->ptr_3        = 1;          /* pointer */
3162         bzero(usr->padding_6, sizeof(usr->padding_6)); /* 0 - padding 32 bytes */
3163
3164         usr->rid_user     = rid_user; 
3165         usr->rid_group    = rid_group;
3166
3167         usr->acct_ctrl    = acct_ctrl;
3168         usr->unknown_3    = 0x0000;
3169
3170         usr->unknown_4    = 0x003f;       /* 0x003f      - 16 bit unknown */
3171         usr->unknown_5    = 0x003c;       /* 0x003c      - 16 bit unknown */
3172
3173         bzero(usr->padding_7, sizeof(usr->padding_7)); /* 0 - padding 16 bytes */
3174         usr->padding_8    = 0;            /* 0 - padding 4 bytes */
3175         
3176         make_unistr2(&(usr->uni_mach_acct), mach_acct, len_mach_acct);  /* unicode string for machine account */
3177
3178         bzero(usr->padding_9, sizeof(usr->padding_9)); /* 0 - padding 48 bytes */
3179 }
3180
3181 /*******************************************************************
3182 reads or writes a structure.
3183 ********************************************************************/
3184 void sam_io_user_info11(char *desc,  SAM_USER_INFO_11 *usr, prs_struct *ps, int depth)
3185 {
3186         if (usr == NULL) return;
3187
3188         prs_debug(ps, depth, desc, "samr_io_r_unknown_24");
3189         depth++;
3190
3191         prs_align(ps);
3192
3193         prs_uint8s (False, "padding_0", ps, depth, usr->padding_0, sizeof(usr->padding_0)); 
3194
3195         smb_io_time("time", &(usr->expiry), ps, depth); 
3196
3197         prs_uint8s (False, "padding_1", ps, depth, usr->padding_1, sizeof(usr->padding_1));
3198
3199         smb_io_unihdr ("unihdr", &(usr->hdr_mach_acct), ps, depth); 
3200         prs_uint32(        "padding_2", ps, depth, &(usr->padding_2));
3201
3202         prs_uint32(        "ptr_1    ", ps, depth, &(usr->ptr_1    ));
3203         prs_uint8s (False, "padding_3", ps, depth, usr->padding_3, sizeof(usr->padding_3));
3204         prs_uint32(        "padding_4", ps, depth, &(usr->padding_4));
3205
3206         prs_uint32(        "ptr_2    ", ps, depth, &(usr->ptr_2    ));
3207         prs_uint32(        "padding_5", ps, depth, &(usr->padding_5));
3208
3209         prs_uint32(        "ptr_3    ", ps, depth, &(usr->ptr_3    ));
3210         prs_uint8s (False, "padding_6", ps, depth, usr->padding_6, sizeof(usr->padding_6));
3211
3212         prs_uint32(        "rid_user ", ps, depth, &(usr->rid_user ));
3213         prs_uint32(        "rid_group", ps, depth, &(usr->rid_group));
3214         prs_uint16(        "acct_ctrl", ps, depth, &(usr->acct_ctrl));
3215         prs_uint16(        "unknown_3", ps, depth, &(usr->unknown_3));
3216         prs_uint16(        "unknown_4", ps, depth, &(usr->unknown_4));
3217         prs_uint16(        "unknown_5", ps, depth, &(usr->unknown_5));
3218
3219         prs_uint8s (False, "padding_7", ps, depth, usr->padding_7, sizeof(usr->padding_7));
3220         prs_uint32(        "padding_8", ps, depth, &(usr->padding_8));
3221         
3222         smb_io_unistr2("unistr2", &(usr->uni_mach_acct), True, ps, depth); 
3223         prs_align(ps);
3224
3225         prs_uint8s (False, "padding_9", ps, depth, usr->padding_9, sizeof(usr->padding_9));
3226 }
3227 /*************************************************************************
3228  make_sam_user_info21
3229
3230  unknown_3 = 0x00ff ffff
3231  unknown_5 = 0x0002 0000
3232  unknown_6 = 0x0000 04ec 
3233
3234  *************************************************************************/
3235 void make_sam_user_info21(SAM_USER_INFO_21 *usr,
3236
3237         NTTIME *logon_time,
3238         NTTIME *logoff_time,
3239         NTTIME *kickoff_time,
3240         NTTIME *pass_last_set_time,
3241         NTTIME *pass_can_change_time,
3242         NTTIME *pass_must_change_time,
3243
3244         char *user_name,
3245         char *full_name,
3246         char *home_dir,
3247         char *dir_drive,
3248         char *logon_script,
3249         char *profile_path,
3250         char *description,
3251         char *workstations,
3252         char *unknown_str,
3253         char *munged_dial,
3254
3255         uint32 user_rid,
3256         uint32 group_rid,
3257         uint16 acb_info, 
3258
3259         uint32 unknown_3,
3260         uint16 logon_divs,
3261         LOGON_HRS *hrs,
3262         uint32 unknown_5,
3263         uint32 unknown_6)
3264 {
3265         int len_user_name    = user_name    != NULL ? strlen(user_name   ) : 0;
3266         int len_full_name    = full_name    != NULL ? strlen(full_name   ) : 0;
3267         int len_home_dir     = home_dir     != NULL ? strlen(home_dir    ) : 0;
3268         int len_dir_drive    = dir_drive    != NULL ? strlen(dir_drive   ) : 0;
3269         int len_logon_script = logon_script != NULL ? strlen(logon_script) : 0;
3270         int len_profile_path = profile_path != NULL ? strlen(profile_path) : 0;
3271         int len_description  = description  != NULL ? strlen(description ) : 0;
3272         int len_workstations = workstations != NULL ? strlen(workstations) : 0;
3273         int len_unknown_str  = unknown_str  != NULL ? strlen(unknown_str ) : 0;
3274         int len_munged_dial  = munged_dial  != NULL ? strlen(munged_dial ) : 0;
3275
3276         usr->logon_time            = *logon_time;
3277         usr->logoff_time           = *logoff_time;
3278         usr->kickoff_time          = *kickoff_time;
3279         usr->pass_last_set_time    = *pass_last_set_time;
3280         usr->pass_can_change_time  = *pass_can_change_time;
3281         usr->pass_must_change_time = *pass_must_change_time;
3282
3283         make_uni_hdr(&(usr->hdr_user_name   ), len_user_name   , len_user_name   , 1);
3284         make_uni_hdr(&(usr->hdr_full_name   ), len_full_name   , len_full_name   , 1);
3285         make_uni_hdr(&(usr->hdr_home_dir    ), len_home_dir    , len_home_dir    , 1);
3286         make_uni_hdr(&(usr->hdr_dir_drive   ), len_dir_drive   , len_dir_drive   , 1);
3287         make_uni_hdr(&(usr->hdr_logon_script), len_logon_script, len_logon_script, 1);
3288         make_uni_hdr(&(usr->hdr_profile_path), len_profile_path, len_profile_path, 1);
3289         make_uni_hdr(&(usr->hdr_acct_desc   ), len_description , len_description , 1);
3290         make_uni_hdr(&(usr->hdr_workstations), len_workstations, len_workstations, 1);
3291         make_uni_hdr(&(usr->hdr_unknown_str ), len_unknown_str , len_unknown_str , 1);
3292         make_uni_hdr(&(usr->hdr_munged_dial ), len_munged_dial , len_munged_dial , 1);
3293
3294         bzero(usr->nt_pwd, sizeof(usr->nt_pwd));
3295         bzero(usr->lm_pwd, sizeof(usr->lm_pwd));
3296
3297         usr->user_rid  = user_rid;
3298         usr->group_rid = group_rid;
3299         usr->acb_info = acb_info;
3300         usr->unknown_3 = unknown_3; /* 0x00ff ffff */
3301
3302         usr->logon_divs = logon_divs; /* should be 168 (hours/week) */
3303         usr->ptr_logon_hrs = hrs ? 1 : 0;
3304         usr->unknown_5 = unknown_5; /* 0x0002 0000 */
3305
3306         bzero(usr->padding1, sizeof(usr->padding1));
3307
3308         make_unistr2(&(usr->uni_user_name   ), user_name   , len_user_name   );
3309         make_unistr2(&(usr->uni_full_name   ), full_name   , len_full_name   );
3310         make_unistr2(&(usr->uni_home_dir    ), home_dir    , len_home_dir    );
3311         make_unistr2(&(usr->uni_dir_drive   ), dir_drive   , len_dir_drive   );
3312         make_unistr2(&(usr->uni_logon_script), logon_script, len_logon_script);
3313         make_unistr2(&(usr->uni_profile_path), profile_path, len_profile_path);
3314         make_unistr2(&(usr->uni_acct_desc ), description , len_description );
3315         make_unistr2(&(usr->uni_workstations), workstations, len_workstations);
3316         make_unistr2(&(usr->uni_unknown_str ), unknown_str , len_unknown_str );
3317         make_unistr2(&(usr->uni_munged_dial ), munged_dial , len_munged_dial );
3318
3319         usr->unknown_6 = unknown_6; /* 0x0000 04ec */
3320         usr->padding4 = 0;
3321
3322         if (hrs)
3323         {
3324                 memcpy(&(usr->logon_hrs), hrs, sizeof(usr->logon_hrs));
3325         }
3326         else
3327         {
3328                 memset(&(usr->logon_hrs), 0xff, sizeof(usr->logon_hrs));
3329         }
3330 }
3331
3332
3333 /*******************************************************************
3334 reads or writes a structure.
3335 ********************************************************************/
3336 static void sam_io_user_info21(char *desc,  SAM_USER_INFO_21 *usr, prs_struct *ps, int depth)
3337 {
3338         if (usr == NULL) return;
3339
3340         prs_debug(ps, depth, desc, "lsa_io_user_info");
3341         depth++;
3342
3343         prs_align(ps);
3344         
3345         smb_io_time("logon_time           ", &(usr->logon_time)           , ps, depth);
3346         smb_io_time("logoff_time          ", &(usr->logoff_time)          , ps, depth); 
3347         smb_io_time("kickoff_time         ", &(usr->kickoff_time)         , ps, depth); 
3348         smb_io_time("pass_last_set_time   ", &(usr->pass_last_set_time)   , ps, depth); 
3349         smb_io_time("pass_can_change_time ", &(usr->pass_can_change_time) , ps, depth); 
3350         smb_io_time("pass_must_change_time", &(usr->pass_must_change_time), ps, depth); 
3351
3352         smb_io_unihdr("hdr_user_name   ", &(usr->hdr_user_name)   , ps, depth); /* username unicode string header */
3353         smb_io_unihdr("hdr_full_name   ", &(usr->hdr_full_name)   , ps, depth); /* user's full name unicode string header */
3354         smb_io_unihdr("hdr_home_dir    ", &(usr->hdr_home_dir)    , ps, depth); /* home directory unicode string header */
3355         smb_io_unihdr("hdr_dir_drive   ", &(usr->hdr_dir_drive)   , ps, depth); /* home directory drive */
3356         smb_io_unihdr("hdr_logon_script", &(usr->hdr_logon_script), ps, depth); /* logon script unicode string header */
3357         smb_io_unihdr("hdr_profile_path", &(usr->hdr_profile_path), ps, depth); /* profile path unicode string header */
3358         smb_io_unihdr("hdr_acct_desc   ", &(usr->hdr_acct_desc  ) , ps, depth); /* account description */
3359         smb_io_unihdr("hdr_workstations", &(usr->hdr_workstations), ps, depth); /* workstations user can log on from */
3360         smb_io_unihdr("hdr_unknown_str ", &(usr->hdr_unknown_str ), ps, depth); /* unknown string */
3361         smb_io_unihdr("hdr_munged_dial ", &(usr->hdr_munged_dial ), ps, depth); /* workstations user can log on from */
3362
3363         prs_uint8s (False, "lm_pwd        ", ps, depth, usr->lm_pwd   , sizeof(usr->lm_pwd   ));
3364         prs_uint8s (False, "nt_pwd        ", ps, depth, usr->nt_pwd   , sizeof(usr->nt_pwd   ));
3365
3366         prs_uint32("user_rid      ", ps, depth, &(usr->user_rid     ));       /* User ID */
3367         prs_uint32("group_rid     ", ps, depth, &(usr->group_rid    ));      /* Group ID */
3368         prs_uint16("acb_info      ", ps, depth, &(usr->acb_info     ));      /* Group ID */
3369         prs_align(ps);
3370
3371         prs_uint32("unknown_3     ", ps, depth, &(usr->unknown_3    ));
3372         prs_uint16("logon_divs    ", ps, depth, &(usr->logon_divs   ));     /* logon divisions per week */
3373         prs_align(ps);
3374         prs_uint32("ptr_logon_hrs ", ps, depth, &(usr->ptr_logon_hrs));
3375         prs_uint32("unknown_5     ", ps, depth, &(usr->unknown_5    ));
3376
3377         prs_uint8s (False, "padding1      ", ps, depth, usr->padding1, sizeof(usr->padding1));
3378
3379         /* here begins pointed-to data */
3380
3381         smb_io_unistr2("uni_user_name   ", &(usr->uni_user_name)   , usr->hdr_user_name   .buffer, ps, depth); /* username unicode string */
3382         smb_io_unistr2("uni_full_name   ", &(usr->uni_full_name)   , usr->hdr_full_name   .buffer, ps, depth); /* user's full name unicode string */
3383         smb_io_unistr2("uni_home_dir    ", &(usr->uni_home_dir)    , usr->hdr_home_dir    .buffer, ps, depth); /* home directory unicode string */
3384         smb_io_unistr2("uni_dir_drive   ", &(usr->uni_dir_drive)   , usr->hdr_dir_drive   .buffer, ps, depth); /* home directory drive unicode string */
3385         smb_io_unistr2("uni_logon_script", &(usr->uni_logon_script), usr->hdr_logon_script.buffer, ps, depth); /* logon script unicode string */
3386         smb_io_unistr2("uni_profile_path", &(usr->uni_profile_path), usr->hdr_profile_path.buffer, ps, depth); /* profile path unicode string */
3387         smb_io_unistr2("uni_acct_desc   ", &(usr->uni_acct_desc   ), usr->hdr_acct_desc   .buffer, ps, depth); /* user description unicode string */
3388         smb_io_unistr2("uni_workstations", &(usr->uni_workstations), usr->hdr_workstations.buffer, ps, depth); /* worksations user can log on from */
3389         smb_io_unistr2("uni_unknown_str ", &(usr->uni_unknown_str ), usr->hdr_unknown_str .buffer, ps, depth); /* unknown string */
3390         smb_io_unistr2("uni_munged_dial ", &(usr->uni_munged_dial ), usr->hdr_munged_dial .buffer, ps, depth); /* worksations user can log on from */
3391
3392         prs_uint32("unknown_6     ", ps, depth, &(usr->unknown_6  ));
3393         prs_uint32("padding4      ", ps, depth, &(usr->padding4   ));
3394
3395         if (usr->ptr_logon_hrs)
3396         {
3397                 sam_io_logon_hrs("logon_hrs", &(usr->logon_hrs)   , ps, depth);
3398                 prs_align(ps);
3399         }
3400 }
3401
3402
3403 /*******************************************************************
3404 makes a SAMR_R_QUERY_USERINFO structure.
3405 ********************************************************************/
3406 void make_samr_r_query_userinfo(SAMR_R_QUERY_USERINFO *r_u,
3407                                 uint16 switch_value, void *info, uint32 status)
3408                                 
3409 {
3410         if (r_u == NULL || info == NULL) return;
3411
3412         DEBUG(5,("make_samr_r_query_userinfo\n"));
3413
3414         r_u->ptr = 0;
3415         r_u->switch_value = 0;
3416
3417         if (status == 0)
3418         {
3419                 r_u->switch_value = switch_value;
3420
3421                 switch (switch_value)
3422                 {
3423                         case 0x10:
3424                         {
3425                                 r_u->ptr = 1;
3426                                 r_u->info.id10 = (SAM_USER_INFO_10*)info;
3427
3428                                 break;
3429                         }
3430
3431                         case 0x11:
3432                         {
3433                                 r_u->ptr = 1;
3434                                 r_u->info.id11 = (SAM_USER_INFO_11*)info;
3435
3436                                 break;
3437                         }
3438
3439                         case 21:
3440                         {
3441                                 r_u->ptr = 1;
3442                                 r_u->info.id21 = (SAM_USER_INFO_21*)info;
3443
3444                                 break;
3445                         }
3446
3447                         default:
3448                         {
3449                                 DEBUG(4,("make_samr_r_query_userinfo: unsupported switch level\n"));
3450                                 break;
3451                         }
3452                 }
3453         }
3454
3455         r_u->status = status;         /* return status */
3456 }
3457
3458 /*******************************************************************
3459 reads or writes a structure.
3460 ********************************************************************/
3461 void samr_io_r_query_userinfo(char *desc,  SAMR_R_QUERY_USERINFO *r_u, prs_struct *ps, int depth)
3462 {
3463         if (r_u == NULL) return;
3464
3465         prs_debug(ps, depth, desc, "samr_io_r_query_userinfo");
3466         depth++;
3467
3468         prs_align(ps);
3469
3470         prs_uint32("ptr         ", ps, depth, &(r_u->ptr         ));
3471         prs_uint16("switch_value", ps, depth, &(r_u->switch_value));
3472         prs_align(ps);
3473
3474         if (r_u->ptr != 0 && r_u->switch_value != 0)
3475         {
3476                 switch (r_u->switch_value)
3477                 {
3478                         case 0x10:
3479                         {
3480                                 if (r_u->info.id10 != NULL)
3481                                 {
3482                                         sam_io_user_info10("", r_u->info.id10, ps, depth);
3483                                 }
3484                                 else
3485                                 {
3486                                         DEBUG(2,("samr_io_r_query_userinfo: info pointer not initialised\n"));
3487                                         return;
3488                                 }
3489                                 break;
3490                         }
3491 /*
3492                         case 0x11:
3493                         {
3494                                 if (r_u->info.id11 != NULL)
3495                                 {
3496                                         sam_io_user_info11("", r_u->info.id11, ps, depth);
3497                                 }
3498                                 else
3499                                 {
3500                                         DEBUG(2,("samr_io_r_query_userinfo: info pointer not initialised\n"));
3501                                         return;
3502                                 }
3503                                 break;
3504                         }
3505 */
3506                         case 21:
3507                         {
3508                                 if (r_u->info.id21 != NULL)
3509                                 {
3510                                         sam_io_user_info21("", r_u->info.id21, ps, depth);
3511                                 }
3512                                 else
3513                                 {
3514                                         DEBUG(2,("samr_io_r_query_userinfo: info pointer not initialised\n"));
3515                                         return;
3516                                 }
3517                                 break;
3518                         }
3519                         default:
3520                         {
3521                                 DEBUG(2,("samr_io_r_query_userinfo: unknown switch level\n"));
3522                                 break;
3523                         }
3524                                 
3525                 }
3526         }
3527
3528         prs_uint32("status", ps, depth, &(r_u->status));
3529 }
3530
3531 /*******************************************************************
3532 reads or writes a structure.
3533 ********************************************************************/
3534 void samr_io_q_unknown_32(char *desc,  SAMR_Q_UNKNOWN_32 *q_u, prs_struct *ps, int depth)
3535 {