Changeset 84


Ignore:
Timestamp:
01/19/07 09:52:25 (18 years ago)
Author:
tim
Message:

rearranged structure contents to reduce fragmentation on 64 bit systems.

make regfi interface return const structures to help enforce separation

removed a little cruft from some parsing functions

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/regfi.h

    r81 r84  
    11/*
    22 * Branched from Samba project, Subversion repository version #6903:
    3  *   http://websvn.samba.org/cgi-bin/viewcvs.cgi/trunk/source/include/regfio.h
     3 *   http://viewcvs.samba.org/cgi-bin/viewcvs.cgi/trunk/source/include/regfio.h?rev=6903&view=auto
    44 *
    55 * Unix SMB/CIFS implementation.
     
    109109  uint32 free_off;       /* offset to free space within the hbin record */
    110110  uint32 free_size;      /* amount of data left in the block */
    111   int    ref_count;      /* how many active records are pointing to this
     111  uint32 ref_count;      /* how many active records are pointing to this
    112112                          * block (not used currently)
    113113                          */
    114        
    115   uint8  header[HBIN_HDR_SIZE]; /* "hbin" */
     114 
    116115  uint32 first_hbin_off; /* offset from first hbin block */
    117116  uint32 block_size;     /* block size of this block is
    118117                          * usually a multiple of 4096Kb
    119118                          */
     119  uint8  header[HBIN_HDR_SIZE]; /* "hbin" */
    120120  prs_struct ps;         /* data */
    121121  bool dirty;            /* has this hbin block been modified? */
     
    129129
    130130typedef struct {
    131   REGF_HBIN *hbin;       /* pointer to HBIN record (in memory) containing
     131  REGF_HBIN* hbin;       /* pointer to HBIN record (in memory) containing
    132132                          * this nk record
    133133                          */
     134  REGF_HASH_REC* hashes;
    134135  uint32 hbin_off;       /* offset from beginning of this hbin block */
    135136  uint32 rec_size;       /* ((start_offset - end_offset) & 0xfffffff8) */
     
    137138  uint8 header[REC_HDR_SIZE];
    138139  uint16 num_keys;
    139   REGF_HASH_REC *hashes;
    140140} REGF_LF_REC;
    141141
     
    143143
    144144typedef struct {
    145   REGF_HBIN *hbin;      /* pointer to HBIN record (in memory) containing
     145  REGF_HBIN* hbin;      /* pointer to HBIN record (in memory) containing
    146146                         * this nk record
    147147                         */
     148  char*  valuename;
     149  uint8* data;
    148150  uint32 hbin_off;      /* offset from beginning of this hbin block */
    149151  uint32 rec_size;      /* ((start_offset - end_offset) & 0xfffffff8) */
    150152  uint32 rec_off;       /* offset stored in the value list */
    151153 
    152   uint8  header[REC_HDR_SIZE];
    153   char*  valuename;
    154154  uint32 data_size;
    155155  uint32 data_off;
    156   uint8* data;
    157156  uint32 type;
     157  uint8  header[REC_HDR_SIZE];
    158158  uint16 flag;
    159159} REGF_VK_REC;
     
    164164
    165165typedef struct _regf_sk_rec {
    166   struct _regf_sk_rec *next, *prev;
    167   REGF_HBIN *hbin;      /* pointer to HBIN record (in memory) containing
     166  struct _regf_sk_rec* next;
     167  struct _regf_sk_rec* prev;
     168  REGF_HBIN* hbin;      /* pointer to HBIN record (in memory) containing
    168169                         * this nk record
    169170                         */
     171  SEC_DESC* sec_desc;
    170172  uint32 hbin_off;      /* offset from beginning of this hbin block */
    171173  uint32 rec_size;      /* ((start_offset - end_offset) & 0xfffffff8) */
     
    175177                         */
    176178 
    177   uint8  header[REC_HDR_SIZE];
    178179  uint32 prev_sk_off;
    179180  uint32 next_sk_off;
    180181  uint32 ref_count;
    181182  uint32 size;
    182   SEC_DESC *sec_desc;
     183  uint8  header[REC_HDR_SIZE];
    183184} REGF_SK_REC;
    184185
     
    186187/* Key Name */
    187188typedef struct {
     189  uint32 hbin_off;      /* offset from beginning of this hbin block */
     190  uint32 rec_size;      /* ((start_offset - end_offset) & 0xfffffff8) */
    188191  REGF_HBIN *hbin;      /* pointer to HBIN record (in memory) containing
    189                          * this nk record
    190                          */
    191   uint32 hbin_off;      /* offset from beginning of this hbin block */
    192   /*uint32 subkey_index;*/      /* index to next subkey record to return */
    193   uint32 rec_size;      /* ((start_offset - end_offset) & 0xfffffff8) */
     192                         * this nk record */
     193
     194  /* link in the other records here */
     195  REGF_VK_REC* values;
     196  REGF_SK_REC* sec_desc;
     197  REGF_LF_REC subkeys;
    194198 
    195199  /* header information */
     200  /* XXX: should we be looking for types other than the root key type? */
     201  uint16 key_type;     
    196202  uint8  header[REC_HDR_SIZE];
    197   uint16 key_type;
    198203  NTTIME mtime;
     204  char* classname;
     205  char* keyname;
    199206  uint32 parent_off;    /* back pointer in registry hive */
    200207  uint32 classname_off;
    201   char *classname;
    202   char *keyname;
    203208 
    204209  /* max lengths */
     
    218223  uint32 sk_off;        /* offset to SK record */
    219224 
    220   /* link in the other records here */
    221   REGF_LF_REC subkeys;
    222   REGF_VK_REC* values;
    223   REGF_SK_REC* sec_desc;
    224        
    225225} REGF_NK_REC;
    226226
     
    231231  int fd;         /* file descriptor */
    232232  int open_flags; /* flags passed to the open() call */
    233   void *mem_ctx;  /* memory context for run-time file access information */
    234   REGF_HBIN *block_list; /* list of open hbin blocks */
     233  void* mem_ctx;  /* memory context for run-time file access information */
     234  REGF_HBIN* block_list; /* list of open hbin blocks */
    235235 
    236236  /* file format information */
     237  REGF_SK_REC* sec_desc_list;   /* list of security descriptors referenced
     238                                 * by NK records
     239                                 */
    237240 
    238241  uint8  header[REGF_HDR_SIZE]; /* "regf" */
     242  NTTIME mtime;
    239243  uint32 data_offset;           /* offset to record in the first (or any?)
    240244                                 * hbin block
     
    242246  uint32 last_block;            /* offset to last hbin block in file */
    243247  uint32 checksum;              /* XOR of bytes 0x0000 - 0x01FB */
    244   NTTIME mtime;
    245  
    246   REGF_SK_REC *sec_desc_list;   /* list of security descriptors referenced
    247                                  * by NK records
    248                                  */
    249248 
    250249  /* unknowns */
     
    279278/* Function Declarations */
    280279
    281 const char*   regfi_type_val2str(unsigned int val);
    282 int           regfi_type_str2val(const char* str);
    283 
    284 char*         regfi_get_sacl(SEC_DESC* sec_desc);
    285 char*         regfi_get_dacl(SEC_DESC* sec_desc);
    286 char*         regfi_get_owner(SEC_DESC* sec_desc);
    287 char*         regfi_get_group(SEC_DESC* sec_desc);
    288 
    289 REGF_FILE*    regfi_open(const char* filename);
    290 int           regfi_close(REGF_FILE* r);
    291 
    292 REGF_NK_REC*  regfi_rootkey(REGF_FILE* file);
    293 /* REGF_NK_REC*  regfi_fetch_subkey( REGF_FILE* file, REGF_NK_REC* nk ); */
    294 
    295 void            regfi_key_free(REGF_NK_REC* nk);
    296 
    297 REGFI_ITERATOR* regfi_iterator_new(REGF_FILE* fh);
    298 void            regfi_iterator_free(REGFI_ITERATOR* i);
    299 bool            regfi_iterator_down(REGFI_ITERATOR* i);
    300 bool            regfi_iterator_up(REGFI_ITERATOR* i);
    301 bool            regfi_iterator_to_root(REGFI_ITERATOR* i);
    302 
    303 bool            regfi_iterator_find_subkey(REGFI_ITERATOR* i, const char* subkey_name);
    304 bool            regfi_iterator_walk_path(REGFI_ITERATOR* i, const char** path);
    305 /* XXX: these which return NK and VK records should return them as consts */
    306 REGF_NK_REC*    regfi_iterator_cur_key(REGFI_ITERATOR* i);
    307 REGF_NK_REC*    regfi_iterator_first_subkey(REGFI_ITERATOR* i);
    308 REGF_NK_REC*    regfi_iterator_cur_subkey(REGFI_ITERATOR* i);
    309 REGF_NK_REC*    regfi_iterator_next_subkey(REGFI_ITERATOR* i);
    310 
    311 bool            regfi_iterator_find_value(REGFI_ITERATOR* i, const char* value_name);
    312 REGF_VK_REC*    regfi_iterator_first_value(REGFI_ITERATOR* i);
    313 REGF_VK_REC*    regfi_iterator_cur_value(REGFI_ITERATOR* i);
    314 REGF_VK_REC*    regfi_iterator_next_value(REGFI_ITERATOR* i);
     280const char*           regfi_type_val2str(unsigned int val);
     281int                   regfi_type_str2val(const char* str);
     282
     283char*                 regfi_get_sacl(SEC_DESC* sec_desc);
     284char*                 regfi_get_dacl(SEC_DESC* sec_desc);
     285char*                 regfi_get_owner(SEC_DESC* sec_desc);
     286char*                 regfi_get_group(SEC_DESC* sec_desc);
     287
     288REGF_FILE*            regfi_open(const char* filename);
     289int                   regfi_close(REGF_FILE* r);
     290
     291REGFI_ITERATOR*       regfi_iterator_new(REGF_FILE* fh);
     292void                  regfi_iterator_free(REGFI_ITERATOR* i);
     293bool                  regfi_iterator_down(REGFI_ITERATOR* i);
     294bool                  regfi_iterator_up(REGFI_ITERATOR* i);
     295bool                  regfi_iterator_to_root(REGFI_ITERATOR* i);
     296
     297bool                  regfi_iterator_find_subkey(REGFI_ITERATOR* i,
     298                                                 const char* subkey_name);
     299bool                  regfi_iterator_walk_path(REGFI_ITERATOR* i,
     300                                               const char** path);
     301const REGF_NK_REC*    regfi_iterator_cur_key(REGFI_ITERATOR* i);
     302const REGF_NK_REC*    regfi_iterator_first_subkey(REGFI_ITERATOR* i);
     303const REGF_NK_REC*    regfi_iterator_cur_subkey(REGFI_ITERATOR* i);
     304const REGF_NK_REC*    regfi_iterator_next_subkey(REGFI_ITERATOR* i);
     305
     306bool                  regfi_iterator_find_value(REGFI_ITERATOR* i,
     307                                                const char* value_name);
     308const REGF_VK_REC*    regfi_iterator_first_value(REGFI_ITERATOR* i);
     309const REGF_VK_REC*    regfi_iterator_cur_value(REGFI_ITERATOR* i);
     310const REGF_VK_REC*    regfi_iterator_next_value(REGFI_ITERATOR* i);
     311
     312
     313/* Private Functions */
     314REGF_NK_REC*          regfi_rootkey(REGF_FILE* file);
     315void                  regfi_key_free(REGF_NK_REC* nk);
     316
    315317
    316318#endif  /* _REGFI_H */
  • trunk/include/smb_deps.h

    r68 r84  
    151151#define TIME_FIXUP_CONSTANT (369.0*365.25*24*60*60-(3.0*24*60*60+6.0*60*60))
    152152
    153 void unix_to_nt_time(NTTIME *nt, time_t t);
    154 time_t nt_time_to_unix(NTTIME *nt);
     153void unix_to_nt_time(NTTIME* nt, time_t t);
     154time_t nt_time_to_unix(const NTTIME* nt);
    155155
    156156/* End of stuff from lib/time.c */
     
    169169char *prs_mem_get(prs_struct *ps, uint32 extra_size);
    170170bool prs_uint32(const char *name, prs_struct *ps, int depth, uint32 *data32);
    171 bool prs_uint32s(bool charmode, const char *name, prs_struct *ps,
     171bool prs_uint32s(const char *name, prs_struct *ps,
    172172                 int depth, uint32 *data32s, int len);
    173173bool prs_uint16(const char *name, prs_struct *ps, int depth, uint16 *data16);
     
    177177                     uint16 *data16, uint32 ptr_uint16, uint32 start_offset);
    178178bool prs_uint8(const char *name, prs_struct *ps, int depth, uint8 *data8);
    179 bool prs_uint8s(bool charmode, const char *name, prs_struct *ps, int depth,
     179bool prs_uint8s(const char *name, prs_struct *ps, int depth,
    180180                uint8* data8s, int len);
    181181bool prs_set_offset(prs_struct *ps, uint32 offset);
  • trunk/lib/regfi.c

    r82 r84  
    11/*
    22 * Branched from Samba project Subversion repository, version #7470:
    3  *   http://websvn.samba.org/cgi-bin/viewcvs.cgi/trunk/source/registry/regfio.c
     3 *   http://viewcvs.samba.org/cgi-bin/viewcvs.cgi/trunk/source/registry/regfio.c?rev=7470&view=auto
    44 *
    55 * Unix SMB/CIFS implementation.
     
    437437  depth++;
    438438       
    439   if(!prs_uint8s(true, "header", ps, depth, file->header, sizeof(file->header)))
     439  if(!prs_uint8s("header", ps, depth, file->header, sizeof(file->header)))
    440440    return false;
    441441       
     
    499499  depth++;
    500500       
    501   if(!prs_uint8s(true, "header", ps, depth, hbin->header, sizeof(hbin->header)))
     501  if(!prs_uint8s("header", ps, depth, hbin->header, sizeof(hbin->header)))
    502502    return false;
    503503
     
    547547    return false;
    548548       
    549   if (!prs_uint8s(true, "header", ps, depth, nk->header, sizeof(nk->header)))
     549  if (!prs_uint8s("header", ps, depth, nk->header, sizeof(nk->header)))
    550550    return false;
    551551               
     
    610610        return false;
    611611
    612     if(!prs_uint8s(true, "name", ps, depth, (uint8*)nk->keyname, name_length))
     612    if(!prs_uint8s("name", ps, depth, (uint8*)nk->keyname, name_length))
    613613      return false;
    614614
     
    848848  if ( !prs_uint32( "nk_off", ps, depth, &hash->nk_off ))
    849849    return false;
    850   if ( !prs_uint8s( true, "keycheck", ps, depth, hash->keycheck, sizeof( hash->keycheck )) )
     850  if ( !prs_uint8s("keycheck", ps, depth, hash->keycheck, sizeof( hash->keycheck )) )
    851851    return false;
    852852       
     
    884884    return false;
    885885
    886   if(!prs_uint8s(true, "header", &hbin->ps, depth,
     886  if(!prs_uint8s("header", &hbin->ps, depth,
    887887                 lf->header, sizeof(lf->header)))
    888888    return false;
     
    938938    return false;
    939939
    940   if (!prs_uint8s(true, "header", ps, depth, sk->header, sizeof(sk->header)))
     940  if (!prs_uint8s("header", ps, depth, sk->header, sizeof(sk->header)))
    941941    return false;
    942942  if ( !prs_uint16( "tag", ps, depth, &tag))
     
    990990    return false;
    991991
    992   if ( !prs_uint8s( true, "header", ps, depth, vk->header, sizeof( vk->header )) )
     992  if ( !prs_uint8s("header", ps, depth, vk->header, sizeof( vk->header )) )
    993993    return false;
    994994
     
    10191019        return false;
    10201020    }
    1021     if ( !prs_uint8s(true, "name", ps, depth,
     1021    if ( !prs_uint8s("name", ps, depth,
    10221022                     (uint8*)vk->valuename, name_length) )
    10231023      return false;
     
    10301030  if ( vk->data_size != 0 )
    10311031  {
    1032     bool charmode = false;
    1033 
    1034     if ( (vk->type == REG_SZ) || (vk->type == REG_MULTI_SZ) )
    1035       charmode = true;
    1036 
    10371032    /* the data is stored in the offset if the size <= 4 */
    10381033    if ( !(vk->data_size & VK_DATA_IN_OFFSET) )
     
    10671062      if ( !prs_uint32( "data_rec_size", &hblock->ps, depth, &data_rec_size ))
    10681063        return false;
    1069       if(!prs_uint8s(charmode, "data", &hblock->ps, depth,
     1064      if(!prs_uint8s("data", &hblock->ps, depth,
    10701065                     vk->data, vk->data_size))
    10711066        return false;
     
    13231318    if ( !prs_uint32( "record_size", ps, 0, &record_size ) )
    13241319      return false;
    1325     if ( !prs_uint8s( true, "header", ps, 0, header, REC_HDR_SIZE ) )
     1320    if ( !prs_uint8s("header", ps, 0, header, REC_HDR_SIZE ) )
    13261321      return false;
    13271322
     
    16001595    return false;
    16011596
    1602   subkey = regfi_iterator_cur_subkey(i);
     1597  subkey = (REGF_NK_REC*)regfi_iterator_cur_subkey(i);
    16031598  if(subkey == NULL)
    16041599  {
     
    16671662
    16681663  /* XXX: this alloc/free of each sub key might be a bit excessive */
    1669   subkey = regfi_iterator_first_subkey(i);
     1664  subkey = (REGF_NK_REC*)regfi_iterator_first_subkey(i);
    16701665  while((subkey != NULL) && (found == false))
    16711666  {
     
    16761671    {
    16771672      regfi_key_free(subkey);
    1678       subkey = regfi_iterator_next_subkey(i);
     1673      subkey = (REGF_NK_REC*)regfi_iterator_next_subkey(i);
    16791674    }
    16801675  }
     
    17181713/******************************************************************************
    17191714 *****************************************************************************/
    1720 REGF_NK_REC* regfi_iterator_cur_key(REGFI_ITERATOR* i)
     1715const REGF_NK_REC* regfi_iterator_cur_key(REGFI_ITERATOR* i)
    17211716{
    17221717  return i->cur_key;
     
    17261721/******************************************************************************
    17271722 *****************************************************************************/
    1728 REGF_NK_REC* regfi_iterator_first_subkey(REGFI_ITERATOR* i)
     1723const REGF_NK_REC* regfi_iterator_first_subkey(REGFI_ITERATOR* i)
    17291724{
    17301725  i->cur_subkey = 0;
     
    17351730/******************************************************************************
    17361731 *****************************************************************************/
    1737 REGF_NK_REC* regfi_iterator_cur_subkey(REGFI_ITERATOR* i)
     1732const REGF_NK_REC* regfi_iterator_cur_subkey(REGFI_ITERATOR* i)
    17381733{
    17391734  REGF_NK_REC* subkey;
     
    17781773 *****************************************************************************/
    17791774/* XXX: some way of indicating reason for failure should be added. */
    1780 REGF_NK_REC* regfi_iterator_next_subkey(REGFI_ITERATOR* i)
    1781 {
    1782   REGF_NK_REC* subkey;
     1775const REGF_NK_REC* regfi_iterator_next_subkey(REGFI_ITERATOR* i)
     1776{
     1777  const REGF_NK_REC* subkey;
    17831778
    17841779  i->cur_subkey++;
     
    17961791bool regfi_iterator_find_value(REGFI_ITERATOR* i, const char* value_name)
    17971792{
    1798   REGF_VK_REC* cur;
     1793  const REGF_VK_REC* cur;
    17991794  bool found = false;
    18001795
     
    18231818/******************************************************************************
    18241819 *****************************************************************************/
    1825 REGF_VK_REC* regfi_iterator_first_value(REGFI_ITERATOR* i)
     1820const REGF_VK_REC* regfi_iterator_first_value(REGFI_ITERATOR* i)
    18261821{
    18271822  i->cur_value = 0;
     
    18321827/******************************************************************************
    18331828 *****************************************************************************/
    1834 REGF_VK_REC* regfi_iterator_cur_value(REGFI_ITERATOR* i)
     1829const REGF_VK_REC* regfi_iterator_cur_value(REGFI_ITERATOR* i)
    18351830{
    18361831  REGF_VK_REC* ret_val = NULL;
     
    18441839/******************************************************************************
    18451840 *****************************************************************************/
    1846 REGF_VK_REC* regfi_iterator_next_value(REGFI_ITERATOR* i)
    1847 {
    1848   REGF_VK_REC* ret_val;
     1841const REGF_VK_REC* regfi_iterator_next_value(REGFI_ITERATOR* i)
     1842{
     1843  const REGF_VK_REC* ret_val;
    18491844
    18501845  i->cur_value++;
  • trunk/lib/smb_deps.c

    r65 r84  
    101101 converts this to real GMT.
    102102****************************************************************************/
    103 time_t nt_time_to_unix(NTTIME *nt)
     103time_t nt_time_to_unix(const NTTIME* nt)
    104104{
    105105  double d;
     
    316316 Stream an array of uint32s. Length is number of uint32s.
    317317 ********************************************************************/
    318 bool prs_uint32s(bool charmode, const char *name, prs_struct *ps,
     318bool prs_uint32s(const char *name, prs_struct *ps,
    319319                 int depth, uint32 *data32s, int len)
    320320{
     
    462462 Stream an array of uint8s. Length is number of uint8s.
    463463 ********************************************************************/
    464 bool prs_uint8s(bool charmode, const char *name, prs_struct *ps, int depth,
     464bool prs_uint8s(const char *name, prs_struct *ps, int depth,
    465465                uint8* data8s, int len)
    466466{
     
    526526    return false;
    527527 
    528   if(!prs_uint8s (false, "data   ", ps, depth,
     528  if(!prs_uint8s ("data   ", ps, depth,
    529529                  uuid->clock_seq, sizeof(uuid->clock_seq)))
    530530    return false;
    531531
    532   if(!prs_uint8s (false, "data   ", ps, depth, uuid->node, sizeof(uuid->node)))
     532  if(!prs_uint8s ("data   ", ps, depth, uuid->node, sizeof(uuid->node)))
    533533    return false;
    534534 
     
    587587    sid->num_auths = MAXSUBAUTHS;
    588588
    589   if(!prs_uint32s(false, "sub_auths ", ps, depth,
     589  if(!prs_uint32s("sub_auths ", ps, depth,
    590590                  sid->sub_auths, sid->num_auths))
    591591  { return false; }
  • trunk/src/reglookup.c

    r83 r84  
    524524
    525525
    526 void printValue(REGF_VK_REC* vk, char* prefix)
     526void printValue(const REGF_VK_REC* vk, char* prefix)
    527527{
    528528  char* quoted_value = NULL;
     
    534534
    535535  /* Thanks Microsoft for making this process so straight-forward!!! */
     536  /* XXX: this logic should be abstracted  and pushed into the regfi
     537   *      interface.  This includes the size limits.
     538   */
    536539  size = (vk->data_size & ~VK_DATA_IN_OFFSET);
    537540  if(vk->data_size & VK_DATA_IN_OFFSET)
     
    618621void printValueList(REGFI_ITERATOR* i, char* prefix)
    619622{
    620   REGF_VK_REC* value;
     623  const REGF_VK_REC* value;
    621624
    622625  value = regfi_iterator_first_value(i);
     
    630633
    631634
    632 void printKey(REGF_NK_REC* k, char* full_path)
     635void printKey(const REGF_NK_REC* k, char* full_path)
    633636{
    634637  static char empty_str[1] = "";
     
    679682void printKeyTree(REGFI_ITERATOR* iter)
    680683{
    681   REGF_NK_REC* root = NULL;
    682   REGF_NK_REC* cur = NULL;
    683   REGF_NK_REC* sub = NULL;
     684  const REGF_NK_REC* root = NULL;
     685  const REGF_NK_REC* cur = NULL;
     686  const REGF_NK_REC* sub = NULL;
    684687  char* path = NULL;
    685688  int key_type = regfi_type_str2val("KEY");
     
    750753int retrievePath(REGFI_ITERATOR* iter, char** path)
    751754{
    752   REGF_VK_REC* value;
     755  const REGF_VK_REC* value;
    753756  char* tmp_path_joined;
    754757  const char** tmp_path;
Note: See TracChangeset for help on using the changeset viewer.