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