Changeset 32
- Timestamp:
- 07/16/05 19:16:17 (19 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/regfio.h
r31 r32 48 48 #include "smb_deps.h" 49 49 50 51 50 /******************************************************************************/ 52 51 /* Macros */ 53 52 53 /* Registry data types */ 54 #define REG_NONE 0 55 #define REG_SZ 1 56 #define REG_EXPAND_SZ 2 57 #define REG_BINARY 3 58 #define REG_DWORD 4 59 #define REG_DWORD_LE 4 /* DWORD, little endian */ 60 #define REG_DWORD_BE 5 /* DWORD, big endian */ 61 #define REG_LINK 6 62 #define REG_MULTI_SZ 7 63 #define REG_RESOURCE_LIST 8 64 #define REG_FULL_RESOURCE_DESCRIPTOR 9 65 #define REG_RESOURCE_REQUIREMENTS_LIST 10 66 /* Not a real type in the registry */ 67 #define REG_KEY 255 68 69 typedef struct _val_str { 70 unsigned int val; 71 const char * str; 72 } VAL_STR; 73 54 74 #define REGF_BLOCKSIZE 0x1000 55 75 #define REGF_ALLOC_BLOCK 0x1000 … … 230 250 /* Function Declarations */ 231 251 252 const char* type_val2str(unsigned int val); 253 int type_str2val(const char* str); 254 232 255 REGF_FILE* regfio_open( const char *filename ); 233 256 int regfio_close( REGF_FILE *r ); -
trunk/include/smb_deps.h
r31 r32 366 366 /* End of stuff from reg_objects.h */ 367 367 368 /* From rpc_reg.h */369 370 /* Registry data types */371 372 #define REG_NONE 0373 #define REG_SZ 1374 #define REG_EXPAND_SZ 2375 #define REG_BINARY 3376 #define REG_DWORD 4377 #define REG_DWORD_LE 4 /* DWORD, little endian */378 #define REG_DWORD_BE 5 /* DWORD, big endian */379 #define REG_LINK 6380 #define REG_MULTI_SZ 7381 #define REG_RESOURCE_LIST 8382 #define REG_FULL_RESOURCE_DESCRIPTOR 9383 #define REG_RESOURCE_REQUIREMENTS_LIST 10384 385 /* End of stuff from rpc_reg.h */386 387 368 /* From rpc_secdes.h */ 388 369 -
trunk/lib/regfio.c
r31 r32 35 35 ******************************************************************/ 36 36 37 /* Registry types mapping */ 38 const VAL_STR reg_type_names[] = 39 { 40 { REG_SZ, "SZ" }, 41 { REG_EXPAND_SZ, "EXPAND_SZ" }, 42 { REG_BINARY, "BIN" }, 43 { REG_DWORD, "DWORD" }, 44 { REG_DWORD_BE, "DWORD_BE" }, 45 { REG_LINK, "LINK" }, 46 { REG_MULTI_SZ, "MULTI_SZ" }, 47 { REG_RESOURCE_LIST, "RSRC_LIST" }, 48 { REG_FULL_RESOURCE_DESCRIPTOR, "RSRC_DESC" }, 49 { REG_RESOURCE_REQUIREMENTS_LIST,"RSRC_REQ_LIST"}, 50 { REG_KEY, "KEY" }, 51 { 0, NULL }, 52 }; 53 54 55 /* Returns NULL on error */ 56 const char* type_val2str(unsigned int val) 57 { 58 int i; 59 60 for(i=0; reg_type_names[i].val && reg_type_names[i].str; i++) 61 if (reg_type_names[i].val == val) 62 return reg_type_names[i].str; 63 64 return NULL; 65 } 66 67 68 /* Returns 0 on error */ 69 int type_str2val(const char* str) 70 { 71 int i; 72 73 for(i=0; reg_type_names[i].val && reg_type_names[i].str; i++) 74 if (strcmp(reg_type_names[i].str, str) == 0) 75 return reg_type_names[i].val; 76 77 return 0; 78 } 79 37 80 38 81 /******************************************************************* … … 95 138 bytes_read = returned = 0; 96 139 97 while ( bytes_read < block_size ) { 98 if ( (returned = read( file->fd, buffer+bytes_read, block_size-bytes_read )) == -1 ) { 140 while ( bytes_read < block_size ) 141 { 142 if((returned = 143 read(file->fd, buffer+bytes_read, block_size-bytes_read)) == -1) 144 { 99 145 /*DEBUG(0,("read_block: read() failed (%s)\n", strerror(errno) ));*/ 100 146 return false; 101 147 } 102 if ( (returned == 0) && (bytes_read < block_size) ) { 148 if ((returned == 0) && (bytes_read < block_size)) 149 { 103 150 /*DEBUG(0,("read_block: not a vald registry file ?\n" ));*/ 104 151 return false; 105 152 } 106 153 107 154 bytes_read += returned; 108 155 } … … 701 748 /* get the data if necessary */ 702 749 703 if ( vk->data_size != 0 ) { 750 if ( vk->data_size != 0 ) 751 { 704 752 bool charmode = false; 705 753 … … 708 756 709 757 /* the data is stored in the offset if the size <= 4 */ 710 711 if ( !(vk->data_size & VK_DATA_IN_OFFSET) ){758 if ( !(vk->data_size & VK_DATA_IN_OFFSET) ) 759 { 712 760 REGF_HBIN *hblock = hbin; 713 761 uint32 data_rec_size; 714 762 715 if ( hbin->ps.io ) { 763 if ( hbin->ps.io ) 764 { 716 765 if ( !(vk->data = (uint8*)zcalloc(sizeof(uint8), vk->data_size) ) ) 717 766 return false; … … 719 768 720 769 /* this data can be in another hbin */ 721 if ( !hbin_contains_offset( hbin, vk->data_off ) ) { 770 if ( !hbin_contains_offset( hbin, vk->data_off ) ) 771 { 722 772 if ( !(hblock = lookup_hbin_block( file, vk->data_off )) ) 723 773 return false; 724 774 } 725 if ( !(prs_set_offset( &hblock->ps, (vk->data_off+HBIN_HDR_SIZE-hblock->first_hbin_off)-sizeof(uint32) )) ) 726 return false; 727 728 if ( !hblock->ps.io ) { 775 if (!(prs_set_offset(&hblock->ps, 776 (vk->data_off 777 + HBIN_HDR_SIZE 778 - hblock->first_hbin_off) 779 - sizeof(uint32)))) 780 { return false; } 781 782 if ( !hblock->ps.io ) 783 { 729 784 data_rec_size = ( (vk->data_size+sizeof(uint32)) & 0xfffffff8 ) + 8; 730 785 data_rec_size = ( data_rec_size - 1 ) ^ 0xFFFFFFFF; … … 732 787 if ( !prs_uint32( "data_rec_size", &hblock->ps, depth, &data_rec_size )) 733 788 return false; 734 if ( !prs_uint8s( charmode, "data", &hblock->ps, depth, vk->data, vk->data_size) ) 789 if(!prs_uint8s(charmode, "data", &hblock->ps, depth, 790 vk->data, vk->data_size)) 735 791 return false; 736 792 … … 738 794 hblock->dirty = true; 739 795 } 740 else { 741 if ( !(vk->data = zcalloc(sizeof(uint8), 4) ) ) 796 else 797 { 798 if(!(vk->data = zcalloc(sizeof(uint8), 4))) 742 799 return false; 743 800 SIVAL( vk->data, 0, vk->data_off ); … … 749 806 750 807 data_size = ((start_off - end_off ) & 0xfffffff8 ); 751 if ( data_size != vk->rec_size )752 /*DEBUG(10,("prs_vk_rec: data_size check failed (0x%x < 0x%x)\n", data_size, vk->rec_size));*/753 754 755 808 /*if ( data_size != vk->rec_size ) 809 DEBUG(10,("prs_vk_rec: data_size check failed (0x%x < 0x%x)\n", data_size, vk->rec_size));*/ 810 811 if ( !hbin->ps.io ) 812 hbin->dirty = true; 756 813 757 814 return true; … … 763 820 in the prs_struct *ps. 764 821 *******************************************************************/ 765 static bool hbin_prs_vk_records( 766 int depth, REGF_NK_REC *nk, REGF_FILE *file)822 static bool hbin_prs_vk_records(const char *desc, REGF_HBIN *hbin, 823 int depth, REGF_NK_REC *nk, REGF_FILE *file) 767 824 { 768 825 int i; … … 772 829 773 830 /* check if we have anything to do first */ 774 775 if ( nk->num_values == 0 ) 831 if(nk->num_values == 0) 776 832 return true; 777 833 778 if ( hbin->ps.io ) { 779 if ( !(nk->values = (REGF_VK_REC*)zcalloc(sizeof(REGF_VK_REC), nk->num_values ) ) ) 834 if(hbin->ps.io) 835 { 836 if (!(nk->values = (REGF_VK_REC*)zcalloc(sizeof(REGF_VK_REC), 837 nk->num_values ))) 780 838 return false; 781 839 } 782 840 783 841 /* convert the offset to something relative to this HBIN block */ 784 785 if ( !prs_set_offset( &hbin->ps, nk->values_off+HBIN_HDR_SIZE-hbin->first_hbin_off-sizeof(uint32)) ) 786 return false; 787 788 if ( !hbin->ps.io ) { 842 if (!prs_set_offset(&hbin->ps, 843 nk->values_off 844 + HBIN_HDR_SIZE 845 - hbin->first_hbin_off 846 - sizeof(uint32))) 847 { return false; } 848 849 if ( !hbin->ps.io ) 850 { 789 851 record_size = ( ( nk->num_values * sizeof(uint32) ) & 0xfffffff8 ) + 8; 790 852 record_size = (record_size - 1) ^ 0xFFFFFFFF; … … 794 856 return false; 795 857 796 for ( i=0; i<nk->num_values; i++ ) { 858 for ( i=0; i<nk->num_values; i++ ) 859 { 797 860 if ( !prs_uint32( "vk_off", &hbin->ps, depth, &nk->values[i].rec_off ) ) 798 861 return false; 799 862 } 800 863 801 for ( i=0; i<nk->num_values; i++ ) { 864 for ( i=0; i<nk->num_values; i++ ) 865 { 802 866 REGF_HBIN *sub_hbin = hbin; 803 867 uint32 new_offset; 804 868 805 if ( !hbin_contains_offset( hbin, nk->values[i].rec_off ) ) { 869 if ( !hbin_contains_offset( hbin, nk->values[i].rec_off ) ) 870 { 806 871 sub_hbin = lookup_hbin_block( file, nk->values[i].rec_off ); 807 if ( !sub_hbin ) { 872 if ( !sub_hbin ) 873 { 808 874 /*DEBUG(0,("hbin_prs_vk_records: Failed to find HBIN block containing offset [0x%x]\n", 809 875 nk->values[i].hbin_off));*/ … … 812 878 } 813 879 814 new_offset = nk->values[i].rec_off + HBIN_HDR_SIZE - sub_hbin->first_hbin_off; 815 if ( !prs_set_offset( &sub_hbin->ps, new_offset ) ) 816 return false; 817 if ( !hbin_prs_vk_rec( "vk_rec", sub_hbin, depth, &nk->values[i], file ) ) 880 new_offset = nk->values[i].rec_off 881 + HBIN_HDR_SIZE 882 - sub_hbin->first_hbin_off; 883 884 if (!prs_set_offset(&sub_hbin->ps, new_offset)) 885 return false; 886 if (!hbin_prs_vk_rec("vk_rec", sub_hbin, depth, &nk->values[i], file)) 818 887 return false; 819 888 } … … 822 891 hbin->dirty = true; 823 892 824 825 893 return true; 826 894 } … … 829 897 /******************************************************************* 830 898 *******************************************************************/ 831 832 899 static REGF_SK_REC* find_sk_record_by_offset( REGF_FILE *file, uint32 offset ) 833 900 { … … 842 909 } 843 910 844 /******************************************************************* 845 *******************************************************************/ 846 911 912 /******************************************************************* 913 *******************************************************************/ 847 914 static REGF_SK_REC* find_sk_record_by_sec_desc( REGF_FILE *file, SEC_DESC *sd ) 848 915 { … … 859 926 } 860 927 861 /******************************************************************* 862 *******************************************************************/ 863 928 929 /******************************************************************* 930 *******************************************************************/ 864 931 static bool hbin_prs_key( REGF_FILE *file, REGF_HBIN *hbin, REGF_NK_REC *nk ) 865 932 { … … 876 943 /* fill in values */ 877 944 878 if ( nk->num_values && (nk->values_off!=REGF_OFFSET_NONE) ) { 945 if ( nk->num_values && (nk->values_off!=REGF_OFFSET_NONE) ) 946 { 879 947 sub_hbin = hbin; 880 if ( !hbin_contains_offset( hbin, nk->values_off ) ) { 948 if ( !hbin_contains_offset( hbin, nk->values_off ) ) 949 { 881 950 sub_hbin = lookup_hbin_block( file, nk->values_off ); 882 if ( !sub_hbin ) { 951 if ( !sub_hbin ) 952 { 883 953 /*DEBUG(0,("hbin_prs_key: Failed to find HBIN block containing value_list_offset [0x%x]\n", 884 954 nk->values_off));*/ … … 887 957 } 888 958 889 if ( !hbin_prs_vk_records( "vk_rec", sub_hbin, depth, nk, file))959 if(!hbin_prs_vk_records("vk_rec", sub_hbin, depth, nk, file)) 890 960 return false; 891 961 } 892 962 893 963 /* now get subkeys */ 894 895 if ( nk->num_subkeys && (nk->subkeys_off!=REGF_OFFSET_NONE) ){964 if ( nk->num_subkeys && (nk->subkeys_off!=REGF_OFFSET_NONE) ) 965 { 896 966 sub_hbin = hbin; 897 if ( !hbin_contains_offset( hbin, nk->subkeys_off ) ) { 967 if ( !hbin_contains_offset( hbin, nk->subkeys_off ) ) 968 { 898 969 sub_hbin = lookup_hbin_block( file, nk->subkeys_off ); 899 if ( !sub_hbin ) { 970 if ( !sub_hbin ) 971 { 900 972 /*DEBUG(0,("hbin_prs_key: Failed to find HBIN block containing subkey_offset [0x%x]\n", 901 973 nk->subkeys_off));*/ … … 904 976 } 905 977 906 if ( !hbin_prs_lf_records( "lf_rec", sub_hbin, depth, nk))978 if (!hbin_prs_lf_records("lf_rec", sub_hbin, depth, nk)) 907 979 return false; 908 980 } … … 910 982 /* get the to the security descriptor. First look if we have already parsed it */ 911 983 912 if ( (nk->sk_off!=REGF_OFFSET_NONE) && !( nk->sec_desc = find_sk_record_by_offset( file, nk->sk_off )) ) { 913 984 if ((nk->sk_off!=REGF_OFFSET_NONE) 985 && !(nk->sec_desc = find_sk_record_by_offset( file, nk->sk_off ))) 986 { 914 987 sub_hbin = hbin; 915 if ( !hbin_contains_offset( hbin, nk->sk_off ) ) { 988 if (!hbin_contains_offset(hbin, nk->sk_off)) 989 { 916 990 sub_hbin = lookup_hbin_block( file, nk->sk_off ); 917 991 if ( !sub_hbin ) { … … 937 1011 } 938 1012 939 /******************************************************************* 940 *******************************************************************/ 941 1013 1014 /******************************************************************* 1015 *******************************************************************/ 942 1016 static bool next_record( REGF_HBIN *hbin, const char *hdr, bool *eob ) 943 1017 { … … 954 1028 /* assume that the current offset is at the reacord header 955 1029 and we need to backup to read the record size */ 956 957 1030 curr_off -= sizeof(uint32); 958 1031 959 1032 block_size = ps->buffer_size; 960 1033 record_size = 0; 961 while ( !found ) {962 1034 while ( !found ) 1035 { 963 1036 curr_off = curr_off+record_size; 964 1037 if ( curr_off >= block_size ) … … 985 1058 986 1059 /* mark prs_struct as done ( at end ) if no more SK records */ 987 /* mark end-of-block as true */ 988 989 if ( !found ) 1060 /* mark end-of-block as true */ 1061 if ( !found ) 990 1062 { 991 1063 prs_set_offset( &hbin->ps, hbin->ps.buffer_size ); … … 993 1065 return false; 994 1066 } 995 996 if ( !prs_set_offset( ps, curr_off ))1067 1068 if (!prs_set_offset(ps, curr_off)) 997 1069 return false; 998 1070 … … 1003 1075 /******************************************************************* 1004 1076 *******************************************************************/ 1005 static bool next_nk_record( REGF_FILE *file, REGF_HBIN *hbin, REGF_NK_REC *nk, bool *eob ) 1006 { 1007 if ( next_record( hbin, "nk", eob ) && hbin_prs_key( file, hbin, nk ) ) 1077 static bool next_nk_record(REGF_FILE *file, REGF_HBIN *hbin, 1078 REGF_NK_REC *nk, bool *eob) 1079 { 1080 if (next_record(hbin, "nk", eob) 1081 && hbin_prs_key(file, hbin, nk)) 1008 1082 return true; 1009 1083 … … 1161 1235 1162 1236 /* see if there is anything left to report */ 1163 1164 if ( !nk || (nk->subkeys_off==REGF_OFFSET_NONE) || (nk->subkey_index >= nk->num_subkeys))1237 if (!nk || (nk->subkeys_off==REGF_OFFSET_NONE) 1238 || (nk->subkey_index >= nk->num_subkeys)) 1165 1239 return NULL; 1166 1240 1167 1241 /* find the HBIN block which should contain the nk record */ 1168 1169 1242 if(!(hbin 1170 1243 = lookup_hbin_block(file, nk->subkeys.hashes[nk->subkey_index].nk_off ))) … … 1176 1249 1177 1250 nk_offset = nk->subkeys.hashes[nk->subkey_index].nk_off; 1178 if ( !prs_set_offset( &hbin->ps, (HBIN_HDR_SIZE + nk_offset - hbin->first_hbin_off) ) ) 1251 if(!prs_set_offset(&hbin->ps, 1252 (HBIN_HDR_SIZE + nk_offset - hbin->first_hbin_off))) 1179 1253 return NULL; 1180 1254 1181 1255 nk->subkey_index++; 1182 if 1183 return NULL; 1184 1185 if ( !hbin_prs_key( file, hbin, subkey ))1186 return NULL; 1187 1256 if(!(subkey = (REGF_NK_REC*)zalloc(sizeof(REGF_NK_REC)))) 1257 return NULL; 1258 1259 if(!hbin_prs_key(file, hbin, subkey)) 1260 return NULL; 1261 1188 1262 return subkey; 1189 1263 } -
trunk/test/lib-regfio.c
r31 r32 74 74 } 75 75 76 /* Cut trailing slash */ 77 if(buf[buf_len-buf_left-2] == '/') 78 buf[buf_len-buf_left-2] = '\0'; 79 76 80 return buf; 77 81 } 78 82 79 83 80 void printKeyTree(REGF_FILE* f, void_stack* nk_stack) 84 void printKeyList(REGF_NK_REC* nk, char* prefix) 85 { 86 unsigned int i; 87 const char* str_type; 88 89 for(i=0; i < nk->num_values; i++) 90 { 91 str_type = type_val2str(nk->values[i].type); 92 printf("%s/%s:%s=\n", prefix, nk->values[i].valuename, str_type); 93 } 94 } 95 96 97 void printKeyTree(REGF_FILE* f, void_stack* nk_stack) 81 98 { 82 99 REGF_NK_REC* cur; … … 84 101 char* path; 85 102 86 while((cur = (REGF_NK_REC*)void_stack_cur(nk_stack)) != NULL)103 if((cur = (REGF_NK_REC*)void_stack_cur(nk_stack)) != NULL) 87 104 { 88 if((sub = regfio_fetch_subkey(f, cur)) != NULL) 105 printf("%s:KEY\n", cur->keyname); 106 while((cur = (REGF_NK_REC*)void_stack_cur(nk_stack)) != NULL) 89 107 { 90 path = getStackPath(nk_stack); 91 if(path != NULL) 108 if((sub = regfio_fetch_subkey(f, cur)) != NULL) 92 109 { 93 printf("%s%s:KEY\n", path, sub->keyname); 94 free(path); 110 void_stack_push(nk_stack, sub); 111 path = getStackPath(nk_stack); 112 if(path != NULL) 113 { 114 printKeyList(cur, path); 115 printf("%s:KEY\n", path); 116 free(path); 117 } 95 118 } 96 void_stack_push(nk_stack, sub); 97 } 98 else 99 { 100 cur = void_stack_pop(nk_stack); 101 /* XXX: This is just a shallow free. Need to write deep free 102 * routines to replace the Samba code for this. 103 */ 104 if(cur != NULL) 105 free(cur); 119 else 120 { 121 cur = void_stack_pop(nk_stack); 122 /* XXX: This is just a shallow free. Need to write deep free 123 * routines to replace the Samba code for this. 124 */ 125 if(cur != NULL) 126 free(cur); 127 } 106 128 } 107 129 }
Note: See TracChangeset
for help on using the changeset viewer.