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