19 package org.sleuthkit.autopsy.casemodule;
 
   22 import java.io.IOException;
 
   23 import java.nio.file.Path;
 
   24 import java.nio.file.Paths;
 
   25 import java.sql.Connection;
 
   26 import java.sql.DriverManager;
 
   27 import java.sql.PreparedStatement;
 
   28 import java.sql.ResultSet;
 
   29 import java.sql.ResultSetMetaData;
 
   30 import java.sql.SQLException;
 
   31 import java.sql.Statement;
 
   32 import java.text.SimpleDateFormat;
 
   33 import java.util.Date;
 
   34 import org.apache.commons.io.FileUtils;
 
   35 import org.openide.util.NbBundle;
 
   70         private final CaseDbConnectionInfo 
db;
 
   81                 boolean copySourceImages,
 
   84             this.imageInputFolder = imageInput;
 
   85             this.caseInputFolder = caseInput;
 
   86             this.imageOutputFolder = imageOutput;
 
   87             this.caseOutputFolder = caseOutput;
 
  105         Path getImageInputFolder() {
 
  109         Path getImageOutputFolder() {
 
  113         String getOldCaseName() {
 
  117         String getNewCaseName() {
 
  121         boolean getCopySourceImages() {
 
  125         boolean getDeleteCase() {
 
  129         String getPostgreSQLDbName() {
 
  133         String getAutFileName() {
 
  137         String getRawFolderName() {
 
  141         CaseDbConnectionInfo getDb() {
 
  145         void setPostgreSQLDbName(String dbName) {
 
  146             this.postgreSQLDbName = dbName;
 
  161         Class.forName(
"org.postgresql.Driver"); 
 
  164         Path oldDatabasePath = icd.getCaseInputFolder().resolve(AUTOPSY_DB_FILE);
 
  165         if (
false == oldDatabasePath.toFile().exists()) {
 
  166             throw new Exception(NbBundle.getMessage(
SingleUserCaseConverter.class, 
"SingleUserCaseConverter.BadDatabaseFileName")); 
 
  172             throw new Exception(NbBundle.getMessage(
SingleUserCaseConverter.class, 
"SingleUserCaseConverter.AlreadyMultiUser")); 
 
  176         SimpleDateFormat dateFormat = 
new SimpleDateFormat(
"yyyyMMdd_HHmmss"); 
 
  177         Date date = 
new Date();
 
  178         String dbName = 
Case.sanitizeCaseName(icd.getNewCaseName()) + 
"_" + dateFormat.format(date); 
 
  179         String solrName = dbName;
 
  180         icd.setPostgreSQLDbName(dbName);
 
  197                 icd.getNewCaseName(),
 
  202         newCaseMetadata.setCreatedDate(oldCaseMetadata.getCreatedDate());
 
  203         newCaseMetadata.setCreatedByVersion(oldCaseMetadata.getCreatedByVersion());
 
  209         if (icd.getDeleteCase()) {
 
  210             FileUtils.deleteDirectory(icd.getCaseInputFolder().toFile());
 
  223         File thePath = icd.getImageInputFolder().resolve(icd.getOldCaseName()).toFile();
 
  224         if (thePath.isDirectory()) {
 
  228         thePath = icd.getImageInputFolder().resolve(icd.getRawFolderName()).toFile();
 
  229         if (thePath.isDirectory()) {
 
  233         return icd.getImageInputFolder().toFile();
 
  249         Path source = icd.getCaseInputFolder();
 
  250         if (source.toFile().exists()) {
 
  251             destination = icd.getCaseOutputFolder().resolve(hostName);
 
  252             FileUtils.copyDirectory(source.toFile(), destination.toFile());
 
  255         source = icd.getCaseInputFolder().resolve(TIMELINE_FILE);
 
  256         if (source.toFile().exists()) {
 
  258             FileUtils.copyFile(source.toFile(), destination.toFile());
 
  262         File oldAutopsyFile = Paths.get(icd.getCaseOutputFolder().toString(), hostName, icd.getOldCaseName() + 
DOTAUT).toFile();
 
  263         if (oldAutopsyFile.exists()) {
 
  264             oldAutopsyFile.delete();
 
  268         File oldDatabaseFile = Paths.get(icd.getCaseOutputFolder().toString(), hostName, 
AUTOPSY_DB_FILE).toFile();
 
  269         if (oldDatabaseFile.exists()) {
 
  270             oldDatabaseFile.delete();
 
  274         File oldTimelineFile = Paths.get(icd.getCaseOutputFolder().toString(), hostName, 
TIMELINE_FILE).toFile();
 
  275         if (oldTimelineFile.exists()) {
 
  276             oldTimelineFile.delete();
 
  296         SleuthkitCase newCase = SleuthkitCase.newCase(icd.getPostgreSQLDbName(), icd.getDb(), icd.getCaseOutputFolder().toString());
 
  300         Class.forName(
"org.sqlite.JDBC"); 
 
  305         Statement inputStatement = sqliteConnection.createStatement();
 
  306         ResultSet inputResultSet = inputStatement.executeQuery(
"SELECT * FROM blackboard_artifact_types"); 
 
  307         Statement outputStatement;
 
  308         Statement numberingPK;
 
  311         while (inputResultSet.next()) {
 
  313                 long value = inputResultSet.getLong(1);
 
  314                 if (value > biggestPK) {
 
  317                 Statement check = postgreSQLConnection.createStatement();
 
  318                 ResultSet checkResult = check.executeQuery(
"SELECT * FROM blackboard_artifact_types WHERE artifact_type_id=" + value + 
" AND type_name LIKE '" + inputResultSet.getString(2) + 
"' AND display_name LIKE '" + inputResultSet.getString(3) + 
"'"); 
 
  319                 if (!checkResult.isBeforeFirst()) { 
 
  320                     String sql = 
"INSERT INTO blackboard_artifact_types (artifact_type_id, type_name, display_name) VALUES ("  
  322                             + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(2)) + 
"'," 
  324                     PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
 
  328             } 
catch (SQLException ex) {
 
  329                 if (ex.getErrorCode() != 0) { 
 
  330                     throw new SQLException(ex);
 
  334         numberingPK = postgreSQLConnection.createStatement();
 
  335         numberingPK.execute(
"ALTER SEQUENCE blackboard_artifact_types_artifact_type_id_seq RESTART WITH " + (biggestPK + 1)); 
 
  339         inputStatement = sqliteConnection.createStatement();
 
  340         inputResultSet = inputStatement.executeQuery(
"SELECT * FROM blackboard_attribute_types"); 
 
  342         while (inputResultSet.next()) {
 
  344                 long value = inputResultSet.getLong(1);
 
  345                 if (value > biggestPK) {
 
  348                 Statement check = postgreSQLConnection.createStatement();
 
  349                 ResultSet checkResult = check.executeQuery(
"SELECT * FROM blackboard_attribute_types WHERE attribute_type_id=" + value + 
" AND type_name LIKE '" + inputResultSet.getString(2) + 
"' AND display_name LIKE '" + inputResultSet.getString(3) + 
"'"); 
 
  350                 if (!checkResult.isBeforeFirst()) { 
 
  351                     String sql = 
"INSERT INTO blackboard_attribute_types (attribute_type_id, type_name, display_name) VALUES ("  
  353                             + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(2)) + 
"'," 
  356                     PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
 
  360             } 
catch (SQLException ex) {
 
  361                 if (ex.getErrorCode() != 0) { 
 
  362                     throw new SQLException(ex);
 
  366         numberingPK = postgreSQLConnection.createStatement();
 
  367         numberingPK.execute(
"ALTER SEQUENCE blackboard_attribute_types_attribute_type_id_seq RESTART WITH " + (biggestPK + 1)); 
 
  371         inputStatement = sqliteConnection.createStatement();
 
  372         inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_objects"); 
 
  374         while (inputResultSet.next()) {
 
  375             outputStatement = postgreSQLConnection.createStatement();
 
  377                 long value = inputResultSet.getLong(1);
 
  378                 if (value > biggestPK) {
 
  381                 outputStatement.executeUpdate(
"INSERT INTO tsk_objects (obj_id, par_obj_id, type) VALUES ("  
  384                         + inputResultSet.getInt(3) + 
")"); 
 
  385             } 
catch (SQLException ex) {
 
  386                 if (ex.getErrorCode() != 0) { 
 
  387                     throw new SQLException(ex);
 
  391         numberingPK = postgreSQLConnection.createStatement();
 
  392         numberingPK.execute(
"ALTER SEQUENCE tsk_objects_obj_id_seq RESTART WITH " + (biggestPK + 1)); 
 
  395         inputStatement = sqliteConnection.createStatement();
 
  396         inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_image_names"); 
 
  398         while (inputResultSet.next()) {
 
  399             outputStatement = postgreSQLConnection.createStatement();
 
  401                 outputStatement.executeUpdate(
"INSERT INTO tsk_image_names (obj_id, name, sequence) VALUES ("  
  402                         + inputResultSet.getLong(1) + 
",'" 
  403                         + inputResultSet.getString(2) + 
"'," 
  404                         + inputResultSet.getInt(3) + 
")"); 
 
  405             } 
catch (SQLException ex) {
 
  406                 if (ex.getErrorCode() != 0) { 
 
  407                     throw new SQLException(ex);
 
  414         inputStatement = sqliteConnection.createStatement();
 
  415         inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_image_info"); 
 
  417         while (inputResultSet.next()) {
 
  419                 long value = inputResultSet.getLong(1);
 
  420                 if (value > biggestPK) {
 
  423                 String sql = 
"INSERT INTO tsk_image_info (obj_id, type, ssize, tzone, size, md5, display_name) VALUES ("  
  432                 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
 
  438             } 
catch (SQLException ex) {
 
  439                 if (ex.getErrorCode() != 0) { 
 
  440                     throw new SQLException(ex);
 
  444         numberingPK = postgreSQLConnection.createStatement();
 
  445         numberingPK.execute(
"ALTER SEQUENCE tsk_image_info_obj_id_seq RESTART WITH " + (biggestPK + 1)); 
 
  449         inputStatement = sqliteConnection.createStatement();
 
  450         inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_fs_info"); 
 
  452         while (inputResultSet.next()) {
 
  454                 long value = inputResultSet.getLong(1);
 
  455                 if (value > biggestPK) {
 
  458                 String sql = 
"INSERT INTO tsk_fs_info (obj_id, img_offset, fs_type, block_size, block_count, root_inum, first_inum, last_inum, display_name) VALUES ("  
  460                         + inputResultSet.getLong(2) + 
"," 
  461                         + inputResultSet.getInt(3) + 
"," 
  462                         + inputResultSet.getLong(4) + 
"," 
  463                         + inputResultSet.getLong(5) + 
"," 
  464                         + inputResultSet.getLong(6) + 
"," 
  465                         + inputResultSet.getLong(7) + 
"," 
  466                         + inputResultSet.getLong(8) + 
"," 
  469                 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
 
  473             } 
catch (SQLException ex) {
 
  474                 if (ex.getErrorCode() != 0) { 
 
  475                     throw new SQLException(ex);
 
  479         numberingPK = postgreSQLConnection.createStatement();
 
  480         numberingPK.execute(
"ALTER SEQUENCE tsk_fs_info_obj_id_seq RESTART WITH " + (biggestPK + 1)); 
 
  484         inputStatement = sqliteConnection.createStatement();
 
  485         inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_files_path"); 
 
  487         while (inputResultSet.next()) {
 
  488             outputStatement = postgreSQLConnection.createStatement();
 
  490                 long value = inputResultSet.getLong(1);
 
  491                 if (value > biggestPK) {
 
  497                 int encoding = TskData.EncodingType.NONE.getType();
 
  498                 ResultSetMetaData rsMetaData = inputResultSet.getMetaData();
 
  499                 if(rsMetaData.getColumnCount() == 3){
 
  500                     encoding = inputResultSet.getInt(3);
 
  502                 outputStatement.executeUpdate(
"INSERT INTO tsk_files_path (obj_id, path, encoding_type) VALUES ("  
  504                         + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(2)) + 
"', " 
  506             } 
catch (SQLException ex) {
 
  507                 if (ex.getErrorCode() != 0) { 
 
  508                     throw new SQLException(ex);
 
  512         numberingPK = postgreSQLConnection.createStatement();
 
  513         numberingPK.execute(
"ALTER SEQUENCE tsk_files_path_obj_id_seq RESTART WITH " + (biggestPK + 1)); 
 
  517         inputStatement = sqliteConnection.createStatement();
 
  518         inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_files"); 
 
  520         while (inputResultSet.next()) {
 
  522                 long value = inputResultSet.getLong(1);
 
  523                 if (value > biggestPK) {
 
  526                 String sql = 
"INSERT INTO tsk_files (obj_id, fs_obj_id, attr_type, attr_id, name, meta_addr, meta_seq, type, has_layout, has_path, dir_type, meta_type, dir_flags, meta_flags, size, ctime, crtime, atime, mtime, mode, uid, gid, md5, known, parent_path) VALUES ("  
  531                         + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(5)) + 
"'," 
  553                 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
 
  558             } 
catch (SQLException ex) {
 
  559                 if (ex.getErrorCode() != 0) { 
 
  560                     throw new SQLException(ex);
 
  564         numberingPK = postgreSQLConnection.createStatement();
 
  565         numberingPK.execute(
"ALTER SEQUENCE tsk_files_obj_id_seq RESTART WITH " + (biggestPK + 1)); 
 
  568         inputStatement = sqliteConnection.createStatement();
 
  569         inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_file_layout"); 
 
  571         while (inputResultSet.next()) {
 
  572             outputStatement = postgreSQLConnection.createStatement();
 
  574                 outputStatement.executeUpdate(
"INSERT INTO tsk_file_layout (obj_id, byte_start, byte_len, sequence) VALUES ("  
  575                         + inputResultSet.getLong(1) + 
"," 
  576                         + inputResultSet.getLong(2) + 
"," 
  577                         + inputResultSet.getLong(3) + 
"," 
  578                         + inputResultSet.getInt(4) + 
")"); 
 
  579             } 
catch (SQLException ex) {
 
  580                 if (ex.getErrorCode() != 0) { 
 
  581                     throw new SQLException(ex);
 
  587         inputStatement = sqliteConnection.createStatement();
 
  588         inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_db_info"); 
 
  590         while (inputResultSet.next()) {
 
  591             outputStatement = postgreSQLConnection.createStatement();
 
  593                 Statement check = postgreSQLConnection.createStatement();
 
  594                 ResultSet checkResult = check.executeQuery(
"SELECT * FROM tsk_db_info WHERE schema_ver=" + inputResultSet.getInt(1) + 
" AND tsk_ver=" + inputResultSet.getInt(2)); 
 
  595                 if (!checkResult.isBeforeFirst()) { 
 
  596                     outputStatement.executeUpdate(
"INSERT INTO tsk_db_info (schema_ver, tsk_ver) VALUES ("  
  600             } 
catch (SQLException ex) {
 
  601                 if (ex.getErrorCode() != 0) { 
 
  602                     throw new SQLException(ex);
 
  609         inputStatement = sqliteConnection.createStatement();
 
  610         inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tag_names"); 
 
  612         while (inputResultSet.next()) {
 
  614                 long value = inputResultSet.getLong(1);
 
  615                 if (value > biggestPK) {
 
  618                 String sql = 
"INSERT INTO tag_names (tag_name_id, display_name, description, color) VALUES ("  
  621                         + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(3)) + 
"','" 
  622                         + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(4)) + 
"')"; 
 
  624                 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
 
  628             } 
catch (SQLException ex) {
 
  629                 if (ex.getErrorCode() != 0) { 
 
  630                     throw new SQLException(ex);
 
  634         numberingPK = postgreSQLConnection.createStatement();
 
  635         numberingPK.execute(
"ALTER SEQUENCE tag_names_tag_name_id_seq RESTART WITH " + (biggestPK + 1)); 
 
  639         inputStatement = sqliteConnection.createStatement();
 
  640         inputResultSet = inputStatement.executeQuery(
"SELECT * FROM reports"); 
 
  642         while (inputResultSet.next()) {
 
  643             outputStatement = postgreSQLConnection.createStatement();
 
  645                 long value = inputResultSet.getLong(1);
 
  646                 if (value > biggestPK) {
 
  649                 outputStatement.executeUpdate(
"INSERT INTO reports (report_id, path, crtime, src_module_name, report_name) VALUES ("  
  651                         + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(2)) + 
"'," 
  652                         + inputResultSet.getInt(3) + 
",'" 
  653                         + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(4)) + 
"','" 
  654                         + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(5)) + 
"')"); 
 
  656             } 
catch (SQLException ex) {
 
  657                 if (ex.getErrorCode() != 0) { 
 
  658                     throw new SQLException(ex);
 
  662         numberingPK = postgreSQLConnection.createStatement();
 
  663         numberingPK.execute(
"ALTER SEQUENCE reports_report_id_seq RESTART WITH " + (biggestPK + 1)); 
 
  666         biggestPK = Long.MIN_VALUE; 
 
  667         inputStatement = sqliteConnection.createStatement();
 
  668         inputResultSet = inputStatement.executeQuery(
"SELECT * FROM blackboard_artifacts"); 
 
  670         while (inputResultSet.next()) {
 
  671             outputStatement = postgreSQLConnection.createStatement();
 
  673                 long value = inputResultSet.getLong(1);
 
  674                 if (value > biggestPK) {
 
  677                 outputStatement.executeUpdate(
"INSERT INTO blackboard_artifacts (artifact_id, obj_id, artifact_type_id) VALUES ("  
  679                         + inputResultSet.getLong(2) + 
"," 
  680                         + inputResultSet.getLong(3) + 
")"); 
 
  682             } 
catch (SQLException ex) {
 
  683                 if (ex.getErrorCode() != 0) { 
 
  684                     throw new SQLException(ex);
 
  688         numberingPK = postgreSQLConnection.createStatement();
 
  689         numberingPK.execute(
"ALTER SEQUENCE blackboard_artifacts_artifact_id_seq RESTART WITH " + (biggestPK + 1)); 
 
  692         inputStatement = sqliteConnection.createStatement();
 
  693         inputResultSet = inputStatement.executeQuery(
"SELECT * FROM blackboard_attributes"); 
 
  695         while (inputResultSet.next()) {
 
  697                 String sql = 
"INSERT INTO blackboard_attributes (artifact_id, artifact_type_id, source, context, attribute_type_id, value_type, value_byte, value_text, value_int32, value_int64, value_double) VALUES ("  
  698                         + inputResultSet.getLong(1) + 
"," 
  699                         + inputResultSet.getLong(2) + 
"," 
  702                         + inputResultSet.getLong(5) + 
"," 
  703                         + inputResultSet.getInt(6) + 
"," 
  709                 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
 
  717             } 
catch (SQLException ex) {
 
  718                 if (ex.getErrorCode() != 0) { 
 
  719                     throw new SQLException(ex);
 
  726         inputStatement = sqliteConnection.createStatement();
 
  727         inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_vs_parts"); 
 
  729         while (inputResultSet.next()) {
 
  731                 long value = inputResultSet.getLong(1);
 
  732                 if (value > biggestPK) {
 
  735                 String sql = 
"INSERT INTO tsk_vs_parts (obj_id, addr, start, length, descr, flags) VALUES ("  
  737                         + inputResultSet.getLong(2) + 
"," 
  738                         + inputResultSet.getLong(3) + 
"," 
  739                         + inputResultSet.getLong(4) + 
"," 
  741                         + inputResultSet.getInt(6) + 
")"; 
 
  742                 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
 
  746             } 
catch (SQLException ex) {
 
  747                 if (ex.getErrorCode() != 0) { 
 
  748                     throw new SQLException(ex);
 
  752         numberingPK = postgreSQLConnection.createStatement();
 
  753         numberingPK.execute(
"ALTER SEQUENCE tsk_vs_parts_obj_id_seq RESTART WITH " + (biggestPK + 1)); 
 
  757         inputStatement = sqliteConnection.createStatement();
 
  758         inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_vs_info"); 
 
  760         while (inputResultSet.next()) {
 
  761             outputStatement = postgreSQLConnection.createStatement();
 
  763                 long value = inputResultSet.getLong(1);
 
  764                 if (value > biggestPK) {
 
  767                 outputStatement.executeUpdate(
"INSERT INTO tsk_vs_info (obj_id, vs_type, img_offset, block_size) VALUES ("  
  769                         + inputResultSet.getInt(2) + 
"," 
  770                         + inputResultSet.getLong(3) + 
"," 
  771                         + inputResultSet.getLong(4) + 
")"); 
 
  773             } 
catch (SQLException ex) {
 
  774                 if (ex.getErrorCode() != 0) { 
 
  775                     throw new SQLException(ex);
 
  779         numberingPK = postgreSQLConnection.createStatement();
 
  780         numberingPK.execute(
"ALTER SEQUENCE tsk_vs_info_obj_id_seq RESTART WITH " + (biggestPK + 1)); 
 
  784         inputStatement = sqliteConnection.createStatement();
 
  785         inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_files_derived"); 
 
  787         while (inputResultSet.next()) {
 
  789                 long value = inputResultSet.getLong(1);
 
  790                 if (value > biggestPK) {
 
  793                 String sql = 
"INSERT INTO tsk_files_derived (obj_id, derived_id, rederive) VALUES ("  
  795                         + inputResultSet.getLong(2) + 
"," 
  797                 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
 
  801             } 
catch (SQLException ex) {
 
  802                 if (ex.getErrorCode() != 0) { 
 
  803                     throw new SQLException(ex);
 
  807         numberingPK = postgreSQLConnection.createStatement();
 
  808         numberingPK.execute(
"ALTER SEQUENCE tsk_files_derived_obj_id_seq RESTART WITH " + (biggestPK + 1)); 
 
  812         inputStatement = sqliteConnection.createStatement();
 
  813         inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_files_derived_method"); 
 
  815         while (inputResultSet.next()) {
 
  817                 long value = inputResultSet.getLong(1);
 
  818                 if (value > biggestPK) {
 
  821                 String sql = 
"INSERT INTO tsk_files_derived_method (derived_id, tool_name, tool_version, other) VALUES ("  
  823                         + inputResultSet.getString(2) + 
"','" 
  824                         + inputResultSet.getString(3) + 
"'," 
  826                 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
 
  830             } 
catch (SQLException ex) {
 
  831                 if (ex.getErrorCode() != 0) { 
 
  832                     throw new SQLException(ex);
 
  836         numberingPK = postgreSQLConnection.createStatement();
 
  837         numberingPK.execute(
"ALTER SEQUENCE tsk_files_derived_method_derived_id_seq RESTART WITH " + (biggestPK + 1)); 
 
  841         inputStatement = sqliteConnection.createStatement();
 
  842         inputResultSet = inputStatement.executeQuery(
"SELECT * FROM content_tags"); 
 
  844         while (inputResultSet.next()) {
 
  845             outputStatement = postgreSQLConnection.createStatement();
 
  847                 long value = inputResultSet.getLong(1);
 
  848                 if (value > biggestPK) {
 
  851                 outputStatement.executeUpdate(
"INSERT INTO content_tags (tag_id, obj_id, tag_name_id, comment, begin_byte_offset, end_byte_offset) VALUES ("  
  853                         + inputResultSet.getLong(2) + 
"," 
  854                         + inputResultSet.getLong(3) + 
",'" 
  855                         + inputResultSet.getString(4) + 
"'," 
  856                         + inputResultSet.getLong(5) + 
"," 
  857                         + inputResultSet.getLong(6) + 
")"); 
 
  859             } 
catch (SQLException ex) {
 
  860                 if (ex.getErrorCode() != 0) { 
 
  861                     throw new SQLException(ex);
 
  865         numberingPK = postgreSQLConnection.createStatement();
 
  866         numberingPK.execute(
"ALTER SEQUENCE content_tags_tag_id_seq RESTART WITH " + (biggestPK + 1)); 
 
  870         inputStatement = sqliteConnection.createStatement();
 
  871         inputResultSet = inputStatement.executeQuery(
"SELECT * FROM blackboard_artifact_tags"); 
 
  873         while (inputResultSet.next()) {
 
  874             outputStatement = postgreSQLConnection.createStatement();
 
  876                 long value = inputResultSet.getLong(1);
 
  877                 if (value > biggestPK) {
 
  880                 outputStatement.executeUpdate(
"INSERT INTO blackboard_artifact_tags (tag_id, artifact_id, tag_name_id, comment) VALUES ("  
  882                         + inputResultSet.getLong(2) + 
"," 
  883                         + inputResultSet.getLong(3) + 
",'" 
  884                         + inputResultSet.getString(4) + 
"')"); 
 
  886             } 
catch (SQLException ex) {
 
  887                 if (ex.getErrorCode() != 0) { 
 
  888                     throw new SQLException(ex);
 
  892         numberingPK = postgreSQLConnection.createStatement();
 
  893         numberingPK.execute(
"ALTER SEQUENCE blackboard_artifact_tags_tag_id_seq RESTART WITH " + (biggestPK + 1)); 
 
  895         sqliteConnection.close();
 
  896         postgreSQLConnection.close();
 
  915         boolean unique = 
false;
 
  916         String sanitizedDbName = icd.getPostgreSQLDbName();
 
  918             sanitizedDbName = sanitizedDbName.substring(0, MAX_DB_NAME_LENGTH);
 
  921         if (postgreSQLConnection != null) {
 
  922             while (unique == 
false) {
 
  923                 Statement st = postgreSQLConnection.createStatement();
 
  924                 ResultSet answer = st.executeQuery(
"SELECT datname FROM pg_catalog.pg_database WHERE LOWER(datname) LIKE LOWER('" + sanitizedDbName + 
"%')"); 
 
  926                 if (!answer.next()) {
 
  930                     if (number == Integer.MAX_VALUE) {
 
  932                         throw new Exception(NbBundle.getMessage(
SingleUserCaseConverter.class, 
"SingleUserCaseConverter.NonUniqueDatabaseName")); 
 
  934                     sanitizedDbName = 
"db_" + Integer.toString(number) + 
"_" + icd.getPostgreSQLDbName(); 
 
  938                         sanitizedDbName = sanitizedDbName.substring(0, MAX_DB_NAME_LENGTH);
 
  943             postgreSQLConnection.close();
 
  949         icd.setPostgreSQLDbName(sanitizedDbName);
 
  961         if (icd.getCopySourceImages()) {
 
  963             File imageDestination = 
new File(icd.getImageOutputFolder().toString());
 
  966             if (imageSource.exists()) {
 
  967                 FileUtils.copyDirectory(imageSource, imageDestination);
 
  970                 throw new Exception(NbBundle.getMessage(
SingleUserCaseConverter.class, 
"SingleUserCaseConverter.UnableToCopySourceImages")); 
 
  987         String input = icd.getImageInputFolder().toString();
 
  988         String output = icd.getImageOutputFolder().toString();
 
  992         if (postgresqlConnection != null) {
 
  996             Statement updateStatement = postgresqlConnection.createStatement();
 
  997             updateStatement.executeUpdate(
"UPDATE reports SET path=CONCAT('" + hostName + 
"/', path) WHERE path IS NOT NULL AND path != ''"); 
 
 1000             updateStatement = postgresqlConnection.createStatement();
 
 1001             updateStatement.executeUpdate(
"UPDATE tsk_files_path SET path=CONCAT('" + hostName + 
"\\', path) WHERE path IS NOT NULL AND path != ''"); 
 
 1003             String caseName = icd.getRawFolderName().toLowerCase();
 
 1005             if (icd.getCopySourceImages()) {
 
 1007                 Statement inputStatement = postgresqlConnection.createStatement();
 
 1008                 ResultSet inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_image_names"); 
 
 1010                 while (inputResultSet.next()) {
 
 1011                     Path oldPath = Paths.get(inputResultSet.getString(2));
 
 1013                     for (
int x = 0; x < oldPath.getNameCount(); ++x) {
 
 1014                         if (oldPath.getName(x).toString().toLowerCase().equals(caseName)) {
 
 1015                             Path newPath = Paths.get(output, oldPath.subpath(x + 1, oldPath.getNameCount()).toString());
 
 1016                             updateStatement = postgresqlConnection.createStatement();
 
 1017                             updateStatement.executeUpdate(
"UPDATE tsk_image_names SET name='" + newPath.toString() + 
"' WHERE obj_id = " + inputResultSet.getInt(1)); 
 
 1023             postgresqlConnection.close();
 
 1025             throw new Exception(NbBundle.getMessage(
SingleUserCaseConverter.class, 
"SingleUserCaseConverter.CanNotOpenDatabase")); 
 
 1041         int value = rs.getInt(index);
 
 1045             return Integer.toString(value);
 
 1061         long value = rs.getLong(index);
 
 1065             return Long.toString(value);
 
 1080     private static void populateNullableString(PreparedStatement pst, ResultSet rs, 
int rsIndex, 
int psIndex) 
throws SQLException {
 
 1081         String nullableString = rs.getString(rsIndex);
 
 1083             pst.setNull(psIndex, java.sql.Types.NULL);
 
 1085             pst.setString(psIndex, SleuthkitCase.escapeSingleQuotes(nullableString));
 
 1101         byte[] nullableBytes = rs.getBytes(rsIndex);
 
 1103             pst.setNull(psIndex, java.sql.Types.NULL);
 
 1105             pst.setBytes(psIndex, nullableBytes);
 
 1121         double nullableNumeric = rs.getDouble(rsIndex);
 
 1123             pst.setNull(psIndex, java.sql.Types.NULL);
 
 1125             pst.setDouble(psIndex, nullableNumeric);
 
 1153         return DriverManager.getConnection(
"jdbc:postgresql://"  
 1154                 + icd.getDb().getHost() + 
":" 
 1155                 + icd.getDb().getPort() + 
"/" 
 1157                 icd.getDb().getUserName(),
 
 1158                 icd.getDb().getPassword()); 
 
 1171         return DriverManager.getConnection(
"jdbc:sqlite:" + icd.getCaseInputFolder().resolve(AUTOPSY_DB_FILE).toString(), 
"", 
""); 
 
static Connection getPostgreSQLConnection(ImportCaseData icd)
final Path caseInputFolder
final Path imageOutputFolder
static void populateNullableNumeric(PreparedStatement pst, ResultSet rs, int rsIndex, int psIndex)
static String getNullableInt(ResultSet rs, int index)
static final int MAX_DB_NAME_LENGTH
static void deconflictDatabaseName(ImportCaseData icd)
static Connection getSQLiteConnection(ImportCaseData icd)
final String rawFolderName
ImportCaseData(Path imageInput, Path caseInput, Path imageOutput, Path caseOutput, String oldCaseName, String newCaseName, String autFileName, String rawFolderName, boolean copySourceImages, boolean deleteCase)
Path getCaseOutputFolder()
static void importCase(ImportCaseData icd)
static final String POSTGRES_DEFAULT_DB_NAME
static CaseDbConnectionInfo getDatabaseConnectionInfo()
static final String TIMELINE_FILE
final CaseDbConnectionInfo db
static void copyImages(ImportCaseData icd)
static final String DOTAUT
final Path imageInputFolder
final boolean copySourceImages
static void populateNullableString(PreparedStatement pst, ResultSet rs, int rsIndex, int psIndex)
static String getNullableLong(ResultSet rs, int index)
static void populateNullableByteArray(PreparedStatement pst, ResultSet rs, int rsIndex, int psIndex)
static final String AUTOPSY_DB_FILE
static final String TIMELINE_FOLDER
static void copyResults(ImportCaseData icd)
static String getLocalHostName()
static void importDb(ImportCaseData icd)
Path getCaseInputFolder()
final Path caseOutputFolder
static void fixPaths(ImportCaseData icd)
static File findInputFolder(ImportCaseData icd)
static Connection getPostgreSQLConnection(ImportCaseData icd, String dbName)