Changeset 81
- Timestamp:
- 01/17/07 11:47:39 (18 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Makefile
r74 r81 11 11 12 12 CC=gcc 13 OPTS=-std=gnu89 -pedantic -Wall 13 OPTS=-std=gnu89 -pedantic -Wall -ggdb 14 14 INC=-I/usr/local/include 15 15 LIB=-L/usr/local/lib -
trunk/include/regfi.h
r80 r81 6 6 * Windows NT registry I/O library 7 7 * 8 * Copyright (C) 2005-200 6Timothy D. Morgan8 * Copyright (C) 2005-2007 Timothy D. Morgan 9 9 * Copyright (C) 2005 Gerald (Jerry) Carter 10 10 * … … 68 68 /* XXX: Has MS defined a REG_QWORD_BE? */ 69 69 /* Not a real type in the registry */ 70 #define REG_KEY 0x FFFFFFFF70 #define REG_KEY 0x7FFFFFFF 71 71 72 72 … … 183 183 } REGF_SK_REC; 184 184 185 185 186 /* Key Name */ 186 187 187 typedef struct { 188 188 REGF_HBIN *hbin; /* pointer to HBIN record (in memory) containing … … 220 220 /* link in the other records here */ 221 221 REGF_LF_REC subkeys; 222 REGF_VK_REC *values;223 REGF_SK_REC *sec_desc;222 REGF_VK_REC* values; 223 REGF_SK_REC* sec_desc; 224 224 225 225 } REGF_NK_REC; 226 226 227 227 228 /* REGF block */ 228 229 229 typedef struct { 230 230 /* run time information */ … … 290 290 int regfi_close(REGF_FILE* r); 291 291 292 REGF_NK_REC* regfi_rootkey( REGF_FILE* file);292 REGF_NK_REC* regfi_rootkey(REGF_FILE* file); 293 293 /* REGF_NK_REC* regfi_fetch_subkey( REGF_FILE* file, REGF_NK_REC* nk ); */ 294 294 295 295 void regfi_key_free(REGF_NK_REC* nk); 296 void regfi_value_free(REGF_VK_REC* vk);297 296 298 297 REGFI_ITERATOR* regfi_iterator_new(REGF_FILE* fh); … … 302 301 bool regfi_iterator_to_root(REGFI_ITERATOR* i); 303 302 304 bool regfi_iterator_find_subkey(REGFI_ITERATOR* i, const char* subkey_name) 303 bool regfi_iterator_find_subkey(REGFI_ITERATOR* i, const char* subkey_name); 305 304 bool regfi_iterator_walk_path(REGFI_ITERATOR* i, const char** path); 305 /* XXX: these which return NK and VK records should return them as consts */ 306 306 REGF_NK_REC* regfi_iterator_cur_key(REGFI_ITERATOR* i); 307 307 REGF_NK_REC* regfi_iterator_first_subkey(REGFI_ITERATOR* i); -
trunk/include/void_stack.h
r80 r81 1 1 /* 2 * Copyright (C) 2005 Timothy D. Morgan2 * Copyright (C) 2005,2007 Timothy D. Morgan 3 3 * 4 4 * This program is free software; you can redistribute it and/or modify … … 22 22 #include <string.h> 23 23 24 #ifndef _VOID_STACK_H 24 25 #define _VOID_STACK_H 25 #ifndef _VOID_STACK_H26 26 27 27 typedef struct _void_stack -
trunk/lib/Makefile
r73 r81 3 3 ################################################################################ 4 4 5 FILES=regfi o.o smb_deps.o void_stack.o5 FILES=regfi.o smb_deps.o void_stack.o 6 6 7 7 all: $(FILES) 8 8 9 regfi o.o: regfio.c10 $(CC) $(CFLAGS) $(OPTS) $(INC) -c -o $@ regfi o.c9 regfi.o: regfi.c 10 $(CC) $(CFLAGS) $(OPTS) $(INC) -c -o $@ regfi.c 11 11 12 12 smb_deps.o: smb_deps.c -
trunk/lib/regfi.c
r80 r81 6 6 * Windows NT registry I/O library 7 7 * 8 * Copyright (C) 2005-200 6Timothy D. Morgan8 * Copyright (C) 2005-2007 Timothy D. Morgan 9 9 * Copyright (C) 2005 Gerald (Jerry) Carter 10 10 * … … 25 25 */ 26 26 27 #include "../include/regfi o.h"27 #include "../include/regfi.h" 28 28 29 29 … … 629 629 nk->hbin->dirty = true; 630 630 631 nk->subkey_index = 0;632 631 return true; 633 632 } … … 1516 1515 { 1517 1516 for(i=0; i < nk->num_values; i++) 1518 regfi_value_free(nk->values[i]); 1517 { 1518 if(nk->values[i].valuename != NULL) 1519 free(nk->values[i].valuename); 1520 if(nk->values[i].data != NULL) 1521 free(nk->values[i].data); 1522 } 1519 1523 free(nk->values); 1520 1524 } … … 1533 1537 /****************************************************************************** 1534 1538 *****************************************************************************/ 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 1539 REGFI_ITERATOR* regfi_iterator_new(REGF_FILE* fh) 1550 1540 { … … 1554 1544 return NULL; 1555 1545 1556 root = regfi_rootkey(f );1546 root = regfi_rootkey(fh); 1557 1547 if(root == NULL) 1558 1548 { … … 1725 1715 /****************************************************************************** 1726 1716 *****************************************************************************/ 1727 REGF_NK_REC* regfi_iterator_cur_key(REGFI_ITERATOR* i) ;1717 REGF_NK_REC* regfi_iterator_cur_key(REGFI_ITERATOR* i) 1728 1718 { 1729 1719 return i->cur_key; … … 1735 1725 REGF_NK_REC* regfi_iterator_first_subkey(REGFI_ITERATOR* i) 1736 1726 { 1737 REGF_NK_REC* subkey;1738 REGF_HBIN* hbin;1739 1740 1727 i->cur_subkey = 0; 1741 1728 return regfi_iterator_cur_subkey(i); … … 1821 1808 && (strcasecmp(cur->valuename, value_name) == 0)) 1822 1809 found = true; 1823 cur = re tfi_iterator_next_value(i);1810 cur = regfi_iterator_next_value(i); 1824 1811 } 1825 1812 … … 1846 1833 REGF_VK_REC* ret_val = NULL; 1847 1834 if(i->cur_value < i->cur_key->num_values) 1848 ret_val = i->cur_key->values[i];1835 ret_val = &(i->cur_key->values[i->cur_value]); 1849 1836 1850 1837 return ret_val; -
trunk/lib/void_stack.c
r80 r81 4 4 * leaks. 5 5 * 6 * Copyright (C) 2005 Timothy D. Morgan6 * Copyright (C) 2005,2007 Timothy D. Morgan 7 7 * 8 8 * This program is free software; you can redistribute it and/or modify -
trunk/src/reglookup.c
r80 r81 3 3 * Gerald Carter''s regfio interface. 4 4 * 5 * Copyright (C) 2005-200 6Timothy D. Morgan5 * Copyright (C) 2005-2007 Timothy D. Morgan 6 6 * Copyright (C) 2002 Richard Sharpe, rsharpe@richardsharpe.com 7 7 * … … 382 382 383 383 384 void_stack* path2Stack(const char* s) 385 { 386 void_stack* ret_val; 387 void_stack* rev_ret = void_stack_new(REGF_MAX_DEPTH); 384 char** splitPath(const char* s) 385 { 386 char** ret_val; 388 387 const char* cur = s; 389 388 char* next = NULL; 390 389 char* copy; 391 392 if (rev_ret == NULL) 390 uint32 ret_cur = 0; 391 392 ret_val = (char**)malloc((REGF_MAX_DEPTH+1+1)*sizeof(char**)); 393 if (ret_val == NULL) 393 394 return NULL; 395 ret_val[0] = NULL; 396 397 /* We return a well-formed, 0-length, path even when input is icky. */ 394 398 if (s == NULL) 395 return re v_ret;399 return ret_val; 396 400 397 401 while((next = strchr(cur, '/')) != NULL) … … 405 409 memcpy(copy, cur, next-cur); 406 410 copy[next-cur] = '\0'; 407 if(!void_stack_push(rev_ret, copy)) 411 ret_val[ret_cur++] = copy; 412 if(ret_cur < (REGF_MAX_DEPTH+1+1)) 413 ret_val[ret_cur] = NULL; 414 else 408 415 bailOut(2, "ERROR: Registry maximum depth exceeded.\n"); 409 416 } 410 417 cur = next+1; 411 418 } 419 420 /* Grab last element, if path doesn't end in '/'. */ 412 421 if(strlen(cur) > 0) 413 422 { 414 423 copy = strdup(cur); 415 if(!void_stack_push(rev_ret, copy)) 424 ret_val[ret_cur++] = copy; 425 if(ret_cur < (REGF_MAX_DEPTH+1+1)) 426 ret_val[ret_cur] = NULL; 427 else 416 428 bailOut(2, "ERROR: Registry maximum depth exceeded.\n"); 417 429 } 418 430 419 ret_val = void_stack_copy_reverse(rev_ret);420 void_stack_free(rev_ret);421 422 431 return ret_val; 423 432 } 424 433 425 /* Returns a quoted path from an nk_stack */ 426 char* stack2Path(void_stack* nk_stack) 427 { 428 const REGF_NK_REC* cur; 434 435 /* Returns a quoted path from an iterator's stack */ 436 /* XXX: Some way should be found to integrate this into regfi's API 437 * The problem is that the escaping is sorta reglookup-specific. 438 */ 439 char* iter2Path(REGFI_ITERATOR* i) 440 { 441 const REGFI_ITER_POSITION* cur; 429 442 uint32 buf_left = 127; 430 443 uint32 buf_len = buf_left+1; 431 444 uint32 name_len = 0; 432 445 uint32 grow_amt; 433 char* buf; 446 char* buf; 434 447 char* new_buf; 435 448 char* name; 449 const char* cur_name; 436 450 void_stack_iterator* iter; 437 451 … … 441 455 buf[0] = '\0'; 442 456 443 iter = void_stack_iterator_new( nk_stack);457 iter = void_stack_iterator_new(i->key_positions); 444 458 if (iter == NULL) 445 459 { … … 449 463 450 464 /* skip root element */ 465 if(void_stack_size(i->key_positions) < 1) 466 { 467 buf[0] = '/'; 468 buf[1] = '\0'; 469 return buf; 470 } 451 471 cur = void_stack_iterator_next(iter); 452 472 453 while((cur = void_stack_iterator_next(iter)) != NULL) 454 { 473 do 474 { 475 cur = void_stack_iterator_next(iter); 476 if (cur == NULL) 477 cur_name = i->cur_key->keyname; 478 else 479 cur_name = cur->nk->keyname; 480 455 481 buf[buf_len-buf_left-1] = '/'; 456 482 buf_left -= 1; 457 name = quote_string(cur ->keyname, key_special_chars);483 name = quote_string(cur_name, key_special_chars); 458 484 name_len = strlen(name); 459 485 if(name_len+1 > buf_left) … … 474 500 buf[buf_len-buf_left-1] = '\0'; 475 501 free(name); 476 } 502 } while(cur != NULL); 477 503 478 504 return buf; … … 572 598 573 599 574 void printValueList(REGFI_ITERATOR i, char* prefix)600 void printValueList(REGFI_ITERATOR* i, char* prefix) 575 601 { 576 602 REGF_VK_REC* value; … … 578 604 value = regfi_iterator_first_value(i); 579 605 while(value != NULL) 580 if(!type_filter_enabled || (value.type == type_filter)) 606 { 607 if(!type_filter_enabled || (value->type == type_filter)) 581 608 printValue(value, prefix); 609 value = regfi_iterator_next_value(i); 610 } 582 611 } 583 612 … … 630 659 631 660 632 void printKeyTree(REGF_FILE* f, void_stack* nk_stack, const char* prefix) 633 { 661 void printKeyTree(REGFI_ITERATOR* iter) 662 { 663 REGF_NK_REC* root = NULL; 634 664 REGF_NK_REC* cur = NULL; 635 665 REGF_NK_REC* sub = NULL; 636 666 char* path = NULL; 637 char* val_path = NULL;638 uint32 val_path_len = 0;639 uint32 path_len = 0;640 uint32 prefix_len = strlen(prefix);641 667 int key_type = regfi_type_str2val("KEY"); 668 bool print_this = true; 669 670 root = cur = regfi_iterator_cur_key(iter); 671 sub = regfi_iterator_first_subkey(iter); 642 672 643 if((cur = (REGF_NK_REC*)void_stack_cur(nk_stack)) != NULL) 644 { 645 cur->subkey_index = 0; 646 path = stack2Path(nk_stack); 647 648 if(print_verbose) 649 { 650 if(prefix[0] == '\0') 651 fprintf(stderr, "VERBOSE: Printing key tree under path: /\n"); 652 else 653 fprintf(stderr, "VERBOSE: Printing key tree under path: %s\n", 654 prefix); 655 } 656 657 path_len = strlen(path); 658 val_path_len = prefix_len+path_len; 659 val_path = (char*)malloc(val_path_len+1+1); 660 if(val_path == NULL) 661 bailOut(2, "ERROR: Could not allocate val_path.\n"); 662 663 strcpy(val_path, prefix); 664 strcpy(val_path+prefix_len, path); 665 if(val_path[0] == '\0') 666 { 667 val_path[0] = '/'; 668 val_path[1] = '\0'; 669 } 670 if(!type_filter_enabled || (key_type == type_filter)) 671 printKey(cur, val_path); 672 if(!type_filter_enabled || (key_type != type_filter)) 673 printValueList(cur, val_path); 673 if(root == NULL) 674 bailOut(3, "ERROR: root cannot be NULL.\n"); 675 676 do 677 { 678 if(print_this) 679 { 680 path = iter2Path(iter); 681 if(path == NULL) 682 bailOut(2, "ERROR: Could not construct iterator's path.\n"); 683 684 if(!type_filter_enabled || (key_type == type_filter)) 685 printKey(cur, path); 686 if(!type_filter_enabled || (key_type != type_filter)) 687 printValueList(iter, path); 688 689 free(path); 690 } 674 691 675 while((cur = (REGF_NK_REC*)void_stack_cur(nk_stack)) != NULL)676 { 677 if( (sub = regfi_fetch_subkey(f, cur)) == NULL)692 if(sub == NULL) 693 { 694 if(cur != root) 678 695 { 679 sub = void_stack_pop(nk_stack); 680 /* XXX: This is just a shallow free. Need to write deep free 681 * routines to replace the Samba code for this. 682 */ 683 if(sub != NULL) 684 free(sub); 696 /* We're done with this sub-tree, going up and hitting other branches. */ 697 if(!regfi_iterator_up(iter)) 698 bailOut(3, "ERROR: could not traverse iterator upward.\n"); 699 700 cur = regfi_iterator_cur_key(iter); 701 if(cur == NULL) 702 bailOut(3, "ERROR: unexpected NULL for key.\n"); 703 704 sub = regfi_iterator_next_subkey(iter); 685 705 } 686 else 687 { 688 sub->subkey_index = 0; 689 if(!void_stack_push(nk_stack, sub)) 690 bailOut(2, "ERROR: Registry maximum depth exceeded.\n"); 691 path = stack2Path(nk_stack); 692 if(path != NULL) 693 { 694 path_len = strlen(path); 695 if(val_path_len < prefix_len+path_len) 696 { 697 val_path_len = prefix_len+path_len; 698 val_path = (char*)realloc(val_path, val_path_len+1); 699 if(val_path == NULL) 700 bailOut(2, "ERROR: Could not reallocate val_path.\n"); 701 } 702 strcpy(val_path, prefix); 703 strcpy(val_path+prefix_len, path); 704 if(!type_filter_enabled || (key_type == type_filter)) 705 printKey(sub, val_path); 706 if(!type_filter_enabled || (key_type != type_filter)) 707 printValueList(sub, val_path); 708 } 709 } 710 } 711 } 712 if(val_path != NULL) 713 free(val_path); 706 print_this = false; 707 } 708 else 709 { /* We have unexplored sub-keys. 710 * Let's move down and print this first sub-tree out. 711 */ 712 if(!regfi_iterator_down(iter)) 713 bailOut(3, "ERROR: could not traverse iterator downward.\n"); 714 715 cur = sub; 716 sub = regfi_iterator_first_subkey(iter); 717 print_this = true; 718 } 719 } while(!((cur == root) && (sub == NULL))); 720 714 721 if(print_verbose) 715 722 fprintf(stderr, "VERBOSE: Finished printing key tree.\n"); 716 723 } 724 717 725 718 726 /* … … 724 732 int retrievePath(REGFI_ITERATOR* iter, char** path) 725 733 { 726 REG_VK_REC* value; 734 REGF_VK_REC* value; 735 char* tmp_path_joined; 736 const char** tmp_path; 727 737 uint32 i; 728 char* p;729 char* tmp_path_joined;730 char** tmp_path;731 738 732 739 if(path == NULL) … … 734 741 735 742 /* One extra for any value at the end, and one more for NULL */ 736 tmp_path = (c har**)malloc(sizeof(char**)*(REGF_MAX_DEPTH+1+1));743 tmp_path = (const char**)malloc(sizeof(const char**)*(REGF_MAX_DEPTH+1+1)); 737 744 if(tmp_path == NULL) 738 745 return -2; … … 763 770 764 771 value = regfi_iterator_cur_value(iter); 765 tmp_path_joined = joinPath(tmp_path);772 tmp_path_joined = iter2Path(iter); 766 773 767 774 if((value == NULL) || (tmp_path_joined == NULL)) … … 808 815 int main(int argc, char** argv) 809 816 { 810 void_stack* path_stack;811 817 char** path = NULL; 812 818 REGF_FILE* f; 813 REGF_NK_REC* root;814 819 REGFI_ITERATOR* iter; 815 820 int retr_path_ret; … … 883 888 bailOut(3, "ERROR: Couldn't create registry iterator.\n"); 884 889 890 if(print_header) 891 { 892 if(print_security) 893 printf("PATH,TYPE,VALUE,MTIME,OWNER,GROUP,SACL,DACL\n"); 894 else 895 printf("PATH,TYPE,VALUE,MTIME\n"); 896 } 897 885 898 if(path_filter_enabled && path_filter != NULL) 886 899 path = splitPath(path_filter); 887 900 888 901 if(path != NULL) 889 902 { … … 892 905 fprintf(stderr, "WARNING: specified path not found.\n"); 893 906 else if (retr_path_ret == 2) 894 printKeyTree(iter , path_filter);907 printKeyTree(iter); 895 908 else if(retr_path_ret != 0) 896 909 bailOut(4, "ERROR: Unknown error occurred in retrieving path.\n"); 897 910 } 898 911 else 899 printKeyTree(iter , "");912 printKeyTree(iter); 900 913 901 914 regfi_iterator_free(iter);
Note: See TracChangeset
for help on using the changeset viewer.