NULL pointer handling in nt_lm_owf_gen
[samba.git] / source3 / rpc_parse / parse_samr.c
1 /* 
2  *  Unix SMB/Netbios implementation.
3  *  Version 1.9.
4  *  RPC Pipe client / server routines
5  *  Copyright (C) Andrew Tridgell              1992-1998,
6  *  Copyright (C) Luke Kenneth Casson Leighton 1996-1998,
7  *  Copyright (C) Paul Ashton                  1997-1998.
8  *  
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 2 of the License, or
12  *  (at your option) any later version.
13  *  
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *  
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, write to the Free Software
21  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  */
23
24
25 #include "includes.h"
26
27 extern int DEBUGLEVEL;
28
29
30 /*******************************************************************
31 makes a SAMR_Q_CLOSE_HND structure.
32 ********************************************************************/
33 void make_samr_q_close_hnd(SAMR_Q_CLOSE_HND *q_c, POLICY_HND *hnd)
34 {
35         if (q_c == NULL || hnd == NULL) return;
36
37         DEBUG(5,("make_samr_q_close_hnd\n"));
38
39         memcpy(&(q_c->pol), hnd, sizeof(q_c->pol));
40 }
41
42 /*******************************************************************
43 reads or writes a structure.
44 ********************************************************************/
45 void samr_io_q_close_hnd(char *desc,  SAMR_Q_CLOSE_HND *q_u, prs_struct *ps, int depth)
46 {
47         if (q_u == NULL) return;
48
49         prs_debug(ps, depth, desc, "samr_io_q_close_hnd");
50         depth++;
51
52         prs_align(ps);
53
54         smb_io_pol_hnd("pol", &(q_u->pol), ps, depth); 
55         prs_align(ps);
56 }
57
58 /*******************************************************************
59 reads or writes a structure.
60 ********************************************************************/
61 void samr_io_r_close_hnd(char *desc,  SAMR_R_CLOSE_HND *r_u, prs_struct *ps, int depth)
62 {
63         if (r_u == NULL) return;
64
65         prs_debug(ps, depth, desc, "samr_io_r_close_hnd");
66         depth++;
67
68         prs_align(ps);
69
70         smb_io_pol_hnd("pol", &(r_u->pol), ps, depth); 
71         prs_align(ps);
72
73         prs_uint32("status", ps, depth, &(r_u->status));
74 }
75
76 /*******************************************************************
77 makes a SAMR_Q_LOOKUP_DOMAIN structure.
78 ********************************************************************/
79 void make_samr_q_lookup_domain(SAMR_Q_LOOKUP_DOMAIN *q_u,
80                 POLICY_HND *pol, const char *dom_name)
81 {
82         int len_name = strlen(dom_name);
83
84         if (q_u == NULL) return;
85
86         DEBUG(5,("make_samr_q_lookup_domain\n"));
87
88         memcpy(&(q_u->connect_pol), pol, sizeof(*pol));
89
90         make_uni_hdr(&(q_u->hdr_domain), len_name);
91         make_unistr2(&(q_u->uni_domain), dom_name, len_name);
92 }
93
94 /*******************************************************************
95 reads or writes a structure.
96 ********************************************************************/
97 void samr_io_q_lookup_domain(char *desc, SAMR_Q_LOOKUP_DOMAIN *q_u, prs_struct *ps, int depth)
98 {
99         if (q_u == NULL) return;
100
101         prs_debug(ps, depth, desc, "samr_io_q_lookup_domain");
102         depth++;
103
104         prs_align(ps);
105
106         smb_io_pol_hnd("connect_pol", &(q_u->connect_pol), ps, depth);
107         prs_align(ps);
108
109         smb_io_unihdr("hdr_domain", &(q_u->hdr_domain), ps, depth);
110         smb_io_unistr2("uni_domain", &(q_u->uni_domain),
111                        q_u->hdr_domain.buffer, ps, depth);
112 }
113
114 /*******************************************************************
115 reads or writes a structure.
116 ********************************************************************/
117 void samr_io_r_lookup_domain(char *desc, SAMR_R_LOOKUP_DOMAIN *r_u, prs_struct *ps, int depth)
118 {
119         if (r_u == NULL) return;
120
121         prs_debug(ps, depth, desc, "samr_io_r_lookup_domain");
122         depth++;
123
124         prs_align(ps);
125
126         prs_uint32("ptr", ps, depth, &(r_u->ptr_sid));
127
128         if (r_u->ptr_sid != 0)
129         {
130                 smb_io_dom_sid2("sid", &(r_u->dom_sid), ps, depth);
131                 prs_align(ps);
132         }
133
134         prs_uint32("status", ps, depth, &(r_u->status));
135 }
136
137 /*******************************************************************
138 reads or writes a structure.
139 ********************************************************************/
140 void make_samr_q_open_domain(SAMR_Q_OPEN_DOMAIN *q_u,
141                                 POLICY_HND *connect_pol, uint32 flags,
142                                 DOM_SID *sid)
143 {
144         if (q_u == NULL) return;
145
146         DEBUG(5,("samr_make_samr_q_open_domain\n"));
147
148         memcpy(&q_u->connect_pol, connect_pol, sizeof(q_u->connect_pol));
149         q_u->flags = flags;
150         make_dom_sid2(&(q_u->dom_sid), sid);
151 }
152
153 /*******************************************************************
154 reads or writes a structure.
155 ********************************************************************/
156 void samr_io_q_open_domain(char *desc,  SAMR_Q_OPEN_DOMAIN *q_u, prs_struct *ps, int depth)
157 {
158         if (q_u == NULL) return;
159
160         prs_debug(ps, depth, desc, "samr_io_q_open_domain");
161         depth++;
162
163         prs_align(ps);
164
165         smb_io_pol_hnd("connect_pol", &(q_u->connect_pol), ps, depth); 
166         prs_align(ps);
167
168         prs_uint32("flags", ps, depth, &(q_u->flags));
169
170         smb_io_dom_sid2("sid", &(q_u->dom_sid), ps, depth); 
171         prs_align(ps);
172 }
173
174
175 /*******************************************************************
176 reads or writes a structure.
177 ********************************************************************/
178 void samr_io_r_open_domain(char *desc,  SAMR_R_OPEN_DOMAIN *r_u, prs_struct *ps, int depth)
179 {
180         if (r_u == NULL) return;
181
182         prs_debug(ps, depth, desc, "samr_io_r_open_domain");
183         depth++;
184
185         prs_align(ps);
186
187         smb_io_pol_hnd("domain_pol", &(r_u->domain_pol), ps, depth); 
188         prs_align(ps);
189
190         prs_uint32("status", ps, depth, &(r_u->status));
191 }
192
193 /*******************************************************************
194 reads or writes a structure.
195 ********************************************************************/
196 void make_samr_q_unknown_2c(SAMR_Q_UNKNOWN_2C *q_u, POLICY_HND *user_pol)
197 {
198         if (q_u == NULL) return;
199
200         DEBUG(5,("samr_make_samr_q_unknown_2c\n"));
201
202         memcpy(&q_u->user_pol, user_pol, sizeof(q_u->user_pol));
203 }
204
205
206 /*******************************************************************
207 reads or writes a structure.
208 ********************************************************************/
209 void samr_io_q_unknown_2c(char *desc,  SAMR_Q_UNKNOWN_2C *q_u, prs_struct *ps, int depth)
210 {
211         if (q_u == NULL) return;
212
213         prs_debug(ps, depth, desc, "samr_io_q_unknown_2c");
214         depth++;
215
216         prs_align(ps);
217
218         smb_io_pol_hnd("user_pol", &(q_u->user_pol), ps, depth); 
219         prs_align(ps);
220 }
221
222 /*******************************************************************
223 makes a structure.
224 ********************************************************************/
225 void make_samr_r_unknown_2c(SAMR_R_UNKNOWN_2C *q_u, uint32 status)
226 {
227         if (q_u == NULL) return;
228
229         DEBUG(5,("samr_make_r_unknown_2c\n"));
230
231         q_u->unknown_0 = 0x00160000;
232         q_u->unknown_1 = 0x00000000;
233         q_u->status    = status;
234 }
235
236
237 /*******************************************************************
238 reads or writes a structure.
239 ********************************************************************/
240 void samr_io_r_unknown_2c(char *desc,  SAMR_R_UNKNOWN_2C *r_u, prs_struct *ps, int depth)
241 {
242         if (r_u == NULL) return;
243
244         prs_debug(ps, depth, desc, "samr_io_r_unknown_2c");
245         depth++;
246
247         prs_align(ps);
248
249         prs_uint32("unknown_0", ps, depth, &(r_u->unknown_0));
250         prs_uint32("unknown_1", ps, depth, &(r_u->unknown_1));
251         prs_uint32("status   ", ps, depth, &(r_u->status   ));
252 }
253
254 /*******************************************************************
255 reads or writes a structure.
256 ********************************************************************/
257 void make_samr_q_unknown_3(SAMR_Q_UNKNOWN_3 *q_u,
258                                 POLICY_HND *user_pol, uint16 switch_value)
259 {
260         if (q_u == NULL) return;
261
262         DEBUG(5,("samr_make_samr_q_unknown_3\n"));
263
264         memcpy(&q_u->user_pol, user_pol, sizeof(q_u->user_pol));
265         q_u->switch_value = switch_value;
266 }
267
268
269 /*******************************************************************
270 reads or writes a structure.
271 ********************************************************************/
272 void samr_io_q_unknown_3(char *desc,  SAMR_Q_UNKNOWN_3 *q_u, prs_struct *ps, int depth)
273 {
274         if (q_u == NULL) return;
275
276         prs_debug(ps, depth, desc, "samr_io_q_unknown_3");
277         depth++;
278
279         prs_align(ps);
280
281         smb_io_pol_hnd("user_pol", &(q_u->user_pol), ps, depth); 
282         prs_align(ps);
283
284         prs_uint16("switch_value", ps, depth, &(q_u->switch_value));
285         prs_align(ps);
286 }
287
288 /*******************************************************************
289 reads or writes a structure.
290 ********************************************************************/
291 void make_samr_q_query_dom_info(SAMR_Q_QUERY_DOMAIN_INFO *q_u,
292                                 POLICY_HND *domain_pol, uint16 switch_value)
293 {
294         if (q_u == NULL) return;
295
296         DEBUG(5,("samr_make_samr_q_query_dom_info\n"));
297
298         memcpy(&q_u->domain_pol, domain_pol, sizeof(q_u->domain_pol));
299         q_u->switch_value = switch_value;
300 }
301
302 /*******************************************************************
303 reads or writes a structure.
304 ********************************************************************/
305 void samr_io_q_query_dom_info(char *desc,  SAMR_Q_QUERY_DOMAIN_INFO *q_u, prs_struct *ps, int depth)
306 {
307         if (q_u == NULL) return;
308
309         prs_debug(ps, depth, desc, "samr_io_q_query_dom_info");
310         depth++;
311
312         prs_align(ps);
313
314         smb_io_pol_hnd("domain_pol", &(q_u->domain_pol), ps, depth); 
315         prs_align(ps);
316
317         prs_uint16("switch_value", ps, depth, &(q_u->switch_value));
318         prs_align(ps);
319 }
320
321
322 /*******************************************************************
323 makes a structure.
324 ********************************************************************/
325 void make_unk_info6(SAM_UNK_INFO_6 *u_6)
326 {
327         if (u_6 == NULL) return;
328
329         u_6->unknown_0 = 0x00000000;
330         u_6->ptr_0 = 1;
331         memset(u_6->padding, 0, sizeof(u_6->padding)); /* 12 bytes zeros */
332 }
333
334 /*******************************************************************
335 reads or writes a structure.
336 ********************************************************************/
337 void sam_io_unk_info6(char *desc, SAM_UNK_INFO_6 *u_6, prs_struct *ps, int depth)
338 {
339         if (u_6 == NULL) return;
340
341         prs_debug(ps, depth, desc, "sam_io_unk_info6");
342         depth++;
343
344         prs_uint32("unknown_0", ps, depth, &u_6->unknown_0); /* 0x0000 0000 */
345         prs_uint32("ptr_0", ps, depth, &u_6->ptr_0);     /* pointer to unknown structure */
346         prs_uint8s(False, "padding", ps, depth, u_6->padding, sizeof(u_6->padding)); /* 12 bytes zeros */
347
348         prs_align(ps);
349
350 }
351
352 /*******************************************************************
353 makes a structure.
354 ********************************************************************/
355 void make_unk_info7(SAM_UNK_INFO_7 *u_7)
356 {
357         if (u_7 == NULL) return;
358
359         u_7->unknown_0 = 0x0003;
360 }
361
362 /*******************************************************************
363 reads or writes a structure.
364 ********************************************************************/
365 void sam_io_unk_info7(char *desc, SAM_UNK_INFO_7 *u_7, prs_struct *ps, int depth)
366 {
367         if (u_7 == NULL) return;
368
369         prs_debug(ps, depth, desc, "sam_io_unk_info7");
370         depth++;
371
372         prs_uint16("unknown_0", ps, depth, &u_7->unknown_0); /* 0x0003 */
373         prs_align(ps);
374
375 }
376
377 /*******************************************************************
378 makes a structure.
379 ********************************************************************/
380 void make_unk_info2(SAM_UNK_INFO_2 *u_2, char *domain, char *server)
381 {
382         int len_domain = strlen(domain);
383         int len_server = strlen(server);
384
385         if (u_2 == NULL) return;
386
387         u_2->unknown_0 = 0x00000000;
388         u_2->unknown_1 = 0x80000000;
389         u_2->unknown_2 = 0x00000000;
390
391         u_2->ptr_0 = 1;
392         make_uni_hdr(&(u_2->hdr_domain), len_domain);
393         make_uni_hdr(&(u_2->hdr_server), len_server);
394
395         u_2->seq_num = 0x10000000;
396         u_2->unknown_3 = 0x00000000;
397         
398         u_2->unknown_4  = 0x00000001;
399         u_2->unknown_5  = 0x00000003;
400         u_2->unknown_6  = 0x00000001;
401         u_2->num_domain_usrs  = MAX_SAM_ENTRIES;
402         u_2->num_domain_grps = MAX_SAM_ENTRIES;
403         u_2->num_local_grps = MAX_SAM_ENTRIES;
404
405         memset(u_2->padding, 0, sizeof(u_2->padding)); /* 12 bytes zeros */
406
407         make_unistr2(&u_2->uni_domain, domain, len_domain);
408         make_unistr2(&u_2->uni_server, server, len_server);
409 }
410
411 /*******************************************************************
412 reads or writes a structure.
413 ********************************************************************/
414 void sam_io_unk_info2(char *desc, SAM_UNK_INFO_2 *u_2, prs_struct *ps, int depth)
415 {
416         if (u_2 == NULL) return;
417
418         prs_debug(ps, depth, desc, "sam_io_unk_info2");
419         depth++;
420
421         prs_uint32("unknown_0", ps, depth, &u_2->unknown_0); /* 0x0000 0000 */
422         prs_uint32("unknown_1", ps, depth, &u_2->unknown_1); /* 0x8000 0000 */
423         prs_uint32("unknown_2", ps, depth, &u_2->unknown_2); /* 0x0000 0000 */
424
425         prs_uint32("ptr_0", ps, depth, &u_2->ptr_0);     /* pointer to unknown structure */
426         smb_io_unihdr("hdr_domain", &u_2->hdr_domain, ps, depth); /* domain name unicode header */
427         smb_io_unihdr("hdr_server", &u_2->hdr_server, ps, depth); /* server name unicode header */
428
429         /* put all the data in here, at the moment, including what the above
430            pointer is referring to
431          */
432
433         prs_uint32("seq_num ", ps, depth, &u_2->seq_num ); /* 0x0000 0099 or 0x1000 0000 */
434         prs_uint32("unknown_3 ", ps, depth, &u_2->unknown_3 ); /* 0x0000 0000 */
435         
436         prs_uint32("unknown_4 ", ps, depth, &u_2->unknown_4 ); /* 0x0000 0001 */
437         prs_uint32("unknown_5 ", ps, depth, &u_2->unknown_5 ); /* 0x0000 0003 */
438         prs_uint32("unknown_6 ", ps, depth, &u_2->unknown_6 ); /* 0x0000 0001 */
439         prs_uint32("num_domain_usrs ", ps, depth, &u_2->num_domain_usrs ); /* 0x0000 0008 */
440         prs_uint32("num_domain_grps", ps, depth, &u_2->num_domain_grps); /* 0x0000 0003 */
441         prs_uint32("num_local_grps", ps, depth, &u_2->num_local_grps); /* 0x0000 0003 */
442
443         prs_uint8s(False, "padding", ps, depth, u_2->padding, sizeof(u_2->padding)); /* 12 bytes zeros */
444
445         smb_io_unistr2( "uni_domain", &u_2->uni_domain, u_2->hdr_domain.buffer, ps, depth); /* domain name unicode string */
446         smb_io_unistr2( "uni_server", &u_2->uni_server, u_2->hdr_server.buffer, ps, depth); /* server name unicode string */
447
448         prs_align(ps);
449
450 }
451
452 /*******************************************************************
453 makes a 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);
762         make_uni_hdr(&(sam->hdr_user_name), len_sam_full);
763         make_uni_hdr(&(sam->hdr_user_desc), len_sam_desc);
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);
822         make_uni_hdr(&(sam->hdr_srv_desc), len_sam_desc);
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);
878         make_uni_hdr(&(sam->hdr_grp_desc), len_grp_desc);
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);
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         r_u->next_idx = next_idx;
1051         r_u->sam = NULL;
1052         r_u->uni_acct_name = NULL;
1053
1054         if (num_sam_entries != 0)
1055         {
1056                 r_u->ptr_entries1 = 1;
1057                 r_u->ptr_entries2 = 1;
1058                 r_u->num_entries2 = num_sam_entries;
1059                 r_u->num_entries3 = num_sam_entries;
1060
1061                 r_u->sam = Realloc(NULL, r_u->num_entries2 * sizeof(r_u->sam[0]));
1062                 r_u->uni_acct_name = Realloc(NULL, r_u->num_entries2 * sizeof(r_u->uni_acct_name[0]));
1063
1064                 if (r_u->sam == NULL || r_u->uni_acct_name == NULL)
1065                 {
1066                         DEBUG(0,("NULL pointers in SAMR_R_QUERY_DISPINFO\n"));
1067                         return;
1068                 }
1069
1070                 for (i = 0; i < num_sam_entries; i++)
1071                 {
1072                         make_sam_entry(&(r_u->sam[i]),
1073                                        pass[i].uni_user_name.uni_str_len,
1074                                        pass[i].user_rid);
1075
1076                         copy_unistr2(&(r_u->uni_acct_name[i]), &(pass[i].uni_user_name));
1077                 }
1078
1079                 r_u->num_entries4 = num_sam_entries;
1080         }
1081         else
1082         {
1083                 r_u->ptr_entries1 = 0;
1084                 r_u->num_entries2 = num_sam_entries;
1085                 r_u->ptr_entries2 = 1;
1086         }
1087
1088         r_u->status = status;
1089 }
1090
1091 /*******************************************************************
1092 reads or writes a structure.
1093 ********************************************************************/
1094 void samr_io_r_enum_dom_users(char *desc,  SAMR_R_ENUM_DOM_USERS *r_u, prs_struct *ps, int depth)
1095 {
1096         int i;
1097
1098         if (r_u == NULL) return;
1099
1100         prs_debug(ps, depth, desc, "samr_io_r_enum_dom_users");
1101         depth++;
1102
1103         prs_align(ps);
1104
1105         prs_uint32("next_idx    ", ps, depth, &(r_u->next_idx    ));
1106         prs_uint32("ptr_entries1", ps, depth, &(r_u->ptr_entries1));
1107
1108         if (r_u->ptr_entries1 != 0)
1109         {
1110                 prs_uint32("num_entries2", ps, depth, &(r_u->num_entries2));
1111                 prs_uint32("ptr_entries2", ps, depth, &(r_u->ptr_entries2));
1112                 prs_uint32("num_entries3", ps, depth, &(r_u->num_entries3));
1113
1114                 if (ps->io)
1115                 {
1116                         r_u->sam = Realloc(NULL, r_u->num_entries2 * sizeof(r_u->sam[0]));
1117                         r_u->uni_acct_name = Realloc(NULL, r_u->num_entries2 * sizeof(r_u->uni_acct_name[0]));
1118                 }
1119
1120                 if ((r_u->sam == NULL || r_u->uni_acct_name == NULL) && r_u->num_entries2 != 0)
1121                 {
1122                         DEBUG(0,("NULL pointers in SAMR_R_QUERY_DISPINFO\n"));
1123                         return;
1124                 }
1125
1126                 for (i = 0; i < r_u->num_entries2; i++)
1127                 {
1128                         prs_grow(ps);
1129                         sam_io_sam_entry("", &(r_u->sam[i]), ps, depth);
1130                 }
1131
1132                 for (i = 0; i < r_u->num_entries2; i++)
1133                 {
1134                         prs_grow(ps);
1135                         smb_io_unistr2("", &(r_u->uni_acct_name[i]), r_u->sam[i].hdr_name.buffer, ps, depth);
1136                 }
1137
1138                 prs_align(ps);
1139
1140         }
1141
1142         prs_uint32("num_entries4", ps, depth, &(r_u->num_entries4));
1143         prs_uint32("status", ps, depth, &(r_u->status));
1144 }
1145
1146 /*******************************************************************
1147 makes a SAMR_Q_QUERY_DISPINFO structure.
1148 ********************************************************************/
1149 void make_samr_q_query_dispinfo(SAMR_Q_QUERY_DISPINFO *q_e, POLICY_HND *pol,
1150                                 uint16 switch_level, uint32 start_idx,
1151                                 uint32 max_entries)
1152 {
1153         if (q_e == NULL || pol == NULL) return;
1154
1155         DEBUG(5,("make_samr_q_query_dispinfo\n"));
1156
1157         memcpy(&(q_e->domain_pol), pol, sizeof(*pol));
1158
1159         q_e->switch_level = switch_level;
1160
1161         q_e->start_idx = start_idx;
1162         q_e->max_entries = max_entries;
1163         q_e->max_size = 0xffff; /* Not especially useful */
1164 }
1165
1166 /*******************************************************************
1167 reads or writes a structure.
1168 ********************************************************************/
1169 void samr_io_q_query_dispinfo(char *desc,  SAMR_Q_QUERY_DISPINFO *q_e, prs_struct *ps, int depth)
1170 {
1171         if (q_e == NULL) return;
1172
1173         prs_debug(ps, depth, desc, "samr_io_q_query_dispinfo");
1174         depth++;
1175
1176         prs_align(ps);
1177
1178         smb_io_pol_hnd("domain_pol", &(q_e->domain_pol), ps, depth); 
1179         prs_align(ps);
1180
1181         prs_uint16("switch_level", ps, depth, &(q_e->switch_level));
1182         prs_align(ps);
1183
1184         prs_uint32("start_idx   ", ps, depth, &(q_e->start_idx   ));
1185         prs_uint32("max_entries ", ps, depth, &(q_e->max_entries ));
1186         prs_uint32("max_size    ", ps, depth, &(q_e->max_size    ));
1187 }
1188
1189
1190 /*******************************************************************
1191 makes a SAM_DISPINFO_1 structure.
1192 ********************************************************************/
1193 void make_sam_dispinfo_1(SAM_DISPINFO_1 *sam, uint32 *num_entries,
1194                          uint32 *data_size, uint32 start_idx,
1195                          SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES])
1196 {
1197         uint32 len_sam_name, len_sam_full, len_sam_desc;
1198         uint32 max_entries, max_data_size;
1199         uint32 dsize = 0;
1200         int i;
1201
1202         if (sam == NULL || num_entries == NULL || data_size == NULL) return;
1203
1204         DEBUG(5,("make_sam_dispinfo_1\n"));
1205
1206         max_entries = *num_entries;
1207         max_data_size = *data_size;
1208
1209         for (i = 0; (i < max_entries) && (dsize < max_data_size); i++)
1210         {
1211                 len_sam_name = pass[i].uni_user_name.uni_str_len;
1212                 len_sam_full = pass[i].uni_full_name.uni_str_len;
1213                 len_sam_desc = pass[i].uni_acct_desc.uni_str_len;
1214
1215                 make_sam_entry1(&(sam->sam[i]), start_idx + i + 1,
1216                                 len_sam_name, len_sam_full, len_sam_desc,
1217                                 pass[i].user_rid, pass[i].acb_info);
1218
1219                 copy_unistr2(&(sam->str[i].uni_acct_name), &(pass[i].uni_user_name));
1220                 copy_unistr2(&(sam->str[i].uni_full_name), &(pass[i].uni_full_name));
1221                 copy_unistr2(&(sam->str[i].uni_acct_desc), &(pass[i].uni_acct_desc));
1222
1223                 dsize += sizeof(SAM_ENTRY1);
1224                 dsize += len_sam_name + len_sam_full + len_sam_desc;
1225         }
1226
1227         *num_entries = i;
1228         *data_size = dsize;
1229 }
1230
1231 /*******************************************************************
1232 reads or writes a structure.
1233 ********************************************************************/
1234 static void sam_io_sam_dispinfo_1(char *desc, SAM_DISPINFO_1 *sam, uint32 num_entries, prs_struct *ps, int depth)
1235 {
1236         int i;
1237
1238         if (sam == NULL) return;
1239
1240         prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_1");
1241         depth++;
1242
1243         prs_align(ps);
1244
1245         SMB_ASSERT_ARRAY(sam->sam, num_entries);
1246
1247         for (i = 0; i < num_entries; i++)
1248         {
1249                 prs_grow(ps);
1250                 sam_io_sam_entry1("", &(sam->sam[i]), ps, depth);
1251         }
1252
1253         for (i = 0; i < num_entries; i++)
1254         {
1255                 prs_grow(ps);
1256                 sam_io_sam_str1 ("", &(sam->str[i]),
1257                                  sam->sam[i].hdr_acct_name.buffer,
1258                                  sam->sam[i].hdr_user_name.buffer,
1259                                  sam->sam[i].hdr_user_desc.buffer,
1260                                  ps, depth);
1261         }
1262 }
1263
1264
1265 /*******************************************************************
1266 makes a SAM_DISPINFO_2 structure.
1267 ********************************************************************/
1268 void make_sam_dispinfo_2(SAM_DISPINFO_2 *sam, uint32 *num_entries,
1269                          uint32 *data_size, uint32 start_idx,
1270                          SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES])
1271 {
1272         uint32 len_sam_name, len_sam_desc;
1273         uint32 max_entries, max_data_size;
1274         uint32 dsize = 0;
1275         int i;
1276
1277         if (sam == NULL || num_entries == NULL || data_size == NULL) return;
1278
1279         DEBUG(5,("make_sam_dispinfo_2\n"));
1280
1281         max_entries = *num_entries;
1282         max_data_size = *data_size;
1283
1284         for (i = 0; (i < max_entries) && (dsize < max_data_size); i++)
1285         {
1286                 len_sam_name = pass[i].uni_user_name.uni_str_len;
1287                 len_sam_desc = pass[i].uni_acct_desc.uni_str_len;
1288
1289                 make_sam_entry2(&(sam->sam[i]), start_idx + i + 1,
1290                                 len_sam_name, len_sam_desc,
1291                                 pass[i].user_rid, pass[i].acb_info);
1292
1293                 copy_unistr2(&(sam->str[i].uni_srv_name), &(pass[i].uni_user_name));
1294                 copy_unistr2(&(sam->str[i].uni_srv_desc), &(pass[i].uni_acct_desc));
1295
1296                 dsize += sizeof(SAM_ENTRY2);
1297                 dsize += len_sam_name + len_sam_desc;
1298         }
1299
1300         *num_entries = i;
1301         *data_size = dsize;
1302 }
1303
1304 /*******************************************************************
1305 reads or writes a structure.
1306 ********************************************************************/
1307 static void sam_io_sam_dispinfo_2(char *desc, SAM_DISPINFO_2 *sam, uint32 num_entries, prs_struct *ps, int depth)
1308 {
1309         int i;
1310
1311         if (sam == NULL) return;
1312
1313         prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_2");
1314         depth++;
1315
1316         prs_align(ps);
1317
1318         SMB_ASSERT_ARRAY(sam->sam, num_entries);
1319
1320         for (i = 0; i < num_entries; i++)
1321         {
1322                 prs_grow(ps);
1323                 sam_io_sam_entry2("", &(sam->sam[i]), ps, depth);
1324         }
1325
1326         for (i = 0; i < num_entries; i++)
1327         {
1328                 prs_grow(ps);
1329                 sam_io_sam_str2 ("", &(sam->str[i]),
1330                                  sam->sam[i].hdr_srv_name.buffer,
1331                                  sam->sam[i].hdr_srv_desc.buffer,
1332                                  ps, depth);
1333         }
1334 }
1335
1336
1337 /*******************************************************************
1338 makes a SAM_DISPINFO_3 structure.
1339 ********************************************************************/
1340 void make_sam_dispinfo_3(SAM_DISPINFO_3 *sam, uint32 *num_entries,
1341                          uint32 *data_size, uint32 start_idx,
1342                          DOMAIN_GRP *grp)
1343 {
1344         uint32 len_sam_name, len_sam_desc;
1345         uint32 max_entries, max_data_size;
1346         uint32 dsize = 0;
1347         int i;
1348
1349         if (sam == NULL || num_entries == NULL || data_size == NULL) return;
1350
1351         DEBUG(5,("make_sam_dispinfo_3\n"));
1352
1353         max_entries = *num_entries;
1354         max_data_size = *data_size;
1355
1356         for (i = 0; (i < max_entries) && (dsize < max_data_size); i++)
1357         {
1358                 len_sam_name = strlen(grp[i].name);
1359                 len_sam_desc = strlen(grp[i].comment);
1360
1361                 make_sam_entry3(&(sam->sam[i]), start_idx + i + 1,
1362                                 len_sam_name, len_sam_desc,
1363                                 grp[i].rid);
1364
1365                 make_unistr2(&(sam->str[i].uni_grp_name), grp[i].name   , len_sam_name);
1366                 make_unistr2(&(sam->str[i].uni_grp_desc), grp[i].comment, len_sam_desc);
1367
1368                 dsize += sizeof(SAM_ENTRY3);
1369                 dsize += (len_sam_name + len_sam_desc) * 2;
1370         }
1371
1372         *num_entries = i;
1373         *data_size = dsize;
1374 }
1375
1376 /*******************************************************************
1377 reads or writes a structure.
1378 ********************************************************************/
1379 static void sam_io_sam_dispinfo_3(char *desc, SAM_DISPINFO_3 *sam, int num_entries, prs_struct *ps, int depth)
1380 {
1381         int i;
1382
1383         if (sam == NULL) return;
1384
1385         prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_3");
1386         depth++;
1387
1388         prs_align(ps);
1389
1390         SMB_ASSERT_ARRAY(sam->sam, num_entries);
1391
1392         for (i = 0; i < num_entries; i++)
1393         {
1394                 prs_grow(ps);
1395                 sam_io_sam_entry3("", &(sam->sam[i]), ps, depth);
1396         }
1397
1398         for (i = 0; i < num_entries; i++)
1399         {
1400                 prs_grow(ps);
1401                 sam_io_sam_str3 ("", &(sam->str[i]),
1402                                  sam->sam[i].hdr_grp_name.buffer,
1403                                  sam->sam[i].hdr_grp_desc.buffer,
1404                                  ps, depth);
1405         }
1406 }
1407
1408
1409 /*******************************************************************
1410 makes a SAM_DISPINFO_4 structure.
1411 ********************************************************************/
1412 void make_sam_dispinfo_4(SAM_DISPINFO_4 *sam, uint32 *num_entries,
1413                          uint32 *data_size, uint32 start_idx,
1414                          SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES])
1415 {
1416         fstring sam_name;
1417         uint32 len_sam_name;
1418         uint32 max_entries, max_data_size;
1419         uint32 dsize = 0;
1420         int i;
1421
1422         if (sam == NULL || num_entries == NULL || data_size == NULL) return;
1423
1424         DEBUG(5,("make_sam_dispinfo_4\n"));
1425
1426         max_entries = *num_entries;
1427         max_data_size = *data_size;
1428
1429         for (i = 0; (i < max_entries) && (dsize < max_data_size); i++)
1430         {
1431                 len_sam_name = pass[i].uni_user_name.uni_str_len;
1432
1433                 make_sam_entry4(&(sam->sam[i]), start_idx + i + 1,
1434                                 len_sam_name);
1435
1436                 unistr2_to_ascii(sam_name, &(pass[i].uni_user_name), sizeof(sam_name));
1437                 make_string2(&(sam->str[i].acct_name), sam_name, len_sam_name);
1438
1439                 dsize += sizeof(SAM_ENTRY4);
1440                 dsize += len_sam_name;
1441         }
1442
1443         *num_entries = i;
1444         *data_size = dsize;
1445 }
1446
1447 /*******************************************************************
1448 reads or writes a structure.
1449 ********************************************************************/
1450 static void sam_io_sam_dispinfo_4(char *desc, SAM_DISPINFO_4 *sam, int num_entries, prs_struct *ps, int depth)
1451 {
1452         int i;
1453
1454         if (sam == NULL) return;
1455
1456         prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_4");
1457         depth++;
1458
1459         prs_align(ps);
1460
1461         SMB_ASSERT_ARRAY(sam->sam, num_entries);
1462
1463         for (i = 0; i < num_entries; i++)
1464         {
1465                 prs_grow(ps);
1466                 sam_io_sam_entry4("", &(sam->sam[i]), ps, depth);
1467         }
1468
1469         for (i = 0; i < num_entries; i++)
1470         {
1471                 prs_grow(ps);
1472                 smb_io_string2("acct_name", &(sam->str[i].acct_name),
1473                                sam->sam[i].hdr_acct_name.buffer, ps, depth);
1474         }
1475 }
1476
1477
1478 /*******************************************************************
1479 makes a SAM_DISPINFO_5 structure.
1480 ********************************************************************/
1481 void make_sam_dispinfo_5(SAM_DISPINFO_5 *sam, uint32 *num_entries,
1482                          uint32 *data_size, uint32 start_idx,
1483                          DOMAIN_GRP *grp)
1484 {
1485         uint32 len_sam_name;
1486         uint32 max_entries, max_data_size;
1487         uint32 dsize = 0;
1488         int i;
1489
1490         if (sam == NULL || num_entries == NULL || data_size == NULL) return;
1491
1492         DEBUG(5,("make_sam_dispinfo_5\n"));
1493
1494         max_entries = *num_entries;
1495         max_data_size = *data_size;
1496
1497         for (i = 0; (i < max_entries) && (dsize < max_data_size); i++)
1498         {
1499                 len_sam_name = strlen(grp[i].name);
1500
1501                 make_sam_entry5(&(sam->sam[i]), start_idx + i + 1,
1502                                 len_sam_name);
1503
1504                 make_string2(&(sam->str[i].grp_name), grp[i].name,
1505                              len_sam_name);
1506
1507                 dsize += sizeof(SAM_ENTRY5);
1508                 dsize += len_sam_name;
1509         }
1510
1511         *num_entries = i;
1512         *data_size = dsize;
1513 }
1514
1515 /*******************************************************************
1516 reads or writes a structure.
1517 ********************************************************************/
1518 static void sam_io_sam_dispinfo_5(char *desc, SAM_DISPINFO_5 *sam, int num_entries, prs_struct *ps, int depth)
1519 {
1520         int i;
1521
1522         if (sam == NULL) return;
1523
1524         prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_5");
1525         depth++;
1526
1527         prs_align(ps);
1528
1529         SMB_ASSERT_ARRAY(sam->sam, num_entries);
1530
1531         for (i = 0; i < num_entries; i++)
1532         {
1533                 prs_grow(ps);
1534                 sam_io_sam_entry5("", &(sam->sam[i]), ps, depth);
1535         }
1536
1537         for (i = 0; i < num_entries; i++)
1538         {
1539                 prs_grow(ps);
1540                 smb_io_string2("grp_name", &(sam->str[i].grp_name),
1541                                sam->sam[i].hdr_grp_name.buffer, ps, depth);
1542         }
1543 }
1544
1545
1546 /*******************************************************************
1547 makes a SAMR_R_QUERY_DISPINFO structure.
1548 ********************************************************************/
1549 void make_samr_r_query_dispinfo(SAMR_R_QUERY_DISPINFO *r_u,
1550                                 uint32 num_entries, uint32 data_size,
1551                                 uint16 switch_level, SAM_DISPINFO_CTR *ctr,
1552                                 uint32 status)
1553 {
1554         if (r_u == NULL) return;
1555
1556         DEBUG(5,("make_samr_r_query_dispinfo: level %d\n", switch_level));
1557
1558         r_u->total_size = 0; /* not calculated */
1559         r_u->data_size = data_size;
1560
1561         r_u->switch_level = switch_level;
1562         r_u->num_entries = num_entries;
1563         r_u->ptr_entries = 1;
1564         r_u->num_entries2 = num_entries;
1565         r_u->ctr = ctr;
1566
1567         r_u->status = status;
1568 }
1569
1570
1571 /*******************************************************************
1572 reads or writes a structure.
1573 ********************************************************************/
1574 void samr_io_r_query_dispinfo(char *desc, SAMR_R_QUERY_DISPINFO *r_u, prs_struct *ps, int depth)
1575 {
1576         if (r_u == NULL) return;
1577
1578         prs_debug(ps, depth, desc, "samr_io_r_query_dispinfo");
1579         depth++;
1580
1581         prs_align(ps);
1582
1583         prs_uint32("total_size  ", ps, depth, &(r_u->total_size  ));
1584         prs_uint32("data_size   ", ps, depth, &(r_u->data_size   ));
1585         prs_uint16("switch_level", ps, depth, &(r_u->switch_level));
1586         prs_align(ps);
1587
1588         prs_uint32("num_entries ", ps, depth, &(r_u->num_entries ));
1589         prs_uint32("ptr_entries ", ps, depth, &(r_u->ptr_entries ));
1590         prs_uint32("num_entries2", ps, depth, &(r_u->num_entries2));
1591
1592         switch (r_u->switch_level)
1593         {
1594                 case 0x1:
1595                 {
1596                         sam_io_sam_dispinfo_1("users", r_u->ctr->sam.info1, r_u->num_entries, ps, depth);
1597                         break;
1598                 }
1599                 case 0x2:
1600                 {
1601                         sam_io_sam_dispinfo_2("servers", r_u->ctr->sam.info2, r_u->num_entries, ps, depth);
1602                         break;
1603                 }
1604                 case 0x3:
1605                 {
1606                         sam_io_sam_dispinfo_3("groups", r_u->ctr->sam.info3, r_u->num_entries, ps, depth);
1607                         break;
1608                 }
1609                 case 0x4:
1610                 {
1611                         sam_io_sam_dispinfo_4("user list", r_u->ctr->sam.info4,r_u->num_entries, ps, depth);
1612                         break;
1613                 }
1614                 case 0x5:
1615                 {
1616                         sam_io_sam_dispinfo_5("group list", r_u->ctr->sam.info5, r_u->num_entries, ps, depth);
1617                         break;
1618                 }
1619                 default:
1620                 {
1621                         DEBUG(5,("samr_io_r_query_dispinfo: unknown switch value\n"));
1622                         break;
1623                 }
1624         }
1625
1626         prs_align(ps);
1627         prs_align(ps);
1628         prs_uint32("status", ps, depth, &(r_u->status));
1629 }
1630
1631
1632 /*******************************************************************
1633 makes a SAMR_Q_OPEN_GROUP structure.
1634 ********************************************************************/
1635 void make_samr_q_open_group(SAMR_Q_OPEN_GROUP *q_c,
1636                                 POLICY_HND *hnd, uint32 unk, uint32 rid)
1637 {
1638         if (q_c == NULL || hnd == NULL) return;
1639
1640         DEBUG(5,("make_samr_q_open_group\n"));
1641
1642         memcpy(&(q_c->domain_pol), hnd, sizeof(q_c->domain_pol));
1643         q_c->unknown = unk;
1644         q_c->rid_group = rid;
1645 }
1646
1647 /*******************************************************************
1648 reads or writes a structure.
1649 ********************************************************************/
1650 void samr_io_q_open_group(char *desc,  SAMR_Q_OPEN_GROUP *q_u, prs_struct *ps, int depth)
1651 {
1652         if (q_u == NULL) return;
1653
1654         prs_debug(ps, depth, desc, "samr_io_q_open_group");
1655         depth++;
1656
1657         prs_align(ps);
1658
1659         smb_io_pol_hnd("domain_pol", &(q_u->domain_pol), ps, depth); 
1660
1661         prs_uint32("unknown  ", ps, depth, &(q_u->unknown  ));
1662         prs_uint32("rid_group", ps, depth, &(q_u->rid_group));
1663 }
1664
1665 /*******************************************************************
1666 reads or writes a structure.
1667 ********************************************************************/
1668 void samr_io_r_open_group(char *desc,  SAMR_R_OPEN_GROUP *r_u, prs_struct *ps, int depth)
1669 {
1670         if (r_u == NULL) return;
1671
1672         prs_debug(ps, depth, desc, "samr_io_r_open_group");
1673         depth++;
1674
1675         prs_align(ps);
1676
1677         smb_io_pol_hnd("pol", &(r_u->pol), ps, depth); 
1678         prs_align(ps);
1679
1680         prs_uint32("status", ps, depth, &(r_u->status));
1681 }
1682
1683
1684 /*******************************************************************
1685 makes a GROUP_INFO1 structure.
1686 ********************************************************************/
1687 void make_samr_group_info1(GROUP_INFO1 *gr1,
1688                                 char *acct_name, char *acct_desc)
1689 {
1690         int desc_len = acct_desc != NULL ? strlen(acct_desc) : 0;
1691         int acct_len = acct_name != NULL ? strlen(acct_name) : 0;
1692         if (gr1 == NULL) return;
1693
1694         DEBUG(5,("make_samr_group_info1\n"));
1695
1696         make_uni_hdr(&(gr1->hdr_acct_name), acct_len);
1697
1698         gr1->unknown_1 = 0x3;
1699         gr1->unknown_2 = 0x3;
1700
1701         make_uni_hdr(&(gr1->hdr_acct_desc), desc_len);
1702
1703         make_unistr2(&(gr1->uni_acct_name), acct_name, acct_len);
1704         make_unistr2(&(gr1->uni_acct_desc), acct_desc, desc_len);
1705 }
1706
1707
1708 /*******************************************************************
1709 reads or writes a structure.
1710 ********************************************************************/
1711 void samr_io_group_info1(char *desc,  GROUP_INFO1 *gr1, prs_struct *ps, int depth)
1712 {
1713         if (gr1 == NULL) return;
1714
1715         prs_debug(ps, depth, desc, "samr_io_group_info1");
1716         depth++;
1717
1718         prs_align(ps);
1719
1720         smb_io_unihdr ("hdr_acct_name", &(gr1->hdr_acct_name) , ps, depth); 
1721
1722         prs_uint32("unknown_1", ps, depth, &(gr1->unknown_1));
1723         prs_uint32("unknown_2", ps, depth, &(gr1->unknown_2));
1724
1725         smb_io_unihdr ("hdr_acct_desc", &(gr1->hdr_acct_desc) , ps, depth); 
1726
1727         smb_io_unistr2("uni_acct_name", &(gr1->uni_acct_name), gr1->hdr_acct_name.buffer, ps, depth);
1728         prs_align(ps);
1729
1730         smb_io_unistr2("uni_acct_desc", &(gr1->uni_acct_desc), gr1->hdr_acct_desc.buffer, ps, depth);
1731 }
1732
1733 /*******************************************************************
1734 makes a GROUP_INFO4 structure.
1735 ********************************************************************/
1736 void make_samr_group_info4(GROUP_INFO4 *gr4, const char *acct_desc)
1737 {
1738         int acct_len = acct_desc != NULL ? strlen(acct_desc) : 0;
1739         if (gr4 == NULL) return;
1740
1741         DEBUG(5,("make_samr_group_info4\n"));
1742
1743         make_uni_hdr(&(gr4->hdr_acct_desc), acct_len);
1744         make_unistr2(&(gr4->uni_acct_desc), acct_desc, acct_len);
1745 }
1746
1747
1748 /*******************************************************************
1749 reads or writes a structure.
1750 ********************************************************************/
1751 void samr_io_group_info4(char *desc,  GROUP_INFO4 *gr4, prs_struct *ps, int depth)
1752 {
1753         if (gr4 == NULL) return;
1754
1755         prs_debug(ps, depth, desc, "samr_io_group_info4");
1756         depth++;
1757
1758         prs_align(ps);
1759
1760         smb_io_unihdr ("hdr_acct_desc", &(gr4->hdr_acct_desc) , ps, depth); 
1761         smb_io_unistr2("uni_acct_desc", &(gr4->uni_acct_desc), gr4->hdr_acct_desc.buffer, ps, depth);
1762 }
1763
1764 /*******************************************************************
1765 reads or writes a structure.
1766 ********************************************************************/
1767 void samr_group_info_ctr(char *desc,  GROUP_INFO_CTR *ctr, prs_struct *ps, int depth)
1768 {
1769         if (ctr == NULL) return;
1770
1771         prs_debug(ps, depth, desc, "samr_group_info_ctr");
1772         depth++;
1773
1774         prs_uint16("switch_value1", ps, depth, &(ctr->switch_value1));
1775         prs_uint16("switch_value2", ps, depth, &(ctr->switch_value2));
1776
1777         switch (ctr->switch_value1)
1778         {
1779                 case 1:
1780                 {
1781                         samr_io_group_info1("group_info1", &(ctr->group.info1), ps, depth);
1782                         break;
1783                 }
1784                 case 4:
1785                 {
1786                         samr_io_group_info4("group_info4", &(ctr->group.info4), ps, depth);
1787                         break;
1788                 }
1789                 default:
1790                 {
1791                         DEBUG(4,("samr_group_info_ctr: unsupported switch level\n"));
1792                         break;
1793                 }
1794         }
1795
1796         prs_align(ps);
1797 }
1798
1799
1800 /*******************************************************************
1801 makes a SAMR_Q_CREATE_DOM_GROUP structure.
1802 ********************************************************************/
1803 void make_samr_q_create_dom_group(SAMR_Q_CREATE_DOM_GROUP *q_e,
1804                                 POLICY_HND *pol,
1805                                 const char *acct_desc)
1806 {
1807         int acct_len = acct_desc != NULL ? strlen(acct_desc) : 0;
1808         if (q_e == NULL || pol == NULL) return;
1809
1810         DEBUG(5,("make_samr_q_create_dom_group\n"));
1811
1812         memcpy(&(q_e->pol), pol, sizeof(*pol));
1813
1814         make_uni_hdr(&(q_e->hdr_acct_desc), acct_len);
1815         make_unistr2(&(q_e->uni_acct_desc), acct_desc, acct_len);
1816
1817         q_e->unknown_1 = 0x0002;
1818         q_e->unknown_2 = 0x0001;
1819 }
1820
1821
1822 /*******************************************************************
1823 reads or writes a structure.
1824 ********************************************************************/
1825 void samr_io_q_create_dom_group(char *desc,  SAMR_Q_CREATE_DOM_GROUP *q_e, prs_struct *ps, int depth)
1826 {
1827         if (q_e == NULL) return;
1828
1829         prs_debug(ps, depth, desc, "samr_io_q_create_dom_group");
1830         depth++;
1831
1832         prs_align(ps);
1833
1834         smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); 
1835         prs_align(ps);
1836
1837         smb_io_unihdr ("hdr_acct_desc", &(q_e->hdr_acct_desc), ps, depth); 
1838         smb_io_unistr2("uni_acct_desc", &(q_e->uni_acct_desc), q_e->hdr_acct_desc.buffer, ps, depth);
1839         prs_align(ps);
1840
1841         prs_uint16("unknown_1", ps, depth, &(q_e->unknown_1));
1842         prs_uint16("unknown_2", ps, depth, &(q_e->unknown_2));
1843 }
1844
1845
1846 /*******************************************************************
1847 makes a SAMR_R_CREATE_DOM_GROUP structure.
1848 ********************************************************************/
1849 void make_samr_r_create_dom_group(SAMR_R_CREATE_DOM_GROUP *r_u, POLICY_HND *pol,
1850                 uint32 rid, uint32 status)
1851 {
1852         if (r_u == NULL) return;
1853
1854         DEBUG(5,("make_samr_r_create_dom_group\n"));
1855
1856         memcpy(&(r_u->pol), pol, sizeof(*pol));
1857
1858         r_u->rid    = rid   ;
1859         r_u->status = status;
1860 }
1861
1862
1863 /*******************************************************************
1864 reads or writes a structure.
1865 ********************************************************************/
1866 void samr_io_r_create_dom_group(char *desc,  SAMR_R_CREATE_DOM_GROUP *r_u, prs_struct *ps, int depth)
1867 {
1868         if (r_u == NULL) return;
1869
1870         prs_debug(ps, depth, desc, "samr_io_r_create_dom_group");
1871         depth++;
1872
1873         prs_align(ps);
1874
1875         smb_io_pol_hnd("pol", &(r_u->pol), ps, depth); 
1876         prs_align(ps);
1877
1878         prs_uint32("rid   ", ps, depth, &(r_u->rid   ));
1879         prs_uint32("status", ps, depth, &(r_u->status));
1880 }
1881
1882 /*******************************************************************
1883 makes a SAMR_Q_DELETE_DOM_GROUP structure.
1884 ********************************************************************/
1885 void make_samr_q_delete_dom_group(SAMR_Q_DELETE_DOM_GROUP *q_c, POLICY_HND *hnd)
1886 {
1887         if (q_c == NULL || hnd == NULL) return;
1888
1889         DEBUG(5,("make_samr_q_delete_dom_group\n"));
1890
1891         memcpy(&(q_c->group_pol), hnd, sizeof(q_c->group_pol));
1892 }
1893
1894 /*******************************************************************
1895 reads or writes a structure.
1896 ********************************************************************/
1897 void samr_io_q_delete_dom_group(char *desc,  SAMR_Q_DELETE_DOM_GROUP *q_u, prs_struct *ps, int depth)
1898 {
1899         if (q_u == NULL) return;
1900
1901         prs_debug(ps, depth, desc, "samr_io_q_delete_dom_group");
1902         depth++;
1903
1904         prs_align(ps);
1905
1906         smb_io_pol_hnd("group_pol", &(q_u->group_pol), ps, depth); 
1907 }
1908
1909 /*******************************************************************
1910 makes a SAMR_R_DELETE_DOM_GROUP structure.
1911 ********************************************************************/
1912 void make_samr_r_delete_dom_group(SAMR_R_DELETE_DOM_GROUP *r_u,
1913                 uint32 status)
1914 {
1915         if (r_u == NULL) return;
1916
1917         DEBUG(5,("make_samr_r_delete_dom_group\n"));
1918
1919         r_u->status = status;
1920 }
1921
1922 /*******************************************************************
1923 reads or writes a structure.
1924 ********************************************************************/
1925 void samr_io_r_delete_dom_group(char *desc,  SAMR_R_DELETE_DOM_GROUP *r_u, prs_struct *ps, int depth)
1926 {
1927         if (r_u == NULL) return;
1928
1929         prs_debug(ps, depth, desc, "samr_io_r_delete_dom_group");
1930         depth++;
1931
1932         prs_align(ps);
1933
1934         prs_uint32("status", ps, depth, &(r_u->status));
1935 }
1936
1937
1938
1939 /*******************************************************************
1940 makes a SAMR_Q_DEL_GROUPMEM structure.
1941 ********************************************************************/
1942 void make_samr_q_del_groupmem(SAMR_Q_DEL_GROUPMEM *q_e,
1943                                 POLICY_HND *pol,
1944                                 uint32 rid)
1945 {
1946         if (q_e == NULL || pol == NULL) return;
1947
1948         DEBUG(5,("make_samr_q_del_groupmem\n"));
1949
1950         memcpy(&(q_e->pol), pol, sizeof(*pol));
1951
1952         q_e->rid = rid;
1953 }
1954
1955
1956 /*******************************************************************
1957 reads or writes a structure.
1958 ********************************************************************/
1959 void samr_io_q_del_groupmem(char *desc,  SAMR_Q_DEL_GROUPMEM *q_e, prs_struct *ps, int depth)
1960 {
1961         if (q_e == NULL) return;
1962
1963         prs_debug(ps, depth, desc, "samr_io_q_del_groupmem");
1964         depth++;
1965
1966         prs_align(ps);
1967
1968         smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); 
1969         prs_align(ps);
1970
1971         prs_uint32("rid    ", ps, depth, &(q_e->rid));
1972 }
1973
1974
1975 /*******************************************************************
1976 makes a SAMR_R_DEL_GROUPMEM structure.
1977 ********************************************************************/
1978 void make_samr_r_del_groupmem(SAMR_R_DEL_GROUPMEM *r_u, POLICY_HND *pol,
1979                 uint32 status)
1980 {
1981         if (r_u == NULL) return;
1982
1983         DEBUG(5,("make_samr_r_del_groupmem\n"));
1984
1985         r_u->status = status;
1986 }
1987
1988
1989 /*******************************************************************
1990 reads or writes a structure.
1991 ********************************************************************/
1992 void samr_io_r_del_groupmem(char *desc,  SAMR_R_DEL_GROUPMEM *r_u, prs_struct *ps, int depth)
1993 {
1994         if (r_u == NULL) return;
1995
1996         prs_debug(ps, depth, desc, "samr_io_r_del_groupmem");
1997         depth++;
1998
1999         prs_align(ps);
2000
2001         prs_uint32("status", ps, depth, &(r_u->status));
2002 }
2003
2004
2005 /*******************************************************************
2006 makes a SAMR_Q_ADD_GROUPMEM structure.
2007 ********************************************************************/
2008 void make_samr_q_add_groupmem(SAMR_Q_ADD_GROUPMEM *q_e,
2009                                 POLICY_HND *pol,
2010                                 uint32 rid)
2011 {
2012         if (q_e == NULL || pol == NULL) return;
2013
2014         DEBUG(5,("make_samr_q_add_groupmem\n"));
2015
2016         memcpy(&(q_e->pol), pol, sizeof(*pol));
2017
2018         q_e->rid = rid;
2019         q_e->unknown = 0x0005;
2020 }
2021
2022
2023 /*******************************************************************
2024 reads or writes a structure.
2025 ********************************************************************/
2026 void samr_io_q_add_groupmem(char *desc,  SAMR_Q_ADD_GROUPMEM *q_e, prs_struct *ps, int depth)
2027 {
2028         if (q_e == NULL) return;
2029
2030         prs_debug(ps, depth, desc, "samr_io_q_add_groupmem");
2031         depth++;
2032
2033         prs_align(ps);
2034
2035         smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); 
2036         prs_align(ps);
2037
2038         prs_uint32("rid    ", ps, depth, &(q_e->rid));
2039         prs_uint32("unknown", ps, depth, &(q_e->unknown));
2040 }
2041
2042
2043 /*******************************************************************
2044 makes a SAMR_R_ADD_GROUPMEM structure.
2045 ********************************************************************/
2046 void make_samr_r_add_groupmem(SAMR_R_ADD_GROUPMEM *r_u, POLICY_HND *pol,
2047                 uint32 status)
2048 {
2049         if (r_u == NULL) return;
2050
2051         DEBUG(5,("make_samr_r_add_groupmem\n"));
2052
2053         r_u->status = status;
2054 }
2055
2056
2057 /*******************************************************************
2058 reads or writes a structure.
2059 ********************************************************************/
2060 void samr_io_r_add_groupmem(char *desc,  SAMR_R_ADD_GROUPMEM *r_u, prs_struct *ps, int depth)
2061 {
2062         if (r_u == NULL) return;
2063
2064         prs_debug(ps, depth, desc, "samr_io_r_add_groupmem");
2065         depth++;
2066
2067         prs_align(ps);
2068
2069         prs_uint32("status", ps, depth, &(r_u->status));
2070 }
2071
2072
2073 /*******************************************************************
2074 makes a SAMR_Q_SET_GROUPINFO structure.
2075 ********************************************************************/
2076 void make_samr_q_set_groupinfo(SAMR_Q_SET_GROUPINFO *q_e,
2077                                 POLICY_HND *pol, GROUP_INFO_CTR *ctr)
2078 {
2079         if (q_e == NULL || pol == NULL) return;
2080
2081         DEBUG(5,("make_samr_q_set_groupinfo\n"));
2082
2083         memcpy(&(q_e->pol), pol, sizeof(*pol));
2084         q_e->ctr = ctr;
2085 }
2086
2087
2088 /*******************************************************************
2089 reads or writes a structure.
2090 ********************************************************************/
2091 void samr_io_q_set_groupinfo(char *desc,  SAMR_Q_SET_GROUPINFO *q_e, prs_struct *ps, int depth)
2092 {
2093         if (q_e == NULL) return;
2094
2095         prs_debug(ps, depth, desc, "samr_io_q_set_groupinfo");
2096         depth++;
2097
2098         prs_align(ps);
2099
2100         smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); 
2101         prs_align(ps);
2102
2103         samr_group_info_ctr("ctr", q_e->ctr, ps, depth);
2104 }
2105
2106
2107 /*******************************************************************
2108 makes a SAMR_R_SET_GROUPINFO structure.
2109 ********************************************************************/
2110 void make_samr_r_set_groupinfo(SAMR_R_SET_GROUPINFO *r_u, 
2111                 uint32 status)
2112 {
2113         if (r_u == NULL) return;
2114
2115         DEBUG(5,("make_samr_r_set_groupinfo\n"));
2116
2117         r_u->status = status;
2118 }
2119
2120
2121 /*******************************************************************
2122 reads or writes a structure.
2123 ********************************************************************/
2124 void samr_io_r_set_groupinfo(char *desc,  SAMR_R_SET_GROUPINFO *r_u, prs_struct *ps, int depth)
2125 {
2126         if (r_u == NULL) return;
2127
2128         prs_debug(ps, depth, desc, "samr_io_r_set_groupinfo");
2129         depth++;
2130
2131         prs_align(ps);
2132
2133         prs_uint32("status", ps, depth, &(r_u->status));
2134 }
2135
2136 /*******************************************************************
2137 makes a SAMR_Q_QUERY_GROUPINFO structure.
2138 ********************************************************************/
2139 void make_samr_q_query_groupinfo(SAMR_Q_QUERY_GROUPINFO *q_e,
2140                                 POLICY_HND *pol,
2141                                 uint16 switch_level)
2142 {
2143         if (q_e == NULL || pol == NULL) return;
2144
2145         DEBUG(5,("make_samr_q_query_groupinfo\n"));
2146
2147         memcpy(&(q_e->pol), pol, sizeof(*pol));
2148
2149         q_e->switch_level = switch_level;
2150 }
2151
2152
2153 /*******************************************************************
2154 reads or writes a structure.
2155 ********************************************************************/
2156 void samr_io_q_query_groupinfo(char *desc,  SAMR_Q_QUERY_GROUPINFO *q_e, prs_struct *ps, int depth)
2157 {
2158         if (q_e == NULL) return;
2159
2160         prs_debug(ps, depth, desc, "samr_io_q_query_groupinfo");
2161         depth++;
2162
2163         prs_align(ps);
2164
2165         smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); 
2166         prs_align(ps);
2167
2168         prs_uint16("switch_level", ps, depth, &(q_e->switch_level));
2169 }
2170
2171
2172 /*******************************************************************
2173 makes a SAMR_R_QUERY_GROUPINFO structure.
2174 ********************************************************************/
2175 void make_samr_r_query_groupinfo(SAMR_R_QUERY_GROUPINFO *r_u, GROUP_INFO_CTR *ctr,
2176                 uint32 status)
2177 {
2178         if (r_u == NULL) return;
2179
2180         DEBUG(5,("make_samr_r_query_groupinfo\n"));
2181
2182         r_u->ptr = (status == 0x0 && ctr != NULL) ? 1 : 0;
2183         r_u->ctr = ctr;
2184         r_u->status = status;
2185 }
2186
2187
2188 /*******************************************************************
2189 reads or writes a structure.
2190 ********************************************************************/
2191 void samr_io_r_query_groupinfo(char *desc,  SAMR_R_QUERY_GROUPINFO *r_u, prs_struct *ps, int depth)
2192 {
2193         if (r_u == NULL) return;
2194
2195         prs_debug(ps, depth, desc, "samr_io_r_query_groupinfo");
2196         depth++;
2197
2198         prs_align(ps);
2199
2200         prs_uint32("ptr", ps, depth, &(r_u->ptr));
2201         
2202         if (r_u->ptr != 0)
2203         {
2204                 samr_group_info_ctr("ctr", r_u->ctr, ps, depth);
2205         }
2206
2207         prs_uint32("status", ps, depth, &(r_u->status));
2208 }
2209
2210
2211 /*******************************************************************
2212 makes a SAMR_Q_QUERY_GROUPMEM structure.
2213 ********************************************************************/
2214 void make_samr_q_query_groupmem(SAMR_Q_QUERY_GROUPMEM *q_c, POLICY_HND *hnd)
2215 {
2216         if (q_c == NULL || hnd == NULL) return;
2217
2218         DEBUG(5,("make_samr_q_query_groupmem\n"));
2219
2220         memcpy(&(q_c->group_pol), hnd, sizeof(q_c->group_pol));
2221 }
2222
2223 /*******************************************************************
2224 reads or writes a structure.
2225 ********************************************************************/
2226 void samr_io_q_query_groupmem(char *desc,  SAMR_Q_QUERY_GROUPMEM *q_u, prs_struct *ps, int depth)
2227 {
2228         if (q_u == NULL) return;
2229
2230         prs_debug(ps, depth, desc, "samr_io_q_query_groupmem");
2231         depth++;
2232
2233         prs_align(ps);
2234
2235         smb_io_pol_hnd("group_pol", &(q_u->group_pol), ps, depth); 
2236 }
2237
2238 /*******************************************************************
2239 makes a SAMR_R_QUERY_GROUPMEM structure.
2240 ********************************************************************/
2241 void make_samr_r_query_groupmem(SAMR_R_QUERY_GROUPMEM *r_u,
2242                 uint32 num_entries, uint32 *rid, uint32 *attr, uint32 status)
2243 {
2244         if (r_u == NULL) return;
2245
2246         DEBUG(5,("make_samr_r_query_groupmem\n"));
2247
2248         if (status == 0x0)
2249         {
2250                 r_u->ptr         = 1;
2251                 r_u->num_entries = num_entries;
2252
2253                 r_u->ptr_attrs = attr != NULL ? 1 : 0;
2254                 r_u->ptr_rids = rid != NULL ? 1 : 0;
2255
2256                 r_u->num_rids = num_entries;
2257                 r_u->rid  = rid;
2258
2259                 r_u->num_attrs = num_entries;
2260                 r_u->attr = attr;
2261         }
2262         else
2263         {
2264                 r_u->ptr         = 0;
2265                 r_u->num_entries = 0;
2266         }
2267
2268         r_u->status = status;
2269 }
2270
2271 /*******************************************************************
2272 reads or writes a structure.
2273 ********************************************************************/
2274 void samr_io_r_query_groupmem(char *desc,  SAMR_R_QUERY_GROUPMEM *r_u, prs_struct *ps, int depth)
2275 {
2276         int i;
2277
2278         if (r_u == NULL) return;
2279
2280         prs_debug(ps, depth, desc, "samr_io_r_query_groupmem");
2281         depth++;
2282
2283         prs_align(ps);
2284
2285         prs_uint32("ptr", ps, depth, &(r_u->ptr));
2286         prs_uint32("num_entries ", ps, depth, &(r_u->num_entries));
2287
2288         if (r_u->ptr != 0)
2289         {
2290                 prs_uint32("ptr_rids ", ps, depth, &(r_u->ptr_rids ));
2291                 prs_uint32("ptr_attrs", ps, depth, &(r_u->ptr_attrs));
2292
2293                 if (r_u->ptr_rids != 0)
2294                 {
2295                         prs_uint32("num_rids", ps, depth, &(r_u->num_rids));
2296                         for (i = 0; i < r_u->num_rids; i++)
2297                         {
2298                                 prs_grow(ps);
2299                                 prs_uint32("", ps, depth, &(r_u->rid[i]));
2300                         }
2301                 }
2302
2303                 if (r_u->ptr_attrs != 0)
2304                 {
2305                         prs_uint32("num_attrs", ps, depth, &(r_u->num_attrs));
2306                         for (i = 0; i < r_u->num_attrs; i++)
2307                         {
2308                                 prs_grow(ps);
2309                                 prs_uint32("", ps, depth, &(r_u->attr[i]));
2310                         }
2311                 }
2312         }
2313
2314         prs_uint32("status", ps, depth, &(r_u->status));
2315 }
2316
2317
2318 /*******************************************************************
2319 makes a SAMR_Q_QUERY_USERGROUPS structure.
2320 ********************************************************************/
2321 void make_samr_q_query_usergroups(SAMR_Q_QUERY_USERGROUPS *q_u,
2322                                 POLICY_HND *hnd)
2323 {
2324         if (q_u == NULL || hnd == NULL) return;
2325
2326         DEBUG(5,("make_samr_q_query_usergroups\n"));
2327
2328         memcpy(&(q_u->pol), hnd, sizeof(q_u->pol));
2329 }
2330
2331
2332 /*******************************************************************
2333 reads or writes a structure.
2334 ********************************************************************/
2335 void samr_io_q_query_usergroups(char *desc,  SAMR_Q_QUERY_USERGROUPS *q_u, prs_struct *ps, int depth)
2336 {
2337         if (q_u == NULL) return;
2338
2339         prs_debug(ps, depth, desc, "samr_io_q_query_usergroups");
2340         depth++;
2341
2342         prs_align(ps);
2343
2344         smb_io_pol_hnd("pol", &(q_u->pol), ps, depth); 
2345         prs_align(ps);
2346 }
2347
2348 /*******************************************************************
2349 makes a SAMR_R_QUERY_USERGROUPS structure.
2350 ********************************************************************/
2351 void make_samr_r_query_usergroups(SAMR_R_QUERY_USERGROUPS *r_u,
2352                 uint32 num_gids, DOM_GID *gid, uint32 status)
2353 {
2354         if (r_u == NULL) return;
2355
2356         DEBUG(5,("make_samr_r_query_usergroups\n"));
2357
2358         if (status == 0x0)
2359         {
2360                 r_u->ptr_0        = 1;
2361                 r_u->num_entries  = num_gids;
2362                 r_u->ptr_1        = (num_gids != 0) ? 1 : 0;
2363                 r_u->num_entries2 = num_gids;
2364
2365                 r_u->gid = gid;
2366         }
2367         else
2368         {
2369                 r_u->ptr_0       = 0;
2370                 r_u->num_entries = 0;
2371                 r_u->ptr_1       = 0;
2372         }
2373
2374         r_u->status = status;
2375 }
2376
2377 /*******************************************************************
2378 reads or writes a structure.
2379 ********************************************************************/
2380 void samr_io_r_query_usergroups(char *desc,  SAMR_R_QUERY_USERGROUPS *r_u, prs_struct *ps, int depth)
2381 {
2382         int i;
2383         if (r_u == NULL) return;
2384
2385         prs_debug(ps, depth, desc, "samr_io_r_query_usergroups");
2386         depth++;
2387
2388         prs_align(ps);
2389
2390         prs_uint32("ptr_0       ", ps, depth, &(r_u->ptr_0      ));
2391
2392         if (r_u->ptr_0 != 0)
2393         {
2394                 prs_uint32("num_entries ", ps, depth, &(r_u->num_entries));
2395                 prs_uint32("ptr_1       ", ps, depth, &(r_u->ptr_1      ));
2396
2397                 if (r_u->num_entries != 0)
2398                 {
2399                         prs_uint32("num_entries2", ps, depth, &(r_u->num_entries2));
2400
2401                         for (i = 0; i < r_u->num_entries2; i++)
2402                         {
2403                                 prs_grow(ps);
2404                                 smb_io_gid("", &(r_u->gid[i]), ps, depth);
2405                         }
2406                 }
2407         }
2408         prs_uint32("status", ps, depth, &(r_u->status));
2409 }
2410
2411
2412 /*******************************************************************
2413 makes a SAMR_Q_ENUM_DOM_GROUPS structure.
2414 ********************************************************************/
2415 void make_samr_q_enum_dom_groups(SAMR_Q_ENUM_DOM_GROUPS *q_e, POLICY_HND *pol, uint32 size)
2416 {
2417         if (q_e == NULL || pol == NULL) return;
2418
2419         DEBUG(5,("make_samr_q_enum_dom_groups\n"));
2420
2421         memcpy(&(q_e->pol), pol, sizeof(*pol));
2422
2423         q_e->unknown_0 = 0;
2424         q_e->max_size = size;
2425 }
2426
2427
2428 /*******************************************************************
2429 reads or writes a structure.
2430 ********************************************************************/
2431 void samr_io_q_enum_dom_groups(char *desc, SAMR_Q_ENUM_DOM_GROUPS *q_e, prs_struct *ps, int depth)
2432 {
2433         if (q_e == NULL) return;
2434
2435         prs_debug(ps, depth, desc, "samr_io_q_enum_dom_groups");
2436         depth++;
2437
2438         prs_align(ps);
2439
2440         smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); 
2441         prs_align(ps);
2442
2443         prs_uint32("unknown_0", ps, depth, &(q_e->unknown_0));
2444         prs_uint32("max_size ", ps, depth, &(q_e->max_size ));
2445
2446         prs_align(ps);
2447 }
2448
2449
2450 /*******************************************************************
2451 makes a SAMR_R_ENUM_DOM_GROUPS structure.
2452 ********************************************************************/
2453 void make_samr_r_enum_dom_groups(SAMR_R_ENUM_DOM_GROUPS *r_u,
2454                 uint32 num_sam_entries, DOMAIN_GRP *grps,
2455                 uint32 status)
2456 {
2457         int i;
2458
2459         if (r_u == NULL) return;
2460
2461         DEBUG(5,("make_samr_r_enum_dom_groups\n"));
2462
2463         if (num_sam_entries >= MAX_SAM_ENTRIES)
2464         {
2465                 num_sam_entries = MAX_SAM_ENTRIES;
2466                 DEBUG(5,("limiting number of entries to %d\n", 
2467                          num_sam_entries));
2468         }
2469
2470         r_u->num_entries  = num_sam_entries;
2471
2472         if (num_sam_entries > 0)
2473         {
2474                 r_u->ptr_entries  = 1;
2475                 r_u->num_entries2 = num_sam_entries;
2476                 r_u->ptr_entries2 = 1;
2477                 r_u->num_entries3 = num_sam_entries;
2478
2479                 SMB_ASSERT_ARRAY(r_u->sam, num_sam_entries);
2480
2481                 for (i = 0; i < num_sam_entries; i++)
2482                 {
2483                         int acct_name_len = strlen(grps[i].name);
2484
2485                         make_sam_entry(&(r_u->sam[i]),
2486                                         acct_name_len,
2487                                         grps[i].rid);
2488
2489                         make_unistr2(&(r_u->uni_grp_name[i]), grps[i].name, acct_name_len);
2490                 }
2491
2492                 r_u->num_entries4 = num_sam_entries;
2493         }
2494         else
2495         {
2496                 r_u->ptr_entries = 0;
2497         }
2498
2499         r_u->status = status;
2500 }
2501
2502 /*******************************************************************
2503 reads or writes a structure.
2504 ********************************************************************/
2505 void samr_io_r_enum_dom_groups(char *desc, SAMR_R_ENUM_DOM_GROUPS *r_u, prs_struct *ps, int depth)
2506 {
2507         int i;
2508
2509         if (r_u == NULL) return;
2510
2511         prs_debug(ps, depth, desc, "samr_io_r_enum_dom_groups");
2512         depth++;
2513
2514         prs_align(ps);
2515
2516         prs_uint32("num_entries", ps, depth, &(r_u->num_entries));
2517         prs_uint32("ptr_entries", ps, depth, &(r_u->ptr_entries));
2518         
2519         if (r_u->num_entries != 0 && r_u->ptr_entries != 0)
2520         {
2521                 prs_uint32("num_entries2", ps, depth, &(r_u->num_entries2));
2522                 prs_uint32("ptr_entries2", ps, depth, &(r_u->ptr_entries2));
2523                 prs_uint32("num_entries3", ps, depth, &(r_u->num_entries3));
2524
2525                 SMB_ASSERT_ARRAY(r_u->sam, r_u->num_entries);
2526
2527                 for (i = 0; i < r_u->num_entries; i++)
2528                 {
2529                         sam_io_sam_entry("", &(r_u->sam[i]), ps, depth);
2530                 }
2531
2532                 for (i = 0; i < r_u->num_entries; i++)
2533                 {
2534                         smb_io_unistr2("", &(r_u->uni_grp_name[i]), r_u->sam[i].hdr_name.buffer, ps, depth);
2535                 }
2536
2537                 prs_align(ps);
2538         }
2539
2540         prs_uint32("num_entries4", ps, depth, &(r_u->num_entries4));
2541         prs_uint32("status", ps, depth, &(r_u->status));
2542 }
2543
2544
2545 /*******************************************************************
2546 makes a SAMR_Q_ENUM_DOM_ALIASES structure.
2547 ********************************************************************/
2548 void make_samr_q_enum_dom_aliases(SAMR_Q_ENUM_DOM_ALIASES *q_e, POLICY_HND *pol, uint32 size)
2549 {
2550         if (q_e == NULL || pol == NULL) return;
2551
2552         DEBUG(5,("make_samr_q_enum_dom_aliases\n"));
2553
2554         memcpy(&(q_e->pol), pol, sizeof(*pol));
2555
2556         q_e->unknown_0 = 0;
2557         q_e->max_size = size;
2558 }
2559
2560
2561 /*******************************************************************
2562 reads or writes a structure.
2563 ********************************************************************/
2564 void samr_io_q_enum_dom_aliases(char *desc,  SAMR_Q_ENUM_DOM_ALIASES *q_e, prs_struct *ps, int depth)
2565 {
2566         if (q_e == NULL) return;
2567
2568         prs_debug(ps, depth, desc, "samr_io_q_enum_dom_aliases");
2569         depth++;
2570
2571         prs_align(ps);
2572
2573         smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); 
2574         prs_align(ps);
2575
2576         prs_uint32("unknown_0", ps, depth, &(q_e->unknown_0));
2577         prs_uint32("max_size ", ps, depth, &(q_e->max_size ));
2578
2579         prs_align(ps);
2580 }
2581
2582
2583 /*******************************************************************
2584 makes a SAMR_R_ENUM_DOM_ALIASES structure.
2585 ********************************************************************/
2586 void make_samr_r_enum_dom_aliases(SAMR_R_ENUM_DOM_ALIASES *r_u,
2587                 uint32 num_sam_entries, LOCAL_GRP *alss,
2588                 uint32 status)
2589 {
2590         int i;
2591
2592         if (r_u == NULL) return;
2593
2594         DEBUG(5,("make_samr_r_enum_dom_aliases\n"));
2595
2596         if (num_sam_entries >= MAX_SAM_ENTRIES)
2597         {
2598                 num_sam_entries = MAX_SAM_ENTRIES;
2599                 DEBUG(5,("limiting number of entries to %d\n", 
2600                          num_sam_entries));
2601         }
2602
2603         r_u->num_entries  = num_sam_entries;
2604
2605         if (num_sam_entries > 0)
2606         {
2607                 r_u->ptr_entries  = 1;
2608                 r_u->num_entries2 = num_sam_entries;
2609                 r_u->ptr_entries2 = 1;
2610                 r_u->num_entries3 = num_sam_entries;
2611
2612                 SMB_ASSERT_ARRAY(r_u->sam, num_sam_entries);
2613
2614                 for (i = 0; i < num_sam_entries; i++)
2615                 {
2616                         int acct_name_len = strlen(alss[i].name);
2617
2618                         make_sam_entry(&(r_u->sam[i]),
2619                                         acct_name_len,
2620                                         alss[i].rid);
2621
2622                         make_unistr2(&(r_u->uni_grp_name[i]), alss[i].name   , acct_name_len);
2623                 }
2624
2625                 r_u->num_entries4 = num_sam_entries;
2626         }
2627         else
2628         {
2629                 r_u->ptr_entries = 0;
2630         }
2631
2632         r_u->status = status;
2633 }
2634
2635 /*******************************************************************
2636 reads or writes a structure.
2637 ********************************************************************/
2638 void samr_io_r_enum_dom_aliases(char *desc,  SAMR_R_ENUM_DOM_ALIASES *r_u, prs_struct *ps, int depth)
2639 {
2640         int i;
2641
2642         if (r_u == NULL) return;
2643
2644         prs_debug(ps, depth, desc, "samr_io_r_enum_dom_aliases");
2645         depth++;
2646
2647         prs_align(ps);
2648
2649         prs_uint32("num_entries", ps, depth, &(r_u->num_entries));
2650         prs_uint32("ptr_entries", ps, depth, &(r_u->ptr_entries));
2651         
2652         if (r_u->num_entries != 0 && r_u->ptr_entries != 0)
2653         {
2654                 prs_uint32("num_entries2", ps, depth, &(r_u->num_entries2));
2655                 prs_uint32("ptr_entries2", ps, depth, &(r_u->ptr_entries2));
2656                 prs_uint32("num_entries3", ps, depth, &(r_u->num_entries3));
2657
2658                 SMB_ASSERT_ARRAY(r_u->sam, r_u->num_entries);
2659
2660                 for (i = 0; i < r_u->num_entries; i++)
2661                 {
2662                         sam_io_sam_entry("", &(r_u->sam[i]), ps, depth);
2663                 }
2664
2665                 for (i = 0; i < r_u->num_entries; i++)
2666                 {
2667                         smb_io_unistr2("", &(r_u->uni_grp_name[i]), r_u->sam[i].hdr_name.buffer, ps, depth);
2668                 }
2669
2670                 prs_align(ps);
2671         }
2672
2673         prs_uint32("num_entries4", ps, depth, &(r_u->num_entries4));
2674         prs_uint32("status", ps, depth, &(r_u->status));
2675 }
2676
2677
2678 /*******************************************************************
2679 makes a ALIAS_INFO3 structure.
2680 ********************************************************************/
2681 void make_samr_alias_info3(ALIAS_INFO3 *al3, const char *acct_desc)
2682 {
2683         int acct_len = acct_desc != NULL ? strlen(acct_desc) : 0;
2684         if (al3 == NULL) return;
2685
2686         DEBUG(5,("make_samr_alias_info3\n"));
2687
2688         make_uni_hdr(&(al3->hdr_acct_desc), acct_len);
2689         make_unistr2(&(al3->uni_acct_desc), acct_desc, acct_len);
2690 }
2691
2692
2693 /*******************************************************************
2694 reads or writes a structure.
2695 ********************************************************************/
2696 void samr_io_alias_info3(char *desc,  ALIAS_INFO3 *al3, prs_struct *ps, int depth)
2697 {
2698         if (al3 == NULL) return;
2699
2700         prs_debug(ps, depth, desc, "samr_io_alias_info3");
2701         depth++;
2702
2703         prs_align(ps);
2704
2705         smb_io_unihdr ("hdr_acct_desc", &(al3->hdr_acct_desc) , ps, depth); 
2706         smb_io_unistr2("uni_acct_desc", &(al3->uni_acct_desc), al3->hdr_acct_desc.buffer, ps, depth);
2707 }
2708
2709 /*******************************************************************
2710 reads or writes a structure.
2711 ********************************************************************/
2712 void samr_alias_info_ctr(char *desc,  ALIAS_INFO_CTR *ctr, prs_struct *ps, int depth)
2713 {
2714         if (ctr == NULL) return;
2715
2716         prs_debug(ps, depth, desc, "samr_alias_info_ctr");
2717         depth++;
2718
2719         prs_uint16("switch_value1", ps, depth, &(ctr->switch_value1));
2720         prs_uint16("switch_value2", ps, depth, &(ctr->switch_value2));
2721
2722         switch (ctr->switch_value1)
2723         {
2724                 case 3:
2725                 {
2726                         samr_io_alias_info3("alias_info3", &(ctr->alias.info3), ps, depth);
2727                         break;
2728                 }
2729                 default:
2730                 {
2731                         DEBUG(4,("samr_alias_info_ctr: unsupported switch level\n"));
2732                         break;
2733                 }
2734         }
2735
2736         prs_align(ps);
2737 }
2738
2739
2740 /*******************************************************************
2741 makes a SAMR_Q_QUERY_ALIASINFO structure.
2742 ********************************************************************/
2743 void make_samr_q_query_aliasinfo(SAMR_Q_QUERY_ALIASINFO *q_e,
2744                                 POLICY_HND *pol,
2745                                 uint16 switch_level)
2746 {
2747         if (q_e == NULL || pol == NULL) return;
2748
2749         DEBUG(5,("make_samr_q_query_aliasinfo\n"));
2750
2751         memcpy(&(q_e->pol), pol, sizeof(*pol));
2752
2753         q_e->switch_level = switch_level;
2754 }
2755
2756
2757 /*******************************************************************
2758 reads or writes a structure.
2759 ********************************************************************/
2760 void samr_io_q_query_aliasinfo(char *desc,  SAMR_Q_QUERY_ALIASINFO *q_e, prs_struct *ps, int depth)
2761 {
2762         if (q_e == NULL) return;
2763
2764         prs_debug(ps, depth, desc, "samr_io_q_query_aliasinfo");
2765         depth++;
2766
2767         prs_align(ps);
2768
2769         smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); 
2770         prs_align(ps);
2771
2772         prs_uint16("switch_level", ps, depth, &(q_e->switch_level));
2773 }
2774
2775
2776 /*******************************************************************
2777 makes a SAMR_R_QUERY_ALIASINFO structure.
2778 ********************************************************************/
2779 void make_samr_r_query_aliasinfo(SAMR_R_QUERY_ALIASINFO *r_u, ALIAS_INFO_CTR *ctr,
2780                 uint32 status)
2781 {
2782         if (r_u == NULL) return;
2783
2784         DEBUG(5,("make_samr_r_query_aliasinfo\n"));
2785
2786         r_u->ptr = (status == 0x0 && ctr != NULL) ? 1 : 0;
2787         r_u->ctr = ctr;
2788         r_u->status = status;
2789 }
2790
2791
2792 /*******************************************************************
2793 reads or writes a structure.
2794 ********************************************************************/
2795 void samr_io_r_query_aliasinfo(char *desc,  SAMR_R_QUERY_ALIASINFO *r_u, prs_struct *ps, int depth)
2796 {
2797         if (r_u == NULL) return;
2798
2799         prs_debug(ps, depth, desc, "samr_io_r_query_aliasinfo");
2800         depth++;
2801
2802         prs_align(ps);
2803
2804         prs_uint32("ptr", ps, depth, &(r_u->ptr));
2805         
2806         if (r_u->ptr != 0)
2807         {
2808                 samr_alias_info_ctr("ctr", r_u->ctr, ps, depth);
2809         }
2810
2811         prs_uint32("status", ps, depth, &(r_u->status));
2812 }
2813
2814
2815 /*******************************************************************
2816 makes a SAMR_Q_SET_ALIASINFO structure.
2817 ********************************************************************/
2818 void make_samr_q_set_aliasinfo(SAMR_Q_SET_ALIASINFO *q_u, POLICY_HND *hnd,
2819                                 ALIAS_INFO_CTR *ctr)
2820 {
2821         if (q_u == NULL) return;
2822
2823         DEBUG(5,("make_samr_q_set_aliasinfo\n"));
2824
2825         memcpy(&(q_u->alias_pol), hnd, sizeof(q_u->alias_pol));
2826         q_u->ctr = ctr;
2827 }
2828
2829
2830 /*******************************************************************
2831 reads or writes a structure.
2832 ********************************************************************/
2833 void samr_io_q_set_aliasinfo(char *desc,  SAMR_Q_SET_ALIASINFO *q_u, prs_struct *ps, int depth)
2834 {
2835         if (q_u == NULL) return;
2836
2837         prs_debug(ps, depth, desc, "samr_io_q_set_aliasinfo");
2838         depth++;
2839
2840         prs_align(ps);
2841
2842         smb_io_pol_hnd("alias_pol", &(q_u->alias_pol), ps, depth); 
2843         samr_alias_info_ctr("ctr", q_u->ctr, ps, depth);
2844 }
2845
2846 /*******************************************************************
2847 reads or writes a structure.
2848 ********************************************************************/
2849 void samr_io_r_set_aliasinfo(char *desc,  SAMR_R_SET_ALIASINFO *r_u, prs_struct *ps, int depth)
2850 {
2851         if (r_u == NULL) return;
2852
2853         prs_debug(ps, depth, desc, "samr_io_r_set_aliasinfo");
2854         depth++;
2855
2856         prs_align(ps);
2857         prs_uint32("status", ps, depth, &(r_u->status));
2858 }
2859
2860
2861
2862 /*******************************************************************
2863 makes a SAMR_Q_QUERY_USERALIASES structure.
2864 ********************************************************************/
2865 void make_samr_q_query_useraliases(SAMR_Q_QUERY_USERALIASES *q_u,
2866                                 POLICY_HND *hnd,
2867                                 DOM_SID *sid)
2868 {
2869         if (q_u == NULL || hnd == NULL) return;
2870
2871         DEBUG(5,("make_samr_q_query_useraliases\n"));
2872
2873         memcpy(&(q_u->pol), hnd, sizeof(q_u->pol));
2874
2875         q_u->num_sids1 = 1;
2876         q_u->ptr = 1;
2877         q_u->num_sids2 = 1;
2878
2879         {
2880                 q_u->ptr_sid[0] = 1;
2881                 make_dom_sid2(&q_u->sid[0], sid);
2882         }
2883 }
2884
2885 /*******************************************************************
2886 reads or writes a SAMR_Q_QUERY_USERALIASES structure.
2887 ********************************************************************/
2888 void samr_io_q_query_useraliases(char *desc,  SAMR_Q_QUERY_USERALIASES *q_u, prs_struct *ps, int depth)
2889 {
2890         fstring tmp;
2891         int i;
2892
2893         if (q_u == NULL) return;
2894
2895         prs_debug(ps, depth, desc, "samr_io_q_query_useraliases");
2896         depth++;
2897
2898         prs_align(ps);
2899
2900         smb_io_pol_hnd("pol", &(q_u->pol), ps, depth); 
2901         prs_align(ps);
2902
2903         prs_uint32("num_sids1", ps, depth, &(q_u->num_sids1));
2904         prs_uint32("ptr      ", ps, depth, &(q_u->ptr      ));
2905         prs_uint32("num_sids2", ps, depth, &(q_u->num_sids2));
2906
2907         SMB_ASSERT_ARRAY(q_u->ptr_sid, q_u->num_sids2);
2908
2909         for (i = 0; i < q_u->num_sids2; i++)
2910         {
2911                 slprintf(tmp, sizeof(tmp) - 1, "ptr[%02d]", i);
2912                 prs_uint32(tmp, ps, depth, &(q_u->ptr_sid[i]));
2913         }
2914
2915         for (i = 0; i < q_u->num_sids2; i++)
2916         {
2917                 if (q_u->ptr_sid[i] != 0)
2918                 {
2919                         prs_grow(ps);
2920                         slprintf(tmp, sizeof(tmp)-1, "sid[%02d]", i);
2921                         smb_io_dom_sid2(tmp, &(q_u->sid[i]), ps, depth); 
2922                 }
2923         }
2924
2925         prs_align(ps);
2926 }
2927
2928
2929 /*******************************************************************
2930 makes a SAMR_R_QUERY_USERALIASES structure.
2931 ********************************************************************/
2932 void make_samr_r_query_useraliases(SAMR_R_QUERY_USERALIASES *r_u,
2933                 uint32 num_rids, uint32 *rid, uint32 status)
2934 {
2935         if (r_u == NULL) return;
2936
2937         DEBUG(5,("make_samr_r_query_useraliases\n"));
2938
2939         if (status == 0x0)
2940         {
2941                 r_u->num_entries  = num_rids;
2942                 r_u->ptr = 1;
2943                 r_u->num_entries2 = num_rids;
2944
2945                 r_u->rid = rid;
2946         }
2947         else
2948         {
2949                 r_u->num_entries  = 0;
2950                 r_u->ptr = 0;
2951                 r_u->num_entries2 = 0;
2952         }
2953
2954         r_u->status = status;
2955 }
2956
2957 /*******************************************************************
2958 reads or writes a structure.
2959 ********************************************************************/
2960 void samr_io_r_query_useraliases(char *desc,  SAMR_R_QUERY_USERALIASES *r_u, prs_struct *ps, int depth)
2961 {
2962         fstring tmp;
2963         int i;
2964         if (r_u == NULL) return;
2965
2966         prs_debug(ps, depth, desc, "samr_io_r_query_useraliases");
2967         depth++;
2968
2969         prs_align(ps);
2970
2971         prs_uint32("num_entries", ps, depth, &(r_u->num_entries));
2972         prs_uint32("ptr        ", ps, depth, &(r_u->ptr        ));
2973         prs_uint32("num_entries2", ps, depth, &(r_u->num_entries2));
2974
2975         if (r_u->num_entries != 0)
2976         {
2977                 for (i = 0; i < r_u->num_entries2; i++)
2978                 {
2979                         slprintf(tmp, sizeof(tmp)-1, "rid[%02d]", i);
2980                         prs_uint32(tmp, ps, depth, &(r_u->rid[i]));
2981                 }
2982         }
2983
2984         prs_uint32("status", ps, depth, &(r_u->status));
2985 }
2986
2987 /*******************************************************************
2988 makes a SAMR_Q_OPEN_ALIAS structure.
2989 ********************************************************************/
2990 void make_samr_q_open_alias(SAMR_Q_OPEN_ALIAS *q_u, POLICY_HND *pol,
2991                                 uint32 unknown_0, uint32 rid)
2992 {
2993         if (q_u == NULL) return;
2994
2995         DEBUG(5,("make_samr_q_open_alias\n"));
2996
2997         memcpy(&(q_u->dom_pol), pol, sizeof(q_u->dom_pol));
2998
2999         /* example values: 0x0000 0008 */
3000         q_u->unknown_0 = unknown_0; 
3001
3002         q_u->rid_alias = rid; 
3003 }
3004
3005 /*******************************************************************
3006 reads or writes a structure.
3007 ********************************************************************/
3008 void samr_io_q_open_alias(char *desc,  SAMR_Q_OPEN_ALIAS *q_u, prs_struct *ps, int depth)
3009 {
3010         if (q_u == NULL) return;
3011
3012         prs_debug(ps, depth, desc, "samr_io_q_open_alias");
3013         depth++;
3014
3015         prs_align(ps);
3016
3017         smb_io_pol_hnd("dom_pol", &(q_u->dom_pol), ps, depth); 
3018
3019         prs_uint32("unknown_0", ps, depth, &(q_u->unknown_0));
3020         prs_uint32("rid_alias", ps, depth, &(q_u->rid_alias));
3021 }
3022
3023 /*******************************************************************
3024 reads or writes a structure.
3025 ********************************************************************/
3026 void samr_io_r_open_alias(char *desc,  SAMR_R_OPEN_ALIAS *r_u, prs_struct *ps, int depth)
3027 {
3028         if (r_u == NULL) return;
3029
3030         prs_debug(ps, depth, desc, "samr_io_r_open_alias");
3031         depth++;
3032
3033         prs_align(ps);
3034
3035         smb_io_pol_hnd("pol", &(r_u->pol), ps, depth); 
3036         prs_align(ps);
3037
3038         prs_uint32("status", ps, depth, &(r_u->status));
3039 }
3040
3041 /*******************************************************************
3042 makes a SAMR_Q_LOOKUP_RIDS structure.
3043 ********************************************************************/
3044 void make_samr_q_lookup_rids(SAMR_Q_LOOKUP_RIDS *q_u,
3045                 POLICY_HND *pol, uint32 flags,
3046                 uint32 num_rids, uint32 *rid)
3047 {
3048         int i;
3049         if (q_u == NULL) return;
3050
3051         DEBUG(5,("make_samr_r_unknwon_12\n"));
3052
3053         memcpy(&(q_u->pol), pol, sizeof(*pol));
3054
3055         q_u->num_rids1 = num_rids;
3056         q_u->flags     = flags;
3057         q_u->ptr       = 0;
3058         q_u->num_rids2 = num_rids;
3059
3060         for (i = 0; i < num_rids; i++)
3061         {
3062                 q_u->rid[i] = rid[i];
3063         }
3064 }
3065
3066 /*******************************************************************
3067 reads or writes a structure.
3068 ********************************************************************/
3069 void samr_io_q_lookup_rids(char *desc,  SAMR_Q_LOOKUP_RIDS *q_u, prs_struct *ps, int depth)
3070 {
3071         int i;
3072         fstring tmp;
3073
3074         if (q_u == NULL) return;
3075
3076         prs_debug(ps, depth, desc, "samr_io_q_lookup_rids");
3077         depth++;
3078
3079         prs_align(ps);
3080
3081         smb_io_pol_hnd("pol", &(q_u->pol), ps, depth); 
3082         prs_align(ps);
3083
3084         prs_uint32("num_rids1", ps, depth, &(q_u->num_rids1));
3085         prs_uint32("flags    ", ps, depth, &(q_u->flags    ));
3086         prs_uint32("ptr      ", ps, depth, &(q_u->ptr      ));
3087         prs_uint32("num_rids2", ps, depth, &(q_u->num_rids2));
3088
3089         SMB_ASSERT_ARRAY(q_u->rid, q_u->num_rids2);
3090
3091         for (i = 0; i < q_u->num_rids2; i++)
3092         {
3093                 prs_grow(ps);
3094                 slprintf(tmp, sizeof(tmp) - 1, "rid[%02d]  ", i);
3095                 prs_uint32(tmp, ps, depth, &(q_u->rid[i]));
3096         }
3097
3098         prs_align(ps);
3099 }
3100
3101
3102 /*******************************************************************
3103 makes a SAMR_R_LOOKUP_RIDS structure.
3104 ********************************************************************/
3105 void make_samr_r_lookup_rids(SAMR_R_LOOKUP_RIDS *r_u,
3106                 uint32 num_names, fstring *name, uint8 *type,
3107                 uint32 status)
3108 {
3109         int i;
3110         if (r_u == NULL || name == NULL || type == NULL) return;
3111
3112         DEBUG(5,("make_samr_r_lookup_rids\n"));
3113
3114         if (status == 0x0)
3115         {
3116                 r_u->num_names1 = num_names;
3117                 r_u->ptr_names  = 1;
3118                 r_u->num_names2 = num_names;
3119
3120                 r_u->num_types1 = num_names;
3121                 r_u->ptr_types  = 1;
3122                 r_u->num_types2 = num_names;
3123
3124                 SMB_ASSERT_ARRAY(r_u->hdr_name, num_names);
3125
3126                 for (i = 0; i < num_names; i++)
3127                 {
3128                         int len = name[i] != NULL ? strlen(name[i]) : 0;
3129                         make_uni_hdr(&(r_u->hdr_name[i]), len);
3130                         make_unistr2(&(r_u->uni_name[i]), name[i], len);
3131                         r_u->type[i] = type[i];
3132                 }
3133         }
3134         else
3135         {
3136                 r_u->num_names1 = num_names;
3137                 r_u->ptr_names  = 0;
3138                 r_u->num_names2 = num_names;
3139
3140                 r_u->num_types1 = num_names;
3141                 r_u->ptr_types  = 0;
3142                 r_u->num_types2 = num_names;
3143         }
3144
3145         r_u->status = status;
3146 }
3147
3148 /*******************************************************************
3149 reads or writes a structure.
3150 ********************************************************************/
3151 void samr_io_r_lookup_rids(char *desc,  SAMR_R_LOOKUP_RIDS *r_u, prs_struct *ps, int depth)
3152 {
3153         int i;
3154         fstring tmp;
3155         if (r_u == NULL) return;
3156
3157         prs_debug(ps, depth, desc, "samr_io_r_lookup_rids");
3158         depth++;
3159
3160         prs_align(ps);
3161
3162         prs_uint32("num_names1", ps, depth, &(r_u->num_names1));
3163         prs_uint32("ptr_names ", ps, depth, &(r_u->ptr_names ));
3164         prs_uint32("num_names2", ps, depth, &(r_u->num_names2));
3165
3166         if (r_u->ptr_names != 0 && r_u->num_names1 != 0)
3167         {
3168                 SMB_ASSERT_ARRAY(r_u->hdr_name, r_u->num_names2);
3169
3170                 for (i = 0; i < r_u->num_names2; i++)
3171                 {
3172                         prs_grow(ps);
3173                         slprintf(tmp, sizeof(tmp) - 1, "hdr[%02d]  ", i);
3174                         smb_io_unihdr ("", &(r_u->hdr_name[i]), ps, depth); 
3175                 }
3176                 for (i = 0; i < r_u->num_names2; i++)
3177                 {
3178                         prs_grow(ps);
3179                         slprintf(tmp, sizeof(tmp) - 1, "str[%02d]  ", i);
3180                         smb_io_unistr2("", &(r_u->uni_name[i]), r_u->hdr_name[i].buffer, ps, depth); 
3181                 }
3182         }
3183
3184         prs_align(ps);
3185
3186         prs_uint32("num_types1", ps, depth, &(r_u->num_types1));
3187         prs_uint32("ptr_types ", ps, depth, &(r_u->ptr_types ));
3188         prs_uint32("num_types2", ps, depth, &(r_u->num_types2));
3189
3190         if (r_u->ptr_types != 0 && r_u->num_types1 != 0)
3191         {
3192                 for (i = 0; i < r_u->num_types2; i++)
3193                 {
3194                         prs_grow(ps);
3195                         slprintf(tmp, sizeof(tmp) - 1, "type[%02d]  ", i);
3196                         prs_uint32(tmp, ps, depth, &(r_u->type[i]));
3197                 }
3198         }
3199
3200         prs_uint32("status", ps, depth, &(r_u->status));
3201 }
3202
3203 /*******************************************************************
3204 makes a SAMR_Q_OPEN_ALIAS structure.
3205 ********************************************************************/
3206 void make_samr_q_delete_alias(SAMR_Q_DELETE_DOM_ALIAS *q_u, POLICY_HND *hnd)
3207 {
3208         if (q_u == NULL) return;
3209
3210         DEBUG(5,("make_samr_q_delete_alias\n"));
3211
3212         memcpy(&(q_u->alias_pol), hnd, sizeof(q_u->alias_pol));
3213 }
3214
3215
3216 /*******************************************************************
3217 reads or writes a structure.
3218 ********************************************************************/
3219 void samr_io_q_delete_alias(char *desc,  SAMR_Q_DELETE_DOM_ALIAS *q_u, prs_struct *ps, int depth)
3220 {
3221         if (q_u == NULL) return;
3222
3223         prs_debug(ps, depth, desc, "samr_io_q_delete_alias");
3224         depth++;
3225
3226         prs_align(ps);
3227
3228         smb_io_pol_hnd("alias_pol", &(q_u->alias_pol), ps, depth); 
3229 }
3230
3231 /*******************************************************************
3232 reads or writes a structure.
3233 ********************************************************************/
3234 void samr_io_r_delete_alias(char *desc,  SAMR_R_DELETE_DOM_ALIAS *r_u, prs_struct *ps, int depth)
3235 {
3236         if (r_u == NULL) return;
3237
3238         prs_debug(ps, depth, desc, "samr_io_r_delete_alias");
3239         depth++;
3240
3241         prs_align(ps);
3242
3243         smb_io_pol_hnd("pol", &(r_u->pol), ps, depth); 
3244         prs_uint32("status", ps, depth, &(r_u->status));
3245 }
3246
3247
3248 /*******************************************************************
3249 makes a SAMR_Q_CREATE_DOM_ALIAS structure.
3250 ********************************************************************/
3251 void make_samr_q_create_dom_alias(SAMR_Q_CREATE_DOM_ALIAS *q_u, POLICY_HND *hnd,
3252                                 const char *acct_desc)
3253 {
3254         int acct_len = acct_desc != NULL ? strlen(acct_desc) : 0;
3255         if (q_u == NULL) return;
3256
3257         DEBUG(5,("make_samr_q_create_dom_alias\n"));
3258
3259         memcpy(&(q_u->dom_pol), hnd, sizeof(q_u->dom_pol));
3260
3261         make_uni_hdr(&(q_u->hdr_acct_desc), acct_len);
3262         make_unistr2(&(q_u->uni_acct_desc), acct_desc, acct_len);
3263
3264         q_u->unknown_1 = 0x001f;
3265         q_u->unknown_2 = 0x000f;
3266 }
3267
3268
3269 /*******************************************************************
3270 reads or writes a structure.
3271 ********************************************************************/
3272 void samr_io_q_create_dom_alias(char *desc,  SAMR_Q_CREATE_DOM_ALIAS *q_u, prs_struct *ps, int depth)
3273 {
3274         if (q_u == NULL) return;
3275
3276         prs_debug(ps, depth, desc, "samr_io_q_create_dom_alias");
3277         depth++;
3278
3279         prs_align(ps);
3280
3281         smb_io_pol_hnd("dom_pol", &(q_u->dom_pol), ps, depth); 
3282
3283         smb_io_unihdr ("hdr_acct_desc", &(q_u->hdr_acct_desc) , ps, depth); 
3284         smb_io_unistr2("uni_acct_desc", &(q_u->uni_acct_desc), q_u->hdr_acct_desc.buffer, ps, depth);
3285
3286         prs_uint16("unknown_1", ps, depth, &(q_u->unknown_1));
3287         prs_uint16("unknown_2", ps, depth, &(q_u->unknown_2));
3288 }
3289
3290 /*******************************************************************
3291 makes a SAMR_R_CREATE_DOM_ALIAS structure.
3292 ********************************************************************/
3293 void make_samr_r_create_dom_alias(SAMR_R_CREATE_DOM_ALIAS *r_u, POLICY_HND *pol,
3294                 uint32 rid, uint32 status)
3295 {
3296         if (r_u == NULL) return;
3297
3298         DEBUG(5,("make_samr_r_create_dom_alias\n"));
3299
3300         memcpy(&(r_u->alias_pol), pol, sizeof(*pol));
3301         r_u->rid    = rid   ;
3302         r_u->status = status;
3303 }
3304
3305
3306 /*******************************************************************
3307 reads or writes a structure.
3308 ********************************************************************/
3309 void samr_io_r_create_dom_alias(char *desc,  SAMR_R_CREATE_DOM_ALIAS *r_u, prs_struct *ps, int depth)
3310 {
3311         if (r_u == NULL) return;
3312
3313         prs_debug(ps, depth, desc, "samr_io_r_create_dom_alias");
3314         depth++;
3315
3316         prs_align(ps);
3317
3318         smb_io_pol_hnd("alias_pol", &(r_u->alias_pol), ps, depth); 
3319         prs_uint32("rid", ps, depth, &(r_u->rid));
3320
3321         prs_uint32("status", ps, depth, &(r_u->status));
3322 }
3323
3324
3325
3326 /*******************************************************************
3327 makes a SAMR_Q_ADD_ALIASMEM structure.
3328 ********************************************************************/
3329 void make_samr_q_add_aliasmem(SAMR_Q_ADD_ALIASMEM *q_u, POLICY_HND *hnd,
3330                                 DOM_SID *sid)
3331 {
3332         if (q_u == NULL) return;
3333
3334         DEBUG(5,("make_samr_q_add_aliasmem\n"));
3335
3336         memcpy(&(q_u->alias_pol), hnd, sizeof(q_u->alias_pol));
3337         make_dom_sid2(&q_u->sid, sid);
3338 }
3339
3340
3341 /*******************************************************************
3342 reads or writes a structure.
3343 ********************************************************************/
3344 void samr_io_q_add_aliasmem(char *desc,  SAMR_Q_ADD_ALIASMEM *q_u, prs_struct *ps, int depth)
3345 {
3346         if (q_u == NULL) return;
3347
3348         prs_debug(ps, depth, desc, "samr_io_q_add_aliasmem");
3349         depth++;
3350
3351         prs_align(ps);
3352
3353         smb_io_pol_hnd ("alias_pol", &(q_u->alias_pol), ps, depth); 
3354         smb_io_dom_sid2("sid      ", &(q_u->sid      ), ps, depth); 
3355 }
3356
3357 /*******************************************************************
3358 reads or writes a structure.
3359 ********************************************************************/
3360 void samr_io_r_add_aliasmem(char *desc,  SAMR_R_ADD_ALIASMEM *r_u, prs_struct *ps, int depth)
3361 {
3362         if (r_u == NULL) return;
3363
3364         prs_debug(ps, depth, desc, "samr_io_r_add_aliasmem");
3365         depth++;
3366
3367         prs_align(ps);
3368
3369         prs_uint32("status", ps, depth, &(r_u->status));
3370 }
3371
3372
3373 /*******************************************************************
3374 makes a SAMR_Q_DEL_ALIASMEM structure.
3375 ********************************************************************/
3376 void make_samr_q_del_aliasmem(SAMR_Q_DEL_ALIASMEM *q_u, POLICY_HND *hnd,
3377                                 DOM_SID *sid)
3378 {
3379         if (q_u == NULL) return;
3380
3381         DEBUG(5,("make_samr_q_del_aliasmem\n"));
3382
3383         memcpy(&(q_u->alias_pol), hnd, sizeof(q_u->alias_pol));
3384         make_dom_sid2(&q_u->sid, sid);
3385 }
3386
3387
3388 /*******************************************************************
3389 reads or writes a structure.
3390 ********************************************************************/
3391 void samr_io_q_del_aliasmem(char *desc,  SAMR_Q_DEL_ALIASMEM *q_u, prs_struct *ps, int depth)
3392 {
3393         if (q_u == NULL) return;
3394
3395         prs_debug(ps, depth, desc, "samr_io_q_del_aliasmem");
3396         depth++;
3397
3398         prs_align(ps);
3399
3400         smb_io_pol_hnd("alias_pol", &(q_u->alias_pol), ps, depth); 
3401         smb_io_dom_sid2("sid      ", &(q_u->sid      ), ps, depth); 
3402 }
3403
3404 /*******************************************************************
3405 reads or writes a structure.
3406 ********************************************************************/
3407 void samr_io_r_del_aliasmem(char *desc,  SAMR_R_DEL_ALIASMEM *r_u, prs_struct *ps, int depth)
3408 {
3409         if (r_u == NULL) return;
3410
3411         prs_debug(ps, depth, desc, "samr_io_r_del_aliasmem");
3412         depth++;
3413
3414         prs_align(ps);
3415
3416         prs_uint32("status", ps, depth, &(r_u->status));
3417 }
3418
3419 /*******************************************************************
3420 makes a SAMR_Q_DELETE_DOM_ALIAS structure.
3421 ********************************************************************/
3422 void make_samr_q_delete_dom_alias(SAMR_Q_DELETE_DOM_ALIAS *q_c, POLICY_HND *hnd)
3423 {
3424         if (q_c == NULL || hnd == NULL) return;
3425
3426         DEBUG(5,("make_samr_q_delete_dom_alias\n"));
3427
3428         memcpy(&(q_c->alias_pol), hnd, sizeof(q_c->alias_pol));
3429 }
3430
3431 /*******************************************************************
3432 reads or writes a structure.
3433 ********************************************************************/
3434 void samr_io_q_delete_dom_alias(char *desc,  SAMR_Q_DELETE_DOM_ALIAS *q_u, prs_struct *ps, int depth)
3435 {
3436         if (q_u == NULL) return;
3437
3438         prs_debug(ps, depth, desc, "samr_io_q_delete_dom_alias");
3439         depth++;
3440
3441         prs_align(ps);
3442
3443         smb_io_pol_hnd("alias_pol", &(q_u->alias_pol), ps, depth); 
3444 }
3445
3446 /*******************************************************************
3447 makes a SAMR_R_DELETE_DOM_ALIAS structure.
3448 ********************************************************************/
3449 void make_samr_r_delete_dom_alias(SAMR_R_DELETE_DOM_ALIAS *r_u,
3450                 uint32 status)
3451 {
3452         if (r_u == NULL) return;
3453
3454         DEBUG(5,("make_samr_r_delete_dom_alias\n"));
3455
3456         r_u->status = status;
3457 }
3458
3459 /*******************************************************************
3460 reads or writes a structure.
3461 ********************************************************************/
3462 void samr_io_r_delete_dom_alias(char *desc,  SAMR_R_DELETE_DOM_ALIAS *r_u, prs_struct *ps, int depth)
3463 {
3464         if (r_u == NULL) return;
3465
3466         prs_debug(ps, depth, desc, "samr_io_r_delete_dom_alias");
3467         depth++;
3468
3469         prs_align(ps);
3470
3471         prs_uint32("status", ps, depth, &(r_u->status));
3472 }
3473
3474
3475 /*******************************************************************
3476 makes a SAMR_Q_QUERY_ALIASMEM structure.
3477 ********************************************************************/
3478 void make_samr_q_query_aliasmem(SAMR_Q_QUERY_ALIASMEM *q_c, POLICY_HND *hnd)
3479 {
3480         if (q_c == NULL || hnd == NULL) return;
3481
3482         DEBUG(5,("make_samr_q_query_aliasmem\n"));
3483
3484         memcpy(&(q_c->alias_pol), hnd, sizeof(q_c->alias_pol));
3485 }
3486
3487 /*******************************************************************
3488 reads or writes a structure.
3489 ********************************************************************/
3490 void samr_io_q_query_aliasmem(char *desc,  SAMR_Q_QUERY_ALIASMEM *q_u, prs_struct *ps, int depth)
3491 {
3492         if (q_u == NULL) return;
3493
3494         prs_debug(ps, depth, desc, "samr_io_q_query_aliasmem");
3495         depth++;
3496
3497         prs_align(ps);
3498
3499         smb_io_pol_hnd("alias_pol", &(q_u->alias_pol), ps, depth); 
3500 }
3501
3502 /*******************************************************************
3503 makes a SAMR_R_QUERY_ALIASMEM structure.
3504 ********************************************************************/
3505 void make_samr_r_query_aliasmem(SAMR_R_QUERY_ALIASMEM *r_u,
3506                 uint32 num_sids, DOM_SID2 *sid, uint32 status)
3507 {
3508         if (r_u == NULL) return;
3509
3510         DEBUG(5,("make_samr_r_query_aliasmem\n"));
3511
3512         if (status == 0x0)
3513         {
3514                 r_u->num_sids  = num_sids;
3515                 r_u->ptr       = (num_sids != 0) ? 1 : 0;
3516                 r_u->num_sids1 = num_sids;
3517
3518                 r_u->sid = sid;
3519         }
3520         else
3521         {
3522                 r_u->ptr      = 0;
3523                 r_u->num_sids = 0;
3524         }
3525
3526         r_u->status = status;
3527 }
3528
3529 /*******************************************************************
3530 reads or writes a structure.
3531 ********************************************************************/
3532 void samr_io_r_query_aliasmem(char *desc,  SAMR_R_QUERY_ALIASMEM *r_u, prs_struct *ps, int depth)
3533 {
3534         int i;
3535         uint32 ptr_sid[MAX_LOOKUP_SIDS];
3536
3537         if (r_u == NULL) return;
3538
3539         prs_debug(ps, depth, desc, "samr_io_r_query_aliasmem");
3540         depth++;
3541
3542         prs_align(ps);
3543
3544         prs_uint32("num_sids ", ps, depth, &(r_u->num_sids));
3545         prs_uint32("ptr", ps, depth, &(r_u->ptr));
3546
3547         if (r_u->ptr != 0)
3548         {
3549                 SMB_ASSERT_ARRAY(ptr_sid, r_u->num_sids);
3550
3551                 if (r_u->num_sids != 0)
3552                 {
3553                         prs_uint32("num_sids1", ps, depth, &(r_u->num_sids1));
3554
3555                         for (i = 0; i < r_u->num_sids1; i++)
3556                         {
3557                                 prs_grow(ps);
3558                                 ptr_sid[i] = 1;
3559                                 prs_uint32("", ps, depth, &(ptr_sid[i]));
3560                         }
3561                         for (i = 0; i < r_u->num_sids1; i++)
3562                         {
3563                                 prs_grow(ps);
3564                                 if (ptr_sid[i] != 0)
3565                                 {
3566                                         smb_io_dom_sid2("", &(r_u->sid[i]), ps, depth);
3567                                 }
3568                         }
3569                 }
3570         }
3571         prs_uint32("status", ps, depth, &(r_u->status));
3572 }
3573
3574 /*******************************************************************
3575 makes a SAMR_Q_LOOKUP_NAMES structure.
3576 ********************************************************************/
3577 void make_samr_q_lookup_names(SAMR_Q_LOOKUP_NAMES *q_u,
3578                 POLICY_HND *pol, uint32 flags,
3579                 uint32 num_names, const char **name)
3580 {
3581         int i;
3582         if (q_u == NULL) return;
3583
3584         DEBUG(5,("make_samr_q_lookup_names\n"));
3585
3586         memcpy(&(q_u->pol), pol, sizeof(*pol));
3587
3588         q_u->num_names1 = num_names;
3589         q_u->flags     = flags;
3590         q_u->ptr       = 0;
3591         q_u->num_names2 = num_names;
3592
3593         for (i = 0; i < num_names; i++)
3594         {
3595                 int len_name = name[i] != NULL ? strlen(name[i]) : 0;
3596                 make_uni_hdr(&(q_u->hdr_name[i]), len_name);  /* unicode header for user_name */
3597                 make_unistr2(&(q_u->uni_name[i]), name[i], len_name);  /* unicode string for machine account */
3598         }
3599 }
3600
3601
3602 /*******************************************************************
3603 reads or writes a structure.
3604 ********************************************************************/
3605 void samr_io_q_lookup_names(char *desc,  SAMR_Q_LOOKUP_NAMES *q_u, prs_struct *ps, int depth)
3606 {
3607         int i;
3608
3609         if (q_u == NULL) return;
3610
3611         prs_debug(ps, depth, desc, "samr_io_q_lookup_names");
3612         depth++;
3613
3614         prs_align(ps);
3615
3616         smb_io_pol_hnd("pol", &(q_u->pol), ps, depth); 
3617         prs_align(ps);
3618
3619         prs_uint32("num_names1", ps, depth, &(q_u->num_names1));
3620         prs_uint32("flags     ", ps, depth, &(q_u->flags     ));
3621         prs_uint32("ptr      ", ps, depth, &(q_u->ptr      ));
3622         prs_uint32("num_names2", ps, depth, &(q_u->num_names2));
3623
3624         SMB_ASSERT_ARRAY(q_u->hdr_name, q_u->num_names2);
3625
3626         for (i = 0; i < q_u->num_names2; i++)
3627         {
3628                 prs_grow(ps);
3629                 smb_io_unihdr ("", &(q_u->hdr_name[i]), ps, depth); 
3630         }
3631         for (i = 0; i < q_u->num_names2; i++)
3632         {
3633                 prs_grow(ps);