File indexing completed on 2024-09-15 04:56:42
0001 /* This file is part of the KDE project 0002 SPDX-FileCopyrightText: 2009 Jaroslav Reznik <jreznik@redhat.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "config.h" 0008 #include "policykitlistener.h" 0009 // KF 0010 #include <KAboutData> 0011 #include <KCrash> 0012 #include <KDBusService> 0013 #include <KLocalizedString> 0014 // PolkitQt1 0015 #include <PolkitQt1/Subject> 0016 // Qt 0017 #include <QApplication> 0018 #include <QDebug> 0019 #include <QSessionManager> 0020 // std 0021 #if HAVE_SYS_PRCTL_H 0022 #include <sys/prctl.h> 0023 #endif 0024 #if HAVE_SYS_PROCCTL_H 0025 #include <sys/procctl.h> 0026 #include <unistd.h> 0027 #endif 0028 0029 int main(int argc, char *argv[]) 0030 { 0031 // disable ptrace 0032 #if HAVE_PR_SET_DUMPABLE 0033 prctl(PR_SET_DUMPABLE, 0); 0034 #endif 0035 #if HAVE_PROC_TRACE_CTL 0036 int mode = PROC_TRACE_CTL_DISABLE; 0037 procctl(P_PID, getpid(), PROC_TRACE_CTL, &mode); 0038 #endif 0039 KCrash::setFlags(KCrash::AutoRestart); 0040 0041 QApplication app(argc, argv); 0042 app.setQuitOnLastWindowClosed(false); 0043 0044 KLocalizedString::setApplicationDomain(QByteArrayLiteral("polkit-kde-authentication-agent-1")); 0045 0046 KAboutData aboutData("polkit-kde-authentication-agent-1", QString(), POLKIT_KDE_1_VERSION); 0047 aboutData.addLicense(KAboutLicense::GPL); 0048 aboutData.addCredit(i18n("(c) 2009 Red Hat, Inc.")); 0049 aboutData.addAuthor(i18n("Lukáš Tinkl"), i18n("Maintainer"), "ltinkl@redhat.com"); 0050 aboutData.addAuthor(i18n("Jaroslav Reznik"), i18n("Former maintainer"), "jreznik@redhat.com"); 0051 aboutData.setProductName("policykit-kde/polkit-kde-authentication-agent-1"); 0052 0053 KAboutData::setApplicationData(aboutData); 0054 0055 // ensure singleton run 0056 KDBusService service(KDBusService::Unique | KDBusService::Replace); 0057 0058 // disable session management 0059 auto disableSessionManagement = [](QSessionManager &sm) { 0060 sm.setRestartHint(QSessionManager::RestartNever); 0061 }; 0062 0063 QObject::connect(&app, &QGuiApplication::commitDataRequest, disableSessionManagement); 0064 QObject::connect(&app, &QGuiApplication::saveStateRequest, disableSessionManagement); 0065 0066 // register agent 0067 PolicyKitListener *listener = new PolicyKitListener(&app); 0068 0069 PolkitQt1::UnixSessionSubject session(getpid()); 0070 0071 const bool result = listener->registerListener(session, "/org/kde/PolicyKit1/AuthenticationAgent"); 0072 0073 qDebug() << "Authentication agent result:" << result; 0074 0075 if (!result) { 0076 qWarning() << "Couldn't register listener!"; 0077 exit(1); 0078 } 0079 0080 app.exec(); 0081 }