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