From 46aecc23b2983c807ff2232ae9cb9651b4d2fdc2 Mon Sep 17 00:00:00 2001 From: Arttu Tarkiainen Date: Mon, 27 May 2019 16:05:57 +0300 Subject: 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 --- src/libs/installer/packagemanagercore_p.cpp | 20 +++++++++++++++++++- src/libs/installer/packagemanagercore_p.h | 2 ++ 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/libs/installer/packagemanagercore_p.cpp b/src/libs/installer/packagemanagercore_p.cpp index 29c3fb03a..47e1dadb4 100644 --- a/src/libs/installer/packagemanagercore_p.cpp +++ b/src/libs/installer/packagemanagercore_p.cpp @@ -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 componentsToInstall = m_core->orderedComponentsToInstall(); qDebug() << "Install size:" << componentsToInstall.size() << "components"; diff --git a/src/libs/installer/packagemanagercore_p.h b/src/libs/installer/packagemanagercore_p.h index e0817c573..3e3f15ab8 100644 --- a/src/libs/installer/packagemanagercore_p.h +++ b/src/libs/installer/packagemanagercore_p.h @@ -92,6 +92,8 @@ public: QString targetDir() const; QString registerPath(); + bool targetSubDirsWritable(); + QString maintenanceToolName() const; QString installerBinaryPath() const; -- cgit v1.2.3