Changeset 148 for trunk


Ignore:
Timestamp:
02/22/09 18:22:59 (15 years ago)
Author:
tim
Message:

integrated talloc into range_list

fixed some uninitialized structure values in the winsec library

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/range_list.h

    r122 r148  
    11/*
    2  * Copyright (C) 2008 Timothy D. Morgan
     2 * Copyright (C) 2008-2009 Timothy D. Morgan
    33 *
    44 * This program is free software; you can redistribute it and/or modify
     
    1818 */
    1919
     20#ifndef _RANGE_LIST_H
     21#define _RANGE_LIST_H
     22
    2023#include <stdlib.h>
    2124#include <stdbool.h>
    2225#include <stdint.h>
    2326#include <string.h>
    24 
    25 #ifndef _RANGE_LIST_H
    26 #define _RANGE_LIST_H
    27 
     27#include <math.h>
     28#include "talloc.h"
    2829
    2930typedef struct _range_list_element
  • trunk/include/winsec.h

    r147 r148  
    5454#define WINSEC_ACE_MIN_SIZE         16
    5555
    56 /* TODO: Fill in definitions of other flags */
    57 /* This means offsets contained in the descriptor are relative to the
    58  * descriptor's offset.  This had better be true in the registry.
     56/* XXX: Fill in definitions of other flags */
     57/* This self relative flag means offsets contained in the descriptor are relative
     58 * to the descriptor's offset.  This had better be true in the registry.
    5959 */
    6060#define WINSEC_DESC_SELF_RELATIVE   0x8000
     
    7070
    7171
    72 typedef struct _winsec_uuid 
     72typedef struct _winsec_uuid
    7373{
    7474       uint32 time_low;
  • trunk/lib/range_list.c

    r147 r148  
    1818 */
    1919
    20 #include <math.h>
    2120#include "range_list.h"
    2221
     
    2726#define RANGE_LIST_ALLOC_SIZE 256
    2827
    29 #if 0
     28#if 0 /* For debugging */
    3029#include <stdio.h>
    3130static void range_list_print(const range_list* rl)
     
    5352  if(rl->size == rl->elem_alloced)
    5453  {
    55     tmp = (range_list_element**)realloc(rl->elements,
    56                                         (rl->elem_alloced+RANGE_LIST_ALLOC_SIZE)
    57                                         * sizeof(range_list_element*));
     54    tmp = talloc_realloc(rl, rl->elements, range_list_element*,
     55                         (rl->elem_alloced+RANGE_LIST_ALLOC_SIZE));
    5856    if(tmp == NULL)
    5957      return false;
     
    125123  range_list* rl;
    126124
    127   rl = (range_list*)malloc(sizeof(range_list));
     125  rl = talloc(NULL, range_list);
    128126  if(rl == NULL)
    129127    return NULL;
    130128
    131   rl->elements = (range_list_element**)malloc(sizeof(range_list_element*)
    132                                               * RANGE_LIST_ALLOC_SIZE);
    133 
     129  rl->elements = talloc_array(rl, range_list_element*, RANGE_LIST_ALLOC_SIZE);
    134130  if(rl->elements == NULL)
    135131  {
    136     free(rl);
     132    talloc_free(rl);
    137133    return NULL;
    138134  }
     
    147143void range_list_free(range_list* rl)
    148144{
    149   uint32_t i;
    150 
    151145  if(rl == NULL)
    152146    return;
    153147
    154   for(i=0; i < rl->size; i++)
    155     free(rl->elements[i]);
    156 
    157   free(rl->elements);
    158   free(rl);
     148  talloc_free(rl);
    159149}
    160150
     
    201191    return false;
    202192
    203   elem = (range_list_element*)malloc(sizeof(range_list_element));
     193  elem = talloc(rl->elements, range_list_element);
    204194  if(elem == NULL)
    205195    return false;
     
    210200  if(!range_list_insert(rl, elem, insert_index))
    211201  {
    212     free(elem);
     202    talloc_free(elem);
    213203    return false;
    214204  }
     
    226216    return false;
    227217
    228   free(rl->elements[index]);
     218  talloc_free(rl->elements[index]);
    229219
    230220  /* Do the shuffle to the left. */
     
    237227  if(rl->size + 2 * RANGE_LIST_ALLOC_SIZE  < rl->elem_alloced)
    238228  {
    239     tmp = (range_list_element**)realloc(rl->elements,
    240                                         (rl->elem_alloced-2*RANGE_LIST_ALLOC_SIZE)
    241                                         * sizeof(range_list_element*));
     229    tmp = talloc_realloc(rl, rl->elements, range_list_element*,
     230                         (rl->elem_alloced-2*RANGE_LIST_ALLOC_SIZE));
    242231    if(tmp != NULL)
    243232    {
     
    305294    return false;
    306295
    307   new_elem = (range_list_element*)malloc(sizeof(range_list_element));
     296  new_elem = talloc(rl->elements, range_list_element);
    308297  if(new_elem == NULL)
    309298    return false;
     
    315304  if(!range_list_insert(rl, new_elem, index+1))
    316305  {
    317     free(new_elem);
     306    talloc_free(new_elem);
    318307    return false;
    319308  }
  • trunk/lib/regfi.c

    r147 r148  
    343343      {
    344344        ret_val = tmp_val;
    345         size += snprintf(ret_val+size, extra, "%s%s%c%s%c%s%c%s",
    346                          ace_delim,sid_str,
    347                          field_delim,type_str,
    348                          field_delim,perms_str,
    349                          field_delim,flags_str);
     345        size += sprintf(ret_val+size, "%s%s%c%s%c%s%c%s",
     346                        ace_delim,sid_str,
     347                        field_delim,type_str,
     348                        field_delim,perms_str,
     349                        field_delim,flags_str);
    350350        ace_delim = "|";
    351351      }
     
    12791279  {
    12801280    rla = range_list_add(rb->hbins, hbin->file_off, hbin->block_size, hbin);
     1281    if(rla)
     1282      talloc_steal(rb->hbins, hbin);
    12811283    hbin_off = hbin->file_off + hbin->block_size;
    12821284    hbin = regfi_parse_hbin(rb, hbin_off, true);
    12831285  }
    1284 
    12851286
    12861287  /* This secret isn't very secret, but we don't need a good one.  This
     
    13011302
    13021303
    1303 /*******************************************************************
    1304  *******************************************************************/
     1304/******************************************************************************
     1305 ******************************************************************************/
    13051306int regfi_close(REGFI_FILE *file)
    13061307{
    13071308  int fd;
    1308   uint32 i;
    13091309
    13101310  /* nothing to do if there is no open file */
     
    13141314  fd = file->fd;
    13151315  file->fd = -1;
    1316   for(i=0; i < range_list_size(file->hbins); i++)
    1317     free(range_list_get(file->hbins, i)->data);
     1316
    13181317  range_list_free(file->hbins);
    13191318
    1320  
    13211319  if(file->sk_cache != NULL)
    13221320    lru_cache_destroy(file->sk_cache);
     1321
    13231322  free(file);
    1324 
    13251323  return close(fd);
    13261324}
     
    13301328 * There should be only *one* root key in the registry file based
    13311329 * on my experience.  --jerry
    1332  *****************************************************************************/
     1330 ******************************************************************************/
    13331331REGFI_NK_REC* regfi_rootkey(REGFI_FILE *file)
    13341332{
     
    17911789
    17921790
    1793 /*******************************************************************
     1791/******************************************************************************
    17941792 * Given real file offset, read and parse the hbin at that location
    17951793 * along with it's associated cells.
    1796  *******************************************************************/
    1797 /* XXX: Need a way to return types of errors.
    1798  */
     1794 ******************************************************************************/
    17991795REGFI_HBIN* regfi_parse_hbin(REGFI_FILE* file, uint32 offset, bool strict)
    18001796{
     
    18251821  }
    18261822
    1827   if(!(hbin = (REGFI_HBIN*)zalloc(sizeof(REGFI_HBIN))))
     1823  hbin = talloc(NULL, REGFI_HBIN);
     1824  if(hbin == NULL)
    18281825    return NULL;
    18291826  hbin->file_off = offset;
     
    18361833                      " 0x%.8X.", hbin->magic[0], hbin->magic[1],
    18371834                      hbin->magic[2], hbin->magic[3], offset);
    1838     free(hbin);
     1835    talloc_free(hbin);
    18391836    return NULL;
    18401837  }
     
    18581855                      " or runs off the end of the file"
    18591856                      " while parsing hbin at offset 0x%.8X.", offset);
    1860     free(hbin);
     1857    talloc_free(hbin);
    18611858    return NULL;
    18621859  }
  • trunk/lib/winsec.c

    r147 r148  
    5555  if (buf == NULL || buf_len <  WINSEC_DESC_HEADER_SIZE)
    5656    return NULL;
    57   /*
    58   if((ret_val = (WINSEC_DESC*)zalloc(sizeof(WINSEC_DESC))) == NULL)
    59     return NULL;
    60   */
     57
    6158  if((ret_val = talloc(talloc_ctx, WINSEC_DESC)) == NULL)
    6259    return NULL;
     
    8683  }
    8784
    88   if(ret_val->off_owner_sid != 0)
     85  if(ret_val->off_owner_sid == 0)
     86    ret_val->owner_sid = NULL;
     87  else
    8988  {
    9089    ret_val->owner_sid = winsec_parse_dom_sid(ret_val,
     
    9897  }
    9998
    100   if (ret_val->off_grp_sid != 0)
     99  if(ret_val->off_grp_sid == 0)
     100    ret_val->grp_sid = NULL;
     101  else
    101102  {
    102103    ret_val->grp_sid = winsec_parse_dom_sid(ret_val, buf + ret_val->off_grp_sid,
     
    109110  }
    110111
    111   if ((ret_val->control & WINSEC_DESC_SACL_PRESENT) && ret_val->off_sacl)
     112  if((ret_val->control & WINSEC_DESC_SACL_PRESENT) && ret_val->off_sacl)
    112113  {
    113114    ret_val->sacl = winsec_parse_acl(ret_val, buf + ret_val->off_sacl,
     
    119120    }
    120121  }
    121 
    122   if ((ret_val->control & WINSEC_DESC_DACL_PRESENT) && ret_val->off_dacl != 0)
     122  else
     123    ret_val->sacl = NULL;
     124
     125  if((ret_val->control & WINSEC_DESC_DACL_PRESENT) && ret_val->off_dacl != 0)
    123126  {
    124127    ret_val->dacl = winsec_parse_acl(ret_val, buf + ret_val->off_dacl,
     
    130133    }
    131134  }
     135  else
     136    ret_val->dacl = NULL;
    132137
    133138  return ret_val;
     
    150155  if (buf == NULL || buf_len < 8)
    151156    return NULL;
    152   /*
    153   if((ret_val = (WINSEC_ACL*)zalloc(sizeof(WINSEC_ACL))) == NULL)
    154     return NULL;
    155   */
     157
    156158  if((ret_val = talloc(talloc_ctx, WINSEC_ACL)) == NULL)
    157159    return NULL;
     
    175177   * (allow no access).
    176178   */
    177   /*  if((ret_val->aces = (WINSEC_ACE**)zcalloc(sizeof(WINSEC_ACE*),
    178                                            ret_val->num_aces+1)) == NULL)
    179   */
    180179  if((ret_val->aces = talloc_array(ret_val, WINSEC_ACE*,
    181180                                   ret_val->num_aces+1)) == NULL)
     
    203202    }
    204203  }
     204  ret_val->aces[ret_val->num_aces] = NULL;
    205205
    206206  return ret_val;
     
    219219  if(buf == NULL || buf_len < WINSEC_ACE_MIN_SIZE)
    220220    return NULL;
    221 
    222   /*  if((ret_val = (WINSEC_ACE*)zalloc(sizeof(WINSEC_ACE))) == NULL)*/
    223221
    224222  if((ret_val = talloc(talloc_ctx, WINSEC_ACE)) == NULL)
     
    249247      offset += sizeof(WINSEC_UUID);
    250248    }
     249    else
     250      ret_val->obj_guid = NULL;
    251251
    252252    if(ret_val->obj_flags & WINSEC_ACE_OBJECT_INHERITED_PRESENT)
     
    261261      offset += sizeof(WINSEC_UUID);
    262262    }
     263    else
     264      ret_val->inh_guid = NULL;
    263265  }
    264266
     
    322324    return false;
    323325
    324   /* if((ret_val = (WINSEC_UUID*)zalloc(sizeof(WINSEC_UUID))) == NULL)*/
    325326  if((ret_val = talloc(talloc_ctx, WINSEC_UUID)) == NULL)
    326327    return NULL;
  • trunk/src/reglookup-recover.c

    r147 r148  
    2323#include <stdlib.h>
    2424
     25#include "talloc.h"
    2526#include "regfi.h"
    2627#include "range_list.h"
     
    684685          return 20;
    685686        }
     687        talloc_steal(unalloc_sks, sk);
    686688        j+=sk->cell_size-8;
    687689      }
     
    908910  }
    909911
     912  range_list_free(unalloc_cells);
     913  range_list_free(unalloc_keys);
     914  range_list_free(unalloc_linked_values);
     915  range_list_free(unalloc_values);
     916  range_list_free(unalloc_sks);
     917
    910918  return 0;
    911919}
Note: See TracChangeset for help on using the changeset viewer.