Skip to content

Commit f626a69

Browse files
committed
Merge remote-tracking branch 'sam/hashdb_sqlite' into hashdb_sqlite
2 parents 023f10b + aa39264 commit f626a69

File tree

3 files changed

+215
-46
lines changed

3 files changed

+215
-46
lines changed

tsk/hashdb/hdb_index.cpp

+35-19
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,30 @@ tsk_idx_close_file(FILE * idx)
8181
}
8282
}
8383

84+
/**
85+
* Update the hash type. New indices can handle multiple hash types, so hash
86+
* type is now dependent on what the client is doing (e.g. lookup md5).
87+
* @return 1 on error, 0 on success
88+
*/
89+
static int
90+
hdb_update_htype(TSK_HDB_INFO * hdb_info, uint8_t htype)
91+
{
92+
/* Get hash type specific information */
93+
switch (htype) {
94+
case TSK_HDB_HTYPE_MD5_ID:
95+
hdb_info->hash_type = static_cast<TSK_HDB_HTYPE_ENUM>(htype);
96+
hdb_info->hash_len = TSK_HDB_HTYPE_MD5_LEN;
97+
break;
98+
case TSK_HDB_HTYPE_SHA1_ID:
99+
hdb_info->hash_type = static_cast<TSK_HDB_HTYPE_ENUM>(htype);
100+
hdb_info->hash_len = TSK_HDB_HTYPE_SHA1_LEN;
101+
break;
102+
default:
103+
return 1;
104+
}
105+
return 0;
106+
}
107+
84108
/**
85109
* Open an index for the given hash db
86110
* We only create kdb (SQLite) files, but can open old indexes.
@@ -117,27 +141,16 @@ tsk_idx_open(TSK_HDB_INFO * hdb_info, uint8_t htype, uint8_t create)
117141
return NULL;
118142
}
119143

120-
/* Get hash type specific information */
121-
switch (htype) {
122-
case TSK_HDB_HTYPE_MD5_ID:
123-
hdb_info->hash_type = static_cast<TSK_HDB_HTYPE_ENUM>(htype);
124-
hdb_info->hash_len = TSK_HDB_HTYPE_MD5_LEN;
125-
break;
126-
case TSK_HDB_HTYPE_SHA1_ID:
127-
hdb_info->hash_type = static_cast<TSK_HDB_HTYPE_ENUM>(htype);
128-
hdb_info->hash_len = TSK_HDB_HTYPE_SHA1_LEN;
129-
break;
130-
default:
131-
free(idx_info);
132-
tsk_error_reset();
133-
tsk_error_set_errno(TSK_ERR_HDB_MISSING);
134-
tsk_error_set_errstr(
135-
"tsk_idx_open: Unknown hash type: %d\n",
136-
(int)htype);
137-
return NULL;
144+
if (hdb_update_htype(hdb_info, htype) == 1) {
145+
free(idx_info);
146+
tsk_error_reset();
147+
tsk_error_set_errno(TSK_ERR_HDB_MISSING);
148+
tsk_error_set_errstr(
149+
"tsk_idx_open: Unknown hash type: %d\n",
150+
(int)htype);
151+
return NULL;
138152
}
139153

140-
141154
// Verify the new SQLite index exists, get its size, and open it for header reading
142155

143156
// Set SQLite index filename
@@ -308,6 +321,9 @@ hdb_setupindex(TSK_HDB_INFO * hdb_info, uint8_t htype, uint8_t create)
308321

309322
// already opened
310323
if (hdb_info->idx_info != NULL) {
324+
// update htype
325+
hdb_update_htype(hdb_info, htype);
326+
311327
tsk_release_lock(&hdb_info->lock);
312328
return 0;
313329
}

0 commit comments

Comments
 (0)