Fix MaintenanceTool file write permission check on Linux and macOS

Running the Qt installer on Linux and macOS with sudo will leave
the installation target directory and some installation files
writable by other users than their owner (root). Make
MaintenanceTool check over all subdirectories in the installation
directory for write permission so that admin rights can be always
requested when needed.

Task-number: QTIFW-1324
Change-Id: I9b314853634642b0be1fb3ea7a9164a2d4beb853
Reviewed-by: Katja Marttila <katja.marttila@qt.io>
This commit is contained in:
Arttu Tarkiainen 2019-05-27 16:05:57 +03:00
parent c97eb6750c
commit 46aecc23b2
2 changed files with 21 additions and 1 deletions

View File

@ -345,6 +345,18 @@ QString PackageManagerCorePrivate::targetDir() const
return m_core->value(scTargetDir);
}
bool PackageManagerCorePrivate::targetSubDirsWritable()
{
// Iterate over target directory subdirectories for writing access
QDirIterator iterator(targetDir(), QDir::AllDirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
while (iterator.hasNext()) {
QTemporaryFile tempFile(iterator.next() + QLatin1String("/tempFile"));
if (!tempFile.open() || !tempFile.isWritable())
return false;
}
return true;
}
QString PackageManagerCorePrivate::configurationFileName() const
{
return m_core->value(scTargetConfigurationFile, QLatin1String("components.xml"));
@ -1622,10 +1634,16 @@ bool PackageManagerCorePrivate::runPackageUpdater()
//to have some progress for the cleanup/write component.xml step
ProgressCoordinator::instance()->addReservePercentagePoints(1);
#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
// check if we need admin rights and ask before the action happens
// on Linux and macOS also check target directory subdirectories
if (!QTemporaryFile(targetDir() + QStringLiteral("/XXXXXX")).open() || !targetSubDirsWritable())
adminRightsGained = m_core->gainAdminRights();
#else
// check if we need admin rights and ask before the action happens
if (!QTemporaryFile(targetDir() + QStringLiteral("/XXXXXX")).open())
adminRightsGained = m_core->gainAdminRights();
#endif
const QList<Component *> componentsToInstall = m_core->orderedComponentsToInstall();
qDebug() << "Install size:" << componentsToInstall.size() << "components";

View File

@ -92,6 +92,8 @@ public:
QString targetDir() const;
QString registerPath();
bool targetSubDirsWritable();
QString maintenanceToolName() const;
QString installerBinaryPath() const;