- Timestamp:
- 12/06/09 20:00:58 (15 years ago)
- Location:
- trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/common.c
r159 r160 145 145 146 146 /* 147 * Convert from UTF-16LE to ASCII. Accepts a Unicode buffer, uni, and148 * it's length, uni_max. Writes ASCII to the buffer ascii, whose size149 * is ascii_max. Writes at most (ascii_max-1) bytes to ascii, and null150 * terminates the string. Returns the length of the data written to151 * ascii. On error, returns a negative errno code.152 */153 static int uni_to_ascii(unsigned char* uni, char* ascii,154 uint32 uni_max, uint32 ascii_max)155 {156 char* inbuf = (char*)uni;157 char* outbuf = ascii;158 size_t in_len = (size_t)uni_max;159 size_t out_len = (size_t)(ascii_max-1);160 int ret;161 162 conv_desc = iconv_open("US-ASCII//TRANSLIT", "UTF-16LE");163 164 ret = iconv(conv_desc, &inbuf, &in_len, &outbuf, &out_len);165 if(ret == -1)166 {167 iconv_close(conv_desc);168 return -errno;169 }170 *outbuf = '\0';171 172 iconv_close(conv_desc);173 return ascii_max-out_len-1;174 }175 176 177 static char* quote_unicode(unsigned char* uni, uint32 length,178 const char* special, char** error_msg)179 {180 char* ret_val;181 char* ascii = NULL;182 char* tmp_err;183 int ret_err;184 *error_msg = NULL;185 186 if(length+1 > 0)187 ascii = malloc(length+1);188 if(ascii == NULL)189 {190 *error_msg = (char*)malloc(27);191 if(*error_msg == NULL)192 return NULL;193 strcpy(*error_msg, "Memory allocation failure.");194 return NULL;195 }196 197 ret_err = uni_to_ascii(uni, ascii, length, length+1);198 if(ret_err < 0)199 {200 free(ascii);201 tmp_err = strerror(-ret_err);202 *error_msg = (char*)malloc(61+strlen(tmp_err));203 if(*error_msg == NULL)204 return NULL;205 206 sprintf(*error_msg,207 "Unicode conversion failed with '%s'. Quoting as binary.", tmp_err);208 ret_val = quote_buffer(uni, length, special);209 }210 else211 {212 ret_val = quote_string(ascii, special);213 free(ascii);214 }215 216 return ret_val;217 }218 219 220 /*221 147 * Convert a data value to a string for display. Returns NULL on error, 222 148 * and the string to display if there is no error, or a non-fatal -
trunk/src/reglookup-recover.c
r159 r160 66 66 } 67 67 68 68 /* XXX: Somewhere in here, need to start looking for and handling classnames */ 69 69 void printKey(REGFI_FILE* f, REGFI_NK_REC* nk, const char* prefix) 70 70 { -
trunk/src/reglookup.c
r159 r160 282 282 char* dacl = NULL; 283 283 char* quoted_classname; 284 char* error_msg = NULL;285 284 char mtime[20]; 286 285 time_t tmp_time[1]; … … 288 287 const REGFI_SK_REC* sk; 289 288 const REGFI_NK_REC* k = regfi_iterator_cur_key(iter); 289 REGFI_CLASSNAME* classname; 290 290 291 291 *tmp_time = nt_time_to_unix(&k->mtime); … … 308 308 dacl = empty_str; 309 309 310 if(k->classname != NULL) 311 { 312 quoted_classname = quote_unicode((uint8*)k->classname, k->classname_length, 313 key_special_chars, &error_msg); 310 classname = regfi_iterator_fetch_classname(iter, k); 311 printMsgs(iter->f); 312 if(classname != NULL) 313 { 314 if(classname->interpreted == NULL) 315 { 316 fprintf(stderr, "WARN: Could not convert class name" 317 " charset for key '%s'. Quoting raw...\n", full_path); 318 quoted_classname = quote_buffer(classname->raw, classname->size, 319 key_special_chars); 320 } 321 else 322 quoted_classname = quote_string(classname->interpreted, 323 key_special_chars); 324 314 325 if(quoted_classname == NULL) 315 326 { 316 if(error_msg == NULL) 317 fprintf(stderr, "ERROR: Could not quote classname" 318 " for key '%s' due to unknown error.\n", full_path); 319 else 320 { 321 fprintf(stderr, "ERROR: Could not quote classname" 322 " for key '%s' due to error: %s\n", full_path, error_msg); 323 free(error_msg); 324 } 325 } 326 else if (error_msg != NULL) 327 { 328 if(print_verbose) 329 fprintf(stderr, "INFO: While converting classname" 330 " for key '%s': %s.\n", full_path, error_msg); 331 free(error_msg); 327 fprintf(stderr, "ERROR: Could not quote classname" 328 " for key '%s' due to unknown error.\n", full_path); 329 quoted_classname = empty_str; 332 330 } 333 331 } 334 332 else 335 333 quoted_classname = empty_str; 334 regfi_free_classname(classname); 336 335 337 336 printMsgs(iter->f);
Note: See TracChangeset
for help on using the changeset viewer.