Changeset 43
- Timestamp:
- 08/05/05 20:47:37 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/reglookup.c
r42 r43 267 267 268 268 /* Security descriptor print functions */ 269 269 /* XXX: these functions should be moved out into regfio library */ 270 270 const char* ace_type2str(uint8 type) 271 271 { … … 330 330 { 331 331 char* ret_val = malloc(9*sizeof(char)); 332 sprintf(ret_val, "% 8X", perms);332 sprintf(ret_val, "%.8X", perms); 333 333 334 334 return ret_val; … … 369 369 char field_delim = ':'; 370 370 371 printf("acl: %.8X\n", (uint32)acl); 372 371 373 for (i = 0; i < acl->num_aces; i++) 372 374 { … … 379 381 /* XXX: this is slow */ 380 382 extra = strlen(sid_str) + strlen(type_str) 381 + strlen(perms_str) + strlen(flags_str) ;382 ret_val = realloc(ret_val, size+extra +5);383 + strlen(perms_str) + strlen(flags_str)+5; 384 ret_val = realloc(ret_val, size+extra); 383 385 if(ret_val == NULL) 384 386 return NULL; 385 snprintf(ret_val+size, extra+4, "%s%s%c%s%c%s%c%s", 386 ace_delim,sid_str, 387 field_delim,type_str, 388 field_delim,perms_str, 389 field_delim,flags_str); 390 size += extra; 387 size += snprintf(ret_val+size, extra, "%s%s%c%s%c%s%c%s", 388 ace_delim,sid_str, 389 field_delim,type_str, 390 field_delim,perms_str, 391 field_delim,flags_str); 391 392 ace_delim = "|"; 392 393 free(sid_str); … … 404 405 return get_acl(sec_desc->sacl); 405 406 else 406 return "";407 return NULL; 407 408 } 408 409 … … 413 414 return get_acl(sec_desc->dacl); 414 415 else 415 return "";416 return NULL; 416 417 } 417 418 … … 483 484 if (buf == NULL) 484 485 return NULL; 485 buf[0] = '\0'; 486 buf[0] = '/'; 487 buf[1] = '\0'; 486 488 487 489 iter = void_stack_iterator_new(nk_stack); … … 530 532 char* quoted_name; 531 533 532 if(!type_filter_enabled || (vk->type == type_filter)) 533 { 534 /* Thanks Microsoft for making this process so straight-forward!!! */ 535 size = (vk->data_size & ~VK_DATA_IN_OFFSET); 536 if(vk->data_size & VK_DATA_IN_OFFSET) 537 { 538 tmp_buf[0] = (uint8)((vk->data_off >> 3) & 0xFF); 539 tmp_buf[1] = (uint8)((vk->data_off >> 2) & 0xFF); 540 tmp_buf[2] = (uint8)((vk->data_off >> 1) & 0xFF); 541 tmp_buf[3] = (uint8)(vk->data_off & 0xFF); 542 if(size > 4) 543 size = 4; 544 quoted_value = data_to_ascii(tmp_buf, 4, vk->type); 545 } 546 else 547 { 548 /* XXX: This is a safety hack. No data fields have yet been found 549 * larger, but length limits are probably better got from fields 550 * in the registry itself, within reason. 551 */ 552 if(size > 16384) 553 { 554 fprintf(stderr, "WARNING: key size %d larger than " 555 "16384, truncating...\n", size); 556 size = 16384; 557 } 558 quoted_value = data_to_ascii(vk->data, vk->data_size, vk->type); 559 } 560 561 /* XXX: Sometimes value names can be NULL in registry. Need to 562 * figure out why and when, and generate the appropriate output 563 * for that condition. 534 /* Thanks Microsoft for making this process so straight-forward!!! */ 535 size = (vk->data_size & ~VK_DATA_IN_OFFSET); 536 if(vk->data_size & VK_DATA_IN_OFFSET) 537 { 538 tmp_buf[0] = (uint8)((vk->data_off >> 3) & 0xFF); 539 tmp_buf[1] = (uint8)((vk->data_off >> 2) & 0xFF); 540 tmp_buf[2] = (uint8)((vk->data_off >> 1) & 0xFF); 541 tmp_buf[3] = (uint8)(vk->data_off & 0xFF); 542 if(size > 4) 543 size = 4; 544 quoted_value = data_to_ascii(tmp_buf, 4, vk->type); 545 } 546 else 547 { 548 /* XXX: This is a safety hack. No data fields have yet been found 549 * larger, but length limits are probably better got from fields 550 * in the registry itself, within reason. 564 551 */ 565 quoted_prefix = quote_string(prefix, special_chars); 566 quoted_name = quote_string(vk->valuename, special_chars); 567 552 if(size > 16384) 553 { 554 fprintf(stderr, "WARNING: key size %d larger than " 555 "16384, truncating...\n", size); 556 size = 16384; 557 } 558 quoted_value = data_to_ascii(vk->data, vk->data_size, vk->type); 559 } 560 561 /* XXX: Sometimes value names can be NULL in registry. Need to 562 * figure out why and when, and generate the appropriate output 563 * for that condition. 564 */ 565 quoted_prefix = quote_string(prefix, special_chars); 566 quoted_name = quote_string(vk->valuename, special_chars); 567 568 if(print_security) 568 569 printf("%s/%s,%s,%s,,,,,\n", quoted_prefix, quoted_name, 569 570 regfio_type_val2str(vk->type), quoted_value); 570 571 if(quoted_value != NULL) 572 free(quoted_value); 573 if(quoted_prefix != NULL) 574 free(quoted_prefix); 575 if(quoted_name != NULL) 576 free(quoted_name); 577 } 571 else 572 printf("%s/%s,%s,%s,\n", quoted_prefix, quoted_name, 573 regfio_type_val2str(vk->type), quoted_value); 574 575 if(quoted_value != NULL) 576 free(quoted_value); 577 if(quoted_prefix != NULL) 578 free(quoted_prefix); 579 if(quoted_name != NULL) 580 free(quoted_name); 578 581 } 579 582 … … 584 587 585 588 for(i=0; i < nk->num_values; i++) 586 printValue(&nk->values[i], prefix); 587 } 588 589 590 /* XXX: this function is god-awful. Needs to be re-designed. */ 591 void printKeyTree(REGF_FILE* f, void_stack* nk_stack, char* prefix) 592 { 593 REGF_NK_REC* cur; 594 REGF_NK_REC* sub; 595 char* path = NULL; 596 char* val_path = NULL; 589 if(!type_filter_enabled || (nk->values[i].type == type_filter)) 590 printValue(&nk->values[i], prefix); 591 } 592 593 594 void printKey(REGF_NK_REC* k, char* full_path) 595 { 596 static char empty_str[1] = ""; 597 597 char* owner = NULL; 598 598 char* group = NULL; … … 603 603 struct tm* tmp_time_s = NULL; 604 604 605 *tmp_time = nt_time_to_unix(&k->mtime); 606 tmp_time_s = gmtime(tmp_time); 607 strftime(mtime, sizeof(mtime), "%Y-%m-%d %H:%M:%S", tmp_time_s); 608 609 if(print_security) 610 { 611 owner = get_owner(k->sec_desc->sec_desc); 612 group = get_group(k->sec_desc->sec_desc); 613 sacl = get_sacl(k->sec_desc->sec_desc); 614 dacl = get_dacl(k->sec_desc->sec_desc); 615 if(owner == NULL) 616 owner = empty_str; 617 if(group == NULL) 618 group = empty_str; 619 if(sacl == NULL) 620 sacl = empty_str; 621 if(dacl == NULL) 622 dacl = empty_str; 623 624 printf("%s,KEY,,%s,%s,%s,%s,%s\n", full_path, mtime, 625 owner, group, sacl, dacl); 626 627 if(owner != empty_str) 628 free(owner); 629 if(group != empty_str) 630 free(group); 631 if(sacl != empty_str) 632 free(sacl); 633 if(dacl != empty_str) 634 free(dacl); 635 } 636 else 637 printf("%s,KEY,,%s\n", full_path, mtime); 638 } 639 640 641 /* XXX: this function is god-awful. Needs to be re-designed. */ 642 void printKeyTree(REGF_FILE* f, void_stack* nk_stack, char* prefix) 643 { 644 REGF_NK_REC* cur; 645 REGF_NK_REC* sub; 646 char* path = NULL; 647 char* val_path = NULL; 648 605 649 int key_type = regfio_type_str2val("KEY"); 606 650 607 651 if((cur = (REGF_NK_REC*)void_stack_cur(nk_stack)) != NULL) 608 652 { … … 610 654 path = stack2Path(nk_stack); 611 655 612 if(strlen(path) > 0) 613 if(!type_filter_enabled || (key_type == type_filter)) 614 { 615 owner = get_owner(cur->sec_desc->sec_desc); 616 group = get_group(cur->sec_desc->sec_desc); 617 sacl = get_sacl(cur->sec_desc->sec_desc); 618 dacl = get_dacl(cur->sec_desc->sec_desc); 619 *tmp_time = nt_time_to_unix(&cur->mtime); 620 tmp_time_s = gmtime(tmp_time); 621 strftime(mtime, sizeof(mtime), "%Y-%m-%d %H:%M:%S", tmp_time_s); 622 printf("%s%s,KEY,,%s,%s,%s,%s,%s\n", prefix, path, mtime, 623 owner, group, sacl, dacl); 624 if(owner != NULL) 625 free(owner); 626 owner = NULL; 627 if(group != NULL) 628 free(group); 629 group = NULL; 630 if(sacl != NULL) 631 free(sacl); 632 sacl = NULL; 633 if(dacl != NULL) 634 free(dacl); 635 dacl = NULL; 636 } 656 657 val_path = (char*)malloc(strlen(prefix)+strlen(path)+1); 658 sprintf(val_path, "%s%s", prefix, path); 659 if(!type_filter_enabled || (key_type == type_filter)) 660 printKey(cur, val_path); 661 637 662 if(!type_filter_enabled || (key_type != type_filter)) 638 printValueList(cur, path); 663 printValueList(cur, val_path); 664 if(val_path != NULL) 665 free(val_path); 639 666 while((cur = (REGF_NK_REC*)void_stack_cur(nk_stack)) != NULL) 640 667 { … … 649 676 sprintf(val_path, "%s%s", prefix, path); 650 677 if(!type_filter_enabled || (key_type == type_filter)) 651 { 652 owner = get_owner(sub->sec_desc->sec_desc); 653 group = get_group(sub->sec_desc->sec_desc); 654 sacl = get_sacl(sub->sec_desc->sec_desc); 655 dacl = get_dacl(sub->sec_desc->sec_desc); 656 *tmp_time = nt_time_to_unix(&cur->mtime); 657 tmp_time_s = gmtime(tmp_time); 658 strftime(mtime, sizeof(mtime), "%Y-%m-%d %H:%M:%S", tmp_time_s); 659 printf("%s,KEY,,%s,%s,%s,%s,%s\n", val_path, mtime, 660 owner, group, sacl, dacl); 661 } 678 printKey(sub, val_path); 662 679 if(!type_filter_enabled || (key_type != type_filter)) 663 680 printValueList(sub, val_path); 664 681 if(val_path != NULL) 665 682 free(val_path); 666 val_path = NULL;667 if(path != NULL)668 free(path);669 path = NULL;670 if(owner != NULL)671 free(owner);672 owner = NULL;673 if(group != NULL)674 free(group);675 group = NULL;676 /* XXX: causes segfaults. fix mem allocation bug */677 /* if(sacl != NULL)678 free(sacl);*/679 sacl = NULL;680 if(dacl != NULL)681 free(dacl);682 dacl = NULL;683 tmp_time_s = NULL;684 683 } 685 684 } … … 754 753 if(strcasecmp(sub->values[i].valuename, cur_str) == 0) 755 754 { 755 /* XXX: fix mem leak with stack2Path return value */ 756 756 printValue(&sub->values[i], stack2Path(nk_stack)); 757 757 return 0; … … 867 867 { 868 868 if(print_header) 869 printf("PATH,TYPE,VALUE,MTIME,OWNER,GROUP,SACL,DACL\n"); 869 { 870 if(print_security) 871 printf("PATH,TYPE,VALUE,MTIME,OWNER,GROUP,SACL,DACL\n"); 872 else 873 printf("PATH,TYPE,VALUE,MTIME\n"); 874 } 870 875 871 876 path_stack = path2Stack(path_filter);
Note: See TracChangeset
for help on using the changeset viewer.