- Timestamp:
- 01/16/07 20:46:07 (18 years ago)
- Location:
- trunk/lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/regfi.c
r79 r80 601 601 if ( class_length ) 602 602 { 603 /* XXX: why isn't this parsed? */ 603 604 ;; 604 605 } … … 833 834 834 835 if ( hbin ) 836 /* XXX: this kind of caching needs to be re-evaluated */ 835 837 DLIST_ADD( file->block_list, hbin ); 836 838 … … 1107 1109 1108 1110 depth++; 1109 1111 1110 1112 /* check if we have anything to do first */ 1111 1113 if(nk->num_values == 0) 1112 1114 return true; 1113 1115 1114 1116 if(hbin->ps.io) 1115 1117 { … … 1118 1120 return false; 1119 1121 } 1120 1122 1121 1123 /* convert the offset to something relative to this HBIN block */ 1122 1124 if (!prs_set_offset(&hbin->ps, … … 1135 1137 if ( !prs_uint32( "record_size", &hbin->ps, depth, &record_size ) ) 1136 1138 return false; 1137 1139 1138 1140 for ( i=0; i<nk->num_values; i++ ) 1139 1141 { … … 1157 1159 } 1158 1160 } 1159 1161 1160 1162 new_offset = nk->values[i].rec_off 1161 1163 + HBIN_HDR_SIZE … … 1180 1182 { 1181 1183 REGF_SK_REC *p_sk; 1182 1184 1183 1185 for ( p_sk=file->sec_desc_list; p_sk; p_sk=p_sk->next ) { 1184 1186 if ( p_sk->sk_off == offset ) 1185 1187 return p_sk; 1186 1188 } 1187 1189 1188 1190 return NULL; 1189 1191 } … … 1213 1215 int depth = 0; 1214 1216 REGF_HBIN *sub_hbin; 1215 1217 1216 1218 depth++; 1217 1219 … … 1283 1285 1284 1286 nk->sec_desc->sk_off = nk->sk_off; 1287 /* XXX: this kind of caching needs to be re-evaluated */ 1285 1288 DLIST_ADD( file->sec_desc_list, nk->sec_desc ); 1286 1289 } … … 1411 1414 1412 1415 /******************************************************************* 1416 XXX: should this be nuked? 1413 1417 *******************************************************************/ 1414 1418 static void regfi_mem_free( REGF_FILE *file ) … … 1443 1447 1444 1448 1445 /******************************************************************* 1446 There should be only *one* root key in the registry file based1447 on my experience. --jerry1448 *******************************************************************/1449 /****************************************************************************** 1450 * There should be only *one* root key in the registry file based 1451 * on my experience. --jerry 1452 *****************************************************************************/ 1449 1453 REGF_NK_REC* regfi_rootkey( REGF_FILE *file ) 1450 1454 { … … 1496 1500 } 1497 1501 1502 /* XXX: this kind of caching needs to be re-evaluated */ 1498 1503 DLIST_ADD( file->block_list, hbin ); 1499 1504 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 *****************************************************************************/ 1511 void 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 *****************************************************************************/ 1535 void 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 *****************************************************************************/ 1549 REGFI_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 *****************************************************************************/ 1582 void 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. */ 1603 bool 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 *****************************************************************************/ 1638 bool 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 *****************************************************************************/ 1658 bool 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 *****************************************************************************/ 1669 bool 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 *****************************************************************************/ 1702 bool 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 *****************************************************************************/ 1727 REGF_NK_REC* regfi_iterator_cur_key(REGFI_ITERATOR* i); 1728 { 1729 return i->cur_key; 1730 } 1731 1732 1733 /****************************************************************************** 1734 *****************************************************************************/ 1735 REGF_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 *****************************************************************************/ 1747 REGF_NK_REC* regfi_iterator_cur_subkey(REGFI_ITERATOR* i) 1748 { 1749 REGF_NK_REC* subkey; 1750 REGF_HBIN* hbin; 1751 uint32 nk_offset; 1517 1752 1518 1753 /* 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; 1522 1759 1523 1760 /* 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 */ 1527 1765 /*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 1533 1770 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 1538 1774 if(!(subkey = (REGF_NK_REC*)zalloc(sizeof(REGF_NK_REC)))) 1539 1775 return NULL; 1540 1776 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 } 1543 1782 1544 1783 return subkey; 1545 1784 } 1785 1786 1787 /****************************************************************************** 1788 *****************************************************************************/ 1789 /* XXX: some way of indicating reason for failure should be added. */ 1790 REGF_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 *****************************************************************************/ 1806 bool 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 *****************************************************************************/ 1835 REGF_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 *****************************************************************************/ 1844 REGF_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 *****************************************************************************/ 1856 REGF_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 88 88 89 89 90 void void_stack_ destroy(void_stack* stack)90 void void_stack_free(void_stack* stack) 91 91 { 92 92 free(stack->elements); … … 95 95 96 96 97 void void_stack_ destroy_deep(void_stack* stack)97 void void_stack_free_deep(void_stack* stack) 98 98 { 99 99 unsigned short i; … … 167 167 168 168 169 void void_stack_iterator_ destroy(void_stack_iterator* iter)169 void void_stack_iterator_free(void_stack_iterator* iter) 170 170 { 171 171 free(iter);
Note: See TracChangeset
for help on using the changeset viewer.