Debian Codegraph @

src/helper/helper.cpp

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-3.0-or-latercxx . . $ `<file>/src/helper/helper.cpp`/
2 // Copyright 2019 Juan Palacios <[email protected]>
3
4 #include "helper.h"cxx . . $ `<file>/src/helper/helper.h`/
5
6 #include "common/cryptolayer.h"cxx . . $ `<file>/src/common/cryptolayer.h`/
7 #include "common/logger.h"cxx . . $ `<file>/src/common/logger.h`/
8 #include "helperids.h"cxx . . $ `<file>/src/helper/helperids.h`/
9 #include "pmon/appregistry.h"cxx . . $ `<file>/src/helper/pmon/appregistry.h`/
10 #include "pmon/msgdispatcher.h"cxx . . $ `<file>/src/helper/pmon/msgdispatcher.h`/
11 #include "pmon/nlprocexecmonitor.h"cxx . . $ `<file>/src/helper/pmon/nlprocexecmonitor.h`/
12 #include "pmon/nlprocexecsocket.h"cxx . . $ `<file>/src/helper/pmon/nlprocexecsocket.h`/
13 #include "pmon/procpidsolver.h"cxx . . $ `<file>/src/helper/pmon/procpidsolver.h`/
14 #include "polkit.h"cxx . . $ `<file>/src/helper/polkit.h`/
15 #include "sysctl/msgreceiver.h"cxx . . $ `<file>/src/helper/sysctl/msgreceiver.h`/
16 #include "sysctl/sysfswriter.h"cxx . . $ `<file>/src/helper/sysctl/sysfswriter.h`/
17 #include <QByteArray>
18 #include <QCoreApplication>
19 #include <QDBusConnection>
20 #include <QDBusError>
21 #include <QString>
22 #include <exception>
23 #include <filesystem>
24
25 Helpercxx . . $ Helper#::Helpercxx . . $ Helper#Helper(cc6a52b634b3d446).(QObjectcxx . . $ QObject# *parent) noexcept
26 : QDBusAbstractAdaptorcxx . . $ QDBusAbstractAdaptor#(parent)
27 {
28 }
29
30 Helpercxx . . $ Helper#::~cxx . . $ Helper#`~Helper`(ced63f7c635d850d).Helpercxx . . $ Helper#() = default;
31
32 QDBusVariantcxx . . $ QDBusVariant# Helpercxx . . $ Helper#::startcxx . . $ Helper#start(f145be74c3091c78).(QByteArraycxx . . $ QByteArray# const &appPublicKey, int autoExitTimeout,
33 QDBusMessagecxx . . $ QDBusMessage# const &message)
34 {
35 if (!startedcxx . . $ Helper#started(50ce9a9e25b4a850).()) {
36 setupLoggercxx . . $ setupLogger(3f42e2c2fac0d5fc).(stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::temp_directory_pathcxx . . $ std/filesystem/temp_directory_path(4c12bfa3c403d782).() /cxx . . $ std/filesystem/__cxx11/`operator/`(578e0438ad5f0e7e). LOG_HELPER_FILE_NAMEcxx . . $ `src/helper/helperids.h:21:9`!);
37
38 SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!("----- Helper started -----");
39
40 if (!(isAuthorizedcxx . . $ Helper#isAuthorized(88cf1e7c0a6f9f8e).(message) && initCryptocxx . . $ Helper#initCrypto(544790aa27d183a0).(appPublicKey) &&
41 initProcessMonitorcxx . . $ Helper#initProcessMonitor(c9857a73d68e59ba).() && initMsgReceivercxx . . $ Helper#initMsgReceiver(c9857a73d68e59ba).())) {
42 exitHelpercxx . . $ Helper#exitHelper(49f6e7a06ebc5aa8).();
43 return QDBusVariantcxx . . $ QDBusVariant#(falsecxx . . $ QVariant#QVariant(9f0ba574c1c44ffc).);
44 }
45
46 autoExitTimer_cxx . . $ Helper#autoExitTimer_..setIntervalcxx . . $ QTimer#setInterval(d4f767463ce0a6b3).(autoExitTimeout);
47 autoExitTimer_cxx . . $ Helper#autoExitTimer_..setSingleShotcxx . . $ QTimer#setSingleShot(b45ddcbc8423892c).(true);
48 connectcxx . . $ QObject#connect(dad3a9587f3dce3c).(&autoExitTimer_cxx . . $ Helper#autoExitTimer_., &QTimercxx . . $ QTimer#::timeoutcxx . . $ QTimer#timeout(32604d697c0ceadc)., this, &Helpercxx . . $ Helper#::autoExitTimeoutcxx . . $ Helper#autoExitTimeout(49f6e7a06ebc5aa8).);
49 autoExitTimer_cxx . . $ Helper#autoExitTimer_..startcxx . . $ QTimer#start(49f6e7a06ebc5aa8).();
50 }
51
52 return QDBusVariantcxx . . $ QDBusVariant#(cryptoLayer_cxx . . $ QVariant#QVariant(6bfe0b9ef323589d).->cxx . . $ std/__shared_ptr_access#`operator->`(34d6acfd341ba7ab).publicKeycxx . . $ ICryptoLayer#publicKey(b3c286cec66e09f4).());
53 }
54
55 bool Helpercxx . . $ Helper#::startedcxx . . $ Helper#started(50ce9a9e25b4a850).() const
56 {
57 return autoExitTimer_cxx . . $ Helper#autoExitTimer_..isActivecxx . . $ QTimer#isActive(50ce9a9e25b4a850).();
58 }
59
60 void Helpercxx . . $ Helper#::exitcxx . . $ Helper#exit(45672f3c6961a244).(QByteArraycxx . . $ QByteArray# const &signature)
61 {
62 if (cryptoLayer_cxx . . $ Helper#cryptoLayer_.->cxx . . $ std/__shared_ptr_access#`operator->`(34d6acfd341ba7ab).verifycxx . . $ ICryptoLayer#verify(5ad6b2491b335728).({cxx . . $ QByteArray#QByteArray(de40a1f2d6082f12)."exit"}, signature)) {
63 autoExitTimer_cxx . . $ Helper#autoExitTimer_..stopcxx . . $ QTimer#stop(49f6e7a06ebc5aa8).();
64 exitHelpercxx . . $ Helper#exitHelper(49f6e7a06ebc5aa8).();
65 }
66 else
67 SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!("Failed to verify 'exit' call from D-Bus");
68 }
69
70 void Helpercxx . . $ Helper#::exitHelpercxx . . $ Helper#exitHelper(49f6e7a06ebc5aa8).()
71 {
72 endProcessMonitorcxx . . $ Helper#endProcessMonitor(49f6e7a06ebc5aa8).();
73 QTimercxx . . $ QTimer#::singleShotcxx . . $ QTimer#singleShot(aa6a4c6cfc6f625a).(0, QCoreApplicationcxx . . $ QCoreApplication#::instancecxx . . $ QCoreApplication#instance(fc464b6fd63b8c1).(), &QCoreApplicationcxx . . $ QCoreApplication#::quitcxx . . $ QCoreApplication#quit(49f6e7a06ebc5aa8).);
74 }
75
76 void Helpercxx . . $ Helper#::autoExitTimeoutcxx . . $ Helper#autoExitTimeout(49f6e7a06ebc5aa8).()
77 {
78 SPDLOG_WARNcxx . . $ `<external>/13613935168682455490/spdlog.h:329:13`!("Auto exit timeout. Killing helper instance...");
79 exitHelpercxx . . $ Helper#exitHelper(49f6e7a06ebc5aa8).();
80 }
81
82 bool Helpercxx . . $ Helper#::isAuthorizedcxx . . $ Helper#isAuthorized(88cf1e7c0a6f9f8e).(QDBusMessagecxx . . $ QDBusMessage# const &message) const
83 {
84 auto subject = Polkitcxx . . $ Polkit/::BusNameSubjectcxx . . $ Polkit/BusNameSubject#{message.servicecxx . . $ QDBusMessage#service(6ef7b6c27b00b43d).().toStdStringcxx . . $ QString#toStdString(219584694fe2b248).()};
85 return Polkitcxx . . $ Polkit/::checkAuthorizationSynccxx . . $ Polkit/checkAuthorizationSync(da9f429a3fd357d7).(POLKIT_HELPER_ACTIONcxx . . $ `src/helper/helperids.h:12:9`!, subject) ==
86 Polkitcxx . . $ Polkit/::AuthResultcxx . . $ Polkit/AuthResult#::Yescxx . . $ Polkit/AuthResult#Yes.;
87 }
88
89 bool Helpercxx . . $ Helper#::initCryptocxx . . $ Helper#initCrypto(544790aa27d183a0).(QByteArraycxx . . $ QByteArray# const &appPublicKey)
90 {
91 try {
92 cryptoLayer_cxx . . $ Helper#cryptoLayer_. =cxx . . $ std/shared_ptr#`operator=`(a57a326de26a0fa9). stdcxx . . $ std/::make_sharedcxx . . $ std/make_shared(25752750ef11e821).<CryptoLayercxx . . $ CryptoLayer#>();
93 cryptoLayer_cxx . . $ Helper#cryptoLayer_.->cxx . . $ std/__shared_ptr_access#`operator->`(34d6acfd341ba7ab).initcxx . . $ ICryptoLayer#init(49f6e7a06ebc5aa8).();
94 cryptoLayer_cxx . . $ Helper#cryptoLayer_.->cxx . . $ std/__shared_ptr_access#`operator->`(34d6acfd341ba7ab).usePublicKeycxx . . $ ICryptoLayer#usePublicKey(45672f3c6961a244).(appPublicKey);
95
96 return true;
97 }
98 catch (stdcxx . . $ std/::exception const &e) {
99 SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!(e.what());
100 }
101
102 return false;
103 }
104
105 void Helpercxx . . $ Helper#::delayAutoExitcxx . . $ Helper#delayAutoExit(49f6e7a06ebc5aa8).()
106 {
107 if (autoExitTimer_cxx . . $ Helper#autoExitTimer_..isActivecxx . . $ QTimer#isActive(50ce9a9e25b4a850).())
108 autoExitTimer_cxx . . $ Helper#autoExitTimer_..startcxx . . $ QTimer#start(49f6e7a06ebc5aa8).();
109 }
110
111 bool Helpercxx . . $ Helper#::initProcessMonitorcxx . . $ Helper#initProcessMonitor(c9857a73d68e59ba).()
112 {
113 bool success = false;
114
115 try {
116 appRegistry_cxx . . $ Helper#appRegistry_. =cxx . . $ std/shared_ptr#`operator=`(a57a326de26a0fa9). stdcxx . . $ std/::make_sharedcxx . . $ std/make_shared(25752750ef11e821).<AppRegistrycxx . . $ AppRegistry#>();
117 processMonitor_cxx . . $ Helper#processMonitor_. =cxx . . $ std/unique_ptr#`operator=`(274635e25750a47f). stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<NLProcExecMonitorcxx . . $ NLProcExecMonitor#>(
118 appRegistry_cxx . . $ Helper#appRegistry_., stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<ProcPIDSolvercxx . . $ ProcPIDSolver#>(),
119 stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<MsgDispatchercxx . . $ MsgDispatcher#>(cryptoLayer_cxx . . $ Helper#cryptoLayer_., appRegistry_cxx . . $ Helper#appRegistry_.));
120
121 auto pMonInit = [&]() { processMonitor_cxx . . $ Helper#processMonitor_.->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).startcxx . . $ IProcessMonitor#start(49f6e7a06ebc5aa8).(); };
122 pMonThread_cxx . . $ Helper#pMonThread_. =cxx . . $ std/unique_ptr#`operator=`(1b63e42eaa758a73). stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<stdcxx . . $ std/::threadcxx . . $ std/thread#>(pMonInit);
123
124 success = true;
125 }
126 catch (NLProcExecSocketcxx . . $ NLProcExecSocket#::BindErrorcxx . . $ NLProcExecSocket#BindError# &e) {
127 SPDLOG_WARNcxx . . $ `<external>/13613935168682455490/spdlog.h:329:13`!("Bind socket error: {}", e.what());
128 SPDLOG_WARNcxx . . $ `<external>/13613935168682455490/spdlog.h:329:13`!("Do you have root permissions?");
129 }
130 catch (stdcxx . . $ std/::exception const &e) {
131 SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!(e.what());
132 }
133
134 return success;
135 }
136
137 void Helpercxx . . $ Helper#::endProcessMonitorcxx . . $ Helper#endProcessMonitor(49f6e7a06ebc5aa8).()
138 {
139 if (pMonThread_cxx . . $ Helper#pMonThread_. != nullptr) {
140 processMonitor_cxx . . $ Helper#processMonitor_.->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).stopcxx . . $ IProcessMonitor#stop(49f6e7a06ebc5aa8).();
141 pMonThread_cxx . . $ Helper#pMonThread_.->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).joincxx . . $ std/thread#join(49f6e7a06ebc5aa8).();
142 }
143 }
144
145 bool Helpercxx . . $ Helper#::initMsgReceivercxx . . $ Helper#initMsgReceiver(c9857a73d68e59ba).()
146 {
147 try {
148 msgReceiver_cxx . . $ Helper#msgReceiver_. =cxx . . $ std/unique_ptr#`operator=`(1b63e42eaa758a73). stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<MsgReceivercxx . . $ MsgReceiver#>(
149 cryptoLayer_cxx . . $ Helper#cryptoLayer_., stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<SysfsWritercxx . . $ SysfsWriter#>());
150
151 return true;
152 }
153 catch (stdcxx . . $ std/::exception const &e) {
154 SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!(e.what());
155 }
156
157 return false;
158 }
159
160 bool initDBusForHelperServicecxx . . $ initDBusForHelperService(967f3292d4f23d29).(QObjectcxx . . $ QObject# *obj)
161 {
162 QDBusConnectioncxx . . $ QDBusConnection# bus = QDBusConnectioncxx . . $ QDBusConnection#::systemBuscxx . . $ QDBusConnection#systemBus(45d475f1888103b2).();
163 if (!bus.isConnectedcxx . . $ QDBusConnection#isConnected(50ce9a9e25b4a850).()) {
164 SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!("Could not connect to D-Bus system bus");
165 return false;
166 }
167
168 if (!bus.registerObjectcxx . . $ QDBusConnection#registerObject(3ca2fdce2ef96dc8).(QStringLiteralcxx . . $ `<external>/13954984326995544643/qstring.h:1789:9`!(DBUS_HELPER_PATHcxx . . $ `src/helper/helperids.h:15:9`!), obj)) {
169 SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!("Could not register D-Bus object on path {} "
170 "using the interface {}\n.Last D-Bus error: {}",
171 DBUS_HELPER_PATHcxx . . $ `src/helper/helperids.h:15:9`!, DBUS_HELPER_INTERFACEcxx . . $ `src/helper/helperids.h:14:9`!,
172 bus.lastError().message().toStdString());
173 return false;
174 }
175
176 if (!bus.registerServicecxx . . $ QDBusConnection#registerService(e1defb592416720d).(QStringLiteralcxx . . $ `<external>/13954984326995544643/qstring.h:1789:9`!(DBUS_HELPER_SERVICEcxx . . $ `src/helper/helperids.h:13:9`!))) {
177 SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!("Could not register D-Bus service {}.\nLast D-Bus error: {}",
178 DBUS_HELPER_SERVICEcxx . . $ `src/helper/helperids.h:13:9`!, bus.lastError().message().toStdString());
179 return false;
180 }
181
182 return true;
183 }
184
185 bool endDBusForHelperServicecxx . . $ endDBusForHelperService(c9857a73d68e59ba).()
186 {
187 QDBusConnectioncxx . . $ QDBusConnection# bus = QDBusConnectioncxx . . $ QDBusConnection#::systemBuscxx . . $ QDBusConnection#systemBus(45d475f1888103b2).();
188 bus.unregisterObjectcxx . . $ QDBusConnection#unregisterObject(1667c585e463f5a5).(QStringLiteralcxx . . $ `<external>/13954984326995544643/qstring.h:1789:9`!(DBUS_HELPER_PATHcxx . . $ `src/helper/helperids.h:15:9`!));
189 auto success = bus.unregisterServicecxx . . $ QDBusConnection#unregisterService(e1defb592416720d).(QStringLiteralcxx . . $ `<external>/13954984326995544643/qstring.h:1789:9`!(DBUS_HELPER_SERVICEcxx . . $ `src/helper/helperids.h:13:9`!));
190 if (!success) {
191 SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!("D-Bus error unregistering service {}: {}",
192 DBUS_HELPER_SERVICEcxx . . $ `src/helper/helperids.h:13:9`!, bus.lastError().message().toStdString());
193 }
194
195 return success;
196 }
197
198 int maincxx . . $ main(afcd3168fc1188a4).(int argc, char **argv)
199 {
200 QCoreApplicationcxx . . $ QCoreApplication# appcxx . . $ QCoreApplication#QCoreApplication(6e9b1c7df49e191d).(argc, argv);
201 new Helpercxx . . $ Helper#(&app);
202
203 if (!initDBusForHelperServicecxx . . $ initDBusForHelperService(967f3292d4f23d29).(&app))
204 exit(1);
205
206 app.execcxx . . $ QCoreApplication#exec(b126dc7c1de90089).();
207
208 if (!endDBusForHelperServicecxx . . $ endDBusForHelperService(c9857a73d68e59ba).())
209 exit(1);
210
211 return 0;
212 }