- Timestamp:
- 07/17/06 21:56:59 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/regfio.c
r59 r61 6 6 * Windows NT registry I/O library 7 7 * 8 * Copyright (C) 2005 Timothy D. Morgan8 * Copyright (C) 2005-2006 Timothy D. Morgan 9 9 * Copyright (C) 2005 Gerald (Jerry) Carter 10 10 * … … 28 28 29 29 30 31 30 /* Registry types mapping */ 32 const VAL_STR reg_type_names[] = 33 { 34 { REG_SZ, "SZ" }, 35 { REG_EXPAND_SZ, "EXPAND_SZ" }, 36 { REG_BINARY, "BINARY" }, 37 { REG_DWORD, "DWORD" }, 38 { REG_DWORD_BE, "DWORD_BE" }, 39 { REG_LINK, "LINK" }, 40 { REG_MULTI_SZ, "MULTI_SZ" }, 41 { REG_RESOURCE_LIST, "RSRC_LIST" }, 42 { REG_FULL_RESOURCE_DESCRIPTOR, "RSRC_DESC" }, 43 { REG_RESOURCE_REQUIREMENTS_LIST,"RSRC_REQ_LIST"}, 44 { REG_KEY, "KEY" }, 45 { 0, NULL }, 46 }; 31 const unsigned int regfio_num_reg_types = 11; 32 static const char* regfio_type_names[] = 33 {"NONE", "SZ", "EXPAND_SZ", "BINARY", "DWORD", "DWORD_BE", "LINK" 34 "MULTI_SZ", "RSRC_LIST", "RSRC_DESC", "RSRC_REQ_LIST"}; 47 35 48 36 … … 50 38 const char* regfio_type_val2str(unsigned int val) 51 39 { 40 if(val == REG_KEY) 41 return "KEY"; 42 43 if(val >= regfio_num_reg_types) 44 return NULL; 45 46 return regfio_type_names[val]; 47 } 48 49 50 /* Returns -1 on error */ 51 int regfio_type_str2val(const char* str) 52 { 52 53 int i; 53 54 54 for(i=0; reg_type_names[i].val && reg_type_names[i].str; i++) 55 if (reg_type_names[i].val == val) 56 return reg_type_names[i].str; 57 58 return NULL; 59 } 60 61 62 /* Returns 0 on error */ 63 int regfio_type_str2val(const char* str) 64 { 65 int i; 66 67 for(i=0; reg_type_names[i].val && reg_type_names[i].str; i++) 68 if (strcmp(reg_type_names[i].str, str) == 0) 69 return reg_type_names[i].val; 70 71 return 0; 55 if(strcmp("KEY", str) == 0) 56 return REG_KEY; 57 58 for(i=0; i < regfio_num_reg_types; i++) 59 if (strcmp(regfio_type_names[i], str) == 0) 60 return i; 61 62 if(strcmp("DWORD_LE", str) == 0) 63 return REG_DWORD_LE; 64 65 return -1; 72 66 } 73 67 … … 182 176 char* perms_str; 183 177 char* sid_str; 178 char* ace_delim = ""; 184 179 char* ret_val = NULL; 185 char* ace_delim = ""; 180 char* tmp_val = NULL; 181 bool failed = false; 186 182 char field_delim = ':'; 187 183 188 for (i = 0; i < acl->num_aces ; i++)184 for (i = 0; i < acl->num_aces && !failed; i++) 189 185 { 190 186 sid_str = regfio_sid2str(&acl->ace[i].trustee); … … 193 189 flags_str = regfio_ace_flags2str(acl->ace[i].flags); 194 190 195 if(flags_str == NULL || perms_str == NULL 196 || type_str == NULL || sid_str == NULL) 197 return NULL; 198 199 /* XXX: this is slow */ 200 extra = strlen(sid_str) + strlen(type_str) 201 + strlen(perms_str) + strlen(flags_str)+5; 202 ret_val = realloc(ret_val, size+extra); 203 if(ret_val == NULL) 204 return NULL; 205 size += snprintf(ret_val+size, extra, "%s%s%c%s%c%s%c%s", 206 ace_delim,sid_str, 207 field_delim,type_str, 208 field_delim,perms_str, 209 field_delim,flags_str); 210 ace_delim = "|"; 211 free(sid_str); 212 free(perms_str); 213 free(flags_str); 191 if(flags_str != NULL && perms_str != NULL 192 && type_str != NULL && sid_str != NULL) 193 { 194 /* XXX: this is slow */ 195 extra = strlen(sid_str) + strlen(type_str) 196 + strlen(perms_str) + strlen(flags_str)+5; 197 tmp_val = realloc(ret_val, size+extra); 198 199 if(tmp_val == NULL) 200 { 201 free(ret_val); 202 failed = true; 203 } 204 else 205 { 206 ret_val = tmp_val; 207 size += snprintf(ret_val+size, extra, "%s%s%c%s%c%s%c%s", 208 ace_delim,sid_str, 209 field_delim,type_str, 210 field_delim,perms_str, 211 field_delim,flags_str); 212 ace_delim = "|"; 213 } 214 } 215 else 216 failed = true; 217 218 if(sid_str != NULL) 219 free(sid_str); 220 if(sid_str != NULL) 221 free(perms_str); 222 if(sid_str != NULL) 223 free(flags_str); 214 224 } 215 225 … … 254 264 uint32 block_size ) 255 265 { 266 const int hdr_size = 0x20; 256 267 int bytes_read, returned; 257 268 char *buffer; … … 279 290 } 280 291 281 returned = read( file->fd, hdr, 0x20 ); 282 if ( (returned == -1) || (returned < 0x20) ) { 283 /*DEBUG(0,("read_block: failed to read in HBIN header. Is the file corrupt?\n"));*/ 284 return -1; 292 bytes_read = returned = 0; 293 while (bytes_read < hdr_size) 294 { 295 returned = read(file->fd, hdr + bytes_read, hdr_size - bytes_read); 296 if(returned == -1 && errno != EINTR && errno != EAGAIN) 297 { 298 /*DEBUG(0,("read_block: read of hdr failed (%s)\n",strerror(errno)));*/ 299 return -1; 300 } 301 302 if(returned == 0) 303 return -1; 304 305 bytes_read += returned; 285 306 } 286 307 … … 310 331 while ( bytes_read < block_size ) 311 332 { 312 if((returned =313 read(file->fd, buffer+bytes_read, block_size-bytes_read)) == -1)333 returned = read(file->fd, buffer+bytes_read, block_size-bytes_read); 334 if(returned == -1 && errno != EINTR && errno != EAGAIN) 314 335 { 315 336 /*DEBUG(0,("read_block: read() failed (%s)\n", strerror(errno) ));*/ 316 return false; 317 } 337 return -1; 338 } 339 318 340 if ((returned == 0) && (bytes_read < block_size)) 319 341 { 320 342 /*DEBUG(0,("read_block: not a vald registry file ?\n" ));*/ 321 return false;343 return -1; 322 344 } 323 345
Note: See TracChangeset
for help on using the changeset viewer.