a70d1e98a9e09b36f8c3ede5b7265e226e424431
[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
26 static BOOL lsa_io_trans_names(char *desc, LSA_TRANS_NAME_ENUM *trn, prs_struct *ps, int depth);
27
28 /*******************************************************************
29  Inits a LSA_TRANS_NAME structure.
30 ********************************************************************/
31
32 void init_lsa_trans_name(LSA_TRANS_NAME *trn, UNISTR2 *uni_name,
33                          uint16 sid_name_use, char *name, uint32 idx)
34 {
35         int len_name = strlen(name);
36
37         if(len_name == 0)
38                 len_name = 1;
39
40         trn->sid_name_use = sid_name_use;
41         init_uni_hdr(&trn->hdr_name, len_name);
42         init_unistr2(uni_name, name, len_name);
43         trn->domain_idx = idx;
44 }
45
46 /*******************************************************************
47  Reads or writes a LSA_TRANS_NAME structure.
48 ********************************************************************/
49
50 static BOOL lsa_io_trans_name(char *desc, LSA_TRANS_NAME *trn, prs_struct *ps, 
51                               int depth)
52 {
53         prs_debug(ps, depth, desc, "lsa_io_trans_name");
54         depth++;
55
56         if(!prs_align(ps))
57                 return False;
58         
59         if(!prs_uint16("sid_name_use", ps, depth, &trn->sid_name_use))
60                 return False;
61         if(!prs_align(ps))
62                 return False;
63         
64         if(!smb_io_unihdr ("hdr_name", &trn->hdr_name, ps, depth))
65                 return False;
66         if(!prs_uint32("domain_idx  ", ps, depth, &trn->domain_idx))
67                 return False;
68
69         return True;
70 }
71
72 /*******************************************************************
73  Reads or writes a DOM_R_REF structure.
74 ********************************************************************/
75
76 static BOOL lsa_io_dom_r_ref(char *desc, DOM_R_REF *r_r, prs_struct *ps, 
77                              int depth)
78 {
79         int i;
80
81         prs_debug(ps, depth, desc, "lsa_io_dom_r_ref");
82         depth++;
83
84         if(!prs_align(ps))
85                 return False;
86         
87         if(!prs_uint32("num_ref_doms_1", ps, depth, &r_r->num_ref_doms_1)) /* num referenced domains? */
88                 return False;
89         if(!prs_uint32("ptr_ref_dom   ", ps, depth, &r_r->ptr_ref_dom)) /* undocumented buffer pointer. */
90                 return False;
91         if(!prs_uint32("max_entries   ", ps, depth, &r_r->max_entries)) /* 32 - max number of entries */
92                 return False;
93
94         SMB_ASSERT_ARRAY(r_r->hdr_ref_dom, r_r->num_ref_doms_1);
95
96         if (r_r->ptr_ref_dom != 0) {
97
98                 if(!prs_uint32("num_ref_doms_2", ps, depth, &r_r->num_ref_doms_2)) /* 4 - num referenced domains? */
99                         return False;
100
101                 SMB_ASSERT_ARRAY(r_r->ref_dom, r_r->num_ref_doms_2);
102
103                 for (i = 0; i < r_r->num_ref_doms_1; i++) {
104                         fstring t;
105
106                         slprintf(t, sizeof(t) - 1, "dom_ref[%d] ", i);
107                         if(!smb_io_unihdr(t, &r_r->hdr_ref_dom[i].hdr_dom_name, ps, depth))
108                                 return False;
109
110                         slprintf(t, sizeof(t) - 1, "sid_ptr[%d] ", i);
111                         if(!prs_uint32(t, ps, depth, &r_r->hdr_ref_dom[i].ptr_dom_sid))
112                                 return False;
113                 }
114
115                 for (i = 0; i < r_r->num_ref_doms_2; i++) {
116                         fstring t;
117
118                         if (r_r->hdr_ref_dom[i].hdr_dom_name.buffer != 0) {
119                                 slprintf(t, sizeof(t) - 1, "dom_ref[%d] ", i);
120                                 if(!smb_io_unistr2(t, &r_r->ref_dom[i].uni_dom_name, True, ps, depth)) /* domain name unicode string */
121                                         return False;
122                                 if(!prs_align(ps))
123                                         return False;
124                         }
125
126                         if (r_r->hdr_ref_dom[i].ptr_dom_sid != 0) {
127                                 slprintf(t, sizeof(t) - 1, "sid_ptr[%d] ", i);
128                                 if(!smb_io_dom_sid2(t, &r_r->ref_dom[i].ref_dom, ps, depth)) /* referenced domain SIDs */
129                                         return False;
130                         }
131                 }
132         }
133
134         return True;
135 }
136
137 /*******************************************************************
138  Inits an LSA_SEC_QOS structure.
139 ********************************************************************/
140
141 void init_lsa_sec_qos(LSA_SEC_QOS *qos, uint16 imp_lev, uint8 ctxt, uint8 eff)
142 {
143         DEBUG(5, ("init_lsa_sec_qos\n"));
144
145         qos->len = 0x0c; /* length of quality of service block, in bytes */
146         qos->sec_imp_level = imp_lev;
147         qos->sec_ctxt_mode = ctxt;
148         qos->effective_only = eff;
149 }
150
151 /*******************************************************************
152  Reads or writes an LSA_SEC_QOS structure.
153 ********************************************************************/
154
155 static BOOL lsa_io_sec_qos(char *desc,  LSA_SEC_QOS *qos, prs_struct *ps, 
156                            int depth)
157 {
158         uint32 start;
159
160         prs_debug(ps, depth, desc, "lsa_io_obj_qos");
161         depth++;
162
163         if(!prs_align(ps))
164                 return False;
165         
166         start = prs_offset(ps);
167
168         /* these pointers had _better_ be zero, because we don't know
169            what they point to!
170          */
171         if(!prs_uint32("len           ", ps, depth, &qos->len)) /* 0x18 - length (in bytes) inc. the length field. */
172                 return False;
173         if(!prs_uint16("sec_imp_level ", ps, depth, &qos->sec_imp_level ))
174                 return False;
175         if(!prs_uint8 ("sec_ctxt_mode ", ps, depth, &qos->sec_ctxt_mode ))
176                 return False;
177         if(!prs_uint8 ("effective_only", ps, depth, &qos->effective_only))
178                 return False;
179
180         if (qos->len != prs_offset(ps) - start) {
181                 DEBUG(3,("lsa_io_sec_qos: length %x does not match size %x\n",
182                          qos->len, prs_offset(ps) - start));
183         }
184
185         return True;
186 }
187
188 /*******************************************************************
189  Inits an LSA_OBJ_ATTR structure.
190 ********************************************************************/
191
192 void init_lsa_obj_attr(LSA_OBJ_ATTR *attr, uint32 attributes, LSA_SEC_QOS *qos)
193 {
194         DEBUG(5, ("init_lsa_obj_attr\n"));
195
196         attr->len = 0x18; /* length of object attribute block, in bytes */
197         attr->ptr_root_dir = 0;
198         attr->ptr_obj_name = 0;
199         attr->attributes = attributes;
200         attr->ptr_sec_desc = 0;
201         
202         if (qos != NULL) {
203                 attr->ptr_sec_qos = 1;
204                 attr->sec_qos = qos;
205         } else {
206                 attr->ptr_sec_qos = 0;
207                 attr->sec_qos = NULL;
208         }
209 }
210
211 /*******************************************************************
212  Reads or writes an LSA_OBJ_ATTR structure.
213 ********************************************************************/
214
215 static BOOL lsa_io_obj_attr(char *desc, LSA_OBJ_ATTR *attr, prs_struct *ps, 
216                             int depth)
217 {
218         uint32 start;
219
220         prs_debug(ps, depth, desc, "lsa_io_obj_attr");
221         depth++;
222
223         if(!prs_align(ps))
224                 return False;
225         
226         start = prs_offset(ps);
227
228         /* these pointers had _better_ be zero, because we don't know
229            what they point to!
230          */
231         if(!prs_uint32("len         ", ps, depth, &attr->len)) /* 0x18 - length (in bytes) inc. the length field. */
232                 return False;
233         if(!prs_uint32("ptr_root_dir", ps, depth, &attr->ptr_root_dir)) /* 0 - root directory (pointer) */
234                 return False;
235         if(!prs_uint32("ptr_obj_name", ps, depth, &attr->ptr_obj_name)) /* 0 - object name (pointer) */
236                 return False;
237         if(!prs_uint32("attributes  ", ps, depth, &attr->attributes)) /* 0 - attributes (undocumented) */
238                 return False;
239         if(!prs_uint32("ptr_sec_desc", ps, depth, &attr->ptr_sec_desc)) /* 0 - security descriptior (pointer) */
240                 return False;
241         if(!prs_uint32("ptr_sec_qos ", ps, depth, &attr->ptr_sec_qos )) /* security quality of service (pointer) */
242                 return False;
243
244         /* code commented out as it's not necessary true (tested with hyena). JFM, 11/22/2001 */
245 #if 0
246         if (attr->len != prs_offset(ps) - start) {
247                 DEBUG(3,("lsa_io_obj_attr: length %x does not match size %x\n",
248                          attr->len, prs_offset(ps) - start));
249                 return False;
250         }
251 #endif
252
253         if (attr->ptr_sec_qos != 0) {
254                 if (UNMARSHALLING(ps))
255                         if (!(attr->sec_qos = (LSA_SEC_QOS *)prs_alloc_mem(ps,sizeof(LSA_SEC_QOS))))
256                                 return False;
257
258                 if(!lsa_io_sec_qos("sec_qos", attr->sec_qos, ps, depth))
259                         return False;
260         }
261
262         return True;
263 }
264
265
266 /*******************************************************************
267  Inits an LSA_Q_OPEN_POL structure.
268 ********************************************************************/
269
270 void init_q_open_pol(LSA_Q_OPEN_POL *r_q, uint16 system_name,
271                      uint32 attributes, uint32 desired_access,
272                      LSA_SEC_QOS *qos)
273 {
274         DEBUG(5, ("init_open_pol: attr:%d da:%d\n", attributes, 
275                   desired_access));
276
277         r_q->ptr = 1; /* undocumented pointer */
278
279         r_q->des_access = desired_access;
280
281         r_q->system_name = system_name;
282         init_lsa_obj_attr(&r_q->attr, attributes, qos);
283 }
284
285 /*******************************************************************
286  Reads or writes an LSA_Q_OPEN_POL structure.
287 ********************************************************************/
288
289 BOOL lsa_io_q_open_pol(char *desc, LSA_Q_OPEN_POL *r_q, prs_struct *ps, 
290                        int depth)
291 {
292         prs_debug(ps, depth, desc, "lsa_io_q_open_pol");
293         depth++;
294
295         if(!prs_uint32("ptr       ", ps, depth, &r_q->ptr))
296                 return False;
297         if(!prs_uint16("system_name", ps, depth, &r_q->system_name))
298                 return False;
299         if(!prs_align( ps ))
300                 return False;
301
302         if(!lsa_io_obj_attr("", &r_q->attr, ps, depth))
303                 return False;
304
305         if(!prs_uint32("des_access", ps, depth, &r_q->des_access))
306                 return False;
307
308         return True;
309 }
310
311 /*******************************************************************
312  Reads or writes an LSA_R_OPEN_POL structure.
313 ********************************************************************/
314
315 BOOL lsa_io_r_open_pol(char *desc, LSA_R_OPEN_POL *r_p, prs_struct *ps, 
316                        int depth)
317 {
318         prs_debug(ps, depth, desc, "lsa_io_r_open_pol");
319         depth++;
320
321         if(!smb_io_pol_hnd("", &r_p->pol, ps, depth))
322                 return False;
323
324         if(!prs_ntstatus("status", ps, depth, &r_p->status))
325                 return False;
326
327         return True;
328 }
329
330 /*******************************************************************
331  Inits an LSA_Q_OPEN_POL2 structure.
332 ********************************************************************/
333
334 void init_q_open_pol2(LSA_Q_OPEN_POL2 *r_q, char *server_name,
335                         uint32 attributes, uint32 desired_access,
336                         LSA_SEC_QOS *qos)
337 {
338         DEBUG(5, ("init_q_open_pol2: attr:%d da:%d\n", attributes, 
339                   desired_access));
340
341         r_q->ptr = 1; /* undocumented pointer */
342
343         r_q->des_access = desired_access;
344
345         init_unistr2(&r_q->uni_server_name, server_name, 
346                      strlen(server_name) + 1);
347
348         init_lsa_obj_attr(&r_q->attr, attributes, qos);
349 }
350
351 /*******************************************************************
352  Reads or writes an LSA_Q_OPEN_POL2 structure.
353 ********************************************************************/
354
355 BOOL lsa_io_q_open_pol2(char *desc, LSA_Q_OPEN_POL2 *r_q, prs_struct *ps, 
356                         int depth)
357 {
358         prs_debug(ps, depth, desc, "lsa_io_q_open_pol2");
359         depth++;
360
361         if(!prs_uint32("ptr       ", ps, depth, &r_q->ptr))
362                 return False;
363
364         if(!smb_io_unistr2 ("", &r_q->uni_server_name, r_q->ptr, ps, depth))
365                 return False;
366         if(!lsa_io_obj_attr("", &r_q->attr, ps, depth))
367                 return False;
368
369         if(!prs_uint32("des_access", ps, depth, &r_q->des_access))
370                 return False;
371
372         return True;
373 }
374
375 /*******************************************************************
376  Reads or writes an LSA_R_OPEN_POL2 structure.
377 ********************************************************************/
378
379 BOOL lsa_io_r_open_pol2(char *desc, LSA_R_OPEN_POL2 *r_p, prs_struct *ps, 
380                         int depth)
381 {
382         prs_debug(ps, depth, desc, "lsa_io_r_open_pol2");
383         depth++;
384
385         if(!smb_io_pol_hnd("", &r_p->pol, ps, depth))
386                 return False;
387
388         if(!prs_ntstatus("status", ps, depth, &r_p->status))
389                 return False;
390
391         return True;
392 }
393
394 /*******************************************************************
395 makes an LSA_Q_QUERY_SEC_OBJ structure.
396 ********************************************************************/
397
398 void init_q_query_sec_obj(LSA_Q_QUERY_SEC_OBJ *q_q, const POLICY_HND *hnd, 
399                           uint32 sec_info)
400 {
401         DEBUG(5, ("init_q_query_sec_obj\n"));
402
403         q_q->pol = *hnd;
404         q_q->sec_info = sec_info;
405
406         return;
407 }
408
409 /*******************************************************************
410  Reads or writes an LSA_Q_QUERY_SEC_OBJ structure.
411 ********************************************************************/
412
413 BOOL lsa_io_q_query_sec_obj(char *desc, LSA_Q_QUERY_SEC_OBJ *q_q, 
414                             prs_struct *ps, int depth)
415 {
416         prs_debug(ps, depth, desc, "lsa_io_q_query_sec_obj");
417         depth++;
418
419         if (!smb_io_pol_hnd("", &q_q->pol, ps, depth))
420                 return False;
421
422         if (!prs_uint32("sec_info", ps, depth, &q_q->sec_info))
423                 return False;
424
425         return True;
426
427
428 /*******************************************************************
429  Reads or writes a LSA_R_QUERY_SEC_OBJ structure.
430 ********************************************************************/
431
432 BOOL lsa_io_r_query_sec_obj(char *desc, LSA_R_QUERY_SEC_OBJ *r_u, 
433                             prs_struct *ps, int depth)
434 {
435         prs_debug(ps, depth, desc, "lsa_io_r_query_sec_obj");
436         depth++;
437
438         if (!prs_align(ps))
439                 return False;
440
441         if (!prs_uint32("ptr", ps, depth, &r_u->ptr))
442                 return False;
443
444         if (r_u->ptr != 0) {
445                 if (!sec_io_desc_buf("sec", &r_u->buf, ps, depth))
446                         return False;
447         }
448
449         if (!prs_ntstatus("status", ps, depth, &r_u->status))
450                 return False;
451
452         return True;
453 }
454
455 /*******************************************************************
456  Inits an LSA_Q_QUERY_INFO structure.
457 ********************************************************************/
458
459 void init_q_query(LSA_Q_QUERY_INFO *q_q, POLICY_HND *hnd, uint16 info_class)
460 {
461         DEBUG(5, ("init_q_query\n"));
462
463         memcpy(&q_q->pol, hnd, sizeof(q_q->pol));
464
465         q_q->info_class = info_class;
466 }
467
468 /*******************************************************************
469  Reads or writes an LSA_Q_QUERY_INFO structure.
470 ********************************************************************/
471
472 BOOL lsa_io_q_query(char *desc, LSA_Q_QUERY_INFO *q_q, prs_struct *ps, 
473                     int depth)
474 {
475         prs_debug(ps, depth, desc, "lsa_io_q_query");
476         depth++;
477
478         if(!smb_io_pol_hnd("", &q_q->pol, ps, depth))
479                 return False;
480
481         if(!prs_uint16("info_class", ps, depth, &q_q->info_class))
482                 return False;
483
484         return True;
485 }
486
487 /*******************************************************************
488 makes an LSA_Q_ENUM_TRUST_DOM structure.
489 ********************************************************************/
490 BOOL init_q_enum_trust_dom(LSA_Q_ENUM_TRUST_DOM * q_e, POLICY_HND *pol,
491                            uint32 enum_context, uint32 preferred_len)
492 {
493         DEBUG(5, ("init_q_enum_trust_dom\n"));
494
495         q_e->pol = *pol;
496         q_e->enum_context = enum_context;
497         q_e->preferred_len = preferred_len;
498
499         return True;
500 }
501
502 /*******************************************************************
503  Reads or writes an LSA_Q_ENUM_TRUST_DOM structure.
504 ********************************************************************/
505
506 BOOL lsa_io_q_enum_trust_dom(char *desc, LSA_Q_ENUM_TRUST_DOM *q_e, 
507                              prs_struct *ps, int depth)
508 {
509         prs_debug(ps, depth, desc, "lsa_io_q_enum_trust_dom");
510         depth++;
511
512         if(!smb_io_pol_hnd("", &q_e->pol, ps, depth))
513                 return False;
514
515         if(!prs_uint32("enum_context ", ps, depth, &q_e->enum_context))
516                 return False;
517         if(!prs_uint32("preferred_len", ps, depth, &q_e->preferred_len))
518                 return False;
519
520         return True;
521 }
522
523 /*******************************************************************
524  Inits an LSA_R_ENUM_TRUST_DOM structure.
525 ********************************************************************/
526
527 void init_r_enum_trust_dom(TALLOC_CTX *ctx, LSA_R_ENUM_TRUST_DOM *r_e, uint32 enum_context, 
528                            char *domain_name, DOM_SID *domain_sid,
529                            NTSTATUS status)
530 {
531         DEBUG(5, ("init_r_enum_trust_dom\n"));
532         
533         r_e->enum_context = enum_context;
534         
535         if (NT_STATUS_IS_OK(status)) {
536                 int len_domain_name = strlen(domain_name) + 1;
537                 
538                 r_e->num_domains  = 1;
539                 r_e->ptr_enum_domains = 1;
540                 r_e->num_domains2 = 1;
541                 
542                 if (!(r_e->hdr_domain_name = (UNIHDR2 *)talloc(ctx,sizeof(UNIHDR2))))
543                         return;
544
545                 if (!(r_e->uni_domain_name = (UNISTR2 *)talloc(ctx,sizeof(UNISTR2))))
546                         return;
547
548                 if (!(r_e->domain_sid = (DOM_SID2 *)talloc(ctx,sizeof(DOM_SID2))))
549                         return;
550
551                 init_uni_hdr2(&r_e->hdr_domain_name[0], len_domain_name);
552                 init_unistr2 (&r_e->uni_domain_name[0], domain_name, 
553                               len_domain_name);
554                 init_dom_sid2(&r_e->domain_sid[0], domain_sid);
555         } else {
556                 r_e->num_domains = 0;
557                 r_e->ptr_enum_domains = 0;
558         }
559         
560         r_e->status = status;
561 }
562
563 /*******************************************************************
564  Reads or writes an LSA_R_ENUM_TRUST_DOM structure.
565 ********************************************************************/
566
567 BOOL lsa_io_r_enum_trust_dom(char *desc, LSA_R_ENUM_TRUST_DOM *r_e, 
568                              prs_struct *ps, int depth)
569 {
570         prs_debug(ps, depth, desc, "lsa_io_r_enum_trust_dom");
571         depth++;
572
573         if(!prs_uint32("enum_context    ", ps, depth, &r_e->enum_context))
574                 return False;
575         if(!prs_uint32("num_domains     ", ps, depth, &r_e->num_domains))
576                 return False;
577         if(!prs_uint32("ptr_enum_domains", ps, depth, &r_e->ptr_enum_domains))
578                 return False;
579
580         if (r_e->ptr_enum_domains) {
581                 int i, num_domains;
582
583                 if(!prs_uint32("num_domains2", ps, depth, &r_e->num_domains2))
584                         return False;
585
586                 num_domains = r_e->num_domains2;
587
588                 if (UNMARSHALLING(ps)) {
589                         if (!(r_e->hdr_domain_name = (UNIHDR2 *)prs_alloc_mem(ps,sizeof(UNIHDR2) * num_domains)))
590                                 return False;
591
592                         if (!(r_e->uni_domain_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2) * num_domains)))
593                                 return False;
594
595                         if (!(r_e->domain_sid = (DOM_SID2 *)prs_alloc_mem(ps,sizeof(DOM_SID2) * num_domains)))
596                                 return False;
597                 }
598
599                 for (i = 0; i < num_domains; i++) {
600                         if(!smb_io_unihdr2 ("", &r_e->hdr_domain_name[i], ps, 
601                                             depth))
602                                 return False;
603                 }
604                 
605                 for (i = 0; i < num_domains; i++) {
606                         if(!smb_io_unistr2 ("", &r_e->uni_domain_name[i],
607                                             r_e->hdr_domain_name[i].buffer, 
608                                             ps, depth))
609                                 return False;
610                         if(!smb_io_dom_sid2("", &r_e->domain_sid[i], ps, 
611                                             depth))
612                                 return False;
613                 }
614         }
615
616         if(!prs_ntstatus("status", ps, depth, &r_e->status))
617                 return False;
618
619         return True;
620 }
621
622 /*******************************************************************
623 reads or writes a dom query structure.
624 ********************************************************************/
625
626 static BOOL lsa_io_dom_query(char *desc, DOM_QUERY *d_q, prs_struct *ps, int depth)
627 {
628         if (d_q == NULL)
629                 return False;
630
631         prs_debug(ps, depth, desc, "lsa_io_dom_query");
632         depth++;
633
634         if(!prs_align(ps))
635                 return False;
636
637         if(!prs_uint16("uni_dom_max_len", ps, depth, &d_q->uni_dom_max_len)) /* domain name string length * 2 */
638                 return False;
639         if(!prs_uint16("uni_dom_str_len", ps, depth, &d_q->uni_dom_str_len)) /* domain name string length * 2 */
640                 return False;
641
642         if(!prs_uint32("buffer_dom_name", ps, depth, &d_q->buffer_dom_name)) /* undocumented domain name string buffer pointer */
643                 return False;
644         if(!prs_uint32("buffer_dom_sid ", ps, depth, &d_q->buffer_dom_sid)) /* undocumented domain SID string buffer pointer */
645                 return False;
646
647         if(!smb_io_unistr2("unistr2", &d_q->uni_domain_name, d_q->buffer_dom_name, ps, depth)) /* domain name (unicode string) */
648                 return False;
649
650         if(!prs_align(ps))
651                 return False;
652
653         if (d_q->buffer_dom_sid != 0) {
654                 if(!smb_io_dom_sid2("", &d_q->dom_sid, ps, depth)) /* domain SID */
655                         return False;
656         } else {
657                 memset((char *)&d_q->dom_sid, '\0', sizeof(d_q->dom_sid));
658         }
659
660         return True;
661 }
662
663 /*******************************************************************
664 reads or writes a structure.
665 ********************************************************************/
666
667 static BOOL lsa_io_dom_query_2(char *desc, DOM_QUERY_2 *d_q, prs_struct *ps, int depth)
668 {
669         uint32 ptr = 1;
670
671         if (d_q == NULL)
672                 return False;
673
674         prs_debug(ps, depth, desc, "lsa_io_dom_query_2");
675         depth++;
676
677         if (!prs_align(ps))
678                 return False;
679
680         if (!prs_uint32("auditing_enabled", ps, depth, &d_q->auditing_enabled))
681                 return False;
682         if (!prs_uint32("ptr   ", ps, depth, &ptr))
683                 return False;
684         if (!prs_uint32("count1", ps, depth, &d_q->count1))
685                 return False;
686         if (!prs_uint32("count2", ps, depth, &d_q->count2))
687                 return False;
688
689         if (UNMARSHALLING(ps)) {
690                 d_q->auditsettings = (uint32 *)talloc_zero(ps->mem_ctx, d_q->count2 * sizeof(uint32));
691         }
692
693         if (d_q->auditsettings == NULL) {
694                 DEBUG(1, ("lsa_io_dom_query_2: NULL auditsettings!\n"));
695                 return False;
696         }
697
698         if (!prs_uint32s(False, "auditsettings", ps, depth, d_q->auditsettings, d_q->count2))
699                 return False;
700
701     return True;
702 }
703
704 /*******************************************************************
705  Reads or writes a dom query structure.
706 ********************************************************************/
707
708 static BOOL lsa_io_dom_query_3(char *desc, DOM_QUERY_3 *d_q, prs_struct *ps, int depth)
709 {
710         return lsa_io_dom_query("", d_q, ps, depth);
711 }
712
713 /*******************************************************************
714  Reads or writes a dom query structure.
715 ********************************************************************/
716
717 BOOL lsa_io_dom_query_5(char *desc, DOM_QUERY_5 *d_q, prs_struct *ps, int depth)
718 {
719         return lsa_io_dom_query("", d_q, ps, depth);
720 }
721
722 /*******************************************************************
723  Reads or writes a dom query structure.
724 ********************************************************************/
725
726 static BOOL lsa_io_dom_query_6(char *desc, DOM_QUERY_6 *d_q, prs_struct *ps, int depth)
727 {
728         if (d_q == NULL)
729                 return False;
730
731         prs_debug(ps, depth, desc, "lsa_io_dom_query_6");
732         depth++;
733
734         if (!prs_uint16("server_role", ps, depth, &d_q->server_role))
735                 return False;
736
737         return True;
738 }
739
740 /*******************************************************************
741  Reads or writes an LSA_R_QUERY_INFO structure.
742 ********************************************************************/
743
744 BOOL lsa_io_r_query(char *desc, LSA_R_QUERY_INFO *r_q, prs_struct *ps,
745                     int depth)
746 {
747         prs_debug(ps, depth, desc, "lsa_io_r_query");
748         depth++;
749
750         if(!prs_uint32("undoc_buffer", ps, depth, &r_q->undoc_buffer))
751                 return False;
752
753         if (r_q->undoc_buffer != 0) {
754                 if(!prs_uint16("info_class", ps, depth, &r_q->info_class))
755                         return False;
756
757                 if(!prs_align(ps))
758                         return False;
759
760                 switch (r_q->info_class) {
761                 case 2:
762                         if(!lsa_io_dom_query_2("", &r_q->dom.id2, ps, depth))
763                                 return False;
764                         break;
765                 case 3:
766                         if(!lsa_io_dom_query_3("", &r_q->dom.id3, ps, depth))
767                                 return False;
768                         break;
769                 case 5:
770                         if(!lsa_io_dom_query_5("", &r_q->dom.id5, ps, depth))
771                                 return False;
772                         break;
773                 case 6:
774                         if(!lsa_io_dom_query_6("", &r_q->dom.id6, ps, depth))
775                                 return False;
776                         break;
777                 default:
778                         /* PANIC! */
779                         break;
780                 }
781         }
782
783         if(!prs_align(ps))
784                 return False;
785
786         if(!prs_ntstatus("status", ps, depth, &r_q->status))
787                 return False;
788
789         return True;
790 }
791
792 /*******************************************************************
793  Inits a LSA_SID_ENUM structure.
794 ********************************************************************/
795
796 void init_lsa_sid_enum(TALLOC_CTX *mem_ctx, LSA_SID_ENUM *sen, 
797                        int num_entries, DOM_SID *sids)
798 {
799         int i;
800
801         DEBUG(5, ("init_lsa_sid_enum\n"));
802
803         sen->num_entries  = num_entries;
804         sen->ptr_sid_enum = (num_entries != 0);
805         sen->num_entries2 = num_entries;
806
807         /* Allocate memory for sids and sid pointers */
808
809         if (num_entries == 0) return;
810
811         if ((sen->ptr_sid = (uint32 *)talloc_zero(mem_ctx, num_entries * 
812                                              sizeof(uint32))) == NULL) {
813                 DEBUG(3, ("init_lsa_sid_enum(): out of memory for ptr_sid\n"));
814                 return;
815         }
816
817         if ((sen->sid = (DOM_SID2 *)talloc_zero(mem_ctx, num_entries * 
818                                            sizeof(DOM_SID2))) == NULL) {
819                 DEBUG(3, ("init_lsa_sid_enum(): out of memory for sids\n"));
820                 return;
821         }
822
823         /* Copy across SIDs and SID pointers */
824
825         for (i = 0; i < num_entries; i++) {
826                 sen->ptr_sid[i] = 1;
827                 init_dom_sid2(&sen->sid[i], &sids[i]);
828         }
829 }
830
831 /*******************************************************************
832  Reads or writes a LSA_SID_ENUM structure.
833 ********************************************************************/
834
835 static BOOL lsa_io_sid_enum(char *desc, LSA_SID_ENUM *sen, prs_struct *ps, 
836                             int depth)
837 {
838         int i;
839
840         prs_debug(ps, depth, desc, "lsa_io_sid_enum");
841         depth++;
842
843         if(!prs_align(ps))
844                 return False;
845         
846         if(!prs_uint32("num_entries ", ps, depth, &sen->num_entries))
847                 return False;
848         if(!prs_uint32("ptr_sid_enum", ps, depth, &sen->ptr_sid_enum))
849                 return False;
850
851         /*
852            if the ptr is NULL, leave here. checked from a real w2k trace.
853            JFM, 11/23/2001
854          */
855         
856         if (sen->ptr_sid_enum==0)
857                 return True;
858
859         if(!prs_uint32("num_entries2", ps, depth, &sen->num_entries2))
860                 return False;
861
862         /* Mallocate memory if we're unpacking from the wire */
863
864         if (UNMARSHALLING(ps)) {
865                 if ((sen->ptr_sid = (uint32 *)prs_alloc_mem( ps,
866                         sen->num_entries * sizeof(uint32))) == NULL) {
867                         DEBUG(3, ("init_lsa_sid_enum(): out of memory for "
868                                   "ptr_sid\n"));
869                         return False;
870                 }
871
872                 if ((sen->sid = (DOM_SID2 *)prs_alloc_mem( ps,
873                         sen->num_entries * sizeof(DOM_SID2))) == NULL) {
874                         DEBUG(3, ("init_lsa_sid_enum(): out of memory for "
875                                   "sids\n"));
876                         return False;
877                 }
878         }
879
880         for (i = 0; i < sen->num_entries; i++) {        
881                 fstring temp;
882
883                 slprintf(temp, sizeof(temp) - 1, "ptr_sid[%d]", i);
884                 if(!prs_uint32(temp, ps, depth, &sen->ptr_sid[i])) {
885                         return False;
886                 }
887         }
888
889         for (i = 0; i < sen->num_entries; i++) {
890                 fstring temp;
891
892                 slprintf(temp, sizeof(temp) - 1, "sid[%d]", i);
893                 if(!smb_io_dom_sid2(temp, &sen->sid[i], ps, depth)) {
894                         return False;
895                 }
896         }
897
898         return True;
899 }
900
901 /*******************************************************************
902  Inits an LSA_R_ENUM_TRUST_DOM structure.
903 ********************************************************************/
904
905 void init_q_lookup_sids(TALLOC_CTX *mem_ctx, LSA_Q_LOOKUP_SIDS *q_l, 
906                         POLICY_HND *hnd, int num_sids, DOM_SID *sids,
907                         uint16 level)
908 {
909         DEBUG(5, ("init_r_enum_trust_dom\n"));
910
911         ZERO_STRUCTP(q_l);
912
913         memcpy(&q_l->pol, hnd, sizeof(q_l->pol));
914         init_lsa_sid_enum(mem_ctx, &q_l->sids, num_sids, sids);
915         
916         q_l->level.value = level;
917 }
918
919 /*******************************************************************
920  Reads or writes a LSA_Q_LOOKUP_SIDS structure.
921 ********************************************************************/
922
923 BOOL lsa_io_q_lookup_sids(char *desc, LSA_Q_LOOKUP_SIDS *q_s, prs_struct *ps,
924                           int depth)
925 {
926         prs_debug(ps, depth, desc, "lsa_io_q_lookup_sids");
927         depth++;
928
929         if(!prs_align(ps))
930                 return False;
931         
932         if(!smb_io_pol_hnd("pol_hnd", &q_s->pol, ps, depth)) /* policy handle */
933                 return False;
934         if(!lsa_io_sid_enum("sids   ", &q_s->sids, ps, depth)) /* sids to be looked up */
935                 return False;
936         if(!lsa_io_trans_names("names  ", &q_s->names, ps, depth)) /* translated names */
937                 return False;
938         if(!smb_io_lookup_level("switch ", &q_s->level, ps, depth)) /* lookup level */
939                 return False;
940
941         if(!prs_uint32("mapped_count", ps, depth, &q_s->mapped_count))
942                 return False;
943
944         return True;
945 }
946
947 /*******************************************************************
948  Reads or writes a structure.
949 ********************************************************************/
950
951 static BOOL lsa_io_trans_names(char *desc, LSA_TRANS_NAME_ENUM *trn,
952                 prs_struct *ps, int depth)
953 {
954         int i;
955
956         prs_debug(ps, depth, desc, "lsa_io_trans_names");
957         depth++;
958
959         if(!prs_align(ps))
960                 return False;
961    
962         if(!prs_uint32("num_entries    ", ps, depth, &trn->num_entries))
963                 return False;
964         if(!prs_uint32("ptr_trans_names", ps, depth, &trn->ptr_trans_names))
965                 return False;
966
967         if (trn->ptr_trans_names != 0) {
968                 if(!prs_uint32("num_entries2   ", ps, depth, 
969                                &trn->num_entries2))
970                         return False;
971
972                 if (UNMARSHALLING(ps)) {
973                         if ((trn->name = (LSA_TRANS_NAME *)
974                              prs_alloc_mem(ps, trn->num_entries * 
975                                     sizeof(LSA_TRANS_NAME))) == NULL) {
976                                 return False;
977                         }
978
979                         if ((trn->uni_name = (UNISTR2 *)
980                              prs_alloc_mem(ps, trn->num_entries *
981                                     sizeof(UNISTR2))) == NULL) {
982                                 return False;
983                         }
984                 }
985
986                 for (i = 0; i < trn->num_entries2; i++) {
987                         fstring t;
988                         slprintf(t, sizeof(t) - 1, "name[%d] ", i);
989
990                         if(!lsa_io_trans_name(t, &trn->name[i], ps, depth)) /* translated name */
991                                 return False;
992                 }
993
994                 for (i = 0; i < trn->num_entries2; i++) {
995                         fstring t;
996                         slprintf(t, sizeof(t) - 1, "name[%d] ", i);
997
998                         if(!smb_io_unistr2(t, &trn->uni_name[i], trn->name[i].hdr_name.buffer, ps, depth))
999                                 return False;
1000                         if(!prs_align(ps))
1001                                 return False;
1002                 }
1003         }
1004
1005         return True;
1006 }
1007
1008 /*******************************************************************
1009  Reads or writes a structure.
1010 ********************************************************************/
1011
1012 BOOL lsa_io_r_lookup_sids(char *desc, LSA_R_LOOKUP_SIDS *r_s, 
1013                           prs_struct *ps, int depth)
1014 {
1015         prs_debug(ps, depth, desc, "lsa_io_r_lookup_sids");
1016         depth++;
1017
1018         if(!prs_align(ps))
1019                 return False;
1020         
1021         if(!prs_uint32("ptr_dom_ref", ps, depth, &r_s->ptr_dom_ref))
1022                 return False;
1023
1024         if (r_s->ptr_dom_ref != 0)
1025                 if(!lsa_io_dom_r_ref ("dom_ref", r_s->dom_ref, ps, depth)) /* domain reference info */
1026                         return False;
1027
1028         if(!lsa_io_trans_names("names  ", r_s->names, ps, depth)) /* translated names */
1029                 return False;
1030
1031         if(!prs_align(ps))
1032                 return False;
1033
1034         if(!prs_uint32("mapped_count", ps, depth, &r_s->mapped_count))
1035                 return False;
1036
1037         if(!prs_ntstatus("status      ", ps, depth, &r_s->status))
1038                 return False;
1039
1040         return True;
1041 }
1042
1043 /*******************************************************************
1044 makes a structure.
1045 ********************************************************************/
1046
1047 void init_q_lookup_names(TALLOC_CTX *mem_ctx, LSA_Q_LOOKUP_NAMES *q_l, 
1048                          POLICY_HND *hnd, int num_names, const char **names)
1049 {
1050         int i;
1051
1052         DEBUG(5, ("init_q_lookup_names\n"));
1053
1054         ZERO_STRUCTP(q_l);
1055
1056         q_l->pol = *hnd;
1057         q_l->num_entries = num_names;
1058         q_l->num_entries2 = num_names;
1059         q_l->lookup_level = 1;
1060
1061         if ((q_l->uni_name = (UNISTR2 *)talloc_zero(
1062                 mem_ctx, num_names * sizeof(UNISTR2))) == NULL) {
1063                 DEBUG(3, ("init_q_lookup_names(): out of memory\n"));
1064                 return;
1065         }
1066
1067         if ((q_l->hdr_name = (UNIHDR *)talloc_zero(
1068                 mem_ctx, num_names * sizeof(UNIHDR))) == NULL) {
1069                 DEBUG(3, ("init_q_lookup_names(): out of memory\n"));
1070                 return;
1071         }
1072
1073         for (i = 0; i < num_names; i++) {
1074                 int len;
1075                 len = strlen(names[i]);
1076
1077                 init_uni_hdr(&q_l->hdr_name[i], len);
1078                 init_unistr2(&q_l->uni_name[i], names[i], len);
1079         }
1080 }
1081
1082 /*******************************************************************
1083 reads or writes a structure.
1084 ********************************************************************/
1085
1086 BOOL lsa_io_q_lookup_names(char *desc, LSA_Q_LOOKUP_NAMES *q_r, 
1087                            prs_struct *ps, int depth)
1088 {
1089         int i;
1090
1091         prs_debug(ps, depth, desc, "lsa_io_q_lookup_names");
1092         depth++;
1093
1094         if(!prs_align(ps))
1095                 return False;
1096
1097         if(!smb_io_pol_hnd("", &q_r->pol, ps, depth)) /* policy handle */
1098                 return False;
1099
1100         if(!prs_align(ps))
1101                 return False;
1102         if(!prs_uint32("num_entries    ", ps, depth, &q_r->num_entries))
1103                 return False;
1104         if(!prs_uint32("num_entries2   ", ps, depth, &q_r->num_entries2))
1105                 return False;
1106
1107         if (UNMARSHALLING(ps)) {
1108                 if (q_r->num_entries) {
1109                         if ((q_r->hdr_name = (UNIHDR *)prs_alloc_mem(ps,
1110                                         q_r->num_entries * sizeof(UNIHDR))) == NULL)
1111                                 return False;
1112                         if ((q_r->uni_name = (UNISTR2 *)prs_alloc_mem(ps,
1113                                         q_r->num_entries * sizeof(UNISTR2))) == NULL)
1114                                 return False;
1115                 }
1116         }
1117
1118         for (i = 0; i < q_r->num_entries; i++) {
1119                 if(!prs_align(ps))
1120                         return False;
1121                 if(!smb_io_unihdr("hdr_name", &q_r->hdr_name[i], ps, depth)) /* pointer names */
1122                         return False;
1123         }
1124
1125         for (i = 0; i < q_r->num_entries; i++) {
1126                 if(!prs_align(ps))
1127                         return False;
1128                 if(!smb_io_unistr2("dom_name", &q_r->uni_name[i], q_r->hdr_name[i].buffer, ps, depth)) /* names to be looked up */
1129                         return False;
1130         }
1131
1132         if(!prs_align(ps))
1133                 return False;
1134         if(!prs_uint32("num_trans_entries ", ps, depth, &q_r->num_trans_entries))
1135                 return False;
1136         if(!prs_uint32("ptr_trans_sids ", ps, depth, &q_r->ptr_trans_sids))
1137                 return False;
1138         if(!prs_uint32("lookup_level   ", ps, depth, &q_r->lookup_level))
1139                 return False;
1140         if(!prs_uint32("mapped_count   ", ps, depth, &q_r->mapped_count))
1141                 return False;
1142
1143         return True;
1144 }
1145
1146 /*******************************************************************
1147 reads or writes a structure.
1148 ********************************************************************/
1149
1150 BOOL lsa_io_r_lookup_names(char *desc, LSA_R_LOOKUP_NAMES *r_r, 
1151                            prs_struct *ps, int depth)
1152 {
1153         int i;
1154
1155         prs_debug(ps, depth, desc, "lsa_io_r_lookup_names");
1156         depth++;
1157
1158         if(!prs_align(ps))
1159                 return False;
1160
1161         if(!prs_uint32("ptr_dom_ref", ps, depth, &r_r->ptr_dom_ref))
1162                 return False;
1163
1164         if (r_r->ptr_dom_ref != 0)
1165                 if(!lsa_io_dom_r_ref("", r_r->dom_ref, ps, depth))
1166                         return False;
1167
1168         if(!prs_uint32("num_entries", ps, depth, &r_r->num_entries))
1169                 return False;
1170         if(!prs_uint32("ptr_entries", ps, depth, &r_r->ptr_entries))
1171                 return False;
1172
1173         if (r_r->ptr_entries != 0) {
1174                 if(!prs_uint32("num_entries2", ps, depth, &r_r->num_entries2))
1175                         return False;
1176
1177                 if (r_r->num_entries2 != r_r->num_entries) {
1178                         /* RPC fault */
1179                         return False;
1180                 }
1181
1182                 if (UNMARSHALLING(ps)) {
1183                         if ((r_r->dom_rid = (DOM_RID2 *)prs_alloc_mem(ps, r_r->num_entries2 * sizeof(DOM_RID2)))
1184                             == NULL) {
1185                                 DEBUG(3, ("lsa_io_r_lookup_names(): out of memory\n"));
1186                                 return False;
1187                         }
1188                 }
1189
1190                 for (i = 0; i < r_r->num_entries2; i++)
1191                         if(!smb_io_dom_rid2("", &r_r->dom_rid[i], ps, depth)) /* domain RIDs being looked up */
1192                                 return False;
1193         }
1194
1195         if(!prs_uint32("mapped_count", ps, depth, &r_r->mapped_count))
1196                 return False;
1197
1198         if(!prs_ntstatus("status      ", ps, depth, &r_r->status))
1199                 return False;
1200
1201         return True;
1202 }
1203
1204
1205 /*******************************************************************
1206  Inits an LSA_Q_CLOSE structure.
1207 ********************************************************************/
1208
1209 void init_lsa_q_close(LSA_Q_CLOSE *q_c, POLICY_HND *hnd)
1210 {
1211         DEBUG(5, ("init_lsa_q_close\n"));
1212
1213         memcpy(&q_c->pol, hnd, sizeof(q_c->pol));
1214 }
1215
1216 /*******************************************************************
1217  Reads or writes an LSA_Q_CLOSE structure.
1218 ********************************************************************/
1219
1220 BOOL lsa_io_q_close(char *desc, LSA_Q_CLOSE *q_c, prs_struct *ps, int depth)
1221 {
1222         prs_debug(ps, depth, desc, "lsa_io_q_close");
1223         depth++;
1224
1225         if(!smb_io_pol_hnd("", &q_c->pol, ps, depth))
1226                 return False;
1227
1228         return True;
1229 }
1230
1231 /*******************************************************************
1232  Reads or writes an LSA_R_CLOSE structure.
1233 ********************************************************************/
1234
1235 BOOL lsa_io_r_close(char *desc,  LSA_R_CLOSE *r_c, prs_struct *ps, int depth)
1236 {
1237         prs_debug(ps, depth, desc, "lsa_io_r_close");
1238         depth++;
1239
1240         if(!smb_io_pol_hnd("", &r_c->pol, ps, depth))
1241                 return False;
1242
1243         if(!prs_ntstatus("status", ps, depth, &r_c->status))
1244                 return False;
1245
1246         return True;
1247 }
1248
1249 /*******************************************************************
1250  Reads or writes an LSA_Q_OPEN_SECRET structure.
1251 ********************************************************************/
1252
1253 BOOL lsa_io_q_open_secret(char *desc, LSA_Q_OPEN_SECRET *q_c, prs_struct *ps, int depth)
1254 {
1255         prs_debug(ps, depth, desc, "lsa_io_q_open_secret");
1256         depth++;
1257
1258         /* Don't bother to read or write at present... */
1259         return True;
1260 }
1261
1262 /*******************************************************************
1263  Reads or writes an LSA_R_OPEN_SECRET structure.
1264 ********************************************************************/
1265
1266 BOOL lsa_io_r_open_secret(char *desc, LSA_R_OPEN_SECRET *r_c, prs_struct *ps, int depth)
1267 {
1268         prs_debug(ps, depth, desc, "lsa_io_r_open_secret");
1269         depth++;
1270
1271         if(!prs_align(ps))
1272                 return False;
1273    
1274         if(!prs_uint32("dummy1", ps, depth, &r_c->dummy1))
1275                 return False;
1276         if(!prs_uint32("dummy2", ps, depth, &r_c->dummy2))
1277                 return False;
1278         if(!prs_uint32("dummy3", ps, depth, &r_c->dummy3))
1279                 return False;
1280         if(!prs_uint32("dummy4", ps, depth, &r_c->dummy4))
1281                 return False;
1282         if(!prs_ntstatus("status", ps, depth, &r_c->status))
1283                 return False;
1284
1285         return True;
1286 }
1287
1288 /*******************************************************************
1289  Inits an LSA_Q_ENUM_PRIVS structure.
1290 ********************************************************************/
1291
1292 void init_q_enum_privs(LSA_Q_ENUM_PRIVS *q_q, POLICY_HND *hnd, uint32 enum_context, uint32 pref_max_length)
1293 {
1294         DEBUG(5, ("init_q_enum_privs\n"));
1295
1296         memcpy(&q_q->pol, hnd, sizeof(q_q->pol));
1297
1298         q_q->enum_context = enum_context;
1299         q_q->pref_max_length = pref_max_length;
1300 }
1301
1302 /*******************************************************************
1303 reads or writes a structure.
1304 ********************************************************************/
1305 BOOL lsa_io_q_enum_privs(char *desc, LSA_Q_ENUM_PRIVS *q_q, prs_struct *ps, int depth)
1306 {
1307         if (q_q == NULL)
1308                 return False;
1309
1310         prs_debug(ps, depth, desc, "lsa_io_q_enum_privs");
1311         depth++;
1312
1313         if (!smb_io_pol_hnd("", &q_q->pol, ps, depth))
1314                 return False;
1315
1316         if(!prs_uint32("enum_context   ", ps, depth, &q_q->enum_context))
1317                 return False;
1318         if(!prs_uint32("pref_max_length", ps, depth, &q_q->pref_max_length))
1319                 return False;
1320
1321         return True;
1322 }
1323
1324 /*******************************************************************
1325 reads or writes a structure.
1326 ********************************************************************/
1327 static BOOL lsa_io_priv_entries(char *desc, LSA_PRIV_ENTRY *entries, uint32 count, prs_struct *ps, int depth)
1328 {
1329         uint32 i;
1330
1331         if (entries == NULL)
1332                 return False;
1333
1334         prs_debug(ps, depth, desc, "lsa_io_priv_entries");
1335         depth++;
1336
1337         if(!prs_align(ps))
1338                 return False;
1339
1340         for (i = 0; i < count; i++) {
1341                 if (!smb_io_unihdr("", &entries[i].hdr_name, ps, depth))
1342                         return False;
1343                 if(!prs_uint32("luid_low ", ps, depth, &entries[i].luid_low))
1344                         return False;
1345                 if(!prs_uint32("luid_high", ps, depth, &entries[i].luid_high))
1346                         return False;
1347         }
1348
1349         for (i = 0; i < count; i++)
1350                 if (!smb_io_unistr2("", &entries[i].name, entries[i].hdr_name.buffer, ps, depth))
1351                         return False;
1352
1353         return True;
1354 }
1355
1356 /*******************************************************************
1357  Inits an LSA_R_ENUM_PRIVS structure.
1358 ********************************************************************/
1359
1360 void init_lsa_r_enum_privs(LSA_R_ENUM_PRIVS *r_u, uint32 enum_context,
1361                           uint32 count, LSA_PRIV_ENTRY *entries)
1362 {
1363         DEBUG(5, ("init_lsa_r_enum_privs\n"));
1364
1365         r_u->enum_context=enum_context;
1366         r_u->count=count;
1367         
1368         if (entries!=NULL) {
1369                 r_u->ptr=1;
1370                 r_u->count1=count;
1371                 r_u->privs=entries;
1372         } else {
1373                 r_u->ptr=0;
1374                 r_u->count1=0;
1375                 r_u->privs=NULL;
1376         }               
1377 }
1378
1379 /*******************************************************************
1380 reads or writes a structure.
1381 ********************************************************************/
1382 BOOL lsa_io_r_enum_privs(char *desc, LSA_R_ENUM_PRIVS *r_q, prs_struct *ps, int depth)
1383 {
1384         if (r_q == NULL)
1385                 return False;
1386
1387         prs_debug(ps, depth, desc, "lsa_io_r_enum_privs");
1388         depth++;
1389
1390         if(!prs_align(ps))
1391                 return False;
1392
1393         if(!prs_uint32("enum_context", ps, depth, &r_q->enum_context))
1394                 return False;
1395         if(!prs_uint32("count", ps, depth, &r_q->count))
1396                 return False;
1397         if(!prs_uint32("ptr", ps, depth, &r_q->ptr))
1398                 return False;
1399
1400         if (r_q->ptr) {
1401                 if(!prs_uint32("count1", ps, depth, &r_q->count1))
1402                         return False;
1403
1404                 if (UNMARSHALLING(ps))
1405                         if (!(r_q->privs = (LSA_PRIV_ENTRY *)prs_alloc_mem(ps, sizeof(LSA_PRIV_ENTRY) * r_q->count1)))
1406                                 return False;
1407
1408                 if (!lsa_io_priv_entries("", r_q->privs, r_q->count1, ps, depth))
1409                         return False;
1410         }
1411
1412         if(!prs_align(ps))
1413                 return False;
1414
1415         if(!prs_ntstatus("status", ps, depth, &r_q->status))
1416                 return False;
1417
1418         return True;
1419 }
1420
1421 void init_lsa_priv_get_dispname(LSA_Q_PRIV_GET_DISPNAME *trn, POLICY_HND *hnd, char *name, uint16 lang_id, uint16 lang_id_sys)
1422 {
1423         int len_name = strlen(name);
1424
1425         if(len_name == 0)
1426                 len_name = 1;
1427
1428         memcpy(&trn->pol, hnd, sizeof(trn->pol));
1429
1430         init_uni_hdr(&trn->hdr_name, len_name);
1431         init_unistr2(&trn->name, name, len_name);
1432         trn->lang_id = lang_id;
1433         trn->lang_id_sys = lang_id_sys;
1434 }
1435
1436 /*******************************************************************
1437 reads or writes a structure.
1438 ********************************************************************/
1439 BOOL lsa_io_q_priv_get_dispname(char *desc, LSA_Q_PRIV_GET_DISPNAME *q_q, prs_struct *ps, int depth)
1440 {
1441         if (q_q == NULL)
1442                 return False;
1443
1444         prs_debug(ps, depth, desc, "lsa_io_q_priv_get_dispname");
1445         depth++;
1446
1447         if(!prs_align(ps))
1448                 return False;
1449
1450         if (!smb_io_pol_hnd("", &q_q->pol, ps, depth))
1451                 return False;
1452
1453         if (!smb_io_unihdr("hdr_name", &q_q->hdr_name, ps, depth))
1454                 return False;
1455
1456         if (!smb_io_unistr2("name", &q_q->name, q_q->hdr_name.buffer, ps, depth))
1457                 return False;
1458
1459         if(!prs_uint16("lang_id    ", ps, depth, &q_q->lang_id))
1460                 return False;
1461         if(!prs_uint16("lang_id_sys", ps, depth, &q_q->lang_id_sys))
1462                 return False;
1463
1464         return True;
1465 }
1466
1467 /*******************************************************************
1468 reads or writes a structure.
1469 ********************************************************************/
1470 BOOL lsa_io_r_priv_get_dispname(char *desc, LSA_R_PRIV_GET_DISPNAME *r_q, prs_struct *ps, int depth)
1471 {
1472         if (r_q == NULL)
1473                 return False;
1474
1475         prs_debug(ps, depth, desc, "lsa_io_r_priv_get_dispname");
1476         depth++;
1477
1478         if (!prs_align(ps))
1479                 return False;
1480
1481         if (!prs_uint32("ptr_info", ps, depth, &r_q->ptr_info))
1482                 return False;
1483
1484         if (r_q->ptr_info){
1485                 if (!smb_io_unihdr("hdr_name", &r_q->hdr_desc, ps, depth))
1486                         return False;
1487
1488                 if (!smb_io_unistr2("desc", &r_q->desc, r_q->hdr_desc.buffer, ps, depth))
1489                         return False;
1490         }
1491 /*
1492         if(!prs_align(ps))
1493                 return False;
1494 */
1495         if(!prs_uint16("lang_id", ps, depth, &r_q->lang_id))
1496                 return False;
1497
1498         if(!prs_align(ps))
1499                 return False;
1500         if(!prs_ntstatus("status", ps, depth, &r_q->status))
1501                 return False;
1502
1503         return True;
1504 }
1505
1506 void init_lsa_q_enum_accounts(LSA_Q_ENUM_ACCOUNTS *trn, POLICY_HND *hnd, uint32 enum_context, uint32 pref_max_length)
1507 {
1508         memcpy(&trn->pol, hnd, sizeof(trn->pol));
1509
1510         trn->enum_context = enum_context;
1511         trn->pref_max_length = pref_max_length;
1512 }
1513
1514 /*******************************************************************
1515 reads or writes a structure.
1516 ********************************************************************/
1517 BOOL lsa_io_q_enum_accounts(char *desc, LSA_Q_ENUM_ACCOUNTS *q_q, prs_struct *ps, int depth)
1518 {
1519         if (q_q == NULL)
1520                 return False;
1521
1522         prs_debug(ps, depth, desc, "lsa_io_q_enum_accounts");
1523         depth++;
1524
1525         if (!smb_io_pol_hnd("", &q_q->pol, ps, depth))
1526                 return False;
1527
1528         if(!prs_uint32("enum_context   ", ps, depth, &q_q->enum_context))
1529                 return False;
1530         if(!prs_uint32("pref_max_length", ps, depth, &q_q->pref_max_length))
1531                 return False;
1532
1533         return True;
1534 }
1535
1536 /*******************************************************************
1537  Inits an LSA_R_ENUM_PRIVS structure.
1538 ********************************************************************/
1539
1540 void init_lsa_r_enum_accounts(LSA_R_ENUM_ACCOUNTS *r_u, uint32 enum_context)
1541 {
1542         DEBUG(5, ("init_lsa_r_enum_accounts\n"));
1543
1544         r_u->enum_context=enum_context;
1545         if (r_u->enum_context!=0) {
1546                 r_u->sids.num_entries=enum_context;
1547                 r_u->sids.ptr_sid_enum=1;
1548                 r_u->sids.num_entries2=enum_context;
1549         } else {
1550                 r_u->sids.num_entries=0;
1551                 r_u->sids.ptr_sid_enum=0;
1552                 r_u->sids.num_entries2=0;
1553         }
1554 }
1555
1556 /*******************************************************************
1557 reads or writes a structure.
1558 ********************************************************************/
1559 BOOL lsa_io_r_enum_accounts(char *desc, LSA_R_ENUM_ACCOUNTS *r_q, prs_struct *ps, int depth)
1560 {
1561         if (r_q == NULL)
1562                 return False;
1563
1564         prs_debug(ps, depth, desc, "lsa_io_r_enum_accounts");
1565         depth++;
1566
1567         if (!prs_align(ps))
1568                 return False;
1569
1570         if(!prs_uint32("enum_context", ps, depth, &r_q->enum_context))
1571                 return False;
1572
1573         if (!lsa_io_sid_enum("sids", &r_q->sids, ps, depth))
1574                 return False;
1575
1576         if (!prs_align(ps))
1577                 return False;
1578
1579         if(!prs_ntstatus("status", ps, depth, &r_q->status))
1580                 return False;
1581
1582         return True;
1583 }
1584
1585
1586 /*******************************************************************
1587  Reads or writes an LSA_Q_UNK_GET_CONNUSER structure.
1588 ********************************************************************/
1589
1590 BOOL lsa_io_q_unk_get_connuser(char *desc, LSA_Q_UNK_GET_CONNUSER *q_c, prs_struct *ps, int depth)
1591 {
1592         prs_debug(ps, depth, desc, "lsa_io_q_unk_get_connuser");
1593         depth++;
1594
1595         if(!prs_align(ps))
1596                 return False;
1597    
1598         if(!prs_uint32("ptr_srvname", ps, depth, &q_c->ptr_srvname))
1599                 return False;
1600
1601         if(!smb_io_unistr2("uni2_srvname", &q_c->uni2_srvname, q_c->ptr_srvname, ps, depth)) /* server name to be looked up */
1602                 return False;
1603
1604         if (!prs_align(ps))
1605           return False;
1606
1607         if(!prs_uint32("unk1", ps, depth, &q_c->unk1))
1608                 return False;
1609         if(!prs_uint32("unk2", ps, depth, &q_c->unk2))
1610                 return False;
1611         if(!prs_uint32("unk3", ps, depth, &q_c->unk3))
1612                 return False;
1613
1614         /* Don't bother to read or write at present... */
1615         return True;
1616 }
1617
1618 /*******************************************************************
1619  Reads or writes an LSA_R_UNK_GET_CONNUSER structure.
1620 ********************************************************************/
1621
1622 BOOL lsa_io_r_unk_get_connuser(char *desc, LSA_R_UNK_GET_CONNUSER *r_c, prs_struct *ps, int depth)
1623 {
1624         prs_debug(ps, depth, desc, "lsa_io_r_unk_get_connuser");
1625         depth++;
1626
1627         if(!prs_align(ps))
1628                 return False;
1629    
1630         if(!prs_uint32("ptr_user_name", ps, depth, &r_c->ptr_user_name))
1631                 return False;
1632         if(!smb_io_unihdr("hdr_user_name", &r_c->hdr_user_name, ps, depth))
1633                 return False;
1634         if(!smb_io_unistr2("uni2_user_name", &r_c->uni2_user_name, r_c->ptr_user_name, ps, depth))
1635                 return False;
1636
1637         if (!prs_align(ps))
1638           return False;
1639         
1640         if(!prs_uint32("unk1", ps, depth, &r_c->unk1))
1641                 return False;
1642
1643         if(!prs_uint32("ptr_dom_name", ps, depth, &r_c->ptr_dom_name))
1644                 return False;
1645         if(!smb_io_unihdr("hdr_dom_name", &r_c->hdr_dom_name, ps, depth))
1646                 return False;
1647         if(!smb_io_unistr2("uni2_dom_name", &r_c->uni2_dom_name, r_c->ptr_dom_name, ps, depth))
1648                 return False;
1649
1650         if (!prs_align(ps))
1651           return False;
1652         
1653         if(!prs_ntstatus("status", ps, depth, &r_c->status))
1654                 return False;
1655
1656         return True;
1657 }
1658
1659 void init_lsa_q_open_account(LSA_Q_OPENACCOUNT *trn, POLICY_HND *hnd, DOM_SID *sid, uint32 desired_access)
1660 {
1661         memcpy(&trn->pol, hnd, sizeof(trn->pol));
1662
1663         init_dom_sid2(&trn->sid, sid);
1664         trn->access = desired_access;
1665 }
1666
1667 /*******************************************************************
1668  Reads or writes an LSA_Q_OPENACCOUNT structure.
1669 ********************************************************************/
1670
1671 BOOL lsa_io_q_open_account(char *desc, LSA_Q_OPENACCOUNT *r_c, prs_struct *ps, int depth)
1672 {
1673         prs_debug(ps, depth, desc, "lsa_io_q_open_account");
1674         depth++;
1675
1676         if(!prs_align(ps))
1677                 return False;
1678  
1679         if(!smb_io_pol_hnd("pol", &r_c->pol, ps, depth))
1680                 return False;
1681
1682         if(!smb_io_dom_sid2("sid", &r_c->sid, ps, depth)) /* domain SID */
1683                 return False;
1684
1685         if(!prs_uint32("access", ps, depth, &r_c->access))
1686                 return False;
1687   
1688         return True;
1689 }
1690
1691 /*******************************************************************
1692  Reads or writes an LSA_R_OPENACCOUNT structure.
1693 ********************************************************************/
1694
1695 BOOL lsa_io_r_open_account(char *desc, LSA_R_OPENACCOUNT  *r_c, prs_struct *ps, int depth)
1696 {
1697         prs_debug(ps, depth, desc, "lsa_io_r_open_account");
1698         depth++;
1699
1700         if(!prs_align(ps))
1701                 return False;
1702  
1703         if(!smb_io_pol_hnd("pol", &r_c->pol, ps, depth))
1704                 return False;
1705
1706         if(!prs_ntstatus("status", ps, depth, &r_c->status))
1707                 return False;
1708
1709         return True;
1710 }
1711
1712
1713 void init_lsa_q_enum_privsaccount(LSA_Q_ENUMPRIVSACCOUNT *trn, POLICY_HND *hnd)
1714 {
1715         memcpy(&trn->pol, hnd, sizeof(trn->pol));
1716
1717 }
1718
1719 /*******************************************************************
1720  Reads or writes an LSA_Q_ENUMPRIVSACCOUNT structure.
1721 ********************************************************************/
1722
1723 BOOL lsa_io_q_enum_privsaccount(char *desc, LSA_Q_ENUMPRIVSACCOUNT *r_c, prs_struct *ps, int depth)
1724 {
1725         prs_debug(ps, depth, desc, "lsa_io_q_enum_privsaccount");
1726         depth++;
1727
1728         if(!prs_align(ps))
1729                 return False;
1730  
1731         if(!smb_io_pol_hnd("pol", &r_c->pol, ps, depth))
1732                 return False;
1733
1734         return True;
1735 }
1736
1737 /*******************************************************************
1738  Reads or writes an LUID structure.
1739 ********************************************************************/
1740
1741 BOOL lsa_io_luid(char *desc, LUID *r_c, prs_struct *ps, int depth)
1742 {
1743         prs_debug(ps, depth, desc, "lsa_io_luid");
1744         depth++;
1745
1746         if(!prs_align(ps))
1747                 return False;
1748  
1749         if(!prs_uint32("low", ps, depth, &r_c->low))
1750                 return False;
1751
1752         if(!prs_uint32("high", ps, depth, &r_c->high))
1753                 return False;
1754
1755         return True;
1756 }
1757
1758 /*******************************************************************
1759  Reads or writes an LUID_ATTR structure.
1760 ********************************************************************/
1761
1762 BOOL lsa_io_luid_attr(char *desc, LUID_ATTR *r_c, prs_struct *ps, int depth)
1763 {
1764         prs_debug(ps, depth, desc, "lsa_io_luid_attr");
1765         depth++;
1766
1767         if(!prs_align(ps))
1768                 return False;
1769  
1770         if (!lsa_io_luid(desc, &r_c->luid, ps, depth))
1771                 return False;
1772
1773         if(!prs_uint32("attr", ps, depth, &r_c->attr))
1774                 return False;
1775
1776         return True;
1777 }
1778
1779 /*******************************************************************
1780  Reads or writes an PRIVILEGE_SET structure.
1781 ********************************************************************/
1782
1783 BOOL lsa_io_privilege_set(char *desc, PRIVILEGE_SET *r_c, prs_struct *ps, int depth)
1784 {
1785         uint32 i;
1786
1787         prs_debug(ps, depth, desc, "lsa_io_privilege_set");
1788         depth++;
1789
1790         if(!prs_align(ps))
1791                 return False;
1792  
1793         if(!prs_uint32("count", ps, depth, &r_c->count))
1794                 return False;
1795         if(!prs_uint32("control", ps, depth, &r_c->control))
1796                 return False;
1797
1798         for (i=0; i<r_c->count; i++) {
1799                 if (!lsa_io_luid_attr(desc, &r_c->set[i], ps, depth))
1800                         return False;
1801         }
1802         
1803         return True;
1804 }
1805
1806 void init_lsa_r_enum_privsaccount(LSA_R_ENUMPRIVSACCOUNT *r_u, LUID_ATTR *set, uint32 count, uint32 control)
1807 {
1808         r_u->ptr=1;
1809         r_u->count=count;
1810         r_u->set.set=set;
1811         r_u->set.count=count;
1812         r_u->set.control=control;
1813         DEBUG(10,("init_lsa_r_enum_privsaccount: %d %d privileges\n", r_u->count, r_u->set.count));
1814 }
1815
1816 /*******************************************************************
1817  Reads or writes an LSA_R_ENUMPRIVSACCOUNT structure.
1818 ********************************************************************/
1819
1820 BOOL lsa_io_r_enum_privsaccount(char *desc, LSA_R_ENUMPRIVSACCOUNT *r_c, prs_struct *ps, int depth)
1821 {
1822         prs_debug(ps, depth, desc, "lsa_io_r_enum_privsaccount");
1823         depth++;
1824
1825         if(!prs_align(ps))
1826                 return False;
1827  
1828         if(!prs_uint32("ptr", ps, depth, &r_c->ptr))
1829                 return False;
1830
1831         if (r_c->ptr!=0) {
1832                 if(!prs_uint32("count", ps, depth, &r_c->count))
1833                         return False;
1834
1835                 /* malloc memory if unmarshalling here */
1836
1837                 if (UNMARSHALLING(ps) && r_c->count!=0) {
1838                         if (!(r_c->set.set = (LUID_ATTR *)prs_alloc_mem(ps,sizeof(LUID_ATTR) * r_c->count)))
1839                                 return False;
1840
1841                 }
1842                 
1843                 if(!lsa_io_privilege_set(desc, &r_c->set, ps, depth))
1844                         return False;
1845         }
1846
1847         if(!prs_ntstatus("status", ps, depth, &r_c->status))
1848                 return False;
1849
1850         return True;
1851 }
1852
1853
1854
1855 /*******************************************************************
1856  Reads or writes an  LSA_Q_GETSYSTEMACCOUNTstructure.
1857 ********************************************************************/
1858
1859 BOOL lsa_io_q_getsystemaccount(char *desc, LSA_Q_GETSYSTEMACCOUNT  *r_c, prs_struct *ps, int depth)
1860 {
1861         prs_debug(ps, depth, desc, "lsa_io_q_getsystemaccount");
1862         depth++;
1863
1864         if(!prs_align(ps))
1865                 return False;
1866  
1867         if(!smb_io_pol_hnd("pol", &r_c->pol, ps, depth))
1868                 return False;
1869
1870         return True;
1871 }
1872
1873 /*******************************************************************
1874  Reads or writes an  LSA_R_GETSYSTEMACCOUNTstructure.
1875 ********************************************************************/
1876
1877 BOOL lsa_io_r_getsystemaccount(char *desc, LSA_R_GETSYSTEMACCOUNT  *r_c, prs_struct *ps, int depth)
1878 {
1879         prs_debug(ps, depth, desc, "lsa_io_r_getsystemaccount");
1880         depth++;
1881
1882         if(!prs_align(ps))
1883                 return False;
1884  
1885         if(!prs_uint32("access", ps, depth, &r_c->access))
1886                 return False;
1887
1888         if(!prs_ntstatus("status", ps, depth, &r_c->status))
1889                 return False;
1890
1891         return True;
1892 }
1893
1894
1895 /*******************************************************************
1896  Reads or writes an LSA_Q_SETSYSTEMACCOUNT structure.
1897 ********************************************************************/
1898
1899 BOOL lsa_io_q_setsystemaccount(char *desc, LSA_Q_SETSYSTEMACCOUNT  *r_c, prs_struct *ps, int depth)
1900 {
1901         prs_debug(ps, depth, desc, "lsa_io_q_setsystemaccount");
1902         depth++;
1903
1904         if(!prs_align(ps))
1905                 return False;
1906  
1907         if(!smb_io_pol_hnd("pol", &r_c->pol, ps, depth))
1908                 return False;
1909
1910         if(!prs_uint32("access", ps, depth, &r_c->access))
1911                 return False;
1912
1913         return True;
1914 }
1915
1916 /*******************************************************************
1917  Reads or writes an LSA_R_SETSYSTEMACCOUNT structure.
1918 ********************************************************************/
1919
1920 BOOL lsa_io_r_setsystemaccount(char *desc, LSA_R_SETSYSTEMACCOUNT  *r_c, prs_struct *ps, int depth)
1921 {
1922         prs_debug(ps, depth, desc, "lsa_io_r_setsystemaccount");
1923         depth++;
1924
1925         if(!prs_align(ps))
1926                 return False;
1927  
1928         if(!prs_ntstatus("status", ps, depth, &r_c->status))
1929                 return False;
1930
1931         return True;
1932 }
1933
1934
1935 void init_lsa_q_lookupprivvalue(LSA_Q_LOOKUPPRIVVALUE *trn, POLICY_HND *hnd, char *name)
1936 {
1937         int len_name = strlen(name);
1938         memcpy(&trn->pol, hnd, sizeof(trn->pol));
1939
1940         if(len_name == 0)
1941                 len_name = 1;
1942
1943         init_uni_hdr(&trn->hdr_right, len_name);
1944         init_unistr2(&trn->uni2_right, name, len_name);
1945 }
1946
1947 /*******************************************************************
1948  Reads or writes an LSA_Q_LOOKUPPRIVVALUE  structure.
1949 ********************************************************************/
1950
1951 BOOL lsa_io_q_lookupprivvalue(char *desc, LSA_Q_LOOKUPPRIVVALUE  *r_c, prs_struct *ps, int depth)
1952 {
1953         prs_debug(ps, depth, desc, "lsa_io_q_lookupprivvalue");
1954         depth++;
1955
1956         if(!prs_align(ps))
1957                 return False;
1958  
1959         if(!smb_io_pol_hnd("pol", &r_c->pol, ps, depth))
1960                 return False;
1961         if(!smb_io_unihdr ("hdr_name", &r_c->hdr_right, ps, depth))
1962                 return False;
1963         if(!smb_io_unistr2("uni2_right", &r_c->uni2_right, r_c->hdr_right.buffer, ps, depth))
1964                 return False;
1965
1966         return True;
1967 }
1968
1969 /*******************************************************************
1970  Reads or writes an  LSA_R_LOOKUPPRIVVALUE structure.
1971 ********************************************************************/
1972
1973 BOOL lsa_io_r_lookupprivvalue(char *desc, LSA_R_LOOKUPPRIVVALUE  *r_c, prs_struct *ps, int depth)
1974 {
1975         prs_debug(ps, depth, desc, "lsa_io_r_lookupprivvalue");
1976         depth++;
1977
1978         if(!prs_align(ps))
1979                 return False;
1980                 
1981         if(!lsa_io_luid("luid", &r_c->luid, ps, depth))
1982                 return False;
1983  
1984         if(!prs_ntstatus("status", ps, depth, &r_c->status))
1985                 return False;
1986
1987         return True;
1988 }
1989
1990
1991 /*******************************************************************
1992  Reads or writes an LSA_Q_ADDPRIVS structure.
1993 ********************************************************************/
1994
1995 BOOL lsa_io_q_addprivs(char *desc, LSA_Q_ADDPRIVS *r_c, prs_struct *ps, int depth)
1996 {
1997         prs_debug(ps, depth, desc, "lsa_io_q_addprivs");
1998         depth++;
1999
2000         if(!prs_align(ps))
2001                 return False;
2002  
2003         if(!smb_io_pol_hnd("pol", &r_c->pol, ps, depth))
2004                 return False;
2005         
2006         if(!prs_uint32("count", ps, depth, &r_c->count))
2007                 return False;
2008
2009         if (UNMARSHALLING(ps) && r_c->count!=0) {
2010                 if (!(r_c->set.set = (LUID_ATTR *)prs_alloc_mem(ps,sizeof(LUID_ATTR) * r_c->count)))
2011                         return False;
2012         }
2013         
2014         if(!lsa_io_privilege_set(desc, &r_c->set, ps, depth))
2015                 return False;
2016         
2017         return True;
2018 }
2019
2020 /*******************************************************************
2021  Reads or writes an LSA_R_ADDPRIVS structure.
2022 ********************************************************************/
2023
2024 BOOL lsa_io_r_addprivs(char *desc, LSA_R_ADDPRIVS *r_c, prs_struct *ps, int depth)
2025 {
2026         prs_debug(ps, depth, desc, "lsa_io_r_addprivs");
2027         depth++;
2028
2029         if(!prs_align(ps))
2030                 return False;
2031  
2032         if(!prs_ntstatus("status", ps, depth, &r_c->status))
2033                 return False;
2034
2035         return True;
2036 }
2037
2038 /*******************************************************************
2039  Reads or writes an LSA_Q_REMOVEPRIVS structure.
2040 ********************************************************************/
2041
2042 BOOL lsa_io_q_removeprivs(char *desc, LSA_Q_REMOVEPRIVS *r_c, prs_struct *ps, int depth)
2043 {
2044         prs_debug(ps, depth, desc, "lsa_io_q_removeprivs");
2045         depth++;
2046
2047         if(!prs_align(ps))
2048                 return False;
2049  
2050         if(!smb_io_pol_hnd("pol", &r_c->pol, ps, depth))
2051                 return False;
2052         
2053         if(!prs_uint32("allrights", ps, depth, &r_c->allrights))
2054                 return False;
2055
2056         if(!prs_uint32("ptr", ps, depth, &r_c->ptr))
2057                 return False;
2058
2059         /* 
2060          * JFM: I'm not sure at all if the count is inside the ptr
2061          * never seen one with ptr=0
2062          */
2063
2064         if (r_c->ptr!=0) {
2065                 if(!prs_uint32("count", ps, depth, &r_c->count))
2066                         return False;
2067
2068                 if (UNMARSHALLING(ps) && r_c->count!=0) {
2069                         if (!(r_c->set.set = (LUID_ATTR *)prs_alloc_mem(ps,sizeof(LUID_ATTR) * r_c->count)))
2070                                 return False;
2071                 }
2072
2073                 if(!lsa_io_privilege_set(desc, &r_c->set, ps, depth))
2074                         return False;
2075         }
2076
2077         return True;
2078 }
2079
2080 /*******************************************************************
2081  Reads or writes an LSA_R_REMOVEPRIVS structure.
2082 ********************************************************************/
2083
2084 BOOL lsa_io_r_removeprivs(char *desc, LSA_R_REMOVEPRIVS *r_c, prs_struct *ps, int depth)
2085 {
2086         prs_debug(ps, depth, desc, "lsa_io_r_removeprivs");
2087         depth++;
2088
2089         if(!prs_align(ps))
2090                 return False;
2091  
2092         if(!prs_ntstatus("status", ps, depth, &r_c->status))
2093                 return False;
2094
2095         return True;
2096 }
2097
2098