removed 2 unnecessary args from make_uni_hdr.
[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 /*******************************************************************
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);
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("num_ref_doms_1", ps, depth, &(r_r->num_ref_doms_1)); /* num referenced domains? */
75         prs_uint32("ptr_ref_dom   ", ps, depth, &(r_r->ptr_ref_dom   )); /* undocumented buffer pointer. */
76         prs_uint32("max_entries   ", ps, depth, &(r_r->max_entries   )); /* 32 - max number of entries */
77
78         SMB_ASSERT_ARRAY(r_r->hdr_ref_dom, r_r->num_ref_doms_1);
79
80         if (r_r->ptr_ref_dom != 0)
81         {
82                 prs_uint32("num_ref_doms_2", ps, depth, &(r_r->num_ref_doms_2)); /* 4 - num referenced domains? */
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 /*******************************************************************
119 makes an LSA_SEC_QOS structure.
120 ********************************************************************/
121 void make_lsa_sec_qos(LSA_SEC_QOS *qos, uint16 imp_lev, uint8 ctxt, uint8 eff,
122                                 uint32 unknown)
123 {
124         if (qos == NULL) return;
125
126         DEBUG(5,("make_lsa_sec_qos\n"));
127
128         qos->len = 0x0c; /* length of quality of service block, in bytes */
129         qos->sec_imp_level = imp_lev;
130         qos->sec_ctxt_mode = ctxt;
131         qos->effective_only = eff;
132         qos->unknown = unknown;
133 }
134
135 /*******************************************************************
136 reads or writes an LSA_SEC_QOS structure.
137 ********************************************************************/
138 static void lsa_io_sec_qos(char *desc,  LSA_SEC_QOS *qos, prs_struct *ps, int depth)
139 {
140         int start;
141
142         if (qos == NULL) return;
143
144         prs_debug(ps, depth, desc, "lsa_io_obj_qos");
145         depth++;
146
147         prs_align(ps);
148         
149         start = ps->offset;
150
151         /* these pointers had _better_ be zero, because we don't know
152            what they point to!
153          */
154         prs_uint32("len           ", ps, depth, &(qos->len           )); /* 0x18 - length (in bytes) inc. the length field. */
155         prs_uint16("sec_imp_level ", ps, depth, &(qos->sec_imp_level )); 
156         prs_uint8 ("sec_ctxt_mode ", ps, depth, &(qos->sec_ctxt_mode )); 
157         prs_uint8 ("effective_only", ps, depth, &(qos->effective_only)); 
158         prs_uint32("unknown       ", ps, depth, &(qos->unknown       )); 
159
160         if (qos->len != ps->offset - start)
161         {
162                 DEBUG(3,("lsa_io_sec_qos: length %x does not match size %x\n",
163                          qos->len, ps->offset - start));
164         }
165 }
166
167
168 /*******************************************************************
169 makes an LSA_OBJ_ATTR structure.
170 ********************************************************************/
171 void make_lsa_obj_attr(LSA_OBJ_ATTR *attr, uint32 attributes, LSA_SEC_QOS *qos)
172 {
173         if (attr == NULL) return;
174
175         DEBUG(5,("make_lsa_obj_attr\n"));
176
177         attr->len = 0x18; /* length of object attribute block, in bytes */
178         attr->ptr_root_dir = 0;
179         attr->ptr_obj_name = 0;
180         attr->attributes = attributes;
181         attr->ptr_sec_desc = 0;
182         
183         if (qos != NULL)
184         {
185                 attr->ptr_sec_qos = 1;
186                 attr->sec_qos = qos;
187         }
188         else
189         {
190                 attr->ptr_sec_qos = 0;
191                 attr->sec_qos = NULL;
192         }
193 }
194
195 /*******************************************************************
196 reads or writes an LSA_OBJ_ATTR structure.
197 ********************************************************************/
198 static void lsa_io_obj_attr(char *desc,  LSA_OBJ_ATTR *attr, prs_struct *ps, int depth)
199 {
200         int start;
201
202         if (attr == NULL) return;
203
204         prs_debug(ps, depth, desc, "lsa_io_obj_attr");
205         depth++;
206
207         prs_align(ps);
208         
209         start = ps->offset;
210
211         /* these pointers had _better_ be zero, because we don't know
212            what they point to!
213          */
214         prs_uint32("len         ", ps, depth, &(attr->len         )); /* 0x18 - length (in bytes) inc. the length field. */
215         prs_uint32("ptr_root_dir", ps, depth, &(attr->ptr_root_dir)); /* 0 - root directory (pointer) */
216         prs_uint32("ptr_obj_name", ps, depth, &(attr->ptr_obj_name)); /* 0 - object name (pointer) */
217         prs_uint32("attributes  ", ps, depth, &(attr->attributes  )); /* 0 - attributes (undocumented) */
218         prs_uint32("ptr_sec_desc", ps, depth, &(attr->ptr_sec_desc)); /* 0 - security descriptior (pointer) */
219         prs_uint32("ptr_sec_qos ", ps, depth, &(attr->ptr_sec_qos )); /* security quality of service (pointer) */
220
221         if (attr->len != ps->offset - start)
222         {
223                 DEBUG(3,("lsa_io_obj_attr: length %x does not match size %x\n",
224                          attr->len, ps->offset - start));
225         }
226
227         if (attr->ptr_sec_qos != 0 && attr->sec_qos != NULL)
228         {
229                 lsa_io_sec_qos("sec_qos", attr->sec_qos, ps, depth);
230         }
231 }
232
233
234 /*******************************************************************
235 makes an LSA_Q_OPEN_POL structure.
236 ********************************************************************/
237 void make_q_open_pol(LSA_Q_OPEN_POL *r_q, uint16 system_name,
238                         uint32 attributes,
239                         uint32 desired_access,
240                         LSA_SEC_QOS *qos)
241 {
242         if (r_q == NULL) return;
243
244         DEBUG(5,("make_open_pol: attr:%d da:%d\n", attributes, desired_access));
245
246         r_q->ptr = 1; /* undocumented pointer */
247
248         if (qos == NULL)
249         {
250                 r_q->des_access = desired_access;
251         }
252
253         r_q->system_name = system_name;
254         make_lsa_obj_attr(&(r_q->attr           ), attributes, qos);
255 }
256
257 /*******************************************************************
258 reads or writes an LSA_Q_OPEN_POL structure.
259 ********************************************************************/
260 void lsa_io_q_open_pol(char *desc,  LSA_Q_OPEN_POL *r_q, prs_struct *ps, int depth)
261 {
262         if (r_q == NULL) return;
263
264         prs_debug(ps, depth, desc, "lsa_io_q_open_pol");
265         depth++;
266
267         prs_uint32("ptr       ", ps, depth, &(r_q->ptr       ));
268         prs_uint16("system_name", ps, depth, &(r_q->system_name ));
269         prs_align ( ps );
270
271         lsa_io_obj_attr("", &(r_q->attr           ), ps, depth);
272
273         if (r_q->attr.ptr_sec_qos == 0)
274         {
275                 prs_uint32("des_access", ps, depth, &(r_q->des_access));
276         }
277 }
278
279 /*******************************************************************
280 reads or writes an LSA_R_OPEN_POL structure.
281 ********************************************************************/
282 void lsa_io_r_open_pol(char *desc,  LSA_R_OPEN_POL *r_p, prs_struct *ps, int depth)
283 {
284         if (r_p == NULL) return;
285
286         prs_debug(ps, depth, desc, "lsa_io_r_open_pol");
287         depth++;
288
289         smb_io_pol_hnd("", &(r_p->pol), ps, depth);
290
291         prs_uint32("status", ps, depth, &(r_p->status));
292 }
293
294 /*******************************************************************
295 makes an LSA_Q_OPEN_POL2 structure.
296 ********************************************************************/
297 void make_q_open_pol2(LSA_Q_OPEN_POL2 *r_q, char *server_name,
298                         uint32 attributes,
299                         uint32 desired_access,
300                         LSA_SEC_QOS *qos)
301 {
302         if (r_q == NULL) return;
303
304         DEBUG(5,("make_open_pol2: attr:%d da:%d\n", attributes, desired_access));
305
306         r_q->ptr = 1; /* undocumented pointer */
307
308         if (qos == NULL)
309         {
310                 r_q->des_access = desired_access;
311         }
312
313         make_unistr2     (&(r_q->uni_server_name), server_name, strlen(server_name));
314         make_lsa_obj_attr(&(r_q->attr           ), attributes, qos);
315 }
316
317 /*******************************************************************
318 reads or writes an LSA_Q_OPEN_POL2 structure.
319 ********************************************************************/
320 void lsa_io_q_open_pol2(char *desc,  LSA_Q_OPEN_POL2 *r_q, prs_struct *ps, int depth)
321 {
322         if (r_q == NULL) return;
323
324         prs_debug(ps, depth, desc, "lsa_io_q_open_pol2");
325         depth++;
326
327         prs_uint32("ptr       ", ps, depth, &(r_q->ptr       ));
328
329         smb_io_unistr2 ("", &(r_q->uni_server_name), r_q->ptr, ps, depth);
330         lsa_io_obj_attr("", &(r_q->attr           ), ps, depth);
331
332         if (r_q->attr.ptr_sec_qos == 0)
333         {
334                 prs_uint32("des_access", ps, depth, &(r_q->des_access));
335         }
336 }
337
338 /*******************************************************************
339 reads or writes an LSA_R_OPEN_POL2 structure.
340 ********************************************************************/
341 void lsa_io_r_open_pol2(char *desc,  LSA_R_OPEN_POL2 *r_p, prs_struct *ps, int depth)
342 {
343         if (r_p == NULL) return;
344
345         prs_debug(ps, depth, desc, "lsa_io_r_open_pol2");
346         depth++;
347
348         smb_io_pol_hnd("", &(r_p->pol), ps, depth);
349
350         prs_uint32("status", ps, depth, &(r_p->status));
351 }
352
353 /*******************************************************************
354 makes an LSA_Q_QUERY_INFO structure.
355 ********************************************************************/
356 void make_q_query(LSA_Q_QUERY_INFO *q_q, POLICY_HND *hnd, uint16 info_class)
357 {
358         if (q_q == NULL || hnd == NULL) return;
359
360         DEBUG(5,("make_q_query\n"));
361
362         memcpy(&(q_q->pol), hnd, sizeof(q_q->pol));
363
364         q_q->info_class = info_class;
365 }
366
367 /*******************************************************************
368 reads or writes an LSA_Q_QUERY_INFO structure.
369 ********************************************************************/
370 void lsa_io_q_query(char *desc,  LSA_Q_QUERY_INFO *q_q, prs_struct *ps, int depth)
371 {
372         if (q_q == NULL) return;
373
374         prs_debug(ps, depth, desc, "lsa_io_q_query");
375         depth++;
376
377         smb_io_pol_hnd("", &(q_q->pol), ps, depth);
378
379         prs_uint16("info_class", ps, depth, &(q_q->info_class));
380 }
381
382 /*******************************************************************
383 makes an LSA_Q_OPEN_SECRET structure.
384 ********************************************************************/
385 void make_q_open_secret(LSA_Q_OPEN_SECRET *q_o, POLICY_HND *pol_hnd,
386                         char *secret_name, uint32 desired_access)
387 {
388         int len = strlen(secret_name);
389
390         if (q_o == NULL) return;
391
392         DEBUG(5,("make_q_open_secret"));
393
394         memcpy(&(q_o->pol), pol_hnd, sizeof(q_o->pol));
395
396         make_uni_hdr(&(q_o->hdr_secret), len);
397         make_unistr2(&(q_o->uni_secret), secret_name, len);
398
399         q_o->des_access = desired_access;
400 }
401
402 /*******************************************************************
403 reads or writes an LSA_Q_OPEN_SECRET structure.
404 ********************************************************************/
405 void lsa_io_q_open_secret(char *desc, LSA_Q_OPEN_SECRET *q_o, prs_struct *ps, int depth)
406 {
407         if (q_o == NULL) return;
408
409         prs_debug(ps, depth, desc, "lsa_io_q_open_secret");
410         depth++;
411
412         smb_io_pol_hnd("", &(q_o->pol), ps, depth);
413
414         prs_align(ps);
415         smb_io_unihdr ("", &(q_o->hdr_secret), ps, depth);
416         smb_io_unistr2("", &(q_o->uni_secret), 1, ps, depth);
417
418         prs_align(ps);
419         prs_uint32("des_access", ps, depth, &(q_o->des_access));
420 }
421
422 /*******************************************************************
423 reads or writes an LSA_R_OPEN_SECRET structure.
424 ********************************************************************/
425 void lsa_io_r_open_secret(char *desc, LSA_R_OPEN_SECRET *r_o, prs_struct *ps, int depth)
426 {
427         if (r_o == NULL) return;
428
429         prs_debug(ps, depth, desc, "lsa_io_r_open_secret");
430         depth++;
431
432         smb_io_pol_hnd("", &(r_o->pol), ps, depth);
433
434         prs_uint32("status", ps, depth, &(r_o->status));
435 }
436
437 /*******************************************************************
438 reads or writes an LSA_SECRET_VALUE structure.
439 ********************************************************************/
440 void lsa_io_secret_value(char *desc, LSA_SECRET_VALUE *value, prs_struct *ps, int depth)
441 {
442         if (value == NULL) return;
443
444         prs_debug(ps, depth, desc, "lsa_io_secret_value");
445         depth++;
446
447         prs_align(ps);
448         prs_uint32("ptr_secret", ps, depth, &(value->ptr_secret));
449
450         if (value->ptr_secret != 0)
451         {
452                 smb_io_strhdr2("hdr_secret", &(value->hdr_secret), ps, depth);
453                 smb_io_string2("secret"    , &(value->enc_secret),
454                                value->hdr_secret.buffer, ps, depth);
455         }
456 }
457
458 /*******************************************************************
459 reads or writes an LSA_SECRET_INFO structure.
460 ********************************************************************/
461 void lsa_io_secret_info(char *desc, LSA_SECRET_INFO *info, prs_struct *ps, int depth)
462 {
463         if (info == NULL) return;
464
465         prs_debug(ps, depth, desc, "lsa_io_secret_info");
466         depth++;
467
468         prs_align(ps);
469         prs_uint32("ptr_value ", ps, depth, &(info->ptr_value ));
470
471         if (info->ptr_value != 0)
472         {
473                 lsa_io_secret_value("", &(info->value), ps, depth);
474         }
475
476         prs_align(ps);
477         prs_uint32("ptr_update", ps, depth, &(info->ptr_update));
478
479         if (info->ptr_update != 0)
480         {
481                 ps->align = 8;
482                 prs_align(ps);
483                 ps->align = 4;
484
485                 smb_io_time("last_update", &(info->last_update), ps, depth);
486         }
487 }
488
489 /*******************************************************************
490 makes an LSA_Q_QUERY_SECRET structure.
491 ********************************************************************/
492 void make_q_query_secret(LSA_Q_QUERY_SECRET *q_q, POLICY_HND *pol)
493 {
494         if (q_q == NULL) return;
495
496         DEBUG(5,("make_q_query_secret"));
497
498         memcpy(&(q_q->pol), pol, sizeof(q_q->pol));
499
500         /* Want secret */
501         q_q->info.ptr_value = 1;
502         q_q->info.value.ptr_secret = 0;
503
504         /* Want last change time */
505         q_q->info.ptr_update = 1;
506
507         /* Don't care about old info */
508         q_q->oldinfo.ptr_value = 0;
509         q_q->oldinfo.ptr_update = 0;
510 }
511
512 /*******************************************************************
513 reads or writes an LSA_Q_QUERY_SECRET structure.
514 ********************************************************************/
515 void lsa_io_q_query_secret(char *desc, LSA_Q_QUERY_SECRET *q_q, prs_struct *ps, int depth)
516 {
517         if (q_q == NULL) return;
518
519         prs_debug(ps, depth, desc, "lsa_io_q_query_secret");
520         depth++;
521
522         smb_io_pol_hnd("", &(q_q->pol), ps, depth);
523
524         lsa_io_secret_info("", &(q_q->info   ), ps, depth);
525         lsa_io_secret_info("", &(q_q->oldinfo), ps, depth);
526 }
527
528 /*******************************************************************
529 reads or writes an LSA_Q_QUERY_SECRET structure.
530 ********************************************************************/
531 void lsa_io_r_query_secret(char *desc, LSA_R_QUERY_SECRET *r_q, prs_struct *ps, int depth)
532 {
533         if (r_q == NULL) return;
534
535         prs_debug(ps, depth, desc, "lsa_io_r_query_secret");
536         depth++;
537
538         lsa_io_secret_info("", &(r_q->info   ), ps, depth);
539         lsa_io_secret_info("", &(r_q->oldinfo), ps, depth);
540
541         prs_align(ps);
542         prs_uint32("status", ps, depth, &(r_q->status));
543 }
544
545 /*******************************************************************
546 reads or writes an LSA_Q_ENUM_TRUST_DOM structure.
547 ********************************************************************/
548 void lsa_io_q_enum_trust_dom(char *desc,  LSA_Q_ENUM_TRUST_DOM *q_e, prs_struct *ps, int depth)
549 {
550         if (q_e == NULL) return;
551
552         prs_debug(ps, depth, desc, "lsa_io_q_enum_trust_dom");
553         depth++;
554
555
556         smb_io_pol_hnd("", &(q_e->pol), ps, depth);
557
558         prs_uint32("enum_context ", ps, depth, &(q_e->enum_context ));
559         prs_uint32("preferred_len", ps, depth, &(q_e->preferred_len));
560 }
561
562 /*******************************************************************
563 makes an LSA_R_ENUM_TRUST_DOM structure.
564 ********************************************************************/
565 void make_r_enum_trust_dom(LSA_R_ENUM_TRUST_DOM *r_e,
566                            uint32 enum_context, char *domain_name, DOM_SID *domain_sid,
567                            uint32 status)
568 {
569         if (r_e == NULL) return;
570
571         DEBUG(5,("make_r_enum_trust_dom\n"));
572
573         r_e->enum_context = enum_context;
574
575         if (status == 0)
576         {
577                 int len_domain_name = strlen(domain_name);
578
579                 r_e->num_domains  = 1;
580                 r_e->ptr_enum_domains = 1;
581                 r_e->num_domains2 = 1;
582
583                 make_uni_hdr2(&(r_e->hdr_domain_name ), len_domain_name);
584                 make_unistr2 (&(r_e->uni_domain_name ), domain_name, len_domain_name);
585                 make_dom_sid2(&(r_e->other_domain_sid), domain_sid);
586         }
587         else
588         {
589                 r_e->num_domains = 0;
590                 r_e->ptr_enum_domains = 0;
591         }
592
593         r_e->status = status;
594 }
595
596 /*******************************************************************
597 reads or writes an LSA_R_ENUM_TRUST_DOM structure.
598 ********************************************************************/
599 void lsa_io_r_enum_trust_dom(char *desc,  LSA_R_ENUM_TRUST_DOM *r_e, prs_struct *ps, int depth)
600 {
601         if (r_e == NULL) return;
602
603         prs_debug(ps, depth, desc, "lsa_io_r_enum_trust_dom");
604         depth++;
605
606         prs_uint32("enum_context    ", ps, depth, &(r_e->enum_context    ));
607         prs_uint32("num_domains     ", ps, depth, &(r_e->num_domains     ));
608         prs_uint32("ptr_enum_domains", ps, depth, &(r_e->ptr_enum_domains));
609
610         if (r_e->ptr_enum_domains != 0)
611         {
612                 prs_uint32("num_domains2", ps, depth, &(r_e->num_domains2));
613                 smb_io_unihdr2 ("", &(r_e->hdr_domain_name ), ps, depth);
614                 smb_io_unistr2 ("", &(r_e->uni_domain_name ), r_e->hdr_domain_name.buffer, ps, depth);
615                 smb_io_dom_sid2("", &(r_e->other_domain_sid), ps, depth);
616         }
617
618         prs_uint32("status", ps, depth, &(r_e->status));
619 }
620
621 /*******************************************************************
622 reads or writes an LSA_Q_QUERY_INFO structure.
623 ********************************************************************/
624 void lsa_io_r_query(char *desc,  LSA_R_QUERY_INFO *r_q, prs_struct *ps, int depth)
625 {
626         if (r_q == NULL) return;
627
628         prs_debug(ps, depth, desc, "lsa_io_r_query");
629         depth++;
630
631         prs_uint32("undoc_buffer", ps, depth, &(r_q->undoc_buffer));
632
633         if (r_q->undoc_buffer != 0)
634         {
635                 prs_uint16("info_class", ps, depth, &(r_q->info_class));
636
637                 switch (r_q->info_class)
638                 {
639                         case 3:
640                         {
641                                 smb_io_dom_query_3("", &(r_q->dom.id3), ps, depth);
642                                 break;
643                         }
644                         case 5:
645                         {
646                                 smb_io_dom_query_5("", &(r_q->dom.id3), ps, depth);
647                                 break;
648                         }
649                         default:
650                         {
651                                 /* PANIC! */
652                                 break;
653                         }
654                 }
655         }
656
657         prs_uint32("status", ps, depth, &(r_q->status));
658 }
659
660 /*******************************************************************
661 makes a LSA_SID_ENUM structure.
662 ********************************************************************/
663 void make_lsa_sid_enum(LSA_SID_ENUM *sen, int num_entries, DOM_SID **sids)
664 {
665         int i, i2;
666         if (sen == NULL || sids == NULL) return;
667
668         DEBUG(5,("make_lsa_sid_enum\n"));
669
670         sen->num_entries  = num_entries;
671         sen->ptr_sid_enum = num_entries != 0 ? 1 : 0;
672         sen->num_entries2 = num_entries;
673
674         SMB_ASSERT_ARRAY(sen->sid, sen->num_entries);
675
676         for (i = 0, i2 = 0; i < num_entries; i++)
677         {
678                 if (sids[i] != NULL)
679                 {
680                         sen->ptr_sid[i] = 1;
681                         make_dom_sid2(&(sen->sid[i2]), sids[i]);
682                         i2++;
683                 }
684                 else
685                 {
686                         sen->ptr_sid[i] = 0;
687                 }
688         }
689 }
690
691 /*******************************************************************
692 reads or writes a LSA_SID_ENUM structure.
693 ********************************************************************/
694 static void lsa_io_sid_enum(char *desc, LSA_SID_ENUM *sen,
695                                 prs_struct *ps, int depth)
696 {
697         int i;
698
699         if (sen == NULL) return;
700
701         prs_debug(ps, depth, desc, "lsa_io_sid_enum");
702         depth++;
703
704         prs_align(ps);
705         
706         prs_uint32("num_entries ", ps, depth, &(sen->num_entries));
707         prs_uint32("ptr_sid_enum", ps, depth, &(sen->ptr_sid_enum)); 
708         prs_uint32("num_entries2", ps, depth, &(sen->num_entries2)); 
709
710         SMB_ASSERT_ARRAY(sen->ptr_sid, sen->num_entries);
711
712         for (i = 0; i < sen->num_entries; i++)
713         {       
714                 fstring temp;
715                 slprintf(temp, sizeof(temp) - 1, "ptr_sid[%d]", i);
716                 prs_uint32(temp, ps, depth, &(sen->ptr_sid[i])); /* domain SID pointers to be looked up. */
717         }
718
719         SMB_ASSERT_ARRAY(sen->sid, sen->num_entries);
720
721         for (i = 0; i < sen->num_entries; i++)
722         {
723                 fstring temp;
724                 slprintf(temp, sizeof(temp) - 1, "sid[%d]", i);
725                 smb_io_dom_sid2(temp, &(sen->sid[i]), ps, depth); /* domain SIDs to be looked up. */
726         }
727 }
728
729 /*******************************************************************
730 reads or writes a structure.
731 ********************************************************************/
732 static void lsa_io_trans_names(char *desc, LSA_TRANS_NAME_ENUM *trn,
733                                 prs_struct *ps, int depth)
734 {
735         int i;
736
737         if (trn == NULL) return;
738
739         prs_debug(ps, depth, desc, "lsa_io_trans_names");
740         depth++;
741
742         prs_align(ps);
743         
744         prs_uint32("num_entries    ", ps, depth, &(trn->num_entries));
745         prs_uint32("ptr_trans_names", ps, depth, &(trn->ptr_trans_names));
746
747         if (trn->ptr_trans_names != 0)
748         {
749                 prs_uint32("num_entries2   ", ps, depth, &(trn->num_entries2));
750                 SMB_ASSERT_ARRAY(trn->name, trn->num_entries);
751
752                 for (i = 0; i < trn->num_entries2; i++)
753                 {
754                         fstring t;
755                         slprintf(t, sizeof(t) - 1, "name[%d] ", i);
756
757                         lsa_io_trans_name(t, &(trn->name[i]), ps, depth); /* translated name */
758
759                 }
760                 for (i = 0; i < trn->num_entries2; i++)
761                 {
762                         fstring t;
763                         slprintf(t, sizeof(t) - 1, "name[%d] ", i);
764
765                         smb_io_unistr2(t, &(trn->uni_name[i]), trn->name[i].hdr_name.buffer, ps, depth);
766                         prs_align(ps);
767                 }
768         }
769 }
770
771 /*******************************************************************
772 makes a structure.
773 ********************************************************************/
774 void make_q_lookup_sids(LSA_Q_LOOKUP_SIDS *q_l, POLICY_HND *hnd,
775                                 int num_sids, DOM_SID **sids,
776                                 uint16 level)
777 {
778         if (q_l == NULL) return;
779
780         DEBUG(5,("make_q_lookup_sids\n"));
781
782         memcpy(&(q_l->pol), hnd, sizeof(q_l->pol));
783         make_lsa_sid_enum(&(q_l->sids), num_sids, sids);
784
785         q_l->names.ptr_trans_names = 0;
786         q_l->names.num_entries     = 0;
787
788         q_l->level.value = level;
789 }
790
791 /*******************************************************************
792 reads or writes a LSA_Q_LOOKUP_SIDS structure.
793 ********************************************************************/
794 void lsa_io_q_lookup_sids(char *desc, LSA_Q_LOOKUP_SIDS *q_s, prs_struct *ps, int depth)
795 {
796         if (q_s == NULL) return;
797
798         prs_debug(ps, depth, desc, "lsa_io_q_lookup_sids");
799         depth++;
800
801         prs_align(ps);
802         
803         smb_io_pol_hnd     ("pol_hnd", &(q_s->pol), ps, depth); /* policy handle */
804         lsa_io_sid_enum    ("sids   ", &(q_s->sids   ), ps, depth); /* sids to be looked up */
805         lsa_io_trans_names ("names  ", &(q_s->names  ), ps, depth); /* translated names */
806         smb_io_lookup_level("switch ", &(q_s->level  ), ps, depth); /* lookup level */
807
808         prs_uint32("mapped_count", ps, depth, &(q_s->mapped_count));
809 }
810
811 /*******************************************************************
812 reads or writes a structure.
813 ********************************************************************/
814 void lsa_io_r_lookup_sids(char *desc,  LSA_R_LOOKUP_SIDS *r_s, prs_struct *ps, int depth)
815 {
816         if (r_s == NULL) return;
817
818         prs_debug(ps, depth, desc, "lsa_io_r_lookup_sids");
819         depth++;
820
821         prs_align(ps);
822         
823         lsa_io_dom_r_ref  ("dom_ref", r_s->dom_ref, ps, depth); /* domain reference info */
824         lsa_io_trans_names("names  ", r_s->names  , ps, depth); /* translated names */
825
826         prs_align(ps);
827
828         prs_uint32("mapped_count", ps, depth, &(r_s->mapped_count));
829
830         prs_uint32("status      ", ps, depth, &(r_s->status));
831 }
832
833 /*******************************************************************
834 makes a structure.
835 ********************************************************************/
836 void make_q_lookup_names(LSA_Q_LOOKUP_NAMES *q_l, POLICY_HND *hnd,
837                                 int num_names, const char **names)
838 {
839         int i;
840         if (q_l == NULL) return;
841
842         DEBUG(5,("make_q_lookup_names\n"));
843
844         memcpy(&(q_l->pol), hnd, sizeof(q_l->pol));
845
846         q_l->num_entries     = num_names;
847         q_l->num_entries2    = num_names;
848
849         SMB_ASSERT_ARRAY(q_l->uni_name, q_l->num_entries);
850
851         for (i = 0; i < num_names; i++)
852         {
853                 const char* name = names[i];
854                 int len = strlen(name);
855                 make_uni_hdr(&q_l->hdr_name[i], len);
856                 make_unistr2(&q_l->uni_name[i], name, len);
857         }
858
859         q_l->num_trans_entries  = 0;
860         q_l->ptr_trans_sids  = 0;
861         q_l->lookup_level = 1;
862         q_l->mapped_count = 0;
863 }
864
865 /*******************************************************************
866 reads or writes a structure.
867 ********************************************************************/
868 void lsa_io_q_lookup_names(char *desc,  LSA_Q_LOOKUP_NAMES *q_r, prs_struct *ps, int depth)
869 {
870         int i;
871
872         if (q_r == NULL) return;
873
874         prs_debug(ps, depth, desc, "lsa_io_q_lookup_names");
875         depth++;
876
877         prs_align(ps);
878         
879         smb_io_pol_hnd("", &(q_r->pol), ps, depth); /* policy handle */
880
881         prs_uint32("num_entries    ", ps, depth, &(q_r->num_entries));
882         prs_uint32("num_entries2   ", ps, depth, &(q_r->num_entries2));
883
884         SMB_ASSERT_ARRAY(q_r->uni_name, q_r->num_entries);
885
886         for (i = 0; i < q_r->num_entries; i++)
887         {
888                 smb_io_unihdr("hdr_name", &(q_r->hdr_name[i]), ps, depth); /* pointer names */
889         }
890
891         for (i = 0; i < q_r->num_entries; i++)
892         {
893                 smb_io_unistr2("dom_name", &(q_r->uni_name[i]), q_r->hdr_name[i].buffer, ps, depth); /* names to be looked up */
894                 prs_align(ps);
895         }
896
897         prs_uint32("num_trans_entries ", ps, depth, &(q_r->num_trans_entries));
898         prs_uint32("ptr_trans_sids ", ps, depth, &(q_r->ptr_trans_sids));
899         prs_uint32("lookup_level   ", ps, depth, &(q_r->lookup_level  ));
900         prs_uint32("mapped_count   ", ps, depth, &(q_r->mapped_count  ));
901 }
902
903 /*******************************************************************
904 reads or writes a structure.
905 ********************************************************************/
906 void lsa_io_r_lookup_names(char *desc,  LSA_R_LOOKUP_NAMES *r_r, prs_struct *ps, int depth)
907 {
908         int i;
909
910         if (r_r == NULL) return;
911
912         prs_debug(ps, depth, desc, "lsa_io_r_lookup_names");
913         depth++;
914
915         prs_align(ps);
916         
917         prs_uint32("ptr_dom_ref", ps, depth, &(r_r->ptr_dom_ref));
918         if (r_r->ptr_dom_ref != 0)
919         {
920                 lsa_io_dom_r_ref("", r_r->dom_ref, ps, depth);
921         }
922
923         prs_uint32("num_entries", ps, depth, &(r_r->num_entries));
924         prs_uint32("ptr_entries", ps, depth, &(r_r->ptr_entries));
925
926         if (r_r->ptr_entries != 0)
927         {
928                 prs_uint32("num_entries2", ps, depth, &(r_r->num_entries2));
929
930                 if (r_r->num_entries2 != r_r->num_entries)
931                 {
932                         /* RPC fault */
933                         return;
934                 }
935
936                 for (i = 0; i < r_r->num_entries2; i++)
937                 {
938                         smb_io_dom_rid2("", &(r_r->dom_rid[i]), ps, depth); /* domain RIDs being looked up */
939                 }
940         }
941
942         prs_uint32("mapped_count", ps, depth, &(r_r->mapped_count));
943
944         prs_uint32("status      ", ps, depth, &(r_r->status));
945 }
946
947
948 /*******************************************************************
949 makes an LSA_Q_CLOSE structure.
950 ********************************************************************/
951 void make_lsa_q_close(LSA_Q_CLOSE *q_c, POLICY_HND *hnd)
952 {
953         if (q_c == NULL || hnd == NULL) return;
954
955         DEBUG(5,("make_lsa_q_close\n"));
956
957         memcpy(&(q_c->pol), hnd, sizeof(q_c->pol));
958 }
959
960 /*******************************************************************
961 reads or writes an LSA_Q_CLOSE structure.
962 ********************************************************************/
963 void lsa_io_q_close(char *desc,  LSA_Q_CLOSE *q_c, prs_struct *ps, int depth)
964 {
965         if (q_c == NULL) return;
966
967         prs_debug(ps, depth, desc, "lsa_io_q_close");
968         depth++;
969
970         smb_io_pol_hnd("", &(q_c->pol), ps, depth);
971 }
972
973 /*******************************************************************
974 reads or writes an LSA_R_CLOSE structure.
975 ********************************************************************/
976 void lsa_io_r_close(char *desc,  LSA_R_CLOSE *r_c, prs_struct *ps, int depth)
977 {
978         if (r_c == NULL) return;
979
980         prs_debug(ps, depth, desc, "lsa_io_r_close");
981         depth++;
982
983         smb_io_pol_hnd("", &(r_c->pol), ps, depth);
984
985         prs_uint32("status", ps, depth, &(r_c->status));
986 }
987