diff --git a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java index b75f4b7cb1e31068ac184019fa1529f4de7f5eb1..b56b9d350391a2af9d78f21de6dfba6ac8512c9e 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java +++ b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java @@ -94,7 +94,7 @@ public class SleuthkitCase { * tsk/auto/tsk_db.h. */ private static final CaseDbSchemaVersionNumber CURRENT_DB_SCHEMA_VERSION - = new CaseDbSchemaVersionNumber(8, 2); + = new CaseDbSchemaVersionNumber(8, 1); private static final long BASE_ARTIFACT_ID = Long.MIN_VALUE; // Artifact ids will start at the lowest negative value private static final Logger logger = Logger.getLogger(SleuthkitCase.class.getName()); @@ -107,58 +107,56 @@ public class SleuthkitCase { private static final String SQL_ERROR_LIMIT_GROUP = "54"; private static final String SQL_ERROR_INTERNAL_GROUP = "xx"; private static final int MIN_USER_DEFINED_TYPE_ID = 10000; - private static final String[] CORE_TABLE_NAMES = new String[] { - "tsk_db_info", - "tsk_objects", - "tsk_image_info", - "tsk_image_names", - "tsk_vs_info", - "tsk_vs_parts", - "tsk_fs_info", - "tsk_file_layout", - "tsk_files", - "tsk_files_path", - "tsk_files_derived", - "tsk_files_derived_method", - "tag_names", - "content_tags", - "blackboard_artifact_tags", - "blackboard_artifacts", - "blackboard_attributes", - "blackboard_artifact_types", - "blackboard_attribute_types", - "data_source_info", - "file_encoding_types", - "ingest_module_types", - "ingest_job_status_types", - "ingest_modules", - "ingest_jobs", - "ingest_job_modules", - "account_types", - "accounts", - "account_relationships", - "review_statuses", - "reports" }; + private static final String[] CORE_TABLE_NAMES = new String[]{ + "tsk_db_info", + "tsk_objects", + "tsk_image_info", + "tsk_image_names", + "tsk_vs_info", + "tsk_vs_parts", + "tsk_fs_info", + "tsk_file_layout", + "tsk_files", + "tsk_files_path", + "tsk_files_derived", + "tsk_files_derived_method", + "tag_names", + "content_tags", + "blackboard_artifact_tags", + "blackboard_artifacts", + "blackboard_attributes", + "blackboard_artifact_types", + "blackboard_attribute_types", + "data_source_info", + "file_encoding_types", + "ingest_module_types", + "ingest_job_status_types", + "ingest_modules", + "ingest_jobs", + "ingest_job_modules", + "account_types", + "accounts", + "account_relationships", + "review_statuses", + "reports"}; private static final Set<String> CORE_TABLE_NAMES_SET = new HashSet<String>(Arrays.asList(CORE_TABLE_NAMES)); - private static final String[] CORE_INDEX_NAMES = new String[] { - "parObjId", - "layout_objID", - "artifact_objID", - "artifact_artifact_objID", - "artifact_typeID", - "attrsArtifactID", - "mime_type", - "file_extension", - "relationships_account1", - "relationships_account2", - "relationships_relationship_source_obj_id", - "relationships_date_time", - "relationships_relationship_type", - "relationships_data_source_obj_id", - }; + private static final String[] CORE_INDEX_NAMES = new String[]{ + "parObjId", + "layout_objID", + "artifact_objID", + "artifact_artifact_objID", + "artifact_typeID", + "attrsArtifactID", + "mime_type", + "file_extension", + "relationships_account1", + "relationships_account2", + "relationships_relationship_source_obj_id", + "relationships_date_time", + "relationships_relationship_type", + "relationships_data_source_obj_id",}; private static final Set<String> CORE_INDEX_NAMES_SET = new HashSet<String>(Arrays.asList(CORE_INDEX_NAMES)); - - + private final ConnectionPool connections; private final Map<Long, VirtualDirectory> rootIdsToCarvedFileDirs = new HashMap<Long, VirtualDirectory>(); private final Map<Long, FileSystem> fileSystemIdMap = new HashMap<Long, FileSystem>(); // Cache for file system files. @@ -190,7 +188,7 @@ public class SleuthkitCase { private final Object blackboardInstanceLock = new Object(); private Blackboard blackboardInstance = null; private CaseDbAccessManager dbAccessManagerInstance = null; - + private final Map<String, Set<Long>> deviceIdToDatasourceObjIdMap = new HashMap<String, Set<Long>>(); // Cache of frequently used content objects (e.g. data source, file system). @@ -337,7 +335,7 @@ private void init() throws Exception { initReviewStatuses(connection); initEncodingTypes(connection); populateHasChildrenMap(connection); - + updateExaminers(connection); connection.close(); } @@ -350,17 +348,17 @@ private void init() throws Exception { static Set<String> getCoreTableNames() { return CORE_TABLE_NAMES_SET; } - + /** * Returns a set of core index names in the SleuthKit case database. - * + * * @return set of core index names */ static Set<String> getCoreIndexNames() { return CORE_INDEX_NAMES_SET; - + } - + /** * Use the internal map to determine whether the content object has children * (of any type). @@ -435,7 +433,7 @@ public Blackboard getBlackboard() { * Returns an instance of CaseDbAccessManager * * @return CaseDbAccessManager - * + * * @throws org.sleuthkit.datamodel.TskCoreException */ public synchronized CaseDbAccessManager getCaseDbAccessManager() throws TskCoreException { @@ -444,7 +442,7 @@ public synchronized CaseDbAccessManager getCaseDbAccessManager() throws TskCoreE } return dbAccessManagerInstance; } - + /** * Make sure the predefined artifact types are in the artifact types table. * @@ -691,18 +689,19 @@ private void initEncodingTypes(CaseDbConnection connection) throws SQLException, /** * Records the current examiner name in the tsk_examiners table * - * @param CaseDbConnection + * @param CaseDbConnection + * * @throws SQLException * @throws TskCoreException */ private void updateExaminers(CaseDbConnection connection) throws SQLException, TskCoreException { - + String loginName = System.getProperty("user.name"); if (loginName.isEmpty()) { logger.log(Level.SEVERE, "Cannot determine logged in user name"); return; } - + acquireSingleUserCaseWriteLock(); Statement statement = connection.createStatement(); try { @@ -721,13 +720,12 @@ private void updateExaminers(CaseDbConnection connection) throws SQLException, T statement.execute(query); //NON-NLS } catch (SQLException ex) { throw new TskCoreException("Error inserting row in tsk_examiners", ex); - } - finally { + } finally { closeStatement(statement); releaseSingleUserCaseWriteLock(); } } - + /** * Set up or update the hasChildren map using the tsk_objects table. * @@ -856,7 +854,6 @@ private void updateDatabaseSchema(String dbPath) throws Exception { dbSchemaVersion = updateFromSchema7dot1toSchema7dot2(dbSchemaVersion, connection); dbSchemaVersion = updateFromSchema7dot2toSchema8dot0(dbSchemaVersion, connection); dbSchemaVersion = updateFromSchema8dot0toSchema8dot1(dbSchemaVersion, connection); - dbSchemaVersion = updateFromSchema8dot1toSchema8dot2(dbSchemaVersion, connection); statement = connection.createStatement(); connection.executeUpdate(statement, "UPDATE tsk_db_info SET schema_ver = " + dbSchemaVersion.getMajor() + ", schema_minor_ver = " + dbSchemaVersion.getMinor()); //NON-NLS statement.close(); @@ -1590,54 +1587,25 @@ private CaseDbSchemaVersionNumber updateFromSchema8dot0toSchema8dot1(CaseDbSchem Statement statement = connection.createStatement(); acquireSingleUserCaseWriteLock(); try { - statement.execute("ALTER TABLE content_tags ADD COLUMN user_name TEXT DEFAULT NULL"); - statement.execute("ALTER TABLE blackboard_artifact_tags ADD COLUMN user_name TEXT DEFAULT NULL"); - return new CaseDbSchemaVersionNumber(8, 1); - } finally { - closeStatement(statement); - releaseSingleUserCaseWriteLock(); - } - } - /** - * Updates a schema version 8.1 database to a schema version 8.2 database. - * - * @param schemaVersion The current schema version of the database. - * @param connection A connection to the case database. - * - * @return The new database schema version. - * - * @throws SQLException If there is an error completing a database - * operation. - * @throws TskCoreException If there is an error completing a database - * operation via another SleuthkitCase method. - */ - private CaseDbSchemaVersionNumber updateFromSchema8dot1toSchema8dot2(CaseDbSchemaVersionNumber schemaVersion, CaseDbConnection connection) throws SQLException, TskCoreException { - if (schemaVersion.getMajor() != 8) { - return schemaVersion; - } - - if (schemaVersion.getMinor() != 1) { - return schemaVersion; - } - Statement statement = connection.createStatement(); - acquireSingleUserCaseWriteLock(); - try { // create examiners table if (this.dbType.equals(DbType.SQLITE)) { statement.execute("CREATE TABLE tsk_examiners (examiner_id INTEGER PRIMARY KEY, login_name TEXT NOT NULL, display_name TEXT, UNIQUE(login_name) )"); - } - else { + statement.execute("ALTER TABLE content_tags ADD COLUMN examiner_id INTEGER REFERENCES tsk_examiners(examiner_id) DEFAULT NULL"); + statement.execute("ALTER TABLE blackboard_artifact_tags ADD COLUMN examiner_id INTEGER REFERENCES tsk_examiners(examiner_id) DEFAULT NULL"); + } else { statement.execute("CREATE TABLE tsk_examiners (examiner_id BIGSERIAL PRIMARY KEY, login_name TEXT NOT NULL, display_name TEXT, UNIQUE(login_name))"); + statement.execute("ALTER TABLE content_tags ADD COLUMN examiner_id BIGINT REFERENCES tsk_examiners(examiner_id) DEFAULT NULL"); + statement.execute("ALTER TABLE blackboard_artifact_tags ADD COLUMN examiner_id BIGINT REFERENCES tsk_examiners(examiner_id) DEFAULT NULL"); } - - return new CaseDbSchemaVersionNumber(8, 2); + + return new CaseDbSchemaVersionNumber(8, 1); } finally { closeStatement(statement); releaseSingleUserCaseWriteLock(); } } - + /** * Extract the extension from a file name. * @@ -1969,19 +1937,19 @@ private static String createCaseDataBaseName(String candidateDbName) { } /** - * Returns the Examiner object for currently logged in user + * Returns the Examiner object for currently logged in user * * @return A Examiner object. * * @throws org.sleuthkit.datamodel.TskCoreException */ public Examiner getCurrentExaminer() throws TskCoreException { - + String loginName = System.getProperty("user.name"); if (loginName == null || loginName.isEmpty()) { throw new TskCoreException("Failed to determine logged in user name."); } - + CaseDbConnection connection = connections.getConnection(); acquireSingleUserCaseReadLock(); ResultSet resultSet = null; @@ -1992,11 +1960,10 @@ public Examiner getCurrentExaminer() throws TskCoreException { resultSet = connection.executeQuery(statement); if (resultSet.next()) { return new Examiner(resultSet.getLong("examiner_id"), resultSet.getString("login_name"), resultSet.getString("display_name")); - } - else { + } else { throw new TskCoreException("Error getting examaminer for name = " + loginName); } - + } catch (SQLException ex) { throw new TskCoreException("Error getting examaminer for name = " + loginName, ex); } finally { @@ -2005,19 +1972,18 @@ public Examiner getCurrentExaminer() throws TskCoreException { releaseSingleUserCaseReadLock(); } } - - + /** - * Returns the Examiner object for given id - * + * Returns the Examiner object for given id + * * @param id - * - * @return Examiner object - * - * @throws TskCoreException + * + * @return Examiner object + * + * @throws TskCoreException */ Examiner getExaminerById(long id) throws TskCoreException { - + CaseDbConnection connection = connections.getConnection(); acquireSingleUserCaseReadLock(); ResultSet resultSet = null; @@ -2028,8 +1994,7 @@ Examiner getExaminerById(long id) throws TskCoreException { resultSet = connection.executeQuery(statement); if (resultSet.next()) { return new Examiner(resultSet.getLong("examiner_id"), resultSet.getString("login_name"), resultSet.getString("full_name")); - } - else { + } else { throw new TskCoreException("Error getting examaminer for id = " + id); } } catch (SQLException ex) { @@ -2040,7 +2005,7 @@ Examiner getExaminerById(long id) throws TskCoreException { releaseSingleUserCaseReadLock(); } } - + /** * Starts the multi-step process of adding an image data source to the case * by creating an object that can be used to control the process and get @@ -4586,16 +4551,16 @@ public AbstractFile getAbstractFileById(long id) throws TskCoreException { connection.close(); } } - + /** * Get abstract file object from tsk_files table by its id on an existing * connection. - * + * * @param objectId The id of the file object in tsk_files table. * @param connection An open database connection. - * + * * @return AbstractFile object populated, or null if not found. - * + * * @throws TskCoreException thrown if critical error occurred within tsk * core and file could not be queried */ @@ -5839,7 +5804,7 @@ public LocalFile addLocalFile(String fileName, String localPath, long size, long ctime, long crtime, long atime, long mtime, boolean isFile, TskData.EncodingType encodingType, AbstractFile parent) throws TskCoreException { - + CaseDbTransaction localTrans = beginTransaction(); try { LocalFile created = addLocalFile(fileName, localPath, size, ctime, crtime, atime, mtime, isFile, encodingType, parent, localTrans); @@ -5918,7 +5883,7 @@ public LocalFile addLocalFile(String fileName, String localPath, statement.setLong(13, atime); statement.setLong(14, mtime); String parentPath; - + if (parent.getParent() == null && parent.getType().equals(TskData.TSK_DB_FILES_TYPE_ENUM.VIRTUAL_DIR)) { parentPath = "/"; } else { @@ -8012,7 +7977,8 @@ public ContentTag addContentTag(Content content, TagName tagName, String comment acquireSingleUserCaseWriteLock(); ResultSet resultSet = null; try { - // INSERT INTO content_tags (obj_id, tag_name_id, comment, begin_byte_offset, end_byte_offset) VALUES (?, ?, ?, ?, ?) + Examiner currentExaminer = getCurrentExaminer(); + // INSERT INTO content_tags (obj_id, tag_name_id, comment, begin_byte_offset, end_byte_offset, examiner_id) VALUES (?, ?, ?, ?, ?, ?) PreparedStatement statement = connection.getPreparedStatement(PREPARED_STATEMENT.INSERT_CONTENT_TAG, Statement.RETURN_GENERATED_KEYS); statement.clearParameters(); statement.setLong(1, content.getId()); @@ -8020,13 +7986,12 @@ public ContentTag addContentTag(Content content, TagName tagName, String comment statement.setString(3, comment); statement.setLong(4, beginByteOffset); statement.setLong(5, endByteOffset); - String userName = System.getProperty("user.name"); - statement.setString(6, userName); + statement.setLong(6, currentExaminer.getId()); connection.executeUpdate(statement); resultSet = statement.getGeneratedKeys(); resultSet.next(); return new ContentTag(resultSet.getLong(1), //last_insert_rowid() - content, tagName, comment, beginByteOffset, endByteOffset, userName); + content, tagName, comment, beginByteOffset, endByteOffset, currentExaminer.getLoginName()); } catch (SQLException ex) { throw new TskCoreException("Error adding row to content_tags table (obj_id = " + content.getId() + ", tag_name_id = " + tagName.getId() + ")", ex); } finally { @@ -8071,7 +8036,10 @@ public List<ContentTag> getAllContentTags() throws TskCoreException { acquireSingleUserCaseReadLock(); ResultSet resultSet = null; try { - // SELECT * FROM content_tags INNER JOIN tag_names ON content_tags.tag_name_id = tag_names.tag_name_id + // SELECT content_tags.tag_id, content_tags.obj_id, content_tags.tag_name_id, content_tags.comment, content_tags.begin_byte_offset, content_tags.end_byte_offset, tag_names.display_name, tag_names.description, tag_names.color, tag_names.knownStatus, tsk_examiners.login_name + // FROM content_tags + // INNER JOIN tag_names ON content_tags.tag_name_id = tag_names.tag_name_id + // LEFT OUTER JOIN tsk_examiners ON content_tags.examiner_id = tsk_examiners.examiner_id PreparedStatement statement = connection.getPreparedStatement(PREPARED_STATEMENT.SELECT_CONTENT_TAGS); resultSet = connection.executeQuery(statement); ArrayList<ContentTag> tags = new ArrayList<ContentTag>(); @@ -8081,7 +8049,7 @@ public List<ContentTag> getAllContentTags() throws TskCoreException { TskData.FileKnown.valueOf(resultSet.getByte("knownStatus"))); //NON-NLS Content content = getContentById(resultSet.getLong("obj_id")); //NON-NLS tags.add(new ContentTag(resultSet.getLong("tag_id"), content, tagName, resultSet.getString("comment"), - resultSet.getLong("begin_byte_offset"), resultSet.getLong("end_byte_offset"), resultSet.getString("user_name"))); //NON-NLS + resultSet.getLong("begin_byte_offset"), resultSet.getLong("end_byte_offset"), resultSet.getString("login_name"))); //NON-NLS } return tags; } catch (SQLException ex) { @@ -8195,7 +8163,11 @@ public ContentTag getContentTagByID(long contentTagID) throws TskCoreException { ResultSet resultSet = null; ContentTag tag = null; try { - // SELECT * FROM content_tags INNER JOIN tag_names ON content_tags.tag_name_id = tag_names.tag_name_id WHERE tag_id = ? + // SELECT content_tags.tag_id, content_tags.obj_id, content_tags.tag_name_id, content_tags.comment, content_tags.begin_byte_offset, content_tags.end_byte_offset, tag_names.display_name, tag_names.description, tag_names.color, tag_names.knownStatus, tsk_examiners.login_name + // FROM content_tags + // INNER JOIN tag_names ON content_tags.tag_name_id = tag_names.tag_name_id + // UTER LEFT JOIN tsk_examiners ON content_tags.examiner_id = tsk_examiners.examiner_id + // WHERE tag_id = ? PreparedStatement statement = connection.getPreparedStatement(PREPARED_STATEMENT.SELECT_CONTENT_TAG_BY_ID); statement.clearParameters(); statement.setLong(1, contentTagID); @@ -8206,7 +8178,7 @@ public ContentTag getContentTagByID(long contentTagID) throws TskCoreException { resultSet.getString("description"), TagName.HTML_COLOR.getColorByName(resultSet.getString("color")), TskData.FileKnown.valueOf(resultSet.getByte("knownStatus"))); tag = new ContentTag(resultSet.getLong("tag_id"), getContentById(resultSet.getLong("obj_id")), tagName, - resultSet.getString("comment"), resultSet.getLong("begin_byte_offset"), resultSet.getLong("end_byte_offset"), resultSet.getString("user_name")); + resultSet.getString("comment"), resultSet.getLong("begin_byte_offset"), resultSet.getLong("end_byte_offset"), resultSet.getString("login_name")); } resultSet.close(); @@ -8239,7 +8211,10 @@ public List<ContentTag> getContentTagsByTagName(TagName tagName) throws TskCoreE acquireSingleUserCaseReadLock(); ResultSet resultSet = null; try { - // SELECT * FROM content_tags WHERE tag_name_id = ? + // SELECT content_tags.tag_id, content_tags.obj_id, content_tags.tag_name_id, content_tags.comment, content_tags.begin_byte_offset, content_tags.end_byte_offset, tsk_examiners.login_name + // FROM content_tags + // LEFT OUTER JOIN tsk_examiners ON content_tags.examiner_id = tsk_examiners.examiner_id + // WHERE tag_name_id = ? PreparedStatement statement = connection.getPreparedStatement(PREPARED_STATEMENT.SELECT_CONTENT_TAGS_BY_TAG_NAME); statement.clearParameters(); statement.setLong(1, tagName.getId()); @@ -8247,7 +8222,7 @@ public List<ContentTag> getContentTagsByTagName(TagName tagName) throws TskCoreE ArrayList<ContentTag> tags = new ArrayList<ContentTag>(); while (resultSet.next()) { ContentTag tag = new ContentTag(resultSet.getLong("tag_id"), getContentById(resultSet.getLong("obj_id")), - tagName, resultSet.getString("comment"), resultSet.getLong("begin_byte_offset"), resultSet.getLong("end_byte_offset"), resultSet.getString("user_name")); //NON-NLS + tagName, resultSet.getString("comment"), resultSet.getLong("begin_byte_offset"), resultSet.getLong("end_byte_offset"), resultSet.getString("login_name")); //NON-NLS tags.add(tag); } resultSet.close(); @@ -8280,9 +8255,12 @@ public List<ContentTag> getContentTagsByTagName(TagName tagName, long dsObjId) t ResultSet resultSet = null; try { - // "SELECT * FROM content_tags as content_tags, tsk_files as tsk_files WHERE content_tags.obj_id = tsk_files.obj_id" - // + " AND content_tags.tag_name_id = ?" - // + " AND tsk_files.data_source_obj_id = ? " + // SELECT content_tags.tag_id, content_tags.obj_id, content_tags.tag_name_id, content_tags.comment, content_tags.begin_byte_offset, content_tags.end_byte_offset, tag_names.display_name, tag_names.description, tag_names.color, tag_names.knownStatus, tsk_examiners.login_name + // FROM content_tags as content_tags, tsk_files as tsk_files + // LEFT OUTER JOIN tsk_examiners ON content_tags.examiner_id = tsk_examiners.examiner_id + // WHERE content_tags.obj_id = tsk_files.obj_id + // AND content_tags.tag_name_id = ? + // AND tsk_files.data_source_obj_id = ? PreparedStatement statement = connection.getPreparedStatement(PREPARED_STATEMENT.SELECT_CONTENT_TAGS_BY_TAG_NAME_BY_DATASOURCE); statement.clearParameters(); statement.setLong(1, tagName.getId()); @@ -8291,7 +8269,7 @@ public List<ContentTag> getContentTagsByTagName(TagName tagName, long dsObjId) t ArrayList<ContentTag> tags = new ArrayList<ContentTag>(); while (resultSet.next()) { ContentTag tag = new ContentTag(resultSet.getLong("tag_id"), getContentById(resultSet.getLong("obj_id")), - tagName, resultSet.getString("comment"), resultSet.getLong("begin_byte_offset"), resultSet.getLong("end_byte_offset"), resultSet.getString("user_name")); //NON-NLS + tagName, resultSet.getString("comment"), resultSet.getLong("begin_byte_offset"), resultSet.getLong("end_byte_offset"), resultSet.getString("login_name")); //NON-NLS tags.add(tag); } resultSet.close(); @@ -8321,7 +8299,11 @@ public List<ContentTag> getContentTagsByContent(Content content) throws TskCoreE acquireSingleUserCaseReadLock(); ResultSet resultSet = null; try { - // SELECT * FROM content_tags INNER JOIN tag_names ON content_tags.tag_name_id = tag_names.tag_name_id WHERE content_tags.obj_id = ? + // SELECT content_tags.tag_id, content_tags.obj_id, content_tags.tag_name_id, content_tags.comment, content_tags.begin_byte_offset, content_tags.end_byte_offset, tag_names.display_name, tag_names.description, tag_names.color, tag_names.knownStatus, tsk_examiners.login_name + // FROM content_tags + // INNER JOIN tag_names ON content_tags.tag_name_id = tag_names.tag_name_id + // LEFT OUTER JOIN tsk_examiners ON content_tags.examiner_id = tsk_examiners.examiner_id + // WHERE content_tags.obj_id = ? PreparedStatement statement = connection.getPreparedStatement(PREPARED_STATEMENT.SELECT_CONTENT_TAGS_BY_CONTENT); statement.clearParameters(); statement.setLong(1, content.getId()); @@ -8332,7 +8314,7 @@ public List<ContentTag> getContentTagsByContent(Content content) throws TskCoreE resultSet.getString("description"), TagName.HTML_COLOR.getColorByName(resultSet.getString("color")), TskData.FileKnown.valueOf(resultSet.getByte("knownStatus"))); //NON-NLS ContentTag tag = new ContentTag(resultSet.getLong("tag_id"), content, tagName, - resultSet.getString("comment"), resultSet.getLong("begin_byte_offset"), resultSet.getLong("end_byte_offset"), resultSet.getString("user_name")); //NON-NLS + resultSet.getString("comment"), resultSet.getLong("begin_byte_offset"), resultSet.getLong("end_byte_offset"), resultSet.getString("login_name")); //NON-NLS tags.add(tag); } return tags; @@ -8363,19 +8345,19 @@ public BlackboardArtifactTag addBlackboardArtifactTag(BlackboardArtifact artifac acquireSingleUserCaseWriteLock(); ResultSet resultSet = null; try { - // INSERT INTO blackboard_artifact_tags (artifact_id, tag_name_id, comment, begin_byte_offset, end_byte_offset) VALUES (?, ?, ?, ?, ?) + Examiner currentExaminer= getCurrentExaminer(); + // "INSERT INTO blackboard_artifact_tags (artifact_id, tag_name_id, comment, examiner_id) VALUES (?, ?, ?, ?)"), //NON-NLS PreparedStatement statement = connection.getPreparedStatement(PREPARED_STATEMENT.INSERT_ARTIFACT_TAG, Statement.RETURN_GENERATED_KEYS); statement.clearParameters(); statement.setLong(1, artifact.getArtifactID()); statement.setLong(2, tagName.getId()); statement.setString(3, comment); - String userName = System.getProperty("user.name"); - statement.setString(4, userName); + statement.setLong(4, currentExaminer.getId()); connection.executeUpdate(statement); resultSet = statement.getGeneratedKeys(); resultSet.next(); return new BlackboardArtifactTag(resultSet.getLong(1), //last_insert_rowid() - artifact, getContentById(artifact.getObjectID()), tagName, comment, userName); + artifact, getContentById(artifact.getObjectID()), tagName, comment, currentExaminer.getLoginName()); } catch (SQLException ex) { throw new TskCoreException("Error adding row to blackboard_artifact_tags table (obj_id = " + artifact.getArtifactID() + ", tag_name_id = " + tagName.getId() + ")", ex); } finally { @@ -8421,7 +8403,10 @@ public List<BlackboardArtifactTag> getAllBlackboardArtifactTags() throws TskCore acquireSingleUserCaseReadLock(); ResultSet resultSet = null; try { - // SELECT * FROM blackboard_artifact_tags INNER JOIN tag_names ON blackboard_artifact_tags.tag_name_id = tag_names.tag_name_id + // SELECT blackboard_artifact_tags.tag_id, blackboard_artifact_tags.artifact_id, blackboard_artifact_tags.tag_name_id, blackboard_artifact_tags.comment, tag_names.display_name, tag_names.description, tag_names.color, tag_names.knownStatus, tsk_examiners.login_name + // FROM blackboard_artifact_tags + // INNER JOIN tag_names ON blackboard_artifact_tags.tag_name_id = tag_names.tag_name_id + // LEFT OUTER JOIN tsk_examiners ON blackboard_artifact_tags.examiner_id = tsk_examiners.examiner_id PreparedStatement statement = connection.getPreparedStatement(PREPARED_STATEMENT.SELECT_ARTIFACT_TAGS); resultSet = connection.executeQuery(statement); ArrayList<BlackboardArtifactTag> tags = new ArrayList<BlackboardArtifactTag>(); @@ -8432,7 +8417,7 @@ public List<BlackboardArtifactTag> getAllBlackboardArtifactTags() throws TskCore BlackboardArtifact artifact = getBlackboardArtifact(resultSet.getLong("artifact_id")); //NON-NLS Content content = getContentById(artifact.getObjectID()); BlackboardArtifactTag tag = new BlackboardArtifactTag(resultSet.getLong("tag_id"), - artifact, content, tagName, resultSet.getString("comment"), resultSet.getString("user_name")); //NON-NLS + artifact, content, tagName, resultSet.getString("comment"), resultSet.getString("login_name")); //NON-NLS tags.add(tag); } return tags; @@ -8547,7 +8532,10 @@ public List<BlackboardArtifactTag> getBlackboardArtifactTagsByTagName(TagName ta acquireSingleUserCaseReadLock(); ResultSet resultSet = null; try { - // SELECT * FROM blackboard_artifact_tags WHERE tag_name_id = ? + // SELECT blackboard_artifact_tags.tag_id, blackboard_artifact_tags.artifact_id, blackboard_artifact_tags.tag_name_id, blackboard_artifact_tags.comment, tsk_examiners.login_name + // FROM blackboard_artifact_tags + // LEFT OUTER JOIN tsk_examiners ON blackboard_artifact_tags.examiner_id = tsk_examiners.examiner_id + // WHERE tag_name_id = ? PreparedStatement statement = connection.getPreparedStatement(PREPARED_STATEMENT.SELECT_ARTIFACT_TAGS_BY_TAG_NAME); statement.clearParameters(); statement.setLong(1, tagName.getId()); @@ -8557,7 +8545,7 @@ public List<BlackboardArtifactTag> getBlackboardArtifactTagsByTagName(TagName ta BlackboardArtifact artifact = getBlackboardArtifact(resultSet.getLong("artifact_id")); //NON-NLS Content content = getContentById(artifact.getObjectID()); BlackboardArtifactTag tag = new BlackboardArtifactTag(resultSet.getLong("tag_id"), - artifact, content, tagName, resultSet.getString("comment"), resultSet.getString("user_name")); //NON-NLS + artifact, content, tagName, resultSet.getString("comment"), resultSet.getString("login_name")); //NON-NLS tags.add(tag); } return tags; @@ -8594,9 +8582,12 @@ public List<BlackboardArtifactTag> getBlackboardArtifactTagsByTagName(TagName ta acquireSingleUserCaseReadLock(); ResultSet resultSet = null; try { - // "SELECT * FROM blackboard_artifact_tags as artifact_tags, blackboard_artifacts AS arts WHERE artifact_tags.artifact_id = arts.artifact_id" - // + " AND artifact_tags.tag_name_id = ? " - // + " AND arts.data_source_obj_id = ? " + // SELECT SELECT artifact_tags.tag_id, artifact_tags.artifact_id, artifact_tags.tag_name_id, artifact_tags.comment, arts.obj_id, arts.artifact_obj_id, arts.data_source_obj_id, arts.artifact_type_id, arts.review_status_id, tsk_examiners.login_name + // FROM blackboard_artifact_tags as artifact_tags, blackboard_artifacts AS arts + // LEFT OUTER JOIN tsk_examiners ON artifact_tags.examiner_id = tsk_examiners.examiner_id + // WHERE artifact_tags.artifact_id = arts.artifact_id + // AND artifact_tags.tag_name_id = ? + // AND arts.data_source_obj_id = ? PreparedStatement statement = connection.getPreparedStatement(PREPARED_STATEMENT.SELECT_ARTIFACT_TAGS_BY_TAG_NAME_BY_DATASOURCE); statement.clearParameters(); statement.setLong(1, tagName.getId()); @@ -8607,7 +8598,7 @@ public List<BlackboardArtifactTag> getBlackboardArtifactTagsByTagName(TagName ta BlackboardArtifact artifact = getBlackboardArtifact(resultSet.getLong("artifact_id")); //NON-NLS Content content = getContentById(artifact.getObjectID()); BlackboardArtifactTag tag = new BlackboardArtifactTag(resultSet.getLong("tag_id"), - artifact, content, tagName, resultSet.getString("comment"), resultSet.getString("user_name")); //NON-NLS + artifact, content, tagName, resultSet.getString("comment"), resultSet.getString("login_name")); //NON-NLS tags.add(tag); } return tags; @@ -8639,7 +8630,11 @@ public BlackboardArtifactTag getBlackboardArtifactTagByID(long artifactTagID) th ResultSet resultSet = null; BlackboardArtifactTag tag = null; try { - // SELECT * FROM blackboard_artifact_tags INNER JOIN tag_names ON blackboard_artifact_tags.tag_name_id = tag_names.tag_name_id WHERE blackboard_artifact_tags.tag_id = ? + //SELECT blackboard_artifact_tags.tag_id, blackboard_artifact_tags.artifact_id, blackboard_artifact_tags.tag_name_id, blackboard_artifact_tags.comment, tag_names.display_name, tag_names.description, tag_names.color, tag_names.knownStatus, tsk_examiners.login_name + // FROM blackboard_artifact_tags + // INNER JOIN tag_names ON blackboard_artifact_tags.tag_name_id = tag_names.tag_name_id + // LEFT OUTER JOIN tsk_examiners ON blackboard_artifact_tags.examiner_id = tsk_examiners.examiner_id + // WHERE blackboard_artifact_tags.tag_id = ? PreparedStatement statement = connection.getPreparedStatement(PREPARED_STATEMENT.SELECT_ARTIFACT_TAG_BY_ID); statement.clearParameters(); statement.setLong(1, artifactTagID); @@ -8652,7 +8647,7 @@ public BlackboardArtifactTag getBlackboardArtifactTagByID(long artifactTagID) th BlackboardArtifact artifact = getBlackboardArtifact(resultSet.getLong("artifact_id")); //NON-NLS Content content = getContentById(artifact.getObjectID()); tag = new BlackboardArtifactTag(resultSet.getLong("tag_id"), - artifact, content, tagName, resultSet.getString("comment"), resultSet.getString("user_name")); + artifact, content, tagName, resultSet.getString("comment"), resultSet.getString("login_name")); } resultSet.close(); @@ -8683,7 +8678,11 @@ public List<BlackboardArtifactTag> getBlackboardArtifactTagsByArtifact(Blackboar acquireSingleUserCaseReadLock(); ResultSet resultSet = null; try { - // SELECT * FROM blackboard_artifact_tags INNER JOIN tag_names ON blackboard_artifact_tags.tag_name_id = tag_names.tag_name_id WHERE blackboard_artifact_tags.artifact_id = ? + // SELECT blackboard_artifact_tags.tag_id, blackboard_artifact_tags.artifact_id, blackboard_artifact_tags.tag_name_id, blackboard_artifact_tags.comment, tag_names.display_name, tag_names.description, tag_names.color, tag_names.knownStatus, tsk_examiners.login_name + // FROM blackboard_artifact_tags + // INNER JOIN tag_names ON blackboard_artifact_tags.tag_name_id = tag_names.tag_name_id + // LEFT OUTER JOIN tsk_examiners ON blackboard_artifact_tags.examiner_id = tsk_examiners.examiner_id + // WHERE blackboard_artifact_tags.artifact_id = ? PreparedStatement statement = connection.getPreparedStatement(PREPARED_STATEMENT.SELECT_ARTIFACT_TAGS_BY_ARTIFACT); statement.clearParameters(); statement.setLong(1, artifact.getArtifactID()); @@ -8695,7 +8694,7 @@ public List<BlackboardArtifactTag> getBlackboardArtifactTagsByArtifact(Blackboar TskData.FileKnown.valueOf(resultSet.getByte("knownStatus"))); //NON-NLS Content content = getContentById(artifact.getObjectID()); BlackboardArtifactTag tag = new BlackboardArtifactTag(resultSet.getLong("tag_id"), - artifact, content, tagName, resultSet.getString("comment"), resultSet.getString("user_name")); //NON-NLS + artifact, content, tagName, resultSet.getString("comment"), resultSet.getString("login_name")); //NON-NLS tags.add(tag); } return tags; @@ -9290,7 +9289,7 @@ private enum PREPARED_STATEMENT { + " AND arts.data_source_obj_id = ?" + " )"), INSERT_TAG_NAME("INSERT INTO tag_names (display_name, description, color, knownStatus) VALUES (?, ?, ?, ?)"), //NON-NLS - INSERT_CONTENT_TAG("INSERT INTO content_tags (obj_id, tag_name_id, comment, begin_byte_offset, end_byte_offset, user_name) VALUES (?, ?, ?, ?, ?, ?)"), //NON-NLS + INSERT_CONTENT_TAG("INSERT INTO content_tags (obj_id, tag_name_id, comment, begin_byte_offset, end_byte_offset, examiner_id) VALUES (?, ?, ?, ?, ?, ?)"), //NON-NLS DELETE_CONTENT_TAG("DELETE FROM content_tags WHERE tag_id = ?"), //NON-NLS COUNT_CONTENT_TAGS_BY_TAG_NAME("SELECT COUNT(*) AS count FROM content_tags WHERE tag_name_id = ?"), //NON-NLS COUNT_CONTENT_TAGS_BY_TAG_NAME_BY_DATASOURCE( @@ -9298,27 +9297,61 @@ private enum PREPARED_STATEMENT { + " AND content_tags.tag_name_id = ? " + " AND tsk_files.data_source_obj_id = ? " ), - SELECT_CONTENT_TAGS("SELECT * FROM content_tags INNER JOIN tag_names ON content_tags.tag_name_id = tag_names.tag_name_id"), //NON-NLS - SELECT_CONTENT_TAGS_BY_TAG_NAME("SELECT * FROM content_tags WHERE tag_name_id = ?"), //NON-NLS - SELECT_CONTENT_TAGS_BY_TAG_NAME_BY_DATASOURCE( - "SELECT * FROM content_tags as content_tags, tsk_files as tsk_files WHERE content_tags.obj_id = tsk_files.obj_id" + SELECT_CONTENT_TAGS("SELECT content_tags.tag_id, content_tags.obj_id, content_tags.tag_name_id, content_tags.comment, content_tags.begin_byte_offset, content_tags.end_byte_offset, tag_names.display_name, tag_names.description, tag_names.color, tag_names.knownStatus, tsk_examiners.login_name " + + "FROM content_tags " + + "INNER JOIN tag_names ON content_tags.tag_name_id = tag_names.tag_name_id " + + "LEFT OUTER JOIN tsk_examiners ON content_tags.examiner_id = tsk_examiners.examiner_id"), //NON-NLS + SELECT_CONTENT_TAGS_BY_TAG_NAME("SELECT content_tags.tag_id, content_tags.obj_id, content_tags.tag_name_id, content_tags.comment, content_tags.begin_byte_offset, content_tags.end_byte_offset, tsk_examiners.login_name " + + "FROM content_tags " + + "LEFT OUTER JOIN tsk_examiners ON content_tags.examiner_id = tsk_examiners.examiner_id " + + "WHERE tag_name_id = ?"), //NON-NLS + SELECT_CONTENT_TAGS_BY_TAG_NAME_BY_DATASOURCE("SELECT content_tags.tag_id, content_tags.obj_id, content_tags.tag_name_id, content_tags.comment, content_tags.begin_byte_offset, content_tags.end_byte_offset, tag_names.display_name, tag_names.description, tag_names.color, tag_names.knownStatus, tsk_examiners.login_name " + + "FROM content_tags as content_tags, tsk_files as tsk_files " + + "LEFT OUTER JOIN tsk_examiners ON content_tags.examiner_id = tsk_examiners.examiner_id " + + "WHERE content_tags.obj_id = tsk_files.obj_id" + " AND content_tags.tag_name_id = ?" + " AND tsk_files.data_source_obj_id = ? "), - SELECT_CONTENT_TAG_BY_ID("SELECT * FROM content_tags INNER JOIN tag_names ON content_tags.tag_name_id = tag_names.tag_name_id WHERE tag_id = ?"), //NON-NLS - SELECT_CONTENT_TAGS_BY_CONTENT("SELECT * FROM content_tags INNER JOIN tag_names ON content_tags.tag_name_id = tag_names.tag_name_id WHERE content_tags.obj_id = ?"), //NON-NLS - INSERT_ARTIFACT_TAG("INSERT INTO blackboard_artifact_tags (artifact_id, tag_name_id, comment, user_name) VALUES (?, ?, ?, ?)"), //NON-NLS + SELECT_CONTENT_TAG_BY_ID("SELECT content_tags.tag_id, content_tags.obj_id, content_tags.tag_name_id, content_tags.comment, content_tags.begin_byte_offset, content_tags.end_byte_offset, tag_names.display_name, tag_names.description, tag_names.color, tag_names.knownStatus, tsk_examiners.login_name " + + "FROM content_tags " + + "INNER JOIN tag_names ON content_tags.tag_name_id = tag_names.tag_name_id " + + "LEFT OUTER JOIN tsk_examiners ON content_tags.examiner_id = tsk_examiners.examiner_id " + + "WHERE tag_id = ?"), //NON-NLS + SELECT_CONTENT_TAGS_BY_CONTENT("SELECT content_tags.tag_id, content_tags.obj_id, content_tags.tag_name_id, content_tags.comment, content_tags.begin_byte_offset, content_tags.end_byte_offset, tag_names.display_name, tag_names.description, tag_names.color, tag_names.knownStatus, tsk_examiners.login_name " + + "FROM content_tags " + + "INNER JOIN tag_names ON content_tags.tag_name_id = tag_names.tag_name_id " + + "LEFT OUTER JOIN tsk_examiners ON content_tags.examiner_id = tsk_examiners.examiner_id " + + "WHERE content_tags.obj_id = ?"), //NON-NLS + INSERT_ARTIFACT_TAG("INSERT INTO blackboard_artifact_tags (artifact_id, tag_name_id, comment, examiner_id) " + + "VALUES (?, ?, ?, ?)"), //NON-NLS DELETE_ARTIFACT_TAG("DELETE FROM blackboard_artifact_tags WHERE tag_id = ?"), //NON-NLS - SELECT_ARTIFACT_TAGS("SELECT * FROM blackboard_artifact_tags INNER JOIN tag_names ON blackboard_artifact_tags.tag_name_id = tag_names.tag_name_id"), //NON-NLS + SELECT_ARTIFACT_TAGS("SELECT blackboard_artifact_tags.tag_id, blackboard_artifact_tags.artifact_id, blackboard_artifact_tags.tag_name_id, blackboard_artifact_tags.comment, tag_names.display_name, tag_names.description, tag_names.color, tag_names.knownStatus, tsk_examiners.login_name " + + "FROM blackboard_artifact_tags " + + "INNER JOIN tag_names ON blackboard_artifact_tags.tag_name_id = tag_names.tag_name_id " + + "LEFT OUTER JOIN tsk_examiners ON blackboard_artifact_tags.examiner_id = tsk_examiners.examiner_id"), //NON-NLS COUNT_ARTIFACTS_BY_TAG_NAME("SELECT COUNT(*) AS count FROM blackboard_artifact_tags WHERE tag_name_id = ?"), //NON-NLS COUNT_ARTIFACTS_BY_TAG_NAME_BY_DATASOURCE("SELECT COUNT(*) AS count FROM blackboard_artifact_tags as artifact_tags, blackboard_artifacts AS arts WHERE artifact_tags.artifact_id = arts.artifact_id" + " AND artifact_tags.tag_name_id = ?" + " AND arts.data_source_obj_id = ? "), - SELECT_ARTIFACT_TAGS_BY_TAG_NAME("SELECT * FROM blackboard_artifact_tags WHERE tag_name_id = ?"), //NON-NLS - SELECT_ARTIFACT_TAGS_BY_TAG_NAME_BY_DATASOURCE("SELECT * FROM blackboard_artifact_tags as artifact_tags, blackboard_artifacts AS arts WHERE artifact_tags.artifact_id = arts.artifact_id" + SELECT_ARTIFACT_TAGS_BY_TAG_NAME("SELECT blackboard_artifact_tags.tag_id, blackboard_artifact_tags.artifact_id, blackboard_artifact_tags.tag_name_id, blackboard_artifact_tags.comment, tsk_examiners.login_name " + + "FROM blackboard_artifact_tags " + + "LEFT OUTER JOIN tsk_examiners ON blackboard_artifact_tags.examiner_id = tsk_examiners.examiner_id " + + "WHERE tag_name_id = ?"), //NON-NLS + SELECT_ARTIFACT_TAGS_BY_TAG_NAME_BY_DATASOURCE("SELECT SELECT artifact_tags.tag_id, artifact_tags.artifact_id, artifact_tags.tag_name_id, artifact_tags.comment, arts.obj_id, arts.artifact_obj_id, arts.data_source_obj_id, arts.artifact_type_id, arts.review_status_id, tsk_examiners.login_name " + + "FROM blackboard_artifact_tags as artifact_tags, blackboard_artifacts AS arts " + + "LEFT OUTER JOIN tsk_examiners ON artifact_tags.examiner_id = tsk_examiners.examiner_id " + + "WHERE artifact_tags.artifact_id = arts.artifact_id" + " AND artifact_tags.tag_name_id = ? " + " AND arts.data_source_obj_id = ? "), - SELECT_ARTIFACT_TAG_BY_ID("SELECT * FROM blackboard_artifact_tags INNER JOIN tag_names ON blackboard_artifact_tags.tag_name_id = tag_names.tag_name_id WHERE blackboard_artifact_tags.tag_id = ?"), //NON-NLS - SELECT_ARTIFACT_TAGS_BY_ARTIFACT("SELECT * FROM blackboard_artifact_tags INNER JOIN tag_names ON blackboard_artifact_tags.tag_name_id = tag_names.tag_name_id WHERE blackboard_artifact_tags.artifact_id = ?"), //NON-NLS + SELECT_ARTIFACT_TAG_BY_ID("SELECT blackboard_artifact_tags.tag_id, blackboard_artifact_tags.artifact_id, blackboard_artifact_tags.tag_name_id, blackboard_artifact_tags.comment, tag_names.display_name, tag_names.description, tag_names.color, tag_names.knownStatus, tsk_examiners.login_name " + + "FROM blackboard_artifact_tags " + + "INNER JOIN tag_names ON blackboard_artifact_tags.tag_name_id = tag_names.tag_name_id " + + "LEFT OUTER JOIN tsk_examiners ON blackboard_artifact_tags.examiner_id = tsk_examiners.examiner_id " + + "WHERE blackboard_artifact_tags.tag_id = ?"), //NON-NLS + SELECT_ARTIFACT_TAGS_BY_ARTIFACT("SELECT blackboard_artifact_tags.tag_id, blackboard_artifact_tags.artifact_id, blackboard_artifact_tags.tag_name_id, blackboard_artifact_tags.comment, tag_names.display_name, tag_names.description, tag_names.color, tag_names.knownStatus, tsk_examiners.login_name " + + "FROM blackboard_artifact_tags " + + "INNER JOIN tag_names ON blackboard_artifact_tags.tag_name_id = tag_names.tag_name_id " + + "LEFT OUTER JOIN tsk_examiners ON blackboard_artifact_tags.examiner_id = tsk_examiners.examiner_id " + + "WHERE blackboard_artifact_tags.artifact_id = ?"), //NON-NLS SELECT_REPORTS("SELECT * FROM reports"), //NON-NLS SELECT_REPORT_BY_ID("SELECT * FROM reports WHERE obj_id = ?"), //NON-NLS INSERT_REPORT("INSERT INTO reports (obj_id, path, crtime, src_module_name, report_name) VALUES (?, ?, ?, ?, ?)"), //NON-NLS @@ -9341,7 +9374,6 @@ private enum PREPARED_STATEMENT { SELECT_EXAMINER_BY_ID("SELECT * FROM tsk_examiners WHERE examiner_id = ?"), SELECT_EXAMINER_BY_LOGIN_NAME("SELECT * FROM tsk_examiners WHERE login_name = ?"); private final String sql; - private PREPARED_STATEMENT(String sql) { this.sql = sql; @@ -9904,16 +9936,16 @@ private CaseDbTransaction(SleuthkitCase sleuthkitCase, CaseDbConnection connecti CaseDbConnection getConnection() { return this.connection; } - + /** - * Obtain a write lock for this transaction. Only one - * will be obtained (no matter how many times it is called) - * and will be released when commit or rollback is called. - * - * If this is not used, you risk deadlock because this transaction - * can lock up SQLite and make it "busy" and another thread may get - * a write lock to the DB, but not be able to do anything because the - * DB is busy. + * Obtain a write lock for this transaction. Only one will be obtained + * (no matter how many times it is called) and will be released when + * commit or rollback is called. + * + * If this is not used, you risk deadlock because this transaction can + * lock up SQLite and make it "busy" and another thread may get a write + * lock to the DB, but not be able to do anything because the DB is + * busy. */ void acquireSingleUserCaseWriteLock() { if (!hasWriteLock) { diff --git a/tsk/auto/db_postgresql.cpp b/tsk/auto/db_postgresql.cpp index c1dbf35cd39c4d2a4d5af4675e62ab4b1ff76895..ab219d0cc1f4da25ce5344c9a34bfc8ac9b7271d 100755 --- a/tsk/auto/db_postgresql.cpp +++ b/tsk/auto/db_postgresql.cpp @@ -536,10 +536,6 @@ int TskDbPostgreSQL::initialize() { || attempt_exec("CREATE TABLE tag_names (tag_name_id BIGSERIAL PRIMARY KEY, display_name TEXT UNIQUE, description TEXT NOT NULL, color TEXT NOT NULL, knownStatus INTEGER NOT NULL)","Error creating tag_names table: %s\n") || - attempt_exec("CREATE TABLE content_tags (tag_id BIGSERIAL PRIMARY KEY, obj_id BIGINT NOT NULL, tag_name_id BIGINT NOT NULL, comment TEXT NOT NULL, begin_byte_offset BIGINT NOT NULL, end_byte_offset BIGINT NOT NULL, user_name TEXT, " - "FOREIGN KEY(obj_id) REFERENCES tsk_objects(obj_id), FOREIGN KEY(tag_name_id) REFERENCES tag_names(tag_name_id))", - "Error creating content_tags table: %s\n") - || attempt_exec("CREATE TABLE blackboard_artifact_types (artifact_type_id BIGSERIAL PRIMARY KEY, type_name TEXT NOT NULL, display_name TEXT)","Error creating blackboard_artifact_types table: %s\n") || attempt_exec("CREATE TABLE blackboard_attribute_types (attribute_type_id BIGSERIAL PRIMARY KEY, type_name TEXT NOT NULL, display_name TEXT, value_type INTEGER NOT NULL)","Error creating blackboard_attribute_types table: %s\n") @@ -564,10 +560,6 @@ int TskDbPostgreSQL::initialize() { || attempt_exec("ALTER SEQUENCE blackboard_artifacts_artifact_id_seq minvalue -9223372036854775808 restart with -9223372036854775808", "Error setting starting value for artifact_id: %s\n") || - attempt_exec("CREATE TABLE blackboard_artifact_tags (tag_id BIGSERIAL PRIMARY KEY, artifact_id BIGINT NOT NULL, tag_name_id BIGINT NOT NULL, comment TEXT NOT NULL, user_name TEXT, " - "FOREIGN KEY(artifact_id) REFERENCES blackboard_artifacts(artifact_id), FOREIGN KEY(tag_name_id) REFERENCES tag_names(tag_name_id))", - "Error creating blackboard_artifact_tags table: %s\n") - || /* Binary representation of BYTEA is a bunch of bytes, which could * include embedded nulls so we have to pay attention to field length. * http://www.postgresql.org/docs/9.4/static/libpq-example.html @@ -620,7 +612,17 @@ int TskDbPostgreSQL::initialize() { || attempt_exec ("CREATE TABLE tsk_examiners (examiner_id BIGSERIAL PRIMARY KEY, login_name TEXT NOT NULL, display_name TEXT, UNIQUE(login_name))", - "Error creating tsk_examiners table: %s\n") ){ + "Error creating tsk_examiners table: %s\n") + || + attempt_exec + ("CREATE TABLE content_tags (tag_id BIGSERIAL PRIMARY KEY, obj_id BIGINT NOT NULL, tag_name_id BIGINT NOT NULL, comment TEXT NOT NULL, begin_byte_offset BIGINT NOT NULL, end_byte_offset BIGINT NOT NULL, examiner_id BIGINT, " + "FOREIGN KEY(examiner_id) REFERENCES tsk_examiners(examiner_id), FOREIGN KEY(obj_id) REFERENCES tsk_objects(obj_id), FOREIGN KEY(tag_name_id) REFERENCES tag_names(tag_name_id))", + "Error creating content_tags table: %s\n") + || + attempt_exec + ("CREATE TABLE blackboard_artifact_tags (tag_id BIGSERIAL PRIMARY KEY, artifact_id BIGINT NOT NULL, tag_name_id BIGINT NOT NULL, comment TEXT NOT NULL, examiner_id BIGINT, " + "FOREIGN KEY(examiner_id) REFERENCES tsk_examiners(examiner_id), FOREIGN KEY(artifact_id) REFERENCES blackboard_artifacts(artifact_id), FOREIGN KEY(tag_name_id) REFERENCES tag_names(tag_name_id))", + "Error creating blackboard_artifact_tags table: %s\n")){ return 1; } diff --git a/tsk/auto/db_sqlite.cpp b/tsk/auto/db_sqlite.cpp index 88df25f062d45d82d8f3355a7a1522ca13ea89aa..0ec44d14406d46a8404c203b1c000cc549572747 100755 --- a/tsk/auto/db_sqlite.cpp +++ b/tsk/auto/db_sqlite.cpp @@ -298,16 +298,6 @@ int attempt_exec ("CREATE TABLE tag_names (tag_name_id INTEGER PRIMARY KEY, display_name TEXT UNIQUE, description TEXT NOT NULL, color TEXT NOT NULL, knownStatus INTEGER NOT NULL)", "Error creating tag_names table: %s\n") - || - attempt_exec - ("CREATE TABLE content_tags (tag_id INTEGER PRIMARY KEY, obj_id INTEGER NOT NULL, tag_name_id INTEGER NOT NULL, comment TEXT NOT NULL, begin_byte_offset INTEGER NOT NULL, end_byte_offset INTEGER NOT NULL, user_name TEXT, " - "FOREIGN KEY(obj_id) REFERENCES tsk_objects(obj_id), FOREIGN KEY(tag_name_id) REFERENCES tag_names(tag_name_id))", - "Error creating content_tags table: %s\n") - || - attempt_exec - ("CREATE TABLE blackboard_artifact_tags (tag_id INTEGER PRIMARY KEY, artifact_id INTEGER NOT NULL, tag_name_id INTEGER NOT NULL, comment TEXT NOT NULL, user_name TEXT, " - "FOREIGN KEY(artifact_id) REFERENCES blackboard_artifacts(artifact_id), FOREIGN KEY(tag_name_id) REFERENCES tag_names(tag_name_id))", - "Error creating blackboard_artifact_tags table: %s\n") || attempt_exec("CREATE TABLE review_statuses (review_status_id INTEGER PRIMARY KEY, " "review_status_name TEXT NOT NULL, " @@ -380,7 +370,17 @@ int || attempt_exec ("CREATE TABLE tsk_examiners (examiner_id INTEGER PRIMARY KEY, login_name TEXT NOT NULL, display_name TEXT, UNIQUE(login_name))", - "Error creating tsk_examiners table: %s\n") ) { + "Error creating tsk_examiners table: %s\n") + || + attempt_exec + ("CREATE TABLE content_tags (tag_id INTEGER PRIMARY KEY, obj_id INTEGER NOT NULL, tag_name_id INTEGER NOT NULL, comment TEXT NOT NULL, begin_byte_offset INTEGER NOT NULL, end_byte_offset INTEGER NOT NULL, examiner_id INTEGER, " + "FOREIGN KEY(examiner_id) REFERENCES tsk_examiners(examiner_id), FOREIGN KEY(obj_id) REFERENCES tsk_objects(obj_id), FOREIGN KEY(tag_name_id) REFERENCES tag_names(tag_name_id))", + "Error creating content_tags table: %s\n") + || + attempt_exec + ("CREATE TABLE blackboard_artifact_tags (tag_id INTEGER PRIMARY KEY, artifact_id INTEGER NOT NULL, tag_name_id INTEGER NOT NULL, comment TEXT NOT NULL, examiner_id INTEGER, " + "FOREIGN KEY(examiner_id) REFERENCES tsk_examiners(examiner_id), FOREIGN KEY(artifact_id) REFERENCES blackboard_artifacts(artifact_id), FOREIGN KEY(tag_name_id) REFERENCES tag_names(tag_name_id))", + "Error creating blackboard_artifact_tags table: %s\n")) { return 1; } diff --git a/tsk/auto/tsk_db.h b/tsk/auto/tsk_db.h index 3a78f56b7b2503a351b423335db2aad46a593e01..6c879043e8efd96bde37620c0be066b0836c6af9 100755 --- a/tsk/auto/tsk_db.h +++ b/tsk/auto/tsk_db.h @@ -29,7 +29,7 @@ using std::vector; using std::string; #define TSK_SCHEMA_VER 8 -#define TSK_SCHEMA_MINOR_VER 2 +#define TSK_SCHEMA_MINOR_VER 1 /** * Values for the type column in the tsk_objects table.