Changeset 105


Ignore:
Timestamp:
04/14/08 00:55:41 (17 years ago)
Author:
tim
Message:

fully removed dependence on Samba parse structures from core library

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/regfi.h

    r104 r105  
    128128
    129129  uint8 magic[HBIN_MAGIC_SIZE]; /* "hbin" */
    130   prs_struct ps;         /* data */
    131130} REGF_HBIN;
    132131
     
    384383/* Experimental */
    385384/****************/
     385REGF_NK_REC* regfi_load_key(REGF_FILE* file, uint32 offset, bool strict);
     386
    386387REGF_HASH_LIST* regfi_load_hashlist(REGF_FILE* file, uint32 offset,
    387                                     uint32 num_keys, bool strict);
     388                                    uint32 num_keys, uint32 max_size,
     389                                    bool strict);
    388390
    389391REGF_VK_REC** regfi_load_valuelist(REGF_FILE* file, uint32 offset,
    390                                    uint32 num_values);
     392                                   uint32 num_values, uint32 max_size,
     393                                   bool strict);
    391394
    392395REGF_VK_REC* regfi_parse_vk(REGF_FILE* file, uint32 offset,
     
    397400
    398401
    399 
    400402#endif  /* _REGFI_H */
  • trunk/lib/regfi.c

    r104 r105  
    450450    block_off = REGF_BLOCKSIZE;
    451451    do {
    452       /* cleanup before the next round */
    453       if ( hbin )
    454       {
    455         if(hbin->ps.is_dynamic)
    456           SAFE_FREE(hbin->ps.data_p);
    457         hbin->ps.is_dynamic = false;
    458         hbin->ps.buffer_size = 0;
    459         hbin->ps.data_offset = 0;
    460       }
    461 
    462452      hbin = regfi_parse_hbin(file, block_off, true, false);
    463453
     
    478468
    479469/*******************************************************************
     470 TODO: not currently validating against max_size
    480471 *******************************************************************/
    481472REGF_HASH_LIST* regfi_load_hashlist(REGF_FILE* file, uint32 offset,
    482                                     uint32 num_keys, bool strict)
     473                                    uint32 num_keys, uint32 max_size,
     474                                    bool strict)
    483475{
    484476  REGF_HASH_LIST* ret_val;
     
    657649
    658650/******************************************************************************
    659  *
     651 TODO: not currently validating against max_size.
    660652 ******************************************************************************/
    661653REGF_VK_REC** regfi_load_valuelist(REGF_FILE* file, uint32 offset,
    662                                    uint32 num_values)
     654                                   uint32 num_values, uint32 max_size,
     655                                   bool strict)
    663656{
    664657  REGF_VK_REC** ret_val;
     
    748741/*******************************************************************
    749742 *******************************************************************/
    750 static REGF_NK_REC* hbin_prs_key(REGF_FILE *file, REGF_HBIN *hbin)
    751 {
     743REGF_NK_REC* regfi_load_key(REGF_FILE *file, uint32 offset, bool strict)
     744{
     745  REGF_HBIN* hbin;
    752746  REGF_HBIN* sub_hbin;
    753747  REGF_NK_REC* nk;
    754   uint32 nk_cell_offset;
    755   uint32 nk_max_length;
    756   uint32 sk_max_length;
    757   int depth = 0;
    758 
    759   depth++;
     748  uint32 max_length, off;
     749
     750  hbin = lookup_hbin_block(file, offset-REGF_BLOCKSIZE);
     751  if (hbin == NULL)
     752    return NULL;
    760753
    761754  /* get the initial nk record */
    762   nk_cell_offset = hbin->file_off + hbin->ps.data_offset - sizeof(uint32);
    763   nk_max_length = hbin->block_size - hbin->ps.data_offset + sizeof(uint32);
    764   if ((nk = regfi_parse_nk(file, nk_cell_offset, nk_max_length, true)) == NULL)
    765   {
    766 fprintf(stderr, "DEBUG: regfi_parse_nk returned NULL!\n");
    767     return NULL;
    768   }
     755  max_length = hbin->block_size + hbin->file_off - offset;
     756  if ((nk = regfi_parse_nk(file, offset, max_length, true)) == NULL)
     757    return NULL;
    769758
    770759  /* fill in values */
    771   if ( nk->num_values && (nk->values_off!=REGF_OFFSET_NONE) )
     760  if(nk->num_values && (nk->values_off!=REGF_OFFSET_NONE))
    772761  {
    773762    sub_hbin = hbin;
    774     if ( !hbin_contains_offset( hbin, nk->values_off ) )
    775     {
    776       sub_hbin = lookup_hbin_block( file, nk->values_off );
    777       if ( !sub_hbin )
     763    if(!hbin_contains_offset(hbin, nk->values_off))
     764      sub_hbin = lookup_hbin_block(file, nk->values_off);
     765   
     766    if(sub_hbin == NULL)
     767    {
     768      if(strict)
    778769      {
    779         /*DEBUG(0,("hbin_prs_key: Failed to find HBIN block containing value_list_offset [0x%x]\n",
    780           nk->values_off));*/
     770        free(nk);
    781771        return NULL;
    782772      }
    783     }
    784    
    785     nk->values = regfi_load_valuelist(file, nk->values_off+REGF_BLOCKSIZE,
    786                                       nk->num_values);
    787     if(nk->values == NULL)
    788     {
    789       printf("values borked!\n");
    790       return NULL;
    791     }
    792   }
    793                
    794   /* now get subkeys */
    795   if ( nk->num_subkeys && (nk->subkeys_off!=REGF_OFFSET_NONE) )
    796   {
    797     sub_hbin = hbin;
    798     if ( !hbin_contains_offset( hbin, nk->subkeys_off ) )
    799     {
    800       sub_hbin = lookup_hbin_block( file, nk->subkeys_off );
    801       if ( !sub_hbin )
     773      else
     774        nk->values = NULL;
     775    }
     776    else
     777    {
     778      off = nk->values_off + REGF_BLOCKSIZE;
     779      max_length = sub_hbin->block_size + sub_hbin->file_off - off;
     780      nk->values = regfi_load_valuelist(file, off, nk->num_values, max_length,
     781                                        true);
     782      if(strict && nk->values == NULL)
    802783      {
    803         /*DEBUG(0,("hbin_prs_key: Failed to find HBIN block containing subkey_offset [0x%x]\n",
    804           nk->subkeys_off));*/
     784        free(nk);
    805785        return NULL;
    806786      }
    807787    }
    808 
    809     nk->subkeys = regfi_load_hashlist(file, nk->subkeys_off + REGF_BLOCKSIZE,
    810                                       nk->num_subkeys, true);
    811     if (nk->subkeys == NULL)
    812     {
    813       /* TODO: temporary hack to get around 'ri' records */
    814       nk->num_subkeys = 0;
    815     }
    816   }
    817 
    818   /* get the security descriptor.  First look if we have already parsed it */
    819   if ((nk->sk_off!=REGF_OFFSET_NONE)
    820       && !(nk->sec_desc = find_sk_record_by_offset( file, nk->sk_off )))
     788  }
     789
     790  /* now get subkeys */
     791  if(nk->num_subkeys && (nk->subkeys_off != REGF_OFFSET_NONE))
    821792  {
    822793    sub_hbin = hbin;
    823     if (!hbin_contains_offset(hbin, nk->sk_off))
    824     {
    825       sub_hbin = lookup_hbin_block( file, nk->sk_off );
    826       if ( !sub_hbin )
     794    if(!hbin_contains_offset(hbin, nk->subkeys_off))
     795      sub_hbin = lookup_hbin_block(file, nk->subkeys_off);
     796
     797    if (sub_hbin == NULL)
     798    {
     799      if(strict)
    827800      {
    828801        free(nk);
    829         /*DEBUG(0,("hbin_prs_key: Failed to find HBIN block containing sk_offset [0x%x]\n",
    830           nk->subkeys_off));*/
     802        /* TODO: need convenient way to free nk->values deeply in all cases. */
    831803        return NULL;
    832804      }
    833     }
     805      else
     806        nk->subkeys = NULL;
     807    }
     808    else
     809    {
     810      off = nk->subkeys_off + REGF_BLOCKSIZE;
     811      max_length = sub_hbin->block_size + sub_hbin->file_off - off;
     812      nk->subkeys = regfi_load_hashlist(file, off, nk->num_subkeys,
     813                                        max_length, true);
     814      if(nk->subkeys == NULL)
     815      {
     816        /* TODO: temporary hack to get around 'ri' records */
     817        nk->num_subkeys = 0;
     818      }
     819    }
     820  }
     821
     822  /* get the security descriptor.  First look if we have already parsed it */
     823  if((nk->sk_off!=REGF_OFFSET_NONE)
     824     && !(nk->sec_desc = find_sk_record_by_offset( file, nk->sk_off )))
     825  {
     826    sub_hbin = hbin;
     827    if(!hbin_contains_offset(hbin, nk->sk_off))
     828      sub_hbin = lookup_hbin_block(file, nk->sk_off);
     829
     830    if(sub_hbin == NULL)
     831    {
     832      free(nk);
     833      /* TODO: need convenient way to free nk->values and nk->subkeys deeply
     834       *       in all cases.
     835       */
     836      return NULL;
     837    }
     838
     839    off = nk->sk_off + REGF_BLOCKSIZE;
     840    max_length = sub_hbin->block_size + sub_hbin->file_off - off;
     841    nk->sec_desc = regfi_parse_sk(file, off, max_length, true);
     842    if(strict && nk->sec_desc == NULL)
     843    {
     844      free(nk);
     845      /* TODO: need convenient way to free nk->values and nk->subkeys deeply
     846       *       in all cases.
     847       */
     848      return NULL;
     849    }
     850    nk->sec_desc->sk_off = nk->sk_off;
    834851   
    835     sk_max_length = sub_hbin->block_size - (nk->sk_off - sub_hbin->first_hbin_off);
    836     nk->sec_desc = regfi_parse_sk(file, nk->sk_off + REGF_BLOCKSIZE,
    837                                   sk_max_length, true);
    838     if(nk->sec_desc == NULL)
    839       return NULL;
    840     nk->sec_desc->sk_off = nk->sk_off;
    841                        
    842852    /* add to the list of security descriptors (ref_count has been read from the files) */
    843853    /* XXX: this kind of caching needs to be re-evaluated */
     
    976986                          hbin->block_size-HBIN_HEADER_REC_SIZE, &root_offset))
    977987    {
    978       if(!prs_set_offset(&hbin->ps, root_offset + 4
    979                          - hbin->first_hbin_off - REGF_BLOCKSIZE))
    980         return NULL;
    981      
    982       nk = hbin_prs_key(file, hbin);
     988      nk = regfi_load_key(file, root_offset, true);
    983989      break;
    984990    }
     
    12231229const REGF_NK_REC* regfi_iterator_cur_subkey(REGFI_ITERATOR* i)
    12241230{
    1225   REGF_NK_REC* subkey;
    1226   REGF_HBIN* hbin;
    12271231  uint32 nk_offset;
    12281232
     
    12331237
    12341238  nk_offset = i->cur_key->subkeys->hashes[i->cur_subkey].nk_off;
    1235 
    1236   /* find the HBIN block which should contain the nk record */
    1237   hbin = lookup_hbin_block(i->f, nk_offset);
    1238   if(!hbin)
    1239   {
    1240     /* XXX: should print out some kind of error message every time here */
    1241     /*DEBUG(0,("hbin_prs_key: Failed to find HBIN block containing offset [0x%x]\n",
    1242       i->cur_key->subkeys->hashes[i->cur_subkey].nk_off));*/
    1243     return NULL;
    1244   }
    1245  
    1246   if(!prs_set_offset(&hbin->ps,
    1247                      HBIN_MAGIC_SIZE + nk_offset - hbin->first_hbin_off))
    1248     return NULL;
    1249                
    1250   if((subkey = hbin_prs_key(i->f, hbin)) == NULL)
    1251     return NULL;
    1252 
    1253   return subkey;
     1239 
     1240  return regfi_load_key(i->f, nk_offset+REGF_BLOCKSIZE, true);
    12541241}
    12551242
     
    14591446  uint8 hbin_header[HBIN_HEADER_REC_SIZE];
    14601447  uint32 length, curr_off;
    1461   int32 cell_len;
     1448  uint32 cell_len;
    14621449  bool is_unalloc;
    14631450 
     
    15061493  }
    15071494
    1508   /* TODO: need to get rid of this, but currently lots depends on the
    1509    * ps structure.
    1510    */
    1511   if(!prs_init(&hbin->ps, hbin->block_size, file->mem_ctx, UNMARSHALL))
    1512   {
    1513     free(hbin);
    1514     return NULL;
    1515   }
    1516   length = hbin->block_size;
    1517   if((regfi_read(file->fd, (uint8*)hbin->ps.data_p, &length) != 0)
    1518      || length != hbin->block_size)
    1519   {
    1520     free(hbin);
    1521     return NULL;
    1522   }
    1523 
    1524 
    15251495  if(save_unalloc)
    15261496  {
    1527     cell_len = 0;
    15281497    curr_off = HBIN_HEADER_REC_SIZE;
    1529     while ( curr_off < hbin->block_size )
    1530     {
    1531       is_unalloc = false;
    1532       cell_len = IVALS(hbin->ps.data_p, curr_off);
    1533       if(cell_len > 0)
    1534         is_unalloc = true;
    1535       else
    1536         cell_len = -1*cell_len;
     1498    while(curr_off < hbin->block_size)
     1499    {
     1500      if(!regfi_parse_cell(file->fd, hbin->file_off+curr_off, NULL, 0,
     1501                           &cell_len, &is_unalloc))
     1502        break;
    15371503
    15381504      if((cell_len == 0) || ((cell_len & 0xFFFFFFFC) != cell_len))
     
    15541520    }
    15551521  }
    1556 
    1557   /* TODO: need to get rid of this, but currently lots depends on the
    1558    * ps structure.
    1559    */
    1560   if(!prs_set_offset(&hbin->ps, file->data_offset+HBIN_MAGIC_SIZE))
    1561     return NULL;
    15621522
    15631523  return hbin;
Note: See TracChangeset for help on using the changeset viewer.