Changeset 78
- Timestamp:
- 01/15/07 10:22:47 (18 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/regfio.h
r77 r78 31 31 ***********************************************************/ 32 32 33 #ifndef _REGFI O_H34 #define _REGFI O_H33 #ifndef _REGFI_H 34 #define _REGFI_H 35 35 36 36 #include <stdlib.h> … … 47 47 48 48 #include "smb_deps.h" 49 #include "void_stack.h" 49 50 50 51 /******************************************************************************/ … … 72 73 #define REGF_BLOCKSIZE 0x1000 73 74 #define REGF_ALLOC_BLOCK 0x1000 75 #define REGF_MAX_DEPTH 512 74 76 75 77 /* header sizes for various records */ … … 188 190 */ 189 191 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 */ 191 193 uint32 rec_size; /* ((start_offset - end_offset) & 0xfffffff8) */ 192 194 … … 246 248 */ 247 249 248 /* unknowns used to simply writing*/250 /* unknowns */ 249 251 uint32 unknown1; 250 252 uint32 unknown2; … … 256 258 257 259 260 261 typedef struct { 262 REGF_FILE* f; 263 void_stack* keys; 264 uint32 cur_subkey; 265 uint32 cur_value; 266 } REGFI_ITERATOR; 267 258 268 /******************************************************************************/ 259 269 /* Function Declarations */ 260 270 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 */ 271 const char* regfi_type_val2str(unsigned int val); 272 int regfi_type_str2val(const char* str); 273 274 char* regfi_get_sacl(SEC_DESC *sec_desc); 275 char* regfi_get_dacl(SEC_DESC *sec_desc); 276 char* regfi_get_owner(SEC_DESC *sec_desc); 277 char* regfi_get_group(SEC_DESC *sec_desc); 278 279 REGF_FILE* regfi_open( const char *filename ); 280 int regfi_close( REGF_FILE *r ); 281 282 REGF_NK_REC* regfi_rootkey( REGF_FILE *file ); 283 /* REGF_NK_REC* regfi_fetch_subkey( REGF_FILE *file, REGF_NK_REC *nk ); */ 284 285 REGFI_ITERATOR* regfi_iterator_create(REGF_FILE* fh); 286 bool regfi_iterator_down(REGFI_ITERATOR* i, const char* subkey_name); 287 bool regfi_iterator_up(REGFI_ITERATOR* i); 288 REGF_NK_REC* regfi_iterator_next_subkey(REGFI_ITERATOR* i); 289 REGF_VK_REC* regfi_iterator_next_value(REGFI_ITERATOR* i); 290 REGF_VK_REC* regfi_iterator_fetch_value(REGFI_ITERATOR* i, const char* value_name); 291 char* regfi_iterator_curpath(REGFI_ITERATOR* i); 292 293 #endif /* _REGFI_H */ -
trunk/lib/regfio.c
r77 r78 29 29 30 30 /* Registry types mapping */ 31 const unsigned int regfi o_num_reg_types = 12;32 static const char* regfi o_type_names[] =31 const unsigned int regfi_num_reg_types = 12; 32 static const char* regfi_type_names[] = 33 33 {"NONE", "SZ", "EXPAND_SZ", "BINARY", "DWORD", "DWORD_BE", "LINK", 34 34 "MULTI_SZ", "RSRC_LIST", "RSRC_DESC", "RSRC_REQ_LIST", "QWORD"}; … … 36 36 37 37 /* Returns NULL on error */ 38 const char* regfi o_type_val2str(unsigned int val)38 const char* regfi_type_val2str(unsigned int val) 39 39 { 40 40 if(val == REG_KEY) 41 41 return "KEY"; 42 42 43 if(val >= regfi o_num_reg_types)43 if(val >= regfi_num_reg_types) 44 44 return NULL; 45 45 46 return regfi o_type_names[val];46 return regfi_type_names[val]; 47 47 } 48 48 49 49 50 50 /* Returns -1 on error */ 51 int regfi o_type_str2val(const char* str)51 int regfi_type_str2val(const char* str) 52 52 { 53 53 int i; … … 56 56 return REG_KEY; 57 57 58 for(i=0; i < regfi o_num_reg_types; i++)59 if (strcmp(regfi o_type_names[i], str) == 0)58 for(i=0; i < regfi_num_reg_types; i++) 59 if (strcmp(regfi_type_names[i], str) == 0) 60 60 return i; 61 61 … … 69 69 /* Security descriptor parsing functions */ 70 70 71 const char* regfi o_ace_type2str(uint8 type)71 const char* regfi_ace_type2str(uint8 type) 72 72 { 73 73 static const char* map[7] … … 89 89 * http://msdn2.microsoft.com/en-us/library/aa772242.aspx 90 90 */ 91 char* regfi o_ace_flags2str(uint8 flags)91 char* regfi_ace_flags2str(uint8 flags) 92 92 { 93 93 static const char* flag_map[32] = … … 147 147 148 148 149 char* regfi o_ace_perms2str(uint32 perms)149 char* regfi_ace_perms2str(uint32 perms) 150 150 { 151 151 uint32 i, p; … … 226 226 227 227 228 char* regfi o_sid2str(DOM_SID* sid)228 char* regfi_sid2str(DOM_SID* sid) 229 229 { 230 230 uint32 i, size = MAXSUBAUTHS*11 + 24; … … 248 248 249 249 250 char* regfi o_get_acl(SEC_ACL* acl)250 char* regfi_get_acl(SEC_ACL* acl) 251 251 { 252 252 uint32 i, extra, size = 0; … … 263 263 for (i = 0; i < acl->num_aces && !failed; i++) 264 264 { 265 sid_str = regfi o_sid2str(&acl->ace[i].trustee);266 type_str = regfi o_ace_type2str(acl->ace[i].type);267 perms_str = regfi o_ace_perms2str(acl->ace[i].info.mask);268 flags_str = regfi o_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); 269 269 270 270 if(flags_str != NULL && perms_str != NULL … … 307 307 308 308 309 char* regfi o_get_sacl(SEC_DESC *sec_desc)309 char* regfi_get_sacl(SEC_DESC *sec_desc) 310 310 { 311 311 if (sec_desc->sacl) 312 return regfi o_get_acl(sec_desc->sacl);312 return regfi_get_acl(sec_desc->sacl); 313 313 else 314 314 return NULL; … … 316 316 317 317 318 char* regfi o_get_dacl(SEC_DESC *sec_desc)318 char* regfi_get_dacl(SEC_DESC *sec_desc) 319 319 { 320 320 if (sec_desc->dacl) 321 return regfi o_get_acl(sec_desc->dacl);321 return regfi_get_acl(sec_desc->dacl); 322 322 else 323 323 return NULL; … … 325 325 326 326 327 char* regfi o_get_owner(SEC_DESC *sec_desc)328 { 329 return regfi o_sid2str(sec_desc->owner_sid);330 } 331 332 333 char* regfi o_get_group(SEC_DESC *sec_desc)334 { 335 return regfi o_sid2str(sec_desc->grp_sid);327 char* regfi_get_owner(SEC_DESC *sec_desc) 328 { 329 return regfi_sid2str(sec_desc->owner_sid); 330 } 331 332 333 char* regfi_get_group(SEC_DESC *sec_desc) 334 { 335 return regfi_sid2str(sec_desc->grp_sid); 336 336 } 337 337 … … 1368 1368 first hbin offset. 1369 1369 *******************************************************************/ 1370 REGF_FILE* regfi o_open( const char *filename )1370 REGF_FILE* regfi_open( const char *filename ) 1371 1371 { 1372 1372 REGF_FILE *rb; … … 1382 1382 /* if ( !(rb->mem_ctx = talloc_init( "read_regf_block" )) ) 1383 1383 { 1384 regfi o_close( rb );1384 regfi_close( rb ); 1385 1385 return NULL; 1386 1386 } … … 1391 1391 1392 1392 if ( (rb->fd = open(filename, flags)) == -1 ) { 1393 /* DEBUG(0,("regfi o_open: failure to open %s (%s)\n", filename, strerror(errno)));*/1394 regfi o_close( rb );1393 /* DEBUG(0,("regfi_open: failure to open %s (%s)\n", filename, strerror(errno)));*/ 1394 regfi_close( rb ); 1395 1395 return NULL; 1396 1396 } … … 1399 1399 1400 1400 if ( !read_regf_block( rb ) ) { 1401 /* DEBUG(0,("regfi o_open: Failed to read initial REGF block\n"));*/1402 regfi o_close( rb );1401 /* DEBUG(0,("regfi_open: Failed to read initial REGF block\n"));*/ 1402 regfi_close( rb ); 1403 1403 return NULL; 1404 1404 } … … 1412 1412 /******************************************************************* 1413 1413 *******************************************************************/ 1414 static void regfi o_mem_free( REGF_FILE *file )1414 static void regfi_mem_free( REGF_FILE *file ) 1415 1415 { 1416 1416 /* free any zalloc()'d memory */ … … 1424 1424 /******************************************************************* 1425 1425 *******************************************************************/ 1426 int regfi o_close( REGF_FILE *file )1426 int regfi_close( REGF_FILE *file ) 1427 1427 { 1428 1428 int fd; 1429 1429 1430 regfi o_mem_free( file );1430 regfi_mem_free( file ); 1431 1431 1432 1432 /* nothing to do if there is no open file */ … … 1447 1447 on my experience. --jerry 1448 1448 *******************************************************************/ 1449 REGF_NK_REC* regfi o_rootkey( REGF_FILE *file )1449 REGF_NK_REC* regfi_rootkey( REGF_FILE *file ) 1450 1450 { 1451 1451 REGF_NK_REC *nk; … … 1459 1459 1460 1460 if ( !(nk = (REGF_NK_REC*)zalloc(sizeof(REGF_NK_REC) )) ) { 1461 /*DEBUG(0,("regfi o_rootkey: zalloc() failed!\n"));*/1461 /*DEBUG(0,("regfi_rootkey: zalloc() failed!\n"));*/ 1462 1462 return NULL; 1463 1463 } … … 1492 1492 1493 1493 if ( !found ) { 1494 /*DEBUG(0,("regfi o_rootkey: corrupt registry file ? No root key record located\n"));*/1494 /*DEBUG(0,("regfi_rootkey: corrupt registry file ? No root key record located\n"));*/ 1495 1495 return NULL; 1496 1496 } … … 1510 1510 NK record. Remember that offsets are from the *first* HBIN block. 1511 1511 *******************************************************************/ 1512 REGF_NK_REC* regfi o_fetch_subkey( REGF_FILE *file, REGF_NK_REC *nk )1512 REGF_NK_REC* regfi_fetch_subkey( REGF_FILE *file, REGF_NK_REC *nk ) 1513 1513 { 1514 1514 REGF_NK_REC *subkey; … … 1529 1529 return NULL; 1530 1530 } 1531 1531 1532 1532 nk_offset = nk->subkeys.hashes[nk->subkey_index].nk_off; 1533 1533 if(!prs_set_offset(&hbin->ps, -
trunk/src/reglookup.c
r77 r78 216 216 { 217 217 tmp_err = strerror(-ret_err); 218 str_type = regfi o_type_val2str(type);218 str_type = regfi_type_val2str(type); 219 219 *error_msg = (char*)malloc(65+strlen(str_type)+strlen(tmp_err)+1); 220 220 if(*error_msg == NULL) … … 385 385 { 386 386 void_stack* ret_val; 387 void_stack* rev_ret = void_stack_new( 1024);387 void_stack* rev_ret = void_stack_new(REGF_MAX_DEPTH); 388 388 const char* cur = s; 389 389 char* next = NULL; … … 405 405 memcpy(copy, cur, next-cur); 406 406 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"); 408 409 } 409 410 cur = next+1; … … 412 413 { 413 414 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"); 415 417 } 416 418 … … 541 543 "warning returned: %s\n", prefix, quoted_name, conv_error); 542 544 543 str_type = regfi o_type_val2str(vk->type);545 str_type = regfi_type_val2str(vk->type); 544 546 if(print_security) 545 547 { … … 597 599 if(print_security) 598 600 { 599 owner = regfi o_get_owner(k->sec_desc->sec_desc);600 group = regfi o_get_group(k->sec_desc->sec_desc);601 sacl = regfi o_get_sacl(k->sec_desc->sec_desc);602 dacl = regfi o_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); 603 605 if(owner == NULL) 604 606 owner = empty_str; … … 636 638 uint32 path_len = 0; 637 639 uint32 prefix_len = strlen(prefix); 638 int key_type = regfi o_type_str2val("KEY");640 int key_type = regfi_type_str2val("KEY"); 639 641 640 642 if((cur = (REGF_NK_REC*)void_stack_cur(nk_stack)) != NULL) … … 672 674 while((cur = (REGF_NK_REC*)void_stack_cur(nk_stack)) != NULL) 673 675 { 674 if((sub = regfi o_fetch_subkey(f, cur)) == NULL)676 if((sub = regfi_fetch_subkey(f, cur)) == NULL) 675 677 { 676 678 sub = void_stack_pop(nk_stack); … … 684 686 { 685 687 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"); 687 690 path = stack2Path(nk_stack); 688 691 if(path != NULL) … … 753 756 found_cur = false; 754 757 while(!found_cur && 755 (sub = regfi o_fetch_subkey(f, cur)) != NULL)758 (sub = regfi_fetch_subkey(f, cur)) != NULL) 756 759 { 757 760 if(strcasecmp(sub->keyname, cur_str) == 0) 758 761 { 759 762 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 761 766 found_cur = true; 762 767 } … … 802 807 " of specified path.\n"); 803 808 804 while((sub = regfi o_fetch_subkey(f, cur)) != NULL)809 while((sub = regfi_fetch_subkey(f, cur)) != NULL) 805 810 { 806 811 if(strcasecmp(sub->keyname, cur_str) == 0) 807 812 { 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"); 810 816 prefix = stack2Path(nk_stack); 811 817 prefix_len = strlen(prefix); … … 890 896 bailOut(1, "ERROR: '-t' option requires parameter.\n"); 891 897 } 892 if((type_filter = regfi o_type_str2val(argv[argi])) < 0)898 if((type_filter = regfi_type_str2val(argv[argi])) < 0) 893 899 { 894 900 fprintf(stderr, "ERROR: Invalid type specified: %s.\n", argv[argi]); … … 917 923 bailOut(2, "ERROR: Memory allocation problem.\n"); 918 924 919 f = regfi o_open(registry_file);925 f = regfi_open(registry_file); 920 926 if(f == NULL) 921 927 { … … 924 930 } 925 931 926 root = regfi o_rootkey(f);927 nk_stack = void_stack_new( 1024);932 root = regfi_rootkey(f); 933 nk_stack = void_stack_new(REGF_MAX_DEPTH); 928 934 929 935 if(void_stack_push(nk_stack, root)) … … 950 956 } 951 957 else 952 bailOut(2, "ERROR: Memory allocation problem.\n");958 bailOut(2, "ERROR: Registry maximum depth exceeded.\n"); 953 959 954 960 void_stack_destroy_deep(nk_stack); 955 regfi o_close(f);961 regfi_close(f); 956 962 957 963 return 0;
Note: See TracChangeset
for help on using the changeset viewer.