From cc742bbcd6acf27a34928f6ae48e23ce2dbde93f Mon Sep 17 00:00:00 2001 From: Karl Mortensen Date: Mon, 28 Dec 2015 17:12:07 -0500 Subject: [PATCH] Check if permissions are sufficient to read and write output folder --- .../sleuthkit/autopsy/coreutils/FileUtil.java | 39 +++++++++++++++++++ .../modules/photoreccarver/Bundle.properties | 4 +- .../PhotoRecCarverFileIngestModule.java | 7 ++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/coreutils/FileUtil.java b/Core/src/org/sleuthkit/autopsy/coreutils/FileUtil.java index a6f11ec684..159bb6efce 100644 --- a/Core/src/org/sleuthkit/autopsy/coreutils/FileUtil.java +++ b/Core/src/org/sleuthkit/autopsy/coreutils/FileUtil.java @@ -22,6 +22,11 @@ import java.io.File; import java.io.IOException; import java.util.logging.Level; import org.openide.filesystems.FileObject; +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.nio.file.Files; +import java.nio.file.Path; /** * File and dir utilities @@ -29,6 +34,8 @@ import org.openide.filesystems.FileObject; public class FileUtil { private static final Logger logger = Logger.getLogger(FileUtil.class.getName()); + private static String TEST_STRING = "Testing"; + private static String TEMP_FILE_PREFIX = "Autopsy"; /** * Recursively delete all of the files and sub-directories in a directory. @@ -167,4 +174,36 @@ public class FileUtil { //with underscores. We are only keeping \ as it could be part of the path. 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 arePermissionsAppropriate(Path path) { + Path p = null; + try { + p = Files.createTempFile(path, TEMP_FILE_PREFIX, null); + try (FileWriter fw = new FileWriter(p.toFile(), false)) { + fw.write(TEST_STRING); + } + + String result; + try (BufferedReader br = new BufferedReader(new FileReader(p.toFile()))) { + result = br.readLine(); + } + return result.compareTo(TEST_STRING) == 0; + } catch (Exception ex) { + return false; + } finally { + if (p != null) { + try { + p.toFile().delete(); + } catch (Exception ignored) { + } + } + } + } } diff --git a/Core/src/org/sleuthkit/autopsy/modules/photoreccarver/Bundle.properties b/Core/src/org/sleuthkit/autopsy/modules/photoreccarver/Bundle.properties index ed1afb9be9..0d18ff4e2f 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/photoreccarver/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/modules/photoreccarver/Bundle.properties @@ -23,4 +23,6 @@ PhotoRecIngestModule.NotEnoughDiskSpace.detail.msg=PhotoRec error processing {0} PhotoRecIngestModule.cancelledByUser=PhotoRec cancelled by user. PhotoRecIngestModule.error.exitValue=PhotoRec carver returned error exit value = {0} when scanning {1} PhotoRecIngestModule.error.msg=Error processing {0} with PhotoRec carver. -PhotoRecIngestModule.complete.numberOfErrors=Number of Errors while Carving\: \ No newline at end of file +PhotoRecIngestModule.complete.numberOfErrors=Number of Errors while Carving\: +PhotoRecIngestModule.PermissionsNotSufficient=Insufficient permissions accessing +PhotoRecIngestModule.PermissionsNotSufficientSeeReference=See "Shared Drive Authentication" in Autopsy help. \ No newline at end of file diff --git a/Core/src/org/sleuthkit/autopsy/modules/photoreccarver/PhotoRecCarverFileIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/photoreccarver/PhotoRecCarverFileIngestModule.java index b923c4294a..16e3659777 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/photoreccarver/PhotoRecCarverFileIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/photoreccarver/PhotoRecCarverFileIngestModule.java @@ -77,6 +77,7 @@ final class PhotoRecCarverFileIngestModule implements FileIngestModule { 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 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 HashMap totalsForIngestJobs = new HashMap<>(); private static final IngestModuleReferenceCounter refCounter = new IngestModuleReferenceCounter(); @@ -383,6 +384,12 @@ final class PhotoRecCarverFileIngestModule implements FileIngestModule { if (path == null) { throw new IngestModule.IngestModuleException(NbBundle.getMessage(PhotoRecCarverFileIngestModule.class, "PhotoRecIngestModule.nonHostnameUNCPathUsed")); } + if (false == FileUtil.arePermissionsAppropriate(path)) { + throw new IngestModule.IngestModuleException( + NbBundle.getMessage(PhotoRecCarverFileIngestModule.class, "PhotoRecIngestModule.PermissionsNotSufficient") + + SEP + path.toString()+ SEP + + NbBundle.getMessage(PhotoRecCarverFileIngestModule.class, "PhotoRecIngestModule.PermissionsNotSufficientSeeReference")); + } } try { Files.createDirectory(path);