r6942: * merging the registry changes back to the 3.0 tree
[ira/wip.git] / source3 / rpc_parse / parse_reg.c
1 /*
2  *  Unix SMB/CIFS implementation.
3  *  RPC Pipe client / server routines
4  *  Copyright (C) Andrew Tridgell              1992-1997,
5  *  Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
6  *  Copyright (C) Paul Ashton                       1997.
7  *  Copyright (C) Marc Jacobsen                     1999.
8  *  Copyright (C) Simo Sorce                        2000.
9  *  Copyright (C) Jeremy Cooper                     2004
10  *  Copyright (C) Gerald Carter                     2002-2005.
11  *  
12  *  This program is free software; you can redistribute it and/or modify
13  *  it under the terms of the GNU General Public License as published by
14  *  the Free Software Foundation; either version 2 of the License, or
15  *  (at your option) any later version.
16  *  
17  *  This program is distributed in the hope that it will be useful,
18  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  *  GNU General Public License for more details.
21  *  
22  *  You should have received a copy of the GNU General Public License
23  *  along with this program; if not, write to the Free Software
24  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25  */
26
27 #include "includes.h"
28
29 #undef DBGC_CLASS
30 #define DBGC_CLASS DBGC_RPC_PARSE
31
32 /*******************************************************************
33  Fill in a REGVAL_BUFFER for the data given a REGISTRY_VALUE
34  *******************************************************************/
35
36 static uint32 reg_init_regval_buffer( REGVAL_BUFFER *buf2, REGISTRY_VALUE *val )
37 {
38         uint32          real_size = 0;
39         
40         if ( !buf2 || !val )
41                 return 0;
42                 
43         real_size = regval_size(val);
44         init_regval_buffer( buf2, (unsigned char*)regval_data_p(val), real_size );
45
46         return real_size;
47 }
48
49 /*******************************************************************
50  Inits a hive connect request structure
51 ********************************************************************/
52
53 void init_reg_q_open_hive( REG_Q_OPEN_HIVE *q_o, uint32 access_desired )
54 {
55         
56         q_o->server = TALLOC_P( get_talloc_ctx(), uint16);
57         *q_o->server = 0x1;
58         
59         q_o->access = access_desired;
60 }
61
62 /*******************************************************************
63 Marshalls a hive connect request
64 ********************************************************************/
65
66 BOOL reg_io_q_open_hive(const char *desc, REG_Q_OPEN_HIVE *q_u,
67                         prs_struct *ps, int depth)
68 {
69         prs_debug(ps, depth, desc, "reg_io_q_open_hive");
70         depth++;
71
72         if(!prs_align(ps))
73                 return False;
74
75         if(!prs_pointer("server", ps, depth, (void**)&q_u->server, sizeof(uint16), (PRS_POINTER_CAST)prs_uint16))
76                 return False;
77
78         if(!prs_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->pnt_pol, hnd, sizeof(q_c->pnt_pol));
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->pnt_pol, 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->key_pol, 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->pnt_pol, hnd, sizeof(q_c->pnt_pol));
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_val(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_val");
336         depth++;
337
338         if(!prs_align(ps))
339                 return False;
340         
341         if(!smb_io_pol_hnd("", &q_u->pnt_pol, 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_val(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_val");
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->pnt_pol, hnd, sizeof(q_c->pnt_pol));
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->pnt_pol, ps, depth))
406                 return False;
407
408         if(!prs_unistr4("", ps, depth, &q_u->name))
409                 return False;
410         if(!prs_align(ps))
411                 return False;
412
413         return True;
414 }
415
416 /*******************************************************************
417 reads or writes a structure.
418 ********************************************************************/
419
420 BOOL reg_io_r_delete_key(const char *desc,  REG_R_DELETE_KEY *r_u, prs_struct *ps, int depth)
421 {
422         if ( !r_u )
423                 return False;
424
425         prs_debug(ps, depth, desc, "reg_io_r_delete_key");
426         depth++;
427
428         if(!prs_align(ps))
429                 return False;
430         
431         if(!prs_werror("status", ps, depth, &r_u->status))
432                 return False;
433
434         return True;
435 }
436
437 /*******************************************************************
438  Inits a structure.
439 ********************************************************************/
440
441 void init_reg_q_query_key(REG_Q_QUERY_KEY *q_o, POLICY_HND *hnd, const char *class)
442 {
443         ZERO_STRUCTP(q_o);
444
445         memcpy(&q_o->pol, hnd, sizeof(q_o->pol));
446         init_unistr4(&q_o->class, class, UNI_STR_TERMINATE);
447 }
448
449 /*******************************************************************
450 reads or writes a structure.
451 ********************************************************************/
452
453 BOOL reg_io_q_query_key(const char *desc,  REG_Q_QUERY_KEY *q_u, prs_struct *ps, int depth)
454 {
455         if ( !q_u )
456                 return False;
457
458         prs_debug(ps, depth, desc, "reg_io_q_query_key");
459         depth++;
460
461         if(!prs_align(ps))
462                 return False;
463         
464         if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
465                 return False;
466         if(!prs_unistr4("class", ps, depth, &q_u->class))
467                 return False;
468
469         if(!prs_align(ps))
470                 return False;
471
472         return True;
473 }
474
475
476 /*******************************************************************
477 reads or writes a structure.
478 ********************************************************************/
479
480 BOOL reg_io_r_query_key(const char *desc,  REG_R_QUERY_KEY *r_u, prs_struct *ps, int depth)
481 {
482         if ( !r_u )
483                 return False;
484
485         prs_debug(ps, depth, desc, "reg_io_r_query_key");
486         depth++;
487
488         if(!prs_align(ps))
489                 return False;
490         
491         if(!prs_unistr4("class", ps, depth, &r_u->class))
492                 return False;
493
494         if(!prs_align(ps))
495                 return False;
496
497         if(!prs_uint32("num_subkeys   ", ps, depth, &r_u->num_subkeys))
498                 return False;
499         if(!prs_uint32("max_subkeylen ", ps, depth, &r_u->max_subkeylen))
500                 return False;
501         if(!prs_uint32("reserved      ", ps, depth, &r_u->reserved))
502                 return False;
503         if(!prs_uint32("num_values    ", ps, depth, &r_u->num_values))
504                 return False;
505         if(!prs_uint32("max_valnamelen", ps, depth, &r_u->max_valnamelen))
506                 return False;
507         if(!prs_uint32("max_valbufsize", ps, depth, &r_u->max_valbufsize))
508                 return False;
509         if(!prs_uint32("sec_desc      ", ps, depth, &r_u->sec_desc))
510                 return False;
511         if(!smb_io_time("mod_time     ", &r_u->mod_time, ps, depth))
512                 return False;
513
514         if(!prs_werror("status", ps, depth, &r_u->status))
515                 return False;
516
517         return True;
518 }
519
520 /*******************************************************************
521  Inits a structure.
522 ********************************************************************/
523
524 void init_reg_q_getversion(REG_Q_GETVERSION *q_o, POLICY_HND *hnd)
525 {
526         memcpy(&q_o->pol, hnd, sizeof(q_o->pol));
527 }
528
529
530 /*******************************************************************
531 reads or writes a structure.
532 ********************************************************************/
533
534 BOOL reg_io_q_getversion(const char *desc,  REG_Q_GETVERSION *q_u, prs_struct *ps, int depth)
535 {
536         if ( !q_u )
537                 return False;
538
539         prs_debug(ps, depth, desc, "reg_io_q_getversion");
540         depth++;
541
542         if(!prs_align(ps))
543                 return False;
544
545         if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
546                 return False;
547
548         return True;
549 }
550
551 /*******************************************************************
552 reads or writes a structure.
553 ********************************************************************/
554
555 BOOL reg_io_r_getversion(const char *desc,  REG_R_GETVERSION *r_u, prs_struct *ps, int depth)
556 {
557         if ( !r_u )
558                 return False;
559
560         prs_debug(ps, depth, desc, "reg_io_r_getversion");
561         depth++;
562
563         if(!prs_align(ps))
564                 return False;
565
566         if(!prs_uint32("unknown", ps, depth, &r_u->unknown))
567                 return False;
568         if(!prs_werror("status" , ps, depth, &r_u->status))
569                 return False;
570
571         return True;
572 }
573
574
575 /*******************************************************************
576 reads or writes a structure.
577 ********************************************************************/
578
579 BOOL reg_io_q_restore_key(const char *desc,  REG_Q_RESTORE_KEY *q_u, prs_struct *ps, int depth)
580 {
581         if ( !q_u )
582                 return False;
583
584         prs_debug(ps, depth, desc, "reg_io_q_restore_key");
585         depth++;
586
587         if(!prs_align(ps))
588                 return False;
589
590         if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
591                 return False;
592
593         if(!prs_unistr4("filename", ps, depth, &q_u->filename))
594                 return False;
595
596         if(!prs_uint32("flags", ps, depth, &q_u->flags))
597                 return False;
598
599         return True;
600 }
601
602 /*******************************************************************
603 reads or writes a structure.
604 ********************************************************************/
605
606 BOOL reg_io_r_restore_key(const char *desc,  REG_R_RESTORE_KEY *r_u, prs_struct *ps, int depth)
607 {
608         if ( !r_u )
609                 return False;
610
611         prs_debug(ps, depth, desc, "reg_io_r_restore_key");
612         depth++;
613
614         if(!prs_align(ps))
615                 return False;
616         
617         if(!prs_werror("status" , ps, depth, &r_u->status))
618                 return False;
619
620         return True;
621 }
622
623 /*******************************************************************
624 reads or writes a structure.
625 ********************************************************************/
626
627 BOOL reg_io_q_save_key(const char *desc,  REG_Q_SAVE_KEY *q_u, prs_struct *ps, int depth)
628 {
629         if ( !q_u )
630                 return False;
631
632         prs_debug(ps, depth, desc, "reg_io_q_save_key");
633         depth++;
634
635         if(!prs_align(ps))
636                 return False;
637
638         if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
639                 return False;
640
641         if(!prs_unistr4("filename", ps, depth, &q_u->filename))
642                 return False;
643
644 #if 0   /* reg_io_sec_attr() */
645         if(!prs_uint32("unknown", ps, depth, &q_u->unknown))
646                 return False;
647 #endif
648
649         return True;
650 }
651
652 /*******************************************************************
653 reads or writes a structure.
654 ********************************************************************/
655
656 BOOL reg_io_r_save_key(const char *desc,  REG_R_SAVE_KEY *r_u, prs_struct *ps, int depth)
657 {
658         if ( !r_u )
659                 return False;
660
661         prs_debug(ps, depth, desc, "reg_io_r_save_key");
662         depth++;
663
664         if(!prs_align(ps))
665                 return False;
666         
667         if(!prs_werror("status" , ps, depth, &r_u->status))
668                 return False;
669
670         return True;
671 }
672
673 /*******************************************************************
674  Inits an REG_Q_CLOSE structure.
675 ********************************************************************/
676
677 void init_reg_q_close(REG_Q_CLOSE *q_c, POLICY_HND *hnd)
678 {
679         DEBUG(5,("init_reg_q_close\n"));
680
681         memcpy(&q_c->pol, hnd, sizeof(q_c->pol));
682 }
683
684 /*******************************************************************
685 reads or writes a structure.
686 ********************************************************************/
687
688 BOOL reg_io_q_close(const char *desc,  REG_Q_CLOSE *q_u, prs_struct *ps, int depth)
689 {
690         if (q_u == NULL)
691                 return False;
692
693         prs_debug(ps, depth, desc, "reg_io_q_close");
694         depth++;
695
696         if(!prs_align(ps))
697                 return False;
698
699         if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
700                 return False;
701         if(!prs_align(ps))
702                 return False;
703
704         return True;
705 }
706
707 /*******************************************************************
708 reads or writes a structure.
709 ********************************************************************/
710
711 BOOL reg_io_r_close(const char *desc,  REG_R_CLOSE *r_u, prs_struct *ps, int depth)
712 {
713         if ( !r_u )
714                 return False;
715
716         prs_debug(ps, depth, desc, "reg_io_r_close");
717         depth++;
718
719         if(!prs_align(ps))
720                 return False;
721
722         if(!smb_io_pol_hnd("", &r_u->pol, ps, depth))
723                 return False;
724         if(!prs_align(ps))
725                 return False;
726
727         if(!prs_werror("status", ps, depth, &r_u->status))
728                 return False;
729
730         return True;
731 }
732
733 /*******************************************************************
734 makes a structure.
735 ********************************************************************/
736
737 void init_reg_q_set_key_sec(REG_Q_SET_KEY_SEC *q_u, POLICY_HND *pol,
738                             uint32 sec_info, SEC_DESC_BUF *sec_desc_buf)
739 {
740         memcpy(&q_u->pol, pol, sizeof(q_u->pol));
741
742         q_u->sec_info = sec_info;
743
744         q_u->ptr = 1;
745         init_buf_hdr(&q_u->hdr_sec, sec_desc_buf->len, sec_desc_buf->len);
746         q_u->data = sec_desc_buf;
747 }
748
749 /*******************************************************************
750 reads or writes a structure.
751 ********************************************************************/
752
753 BOOL reg_io_q_set_key_sec(const char *desc,  REG_Q_SET_KEY_SEC *q_u, prs_struct *ps, int depth)
754 {
755         if ( !q_u )
756                 return False;
757
758         prs_debug(ps, depth, desc, "reg_io_q_set_key_sec");
759         depth++;
760
761         if(!prs_align(ps))
762                 return False;
763         
764         if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
765                 return False;
766
767         if(!prs_uint32("sec_info", ps, depth, &q_u->sec_info))
768                 return False;
769         if(!prs_uint32("ptr    ", ps, depth, &q_u->ptr))
770                 return False;
771
772         if(!reg_io_hdrbuf_sec(q_u->ptr, NULL, &q_u->hdr_sec, q_u->data, ps, depth))
773                 return False;
774
775         return True;
776 }
777
778 /*******************************************************************
779 reads or writes a structure.
780 ********************************************************************/
781
782 BOOL reg_io_r_set_key_sec(const char *desc, REG_R_SET_KEY_SEC *q_u, prs_struct *ps, int depth)
783 {
784         if ( !q_u )
785                 return False;
786
787         prs_debug(ps, depth, desc, "reg_io_r_set_key_sec");
788         depth++;
789
790         if(!prs_align(ps))
791                 return False;
792         
793         if(!prs_werror("status", ps, depth, &q_u->status))
794                 return False;
795
796         return True;
797 }
798
799
800 /*******************************************************************
801 makes a structure.
802 ********************************************************************/
803
804 void init_reg_q_get_key_sec(REG_Q_GET_KEY_SEC *q_u, POLICY_HND *pol, 
805                             uint32 sec_info, uint32 sec_buf_size,
806                             SEC_DESC_BUF *psdb)
807 {
808         memcpy(&q_u->pol, pol, sizeof(q_u->pol));
809
810         q_u->sec_info = sec_info;
811
812         q_u->ptr = psdb != NULL ? 1 : 0;
813         q_u->data = psdb;
814
815         init_buf_hdr(&q_u->hdr_sec, sec_buf_size, 0);
816 }
817
818 /*******************************************************************
819 reads or writes a structure.
820 ********************************************************************/
821
822 BOOL reg_io_q_get_key_sec(const char *desc,  REG_Q_GET_KEY_SEC *q_u, prs_struct *ps, int depth)
823 {
824         if ( !q_u )
825                 return False;
826
827         prs_debug(ps, depth, desc, "reg_io_q_get_key_sec");
828         depth++;
829
830         if(!prs_align(ps))
831                 return False;
832         
833         if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
834                 return False;
835
836         if(!prs_uint32("sec_info", ps, depth, &q_u->sec_info))
837                 return False;
838         if(!prs_uint32("ptr     ", ps, depth, &q_u->ptr))
839                 return False;
840
841         if(!reg_io_hdrbuf_sec(q_u->ptr, NULL, &q_u->hdr_sec, q_u->data, ps, depth))
842                 return False;
843
844         return True;
845 }
846
847 #if 0
848 /*******************************************************************
849 makes a structure.
850 ********************************************************************/
851  void init_reg_r_get_key_sec(REG_R_GET_KEY_SEC *r_i, POLICY_HND *pol, 
852                                 uint32 buf_len, uint8 *buf,
853                                 NTSTATUS status)
854 {
855         r_i->ptr = 1;
856         init_buf_hdr(&r_i->hdr_sec, buf_len, buf_len);
857         init_sec_desc_buf(r_i->data, buf_len, 1);
858
859         r_i->status = status; /* 0x0000 0000 or 0x0000 007a */
860 }
861 #endif 
862
863 /*******************************************************************
864 reads or writes a structure.
865 ********************************************************************/
866
867 BOOL reg_io_r_get_key_sec(const char *desc,  REG_R_GET_KEY_SEC *q_u, prs_struct *ps, int depth)
868 {
869         if ( !q_u )
870                 return False;
871
872         prs_debug(ps, depth, desc, "reg_io_r_get_key_sec");
873         depth++;
874
875         if(!prs_align(ps))
876                 return False;
877         
878         if(!prs_uint32("ptr      ", ps, depth, &q_u->ptr))
879                 return False;
880
881         if (q_u->ptr != 0) {
882                 if(!smb_io_hdrbuf("", &q_u->hdr_sec, ps, depth))
883                         return False;
884                 if(!sec_io_desc_buf("", &q_u->data, ps, depth))
885                         return False;
886                 if(!prs_align(ps))
887                         return False;
888         }
889
890         if(!prs_werror("status", ps, depth, &q_u->status))
891                 return False;
892
893         return True;
894 }
895
896 /*******************************************************************
897 makes a structure.
898 ********************************************************************/
899
900 BOOL init_reg_q_info(REG_Q_INFO *q_u, POLICY_HND *pol, const char *val_name,
901                      REGVAL_BUFFER *value_output)
902 {
903         if (q_u == NULL)
904                 return False;
905
906         q_u->pol = *pol;
907
908         init_unistr4(&q_u->name, val_name, UNI_STR_TERMINATE);
909
910         q_u->ptr_reserved = 1;
911         q_u->ptr_buf = 1;
912
913         q_u->ptr_bufsize = 1;
914         q_u->bufsize = value_output->buf_max_len;
915         q_u->buf_unk = 0;
916
917         q_u->unk1 = 0;
918         q_u->ptr_buflen = 1;
919         q_u->buflen = value_output->buf_max_len; 
920
921         q_u->ptr_buflen2 = 1;
922         q_u->buflen2 = 0;
923
924         return True;
925 }
926
927 /*******************************************************************
928 reads or writes a structure.
929 ********************************************************************/
930
931 BOOL reg_io_q_info(const char *desc,  REG_Q_INFO *q_u, prs_struct *ps, int depth)
932 {
933         if ( !q_u )
934                 return False;
935
936         prs_debug(ps, depth, desc, "reg_io_q_info");
937         depth++;
938
939         if(!prs_align(ps))
940                 return False;
941         
942         if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
943                 return False;
944         if(!prs_unistr4("name", ps, depth, &q_u->name))
945                 return False;
946
947         if(!prs_align(ps))
948                 return False;
949         
950         if(!prs_uint32("ptr_reserved", ps, depth, &(q_u->ptr_reserved)))
951                 return False;
952
953         if(!prs_uint32("ptr_buf", ps, depth, &(q_u->ptr_buf)))
954                 return False;
955
956         if(q_u->ptr_buf) {
957                 if(!prs_uint32("ptr_bufsize", ps, depth, &(q_u->ptr_bufsize)))
958                         return False;
959                 if(!prs_uint32("bufsize", ps, depth, &(q_u->bufsize)))
960                         return False;
961                 if(!prs_uint32("buf_unk", ps, depth, &(q_u->buf_unk)))
962                         return False;
963         }
964
965         if(!prs_uint32("unk1", ps, depth, &(q_u->unk1)))
966                 return False;
967
968         if(!prs_uint32("ptr_buflen", ps, depth, &(q_u->ptr_buflen)))
969                 return False;
970
971         if (q_u->ptr_buflen) {
972                 if(!prs_uint32("buflen", ps, depth, &(q_u->buflen)))
973                         return False;
974                 if(!prs_uint32("ptr_buflen2", ps, depth, &(q_u->ptr_buflen2)))
975                         return False;
976                 if(!prs_uint32("buflen2", ps, depth, &(q_u->buflen2)))
977                         return False;
978         }
979
980         return True;
981 }
982
983 /*******************************************************************
984  Inits a structure.
985  New version to replace older init_reg_r_info()
986 ********************************************************************/
987
988 BOOL init_reg_r_info(uint32 include_keyval, REG_R_INFO *r_u,
989                      REGISTRY_VALUE *val, WERROR status)
990 {
991         uint32                  buf_len = 0;
992         REGVAL_BUFFER           buf2;
993                 
994         if( !r_u || !val )
995                 return False;
996         
997         r_u->type = TALLOC_P( get_talloc_ctx(), uint32 );
998         *r_u->type = val->type;
999
1000         buf_len = reg_init_regval_buffer( &buf2, val );
1001         
1002         r_u->buf_max_len = TALLOC_P( get_talloc_ctx(), uint32 );
1003         *r_u->buf_max_len = buf_len;
1004
1005         r_u->buf_len = TALLOC_P( get_talloc_ctx(), uint32 );
1006         *r_u->buf_len = buf_len;
1007         
1008         /* if include_keyval is not set, don't send the key value, just
1009            the buflen data. probably used by NT5 to allocate buffer space - SK */
1010
1011         if ( include_keyval ) {
1012                 r_u->value = TALLOC_P( get_talloc_ctx(), REGVAL_BUFFER );
1013                 /* steal the memory */
1014                 *r_u->value = buf2;
1015         }
1016
1017         r_u->status = status;
1018
1019         return True;
1020 }
1021
1022 /*******************************************************************
1023 reads or writes a structure.
1024 ********************************************************************/
1025
1026 BOOL reg_io_r_info(const char *desc, REG_R_INFO *r_u, prs_struct *ps, int depth)
1027 {
1028         if ( !r_u )
1029                 return False;
1030
1031         prs_debug(ps, depth, desc, "reg_io_r_info");
1032         depth++;
1033
1034         if(!prs_align(ps))
1035                 return False;
1036         
1037         if ( !prs_pointer("type", ps, depth, (void**)&r_u->type, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
1038                 return False;
1039
1040         if ( !prs_pointer("value", ps, depth, (void**)&r_u->value, sizeof(REGVAL_BUFFER), (PRS_POINTER_CAST)smb_io_regval_buffer))
1041                 return False;
1042         if(!prs_align(ps))
1043                 return False;
1044
1045         if ( !prs_pointer("buf_max_len", ps, depth, (void**)&r_u->buf_max_len, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
1046                 return False;
1047         if ( !prs_pointer("buf_len", ps, depth, (void**)&r_u->buf_len, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
1048                 return False;
1049
1050         if(!prs_werror("status", ps, depth, &r_u->status))
1051                 return False;
1052
1053         return True;
1054 }
1055
1056 /*******************************************************************
1057 makes a structure.
1058 ********************************************************************/
1059
1060 void init_reg_q_enum_val(REG_Q_ENUM_VALUE *q_u, POLICY_HND *pol,
1061                                 uint32 val_idx,
1062                                 uint32 max_name_len, uint32 max_buf_len)
1063 {
1064         ZERO_STRUCTP(q_u);
1065
1066         memcpy(&q_u->pol, pol, sizeof(q_u->pol));
1067
1068         q_u->val_index = val_idx;
1069
1070         q_u->name.size = max_name_len*2;
1071         q_u->name.string = TALLOC_ZERO_P( get_talloc_ctx(), UNISTR2 );
1072         q_u->name.string->uni_max_len = max_name_len;
1073         
1074         q_u->type = TALLOC_P( get_talloc_ctx(), uint32 );
1075         *q_u->type = 0x0;
1076
1077         q_u->value = TALLOC_ZERO_P( get_talloc_ctx(), REGVAL_BUFFER );
1078         q_u->value->buf_max_len = max_buf_len;
1079
1080         q_u->buffer_len  = TALLOC_P( get_talloc_ctx(), uint32 );
1081         *q_u->buffer_len = max_buf_len;
1082
1083         q_u->name_len  = TALLOC_P( get_talloc_ctx(), uint32 );
1084         *q_u->name_len = 0x0;
1085 }
1086
1087 /*******************************************************************
1088 makes a structure.
1089 ********************************************************************/
1090
1091 void init_reg_r_enum_val(REG_R_ENUM_VALUE *r_u, REGISTRY_VALUE *val )
1092 {
1093         uint32 real_size;
1094         
1095         ZERO_STRUCTP(r_u);
1096
1097         /* value name */
1098
1099         DEBUG(10,("init_reg_r_enum_val: Valuename => [%s]\n", val->valuename));
1100         
1101         init_unistr4( &r_u->name, val->valuename, UNI_STR_TERMINATE);
1102                 
1103         /* type */
1104         
1105         r_u->type = TALLOC_P( get_talloc_ctx(), uint32 );
1106         *r_u->type = val->type;
1107
1108         /* REG_SZ & REG_MULTI_SZ must be converted to UNICODE */
1109         
1110         r_u->value = TALLOC_P( get_talloc_ctx(), REGVAL_BUFFER );
1111         real_size = reg_init_regval_buffer( r_u->value, val );
1112         
1113         /* lengths */
1114
1115         r_u->buffer_len1  = TALLOC_P( get_talloc_ctx(), uint32 );
1116         *r_u->buffer_len1 = real_size;
1117         r_u->buffer_len2  = TALLOC_P( get_talloc_ctx(), uint32 );
1118         *r_u->buffer_len2 = real_size;
1119 }
1120
1121 /*******************************************************************
1122 reads or writes a structure.
1123 ********************************************************************/
1124
1125 BOOL reg_io_q_enum_val(const char *desc,  REG_Q_ENUM_VALUE *q_u, prs_struct *ps, int depth)
1126 {
1127         if (q_u == NULL)
1128                 return False;
1129
1130         prs_debug(ps, depth, desc, "reg_io_q_enum_val");
1131         depth++;
1132
1133         if(!prs_align(ps))
1134                 return False;
1135         
1136         if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
1137                 return False;
1138         
1139         if(!prs_uint32("val_index", ps, depth, &q_u->val_index))
1140                 return False;
1141                 
1142         if(!prs_unistr4("name", ps, depth, &q_u->name ))
1143                 return False;
1144         if(!prs_align(ps))
1145                 return False;
1146
1147         if(!prs_pointer("type", ps, depth, (void**)&q_u->type, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
1148                 return False;
1149
1150         if ( !prs_pointer("value", ps, depth, (void**)&q_u->value, sizeof(REGVAL_BUFFER), (PRS_POINTER_CAST)smb_io_regval_buffer))
1151                 return False;
1152         if(!prs_align(ps))
1153                 return False;
1154
1155         if(!prs_pointer("buffer_len", ps, depth, (void**)&q_u->buffer_len, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
1156                 return False;
1157         if(!prs_pointer("name_len", ps, depth, (void**)&q_u->name_len, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
1158                 return False;
1159
1160         return True;
1161 }
1162
1163 /*******************************************************************
1164 reads or writes a structure.
1165 ********************************************************************/
1166
1167 BOOL reg_io_r_enum_val(const char *desc,  REG_R_ENUM_VALUE *r_u, prs_struct *ps, int depth)
1168 {
1169         if ( !r_u )
1170                 return False;
1171
1172         prs_debug(ps, depth, desc, "reg_io_r_enum_val");
1173         depth++;
1174
1175         if(!prs_align(ps))
1176                 return False;
1177         
1178         if(!prs_unistr4("name", ps, depth, &r_u->name ))
1179                 return False;
1180         if(!prs_align(ps))
1181                 return False;
1182
1183         if(!prs_pointer("type", ps, depth, (void**)&r_u->type, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
1184                 return False;
1185
1186         if ( !prs_pointer("value", ps, depth, (void**)&r_u->value, sizeof(REGVAL_BUFFER), (PRS_POINTER_CAST)smb_io_regval_buffer))
1187                 return False;
1188         if(!prs_align(ps))
1189                 return False;
1190
1191         if(!prs_pointer("buffer_len1", ps, depth, (void**)&r_u->buffer_len1, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
1192                 return False;
1193         if(!prs_pointer("buffer_len2", ps, depth, (void**)&r_u->buffer_len2, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
1194                 return False;
1195
1196         if(!prs_werror("status", ps, depth, &r_u->status))
1197                 return False;
1198
1199         return True;
1200 }
1201
1202 /*******************************************************************
1203 makes a structure.
1204 ********************************************************************/
1205
1206 void init_reg_q_set_val(REG_Q_SET_VALUE *q_u, POLICY_HND *pol,
1207                                 char *val_name, uint32 type,
1208                                 RPC_DATA_BLOB *val)
1209 {
1210         ZERO_STRUCTP(q_u);
1211
1212         memcpy(&q_u->pol, pol, sizeof(q_u->pol));
1213
1214         init_unistr4(&q_u->name, val_name, UNI_STR_TERMINATE);
1215         
1216         q_u->type      = type;
1217         q_u->value     = *val;
1218         q_u->size      = val->buf_len;
1219 }
1220
1221 /*******************************************************************
1222 reads or writes a structure.
1223 ********************************************************************/
1224
1225 BOOL reg_io_q_set_val(const char *desc,  REG_Q_SET_VALUE *q_u, prs_struct *ps, int depth)
1226 {
1227         if (q_u == NULL)
1228                 return False;
1229
1230         prs_debug(ps, depth, desc, "reg_io_q_set_val");
1231         depth++;
1232
1233         if(!prs_align(ps))
1234                 return False;
1235         
1236         if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
1237                 return False;
1238         
1239         if(!prs_unistr4("name", ps, depth, &q_u->name ))
1240                 return False;
1241         if(!prs_align(ps))
1242                 return False;
1243
1244         if(!prs_uint32("type", ps, depth, &q_u->type))
1245                 return False;
1246
1247         if(!smb_io_rpc_blob("value", &q_u->value, ps, depth ))
1248                 return False;
1249         if(!prs_align(ps))
1250                 return False;
1251
1252         if(!prs_uint32("size", ps, depth, &q_u->size))
1253                 return False;
1254
1255         return True;
1256 }
1257
1258 /*******************************************************************
1259 reads or writes a structure.
1260 ********************************************************************/
1261
1262 BOOL reg_io_r_set_val(const char *desc,  REG_R_SET_VALUE *q_u, prs_struct *ps, int depth)
1263 {
1264         if ( !q_u )
1265                 return False;
1266
1267         prs_debug(ps, depth, desc, "reg_io_r_set_val");
1268         depth++;
1269
1270         if(!prs_align(ps))
1271                 return False;
1272         
1273         if(!prs_werror("status", ps, depth, &q_u->status))
1274                 return False;
1275
1276         return True;
1277 }
1278
1279 /*******************************************************************
1280 makes a structure.
1281 ********************************************************************/
1282
1283 void init_reg_q_enum_key(REG_Q_ENUM_KEY *q_u, POLICY_HND *pol, uint32 key_idx)
1284 {
1285         memcpy(&q_u->pol, pol, sizeof(q_u->pol));
1286
1287         q_u->key_index = key_idx;
1288         q_u->key_name_len = 0;
1289         q_u->unknown_1 = 0x0414;
1290
1291         q_u->ptr1 = 1;
1292         q_u->unknown_2 = 0x0000020A;
1293         memset(q_u->pad1, 0, sizeof(q_u->pad1));
1294
1295         q_u->ptr2 = 1;
1296         memset(q_u->pad2, 0, sizeof(q_u->pad2));
1297
1298         q_u->ptr3 = 1;
1299         unix_to_nt_time(&q_u->time, 0);            /* current time? */
1300 }
1301
1302 /*******************************************************************
1303 makes a reply structure.
1304 ********************************************************************/
1305
1306 void init_reg_r_enum_key(REG_R_ENUM_KEY *r_u, char *subkey )
1307 {
1308         if ( !r_u )
1309                 return;
1310                 
1311         init_unistr4( &r_u->keyname, subkey, STR_TERMINATE );
1312         r_u->classname = TALLOC_ZERO_P( get_talloc_ctx(), UNISTR4 );
1313         r_u->time       = TALLOC_ZERO_P( get_talloc_ctx(), NTTIME );
1314 }
1315
1316 /*******************************************************************
1317 reads or writes a structure.
1318 ********************************************************************/
1319
1320 BOOL reg_io_q_enum_key(const char *desc,  REG_Q_ENUM_KEY *q_u, prs_struct *ps, int depth)
1321 {
1322         if (q_u == NULL)
1323                 return False;
1324
1325         prs_debug(ps, depth, desc, "reg_io_q_enum_key");
1326         depth++;
1327
1328         if(!prs_align(ps))
1329                 return False;
1330         
1331         if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
1332                 return False;
1333         
1334         if(!prs_uint32("key_index", ps, depth, &q_u->key_index))
1335                 return False;
1336         if(!prs_uint16("key_name_len", ps, depth, &q_u->key_name_len))
1337                 return False;
1338         if(!prs_uint16("unknown_1", ps, depth, &q_u->unknown_1))
1339                 return False;
1340
1341         if(!prs_uint32("ptr1", ps, depth, &q_u->ptr1))
1342                 return False;
1343
1344         if (q_u->ptr1 != 0) {
1345                 if(!prs_uint32("unknown_2", ps, depth, &q_u->unknown_2))
1346                         return False;
1347                 if(!prs_uint8s(False, "pad1", ps, depth, q_u->pad1, sizeof(q_u->pad1)))
1348                         return False;
1349         }
1350
1351         if(!prs_uint32("ptr2", ps, depth, &q_u->ptr2))
1352                 return False;
1353
1354         if (q_u->ptr2 != 0) {
1355                 if(!prs_uint8s(False, "pad2", ps, depth, q_u->pad2, sizeof(q_u->pad2)))
1356                         return False;
1357         }
1358
1359         if(!prs_uint32("ptr3", ps, depth, &q_u->ptr3))
1360                 return False;
1361
1362         if (q_u->ptr3 != 0) {
1363                 if(!smb_io_time("", &q_u->time, ps, depth))
1364                         return False;
1365         }
1366
1367         return True;
1368 }
1369
1370 /*******************************************************************
1371 reads or writes a structure.
1372 ********************************************************************/
1373
1374 BOOL reg_io_r_enum_key(const char *desc,  REG_R_ENUM_KEY *q_u, prs_struct *ps, int depth)
1375 {
1376         if ( !q_u )
1377                 return False;
1378
1379         prs_debug(ps, depth, desc, "reg_io_r_enum_key");
1380         depth++;
1381
1382         if(!prs_align(ps))
1383                 return False;
1384         if ( !prs_unistr4( "keyname", ps, depth, &q_u->keyname ) )
1385                 return False;
1386         
1387         if(!prs_align(ps))
1388                 return False;
1389         if (!prs_pointer("class", ps, depth, (void**)&q_u->classname, sizeof(UNISTR4), (PRS_POINTER_CAST)prs_unistr4))
1390                 return False;
1391
1392         if(!prs_align(ps))
1393                 return False;
1394         if (!prs_pointer("time", ps, depth, (void**)&q_u->time, sizeof(NTTIME), (PRS_POINTER_CAST)smb_io_nttime))
1395                 return False;
1396
1397         if(!prs_align(ps))
1398                 return False;
1399         if(!prs_werror("status", ps, depth, &q_u->status))
1400                 return False;
1401
1402         return True;
1403 }
1404
1405 /*******************************************************************
1406 makes a structure.
1407 ********************************************************************/
1408
1409 void init_reg_q_open_entry(REG_Q_OPEN_ENTRY *q_u, POLICY_HND *pol,
1410                                 char *key_name, uint32 access_desired)
1411 {
1412         memcpy(&q_u->pol, pol, sizeof(q_u->pol));
1413
1414         init_unistr4(&q_u->name, key_name, UNI_STR_TERMINATE);
1415
1416         q_u->unknown_0 = 0x00000000;
1417         q_u->access = access_desired;
1418 }
1419
1420 /*******************************************************************
1421 reads or writes a structure.
1422 ********************************************************************/
1423
1424 BOOL reg_io_q_open_entry(const char *desc,  REG_Q_OPEN_ENTRY *q_u, prs_struct *ps, int depth)
1425 {
1426         if ( !q_u )
1427                 return False;
1428
1429         prs_debug(ps, depth, desc, "reg_io_q_open_entry");
1430         depth++;
1431
1432         if(!prs_align(ps))
1433                 return False;
1434         
1435         if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
1436                 return False;
1437         if(!prs_unistr4("name", ps, depth, &q_u->name))
1438                 return False;
1439
1440         if(!prs_align(ps))
1441                 return False;
1442         
1443         if(!prs_uint32("unknown_0        ", ps, depth, &q_u->unknown_0))
1444                 return False;
1445         if(!prs_uint32("access", ps, depth, &q_u->access))
1446                 return False;
1447
1448         return True;
1449 }
1450
1451 /*******************************************************************
1452  Inits a structure.
1453 ********************************************************************/
1454
1455 void init_reg_r_open_entry(REG_R_OPEN_ENTRY *r_u,
1456                            POLICY_HND *pol, WERROR werr)
1457 {
1458         if (W_ERROR_IS_OK(werr)) {
1459                 memcpy(&r_u->pol, pol, sizeof(r_u->pol));
1460         } else {
1461                 ZERO_STRUCT(r_u->pol);
1462         }
1463         r_u->status = werr;
1464 }
1465
1466 /*******************************************************************
1467 reads or writes a structure.
1468 ********************************************************************/
1469
1470 BOOL reg_io_r_open_entry(const char *desc,  REG_R_OPEN_ENTRY *r_u, prs_struct *ps, int depth)
1471 {
1472         if ( !r_u )
1473                 return False;
1474
1475         prs_debug(ps, depth, desc, "reg_io_r_open_entry");
1476         depth++;
1477
1478         if(!prs_align(ps))
1479                 return False;
1480         
1481         if(!smb_io_pol_hnd("", &r_u->pol, ps, depth))
1482                 return False;
1483
1484         if(!prs_werror("status", ps, depth, &r_u->status))
1485                 return False;
1486
1487         return True;
1488 }
1489
1490 /*******************************************************************
1491 Inits a structure.
1492 ********************************************************************/
1493
1494 void init_reg_q_shutdown(REG_Q_SHUTDOWN *q_u, const char *msg,
1495                         uint32 timeout, BOOL do_reboot, BOOL force)
1496 {
1497         q_u->server = TALLOC_P( get_talloc_ctx(), uint16 );
1498         *q_u->server = 0x1;
1499
1500         q_u->message = TALLOC_P( get_talloc_ctx(), UNISTR4 );
1501         init_unistr4( q_u->message, msg, UNI_FLAGS_NONE );
1502
1503         q_u->timeout = timeout;
1504
1505         q_u->reboot = do_reboot ? 1 : 0;
1506         q_u->force = force ? 1 : 0;
1507 }
1508
1509 /*******************************************************************
1510 Inits a REG_Q_SHUTDOWN_EX structure.
1511 ********************************************************************/
1512
1513 void init_reg_q_shutdown_ex(REG_Q_SHUTDOWN_EX * q_u_ex, const char *msg,
1514                         uint32 timeout, BOOL do_reboot, BOOL force, uint32 reason)
1515 {
1516         REG_Q_SHUTDOWN q_u;
1517         
1518         ZERO_STRUCT( q_u );
1519         
1520         init_reg_q_shutdown( &q_u, msg, timeout, do_reboot, force );
1521         
1522         /* steal memory */
1523         
1524         q_u_ex->server  = q_u.server;
1525         q_u_ex->message = q_u.message;
1526         
1527         q_u_ex->reboot  = q_u.reboot;
1528         q_u_ex->force   = q_u.force;
1529         
1530         q_u_ex->reason = reason;
1531 }
1532
1533 /*******************************************************************
1534 reads or writes a structure.
1535 ********************************************************************/
1536
1537 BOOL reg_io_q_shutdown(const char *desc, REG_Q_SHUTDOWN *q_u, prs_struct *ps,
1538                        int depth)
1539 {
1540         if ( !q_u )
1541                 return False;
1542
1543         prs_debug(ps, depth, desc, "reg_io_q_shutdown");
1544         depth++;
1545
1546         if (!prs_align(ps))
1547                 return False;
1548
1549         if (!prs_pointer("server", ps, depth, (void**)&q_u->server, sizeof(uint16), (PRS_POINTER_CAST)prs_uint16))
1550                 return False;
1551
1552         if (!prs_pointer("message", ps, depth, (void**)&q_u->message, sizeof(UNISTR4), (PRS_POINTER_CAST)prs_unistr4))
1553                 return False;
1554
1555         if (!prs_align(ps))
1556                 return False;
1557
1558         if (!prs_uint32("timeout", ps, depth, &(q_u->timeout)))
1559                 return False;
1560
1561         if (!prs_uint8("force  ", ps, depth, &(q_u->force)))
1562                 return False;
1563         if (!prs_uint8("reboot ", ps, depth, &(q_u->reboot)))
1564                 return False;
1565
1566
1567         return True;
1568 }
1569
1570 /*******************************************************************
1571 reads or writes a structure.
1572 ********************************************************************/
1573 BOOL reg_io_r_shutdown(const char *desc, REG_R_SHUTDOWN *r_u, prs_struct *ps,
1574                        int depth)
1575 {
1576         if ( !r_u )
1577                 return False;
1578
1579         prs_debug(ps, depth, desc, "reg_io_r_shutdown");
1580         depth++;
1581
1582         if(!prs_align(ps))
1583                 return False;
1584
1585         if(!prs_werror("status", ps, depth, &r_u->status))
1586                 return False;
1587
1588         return True;
1589 }
1590
1591 /*******************************************************************
1592 reads or writes a REG_Q_SHUTDOWN_EX structure.
1593 ********************************************************************/
1594
1595 BOOL reg_io_q_shutdown_ex(const char *desc, REG_Q_SHUTDOWN_EX *q_u, prs_struct *ps,
1596                        int depth)
1597 {
1598         if ( !q_u )
1599                 return False;
1600
1601         prs_debug(ps, depth, desc, "reg_io_q_shutdown_ex");
1602         depth++;
1603
1604         if (!prs_align(ps))
1605                 return False;
1606
1607         if (!prs_pointer("server", ps, depth, (void**)&q_u->server, sizeof(uint16), (PRS_POINTER_CAST)prs_uint16))
1608                 return False;
1609
1610         if (!prs_pointer("message", ps, depth, (void**)&q_u->message, sizeof(UNISTR4), (PRS_POINTER_CAST)prs_unistr4))
1611                 return False;
1612
1613         if (!prs_align(ps))
1614                 return False;
1615
1616         if (!prs_uint32("timeout", ps, depth, &(q_u->timeout)))
1617                 return False;
1618
1619         if (!prs_uint8("force  ", ps, depth, &(q_u->force)))
1620                 return False;
1621         if (!prs_uint8("reboot ", ps, depth, &(q_u->reboot)))
1622                 return False;
1623
1624         if (!prs_align(ps))
1625                 return False;
1626         if (!prs_uint32("reason", ps, depth, &(q_u->reason)))
1627                 return False;
1628
1629
1630         return True;
1631 }
1632
1633 /*******************************************************************
1634 reads or writes a REG_R_SHUTDOWN_EX structure.
1635 ********************************************************************/
1636 BOOL reg_io_r_shutdown_ex(const char *desc, REG_R_SHUTDOWN_EX *r_u, prs_struct *ps,
1637                        int depth)
1638 {
1639         if ( !r_u )
1640                 return False;
1641
1642         prs_debug(ps, depth, desc, "reg_io_r_shutdown_ex");
1643         depth++;
1644
1645         if(!prs_align(ps))
1646                 return False;
1647
1648         if(!prs_werror("status", ps, depth, &r_u->status))
1649                 return False;
1650
1651         return True;
1652 }
1653
1654
1655
1656 /*******************************************************************
1657 Inits a structure.
1658 ********************************************************************/
1659 void init_reg_q_abort_shutdown(REG_Q_ABORT_SHUTDOWN *q_u)
1660 {
1661         q_u->server = TALLOC_P( get_talloc_ctx(), uint16 );
1662         *q_u->server = 0x1;
1663 }
1664
1665 /*******************************************************************
1666 reads or writes a structure.
1667 ********************************************************************/
1668 BOOL reg_io_q_abort_shutdown(const char *desc, REG_Q_ABORT_SHUTDOWN *q_u,
1669                              prs_struct *ps, int depth)
1670 {
1671         if ( !q_u )
1672                 return False;
1673
1674         prs_debug(ps, depth, desc, "reg_io_q_abort_shutdown");
1675         depth++;
1676
1677         if (!prs_align(ps))
1678                 return False;
1679
1680         if (!prs_pointer("server", ps, depth, (void**)&q_u->server, sizeof(uint16), (PRS_POINTER_CAST)prs_uint16))
1681                 return False;
1682
1683         return True;
1684 }
1685
1686 /*******************************************************************
1687 reads or writes a structure.
1688 ********************************************************************/
1689 BOOL reg_io_r_abort_shutdown(const char *desc, REG_R_ABORT_SHUTDOWN *r_u,
1690                              prs_struct *ps, int depth)
1691 {
1692         if ( !r_u )
1693                 return False;
1694
1695         prs_debug(ps, depth, desc, "reg_io_r_abort_shutdown");
1696         depth++;
1697
1698         if (!prs_align(ps))
1699                 return False;
1700
1701         if (!prs_werror("status", ps, depth, &r_u->status))
1702                 return False;
1703
1704         return True;
1705 }