From 2e3a3bcf84b35d001533d626573ad3fccf00b62c Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Wed, 23 Nov 2016 11:05:41 +0100 Subject: [PATCH] Folder: Make folder only accessible by user #5282 (#5315) Because on OS X the parent folder might not protect against access. --- src/gui/accountsettings.cpp | 4 +++- src/gui/owncloudsetupwizard.cpp | 3 ++- src/libsync/filesystem.cpp | 11 +++++++++++ src/libsync/filesystem.h | 6 ++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index c9dc99269..2e0f41eba 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -31,6 +31,7 @@ #include "owncloudsetupwizard.h" #include "creds/abstractcredentials.h" #include "tooltipupdater.h" +#include "filesystem.h" #include @@ -300,8 +301,9 @@ void AccountSettings::slotFolderWizardAccepted() tr("

Could not create local folder %1.") .arg(QDir::toNativeSeparators(definition.localPath))); return; + } else { + FileSystem::setFolderMinimumPermissions(definition.localPath); } - } } diff --git a/src/gui/owncloudsetupwizard.cpp b/src/gui/owncloudsetupwizard.cpp index 993bf04f0..b33e96bd9 100644 --- a/src/gui/owncloudsetupwizard.cpp +++ b/src/gui/owncloudsetupwizard.cpp @@ -31,6 +31,7 @@ #include "sslerrordialog.h" #include "accountmanager.h" #include "clientproxy.h" +#include "filesystem.h" #include "creds/credentialsfactory.h" #include "creds/abstractcredentials.h" @@ -340,8 +341,8 @@ void OwncloudSetupWizard::slotCreateLocalAndRemoteFolders(const QString& localFo } else { QString res = tr("Creating local sync folder %1...").arg(localFolder); if( fi.mkpath( localFolder ) ) { + FileSystem::setFolderMinimumPermissions(localFolder); Utility::setupFavLink( localFolder ); - // FIXME: Create a local sync folder. res += tr("ok"); } else { res += tr("failed."); diff --git a/src/libsync/filesystem.cpp b/src/libsync/filesystem.cpp index 70ed2cefd..044ea3904 100644 --- a/src/libsync/filesystem.cpp +++ b/src/libsync/filesystem.cpp @@ -146,6 +146,17 @@ void FileSystem::setFileReadOnly(const QString& filename, bool readonly) file.setPermissions(permissions); } +void FileSystem::setFolderMinimumPermissions(const QString& filename) +{ +#ifdef Q_OS_MAC + QFile::Permissions perm = QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner; + QFile file(filename); + file.setPermissions(perm); +#else + Q_UNUSED(filename); +#endif +} + void FileSystem::setFileReadOnlyWeak(const QString& filename, bool readonly) { diff --git a/src/libsync/filesystem.h b/src/libsync/filesystem.h index 3daaefbb3..e53e873a9 100644 --- a/src/libsync/filesystem.h +++ b/src/libsync/filesystem.h @@ -67,6 +67,12 @@ void OWNCLOUDSYNC_EXPORT setFileReadOnly(const QString& filename, bool readonly) */ void OWNCLOUDSYNC_EXPORT setFileReadOnlyWeak(const QString& filename, bool readonly); +/** + * @brief Try to set permissions so that other users on the local machine can not + * go into the folder. + */ +void OWNCLOUDSYNC_EXPORT setFolderMinimumPermissions(const QString& filename); + /** convert a "normal" windows path into a path that can be 32k chars long. */ QString OWNCLOUDSYNC_EXPORT longWinPath( const QString& inpath ); -- 2.30.2