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