Index: trunk/include/regfi.h
===================================================================
--- trunk/include/regfi.h	(revision 108)
+++ trunk/include/regfi.h	(revision 109)
@@ -182,6 +182,4 @@
 typedef struct _regf_sk_rec 
 {
-  struct _regf_sk_rec* next;
-  struct _regf_sk_rec* prev;
   REGF_HBIN* hbin;	/* pointer to HBIN record (in memory) containing 
 			 * this nk record 
@@ -215,5 +213,4 @@
   /* link in the other records here */
   REGF_VK_REC** values;
-  REGF_SK_REC* sec_desc;
   REGF_HASH_LIST* subkeys;
   
@@ -264,5 +261,4 @@
   range_list* hbins;
   range_list* unalloc_cells;
-  lru_cache* sk_recs;
 
   /* file format information */  
@@ -295,4 +291,5 @@
   REGF_FILE* f;
   void_stack* key_positions;
+  lru_cache* sk_recs;
   REGF_NK_REC* cur_key;
   uint32 cur_subkey;
@@ -336,4 +333,5 @@
 					       const char** path);
 const REGF_NK_REC*    regfi_iterator_cur_key(REGFI_ITERATOR* i);
+const REGF_SK_REC*    regfi_iterator_cur_sk(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);
Index: trunk/lib/regfi.c
===================================================================
--- trunk/lib/regfi.c	(revision 108)
+++ trunk/lib/regfi.c	(revision 109)
@@ -681,25 +681,10 @@
 
 
+
 /*******************************************************************
-
-static REGF_SK_REC* find_sk_record_by_sec_desc( REGF_FILE *file, SEC_DESC *sd )
-{
-  REGF_SK_REC *p;
-
-  for ( p=file->sec_desc_list; p; p=p->next ) {
-    if ( sec_desc_equal( p->sec_desc, sd ) )
-      return p;
-  }
-
-
-  return NULL;
-}
- *******************************************************************/
-
-/*******************************************************************
- * TODO: Need to add full key and SK record caching using a 
+ * TODO: Need to add full key caching using a 
  *       custom cache structure.
  *******************************************************************/
-REGF_NK_REC* regfi_load_key(REGF_FILE *file, uint32 offset, bool strict)
+REGF_NK_REC* regfi_load_key(REGF_FILE* file, uint32 offset, bool strict)
 {
   REGF_HBIN* hbin;
@@ -780,38 +765,4 @@
   }
 
-  /* get the security descriptor.  First look if we have already parsed it */
-  if((nk->sk_off!=REGF_OFFSET_NONE)
-     && !(nk->sec_desc = (REGF_SK_REC*)lru_cache_find(file->sk_recs, 
-						      &nk->sk_off, 4)))
-  {
-    sub_hbin = hbin;
-    if(!regfi_offset_in_hbin(hbin, nk->sk_off))
-      sub_hbin = regfi_lookup_hbin(file, nk->sk_off);
-
-    if(sub_hbin == NULL)
-    {
-      free(nk);
-      /* TODO: need convenient way to free nk->values and nk->subkeys deeply 
-       *       in all cases. 
-       */
-      return NULL;
-    }
-
-    off = nk->sk_off + REGF_BLOCKSIZE;
-    max_length = sub_hbin->block_size + sub_hbin->file_off - off;
-    nk->sec_desc = regfi_parse_sk(file, off, max_length, true);
-    if(strict && nk->sec_desc == NULL)
-    {
-      free(nk);
-      /* TODO: need convenient way to free nk->values and nk->subkeys deeply 
-       *       in all cases. 
-       */
-      return NULL;
-    }
-    nk->sec_desc->sk_off = nk->sk_off;
-    
-    lru_cache_update(file->sk_recs, &nk->sk_off, 4, nk->sec_desc);
-  }
-  
   return nk;
 }
@@ -903,7 +854,4 @@
   }
   
-  /* TODO: come up with a better secret. */
-  rb->sk_recs = lru_cache_create(127, 0xDEADBEEF, true);
-
   rla = true;
   hbin_off = REGF_BLOCKSIZE;
@@ -942,6 +890,4 @@
   range_list_free(file->unalloc_cells);
 
-  lru_cache_destroy(file->sk_recs);
-
   free(file);
 
@@ -1038,4 +984,7 @@
   }
 
+  /* TODO: come up with a better secret. */
+  ret_val->sk_recs = lru_cache_create(127, 0xDEADBEEF, true);
+
   ret_val->f = fh;
   ret_val->cur_key = root;
@@ -1062,4 +1011,6 @@
   }
   
+  lru_cache_destroy(i->sk_recs);
+
   free(i);
 }
@@ -1201,4 +1152,40 @@
   return i->cur_key;
 }
+
+
+/******************************************************************************
+ *****************************************************************************/
+const REGF_SK_REC* regfi_iterator_cur_sk(REGFI_ITERATOR* i)
+{
+  REGF_SK_REC* ret_val;
+  REGF_HBIN* hbin;
+  uint32 max_length, off;
+
+  if(i->cur_key == NULL)
+    return NULL;
+  
+  /* First look if we have already parsed it */
+  if((i->cur_key->sk_off!=REGF_OFFSET_NONE)
+     && !(ret_val =(REGF_SK_REC*)lru_cache_find(i->sk_recs, 
+						&i->cur_key->sk_off, 4)))
+  {
+    hbin = regfi_lookup_hbin(i->f, i->cur_key->sk_off);
+
+    if(hbin == NULL)
+      return NULL;
+
+    off = i->cur_key->sk_off + REGF_BLOCKSIZE;
+    max_length = hbin->block_size + hbin->file_off - off;
+    ret_val = regfi_parse_sk(i->f, off, max_length, true);
+    if(ret_val == NULL)
+      return NULL;
+
+    ret_val->sk_off = i->cur_key->sk_off;
+    lru_cache_update(i->sk_recs, &i->cur_key->sk_off, 4, ret_val);
+  }
+
+  return ret_val;
+}
+
 
 
Index: trunk/src/reglookup.c
===================================================================
--- trunk/src/reglookup.c	(revision 108)
+++ trunk/src/reglookup.c	(revision 109)
@@ -44,4 +44,5 @@
 
 /* Other globals */
+REGF_FILE* f;
 const char* key_special_chars = ",\"\\/";
 const char* subfield_special_chars = ",\"\\|";
@@ -621,5 +622,5 @@
 
 
-void printKey(const REGF_NK_REC* k, char* full_path)
+void printKey(REGFI_ITERATOR* i, char* full_path)
 {
   static char empty_str[1] = "";
@@ -631,4 +632,6 @@
   time_t tmp_time[1];
   struct tm* tmp_time_s = NULL;
+  const REGF_SK_REC* sk;
+  const REGF_NK_REC* k = regfi_iterator_cur_key(i);
 
   *tmp_time = nt_time_to_unix(&k->mtime);
@@ -636,10 +639,10 @@
   strftime(mtime, sizeof(mtime), "%Y-%m-%d %H:%M:%S", tmp_time_s);
 
-  if(print_security)
-  {
-    owner = regfi_get_owner(k->sec_desc->sec_desc);
-    group = regfi_get_group(k->sec_desc->sec_desc);
-    sacl = regfi_get_sacl(k->sec_desc->sec_desc);
-    dacl = regfi_get_dacl(k->sec_desc->sec_desc);
+  if(print_security && (sk=regfi_iterator_cur_sk(i)))
+  {
+    owner = regfi_get_owner(sk->sec_desc);
+    group = regfi_get_group(sk->sec_desc);
+    sacl = regfi_get_sacl(sk->sec_desc);
+    dacl = regfi_get_dacl(sk->sec_desc);
     if(owner == NULL)
       owner = empty_str;
@@ -692,5 +695,5 @@
       
       if(!type_filter_enabled || (key_type == type_filter))
-	printKey(cur, path);
+	printKey(iter, path);
       if(!type_filter_enabled || (key_type != type_filter))
 	printValueList(iter, path);
@@ -838,5 +841,4 @@
 {
   char** path = NULL;
-  REGF_FILE* f;
   REGFI_ITERATOR* iter;
   int retr_path_ret;
