Search in sources :

Example 1 with AccessDeniedException

use of ch.cyberduck.core.exception.AccessDeniedException in project cyberduck by iterate-ch.

the class UserDefaultsPreferences method setDefaults.

@Override
protected void setDefaults() {
    // Parent defaults
    super.setDefaults();
    if (Sandbox.get().isSandboxed()) {
        // Set actual home directory outside of sandbox
        this.setDefault("local.user.home", SystemB.INSTANCE.getpwuid(LibC.INSTANCE.getuid()).pw_dir);
    }
    if (null != bundle) {
        if (bundle.objectForInfoDictionaryKey("CFBundleName") != null) {
            this.setDefault("application.name", bundle.objectForInfoDictionaryKey("CFBundleName").toString());
        }
        if (bundle.objectForInfoDictionaryKey("NSHumanReadableCopyright") != null) {
            this.setDefault("application.copyright", bundle.objectForInfoDictionaryKey("NSHumanReadableCopyright").toString());
        }
        if (bundle.objectForInfoDictionaryKey("CFBundleIdentifier") != null) {
            final String bundleIdentifier = bundle.objectForInfoDictionaryKey("CFBundleIdentifier").toString();
            this.setDefault("application.identifier", bundleIdentifier);
            // Append bundle identifier to tmp dir
            final Local directory = LocalFactory.get(FoundationKitFunctions.library.NSTemporaryDirectory(), bundleIdentifier);
            try {
                directory.mkdir();
                this.setDefault("tmp.dir", directory.getAbsolute());
            } catch (AccessDeniedException e) {
                log.warn(String.format("Failure creating temporary directory %s", directory));
            }
        }
        if (bundle.objectForInfoDictionaryKey("CFBundleShortVersionString") != null) {
            this.setDefault("application.version", bundle.objectForInfoDictionaryKey("CFBundleShortVersionString").toString());
        }
        if (bundle.objectForInfoDictionaryKey("CFBundleVersion") != null) {
            this.setDefault("application.revision", bundle.objectForInfoDictionaryKey("CFBundleVersion").toString());
        }
        this.setDefault("application.receipt.path", String.format("%s/Contents/_MASReceipt", bundle.bundlePath()));
    }
    this.setDefault("oauth.handler.scheme", String.format("x-%s-action", StringUtils.deleteWhitespace(StringUtils.lowerCase(this.getProperty("application.name")))));
    this.setDefault("update.feed.release", "https://version.cyberduck.io/changelog.rss");
    this.setDefault("update.feed.beta", "https://version.cyberduck.io/beta/changelog.rss");
    this.setDefault("update.feed.nightly", "https://version.cyberduck.io/nightly/changelog.rss");
    this.setDefault("bookmark.import.filezilla.location", "~/.config/filezilla/sitemanager.xml");
    this.setDefault("bookmark.import.fetch.location", "~/Library/Preferences/com.fetchsoftworks.Fetch.Shortcuts.plist");
    this.setDefault("bookmark.import.flow.location", "~/Library/Application Support/Flow/Bookmarks.plist");
    this.setDefault("bookmark.import.interarchy.location", "~/Library/Application Support/Interarchy/Bookmarks.plist");
    this.setDefault("bookmark.import.transmit3.location", "~/Library/Preferences/com.panic.Transmit.plist");
    this.setDefault("bookmark.import.transmit4.location", "~/Library/Application Support/Transmit/Favorites/Favorites.xml");
    this.setDefault("bookmark.import.transmit5.location", "~/Library/Application Support/Transmit/Metadata");
    this.setDefault("bookmark.import.crossftp.location", "~/.crossftp/sites.xml");
    this.setDefault("bookmark.import.fireftp.location", "~/Library/Application Support/Firefox/Profiles");
    this.setDefault("bookmark.import.expandrive3.location", "~/Library/Application Support/ExpanDrive/favorites.js");
    this.setDefault("bookmark.import.expandrive4.location", "~/Library/Application Support/ExpanDrive/expandrive4.favorites.js");
    this.setDefault("bookmark.import.expandrive5.location", "~/Library/Application Support/ExpanDrive/expandrive5.favorites.js");
    this.setDefault("bookmark.import.expandrive6.location", "~/Library/Application Support/ExpanDrive/expandrive6.favorites.js");
    this.setDefault("bookmark.import.cloudmounter.location", "~/Library/Preferences/com.eltima.cloudmounter.plist");
    this.setDefault("browser.filesize.decimal", String.valueOf(true));
    // SSL Keystore
    this.setDefault("connection.ssl.keystore.type", "KeychainStore");
    this.setDefault("connection.ssl.keystore.provider", "Apple");
    this.setDefault("browser.window.tabbing.identifier", "browser.window.tabbing.identifier");
    // Allow to show transfers in browser window as tab
    this.setDefault("queue.window.tabbing.identifier", "browser.window.tabbing.identifier");
    this.setDefault("terminal.command.iterm2", "set t to (create window with default profile)\n" + "tell t\n" + "set s to (current session)\n" + "tell s\n" + "write text \"{0}\"\n" + "end tell\n" + "end tell");
    this.setDefault("terminal.command.default", "do script \"{0}\"");
    // Workaround for #11508
    this.deleteProperty("__NSDisableSharingTextTabInstance");
}
Also used : AccessDeniedException(ch.cyberduck.core.exception.AccessDeniedException) Local(ch.cyberduck.core.Local) NSString(ch.cyberduck.binding.foundation.NSString)

Example 2 with AccessDeniedException

use of ch.cyberduck.core.exception.AccessDeniedException in project cyberduck by iterate-ch.

the class SecurityApplicationGroupSupportDirectoryFinder method find.

@Override
public Local find() {
    final NSFileManager manager = NSFileManager.defaultManager();
    if (manager.respondsToSelector(Foundation.selector("containerURLForSecurityApplicationGroupIdentifier:"))) {
        final NSURL group = manager.containerURLForSecurityApplicationGroupIdentifier(identifier);
        if (null == group) {
            log.warn("Missing com.apple.security.application-groups in sandbox entitlements");
        } else {
            // You should organize the contents of this directory in the same way that any other Library folder is organized
            final String application = PreferencesFactory.get().getProperty("application.datafolder.name");
            final Local folder = new FinderLocal(String.format("%s/Library/Application Support", group.path()), application);
            final Local previous = new ApplicationSupportDirectoryFinder().find();
            if (previous.exists() && !previous.isSymbolicLink()) {
                log.warn(String.format("Migrate application support folder from %s to %s", previous, folder));
                // Rename folder recursively
                try {
                    FileUtils.copyDirectory(new File(previous.getAbsolute()), new File(folder.getAbsolute()));
                    log.warn(String.format("Move application support folder %s to Trash", previous));
                    try {
                        final Trash trash = LocalTrashFactory.get();
                        trash.trash(previous);
                        final Symlink symlink = LocalSymlinkFactory.get();
                        symlink.symlink(previous, folder.getAbsolute());
                    } catch (AccessDeniedException e) {
                        log.warn(String.format("Failure cleaning up previous application support directory. %s", e.getMessage()));
                    }
                } catch (IOException e) {
                    log.warn(String.format("Failure migrating %s to security application group directory %s. %s", previous, folder, e.getMessage()));
                }
            } else {
                log.debug(String.format("No previous application support folder found in %s", previous));
            }
            return folder;
        }
    }
    log.warn("Missing support for security application groups. Default to application support directory");
    // Fallback for 10.7 and earlier
    return new ApplicationSupportDirectoryFinder().find();
}
Also used : AccessDeniedException(ch.cyberduck.core.exception.AccessDeniedException) FinderLocal(ch.cyberduck.core.local.FinderLocal) Symlink(ch.cyberduck.core.local.features.Symlink) NSFileManager(ch.cyberduck.binding.foundation.NSFileManager) NSURL(ch.cyberduck.binding.foundation.NSURL) FinderLocal(ch.cyberduck.core.local.FinderLocal) Local(ch.cyberduck.core.Local) IOException(java.io.IOException) File(java.io.File) Trash(ch.cyberduck.core.local.features.Trash)

Example 3 with AccessDeniedException

use of ch.cyberduck.core.exception.AccessDeniedException in project cyberduck by iterate-ch.

the class ReceiptFactory method open.

@Override
protected License open(final Local file) {
    // Verify immediately and exit if not a valid receipt
    final ReceiptVerifier verifier = new ReceiptVerifier(file);
    if (verifier.verify(new DisabledLicenseVerifierCallback())) {
        // Set name
        final Receipt receipt = new Receipt(file, verifier.getGuid());
        if (log.isInfoEnabled()) {
            log.info(String.format("Valid receipt %s in %s", receipt, file));
        }
        // Copy to Application Support for users switching versions
        final Local support = SupportDirectoryFinderFactory.get().find();
        try {
            file.copy(LocalFactory.get(support, String.format("%s.cyberduckreceipt", receipt.getName())));
        } catch (AccessDeniedException e) {
            log.warn(e.getMessage());
        }
        return receipt;
    } else {
        log.error(String.format("Invalid receipt found in %s", file));
        System.exit(APPSTORE_VALIDATION_FAILURE);
        return null;
    }
}
Also used : AccessDeniedException(ch.cyberduck.core.exception.AccessDeniedException) Local(ch.cyberduck.core.Local)

Example 4 with AccessDeniedException

use of ch.cyberduck.core.exception.AccessDeniedException in project cyberduck by iterate-ch.

the class PlistWriter method write.

@Override
public void write(final Collection<S> collection, final Local file) throws AccessDeniedException {
    final NSArray list = new NSArray(collection.size());
    int i = 0;
    for (S bookmark : collection) {
        list.setValue(i, bookmark.<NSDictionary>serialize(new PlistSerializer()));
        i++;
    }
    final String content = list.toXMLPropertyList();
    try (final OutputStream out = file.getOutputStream(false)) {
        IOUtils.write(content, out, StandardCharsets.UTF_8);
    } catch (IOException e) {
        throw new AccessDeniedException(String.format("Cannot create file %s", file.getAbsolute()), e);
    }
}
Also used : AccessDeniedException(ch.cyberduck.core.exception.AccessDeniedException) NSArray(com.dd.plist.NSArray) OutputStream(java.io.OutputStream) IOException(java.io.IOException)

Example 5 with AccessDeniedException

use of ch.cyberduck.core.exception.AccessDeniedException in project cyberduck by iterate-ch.

the class AbstractUploadFilter method prepare.

@Override
public TransferStatus prepare(final Path file, final Local local, final TransferStatus parent, final ProgressListener progress) throws BackgroundException {
    if (log.isDebugEnabled()) {
        log.debug(String.format("Prepare %s", file));
    }
    final TransferStatus status = new TransferStatus().hidden(!hidden.accept(file)).withLockId(parent.getLockId());
    // Read remote attributes first
    if (parent.isExists()) {
        if (find.find(file)) {
            status.setExists(true);
            // Read remote attributes
            final PathAttributes attributes = attribute.find(file);
            status.setRemote(attributes);
        } else {
            // Look if there is directory or file that clashes with this upload
            if (file.getType().contains(Path.Type.file)) {
                if (find.find(new Path(file.getAbsolute(), EnumSet.of(Path.Type.directory)))) {
                    throw new AccessDeniedException(String.format("Cannot replace folder %s with file %s", file.getAbsolute(), local.getName()));
                }
            }
            if (file.getType().contains(Path.Type.directory)) {
                if (find.find(new Path(file.getAbsolute(), EnumSet.of(Path.Type.file)))) {
                    throw new AccessDeniedException(String.format("Cannot replace file %s with folder %s", file.getAbsolute(), local.getName()));
                }
            }
        }
    }
    if (file.isFile()) {
        // Set content length from local file
        if (local.isSymbolicLink()) {
            if (!symlinkResolver.resolve(local)) {
                // Will resolve the symbolic link when the file is requested.
                final Local target = local.getSymlinkTarget();
                status.setLength(target.attributes().getSize());
            }
        // No file size increase for symbolic link to be created on the server
        } else {
            // Read file size from filesystem
            status.setLength(local.attributes().getSize());
        }
        if (options.temporary) {
            final Move feature = session.getFeature(Move.class);
            final Path renamed = new Path(file.getParent(), MessageFormat.format(preferences.getProperty("queue.upload.file.temporary.format"), file.getName(), new AlphanumericRandomStringService().random()), file.getType());
            if (feature.isSupported(file, renamed)) {
                if (log.isDebugEnabled()) {
                    log.debug(String.format("Set temporary filename %s", renamed));
                }
                status.temporary(renamed, file);
            }
        }
        status.withMime(new MappingMimeTypeService().getMime(file.getName()));
    }
    if (file.isDirectory()) {
        status.setLength(0L);
    }
    if (options.permissions) {
        final UnixPermission feature = session.getFeature(UnixPermission.class);
        if (feature != null) {
            if (status.isExists()) {
                // Already set when reading attributes of file
                status.setPermission(status.getRemote().getPermission());
            } else {
                status.setPermission(feature.getDefault(local));
            }
        } else {
            // Setting target UNIX permissions in transfer status
            status.setPermission(Permission.EMPTY);
        }
    }
    if (options.acl) {
        final AclPermission feature = session.getFeature(AclPermission.class);
        if (feature != null) {
            if (status.isExists()) {
                progress.message(MessageFormat.format(LocaleFactory.localizedString("Getting permission of {0}", "Status"), file.getName()));
                try {
                    status.setAcl(feature.getPermission(file));
                } catch (NotfoundException | AccessDeniedException | InteroperabilityException e) {
                    status.setAcl(feature.getDefault(file, local));
                }
            } else {
                status.setAcl(feature.getDefault(file, local));
            }
        } else {
            // Setting target ACL in transfer status
            status.setAcl(Acl.EMPTY);
        }
    }
    if (options.timestamp) {
        final Timestamp feature = session.getFeature(Timestamp.class);
        if (feature != null) {
            // Read timestamps from local file
            status.setTimestamp(feature.getDefault(local));
        } else {
            if (1L != local.attributes().getModificationDate()) {
                status.setTimestamp(local.attributes().getModificationDate());
            }
        }
    }
    if (options.metadata) {
        final Headers feature = session.getFeature(Headers.class);
        if (feature != null) {
            if (status.isExists()) {
                progress.message(MessageFormat.format(LocaleFactory.localizedString("Reading metadata of {0}", "Status"), file.getName()));
                try {
                    status.setMetadata(feature.getMetadata(file));
                } catch (NotfoundException | AccessDeniedException | InteroperabilityException e) {
                    status.setMetadata(feature.getDefault(local));
                }
            } else {
                status.setMetadata(feature.getDefault(local));
            }
        }
    }
    if (options.encryption) {
        final Encryption feature = session.getFeature(Encryption.class);
        if (feature != null) {
            if (status.isExists()) {
                progress.message(MessageFormat.format(LocaleFactory.localizedString("Reading metadata of {0}", "Status"), file.getName()));
                try {
                    status.setEncryption(feature.getEncryption(file));
                } catch (NotfoundException | AccessDeniedException | InteroperabilityException e) {
                    status.setEncryption(feature.getDefault(file));
                }
            } else {
                status.setEncryption(feature.getDefault(file));
            }
        }
    }
    if (options.redundancy) {
        if (file.isFile()) {
            final Redundancy feature = session.getFeature(Redundancy.class);
            if (feature != null) {
                if (status.isExists()) {
                    progress.message(MessageFormat.format(LocaleFactory.localizedString("Reading metadata of {0}", "Status"), file.getName()));
                    try {
                        status.setStorageClass(feature.getClass(file));
                    } catch (NotfoundException | AccessDeniedException | InteroperabilityException e) {
                        status.setStorageClass(feature.getDefault());
                    }
                } else {
                    status.setStorageClass(feature.getDefault());
                }
            }
        }
    }
    if (options.checksum) {
        if (file.isFile()) {
            final ChecksumCompute feature = session.getFeature(Write.class).checksum(file, status);
            if (feature != null) {
                progress.message(MessageFormat.format(LocaleFactory.localizedString("Calculate checksum for {0}", "Status"), file.getName()));
                try {
                    status.setChecksum(feature.compute(local.getInputStream(), status));
                } catch (LocalAccessDeniedException e) {
                    // Ignore failure reading file when in sandbox when we miss a security scoped access bookmark.
                    // Lock for files is obtained only later in Transfer#pre
                    log.warn(e.getMessage());
                }
            }
        }
    }
    return status;
}
Also used : Path(ch.cyberduck.core.Path) Write(ch.cyberduck.core.features.Write) AccessDeniedException(ch.cyberduck.core.exception.AccessDeniedException) LocalAccessDeniedException(ch.cyberduck.core.exception.LocalAccessDeniedException) LocalNotfoundException(ch.cyberduck.core.exception.LocalNotfoundException) NotfoundException(ch.cyberduck.core.exception.NotfoundException) InteroperabilityException(ch.cyberduck.core.exception.InteroperabilityException) Redundancy(ch.cyberduck.core.features.Redundancy) Headers(ch.cyberduck.core.features.Headers) PathAttributes(ch.cyberduck.core.PathAttributes) Local(ch.cyberduck.core.Local) Encryption(ch.cyberduck.core.features.Encryption) Timestamp(ch.cyberduck.core.features.Timestamp) UnixPermission(ch.cyberduck.core.features.UnixPermission) ChecksumCompute(ch.cyberduck.core.io.ChecksumCompute) AclPermission(ch.cyberduck.core.features.AclPermission) Move(ch.cyberduck.core.features.Move) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) MappingMimeTypeService(ch.cyberduck.core.MappingMimeTypeService) LocalAccessDeniedException(ch.cyberduck.core.exception.LocalAccessDeniedException)

Aggregations

AccessDeniedException (ch.cyberduck.core.exception.AccessDeniedException)71 Path (ch.cyberduck.core.Path)27 IOException (java.io.IOException)23 InteroperabilityException (ch.cyberduck.core.exception.InteroperabilityException)19 Local (ch.cyberduck.core.Local)18 Test (org.junit.Test)18 NotfoundException (ch.cyberduck.core.exception.NotfoundException)14 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)14 BackgroundException (ch.cyberduck.core.exception.BackgroundException)12 LoginFailureException (ch.cyberduck.core.exception.LoginFailureException)11 IntegrationTest (ch.cyberduck.test.IntegrationTest)9 DisabledConnectionCallback (ch.cyberduck.core.DisabledConnectionCallback)8 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)8 Delete (ch.cyberduck.core.features.Delete)8 InputStream (java.io.InputStream)8 ServiceException (org.jets3t.service.ServiceException)8 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)7 PathAttributes (ch.cyberduck.core.PathAttributes)7 BandwidthThrottle (ch.cyberduck.core.io.BandwidthThrottle)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7