diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,12 +41,11 @@ set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) -find_package(PolkitQt-1 REQUIRED) find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/") -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) +find_package(PolkitQt5-1 REQUIRED) -include_directories(${POLKITQT-1_INCLUDE_DIR}) +include_directories(${POLKITQT5-1_INCLUDE_DIR}) include(KDEInstallDirs) include(KDECMakeSettings) diff --git a/cmake/modules/FindPolkitQt-1.cmake b/cmake/modules/FindPolkitQt-1.cmake deleted file mode 100644 --- a/cmake/modules/FindPolkitQt-1.cmake +++ /dev/null @@ -1,36 +0,0 @@ -/************************************************************************* - * Copyright (c) 2010 Dario Freddi * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License as * - * published by the Free Software Foundation; either version 3 of * - * the License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see .* - *************************************************************************/ - -# Support POLKITQT-1_MIN_VERSION for compatibility: - -if ( NOT PolkitQt-1_FIND_VERSION AND POLKITQT-1_MIN_VERSION ) - set ( PolkitQt-1_FIND_VERSION ${POLKITQT-1_MIN_VERSION} ) -endif ( NOT PolkitQt-1_FIND_VERSION AND POLKITQT-1_MIN_VERSION ) - -set( _PolkitQt-1_FIND_QUIETLY ${PolkitQt-1_FIND_QUIETLY} ) -find_package( PolkitQt-1 ${PolkitQt-1_FIND_VERSION} QUIET NO_MODULE PATHS ${LIB_INSTALL_DIR}/PolkitQt-1/cmake ) -set( PolkitQt-1_FIND_QUIETLY ${_PolkitQt-1_FIND_QUIETLY} ) - -include( FindPackageHandleStandardArgs ) -find_package_handle_standard_args( PolkitQt-1 DEFAULT_MSG PolkitQt-1_CONFIG ) - -if (POLKITQT-1_FOUND) - if (NOT POLKITQT-1_INSTALL_DIR STREQUAL CMAKE_INSTALL_PREFIX) - message("WARNING: Installation prefix does not match PolicyKit install prefixes. You probably will need to move files installed " - "in POLICY_FILES_INSTALL_DIR and by dbus_add_activation_system_service to the ${POLKITQT-1_INSTALL_DIR} prefix") - endif (NOT POLKITQT-1_INSTALL_DIR STREQUAL CMAKE_INSTALL_PREFIX) -endif (POLKITQT-1_FOUND) diff --git a/src/util/dbus.service b/src/util/dbus.service new file mode 100644 --- /dev/null +++ b/src/util/dbus.service @@ -0,0 +1,4 @@ +[D-BUS Service] +Name=org.kde.kpmcore.externalcommand +Exec=@LIBEXEC_INSTALL_DIR@/externalcommandhelper +User=root diff --git a/src/util/externalcommandhelper.h b/src/util/externalcommandhelper.h --- a/src/util/externalcommandhelper.h +++ b/src/util/externalcommandhelper.h @@ -23,20 +23,26 @@ #include +#include #include #include #include +#include + using namespace KAuth; -class ExternalCommandHelper : public QObject +using namespace PolkitQt1; + +class ExternalCommandHelper : public QObject, protected QDBusContext { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.kde.kpmcore.externalcommand") Q_SIGNALS: void progress(int); void quit(); + void actionAuthorized(); public: bool readData(const QString& sourceDevice, QByteArray& buffer, const qint64 offset, const qint64 size); @@ -48,6 +54,8 @@ Q_SCRIPTABLE QVariantMap copyblocks(const QString& sourceDevice, const qint64 sourceFirstByte, const qint64 sourceLength, const QString& targetDevice, const qint64 targetFirstByte, const qint64 blockSize); Q_SCRIPTABLE bool writeData(const QByteArray& buffer, const QString& targetDevice, const qint64 targetFirstByte); Q_SCRIPTABLE void exit(); + Q_SCRIPTABLE bool authorize(const QString &actionId, const Subject &subject, + const Authority::AuthorizationFlags flags); private: void onReadOutput(); diff --git a/src/util/externalcommandhelper.cpp b/src/util/externalcommandhelper.cpp --- a/src/util/externalcommandhelper.cpp +++ b/src/util/externalcommandhelper.cpp @@ -19,14 +19,19 @@ #include "externalcommand_whitelist.h" #include +#include #include #include #include #include #include #include +#include + +using namespace PolkitQt1; + /** Initialize ExternalCommandHelper Daemon and prepare DBus interface * * KAuth helper runs in the background until application exits. @@ -276,6 +281,25 @@ QDBusConnection::systemBus().unregisterService(QStringLiteral("org.kde.kpmcore.helperinterface")); } +bool ExternalCommandHelper::authorize(const QString &actionId, const Subject &subject, + const Authority::AuthorizationFlags flags) +{ + qDebug() << "Authorizing actions through ExternalCommand Helper"; + + const Authority::Result result = Authority::instance()->checkAuthorizationSync(actionId, subject, flags); + //SystemBusNameSubject subject(message().service()); + + if (result == Authority::Yes) { + qDebug() << "Subject is authorized to perform previliged tasks. You can proceed further now"; + emit actionAuthorized(); + return true; + } else { + qDebug() << "Subject was unable to authorize itself. Can not proceed further"; + qApp->quit(); + return false; + } +} + void ExternalCommandHelper::onReadOutput() { /* const QByteArray s = cmd.readAllStandardOutput();