diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f5bc11..33fbdc4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,90 +1,89 @@ cmake_minimum_required(VERSION 3.0) project(polkit-kde-agent-1) set(PROJECT_VERSION "5.12.80") set(QT_MIN_VERSION "5.9.0") set(KF5_MIN_VERSION "5.42.0") # we need some parts of the ECM CMake helpers find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE) set (CMAKE_MODULE_PATH ${ECM_MODULE_PATH}) include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings NO_POLICY_SCOPE) include(FeatureSummary) find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED Core DBus Widgets) # Load the frameworks we need find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS I18n WindowSystem DBusAddons WidgetsAddons CoreAddons Crash IconThemes ) include(CheckIncludeFile) include(CheckSymbolExists) check_include_file("sys/prctl.h" HAVE_SYS_PRCTL_H) check_symbol_exists(PR_SET_DUMPABLE "sys/prctl.h" HAVE_PR_SET_DUMPABLE) check_include_file("sys/procctl.h" HAVE_SYS_PROCCTL_H) check_symbol_exists(PROC_TRACE_CTL "sys/procctl.h" HAVE_PROC_TRACE_CTL) if (HAVE_PR_SET_DUMPABLE OR HAVE_PROC_TRACE_CTL) set(CAN_DISABLE_PTRACE TRUE) endif () add_feature_info("prctl/procctl tracing control" CAN_DISABLE_PTRACE "Required for disallowing ptrace on polkit agent") # create config file configure_file (config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h) # let our config.h be found first in any case include_directories (BEFORE ${CMAKE_CURRENT_BINARY_DIR}) find_package(PolkitQt5-1 REQUIRED 0.103.0) include_directories( ${POLKITQT-1_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) qt5_add_dbus_adaptor(policykit_SRCS org.kde.Polkit1AuthAgent.xml policykitlistener.h PolicyKitListener) ki18n_wrap_ui(policykit_SRCS AuthDialog.ui authdetails.ui) set(policykit_SRCS ${policykit_SRCS} - policykitkde.cpp policykitlistener.cpp main.cpp AuthDialog.cpp ) add_executable(polkit-kde-authentication-agent-1 ${policykit_SRCS}) target_link_libraries(polkit-kde-authentication-agent-1 KF5::DBusAddons KF5::WindowSystem KF5::WidgetsAddons KF5::CoreAddons KF5::I18n KF5::Crash KF5::IconThemes ${POLKITQT-1_LIBRARIES} ) configure_file(polkit-kde-authentication-agent-1.desktop.cmake ${CMAKE_BINARY_DIR}/polkit-kde-authentication-agent-1.desktop) install(TARGETS polkit-kde-authentication-agent-1 DESTINATION ${KDE_INSTALL_LIBEXECDIR}) install(FILES ${CMAKE_BINARY_DIR}/polkit-kde-authentication-agent-1.desktop DESTINATION ${KDE_INSTALL_AUTOSTARTDIR}) install(FILES policykit1-kde.notifyrc DESTINATION ${KDE_INSTALL_KNOTIFY5RCDIR}) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/main.cpp b/main.cpp index 9ec79de..a30eeca 100644 --- a/main.cpp +++ b/main.cpp @@ -1,77 +1,99 @@ /* This file is part of the KDE project Copyright (C) 2009 Jaroslav Reznik 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 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include "policykitlistener.h" #include "config.h" - +// KF #include #include #include #include - +// PolkitQt1 +#include +// Qt +#include #include - -#include "policykitkde.h" - +#include +// std #if HAVE_SYS_PRCTL_H #include #endif #if HAVE_SYS_PROCCTL_H #include #include #endif + int main(int argc, char *argv[]) { // disable ptrace #if HAVE_PR_SET_DUMPABLE prctl(PR_SET_DUMPABLE, 0); #endif #if HAVE_PROC_TRACE_CTL int mode = PROC_TRACE_CTL_DISABLE; procctl(P_PID, getpid(), PROC_TRACE_CTL, &mode); #endif + QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true); + + KCrash::setFlags(KCrash::AutoRestart); + + QApplication app(argc, argv); + app.setQuitOnLastWindowClosed(false); + KLocalizedString::setApplicationDomain("polkit-kde-authentication-agent-1"); + KAboutData aboutData("polkit-kde-authentication-agent-1", i18n("PolicyKit1 KDE Agent"), POLKIT_KDE_1_VERSION); aboutData.addLicense(KAboutLicense::GPL); aboutData.addCredit(i18n("(c) 2009 Red Hat, Inc.")); aboutData.addAuthor(i18n("Lukáš Tinkl"), i18n("Maintainer"), "ltinkl@redhat.com"); aboutData.addAuthor(i18n("Jaroslav Reznik"), i18n("Former maintainer"), "jreznik@redhat.com"); aboutData.setProductName("policykit-kde/polkit-kde-authentication-agent-1"); KAboutData::setApplicationData(aboutData); - QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org")); - QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true); - - KCrash::setFlags(KCrash::AutoRestart); - - PolicyKitKDE agent(argc, argv); + // ensure singleton run KDBusService service(KDBusService::Unique); + // disable session management auto disableSessionManagement = [](QSessionManager &sm) { sm.setRestartHint(QSessionManager::RestartNever); }; - QObject::connect(&agent, &QGuiApplication::commitDataRequest, disableSessionManagement); - QObject::connect(&agent, &QGuiApplication::saveStateRequest, disableSessionManagement); + QObject::connect(&app, &QGuiApplication::commitDataRequest, disableSessionManagement); + QObject::connect(&app, &QGuiApplication::saveStateRequest, disableSessionManagement); + + // register agent + PolicyKitListener *listener = new PolicyKitListener(&app); + + PolkitQt1::UnixSessionSubject session(getpid()); + + const bool result = listener->registerListener(session, "/org/kde/PolicyKit1/AuthenticationAgent"); + + qDebug() << "Authentication agent result:" << result; + + if (!result) { + qWarning() << "Couldn't register listener!"; + exit(1); + } - agent.exec(); + app.exec(); } diff --git a/policykitkde.cpp b/policykitkde.cpp deleted file mode 100644 index 24553a8..0000000 --- a/policykitkde.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2009 Jaroslav Reznik - - 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 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - -*/ - -#include -#include - -#include - -#include "policykitkde.h" - -PolicyKitKDE::PolicyKitKDE(int &argc,char **argv): - QApplication(argc, argv), - m_listener(new PolicyKitListener(this)) -{ - setQuitOnLastWindowClosed(false); - - PolkitQt1::UnixSessionSubject session(getpid()); - - bool result = m_listener->registerListener(session, "/org/kde/PolicyKit1/AuthenticationAgent"); - - qDebug() << "Authentication agent result:" << result; - - if (!result) { - qWarning() << "Couldn't register listener!"; - exit(1); - } -} - -PolicyKitKDE::~PolicyKitKDE() -{ - m_listener->deleteLater(); -} diff --git a/policykitkde.h b/policykitkde.h deleted file mode 100644 index e3cc9a5..0000000 --- a/policykitkde.h +++ /dev/null @@ -1,38 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2009 Jaroslav Reznik - - 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 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - -*/ - -#ifndef POLICYKITKDE_H -#define POLICYKITKDE_H - -#include - -#include "policykitlistener.h" - -class PolicyKitKDE : public QApplication -{ - Q_OBJECT -public: - PolicyKitKDE(int &argc, char **argv); - ~PolicyKitKDE() override; -private: - PolicyKitListener *m_listener; -}; - -#endif