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