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