fix for potential lsass.exe crashing due to negative response from
[samba.git] / source3 / rpc_parse / parse_lsa.c
1 /* 
2  *  Unix SMB/Netbios implementation.
3  *  Version 1.9.
4  *  RPC Pipe client / server routines
5  *  Copyright (C) Andrew Tridgell              1992-1997,
6  *  Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
7  *  Copyright (C) Paul Ashton                       1997.
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 #include "includes.h"
25 #include "nterr.h"
26
27 extern int DEBUGLEVEL;
28
29 /*******************************************************************
30 creates a LSA_TRANS_NAME structure.
31 ********************************************************************/
32 void make_lsa_trans_name(LSA_TRANS_NAME *trn, UNISTR2 *uni_name,
33                         uint32 sid_name_use, char *name, uint32 idx)
34 {
35         int len_name = strlen(name);
36
37         trn->sid_name_use = sid_name_use;
38         make_uni_hdr(&(trn->hdr_name), len_name, len_name, 1);
39         make_unistr2(uni_name, name, len_name);
40         trn->domain_idx = idx;
41 }
42
43 /*******************************************************************
44 reads or writes a LSA_TRANS_NAME structure.
45 ********************************************************************/
46 static void lsa_io_trans_name(char *desc, LSA_TRANS_NAME *trn, prs_struct *ps, int depth)
47 {
48         if (trn == NULL) return;
49
50         prs_debug(ps, depth, desc, "lsa_io_trans_name");
51         depth++;
52
53         prs_align(ps);
54         
55         prs_uint32("sid_name_use", ps, depth, &(trn->sid_name_use));
56         smb_io_unihdr ("hdr_name", &(trn->hdr_name), ps, depth);
57         prs_uint32("domain_idx  ", ps, depth, &(trn->domain_idx  ));
58 }
59
60 /*******************************************************************
61 reads or writes a DOM_R_REF structure.
62 ********************************************************************/
63 static void lsa_io_dom_r_ref(char *desc,  DOM_R_REF *r_r, prs_struct *ps, int depth)
64 {
65         int i, s, n;
66
67         prs_debug(ps, depth, desc, "smb_io_dom_r_ref");
68         depth++;
69
70         if (r_r == NULL) return;
71
72         prs_align(ps);
73         
74         prs_uint32("undoc_buffer  ", ps, depth, &(r_r->undoc_buffer  )); /* undocumented buffer pointer. */
75         prs_uint32("num_ref_doms_1", ps, depth, &(r_r->num_ref_doms_1)); /* num referenced domains? */
76         prs_uint32("ptr_ref_dom   ", ps, depth, &(r_r->ptr_ref_dom   )); /* undocumented buffer pointer. */
77         prs_uint32("max_entries   ", ps, depth, &(r_r->max_entries   )); /* 32 - max number of entries */
78
79         SMB_ASSERT_ARRAY(r_r->hdr_ref_dom, r_r->num_ref_doms_1);
80
81         if (r_r->ptr_ref_dom != 0)
82         {
83                 prs_uint32("num_ref_doms_2", ps, depth, &(r_r->num_ref_doms_2)); /* 4 - num referenced domains? */
84                 SMB_ASSERT_ARRAY(r_r->ref_dom, r_r->num_ref_doms_2);
85
86                 for (i = 0; i < r_r->num_ref_doms_1; i++)
87                 {
88                         fstring t;
89
90                         slprintf(t, sizeof(t) - 1, "dom_ref[%d] ", i);
91                         smb_io_unihdr(t, &(r_r->hdr_ref_dom[i].hdr_dom_name), ps, depth);
92
93                         slprintf(t, sizeof(t) - 1, "sid_ptr[%d] ", i);
94                         prs_uint32(t, ps, depth, &(r_r->hdr_ref_dom[i].ptr_dom_sid));
95                 }
96
97                 for (i = 0, n = 0, s = 0; i < r_r->num_ref_doms_2; i++)
98                 {
99                         fstring t;
100
101                         if (r_r->hdr_ref_dom[i].hdr_dom_name.buffer != 0)
102                         {
103                                 slprintf(t, sizeof(t) - 1, "dom_ref[%d] ", i);
104                                 smb_io_unistr2(t, &(r_r->ref_dom[n].uni_dom_name), True, ps, depth); /* domain name unicode string */
105                                 n++;
106                         }
107
108                         if (r_r->hdr_ref_dom[i].ptr_dom_sid != 0)
109                         {
110                                 slprintf(t, sizeof(t) - 1, "sid_ptr[%d] ", i);
111                                 smb_io_dom_sid2("", &(r_r->ref_dom[s].ref_dom), ps, depth); /* referenced domain SIDs */
112                                 s++;
113                         }
114                 }
115         }
116 }
117
118
119 /*******************************************************************
120 makes an LSA_SEC_QOS structure.
121 ********************************************************************/
122 void make_lsa_sec_qos(LSA_SEC_QOS *qos, uint16 imp_lev, uint8 ctxt, uint8 eff,
123                                 uint32 unknown)
124 {
125         if (qos == NULL) return;
126
127         DEBUG(5,("make_lsa_sec_qos\n"));
128
129         qos->len = 0x0c; /* length of quality of service block, in bytes */
130         qos->sec_imp_level = imp_lev;
131         qos->sec_ctxt_mode = ctxt;
132         qos->effective_only = eff;
133         qos->unknown = unknown;
134 }
135
136 /*******************************************************************
137 reads or writes an LSA_SEC_QOS structure.
138 ********************************************************************/
139 static void lsa_io_sec_qos(char *desc,  LSA_SEC_QOS *qos, prs_struct *ps, int depth)
140 {
141         int start;
142
143         if (qos == NULL) return;
144
145         prs_debug(ps, depth, desc, "lsa_io_obj_qos");
146         depth++;
147
148         prs_align(ps);
149         
150         start = ps->offset;
151
152         /* these pointers had _better_ be zero, because we don't know
153            what they point to!
154          */
155         prs_uint32("len           ", ps, depth, &(qos->len           )); /* 0x18 - length (in bytes) inc. the length field. */
156         prs_uint16("sec_imp_level ", ps, depth, &(qos->sec_imp_level )); 
157         prs_uint8 ("sec_ctxt_mode ", ps, depth, &(qos->sec_ctxt_mode )); 
158         prs_uint8 ("effective_only", ps, depth, &(qos->effective_only)); 
159         prs_uint32("unknown       ", ps, depth, &(qos->unknown       )); 
160
161         if (qos->len != ps->offset - start)
162         {
163                 DEBUG(3,("lsa_io_sec_qos: length %x does not match size %x\n",
164                          qos->len, ps->offset - start));
165         }
166 }
167
168
169 /*******************************************************************
170 makes an LSA_OBJ_ATTR structure.
171 ********************************************************************/
172 void make_lsa_obj_attr(LSA_OBJ_ATTR *attr, uint32 attributes, LSA_SEC_QOS *qos)
173 {
174         if (attr == NULL) return;
175
176         DEBUG(5,("make_lsa_obj_attr\n"));
177
178         attr->len = 0x18; /* length of object attribute block, in bytes */
179         attr->ptr_root_dir = 0;
180         attr->ptr_obj_name = 0;
181         attr->attributes = attributes;
182         attr->ptr_sec_desc = 0;
183         
184         if (qos != NULL)
185         {
186                 attr->ptr_sec_qos = 1;
187                 attr->sec_qos = qos;
188         }
189         else
190         {
191                 attr->ptr_sec_qos = 0;
192                 attr->sec_qos = NULL;
193         }
194 }
195
196 /*******************************************************************
197 reads or writes an LSA_OBJ_ATTR structure.
198 ********************************************************************/
199 static void lsa_io_obj_attr(char *desc,  LSA_OBJ_ATTR *attr, prs_struct *ps, int depth)
200 {
201         int start;
202
203         if (attr == NULL) return;
204
205         prs_debug(ps, depth, desc, "lsa_io_obj_attr");
206         depth++;
207
208         prs_align(ps);
209         
210         start = ps->offset;
211
212         /* these pointers had _better_ be zero, because we don't know
213            what they point to!
214          */
215         prs_uint32("len         ", ps, depth, &(attr->len         )); /* 0x18 - length (in bytes) inc. the length field. */
216         prs_uint32("ptr_root_dir", ps, depth, &(attr->ptr_root_dir)); /* 0 - root directory (pointer) */
217         prs_uint32("ptr_obj_name", ps, depth, &(attr->ptr_obj_name)); /* 0 - object name (pointer) */
218         prs_uint32("attributes  ", ps, depth, &(attr->attributes  )); /* 0 - attributes (undocumented) */
219         prs_uint32("ptr_sec_desc", ps, depth, &(attr->ptr_sec_desc)); /* 0 - security descriptior (pointer) */
220         prs_uint32("ptr_sec_qos ", ps, depth, &(attr->ptr_sec_qos )); /* security quality of service (pointer) */
221
222         if (attr->len != ps->offset - start)
223         {
224                 DEBUG(3,("lsa_io_obj_attr: length %x does not match size %x\n",
225                          attr->len, ps->offset - start));
226         }
227
228         if (attr->ptr_sec_qos != 0 && attr->sec_qos != NULL)
229         {
230                 lsa_io_sec_qos("sec_qos", attr->sec_qos, ps, depth);
231         }
232 }
233
234
235 /*******************************************************************
236 makes an LSA_Q_OPEN_POL structure.
237 ********************************************************************/
238 void make_q_open_pol(LSA_Q_OPEN_POL *r_q, uint16 system_name,
239                         uint32 attributes,
240                         uint32 desired_access,
241                         LSA_SEC_QOS *qos)
242 {
243         if (r_q == NULL) return;
244
245         DEBUG(5,("make_open_pol: attr:%d da:%d\n", attributes, desired_access));
246
247         r_q->ptr = 1; /* undocumented pointer */
248
249         if (qos == NULL)
250         {
251                 r_q->des_access = desired_access;
252         }
253
254         r_q->system_name = system_name;
255         make_lsa_obj_attr(&(r_q->attr           ), attributes, qos);
256 }
257
258 /*******************************************************************
259 reads or writes an LSA_Q_OPEN_POL structure.
260 ********************************************************************/
261 void lsa_io_q_open_pol(char *desc,  LSA_Q_OPEN_POL *r_q, prs_struct *ps, int depth)
262 {
263         if (r_q == NULL) return;
264
265         prs_debug(ps, depth, desc, "lsa_io_q_open_pol");
266         depth++;
267
268         prs_uint32("ptr       ", ps, depth, &(r_q->ptr       ));
269         prs_uint16("system_name", ps, depth, &(r_q->system_name ));
270         prs_align ( ps );
271
272         lsa_io_obj_attr("", &(r_q->attr           ), ps, depth);
273
274         if (r_q->attr.ptr_sec_qos == 0)
275         {
276                 prs_uint32("des_access", ps, depth, &(r_q->des_access));
277         }
278 }
279
280 /*******************************************************************
281 reads or writes an LSA_R_OPEN_POL structure.
282 ********************************************************************/
283 void lsa_io_r_open_pol(char *desc,  LSA_R_OPEN_POL *r_p, prs_struct *ps, int depth)
284 {
285         if (r_p == NULL) return;
286
287         prs_debug(ps, depth, desc, "lsa_io_r_open_pol");
288         depth++;
289
290         smb_io_pol_hnd("", &(r_p->pol), ps, depth);
291
292         prs_uint32("status", ps, depth, &(r_p->status));
293 }
294
295 /*******************************************************************
296 makes an LSA_Q_OPEN_POL2 structure.
297 ********************************************************************/
298 void make_q_open_pol2(LSA_Q_OPEN_POL2 *r_q, char *server_name,
299                         uint32 attributes,
300                         uint32 desired_access,
301                         LSA_SEC_QOS *qos)
302 {
303         if (r_q == NULL) return;
304
305         DEBUG(5,("make_open_pol2: attr:%d da:%d\n", attributes, desired_access));
306
307         r_q->ptr = 1; /* undocumented pointer */
308
309         if (qos == NULL)
310         {
311                 r_q->des_access = desired_access;
312         }
313
314         make_unistr2     (&(r_q->uni_server_name), server_name, strlen(server_name));
315         make_lsa_obj_attr(&(r_q->attr           ), attributes, qos);
316 }
317
318 /*******************************************************************
319 reads or writes an LSA_Q_OPEN_POL2 structure.
320 ********************************************************************/
321 void lsa_io_q_open_pol2(char *desc,  LSA_Q_OPEN_POL2 *r_q, prs_struct *ps, int depth)
322 {
323         if (r_q == NULL) return;
324
325         prs_debug(ps, depth, desc, "lsa_io_q_open_pol2");
326         depth++;
327
328         prs_uint32("ptr       ", ps, depth, &(r_q->ptr       ));
329
330         smb_io_unistr2 ("", &(r_q->uni_server_name), r_q->ptr, ps, depth);
331         lsa_io_obj_attr("", &(r_q->attr           ), ps, depth);
332
333         if (r_q->attr.ptr_sec_qos == 0)
334         {
335                 prs_uint32("des_access", ps, depth, &(r_q->des_access));
336         }
337 }
338
339 /*******************************************************************
340 reads or writes an LSA_R_OPEN_POL2 structure.
341 ********************************************************************/
342 void lsa_io_r_open_pol2(char *desc,  LSA_R_OPEN_POL2 *r_p, prs_struct *ps, int depth)
343 {
344         if (r_p == NULL) return;
345
346         prs_debug(ps, depth, desc, "lsa_io_r_open_pol2");
347         depth++;
348
349         smb_io_pol_hnd("", &(r_p->pol), ps, depth);
350
351         prs_uint32("status", ps, depth, &(r_p->status));
352 }
353
354 /*******************************************************************
355 makes an LSA_Q_QUERY_INFO structure.
356 ********************************************************************/
357 void make_q_query(LSA_Q_QUERY_INFO *q_q, POLICY_HND *hnd, uint16 info_class)
358 {
359         if (q_q == NULL || hnd == NULL) return;
360
361         DEBUG(5,("make_q_query\n"));
362
363         memcpy(&(q_q->pol), hnd, sizeof(q_q->pol));
364
365         q_q->info_class = info_class;
366 }
367
368 /*******************************************************************
369 reads or writes an LSA_Q_QUERY_INFO structure.
370 ********************************************************************/
371 void lsa_io_q_query(char *desc,  LSA_Q_QUERY_INFO *q_q, prs_struct *ps, int depth)
372 {
373         if (q_q == NULL) return;
374
375         prs_debug(ps, depth, desc, "lsa_io_q_query");
376         depth++;
377
378         smb_io_pol_hnd("", &(q_q->pol), ps, depth);
379
380         prs_uint16("info_class", ps, depth, &(q_q->info_class));
381 }
382
383 /*******************************************************************
384 reads or writes an LSA_Q_ENUM_TRUST_DOM structure.
385 ********************************************************************/
386 void lsa_io_q_enum_trust_dom(char *desc,  LSA_Q_ENUM_TRUST_DOM *q_e, prs_struct *ps, int depth)
387 {
388         if (q_e == NULL) return;
389
390         prs_debug(ps, depth, desc, "lsa_io_q_enum_trust_dom");
391         depth++;
392
393
394         smb_io_pol_hnd("", &(q_e->pol), ps, depth);
395
396         prs_uint32("enum_context ", ps, depth, &(q_e->enum_context ));
397         prs_uint32("preferred_len", ps, depth, &(q_e->preferred_len));
398 }
399
400 /*******************************************************************
401 makes an LSA_R_ENUM_TRUST_DOM structure.
402 ********************************************************************/
403 void make_r_enum_trust_dom(LSA_R_ENUM_TRUST_DOM *r_e,
404                            uint32 enum_context, char *domain_name, DOM_SID *domain_sid,
405                            uint32 status)
406 {
407         if (r_e == NULL) return;
408
409         DEBUG(5,("make_r_enum_trust_dom\n"));
410
411         r_e->enum_context = enum_context;
412
413         if (status == 0)
414         {
415                 int len_domain_name = strlen(domain_name);
416
417                 r_e->num_domains  = 1;
418                 r_e->ptr_enum_domains = 1;
419                 r_e->num_domains2 = 1;
420
421                 make_uni_hdr2(&(r_e->hdr_domain_name ), len_domain_name, len_domain_name, 4);
422                 make_unistr2 (&(r_e->uni_domain_name ), domain_name, len_domain_name);
423                 make_dom_sid2(&(r_e->other_domain_sid), domain_sid);
424         }
425         else
426         {
427                 r_e->num_domains = 0;
428                 r_e->ptr_enum_domains = 0;
429         }
430
431         r_e->status = status;
432 }
433
434 /*******************************************************************
435 reads or writes an LSA_R_ENUM_TRUST_DOM structure.
436 ********************************************************************/
437 void lsa_io_r_enum_trust_dom(char *desc,  LSA_R_ENUM_TRUST_DOM *r_e, prs_struct *ps, int depth)
438 {
439         if (r_e == NULL) return;
440
441         prs_debug(ps, depth, desc, "lsa_io_r_enum_trust_dom");
442         depth++;
443
444         prs_uint32("enum_context    ", ps, depth, &(r_e->enum_context    ));
445         prs_uint32("num_domains     ", ps, depth, &(r_e->num_domains     ));
446         prs_uint32("ptr_enum_domains", ps, depth, &(r_e->ptr_enum_domains));
447
448         if (r_e->ptr_enum_domains != 0)
449         {
450                 prs_uint32("num_domains2", ps, depth, &(r_e->num_domains2));
451                 smb_io_unihdr2 ("", &(r_e->hdr_domain_name ), ps, depth);
452                 smb_io_unistr2 ("", &(r_e->uni_domain_name ), r_e->hdr_domain_name.buffer, ps, depth);
453                 smb_io_dom_sid2("", &(r_e->other_domain_sid), ps, depth);
454         }
455
456         prs_uint32("status", ps, depth, &(r_e->status));
457 }
458
459 /*******************************************************************
460 reads or writes an LSA_Q_QUERY_INFO structure.
461 ********************************************************************/
462 void lsa_io_r_query(char *desc,  LSA_R_QUERY_INFO *r_q, prs_struct *ps, int depth)
463 {
464         if (r_q == NULL) return;
465
466         prs_debug(ps, depth, desc, "lsa_io_r_query");
467         depth++;
468
469         prs_uint32("undoc_buffer", ps, depth, &(r_q->undoc_buffer));
470
471         if (r_q->undoc_buffer != 0)
472         {
473                 prs_uint16("info_class", ps, depth, &(r_q->info_class));
474
475                 switch (r_q->info_class)
476                 {
477                         case 3:
478                         {
479                                 smb_io_dom_query_3("", &(r_q->dom.id3), ps, depth);
480                                 break;
481                         }
482                         case 5:
483                         {
484                                 smb_io_dom_query_5("", &(r_q->dom.id3), ps, depth);
485                                 break;
486                         }
487                         default:
488                         {
489                                 /* PANIC! */
490                                 break;
491                         }
492                 }
493         }
494
495         prs_uint32("status", ps, depth, &(r_q->status));
496 }
497
498 /*******************************************************************
499 makes a LSA_SID_ENUM structure.
500 ********************************************************************/
501 void make_lsa_sid_enum(LSA_SID_ENUM *sen, int num_entries, DOM_SID **sids)
502 {
503         int i, i2;
504         if (sen == NULL || sids == NULL) return;
505
506         DEBUG(5,("make_lsa_sid_enum\n"));
507
508         sen->num_entries  = num_entries;
509         sen->ptr_sid_enum = num_entries != 0 ? 1 : 0;
510         sen->num_entries2 = num_entries;
511
512         SMB_ASSERT_ARRAY(sen->sid, sen->num_entries);
513
514         for (i = 0, i2 = 0; i < num_entries; i++)
515         {
516                 if (sids[i] != NULL)
517                 {
518                         sen->ptr_sid[i] = 1;
519                         make_dom_sid2(&(sen->sid[i2]), sids[i]);
520                         i2++;
521                 }
522                 else
523                 {
524                         sen->ptr_sid[i] = 0;
525                 }
526         }
527 }
528
529 /*******************************************************************
530 reads or writes a LSA_SID_ENUM structure.
531 ********************************************************************/
532 static void lsa_io_sid_enum(char *desc, LSA_SID_ENUM *sen,
533                                 prs_struct *ps, int depth)
534 {
535         int i;
536
537         if (sen == NULL) return;
538
539         prs_debug(ps, depth, desc, "lsa_io_sid_enum");
540         depth++;
541
542         prs_align(ps);
543         
544         prs_uint32("num_entries ", ps, depth, &(sen->num_entries));
545         prs_uint32("ptr_sid_enum", ps, depth, &(sen->ptr_sid_enum)); 
546         prs_uint32("num_entries2", ps, depth, &(sen->num_entries2)); 
547
548         SMB_ASSERT_ARRAY(sen->ptr_sid, sen->num_entries);
549
550         for (i = 0; i < sen->num_entries; i++)
551         {       
552                 fstring temp;
553                 slprintf(temp, sizeof(temp) - 1, "ptr_sid[%d]", i);
554                 prs_uint32(temp, ps, depth, &(sen->ptr_sid[i])); /* domain SID pointers to be looked up. */
555         }
556
557         SMB_ASSERT_ARRAY(sen->sid, sen->num_entries);
558
559         for (i = 0; i < sen->num_entries; i++)
560         {
561                 fstring temp;
562                 slprintf(temp, sizeof(temp) - 1, "sid[%d]", i);
563                 smb_io_dom_sid2(temp, &(sen->sid[i]), ps, depth); /* domain SIDs to be looked up. */
564         }
565 }
566
567 /*******************************************************************
568 reads or writes a structure.
569 ********************************************************************/
570 static void lsa_io_trans_names(char *desc, LSA_TRANS_NAME_ENUM *trn,
571                                 prs_struct *ps, int depth)
572 {
573         int i;
574
575         if (trn == NULL) return;
576
577         prs_debug(ps, depth, desc, "lsa_io_trans_names");
578         depth++;
579
580         prs_align(ps);
581         
582         prs_uint32("num_entries    ", ps, depth, &(trn->num_entries));
583         prs_uint32("ptr_trans_names", ps, depth, &(trn->ptr_trans_names));
584
585         if (trn->ptr_trans_names != 0)
586         {
587                 prs_uint32("num_entries2   ", ps, depth, &(trn->num_entries2));
588                 SMB_ASSERT_ARRAY(trn->name, trn->num_entries);
589
590                 for (i = 0; i < trn->num_entries2; i++)
591                 {
592                         fstring t;
593                         slprintf(t, sizeof(t) - 1, "name[%d] ", i);
594
595                         lsa_io_trans_name(t, &(trn->name[i]), ps, depth); /* translated name */
596
597                 }
598                 for (i = 0; i < trn->num_entries2; i++)
599                 {
600                         fstring t;
601                         slprintf(t, sizeof(t) - 1, "name[%d] ", i);
602
603                         smb_io_unistr2(t, &(trn->uni_name[i]), trn->name[i].hdr_name.buffer, ps, depth);
604                         prs_align(ps);
605                 }
606         }
607 }
608
609 /*******************************************************************
610 makes a structure.
611 ********************************************************************/
612 void make_q_lookup_sids(LSA_Q_LOOKUP_SIDS *q_l, POLICY_HND *hnd,
613                                 int num_sids, DOM_SID **sids,
614                                 uint16 level)
615 {
616         if (q_l == NULL) return;
617
618         DEBUG(5,("make_q_lookup_sids\n"));
619
620         memcpy(&(q_l->pol), hnd, sizeof(q_l->pol));
621         make_lsa_sid_enum(&(q_l->sids), num_sids, sids);
622
623         q_l->names.ptr_trans_names = 0;
624         q_l->names.num_entries     = 0;
625
626         q_l->level.value = level;
627 }
628
629 /*******************************************************************
630 reads or writes a LSA_Q_LOOKUP_SIDS structure.
631 ********************************************************************/
632 void lsa_io_q_lookup_sids(char *desc, LSA_Q_LOOKUP_SIDS *q_s, prs_struct *ps, int depth)
633 {
634         if (q_s == NULL) return;
635
636         prs_debug(ps, depth, desc, "lsa_io_q_lookup_sids");
637         depth++;
638
639         prs_align(ps);
640         
641         smb_io_pol_hnd     ("pol_hnd", &(q_s->pol), ps, depth); /* policy handle */
642         lsa_io_sid_enum    ("sids   ", &(q_s->sids   ), ps, depth); /* sids to be looked up */
643         lsa_io_trans_names ("names  ", &(q_s->names  ), ps, depth); /* translated names */
644         smb_io_lookup_level("switch ", &(q_s->level  ), ps, depth); /* lookup level */
645
646         prs_uint32("mapped_count", ps, depth, &(q_s->mapped_count));
647 }
648
649 /*******************************************************************
650 reads or writes a structure.
651 ********************************************************************/
652 void lsa_io_r_lookup_sids(char *desc,  LSA_R_LOOKUP_SIDS *r_s, prs_struct *ps, int depth)
653 {
654         if (r_s == NULL) return;
655
656         prs_debug(ps, depth, desc, "lsa_io_r_lookup_sids");
657         depth++;
658
659         prs_align(ps);
660         
661         lsa_io_dom_r_ref  ("dom_ref", r_s->dom_ref, ps, depth); /* domain reference info */
662         lsa_io_trans_names("names  ", r_s->names  , ps, depth); /* translated names */
663
664         prs_align(ps);
665
666         prs_uint32("mapped_count", ps, depth, &(r_s->mapped_count));
667
668         prs_uint32("status      ", ps, depth, &(r_s->status));
669 }
670
671 /*******************************************************************
672 makes a structure.
673 ********************************************************************/
674 void make_q_lookup_names(LSA_Q_LOOKUP_NAMES *q_l, POLICY_HND *hnd,
675                                 int num_names, const char **names)
676 {
677         int i;
678         if (q_l == NULL) return;
679
680         DEBUG(5,("make_q_lookup_names\n"));
681
682         memcpy(&(q_l->pol), hnd, sizeof(q_l->pol));
683
684         q_l->num_entries     = num_names;
685         q_l->num_entries2    = num_names;
686
687         SMB_ASSERT_ARRAY(q_l->uni_name, q_l->num_entries);
688
689         for (i = 0; i < num_names; i++)
690         {
691                 int len = strlen(names[i]);
692                 make_uni_hdr(&q_l->hdr_name[i], len, len, len != 0);
693                 make_unistr2(&q_l->uni_name[i], names[i], len);
694         }
695
696         q_l->num_trans_entries  = 0;
697         q_l->ptr_trans_sids  = 0;
698         q_l->lookup_level = 1;
699         q_l->mapped_count = 0;
700 }
701
702 /*******************************************************************
703 reads or writes a structure.
704 ********************************************************************/
705 void lsa_io_q_lookup_names(char *desc,  LSA_Q_LOOKUP_NAMES *q_r, prs_struct *ps, int depth)
706 {
707         int i;
708
709         if (q_r == NULL) return;
710
711         prs_debug(ps, depth, desc, "lsa_io_q_lookup_names");
712         depth++;
713
714         prs_align(ps);
715         
716         smb_io_pol_hnd("", &(q_r->pol), ps, depth); /* policy handle */
717
718         prs_uint32("num_entries    ", ps, depth, &(q_r->num_entries));
719         prs_uint32("num_entries2   ", ps, depth, &(q_r->num_entries2));
720
721         SMB_ASSERT_ARRAY(q_r->uni_name, q_r->num_entries);
722
723         for (i = 0; i < q_r->num_entries; i++)
724         {
725                 smb_io_unihdr("hdr_name", &(q_r->hdr_name[i]), ps, depth); /* pointer names */
726         }
727
728         for (i = 0; i < q_r->num_entries; i++)
729         {
730                 smb_io_unistr2("dom_name", &(q_r->uni_name[i]), q_r->hdr_name[i].buffer, ps, depth); /* names to be looked up */
731                 prs_align(ps);
732         }
733
734         prs_uint32("num_trans_entries ", ps, depth, &(q_r->num_trans_entries));
735         prs_uint32("ptr_trans_sids ", ps, depth, &(q_r->ptr_trans_sids));
736         prs_uint32("lookup_level   ", ps, depth, &(q_r->lookup_level  ));
737         prs_uint32("mapped_count   ", ps, depth, &(q_r->mapped_count  ));
738 }
739
740 /*******************************************************************
741 reads or writes a structure.
742 ********************************************************************/
743 void lsa_io_r_lookup_names(char *desc,  LSA_R_LOOKUP_NAMES *r_r, prs_struct *ps, int depth)
744 {
745         int i;
746
747         if (r_r == NULL) return;
748
749         prs_debug(ps, depth, desc, "lsa_io_r_lookup_names");
750         depth++;
751
752         prs_align(ps);
753         
754         lsa_io_dom_r_ref("", r_r->dom_ref, ps, depth); /* domain reference info */
755
756         prs_uint32("num_entries ", ps, depth, &(r_r->num_entries));
757         prs_uint32("undoc_buffer", ps, depth, &(r_r->undoc_buffer));
758         prs_uint32("num_entries2", ps, depth, &(r_r->num_entries2));
759
760         for (i = 0; i < r_r->num_entries2; i++)
761         {
762                 smb_io_dom_rid2("", &(r_r->dom_rid[i]), ps, depth); /* domain RIDs being looked up */
763         }
764
765         prs_uint32("mapped_count", ps, depth, &(r_r->mapped_count));
766
767         prs_uint32("status      ", ps, depth, &(r_r->status));
768 }
769
770
771 /*******************************************************************
772 makes an LSA_Q_CLOSE structure.
773 ********************************************************************/
774 void make_lsa_q_close(LSA_Q_CLOSE *q_c, POLICY_HND *hnd)
775 {
776         if (q_c == NULL || hnd == NULL) return;
777
778         DEBUG(5,("make_lsa_q_close\n"));
779
780         memcpy(&(q_c->pol), hnd, sizeof(q_c->pol));
781 }
782
783 /*******************************************************************
784 reads or writes an LSA_Q_CLOSE structure.
785 ********************************************************************/
786 void lsa_io_q_close(char *desc,  LSA_Q_CLOSE *q_c, prs_struct *ps, int depth)
787 {
788         if (q_c == NULL) return;
789
790         prs_debug(ps, depth, desc, "lsa_io_q_close");
791         depth++;
792
793         smb_io_pol_hnd("", &(q_c->pol), ps, depth);
794 }
795
796 /*******************************************************************
797 reads or writes an LSA_R_CLOSE structure.
798 ********************************************************************/
799 void lsa_io_r_close(char *desc,  LSA_R_CLOSE *r_c, prs_struct *ps, int depth)
800 {
801         if (r_c == NULL) return;
802
803         prs_debug(ps, depth, desc, "lsa_io_r_close");
804         depth++;
805
806         smb_io_pol_hnd("", &(r_c->pol), ps, depth);
807
808         prs_uint32("status", ps, depth, &(r_c->status));
809 }
810