r10656: BIG merge from trunk. Features not copied over
[ira/wip.git] / source3 / registry / regfio.c
index 041db19f27db284ccb4b1f4bbfe8832e1ff15cd6..954f4ae7bd0b6916984c3e783a429ef1d1f07bb4 100644 (file)
@@ -85,11 +85,11 @@ static int read_block( REGF_FILE *file, prs_struct *ps, uint32 file_offset, uint
        if ( (size_t)file_offset >= sbuf.st_size )
                return -1;
        
-       /* if block_size == 0, we are parsnig HBIN records and need 
+       /* if block_size == 0, we are parsing HBIN records and need 
           to read some of the header to get the block_size from there */
           
        if ( block_size == 0 ) {
-               uint8 hdr[0x20];
+               char hdr[0x20];
 
                if ( lseek( file->fd, file_offset, SEEK_SET ) == -1 ) {
                        DEBUG(0,("read_block: lseek() failed! (%s)\n", strerror(errno) ));
@@ -199,7 +199,7 @@ static BOOL prs_regf_block( const char *desc, prs_struct *ps, int depth, REGF_FI
        prs_debug(ps, depth, desc, "prs_regf_block");
        depth++;
        
-       if ( !prs_uint8s( True, "header", ps, depth, file->header, sizeof( file->header )) )
+       if ( !prs_uint8s( True, "header", ps, depth, (uint8*)file->header, sizeof( file->header )) )
                return False;
        
        /* yes, these values are always identical so store them only once */
@@ -261,7 +261,7 @@ static BOOL prs_hbin_block( const char *desc, prs_struct *ps, int depth, REGF_HB
        prs_debug(ps, depth, desc, "prs_regf_block");
        depth++;
        
-       if ( !prs_uint8s( True, "header", ps, depth, hbin->header, sizeof( hbin->header )) )
+       if ( !prs_uint8s( True, "header", ps, depth, (uint8*)hbin->header, sizeof( hbin->header )) )
                return False;
 
        if ( !prs_uint32( "first_hbin_off", ps, depth, &hbin->first_hbin_off ))
@@ -310,7 +310,7 @@ static BOOL prs_nk_rec( const char *desc, prs_struct *ps, int depth, REGF_NK_REC
        if ( !prs_uint32( "rec_size", ps, depth, &nk->rec_size ))
                return False;
        
-       if ( !prs_uint8s( True, "header", ps, depth, nk->header, sizeof( nk->header )) )
+       if ( !prs_uint8s( True, "header", ps, depth, (uint8*)nk->header, sizeof( nk->header )) )
                return False;
                
        if ( !prs_uint16( "key_type", ps, depth, &nk->key_type ))
@@ -371,7 +371,7 @@ static BOOL prs_nk_rec( const char *desc, prs_struct *ps, int depth, REGF_NK_REC
                                return False;
                }
 
-               if ( !prs_uint8s( True, "name", ps, depth, nk->keyname, name_length) )
+               if ( !prs_uint8s( True, "name", ps, depth, (uint8*)nk->keyname, name_length) )
                        return False;
 
                if ( UNMARSHALLING(ps) ) 
@@ -533,7 +533,7 @@ static REGF_HBIN* read_hbin_block( REGF_FILE *file, off_t offset )
 }
 
 /*******************************************************************
- Input a randon offset and receive the correpsonding HBIN 
+ Input a random offset and receive the corresponding HBIN 
  block for it
 *******************************************************************/
 
@@ -549,7 +549,7 @@ static BOOL hbin_contains_offset( REGF_HBIN *hbin, uint32 offset )
 }
 
 /*******************************************************************
- Input a randon offset and receive the correpsonding HBIN 
+ Input a random offset and receive the corresponding HBIN 
  block for it
 *******************************************************************/
 
@@ -561,7 +561,7 @@ static REGF_HBIN* lookup_hbin_block( REGF_FILE *file, uint32 offset )
        /* start with the open list */
 
        for ( hbin=file->block_list; hbin; hbin=hbin->next ) {
-               DEBUG(10,("lookup_hbin_block: address = 0x%x [0x%x]\n", hbin->file_off, (uint32)hbin ));
+               DEBUG(10,("lookup_hbin_block: address = 0x%x [0x%lx]\n", hbin->file_off, (unsigned long)hbin ));
                if ( hbin_contains_offset( hbin, offset ) )
                        return hbin;
        }
@@ -635,7 +635,7 @@ static BOOL hbin_prs_lf_records( const char *desc, REGF_HBIN *hbin, int depth, R
        if ( !prs_uint32( "rec_size", &hbin->ps, depth, &lf->rec_size ))
                return False;
 
-       if ( !prs_uint8s( True, "header", &hbin->ps, depth, lf->header, sizeof( lf->header )) )
+       if ( !prs_uint8s( True, "header", &hbin->ps, depth, (uint8*)lf->header, sizeof( lf->header )) )
                return False;
                
        if ( !prs_uint16( "num_keys", &hbin->ps, depth, &lf->num_keys))
@@ -689,7 +689,7 @@ static BOOL hbin_prs_sk_rec( const char *desc, REGF_HBIN *hbin, int depth, REGF_
        if ( !prs_uint32( "rec_size", &hbin->ps, depth, &sk->rec_size ))
                return False;
 
-       if ( !prs_uint8s( True, "header", ps, depth, sk->header, sizeof( sk->header )) )
+       if ( !prs_uint8s( True, "header", ps, depth, (uint8*)sk->header, sizeof( sk->header )) )
                return False;
        if ( !prs_uint16( "tag", ps, depth, &tag))
                return False;
@@ -741,7 +741,7 @@ static BOOL hbin_prs_vk_rec( const char *desc, REGF_HBIN *hbin, int depth, REGF_
        if ( !prs_uint32( "rec_size", &hbin->ps, depth, &vk->rec_size ))
                return False;
 
-       if ( !prs_uint8s( True, "header", ps, depth, vk->header, sizeof( vk->header )) )
+       if ( !prs_uint8s( True, "header", ps, depth, (uint8*)vk->header, sizeof( vk->header )) )
                return False;
 
        if ( MARSHALLING(&hbin->ps) )
@@ -770,7 +770,7 @@ static BOOL hbin_prs_vk_rec( const char *desc, REGF_HBIN *hbin, int depth, REGF_
                        if ( !(vk->valuename = PRS_ALLOC_MEM( ps, char, name_length+1 )))
                                return False;
                }
-               if ( !prs_uint8s( True, "name", ps, depth, vk->valuename, name_length ) )
+               if ( !prs_uint8s( True, "name", ps, depth, (uint8*)vk->valuename, name_length ) )
                        return False;
        }
 
@@ -1020,7 +1020,7 @@ static BOOL hbin_prs_key( REGF_FILE *file, REGF_HBIN *hbin, REGF_NK_REC *nk )
 
 static BOOL next_record( REGF_HBIN *hbin, const char *hdr, BOOL *eob )
 {
-       char header[REC_HDR_SIZE] = "";
+       uint8 header[REC_HDR_SIZE];
        uint32 record_size;
        uint32 curr_off, block_size;
        BOOL found = False;
@@ -1030,13 +1030,14 @@ static BOOL next_record( REGF_HBIN *hbin, const char *hdr, BOOL *eob )
        if ( curr_off == 0 )
                prs_set_offset( ps, HBIN_HEADER_REC_SIZE );
 
-       /* assume that the current offset is at the reacord header 
+       /* assume that the current offset is at the record header 
           and we need to backup to read the record size */
 
        curr_off -= sizeof(uint32);
 
        block_size = prs_data_size( ps );
        record_size = 0;
+       memset( header, 0x0, sizeof(uint8)*REC_HDR_SIZE );
        while ( !found ) {
 
                curr_off = curr_off+record_size;
@@ -1669,7 +1670,7 @@ static BOOL create_vk_record( REGF_FILE *file, REGF_VK_REC *vk, REGISTRY_VALUE *
 
 static int hashrec_cmp( REGF_HASH_REC *h1, REGF_HASH_REC *h2 )
 {
-       return StrnCaseCmp( h1->keycheck, h2->keycheck, sizeof(uint32) );
+       return StrCaseCmp( h1->fullname, h2->fullname );
 }
 
 /*******************************************************************
@@ -1721,6 +1722,7 @@ static int hashrec_cmp( REGF_HASH_REC *h1, REGF_HASH_REC *h2 )
 
                hash->nk_off = prs_offset( &nk->hbin->ps ) + nk->hbin->first_hbin_off - HBIN_HDR_SIZE;
                memcpy( hash->keycheck, name, sizeof(uint32) );
+               hash->fullname = talloc_strdup( file->mem_ctx, name );
                parent->subkey_index++;
 
                /* sort the list by keyname */
@@ -1766,22 +1768,28 @@ static int hashrec_cmp( REGF_HASH_REC *h1, REGF_HASH_REC *h2 )
 
                        DLIST_ADD_END( file->sec_desc_list, nk->sec_desc, tmp );
 
-                       /* initialize offsets */
-
-                       nk->sec_desc->prev_sk_off = nk->sec_desc->sk_off;
-                       nk->sec_desc->next_sk_off = nk->sec_desc->sk_off;
-
-                       /* now update the offsets for us and the previous sd in the list */
+                       /* update the offsets for us and the previous sd in the list.
+                          if this is the first record, then just set the next and prev
+                          offsets to ourself. */
 
                        if ( nk->sec_desc->prev ) {
                                REGF_SK_REC *prev = nk->sec_desc->prev;
 
                                nk->sec_desc->prev_sk_off = prev->hbin_off + prev->hbin->first_hbin_off - HBIN_HDR_SIZE;
-                               prev->next_sk_off = nk->sk_off;
+                               prev->next_sk_off = nk->sec_desc->sk_off;
+
+                               /* the end must loop around to the front */
+                               nk->sec_desc->next_sk_off = file->sec_desc_list->sk_off;
+
+                               /* and first must loop around to the tail */
+                               file->sec_desc_list->prev_sk_off = nk->sec_desc->sk_off;
+                       } else {
+                               nk->sec_desc->prev_sk_off = nk->sec_desc->sk_off;
+                               nk->sec_desc->next_sk_off = nk->sec_desc->sk_off;
                        }
                }
 
-               /* dump the reference count */
+               /* bump the reference count +1 */
 
                nk->sk_off = nk->sec_desc->sk_off;
                nk->sec_desc->ref_count++;
@@ -1851,8 +1859,8 @@ static int hashrec_cmp( REGF_HASH_REC *h1, REGF_HASH_REC *h2 )
                                nk->max_bytes_valuename = namelen * 2;
 
                        datalen = regval_size( r );
-                       if ( datalen*2 > nk->max_bytes_value )
-                               nk->max_bytes_value = datalen * 2;
+                       if ( datalen > nk->max_bytes_value )
+                               nk->max_bytes_value = datalen;
                }
        }