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