Changeset 80 for trunk/lib


Ignore:
Timestamp:
01/16/07 20:46:07 (18 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/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 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);
Note: See TracChangeset for help on using the changeset viewer.