Changeset 160 for trunk/src


Ignore:
Timestamp:
12/06/09 20:00:58 (15 years ago)
Author:
tim
Message:

reorganized classname parsing and interpretation code

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/common.c

    r159 r160  
    145145
    146146/*
    147  * Convert from UTF-16LE to ASCII.  Accepts a Unicode buffer, uni, and
    148  * it's length, uni_max.  Writes ASCII to the buffer ascii, whose size
    149  * is ascii_max.  Writes at most (ascii_max-1) bytes to ascii, and null
    150  * terminates the string.  Returns the length of the data written to
    151  * 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   else
    211   {
    212     ret_val = quote_string(ascii, special);
    213     free(ascii);
    214   }
    215  
    216   return ret_val;
    217 }
    218 
    219 
    220 /*
    221147 * Convert a data value to a string for display.  Returns NULL on error,
    222148 * and the string to display if there is no error, or a non-fatal
  • trunk/src/reglookup-recover.c

    r159 r160  
    6666}
    6767
    68 
     68/* XXX: Somewhere in here, need to start looking for and handling classnames */
    6969void printKey(REGFI_FILE* f, REGFI_NK_REC* nk, const char* prefix)
    7070{
  • trunk/src/reglookup.c

    r159 r160  
    282282  char* dacl = NULL;
    283283  char* quoted_classname;
    284   char* error_msg = NULL;
    285284  char mtime[20];
    286285  time_t tmp_time[1];
     
    288287  const REGFI_SK_REC* sk;
    289288  const REGFI_NK_REC* k = regfi_iterator_cur_key(iter);
     289  REGFI_CLASSNAME* classname;
    290290
    291291  *tmp_time = nt_time_to_unix(&k->mtime);
     
    308308      dacl = empty_str;
    309309
    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
    314325      if(quoted_classname == NULL)
    315326      {
    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;
    332330      }
    333331    }
    334332    else
    335333      quoted_classname = empty_str;
     334    regfi_free_classname(classname);
    336335
    337336    printMsgs(iter->f);
Note: See TracChangeset for help on using the changeset viewer.