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