Skip to content
Snippets Groups Projects
Commit ceae7787 authored by Samuel H. Kenyon's avatar Samuel H. Kenyon
Browse files

Do two rounds of delete attempts in case there is both an old legacy format...

Do two rounds of delete attempts in case there is both an old legacy format index and an old KDB index.
parent 3b04cc30
No related branches found
No related tags found
No related merge requests found
...@@ -554,6 +554,38 @@ void tsk_idx_clear(TSK_HDB_INFO * hdb_info) ...@@ -554,6 +554,38 @@ void tsk_idx_clear(TSK_HDB_INFO * hdb_info)
} }
} }
/**
* \ingroup hashdblib
* Remove old indices.
*
* @param hdb_info Hash database to consider
* @param htype Hash type that index should be of
*
* @return 0 if success; 1 if failed
*/
uint8_t
tsk_hdb_delete_old(TSK_HDB_INFO * hdb_info)
{
// Call setup to populate the idx_info struct so we can get the filename
hdb_setupindex(hdb_info, hdb_info->hash_type, 0);
// If idx_info is null then there isn't an index
if (hdb_info->idx_info != NULL) {
char cfname[1024];
snprintf(cfname, 1024, "%" PRIttocTSK, hdb_info->idx_info->idx_fname);
// Now that we have a filename, close out all index stuff.
tsk_idx_clear(hdb_info);
if (cfname != "") {
//attempt to delete the old index file
if (remove(cfname) != 0) {
return 1; //error
}
}
}
return 0;
}
/** /**
* \ingroup hashdblib * \ingroup hashdblib
...@@ -572,7 +604,7 @@ tsk_hdb_regenerate_index(TSK_HDB_INFO * hdb_info, TSK_TCHAR * db_type, uint8_t o ...@@ -572,7 +604,7 @@ tsk_hdb_regenerate_index(TSK_HDB_INFO * hdb_info, TSK_TCHAR * db_type, uint8_t o
// Set the hash type since that will affect the filename for legacy indices // Set the hash type since that will affect the filename for legacy indices
char c_db_type[32]; char c_db_type[32];
snprintf(c_db_type, 32, "%" PRIttocTSK, db_type); snprintf(c_db_type, 32, "%" PRIttocTSK, db_type);
TSK_HDB_HTYPE_ENUM htype = TSK_HDB_HTYPE_MD5_ID; hdb_info->hash_type = TSK_HDB_HTYPE_MD5_ID;
if (strcmp(c_db_type, TSK_HDB_DBTYPE_NSRL_MD5_STR) == 0) { if (strcmp(c_db_type, TSK_HDB_DBTYPE_NSRL_MD5_STR) == 0) {
hdb_info->hash_type = TSK_HDB_HTYPE_MD5_ID; hdb_info->hash_type = TSK_HDB_HTYPE_MD5_ID;
} else if (strcmp(c_db_type, TSK_HDB_DBTYPE_NSRL_SHA1_STR) == 0) { } else if (strcmp(c_db_type, TSK_HDB_DBTYPE_NSRL_SHA1_STR) == 0) {
...@@ -584,25 +616,16 @@ tsk_hdb_regenerate_index(TSK_HDB_INFO * hdb_info, TSK_TCHAR * db_type, uint8_t o ...@@ -584,25 +616,16 @@ tsk_hdb_regenerate_index(TSK_HDB_INFO * hdb_info, TSK_TCHAR * db_type, uint8_t o
} else if (strcmp(c_db_type, TSK_HDB_DBTYPE_ENCASE_STR) == 0) { } else if (strcmp(c_db_type, TSK_HDB_DBTYPE_ENCASE_STR) == 0) {
hdb_info->hash_type = TSK_HDB_HTYPE_MD5_ID; hdb_info->hash_type = TSK_HDB_HTYPE_MD5_ID;
} }
if (tsk_hdb_delete_old(hdb_info) != 0) {
return 0; //error
}
// Call setup to populate the idx_info struct so we can get the filename // Run a second pass in case there were two indices
hdb_setupindex(hdb_info, htype, 0); if (tsk_hdb_delete_old(hdb_info) != 0) {
return 0; //error
// If idx_info is null then there isn't an index
if (hdb_info->idx_info != NULL) {
char cfname[1024];
snprintf(cfname, 1024, "%" PRIttocTSK, hdb_info->idx_info->idx_fname);
// Now that we have a filename, close out all index stuff.
tsk_idx_clear(hdb_info);
if (cfname != "") {
//attempt to delete the old index file
if (remove(cfname) != 0) {
return 0; //error
}
}
} }
} else { } else {
// Close index stuff before trying to create a new one. // Close index stuff before trying to create a new one.
tsk_idx_clear(hdb_info); tsk_idx_clear(hdb_info);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment