Initial import
[samba] / 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 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_ex(REG_Q_CREATE_KEY_EX *q_c, POLICY_HND *hnd,
210                            char *name, char *key_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->key_class, key_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->disposition = TALLOC_P( get_talloc_ctx(), uint32 );
231 }
232
233 /*******************************************************************
234 Marshalls a registry key create request
235 ********************************************************************/
236
237 BOOL reg_io_q_create_key_ex(const char *desc,  REG_Q_CREATE_KEY_EX *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_ex");
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 ("key_class", ps, depth, &q_u->key_class))
258                 return False;
259         if(!prs_align(ps))
260                 return False;
261
262         if(!prs_uint32("options", ps, depth, &q_u->options))
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 ( q_u->sec_info ) {
271                 if(!prs_uint32("ptr2", ps, depth, &q_u->ptr2))
272                         return False;
273                 if(!reg_io_hdrbuf_sec(q_u->ptr2, &q_u->ptr3, &q_u->hdr_sec, q_u->data, ps, depth))
274                         return False;
275         }
276
277         if(!prs_pointer("disposition", ps, depth, (void**)&q_u->disposition, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
278                 return False;
279
280         return True;
281 }
282
283 /*******************************************************************
284 Unmarshalls a registry key create response
285 ********************************************************************/
286
287 BOOL reg_io_r_create_key_ex(const char *desc,  REG_R_CREATE_KEY_EX *r_u,
288                          prs_struct *ps, int depth)
289 {
290         if ( !r_u )
291                 return False;
292
293         prs_debug(ps, depth, desc, "reg_io_r_create_key_ex");
294         depth++;
295
296         if(!prs_align(ps))
297                 return False;
298         
299         if(!smb_io_pol_hnd("", &r_u->handle, ps, depth))
300                 return False;
301         if(!prs_uint32("disposition", ps, depth, &r_u->disposition))
302                 return False;
303
304         if(!prs_werror("status", ps, depth, &r_u->status))
305                 return False;
306
307         return True;
308 }
309
310
311 /*******************************************************************
312  Inits a structure.
313 ********************************************************************/
314
315 void init_reg_q_delete_val(REG_Q_DELETE_VALUE *q_c, POLICY_HND *hnd,
316                            char *name)
317 {
318         ZERO_STRUCTP(q_c);
319
320         memcpy(&q_c->handle, hnd, sizeof(q_c->handle));
321         init_unistr4(&q_c->name, name, UNI_STR_TERMINATE);
322 }
323
324 /*******************************************************************
325 reads or writes a structure.
326 ********************************************************************/
327
328 BOOL reg_io_q_delete_value(const char *desc, REG_Q_DELETE_VALUE *q_u,
329                          prs_struct *ps, int depth)
330 {
331         if ( !q_u )
332                 return False;
333
334         prs_debug(ps, depth, desc, "reg_io_q_delete_value");
335         depth++;
336
337         if(!prs_align(ps))
338                 return False;
339         
340         if(!smb_io_pol_hnd("", &q_u->handle, ps, depth))
341                 return False;
342
343         if(!prs_unistr4("name", ps, depth, &q_u->name))
344                 return False;
345
346         return True;
347 }
348
349
350 /*******************************************************************
351 reads or writes a structure.
352 ********************************************************************/
353
354 BOOL reg_io_r_delete_value(const char *desc,  REG_R_DELETE_VALUE *r_u,
355                          prs_struct *ps, int depth)
356 {
357         if ( !r_u )
358                 return False;
359
360         prs_debug(ps, depth, desc, "reg_io_r_delete_value");
361         depth++;
362
363         if(!prs_align(ps))
364                 return False;
365         
366         if(!prs_werror("status", ps, depth, &r_u->status))
367                 return False;
368
369         return True;
370 }
371
372 /*******************************************************************
373  Inits a structure.
374 ********************************************************************/
375
376 void init_reg_q_delete_key(REG_Q_DELETE_KEY *q_c, POLICY_HND *hnd,
377                            char *name)
378 {
379         ZERO_STRUCTP(q_c);
380
381         memcpy(&q_c->handle, hnd, sizeof(q_c->handle));
382
383         init_unistr4(&q_c->name, name, UNI_STR_TERMINATE);
384 }
385
386 /*******************************************************************
387 reads or writes a structure.
388 ********************************************************************/
389
390 BOOL reg_io_q_delete_key(const char *desc,  REG_Q_DELETE_KEY *q_u,
391                          prs_struct *ps, int depth)
392 {
393         if ( !q_u )
394                 return False;
395
396         prs_debug(ps, depth, desc, "reg_io_q_delete_key");
397         depth++;
398
399         if(!prs_align(ps))
400                 return False;
401         
402         if(!smb_io_pol_hnd("", &q_u->handle, ps, depth))
403                 return False;
404
405         if(!prs_unistr4("", ps, depth, &q_u->name))
406                 return False;
407
408         return True;
409 }
410
411 /*******************************************************************
412 reads or writes a structure.
413 ********************************************************************/
414
415 BOOL reg_io_r_delete_key(const char *desc,  REG_R_DELETE_KEY *r_u, prs_struct *ps, int depth)
416 {
417         if ( !r_u )
418                 return False;
419
420         prs_debug(ps, depth, desc, "reg_io_r_delete_key");
421         depth++;
422
423         if(!prs_align(ps))
424                 return False;
425         
426         if(!prs_werror("status", ps, depth, &r_u->status))
427                 return False;
428
429         return True;
430 }
431
432 /*******************************************************************
433  Inits a structure.
434 ********************************************************************/
435
436 void init_reg_q_query_key(REG_Q_QUERY_KEY *q_o, POLICY_HND *hnd, const char *key_class)
437 {
438         ZERO_STRUCTP(q_o);
439
440         memcpy(&q_o->pol, hnd, sizeof(q_o->pol));
441         init_unistr4(&q_o->key_class, key_class, UNI_STR_TERMINATE);
442 }
443
444 /*******************************************************************
445 reads or writes a structure.
446 ********************************************************************/
447
448 BOOL reg_io_q_query_key(const char *desc,  REG_Q_QUERY_KEY *q_u, prs_struct *ps, int depth)
449 {
450         if ( !q_u )
451                 return False;
452
453         prs_debug(ps, depth, desc, "reg_io_q_query_key");
454         depth++;
455
456         if(!prs_align(ps))
457                 return False;
458         
459         if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
460                 return False;
461         if(!prs_unistr4("key_class", ps, depth, &q_u->key_class))
462                 return False;
463
464         return True;
465 }
466
467
468 /*******************************************************************
469 reads or writes a structure.
470 ********************************************************************/
471
472 BOOL reg_io_r_query_key(const char *desc,  REG_R_QUERY_KEY *r_u, prs_struct *ps, int depth)
473 {
474         if ( !r_u )
475                 return False;
476
477         prs_debug(ps, depth, desc, "reg_io_r_query_key");
478         depth++;
479
480         if(!prs_align(ps))
481                 return False;
482         
483         if(!prs_unistr4("key_class", ps, depth, &r_u->key_class))
484                 return False;
485
486         if(!prs_align(ps))
487                 return False;
488
489         if(!prs_uint32("num_subkeys   ", ps, depth, &r_u->num_subkeys))
490                 return False;
491         if(!prs_uint32("max_subkeylen ", ps, depth, &r_u->max_subkeylen))
492                 return False;
493         if(!prs_uint32("reserved      ", ps, depth, &r_u->reserved))
494                 return False;
495         if(!prs_uint32("num_values    ", ps, depth, &r_u->num_values))
496                 return False;
497         if(!prs_uint32("max_valnamelen", ps, depth, &r_u->max_valnamelen))
498                 return False;
499         if(!prs_uint32("max_valbufsize", ps, depth, &r_u->max_valbufsize))
500                 return False;
501         if(!prs_uint32("sec_desc      ", ps, depth, &r_u->sec_desc))
502                 return False;
503         if(!smb_io_time("mod_time     ", &r_u->mod_time, ps, depth))
504                 return False;
505
506         if(!prs_werror("status", ps, depth, &r_u->status))
507                 return False;
508
509         return True;
510 }
511
512 /*******************************************************************
513  Inits a structure.
514 ********************************************************************/
515
516 void init_reg_q_getversion(REG_Q_GETVERSION *q_o, POLICY_HND *hnd)
517 {
518         memcpy(&q_o->pol, hnd, sizeof(q_o->pol));
519 }
520
521
522 /*******************************************************************
523 reads or writes a structure.
524 ********************************************************************/
525
526 BOOL reg_io_q_getversion(const char *desc,  REG_Q_GETVERSION *q_u, prs_struct *ps, int depth)
527 {
528         if ( !q_u )
529                 return False;
530
531         prs_debug(ps, depth, desc, "reg_io_q_getversion");
532         depth++;
533
534         if(!prs_align(ps))
535                 return False;
536
537         if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
538                 return False;
539
540         return True;
541 }
542
543 /*******************************************************************
544 reads or writes a structure.
545 ********************************************************************/
546
547 BOOL reg_io_r_getversion(const char *desc,  REG_R_GETVERSION *r_u, prs_struct *ps, int depth)
548 {
549         if ( !r_u )
550                 return False;
551
552         prs_debug(ps, depth, desc, "reg_io_r_getversion");
553         depth++;
554
555         if(!prs_align(ps))
556                 return False;
557
558         if(!prs_uint32("win_version", ps, depth, &r_u->win_version))
559                 return False;
560         if(!prs_werror("status" , ps, depth, &r_u->status))
561                 return False;
562
563         return True;
564 }
565
566
567 /*******************************************************************
568 reads or writes a structure.
569 ********************************************************************/
570
571 BOOL reg_io_q_restore_key(const char *desc,  REG_Q_RESTORE_KEY *q_u, prs_struct *ps, int depth)
572 {
573         if ( !q_u )
574                 return False;
575
576         prs_debug(ps, depth, desc, "reg_io_q_restore_key");
577         depth++;
578
579         if(!prs_align(ps))
580                 return False;
581
582         if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
583                 return False;
584
585         if(!prs_unistr4("filename", ps, depth, &q_u->filename))
586                 return False;
587
588         if(!prs_uint32("flags", ps, depth, &q_u->flags))
589                 return False;
590
591         return True;
592 }
593
594 /*******************************************************************
595 reads or writes a structure.
596 ********************************************************************/
597
598 BOOL reg_io_r_restore_key(const char *desc,  REG_R_RESTORE_KEY *r_u, prs_struct *ps, int depth)
599 {
600         if ( !r_u )
601                 return False;
602
603         prs_debug(ps, depth, desc, "reg_io_r_restore_key");
604         depth++;
605
606         if(!prs_align(ps))
607                 return False;
608         
609         if(!prs_werror("status" , ps, depth, &r_u->status))
610                 return False;
611
612         return True;
613 }
614
615 /*******************************************************************
616 ********************************************************************/
617
618 void init_q_reg_save_key( REG_Q_SAVE_KEY *q_u, POLICY_HND *handle, const char *fname )
619 {
620         memcpy(&q_u->pol, handle, sizeof(q_u->pol));
621         init_unistr4( &q_u->filename, fname, UNI_STR_TERMINATE );
622         q_u->sec_attr = NULL;
623 }
624
625 /*******************************************************************
626 reads or writes a structure.
627 ********************************************************************/
628
629 BOOL reg_io_q_save_key(const char *desc,  REG_Q_SAVE_KEY *q_u, prs_struct *ps, int depth)
630 {
631         if ( !q_u )
632                 return False;
633
634         prs_debug(ps, depth, desc, "reg_io_q_save_key");
635         depth++;
636
637         if(!prs_align(ps))
638                 return False;
639
640         if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
641                 return False;
642
643         if(!prs_unistr4("filename", ps, depth, &q_u->filename))
644                 return False;
645
646 #if 0   /* reg_io_sec_attr() */
647         if(!prs_uint32("unknown", ps, depth, &q_u->unknown))
648                 return False;
649 #endif
650
651         return True;
652 }
653
654 /*******************************************************************
655 reads or writes a structure.
656 ********************************************************************/
657
658 BOOL reg_io_r_save_key(const char *desc,  REG_R_SAVE_KEY *r_u, prs_struct *ps, int depth)
659 {
660         if ( !r_u )
661                 return False;
662
663         prs_debug(ps, depth, desc, "reg_io_r_save_key");
664         depth++;
665
666         if(!prs_align(ps))
667                 return False;
668         
669         if(!prs_werror("status" , ps, depth, &r_u->status))
670                 return False;
671
672         return True;
673 }
674
675 /*******************************************************************
676  Inits an REG_Q_CLOSE structure.
677 ********************************************************************/
678
679 void init_reg_q_close(REG_Q_CLOSE *q_c, POLICY_HND *hnd)
680 {
681         DEBUG(5,("init_reg_q_close\n"));
682
683         memcpy(&q_c->pol, hnd, sizeof(q_c->pol));
684 }
685
686 /*******************************************************************
687 reads or writes a structure.
688 ********************************************************************/
689
690 BOOL reg_io_q_close(const char *desc,  REG_Q_CLOSE *q_u, prs_struct *ps, int depth)
691 {
692         if (q_u == NULL)
693                 return False;
694
695         prs_debug(ps, depth, desc, "reg_io_q_close");
696         depth++;
697
698         if(!prs_align(ps))
699                 return False;
700
701         if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
702                 return False;
703         if(!prs_align(ps))
704                 return False;
705
706         return True;
707 }
708
709 /*******************************************************************
710 reads or writes a structure.
711 ********************************************************************/
712
713 BOOL reg_io_r_close(const char *desc,  REG_R_CLOSE *r_u, prs_struct *ps, int depth)
714 {
715         if ( !r_u )
716                 return False;
717
718         prs_debug(ps, depth, desc, "reg_io_r_close");
719         depth++;
720
721         if(!prs_align(ps))
722                 return False;
723
724         if(!smb_io_pol_hnd("", &r_u->pol, ps, depth))
725                 return False;
726         if(!prs_align(ps))
727                 return False;
728
729         if(!prs_werror("status", ps, depth, &r_u->status))
730                 return False;
731
732         return True;
733 }
734
735 /*******************************************************************
736 makes a structure.
737 ********************************************************************/
738
739 void init_reg_q_set_key_sec(REG_Q_SET_KEY_SEC *q_u, POLICY_HND *pol,
740                             uint32 sec_info, SEC_DESC_BUF *sec_desc_buf)
741 {
742         memcpy(&q_u->handle, pol, sizeof(q_u->handle));
743
744         q_u->sec_info = sec_info;
745
746         q_u->ptr = 1;
747         init_buf_hdr(&q_u->hdr_sec, sec_desc_buf->len, sec_desc_buf->len);
748         q_u->data = sec_desc_buf;
749 }
750
751 /*******************************************************************
752 reads or writes a structure.
753 ********************************************************************/
754
755 BOOL reg_io_q_set_key_sec(const char *desc,  REG_Q_SET_KEY_SEC *q_u, prs_struct *ps, int depth)
756 {
757         if ( !q_u )
758                 return False;
759
760         prs_debug(ps, depth, desc, "reg_io_q_set_key_sec");
761         depth++;
762
763         if(!prs_align(ps))
764                 return False;
765         
766         if(!smb_io_pol_hnd("", &q_u->handle, ps, depth))
767                 return False;
768
769         if(!prs_uint32("sec_info", ps, depth, &q_u->sec_info))
770                 return False;
771         if(!prs_uint32("ptr    ", ps, depth, &q_u->ptr))
772                 return False;
773
774         if(!reg_io_hdrbuf_sec(q_u->ptr, NULL, &q_u->hdr_sec, q_u->data, ps, depth))
775                 return False;
776
777         return True;
778 }
779
780 /*******************************************************************
781 reads or writes a structure.
782 ********************************************************************/
783
784 BOOL reg_io_r_set_key_sec(const char *desc, REG_R_SET_KEY_SEC *q_u, prs_struct *ps, int depth)
785 {
786         if ( !q_u )
787                 return False;
788
789         prs_debug(ps, depth, desc, "reg_io_r_set_key_sec");
790         depth++;
791
792         if(!prs_align(ps))
793                 return False;
794         
795         if(!prs_werror("status", ps, depth, &q_u->status))
796                 return False;
797
798         return True;
799 }
800
801
802 /*******************************************************************
803 makes a structure.
804 ********************************************************************/
805
806 void init_reg_q_get_key_sec(REG_Q_GET_KEY_SEC *q_u, POLICY_HND *pol, 
807                             uint32 sec_info, uint32 sec_buf_size,
808                             SEC_DESC_BUF *psdb)
809 {
810         memcpy(&q_u->handle, pol, sizeof(q_u->handle));
811
812         q_u->sec_info = sec_info;
813
814         q_u->ptr = psdb != NULL ? 1 : 0;
815         q_u->data = psdb;
816
817         init_buf_hdr(&q_u->hdr_sec, sec_buf_size, 0);
818 }
819
820 /*******************************************************************
821 reads or writes a structure.
822 ********************************************************************/
823
824 BOOL reg_io_q_get_key_sec(const char *desc,  REG_Q_GET_KEY_SEC *q_u, prs_struct *ps, int depth)
825 {
826         if ( !q_u )
827                 return False;
828
829         prs_debug(ps, depth, desc, "reg_io_q_get_key_sec");
830         depth++;
831
832         if(!prs_align(ps))
833                 return False;
834         
835         if(!smb_io_pol_hnd("", &q_u->handle, ps, depth))
836                 return False;
837
838         if(!prs_uint32("sec_info", ps, depth, &q_u->sec_info))
839                 return False;
840         if(!prs_uint32("ptr     ", ps, depth, &q_u->ptr))
841                 return False;
842
843         if(!reg_io_hdrbuf_sec(q_u->ptr, NULL, &q_u->hdr_sec, q_u->data, ps, depth))
844                 return False;
845
846         return True;
847 }
848
849 #if 0
850 /*******************************************************************
851 makes a structure.
852 ********************************************************************/
853  void init_reg_r_get_key_sec(REG_R_GET_KEY_SEC *r_i, POLICY_HND *pol, 
854                                 uint32 buf_len, uint8 *buf,
855                                 NTSTATUS status)
856 {
857         r_i->ptr = 1;
858         init_buf_hdr(&r_i->hdr_sec, buf_len, buf_len);
859         init_sec_desc_buf(r_i->data, buf_len, 1);
860
861         r_i->status = status; /* 0x0000 0000 or 0x0000 007a */
862 }
863 #endif 
864
865 /*******************************************************************
866 reads or writes a structure.
867 ********************************************************************/
868
869 BOOL reg_io_r_get_key_sec(const char *desc,  REG_R_GET_KEY_SEC *q_u, prs_struct *ps, int depth)
870 {
871         if ( !q_u )
872                 return False;
873
874         prs_debug(ps, depth, desc, "reg_io_r_get_key_sec");
875         depth++;
876
877         if(!prs_align(ps))
878                 return False;
879         
880         if(!prs_uint32("ptr      ", ps, depth, &q_u->ptr))
881                 return False;
882
883         if (q_u->ptr != 0) {
884                 if(!smb_io_hdrbuf("", &q_u->hdr_sec, ps, depth))
885                         return False;
886                 if(!sec_io_desc_buf("", &q_u->data, ps, depth))
887                         return False;
888                 if(!prs_align(ps))
889                         return False;
890         }
891
892         if(!prs_werror("status", ps, depth, &q_u->status))
893                 return False;
894
895         return True;
896 }
897
898 /*******************************************************************
899 makes a structure.
900 ********************************************************************/
901
902 BOOL init_reg_q_query_value(REG_Q_QUERY_VALUE *q_u, POLICY_HND *pol, const char *val_name,
903                      REGVAL_BUFFER *value_output)
904 {
905         if (q_u == NULL)
906                 return False;
907
908         q_u->pol = *pol;
909
910         init_unistr4(&q_u->name, val_name, UNI_STR_TERMINATE);
911
912         q_u->ptr_reserved = 1;
913         q_u->ptr_buf = 1;
914
915         q_u->ptr_bufsize = 1;
916         q_u->bufsize = value_output->buf_max_len;
917         q_u->buf_unk = 0;
918
919         q_u->unk1 = 0;
920         q_u->ptr_buflen = 1;
921         q_u->buflen = value_output->buf_max_len; 
922
923         q_u->ptr_buflen2 = 1;
924         q_u->buflen2 = 0;
925
926         return True;
927 }
928
929 /*******************************************************************
930 reads or writes a structure.
931 ********************************************************************/
932
933 BOOL reg_io_q_query_value(const char *desc,  REG_Q_QUERY_VALUE *q_u, prs_struct *ps, int depth)
934 {
935         if ( !q_u )
936                 return False;
937
938         prs_debug(ps, depth, desc, "reg_io_q_query_value");
939         depth++;
940
941         if(!prs_align(ps))
942                 return False;
943         
944         if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
945                 return False;
946         if(!prs_unistr4("name", ps, depth, &q_u->name))
947                 return False;
948
949         if(!prs_align(ps))
950                 return False;
951         
952         if(!prs_uint32("ptr_reserved", ps, depth, &(q_u->ptr_reserved)))
953                 return False;
954
955         if(!prs_uint32("ptr_buf", ps, depth, &(q_u->ptr_buf)))
956                 return False;
957
958         if(q_u->ptr_buf) {
959                 if(!prs_uint32("ptr_bufsize", ps, depth, &(q_u->ptr_bufsize)))
960                         return False;
961                 if(!prs_uint32("bufsize", ps, depth, &(q_u->bufsize)))
962                         return False;
963                 if(!prs_uint32("buf_unk", ps, depth, &(q_u->buf_unk)))
964                         return False;
965         }
966
967         if(!prs_uint32("unk1", ps, depth, &(q_u->unk1)))
968                 return False;
969
970         if(!prs_uint32("ptr_buflen", ps, depth, &(q_u->ptr_buflen)))
971                 return False;
972
973         if (q_u->ptr_buflen) {
974                 if(!prs_uint32("buflen", ps, depth, &(q_u->buflen)))
975                         return False;
976                 if(!prs_uint32("ptr_buflen2", ps, depth, &(q_u->ptr_buflen2)))
977                         return False;
978                 if(!prs_uint32("buflen2", ps, depth, &(q_u->buflen2)))
979                         return False;
980         }
981
982         return True;
983 }
984
985 /*******************************************************************
986  Inits a structure.
987  New version to replace older init_reg_r_query_value()
988 ********************************************************************/
989
990 BOOL init_reg_r_query_value(uint32 include_keyval, REG_R_QUERY_VALUE *r_u,
991                      REGISTRY_VALUE *val, WERROR status)
992 {
993         uint32                  buf_len = 0;
994         REGVAL_BUFFER           buf2;
995                 
996         if( !r_u || !val )
997                 return False;
998         
999         r_u->type = TALLOC_P( get_talloc_ctx(), uint32 );
1000         *r_u->type = val->type;
1001
1002         buf_len = reg_init_regval_buffer( &buf2, val );
1003         
1004         r_u->buf_max_len = TALLOC_P( get_talloc_ctx(), uint32 );
1005         *r_u->buf_max_len = buf_len;
1006
1007         r_u->buf_len = TALLOC_P( get_talloc_ctx(), uint32 );
1008         *r_u->buf_len = buf_len;
1009         
1010         /* if include_keyval is not set, don't send the key value, just
1011            the buflen data. probably used by NT5 to allocate buffer space - SK */
1012
1013         if ( include_keyval ) {
1014                 r_u->value = TALLOC_P( get_talloc_ctx(), REGVAL_BUFFER );
1015                 /* steal the memory */
1016                 *r_u->value = buf2;
1017         }
1018
1019         r_u->status = status;
1020
1021         return True;
1022 }
1023
1024 /*******************************************************************
1025 reads or writes a structure.
1026 ********************************************************************/
1027
1028 BOOL reg_io_r_query_value(const char *desc, REG_R_QUERY_VALUE *r_u, prs_struct *ps, int depth)
1029 {
1030         if ( !r_u )
1031                 return False;
1032
1033         prs_debug(ps, depth, desc, "reg_io_r_query_value");
1034         depth++;
1035
1036         if(!prs_align(ps))
1037                 return False;
1038         
1039         if ( !prs_pointer("type", ps, depth, (void**)&r_u->type, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
1040                 return False;
1041
1042         if ( !prs_pointer("value", ps, depth, (void**)&r_u->value, sizeof(REGVAL_BUFFER), (PRS_POINTER_CAST)smb_io_regval_buffer))
1043                 return False;
1044         if(!prs_align(ps))
1045                 return False;
1046
1047         if ( !prs_pointer("buf_max_len", ps, depth, (void**)&r_u->buf_max_len, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
1048                 return False;
1049         if ( !prs_pointer("buf_len", ps, depth, (void**)&r_u->buf_len, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
1050                 return False;
1051
1052         if(!prs_werror("status", ps, depth, &r_u->status))
1053                 return False;
1054
1055         return True;
1056 }
1057
1058 /*******************************************************************
1059 makes a structure.
1060 ********************************************************************/
1061
1062 void init_reg_q_enum_val(REG_Q_ENUM_VALUE *q_u, POLICY_HND *pol,
1063                                 uint32 val_idx,
1064                                 uint32 max_name_len, uint32 max_buf_len)
1065 {
1066         ZERO_STRUCTP(q_u);
1067
1068         memcpy(&q_u->pol, pol, sizeof(q_u->pol));
1069
1070         q_u->val_index = val_idx;
1071
1072         q_u->name.size = max_name_len*2;
1073         q_u->name.string = TALLOC_ZERO_P( get_talloc_ctx(), UNISTR2 );
1074         q_u->name.string->uni_max_len = max_name_len;
1075         
1076         q_u->type = TALLOC_P( get_talloc_ctx(), uint32 );
1077         *q_u->type = 0x0;
1078
1079         q_u->value = TALLOC_ZERO_P( get_talloc_ctx(), REGVAL_BUFFER );
1080         q_u->value->buf_max_len = max_buf_len;
1081
1082         q_u->buffer_len  = TALLOC_P( get_talloc_ctx(), uint32 );
1083         *q_u->buffer_len = max_buf_len;
1084
1085         q_u->name_len  = TALLOC_P( get_talloc_ctx(), uint32 );
1086         *q_u->name_len = 0x0;
1087 }
1088
1089 /*******************************************************************
1090 makes a structure.
1091 ********************************************************************/
1092
1093 void init_reg_r_enum_val(REG_R_ENUM_VALUE *r_u, REGISTRY_VALUE *val )
1094 {
1095         uint32 real_size;
1096         
1097         ZERO_STRUCTP(r_u);
1098
1099         /* value name */
1100
1101         DEBUG(10,("init_reg_r_enum_val: Valuename => [%s]\n", val->valuename));
1102         
1103         init_unistr4( &r_u->name, val->valuename, UNI_STR_TERMINATE);
1104                 
1105         /* type */
1106         
1107         r_u->type = TALLOC_P( get_talloc_ctx(), uint32 );
1108         *r_u->type = val->type;
1109
1110         /* REG_SZ & REG_MULTI_SZ must be converted to UNICODE */
1111         
1112         r_u->value = TALLOC_P( get_talloc_ctx(), REGVAL_BUFFER );
1113         real_size = reg_init_regval_buffer( r_u->value, val );
1114         
1115         /* lengths */
1116
1117         r_u->buffer_len1  = TALLOC_P( get_talloc_ctx(), uint32 );
1118         *r_u->buffer_len1 = real_size;
1119         r_u->buffer_len2  = TALLOC_P( get_talloc_ctx(), uint32 );
1120         *r_u->buffer_len2 = real_size;
1121 }
1122
1123 /*******************************************************************
1124 reads or writes a structure.
1125 ********************************************************************/
1126
1127 BOOL reg_io_q_enum_val(const char *desc,  REG_Q_ENUM_VALUE *q_u, prs_struct *ps, int depth)
1128 {
1129         if (q_u == NULL)
1130                 return False;
1131
1132         prs_debug(ps, depth, desc, "reg_io_q_enum_val");
1133         depth++;
1134
1135         if(!prs_align(ps))
1136                 return False;
1137         
1138         if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
1139                 return False;
1140         
1141         if(!prs_uint32("val_index", ps, depth, &q_u->val_index))
1142                 return False;
1143                 
1144         if(!prs_unistr4("name", ps, depth, &q_u->name ))
1145                 return False;
1146         if(!prs_align(ps))
1147                 return False;
1148
1149         if(!prs_pointer("type", ps, depth, (void**)&q_u->type, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
1150                 return False;
1151
1152         if ( !prs_pointer("value", ps, depth, (void**)&q_u->value, sizeof(REGVAL_BUFFER), (PRS_POINTER_CAST)smb_io_regval_buffer))
1153                 return False;
1154         if(!prs_align(ps))
1155                 return False;
1156
1157         if(!prs_pointer("buffer_len", ps, depth, (void**)&q_u->buffer_len, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
1158                 return False;
1159         if(!prs_pointer("name_len", ps, depth, (void**)&q_u->name_len, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
1160                 return False;
1161
1162         return True;
1163 }
1164
1165 /*******************************************************************
1166 reads or writes a structure.
1167 ********************************************************************/
1168
1169 BOOL reg_io_r_enum_val(const char *desc,  REG_R_ENUM_VALUE *r_u, prs_struct *ps, int depth)
1170 {
1171         if ( !r_u )
1172                 return False;
1173
1174         prs_debug(ps, depth, desc, "reg_io_r_enum_val");
1175         depth++;
1176
1177         if(!prs_align(ps))
1178                 return False;
1179         
1180         if(!prs_unistr4("name", ps, depth, &r_u->name ))
1181                 return False;
1182         if(!prs_align(ps))
1183                 return False;
1184
1185         if(!prs_pointer("type", ps, depth, (void**)&r_u->type, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
1186                 return False;
1187
1188         if ( !prs_pointer("value", ps, depth, (void**)&r_u->value, sizeof(REGVAL_BUFFER), (PRS_POINTER_CAST)smb_io_regval_buffer))
1189                 return False;
1190         if(!prs_align(ps))
1191                 return False;
1192
1193         if(!prs_pointer("buffer_len1", ps, depth, (void**)&r_u->buffer_len1, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
1194                 return False;
1195         if(!prs_pointer("buffer_len2", ps, depth, (void**)&r_u->buffer_len2, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
1196                 return False;
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->handle, pol, sizeof(q_u->handle));
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_value(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_value");
1233         depth++;
1234
1235         if(!prs_align(ps))
1236                 return False;
1237         
1238         if(!smb_io_pol_hnd("", &q_u->handle, 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_value(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_value");
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 )
1309 {
1310         if ( !r_u )
1311                 return;
1312                 
1313         init_unistr4( &r_u->keyname, subkey, UNI_STR_TERMINATE );
1314         r_u->classname = TALLOC_ZERO_P( get_talloc_ctx(), UNISTR4 );
1315         r_u->time       = TALLOC_ZERO_P( get_talloc_ctx(), NTTIME );
1316 }
1317
1318 /*******************************************************************
1319 reads or writes a structure.
1320 ********************************************************************/
1321
1322 BOOL reg_io_q_enum_key(const char *desc,  REG_Q_ENUM_KEY *q_u, prs_struct *ps, int depth)
1323 {
1324         if (q_u == NULL)
1325                 return False;
1326
1327         prs_debug(ps, depth, desc, "reg_io_q_enum_key");
1328         depth++;
1329
1330         if(!prs_align(ps))
1331                 return False;
1332         
1333         if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
1334                 return False;
1335         
1336         if(!prs_uint32("key_index", ps, depth, &q_u->key_index))
1337                 return False;
1338         if(!prs_uint16("key_name_len", ps, depth, &q_u->key_name_len))
1339                 return False;
1340         if(!prs_uint16("unknown_1", ps, depth, &q_u->unknown_1))
1341                 return False;
1342
1343         if(!prs_uint32("ptr1", ps, depth, &q_u->ptr1))
1344                 return False;
1345
1346         if (q_u->ptr1 != 0) {
1347                 if(!prs_uint32("unknown_2", ps, depth, &q_u->unknown_2))
1348                         return False;
1349                 if(!prs_uint8s(False, "pad1", ps, depth, q_u->pad1, sizeof(q_u->pad1)))
1350                         return False;
1351         }
1352
1353         if(!prs_uint32("ptr2", ps, depth, &q_u->ptr2))
1354                 return False;
1355
1356         if (q_u->ptr2 != 0) {
1357                 if(!prs_uint8s(False, "pad2", ps, depth, q_u->pad2, sizeof(q_u->pad2)))
1358                         return False;
1359         }
1360
1361         if(!prs_uint32("ptr3", ps, depth, &q_u->ptr3))
1362                 return False;
1363
1364         if (q_u->ptr3 != 0) {
1365                 if(!smb_io_time("", &q_u->time, ps, depth))
1366                         return False;
1367         }
1368
1369         return True;
1370 }
1371
1372 /*******************************************************************
1373 reads or writes a structure.
1374 ********************************************************************/
1375
1376 BOOL reg_io_r_enum_key(const char *desc,  REG_R_ENUM_KEY *q_u, prs_struct *ps, int depth)
1377 {
1378         if ( !q_u )
1379                 return False;
1380
1381         prs_debug(ps, depth, desc, "reg_io_r_enum_key");
1382         depth++;
1383
1384         if(!prs_align(ps))
1385                 return False;
1386         if ( !prs_unistr4( "keyname", ps, depth, &q_u->keyname ) )
1387                 return False;
1388         
1389         if(!prs_align(ps))
1390                 return False;
1391         if (!prs_pointer("class", ps, depth, (void**)&q_u->classname, sizeof(UNISTR4), (PRS_POINTER_CAST)prs_unistr4))
1392                 return False;
1393
1394         if(!prs_align(ps))
1395                 return False;
1396         if (!prs_pointer("time", ps, depth, (void**)&q_u->time, sizeof(NTTIME), (PRS_POINTER_CAST)smb_io_nttime))
1397                 return False;
1398
1399         if(!prs_align(ps))
1400                 return False;
1401         if(!prs_werror("status", ps, depth, &q_u->status))
1402                 return False;
1403
1404         return True;
1405 }
1406
1407 /*******************************************************************
1408 makes a structure.
1409 ********************************************************************/
1410
1411 void init_reg_q_open_entry(REG_Q_OPEN_ENTRY *q_u, POLICY_HND *pol,
1412                                 char *key_name, uint32 access_desired)
1413 {
1414         memcpy(&q_u->pol, pol, sizeof(q_u->pol));
1415
1416         init_unistr4(&q_u->name, key_name, UNI_STR_TERMINATE);
1417
1418         q_u->unknown_0 = 0x00000000;
1419         q_u->access = access_desired;
1420 }
1421
1422 /*******************************************************************
1423 reads or writes a structure.
1424 ********************************************************************/
1425
1426 BOOL reg_io_q_open_entry(const char *desc,  REG_Q_OPEN_ENTRY *q_u, prs_struct *ps, int depth)
1427 {
1428         if ( !q_u )
1429                 return False;
1430
1431         prs_debug(ps, depth, desc, "reg_io_q_open_entry");
1432         depth++;
1433
1434         if(!prs_align(ps))
1435                 return False;
1436         
1437         if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
1438                 return False;
1439         if(!prs_unistr4("name", ps, depth, &q_u->name))
1440                 return False;
1441
1442         if(!prs_align(ps))
1443                 return False;
1444         
1445         if(!prs_uint32("unknown_0        ", ps, depth, &q_u->unknown_0))
1446                 return False;
1447         if(!prs_uint32("access", ps, depth, &q_u->access))
1448                 return False;
1449
1450         return True;
1451 }
1452
1453 /*******************************************************************
1454 reads or writes a structure.
1455 ********************************************************************/
1456
1457 BOOL reg_io_r_open_entry(const char *desc,  REG_R_OPEN_ENTRY *r_u, prs_struct *ps, int depth)
1458 {
1459         if ( !r_u )
1460                 return False;
1461
1462         prs_debug(ps, depth, desc, "reg_io_r_open_entry");
1463         depth++;
1464
1465         if(!prs_align(ps))
1466                 return False;
1467         
1468         if(!smb_io_pol_hnd("handle", &r_u->handle, ps, depth))
1469                 return False;
1470
1471         if(!prs_werror("status", ps, depth, &r_u->status))
1472                 return False;
1473
1474         return True;
1475 }
1476
1477 /*******************************************************************
1478 Inits a structure.
1479 ********************************************************************/
1480
1481 void init_reg_q_shutdown(REG_Q_SHUTDOWN *q_u, const char *msg,
1482                         uint32 timeout, BOOL do_reboot, BOOL force)
1483 {
1484         q_u->server = TALLOC_P( get_talloc_ctx(), uint16 );
1485         *q_u->server = 0x1;
1486
1487         q_u->message = TALLOC_ZERO_P( get_talloc_ctx(), UNISTR4 );
1488
1489         if ( msg && *msg ) { 
1490                 init_unistr4( q_u->message, msg, UNI_FLAGS_NONE );
1491
1492                 /* Win2000 is apparently very sensitive to these lengths */
1493                 /* do a special case here */
1494
1495                 q_u->message->string->uni_max_len++;
1496                 q_u->message->size += 2;
1497
1498         }
1499
1500         q_u->timeout = timeout;
1501
1502         q_u->reboot = do_reboot ? 1 : 0;
1503         q_u->force = force ? 1 : 0;
1504 }
1505
1506 /*******************************************************************
1507 Inits a REG_Q_SHUTDOWN_EX structure.
1508 ********************************************************************/
1509
1510 void init_reg_q_shutdown_ex(REG_Q_SHUTDOWN_EX * q_u_ex, const char *msg,
1511                         uint32 timeout, BOOL do_reboot, BOOL force, uint32 reason)
1512 {
1513         REG_Q_SHUTDOWN q_u;
1514         
1515         ZERO_STRUCT( q_u );
1516         
1517         init_reg_q_shutdown( &q_u, msg, timeout, do_reboot, force );
1518         
1519         /* steal memory */
1520         
1521         q_u_ex->server  = q_u.server;
1522         q_u_ex->message = q_u.message;
1523         
1524         q_u_ex->reboot  = q_u.reboot;
1525         q_u_ex->force   = q_u.force;
1526         
1527         q_u_ex->reason = reason;
1528 }
1529
1530 /*******************************************************************
1531 reads or writes a structure.
1532 ********************************************************************/
1533
1534 BOOL reg_io_q_shutdown(const char *desc, REG_Q_SHUTDOWN *q_u, prs_struct *ps,
1535                        int depth)
1536 {
1537         if ( !q_u )
1538                 return False;
1539
1540         prs_debug(ps, depth, desc, "reg_io_q_shutdown");
1541         depth++;
1542
1543         if (!prs_align(ps))
1544                 return False;
1545
1546         if (!prs_pointer("server", ps, depth, (void**)&q_u->server, sizeof(uint16), (PRS_POINTER_CAST)prs_uint16))
1547                 return False;
1548         if (!prs_align(ps))
1549                 return False;
1550
1551         if (!prs_pointer("message", ps, depth, (void**)&q_u->message, sizeof(UNISTR4), (PRS_POINTER_CAST)prs_unistr4))
1552                 return False;
1553
1554         if (!prs_align(ps))
1555                 return False;
1556
1557         if (!prs_uint32("timeout", ps, depth, &(q_u->timeout)))
1558                 return False;
1559
1560         if (!prs_uint8("force  ", ps, depth, &(q_u->force)))
1561                 return False;
1562         if (!prs_uint8("reboot ", ps, depth, &(q_u->reboot)))
1563                 return False;
1564
1565
1566         return True;
1567 }
1568
1569 /*******************************************************************
1570 reads or writes a structure.
1571 ********************************************************************/
1572 BOOL reg_io_r_shutdown(const char *desc, REG_R_SHUTDOWN *r_u, prs_struct *ps,
1573                        int depth)
1574 {
1575         if ( !r_u )
1576                 return False;
1577
1578         prs_debug(ps, depth, desc, "reg_io_r_shutdown");
1579         depth++;
1580
1581         if(!prs_align(ps))
1582                 return False;
1583
1584         if(!prs_werror("status", ps, depth, &r_u->status))
1585                 return False;
1586
1587         return True;
1588 }
1589
1590 /*******************************************************************
1591 reads or writes a REG_Q_SHUTDOWN_EX structure.
1592 ********************************************************************/
1593
1594 BOOL reg_io_q_shutdown_ex(const char *desc, REG_Q_SHUTDOWN_EX *q_u, prs_struct *ps,
1595                        int depth)
1596 {
1597         if ( !q_u )
1598                 return False;
1599
1600         prs_debug(ps, depth, desc, "reg_io_q_shutdown_ex");
1601         depth++;
1602
1603         if (!prs_align(ps))
1604                 return False;
1605
1606         if (!prs_pointer("server", ps, depth, (void**)&q_u->server, sizeof(uint16), (PRS_POINTER_CAST)prs_uint16))
1607                 return False;
1608         if (!prs_align(ps))
1609                 return False;
1610
1611         if (!prs_pointer("message", ps, depth, (void**)&q_u->message, sizeof(UNISTR4), (PRS_POINTER_CAST)prs_unistr4))
1612                 return False;
1613
1614         if (!prs_align(ps))
1615                 return False;
1616
1617         if (!prs_uint32("timeout", ps, depth, &(q_u->timeout)))
1618                 return False;
1619
1620         if (!prs_uint8("force  ", ps, depth, &(q_u->force)))
1621                 return False;
1622         if (!prs_uint8("reboot ", ps, depth, &(q_u->reboot)))
1623                 return False;
1624
1625         if (!prs_align(ps))
1626                 return False;
1627         if (!prs_uint32("reason", ps, depth, &(q_u->reason)))
1628                 return False;
1629
1630
1631         return True;
1632 }
1633
1634 /*******************************************************************
1635 reads or writes a REG_R_SHUTDOWN_EX structure.
1636 ********************************************************************/
1637 BOOL reg_io_r_shutdown_ex(const char *desc, REG_R_SHUTDOWN_EX *r_u, prs_struct *ps,
1638                        int depth)
1639 {
1640         if ( !r_u )
1641                 return False;
1642
1643         prs_debug(ps, depth, desc, "reg_io_r_shutdown_ex");
1644         depth++;
1645
1646         if(!prs_align(ps))
1647                 return False;
1648
1649         if(!prs_werror("status", ps, depth, &r_u->status))
1650                 return False;
1651
1652         return True;
1653 }
1654
1655
1656
1657 /*******************************************************************
1658 Inits a structure.
1659 ********************************************************************/
1660 void init_reg_q_abort_shutdown(REG_Q_ABORT_SHUTDOWN *q_u)
1661 {
1662         q_u->server = TALLOC_P( get_talloc_ctx(), uint16 );
1663         *q_u->server = 0x1;
1664 }
1665
1666 /*******************************************************************
1667 reads or writes a structure.
1668 ********************************************************************/
1669 BOOL reg_io_q_abort_shutdown(const char *desc, REG_Q_ABORT_SHUTDOWN *q_u,
1670                              prs_struct *ps, int depth)
1671 {
1672         if ( !q_u )
1673                 return False;
1674
1675         prs_debug(ps, depth, desc, "reg_io_q_abort_shutdown");
1676         depth++;
1677
1678         if (!prs_align(ps))
1679                 return False;
1680
1681         if (!prs_pointer("server", ps, depth, (void**)&q_u->server, sizeof(uint16), (PRS_POINTER_CAST)prs_uint16))
1682                 return False;
1683         if (!prs_align(ps))
1684                 return False;
1685
1686         return True;
1687 }
1688
1689 /*******************************************************************
1690 reads or writes a structure.
1691 ********************************************************************/
1692 BOOL reg_io_r_abort_shutdown(const char *desc, REG_R_ABORT_SHUTDOWN *r_u,
1693                              prs_struct *ps, int depth)
1694 {
1695         if ( !r_u )
1696                 return False;
1697
1698         prs_debug(ps, depth, desc, "reg_io_r_abort_shutdown");
1699         depth++;
1700
1701         if (!prs_align(ps))
1702                 return False;
1703
1704         if (!prs_werror("status", ps, depth, &r_u->status))
1705                 return False;
1706
1707         return True;
1708 }