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