Changeset 80 for trunk


Ignore:
Timestamp:
01/16/07 20:46:07 (17 years ago)
Author:
tim
Message:

Major API updates for regfi, and started porting reglookup to the API.

Code is non-functional, but should be soon.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/regfi.h

    r79 r80  
    6868/* XXX: Has MS defined a REG_QWORD_BE? */
    6969/* Not a real type in the registry */
    70 #define REG_KEY                        255
     70#define REG_KEY                        0xFFFFFFFF
    7171
    7272
     
    258258
    259259
    260 
    261260typedef struct {
    262261  REGF_FILE* f;
    263   void_stack* keys;
     262  void_stack* key_positions;
     263  REGF_NK_REC* cur_key;
    264264  uint32 cur_subkey;
    265265  uint32 cur_value;
    266266} REGFI_ITERATOR;
    267267
     268
     269typedef struct {
     270  REGF_NK_REC* nk;
     271  uint32 cur_subkey;
     272  /* We could store a cur_value here as well, but didn't see
     273   * the use in it right now.
     274   */
     275} REGFI_ITER_POSITION;
     276
     277
    268278/******************************************************************************/
    269279/* Function Declarations */
     
    272282int           regfi_type_str2val(const char* str);
    273283
    274 char*         regfi_get_sacl(SEC_DESC *sec_desc);
    275 char*         regfi_get_dacl(SEC_DESC *sec_desc);
    276 char*         regfi_get_owner(SEC_DESC *sec_desc);
    277 char*         regfi_get_group(SEC_DESC *sec_desc);
    278 
    279 REGF_FILE*    regfi_open( const char *filename );
    280 int           regfi_close( REGF_FILE *r );
    281 
    282 REGF_NK_REC*  regfi_rootkey( REGF_FILE *file );
    283 /* REGF_NK_REC*  regfi_fetch_subkey( REGF_FILE *file, REGF_NK_REC *nk ); */
    284 
    285 REGFI_ITERATOR* regfi_iterator_create(REGF_FILE* fh);
    286 bool            regfi_iterator_down(REGFI_ITERATOR* i, const char* subkey_name);
     284char*         regfi_get_sacl(SEC_DESC* sec_desc);
     285char*         regfi_get_dacl(SEC_DESC* sec_desc);
     286char*         regfi_get_owner(SEC_DESC* sec_desc);
     287char*         regfi_get_group(SEC_DESC* sec_desc);
     288
     289REGF_FILE*    regfi_open(const char* filename);
     290int           regfi_close(REGF_FILE* r);
     291
     292REGF_NK_REC*  regfi_rootkey( REGF_FILE* file );
     293/* REGF_NK_REC*  regfi_fetch_subkey( REGF_FILE* file, REGF_NK_REC* nk ); */
     294
     295void            regfi_key_free(REGF_NK_REC* nk);
     296void            regfi_value_free(REGF_VK_REC* vk);
     297
     298REGFI_ITERATOR* regfi_iterator_new(REGF_FILE* fh);
     299void            regfi_iterator_free(REGFI_ITERATOR* i);
     300bool            regfi_iterator_down(REGFI_ITERATOR* i);
    287301bool            regfi_iterator_up(REGFI_ITERATOR* i);
     302bool            regfi_iterator_to_root(REGFI_ITERATOR* i);
     303
     304bool            regfi_iterator_find_subkey(REGFI_ITERATOR* i, const char* subkey_name)
     305bool            regfi_iterator_walk_path(REGFI_ITERATOR* i, const char** path);
     306REGF_NK_REC*    regfi_iterator_cur_key(REGFI_ITERATOR* i);
     307REGF_NK_REC*    regfi_iterator_first_subkey(REGFI_ITERATOR* i);
     308REGF_NK_REC*    regfi_iterator_cur_subkey(REGFI_ITERATOR* i);
    288309REGF_NK_REC*    regfi_iterator_next_subkey(REGFI_ITERATOR* i);
     310
     311bool            regfi_iterator_find_value(REGFI_ITERATOR* i, const char* value_name);
     312REGF_VK_REC*    regfi_iterator_first_value(REGFI_ITERATOR* i);
     313REGF_VK_REC*    regfi_iterator_cur_value(REGFI_ITERATOR* i);
    289314REGF_VK_REC*    regfi_iterator_next_value(REGFI_ITERATOR* i);
    290 REGF_VK_REC*    regfi_iterator_fetch_value(REGFI_ITERATOR* i, const char* value_name);
    291 char*           regfi_iterator_curpath(REGFI_ITERATOR* i);
    292315
    293316#endif  /* _REGFI_H */
  • trunk/include/void_stack.h

    r79 r80  
    3939
    4040
     41/* XXX: need to document these interfaces */
    4142void_stack* void_stack_new(unsigned short max_size);
    4243void_stack* void_stack_copy(const void_stack* v);
    4344void_stack* void_stack_copy_reverse(const void_stack* v);
    44 void void_stack_destroy(void_stack* stack);
    45 void void_stack_destroy_deep(void_stack* stack);
     45void void_stack_free(void_stack* stack);
     46void void_stack_free_deep(void_stack* stack);
    4647unsigned short void_stack_size(void_stack* stack);
    4748void* void_stack_pop(void_stack* stack);
     
    4950const void* void_stack_cur(void_stack* stack);
    5051void_stack_iterator* void_stack_iterator_new(void_stack* stack);
    51 void void_stack_iterator_destroy(void_stack_iterator* iter);
     52void void_stack_iterator_free(void_stack_iterator* iter);
    5253const void* void_stack_iterator_next(void_stack_iterator* iter);
    5354
  • trunk/lib/regfi.c

    r79 r80  
    601601  if ( class_length )
    602602  {
     603    /* XXX: why isn't this parsed? */
    603604    ;;
    604605  }
     
    833834
    834835  if ( hbin )
     836    /* XXX: this kind of caching needs to be re-evaluated */
    835837    DLIST_ADD( file->block_list, hbin );
    836838
     
    11071109
    11081110  depth++;
    1109        
     1111 
    11101112  /* check if we have anything to do first */
    11111113  if(nk->num_values == 0)
    11121114    return true;
    1113                
     1115       
    11141116  if(hbin->ps.io)
    11151117  {
     
    11181120      return false;
    11191121  }
    1120        
     1122 
    11211123  /* convert the offset to something relative to this HBIN block */
    11221124  if (!prs_set_offset(&hbin->ps,
     
    11351137  if ( !prs_uint32( "record_size", &hbin->ps, depth, &record_size ) )
    11361138    return false;
    1137                
     1139       
    11381140  for ( i=0; i<nk->num_values; i++ )
    11391141  {
     
    11571159      }
    11581160    }
    1159                
     1161       
    11601162    new_offset = nk->values[i].rec_off
    11611163      + HBIN_HDR_SIZE
     
    11801182{
    11811183  REGF_SK_REC *p_sk;
    1182        
     1184 
    11831185  for ( p_sk=file->sec_desc_list; p_sk; p_sk=p_sk->next ) {
    11841186    if ( p_sk->sk_off == offset )
    11851187      return p_sk;
    11861188  }
    1187        
     1189 
    11881190  return NULL;
    11891191}
     
    12131215  int depth = 0;
    12141216  REGF_HBIN *sub_hbin;
    1215        
     1217 
    12161218  depth++;
    12171219
     
    12831285
    12841286    nk->sec_desc->sk_off = nk->sk_off;
     1287    /* XXX: this kind of caching needs to be re-evaluated */
    12851288    DLIST_ADD( file->sec_desc_list, nk->sec_desc );
    12861289  }
     
    14111414
    14121415/*******************************************************************
     1416XXX: should this be nuked?
    14131417 *******************************************************************/
    14141418static void regfi_mem_free( REGF_FILE *file )
     
    14431447
    14441448
    1445 /*******************************************************************
    1446  There should be only *one* root key in the registry file based
    1447  on my experience.  --jerry
    1448 *******************************************************************/
     1449/******************************************************************************
     1450 * There should be only *one* root key in the registry file based
     1451 * on my experience.  --jerry
     1452 *****************************************************************************/
    14491453REGF_NK_REC* regfi_rootkey( REGF_FILE *file )
    14501454{
     
    14961500  }
    14971501
     1502  /* XXX: this kind of caching needs to be re-evaluated */
    14981503  DLIST_ADD( file->block_list, hbin );
    14991504
    1500   return nk;           
    1501 }
    1502 
    1503 
    1504 /* XXX: An interator struct should be used instead, and this function
    1505  *   should operate on it, so the state of iteration isn't stored in the
    1506  * REGF_NK_REC struct itself.
    1507  */
    1508 /*******************************************************************
    1509  This acts as an interator over the subkeys defined for a given
    1510  NK record.  Remember that offsets are from the *first* HBIN block.
    1511 *******************************************************************/
    1512 REGF_NK_REC* regfi_fetch_subkey( REGF_FILE *file, REGF_NK_REC *nk )
    1513 {
    1514   REGF_NK_REC *subkey;
    1515   REGF_HBIN   *hbin;
    1516   uint32      nk_offset;
     1505  return nk;
     1506}
     1507
     1508
     1509/******************************************************************************
     1510 *****************************************************************************/
     1511void regfi_key_free(REGF_NK_REC* nk)
     1512{
     1513  uint32 i;
     1514 
     1515  if((nk->values != NULL) && (nk->values_off!=REGF_OFFSET_NONE))
     1516  {
     1517    for(i=0; i < nk->num_values; i++)
     1518      regfi_value_free(nk->values[i]);
     1519    free(nk->values);
     1520  }
     1521
     1522  if(nk->keyname != NULL)
     1523    free(nk->keyname);
     1524  if(nk->classname != NULL)
     1525    free(nk->classname);
     1526
     1527  /* XXX: not freeing hbin because these are cached.  This needs to be reviewed. */
     1528  /* XXX: not freeing sec_desc because these are cached.  This needs to be reviewed. */
     1529  free(nk);
     1530}
     1531
     1532
     1533/******************************************************************************
     1534 *****************************************************************************/
     1535void regfi_value_free(REGF_VK_REC* vk)
     1536{
     1537  if(vk->valuename != NULL)
     1538    free(vk->valuename);
     1539  if(vk->data != NULL)
     1540    free(vk->data); 
     1541 
     1542  /* XXX: not freeing hbin because these are cached.  This needs to be reviewed. */
     1543  free(vk);
     1544}
     1545
     1546
     1547/******************************************************************************
     1548 *****************************************************************************/
     1549REGFI_ITERATOR* regfi_iterator_new(REGF_FILE* fh)
     1550{
     1551  REGF_NK_REC* root;
     1552  REGFI_ITERATOR* ret_val = (REGFI_ITERATOR*)malloc(sizeof(REGFI_ITERATOR));
     1553  if(ret_val == NULL)
     1554    return NULL;
     1555
     1556  root = regfi_rootkey(f);
     1557  if(root == NULL)
     1558  {
     1559    free(ret_val);
     1560    return NULL;
     1561  }
     1562
     1563  ret_val->key_positions = void_stack_new(REGF_MAX_DEPTH);
     1564  if(ret_val->key_positions == NULL)
     1565  {
     1566    free(ret_val);
     1567    free(root);
     1568    return NULL;
     1569  }
     1570
     1571  ret_val->f = fh;
     1572  ret_val->cur_key = root;
     1573  ret_val->cur_subkey = 0;
     1574  ret_val->cur_value = 0;
     1575
     1576  return ret_val;
     1577}
     1578
     1579
     1580/******************************************************************************
     1581 *****************************************************************************/
     1582void regfi_iterator_free(REGFI_ITERATOR* i)
     1583{
     1584  REGFI_ITER_POSITION* cur;
     1585
     1586  if(i->cur_key != NULL)
     1587    regfi_key_free(i->cur_key);
     1588
     1589  while((cur = (REGFI_ITER_POSITION*)void_stack_pop(i->key_positions)) != NULL)
     1590  {
     1591    regfi_key_free(cur->nk);
     1592    free(cur);
     1593  }
     1594 
     1595  free(i);
     1596}
     1597
     1598
     1599
     1600/******************************************************************************
     1601 *****************************************************************************/
     1602/* XXX: some way of indicating reason for failure should be added. */
     1603bool regfi_iterator_down(REGFI_ITERATOR* i)
     1604{
     1605  REGF_NK_REC* subkey;
     1606  REGFI_ITER_POSITION* pos;
     1607
     1608  pos = (REGFI_ITER_POSITION*)malloc(sizeof(REGFI_ITER_POSITION));
     1609  if(pos == NULL)
     1610    return false;
     1611
     1612  subkey = regfi_iterator_cur_subkey(i);
     1613  if(subkey == NULL)
     1614  {
     1615    free(pos);
     1616    return false;
     1617  }
     1618
     1619  pos->nk = i->cur_key;
     1620  pos->cur_subkey = i->cur_subkey;
     1621  if(!void_stack_push(i->key_positions, pos))
     1622  {
     1623    free(pos);
     1624    regfi_key_free(subkey);
     1625    return false;
     1626  }
     1627
     1628  i->cur_key = subkey;
     1629  i->cur_subkey = 0;
     1630  i->cur_value = 0;
     1631
     1632  return true;
     1633}
     1634
     1635
     1636/******************************************************************************
     1637 *****************************************************************************/
     1638bool regfi_iterator_up(REGFI_ITERATOR* i)
     1639{
     1640  REGFI_ITER_POSITION* pos;
     1641
     1642  pos = (REGFI_ITER_POSITION*)void_stack_pop(i->key_positions);
     1643  if(pos == NULL)
     1644    return false;
     1645
     1646  regfi_key_free(i->cur_key);
     1647  i->cur_key = pos->nk;
     1648  i->cur_subkey = pos->cur_subkey;
     1649  i->cur_value = 0;
     1650  free(pos);
     1651
     1652  return true;
     1653}
     1654
     1655
     1656/******************************************************************************
     1657 *****************************************************************************/
     1658bool regfi_iterator_to_root(REGFI_ITERATOR* i)
     1659{
     1660  while(regfi_iterator_up(i))
     1661    continue;
     1662
     1663  return true;
     1664}
     1665
     1666
     1667/******************************************************************************
     1668 *****************************************************************************/
     1669bool regfi_iterator_find_subkey(REGFI_ITERATOR* i, const char* subkey_name)
     1670{
     1671  REGF_NK_REC* subkey;
     1672  bool found = false;
     1673  uint32 old_subkey = i->cur_subkey;
     1674 
     1675  if(subkey_name == NULL)
     1676    return false;
     1677
     1678  /* XXX: this alloc/free of each sub key might be a bit excessive */
     1679  subkey = regfi_iterator_first_subkey(i);
     1680  while((subkey != NULL) && (found == false))
     1681  {
     1682    if(subkey->keyname != NULL
     1683       && strcasecmp(subkey->keyname, subkey_name) == 0)
     1684      found = true;
     1685
     1686    regfi_key_free(subkey);
     1687    subkey = regfi_iterator_next_subkey(i);
     1688  }
     1689
     1690  if(found == false)
     1691  {
     1692    i->cur_subkey = old_subkey;
     1693    return false;
     1694  }
     1695
     1696  return true;
     1697}
     1698
     1699
     1700/******************************************************************************
     1701 *****************************************************************************/
     1702bool regfi_iterator_walk_path(REGFI_ITERATOR* i, const char** path)
     1703{
     1704  uint32 x;
     1705  if(path == NULL)
     1706    return false;
     1707
     1708  for(x=0;
     1709      ((path[x] != NULL) && regfi_iterator_find_subkey(i, path[x])
     1710       && regfi_iterator_down(i));
     1711      x++)
     1712  { continue; }
     1713
     1714  if(path[x] == NULL)
     1715    return true;
     1716 
     1717  /* XXX: is this the right number of times? */
     1718  for(; x > 0; x--)
     1719    regfi_iterator_up(i);
     1720 
     1721  return false;
     1722}
     1723
     1724
     1725/******************************************************************************
     1726 *****************************************************************************/
     1727REGF_NK_REC* regfi_iterator_cur_key(REGFI_ITERATOR* i);
     1728{
     1729  return i->cur_key;
     1730}
     1731
     1732
     1733/******************************************************************************
     1734 *****************************************************************************/
     1735REGF_NK_REC* regfi_iterator_first_subkey(REGFI_ITERATOR* i)
     1736{
     1737  REGF_NK_REC* subkey;
     1738  REGF_HBIN* hbin;
     1739 
     1740  i->cur_subkey = 0;
     1741  return regfi_iterator_cur_subkey(i);
     1742}
     1743
     1744
     1745/******************************************************************************
     1746 *****************************************************************************/
     1747REGF_NK_REC* regfi_iterator_cur_subkey(REGFI_ITERATOR* i)
     1748{
     1749  REGF_NK_REC* subkey;
     1750  REGF_HBIN* hbin;
     1751  uint32 nk_offset;
    15171752
    15181753  /* see if there is anything left to report */
    1519   if (!nk || (nk->subkeys_off==REGF_OFFSET_NONE)
    1520       || (nk->subkey_index >= nk->num_subkeys))
    1521     return NULL;
     1754  if (!(i->cur_key) || (i->cur_key->subkeys_off==REGF_OFFSET_NONE)
     1755      || (i->cur_subkey >= i->cur_key->num_subkeys))
     1756    return NULL;
     1757
     1758  nk_offset = i->cur_key->subkeys.hashes[i->cur_subkey].nk_off;
    15221759
    15231760  /* find the HBIN block which should contain the nk record */
    1524   if(!(hbin
    1525        = lookup_hbin_block(file, nk->subkeys.hashes[nk->subkey_index].nk_off )))
    1526   {
     1761  hbin = lookup_hbin_block(i->f, nk_offset);
     1762  if(!hbin)
     1763  {
     1764    /* XXX: should print out some kind of error message every time here */
    15271765    /*DEBUG(0,("hbin_prs_key: Failed to find HBIN block containing offset [0x%x]\n",
    1528       nk->subkeys.hashes[nk->subkey_index].nk_off));*/
    1529     return NULL;
    1530   }
    1531  
    1532   nk_offset = nk->subkeys.hashes[nk->subkey_index].nk_off;
     1766      i->cur_key->subkeys.hashes[i->cur_subkey].nk_off));*/
     1767    return NULL;
     1768  }
     1769 
    15331770  if(!prs_set_offset(&hbin->ps,
    1534                      (HBIN_HDR_SIZE + nk_offset - hbin->first_hbin_off)))
    1535     return NULL;
    1536                
    1537   nk->subkey_index++;
     1771                     HBIN_HDR_SIZE + nk_offset - hbin->first_hbin_off))
     1772    return NULL;
     1773               
    15381774  if(!(subkey = (REGF_NK_REC*)zalloc(sizeof(REGF_NK_REC))))
    15391775    return NULL;
    15401776
    1541   if(!hbin_prs_key(file, hbin, subkey))
    1542     return NULL;
     1777  if(!hbin_prs_key(i->f, hbin, subkey))
     1778  {
     1779    regfi_key_free(subkey);
     1780    return NULL;
     1781  }
    15431782
    15441783  return subkey;
    15451784}
     1785
     1786
     1787/******************************************************************************
     1788 *****************************************************************************/
     1789/* XXX: some way of indicating reason for failure should be added. */
     1790REGF_NK_REC* regfi_iterator_next_subkey(REGFI_ITERATOR* i)
     1791{
     1792  REGF_NK_REC* subkey;
     1793
     1794  i->cur_subkey++;
     1795  subkey = regfi_iterator_cur_subkey(i);
     1796
     1797  if(subkey == NULL)
     1798    i->cur_subkey--;
     1799
     1800  return subkey;
     1801}
     1802
     1803
     1804/******************************************************************************
     1805 *****************************************************************************/
     1806bool regfi_iterator_find_value(REGFI_ITERATOR* i, const char* value_name)
     1807{
     1808  REGF_VK_REC* cur;
     1809  bool found = false;
     1810
     1811  /* XXX: cur->valuename can be NULL in the registry. 
     1812   *      Should we allow for a way to search for that?
     1813   */
     1814  if(value_name == NULL)
     1815    return false;
     1816
     1817  cur = regfi_iterator_first_value(i);
     1818  while((cur != NULL) && (found == false))
     1819  {
     1820    if((cur->valuename != NULL)
     1821       && (strcasecmp(cur->valuename, value_name) == 0))
     1822      found = true;
     1823    cur = retfi_iterator_next_value(i);
     1824  }
     1825
     1826  if(cur == NULL)
     1827    return false;
     1828 
     1829  return true;
     1830}
     1831
     1832
     1833/******************************************************************************
     1834 *****************************************************************************/
     1835REGF_VK_REC* regfi_iterator_first_value(REGFI_ITERATOR* i)
     1836{
     1837  i->cur_value = 0;
     1838  return regfi_iterator_cur_value(i);
     1839}
     1840
     1841
     1842/******************************************************************************
     1843 *****************************************************************************/
     1844REGF_VK_REC* regfi_iterator_cur_value(REGFI_ITERATOR* i)
     1845{
     1846  REGF_VK_REC* ret_val = NULL;
     1847  if(i->cur_value < i->cur_key->num_values)
     1848    ret_val = i->cur_key->values[i];
     1849
     1850  return ret_val;
     1851}
     1852
     1853
     1854/******************************************************************************
     1855 *****************************************************************************/
     1856REGF_VK_REC* regfi_iterator_next_value(REGFI_ITERATOR* i)
     1857{
     1858  REGF_VK_REC* ret_val;
     1859
     1860  i->cur_value++;
     1861  ret_val = regfi_iterator_cur_value(i);
     1862  if(ret_val == NULL)
     1863    i->cur_value--;
     1864
     1865  return ret_val;
     1866}
  • trunk/lib/void_stack.c

    r52 r80  
    8888
    8989
    90 void void_stack_destroy(void_stack* stack)
     90void void_stack_free(void_stack* stack)
    9191{
    9292  free(stack->elements);
     
    9595
    9696
    97 void void_stack_destroy_deep(void_stack* stack)
     97void void_stack_free_deep(void_stack* stack)
    9898{
    9999  unsigned short i;
     
    167167
    168168
    169 void void_stack_iterator_destroy(void_stack_iterator* iter)
     169void void_stack_iterator_free(void_stack_iterator* iter)
    170170{
    171171  free(iter);
  • trunk/src/reglookup.c

    r79 r80  
    418418
    419419  ret_val = void_stack_copy_reverse(rev_ret);
    420   void_stack_destroy(rev_ret);
     420  void_stack_free(rev_ret);
    421421
    422422  return ret_val;
     
    572572
    573573
    574 void printValueList(REGF_NK_REC* nk, char* prefix)
    575 {
    576   uint32 i;
    577  
    578   for(i=0; i < nk->num_values; i++)
    579     if(!type_filter_enabled || (nk->values[i].type == type_filter))
    580       printValue(nk->values+i, prefix);
     574void printValueList(REGFI_ITERATOR i, char* prefix)
     575{
     576  REGF_VK_REC* value;
     577
     578  value = regfi_iterator_first_value(i);
     579  while(value != NULL)
     580    if(!type_filter_enabled || (value.type == type_filter))
     581      printValue(value, prefix);
    581582}
    582583
     
    715716}
    716717
    717 
    718718/*
    719  * Returns 0 if path was found.
    720  * Returns 1 if path was not found.
     719 * Returns 0 if path was not found.
     720 * Returns 1 if path was found as value.
     721 * Returns 2 if path was found as key.
    721722 * Returns less than 0 on other error.
    722723 */
    723 int retrievePath(REGF_FILE* f, void_stack* nk_stack,
    724                  void_stack* path_stack)
    725 {
    726   REGF_NK_REC* sub = NULL;
    727   REGF_NK_REC* cur = NULL;
    728   void_stack* sub_nk_stack;
    729   char* prefix;
    730   char* cur_str = NULL;
    731   char* path = NULL;
    732   char* name;
    733   uint16 path_depth;
    734   uint32 i, prefix_len;
    735   bool found_cur = true;
    736   if(path_stack == NULL)
     724int retrievePath(REGFI_ITERATOR* iter, char** path)
     725{
     726  REG_VK_REC* value;
     727  uint32 i;
     728  char* p;
     729  char* tmp_path_joined;
     730  char** tmp_path;
     731 
     732  if(path == NULL)
    737733    return -1;
    738734
    739   path_depth = void_stack_size(path_stack);
    740   if(path_depth < 1)
     735  /* One extra for any value at the end, and one more for NULL */
     736  tmp_path = (char**)malloc(sizeof(char**)*(REGF_MAX_DEPTH+1+1));
     737  if(tmp_path == NULL)
    741738    return -2;
    742739
    743   if(void_stack_size(nk_stack) < 1)
    744     return -3;
    745   cur = (REGF_NK_REC*)void_stack_cur(nk_stack);
     740  /* Strip any potential value name at end of path */
     741  for(i=0;
     742      (path[i] != NULL) && (path[i+1] != NULL)
     743        && (i < REGF_MAX_DEPTH+1+1);
     744      i++)
     745    tmp_path[i] = path[i];
     746
     747  tmp_path[i] = NULL;
    746748
    747749  if(print_verbose)
    748     fprintf(stderr, "VERBOSE: Beginning retrieval of specified path: %s\n",
     750    fprintf(stderr, "VERBOSE: Attempting to retrieve specified path: %s\n",
    749751            path_filter);
    750752
    751   while(void_stack_size(path_stack) > 1)
    752   {
    753     /* Search key records only */
    754     cur_str = (char*)void_stack_pop(path_stack);
    755 
    756     found_cur = false;
    757     while(!found_cur &&
    758           (sub = regfi_fetch_subkey(f, cur)) != NULL)
    759     {
    760       if(strcasecmp(sub->keyname, cur_str) == 0)
    761       {
    762         cur = sub;
    763         if(!void_stack_push(nk_stack, sub))
    764           bailOut(2, "ERROR: Registry maximum depth exceeded.\n");
    765 
    766         found_cur = true;
    767       }
    768     }
    769     if(print_verbose && !found_cur)
    770       fprintf(stderr, "VERBOSE: Could not find KEY '%s' in specified path.\n",
    771               cur_str);
    772 
    773     free(cur_str);
    774     if(!found_cur)
    775       return 1;
    776   }
    777 
    778   /* Last round, search value and key records */
    779   cur_str = (char*)void_stack_pop(path_stack);
    780 
    781   if(print_verbose)
    782     fprintf(stderr, "VERBOSE: Searching values for last component"
    783                     " of specified path.\n");
    784 
    785   for(i=0; (i < cur->num_values); i++)
    786   {
    787     /* XXX: Not sure when/why this can be NULL, but it's happened. */
    788     if(sub->values[i].valuename != NULL
    789        && strcasecmp(sub->values[i].valuename, cur_str) == 0)
    790     {
    791       path = stack2Path(nk_stack);
    792 
    793       if(print_verbose)
    794         fprintf(stderr, "VERBOSE: Found final path element as value.\n");
    795 
    796       if(!type_filter_enabled || (sub->values[i].type == type_filter))
    797         printValue(&sub->values[i], path);
    798       if(path != NULL)
    799         free(path);
    800 
    801       return 0;
    802     }
    803   }
    804 
    805   if(print_verbose)
    806     fprintf(stderr, "VERBOSE: Searching keys for last component"
    807                     " of specified path.\n");
    808 
    809   while((sub = regfi_fetch_subkey(f, cur)) != NULL)
    810   {
    811     if(strcasecmp(sub->keyname, cur_str) == 0)
    812     {
    813       sub_nk_stack = void_stack_new(REGF_MAX_DEPTH);
    814       if(!void_stack_push(sub_nk_stack, sub))
    815         bailOut(2, "ERROR: Registry maximum depth exceeded.\n");
    816       prefix = stack2Path(nk_stack);
    817       prefix_len = strlen(prefix);
    818       prefix = realloc(prefix, prefix_len+strlen(sub->keyname)+2);
    819       if(prefix == NULL)
    820         return -1;
    821       name = quote_string(sub->keyname, key_special_chars);
    822       strcat(prefix, "/");
    823       strcat(prefix, name);
    824       free(name);
    825 
    826       if(print_verbose)
    827         fprintf(stderr, "VERBOSE: Found final path element as key.\n");
    828 
    829       printKeyTree(f, sub_nk_stack, prefix);
    830 
    831       return 0;
    832     }
     753  if(!regfi_iterator_walk_path(iter, tmp_path))
     754  {
     755    free(tmp_path);
     756    return 0;
     757  }
     758
     759  if(regfi_iterator_find_value(iter, path[i]))
     760  {
     761    if(print_verbose)
     762      fprintf(stderr, "VERBOSE: Found final path element as value.\n");
     763
     764    value = regfi_iterator_cur_value(iter);
     765    tmp_path_joined = joinPath(tmp_path);
     766
     767    if((value == NULL) || (tmp_path_joined == NULL))
     768      bailOut(2, "ERROR: Unexpected error before printValue.\n");
     769
     770    printValue(value, tmp_path_joined);
     771
     772    free(tmp_path);
     773    free(tmp_path_joined);
     774    return 1;
     775  }
     776  else if(regfi_iterator_find_subkey(iter, path[i]))
     777  {
     778    if(print_verbose)
     779      fprintf(stderr, "VERBOSE: Found final path element as key.\n");
     780    return 2;
    833781  }
    834782
     
    836784    fprintf(stderr, "VERBOSE: Could not find last element of path.\n");
    837785
    838   return 1;
     786  return 0;
    839787}
    840788
     
    860808int main(int argc, char** argv)
    861809{
    862   void_stack* nk_stack;
    863810  void_stack* path_stack;
     811  char** path = NULL;
    864812  REGF_FILE* f;
    865813  REGF_NK_REC* root;
     814  REGFI_ITERATOR* iter;
    866815  int retr_path_ret;
    867816  uint32 argi, arge;
     
    930879  }
    931880
    932   root = regfi_rootkey(f);
    933   nk_stack = void_stack_new(REGF_MAX_DEPTH);
    934 
    935   if(void_stack_push(nk_stack, root))
    936   {
    937     if(print_header)
    938     {
    939       if(print_security)
    940         printf("PATH,TYPE,VALUE,MTIME,OWNER,GROUP,SACL,DACL\n");
    941       else
    942         printf("PATH,TYPE,VALUE,MTIME\n");
    943     }
    944 
    945     path_stack = path2Stack(path_filter);
    946     if(void_stack_size(path_stack) < 1)
    947       printKeyTree(f, nk_stack, "");
    948     else
    949     {
    950       retr_path_ret = retrievePath(f, nk_stack, path_stack);
    951       if(retr_path_ret == 1)
    952         fprintf(stderr, "WARNING: specified path not found.\n");
    953       else if(retr_path_ret != 0)
    954         bailOut(4, "ERROR:\n");
    955     }
     881  iter = regfi_iterator_new(f);
     882  if(iter == NULL)
     883    bailOut(3, "ERROR: Couldn't create registry iterator.\n");
     884
     885  if(path_filter_enabled && path_filter != NULL)
     886    path = splitPath(path_filter);
     887 
     888  if(path != NULL)
     889  {
     890    retr_path_ret = retrievePath(iter, path);
     891    if(retr_path_ret == 0)
     892      fprintf(stderr, "WARNING: specified path not found.\n");
     893    else if (retr_path_ret == 2)
     894      printKeyTree(iter, path_filter);
     895    else if(retr_path_ret != 0)
     896      bailOut(4, "ERROR: Unknown error occurred in retrieving path.\n");
    956897  }
    957898  else
    958     bailOut(2, "ERROR: Registry maximum depth exceeded.\n");
    959 
    960   void_stack_destroy_deep(nk_stack);
     899    printKeyTree(iter, "");
     900
     901  regfi_iterator_free(iter);
    961902  regfi_close(f);
    962903
Note: See TracChangeset for help on using the changeset viewer.