File indexing completed on 2024-09-15 10:40:31
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 #include <KXMessages> 0015 // PolkitQt1 0016 #include <PolkitQt1/Subject> 0017 // Qt 0018 #include <QApplication> 0019 #include <QDebug> 0020 #include <QSessionManager> 0021 // std 0022 #if HAVE_SYS_PRCTL_H 0023 #include <sys/prctl.h> 0024 #endif 0025 #if HAVE_SYS_PROCCTL_H 0026 #include <sys/procctl.h> 0027 #include <unistd.h> 0028 #endif 0029 0030 int main(int argc, char *argv[]) 0031 { 0032 // disable ptrace 0033 #if HAVE_PR_SET_DUMPABLE 0034 prctl(PR_SET_DUMPABLE, 0); 0035 #endif 0036 #if HAVE_PROC_TRACE_CTL 0037 int mode = PROC_TRACE_CTL_DISABLE; 0038 procctl(P_PID, getpid(), PROC_TRACE_CTL, &mode); 0039 #endif 0040 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 0041 QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true); 0042 #endif 0043 KCrash::setFlags(KCrash::AutoRestart); 0044 0045 QApplication app(argc, argv); 0046 app.setQuitOnLastWindowClosed(false); 0047 0048 KLocalizedString::setApplicationDomain("polkit-kde-authentication-agent-1"); 0049 0050 KAboutData aboutData("polkit-kde-authentication-agent-1", i18n("PolicyKit1 KDE Agent"), POLKIT_KDE_1_VERSION); 0051 aboutData.addLicense(KAboutLicense::GPL); 0052 aboutData.addCredit(i18n("(c) 2009 Red Hat, Inc.")); 0053 aboutData.addAuthor(i18n("Lukáš Tinkl"), i18n("Maintainer"), "ltinkl@redhat.com"); 0054 aboutData.addAuthor(i18n("Jaroslav Reznik"), i18n("Former maintainer"), "jreznik@redhat.com"); 0055 aboutData.setProductName("policykit-kde/polkit-kde-authentication-agent-1"); 0056 0057 KAboutData::setApplicationData(aboutData); 0058 0059 // ensure singleton run 0060 KDBusService service(KDBusService::Unique); 0061 0062 // disable session management 0063 auto disableSessionManagement = [](QSessionManager &sm) { 0064 sm.setRestartHint(QSessionManager::RestartNever); 0065 }; 0066 0067 QObject::connect(&app, &QGuiApplication::commitDataRequest, disableSessionManagement); 0068 QObject::connect(&app, &QGuiApplication::saveStateRequest, disableSessionManagement); 0069 0070 // Force extreme focus protection to prevent losing focus to any other window. 0071 // https://bugs.kde.org/show_bug.cgi?id=312325 0072 KXMessages msg; 0073 const QString message = QStringLiteral( 0074 "fpplevel=4\n" 0075 "fpplevelrule=2\n" 0076 "wmclass=polkit-kde-authentication-agent-1\n" 0077 "wmclassmatch=1\n"); 0078 msg.broadcastMessage("_KDE_NET_WM_TEMPORARY_RULES", message, -1); 0079 0080 // register agent 0081 PolicyKitListener *listener = new PolicyKitListener(&app); 0082 0083 PolkitQt1::UnixSessionSubject session(getpid()); 0084 0085 const bool result = listener->registerListener(session, "/org/kde/PolicyKit1/AuthenticationAgent"); 0086 0087 qDebug() << "Authentication agent result:" << result; 0088 0089 if (!result) { 0090 qWarning() << "Couldn't register listener!"; 0091 exit(1); 0092 } 0093 0094 app.exec(); 0095 }