updates and fixes

This commit is contained in:
Greg DiCristofaro 2024-04-23 15:22:50 -04:00
parent 86fbba9659
commit f5082ead11
4 changed files with 65 additions and 39 deletions

View File

@ -575,11 +575,6 @@ public class Installer extends ModuleInstall {
logger.log(Level.INFO, "close()"); //NON-NLS
//exit JavaFx plat
if (javaFxInit) {
Platform.exit();
}
for (ModuleInstall mi : packageInstallers) {
logger.log(Level.INFO, "{0} close()", mi.getClass().getName()); //NON-NLS
try {
@ -591,5 +586,10 @@ public class Installer extends ModuleInstall {
for (Handler h : logger.getHandlers()) {
h.close(); //must call h.close or a .LCK file will remain.
}
//exit JavaFx plat
if (javaFxInit) {
Platform.exit();
}
}
}

View File

@ -169,6 +169,8 @@ ImageNode.createSheet.type.displayName=Type
ImageNode.createSheet.type.name=Type
ImageNode.createSheet.type.text=Image
ImageNode.getActions.openFileSearchByAttr.text=Open File Search by Attributes
Installer_validate_tskLibLock_description=<html>It appears that an older version of an application that opens The Sleuth Kit databases is currently running on your system.<br/> Close this application before opening Autopsy, and consider upgrading in order to have a better user experience.</html>
Installer_validate_tskLibLock_title=Error calling Sleuth Kit library
KeyValueNode.menuItemText.viewFileInDir=View Source File in Directory
KeywordHits.createNodeForKey.accessTime.desc=Access Time
KeywordHits.createNodeForKey.accessTime.displayName=Access Time

View File

@ -19,7 +19,6 @@
package org.sleuthkit.autopsy.datamodel;
import java.awt.Component;
import java.io.IOException;
import java.util.logging.Level;
import org.openide.util.NbBundle;
@ -51,7 +50,7 @@ public class Installer extends ModuleInstall {
@Messages({
"Installer_validate_tskLibLock_title=Error calling Sleuth Kit library",
"Installer_validate_tskLibLock_description=It appears that an older version of an application that opens The Sleuth Kit databases is currently running on your system. Close this application before opening Autopsy, and consider upgrading in order to have a better user experience."
"Installer_validate_tskLibLock_description=<html>It appears that an older version of an application that opens The Sleuth Kit databases is currently running on your system.<br/> Close this application before opening Autopsy, and consider upgrading in order to have a better user experience.</html>"
})
@Override
public void validate() throws IllegalStateException {
@ -70,13 +69,9 @@ public class Installer extends ModuleInstall {
Logger logger = Logger.getLogger(Installer.class.getName());
try {
try {
TskLibLock libLock = TskLibLock.acquireLibLock();
if (libLock != null && libLock.getLockState() == LockState.HELD_BY_OLD) {
throw new OldAppLockException("A lock on the libtsk_jni lib is already held by an old application. " + (libLock.getLibTskJniFile() != null ? libLock.getLibTskJniFile().getAbsolutePath() : ""));
}
} catch (IOException ex) {
logger.log(Level.SEVERE, "An error occurred while acquiring the TSK lib lock", ex);
TskLibLock libLock = TskLibLock.acquireLibLock();
if (libLock != null && libLock.getLockState() == LockState.HELD_BY_OLD) {
throw new OldAppLockException("A lock on the libtsk_jni lib is already held by an old application. " + (libLock.getLibTskJniFile() != null ? libLock.getLibTskJniFile().getAbsolutePath() : ""));
}
String skVersion = SleuthkitJNI.getVersion();
@ -121,6 +116,29 @@ public class Installer extends ModuleInstall {
}
@Override
public void close() {
try {
TskLibLock.removeLibLock();
} catch (Exception ex) {
Logger logger = Logger.getLogger(Installer.class.getName());
logger.log(Level.WARNING, "There was an error removing the TSK lib lock.", ex);
}
}
@Override
public void uninstalled() {
try {
TskLibLock.removeLibLock();
} catch (Exception ex) {
Logger logger = Logger.getLogger(Installer.class.getName());
logger.log(Level.WARNING, "There was an error removing the TSK lib lock.", ex);
}
}
/**
* An exception when an older application (Autopsy
*/

View File

@ -26,6 +26,7 @@ import java.nio.channels.FileLock;
import java.nio.file.Paths;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.logging.Level;
/**
* Creates a file lock at the old location (Autopsy LTE 4.21.0) of TSK
@ -58,7 +59,7 @@ class TskLibLock implements AutoCloseable {
* acquired) and any resources if the lock is acquired.
* @throws IOException
*/
static TskLibLock acquireLibLock() throws IOException {
static TskLibLock acquireLibLock() {
if (libLock == null) {
libLock = getLibLock();
}
@ -84,7 +85,7 @@ class TskLibLock implements AutoCloseable {
* acquired) and any resources if the lock is acquired.
* @throws IOException
*/
private static TskLibLock getLibLock() throws IOException {
private static TskLibLock getLibLock() {
// TODO error handling cleanup
String libExt = getLibExtension();
@ -104,38 +105,43 @@ class TskLibLock implements AutoCloseable {
: LockState.HELD_BY_OLD;
return new TskLibLock(lockState, libTskJniFile, lockFileRaf, null, null);
} catch (IOException ex) {
// if there is an error getting read only access, then it is the old application dll
java.util.logging.Logger.getLogger(TskLibLock.class.getCanonicalName()).log(Level.WARNING, "An error occurred while acquiring the TSK lib lock", ex);
return new TskLibLock(LockState.HELD_BY_OLD, libTskJniFile, null, null, null);
}
} else {
// make directories leading up to that
libTskJniFile.getParentFile().mkdirs();
// get file access to the file
RandomAccessFile lockFileRaf = new RandomAccessFile(libTskJniFile, "rw");
FileChannel lockFileChannel = lockFileRaf.getChannel();
FileLock lockFileLock = lockFileChannel == null
? null
: lockFileChannel.tryLock(1024L, 1L, false);
RandomAccessFile lockFileRaf = null;
FileChannel lockFileChannel = null;
FileLock lockFileLock = null;
try {
lockFileRaf = new RandomAccessFile(libTskJniFile, "rw");
lockFileChannel = lockFileRaf.getChannel();
lockFileLock = lockFileChannel == null
? null
: lockFileChannel.tryLock(1024L, 1L, false);
if (lockFileLock != null) {
lockFileRaf.setLength(0);
lockFileRaf.write(UTF8_BOM);
lockFileRaf.writeChars(LIB_FILE_LOCK_TEXT);
if (lockFileLock != null) {
lockFileRaf.setLength(0);
lockFileRaf.write(UTF8_BOM);
lockFileRaf.writeChars(LIB_FILE_LOCK_TEXT);
return new TskLibLock(LockState.ACQUIRED, libTskJniFile, lockFileRaf, lockFileChannel, lockFileLock);
} else {
if (lockFileChannel != null) {
lockFileChannel.close();
return new TskLibLock(LockState.ACQUIRED, libTskJniFile, lockFileRaf, lockFileChannel, lockFileLock);
} else {
LockState lockState = isNewLock(lockFileRaf)
? LockState.HELD_BY_NEW
: LockState.HELD_BY_OLD;
return new TskLibLock(lockState, libTskJniFile, lockFileRaf, lockFileChannel, null);
}
if (lockFileRaf != null) {
lockFileRaf.close();
}
LockState lockState = isNewLock(lockFileRaf)
? LockState.HELD_BY_NEW
: LockState.HELD_BY_OLD;
return new TskLibLock(lockState, libTskJniFile, lockFileRaf, lockFileChannel, null);
} catch (IOException ex) {
// if there is an error getting read only access, then it is the old application dll
java.util.logging.Logger.getLogger(TskLibLock.class.getCanonicalName()).log(Level.WARNING, "An error occurred while acquiring the TSK lib lock", ex);
return new TskLibLock(LockState.HELD_BY_OLD, libTskJniFile, lockFileRaf, lockFileChannel, lockFileLock);
}
}
}