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