- Timestamp:
- 02/22/09 14:31:52 (16 years ago)
- Location:
- trunk/lib
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Makefile
r132 r147 3 3 ################################################################################ 4 4 5 FILES=regfi.o smb_deps.o winsec.o void_stack.o range_list.o lru_cache.o 5 FILES=regfi.o smb_deps.o winsec.o void_stack.o range_list.o lru_cache.o talloc.o 6 6 7 7 all: $(FILES) … … 25 25 $(CC) $(CFLAGS) $(OPTS) $(INC) -c -o $@ lru_cache.c 26 26 27 talloc.o: talloc.c 28 $(CC) $(CFLAGS) $(OPTS) $(INC) -c -o $@ talloc.c 29 27 30 clean: 28 31 rm -f $(FILES) -
trunk/lib/lru_cache.c
r146 r147 1 1 /* 2 * Copyright (C) 2008 Timothy D. Morgan2 * Copyright (C) 2008-2009 Timothy D. Morgan 3 3 * 4 4 * This program is free software; you can redistribute it and/or modify … … 18 18 */ 19 19 20 #include " ../include/lru_cache.h"20 #include "lru_cache.h" 21 21 22 22 … … 97 97 #endif 98 98 99 lru_cache* lru_cache_create(uint32_t max_keys, uint32_t secret, bool free_data) 99 100 lru_cache* lru_cache_create(uint32_t max_keys, uint32_t secret) 101 { 102 return lru_cache_create_ctx(NULL, max_keys, secret, false); 103 } 104 105 106 lru_cache* lru_cache_create_ctx(void* talloc_ctx, uint32_t max_keys, 107 uint32_t secret, bool talloc_data) 100 108 { 101 109 lru_cache* ret_val; 102 110 103 ret_val = (lru_cache*)malloc(sizeof(lru_cache));111 ret_val = talloc(talloc_ctx, lru_cache); 104 112 if(ret_val == NULL) 105 113 return NULL; … … 114 122 } 115 123 116 ret_val->table 117 = (lru_cache_element**)malloc(sizeof(lru_cache_element*) 118 * ret_val->num_buckets); 124 ret_val->table = talloc_array(ret_val, 125 lru_cache_element*, ret_val->num_buckets); 119 126 if(ret_val->table == NULL) 120 127 { 121 free(ret_val);128 talloc_free(ret_val); 122 129 return NULL; 123 130 } … … 127 134 ret_val->max_keys = max_keys; 128 135 ret_val->secret = secret; 129 ret_val-> free_data = free_data;136 ret_val->talloc_data = talloc_data; 130 137 ret_val->num_keys = 0; 131 138 memset(ret_val->table, 0, ret_val->num_buckets*sizeof(lru_cache_element*)); … … 137 144 void lru_cache_destroy(lru_cache* ht) 138 145 { 139 lru_cache_element* cur;140 lru_cache_element* last = NULL;141 142 for(cur=ht->oldest; cur != NULL; last=cur,cur=cur->newer)143 {144 if(last != NULL)145 {146 if(ht->free_data)147 free(last->data);148 free(last->index);149 free(last);150 }151 }152 free(ht->table);153 146 ht->secret = 0; 154 free(ht);147 talloc_free(ht); 155 148 } 156 149 … … 179 172 * so remove it from the list for now. 180 173 */ 181 if(ht-> free_data)182 free(e->data);174 if(ht->talloc_data) 175 talloc_free(e->data); 183 176 184 177 if(e->newer == NULL) … … 226 219 e->next = NULL; 227 220 228 if(ht-> free_data)229 free(e->data);230 231 tmp_index = realloc(e->index, index_len);221 if(ht->talloc_data) 222 talloc_free(e->data); 223 224 tmp_index = talloc_realloc_size(e, e->index, index_len); 232 225 if(tmp_index == NULL) 233 226 { 234 free(e->index); 235 free(e); 227 talloc_free(e); 236 228 return false; 237 229 } … … 242 234 { /* Brand new element because we have room to spare. */ 243 235 244 e = (lru_cache_element*)malloc(sizeof(lru_cache_element));236 e = talloc(ht->table, lru_cache_element); 245 237 if(e == NULL) 246 238 return false; 247 239 248 e->index = malloc(index_len);240 e->index = talloc_size(e, index_len); 249 241 if(e->index == NULL) 250 242 { 251 free(e);243 talloc_free(e); 252 244 return false; 253 245 } … … 264 256 } 265 257 e->data = data; 258 if(ht->talloc_data) 259 talloc_steal(e, e->data); 266 260 267 261 /* Finally, let's insert the element to the newest position in the LRU list.*/ … … 336 330 return false; 337 331 338 if(ht->free_data)339 free(cur->data);340 341 332 /* Detach from list */ 342 333 if(cur->newer == NULL) … … 356 347 last->next = cur->next; 357 348 358 free(cur->index); 359 free(cur); 349 talloc_free(cur); 360 350 361 351 /* Removing entry, decrement counters. */ -
trunk/lib/range_list.c
r145 r147 1 1 /* 2 * Copyright (C) 2008 Timothy D. Morgan2 * Copyright (C) 2008-2009 Timothy D. Morgan 3 3 * 4 4 * This program is free software; you can redistribute it and/or modify … … 19 19 20 20 #include <math.h> 21 #include " ../include/range_list.h"21 #include "range_list.h" 22 22 23 23 -
trunk/lib/regfi.c
r146 r147 24 24 */ 25 25 26 #include " ../include/regfi.h"26 #include "regfi.h" 27 27 28 28 … … 762 762 763 763 764 /******************************************************************* 765 *******************************************************************/ 766 REGFI_SK_REC* regfi_parse_sk(REGFI_FILE* file, uint32 offset, uint32 max_size, bool strict) 764 /****************************************************************************** 765 * 766 ******************************************************************************/ 767 REGFI_SK_REC* regfi_parse_sk(REGFI_FILE* file, uint32 offset, uint32 max_size, 768 bool strict) 767 769 { 768 770 REGFI_SK_REC* ret_val; 769 uint8* sec_desc_buf ;771 uint8* sec_desc_buf = NULL; 770 772 uint32 cell_length, length; 771 /*prs_struct ps;*/772 773 uint8 sk_header[REGFI_SK_MIN_LENGTH]; 773 774 bool unalloc = false; … … 788 789 } 789 790 790 ret_val = (REGFI_SK_REC*)zalloc(sizeof(REGFI_SK_REC)); 791 /* ret_val = (REGFI_SK_REC*)zalloc(sizeof(REGFI_SK_REC));*/ 792 ret_val = talloc(NULL, REGFI_SK_REC); 791 793 if(ret_val == NULL) 792 794 return NULL; … … 805 807 regfi_add_message(file, REGFI_MSG_WARN, "Invalid cell size found while" 806 808 " parsing SK record at offset 0x%.8X.", offset); 807 free(ret_val); 808 return NULL; 809 goto fail; 809 810 } 810 811 … … 824 825 " are not a multiple of 8 while parsing SK record at" 825 826 " offset 0x%.8X.", offset); 826 free(ret_val); 827 return NULL; 827 goto fail; 828 828 } 829 829 … … 833 833 " cell while parsing SK record at offset 0x%.8X.", 834 834 offset); 835 free(ret_val); 836 return NULL; 837 } 838 839 sec_desc_buf = (uint8*)zalloc(ret_val->desc_size); 840 if(ret_val == NULL) 841 { 842 free(ret_val); 843 return NULL; 844 } 835 goto fail; 836 } 837 838 sec_desc_buf = (uint8*)malloc(ret_val->desc_size); 839 if(sec_desc_buf == NULL) 840 goto fail; 845 841 846 842 length = ret_val->desc_size; … … 851 847 " descriptor while parsing SK record at offset 0x%.8X.", 852 848 offset); 853 free(ret_val);854 return NULL;855 } 856 857 if(!(ret_val->sec_desc = winsec_parse_desc(sec_desc_buf,ret_val->desc_size)))849 goto fail; 850 } 851 852 if(!(ret_val->sec_desc = winsec_parse_desc(ret_val, sec_desc_buf, 853 ret_val->desc_size))) 858 854 { 859 855 regfi_add_message(file, REGFI_MSG_ERROR, "Failed to parse security" 860 856 " descriptor while parsing SK record at offset 0x%.8X.", 861 857 offset); 858 goto fail; 859 } 860 861 free(sec_desc_buf); 862 return ret_val; 863 864 fail: 865 if(sec_desc_buf != NULL) 862 866 free(sec_desc_buf); 863 free(ret_val); 864 return NULL; 865 } 866 free(sec_desc_buf); 867 868 869 return ret_val; 867 talloc_free(ret_val); 868 return NULL; 870 869 } 871 870 … … 1147 1146 const REGFI_HBIN* hbin; 1148 1147 uint32 max_length; 1149 1148 void* failure_ptr = NULL; 1149 1150 1150 /* First look if we have already parsed it */ 1151 1151 ret_val = (REGFI_SK_REC*)lru_cache_find(file->sk_cache, &offset, 4); … … 1165 1165 if(ret_val == NULL) 1166 1166 { /* Cache the parse failure and bail out. */ 1167 lru_cache_update(file->sk_cache, &offset, 4, (void*)REGFI_OFFSET_NONE); 1167 failure_ptr = talloc(NULL, uint32_t); 1168 if(failure_ptr == NULL) 1169 return NULL; 1170 *(uint32_t*)failure_ptr = REGFI_OFFSET_NONE; 1171 lru_cache_update(file->sk_cache, &offset, 4, failure_ptr); 1168 1172 return NULL; 1169 1173 } … … 1287 1291 1288 1292 /* Cache an unlimited number of SK records. Typically there are very few. */ 1289 rb->sk_cache = lru_cache_create (0, cache_secret, true);1293 rb->sk_cache = lru_cache_create_ctx(NULL, 0, cache_secret, true); 1290 1294 1291 1295 /* Default message mask */ … … 1314 1318 range_list_free(file->hbins); 1315 1319 1320 1316 1321 if(file->sk_cache != NULL) 1317 1322 lru_cache_destroy(file->sk_cache); -
trunk/lib/smb_deps.c
r136 r147 24 24 */ 25 25 26 #include " ../include/smb_deps.h"26 #include "smb_deps.h" 27 27 28 28 -
trunk/lib/void_stack.c
r111 r147 22 22 */ 23 23 24 #include " ../include/void_stack.h"24 #include "void_stack.h" 25 25 26 26 void_stack* void_stack_new(unsigned short max_size) -
trunk/lib/winsec.c
r134 r147 24 24 */ 25 25 26 #include "../include/winsec.h" 27 26 #include "winsec.h" 27 28 29 /****************************************************************************** 30 * Non-talloc() interface for parsing a descriptor. 31 ******************************************************************************/ 32 WINSEC_DESC* winsec_parse_descriptor(const uint8_t* buf, uint32_t buf_len) 33 { 34 return winsec_parse_desc(NULL, buf, buf_len); 35 } 36 37 38 /****************************************************************************** 39 * Free a descriptor. Not needed if using talloc and a parent context is freed. 40 ******************************************************************************/ 41 void winsec_free_descriptor(WINSEC_DESC* desc) 42 { 43 talloc_free(desc); 44 } 28 45 29 46 … … 31 48 * Parses a WINSEC_DESC structure and substructures. 32 49 ******************************************************************************/ 33 WINSEC_DESC* winsec_parse_desc(const uint8_t* buf, uint32_t buf_len) 50 WINSEC_DESC* winsec_parse_desc(void* talloc_ctx, 51 const uint8_t* buf, uint32_t buf_len) 34 52 { 35 53 WINSEC_DESC* ret_val; … … 37 55 if (buf == NULL || buf_len < WINSEC_DESC_HEADER_SIZE) 38 56 return NULL; 39 57 /* 40 58 if((ret_val = (WINSEC_DESC*)zalloc(sizeof(WINSEC_DESC))) == NULL) 59 return NULL; 60 */ 61 if((ret_val = talloc(talloc_ctx, WINSEC_DESC)) == NULL) 41 62 return NULL; 42 63 … … 61 82 || (ret_val->off_dacl >= buf_len)) 62 83 { 63 free(ret_val);84 talloc_free(ret_val); 64 85 return NULL; 65 86 } … … 67 88 if(ret_val->off_owner_sid != 0) 68 89 { 69 ret_val->owner_sid = winsec_parse_dom_sid(buf + ret_val->off_owner_sid, 90 ret_val->owner_sid = winsec_parse_dom_sid(ret_val, 91 buf + ret_val->off_owner_sid, 70 92 buf_len - ret_val->off_owner_sid); 71 93 if(ret_val->owner_sid == NULL) 72 94 { 73 free(ret_val);95 talloc_free(ret_val); 74 96 return NULL; 75 97 } … … 78 100 if (ret_val->off_grp_sid != 0) 79 101 { 80 ret_val->grp_sid = winsec_parse_dom_sid( buf + ret_val->off_grp_sid,102 ret_val->grp_sid = winsec_parse_dom_sid(ret_val, buf + ret_val->off_grp_sid, 81 103 buf_len - ret_val->off_grp_sid); 82 104 if(ret_val->grp_sid == NULL) 83 105 { 84 if(ret_val->owner_sid != NULL) 85 free(ret_val->owner_sid); 86 free(ret_val); 106 talloc_free(ret_val); 87 107 return NULL; 88 108 } … … 91 111 if ((ret_val->control & WINSEC_DESC_SACL_PRESENT) && ret_val->off_sacl) 92 112 { 93 ret_val->sacl = winsec_parse_acl( buf + ret_val->off_sacl,113 ret_val->sacl = winsec_parse_acl(ret_val, buf + ret_val->off_sacl, 94 114 buf_len - ret_val->off_sacl); 95 115 if(ret_val->sacl == NULL) 96 116 { 97 if(ret_val->owner_sid != NULL) 98 free(ret_val->owner_sid); 99 if(ret_val->grp_sid != NULL) 100 free(ret_val->grp_sid); 101 free(ret_val); 117 talloc_free(ret_val); 102 118 return NULL; 103 119 } … … 106 122 if ((ret_val->control & WINSEC_DESC_DACL_PRESENT) && ret_val->off_dacl != 0) 107 123 { 108 ret_val->dacl = winsec_parse_acl( buf + ret_val->off_dacl,124 ret_val->dacl = winsec_parse_acl(ret_val, buf + ret_val->off_dacl, 109 125 buf_len - ret_val->off_dacl); 110 126 if(ret_val->dacl == NULL) 111 127 { 112 if(ret_val->owner_sid != NULL) 113 free(ret_val->owner_sid); 114 if(ret_val->grp_sid != NULL) 115 free(ret_val->grp_sid); 116 if(ret_val->sacl != NULL) 117 free(ret_val->sacl); 118 free(ret_val); 128 talloc_free(ret_val); 119 129 return NULL; 120 130 } … … 128 138 * Parses a WINSEC_ACL structure and all substructures. 129 139 ******************************************************************************/ 130 WINSEC_ACL* winsec_parse_acl(const uint8_t* buf, uint32_t buf_len) 140 WINSEC_ACL* winsec_parse_acl(void* talloc_ctx, 141 const uint8_t* buf, uint32_t buf_len) 131 142 { 132 143 uint32_t i, offset; … … 139 150 if (buf == NULL || buf_len < 8) 140 151 return NULL; 141 152 /* 142 153 if((ret_val = (WINSEC_ACL*)zalloc(sizeof(WINSEC_ACL))) == NULL) 154 return NULL; 155 */ 156 if((ret_val = talloc(talloc_ctx, WINSEC_ACL)) == NULL) 143 157 return NULL; 144 158 … … 153 167 if((ret_val->size > buf_len) || (ret_val->num_aces > 4095)) 154 168 { 155 free(ret_val);169 talloc_free(ret_val); 156 170 return NULL; 157 171 } … … 161 175 * (allow no access). 162 176 */ 163 if((ret_val->aces = (WINSEC_ACE**)zcalloc(sizeof(WINSEC_ACE*),177 /* if((ret_val->aces = (WINSEC_ACE**)zcalloc(sizeof(WINSEC_ACE*), 164 178 ret_val->num_aces+1)) == NULL) 165 { 166 free(ret_val); 179 */ 180 if((ret_val->aces = talloc_array(ret_val, WINSEC_ACE*, 181 ret_val->num_aces+1)) == NULL) 182 { 183 talloc_free(ret_val); 167 184 return NULL; 168 185 } … … 171 188 for(i=0; i < ret_val->num_aces; i++) 172 189 { 173 ret_val->aces[i] = winsec_parse_ace(buf+offset, buf_len-offset); 190 ret_val->aces[i] = winsec_parse_ace(ret_val->aces, 191 buf+offset, buf_len-offset); 174 192 if(ret_val->aces[i] == NULL) 175 193 { 176 free(ret_val->aces); 177 free(ret_val); 194 talloc_free(ret_val); 178 195 return NULL; 179 196 } … … 182 199 if(offset > buf_len) 183 200 { 184 free(ret_val->aces); 185 free(ret_val); 201 talloc_free(ret_val); 186 202 return NULL; 187 203 } … … 195 211 * Parses a WINSEC_ACE structure and all substructures. 196 212 ******************************************************************************/ 197 WINSEC_ACE* winsec_parse_ace(const uint8_t* buf, uint32_t buf_len) 213 WINSEC_ACE* winsec_parse_ace(void* talloc_ctx, 214 const uint8_t* buf, uint32_t buf_len) 198 215 { 199 216 uint32_t offset; … … 203 220 return NULL; 204 221 205 if((ret_val = (WINSEC_ACE*)zalloc(sizeof(WINSEC_ACE))) == NULL) 222 /* if((ret_val = (WINSEC_ACE*)zalloc(sizeof(WINSEC_ACE))) == NULL)*/ 223 224 if((ret_val = talloc(talloc_ctx, WINSEC_ACE)) == NULL) 206 225 return NULL; 207 226 … … 221 240 if(ret_val->obj_flags & WINSEC_ACE_OBJECT_PRESENT) 222 241 { 223 ret_val->obj_guid = winsec_parse_uuid(buf+offset, buf_len-offset); 242 ret_val->obj_guid = winsec_parse_uuid(ret_val, 243 buf+offset, buf_len-offset); 224 244 if(ret_val->obj_guid == NULL) 225 245 { 226 free(ret_val);246 talloc_free(ret_val); 227 247 return NULL; 228 248 } … … 232 252 if(ret_val->obj_flags & WINSEC_ACE_OBJECT_INHERITED_PRESENT) 233 253 { 234 ret_val->inh_guid = winsec_parse_uuid(buf+offset, buf_len-offset); 254 ret_val->inh_guid = winsec_parse_uuid(ret_val, 255 buf+offset, buf_len-offset); 235 256 if(ret_val->inh_guid == NULL) 236 257 { 237 if(ret_val->obj_guid != NULL) 238 free(ret_val->obj_guid); 239 free(ret_val); 258 talloc_free(ret_val); 240 259 return NULL; 241 260 } … … 244 263 } 245 264 246 ret_val->trustee = winsec_parse_dom_sid( buf+offset, buf_len-offset);265 ret_val->trustee = winsec_parse_dom_sid(ret_val, buf+offset, buf_len-offset); 247 266 if(ret_val->trustee == NULL) 248 267 { 249 if(ret_val->obj_guid != NULL) 250 free(ret_val->obj_guid); 251 if(ret_val->inh_guid != NULL) 252 free(ret_val->inh_guid); 253 free(ret_val); 254 return NULL; 268 talloc_free(ret_val); 269 return NULL; 255 270 } 256 271 … … 262 277 * Parses a WINSEC_DOM_SID structure. 263 278 ******************************************************************************/ 264 WINSEC_DOM_SID* winsec_parse_dom_sid(const uint8_t* buf, uint32_t buf_len) 279 WINSEC_DOM_SID* winsec_parse_dom_sid(void* talloc_ctx, 280 const uint8_t* buf, uint32_t buf_len) 265 281 { 266 282 uint32_t i; … … 270 286 return NULL; 271 287 272 if((ret_val = (WINSEC_DOM_SID*)zalloc(sizeof(WINSEC_DOM_SID))) == NULL) 288 /* if((ret_val = (WINSEC_DOM_SID*)zalloc(sizeof(WINSEC_DOM_SID))) == NULL)*/ 289 if((ret_val = talloc(talloc_ctx, WINSEC_DOM_SID)) == NULL) 273 290 return NULL; 274 291 … … 283 300 if(buf_len < ret_val->num_auths*sizeof(uint32_t)+8) 284 301 { 285 free(ret_val);302 talloc_free(ret_val); 286 303 return NULL; 287 304 } … … 297 314 * Parses a WINSEC_UUID struct. 298 315 ******************************************************************************/ 299 WINSEC_UUID* winsec_parse_uuid(const uint8_t* buf, uint32_t buf_len) 316 WINSEC_UUID* winsec_parse_uuid(void* talloc_ctx, 317 const uint8_t* buf, uint32_t buf_len) 300 318 { 301 319 WINSEC_UUID* ret_val; … … 304 322 return false; 305 323 306 if((ret_val = (WINSEC_UUID*)zalloc(sizeof(WINSEC_UUID))) == NULL) 324 /* if((ret_val = (WINSEC_UUID*)zalloc(sizeof(WINSEC_UUID))) == NULL)*/ 325 if((ret_val = talloc(talloc_ctx, WINSEC_UUID)) == NULL) 307 326 return NULL; 308 327 … … 321 340 * Calculates the size of a SID. 322 341 ******************************************************************************/ 323 /*size_t sid_size(const WINSEC_DOM_SID *sid)*/324 342 size_t winsec_sid_size(const WINSEC_DOM_SID* sid) 325 343 { … … 334 352 * Compare the auth portion of two SIDs. 335 353 ******************************************************************************/ 336 /*int sid_compare_auth(const WINSEC_DOM_SID *sid1, const WINSEC_DOM_SID *sid2)*/337 354 int winsec_sid_compare_auth(const WINSEC_DOM_SID* sid1, const WINSEC_DOM_SID* sid2) 338 355 { … … 360 377 * Compare two SIDs. 361 378 ******************************************************************************/ 362 /*int sid_compare(const WINSEC_DOM_SID *sid1, const WINSEC_DOM_SID *sid2)*/363 379 int winsec_sid_compare(const WINSEC_DOM_SID* sid1, const WINSEC_DOM_SID* sid2) 364 380 {
Note: See TracChangeset
for help on using the changeset viewer.