Changeset 78 for trunk


Ignore:
Timestamp:
01/15/07 10:22:47 (18 years ago)
Author:
tim
Message:

beginning process of rewriting regfio interface.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/regfio.h

    r77 r78  
    3131 ***********************************************************/
    3232
    33 #ifndef _REGFIO_H
    34 #define _REGFIO_H
     33#ifndef _REGFI_H
     34#define _REGFI_H
    3535
    3636#include <stdlib.h>
     
    4747
    4848#include "smb_deps.h"
     49#include "void_stack.h"
    4950
    5051/******************************************************************************/
     
    7273#define REGF_BLOCKSIZE          0x1000
    7374#define REGF_ALLOC_BLOCK        0x1000
     75#define REGF_MAX_DEPTH          512
    7476
    7577/* header sizes for various records */
     
    188190                         */
    189191  uint32 hbin_off;      /* offset from beginning of this hbin block */
    190   uint32 subkey_index;  /* index to next subkey record to return */
     192  /*uint32 subkey_index;*/      /* index to next subkey record to return */
    191193  uint32 rec_size;      /* ((start_offset - end_offset) & 0xfffffff8) */
    192194 
     
    246248                                 */
    247249 
    248   /* unknowns used to simply writing */
     250  /* unknowns */
    249251  uint32 unknown1;
    250252  uint32 unknown2;
     
    256258
    257259
     260
     261typedef struct {
     262  REGF_FILE* f;
     263  void_stack* keys;
     264  uint32 cur_subkey;
     265  uint32 cur_value;
     266} REGFI_ITERATOR;
     267
    258268/******************************************************************************/
    259269/* Function Declarations */
    260270
    261 const char*   regfio_type_val2str(unsigned int val);
    262 int           regfio_type_str2val(const char* str);
    263 
    264 char*         regfio_get_sacl(SEC_DESC *sec_desc);
    265 char*         regfio_get_dacl(SEC_DESC *sec_desc);
    266 char*         regfio_get_owner(SEC_DESC *sec_desc);
    267 char*         regfio_get_group(SEC_DESC *sec_desc);
    268 
    269 REGF_FILE*    regfio_open( const char *filename );
    270 int           regfio_close( REGF_FILE *r );
    271 
    272 REGF_NK_REC*  regfio_rootkey( REGF_FILE *file );
    273 REGF_NK_REC*  regfio_fetch_subkey( REGF_FILE *file, REGF_NK_REC *nk );
    274 
    275 #endif  /* _REGFIO_H */
     271const char*   regfi_type_val2str(unsigned int val);
     272int           regfi_type_str2val(const char* str);
     273
     274char*         regfi_get_sacl(SEC_DESC *sec_desc);
     275char*         regfi_get_dacl(SEC_DESC *sec_desc);
     276char*         regfi_get_owner(SEC_DESC *sec_desc);
     277char*         regfi_get_group(SEC_DESC *sec_desc);
     278
     279REGF_FILE*    regfi_open( const char *filename );
     280int           regfi_close( REGF_FILE *r );
     281
     282REGF_NK_REC*  regfi_rootkey( REGF_FILE *file );
     283/* REGF_NK_REC*  regfi_fetch_subkey( REGF_FILE *file, REGF_NK_REC *nk ); */
     284
     285REGFI_ITERATOR* regfi_iterator_create(REGF_FILE* fh);
     286bool            regfi_iterator_down(REGFI_ITERATOR* i, const char* subkey_name);
     287bool            regfi_iterator_up(REGFI_ITERATOR* i);
     288REGF_NK_REC*    regfi_iterator_next_subkey(REGFI_ITERATOR* i);
     289REGF_VK_REC*    regfi_iterator_next_value(REGFI_ITERATOR* i);
     290REGF_VK_REC*    regfi_iterator_fetch_value(REGFI_ITERATOR* i, const char* value_name);
     291char*           regfi_iterator_curpath(REGFI_ITERATOR* i);
     292
     293#endif  /* _REGFI_H */
  • trunk/lib/regfio.c

    r77 r78  
    2929
    3030/* Registry types mapping */
    31 const unsigned int regfio_num_reg_types = 12;
    32 static const char* regfio_type_names[] =
     31const unsigned int regfi_num_reg_types = 12;
     32static const char* regfi_type_names[] =
    3333  {"NONE", "SZ", "EXPAND_SZ", "BINARY", "DWORD", "DWORD_BE", "LINK",
    3434   "MULTI_SZ", "RSRC_LIST", "RSRC_DESC", "RSRC_REQ_LIST", "QWORD"};
     
    3636
    3737/* Returns NULL on error */
    38 const char* regfio_type_val2str(unsigned int val)
     38const char* regfi_type_val2str(unsigned int val)
    3939{
    4040  if(val == REG_KEY)
    4141    return "KEY";
    4242 
    43   if(val >= regfio_num_reg_types)
     43  if(val >= regfi_num_reg_types)
    4444    return NULL;
    4545 
    46   return regfio_type_names[val];
     46  return regfi_type_names[val];
    4747}
    4848
    4949
    5050/* Returns -1 on error */
    51 int regfio_type_str2val(const char* str)
     51int regfi_type_str2val(const char* str)
    5252{
    5353  int i;
     
    5656    return REG_KEY;
    5757
    58   for(i=0; i < regfio_num_reg_types; i++)
    59     if (strcmp(regfio_type_names[i], str) == 0)
     58  for(i=0; i < regfi_num_reg_types; i++)
     59    if (strcmp(regfi_type_names[i], str) == 0)
    6060      return i;
    6161
     
    6969/* Security descriptor parsing functions  */
    7070
    71 const char* regfio_ace_type2str(uint8 type)
     71const char* regfi_ace_type2str(uint8 type)
    7272{
    7373  static const char* map[7]
     
    8989 *   http://msdn2.microsoft.com/en-us/library/aa772242.aspx
    9090 */
    91 char* regfio_ace_flags2str(uint8 flags)
     91char* regfi_ace_flags2str(uint8 flags)
    9292{
    9393  static const char* flag_map[32] =
     
    147147
    148148
    149 char* regfio_ace_perms2str(uint32 perms)
     149char* regfi_ace_perms2str(uint32 perms)
    150150{
    151151  uint32 i, p;
     
    226226
    227227
    228 char* regfio_sid2str(DOM_SID* sid)
     228char* regfi_sid2str(DOM_SID* sid)
    229229{
    230230  uint32 i, size = MAXSUBAUTHS*11 + 24;
     
    248248
    249249
    250 char* regfio_get_acl(SEC_ACL* acl)
     250char* regfi_get_acl(SEC_ACL* acl)
    251251{
    252252  uint32 i, extra, size = 0;
     
    263263  for (i = 0; i < acl->num_aces && !failed; i++)
    264264  {
    265     sid_str = regfio_sid2str(&acl->ace[i].trustee);
    266     type_str = regfio_ace_type2str(acl->ace[i].type);
    267     perms_str = regfio_ace_perms2str(acl->ace[i].info.mask);
    268     flags_str = regfio_ace_flags2str(acl->ace[i].flags);
     265    sid_str = regfi_sid2str(&acl->ace[i].trustee);
     266    type_str = regfi_ace_type2str(acl->ace[i].type);
     267    perms_str = regfi_ace_perms2str(acl->ace[i].info.mask);
     268    flags_str = regfi_ace_flags2str(acl->ace[i].flags);
    269269   
    270270    if(flags_str != NULL && perms_str != NULL
     
    307307
    308308
    309 char* regfio_get_sacl(SEC_DESC *sec_desc)
     309char* regfi_get_sacl(SEC_DESC *sec_desc)
    310310{
    311311  if (sec_desc->sacl)
    312     return regfio_get_acl(sec_desc->sacl);
     312    return regfi_get_acl(sec_desc->sacl);
    313313  else
    314314    return NULL;
     
    316316
    317317
    318 char* regfio_get_dacl(SEC_DESC *sec_desc)
     318char* regfi_get_dacl(SEC_DESC *sec_desc)
    319319{
    320320  if (sec_desc->dacl)
    321     return regfio_get_acl(sec_desc->dacl);
     321    return regfi_get_acl(sec_desc->dacl);
    322322  else
    323323    return NULL;
     
    325325
    326326
    327 char* regfio_get_owner(SEC_DESC *sec_desc)
    328 {
    329   return regfio_sid2str(sec_desc->owner_sid);
    330 }
    331 
    332 
    333 char* regfio_get_group(SEC_DESC *sec_desc)
    334 {
    335   return regfio_sid2str(sec_desc->grp_sid);
     327char* regfi_get_owner(SEC_DESC *sec_desc)
     328{
     329  return regfi_sid2str(sec_desc->owner_sid);
     330}
     331
     332
     333char* regfi_get_group(SEC_DESC *sec_desc)
     334{
     335  return regfi_sid2str(sec_desc->grp_sid);
    336336}
    337337
     
    13681368 first hbin offset.
    13691369*******************************************************************/
    1370 REGF_FILE* regfio_open( const char *filename )
     1370REGF_FILE* regfi_open( const char *filename )
    13711371{
    13721372  REGF_FILE *rb;
     
    13821382  /*    if ( !(rb->mem_ctx = talloc_init( "read_regf_block" )) )
    13831383    {
    1384     regfio_close( rb );
     1384    regfi_close( rb );
    13851385    return NULL;
    13861386    }
     
    13911391
    13921392  if ( (rb->fd = open(filename, flags)) == -1 ) {
    1393     /* DEBUG(0,("regfio_open: failure to open %s (%s)\n", filename, strerror(errno)));*/
    1394     regfio_close( rb );
     1393    /* DEBUG(0,("regfi_open: failure to open %s (%s)\n", filename, strerror(errno)));*/
     1394    regfi_close( rb );
    13951395    return NULL;
    13961396  }
     
    13991399       
    14001400  if ( !read_regf_block( rb ) ) {
    1401     /* DEBUG(0,("regfio_open: Failed to read initial REGF block\n"));*/
    1402     regfio_close( rb );
     1401    /* DEBUG(0,("regfi_open: Failed to read initial REGF block\n"));*/
     1402    regfi_close( rb );
    14031403    return NULL;
    14041404  }
     
    14121412/*******************************************************************
    14131413 *******************************************************************/
    1414 static void regfio_mem_free( REGF_FILE *file )
     1414static void regfi_mem_free( REGF_FILE *file )
    14151415{
    14161416  /* free any zalloc()'d memory */
     
    14241424/*******************************************************************
    14251425 *******************************************************************/
    1426 int regfio_close( REGF_FILE *file )
     1426int regfi_close( REGF_FILE *file )
    14271427{
    14281428  int fd;
    14291429
    1430   regfio_mem_free( file );
     1430  regfi_mem_free( file );
    14311431
    14321432  /* nothing to do if there is no open file */
     
    14471447 on my experience.  --jerry
    14481448*******************************************************************/
    1449 REGF_NK_REC* regfio_rootkey( REGF_FILE *file )
     1449REGF_NK_REC* regfi_rootkey( REGF_FILE *file )
    14501450{
    14511451  REGF_NK_REC *nk;
     
    14591459               
    14601460  if ( !(nk = (REGF_NK_REC*)zalloc(sizeof(REGF_NK_REC) )) ) {
    1461     /*DEBUG(0,("regfio_rootkey: zalloc() failed!\n"));*/
     1461    /*DEBUG(0,("regfi_rootkey: zalloc() failed!\n"));*/
    14621462    return NULL;
    14631463  }
     
    14921492       
    14931493  if ( !found ) {
    1494     /*DEBUG(0,("regfio_rootkey: corrupt registry file ?  No root key record located\n"));*/
     1494    /*DEBUG(0,("regfi_rootkey: corrupt registry file ?  No root key record located\n"));*/
    14951495    return NULL;
    14961496  }
     
    15101510 NK record.  Remember that offsets are from the *first* HBIN block.
    15111511*******************************************************************/
    1512 REGF_NK_REC* regfio_fetch_subkey( REGF_FILE *file, REGF_NK_REC *nk )
     1512REGF_NK_REC* regfi_fetch_subkey( REGF_FILE *file, REGF_NK_REC *nk )
    15131513{
    15141514  REGF_NK_REC *subkey;
     
    15291529    return NULL;
    15301530  }
    1531        
     1531 
    15321532  nk_offset = nk->subkeys.hashes[nk->subkey_index].nk_off;
    15331533  if(!prs_set_offset(&hbin->ps,
  • trunk/src/reglookup.c

    r77 r78  
    216216    {
    217217      tmp_err = strerror(-ret_err);
    218       str_type = regfio_type_val2str(type);
     218      str_type = regfi_type_val2str(type);
    219219      *error_msg = (char*)malloc(65+strlen(str_type)+strlen(tmp_err)+1);
    220220      if(*error_msg == NULL)
     
    385385{
    386386  void_stack* ret_val;
    387   void_stack* rev_ret = void_stack_new(1024);
     387  void_stack* rev_ret = void_stack_new(REGF_MAX_DEPTH);
    388388  const char* cur = s;
    389389  char* next = NULL;
     
    405405      memcpy(copy, cur, next-cur);
    406406      copy[next-cur] = '\0';
    407       void_stack_push(rev_ret, copy);
     407      if(!void_stack_push(rev_ret, copy))
     408        bailOut(2, "ERROR: Registry maximum depth exceeded.\n");
    408409    }
    409410    cur = next+1;
     
    412413  {
    413414    copy = strdup(cur);
    414     void_stack_push(rev_ret, copy);
     415    if(!void_stack_push(rev_ret, copy))
     416      bailOut(2, "ERROR: Registry maximum depth exceeded.\n");
    415417  }
    416418
     
    541543              "warning returned: %s\n", prefix, quoted_name, conv_error);
    542544
    543   str_type = regfio_type_val2str(vk->type);
     545  str_type = regfi_type_val2str(vk->type);
    544546  if(print_security)
    545547  {
     
    597599  if(print_security)
    598600  {
    599     owner = regfio_get_owner(k->sec_desc->sec_desc);
    600     group = regfio_get_group(k->sec_desc->sec_desc);
    601     sacl = regfio_get_sacl(k->sec_desc->sec_desc);
    602     dacl = regfio_get_dacl(k->sec_desc->sec_desc);
     601    owner = regfi_get_owner(k->sec_desc->sec_desc);
     602    group = regfi_get_group(k->sec_desc->sec_desc);
     603    sacl = regfi_get_sacl(k->sec_desc->sec_desc);
     604    dacl = regfi_get_dacl(k->sec_desc->sec_desc);
    603605    if(owner == NULL)
    604606      owner = empty_str;
     
    636638  uint32 path_len = 0;
    637639  uint32 prefix_len = strlen(prefix);
    638   int key_type = regfio_type_str2val("KEY");
     640  int key_type = regfi_type_str2val("KEY");
    639641 
    640642  if((cur = (REGF_NK_REC*)void_stack_cur(nk_stack)) != NULL)
     
    672674    while((cur = (REGF_NK_REC*)void_stack_cur(nk_stack)) != NULL)
    673675    {
    674       if((sub = regfio_fetch_subkey(f, cur)) == NULL)
     676      if((sub = regfi_fetch_subkey(f, cur)) == NULL)
    675677      {
    676678        sub = void_stack_pop(nk_stack);
     
    684686      {
    685687        sub->subkey_index = 0;
    686         void_stack_push(nk_stack, sub);
     688        if(!void_stack_push(nk_stack, sub))
     689          bailOut(2, "ERROR: Registry maximum depth exceeded.\n");
    687690        path = stack2Path(nk_stack);
    688691        if(path != NULL)
     
    753756    found_cur = false;
    754757    while(!found_cur &&
    755           (sub = regfio_fetch_subkey(f, cur)) != NULL)
     758          (sub = regfi_fetch_subkey(f, cur)) != NULL)
    756759    {
    757760      if(strcasecmp(sub->keyname, cur_str) == 0)
    758761      {
    759762        cur = sub;
    760         void_stack_push(nk_stack, sub);
     763        if(!void_stack_push(nk_stack, sub))
     764          bailOut(2, "ERROR: Registry maximum depth exceeded.\n");
     765
    761766        found_cur = true;
    762767      }
     
    802807                    " of specified path.\n");
    803808
    804   while((sub = regfio_fetch_subkey(f, cur)) != NULL)
     809  while((sub = regfi_fetch_subkey(f, cur)) != NULL)
    805810  {
    806811    if(strcasecmp(sub->keyname, cur_str) == 0)
    807812    {
    808       sub_nk_stack = void_stack_new(1024);
    809       void_stack_push(sub_nk_stack, sub);
     813      sub_nk_stack = void_stack_new(REGF_MAX_DEPTH);
     814      if(!void_stack_push(sub_nk_stack, sub))
     815        bailOut(2, "ERROR: Registry maximum depth exceeded.\n");
    810816      prefix = stack2Path(nk_stack);
    811817      prefix_len = strlen(prefix);
     
    890896        bailOut(1, "ERROR: '-t' option requires parameter.\n");
    891897      }
    892       if((type_filter = regfio_type_str2val(argv[argi])) < 0)
     898      if((type_filter = regfi_type_str2val(argv[argi])) < 0)
    893899      {
    894900        fprintf(stderr, "ERROR: Invalid type specified: %s.\n", argv[argi]);
     
    917923    bailOut(2, "ERROR: Memory allocation problem.\n");
    918924
    919   f = regfio_open(registry_file);
     925  f = regfi_open(registry_file);
    920926  if(f == NULL)
    921927  {
     
    924930  }
    925931
    926   root = regfio_rootkey(f);
    927   nk_stack = void_stack_new(1024);
     932  root = regfi_rootkey(f);
     933  nk_stack = void_stack_new(REGF_MAX_DEPTH);
    928934
    929935  if(void_stack_push(nk_stack, root))
     
    950956  }
    951957  else
    952     bailOut(2, "ERROR: Memory allocation problem.\n");
     958    bailOut(2, "ERROR: Registry maximum depth exceeded.\n");
    953959
    954960  void_stack_destroy_deep(nk_stack);
    955   regfio_close(f);
     961  regfi_close(f);
    956962
    957963  return 0;
Note: See TracChangeset for help on using the changeset viewer.