Changeset 185
- Timestamp:
- 03/22/10 22:22:07 (15 years ago)
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
test/regfi-threadtest.c
r183 r185 49 49 void traverseValueList(REGFI_ITERATOR* iter) 50 50 { 51 REGFI_VK_REC* value;51 const REGFI_VK_REC* value; 52 52 53 53 value = regfi_iterator_first_value(iter); … … 55 55 { 56 56 printMsgs(iter->f); 57 regfi_free_ value(value);57 regfi_free_record(value); 58 58 value = regfi_iterator_next_value(iter); 59 59 } … … 65 65 const REGFI_NK_REC* root = NULL; 66 66 const REGFI_NK_REC* cur = NULL; 67 REGFI_NK_REC* sub = NULL;67 const REGFI_NK_REC* sub = NULL; 68 68 const REGFI_SK_REC* sk; 69 69 bool print_this = true; … … 116 116 cur = regfi_iterator_cur_key(iter); 117 117 printMsgs(iter->f); 118 regfi_free_ key(sub);118 regfi_free_record(sub); 119 119 120 120 sub = regfi_iterator_first_subkey(iter); … … 131 131 132 132 int num_iterations; 133 void threadLoop(void* file)133 void* threadLoop(void* file) 134 134 { 135 135 REGFI_ITERATOR* iter; 136 136 int i; 137 137 138 regfi_log_set_mask(REGFI_LOG_INFO|REGFI_LOG_WARN|REGFI_LOG_ERROR); 139 138 140 iter = regfi_iterator_new((REGFI_FILE*)f, REGFI_ENCODING_ASCII); 139 141 if(iter == NULL) … … 150 152 151 153 regfi_iterator_free(iter); 154 155 return NULL; 152 156 } 153 157 … … 185 189 registry_file = argv[argi]; 186 190 187 regfi_log_s tart(REGFI_LOG_INFO|REGFI_LOG_WARN|REGFI_LOG_ERROR);191 regfi_log_set_mask(REGFI_LOG_INFO|REGFI_LOG_WARN|REGFI_LOG_ERROR); 188 192 189 193 fd = openHive(registry_file); … … 211 215 212 216 regfi_free(f); 213 regfi_log_stop();214 217 close(fd); 215 218 -
trunk/include/regfi.h
r184 r185 48 48 * 49 49 * Most users will find that a combination of the Base Layer and the Iterator Layer 50 * will be sufficient for accessing registry hive files. Those who are wil ing50 * will be sufficient for accessing registry hive files. Those who are willing 51 51 * to dive deep into registry data structures, for instance to recover deleted 52 52 * data structures or to research Windows registry behavior in detail, will … … 79 79 80 80 81 82 81 83 /******************************************************************************/ 82 84 /* Constants for use while interacting with the library */ … … 87 89 #define REGFI_LOG_WARN 0x0004 88 90 #define REGFI_LOG_ERROR 0x0010 91 #define REGFI_DEFAULT_LOG_MASK REGFI_LOG_ERROR|REGFI_LOG_WARN 89 92 90 93 typedef uint8_t REGFI_ENCODING; … … 146 149 147 150 /* Global thread-local storage key */ 148 pthread_key_t REGFI_LOG_KEY;151 pthread_key_t regfi_log_key; 149 152 150 153 /* Header sizes and magic number lengths for various records */ … … 877 880 878 881 879 /** Enables regfi library logging for the current thread.880 *881 * XXX: finish documenting882 *883 * @ingroup regfiBase884 */885 void regfi_log_start(uint16_t mask);886 887 888 882 /** Get errors, warnings, and/or verbose information relating to processing of 889 883 * the given registry file. … … 896 890 897 891 898 /** Set the verbosity level of errors and warnings generated by the library 899 * (as accessible via regfi_get_messages). 900 * 901 * This may be called at any time and will take effect immediately. 902 * 903 * @param mask an integer representing the types of messages desired. 892 /** Set the verbosity level of messages generated by the library for the 893 * current thread. 894 * 895 * @param mask An integer representing the types of messages desired. 904 896 * Acceptable values are created through bitwise ORs of 905 * REGFI_ MSG_* values. For instance, if only errors and897 * REGFI_LOG_* values. For instance, if only errors and 906 898 * informational messages were desired (but not warnings), 907 * then one would specify: REGFI_MSG_ERROR|REGFI_MSG_INFO 908 * New REGFI_FILE structures are created with: 909 * REGFI_MSG_ERROR|REGFI_MSG_WARN 910 * Note that error and warning messages will continue to 911 * accumulate in memory if they are not fetched using 912 * regfi_get_messages and then freed by the caller. 913 * To disable error messages entirely, supply 0, which 914 * will prevent message accumulation. 899 * then one would specify: REGFI_LOG_ERROR|REGFI_LOG_INFO 900 * By default the message mask is: REGFI_LOG_ERROR|REGFI_LOG_WARN. 901 * 902 * @return true on success and false on failure. Failure occurs if 903 * underlying pthread functions fail. errno is set in this case. 904 * 905 * Message masks are set in a thread-specific way. If one were to set a message 906 * mask in one thread and then spawn a new thread, then the new thread will have 907 * it's message mask reset to the default. This function may be called at any 908 * time and will take effect immediately for the current thread. 909 * 910 * @note When a non-zero message mask is set, messages will 911 * accumulate in memory without limit if they are not fetched using 912 * @ref regfi_get_log_str and subsequently freed by the caller. It is 913 * recommended that messsages be fetched after each regfi API call in 914 * order to provide the most context. 915 915 * 916 916 * @ingroup regfiBase 917 917 */ 918 void regfi_log_set_mask(uint16_t mask); 919 920 921 /** Disables regfi library logging for the current thread. 922 * 923 * XXX: finish documenting 924 * 925 * @ingroup regfiBase 926 */ 927 void regfi_log_stop(); 918 bool regfi_log_set_mask(uint16_t mask); 928 919 929 920 … … 1077 1068 * subkey, or NULL on failure. Failure may be due to a lack of any 1078 1069 * subkeys or other errors. Newly allocated keys must be freed with 1079 * regfi_free_record.1070 * @ref regfi_free_record. 1080 1071 * 1081 1072 * @ingroup regfiIteratorLayer … … 1090 1081 * @return A newly allocated key structure for the currently referenced subkey, 1091 1082 * or NULL on failure. Newly allocated keys must be freed with 1092 * regfi_free_record.1083 * @ref regfi_free_record. 1093 1084 * 1094 1085 * @ingroup regfiIteratorLayer … … 1103 1094 * 1104 1095 * @return A newly allocated key structure for the next subkey or NULL on 1105 * failure. Newly allocated keys must be freed with regfi_free_record. 1096 * failure. Newly allocated keys must be freed with 1097 * @ref regfi_free_record. 1106 1098 * 1107 1099 * @ingroup regfiIteratorLayer … … 1132 1124 * value, or NULL on failure. Failure may be due to a lack of any 1133 1125 * values or other errors. Newly allocated keys must be freed with 1134 * regfi_free_record.1126 * @ref regfi_free_record. 1135 1127 * 1136 1128 * @ingroup regfiIteratorLayer … … 1145 1137 * @return A newly allocated value structure for the currently referenced value, 1146 1138 * or NULL on failure. Newly allocated values must be freed with 1147 * regfi_free_record.1139 * @ref regfi_free_record. 1148 1140 * 1149 1141 * @ingroup regfiIteratorLayer … … 1158 1150 * 1159 1151 * @return A newly allocated key structure for the next value or NULL on 1160 * failure. Newly allocated keys must be freed with regfi_free_record. 1152 * failure. Newly allocated keys must be freed with 1153 * @ref regfi_free_record. 1161 1154 * 1162 1155 * @ingroup regfiIteratorLayer … … 1185 1178 * 1186 1179 * @return Returns a newly allocated classname structure, or NULL on failure. 1187 * Classname structures must be freed with regfi_free_record.1180 * Classname structures must be freed with @ref regfi_free_record. 1188 1181 * 1189 1182 * @ingroup regfiIteratorLayer … … 1199 1192 * 1200 1193 * @return Returns a newly allocated data structure, or NULL on failure. 1201 * Data structures must be freed with regfi_free_record.1194 * Data structures must be freed with @ref regfi_free_record. 1202 1195 * 1203 1196 * @ingroup regfiIteratorLayer -
trunk/lib/regfi.c
r184 r185 45 45 46 46 47 /* Ensures regfi_init runs only once */ 48 static pthread_once_t regfi_init_once = PTHREAD_ONCE_INIT; 49 50 47 51 48 52 /****************************************************************************** 49 53 ******************************************************************************/ 50 void regfi_log_start(uint16_t msg_mask) 51 { 54 void regfi_log_free(void* ptr) 55 { 56 REGFI_LOG* log_info = (REGFI_LOG*)ptr; 57 58 if(log_info->messages != NULL) 59 free(log_info->messages); 60 61 talloc_free(log_info); 62 } 63 64 65 /****************************************************************************** 66 ******************************************************************************/ 67 void regfi_init() 68 { 69 int err; 70 if((err = pthread_key_create(®fi_log_key, regfi_log_free)) != 0) 71 fprintf(stderr, "ERROR: key_create: %s\n", strerror(err)); 72 errno = err; 73 } 74 75 76 /****************************************************************************** 77 ******************************************************************************/ 78 REGFI_LOG* regfi_log_new() 79 { 80 int err; 52 81 REGFI_LOG* log_info = talloc(NULL, REGFI_LOG); 53 82 if(log_info == NULL) 54 return ;55 56 log_info->msg_mask = msg_mask;83 return NULL; 84 85 log_info->msg_mask = REGFI_DEFAULT_LOG_MASK; 57 86 log_info->messages = NULL; 58 87 59 /* XXX: Should we bother with a destructor here? */ 60 if(pthread_key_create(®FI_LOG_KEY, NULL) != 0) 61 { 62 fprintf(stderr, "ERROR: key_create\n"); 63 goto fail; 64 } 65 66 if(pthread_setspecific(REGFI_LOG_KEY, log_info) != 0) 67 { 68 fprintf(stderr, "ERROR: setspecific\n"); 69 goto fail; 70 } 71 72 return; 88 pthread_once(®fi_init_once, regfi_init); 89 90 if((err = pthread_setspecific(regfi_log_key, log_info)) != 0) 91 { 92 fprintf(stderr, "ERROR: setspecific: %s\n", strerror(err)); 93 goto fail; 94 } 95 96 return log_info; 73 97 74 98 fail: 75 99 talloc_free(log_info); 100 errno = err; 101 return NULL; 76 102 } 77 103 … … 93 119 va_list args; 94 120 95 log_info = (REGFI_LOG*)pthread_getspecific(REGFI_LOG_KEY); 96 if(log_info == NULL || (log_info->msg_mask & msg_type) == 0) 121 log_info = (REGFI_LOG*)pthread_getspecific(regfi_log_key); 122 if(log_info == NULL && (log_info = regfi_log_new()) == NULL) 123 return; 124 125 if((log_info->msg_mask & msg_type) == 0) 97 126 return; 98 127 … … 138 167 { 139 168 char* ret_val; 140 REGFI_LOG* log_info = (REGFI_LOG*)pthread_getspecific( REGFI_LOG_KEY);141 if(log_info == NULL )142 return NULL; 143 169 REGFI_LOG* log_info = (REGFI_LOG*)pthread_getspecific(regfi_log_key); 170 if(log_info == NULL && (log_info = regfi_log_new()) == NULL) 171 return NULL; 172 144 173 ret_val = log_info->messages; 145 174 log_info->messages = NULL; … … 151 180 /****************************************************************************** 152 181 ******************************************************************************/ 153 void regfi_log_set_mask(uint16_t msg_mask) 154 { 155 REGFI_LOG* log_info = (REGFI_LOG*)pthread_getspecific(REGFI_LOG_KEY); 156 if(log_info == NULL) 157 return; 182 bool regfi_log_set_mask(uint16_t msg_mask) 183 { 184 REGFI_LOG* log_info = (REGFI_LOG*)pthread_getspecific(regfi_log_key); 185 if(log_info == NULL && (log_info = regfi_log_new()) == NULL) 186 { 187 return false; 188 } 158 189 159 190 log_info->msg_mask = msg_mask; 160 } 161 162 163 /****************************************************************************** 164 ******************************************************************************/ 165 void regfi_log_stop() 166 { 167 REGFI_LOG* log_info = (REGFI_LOG*)pthread_getspecific(REGFI_LOG_KEY); 168 if(log_info == NULL) 169 return; 170 171 if(log_info->messages != NULL) 172 free(log_info->messages); 173 174 pthread_key_delete(REGFI_LOG_KEY); 175 talloc_free(log_info); 191 return true; 176 192 } 177 193 -
trunk/src/common.c
r184 r185 49 49 { 50 50 fprintf(stderr, message); 51 regfi_log_stop();52 51 exit(code); 53 52 } -
trunk/src/reglookup-recover.c
r184 r185 828 828 829 829 if(print_verbose) 830 regfi_log_s tart(REGFI_LOG_ERROR|REGFI_LOG_WARN|REGFI_LOG_INFO);830 regfi_log_set_mask(REGFI_LOG_ERROR|REGFI_LOG_WARN|REGFI_LOG_INFO); 831 831 else 832 regfi_log_s tart(REGFI_LOG_ERROR);832 regfi_log_set_mask(REGFI_LOG_ERROR); 833 833 834 834 f = regfi_alloc(fd); … … 994 994 995 995 regfi_free(f); 996 regfi_log_stop();997 996 close(fd); 998 997 -
trunk/src/reglookup.c
r184 r185 624 624 625 625 if(print_verbose) 626 regfi_log_start(REGFI_LOG_INFO|REGFI_LOG_WARN|REGFI_LOG_ERROR); 627 else 628 regfi_log_start(REGFI_LOG_ERROR|REGFI_LOG_WARN); 626 regfi_log_set_mask(REGFI_LOG_INFO|REGFI_LOG_WARN|REGFI_LOG_ERROR); 629 627 630 628 fd = openHive(registry_file); … … 685 683 regfi_iterator_free(iter); 686 684 regfi_free(f); 687 regfi_log_stop();688 685 close(fd); 689 686
Note: See TracChangeset
for help on using the changeset viewer.