diff --git a/CMakeLists.txt b/CMakeLists.txt index bdb00be..bd001e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,127 +1,130 @@ # Copyright (C) 2008 by Volker Lanz # Copyright (C) 2014-2019 by Andrius Štikonas # # 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 . project(kpmcore) cmake_minimum_required(VERSION 3.1 FATAL_ERROR) set(CMAKE_USE_RELATIVE_PATHS OFF) set(CMAKE_BUILD_WITH_INSTALL_RPATH ON) # Dependencies set(QT_MIN_VERSION "5.10.0") set(KF5_MIN_VERSION "5.56") set(BLKID_MIN_VERSION "2.33.2") # Qca-qt5 (tested with botan and ossl backends) # Runtime # smartmontools 7.0 # Qca plugin (botan or ossl) set(VERSION_MAJOR "4") set(VERSION_MINOR "0") set(VERSION_RELEASE "0") set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_RELEASE}) set(SOVERSION "8") add_definitions(-D'VERSION="${VERSION}"') #" 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/") +include_directories(${POLKITQT-1_INCLUDE_DIR}) + include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings NO_POLICY_SCOPE) include(FeatureSummary) include(GenerateExportHeader) include(ECMSetupVersion) ecm_setup_version(${VERSION} VARIABLE_PREFIX KPMCORE VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/kpmcore_version.h" PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KPMcoreConfigVersion.cmake" SOVERSION ${SOVERSION}) find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core DBus Gui Widgets ) # Load the frameworks we need find_package(KF5 ${KF5_MIN_VERSION} REQUIRED Auth CoreAddons I18n WidgetsAddons ) find_package(Qca-qt5 REQUIRED) # use sane compile flags add_definitions( -DQT_USE_QSTRINGBUILDER -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_STRICT_ITERATORS -DQT_NO_URL_CAST_FROM_STRING -DQT_NO_CAST_FROM_BYTEARRAY -DQT_NO_CAST_TO_BYTEARRAY -DQT_NO_SIGNALS_SLOTS_KEYWORDS -DQT_USE_FAST_OPERATOR_PLUS ) kde_enable_exceptions() if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") find_package(PkgConfig REQUIRED) pkg_check_modules(BLKID REQUIRED blkid>=${BLKID_MIN_VERSION}) endif() include_directories(${Qt5Core_INCLUDE_DIRS} ${UUID_INCLUDE_DIRS} ${BLKID_INCLUDE_DIRS} lib/ src/) add_subdirectory(src) # create a Config.cmake and a ConfigVersion.cmake file and install them set(INCLUDE_INSTALL_DIR "include/kpmcore/") set(CMAKECONFIG_INSTALL_DIR "${CMAKECONFIG_INSTALL_PREFIX}/KPMcore") configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/KPMcoreConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/KPMcoreConfig.cmake" INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} PATH_VARS INCLUDE_INSTALL_DIR ) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/KPMcoreConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/KPMcoreConfigVersion.cmake" DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel ) install(EXPORT KPMcoreTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE KPMcoreTargets.cmake ) ki18n_install(po) set_target_properties( kpmcore PROPERTIES VERSION ${VERSION} SOVERSION ${SOVERSION} ) message(STATUS "kpmcore ${VERSION} will be built for install into ${CMAKE_INSTALL_PREFIX}") feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) enable_testing() add_subdirectory(test) diff --git a/FindPolkitQt-1.cmake b/FindPolkitQt-1.cmake new file mode 100644 index 0000000..c6421b6 --- /dev/null +++ b/FindPolkitQt-1.cmake @@ -0,0 +1,36 @@ +/************************************************************************* + * 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/CMakeLists.txt b/src/CMakeLists.txt index e839af2..01a4bb2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,66 +1,67 @@ # Copyright (C) 2008, 2012 by Volker Lanz # Copyright (C) 2015 by Teo Mrnjavac # # 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 . ############################################ add_definitions(-DTRANSLATION_DOMAIN=\"kpmcore\") include(backend/CMakeLists.txt) include(core/CMakeLists.txt) include(util/CMakeLists.txt) include(ops/CMakeLists.txt) include(jobs/CMakeLists.txt) include(fs/CMakeLists.txt) include(gui/CMakeLists.txt) set(kpmcore_SRCS ${BACKEND_SRC} ${FS_SRC} ${CORE_SRC} ${OPS_SRC} ${JOBS_SRC} ${UTIL_SRC} ${GUI_SRC} ) ki18n_wrap_ui(kpmcore_SRCS ${gui_UIFILES}) add_library(kpmcore SHARED ${kpmcore_SRCS}) target_link_libraries( kpmcore PUBLIC Qt5::Core PRIVATE ${BLKID_LIBRARIES} + ${POLKITQT-1_LIBRARIES} Qt5::DBus Qt5::Gui qca-qt5 KF5::I18n KF5::CoreAddons KF5::WidgetsAddons KF5::AuthCore ) install(TARGETS kpmcore EXPORT KPMcoreTargets ${INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES ${CORE_LIB_HDRS} DESTINATION ${INCLUDE_INSTALL_DIR}/kpmcore/core/ COMPONENT Devel) install(FILES ${BACKEND_LIB_HDRS} DESTINATION ${INCLUDE_INSTALL_DIR}/kpmcore/backend/ COMPONENT Devel) install(FILES ${FS_LIB_HDRS} DESTINATION ${INCLUDE_INSTALL_DIR}/kpmcore/fs/ COMPONENT Devel) install(FILES ${JOBS_LIB_HDRS} DESTINATION ${INCLUDE_INSTALL_DIR}/kpmcore/jobs/ COMPONENT Devel) install(FILES ${OPS_LIB_HDRS} DESTINATION ${INCLUDE_INSTALL_DIR}/kpmcore/ops/ COMPONENT Devel) install(FILES ${UTIL_LIB_HDRS} DESTINATION ${INCLUDE_INSTALL_DIR}/kpmcore/util/ COMPONENT Devel) install(FILES ${GUI_LIB_HDRS} DESTINATION ${INCLUDE_INSTALL_DIR}/kpmcore/gui/ COMPONENT Devel) ############################################ add_subdirectory(plugins) diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index b3f2ee2..0ec3d06 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -1,57 +1,60 @@ set(application_interface_xml org.kde.kpmcore.applicationinterface.xml) set(helper_interface_xml org.kde.kpmcore.helperinterface.xml) qt5_generate_dbus_interface( util/externalcommand.h ${application_interface_xml} OPTIONS -a ) qt5_generate_dbus_interface( util/externalcommandhelper.h ${helper_interface_xml} OPTIONS -a ) qt5_add_dbus_interface(ApplicationInterface_SRCS ${CMAKE_CURRENT_BINARY_DIR}/${application_interface_xml} externalcommand_interface) qt5_add_dbus_interface(HelperInterface_SRCS ${CMAKE_CURRENT_BINARY_DIR}/${helper_interface_xml} externalcommandhelper_interface) set(UTIL_SRC ${HelperInterface_SRCS} util/capacity.cpp + util/externalcommand_authagent.cpp util/externalcommand.cpp util/globallog.cpp util/helpers.cpp util/htmlreport.cpp util/report.cpp ) set(UTIL_LIB_HDRS util/libpartitionmanagerexport.h util/capacity.h + util/externalcommand_authagent.h util/externalcommand.h util/globallog.h util/helpers.h util/htmlreport.h util/report.h ) add_executable(kpmcore_externalcommand ${ApplicationInterface_SRCS} util/externalcommandhelper.cpp ) target_link_libraries(kpmcore_externalcommand qca-qt5 + ${POLKITQT-1_LIBRARIES} Qt5::Core Qt5::DBus KF5::AuthCore KF5::I18n ) install(TARGETS kpmcore_externalcommand DESTINATION ${KAUTH_HELPER_INSTALL_DIR}) install( FILES util/org.kde.kpmcore.helperinterface.conf DESTINATION ${KDE_INSTALL_DBUSDIR}/system.d ) install( FILES util/org.kde.kpmcore.applicationinterface.conf DESTINATION ${KDE_INSTALL_DBUSDIR}/system.d ) kauth_install_helper_files(kpmcore_externalcommand org.kde.kpmcore.externalcommand root) kauth_install_actions(org.kde.kpmcore.externalcommand util/org.kde.kpmcore.externalcommand.actions) diff --git a/src/util/externalcommand_authagent.cpp b/src/util/externalcommand_authagent.cpp new file mode 100644 index 0000000..7266b46 --- /dev/null +++ b/src/util/externalcommand_authagent.cpp @@ -0,0 +1,134 @@ +/************************************************************************* + * Copyright (C) 2019 by Shubham * + * * + * 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 .* + *************************************************************************/ + +#include +#include +#include + +#include +#include +#include +#include + +#include "util/externalcommand_authagent.h" + +using namespace PolkitQt1; + +AgentListener::AgentListener(QObject *parent) + : m_authenticationSession(), + m_agentListener() +{ + Q_UNUSED(parent) +} + +AgentListener::~AgentListener() +{ + // Agent Listener destroyed + delete m_agentListener; + delete m_authenticationSession; +} + +bool AgentListener::registerListener(const Subject &subject, const QString &objectPath) +{ + Q_UNUSED(subject) + Q_UNUSED(objectPath) + return true; +// return m_agentListener->listener()->registerListener(subject, objectPath); +} + +void AgentListener::initiateAuthentication(const QString &actionId, + const QString &message, + const QString &iconName, + const Details &details, + const QString &cookie, + const Identity::List &identities, + Agent::AsyncResult *result) +{ + Q_UNUSED(actionId) + Q_UNUSED(message) + Q_UNUSED(iconName) + Q_UNUSED(details) + + //if (registerListener(subject, path)) { + for (const Identity &identity : identities) { + qDebug() << identity.toString(); + m_authenticationSession = new Agent::Session(identity, cookie, result); + + connect(m_authenticationSession, &Agent::Session::request, this, &AgentListener::request); + connect(m_authenticationSession, &Agent::Session::completed, this, &AgentListener::completed); + connect(m_authenticationSession, &Agent::Session::showError, this, &AgentListener::showError); + connect(m_authenticationSession, &Agent::Session::showInfo, this, &AgentListener::showInfo); + + // Using PolkitQt1::Session class member functions/API to initiate the authentication process + m_authenticationSession->initiate(); + } + //} +} + +bool AgentListener::initiateAuthenticationFinish() +{ + qDebug() << "Initializing Authentication finish"; + return true; +} + +void AgentListener::cancelAuthentication() +{ + qDebug() << "Cancelling the Authentication session"; + m_authenticationSession->cancel(); +} + +void AgentListener::setResponse(const QString &response) +{ + Q_UNUSED(response) + + Agent::Session *m_authenticationSession = dynamic_cast(sender()); + m_authenticationSession->setResponse(QStringLiteral("")); + + delete m_authenticationSession; +} + +void AgentListener::request(const QString &request, bool echo) +{ + Q_UNUSED(echo) + + qDebug() << "Request: " << request; + + Agent::Session *m_authenticationSession = dynamic_cast(sender()); + m_authenticationSession->setResponse(QStringLiteral("")); + + delete m_authenticationSession; +} + +void AgentListener::completed(bool gainedAuthorization) +{ + qDebug() << "Action completed: " << gainedAuthorization; + + Agent::Session *m_authenticationSession = dynamic_cast(sender()); + m_authenticationSession->result()->setCompleted(); + + delete m_authenticationSession; +} + +void AgentListener::showError(const QString& text) const +{ + qDebug() << "Error: " << text; +} + +void AgentListener::showInfo(const QString& text) const +{ + qDebug() << "Information: " << text; +} diff --git a/src/util/externalcommand_authagent.h b/src/util/externalcommand_authagent.h new file mode 100644 index 0000000..fa6a1b1 --- /dev/null +++ b/src/util/externalcommand_authagent.h @@ -0,0 +1,62 @@ +/************************************************************************* + * Copyright (C) 2019 by Shubham * + * * + * 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 .* + *************************************************************************/ + +#ifndef EXTERNALCOMMAND_AUTHAGENT_H +#define EXTERNALCOMMAND_AUTHAGENT_H + +#include + +#include +#include +#include +#include + +using namespace PolkitQt1; + +class AgentListener : public Agent::Listener +{ + Q_OBJECT + Q_DISABLE_COPY(AgentListener) +public: + AgentListener(QObject *parent = nullptr); + ~AgentListener(); + +public Q_SLOTS: + bool registerListener(const Subject &subject, const QString &objectPath); + void initiateAuthentication(const QString &actionId, + const QString &message, + const QString &iconName, + const PolkitQt1::Details &details, + const QString &cookie, + const Identity::List &identities, + Agent::AsyncResult *result) override; + bool initiateAuthenticationFinish() override; + void cancelAuthentication() override; + + void setResponse(const QString &response); + void request(const QString &request, bool echo); + void completed(bool gainedAuthorization); + void showError(const QString& text) const; + void showInfo(const QString& text) const; + +private: + Agent::Session *m_authenticationSession; + Listener *m_agentListener; +}; + +#endif // EXTERNALCOMMAND_AUTHAGENT_H +