Changeset 66
- Timestamp:
- 07/23/06 18:46:15 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/reglookup.c
r61 r66 43 43 44 44 /* Other globals */ 45 const char* special_chars = ",\"\\"; 45 const char* key_special_chars = ",\"\\/"; 46 const char* subfield_special_chars = ",\"\\|"; 47 const char* common_special_chars = ",\"\\"; 48 46 49 iconv_t conv_desc; 47 50 … … 150 153 { 151 154 iconv_close(conv_desc); 152 return -1; 153 } 155 return -errno; 156 } 157 *outbuf = '\0'; 154 158 155 159 iconv_close(conv_desc); … … 173 177 unsigned int ascii_max, cur_str_max; 174 178 unsigned int str_rem, cur_str_rem, alen; 179 int ret_err; 175 180 176 181 switch (type) 177 182 { 183 case REG_SZ: 184 case REG_EXPAND_SZ: 178 185 /* REG_LINK is a symbolic link, stored as a unicode string. */ 179 186 case REG_LINK: 180 case REG_SZ:181 187 ascii_max = sizeof(char)*len; 182 188 ascii = malloc(ascii_max+4); … … 184 190 return NULL; 185 191 186 if(uni_to_ascii(datap, ascii, len, ascii_max) < 0) 187 { 188 free(ascii); 189 return NULL; 190 } 191 cur_quoted = quote_string(ascii, special_chars); 192 free(ascii); 193 return cur_quoted; 194 break; 195 196 /* XXX: This could be Unicode or ASCII. Are we processing it 197 * correctly in both cases? 192 /* Sometimes values have binary stored in them. If the unicode 193 * conversion fails, just quote it raw. 198 194 */ 199 case REG_EXPAND_SZ: 200 ascii_max = sizeof(char)*len; 201 ascii = malloc(ascii_max+2); 202 if(ascii == NULL) 203 return NULL; 204 205 if(uni_to_ascii(datap, ascii, len, ascii_max) < 0) 206 { 207 free(ascii); 208 return NULL; 209 } 210 cur_quoted = quote_string(ascii, special_chars); 195 196 ret_err = uni_to_ascii(datap, ascii, len, ascii_max); 197 if(ret_err < 0) 198 { 199 /* XXX: It would be nice if somehow we could include the name of this 200 * value in the error message. 201 */ 202 if(print_verbose) 203 fprintf(stderr, "VERBOSE: Unicode conversion failed; " 204 "printing as binary. Error: %s\n", strerror(-ret_err)); 205 206 cur_quoted = quote_buffer(datap, len, common_special_chars); 207 } 208 else 209 cur_quoted = quote_string(ascii, common_special_chars); 211 210 free(ascii); 212 211 return cur_quoted; … … 269 268 if(num_nulls == 2) 270 269 { 271 if(uni_to_ascii(cur_str, cur_ascii, cur_str_max, cur_str_max) < 0) 270 ret_err = uni_to_ascii(cur_str, cur_ascii, cur_str_len-1, cur_str_max); 271 if(ret_err < 0) 272 272 { 273 free(ascii); 274 free(cur_ascii); 275 free(cur_str); 276 return NULL; 273 /* XXX: It would be nice if somehow we could include the name of this 274 * value in the error message. 275 */ 276 if(print_verbose) 277 fprintf(stderr, "VERBOSE: Unicode conversion failed on sub-field; " 278 "printing as binary. Error: %s\n", strerror(-ret_err)); 279 280 cur_quoted = quote_buffer(cur_str, cur_str_len-1, 281 subfield_special_chars); 277 282 } 278 279 cur_quoted = quote_string(cur_ascii, ",|\"\\"); 283 else 284 cur_quoted = quote_string(cur_ascii, subfield_special_chars); 285 280 286 alen = snprintf(asciip, str_rem, "%s", cur_quoted); 281 287 asciip += alen; … … 315 321 316 322 case REG_BINARY: 317 return quote_buffer(datap, len, special_chars);323 return quote_buffer(datap, len, common_special_chars); 318 324 break; 319 325 … … 366 372 } 367 373 368 374 /* Returns a quoted path from an nk_stack */ 369 375 char* stack2Path(void_stack* nk_stack) 370 376 { … … 376 382 char* buf; 377 383 char* new_buf; 384 char* name; 378 385 void_stack_iterator* iter; 379 386 … … 397 404 buf[buf_len-buf_left-1] = '/'; 398 405 buf_left -= 1; 399 name_len = strlen(cur->keyname); 406 name = quote_string(cur->keyname, key_special_chars); 407 name_len = strlen(name); 400 408 if(name_len+1 > buf_left) 401 409 { … … 411 419 buf_left = grow_amt + name_len + 1; 412 420 } 413 strncpy(buf+(buf_len-buf_left-1), cur->keyname, name_len);421 strncpy(buf+(buf_len-buf_left-1), name, name_len); 414 422 buf_left -= name_len; 415 423 buf[buf_len-buf_left-1] = '\0'; 424 free(name); 416 425 } 417 426 … … 424 433 uint32 size; 425 434 uint8 tmp_buf[4]; 426 char* quoted_value; 427 char* quoted_prefix; 428 char* quoted_name; 435 char* quoted_value = NULL; 436 char* quoted_name = NULL; 429 437 430 438 /* Thanks Microsoft for making this process so straight-forward!!! */ … … 460 468 * for that condition. 461 469 */ 462 quoted_prefix = quote_string(prefix, special_chars); 463 quoted_name = quote_string(vk->valuename, special_chars); 464 470 quoted_name = quote_string(vk->valuename, common_special_chars); 465 471 if(print_security) 466 printf("%s/%s,%s,%s,,,,,\n", quoted_prefix, quoted_name,472 printf("%s/%s,%s,%s,,,,,\n", prefix, quoted_name, 467 473 regfio_type_val2str(vk->type), quoted_value); 468 474 else 469 printf("%s/%s,%s,%s,\n", quoted_prefix, quoted_name,475 printf("%s/%s,%s,%s,\n", prefix, quoted_name, 470 476 regfio_type_val2str(vk->type), quoted_value); 471 477 472 478 if(quoted_value != NULL) 473 479 free(quoted_value); 474 if(quoted_prefix != NULL)475 free(quoted_prefix);476 480 if(quoted_name != NULL) 477 481 free(quoted_name); … … 485 489 for(i=0; i < nk->num_values; i++) 486 490 if(!type_filter_enabled || (nk->values[i].type == type_filter)) 487 printValue( &nk->values[i], prefix);491 printValue(nk->values+i, prefix); 488 492 } 489 493 … … 499 503 time_t tmp_time[1]; 500 504 struct tm* tmp_time_s = NULL; 501 char* quoted_path = NULL; 502 503 /* XXX: it would be faster to always pass a quoted string to this 504 * function, instead of re-quoting it every call. */ 505 /* XXX: check return of quote_string */ 506 quoted_path = quote_string(full_path, special_chars); 505 507 506 *tmp_time = nt_time_to_unix(&k->mtime); 508 507 tmp_time_s = gmtime(tmp_time); … … 524 523 dacl = empty_str; 525 524 526 printf("%s,KEY,,%s,%s,%s,%s,%s\n", quoted_path, mtime,525 printf("%s,KEY,,%s,%s,%s,%s,%s\n", full_path, mtime, 527 526 owner, group, sacl, dacl); 528 527 … … 537 536 } 538 537 else 539 printf("%s,KEY,,%s\n", quoted_path, mtime); 540 541 free(quoted_path); 542 } 543 544 545 /* XXX: this function is awful. Needs to be re-designed. */ 546 void printKeyTree(REGF_FILE* f, void_stack* nk_stack, char* prefix) 538 printf("%s,KEY,,%s\n", full_path, mtime); 539 } 540 541 542 void printKeyTree(REGF_FILE* f, void_stack* nk_stack, const char* prefix) 547 543 { 548 544 REGF_NK_REC* cur = NULL; … … 550 546 char* path = NULL; 551 547 char* val_path = NULL; 548 uint32 val_path_len = 0; 549 uint32 path_len = 0; 550 uint32 prefix_len = strlen(prefix); 552 551 int key_type = regfio_type_str2val("KEY"); 553 552 … … 566 565 } 567 566 568 val_path = (char*)malloc(strlen(prefix)+strlen(path)+1); 569 sprintf(val_path, "%s%s", prefix, path); 567 path_len = strlen(path); 568 val_path_len = prefix_len+path_len; 569 val_path = (char*)malloc(val_path_len+1+1); 570 if(val_path == NULL) 571 bailOut(2, "ERROR: Could not allocate val_path.\n"); 572 573 strcpy(val_path, prefix); 574 strcpy(val_path+prefix_len, path); 570 575 if(val_path[0] == '\0') 571 576 { … … 573 578 val_path[1] = '\0'; 574 579 } 575 576 580 if(!type_filter_enabled || (key_type == type_filter)) 577 581 printKey(cur, val_path); 578 582 if(!type_filter_enabled || (key_type != type_filter)) 579 583 printValueList(cur, val_path); 580 if(val_path != NULL) 581 free(val_path); 584 582 585 while((cur = (REGF_NK_REC*)void_stack_cur(nk_stack)) != NULL) 583 586 { 584 if((sub = regfio_fetch_subkey(f, cur)) != NULL) 587 if((sub = regfio_fetch_subkey(f, cur)) == NULL) 588 { 589 sub = void_stack_pop(nk_stack); 590 /* XXX: This is just a shallow free. Need to write deep free 591 * routines to replace the Samba code for this. 592 */ 593 if(sub != NULL) 594 free(sub); 595 } 596 else 585 597 { 586 598 sub->subkey_index = 0; … … 589 601 if(path != NULL) 590 602 { 591 val_path = (char*)malloc(strlen(prefix)+strlen(path)+1); 592 sprintf(val_path, "%s%s", prefix, path); 603 path_len = strlen(path); 604 if(val_path_len < prefix_len+path_len) 605 { 606 val_path_len = prefix_len+path_len; 607 val_path = (char*)realloc(val_path, val_path_len+1); 608 if(val_path == NULL) 609 bailOut(2, "ERROR: Could not reallocate val_path.\n"); 610 } 611 strcpy(val_path, prefix); 612 strcpy(val_path+prefix_len, path); 593 613 if(!type_filter_enabled || (key_type == type_filter)) 594 614 printKey(sub, val_path); 595 615 if(!type_filter_enabled || (key_type != type_filter)) 596 616 printValueList(sub, val_path); 597 if(val_path != NULL)598 free(val_path);599 617 } 600 618 } 601 else 602 { 603 cur = void_stack_pop(nk_stack); 604 /* XXX: This is just a shallow free. Need to write deep free 605 * routines to replace the Samba code for this. 606 */ 607 if(cur != NULL) 608 free(cur); 609 } 610 } 611 } 619 } 620 } 621 if(val_path != NULL) 622 free(val_path); 612 623 if(print_verbose) 613 624 fprintf(stderr, "VERBOSE: Finished printing key tree.\n"); … … 627 638 void_stack* sub_nk_stack; 628 639 char* prefix; 629 uint32 prefix_len;630 640 char* cur_str = NULL; 631 641 char* path = NULL; 642 char* name; 643 uint16 path_depth; 644 uint32 i, prefix_len; 632 645 bool found_cur = true; 633 uint32 i;634 uint16 path_depth;635 646 if(path_stack == NULL) 636 647 return -1; … … 715 726 if(prefix == NULL) 716 727 return -1; 728 name = quote_string(sub->keyname, key_special_chars); 717 729 strcat(prefix, "/"); 718 strcat(prefix, sub->keyname); 730 strcat(prefix, name); 731 free(name); 719 732 720 733 if(print_verbose)
Note: See TracChangeset
for help on using the changeset viewer.