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