Changeset 109 for trunk


Ignore:
Timestamp:
04/29/08 16:38:27 (17 years ago)
Author:
tim
Message:

reworked SK record caching to prevent unnecessary loads.

SK records now cached in iterators on an as-needed basis

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/regfi.h

    r108 r109  
    182182typedef struct _regf_sk_rec
    183183{
    184   struct _regf_sk_rec* next;
    185   struct _regf_sk_rec* prev;
    186184  REGF_HBIN* hbin;      /* pointer to HBIN record (in memory) containing
    187185                         * this nk record
     
    215213  /* link in the other records here */
    216214  REGF_VK_REC** values;
    217   REGF_SK_REC* sec_desc;
    218215  REGF_HASH_LIST* subkeys;
    219216 
     
    264261  range_list* hbins;
    265262  range_list* unalloc_cells;
    266   lru_cache* sk_recs;
    267263
    268264  /* file format information */ 
     
    295291  REGF_FILE* f;
    296292  void_stack* key_positions;
     293  lru_cache* sk_recs;
    297294  REGF_NK_REC* cur_key;
    298295  uint32 cur_subkey;
     
    336333                                               const char** path);
    337334const REGF_NK_REC*    regfi_iterator_cur_key(REGFI_ITERATOR* i);
     335const REGF_SK_REC*    regfi_iterator_cur_sk(REGFI_ITERATOR* i);
    338336const REGF_NK_REC*    regfi_iterator_first_subkey(REGFI_ITERATOR* i);
    339337const REGF_NK_REC*    regfi_iterator_cur_subkey(REGFI_ITERATOR* i);
  • trunk/lib/regfi.c

    r108 r109  
    681681
    682682
     683
    683684/*******************************************************************
    684 
    685 static REGF_SK_REC* find_sk_record_by_sec_desc( REGF_FILE *file, SEC_DESC *sd )
    686 {
    687   REGF_SK_REC *p;
    688 
    689   for ( p=file->sec_desc_list; p; p=p->next ) {
    690     if ( sec_desc_equal( p->sec_desc, sd ) )
    691       return p;
    692   }
    693 
    694 
    695   return NULL;
    696 }
    697  *******************************************************************/
    698 
    699 /*******************************************************************
    700  * TODO: Need to add full key and SK record caching using a
     685 * TODO: Need to add full key caching using a
    701686 *       custom cache structure.
    702687 *******************************************************************/
    703 REGF_NK_REC* regfi_load_key(REGF_FILE *file, uint32 offset, bool strict)
     688REGF_NK_REC* regfi_load_key(REGF_FILE* file, uint32 offset, bool strict)
    704689{
    705690  REGF_HBIN* hbin;
     
    780765  }
    781766
    782   /* get the security descriptor.  First look if we have already parsed it */
    783   if((nk->sk_off!=REGF_OFFSET_NONE)
    784      && !(nk->sec_desc = (REGF_SK_REC*)lru_cache_find(file->sk_recs,
    785                                                       &nk->sk_off, 4)))
    786   {
    787     sub_hbin = hbin;
    788     if(!regfi_offset_in_hbin(hbin, nk->sk_off))
    789       sub_hbin = regfi_lookup_hbin(file, nk->sk_off);
    790 
    791     if(sub_hbin == NULL)
    792     {
    793       free(nk);
    794       /* TODO: need convenient way to free nk->values and nk->subkeys deeply
    795        *       in all cases.
    796        */
    797       return NULL;
    798     }
    799 
    800     off = nk->sk_off + REGF_BLOCKSIZE;
    801     max_length = sub_hbin->block_size + sub_hbin->file_off - off;
    802     nk->sec_desc = regfi_parse_sk(file, off, max_length, true);
    803     if(strict && nk->sec_desc == NULL)
    804     {
    805       free(nk);
    806       /* TODO: need convenient way to free nk->values and nk->subkeys deeply
    807        *       in all cases.
    808        */
    809       return NULL;
    810     }
    811     nk->sec_desc->sk_off = nk->sk_off;
    812    
    813     lru_cache_update(file->sk_recs, &nk->sk_off, 4, nk->sec_desc);
    814   }
    815  
    816767  return nk;
    817768}
     
    903854  }
    904855 
    905   /* TODO: come up with a better secret. */
    906   rb->sk_recs = lru_cache_create(127, 0xDEADBEEF, true);
    907 
    908856  rla = true;
    909857  hbin_off = REGF_BLOCKSIZE;
     
    942890  range_list_free(file->unalloc_cells);
    943891
    944   lru_cache_destroy(file->sk_recs);
    945 
    946892  free(file);
    947893
     
    1038984  }
    1039985
     986  /* TODO: come up with a better secret. */
     987  ret_val->sk_recs = lru_cache_create(127, 0xDEADBEEF, true);
     988
    1040989  ret_val->f = fh;
    1041990  ret_val->cur_key = root;
     
    10621011  }
    10631012 
     1013  lru_cache_destroy(i->sk_recs);
     1014
    10641015  free(i);
    10651016}
     
    12011152  return i->cur_key;
    12021153}
     1154
     1155
     1156/******************************************************************************
     1157 *****************************************************************************/
     1158const REGF_SK_REC* regfi_iterator_cur_sk(REGFI_ITERATOR* i)
     1159{
     1160  REGF_SK_REC* ret_val;
     1161  REGF_HBIN* hbin;
     1162  uint32 max_length, off;
     1163
     1164  if(i->cur_key == NULL)
     1165    return NULL;
     1166 
     1167  /* First look if we have already parsed it */
     1168  if((i->cur_key->sk_off!=REGF_OFFSET_NONE)
     1169     && !(ret_val =(REGF_SK_REC*)lru_cache_find(i->sk_recs,
     1170                                                &i->cur_key->sk_off, 4)))
     1171  {
     1172    hbin = regfi_lookup_hbin(i->f, i->cur_key->sk_off);
     1173
     1174    if(hbin == NULL)
     1175      return NULL;
     1176
     1177    off = i->cur_key->sk_off + REGF_BLOCKSIZE;
     1178    max_length = hbin->block_size + hbin->file_off - off;
     1179    ret_val = regfi_parse_sk(i->f, off, max_length, true);
     1180    if(ret_val == NULL)
     1181      return NULL;
     1182
     1183    ret_val->sk_off = i->cur_key->sk_off;
     1184    lru_cache_update(i->sk_recs, &i->cur_key->sk_off, 4, ret_val);
     1185  }
     1186
     1187  return ret_val;
     1188}
     1189
    12031190
    12041191
  • trunk/src/reglookup.c

    r107 r109  
    4444
    4545/* Other globals */
     46REGF_FILE* f;
    4647const char* key_special_chars = ",\"\\/";
    4748const char* subfield_special_chars = ",\"\\|";
     
    621622
    622623
    623 void printKey(const REGF_NK_REC* k, char* full_path)
     624void printKey(REGFI_ITERATOR* i, char* full_path)
    624625{
    625626  static char empty_str[1] = "";
     
    631632  time_t tmp_time[1];
    632633  struct tm* tmp_time_s = NULL;
     634  const REGF_SK_REC* sk;
     635  const REGF_NK_REC* k = regfi_iterator_cur_key(i);
    633636
    634637  *tmp_time = nt_time_to_unix(&k->mtime);
     
    636639  strftime(mtime, sizeof(mtime), "%Y-%m-%d %H:%M:%S", tmp_time_s);
    637640
    638   if(print_security)
    639   {
    640     owner = regfi_get_owner(k->sec_desc->sec_desc);
    641     group = regfi_get_group(k->sec_desc->sec_desc);
    642     sacl = regfi_get_sacl(k->sec_desc->sec_desc);
    643     dacl = regfi_get_dacl(k->sec_desc->sec_desc);
     641  if(print_security && (sk=regfi_iterator_cur_sk(i)))
     642  {
     643    owner = regfi_get_owner(sk->sec_desc);
     644    group = regfi_get_group(sk->sec_desc);
     645    sacl = regfi_get_sacl(sk->sec_desc);
     646    dacl = regfi_get_dacl(sk->sec_desc);
    644647    if(owner == NULL)
    645648      owner = empty_str;
     
    692695     
    693696      if(!type_filter_enabled || (key_type == type_filter))
    694         printKey(cur, path);
     697        printKey(iter, path);
    695698      if(!type_filter_enabled || (key_type != type_filter))
    696699        printValueList(iter, path);
     
    838841{
    839842  char** path = NULL;
    840   REGF_FILE* f;
    841843  REGFI_ITERATOR* iter;
    842844  int retr_path_ret;
Note: See TracChangeset for help on using the changeset viewer.