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