mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-17 10:17:41 +00:00
Merge pull request #1785 from karlmortensen/arePermissionsAppropriate
Check if permissions are sufficient to read and write output folder
This commit is contained in:
commit
1fb8079b18
@ -22,6 +22,8 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import org.openide.filesystems.FileObject;
|
import org.openide.filesystems.FileObject;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* File and dir utilities
|
* File and dir utilities
|
||||||
@ -29,6 +31,7 @@ import org.openide.filesystems.FileObject;
|
|||||||
public class FileUtil {
|
public class FileUtil {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(FileUtil.class.getName());
|
private static final Logger logger = Logger.getLogger(FileUtil.class.getName());
|
||||||
|
private static String TEMP_FILE_PREFIX = "Autopsy";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recursively delete all of the files and sub-directories in a directory.
|
* Recursively delete all of the files and sub-directories in a directory.
|
||||||
@ -167,4 +170,28 @@ public class FileUtil {
|
|||||||
//with underscores. We are only keeping \ as it could be part of the path.
|
//with underscores. We are only keeping \ as it could be part of the path.
|
||||||
return fileName.replaceAll("[/:\"*?<>|]+", "_");
|
return fileName.replaceAll("[/:\"*?<>|]+", "_");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if the current user has read and write access to the path.
|
||||||
|
*
|
||||||
|
* @param path The path to test for read and write access.
|
||||||
|
*
|
||||||
|
* @return True if we have both read and write access, false otherwise.
|
||||||
|
*/
|
||||||
|
public static boolean hasReadWriteAccess(Path path) {
|
||||||
|
Path p = null;
|
||||||
|
try {
|
||||||
|
p = Files.createTempFile(path, TEMP_FILE_PREFIX, null);
|
||||||
|
return (p.toFile().canRead() && p.toFile().canWrite());
|
||||||
|
} catch (IOException ex) {
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
if (p != null) {
|
||||||
|
try {
|
||||||
|
p.toFile().delete();
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,3 +24,5 @@ PhotoRecIngestModule.cancelledByUser=PhotoRec cancelled by user.
|
|||||||
PhotoRecIngestModule.error.exitValue=PhotoRec carver returned error exit value = {0} when scanning {1}
|
PhotoRecIngestModule.error.exitValue=PhotoRec carver returned error exit value = {0} when scanning {1}
|
||||||
PhotoRecIngestModule.error.msg=Error processing {0} with PhotoRec carver.
|
PhotoRecIngestModule.error.msg=Error processing {0} with PhotoRec carver.
|
||||||
PhotoRecIngestModule.complete.numberOfErrors=Number of Errors while Carving\:
|
PhotoRecIngestModule.complete.numberOfErrors=Number of Errors while Carving\:
|
||||||
|
PhotoRecIngestModule.PermissionsNotSufficient=Insufficient permissions accessing
|
||||||
|
PhotoRecIngestModule.PermissionsNotSufficientSeeReference=See "Shared Drive Authentication" in Autopsy help.
|
@ -77,6 +77,7 @@ final class PhotoRecCarverFileIngestModule implements FileIngestModule {
|
|||||||
private static final String PHOTOREC_REPORT = "report.xml"; //NON-NLS
|
private static final String PHOTOREC_REPORT = "report.xml"; //NON-NLS
|
||||||
private static final String LOG_FILE = "run_log.txt"; //NON-NLS
|
private static final String LOG_FILE = "run_log.txt"; //NON-NLS
|
||||||
private static final String TEMP_DIR_NAME = "temp"; // NON-NLS
|
private static final String TEMP_DIR_NAME = "temp"; // NON-NLS
|
||||||
|
private static final String SEP = System.getProperty("line.separator");
|
||||||
private static final Logger logger = Logger.getLogger(PhotoRecCarverFileIngestModule.class.getName());
|
private static final Logger logger = Logger.getLogger(PhotoRecCarverFileIngestModule.class.getName());
|
||||||
private static final HashMap<Long, IngestJobTotals> totalsForIngestJobs = new HashMap<>();
|
private static final HashMap<Long, IngestJobTotals> totalsForIngestJobs = new HashMap<>();
|
||||||
private static final IngestModuleReferenceCounter refCounter = new IngestModuleReferenceCounter();
|
private static final IngestModuleReferenceCounter refCounter = new IngestModuleReferenceCounter();
|
||||||
@ -377,15 +378,21 @@ final class PhotoRecCarverFileIngestModule implements FileIngestModule {
|
|||||||
*/
|
*/
|
||||||
synchronized Path createModuleOutputDirectoryForCase() throws IngestModule.IngestModuleException {
|
synchronized Path createModuleOutputDirectoryForCase() throws IngestModule.IngestModuleException {
|
||||||
Path path = Paths.get(Case.getCurrentCase().getModuleDirectory(), PhotoRecCarverIngestModuleFactory.getModuleName());
|
Path path = Paths.get(Case.getCurrentCase().getModuleDirectory(), PhotoRecCarverIngestModuleFactory.getModuleName());
|
||||||
if (UNCPathUtilities.isUNC(path)) {
|
|
||||||
// if the UNC path is using an IP address, convert to hostname
|
|
||||||
path = uncPathUtilities.ipToHostName(path);
|
|
||||||
if (path == null) {
|
|
||||||
throw new IngestModule.IngestModuleException(NbBundle.getMessage(PhotoRecCarverFileIngestModule.class, "PhotoRecIngestModule.nonHostnameUNCPathUsed"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
Files.createDirectory(path);
|
Files.createDirectory(path);
|
||||||
|
if (UNCPathUtilities.isUNC(path)) {
|
||||||
|
// if the UNC path is using an IP address, convert to hostname
|
||||||
|
path = uncPathUtilities.ipToHostName(path);
|
||||||
|
if (path == null) {
|
||||||
|
throw new IngestModule.IngestModuleException(NbBundle.getMessage(PhotoRecCarverFileIngestModule.class, "PhotoRecIngestModule.nonHostnameUNCPathUsed"));
|
||||||
|
}
|
||||||
|
if (false == FileUtil.hasReadWriteAccess(path)) {
|
||||||
|
throw new IngestModule.IngestModuleException(
|
||||||
|
NbBundle.getMessage(PhotoRecCarverFileIngestModule.class, "PhotoRecIngestModule.PermissionsNotSufficient")
|
||||||
|
+ SEP + path.toString() + SEP // SEP is line breaks to make the dialog display nicely.
|
||||||
|
+ NbBundle.getMessage(PhotoRecCarverFileIngestModule.class, "PhotoRecIngestModule.PermissionsNotSufficientSeeReference"));
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (FileAlreadyExistsException ex) {
|
} catch (FileAlreadyExistsException ex) {
|
||||||
// No worries.
|
// No worries.
|
||||||
} catch (IOException | SecurityException | UnsupportedOperationException ex) {
|
} catch (IOException | SecurityException | UnsupportedOperationException ex) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user