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