Index: /trunk/include/regfi.h
===================================================================
--- /trunk/include/regfi.h	(revision 83)
+++ /trunk/include/regfi.h	(revision 84)
@@ -1,5 +1,5 @@
 /*
  * Branched from Samba project, Subversion repository version #6903:
- *   http://websvn.samba.org/cgi-bin/viewcvs.cgi/trunk/source/include/regfio.h
+ *   http://viewcvs.samba.org/cgi-bin/viewcvs.cgi/trunk/source/include/regfio.h?rev=6903&view=auto
  *
  * Unix SMB/CIFS implementation.
@@ -109,13 +109,13 @@
   uint32 free_off;       /* offset to free space within the hbin record */
   uint32 free_size;      /* amount of data left in the block */
-  int    ref_count;      /* how many active records are pointing to this
+  uint32 ref_count;      /* how many active records are pointing to this
                           * block (not used currently) 
 			  */
-	
-  uint8  header[HBIN_HDR_SIZE]; /* "hbin" */
+  
   uint32 first_hbin_off; /* offset from first hbin block */
   uint32 block_size;     /* block size of this block is
                           * usually a multiple of 4096Kb 
 			  */
+  uint8  header[HBIN_HDR_SIZE]; /* "hbin" */
   prs_struct ps;	 /* data */
   bool dirty;            /* has this hbin block been modified? */
@@ -129,7 +129,8 @@
 
 typedef struct {
-  REGF_HBIN *hbin;       /* pointer to HBIN record (in memory) containing 
+  REGF_HBIN* hbin;       /* pointer to HBIN record (in memory) containing 
 			  * this nk record 
 			  */
+  REGF_HASH_REC* hashes;
   uint32 hbin_off;	 /* offset from beginning of this hbin block */
   uint32 rec_size;	 /* ((start_offset - end_offset) & 0xfffffff8) */
@@ -137,5 +138,4 @@
   uint8 header[REC_HDR_SIZE];
   uint16 num_keys;
-  REGF_HASH_REC *hashes;
 } REGF_LF_REC;
 
@@ -143,17 +143,17 @@
 
 typedef struct {
-  REGF_HBIN *hbin;	/* pointer to HBIN record (in memory) containing 
+  REGF_HBIN* hbin;	/* pointer to HBIN record (in memory) containing 
 			 * this nk record 
 			 */
+  char*  valuename;
+  uint8* data;
   uint32 hbin_off;	/* offset from beginning of this hbin block */
   uint32 rec_size;	/* ((start_offset - end_offset) & 0xfffffff8) */
   uint32 rec_off;	/* offset stored in the value list */
   
-  uint8  header[REC_HDR_SIZE];
-  char*  valuename;
   uint32 data_size;
   uint32 data_off;
-  uint8* data;
   uint32 type;
+  uint8  header[REC_HDR_SIZE];
   uint16 flag;
 } REGF_VK_REC;
@@ -164,8 +164,10 @@
 
 typedef struct _regf_sk_rec {
-  struct _regf_sk_rec *next, *prev;
-  REGF_HBIN *hbin;	/* pointer to HBIN record (in memory) containing 
+  struct _regf_sk_rec* next;
+  struct _regf_sk_rec* prev;
+  REGF_HBIN* hbin;	/* pointer to HBIN record (in memory) containing 
 			 * this nk record 
 			 */
+  SEC_DESC* sec_desc;
   uint32 hbin_off;	/* offset from beginning of this hbin block */
   uint32 rec_size;	/* ((start_offset - end_offset) & 0xfffffff8) */
@@ -175,10 +177,9 @@
 			 */
   
-  uint8  header[REC_HDR_SIZE];
   uint32 prev_sk_off;
   uint32 next_sk_off;
   uint32 ref_count;
   uint32 size;
-  SEC_DESC *sec_desc;
+  uint8  header[REC_HDR_SIZE];
 } REGF_SK_REC;
 
@@ -186,19 +187,23 @@
 /* Key Name */ 
 typedef struct {
+  uint32 hbin_off;	/* offset from beginning of this hbin block */
+  uint32 rec_size;	/* ((start_offset - end_offset) & 0xfffffff8) */
   REGF_HBIN *hbin;	/* pointer to HBIN record (in memory) containing 
-			 * this nk record 
-			 */
-  uint32 hbin_off;	/* offset from beginning of this hbin block */
-  /*uint32 subkey_index;*/	/* index to next subkey record to return */
-  uint32 rec_size;	/* ((start_offset - end_offset) & 0xfffffff8) */
+			 * this nk record */
+
+  /* link in the other records here */
+  REGF_VK_REC* values;
+  REGF_SK_REC* sec_desc;
+  REGF_LF_REC subkeys;
   
   /* header information */
+  /* XXX: should we be looking for types other than the root key type? */
+  uint16 key_type;      
   uint8  header[REC_HDR_SIZE];
-  uint16 key_type;
   NTTIME mtime;
+  char* classname;
+  char* keyname;
   uint32 parent_off;	/* back pointer in registry hive */
   uint32 classname_off;	
-  char *classname;
-  char *keyname;
   
   /* max lengths */
@@ -218,9 +223,4 @@
   uint32 sk_off;	/* offset to SK record */
   
-  /* link in the other records here */
-  REGF_LF_REC subkeys;
-  REGF_VK_REC* values;
-  REGF_SK_REC* sec_desc;
-	
 } REGF_NK_REC;
 
@@ -231,10 +231,14 @@
   int fd;	  /* file descriptor */
   int open_flags; /* flags passed to the open() call */
-  void *mem_ctx;  /* memory context for run-time file access information */
-  REGF_HBIN *block_list; /* list of open hbin blocks */
+  void* mem_ctx;  /* memory context for run-time file access information */
+  REGF_HBIN* block_list; /* list of open hbin blocks */
   
   /* file format information */
+  REGF_SK_REC* sec_desc_list;	/* list of security descriptors referenced 
+				 * by NK records 
+				 */
   
   uint8  header[REGF_HDR_SIZE];	/* "regf" */
+  NTTIME mtime;
   uint32 data_offset;		/* offset to record in the first (or any?) 
 				 * hbin block 
@@ -242,9 +246,4 @@
   uint32 last_block;		/* offset to last hbin block in file */
   uint32 checksum;		/* XOR of bytes 0x0000 - 0x01FB */
-  NTTIME mtime;
-  
-  REGF_SK_REC *sec_desc_list;	/* list of security descriptors referenced 
-				 * by NK records 
-				 */
   
   /* unknowns */
@@ -279,38 +278,41 @@
 /* Function Declarations */
 
-const char*   regfi_type_val2str(unsigned int val);
-int           regfi_type_str2val(const char* str);
-
-char*         regfi_get_sacl(SEC_DESC* sec_desc);
-char*         regfi_get_dacl(SEC_DESC* sec_desc);
-char*         regfi_get_owner(SEC_DESC* sec_desc);
-char*         regfi_get_group(SEC_DESC* sec_desc);
-
-REGF_FILE*    regfi_open(const char* filename);
-int           regfi_close(REGF_FILE* r);
-
-REGF_NK_REC*  regfi_rootkey(REGF_FILE* file);
-/* REGF_NK_REC*  regfi_fetch_subkey( REGF_FILE* file, REGF_NK_REC* nk ); */
-
-void            regfi_key_free(REGF_NK_REC* nk);
-
-REGFI_ITERATOR* regfi_iterator_new(REGF_FILE* fh);
-void            regfi_iterator_free(REGFI_ITERATOR* i);
-bool            regfi_iterator_down(REGFI_ITERATOR* i);
-bool            regfi_iterator_up(REGFI_ITERATOR* i);
-bool            regfi_iterator_to_root(REGFI_ITERATOR* i);
-
-bool            regfi_iterator_find_subkey(REGFI_ITERATOR* i, const char* subkey_name);
-bool            regfi_iterator_walk_path(REGFI_ITERATOR* i, const char** path);
-/* XXX: these which return NK and VK records should return them as consts */
-REGF_NK_REC*    regfi_iterator_cur_key(REGFI_ITERATOR* i);
-REGF_NK_REC*    regfi_iterator_first_subkey(REGFI_ITERATOR* i);
-REGF_NK_REC*    regfi_iterator_cur_subkey(REGFI_ITERATOR* i);
-REGF_NK_REC*    regfi_iterator_next_subkey(REGFI_ITERATOR* i);
-
-bool            regfi_iterator_find_value(REGFI_ITERATOR* i, const char* value_name);
-REGF_VK_REC*    regfi_iterator_first_value(REGFI_ITERATOR* i);
-REGF_VK_REC*    regfi_iterator_cur_value(REGFI_ITERATOR* i);
-REGF_VK_REC*    regfi_iterator_next_value(REGFI_ITERATOR* i);
+const char*           regfi_type_val2str(unsigned int val);
+int                   regfi_type_str2val(const char* str);
+
+char*                 regfi_get_sacl(SEC_DESC* sec_desc);
+char*                 regfi_get_dacl(SEC_DESC* sec_desc);
+char*                 regfi_get_owner(SEC_DESC* sec_desc);
+char*                 regfi_get_group(SEC_DESC* sec_desc);
+
+REGF_FILE*            regfi_open(const char* filename);
+int                   regfi_close(REGF_FILE* r);
+
+REGFI_ITERATOR*       regfi_iterator_new(REGF_FILE* fh);
+void                  regfi_iterator_free(REGFI_ITERATOR* i);
+bool                  regfi_iterator_down(REGFI_ITERATOR* i);
+bool                  regfi_iterator_up(REGFI_ITERATOR* i);
+bool                  regfi_iterator_to_root(REGFI_ITERATOR* i);
+
+bool                  regfi_iterator_find_subkey(REGFI_ITERATOR* i, 
+						 const char* subkey_name);
+bool                  regfi_iterator_walk_path(REGFI_ITERATOR* i, 
+					       const char** path);
+const REGF_NK_REC*    regfi_iterator_cur_key(REGFI_ITERATOR* i);
+const REGF_NK_REC*    regfi_iterator_first_subkey(REGFI_ITERATOR* i);
+const REGF_NK_REC*    regfi_iterator_cur_subkey(REGFI_ITERATOR* i);
+const REGF_NK_REC*    regfi_iterator_next_subkey(REGFI_ITERATOR* i);
+
+bool                  regfi_iterator_find_value(REGFI_ITERATOR* i, 
+						const char* value_name);
+const REGF_VK_REC*    regfi_iterator_first_value(REGFI_ITERATOR* i);
+const REGF_VK_REC*    regfi_iterator_cur_value(REGFI_ITERATOR* i);
+const REGF_VK_REC*    regfi_iterator_next_value(REGFI_ITERATOR* i);
+
+
+/* Private Functions */
+REGF_NK_REC*          regfi_rootkey(REGF_FILE* file);
+void                  regfi_key_free(REGF_NK_REC* nk);
+
 
 #endif	/* _REGFI_H */
Index: /trunk/include/smb_deps.h
===================================================================
--- /trunk/include/smb_deps.h	(revision 83)
+++ /trunk/include/smb_deps.h	(revision 84)
@@ -151,6 +151,6 @@
 #define TIME_FIXUP_CONSTANT (369.0*365.25*24*60*60-(3.0*24*60*60+6.0*60*60))
 
-void unix_to_nt_time(NTTIME *nt, time_t t);
-time_t nt_time_to_unix(NTTIME *nt);
+void unix_to_nt_time(NTTIME* nt, time_t t);
+time_t nt_time_to_unix(const NTTIME* nt);
 
 /* End of stuff from lib/time.c */
@@ -169,5 +169,5 @@
 char *prs_mem_get(prs_struct *ps, uint32 extra_size);
 bool prs_uint32(const char *name, prs_struct *ps, int depth, uint32 *data32);
-bool prs_uint32s(bool charmode, const char *name, prs_struct *ps, 
+bool prs_uint32s(const char *name, prs_struct *ps, 
 		 int depth, uint32 *data32s, int len);
 bool prs_uint16(const char *name, prs_struct *ps, int depth, uint16 *data16);
@@ -177,5 +177,5 @@
 		     uint16 *data16, uint32 ptr_uint16, uint32 start_offset);
 bool prs_uint8(const char *name, prs_struct *ps, int depth, uint8 *data8);
-bool prs_uint8s(bool charmode, const char *name, prs_struct *ps, int depth, 
+bool prs_uint8s(const char *name, prs_struct *ps, int depth, 
 		uint8* data8s, int len);
 bool prs_set_offset(prs_struct *ps, uint32 offset);
Index: /trunk/lib/regfi.c
===================================================================
--- /trunk/lib/regfi.c	(revision 83)
+++ /trunk/lib/regfi.c	(revision 84)
@@ -1,5 +1,5 @@
 /*
  * Branched from Samba project Subversion repository, version #7470:
- *   http://websvn.samba.org/cgi-bin/viewcvs.cgi/trunk/source/registry/regfio.c
+ *   http://viewcvs.samba.org/cgi-bin/viewcvs.cgi/trunk/source/registry/regfio.c?rev=7470&view=auto
  *
  * Unix SMB/CIFS implementation.
@@ -437,5 +437,5 @@
   depth++;
 	
-  if(!prs_uint8s(true, "header", ps, depth, file->header, sizeof(file->header)))
+  if(!prs_uint8s("header", ps, depth, file->header, sizeof(file->header)))
     return false;
 	
@@ -499,5 +499,5 @@
   depth++;
 	
-  if(!prs_uint8s(true, "header", ps, depth, hbin->header, sizeof(hbin->header)))
+  if(!prs_uint8s("header", ps, depth, hbin->header, sizeof(hbin->header)))
     return false;
 
@@ -547,5 +547,5 @@
     return false;
 	
-  if (!prs_uint8s(true, "header", ps, depth, nk->header, sizeof(nk->header)))
+  if (!prs_uint8s("header", ps, depth, nk->header, sizeof(nk->header)))
     return false;
 		
@@ -610,5 +610,5 @@
 	return false;
 
-    if(!prs_uint8s(true, "name", ps, depth, (uint8*)nk->keyname, name_length))
+    if(!prs_uint8s("name", ps, depth, (uint8*)nk->keyname, name_length))
       return false;
 
@@ -848,5 +848,5 @@
   if ( !prs_uint32( "nk_off", ps, depth, &hash->nk_off ))
     return false;
-  if ( !prs_uint8s( true, "keycheck", ps, depth, hash->keycheck, sizeof( hash->keycheck )) )
+  if ( !prs_uint8s("keycheck", ps, depth, hash->keycheck, sizeof( hash->keycheck )) )
     return false;
 	
@@ -884,5 +884,5 @@
     return false;
 
-  if(!prs_uint8s(true, "header", &hbin->ps, depth, 
+  if(!prs_uint8s("header", &hbin->ps, depth, 
 		 lf->header, sizeof(lf->header)))
     return false;
@@ -938,5 +938,5 @@
     return false;
 
-  if (!prs_uint8s(true, "header", ps, depth, sk->header, sizeof(sk->header)))
+  if (!prs_uint8s("header", ps, depth, sk->header, sizeof(sk->header)))
     return false;
   if ( !prs_uint16( "tag", ps, depth, &tag))
@@ -990,5 +990,5 @@
     return false;
 
-  if ( !prs_uint8s( true, "header", ps, depth, vk->header, sizeof( vk->header )) )
+  if ( !prs_uint8s("header", ps, depth, vk->header, sizeof( vk->header )) )
     return false;
 
@@ -1019,5 +1019,5 @@
 	return false;
     }
-    if ( !prs_uint8s(true, "name", ps, depth, 
+    if ( !prs_uint8s("name", ps, depth, 
 		     (uint8*)vk->valuename, name_length) )
       return false;
@@ -1030,9 +1030,4 @@
   if ( vk->data_size != 0 ) 
   {
-    bool charmode = false;
-
-    if ( (vk->type == REG_SZ) || (vk->type == REG_MULTI_SZ) )
-      charmode = true;
-
     /* the data is stored in the offset if the size <= 4 */
     if ( !(vk->data_size & VK_DATA_IN_OFFSET) ) 
@@ -1067,5 +1062,5 @@
       if ( !prs_uint32( "data_rec_size", &hblock->ps, depth, &data_rec_size ))
 	return false;
-      if(!prs_uint8s(charmode, "data", &hblock->ps, depth, 
+      if(!prs_uint8s("data", &hblock->ps, depth, 
 		     vk->data, vk->data_size))
 	return false;
@@ -1323,5 +1318,5 @@
     if ( !prs_uint32( "record_size", ps, 0, &record_size ) )
       return false;
-    if ( !prs_uint8s( true, "header", ps, 0, header, REC_HDR_SIZE ) )
+    if ( !prs_uint8s("header", ps, 0, header, REC_HDR_SIZE ) )
       return false;
 
@@ -1600,5 +1595,5 @@
     return false;
 
-  subkey = regfi_iterator_cur_subkey(i);
+  subkey = (REGF_NK_REC*)regfi_iterator_cur_subkey(i);
   if(subkey == NULL)
   {
@@ -1667,5 +1662,5 @@
 
   /* XXX: this alloc/free of each sub key might be a bit excessive */
-  subkey = regfi_iterator_first_subkey(i);
+  subkey = (REGF_NK_REC*)regfi_iterator_first_subkey(i);
   while((subkey != NULL) && (found == false))
   {
@@ -1676,5 +1671,5 @@
     {
       regfi_key_free(subkey);
-      subkey = regfi_iterator_next_subkey(i);
+      subkey = (REGF_NK_REC*)regfi_iterator_next_subkey(i);
     }
   }
@@ -1718,5 +1713,5 @@
 /******************************************************************************
  *****************************************************************************/
-REGF_NK_REC* regfi_iterator_cur_key(REGFI_ITERATOR* i)
+const REGF_NK_REC* regfi_iterator_cur_key(REGFI_ITERATOR* i)
 {
   return i->cur_key;
@@ -1726,5 +1721,5 @@
 /******************************************************************************
  *****************************************************************************/
-REGF_NK_REC* regfi_iterator_first_subkey(REGFI_ITERATOR* i)
+const REGF_NK_REC* regfi_iterator_first_subkey(REGFI_ITERATOR* i)
 {
   i->cur_subkey = 0;
@@ -1735,5 +1730,5 @@
 /******************************************************************************
  *****************************************************************************/
-REGF_NK_REC* regfi_iterator_cur_subkey(REGFI_ITERATOR* i)
+const REGF_NK_REC* regfi_iterator_cur_subkey(REGFI_ITERATOR* i)
 {
   REGF_NK_REC* subkey;
@@ -1778,7 +1773,7 @@
  *****************************************************************************/
 /* XXX: some way of indicating reason for failure should be added. */
-REGF_NK_REC* regfi_iterator_next_subkey(REGFI_ITERATOR* i)
-{
-  REGF_NK_REC* subkey;
+const REGF_NK_REC* regfi_iterator_next_subkey(REGFI_ITERATOR* i)
+{
+  const REGF_NK_REC* subkey;
 
   i->cur_subkey++;
@@ -1796,5 +1791,5 @@
 bool regfi_iterator_find_value(REGFI_ITERATOR* i, const char* value_name)
 {
-  REGF_VK_REC* cur;
+  const REGF_VK_REC* cur;
   bool found = false;
 
@@ -1823,5 +1818,5 @@
 /******************************************************************************
  *****************************************************************************/
-REGF_VK_REC* regfi_iterator_first_value(REGFI_ITERATOR* i)
+const REGF_VK_REC* regfi_iterator_first_value(REGFI_ITERATOR* i)
 {
   i->cur_value = 0;
@@ -1832,5 +1827,5 @@
 /******************************************************************************
  *****************************************************************************/
-REGF_VK_REC* regfi_iterator_cur_value(REGFI_ITERATOR* i)
+const REGF_VK_REC* regfi_iterator_cur_value(REGFI_ITERATOR* i)
 {
   REGF_VK_REC* ret_val = NULL;
@@ -1844,7 +1839,7 @@
 /******************************************************************************
  *****************************************************************************/
-REGF_VK_REC* regfi_iterator_next_value(REGFI_ITERATOR* i)
-{
-  REGF_VK_REC* ret_val;
+const REGF_VK_REC* regfi_iterator_next_value(REGFI_ITERATOR* i)
+{
+  const REGF_VK_REC* ret_val;
 
   i->cur_value++;
Index: /trunk/lib/smb_deps.c
===================================================================
--- /trunk/lib/smb_deps.c	(revision 83)
+++ /trunk/lib/smb_deps.c	(revision 84)
@@ -101,5 +101,5 @@
  converts this to real GMT.
 ****************************************************************************/
-time_t nt_time_to_unix(NTTIME *nt)
+time_t nt_time_to_unix(const NTTIME* nt)
 {
   double d;
@@ -316,5 +316,5 @@
  Stream an array of uint32s. Length is number of uint32s.
  ********************************************************************/
-bool prs_uint32s(bool charmode, const char *name, prs_struct *ps, 
+bool prs_uint32s(const char *name, prs_struct *ps, 
 		 int depth, uint32 *data32s, int len)
 {
@@ -462,5 +462,5 @@
  Stream an array of uint8s. Length is number of uint8s.
  ********************************************************************/
-bool prs_uint8s(bool charmode, const char *name, prs_struct *ps, int depth, 
+bool prs_uint8s(const char *name, prs_struct *ps, int depth, 
 		uint8* data8s, int len)
 {
@@ -526,9 +526,9 @@
     return false;
   
-  if(!prs_uint8s (false, "data   ", ps, depth, 
+  if(!prs_uint8s ("data   ", ps, depth, 
 		  uuid->clock_seq, sizeof(uuid->clock_seq)))
     return false;
 
-  if(!prs_uint8s (false, "data   ", ps, depth, uuid->node, sizeof(uuid->node)))
+  if(!prs_uint8s ("data   ", ps, depth, uuid->node, sizeof(uuid->node)))
     return false;
   
@@ -587,5 +587,5 @@
     sid->num_auths = MAXSUBAUTHS;
 
-  if(!prs_uint32s(false, "sub_auths ", ps, depth, 
+  if(!prs_uint32s("sub_auths ", ps, depth, 
 		  sid->sub_auths, sid->num_auths))
   { return false; }
Index: /trunk/src/reglookup.c
===================================================================
--- /trunk/src/reglookup.c	(revision 83)
+++ /trunk/src/reglookup.c	(revision 84)
@@ -524,5 +524,5 @@
 
 
-void printValue(REGF_VK_REC* vk, char* prefix)
+void printValue(const REGF_VK_REC* vk, char* prefix)
 {
   char* quoted_value = NULL;
@@ -534,4 +534,7 @@
 
   /* Thanks Microsoft for making this process so straight-forward!!! */
+  /* XXX: this logic should be abstracted  and pushed into the regfi 
+   *      interface.  This includes the size limits.
+   */
   size = (vk->data_size & ~VK_DATA_IN_OFFSET);
   if(vk->data_size & VK_DATA_IN_OFFSET)
@@ -618,5 +621,5 @@
 void printValueList(REGFI_ITERATOR* i, char* prefix)
 {
-  REGF_VK_REC* value;
+  const REGF_VK_REC* value;
 
   value = regfi_iterator_first_value(i);
@@ -630,5 +633,5 @@
 
 
-void printKey(REGF_NK_REC* k, char* full_path)
+void printKey(const REGF_NK_REC* k, char* full_path)
 {
   static char empty_str[1] = "";
@@ -679,7 +682,7 @@
 void printKeyTree(REGFI_ITERATOR* iter)
 {
-  REGF_NK_REC* root = NULL;
-  REGF_NK_REC* cur = NULL;
-  REGF_NK_REC* sub = NULL;
+  const REGF_NK_REC* root = NULL;
+  const REGF_NK_REC* cur = NULL;
+  const REGF_NK_REC* sub = NULL;
   char* path = NULL;
   int key_type = regfi_type_str2val("KEY");
@@ -750,5 +753,5 @@
 int retrievePath(REGFI_ITERATOR* iter, char** path)
 {
-  REGF_VK_REC* value;
+  const REGF_VK_REC* value;
   char* tmp_path_joined;
   const char** tmp_path;
