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