r6942: * merging the registry changes back to the 3.0 tree
[samba.git] / source3 / rpc_parse / parse_reg.c
index 83b55863eb1c134ce108748867fe796d9ce9f8f7..ce23d15a11ca224d72d8f2e98f57c4980ad1c95a 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
  *  Unix SMB/CIFS implementation.
  *  RPC Pipe client / server routines
  *  Copyright (C) Andrew Tridgell              1992-1997,
@@ -6,7 +6,8 @@
  *  Copyright (C) Paul Ashton                       1997.
  *  Copyright (C) Marc Jacobsen                     1999.
  *  Copyright (C) Simo Sorce                        2000.
- *  Copyright (C) Gerald Carter                     2002.
+ *  Copyright (C) Jeremy Cooper                     2004
+ *  Copyright (C) Gerald Carter                     2002-2005.
  *  
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
 #define DBGC_CLASS DBGC_RPC_PARSE
 
 /*******************************************************************
- Fill in a BUFFER2 for the data given a REGISTRY_VALUE
+ Fill in a REGVAL_BUFFER for the data given a REGISTRY_VALUE
  *******************************************************************/
 
-static uint32 reg_init_buffer2( BUFFER2 *buf2, REGISTRY_VALUE *val )
+static uint32 reg_init_regval_buffer( REGVAL_BUFFER *buf2, REGISTRY_VALUE *val )
 {
-       UNISTR2         unistr;
        uint32          real_size = 0;
-       char            *string;
-       char            *list = NULL;
-       char            *list2 = NULL;
        
        if ( !buf2 || !val )
                return 0;
                
-       real_size = val->size;
-               
-       switch (val->type )
-       {
-               case REG_SZ:
-                       string = (char*)val->data_p;
-                       DEBUG(10,("reg_init_buffer2: REG_SZ string => [%s]\n", string));
-                       
-                       init_unistr2( &unistr, (char*)val->data_p, strlen((char*)val->data_p)+1 );
-                       init_buffer2( buf2, (char*)unistr.buffer, unistr.uni_str_len*2 );
-                       real_size = unistr.uni_str_len*2;
-                       break;
-                       
-               case REG_MULTI_SZ:
-                       string = (char*)val->data_p;
-                       real_size = 0;
-                       while ( string && *string )
-                       {
-                               DEBUG(10,("reg_init_buffer2: REG_MULTI_SZ string => [%s], size => [%d]\n", string, real_size ));
-                               
-                               init_unistr2( &unistr, string, strlen(string)+1 );
-                               
-                               list2 = Realloc( list, real_size + unistr.uni_str_len*2 );
-                               if ( !list2 )
-                                       break;
-                               list = list2;
-                               
-                               memcpy( list+real_size, unistr.buffer, unistr.uni_str_len*2 );
-                               
-                               real_size += unistr.uni_str_len*2;
-                               
-                               string += strlen(string)+1;
-                       }
-                       
-                       list2 = Realloc( list, real_size + 2 );
-                       if ( !list2 )
-                               break;
-                       list = list2;
-                       list[real_size++] = 0x0;
-                       list[real_size++] = 0x0;
-                       
-                       init_buffer2( buf2, (char*)list, real_size );
-                       
-                       DEBUG(10,("reg_init_buffer2: REG_MULTI_SZ size => [%d]\n", real_size ));
-                       
-                       break;
-                       
-               case REG_BINARY:
-                       DEBUG(10,("reg_init_buffer2: REG_BINARY size => [%d]\n", val->size ));
-                       
-                       init_buffer2( buf2, val->data_p, val->size );
-                       break;
-                       
-               case REG_DWORD: 
-                       DEBUG(10,("reg_init_buffer2: REG_DWORD value => [%d]\n", *(uint32*)val->data_p));
-                       init_buffer2( buf2, val->data_p, val->size );
-                       break;
-                       
-               default:
-                       DEBUG(0,("reg_init_buffer2: Unsupported registry data type [%d]\n", val->type));
-                       break;
-       }
-       
-       SAFE_FREE( list );
+       real_size = regval_size(val);
+       init_regval_buffer( buf2, (unsigned char*)regval_data_p(val), real_size );
 
        return real_size;
 }
 
 /*******************************************************************
- Inits a structure.
+ Inits a hive connect request structure
 ********************************************************************/
 
-void init_reg_q_open_hkcr(REG_Q_OPEN_HKCR *q_o,
-                               uint16 unknown_0, uint32 level)
+void init_reg_q_open_hive( REG_Q_OPEN_HIVE *q_o, uint32 access_desired )
 {
-       q_o->ptr = 1;
-       q_o->unknown_0 = unknown_0;
-       q_o->unknown_1 = 0x0; /* random - changes */
-       q_o->level = level;
+       
+       q_o->server = TALLOC_P( get_talloc_ctx(), uint16);
+       *q_o->server = 0x1;
+       
+       q_o->access = access_desired;
 }
 
 /*******************************************************************
-reads or writes a structure.
+Marshalls a hive connect request
 ********************************************************************/
 
-BOOL reg_io_q_open_hkcr(char *desc,  REG_Q_OPEN_HKCR *r_q, prs_struct *ps, int depth)
+BOOL reg_io_q_open_hive(const char *desc, REG_Q_OPEN_HIVE *q_u,
+                        prs_struct *ps, int depth)
 {
-       if (r_q == NULL)
-               return False;
-
-       prs_debug(ps, depth, desc, "reg_io_q_open_hkcr");
+       prs_debug(ps, depth, desc, "reg_io_q_open_hive");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint32("ptr      ", ps, depth, &r_q->ptr))
-               return False;
-
-       if (r_q->ptr != 0) {
-               if(!prs_uint16("unknown_0", ps, depth, &r_q->unknown_0))
-                       return False;
-               if(!prs_uint16("unknown_1", ps, depth, &r_q->unknown_1))
-                       return False;
-               if(!prs_uint32("level    ", ps, depth, &r_q->level))
-                       return False;
-       }
-
-       return True;
-}
-
-
-/*******************************************************************
-reads or writes a structure.
-********************************************************************/
-
-BOOL reg_io_r_open_hkcr(char *desc,  REG_R_OPEN_HKCR *r_r, prs_struct *ps, int depth)
-{
-       if (r_r == NULL)
+       if(!prs_pointer("server", ps, depth, (void**)&q_u->server, sizeof(uint16), (PRS_POINTER_CAST)prs_uint16))
                return False;
 
-       prs_debug(ps, depth, desc, "reg_io_r_open_hkcr");
-       depth++;
-
        if(!prs_align(ps))
                return False;
-       
-       if(!smb_io_pol_hnd("", &r_r->pol, ps, depth))
-               return False;
-
-       if(!prs_ntstatus("status", ps, depth, &r_r->status))
+       if(!prs_uint32("access", ps, depth, &q_u->access))
                return False;
 
        return True;
 }
 
-/*******************************************************************
- Inits a structure.
-********************************************************************/
-
-void init_reg_q_open_hklm(REG_Q_OPEN_HKLM * q_o,
-                         uint16 unknown_0, uint32 access_mask)
-{
-       q_o->ptr = 1;
-       q_o->unknown_0 = unknown_0;
-       q_o->unknown_1 = 0x0;   /* random - changes */
-       q_o->access_mask = access_mask;
-
-}
 
 /*******************************************************************
-reads or writes a structure.
+Unmarshalls a hive connect response
 ********************************************************************/
-BOOL reg_io_q_open_hklm(char *desc, REG_Q_OPEN_HKLM * r_q, prs_struct *ps,
-                       int depth)
-{
-       if (r_q == NULL)
-               return False;
-
-       prs_debug(ps, depth, desc, "reg_io_q_open_hklm");
-       depth++;
 
-       if (!prs_align(ps))
-               return False;
-
-       if (!prs_uint32("ptr      ", ps, depth, &(r_q->ptr)))
-               return False;
-       if (r_q->ptr != 0)
-       {
-               if (!prs_uint16("unknown_0", ps, depth, &(r_q->unknown_0)))
-                       return False;
-               if (!prs_uint16("unknown_1", ps, depth, &(r_q->unknown_1)))
-                       return False;
-               if (!prs_uint32("access_mask", ps, depth, &(r_q->access_mask)))
-                       return False;
-       }
-
-       return True;
-}
-
-
-/*******************************************************************
-reads or writes a structure.
-********************************************************************/
-BOOL reg_io_r_open_hklm(char *desc, REG_R_OPEN_HKLM * r_r, prs_struct *ps,
-                       int depth)
+BOOL reg_io_r_open_hive(const char *desc,  REG_R_OPEN_HIVE *r_u,
+                        prs_struct *ps, int depth)
 {
-       if (r_r == NULL)
+       if ( !r_u )
                return False;
 
-       prs_debug(ps, depth, desc, "reg_io_r_open_hklm");
+       prs_debug(ps, depth, desc, "reg_io_r_open_hive");
        depth++;
 
-       if (!prs_align(ps))
+       if(!prs_align(ps))
                return False;
-
-       if (!smb_io_pol_hnd("", &r_r->pol, ps, depth))
+       
+       if(!smb_io_pol_hnd("", &r_u->pol, ps, depth))
                return False;
 
-       if (!prs_ntstatus("status", ps, depth, &r_r->status))
+       if(!prs_werror("status", ps, depth, &r_u->status))
                return False;
 
        return True;
 }
 
-
-
-
 /*******************************************************************
  Inits a structure.
 ********************************************************************/
@@ -264,9 +122,9 @@ void init_reg_q_flush_key(REG_Q_FLUSH_KEY *q_u, POLICY_HND *pol)
 reads or writes a structure.
 ********************************************************************/
 
-BOOL reg_io_q_flush_key(char *desc,  REG_Q_FLUSH_KEY *r_q, prs_struct *ps, int depth)
+BOOL reg_io_q_flush_key(const char *desc,  REG_Q_FLUSH_KEY *q_u, prs_struct *ps, int depth)
 {
-       if (r_q == NULL)
+       if ( !q_u )
                return False;
 
        prs_debug(ps, depth, desc, "reg_io_q_flush_key");
@@ -275,19 +133,20 @@ BOOL reg_io_q_flush_key(char *desc,  REG_Q_FLUSH_KEY *r_q, prs_struct *ps, int d
        if(!prs_align(ps))
                return False;
        
-       if(!smb_io_pol_hnd("", &r_q->pol, ps, depth))
+       if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
                return False;
 
        return True;
 }
 
 /*******************************************************************
-reads or writes a structure.
+Unmarshalls a registry key flush response
 ********************************************************************/
 
-BOOL reg_io_r_flush_key(char *desc,  REG_R_FLUSH_KEY *r_r, prs_struct *ps, int depth)
+BOOL reg_io_r_flush_key(const char *desc,  REG_R_FLUSH_KEY *r_u,
+                        prs_struct *ps, int depth)
 {
-       if (r_r == NULL)
+       if ( !r_u )
                return False;
 
        prs_debug(ps, depth, desc, "reg_io_r_flush_key");
@@ -296,7 +155,7 @@ BOOL reg_io_r_flush_key(char *desc,  REG_R_FLUSH_KEY *r_r, prs_struct *ps, int d
        if(!prs_align(ps))
                return False;
        
-       if(!prs_ntstatus("status", ps, depth, &r_r->status))
+       if(!prs_werror("status", ps, depth, &r_u->status))
                return False;
 
        return True;
@@ -306,12 +165,14 @@ BOOL reg_io_r_flush_key(char *desc,  REG_R_FLUSH_KEY *r_r, prs_struct *ps, int d
 reads or writes SEC_DESC_BUF and SEC_DATA structures.
 ********************************************************************/
 
-static BOOL reg_io_hdrbuf_sec(uint32 ptr, uint32 *ptr3, BUFHDR *hdr_sec, SEC_DESC_BUF *data, prs_struct *ps, int depth)
+static BOOL reg_io_hdrbuf_sec(uint32 ptr, uint32 *ptr3, BUFHDR *hdr_sec,
+                              SEC_DESC_BUF *data, prs_struct *ps, int depth)
 {
        if (ptr != 0) {
                uint32 hdr_offset;
                uint32 old_offset;
-               if(!smb_io_hdrbuf_pre("hdr_sec", hdr_sec, ps, depth, &hdr_offset))
+               if(!smb_io_hdrbuf_pre("hdr_sec", hdr_sec, ps, depth,
+                                     &hdr_offset))
                        return False;
 
                old_offset = prs_offset(ps);
@@ -322,14 +183,16 @@ static BOOL reg_io_hdrbuf_sec(uint32 ptr, uint32 *ptr3, BUFHDR *hdr_sec, SEC_DES
                }
 
                if (ptr3 == NULL || *ptr3 != 0) {
-                       if(!sec_io_desc_buf("data   ", &data, ps, depth)) /* JRA - this line is probably wrong... */
+                       /* JRA - this next line is probably wrong... */
+                       if(!sec_io_desc_buf("data   ", &data, ps, depth))
                                return False;
                }
 
-               if(!smb_io_hdrbuf_post("hdr_sec", hdr_sec, ps, depth, hdr_offset,
-                                  data->max_len, data->len))
+               if(!smb_io_hdrbuf_post("hdr_sec", hdr_sec, ps, depth,
+                                      hdr_offset, data->max_len, data->len))
                                return False;
-               if(!prs_set_offset(ps, old_offset + data->len + sizeof(uint32) * ((ptr3 != NULL) ? 5 : 3)))
+               if(!prs_set_offset(ps, old_offset + data->len +
+                                      sizeof(uint32) * ((ptr3 != NULL) ? 5 : 3)))
                        return False;
 
                if(!prs_align(ps))
@@ -340,31 +203,25 @@ static BOOL reg_io_hdrbuf_sec(uint32 ptr, uint32 *ptr3, BUFHDR *hdr_sec, SEC_DES
 }
 
 /*******************************************************************
- Inits a structure.
+ Inits a registry key create request
 ********************************************************************/
 
 void init_reg_q_create_key(REG_Q_CREATE_KEY *q_c, POLICY_HND *hnd,
-                               char *name, char *class, SEC_ACCESS *sam_access,
-                               SEC_DESC_BUF *sec_buf)
+                           char *name, char *class, uint32 access_desired,
+                           SEC_DESC_BUF *sec_buf)
 {
-       int len_name  = name  != NULL ? strlen(name ) + 1: 0;
-       int len_class = class != NULL ? strlen(class) + 1: 0;
-
        ZERO_STRUCTP(q_c);
 
        memcpy(&q_c->pnt_pol, hnd, sizeof(q_c->pnt_pol));
 
-       init_uni_hdr(&q_c->hdr_name, len_name);
-       init_unistr2(&q_c->uni_name, name, len_name);
 
-       init_uni_hdr(&q_c->hdr_class, len_class);
-       init_unistr2(&q_c->uni_class, class, len_class);
+       init_unistr4( &q_c->name, name, UNI_STR_TERMINATE );
+       init_unistr4( &q_c->class, class, UNI_STR_TERMINATE );
 
-       q_c->reserved = 0x00000000;
-       memcpy(&q_c->sam_access, sam_access, sizeof(q_c->sam_access));
+       q_c->access = access_desired;
 
-       q_c->ptr1 = 1;
-       q_c->sec_info = DACL_SECURITY_INFORMATION | SACL_SECURITY_INFORMATION;
+       q_c->sec_info = TALLOC_P( get_talloc_ctx(), uint32 );
+       *q_c->sec_info = DACL_SECURITY_INFORMATION | SACL_SECURITY_INFORMATION;
 
        q_c->data = sec_buf;
        q_c->ptr2 = 1;
@@ -374,12 +231,13 @@ void init_reg_q_create_key(REG_Q_CREATE_KEY *q_c, POLICY_HND *hnd,
 }
 
 /*******************************************************************
-reads or writes a structure.
+Marshalls a registry key create request
 ********************************************************************/
 
-BOOL reg_io_q_create_key(char *desc,  REG_Q_CREATE_KEY *r_q, prs_struct *ps, int depth)
+BOOL reg_io_q_create_key(const char *desc,  REG_Q_CREATE_KEY *q_u,
+                         prs_struct *ps, int depth)
 {
-       if (r_q == NULL)
+       if ( !q_u )
                return False;
 
        prs_debug(ps, depth, desc, "reg_io_q_create_key");
@@ -388,54 +246,49 @@ BOOL reg_io_q_create_key(char *desc,  REG_Q_CREATE_KEY *r_q, prs_struct *ps, int
        if(!prs_align(ps))
                return False;
        
-       if(!smb_io_pol_hnd("", &r_q->pnt_pol, ps, depth))
+       if(!smb_io_pol_hnd("", &q_u->pnt_pol, ps, depth))
                return False;
 
-       if(!smb_io_unihdr ("", &r_q->hdr_name, ps, depth))
-               return False;
-       if(!smb_io_unistr2("", &r_q->uni_name, r_q->hdr_name.buffer, ps, depth))
+       if(!prs_unistr4 ("name", ps, depth, &q_u->name))
                return False;
        if(!prs_align(ps))
                return False;
 
-       if(!smb_io_unihdr ("", &r_q->hdr_class, ps, depth))
-               return False;
-       if(!smb_io_unistr2("", &r_q->uni_class, r_q->hdr_class.buffer, ps, depth))
+       if(!prs_unistr4 ("class", ps, depth, &q_u->class))
                return False;
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint32("reserved", ps, depth, &r_q->reserved))
+       if(!prs_uint32("reserved", ps, depth, &q_u->reserved))
                return False;
-       if(!sec_io_access("sam_access", &r_q->sam_access, ps, depth))
+       if(!prs_uint32("access", ps, depth, &q_u->access))
                return False;
 
-       if(!prs_uint32("ptr1", ps, depth, &r_q->ptr1))
+       if(!prs_pointer("sec_info", ps, depth, (void**)&q_u->sec_info, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
                return False;
 
-       if (r_q->ptr1 != 0) {
-               if(!prs_uint32("sec_info", ps, depth, &r_q->sec_info))
-                       return False;
-       }
-
-       if(!prs_uint32("ptr2", ps, depth, &r_q->ptr2))
+       if(!prs_uint32("ptr2", ps, depth, &q_u->ptr2))
                return False;
-       if(!reg_io_hdrbuf_sec(r_q->ptr2, &r_q->ptr3, &r_q->hdr_sec, r_q->data, ps, depth))
+       if(!reg_io_hdrbuf_sec(q_u->ptr2, &q_u->ptr3, &q_u->hdr_sec, q_u->data,
+                             ps, depth))
                return False;
 
-       if(!prs_uint32("unknown_2", ps, depth, &r_q->unknown_2))
+#if 0
+       if(!prs_uint32("unknown_2", ps, depth, &q_u->unknown_2))
                return False;
+#endif
 
        return True;
 }
 
 /*******************************************************************
-reads or writes a structure.
+Unmarshalls a registry key create response
 ********************************************************************/
 
-BOOL reg_io_r_create_key(char *desc,  REG_R_CREATE_KEY *r_r, prs_struct *ps, int depth)
+BOOL reg_io_r_create_key(const char *desc,  REG_R_CREATE_KEY *r_u,
+                         prs_struct *ps, int depth)
 {
-       if (r_r == NULL)
+       if ( !r_u )
                return False;
 
        prs_debug(ps, depth, desc, "reg_io_r_create_key");
@@ -444,12 +297,12 @@ BOOL reg_io_r_create_key(char *desc,  REG_R_CREATE_KEY *r_r, prs_struct *ps, int
        if(!prs_align(ps))
                return False;
        
-       if(!smb_io_pol_hnd("", &r_r->key_pol, ps, depth))
+       if(!smb_io_pol_hnd("", &r_u->key_pol, ps, depth))
                return False;
-       if(!prs_uint32("unknown", ps, depth, &r_r->unknown))
+       if(!prs_uint32("unknown", ps, depth, &r_u->unknown))
                return False;
 
-       if(!prs_ntstatus("status", ps, depth, &r_r->status))
+       if(!prs_werror("status", ps, depth, &r_u->status))
                return False;
 
        return True;
@@ -461,24 +314,22 @@ BOOL reg_io_r_create_key(char *desc,  REG_R_CREATE_KEY *r_r, prs_struct *ps, int
 ********************************************************************/
 
 void init_reg_q_delete_val(REG_Q_DELETE_VALUE *q_c, POLICY_HND *hnd,
-                               char *name)
+                           char *name)
 {
-       int len_name  = name  != NULL ? strlen(name ) + 1: 0;
        ZERO_STRUCTP(q_c);
 
        memcpy(&q_c->pnt_pol, hnd, sizeof(q_c->pnt_pol));
-
-       init_uni_hdr(&q_c->hdr_name, len_name);
-       init_unistr2(&q_c->uni_name, name, len_name);
+       init_unistr4(&q_c->name, name, UNI_STR_TERMINATE);
 }
 
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
 
-BOOL reg_io_q_delete_val(char *desc,  REG_Q_DELETE_VALUE *r_q, prs_struct *ps, int depth)
+BOOL reg_io_q_delete_val(const char *desc, REG_Q_DELETE_VALUE *q_u,
+                         prs_struct *ps, int depth)
 {
-       if (r_q == NULL)
+       if ( !q_u )
                return False;
 
        prs_debug(ps, depth, desc, "reg_io_q_delete_val");
@@ -487,12 +338,10 @@ BOOL reg_io_q_delete_val(char *desc,  REG_Q_DELETE_VALUE *r_q, prs_struct *ps, i
        if(!prs_align(ps))
                return False;
        
-       if(!smb_io_pol_hnd("", &r_q->pnt_pol, ps, depth))
+       if(!smb_io_pol_hnd("", &q_u->pnt_pol, ps, depth))
                return False;
 
-       if(!smb_io_unihdr ("", &r_q->hdr_name, ps, depth))
-               return False;
-       if(!smb_io_unistr2("", &r_q->uni_name, r_q->hdr_name.buffer, ps, depth))
+       if(!prs_unistr4("name", ps, depth, &q_u->name))
                return False;
        if(!prs_align(ps))
                return False;
@@ -505,9 +354,10 @@ BOOL reg_io_q_delete_val(char *desc,  REG_Q_DELETE_VALUE *r_q, prs_struct *ps, i
 reads or writes a structure.
 ********************************************************************/
 
-BOOL reg_io_r_delete_val(char *desc,  REG_R_DELETE_VALUE *r_r, prs_struct *ps, int depth)
+BOOL reg_io_r_delete_val(const char *desc,  REG_R_DELETE_VALUE *r_u,
+                         prs_struct *ps, int depth)
 {
-       if (r_r == NULL)
+       if ( !r_u )
                return False;
 
        prs_debug(ps, depth, desc, "reg_io_r_delete_val");
@@ -516,7 +366,7 @@ BOOL reg_io_r_delete_val(char *desc,  REG_R_DELETE_VALUE *r_r, prs_struct *ps, i
        if(!prs_align(ps))
                return False;
        
-       if(!prs_ntstatus("status", ps, depth, &r_r->status))
+       if(!prs_werror("status", ps, depth, &r_u->status))
                return False;
 
        return True;
@@ -527,24 +377,23 @@ BOOL reg_io_r_delete_val(char *desc,  REG_R_DELETE_VALUE *r_r, prs_struct *ps, i
 ********************************************************************/
 
 void init_reg_q_delete_key(REG_Q_DELETE_KEY *q_c, POLICY_HND *hnd,
-                               char *name)
+                           char *name)
 {
-       int len_name  = name  != NULL ? strlen(name ) + 1: 0;
        ZERO_STRUCTP(q_c);
 
        memcpy(&q_c->pnt_pol, hnd, sizeof(q_c->pnt_pol));
 
-       init_uni_hdr(&q_c->hdr_name, len_name);
-       init_unistr2(&q_c->uni_name, name, len_name);
+       init_unistr4(&q_c->name, name, UNI_STR_TERMINATE);
 }
 
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
 
-BOOL reg_io_q_delete_key(char *desc,  REG_Q_DELETE_KEY *r_q, prs_struct *ps, int depth)
+BOOL reg_io_q_delete_key(const char *desc,  REG_Q_DELETE_KEY *q_u,
+                         prs_struct *ps, int depth)
 {
-       if (r_q == NULL)
+       if ( !q_u )
                return False;
 
        prs_debug(ps, depth, desc, "reg_io_q_delete_key");
@@ -553,12 +402,10 @@ BOOL reg_io_q_delete_key(char *desc,  REG_Q_DELETE_KEY *r_q, prs_struct *ps, int
        if(!prs_align(ps))
                return False;
        
-       if(!smb_io_pol_hnd("", &r_q->pnt_pol, ps, depth))
+       if(!smb_io_pol_hnd("", &q_u->pnt_pol, ps, depth))
                return False;
 
-       if(!smb_io_unihdr ("", &r_q->hdr_name, ps, depth))
-               return False;
-       if(!smb_io_unistr2("", &r_q->uni_name, r_q->hdr_name.buffer, ps, depth))
+       if(!prs_unistr4("", ps, depth, &q_u->name))
                return False;
        if(!prs_align(ps))
                return False;
@@ -570,9 +417,9 @@ BOOL reg_io_q_delete_key(char *desc,  REG_Q_DELETE_KEY *r_q, prs_struct *ps, int
 reads or writes a structure.
 ********************************************************************/
 
-BOOL reg_io_r_delete_key(char *desc,  REG_R_DELETE_KEY *r_r, prs_struct *ps, int depth)
+BOOL reg_io_r_delete_key(const char *desc,  REG_R_DELETE_KEY *r_u, prs_struct *ps, int depth)
 {
-       if (r_r == NULL)
+       if ( !r_u )
                return False;
 
        prs_debug(ps, depth, desc, "reg_io_r_delete_key");
@@ -581,7 +428,7 @@ BOOL reg_io_r_delete_key(char *desc,  REG_R_DELETE_KEY *r_r, prs_struct *ps, int
        if(!prs_align(ps))
                return False;
        
-       if(!prs_ntstatus("status", ps, depth, &r_r->status))
+       if(!prs_werror("status", ps, depth, &r_u->status))
                return False;
 
        return True;
@@ -591,23 +438,21 @@ BOOL reg_io_r_delete_key(char *desc,  REG_R_DELETE_KEY *r_r, prs_struct *ps, int
  Inits a structure.
 ********************************************************************/
 
-void init_reg_q_query_key(REG_Q_QUERY_KEY *q_o, POLICY_HND *hnd,
-                               uint32 max_class_len)
+void init_reg_q_query_key(REG_Q_QUERY_KEY *q_o, POLICY_HND *hnd, const char *class)
 {
        ZERO_STRUCTP(q_o);
 
        memcpy(&q_o->pol, hnd, sizeof(q_o->pol));
-       init_uni_hdr(&q_o->hdr_class, max_class_len);
-       q_o->uni_class.uni_max_len = max_class_len;
+       init_unistr4(&q_o->class, class, UNI_STR_TERMINATE);
 }
 
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
 
-BOOL reg_io_q_query_key(char *desc,  REG_Q_QUERY_KEY *r_q, prs_struct *ps, int depth)
+BOOL reg_io_q_query_key(const char *desc,  REG_Q_QUERY_KEY *q_u, prs_struct *ps, int depth)
 {
-       if (r_q == NULL)
+       if ( !q_u )
                return False;
 
        prs_debug(ps, depth, desc, "reg_io_q_query_key");
@@ -616,11 +461,9 @@ BOOL reg_io_q_query_key(char *desc,  REG_Q_QUERY_KEY *r_q, prs_struct *ps, int d
        if(!prs_align(ps))
                return False;
        
-       if(!smb_io_pol_hnd("", &r_q->pol, ps, depth))
-               return False;
-       if(!smb_io_unihdr ("", &r_q->hdr_class, ps, depth))
+       if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
                return False;
-       if(!smb_io_unistr2("", &r_q->uni_class, r_q->hdr_class.buffer, ps, depth))
+       if(!prs_unistr4("class", ps, depth, &q_u->class))
                return False;
 
        if(!prs_align(ps))
@@ -634,9 +477,9 @@ BOOL reg_io_q_query_key(char *desc,  REG_Q_QUERY_KEY *r_q, prs_struct *ps, int d
 reads or writes a structure.
 ********************************************************************/
 
-BOOL reg_io_r_query_key(char *desc,  REG_R_QUERY_KEY *r_r, prs_struct *ps, int depth)
+BOOL reg_io_r_query_key(const char *desc,  REG_R_QUERY_KEY *r_u, prs_struct *ps, int depth)
 {
-       if (r_r == NULL)
+       if ( !r_u )
                return False;
 
        prs_debug(ps, depth, desc, "reg_io_r_query_key");
@@ -645,32 +488,30 @@ BOOL reg_io_r_query_key(char *desc,  REG_R_QUERY_KEY *r_r, prs_struct *ps, int d
        if(!prs_align(ps))
                return False;
        
-       if(!smb_io_unihdr ("", &r_r->hdr_class, ps, depth))
-               return False;
-       if(!smb_io_unistr2("", &r_r->uni_class, r_r->hdr_class.buffer, ps, depth))
+       if(!prs_unistr4("class", ps, depth, &r_u->class))
                return False;
 
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint32("num_subkeys   ", ps, depth, &r_r->num_subkeys))
+       if(!prs_uint32("num_subkeys   ", ps, depth, &r_u->num_subkeys))
                return False;
-       if(!prs_uint32("max_subkeylen ", ps, depth, &r_r->max_subkeylen))
+       if(!prs_uint32("max_subkeylen ", ps, depth, &r_u->max_subkeylen))
                return False;
-       if(!prs_uint32("reserved      ", ps, depth, &r_r->reserved))
+       if(!prs_uint32("reserved      ", ps, depth, &r_u->reserved))
                return False;
-       if(!prs_uint32("num_values    ", ps, depth, &r_r->num_values))
+       if(!prs_uint32("num_values    ", ps, depth, &r_u->num_values))
                return False;
-       if(!prs_uint32("max_valnamelen", ps, depth, &r_r->max_valnamelen))
+       if(!prs_uint32("max_valnamelen", ps, depth, &r_u->max_valnamelen))
                return False;
-       if(!prs_uint32("max_valbufsize", ps, depth, &r_r->max_valbufsize))
+       if(!prs_uint32("max_valbufsize", ps, depth, &r_u->max_valbufsize))
                return False;
-       if(!prs_uint32("sec_desc      ", ps, depth, &r_r->sec_desc))
+       if(!prs_uint32("sec_desc      ", ps, depth, &r_u->sec_desc))
                return False;
-       if(!smb_io_time("mod_time     ", &r_r->mod_time, ps, depth))
+       if(!smb_io_time("mod_time     ", &r_u->mod_time, ps, depth))
                return False;
-       
-       if(!prs_ntstatus("status", ps, depth, &r_r->status))
+
+       if(!prs_werror("status", ps, depth, &r_u->status))
                return False;
 
        return True;
@@ -680,27 +521,28 @@ BOOL reg_io_r_query_key(char *desc,  REG_R_QUERY_KEY *r_r, prs_struct *ps, int d
  Inits a structure.
 ********************************************************************/
 
-void init_reg_q_unknown_1a(REG_Q_UNKNOWN_1A *q_o, POLICY_HND *hnd)
+void init_reg_q_getversion(REG_Q_GETVERSION *q_o, POLICY_HND *hnd)
 {
        memcpy(&q_o->pol, hnd, sizeof(q_o->pol));
 }
 
+
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
 
-BOOL reg_io_q_unknown_1a(char *desc,  REG_Q_UNKNOWN_1A *r_q, prs_struct *ps, int depth)
+BOOL reg_io_q_getversion(const char *desc,  REG_Q_GETVERSION *q_u, prs_struct *ps, int depth)
 {
-       if (r_q == NULL)
+       if ( !q_u )
                return False;
 
-       prs_debug(ps, depth, desc, "reg_io_q_unknown_1a");
+       prs_debug(ps, depth, desc, "reg_io_q_getversion");
        depth++;
 
        if(!prs_align(ps))
                return False;
-       
-       if(!smb_io_pol_hnd("", &r_q->pol, ps, depth))
+
+       if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
                return False;
 
        return True;
@@ -710,63 +552,70 @@ BOOL reg_io_q_unknown_1a(char *desc,  REG_Q_UNKNOWN_1A *r_q, prs_struct *ps, int
 reads or writes a structure.
 ********************************************************************/
 
-BOOL reg_io_r_unknown_1a(char *desc,  REG_R_UNKNOWN_1A *r_r, prs_struct *ps, int depth)
+BOOL reg_io_r_getversion(const char *desc,  REG_R_GETVERSION *r_u, prs_struct *ps, int depth)
 {
-       if (r_r == NULL)
+       if ( !r_u )
                return False;
 
-       prs_debug(ps, depth, desc, "reg_io_r_unknown_1a");
+       prs_debug(ps, depth, desc, "reg_io_r_getversion");
        depth++;
 
        if(!prs_align(ps))
                return False;
-       
-       if(!prs_uint32("unknown", ps, depth, &r_r->unknown))
+
+       if(!prs_uint32("unknown", ps, depth, &r_u->unknown))
                return False;
-       if(!prs_ntstatus("status" , ps, depth, &r_r->status))
+       if(!prs_werror("status" , ps, depth, &r_u->status))
                return False;
 
        return True;
 }
 
+
 /*******************************************************************
- Inits a structure.
+reads or writes a structure.
 ********************************************************************/
 
-void init_reg_q_open_hku(REG_Q_OPEN_HKU *q_o,
-                               uint16 unknown_0, uint32 access_mask)
+BOOL reg_io_q_restore_key(const char *desc,  REG_Q_RESTORE_KEY *q_u, prs_struct *ps, int depth)
 {
-       q_o->ptr = 1;
-       q_o->unknown_0 = unknown_0;
-       q_o->unknown_1 = 0x0; /* random - changes */
-       q_o->access_mask = access_mask;
+       if ( !q_u )
+               return False;
+
+       prs_debug(ps, depth, desc, "reg_io_q_restore_key");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
+               return False;
+
+       if(!prs_unistr4("filename", ps, depth, &q_u->filename))
+               return False;
+
+       if(!prs_uint32("flags", ps, depth, &q_u->flags))
+               return False;
+
+       return True;
 }
 
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
 
-BOOL reg_io_q_open_hku(char *desc,  REG_Q_OPEN_HKU *r_q, prs_struct *ps, int depth)
+BOOL reg_io_r_restore_key(const char *desc,  REG_R_RESTORE_KEY *r_u, prs_struct *ps, int depth)
 {
-       if (r_q == NULL)
+       if ( !r_u )
                return False;
 
-       prs_debug(ps, depth, desc, "reg_io_q_open_hku");
+       prs_debug(ps, depth, desc, "reg_io_r_restore_key");
        depth++;
 
        if(!prs_align(ps))
                return False;
        
-       if(!prs_uint32("ptr      ", ps, depth, &r_q->ptr))
+       if(!prs_werror("status" , ps, depth, &r_u->status))
                return False;
-       if (r_q->ptr != 0) {
-               if(!prs_uint16("unknown_0   ", ps, depth, &r_q->unknown_0))
-                       return False;
-               if(!prs_uint16("unknown_1   ", ps, depth, &r_q->unknown_1))
-                       return False;
-               if(!prs_uint32("access_mask ", ps, depth, &r_q->access_mask))
-                       return False;
-       }
 
        return True;
 }
@@ -775,21 +624,47 @@ BOOL reg_io_q_open_hku(char *desc,  REG_Q_OPEN_HKU *r_q, prs_struct *ps, int dep
 reads or writes a structure.
 ********************************************************************/
 
-BOOL reg_io_r_open_hku(char *desc,  REG_R_OPEN_HKU *r_r, prs_struct *ps, int depth)
+BOOL reg_io_q_save_key(const char *desc,  REG_Q_SAVE_KEY *q_u, prs_struct *ps, int depth)
 {
-       if (r_r == NULL)
+       if ( !q_u )
                return False;
 
-       prs_debug(ps, depth, desc, "reg_io_r_open_hku");
+       prs_debug(ps, depth, desc, "reg_io_q_save_key");
        depth++;
 
        if(!prs_align(ps))
                return False;
-       
-       if(!smb_io_pol_hnd("", &r_r->pol, ps, depth))
+
+       if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
                return False;
 
-       if(!prs_ntstatus("status", ps, depth, &r_r->status))
+       if(!prs_unistr4("filename", ps, depth, &q_u->filename))
+               return False;
+
+#if 0  /* reg_io_sec_attr() */
+       if(!prs_uint32("unknown", ps, depth, &q_u->unknown))
+               return False;
+#endif
+
+       return True;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL reg_io_r_save_key(const char *desc,  REG_R_SAVE_KEY *r_u, prs_struct *ps, int depth)
+{
+       if ( !r_u )
+               return False;
+
+       prs_debug(ps, depth, desc, "reg_io_r_save_key");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+       
+       if(!prs_werror("status" , ps, depth, &r_u->status))
                return False;
 
        return True;
@@ -810,7 +685,7 @@ void init_reg_q_close(REG_Q_CLOSE *q_c, POLICY_HND *hnd)
 reads or writes a structure.
 ********************************************************************/
 
-BOOL reg_io_q_close(char *desc,  REG_Q_CLOSE *q_u, prs_struct *ps, int depth)
+BOOL reg_io_q_close(const char *desc,  REG_Q_CLOSE *q_u, prs_struct *ps, int depth)
 {
        if (q_u == NULL)
                return False;
@@ -833,9 +708,9 @@ BOOL reg_io_q_close(char *desc,  REG_Q_CLOSE *q_u, prs_struct *ps, int depth)
 reads or writes a structure.
 ********************************************************************/
 
-BOOL reg_io_r_close(char *desc,  REG_R_CLOSE *r_u, prs_struct *ps, int depth)
+BOOL reg_io_r_close(const char *desc,  REG_R_CLOSE *r_u, prs_struct *ps, int depth)
 {
-       if (r_u == NULL)
+       if ( !r_u )
                return False;
 
        prs_debug(ps, depth, desc, "reg_io_r_close");
@@ -849,7 +724,7 @@ BOOL reg_io_r_close(char *desc,  REG_R_CLOSE *r_u, prs_struct *ps, int depth)
        if(!prs_align(ps))
                return False;
 
-       if(!prs_ntstatus("status", ps, depth, &r_u->status))
+       if(!prs_werror("status", ps, depth, &r_u->status))
                return False;
 
        return True;
@@ -859,24 +734,25 @@ BOOL reg_io_r_close(char *desc,  REG_R_CLOSE *r_u, prs_struct *ps, int depth)
 makes a structure.
 ********************************************************************/
 
-void init_reg_q_set_key_sec(REG_Q_SET_KEY_SEC *q_i, POLICY_HND *pol, SEC_DESC_BUF *sec_desc_buf)
+void init_reg_q_set_key_sec(REG_Q_SET_KEY_SEC *q_u, POLICY_HND *pol,
+                            uint32 sec_info, SEC_DESC_BUF *sec_desc_buf)
 {
-       memcpy(&q_i->pol, pol, sizeof(q_i->pol));
+       memcpy(&q_u->pol, pol, sizeof(q_u->pol));
 
-       q_i->sec_info = DACL_SECURITY_INFORMATION;
+       q_u->sec_info = sec_info;
 
-       q_i->ptr = 1;
-       init_buf_hdr(&q_i->hdr_sec, sec_desc_buf->len, sec_desc_buf->len);
-       q_i->data = sec_desc_buf;
+       q_u->ptr = 1;
+       init_buf_hdr(&q_u->hdr_sec, sec_desc_buf->len, sec_desc_buf->len);
+       q_u->data = sec_desc_buf;
 }
 
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
 
-BOOL reg_io_q_set_key_sec(char *desc,  REG_Q_SET_KEY_SEC *r_q, prs_struct *ps, int depth)
+BOOL reg_io_q_set_key_sec(const char *desc,  REG_Q_SET_KEY_SEC *q_u, prs_struct *ps, int depth)
 {
-       if (r_q == NULL)
+       if ( !q_u )
                return False;
 
        prs_debug(ps, depth, desc, "reg_io_q_set_key_sec");
@@ -885,15 +761,15 @@ BOOL reg_io_q_set_key_sec(char *desc,  REG_Q_SET_KEY_SEC *r_q, prs_struct *ps, i
        if(!prs_align(ps))
                return False;
        
-       if(!smb_io_pol_hnd("", &r_q->pol, ps, depth))
+       if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
                return False;
 
-       if(!prs_uint32("sec_info", ps, depth, &r_q->sec_info))
+       if(!prs_uint32("sec_info", ps, depth, &q_u->sec_info))
                return False;
-       if(!prs_uint32("ptr    ", ps, depth, &r_q->ptr))
+       if(!prs_uint32("ptr    ", ps, depth, &q_u->ptr))
                return False;
 
-       if(!reg_io_hdrbuf_sec(r_q->ptr, NULL, &r_q->hdr_sec, r_q->data, ps, depth))
+       if(!reg_io_hdrbuf_sec(q_u->ptr, NULL, &q_u->hdr_sec, q_u->data, ps, depth))
                return False;
 
        return True;
@@ -903,9 +779,9 @@ BOOL reg_io_q_set_key_sec(char *desc,  REG_Q_SET_KEY_SEC *r_q, prs_struct *ps, i
 reads or writes a structure.
 ********************************************************************/
 
-BOOL reg_io_r_set_key_sec(char *desc, REG_R_SET_KEY_SEC *r_q, prs_struct *ps, int depth)
+BOOL reg_io_r_set_key_sec(const char *desc, REG_R_SET_KEY_SEC *q_u, prs_struct *ps, int depth)
 {
-       if (r_q == NULL)
+       if ( !q_u )
                return False;
 
        prs_debug(ps, depth, desc, "reg_io_r_set_key_sec");
@@ -914,7 +790,7 @@ BOOL reg_io_r_set_key_sec(char *desc, REG_R_SET_KEY_SEC *r_q, prs_struct *ps, in
        if(!prs_align(ps))
                return False;
        
-       if(!prs_ntstatus("status", ps, depth, &r_q->status))
+       if(!prs_werror("status", ps, depth, &q_u->status))
                return False;
 
        return True;
@@ -925,28 +801,27 @@ BOOL reg_io_r_set_key_sec(char *desc, REG_R_SET_KEY_SEC *r_q, prs_struct *ps, in
 makes a structure.
 ********************************************************************/
 
-void init_reg_q_get_key_sec(REG_Q_GET_KEY_SEC *q_i, POLICY_HND *pol, 
-                               uint32 sec_buf_size, SEC_DESC_BUF *psdb)
+void init_reg_q_get_key_sec(REG_Q_GET_KEY_SEC *q_u, POLICY_HND *pol, 
+                            uint32 sec_info, uint32 sec_buf_size,
+                            SEC_DESC_BUF *psdb)
 {
-       memcpy(&q_i->pol, pol, sizeof(q_i->pol));
+       memcpy(&q_u->pol, pol, sizeof(q_u->pol));
 
-       q_i->sec_info = OWNER_SECURITY_INFORMATION |
-                       GROUP_SECURITY_INFORMATION |
-                       DACL_SECURITY_INFORMATION;
+       q_u->sec_info = sec_info;
 
-       q_i->ptr = psdb != NULL ? 1 : 0;
-       q_i->data = psdb;
+       q_u->ptr = psdb != NULL ? 1 : 0;
+       q_u->data = psdb;
 
-       init_buf_hdr(&q_i->hdr_sec, sec_buf_size, 0);
+       init_buf_hdr(&q_u->hdr_sec, sec_buf_size, 0);
 }
 
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
 
-BOOL reg_io_q_get_key_sec(char *desc,  REG_Q_GET_KEY_SEC *r_q, prs_struct *ps, int depth)
+BOOL reg_io_q_get_key_sec(const char *desc,  REG_Q_GET_KEY_SEC *q_u, prs_struct *ps, int depth)
 {
-       if (r_q == NULL)
+       if ( !q_u )
                return False;
 
        prs_debug(ps, depth, desc, "reg_io_q_get_key_sec");
@@ -955,15 +830,15 @@ BOOL reg_io_q_get_key_sec(char *desc,  REG_Q_GET_KEY_SEC *r_q, prs_struct *ps, i
        if(!prs_align(ps))
                return False;
        
-       if(!smb_io_pol_hnd("", &r_q->pol, ps, depth))
+       if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
                return False;
 
-       if(!prs_uint32("sec_info", ps, depth, &r_q->sec_info))
+       if(!prs_uint32("sec_info", ps, depth, &q_u->sec_info))
                return False;
-       if(!prs_uint32("ptr     ", ps, depth, &r_q->ptr))
+       if(!prs_uint32("ptr     ", ps, depth, &q_u->ptr))
                return False;
 
-       if(!reg_io_hdrbuf_sec(r_q->ptr, NULL, &r_q->hdr_sec, r_q->data, ps, depth))
+       if(!reg_io_hdrbuf_sec(q_u->ptr, NULL, &q_u->hdr_sec, q_u->data, ps, depth))
                return False;
 
        return True;
@@ -989,9 +864,9 @@ makes a structure.
 reads or writes a structure.
 ********************************************************************/
 
-BOOL reg_io_r_get_key_sec(char *desc,  REG_R_GET_KEY_SEC *r_q, prs_struct *ps, int depth)
+BOOL reg_io_r_get_key_sec(const char *desc,  REG_R_GET_KEY_SEC *q_u, prs_struct *ps, int depth)
 {
-       if (r_q == NULL)
+       if ( !q_u )
                return False;
 
        prs_debug(ps, depth, desc, "reg_io_r_get_key_sec");
@@ -1000,19 +875,19 @@ BOOL reg_io_r_get_key_sec(char *desc,  REG_R_GET_KEY_SEC *r_q, prs_struct *ps, i
        if(!prs_align(ps))
                return False;
        
-       if(!prs_uint32("ptr      ", ps, depth, &r_q->ptr))
+       if(!prs_uint32("ptr      ", ps, depth, &q_u->ptr))
                return False;
 
-       if (r_q->ptr != 0) {
-               if(!smb_io_hdrbuf("", &r_q->hdr_sec, ps, depth))
+       if (q_u->ptr != 0) {
+               if(!smb_io_hdrbuf("", &q_u->hdr_sec, ps, depth))
                        return False;
-               if(!sec_io_desc_buf("", &r_q->data, ps, depth))
+               if(!sec_io_desc_buf("", &q_u->data, ps, depth))
                        return False;
                if(!prs_align(ps))
                        return False;
        }
 
-       if(!prs_ntstatus("status", ps, depth, &r_q->status))
+       if(!prs_werror("status", ps, depth, &q_u->status))
                return False;
 
        return True;
@@ -1022,31 +897,29 @@ BOOL reg_io_r_get_key_sec(char *desc,  REG_R_GET_KEY_SEC *r_q, prs_struct *ps, i
 makes a structure.
 ********************************************************************/
 
-BOOL init_reg_q_info(REG_Q_INFO *q_i, POLICY_HND *pol, char* val_name)
+BOOL init_reg_q_info(REG_Q_INFO *q_u, POLICY_HND *pol, const char *val_name,
+                     REGVAL_BUFFER *value_output)
 {
-        int len_type = val_name != NULL ? strlen(val_name) + 1 : 0;
-
-        if (q_i == NULL)
+        if (q_u == NULL)
                 return False;
 
-        q_i->pol = *pol;
+        q_u->pol = *pol;
 
-        init_uni_hdr(&(q_i->hdr_type), len_type);
-        init_unistr2(&(q_i->uni_type), val_name, len_type);
+        init_unistr4(&q_u->name, val_name, UNI_STR_TERMINATE);
 
-        q_i->ptr_reserved = 1;
-        q_i->ptr_buf = 1;
+        q_u->ptr_reserved = 1;
+        q_u->ptr_buf = 1;
 
-        q_i->ptr_bufsize = 1;
-        q_i->bufsize = 0;
-        q_i->buf_unk = 0;
+        q_u->ptr_bufsize = 1;
+        q_u->bufsize = value_output->buf_max_len;
+        q_u->buf_unk = 0;
 
-        q_i->unk1 = 0;
-        q_i->ptr_buflen = 1;
-        q_i->buflen = 0;
+        q_u->unk1 = 0;
+        q_u->ptr_buflen = 1;
+        q_u->buflen = value_output->buf_max_len; 
 
-        q_i->ptr_buflen2 = 1;
-        q_i->buflen2 = 0;
+        q_u->ptr_buflen2 = 1;
+        q_u->buflen2 = 0;
 
         return True;
 }
@@ -1055,9 +928,9 @@ BOOL init_reg_q_info(REG_Q_INFO *q_i, POLICY_HND *pol, char* val_name)
 reads or writes a structure.
 ********************************************************************/
 
-BOOL reg_io_q_info(char *desc,  REG_Q_INFO *r_q, prs_struct *ps, int depth)
+BOOL reg_io_q_info(const char *desc,  REG_Q_INFO *q_u, prs_struct *ps, int depth)
 {
-       if (r_q == NULL)
+       if ( !q_u )
                return False;
 
        prs_debug(ps, depth, desc, "reg_io_q_info");
@@ -1066,43 +939,41 @@ BOOL reg_io_q_info(char *desc,  REG_Q_INFO *r_q, prs_struct *ps, int depth)
        if(!prs_align(ps))
                return False;
        
-       if(!smb_io_pol_hnd("", &r_q->pol, ps, depth))
-               return False;
-       if(!smb_io_unihdr ("", &r_q->hdr_type, ps, depth))
+       if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
                return False;
-       if(!smb_io_unistr2("", &r_q->uni_type, r_q->hdr_type.buffer, ps, depth))
+       if(!prs_unistr4("name", ps, depth, &q_u->name))
                return False;
 
        if(!prs_align(ps))
                return False;
        
-       if(!prs_uint32("ptr_reserved", ps, depth, &(r_q->ptr_reserved)))
+       if(!prs_uint32("ptr_reserved", ps, depth, &(q_u->ptr_reserved)))
                return False;
 
-       if(!prs_uint32("ptr_buf", ps, depth, &(r_q->ptr_buf)))
+       if(!prs_uint32("ptr_buf", ps, depth, &(q_u->ptr_buf)))
                return False;
 
-       if(r_q->ptr_buf) {
-               if(!prs_uint32("ptr_bufsize", ps, depth, &(r_q->ptr_bufsize)))
+       if(q_u->ptr_buf) {
+               if(!prs_uint32("ptr_bufsize", ps, depth, &(q_u->ptr_bufsize)))
                        return False;
-               if(!prs_uint32("bufsize", ps, depth, &(r_q->bufsize)))
+               if(!prs_uint32("bufsize", ps, depth, &(q_u->bufsize)))
                        return False;
-               if(!prs_uint32("buf_unk", ps, depth, &(r_q->buf_unk)))
+               if(!prs_uint32("buf_unk", ps, depth, &(q_u->buf_unk)))
                        return False;
        }
 
-       if(!prs_uint32("unk1", ps, depth, &(r_q->unk1)))
+       if(!prs_uint32("unk1", ps, depth, &(q_u->unk1)))
                return False;
 
-       if(!prs_uint32("ptr_buflen", ps, depth, &(r_q->ptr_buflen)))
+       if(!prs_uint32("ptr_buflen", ps, depth, &(q_u->ptr_buflen)))
                return False;
 
-       if (r_q->ptr_buflen) {
-               if(!prs_uint32("buflen", ps, depth, &(r_q->buflen)))
+       if (q_u->ptr_buflen) {
+               if(!prs_uint32("buflen", ps, depth, &(q_u->buflen)))
                        return False;
-               if(!prs_uint32("ptr_buflen2", ps, depth, &(r_q->ptr_buflen2)))
+               if(!prs_uint32("ptr_buflen2", ps, depth, &(q_u->ptr_buflen2)))
                        return False;
-               if(!prs_uint32("buflen2", ps, depth, &(r_q->buflen2)))
+               if(!prs_uint32("buflen2", ps, depth, &(q_u->buflen2)))
                        return False;
        }
 
@@ -1114,66 +985,36 @@ BOOL reg_io_q_info(char *desc,  REG_Q_INFO *r_q, prs_struct *ps, int depth)
  New version to replace older init_reg_r_info()
 ********************************************************************/
 
-BOOL new_init_reg_r_info(uint32 include_keyval, REG_R_INFO *r_r,
-                    REGISTRY_VALUE *val, NTSTATUS status)
+BOOL init_reg_r_info(uint32 include_keyval, REG_R_INFO *r_u,
+                    REGISTRY_VALUE *val, WERROR status)
 {
-       uint32          buf_len = 0;
-       
-       if(r_r == NULL)
+       uint32                  buf_len = 0;
+       REGVAL_BUFFER           buf2;
+               
+       if( !r_u || !val )
                return False;
        
-       if ( !val )
-               return False;
-  
-       r_r->ptr_type = 1;
-       r_r->type = val->type;
-
-       /* if include_keyval is not set, don't send the key value, just
-          the buflen data. probably used by NT5 to allocate buffer space - SK */
+       r_u->type = TALLOC_P( get_talloc_ctx(), uint32 );
+       *r_u->type = val->type;
 
-       if ( include_keyval ) {
-               r_r->ptr_uni_val = 1;
-               buf_len = reg_init_buffer2( &r_r->uni_val, val );
+       buf_len = reg_init_regval_buffer( &buf2, val );
        
-       }
-
-       r_r->ptr_max_len = 1;
-       r_r->buf_max_len = buf_len;
-
-       r_r->ptr_len = 1;
-       r_r->buf_len = buf_len;
-
-       r_r->status = status;
-
-       return True;
-}
-
-/*******************************************************************
- Inits a structure.
-********************************************************************/
-
-BOOL init_reg_r_info(uint32 include_keyval, REG_R_INFO *r_r,
-                    BUFFER2* buf, uint32 type, NTSTATUS status)
-{
-       if(r_r == NULL)
-               return False;
-  
-       r_r->ptr_type = 1;
-       r_r->type = type;
+       r_u->buf_max_len = TALLOC_P( get_talloc_ctx(), uint32 );
+       *r_u->buf_max_len = buf_len;
 
+       r_u->buf_len = TALLOC_P( get_talloc_ctx(), uint32 );
+       *r_u->buf_len = buf_len;
+       
        /* if include_keyval is not set, don't send the key value, just
           the buflen data. probably used by NT5 to allocate buffer space - SK */
 
-       r_r->ptr_uni_val = include_keyval ? 1:0;
-       r_r->uni_val = *buf;
-
-       r_r->ptr_max_len = 1;
-       r_r->buf_max_len = r_r->uni_val.buf_max_len;
-
-       r_r->ptr_len = 1;
-       r_r->buf_len = r_r->uni_val.buf_len;
+       if ( include_keyval ) {
+               r_u->value = TALLOC_P( get_talloc_ctx(), REGVAL_BUFFER );
+               /* steal the memory */
+               *r_u->value = buf2;
+       }
 
-       r_r->status = status;
+       r_u->status = status;
 
        return True;
 }
@@ -1182,9 +1023,9 @@ BOOL init_reg_r_info(uint32 include_keyval, REG_R_INFO *r_r,
 reads or writes a structure.
 ********************************************************************/
 
-BOOL reg_io_r_info(char *desc, REG_R_INFO *r_r, prs_struct *ps, int depth)
+BOOL reg_io_r_info(const char *desc, REG_R_INFO *r_u, prs_struct *ps, int depth)
 {
-       if (r_r == NULL)
+       if ( !r_u )
                return False;
 
        prs_debug(ps, depth, desc, "reg_io_r_info");
@@ -1193,41 +1034,20 @@ BOOL reg_io_r_info(char *desc, REG_R_INFO *r_r, prs_struct *ps, int depth)
        if(!prs_align(ps))
                return False;
        
-       if(!prs_uint32("ptr_type", ps, depth, &(r_r->ptr_type)))
+       if ( !prs_pointer("type", ps, depth, (void**)&r_u->type, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
                return False;
 
-       if (r_r->ptr_type != 0) {
-               if(!prs_uint32("type", ps, depth, &r_r->type))
-                       return False;
-       }
-
-       if(!prs_uint32("ptr_uni_val", ps, depth, &(r_r->ptr_uni_val)))
+       if ( !prs_pointer("value", ps, depth, (void**)&r_u->value, sizeof(REGVAL_BUFFER), (PRS_POINTER_CAST)smb_io_regval_buffer))
                return False;
-
-       if(r_r->ptr_uni_val != 0) {
-               if(!smb_io_buffer2("uni_val", &r_r->uni_val, r_r->ptr_uni_val, ps, depth))
-                       return False;
-       }
-
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint32("ptr_max_len", ps, depth, &(r_r->ptr_max_len)))
-               return False;
-
-       if (r_r->ptr_max_len != 0) {
-               if(!prs_uint32("buf_max_len", ps, depth, &(r_r->buf_max_len)))
+       if ( !prs_pointer("buf_max_len", ps, depth, (void**)&r_u->buf_max_len, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
                return False;
-       }
-
-       if(!prs_uint32("ptr_len", ps, depth, &(r_r->ptr_len)))
+       if ( !prs_pointer("buf_len", ps, depth, (void**)&r_u->buf_len, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
                return False;
-       if (r_r->ptr_len != 0) {
-               if(!prs_uint32("buf_len", ps, depth, &(r_r->buf_len)))
-                       return False;
-       }
 
-       if(!prs_ntstatus("status", ps, depth, &r_r->status))
+       if(!prs_werror("status", ps, depth, &r_u->status))
                return False;
 
        return True;
@@ -1237,29 +1057,31 @@ BOOL reg_io_r_info(char *desc, REG_R_INFO *r_r, prs_struct *ps, int depth)
 makes a structure.
 ********************************************************************/
 
-void init_reg_q_enum_val(REG_Q_ENUM_VALUE *q_i, POLICY_HND *pol,
-                               uint32 val_idx, uint32 max_val_len,
-                               uint32 max_buf_len)
+void init_reg_q_enum_val(REG_Q_ENUM_VALUE *q_u, POLICY_HND *pol,
+                               uint32 val_idx,
+                               uint32 max_name_len, uint32 max_buf_len)
 {
-       ZERO_STRUCTP(q_i);
+       ZERO_STRUCTP(q_u);
 
-       memcpy(&q_i->pol, pol, sizeof(q_i->pol));
+       memcpy(&q_u->pol, pol, sizeof(q_u->pol));
 
-       q_i->val_index = val_idx;
-       init_uni_hdr(&q_i->hdr_name, max_val_len);
-       q_i->uni_name.uni_max_len = max_val_len;
+       q_u->val_index = val_idx;
+
+       q_u->name.size = max_name_len*2;
+       q_u->name.string = TALLOC_ZERO_P( get_talloc_ctx(), UNISTR2 );
+       q_u->name.string->uni_max_len = max_name_len;
        
-       q_i->ptr_type = 1;
-       q_i->type = 0x0;
+       q_u->type = TALLOC_P( get_talloc_ctx(), uint32 );
+       *q_u->type = 0x0;
 
-       q_i->ptr_value = 1;
-       q_i->buf_value.buf_max_len = max_buf_len;
+       q_u->value = TALLOC_ZERO_P( get_talloc_ctx(), REGVAL_BUFFER );
+       q_u->value->buf_max_len = max_buf_len;
 
-       q_i->ptr1 = 1;
-       q_i->len_value1 = max_buf_len;
+       q_u->buffer_len  = TALLOC_P( get_talloc_ctx(), uint32 );
+       *q_u->buffer_len = max_buf_len;
 
-       q_i->ptr2 = 1;
-       q_i->len_value2 = 0;
+       q_u->name_len  = TALLOC_P( get_talloc_ctx(), uint32 );
+       *q_u->name_len = 0x0;
 }
 
 /*******************************************************************
@@ -1270,45 +1092,39 @@ void init_reg_r_enum_val(REG_R_ENUM_VALUE *r_u, REGISTRY_VALUE *val )
 {
        uint32 real_size;
        
-       DEBUG(8,("init_reg_r_enum_val: Enter\n"));
-       
        ZERO_STRUCTP(r_u);
 
        /* value name */
 
        DEBUG(10,("init_reg_r_enum_val: Valuename => [%s]\n", val->valuename));
        
-       init_uni_hdr( &r_u->hdr_name, strlen(val->valuename)+1 );
-       init_unistr2( &r_u->uni_name, val->valuename, strlen(val->valuename)+1 );
+       init_unistr4( &r_u->name, val->valuename, UNI_STR_TERMINATE);
                
        /* type */
        
-       r_u->ptr_type = 1;
-       r_u->type = val->type;
+       r_u->type = TALLOC_P( get_talloc_ctx(), uint32 );
+       *r_u->type = val->type;
 
        /* REG_SZ & REG_MULTI_SZ must be converted to UNICODE */
        
-       r_u->ptr_value = 1;
-       real_size = reg_init_buffer2( &r_u->buf_value, val );
+       r_u->value = TALLOC_P( get_talloc_ctx(), REGVAL_BUFFER );
+       real_size = reg_init_regval_buffer( r_u->value, val );
        
        /* lengths */
 
-       r_u->ptr1 = 1;
-       r_u->len_value1 = real_size;
-       
-       r_u->ptr2 = 1;
-       r_u->len_value2 = real_size;
-               
-       DEBUG(8,("init_reg_r_enum_val: Exit\n"));
+       r_u->buffer_len1  = TALLOC_P( get_talloc_ctx(), uint32 );
+       *r_u->buffer_len1 = real_size;
+       r_u->buffer_len2  = TALLOC_P( get_talloc_ctx(), uint32 );
+       *r_u->buffer_len2 = real_size;
 }
 
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
 
-BOOL reg_io_q_enum_val(char *desc,  REG_Q_ENUM_VALUE *q_q, prs_struct *ps, int depth)
+BOOL reg_io_q_enum_val(const char *desc,  REG_Q_ENUM_VALUE *q_u, prs_struct *ps, int depth)
 {
-       if (q_q == NULL)
+       if (q_u == NULL)
                return False;
 
        prs_debug(ps, depth, desc, "reg_io_q_enum_val");
@@ -1317,46 +1133,29 @@ BOOL reg_io_q_enum_val(char *desc,  REG_Q_ENUM_VALUE *q_q, prs_struct *ps, int d
        if(!prs_align(ps))
                return False;
        
-       if(!smb_io_pol_hnd("", &q_q->pol, ps, depth))
+       if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
                return False;
        
-       if(!prs_uint32("val_index", ps, depth, &q_q->val_index))
+       if(!prs_uint32("val_index", ps, depth, &q_u->val_index))
                return False;
                
-       if(!smb_io_unihdr ("hdr_name", &q_q->hdr_name, ps, depth))
-               return False;
-       if(!smb_io_unistr2("uni_name", &q_q->uni_name, q_q->hdr_name.buffer, ps, depth))
+       if(!prs_unistr4("name", ps, depth, &q_u->name ))
                return False;
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint32("ptr_type", ps, depth, &q_q->ptr_type))
+       if(!prs_pointer("type", ps, depth, (void**)&q_u->type, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
                return False;
 
-       if (q_q->ptr_type != 0) {
-               if(!prs_uint32("type", ps, depth, &q_q->type))
-                       return False;
-       }
-
-       if(!prs_uint32("ptr_value", ps, depth, &q_q->ptr_value))
-               return False;
-       if(!smb_io_buffer2("buf_value", &q_q->buf_value, q_q->ptr_value, ps, depth))
+       if ( !prs_pointer("value", ps, depth, (void**)&q_u->value, sizeof(REGVAL_BUFFER), (PRS_POINTER_CAST)smb_io_regval_buffer))
                return False;
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint32("ptr1", ps, depth, &q_q->ptr1))
+       if(!prs_pointer("buffer_len", ps, depth, (void**)&q_u->buffer_len, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
                return False;
-       if (q_q->ptr1 != 0) {
-               if(!prs_uint32("len_value1", ps, depth, &q_q->len_value1))
-                       return False;
-       }
-       if(!prs_uint32("ptr2", ps, depth, &q_q->ptr2))
+       if(!prs_pointer("name_len", ps, depth, (void**)&q_u->name_len, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
                return False;
-       if (q_q->ptr2 != 0) {
-               if(!prs_uint32("len_value2", ps, depth, &q_q->len_value2))
-                       return False;
-       }
 
        return True;
 }
@@ -1365,9 +1164,9 @@ BOOL reg_io_q_enum_val(char *desc,  REG_Q_ENUM_VALUE *q_q, prs_struct *ps, int d
 reads or writes a structure.
 ********************************************************************/
 
-BOOL reg_io_r_enum_val(char *desc,  REG_R_ENUM_VALUE *r_q, prs_struct *ps, int depth)
+BOOL reg_io_r_enum_val(const char *desc,  REG_R_ENUM_VALUE *r_u, prs_struct *ps, int depth)
 {
-       if (r_q == NULL)
+       if ( !r_u )
                return False;
 
        prs_debug(ps, depth, desc, "reg_io_r_enum_val");
@@ -1376,43 +1175,25 @@ BOOL reg_io_r_enum_val(char *desc,  REG_R_ENUM_VALUE *r_q, prs_struct *ps, int d
        if(!prs_align(ps))
                return False;
        
-       if(!smb_io_unihdr ("hdr_name", &r_q->hdr_name, ps, depth))
-               return False;
-       if(!smb_io_unistr2("uni_name", &r_q->uni_name, r_q->hdr_name.buffer, ps, depth))
+       if(!prs_unistr4("name", ps, depth, &r_u->name ))
                return False;
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint32("ptr_type", ps, depth, &r_q->ptr_type))
+       if(!prs_pointer("type", ps, depth, (void**)&r_u->type, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
                return False;
 
-       if (r_q->ptr_type != 0) {
-               if(!prs_uint32("type", ps, depth, &r_q->type))
-                       return False;
-       }
-
-       if(!prs_uint32("ptr_value", ps, depth, &r_q->ptr_value))
-               return False;
-       if(!smb_io_buffer2("buf_value", &r_q->buf_value, r_q->ptr_value, ps, depth))
+       if ( !prs_pointer("value", ps, depth, (void**)&r_u->value, sizeof(REGVAL_BUFFER), (PRS_POINTER_CAST)smb_io_regval_buffer))
                return False;
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint32("ptr1", ps, depth, &r_q->ptr1))
+       if(!prs_pointer("buffer_len1", ps, depth, (void**)&r_u->buffer_len1, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
                return False;
-       if (r_q->ptr1 != 0) {
-               if(!prs_uint32("len_value1", ps, depth, &r_q->len_value1))
-                       return False;
-       }
-
-       if(!prs_uint32("ptr2", ps, depth, &r_q->ptr2))
+       if(!prs_pointer("buffer_len2", ps, depth, (void**)&r_u->buffer_len2, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
                return False;
-       if (r_q->ptr2 != 0) {
-               if(!prs_uint32("len_value2", ps, depth, &r_q->len_value2))
-                       return False;
-       }
 
-       if(!prs_ntstatus("status", ps, depth, &r_q->status))
+       if(!prs_werror("status", ps, depth, &r_u->status))
                return False;
 
        return True;
@@ -1422,55 +1203,55 @@ BOOL reg_io_r_enum_val(char *desc,  REG_R_ENUM_VALUE *r_q, prs_struct *ps, int d
 makes a structure.
 ********************************************************************/
 
-void init_reg_q_create_val(REG_Q_CREATE_VALUE *q_i, POLICY_HND *pol,
+void init_reg_q_set_val(REG_Q_SET_VALUE *q_u, POLICY_HND *pol,
                                char *val_name, uint32 type,
-                               BUFFER3 *val)
+                               RPC_DATA_BLOB *val)
 {
-       int val_len = strlen(val_name) + 1;
+       ZERO_STRUCTP(q_u);
 
-       ZERO_STRUCTP(q_i);
-
-       memcpy(&q_i->pol, pol, sizeof(q_i->pol));
+       memcpy(&q_u->pol, pol, sizeof(q_u->pol));
 
-       init_uni_hdr(&q_i->hdr_name, val_len);
-       init_unistr2(&q_i->uni_name, val_name, val_len);
+       init_unistr4(&q_u->name, val_name, UNI_STR_TERMINATE);
        
-       q_i->type      = type;
-       q_i->buf_value = val;
+       q_u->type      = type;
+       q_u->value     = *val;
+       q_u->size      = val->buf_len;
 }
 
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
 
-BOOL reg_io_q_create_val(char *desc,  REG_Q_CREATE_VALUE *q_q, prs_struct *ps, int depth)
+BOOL reg_io_q_set_val(const char *desc,  REG_Q_SET_VALUE *q_u, prs_struct *ps, int depth)
 {
-       if (q_q == NULL)
+       if (q_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "reg_io_q_create_val");
+       prs_debug(ps, depth, desc, "reg_io_q_set_val");
        depth++;
 
        if(!prs_align(ps))
                return False;
        
-       if(!smb_io_pol_hnd("", &q_q->pol, ps, depth))
+       if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
                return False;
        
-       if(!smb_io_unihdr ("hdr_name", &q_q->hdr_name, ps, depth))
-               return False;
-       if(!smb_io_unistr2("uni_name", &q_q->uni_name, q_q->hdr_name.buffer, ps, depth))
+       if(!prs_unistr4("name", ps, depth, &q_u->name ))
                return False;
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint32("type", ps, depth, &q_q->type))
+       if(!prs_uint32("type", ps, depth, &q_u->type))
                return False;
-       if(!smb_io_buffer3("buf_value", q_q->buf_value, ps, depth))
+
+       if(!smb_io_rpc_blob("value", &q_u->value, ps, depth ))
                return False;
        if(!prs_align(ps))
                return False;
 
+       if(!prs_uint32("size", ps, depth, &q_u->size))
+               return False;
+
        return True;
 }
 
@@ -1478,18 +1259,18 @@ BOOL reg_io_q_create_val(char *desc,  REG_Q_CREATE_VALUE *q_q, prs_struct *ps, i
 reads or writes a structure.
 ********************************************************************/
 
-BOOL reg_io_r_create_val(char *desc,  REG_R_CREATE_VALUE *r_q, prs_struct *ps, int depth)
+BOOL reg_io_r_set_val(const char *desc,  REG_R_SET_VALUE *q_u, prs_struct *ps, int depth)
 {
-       if (r_q == NULL)
+       if ( !q_u )
                return False;
 
-       prs_debug(ps, depth, desc, "reg_io_r_create_val");
+       prs_debug(ps, depth, desc, "reg_io_r_set_val");
        depth++;
 
        if(!prs_align(ps))
                return False;
        
-       if(!prs_ntstatus("status", ps, depth, &r_q->status))
+       if(!prs_werror("status", ps, depth, &q_u->status))
                return False;
 
        return True;
@@ -1499,55 +1280,46 @@ BOOL reg_io_r_create_val(char *desc,  REG_R_CREATE_VALUE *r_q, prs_struct *ps, i
 makes a structure.
 ********************************************************************/
 
-void init_reg_q_enum_key(REG_Q_ENUM_KEY *q_i, POLICY_HND *pol, uint32 key_idx)
+void init_reg_q_enum_key(REG_Q_ENUM_KEY *q_u, POLICY_HND *pol, uint32 key_idx)
 {
-       memcpy(&q_i->pol, pol, sizeof(q_i->pol));
+       memcpy(&q_u->pol, pol, sizeof(q_u->pol));
 
-       q_i->key_index = key_idx;
-       q_i->key_name_len = 0;
-       q_i->unknown_1 = 0x0414;
+       q_u->key_index = key_idx;
+       q_u->key_name_len = 0;
+       q_u->unknown_1 = 0x0414;
 
-       q_i->ptr1 = 1;
-       q_i->unknown_2 = 0x0000020A;
-       memset(q_i->pad1, 0, sizeof(q_i->pad1));
+       q_u->ptr1 = 1;
+       q_u->unknown_2 = 0x0000020A;
+       memset(q_u->pad1, 0, sizeof(q_u->pad1));
 
-       q_i->ptr2 = 1;
-       memset(q_i->pad2, 0, sizeof(q_i->pad2));
+       q_u->ptr2 = 1;
+       memset(q_u->pad2, 0, sizeof(q_u->pad2));
 
-       q_i->ptr3 = 1;
-       unix_to_nt_time(&q_i->time, 0);            /* current time? */
+       q_u->ptr3 = 1;
+       unix_to_nt_time(&q_u->time, 0);            /* current time? */
 }
 
 /*******************************************************************
 makes a reply structure.
 ********************************************************************/
 
-void init_reg_r_enum_key(REG_R_ENUM_KEY *r_u, char *subkey, uint32 unknown_1,
-                       uint32 unknown_2)
+void init_reg_r_enum_key(REG_R_ENUM_KEY *r_u, char *subkey )
 {
        if ( !r_u )
                return;
                
-       r_u->unknown_1 = unknown_1;
-       r_u->unknown_2 = unknown_2;
-       r_u->unknown_3 = 0x0;
-       
-       r_u->key_name_len = (strlen(subkey)+1) * 2;
-       if (r_u->key_name_len)
-               r_u->ptr1 = 0x1;
-       init_unistr3( &r_u->key_name, subkey );
-       
-       r_u->ptr2 = 0x1;
-       r_u->ptr3 = 0x1;
+       init_unistr4( &r_u->keyname, subkey, STR_TERMINATE );
+       r_u->classname = TALLOC_ZERO_P( get_talloc_ctx(), UNISTR4 );
+       r_u->time       = TALLOC_ZERO_P( get_talloc_ctx(), NTTIME );
 }
 
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
 
-BOOL reg_io_q_enum_key(char *desc,  REG_Q_ENUM_KEY *q_q, prs_struct *ps, int depth)
+BOOL reg_io_q_enum_key(const char *desc,  REG_Q_ENUM_KEY *q_u, prs_struct *ps, int depth)
 {
-       if (q_q == NULL)
+       if (q_u == NULL)
                return False;
 
        prs_debug(ps, depth, desc, "reg_io_q_enum_key");
@@ -1556,39 +1328,39 @@ BOOL reg_io_q_enum_key(char *desc,  REG_Q_ENUM_KEY *q_q, prs_struct *ps, int dep
        if(!prs_align(ps))
                return False;
        
-       if(!smb_io_pol_hnd("", &q_q->pol, ps, depth))
+       if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
                return False;
        
-       if(!prs_uint32("key_index", ps, depth, &q_q->key_index))
+       if(!prs_uint32("key_index", ps, depth, &q_u->key_index))
                return False;
-       if(!prs_uint16("key_name_len", ps, depth, &q_q->key_name_len))
+       if(!prs_uint16("key_name_len", ps, depth, &q_u->key_name_len))
                return False;
-       if(!prs_uint16("unknown_1", ps, depth, &q_q->unknown_1))
+       if(!prs_uint16("unknown_1", ps, depth, &q_u->unknown_1))
                return False;
 
-       if(!prs_uint32("ptr1", ps, depth, &q_q->ptr1))
+       if(!prs_uint32("ptr1", ps, depth, &q_u->ptr1))
                return False;
 
-       if (q_q->ptr1 != 0) {
-               if(!prs_uint32("unknown_2", ps, depth, &q_q->unknown_2))
+       if (q_u->ptr1 != 0) {
+               if(!prs_uint32("unknown_2", ps, depth, &q_u->unknown_2))
                        return False;
-               if(!prs_uint8s(False, "pad1", ps, depth, q_q->pad1, sizeof(q_q->pad1)))
+               if(!prs_uint8s(False, "pad1", ps, depth, q_u->pad1, sizeof(q_u->pad1)))
                        return False;
        }
 
-       if(!prs_uint32("ptr2", ps, depth, &q_q->ptr2))
+       if(!prs_uint32("ptr2", ps, depth, &q_u->ptr2))
                return False;
 
-       if (q_q->ptr2 != 0) {
-               if(!prs_uint8s(False, "pad2", ps, depth, q_q->pad2, sizeof(q_q->pad2)))
+       if (q_u->ptr2 != 0) {
+               if(!prs_uint8s(False, "pad2", ps, depth, q_u->pad2, sizeof(q_u->pad2)))
                        return False;
        }
 
-       if(!prs_uint32("ptr3", ps, depth, &q_q->ptr3))
+       if(!prs_uint32("ptr3", ps, depth, &q_u->ptr3))
                return False;
 
-       if (q_q->ptr3 != 0) {
-               if(!smb_io_time("", &q_q->time, ps, depth))
+       if (q_u->ptr3 != 0) {
+               if(!smb_io_time("", &q_u->time, ps, depth))
                        return False;
        }
 
@@ -1599,9 +1371,9 @@ BOOL reg_io_q_enum_key(char *desc,  REG_Q_ENUM_KEY *q_q, prs_struct *ps, int dep
 reads or writes a structure.
 ********************************************************************/
 
-BOOL reg_io_r_enum_key(char *desc,  REG_R_ENUM_KEY *r_q, prs_struct *ps, int depth)
+BOOL reg_io_r_enum_key(const char *desc,  REG_R_ENUM_KEY *q_u, prs_struct *ps, int depth)
 {
-       if (r_q == NULL)
+       if ( !q_u )
                return False;
 
        prs_debug(ps, depth, desc, "reg_io_r_enum_key");
@@ -1609,43 +1381,22 @@ BOOL reg_io_r_enum_key(char *desc,  REG_R_ENUM_KEY *r_q, prs_struct *ps, int dep
 
        if(!prs_align(ps))
                return False;
+       if ( !prs_unistr4( "keyname", ps, depth, &q_u->keyname ) )
+               return False;
        
-       if(!prs_uint16("key_name_len", ps, depth, &r_q->key_name_len))
+       if(!prs_align(ps))
                return False;
-       if(!prs_uint16("unknown_1", ps, depth, &r_q->unknown_1))
+       if (!prs_pointer("class", ps, depth, (void**)&q_u->classname, sizeof(UNISTR4), (PRS_POINTER_CAST)prs_unistr4))
                return False;
 
-       if(!prs_uint32("ptr1", ps, depth, &r_q->ptr1))
+       if(!prs_align(ps))
                return False;
-
-       if (r_q->ptr1 != 0) {
-               if(!prs_uint32("unknown_2", ps, depth, &r_q->unknown_2))
-                       return False;
-               if(!prs_uint32("unknown_3", ps, depth, &r_q->unknown_3))
-                       return False;
-               if(!smb_io_unistr3("key_name", &r_q->key_name, ps, depth))
-                       return False;
-               if(!prs_align(ps))
-                       return False;
-       }
-
-       if(!prs_uint32("ptr2", ps, depth, &r_q->ptr2))
+       if (!prs_pointer("time", ps, depth, (void**)&q_u->time, sizeof(NTTIME), (PRS_POINTER_CAST)smb_io_nttime))
                return False;
 
-       if (r_q->ptr2 != 0) {
-               if(!prs_uint8s(False, "pad2", ps, depth, r_q->pad2, sizeof(r_q->pad2)))
-                       return False;
-       }
-
-       if(!prs_uint32("ptr3", ps, depth, &r_q->ptr3))
+       if(!prs_align(ps))
                return False;
-
-       if (r_q->ptr3 != 0) {
-               if(!smb_io_time("", &r_q->time, ps, depth))
-                       return False;
-       }
-
-       if(!prs_ntstatus("status", ps, depth, &r_q->status))
+       if(!prs_werror("status", ps, depth, &q_u->status))
                return False;
 
        return True;
@@ -1655,48 +1406,43 @@ BOOL reg_io_r_enum_key(char *desc,  REG_R_ENUM_KEY *r_q, prs_struct *ps, int dep
 makes a structure.
 ********************************************************************/
 
-void init_reg_q_open_entry(REG_Q_OPEN_ENTRY *r_q, POLICY_HND *pol,
+void init_reg_q_open_entry(REG_Q_OPEN_ENTRY *q_u, POLICY_HND *pol,
                                char *key_name, uint32 access_desired)
 {
-       int len_name = strlen(key_name)+1;
-
-       memcpy(&r_q->pol, pol, sizeof(r_q->pol));
+       memcpy(&q_u->pol, pol, sizeof(q_u->pol));
 
-       init_uni_hdr(&r_q->hdr_name, len_name);
-       init_unistr2(&r_q->uni_name, key_name, len_name);
+       init_unistr4(&q_u->name, key_name, UNI_STR_TERMINATE);
 
-       r_q->unknown_0 = 0x00000000;
-       r_q->access_desired = access_desired;
+       q_u->unknown_0 = 0x00000000;
+       q_u->access = access_desired;
 }
 
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
 
-BOOL reg_io_q_open_entry(char *desc,  REG_Q_OPEN_ENTRY *r_q, prs_struct *ps, int depth)
+BOOL reg_io_q_open_entry(const char *desc,  REG_Q_OPEN_ENTRY *q_u, prs_struct *ps, int depth)
 {
-       if (r_q == NULL)
+       if ( !q_u )
                return False;
 
-       prs_debug(ps, depth, desc, "reg_io_q_entry");
+       prs_debug(ps, depth, desc, "reg_io_q_open_entry");
        depth++;
 
        if(!prs_align(ps))
                return False;
        
-       if(!smb_io_pol_hnd("", &r_q->pol, ps, depth))
-               return False;
-       if(!smb_io_unihdr ("", &r_q->hdr_name, ps, depth))
+       if(!smb_io_pol_hnd("", &q_u->pol, ps, depth))
                return False;
-       if(!smb_io_unistr2("", &r_q->uni_name, r_q->hdr_name.buffer, ps, depth))
+       if(!prs_unistr4("name", ps, depth, &q_u->name))
                return False;
 
        if(!prs_align(ps))
                return False;
        
-       if(!prs_uint32("unknown_0        ", ps, depth, &r_q->unknown_0))
+       if(!prs_uint32("unknown_0        ", ps, depth, &q_u->unknown_0))
                return False;
-       if(!prs_uint32("asccess_desired  ", ps, depth, &r_q->access_desired))
+       if(!prs_uint32("access", ps, depth, &q_u->access))
                return False;
 
        return True;
@@ -1706,20 +1452,24 @@ BOOL reg_io_q_open_entry(char *desc,  REG_Q_OPEN_ENTRY *r_q, prs_struct *ps, int
  Inits a structure.
 ********************************************************************/
 
-void init_reg_r_open_entry(REG_R_OPEN_ENTRY *r_r,
-                          POLICY_HND *pol, NTSTATUS status)
+void init_reg_r_open_entry(REG_R_OPEN_ENTRY *r_u,
+                          POLICY_HND *pol, WERROR werr)
 {
-       memcpy(&r_r->pol, pol, sizeof(r_r->pol));
-       r_r->status = status;
+       if (W_ERROR_IS_OK(werr)) {
+               memcpy(&r_u->pol, pol, sizeof(r_u->pol));
+       } else {
+               ZERO_STRUCT(r_u->pol);
+       }
+       r_u->status = werr;
 }
 
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
 
-BOOL reg_io_r_open_entry(char *desc,  REG_R_OPEN_ENTRY *r_r, prs_struct *ps, int depth)
+BOOL reg_io_r_open_entry(const char *desc,  REG_R_OPEN_ENTRY *r_u, prs_struct *ps, int depth)
 {
-       if (r_r == NULL)
+       if ( !r_u )
                return False;
 
        prs_debug(ps, depth, desc, "reg_io_r_open_entry");
@@ -1728,10 +1478,10 @@ BOOL reg_io_r_open_entry(char *desc,  REG_R_OPEN_ENTRY *r_r, prs_struct *ps, int
        if(!prs_align(ps))
                return False;
        
-       if(!smb_io_pol_hnd("", &r_r->pol, ps, depth))
+       if(!smb_io_pol_hnd("", &r_u->pol, ps, depth))
                return False;
 
-       if(!prs_ntstatus("status", ps, depth, &r_r->status))
+       if(!prs_werror("status", ps, depth, &r_u->status))
                return False;
 
        return True;
@@ -1740,31 +1490,54 @@ BOOL reg_io_r_open_entry(char *desc,  REG_R_OPEN_ENTRY *r_r, prs_struct *ps, int
 /*******************************************************************
 Inits a structure.
 ********************************************************************/
-void init_reg_q_shutdown(REG_Q_SHUTDOWN * q_s,
-                        const char *msg, uint32 timeout, uint16 flags)
+
+void init_reg_q_shutdown(REG_Q_SHUTDOWN *q_u, const char *msg,
+                       uint32 timeout, BOOL do_reboot, BOOL force)
 {
-       int msg_len;
-       msg_len = strlen(msg);
+       q_u->server = TALLOC_P( get_talloc_ctx(), uint16 );
+       *q_u->server = 0x1;
 
-       q_s->ptr_0 = 1;
-       q_s->ptr_1 = 1;
-       q_s->ptr_2 = 1;
+       q_u->message = TALLOC_P( get_talloc_ctx(), UNISTR4 );
+       init_unistr4( q_u->message, msg, UNI_FLAGS_NONE );
 
-       init_uni_hdr(&(q_s->hdr_msg), msg_len);
-       init_unistr2(&(q_s->uni_msg), msg, msg_len);
+       q_u->timeout = timeout;
 
-       q_s->timeout = timeout;
-       q_s->flags = flags;
+       q_u->reboot = do_reboot ? 1 : 0;
+       q_u->force = force ? 1 : 0;
+}
 
+/*******************************************************************
+Inits a REG_Q_SHUTDOWN_EX structure.
+********************************************************************/
+
+void init_reg_q_shutdown_ex(REG_Q_SHUTDOWN_EX * q_u_ex, const char *msg,
+                       uint32 timeout, BOOL do_reboot, BOOL force, uint32 reason)
+{
+       REG_Q_SHUTDOWN q_u;
+       
+       ZERO_STRUCT( q_u );
+       
+       init_reg_q_shutdown( &q_u, msg, timeout, do_reboot, force );
+       
+       /* steal memory */
+       
+       q_u_ex->server  = q_u.server;
+       q_u_ex->message = q_u.message;
+       
+       q_u_ex->reboot  = q_u.reboot;
+       q_u_ex->force   = q_u.force;
+       
+       q_u_ex->reason = reason;
 }
 
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-BOOL reg_io_q_shutdown(char *desc, REG_Q_SHUTDOWN * q_s, prs_struct *ps,
+
+BOOL reg_io_q_shutdown(const char *desc, REG_Q_SHUTDOWN *q_u, prs_struct *ps,
                       int depth)
 {
-       if (q_s == NULL)
+       if ( !q_u )
                return False;
 
        prs_debug(ps, depth, desc, "reg_io_q_shutdown");
@@ -1773,24 +1546,23 @@ BOOL reg_io_q_shutdown(char *desc, REG_Q_SHUTDOWN * q_s, prs_struct *ps,
        if (!prs_align(ps))
                return False;
 
-       if (!prs_uint32("ptr_0", ps, depth, &(q_s->ptr_0)))
-               return False;
-       if (!prs_uint32("ptr_1", ps, depth, &(q_s->ptr_1)))
-               return False;
-       if (!prs_uint32("ptr_2", ps, depth, &(q_s->ptr_2)))
+       if (!prs_pointer("server", ps, depth, (void**)&q_u->server, sizeof(uint16), (PRS_POINTER_CAST)prs_uint16))
                return False;
 
-       if (!smb_io_unihdr("hdr_msg", &(q_s->hdr_msg), ps, depth))
-               return False;
-       if (!smb_io_unistr2("uni_msg", &(q_s->uni_msg), q_s->hdr_msg.buffer, ps, depth))
+       if (!prs_pointer("message", ps, depth, (void**)&q_u->message, sizeof(UNISTR4), (PRS_POINTER_CAST)prs_unistr4))
                return False;
+
        if (!prs_align(ps))
                return False;
 
-       if (!prs_uint32("timeout", ps, depth, &(q_s->timeout)))
+       if (!prs_uint32("timeout", ps, depth, &(q_u->timeout)))
                return False;
-       if (!prs_uint16("flags  ", ps, depth, &(q_s->flags)))
+
+       if (!prs_uint8("force  ", ps, depth, &(q_u->force)))
                return False;
+       if (!prs_uint8("reboot ", ps, depth, &(q_u->reboot)))
+               return False;
+
 
        return True;
 }
@@ -1798,10 +1570,10 @@ BOOL reg_io_q_shutdown(char *desc, REG_Q_SHUTDOWN * q_s, prs_struct *ps,
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-BOOL reg_io_r_shutdown(char *desc, REG_R_SHUTDOWN * r_s, prs_struct *ps,
+BOOL reg_io_r_shutdown(const char *desc, REG_R_SHUTDOWN *r_u, prs_struct *ps,
                       int depth)
 {
-       if (r_s == NULL)
+       if ( !r_u )
                return False;
 
        prs_debug(ps, depth, desc, "reg_io_r_shutdown");
@@ -1810,29 +1582,93 @@ BOOL reg_io_r_shutdown(char *desc, REG_R_SHUTDOWN * r_s, prs_struct *ps,
        if(!prs_align(ps))
                return False;
 
-       if(!prs_ntstatus("status", ps, depth, &r_s->status))
+       if(!prs_werror("status", ps, depth, &r_u->status))
                return False;
 
        return True;
 }
 
 /*******************************************************************
-Inits a structure.
+reads or writes a REG_Q_SHUTDOWN_EX structure.
 ********************************************************************/
-void init_reg_q_abort_shutdown(REG_Q_ABORT_SHUTDOWN * q_s)
+
+BOOL reg_io_q_shutdown_ex(const char *desc, REG_Q_SHUTDOWN_EX *q_u, prs_struct *ps,
+                      int depth)
 {
+       if ( !q_u )
+               return False;
+
+       prs_debug(ps, depth, desc, "reg_io_q_shutdown_ex");
+       depth++;
+
+       if (!prs_align(ps))
+               return False;
 
-       q_s->ptr_server = 0;
+       if (!prs_pointer("server", ps, depth, (void**)&q_u->server, sizeof(uint16), (PRS_POINTER_CAST)prs_uint16))
+               return False;
+
+       if (!prs_pointer("message", ps, depth, (void**)&q_u->message, sizeof(UNISTR4), (PRS_POINTER_CAST)prs_unistr4))
+               return False;
 
+       if (!prs_align(ps))
+               return False;
+
+       if (!prs_uint32("timeout", ps, depth, &(q_u->timeout)))
+               return False;
+
+       if (!prs_uint8("force  ", ps, depth, &(q_u->force)))
+               return False;
+       if (!prs_uint8("reboot ", ps, depth, &(q_u->reboot)))
+               return False;
+
+       if (!prs_align(ps))
+               return False;
+       if (!prs_uint32("reason", ps, depth, &(q_u->reason)))
+               return False;
+
+
+       return True;
+}
+
+/*******************************************************************
+reads or writes a REG_R_SHUTDOWN_EX structure.
+********************************************************************/
+BOOL reg_io_r_shutdown_ex(const char *desc, REG_R_SHUTDOWN_EX *r_u, prs_struct *ps,
+                      int depth)
+{
+       if ( !r_u )
+               return False;
+
+       prs_debug(ps, depth, desc, "reg_io_r_shutdown_ex");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!prs_werror("status", ps, depth, &r_u->status))
+               return False;
+
+       return True;
+}
+
+
+
+/*******************************************************************
+Inits a structure.
+********************************************************************/
+void init_reg_q_abort_shutdown(REG_Q_ABORT_SHUTDOWN *q_u)
+{
+       q_u->server = TALLOC_P( get_talloc_ctx(), uint16 );
+       *q_u->server = 0x1;
 }
 
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-BOOL reg_io_q_abort_shutdown(char *desc, REG_Q_ABORT_SHUTDOWN * q_s,
+BOOL reg_io_q_abort_shutdown(const char *desc, REG_Q_ABORT_SHUTDOWN *q_u,
                             prs_struct *ps, int depth)
 {
-       if (q_s == NULL)
+       if ( !q_u )
                return False;
 
        prs_debug(ps, depth, desc, "reg_io_q_abort_shutdown");
@@ -1841,11 +1677,8 @@ BOOL reg_io_q_abort_shutdown(char *desc, REG_Q_ABORT_SHUTDOWN * q_s,
        if (!prs_align(ps))
                return False;
 
-       if (!prs_uint32("ptr_server", ps, depth, &(q_s->ptr_server)))
+       if (!prs_pointer("server", ps, depth, (void**)&q_u->server, sizeof(uint16), (PRS_POINTER_CAST)prs_uint16))
                return False;
-       if (q_s->ptr_server != 0)
-               if (!prs_uint16("server", ps, depth, &(q_s->server)))
-                       return False;
 
        return True;
 }
@@ -1853,10 +1686,10 @@ BOOL reg_io_q_abort_shutdown(char *desc, REG_Q_ABORT_SHUTDOWN * q_s,
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-BOOL reg_io_r_abort_shutdown(char *desc, REG_R_ABORT_SHUTDOWN * r_s,
+BOOL reg_io_r_abort_shutdown(const char *desc, REG_R_ABORT_SHUTDOWN *r_u,
                             prs_struct *ps, int depth)
 {
-       if (r_s == NULL)
+       if ( !r_u )
                return False;
 
        prs_debug(ps, depth, desc, "reg_io_r_abort_shutdown");
@@ -1865,7 +1698,7 @@ BOOL reg_io_r_abort_shutdown(char *desc, REG_R_ABORT_SHUTDOWN * r_s,
        if (!prs_align(ps))
                return False;
 
-       if (!prs_ntstatus("status", ps, depth, &r_s->status))
+       if (!prs_werror("status", ps, depth, &r_u->status))
                return False;
 
        return True;