Changeset 137 for trunk/src


Ignore:
Timestamp:
01/23/09 17:58:43 (16 years ago)
Author:
tim
Message:

Added error messages to most parse functions in regfi

Relaxed validation requirements on NK types and missing value data

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/common.c

    r136 r137  
    3838}
    3939
     40void printMsgs(REGFI_ITERATOR* iter)
     41{
     42  char* msgs = regfi_get_messages(iter->f);
     43  if(msgs != NULL)
     44  {
     45    fprintf(stderr, "%s", msgs);
     46    free(msgs);
     47  }
     48}
     49
    4050
    4151/* Returns a newly malloc()ed string which contains original buffer,
     
    205215 * is the responsibility of the caller to free both a non-NULL return
    206216 * value, and a non-NULL (*error_msg).
     217 */
     218/* XXX: Part of this function's logic should be pushed into the regfi API.
     219 *      The structures should be parsed and stored with VK records and only
     220 *      escaped/encoded later in reglookup and reglookup-recover.
    207221 */
    208222static char* data_to_ascii(unsigned char* datap, uint32 len, uint32 type,
  • trunk/src/reglookup.c

    r136 r137  
    6767  if(size > REGFI_VK_MAX_DATA_LENGTH)
    6868  {
    69     fprintf(stderr, "WARNING: value data size %d larger than "
     69    fprintf(stderr, "WARN: value data size %d larger than "
    7070            "%d, truncating...\n", size, REGFI_VK_MAX_DATA_LENGTH);
    7171    size = REGFI_VK_MAX_DATA_LENGTH;
     
    9090  {
    9191    if(conv_error == NULL)
    92       fprintf(stderr, "WARNING: Could not quote value for '%s/%s'.  "
     92      fprintf(stderr, "WARN: Could not quote value for '%s/%s'.  "
    9393              "Memory allocation failure likely.\n", prefix, quoted_name);
    9494    else if(print_verbose)
    95       fprintf(stderr, "WARNING: Could not quote value for '%s/%s'.  "
     95      fprintf(stderr, "WARN: Could not quote value for '%s/%s'.  "
    9696              "Returned error: %s\n", prefix, quoted_name, conv_error);
    9797  }
     
    129129
    130130
    131 
    132 /* XXX: Each chunk must be unquoted after it is split out.
    133  *      Quoting syntax may need to be standardized and pushed into the API
    134  *      to deal with this issue and others.
    135  */
    136131char** splitPath(const char* s)
    137132{
     
    200195
    201196/* Returns a quoted path from an iterator's stack */
    202 /* XXX: Some way should be found to integrate this into regfi's API
    203  *      The problem is that the escaping is sorta reglookup-specific.
    204  */
    205197char* iter2Path(REGFI_ITERATOR* i)
    206198{
     
    273265
    274266
    275 void printValueList(REGFI_ITERATOR* i, char* prefix)
     267void printValueList(REGFI_ITERATOR* iter, char* prefix)
    276268{
    277269  const REGFI_VK_REC* value;
    278270
    279   value = regfi_iterator_first_value(i);
     271  value = regfi_iterator_first_value(iter);
    280272  while(value != NULL)
    281273  {
    282274    if(!type_filter_enabled || (value->type == type_filter))
    283275      printValue(value, prefix);
    284     value = regfi_iterator_next_value(i);
    285   }
    286 }
    287 
    288 
    289 void printKey(REGFI_ITERATOR* i, char* full_path)
     276    value = regfi_iterator_next_value(iter);
     277    printMsgs(iter);
     278  }
     279}
     280
     281
     282void printKey(REGFI_ITERATOR* iter, char* full_path)
    290283{
    291284  static char empty_str[1] = "";
     
    300293  struct tm* tmp_time_s = NULL;
    301294  const REGFI_SK_REC* sk;
    302   const REGFI_NK_REC* k = regfi_iterator_cur_key(i);
     295  const REGFI_NK_REC* k = regfi_iterator_cur_key(iter);
    303296
    304297  *tmp_time = nt_time_to_unix(&k->mtime);
     
    306299  strftime(mtime, sizeof(mtime), "%Y-%m-%d %H:%M:%S", tmp_time_s);
    307300
    308   if(print_security && (sk=regfi_iterator_cur_sk(i)))
     301  if(print_security && (sk=regfi_iterator_cur_sk(iter)))
    309302  {
    310303    owner = regfi_get_owner(sk->sec_desc);
     
    340333      {
    341334        if(print_verbose)
    342           fprintf(stderr, "WARNING: While converting classname"
     335          fprintf(stderr, "WARN: While converting classname"
    343336                  " for key '%s': %s.\n", full_path, error_msg);
    344337        free(error_msg);
     
    348341      quoted_classname = empty_str;
    349342
     343    printMsgs(iter);
    350344    printf("%s,KEY,,%s,%s,%s,%s,%s,%s\n", full_path, mtime,
    351345           owner, group, sacl, dacl, quoted_classname);
     
    373367  const REGFI_NK_REC* sub = NULL;
    374368  char* path = NULL;
    375   char* msgs = NULL;
    376369  int key_type = regfi_type_str2val("KEY");
    377370  bool print_this = true;
     
    379372  root = cur = regfi_iterator_cur_key(iter);
    380373  sub = regfi_iterator_first_subkey(iter);
    381   msgs = regfi_get_messages(iter->f);
    382   if(msgs != NULL)
    383     fprintf(stderr, "%s", msgs);
     374  printMsgs(iter);
     375
    384376  if(root == NULL)
    385377    bailOut(EX_DATAERR, "ERROR: root cannot be NULL.\n");
     
    392384      if(path == NULL)
    393385        bailOut(EX_OSERR, "ERROR: Could not construct iterator's path.\n");
    394      
     386
    395387      if(!type_filter_enabled || (key_type == type_filter))
    396388        printKey(iter, path);
     
    407399        /* We're done with this sub-tree, going up and hitting other branches. */
    408400        if(!regfi_iterator_up(iter))
     401        {
     402          printMsgs(iter);
    409403          bailOut(EX_DATAERR, "ERROR: could not traverse iterator upward.\n");
    410        
     404        }
     405
    411406        cur = regfi_iterator_cur_key(iter);
    412407        if(cur == NULL)
     408        {
     409          printMsgs(iter);
    413410          bailOut(EX_DATAERR, "ERROR: unexpected NULL for key.\n");
    414        
     411        }
     412
    415413        sub = regfi_iterator_next_subkey(iter);
    416414      }
     
    422420       */
    423421      if(!regfi_iterator_down(iter))
     422      {
     423        printMsgs(iter);
    424424        bailOut(EX_DATAERR, "ERROR: could not traverse iterator downward.\n");
     425      }
    425426
    426427      cur = sub;
     
    428429      print_this = true;
    429430    }
     431    printMsgs(iter);
    430432  } while(!((cur == root) && (sub == NULL)));
    431433
     
    479481  if(!regfi_iterator_walk_path(iter, tmp_path))
    480482  {
     483    printMsgs(iter);
    481484    free(tmp_path);
    482485    return 0;
     
    489492
    490493    value = regfi_iterator_cur_value(iter);
     494    printMsgs(iter);
    491495    tmp_path_joined = iter2Path(iter);
    492496
     
    503507  else if(regfi_iterator_find_subkey(iter, path[i]))
    504508  {
     509    printMsgs(iter);
    505510    if(print_verbose)
    506511      fprintf(stderr, "VERBOSE: Found final path element as key.\n");
    507512
    508513    if(!regfi_iterator_down(iter))
     514    {
     515      printMsgs(iter);
    509516      bailOut(EX_DATAERR, "ERROR: Unexpected error on traversing path filter key.\n");
     517    }
    510518
    511519    return 2;
    512520  }
     521  printMsgs(iter);
    513522
    514523  if(print_verbose)
     
    625634  {
    626635    retr_path_ret = retrievePath(iter, path);
     636    printMsgs(iter);
    627637    freePath(path);
    628638
    629639    if(retr_path_ret == 0)
    630       fprintf(stderr, "WARNING: specified path not found.\n");
     640      fprintf(stderr, "WARN: specified path not found.\n");
    631641    else if (retr_path_ret == 2)
    632642      printKeyTree(iter);
Note: See TracChangeset for help on using the changeset viewer.