Changeset 80
- Timestamp:
- 01/16/07 20:46:07 (18 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/regfi.h
r79 r80 68 68 /* XXX: Has MS defined a REG_QWORD_BE? */ 69 69 /* Not a real type in the registry */ 70 #define REG_KEY 25570 #define REG_KEY 0xFFFFFFFF 71 71 72 72 … … 258 258 259 259 260 261 260 typedef struct { 262 261 REGF_FILE* f; 263 void_stack* keys; 262 void_stack* key_positions; 263 REGF_NK_REC* cur_key; 264 264 uint32 cur_subkey; 265 265 uint32 cur_value; 266 266 } REGFI_ITERATOR; 267 267 268 269 typedef 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 268 278 /******************************************************************************/ 269 279 /* Function Declarations */ … … 272 282 int regfi_type_str2val(const char* str); 273 283 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); 284 char* regfi_get_sacl(SEC_DESC* sec_desc); 285 char* regfi_get_dacl(SEC_DESC* sec_desc); 286 char* regfi_get_owner(SEC_DESC* sec_desc); 287 char* regfi_get_group(SEC_DESC* sec_desc); 288 289 REGF_FILE* regfi_open(const char* filename); 290 int regfi_close(REGF_FILE* r); 291 292 REGF_NK_REC* regfi_rootkey( REGF_FILE* file ); 293 /* REGF_NK_REC* regfi_fetch_subkey( REGF_FILE* file, REGF_NK_REC* nk ); */ 294 295 void regfi_key_free(REGF_NK_REC* nk); 296 void regfi_value_free(REGF_VK_REC* vk); 297 298 REGFI_ITERATOR* regfi_iterator_new(REGF_FILE* fh); 299 void regfi_iterator_free(REGFI_ITERATOR* i); 300 bool regfi_iterator_down(REGFI_ITERATOR* i); 287 301 bool regfi_iterator_up(REGFI_ITERATOR* i); 302 bool regfi_iterator_to_root(REGFI_ITERATOR* i); 303 304 bool regfi_iterator_find_subkey(REGFI_ITERATOR* i, const char* subkey_name) 305 bool regfi_iterator_walk_path(REGFI_ITERATOR* i, const char** path); 306 REGF_NK_REC* regfi_iterator_cur_key(REGFI_ITERATOR* i); 307 REGF_NK_REC* regfi_iterator_first_subkey(REGFI_ITERATOR* i); 308 REGF_NK_REC* regfi_iterator_cur_subkey(REGFI_ITERATOR* i); 288 309 REGF_NK_REC* regfi_iterator_next_subkey(REGFI_ITERATOR* i); 310 311 bool regfi_iterator_find_value(REGFI_ITERATOR* i, const char* value_name); 312 REGF_VK_REC* regfi_iterator_first_value(REGFI_ITERATOR* i); 313 REGF_VK_REC* regfi_iterator_cur_value(REGFI_ITERATOR* i); 289 314 REGF_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);292 315 293 316 #endif /* _REGFI_H */ -
trunk/include/void_stack.h
r79 r80 39 39 40 40 41 /* XXX: need to document these interfaces */ 41 42 void_stack* void_stack_new(unsigned short max_size); 42 43 void_stack* void_stack_copy(const void_stack* v); 43 44 void_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);45 void void_stack_free(void_stack* stack); 46 void void_stack_free_deep(void_stack* stack); 46 47 unsigned short void_stack_size(void_stack* stack); 47 48 void* void_stack_pop(void_stack* stack); … … 49 50 const void* void_stack_cur(void_stack* stack); 50 51 void_stack_iterator* void_stack_iterator_new(void_stack* stack); 51 void void_stack_iterator_ destroy(void_stack_iterator* iter);52 void void_stack_iterator_free(void_stack_iterator* iter); 52 53 const void* void_stack_iterator_next(void_stack_iterator* iter); 53 54 -
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); -
trunk/src/reglookup.c
r79 r80 418 418 419 419 ret_val = void_stack_copy_reverse(rev_ret); 420 void_stack_ destroy(rev_ret);420 void_stack_free(rev_ret); 421 421 422 422 return ret_val; … … 572 572 573 573 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); 574 void 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); 581 582 } 582 583 … … 715 716 } 716 717 717 718 718 /* 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. 721 722 * Returns less than 0 on other error. 722 723 */ 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) 724 int 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) 737 733 return -1; 738 734 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) 741 738 return -2; 742 739 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; 746 748 747 749 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", 749 751 path_filter); 750 752 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; 833 781 } 834 782 … … 836 784 fprintf(stderr, "VERBOSE: Could not find last element of path.\n"); 837 785 838 return 1;786 return 0; 839 787 } 840 788 … … 860 808 int main(int argc, char** argv) 861 809 { 862 void_stack* nk_stack;863 810 void_stack* path_stack; 811 char** path = NULL; 864 812 REGF_FILE* f; 865 813 REGF_NK_REC* root; 814 REGFI_ITERATOR* iter; 866 815 int retr_path_ret; 867 816 uint32 argi, arge; … … 930 879 } 931 880 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"); 956 897 } 957 898 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); 961 902 regfi_close(f); 962 903
Note: See TracChangeset
for help on using the changeset viewer.