mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-15 09:17:42 +00:00
Merge branch 'develop' of https://github.com/sleuthkit/autopsy into 6133-ChangeDefaultVideoThumb
This commit is contained in:
commit
caeacf97bd
@ -51,7 +51,7 @@ public class CentralRepoDbUpgrader13To14 implements CentralRepoDbUpgrader {
|
|||||||
if (type.getId() >= CorrelationAttributeInstance.ADDITIONAL_TYPES_BASE_ID) {
|
if (type.getId() >= CorrelationAttributeInstance.ADDITIONAL_TYPES_BASE_ID) {
|
||||||
|
|
||||||
// these are new Correlation types - new tables need to be created
|
// these are new Correlation types - new tables need to be created
|
||||||
statement.execute(String.format(RdbmsCentralRepoFactory.getCreateArtifactInstancesTableTemplate(selectedPlatform), instance_type_dbname, instance_type_dbname));
|
statement.execute(String.format(RdbmsCentralRepoFactory.getCreateAccountInstancesTableTemplate(selectedPlatform), instance_type_dbname, instance_type_dbname));
|
||||||
statement.execute(String.format(RdbmsCentralRepoFactory.getAddCaseIdIndexTemplate(), instance_type_dbname, instance_type_dbname));
|
statement.execute(String.format(RdbmsCentralRepoFactory.getAddCaseIdIndexTemplate(), instance_type_dbname, instance_type_dbname));
|
||||||
statement.execute(String.format(RdbmsCentralRepoFactory.getAddDataSourceIdIndexTemplate(), instance_type_dbname, instance_type_dbname));
|
statement.execute(String.format(RdbmsCentralRepoFactory.getAddDataSourceIdIndexTemplate(), instance_type_dbname, instance_type_dbname));
|
||||||
statement.execute(String.format(RdbmsCentralRepoFactory.getAddValueIndexTemplate(), instance_type_dbname, instance_type_dbname));
|
statement.execute(String.format(RdbmsCentralRepoFactory.getAddValueIndexTemplate(), instance_type_dbname, instance_type_dbname));
|
||||||
@ -61,9 +61,8 @@ public class CentralRepoDbUpgrader13To14 implements CentralRepoDbUpgrader {
|
|||||||
// add new correlation type
|
// add new correlation type
|
||||||
CentralRepoDbUtil.insertCorrelationType(connection, type);
|
CentralRepoDbUtil.insertCorrelationType(connection, type);
|
||||||
|
|
||||||
} else {
|
} else if (type.getId() == CorrelationAttributeInstance.EMAIL_TYPE_ID || type.getId() == CorrelationAttributeInstance.PHONE_TYPE_ID) {
|
||||||
|
// Alter the existing _instance tables for Phone and Email attributes to add account_id column
|
||||||
// Alter the existing X_Instance tables to add account_id column
|
|
||||||
String sqlStr = String.format(getAlterArtifactInstancesAddAccountIdTemplate(selectedPlatform), instance_type_dbname);
|
String sqlStr = String.format(getAlterArtifactInstancesAddAccountIdTemplate(selectedPlatform), instance_type_dbname);
|
||||||
statement.execute(sqlStr);
|
statement.execute(sqlStr);
|
||||||
|
|
||||||
|
@ -325,4 +325,17 @@ public class CentralRepoDbUtil {
|
|||||||
closeStatement(preparedStatement);
|
closeStatement(preparedStatement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the given correlation attribute type has an account behind it.
|
||||||
|
*
|
||||||
|
* @param type Correlation type to check.
|
||||||
|
*
|
||||||
|
* @return True If the specified correlation type has an account.
|
||||||
|
*/
|
||||||
|
static boolean correlationAttribHasAnAccount(CorrelationAttributeInstance.Type type) {
|
||||||
|
return (type.getId() >= CorrelationAttributeInstance.ADDITIONAL_TYPES_BASE_ID)
|
||||||
|
|| type.getId() == CorrelationAttributeInstance.PHONE_TYPE_ID
|
||||||
|
|| type.getId() == CorrelationAttributeInstance.EMAIL_TYPE_ID;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -63,9 +63,21 @@ public class CentralRepoPostgresSettingsUtil {
|
|||||||
|
|
||||||
private CentralRepoPostgresSettingsUtil() {}
|
private CentralRepoPostgresSettingsUtil() {}
|
||||||
|
|
||||||
private void logException(TryHandler handler) {
|
/**
|
||||||
|
* Uses setter object to set a value as specified by 'value'. In the event that 'value'
|
||||||
|
* is null, the setter will not be called. Exceptions that are raised from the setter will
|
||||||
|
* be logged.
|
||||||
|
*
|
||||||
|
* @param setter The setter to call.
|
||||||
|
* @param value The value to use with the setter.
|
||||||
|
*/
|
||||||
|
private void setValOrLog(ValueSetter setter, String value) {
|
||||||
|
// ignore null values as they indicate a setting that is not set yet
|
||||||
|
if (value == null || value.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
handler.operation();
|
setter.set(value);
|
||||||
}
|
}
|
||||||
catch (CentralRepoException | NumberFormatException e) {
|
catch (CentralRepoException | NumberFormatException e) {
|
||||||
LOGGER.log(Level.WARNING, "There was an error in converting central repo postgres settings", e);
|
LOGGER.log(Level.WARNING, "There was an error in converting central repo postgres settings", e);
|
||||||
@ -73,10 +85,10 @@ public class CentralRepoPostgresSettingsUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This interface represents an action that potentially throws an exception.
|
* This interface represents a setter that potentially throws an exception.
|
||||||
*/
|
*/
|
||||||
private interface TryHandler {
|
private interface ValueSetter {
|
||||||
void operation() throws CentralRepoException, NumberFormatException;
|
void set(String value) throws CentralRepoException, NumberFormatException;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -96,15 +108,12 @@ public class CentralRepoPostgresSettingsUtil {
|
|||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
logException(() -> settings.setHost(muConn.getHost()));
|
setValOrLog((v) -> settings.setHost(v), muConn.getHost());
|
||||||
logException(() -> settings.setDbName(PostgresConnectionSettings.DEFAULT_DBNAME));
|
setValOrLog((v) -> settings.setUserName(v), muConn.getUserName());
|
||||||
logException(() -> settings.setUserName(muConn.getUserName()));
|
setValOrLog((v) -> settings.setPassword(v), muConn.getPassword());
|
||||||
|
|
||||||
logException(() -> settings.setPort(Integer.parseInt(muConn.getPort())));
|
|
||||||
logException(() -> settings.setBulkThreshold(RdbmsCentralRepo.DEFAULT_BULK_THRESHHOLD));
|
|
||||||
|
|
||||||
logException(() -> settings.setPassword(muConn.getPassword()));
|
|
||||||
|
|
||||||
|
setValOrLog((v) -> settings.setPort(Integer.parseInt(v)), muConn.getPort());
|
||||||
|
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,24 +129,27 @@ public class CentralRepoPostgresSettingsUtil {
|
|||||||
Map<String, String> keyVals = ModuleSettings.getConfigSettings(MODULE_KEY);
|
Map<String, String> keyVals = ModuleSettings.getConfigSettings(MODULE_KEY);
|
||||||
|
|
||||||
|
|
||||||
logException(() -> settings.setHost(keyVals.get(HOST_KEY)));
|
setValOrLog((v) -> settings.setHost(v), keyVals.get(HOST_KEY));
|
||||||
logException(() -> settings.setDbName(keyVals.get(DBNAME_KEY)));
|
setValOrLog((v) -> settings.setDbName(v), keyVals.get(DBNAME_KEY));
|
||||||
logException(() -> settings.setUserName(keyVals.get(USER_KEY)));
|
setValOrLog((v) -> settings.setUserName(v), keyVals.get(USER_KEY));
|
||||||
|
|
||||||
logException(() -> settings.setPort(Integer.parseInt(keyVals.get(PORT_KEY))));
|
setValOrLog((v) -> settings.setPort(Integer.parseInt(v)), keyVals.get(PORT_KEY));
|
||||||
logException(() -> settings.setBulkThreshold(Integer.parseInt(keyVals.get((BULK_THRESHOLD_KEY)))));
|
setValOrLog((v) -> settings.setBulkThreshold(Integer.parseInt(v)), keyVals.get((BULK_THRESHOLD_KEY)));
|
||||||
|
|
||||||
String passwordHex = keyVals.get(PASSWORD_KEY);
|
String passwordHex = keyVals.get(PASSWORD_KEY);
|
||||||
String password;
|
if (passwordHex != null) {
|
||||||
try {
|
String password;
|
||||||
password = TextConverter.convertHexTextToText(passwordHex);
|
try {
|
||||||
} catch (TextConverterException ex) {
|
password = TextConverter.convertHexTextToText(passwordHex);
|
||||||
LOGGER.log(Level.WARNING, "Failed to convert password from hex text to text.", ex);
|
} catch (TextConverterException ex) {
|
||||||
password = null;
|
LOGGER.log(Level.WARNING, "Failed to convert password from hex text to text.", ex);
|
||||||
|
password = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String finalPassword = password;
|
||||||
|
setValOrLog((v) -> settings.setPassword(v), finalPassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String finalPassword = password;
|
|
||||||
logException(() -> settings.setPassword(finalPassword));
|
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1002,18 +1002,26 @@ abstract class RdbmsCentralRepo implements CentralRepository {
|
|||||||
public void addArtifactInstance(CorrelationAttributeInstance eamArtifact) throws CentralRepoException {
|
public void addArtifactInstance(CorrelationAttributeInstance eamArtifact) throws CentralRepoException {
|
||||||
checkAddArtifactInstanceNulls(eamArtifact);
|
checkAddArtifactInstanceNulls(eamArtifact);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// @@@ We should cache the case and data source IDs in memory
|
// @@@ We should cache the case and data source IDs in memory
|
||||||
String tableName = CentralRepoDbUtil.correlationTypeToInstanceTableName(eamArtifact.getCorrelationType());
|
String tableName = CentralRepoDbUtil.correlationTypeToInstanceTableName(eamArtifact.getCorrelationType());
|
||||||
String sql
|
boolean artifactHasAnAccount = CentralRepoDbUtil.correlationAttribHasAnAccount(eamArtifact.getCorrelationType());
|
||||||
= "INSERT INTO "
|
|
||||||
|
String sql;
|
||||||
|
// _instance table for accounts have an additional account_id column
|
||||||
|
if (artifactHasAnAccount) {
|
||||||
|
sql = "INSERT INTO "
|
||||||
+ tableName
|
+ tableName
|
||||||
+ "(case_id, data_source_id, value, file_path, known_status, comment, file_obj_id, account_id) "
|
+ "(case_id, data_source_id, value, file_path, known_status, comment, file_obj_id, account_id) "
|
||||||
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?) "
|
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?) "
|
||||||
+ getConflictClause();
|
+ getConflictClause();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sql = "INSERT INTO "
|
||||||
|
+ tableName
|
||||||
|
+ "(case_id, data_source_id, value, file_path, known_status, comment, file_obj_id) "
|
||||||
|
+ "VALUES (?, ?, ?, ?, ?, ?, ?) "
|
||||||
|
+ getConflictClause();
|
||||||
|
}
|
||||||
|
|
||||||
try (Connection conn = connect();
|
try (Connection conn = connect();
|
||||||
PreparedStatement preparedStatement = conn.prepareStatement(sql);) {
|
PreparedStatement preparedStatement = conn.prepareStatement(sql);) {
|
||||||
@ -1032,10 +1040,13 @@ abstract class RdbmsCentralRepo implements CentralRepository {
|
|||||||
}
|
}
|
||||||
preparedStatement.setLong(7, eamArtifact.getFileObjectId());
|
preparedStatement.setLong(7, eamArtifact.getFileObjectId());
|
||||||
|
|
||||||
if (eamArtifact.getAccountId() >= 0) {
|
// set in the accountId only for artifacts that represent accounts
|
||||||
preparedStatement.setLong(8, eamArtifact.getAccountId());
|
if (artifactHasAnAccount) {
|
||||||
} else {
|
if (eamArtifact.getAccountId() >= 0) {
|
||||||
preparedStatement.setNull(8, Types.INTEGER);
|
preparedStatement.setLong(8, eamArtifact.getAccountId());
|
||||||
|
} else {
|
||||||
|
preparedStatement.setNull(8, Types.INTEGER);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
preparedStatement.executeUpdate();
|
preparedStatement.executeUpdate();
|
||||||
|
@ -83,6 +83,7 @@ public class RdbmsCentralRepoFactory {
|
|||||||
public boolean initializeDatabaseSchema() {
|
public boolean initializeDatabaseSchema() {
|
||||||
|
|
||||||
String createArtifactInstancesTableTemplate = getCreateArtifactInstancesTableTemplate(selectedPlatform);
|
String createArtifactInstancesTableTemplate = getCreateArtifactInstancesTableTemplate(selectedPlatform);
|
||||||
|
String createAccountInstancesTableTemplate = getCreateAccountInstancesTableTemplate(selectedPlatform);
|
||||||
|
|
||||||
String instancesCaseIdIdx = getAddCaseIdIndexTemplate();
|
String instancesCaseIdIdx = getAddCaseIdIndexTemplate();
|
||||||
String instancesDatasourceIdIdx = getAddDataSourceIdIndexTemplate();
|
String instancesDatasourceIdIdx = getAddDataSourceIdIndexTemplate();
|
||||||
@ -147,7 +148,13 @@ public class RdbmsCentralRepoFactory {
|
|||||||
reference_type_dbname = CentralRepoDbUtil.correlationTypeToReferenceTableName(type);
|
reference_type_dbname = CentralRepoDbUtil.correlationTypeToReferenceTableName(type);
|
||||||
instance_type_dbname = CentralRepoDbUtil.correlationTypeToInstanceTableName(type);
|
instance_type_dbname = CentralRepoDbUtil.correlationTypeToInstanceTableName(type);
|
||||||
|
|
||||||
stmt.execute(String.format(createArtifactInstancesTableTemplate, instance_type_dbname, instance_type_dbname));
|
// use the correct create table template, based on whether the attribute type represents an account or not.
|
||||||
|
String createTableTemplate = (CentralRepoDbUtil.correlationAttribHasAnAccount(type))
|
||||||
|
? createAccountInstancesTableTemplate
|
||||||
|
: createArtifactInstancesTableTemplate;
|
||||||
|
|
||||||
|
stmt.execute(String.format(createTableTemplate, instance_type_dbname, instance_type_dbname));
|
||||||
|
|
||||||
stmt.execute(String.format(instancesCaseIdIdx, instance_type_dbname, instance_type_dbname));
|
stmt.execute(String.format(instancesCaseIdIdx, instance_type_dbname, instance_type_dbname));
|
||||||
stmt.execute(String.format(instancesDatasourceIdIdx, instance_type_dbname, instance_type_dbname));
|
stmt.execute(String.format(instancesDatasourceIdIdx, instance_type_dbname, instance_type_dbname));
|
||||||
stmt.execute(String.format(instancesValueIdx, instance_type_dbname, instance_type_dbname));
|
stmt.execute(String.format(instancesValueIdx, instance_type_dbname, instance_type_dbname));
|
||||||
@ -357,7 +364,7 @@ public class RdbmsCentralRepoFactory {
|
|||||||
+ ")";
|
+ ")";
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Get the template String for creating a new _instances table in a Sqlite
|
* Get the template String for creating a new _instances table for non account artifacts in
|
||||||
* central repository. %s will exist in the template where the name of the
|
* central repository. %s will exist in the template where the name of the
|
||||||
* new table will be added.
|
* new table will be added.
|
||||||
*
|
*
|
||||||
@ -365,6 +372,31 @@ public class RdbmsCentralRepoFactory {
|
|||||||
*/
|
*/
|
||||||
static String getCreateArtifactInstancesTableTemplate(CentralRepoPlatforms selectedPlatform) {
|
static String getCreateArtifactInstancesTableTemplate(CentralRepoPlatforms selectedPlatform) {
|
||||||
// Each "%s" will be replaced with the relevant TYPE_instances table name.
|
// Each "%s" will be replaced with the relevant TYPE_instances table name.
|
||||||
|
|
||||||
|
return "CREATE TABLE IF NOT EXISTS %s ("
|
||||||
|
+ getNumericPrimaryKeyClause("id", selectedPlatform)
|
||||||
|
+ "case_id integer NOT NULL,"
|
||||||
|
+ "data_source_id integer NOT NULL,"
|
||||||
|
+ "value text NOT NULL,"
|
||||||
|
+ "file_path text NOT NULL,"
|
||||||
|
+ "known_status integer NOT NULL,"
|
||||||
|
+ "comment text,"
|
||||||
|
+ "file_obj_id " + getBigIntType(selectedPlatform) + " ,"
|
||||||
|
+ "CONSTRAINT %s_multi_unique UNIQUE(data_source_id, value, file_path)" + getOnConflictIgnoreClause(selectedPlatform) + ","
|
||||||
|
+ "foreign key (case_id) references cases(id) ON UPDATE SET NULL ON DELETE SET NULL,"
|
||||||
|
+ "foreign key (data_source_id) references data_sources(id) ON UPDATE SET NULL ON DELETE SET NULL)";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the template String for creating a new _instances table for Accounts in
|
||||||
|
* central repository. %s will exist in the template where the name of the
|
||||||
|
* new table will be added.
|
||||||
|
*
|
||||||
|
* @return a String which is a template for creating a _instances table
|
||||||
|
*/
|
||||||
|
static String getCreateAccountInstancesTableTemplate(CentralRepoPlatforms selectedPlatform) {
|
||||||
|
// Each "%s" will be replaced with the relevant TYPE_instances table name.
|
||||||
|
|
||||||
return "CREATE TABLE IF NOT EXISTS %s ("
|
return "CREATE TABLE IF NOT EXISTS %s ("
|
||||||
+ getNumericPrimaryKeyClause("id", selectedPlatform)
|
+ getNumericPrimaryKeyClause("id", selectedPlatform)
|
||||||
+ "case_id integer NOT NULL,"
|
+ "case_id integer NOT NULL,"
|
||||||
@ -380,7 +412,7 @@ public class RdbmsCentralRepoFactory {
|
|||||||
+ "foreign key (case_id) references cases(id) ON UPDATE SET NULL ON DELETE SET NULL,"
|
+ "foreign key (case_id) references cases(id) ON UPDATE SET NULL ON DELETE SET NULL,"
|
||||||
+ "foreign key (data_source_id) references data_sources(id) ON UPDATE SET NULL ON DELETE SET NULL)";
|
+ "foreign key (data_source_id) references data_sources(id) ON UPDATE SET NULL ON DELETE SET NULL)";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the statement String for creating a new data_sources table in a
|
* Get the statement String for creating a new data_sources table in a
|
||||||
* Sqlite central repository.
|
* Sqlite central repository.
|
||||||
|
@ -273,7 +273,6 @@ final class FileSearchData {
|
|||||||
= new ImmutableSet.Builder<String>()
|
= new ImmutableSet.Builder<String>()
|
||||||
.add("text/html", //NON-NLS
|
.add("text/html", //NON-NLS
|
||||||
"text/csv", //NON-NLS
|
"text/csv", //NON-NLS
|
||||||
"text/x-log", //NON-NLS
|
|
||||||
"application/rtf", //NON-NLS
|
"application/rtf", //NON-NLS
|
||||||
"application/pdf", //NON-NLS
|
"application/pdf", //NON-NLS
|
||||||
"application/xhtml+xml", //NON-NLS
|
"application/xhtml+xml", //NON-NLS
|
||||||
|
Loading…
x
Reference in New Issue
Block a user