Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check path validity on Windows will validate NTFS permissions for network drives #6209

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/common/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ namespace Utility {

OCSYNC_EXPORT QString formatWinError(long error);

OCSYNC_EXPORT bool canCreateFileInPath(const QString &path);

class OCSYNC_EXPORT NtfsPermissionLookupRAII
{
public:
Expand Down
10 changes: 10 additions & 0 deletions src/common/utility_win.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in src/common/utility_win.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/common/utility_win.cpp

File src/common/utility_win.cpp does not conform to Custom style guidelines. (lines 437, 438)
* Copyright (C) by Daniel Molkentin <[email protected]>
*
* This library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -33,6 +33,7 @@
#include <QFile>
#include <QLibrary>
#include <QSettings>
#include <QTemporaryFile>

extern Q_CORE_EXPORT int qt_ntfs_permission_lookup;

Expand Down Expand Up @@ -430,6 +431,15 @@
hundredNSecs->HighPart = ll >>32;
}

bool Utility::canCreateFileInPath(const QString &path)
{
Q_ASSERT(!path.isEmpty());
const auto pathWithSlash = !path.endsWith(QLatin1Char('/'))
? path + QLatin1Char('/')
: path;
QTemporaryFile testFile(pathWithSlash + QStringLiteral("~$write-test-file-XXXXXX"));
return testFile.open();
}

QString Utility::formatWinError(long errorCode)
{
Expand Down
12 changes: 11 additions & 1 deletion src/gui/folderman.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in src/gui/folderman.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/gui/folderman.cpp

File src/gui/folderman.cpp does not conform to Custom style guidelines. (lines 1711)
* Copyright (C) by Klaas Freitag <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -1701,10 +1701,20 @@
return FolderMan::tr("The selected path is not a folder!");
}

#ifdef Q_OS_WIN
if (!selFile.isWritable()) {
// isWritable() doesn't cover all NTFS permissions
// try creating and removing a test file, and make sure it is excluded from sync
if (!Utility::canCreateFileInPath(path)) {
return FolderMan::tr("You have no permission to write to the selected folder!");
}
}
#else
if (!selFile.isWritable()) {
return FolderMan::tr("You have no permission to write to the selected folder!");
}
return QString();
#endif
return {};
}

// QFileInfo::canonicalPath returns an empty string if the file does not exist.
Expand Down
Loading