Folder: Make folder only accessible by user #5282 (#5315)

Because on OS X the parent folder might not protect
against access.
This commit is contained in:
Markus Goetz 2016-11-23 11:05:41 +01:00 committed by GitHub
parent ad437a49f9
commit 2e3a3bcf84
4 changed files with 22 additions and 2 deletions

View file

@ -31,6 +31,7 @@
#include "owncloudsetupwizard.h"
#include "creds/abstractcredentials.h"
#include "tooltipupdater.h"
#include "filesystem.h"
#include <math.h>
@ -300,8 +301,9 @@ void AccountSettings::slotFolderWizardAccepted()
tr("<p>Could not create local folder <i>%1</i>.")
.arg(QDir::toNativeSeparators(definition.localPath)));
return;
} else {
FileSystem::setFolderMinimumPermissions(definition.localPath);
}
}
}

View file

@ -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.");

View file

@ -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)
{

View file

@ -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 );