Changeset 138 for trunk/src


Ignore:
Timestamp:
02/08/09 14:53:48 (16 years ago)
Author:
tim
Message:

extended error message logging to allow for message type filtering

fine tuned message verbosity to more reasonable default levels for reglookup and reglookup-recover

updated related documentation

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/common.c

    r137 r138  
    3838}
    3939
    40 void printMsgs(REGFI_ITERATOR* iter)
    41 {
    42   char* msgs = regfi_get_messages(iter->f);
     40void printMsgs(REGFI_FILE* f)
     41{
     42  char* msgs = regfi_get_messages(f);
    4343  if(msgs != NULL)
    4444  {
     
    4646    free(msgs);
    4747  }
     48}
     49
     50void clearMsgs(REGFI_FILE* f)
     51{
     52  char* msgs = regfi_get_messages(f);
     53  if(msgs != NULL)
     54    free(msgs);
    4855}
    4956
  • trunk/src/reglookup-recover.c

    r136 r138  
    22 * This program attempts to recover deleted data structures in a registry hive.
    33 *
    4  * Copyright (C) 2008 Timothy D. Morgan
     4 * Copyright (C) 2008-2009 Timothy D. Morgan
    55 *
    66 * This program is free software; you can redistribute it and/or modify
     
    8787    quoted_name[0] = '\0';
    8888
    89     fprintf(stderr, "WARNING: NULL key name in NK record at offset %.8X.\n",
     89    fprintf(stderr, "WARN: NULL key name in NK record at offset %.8X.\n",
    9090            nk->offset);
    9191  }
     
    125125  if(size > REGFI_VK_MAX_DATA_LENGTH)
    126126  {
    127     fprintf(stderr, "WARNING: value data size %d larger than "
     127    fprintf(stderr, "WARN: value data size %d larger than "
    128128            "%d, truncating...\n", size, REGFI_VK_MAX_DATA_LENGTH);
    129129    size = REGFI_VK_MAX_DATA_LENGTH;
     
    153153
    154154    if(conv_error == NULL)
    155       fprintf(stderr, "WARNING: Could not quote value for '%s/%s'.  "
     155      fprintf(stderr, "WARN: Could not quote value for '%s/%s'.  "
    156156              "Memory allocation failure likely.\n", prefix, quoted_name);
    157157    else if(print_verbose)
    158       fprintf(stderr, "WARNING: Could not quote value for '%s/%s'.  "
     158      fprintf(stderr, "WARN: Could not quote value for '%s/%s'.  "
    159159              "Returned error: %s\n", prefix, quoted_name, conv_error);
    160160  }
    161161  /* XXX: should these always be printed? */
    162162  else if(conv_error != NULL && print_verbose)
    163     fprintf(stderr, "VERBOSE: While quoting value for '%s/%s', "
     163    fprintf(stderr, "INFO: While quoting value for '%s/%s', "
    164164            "warning returned: %s\n", prefix, quoted_name, conv_error);
    165165
     
    279279      cur_ancestor = regfi_parse_nk(f, virt_offset+REGFI_REGF_SIZE,
    280280                                    max_length, true);
     281      printMsgs(f);
     282
    281283      if(cur_ancestor == NULL)
    282284        virt_offset = REGFI_OFFSET_NONE;
     
    426428  for(i=0; i < range_list_size(unalloc_cells); i++)
    427429  {
     430    printMsgs(f);
    428431    cur_elem = range_list_get(unalloc_cells, i);
    429432    for(j=0; cur_elem->length > REGFI_NK_MIN_LENGTH
     
    432435      key = regfi_parse_nk(f, cur_elem->offset+j,
    433436                           cur_elem->length-j, false);
     437      printMsgs(f);
     438
    434439      if(key != NULL)
    435440      {
     
    587592  for(i=0; i < range_list_size(unalloc_cells); i++)
    588593  {
     594    printMsgs(f);
    589595    cur_elem = range_list_get(unalloc_cells, i);
    590596    for(j=0; j <= cur_elem->length; j+=8)
     
    592598      vk = regfi_parse_vk(f, cur_elem->offset+j,
    593599                           cur_elem->length-j, false);
     600      printMsgs(f);
     601
    594602      if(vk != NULL)
    595603      {
     
    654662  for(i=0; i < range_list_size(unalloc_cells); i++)
    655663  {
     664    printMsgs(f);
    656665    cur_elem = range_list_get(unalloc_cells, i);
    657666    for(j=0; j <= cur_elem->length; j+=8)
     
    659668      sk = regfi_parse_sk(f, cur_elem->offset+j,
    660669                          cur_elem->length-j, false);
     670      printMsgs(f);
     671
    661672      if(sk != NULL)
    662673      {
     
    741752    bailOut(EX_NOINPUT, "");
    742753  }
     754  if(print_verbose)
     755    regfi_set_message_mask(f, REGFI_MSG_ERROR|REGFI_MSG_WARN|REGFI_MSG_INFO);
     756  else
     757    regfi_set_message_mask(f, REGFI_MSG_ERROR);
    743758
    744759  if(print_header)
  • trunk/src/reglookup.c

    r137 r138  
    8686  }
    8787
    88   quoted_value = data_to_ascii(vk->data, size, vk->type, &conv_error);
    89   if(quoted_value == NULL)
    90   {
    91     if(conv_error == NULL)
    92       fprintf(stderr, "WARN: Could not quote value for '%s/%s'.  "
    93               "Memory allocation failure likely.\n", prefix, quoted_name);
    94     else if(print_verbose)
    95       fprintf(stderr, "WARN: Could not quote value for '%s/%s'.  "
    96               "Returned error: %s\n", prefix, quoted_name, conv_error);
    97   }
    98   else if(conv_error != NULL && print_verbose)
    99     fprintf(stderr, "VERBOSE: While quoting value for '%s/%s', "
    100             "warning returned: %s\n", prefix, quoted_name, conv_error);
     88  if(vk->data == NULL)
     89  {
     90    if(print_verbose)
     91      fprintf(stderr, "INFO: While quoting value for '%s/%s', "
     92              "data pointer was NULL.\n", prefix, quoted_name);
     93  }
     94  else
     95  {
     96    quoted_value = data_to_ascii(vk->data, size, vk->type, &conv_error);
     97    if(quoted_value == NULL)
     98    {
     99      if(conv_error == NULL)
     100        fprintf(stderr, "WARN: Could not quote value for '%s/%s'.  "
     101                "Memory allocation failure likely.\n", prefix, quoted_name);
     102      else
     103        fprintf(stderr, "WARN: Could not quote value for '%s/%s'.  "
     104                "Returned error: %s\n", prefix, quoted_name, conv_error);
     105    }
     106    else if(conv_error != NULL && print_verbose)
     107      fprintf(stderr, "INFO: While quoting value for '%s/%s', "
     108              "warning returned: %s\n", prefix, quoted_name, conv_error);
     109  }
    101110
    102111  str_type = regfi_type_val2str(vk->type);
     
    275284      printValue(value, prefix);
    276285    value = regfi_iterator_next_value(iter);
    277     printMsgs(iter);
     286    printMsgs(iter->f);
    278287  }
    279288}
     
    333342      {
    334343        if(print_verbose)
    335           fprintf(stderr, "WARN: While converting classname"
     344          fprintf(stderr, "INFO: While converting classname"
    336345                  " for key '%s': %s.\n", full_path, error_msg);
    337346        free(error_msg);
     
    341350      quoted_classname = empty_str;
    342351
    343     printMsgs(iter);
     352    printMsgs(iter->f);
    344353    printf("%s,KEY,,%s,%s,%s,%s,%s,%s\n", full_path, mtime,
    345354           owner, group, sacl, dacl, quoted_classname);
     
    372381  root = cur = regfi_iterator_cur_key(iter);
    373382  sub = regfi_iterator_first_subkey(iter);
    374   printMsgs(iter);
     383  printMsgs(iter->f);
    375384
    376385  if(root == NULL)
     
    400409        if(!regfi_iterator_up(iter))
    401410        {
    402           printMsgs(iter);
     411          printMsgs(iter->f);
    403412          bailOut(EX_DATAERR, "ERROR: could not traverse iterator upward.\n");
    404413        }
     
    407416        if(cur == NULL)
    408417        {
    409           printMsgs(iter);
     418          printMsgs(iter->f);
    410419          bailOut(EX_DATAERR, "ERROR: unexpected NULL for key.\n");
    411420        }
     
    421430      if(!regfi_iterator_down(iter))
    422431      {
    423         printMsgs(iter);
     432        printMsgs(iter->f);
    424433        bailOut(EX_DATAERR, "ERROR: could not traverse iterator downward.\n");
    425434      }
     
    429438      print_this = true;
    430439    }
    431     printMsgs(iter);
     440    printMsgs(iter->f);
    432441  } while(!((cur == root) && (sub == NULL)));
    433442
    434443  if(print_verbose)
    435     fprintf(stderr, "VERBOSE: Finished printing key tree.\n");
     444    fprintf(stderr, "INFO: Finished printing key tree.\n");
    436445}
    437446
     
    467476
    468477  if(print_verbose)
    469     fprintf(stderr, "VERBOSE: Attempting to retrieve specified path: %s\n",
     478    fprintf(stderr, "INFO: Attempting to retrieve specified path: %s\n",
    470479            path_filter);
    471480
     
    474483  {
    475484    if(print_verbose)
    476       fprintf(stderr, "VERBOSE: Found final path element as root key.\n");
     485      fprintf(stderr, "INFO: Found final path element as root key.\n");
    477486    free(tmp_path);
    478487    return 2;
     
    481490  if(!regfi_iterator_walk_path(iter, tmp_path))
    482491  {
    483     printMsgs(iter);
     492    printMsgs(iter->f);
    484493    free(tmp_path);
    485494    return 0;
     
    489498  {
    490499    if(print_verbose)
    491       fprintf(stderr, "VERBOSE: Found final path element as value.\n");
     500      fprintf(stderr, "INFO: Found final path element as value.\n");
    492501
    493502    value = regfi_iterator_cur_value(iter);
    494     printMsgs(iter);
     503    printMsgs(iter->f);
    495504    tmp_path_joined = iter2Path(iter);
    496505
     
    507516  else if(regfi_iterator_find_subkey(iter, path[i]))
    508517  {
    509     printMsgs(iter);
     518    printMsgs(iter->f);
    510519    if(print_verbose)
    511       fprintf(stderr, "VERBOSE: Found final path element as key.\n");
     520      fprintf(stderr, "INFO: Found final path element as key.\n");
    512521
    513522    if(!regfi_iterator_down(iter))
    514523    {
    515       printMsgs(iter);
     524      printMsgs(iter->f);
    516525      bailOut(EX_DATAERR, "ERROR: Unexpected error on traversing path filter key.\n");
    517526    }
     
    519528    return 2;
    520529  }
    521   printMsgs(iter);
     530  printMsgs(iter->f);
    522531
    523532  if(print_verbose)
    524     fprintf(stderr, "VERBOSE: Could not find last element of path.\n");
     533    fprintf(stderr, "INFO: Could not find last element of path.\n");
    525534
    526535  return 0;
     
    616625  }
    617626
     627  if(print_verbose)
     628    regfi_set_message_mask(f, REGFI_MSG_INFO|REGFI_MSG_WARN|REGFI_MSG_ERROR);
     629
    618630  iter = regfi_iterator_new(f);
    619631  if(iter == NULL)
     
    634646  {
    635647    retr_path_ret = retrievePath(iter, path);
    636     printMsgs(iter);
     648    printMsgs(iter->f);
    637649    freePath(path);
    638650
Note: See TracChangeset for help on using the changeset viewer.