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