Removed 'extern int DEBUGLEVEL' as it is now in the smb.h header.
[kai/samba.git] / source3 / rpc_parse / parse_reg.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  *  Copyright (C) Marc Jacobsen                     1999.
9  *  Copyright (C) Simo Sorce                        2000.
10  *  
11  *  This program is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *  
16  *  This program is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *  
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  */
25
26 #include "includes.h"
27
28 /*******************************************************************
29  Inits a structure.
30 ********************************************************************/
31
32 void init_reg_q_open_hkcr(REG_Q_OPEN_HKCR *q_o,
33                                 uint16 unknown_0, uint32 level)
34 {
35         q_o->ptr = 1;
36         q_o->unknown_0 = unknown_0;
37         q_o->unknown_1 = 0x0; /* random - changes */
38         q_o->level = level;
39 }
40
41 /*******************************************************************
42 reads or writes a structure.
43 ********************************************************************/
44
45 BOOL reg_io_q_open_hkcr(char *desc,  REG_Q_OPEN_HKCR *r_q, prs_struct *ps, int depth)
46 {
47         if (r_q == NULL)
48                 return False;
49
50         prs_debug(ps, depth, desc, "reg_io_q_open_hkcr");
51         depth++;
52
53         if(!prs_align(ps))
54                 return False;
55
56         if(!prs_uint32("ptr      ", ps, depth, &r_q->ptr))
57                 return False;
58
59         if (r_q->ptr != 0) {
60                 if(!prs_uint16("unknown_0", ps, depth, &r_q->unknown_0))
61                         return False;
62                 if(!prs_uint16("unknown_1", ps, depth, &r_q->unknown_1))
63                         return False;
64                 if(!prs_uint32("level    ", ps, depth, &r_q->level))
65                         return False;
66         }
67
68         return True;
69 }
70
71
72 /*******************************************************************
73 reads or writes a structure.
74 ********************************************************************/
75
76 BOOL reg_io_r_open_hkcr(char *desc,  REG_R_OPEN_HKCR *r_r, prs_struct *ps, int depth)
77 {
78         if (r_r == NULL)
79                 return False;
80
81         prs_debug(ps, depth, desc, "reg_io_r_open_hkcr");
82         depth++;
83
84         if(!prs_align(ps))
85                 return False;
86         
87         if(!smb_io_pol_hnd("", &r_r->pol, ps, depth))
88                 return False;
89
90         if(!prs_ntstatus("status", ps, depth, &r_r->status))
91                 return False;
92
93         return True;
94 }
95
96 /*******************************************************************
97  Inits a structure.
98 ********************************************************************/
99
100 void init_reg_q_open_hklm(REG_Q_OPEN_HKLM * q_o,
101                           uint16 unknown_0, uint32 access_mask)
102 {
103         q_o->ptr = 1;
104         q_o->unknown_0 = unknown_0;
105         q_o->unknown_1 = 0x0;   /* random - changes */
106         q_o->access_mask = access_mask;
107
108 }
109
110 /*******************************************************************
111 reads or writes a structure.
112 ********************************************************************/
113 BOOL reg_io_q_open_hklm(char *desc, REG_Q_OPEN_HKLM * r_q, prs_struct *ps,
114                         int depth)
115 {
116         if (r_q == NULL)
117                 return False;
118
119         prs_debug(ps, depth, desc, "reg_io_q_open_hklm");
120         depth++;
121
122         if (!prs_align(ps))
123                 return False;
124
125         if (!prs_uint32("ptr      ", ps, depth, &(r_q->ptr)))
126                 return False;
127         if (r_q->ptr != 0)
128         {
129                 if (!prs_uint16("unknown_0", ps, depth, &(r_q->unknown_0)))
130                 return False;
131                 if (!prs_uint16("unknown_1", ps, depth, &(r_q->unknown_1)))
132                 return False;
133                 if (!prs_uint32("access_mask", ps, depth, &(r_q->access_mask)))
134                 return False;
135         }
136
137         return True;
138 }
139
140
141 /*******************************************************************
142 reads or writes a structure.
143 ********************************************************************/
144 BOOL reg_io_r_open_hklm(char *desc, REG_R_OPEN_HKLM * r_r, prs_struct *ps,
145                         int depth)
146 {
147         if (r_r == NULL)
148                 return False;
149
150         prs_debug(ps, depth, desc, "reg_io_r_open_hklm");
151         depth++;
152
153         if (!prs_align(ps))
154                 return False;
155
156         if (!smb_io_pol_hnd("", &(r_r->pol), ps, depth))
157                 return False;
158
159         if (!prs_ntstatus("status", ps, depth, &(r_r->status)))
160                 return False;
161
162         return True;
163 }
164
165
166 /*******************************************************************
167  Inits a structure.
168 ********************************************************************/
169
170 void init_reg_q_flush_key(REG_Q_FLUSH_KEY *q_u, POLICY_HND *pol)
171 {
172         memcpy(&q_u->pol, pol, sizeof(q_u->pol));
173 }
174
175 /*******************************************************************
176 reads or writes a structure.
177 ********************************************************************/
178
179 BOOL reg_io_q_flush_key(char *desc,  REG_Q_FLUSH_KEY *r_q, prs_struct *ps, int depth)
180 {
181         if (r_q == NULL)
182                 return False;
183
184         prs_debug(ps, depth, desc, "reg_io_q_flush_key");
185         depth++;
186
187         if(!prs_align(ps))
188                 return False;
189         
190         if(!smb_io_pol_hnd("", &r_q->pol, ps, depth))
191                 return False;
192
193         return True;
194 }
195
196 /*******************************************************************
197 reads or writes a structure.
198 ********************************************************************/
199
200 BOOL reg_io_r_flush_key(char *desc,  REG_R_FLUSH_KEY *r_r, prs_struct *ps, int depth)
201 {
202         if (r_r == NULL)
203                 return False;
204
205         prs_debug(ps, depth, desc, "reg_io_r_flush_key");
206         depth++;
207
208         if(!prs_align(ps))
209                 return False;
210         
211         if(!prs_ntstatus("status", ps, depth, &r_r->status))
212                 return False;
213
214         return True;
215 }
216
217 /*******************************************************************
218 reads or writes SEC_DESC_BUF and SEC_DATA structures.
219 ********************************************************************/
220
221 static BOOL reg_io_hdrbuf_sec(uint32 ptr, uint32 *ptr3, BUFHDR *hdr_sec, SEC_DESC_BUF *data, prs_struct *ps, int depth)
222 {
223         if (ptr != 0) {
224                 uint32 hdr_offset;
225                 uint32 old_offset;
226                 if(!smb_io_hdrbuf_pre("hdr_sec", hdr_sec, ps, depth, &hdr_offset))
227                         return False;
228
229                 old_offset = prs_offset(ps);
230
231                 if (ptr3 != NULL) {
232                         if(!prs_uint32("ptr3", ps, depth, ptr3))
233                                 return False;
234                 }
235
236                 if (ptr3 == NULL || *ptr3 != 0) {
237                         if(!sec_io_desc_buf("data   ", &data, ps, depth)) /* JRA - this line is probably wrong... */
238                                 return False;
239                 }
240
241                 if(!smb_io_hdrbuf_post("hdr_sec", hdr_sec, ps, depth, hdr_offset,
242                                    data->max_len, data->len))
243                                 return False;
244                 if(!prs_set_offset(ps, old_offset + data->len + sizeof(uint32) * ((ptr3 != NULL) ? 5 : 3)))
245                         return False;
246
247                 if(!prs_align(ps))
248                         return False;
249         }
250
251         return True;
252 }
253
254 /*******************************************************************
255  Inits a structure.
256 ********************************************************************/
257
258 void init_reg_q_create_key(REG_Q_CREATE_KEY *q_c, POLICY_HND *hnd,
259                                 char *name, char *class, SEC_ACCESS *sam_access,
260                                 SEC_DESC_BUF *sec_buf)
261 {
262         int len_name  = name  != NULL ? strlen(name ) + 1: 0;
263         int len_class = class != NULL ? strlen(class) + 1: 0;
264
265         ZERO_STRUCTP(q_c);
266
267         memcpy(&q_c->pnt_pol, hnd, sizeof(q_c->pnt_pol));
268
269         init_uni_hdr(&q_c->hdr_name, len_name);
270         init_unistr2(&q_c->uni_name, name, len_name);
271
272         init_uni_hdr(&q_c->hdr_class, len_class);
273         init_unistr2(&q_c->uni_class, class, len_class);
274
275         q_c->reserved = 0x00000000;
276         memcpy(&q_c->sam_access, sam_access, sizeof(q_c->sam_access));
277
278         q_c->ptr1 = 1;
279         q_c->sec_info = DACL_SECURITY_INFORMATION | SACL_SECURITY_INFORMATION;
280
281         q_c->data = sec_buf;
282         q_c->ptr2 = 1;
283         init_buf_hdr(&q_c->hdr_sec, sec_buf->len, sec_buf->len);
284         q_c->ptr3 = 1;
285         q_c->unknown_2 = 0x00000000;
286 }
287
288 /*******************************************************************
289 reads or writes a structure.
290 ********************************************************************/
291
292 BOOL reg_io_q_create_key(char *desc,  REG_Q_CREATE_KEY *r_q, prs_struct *ps, int depth)
293 {
294         if (r_q == NULL)
295                 return False;
296
297         prs_debug(ps, depth, desc, "reg_io_q_create_key");
298         depth++;
299
300         if(!prs_align(ps))
301                 return False;
302         
303         if(!smb_io_pol_hnd("", &r_q->pnt_pol, ps, depth))
304                 return False;
305
306         if(!smb_io_unihdr ("", &r_q->hdr_name, ps, depth))
307                 return False;
308         if(!smb_io_unistr2("", &r_q->uni_name, r_q->hdr_name.buffer, ps, depth))
309                 return False;
310         if(!prs_align(ps))
311                 return False;
312
313         if(!smb_io_unihdr ("", &r_q->hdr_class, ps, depth))
314                 return False;
315         if(!smb_io_unistr2("", &r_q->uni_class, r_q->hdr_class.buffer, ps, depth))
316                 return False;
317         if(!prs_align(ps))
318                 return False;
319
320         if(!prs_uint32("reserved", ps, depth, &r_q->reserved))
321                 return False;
322         if(!sec_io_access("sam_access", &r_q->sam_access, ps, depth))
323                 return False;
324
325         if(!prs_uint32("ptr1", ps, depth, &r_q->ptr1))
326                 return False;
327
328         if (r_q->ptr1 != 0) {
329                 if(!prs_uint32("sec_info", ps, depth, &r_q->sec_info))
330                         return False;
331         }
332
333         if(!prs_uint32("ptr2", ps, depth, &r_q->ptr2))
334                 return False;
335         if(!reg_io_hdrbuf_sec(r_q->ptr2, &r_q->ptr3, &r_q->hdr_sec, r_q->data, ps, depth))
336                 return False;
337
338         if(!prs_uint32("unknown_2", ps, depth, &r_q->unknown_2))
339                 return False;
340
341         return True;
342 }
343
344 /*******************************************************************
345 reads or writes a structure.
346 ********************************************************************/
347
348 BOOL reg_io_r_create_key(char *desc,  REG_R_CREATE_KEY *r_r, prs_struct *ps, int depth)
349 {
350         if (r_r == NULL)
351                 return False;
352
353         prs_debug(ps, depth, desc, "reg_io_r_create_key");
354         depth++;
355
356         if(!prs_align(ps))
357                 return False;
358         
359         if(!smb_io_pol_hnd("", &r_r->key_pol, ps, depth))
360                 return False;
361         if(!prs_uint32("unknown", ps, depth, &r_r->unknown))
362                 return False;
363
364         if(!prs_ntstatus("status", ps, depth, &r_r->status))
365                 return False;
366
367         return True;
368 }
369
370
371 /*******************************************************************
372  Inits a structure.
373 ********************************************************************/
374
375 void init_reg_q_delete_val(REG_Q_DELETE_VALUE *q_c, POLICY_HND *hnd,
376                                 char *name)
377 {
378         int len_name  = name  != NULL ? strlen(name ) + 1: 0;
379         ZERO_STRUCTP(q_c);
380
381         memcpy(&q_c->pnt_pol, hnd, sizeof(q_c->pnt_pol));
382
383         init_uni_hdr(&q_c->hdr_name, len_name);
384         init_unistr2(&q_c->uni_name, name, len_name);
385 }
386
387 /*******************************************************************
388 reads or writes a structure.
389 ********************************************************************/
390
391 BOOL reg_io_q_delete_val(char *desc,  REG_Q_DELETE_VALUE *r_q, prs_struct *ps, int depth)
392 {
393         if (r_q == NULL)
394                 return False;
395
396         prs_debug(ps, depth, desc, "reg_io_q_delete_val");
397         depth++;
398
399         if(!prs_align(ps))
400                 return False;
401         
402         if(!smb_io_pol_hnd("", &r_q->pnt_pol, ps, depth))
403                 return False;
404
405         if(!smb_io_unihdr ("", &r_q->hdr_name, ps, depth))
406                 return False;
407         if(!smb_io_unistr2("", &r_q->uni_name, r_q->hdr_name.buffer, ps, depth))
408                 return False;
409         if(!prs_align(ps))
410                 return False;
411
412         return True;
413 }
414
415
416 /*******************************************************************
417 reads or writes a structure.
418 ********************************************************************/
419
420 BOOL reg_io_r_delete_val(char *desc,  REG_R_DELETE_VALUE *r_r, prs_struct *ps, int depth)
421 {
422         if (r_r == NULL)
423                 return False;
424
425         prs_debug(ps, depth, desc, "reg_io_r_delete_val");
426         depth++;
427
428         if(!prs_align(ps))
429                 return False;
430         
431         if(!prs_ntstatus("status", ps, depth, &r_r->status))
432                 return False;
433
434         return True;
435 }
436
437 /*******************************************************************
438  Inits a structure.
439 ********************************************************************/
440
441 void init_reg_q_delete_key(REG_Q_DELETE_KEY *q_c, POLICY_HND *hnd,
442                                 char *name)
443 {
444         int len_name  = name  != NULL ? strlen(name ) + 1: 0;
445         ZERO_STRUCTP(q_c);
446
447         memcpy(&q_c->pnt_pol, hnd, sizeof(q_c->pnt_pol));
448
449         init_uni_hdr(&q_c->hdr_name, len_name);
450         init_unistr2(&q_c->uni_name, name, len_name);
451 }
452
453 /*******************************************************************
454 reads or writes a structure.
455 ********************************************************************/
456
457 BOOL reg_io_q_delete_key(char *desc,  REG_Q_DELETE_KEY *r_q, prs_struct *ps, int depth)
458 {
459         if (r_q == NULL)
460                 return False;
461
462         prs_debug(ps, depth, desc, "reg_io_q_delete_key");
463         depth++;
464
465         if(!prs_align(ps))
466                 return False;
467         
468         if(!smb_io_pol_hnd("", &r_q->pnt_pol, ps, depth))
469                 return False;
470
471         if(!smb_io_unihdr ("", &r_q->hdr_name, ps, depth))
472                 return False;
473         if(!smb_io_unistr2("", &r_q->uni_name, r_q->hdr_name.buffer, ps, depth))
474                 return False;
475         if(!prs_align(ps))
476                 return False;
477
478         return True;
479 }
480
481 /*******************************************************************
482 reads or writes a structure.
483 ********************************************************************/
484
485 BOOL reg_io_r_delete_key(char *desc,  REG_R_DELETE_KEY *r_r, prs_struct *ps, int depth)
486 {
487         if (r_r == NULL)
488                 return False;
489
490         prs_debug(ps, depth, desc, "reg_io_r_delete_key");
491         depth++;
492
493         if(!prs_align(ps))
494                 return False;
495         
496         if(!prs_ntstatus("status", ps, depth, &r_r->status))
497                 return False;
498
499         return True;
500 }
501
502 /*******************************************************************
503  Inits a structure.
504 ********************************************************************/
505
506 void init_reg_q_query_key(REG_Q_QUERY_KEY *q_o, POLICY_HND *hnd,
507                                 uint32 max_class_len)
508 {
509         ZERO_STRUCTP(q_o);
510
511         memcpy(&q_o->pol, hnd, sizeof(q_o->pol));
512         init_uni_hdr(&q_o->hdr_class, max_class_len);
513         q_o->uni_class.uni_max_len = max_class_len;
514 }
515
516 /*******************************************************************
517 reads or writes a structure.
518 ********************************************************************/
519
520 BOOL reg_io_q_query_key(char *desc,  REG_Q_QUERY_KEY *r_q, prs_struct *ps, int depth)
521 {
522         if (r_q == NULL)
523                 return False;
524
525         prs_debug(ps, depth, desc, "reg_io_q_query_key");
526         depth++;
527
528         if(!prs_align(ps))
529                 return False;
530         
531         if(!smb_io_pol_hnd("", &r_q->pol, ps, depth))
532                 return False;
533         if(!smb_io_unihdr ("", &r_q->hdr_class, ps, depth))
534                 return False;
535         if(!smb_io_unistr2("", &r_q->uni_class, r_q->hdr_class.buffer, ps, depth))
536                 return False;
537
538         if(!prs_align(ps))
539                 return False;
540
541         return True;
542 }
543
544
545 /*******************************************************************
546 reads or writes a structure.
547 ********************************************************************/
548
549 BOOL reg_io_r_query_key(char *desc,  REG_R_QUERY_KEY *r_r, prs_struct *ps, int depth)
550 {
551         if (r_r == NULL)
552                 return False;
553
554         prs_debug(ps, depth, desc, "reg_io_r_query_key");
555         depth++;
556
557         if(!prs_align(ps))
558                 return False;
559         
560         if(!smb_io_unihdr ("", &r_r->hdr_class, ps, depth))
561                 return False;
562         if(!smb_io_unistr2("", &r_r->uni_class, r_r->hdr_class.buffer, ps, depth))
563                 return False;
564
565         if(!prs_align(ps))
566                 return False;
567
568         if(!prs_uint32("num_subkeys   ", ps, depth, &r_r->num_subkeys))
569                 return False;
570         if(!prs_uint32("max_subkeylen ", ps, depth, &r_r->max_subkeylen))
571                 return False;
572         if(!prs_uint32("mak_subkeysize", ps, depth, &r_r->max_subkeysize))
573                 return False;
574         if(!prs_uint32("num_values    ", ps, depth, &r_r->num_values))
575                 return False;
576         if(!prs_uint32("max_valnamelen", ps, depth, &r_r->max_valnamelen))
577                 return False;
578         if(!prs_uint32("max_valbufsize", ps, depth, &r_r->max_valbufsize))
579                 return False;
580         if(!prs_uint32("sec_desc      ", ps, depth, &r_r->sec_desc))
581                 return False;
582         if(!smb_io_time("mod_time     ", &r_r->mod_time, ps, depth))
583                 return False;
584         
585         if(!prs_ntstatus("status", ps, depth, &r_r->status))
586                 return False;
587
588         return True;
589 }
590
591 /*******************************************************************
592  Inits a structure.
593 ********************************************************************/
594
595 void init_reg_q_unk_1a(REG_Q_UNK_1A *q_o, POLICY_HND *hnd)
596 {
597         memcpy(&q_o->pol, hnd, sizeof(q_o->pol));
598 }
599
600 /*******************************************************************
601 reads or writes a structure.
602 ********************************************************************/
603
604 BOOL reg_io_q_unk_1a(char *desc,  REG_Q_UNK_1A *r_q, prs_struct *ps, int depth)
605 {
606         if (r_q == NULL)
607                 return False;
608
609         prs_debug(ps, depth, desc, "reg_io_q_unk_1a");
610         depth++;
611
612         if(!prs_align(ps))
613                 return False;
614         
615         if(!smb_io_pol_hnd("", &r_q->pol, ps, depth))
616                 return False;
617
618         return True;
619 }
620
621 /*******************************************************************
622 reads or writes a structure.
623 ********************************************************************/
624
625 BOOL reg_io_r_unk_1a(char *desc,  REG_R_UNK_1A *r_r, prs_struct *ps, int depth)
626 {
627         if (r_r == NULL)
628                 return False;
629
630         prs_debug(ps, depth, desc, "reg_io_r_unk_1a");
631         depth++;
632
633         if(!prs_align(ps))
634                 return False;
635         
636         if(!prs_uint32("unknown", ps, depth, &r_r->unknown))
637                 return False;
638         if(!prs_ntstatus("status" , ps, depth, &r_r->status))
639                 return False;
640
641         return True;
642 }
643
644 /*******************************************************************
645  Inits a structure.
646 ********************************************************************/
647
648 void init_reg_q_open_hku(REG_Q_OPEN_HKU *q_o,
649                                 uint16 unknown_0, uint32 level)
650 {
651         q_o->ptr = 1;
652         q_o->unknown_0 = unknown_0;
653         q_o->unknown_1 = 0x0; /* random - changes */
654         q_o->level = level;
655 }
656
657 /*******************************************************************
658 reads or writes a structure.
659 ********************************************************************/
660
661 BOOL reg_io_q_open_hku(char *desc,  REG_Q_OPEN_HKU *r_q, prs_struct *ps, int depth)
662 {
663         if (r_q == NULL)
664                 return False;
665
666         prs_debug(ps, depth, desc, "reg_io_q_open_hku");
667         depth++;
668
669         if(!prs_align(ps))
670                 return False;
671         
672         if(!prs_uint32("ptr      ", ps, depth, &r_q->ptr))
673                 return False;
674         if (r_q->ptr != 0) {
675                 if(!prs_uint16("unknown_0", ps, depth, &r_q->unknown_0))
676                         return False;
677                 if(!prs_uint16("unknown_1", ps, depth, &r_q->unknown_1))
678                         return False;
679                 if(!prs_uint32("level    ", ps, depth, &r_q->level))
680                         return False;
681         }
682
683         return True;
684 }
685
686 /*******************************************************************
687 reads or writes a structure.
688 ********************************************************************/
689
690 BOOL reg_io_r_open_hku(char *desc,  REG_R_OPEN_HKU *r_r, prs_struct *ps, int depth)
691 {
692         if (r_r == NULL)
693                 return False;
694
695         prs_debug(ps, depth, desc, "reg_io_r_open_hku");
696         depth++;
697
698         if(!prs_align(ps))
699                 return False;
700         
701         if(!smb_io_pol_hnd("", &r_r->pol, ps, depth))
702                 return False;
703
704         if(!prs_ntstatus("status", ps, depth, &r_r->status))
705                 return False;
706
707         return True;
708 }
709
710 /*******************************************************************
711  Inits an REG_Q_CLOSE structure.
712 ********************************************************************/
713
714 void init_reg_q_close(REG_Q_CLOSE *q_c, POLICY_HND *hnd)
715 {
716         DEBUG(5,("init_reg_q_close\n"));
717
718         memcpy(&q_c->pol, hnd, sizeof(q_c->pol));
719 }
720
721 /*******************************************************************
722 reads or writes a structure.
723 ********************************************************************/
724
725 BOOL reg_io_q_close(char *desc,  REG_Q_CLOSE *q_u, prs_struct *ps, int depth)
726 {
727         if (q_u == NULL)
728                 return False;
729
730         prs_debug(ps, depth, desc, "reg_io_q_unknown_1");
731         depth++;
732
733         if(!prs_align(ps))
734                 return False;
735
736         if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
737                 return False;
738         if(!prs_align(ps))
739                 return False;
740
741         return True;
742 }
743
744 /*******************************************************************
745 reads or writes a structure.
746 ********************************************************************/
747
748 BOOL reg_io_r_close(char *desc,  REG_R_CLOSE *r_u, prs_struct *ps, int depth)
749 {
750         if (r_u == NULL)
751                 return False;
752
753         prs_debug(ps, depth, desc, "reg_io_r_unknown_1");
754         depth++;
755
756         if(!prs_align(ps))
757                 return False;
758
759         if(!smb_io_pol_hnd("", &r_u->pol, ps, depth))
760                 return False;
761         if(!prs_align(ps))
762                 return False;
763
764         if(!prs_ntstatus("status", ps, depth, &r_u->status))
765                 return False;
766
767         return True;
768 }
769
770 /*******************************************************************
771 makes a structure.
772 ********************************************************************/
773
774 void init_reg_q_set_key_sec(REG_Q_SET_KEY_SEC *q_i, POLICY_HND *pol, SEC_DESC_BUF *sec_desc_buf)
775 {
776         memcpy(&q_i->pol, pol, sizeof(q_i->pol));
777
778         q_i->sec_info = DACL_SECURITY_INFORMATION;
779
780         q_i->ptr = 1;
781         init_buf_hdr(&q_i->hdr_sec, sec_desc_buf->len, sec_desc_buf->len);
782         q_i->data = sec_desc_buf;
783 }
784
785 /*******************************************************************
786 reads or writes a structure.
787 ********************************************************************/
788
789 BOOL reg_io_q_set_key_sec(char *desc,  REG_Q_SET_KEY_SEC *r_q, prs_struct *ps, int depth)
790 {
791         if (r_q == NULL)
792                 return False;
793
794         prs_debug(ps, depth, desc, "reg_io_q_set_key_sec");
795         depth++;
796
797         if(!prs_align(ps))
798                 return False;
799         
800         if(!smb_io_pol_hnd("", &r_q->pol, ps, depth))
801                 return False;
802
803         if(!prs_uint32("sec_info", ps, depth, &r_q->sec_info))
804                 return False;
805         if(!prs_uint32("ptr    ", ps, depth, &r_q->ptr))
806                 return False;
807
808         if(!reg_io_hdrbuf_sec(r_q->ptr, NULL, &r_q->hdr_sec, r_q->data, ps, depth))
809                 return False;
810
811         return True;
812 }
813
814 /*******************************************************************
815 reads or writes a structure.
816 ********************************************************************/
817
818 BOOL reg_io_r_set_key_sec(char *desc, REG_R_SET_KEY_SEC *r_q, prs_struct *ps, int depth)
819 {
820         if (r_q == NULL)
821                 return False;
822
823         prs_debug(ps, depth, desc, "reg_io_r_set_key_sec");
824         depth++;
825
826         if(!prs_align(ps))
827                 return False;
828         
829         if(!prs_ntstatus("status", ps, depth, &r_q->status))
830                 return False;
831
832         return True;
833 }
834
835
836 /*******************************************************************
837 makes a structure.
838 ********************************************************************/
839
840 void init_reg_q_get_key_sec(REG_Q_GET_KEY_SEC *q_i, POLICY_HND *pol, 
841                                 uint32 sec_buf_size, SEC_DESC_BUF *psdb)
842 {
843         memcpy(&q_i->pol, pol, sizeof(q_i->pol));
844
845         q_i->sec_info = OWNER_SECURITY_INFORMATION |
846                         GROUP_SECURITY_INFORMATION |
847                         DACL_SECURITY_INFORMATION;
848
849         q_i->ptr = psdb != NULL ? 1 : 0;
850         q_i->data = psdb;
851
852         init_buf_hdr(&q_i->hdr_sec, sec_buf_size, 0);
853 }
854
855 /*******************************************************************
856 reads or writes a structure.
857 ********************************************************************/
858
859 BOOL reg_io_q_get_key_sec(char *desc,  REG_Q_GET_KEY_SEC *r_q, prs_struct *ps, int depth)
860 {
861         if (r_q == NULL)
862                 return False;
863
864         prs_debug(ps, depth, desc, "reg_io_q_get_key_sec");
865         depth++;
866
867         if(!prs_align(ps))
868                 return False;
869         
870         if(!smb_io_pol_hnd("", &r_q->pol, ps, depth))
871                 return False;
872
873         if(!prs_uint32("sec_info", ps, depth, &r_q->sec_info))
874                 return False;
875         if(!prs_uint32("ptr     ", ps, depth, &r_q->ptr))
876                 return False;
877
878         if(!reg_io_hdrbuf_sec(r_q->ptr, NULL, &r_q->hdr_sec, r_q->data, ps, depth))
879                 return False;
880
881         return True;
882 }
883
884 #if 0
885 /*******************************************************************
886 makes a structure.
887 ********************************************************************/
888  void init_reg_r_get_key_sec(REG_R_GET_KEY_SEC *r_i, POLICY_HND *pol, 
889                                 uint32 buf_len, uint8 *buf,
890                                 NTSTATUS status)
891 {
892         r_i->ptr = 1;
893         init_buf_hdr(&r_i->hdr_sec, buf_len, buf_len);
894         init_sec_desc_buf(r_i->data, buf_len, 1);
895
896         r_i->status = status; /* 0x0000 0000 or 0x0000 007a */
897 }
898 #endif 
899
900 /*******************************************************************
901 reads or writes a structure.
902 ********************************************************************/
903
904 BOOL reg_io_r_get_key_sec(char *desc,  REG_R_GET_KEY_SEC *r_q, prs_struct *ps, int depth)
905 {
906         if (r_q == NULL)
907                 return False;
908
909         prs_debug(ps, depth, desc, "reg_io_r_get_key_sec");
910         depth++;
911
912         if(!prs_align(ps))
913                 return False;
914         
915         if(!prs_uint32("ptr      ", ps, depth, &r_q->ptr))
916                 return False;
917
918         if (r_q->ptr != 0) {
919                 if(!smb_io_hdrbuf("", &r_q->hdr_sec, ps, depth))
920                         return False;
921                 if(!sec_io_desc_buf("", &r_q->data, ps, depth))
922                         return False;
923                 if(!prs_align(ps))
924                         return False;
925         }
926
927         if(!prs_ntstatus("status", ps, depth, &r_q->status))
928                 return False;
929
930         return True;
931 }
932
933 /*******************************************************************
934 makes a structure.
935 ********************************************************************/
936
937 BOOL init_reg_q_info(REG_Q_INFO *q_i, POLICY_HND *pol, char* val_name)
938 {
939         int len_type = val_name != NULL ? strlen(val_name) + 1 : 0;
940
941         if (q_i == NULL)
942                 return False;
943
944         q_i->pol = *pol;
945
946         init_uni_hdr(&(q_i->hdr_type), len_type);
947         init_unistr2(&(q_i->uni_type), val_name, len_type);
948
949         q_i->ptr_reserved = 1;
950         q_i->ptr_buf = 1;
951
952         q_i->ptr_bufsize = 1;
953         q_i->bufsize = 0;
954         q_i->buf_unk = 0;
955
956         q_i->unk1 = 0;
957         q_i->ptr_buflen = 1;
958         q_i->buflen = 0;
959
960         q_i->ptr_buflen2 = 1;
961         q_i->buflen2 = 0;
962
963         return True;
964 }
965
966 /*******************************************************************
967 reads or writes a structure.
968 ********************************************************************/
969
970 BOOL reg_io_q_info(char *desc,  REG_Q_INFO *r_q, prs_struct *ps, int depth)
971 {
972         if (r_q == NULL)
973                 return False;
974
975         prs_debug(ps, depth, desc, "reg_io_q_info");
976         depth++;
977
978         if(!prs_align(ps))
979                 return False;
980         
981         if(!smb_io_pol_hnd("", &r_q->pol, ps, depth))
982                 return False;
983         if(!smb_io_unihdr ("", &r_q->hdr_type, ps, depth))
984                 return False;
985         if(!smb_io_unistr2("", &r_q->uni_type, r_q->hdr_type.buffer, ps, depth))
986                 return False;
987
988         if(!prs_align(ps))
989                 return False;
990         
991         if(!prs_uint32("ptr_reserved", ps, depth, &(r_q->ptr_reserved)))
992                 return False;
993
994         if(!prs_uint32("ptr_buf", ps, depth, &(r_q->ptr_buf)))
995                 return False;
996
997         if(r_q->ptr_buf) {
998                 if(!prs_uint32("ptr_bufsize", ps, depth, &(r_q->ptr_bufsize)))
999                         return False;
1000                 if(!prs_uint32("bufsize", ps, depth, &(r_q->bufsize)))
1001                         return False;
1002                 if(!prs_uint32("buf_unk", ps, depth, &(r_q->buf_unk)))
1003                         return False;
1004         }
1005
1006         if(!prs_uint32("unk1", ps, depth, &(r_q->unk1)))
1007                 return False;
1008
1009         if(!prs_uint32("ptr_buflen", ps, depth, &(r_q->ptr_buflen)))
1010                 return False;
1011         if(!prs_uint32("buflen", ps, depth, &(r_q->buflen)))
1012                 return False;
1013
1014         if(!prs_uint32("ptr_buflen2", ps, depth, &(r_q->ptr_buflen2)))
1015                 return False;
1016         if(!prs_uint32("buflen2", ps, depth, &(r_q->buflen2)))
1017                 return False;
1018
1019         return True;
1020 }
1021
1022 /*******************************************************************
1023  Inits a structure.
1024 ********************************************************************/
1025
1026 BOOL init_reg_r_info(uint32 include_keyval, REG_R_INFO *r_r,
1027                      BUFFER2* buf, uint32 type, NTSTATUS status)
1028 {
1029   if(r_r == NULL)
1030     return False;
1031
1032   
1033   r_r->ptr_type = 1;
1034   r_r->type = type;
1035
1036   /* if include_keyval is not set, don't send the key value, just
1037      the buflen data. probably used by NT5 to allocate buffer space - SK */
1038   r_r->ptr_uni_val = include_keyval ? 1:0;
1039   r_r->uni_val = buf;
1040
1041   r_r->ptr_max_len = 1;
1042   r_r->buf_max_len = r_r->uni_val->buf_max_len;
1043
1044   r_r->ptr_len = 1;
1045   r_r->buf_len = r_r->uni_val->buf_len;
1046
1047   r_r->status = status;
1048
1049   return True;
1050   
1051 }
1052
1053 /*******************************************************************
1054 reads or writes a structure.
1055 ********************************************************************/
1056
1057 BOOL reg_io_r_info(char *desc, REG_R_INFO *r_r, prs_struct *ps, int depth)
1058 {
1059         if (r_r == NULL)
1060                 return False;
1061
1062         prs_debug(ps, depth, desc, "reg_io_r_info");
1063         depth++;
1064
1065         if(!prs_align(ps))
1066                 return False;
1067         
1068         if(!prs_uint32("ptr_type", ps, depth, &(r_r->ptr_type)))
1069                 return False;
1070
1071         if (r_r->ptr_type != 0) {
1072                 if(!prs_uint32("type", ps, depth, &r_r->type))
1073                         return False;
1074         }
1075
1076         if(!prs_uint32("ptr_uni_val", ps, depth, &(r_r->ptr_uni_val)))
1077                 return False;
1078
1079         if(r_r->ptr_uni_val != 0) {
1080                 if(!smb_io_buffer2("uni_val", r_r->uni_val, r_r->ptr_uni_val, ps, depth))
1081                         return False;
1082         }
1083
1084         if(!prs_align(ps))
1085                 return False;
1086
1087         if(!prs_uint32("ptr_max_len", ps, depth, &(r_r->ptr_max_len)))
1088                 return False;
1089
1090         if (r_r->ptr_max_len != 0) {
1091                 if(!prs_uint32("buf_max_len", ps, depth, &(r_r->buf_max_len)))
1092                 return False;
1093         }
1094
1095         if(!prs_uint32("ptr_len", ps, depth, &(r_r->ptr_len)))
1096                 return False;
1097         if (r_r->ptr_len != 0) {
1098                 if(!prs_uint32("buf_len", ps, depth, &(r_r->buf_len)))
1099                         return False;
1100         }
1101
1102         if(!prs_ntstatus("status", ps, depth, &r_r->status))
1103                 return False;
1104
1105         return True;
1106 }
1107
1108 /*******************************************************************
1109 makes a structure.
1110 ********************************************************************/
1111
1112 void init_reg_q_enum_val(REG_Q_ENUM_VALUE *q_i, POLICY_HND *pol,
1113                                 uint32 val_idx, uint32 max_val_len,
1114                                 uint32 max_buf_len)
1115 {
1116         ZERO_STRUCTP(q_i);
1117
1118         memcpy(&q_i->pol, pol, sizeof(q_i->pol));
1119
1120         q_i->val_index = val_idx;
1121         init_uni_hdr(&q_i->hdr_name, max_val_len);
1122         q_i->uni_name.uni_max_len = max_val_len;
1123         
1124         q_i->ptr_type = 1;
1125         q_i->type = 0x0;
1126
1127         q_i->ptr_value = 1;
1128         q_i->buf_value.buf_max_len = max_buf_len;
1129
1130         q_i->ptr1 = 1;
1131         q_i->len_value1 = max_buf_len;
1132
1133         q_i->ptr2 = 1;
1134         q_i->len_value2 = 0;
1135 }
1136
1137 /*******************************************************************
1138 reads or writes a structure.
1139 ********************************************************************/
1140
1141 BOOL reg_io_q_enum_val(char *desc,  REG_Q_ENUM_VALUE *q_q, prs_struct *ps, int depth)
1142 {
1143         if (q_q == NULL)
1144                 return False;
1145
1146         prs_debug(ps, depth, desc, "reg_io_q_enum_val");
1147         depth++;
1148
1149         if(!prs_align(ps))
1150                 return False;
1151         
1152         if(!smb_io_pol_hnd("", &q_q->pol, ps, depth))
1153                 return False;
1154         
1155         if(!prs_uint32("val_index", ps, depth, &q_q->val_index))
1156                 return False;
1157         if(!smb_io_unihdr ("hdr_name", &q_q->hdr_name, ps, depth))
1158                 return False;
1159         if(!smb_io_unistr2("uni_name", &q_q->uni_name, q_q->hdr_name.buffer, ps, depth))
1160                 return False;
1161         if(!prs_align(ps))
1162                 return False;
1163
1164         if(!prs_uint32("ptr_type", ps, depth, &q_q->ptr_type))
1165                 return False;
1166
1167         if (q_q->ptr_type != 0) {
1168                 if(!prs_uint32("type", ps, depth, &q_q->type))
1169                         return False;
1170         }
1171
1172         if(!prs_uint32("ptr_value", ps, depth, &q_q->ptr_value))
1173                 return False;
1174         if(!smb_io_buffer2("buf_value", &q_q->buf_value, q_q->ptr_value, ps, depth))
1175                 return False;
1176         if(!prs_align(ps))
1177                 return False;
1178
1179         if(!prs_uint32("ptr1", ps, depth, &q_q->ptr1))
1180                 return False;
1181         if (q_q->ptr1 != 0) {
1182                 if(!prs_uint32("len_value1", ps, depth, &q_q->len_value1))
1183                         return False;
1184         }
1185         if(!prs_uint32("ptr2", ps, depth, &q_q->ptr2))
1186                 return False;
1187         if (q_q->ptr2 != 0) {
1188                 if(!prs_uint32("len_value2", ps, depth, &q_q->len_value2))
1189                         return False;
1190         }
1191
1192         return True;
1193 }
1194
1195 /*******************************************************************
1196 reads or writes a structure.
1197 ********************************************************************/
1198
1199 BOOL reg_io_r_enum_val(char *desc,  REG_R_ENUM_VALUE *r_q, prs_struct *ps, int depth)
1200 {
1201         if (r_q == NULL)
1202                 return False;
1203
1204         prs_debug(ps, depth, desc, "reg_io_r_enum_val");
1205         depth++;
1206
1207         if(!prs_align(ps))
1208                 return False;
1209         
1210         if(!smb_io_unihdr ("hdr_name", &r_q->hdr_name, ps, depth))
1211                 return False;
1212         if(!smb_io_unistr2("uni_name", &r_q->uni_name, r_q->hdr_name.buffer, ps, depth))
1213                 return False;
1214         if(!prs_align(ps))
1215                 return False;
1216
1217         if(!prs_uint32("ptr_type", ps, depth, &r_q->ptr_type))
1218                 return False;
1219
1220         if (r_q->ptr_type != 0) {
1221                 if(!prs_uint32("type", ps, depth, &r_q->type))
1222                         return False;
1223         }
1224
1225         if(!prs_uint32("ptr_value", ps, depth, &r_q->ptr_value))
1226                 return False;
1227         if(!smb_io_buffer2("buf_value", r_q->buf_value, r_q->ptr_value, ps, depth))
1228                 return False;
1229         if(!prs_align(ps))
1230                 return False;
1231
1232         if(!prs_uint32("ptr1", ps, depth, &r_q->ptr1))
1233                 return False;
1234         if (r_q->ptr1 != 0) {
1235                 if(!prs_uint32("len_value1", ps, depth, &r_q->len_value1))
1236                         return False;
1237         }
1238
1239         if(!prs_uint32("ptr2", ps, depth, &r_q->ptr2))
1240                 return False;
1241         if (r_q->ptr2 != 0) {
1242                 if(!prs_uint32("len_value2", ps, depth, &r_q->len_value2))
1243                         return False;
1244         }
1245
1246         if(!prs_ntstatus("status", ps, depth, &r_q->status))
1247                 return False;
1248
1249         return True;
1250 }
1251
1252 /*******************************************************************
1253 makes a structure.
1254 ********************************************************************/
1255
1256 void init_reg_q_create_val(REG_Q_CREATE_VALUE *q_i, POLICY_HND *pol,
1257                                 char *val_name, uint32 type,
1258                                 BUFFER3 *val)
1259 {
1260         int val_len = strlen(val_name) + 1;
1261
1262         ZERO_STRUCTP(q_i);
1263
1264         memcpy(&q_i->pol, pol, sizeof(q_i->pol));
1265
1266         init_uni_hdr(&q_i->hdr_name, val_len);
1267         init_unistr2(&q_i->uni_name, val_name, val_len);
1268         
1269         q_i->type      = type;
1270         q_i->buf_value = val;
1271 }
1272
1273 /*******************************************************************
1274 reads or writes a structure.
1275 ********************************************************************/
1276
1277 BOOL reg_io_q_create_val(char *desc,  REG_Q_CREATE_VALUE *q_q, prs_struct *ps, int depth)
1278 {
1279         if (q_q == NULL)
1280                 return False;
1281
1282         prs_debug(ps, depth, desc, "reg_io_q_create_val");
1283         depth++;
1284
1285         if(!prs_align(ps))
1286                 return False;
1287         
1288         if(!smb_io_pol_hnd("", &q_q->pol, ps, depth))
1289                 return False;
1290         
1291         if(!smb_io_unihdr ("hdr_name", &q_q->hdr_name, ps, depth))
1292                 return False;
1293         if(!smb_io_unistr2("uni_name", &q_q->uni_name, q_q->hdr_name.buffer, ps, depth))
1294                 return False;
1295         if(!prs_align(ps))
1296                 return False;
1297
1298         if(!prs_uint32("type", ps, depth, &q_q->type))
1299                 return False;
1300         if(!smb_io_buffer3("buf_value", q_q->buf_value, ps, depth))
1301                 return False;
1302         if(!prs_align(ps))
1303                 return False;
1304
1305         return True;
1306 }
1307
1308 /*******************************************************************
1309 reads or writes a structure.
1310 ********************************************************************/
1311
1312 BOOL reg_io_r_create_val(char *desc,  REG_R_CREATE_VALUE *r_q, prs_struct *ps, int depth)
1313 {
1314         if (r_q == NULL)
1315                 return False;
1316
1317         prs_debug(ps, depth, desc, "reg_io_r_create_val");
1318         depth++;
1319
1320         if(!prs_align(ps))
1321                 return False;
1322         
1323         if(!prs_ntstatus("status", ps, depth, &r_q->status))
1324                 return False;
1325
1326         return True;
1327 }
1328
1329 /*******************************************************************
1330 makes a structure.
1331 ********************************************************************/
1332
1333 void init_reg_q_enum_key(REG_Q_ENUM_KEY *q_i, POLICY_HND *pol, uint32 key_idx)
1334 {
1335         memcpy(&q_i->pol, pol, sizeof(q_i->pol));
1336
1337         q_i->key_index = key_idx;
1338         q_i->key_name_len = 0;
1339         q_i->unknown_1 = 0x0414;
1340
1341         q_i->ptr1 = 1;
1342         q_i->unknown_2 = 0x0000020A;
1343         memset(q_i->pad1, 0, sizeof(q_i->pad1));
1344
1345         q_i->ptr2 = 1;
1346         memset(q_i->pad2, 0, sizeof(q_i->pad2));
1347
1348         q_i->ptr3 = 1;
1349         unix_to_nt_time(&q_i->time, 0);            /* current time? */
1350 }
1351
1352 /*******************************************************************
1353 reads or writes a structure.
1354 ********************************************************************/
1355
1356 BOOL reg_io_q_enum_key(char *desc,  REG_Q_ENUM_KEY *q_q, prs_struct *ps, int depth)
1357 {
1358         if (q_q == NULL)
1359                 return False;
1360
1361         prs_debug(ps, depth, desc, "reg_io_q_enum_key");
1362         depth++;
1363
1364         if(!prs_align(ps))
1365                 return False;
1366         
1367         if(!smb_io_pol_hnd("", &q_q->pol, ps, depth))
1368                 return False;
1369         
1370         if(!prs_uint32("key_index", ps, depth, &q_q->key_index))
1371                 return False;
1372         if(!prs_uint16("key_name_len", ps, depth, &q_q->key_name_len))
1373                 return False;
1374         if(!prs_uint16("unknown_1", ps, depth, &q_q->unknown_1))
1375                 return False;
1376
1377         if(!prs_uint32("ptr1", ps, depth, &q_q->ptr1))
1378                 return False;
1379
1380         if (q_q->ptr1 != 0) {
1381                 if(!prs_uint32("unknown_2", ps, depth, &q_q->unknown_2))
1382                         return False;
1383                 if(!prs_uint8s(False, "pad1", ps, depth, q_q->pad1, sizeof(q_q->pad1)))
1384                         return False;
1385         }
1386
1387         if(!prs_uint32("ptr2", ps, depth, &q_q->ptr2))
1388                 return False;
1389
1390         if (q_q->ptr2 != 0) {
1391                 if(!prs_uint8s(False, "pad2", ps, depth, q_q->pad2, sizeof(q_q->pad2)))
1392                         return False;
1393         }
1394
1395         if(!prs_uint32("ptr3", ps, depth, &q_q->ptr3))
1396                 return False;
1397
1398         if (q_q->ptr3 != 0) {
1399                 if(!smb_io_time("", &q_q->time, ps, depth))
1400                         return False;
1401         }
1402
1403         return True;
1404 }
1405
1406 /*******************************************************************
1407 reads or writes a structure.
1408 ********************************************************************/
1409
1410 BOOL reg_io_r_enum_key(char *desc,  REG_R_ENUM_KEY *r_q, prs_struct *ps, int depth)
1411 {
1412         if (r_q == NULL)
1413                 return False;
1414
1415         prs_debug(ps, depth, desc, "reg_io_r_enum_key");
1416         depth++;
1417
1418         if(!prs_align(ps))
1419                 return False;
1420         
1421         if(!prs_uint16("key_name_len", ps, depth, &r_q->key_name_len))
1422                 return False;
1423         if(!prs_uint16("unknown_1", ps, depth, &r_q->unknown_1))
1424                 return False;
1425
1426         if(!prs_uint32("ptr1", ps, depth, &r_q->ptr1))
1427                 return False;
1428
1429         if (r_q->ptr1 != 0) {
1430                 if(!prs_uint32("unknown_2", ps, depth, &r_q->unknown_2))
1431                         return False;
1432                 if(!prs_uint32("unknown_3", ps, depth, &r_q->unknown_3))
1433                         return False;
1434                 if(!smb_io_unistr3("key_name", &r_q->key_name, ps, depth))
1435                         return False;
1436                 if(!prs_align(ps))
1437                         return False;
1438         }
1439
1440         if(!prs_uint32("ptr2", ps, depth, &r_q->ptr2))
1441                 return False;
1442
1443         if (r_q->ptr2 != 0) {
1444                 if(!prs_uint8s(False, "pad2", ps, depth, r_q->pad2, sizeof(r_q->pad2)))
1445                         return False;
1446         }
1447
1448         if(!prs_uint32("ptr3", ps, depth, &r_q->ptr3))
1449                 return False;
1450
1451         if (r_q->ptr3 != 0) {
1452                 if(!smb_io_time("", &r_q->time, ps, depth))
1453                         return False;
1454         }
1455
1456         if(!prs_ntstatus("status", ps, depth, &r_q->status))
1457                 return False;
1458
1459         return True;
1460 }
1461
1462 /*******************************************************************
1463 makes a structure.
1464 ********************************************************************/
1465
1466 void init_reg_q_open_entry(REG_Q_OPEN_ENTRY *r_q, POLICY_HND *pol,
1467                                 char *key_name, uint32 unk)
1468 {
1469         int len_name = strlen(key_name)+1;
1470
1471         memcpy(&r_q->pol, pol, sizeof(r_q->pol));
1472
1473         init_uni_hdr(&r_q->hdr_name, len_name);
1474         init_unistr2(&r_q->uni_name, key_name, len_name);
1475
1476         r_q->unknown_0 = 0x00000000;
1477         r_q->unknown_1 = unk;
1478 }
1479
1480 /*******************************************************************
1481 reads or writes a structure.
1482 ********************************************************************/
1483
1484 BOOL reg_io_q_open_entry(char *desc,  REG_Q_OPEN_ENTRY *r_q, prs_struct *ps, int depth)
1485 {
1486         if (r_q == NULL)
1487                 return False;
1488
1489         prs_debug(ps, depth, desc, "reg_io_q_entry");
1490         depth++;
1491
1492         if(!prs_align(ps))
1493                 return False;
1494         
1495         if(!smb_io_pol_hnd("", &r_q->pol, ps, depth))
1496                 return False;
1497         if(!smb_io_unihdr ("", &r_q->hdr_name, ps, depth))
1498                 return False;
1499         if(!smb_io_unistr2("", &r_q->uni_name, r_q->hdr_name.buffer, ps, depth))
1500                 return False;
1501
1502         if(!prs_align(ps))
1503                 return False;
1504         
1505         if(!prs_uint32("unknown_0", ps, depth, &r_q->unknown_0))
1506                 return False;
1507         if(!prs_uint32("unknown_1", ps, depth, &r_q->unknown_1))
1508                 return False;
1509
1510         return True;
1511 }
1512
1513 /*******************************************************************
1514  Inits a structure.
1515 ********************************************************************/
1516
1517 void init_reg_r_open_entry(REG_R_OPEN_ENTRY *r_r,
1518                            POLICY_HND *pol, NTSTATUS status)
1519 {
1520         memcpy(&r_r->pol, pol, sizeof(r_r->pol));
1521         r_r->status = status;
1522 }
1523
1524 /*******************************************************************
1525 reads or writes a structure.
1526 ********************************************************************/
1527
1528 BOOL reg_io_r_open_entry(char *desc,  REG_R_OPEN_ENTRY *r_r, prs_struct *ps, int depth)
1529 {
1530         if (r_r == NULL)
1531                 return False;
1532
1533         prs_debug(ps, depth, desc, "reg_io_r_open_entry");
1534         depth++;
1535
1536         if(!prs_align(ps))
1537                 return False;
1538         
1539         if(!smb_io_pol_hnd("", &r_r->pol, ps, depth))
1540                 return False;
1541
1542         if(!prs_ntstatus("status", ps, depth, &r_r->status))
1543                 return False;
1544
1545         return True;
1546 }
1547
1548 /*******************************************************************
1549 Inits a structure.
1550 ********************************************************************/
1551 void init_reg_q_shutdown(REG_Q_SHUTDOWN * q_s,
1552                          const char *msg, uint32 timeout, uint16 flags)
1553 {
1554         int msg_len;
1555         msg_len = strlen(msg);
1556
1557         q_s->ptr_0 = 1;
1558         q_s->ptr_1 = 1;
1559         q_s->ptr_2 = 1;
1560
1561         init_uni_hdr(&(q_s->hdr_msg), msg_len);
1562         init_unistr2(&(q_s->uni_msg), msg, msg_len);
1563
1564         q_s->timeout = timeout;
1565         q_s->flags = flags;
1566
1567 }
1568
1569 /*******************************************************************
1570 reads or writes a structure.
1571 ********************************************************************/
1572 BOOL reg_io_q_shutdown(char *desc, REG_Q_SHUTDOWN * q_s, prs_struct *ps,
1573                        int depth)
1574 {
1575         if (q_s == NULL)
1576                 return False;
1577
1578         prs_debug(ps, depth, desc, "reg_io_q_shutdown");
1579         depth++;
1580
1581         if (!prs_align(ps))
1582                 return False;
1583
1584         if (!prs_uint32("ptr_0", ps, depth, &(q_s->ptr_0)))
1585                 return False;
1586         if (!prs_uint32("ptr_1", ps, depth, &(q_s->ptr_1)))
1587                 return False;
1588         if (!prs_uint32("ptr_2", ps, depth, &(q_s->ptr_2)))
1589                 return False;
1590
1591         if (!smb_io_unihdr("hdr_msg", &(q_s->hdr_msg), ps, depth))
1592                 return False;
1593         if (!smb_io_unistr2("uni_msg", &(q_s->uni_msg), q_s->hdr_msg.buffer, ps, depth))
1594                 return False;
1595         if (!prs_align(ps))
1596                 return False;
1597
1598         if (!prs_uint32("timeout", ps, depth, &(q_s->timeout)))
1599                 return False;
1600         if (!prs_uint16("flags  ", ps, depth, &(q_s->flags)))
1601                 return False;
1602
1603         return True;
1604 }
1605
1606 /*******************************************************************
1607 reads or writes a structure.
1608 ********************************************************************/
1609 BOOL reg_io_r_shutdown(char *desc, REG_R_SHUTDOWN * r_s, prs_struct *ps,
1610                        int depth)
1611 {
1612         if (r_s == NULL)
1613                 return False;
1614
1615         prs_debug(ps, depth, desc, "reg_io_r_shutdown");
1616         depth++;
1617
1618         if(!prs_align(ps))
1619                 return False;
1620
1621         if(!prs_ntstatus("status", ps, depth, &(r_s->status)))
1622                 return False;
1623
1624         return True;
1625 }
1626
1627 /*******************************************************************
1628 Inits a structure.
1629 ********************************************************************/
1630 void init_reg_q_abort_shutdown(REG_Q_ABORT_SHUTDOWN * q_s)
1631 {
1632
1633         q_s->ptr_server = 0;
1634
1635 }
1636
1637 /*******************************************************************
1638 reads or writes a structure.
1639 ********************************************************************/
1640 BOOL reg_io_q_abort_shutdown(char *desc, REG_Q_ABORT_SHUTDOWN * q_s,
1641                              prs_struct *ps, int depth)
1642 {
1643         if (q_s == NULL)
1644                 return False;
1645
1646         prs_debug(ps, depth, desc, "reg_io_q_abort_shutdown");
1647         depth++;
1648
1649         if (!prs_align(ps))
1650                 return False;
1651
1652         if (!prs_uint32("ptr_server", ps, depth, &(q_s->ptr_server)))
1653                 return False;
1654         if (q_s->ptr_server != 0)
1655                 if (!prs_uint16("server", ps, depth, &(q_s->server)))
1656                         return False;
1657
1658         return True;
1659 }
1660
1661 /*******************************************************************
1662 reads or writes a structure.
1663 ********************************************************************/
1664 BOOL reg_io_r_abort_shutdown(char *desc, REG_R_ABORT_SHUTDOWN * r_s,
1665                              prs_struct *ps, int depth)
1666 {
1667         if (r_s == NULL)
1668                 return False;
1669
1670         prs_debug(ps, depth, desc, "reg_io_r_abort_shutdown");
1671         depth++;
1672
1673         if (!prs_align(ps))
1674                 return False;
1675
1676         if (!prs_ntstatus("status", ps, depth, &(r_s->status)))
1677                 return False;
1678
1679         return True;
1680 }