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