Changeset 81 for trunk


Ignore:
Timestamp:
01/17/07 11:47:39 (17 years ago)
Author:
tim
Message:

Finished incorporating changes to reglookup to work with new regfi interface.

Compiles now, but is minimally tested.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Makefile

    r74 r81  
    1111
    1212CC=gcc
    13 OPTS=-std=gnu89 -pedantic -Wall
     13OPTS=-std=gnu89 -pedantic -Wall -ggdb
    1414INC=-I/usr/local/include
    1515LIB=-L/usr/local/lib
  • trunk/include/regfi.h

    r80 r81  
    66 * Windows NT registry I/O library
    77 *
    8  * Copyright (C) 2005-2006 Timothy D. Morgan
     8 * Copyright (C) 2005-2007 Timothy D. Morgan
    99 * Copyright (C) 2005 Gerald (Jerry) Carter
    1010 *
     
    6868/* XXX: Has MS defined a REG_QWORD_BE? */
    6969/* Not a real type in the registry */
    70 #define REG_KEY                        0xFFFFFFFF
     70#define REG_KEY                        0x7FFFFFFF
    7171
    7272
     
    183183} REGF_SK_REC;
    184184
     185
    185186/* Key Name */
    186 
    187187typedef struct {
    188188  REGF_HBIN *hbin;      /* pointer to HBIN record (in memory) containing
     
    220220  /* link in the other records here */
    221221  REGF_LF_REC subkeys;
    222   REGF_VK_REC *values;
    223   REGF_SK_REC *sec_desc;
     222  REGF_VK_REC* values;
     223  REGF_SK_REC* sec_desc;
    224224       
    225225} REGF_NK_REC;
    226226
     227
    227228/* REGF block */
    228  
    229229typedef struct {
    230230  /* run time information */
     
    290290int           regfi_close(REGF_FILE* r);
    291291
    292 REGF_NK_REC*  regfi_rootkey( REGF_FILE* file );
     292REGF_NK_REC*  regfi_rootkey(REGF_FILE* file);
    293293/* REGF_NK_REC*  regfi_fetch_subkey( REGF_FILE* file, REGF_NK_REC* nk ); */
    294294
    295295void            regfi_key_free(REGF_NK_REC* nk);
    296 void            regfi_value_free(REGF_VK_REC* vk);
    297296
    298297REGFI_ITERATOR* regfi_iterator_new(REGF_FILE* fh);
     
    302301bool            regfi_iterator_to_root(REGFI_ITERATOR* i);
    303302
    304 bool            regfi_iterator_find_subkey(REGFI_ITERATOR* i, const char* subkey_name)
     303bool            regfi_iterator_find_subkey(REGFI_ITERATOR* i, const char* subkey_name);
    305304bool            regfi_iterator_walk_path(REGFI_ITERATOR* i, const char** path);
     305/* XXX: these which return NK and VK records should return them as consts */
    306306REGF_NK_REC*    regfi_iterator_cur_key(REGFI_ITERATOR* i);
    307307REGF_NK_REC*    regfi_iterator_first_subkey(REGFI_ITERATOR* i);
  • trunk/include/void_stack.h

    r80 r81  
    11/*
    2  * Copyright (C) 2005 Timothy D. Morgan
     2 * Copyright (C) 2005,2007 Timothy D. Morgan
    33 *
    44 * This program is free software; you can redistribute it and/or modify
     
    2222#include <string.h>
    2323
     24#ifndef _VOID_STACK_H
    2425#define _VOID_STACK_H
    25 #ifndef _VOID_STACK_H
    2626
    2727typedef struct _void_stack
  • trunk/lib/Makefile

    r73 r81  
    33################################################################################
    44
    5 FILES=regfio.o smb_deps.o void_stack.o
     5FILES=regfi.o smb_deps.o void_stack.o
    66
    77all: $(FILES)
    88
    9 regfio.o: regfio.c
    10         $(CC) $(CFLAGS) $(OPTS) $(INC) -c -o $@ regfio.c
     9regfi.o: regfi.c
     10        $(CC) $(CFLAGS) $(OPTS) $(INC) -c -o $@ regfi.c
    1111
    1212smb_deps.o: smb_deps.c
  • trunk/lib/regfi.c

    r80 r81  
    66 * Windows NT registry I/O library
    77 *
    8  * Copyright (C) 2005-2006 Timothy D. Morgan
     8 * Copyright (C) 2005-2007 Timothy D. Morgan
    99 * Copyright (C) 2005 Gerald (Jerry) Carter
    1010 *
     
    2525 */
    2626
    27 #include "../include/regfio.h"
     27#include "../include/regfi.h"
    2828
    2929
     
    629629    nk->hbin->dirty = true;
    630630 
    631   nk->subkey_index = 0;
    632631  return true;
    633632}
     
    15161515  {
    15171516    for(i=0; i < nk->num_values; i++)
    1518       regfi_value_free(nk->values[i]);
     1517    {
     1518      if(nk->values[i].valuename != NULL)
     1519        free(nk->values[i].valuename);
     1520      if(nk->values[i].data != NULL)
     1521        free(nk->values[i].data);
     1522    }
    15191523    free(nk->values);
    15201524  }
     
    15331537/******************************************************************************
    15341538 *****************************************************************************/
    1535 void regfi_value_free(REGF_VK_REC* vk)
    1536 {
    1537   if(vk->valuename != NULL)
    1538     free(vk->valuename);
    1539   if(vk->data != NULL)
    1540     free(vk->data); 
    1541  
    1542   /* XXX: not freeing hbin because these are cached.  This needs to be reviewed. */
    1543   free(vk);
    1544 }
    1545 
    1546 
    1547 /******************************************************************************
    1548  *****************************************************************************/
    15491539REGFI_ITERATOR* regfi_iterator_new(REGF_FILE* fh)
    15501540{
     
    15541544    return NULL;
    15551545
    1556   root = regfi_rootkey(f);
     1546  root = regfi_rootkey(fh);
    15571547  if(root == NULL)
    15581548  {
     
    17251715/******************************************************************************
    17261716 *****************************************************************************/
    1727 REGF_NK_REC* regfi_iterator_cur_key(REGFI_ITERATOR* i);
     1717REGF_NK_REC* regfi_iterator_cur_key(REGFI_ITERATOR* i)
    17281718{
    17291719  return i->cur_key;
     
    17351725REGF_NK_REC* regfi_iterator_first_subkey(REGFI_ITERATOR* i)
    17361726{
    1737   REGF_NK_REC* subkey;
    1738   REGF_HBIN* hbin;
    1739  
    17401727  i->cur_subkey = 0;
    17411728  return regfi_iterator_cur_subkey(i);
     
    18211808       && (strcasecmp(cur->valuename, value_name) == 0))
    18221809      found = true;
    1823     cur = retfi_iterator_next_value(i);
     1810    cur = regfi_iterator_next_value(i);
    18241811  }
    18251812
     
    18461833  REGF_VK_REC* ret_val = NULL;
    18471834  if(i->cur_value < i->cur_key->num_values)
    1848     ret_val = i->cur_key->values[i];
     1835    ret_val = &(i->cur_key->values[i->cur_value]);
    18491836
    18501837  return ret_val;
  • trunk/lib/void_stack.c

    r80 r81  
    44 * leaks.
    55 *
    6  * Copyright (C) 2005 Timothy D. Morgan
     6 * Copyright (C) 2005,2007 Timothy D. Morgan
    77 *
    88 * This program is free software; you can redistribute it and/or modify
  • trunk/src/reglookup.c

    r80 r81  
    33 * Gerald Carter''s regfio interface.
    44 *
    5  * Copyright (C) 2005-2006 Timothy D. Morgan
     5 * Copyright (C) 2005-2007 Timothy D. Morgan
    66 * Copyright (C) 2002 Richard Sharpe, rsharpe@richardsharpe.com
    77 *
     
    382382
    383383
    384 void_stack* path2Stack(const char* s)
    385 {
    386   void_stack* ret_val;
    387   void_stack* rev_ret = void_stack_new(REGF_MAX_DEPTH);
     384char** splitPath(const char* s)
     385{
     386  char** ret_val;
    388387  const char* cur = s;
    389388  char* next = NULL;
    390389  char* copy;
    391 
    392   if (rev_ret == NULL)
     390  uint32 ret_cur = 0;
     391
     392  ret_val = (char**)malloc((REGF_MAX_DEPTH+1+1)*sizeof(char**));
     393  if (ret_val == NULL)
    393394    return NULL;
     395  ret_val[0] = NULL;
     396
     397  /* We return a well-formed, 0-length, path even when input is icky. */
    394398  if (s == NULL)
    395     return rev_ret;
     399    return ret_val;
    396400 
    397401  while((next = strchr(cur, '/')) != NULL)
     
    405409      memcpy(copy, cur, next-cur);
    406410      copy[next-cur] = '\0';
    407       if(!void_stack_push(rev_ret, copy))
     411      ret_val[ret_cur++] = copy;
     412      if(ret_cur < (REGF_MAX_DEPTH+1+1))
     413        ret_val[ret_cur] = NULL;
     414      else
    408415        bailOut(2, "ERROR: Registry maximum depth exceeded.\n");
    409416    }
    410417    cur = next+1;
    411418  }
     419
     420  /* Grab last element, if path doesn't end in '/'. */
    412421  if(strlen(cur) > 0)
    413422  {
    414423    copy = strdup(cur);
    415     if(!void_stack_push(rev_ret, copy))
     424    ret_val[ret_cur++] = copy;
     425    if(ret_cur < (REGF_MAX_DEPTH+1+1))
     426      ret_val[ret_cur] = NULL;
     427    else
    416428      bailOut(2, "ERROR: Registry maximum depth exceeded.\n");
    417429  }
    418430
    419   ret_val = void_stack_copy_reverse(rev_ret);
    420   void_stack_free(rev_ret);
    421 
    422431  return ret_val;
    423432}
    424433
    425 /* Returns a quoted path from an nk_stack */
    426 char* stack2Path(void_stack* nk_stack)
    427 {
    428   const REGF_NK_REC* cur;
     434
     435/* Returns a quoted path from an iterator's stack */
     436/* XXX: Some way should be found to integrate this into regfi's API
     437 *      The problem is that the escaping is sorta reglookup-specific.
     438 */
     439char* iter2Path(REGFI_ITERATOR* i)
     440{
     441  const REGFI_ITER_POSITION* cur;
    429442  uint32 buf_left = 127;
    430443  uint32 buf_len = buf_left+1;
    431444  uint32 name_len = 0;
    432445  uint32 grow_amt;
    433   char* buf; 
     446  char* buf;
    434447  char* new_buf;
    435448  char* name;
     449  const char* cur_name;
    436450  void_stack_iterator* iter;
    437451 
     
    441455  buf[0] = '\0';
    442456
    443   iter = void_stack_iterator_new(nk_stack);
     457  iter = void_stack_iterator_new(i->key_positions);
    444458  if (iter == NULL)
    445459  {
     
    449463
    450464  /* skip root element */
     465  if(void_stack_size(i->key_positions) < 1)
     466  {
     467    buf[0] = '/';
     468    buf[1] = '\0';
     469    return buf;
     470  }
    451471  cur = void_stack_iterator_next(iter);
    452472
    453   while((cur = void_stack_iterator_next(iter)) != NULL)
    454   {
     473  do
     474  {
     475    cur = void_stack_iterator_next(iter);
     476    if (cur == NULL)
     477      cur_name = i->cur_key->keyname;
     478    else
     479      cur_name = cur->nk->keyname;
     480
    455481    buf[buf_len-buf_left-1] = '/';
    456482    buf_left -= 1;
    457     name = quote_string(cur->keyname, key_special_chars);
     483    name = quote_string(cur_name, key_special_chars);
    458484    name_len = strlen(name);
    459485    if(name_len+1 > buf_left)
     
    474500    buf[buf_len-buf_left-1] = '\0';
    475501    free(name);
    476   }
     502  } while(cur != NULL);
    477503
    478504  return buf;
     
    572598
    573599
    574 void printValueList(REGFI_ITERATOR i, char* prefix)
     600void printValueList(REGFI_ITERATOR* i, char* prefix)
    575601{
    576602  REGF_VK_REC* value;
     
    578604  value = regfi_iterator_first_value(i);
    579605  while(value != NULL)
    580     if(!type_filter_enabled || (value.type == type_filter))
     606  {
     607    if(!type_filter_enabled || (value->type == type_filter))
    581608      printValue(value, prefix);
     609    value = regfi_iterator_next_value(i);
     610  }
    582611}
    583612
     
    630659
    631660
    632 void printKeyTree(REGF_FILE* f, void_stack* nk_stack, const char* prefix)
    633 {
     661void printKeyTree(REGFI_ITERATOR* iter)
     662{
     663  REGF_NK_REC* root = NULL;
    634664  REGF_NK_REC* cur = NULL;
    635665  REGF_NK_REC* sub = NULL;
    636666  char* path = NULL;
    637   char* val_path = NULL;
    638   uint32 val_path_len = 0;
    639   uint32 path_len = 0;
    640   uint32 prefix_len = strlen(prefix);
    641667  int key_type = regfi_type_str2val("KEY");
     668  bool print_this = true;
     669
     670  root = cur = regfi_iterator_cur_key(iter);
     671  sub = regfi_iterator_first_subkey(iter);
    642672 
    643   if((cur = (REGF_NK_REC*)void_stack_cur(nk_stack)) != NULL)
    644   {
    645     cur->subkey_index = 0;
    646     path = stack2Path(nk_stack);
    647 
    648     if(print_verbose)
    649     {
    650       if(prefix[0] == '\0')
    651         fprintf(stderr, "VERBOSE: Printing key tree under path: /\n");
    652       else
    653         fprintf(stderr, "VERBOSE: Printing key tree under path: %s\n",
    654                 prefix);
    655     }
    656 
    657     path_len = strlen(path);
    658     val_path_len = prefix_len+path_len;
    659     val_path = (char*)malloc(val_path_len+1+1);
    660     if(val_path == NULL)
    661       bailOut(2, "ERROR: Could not allocate val_path.\n");
    662 
    663     strcpy(val_path, prefix);
    664     strcpy(val_path+prefix_len, path);
    665     if(val_path[0] == '\0')
    666     {
    667       val_path[0] = '/';
    668       val_path[1] = '\0';
    669     }
    670     if(!type_filter_enabled || (key_type == type_filter))
    671       printKey(cur, val_path);
    672     if(!type_filter_enabled || (key_type != type_filter))
    673       printValueList(cur, val_path);
     673  if(root == NULL)
     674    bailOut(3, "ERROR: root cannot be NULL.\n");
     675 
     676  do
     677  {
     678    if(print_this)
     679    {
     680      path = iter2Path(iter);
     681      if(path == NULL)
     682        bailOut(2, "ERROR: Could not construct iterator's path.\n");
     683     
     684      if(!type_filter_enabled || (key_type == type_filter))
     685        printKey(cur, path);
     686      if(!type_filter_enabled || (key_type != type_filter))
     687        printValueList(iter, path);
     688     
     689      free(path);
     690    }
    674691   
    675     while((cur = (REGF_NK_REC*)void_stack_cur(nk_stack)) != NULL)
    676     {
    677       if((sub = regfi_fetch_subkey(f, cur)) == NULL)
     692    if(sub == NULL)
     693    {
     694      if(cur != root)
    678695      {
    679         sub = void_stack_pop(nk_stack);
    680         /* XXX: This is just a shallow free.  Need to write deep free
    681          * routines to replace the Samba code for this.
    682          */
    683         if(sub != NULL)
    684           free(sub);
     696        /* We're done with this sub-tree, going up and hitting other branches. */
     697        if(!regfi_iterator_up(iter))
     698          bailOut(3, "ERROR: could not traverse iterator upward.\n");
     699       
     700        cur = regfi_iterator_cur_key(iter);
     701        if(cur == NULL)
     702          bailOut(3, "ERROR: unexpected NULL for key.\n");
     703       
     704        sub = regfi_iterator_next_subkey(iter);
    685705      }
    686       else
    687       {
    688         sub->subkey_index = 0;
    689         if(!void_stack_push(nk_stack, sub))
    690           bailOut(2, "ERROR: Registry maximum depth exceeded.\n");
    691         path = stack2Path(nk_stack);
    692         if(path != NULL)
    693         {
    694           path_len = strlen(path);
    695           if(val_path_len < prefix_len+path_len)
    696           {
    697             val_path_len = prefix_len+path_len;
    698             val_path = (char*)realloc(val_path, val_path_len+1);
    699             if(val_path == NULL)
    700               bailOut(2, "ERROR: Could not reallocate val_path.\n");
    701           }
    702           strcpy(val_path, prefix);
    703           strcpy(val_path+prefix_len, path);
    704           if(!type_filter_enabled || (key_type == type_filter))
    705             printKey(sub, val_path);
    706           if(!type_filter_enabled || (key_type != type_filter))
    707             printValueList(sub, val_path);
    708         }
    709       }
    710     }
    711   }
    712   if(val_path != NULL)
    713     free(val_path);
     706      print_this = false;
     707    }
     708    else
     709    { /* We have unexplored sub-keys. 
     710       * Let's move down and print this first sub-tree out.
     711       */
     712      if(!regfi_iterator_down(iter))
     713        bailOut(3, "ERROR: could not traverse iterator downward.\n");
     714
     715      cur = sub;
     716      sub = regfi_iterator_first_subkey(iter);
     717      print_this = true;
     718    }
     719  } while(!((cur == root) && (sub == NULL)));
     720
    714721  if(print_verbose)
    715722    fprintf(stderr, "VERBOSE: Finished printing key tree.\n");
    716723}
     724
    717725
    718726/*
     
    724732int retrievePath(REGFI_ITERATOR* iter, char** path)
    725733{
    726   REG_VK_REC* value;
     734  REGF_VK_REC* value;
     735  char* tmp_path_joined;
     736  const char** tmp_path;
    727737  uint32 i;
    728   char* p;
    729   char* tmp_path_joined;
    730   char** tmp_path;
    731738 
    732739  if(path == NULL)
     
    734741
    735742  /* One extra for any value at the end, and one more for NULL */
    736   tmp_path = (char**)malloc(sizeof(char**)*(REGF_MAX_DEPTH+1+1));
     743  tmp_path = (const char**)malloc(sizeof(const char**)*(REGF_MAX_DEPTH+1+1));
    737744  if(tmp_path == NULL)
    738745    return -2;
     
    763770
    764771    value = regfi_iterator_cur_value(iter);
    765     tmp_path_joined = joinPath(tmp_path);
     772    tmp_path_joined = iter2Path(iter);
    766773
    767774    if((value == NULL) || (tmp_path_joined == NULL))
     
    808815int main(int argc, char** argv)
    809816{
    810   void_stack* path_stack;
    811817  char** path = NULL;
    812818  REGF_FILE* f;
    813   REGF_NK_REC* root;
    814819  REGFI_ITERATOR* iter;
    815820  int retr_path_ret;
     
    883888    bailOut(3, "ERROR: Couldn't create registry iterator.\n");
    884889
     890  if(print_header)
     891  {
     892    if(print_security)
     893      printf("PATH,TYPE,VALUE,MTIME,OWNER,GROUP,SACL,DACL\n");
     894    else
     895      printf("PATH,TYPE,VALUE,MTIME\n");
     896  }
     897
    885898  if(path_filter_enabled && path_filter != NULL)
    886899    path = splitPath(path_filter);
    887  
     900
    888901  if(path != NULL)
    889902  {
     
    892905      fprintf(stderr, "WARNING: specified path not found.\n");
    893906    else if (retr_path_ret == 2)
    894       printKeyTree(iter, path_filter);
     907      printKeyTree(iter);
    895908    else if(retr_path_ret != 0)
    896909      bailOut(4, "ERROR: Unknown error occurred in retrieving path.\n");
    897910  }
    898911  else
    899     printKeyTree(iter, "");
     912    printKeyTree(iter);
    900913
    901914  regfi_iterator_free(iter);
Note: See TracChangeset for help on using the changeset viewer.