diff --git a/Core/src/org/sleuthkit/autopsy/coreutils/FileUtil.java b/Core/src/org/sleuthkit/autopsy/coreutils/FileUtil.java index a6f11ec684..b1d1c33c51 100644 --- a/Core/src/org/sleuthkit/autopsy/coreutils/FileUtil.java +++ b/Core/src/org/sleuthkit/autopsy/coreutils/FileUtil.java @@ -22,6 +22,8 @@ import java.io.File; import java.io.IOException; import java.util.logging.Level; import org.openide.filesystems.FileObject; +import java.nio.file.Files; +import java.nio.file.Path; /** * File and dir utilities @@ -29,6 +31,7 @@ import org.openide.filesystems.FileObject; public class FileUtil { 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. @@ -167,4 +170,28 @@ 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 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) { + } + } + } + } } 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..bb8d8ed62f 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(); @@ -377,15 +378,21 @@ final class PhotoRecCarverFileIngestModule implements FileIngestModule { */ synchronized Path createModuleOutputDirectoryForCase() throws IngestModule.IngestModuleException { 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 { 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) { // No worries. } catch (IOException | SecurityException | UnsupportedOperationException ex) {