Changeset View
Changeset View
Standalone View
Standalone View
src/util/externalcommandhelper.cpp
Show All 13 Lines | |||||
14 | * You should have received a copy of the GNU General Public License * | 14 | * You should have received a copy of the GNU General Public License * | ||
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>.* | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>.* | ||
16 | *************************************************************************/ | 16 | *************************************************************************/ | ||
17 | 17 | | |||
18 | #include "externalcommandhelper.h" | 18 | #include "externalcommandhelper.h" | ||
19 | #include "externalcommand_whitelist.h" | 19 | #include "externalcommand_whitelist.h" | ||
20 | 20 | | |||
21 | #include <QtDBus> | 21 | #include <QtDBus> | ||
22 | #include <QCoreApplication> | ||||
22 | #include <QDebug> | 23 | #include <QDebug> | ||
23 | #include <QFile> | 24 | #include <QFile> | ||
24 | #include <QString> | 25 | #include <QString> | ||
25 | #include <QTime> | 26 | #include <QTime> | ||
26 | #include <QVariant> | 27 | #include <QVariant> | ||
27 | 28 | | |||
28 | #include <KLocalizedString> | 29 | #include <KLocalizedString> | ||
29 | 30 | | |||
31 | #include <PolkitQt1/Authority> | ||||
32 | | ||||
33 | using namespace PolkitQt1; | ||||
34 | | ||||
30 | /** Initialize ExternalCommandHelper Daemon and prepare DBus interface | 35 | /** Initialize ExternalCommandHelper Daemon and prepare DBus interface | ||
31 | * | 36 | * | ||
32 | * KAuth helper runs in the background until application exits. | 37 | * KAuth helper runs in the background until application exits. | ||
33 | * To avoid forever running helper in case of application crash | 38 | * To avoid forever running helper in case of application crash | ||
34 | * ExternalCommand class opens a DBus service that we monitor for changes. | 39 | * ExternalCommand class opens a DBus service that we monitor for changes. | ||
35 | * If helper is not busy then it exits when the client services gets | 40 | * If helper is not busy then it exits when the client services gets | ||
36 | * unregistered. Otherwise, | 41 | * unregistered. Otherwise, | ||
37 | * we wait for the current job to finish before exiting, so even in case | 42 | * we wait for the current job to finish before exiting, so even in case | ||
▲ Show 20 Lines • Show All 233 Lines • ▼ Show 20 Line(s) | |||||
271 | void ExternalCommandHelper::exit() | 276 | void ExternalCommandHelper::exit() | ||
272 | { | 277 | { | ||
273 | m_loop->exit(); | 278 | m_loop->exit(); | ||
274 | 279 | | |||
275 | QDBusConnection::systemBus().unregisterObject(QStringLiteral("/Helper")); | 280 | QDBusConnection::systemBus().unregisterObject(QStringLiteral("/Helper")); | ||
276 | QDBusConnection::systemBus().unregisterService(QStringLiteral("org.kde.kpmcore.helperinterface")); | 281 | QDBusConnection::systemBus().unregisterService(QStringLiteral("org.kde.kpmcore.helperinterface")); | ||
277 | } | 282 | } | ||
278 | 283 | | |||
284 | bool ExternalCommandHelper::authorize(const QString &actionId, const Subject &subject, | ||||
cjlcarvalho: How is this method going to be called? | |||||
I may cal this from startHelper(), I am not sure. What are your suggestions? shubham: I may cal this from startHelper(), I am not sure. What are your suggestions? | |||||
285 | const Authority::AuthorizationFlags flags) | ||||
286 | { | ||||
287 | qDebug() << "Authorizing actions through ExternalCommand Helper"; | ||||
288 | | ||||
289 | const Authority::Result result = Authority::instance()->checkAuthorizationSync(actionId, subject, flags); | ||||
290 | //SystemBusNameSubject subject(message().service()); | ||||
291 | | ||||
292 | if (result == Authority::Yes) { | ||||
293 | qDebug() << "Subject is authorized to perform previliged tasks. You can proceed further now"; | ||||
294 | emit actionAuthorized(); | ||||
295 | return true; | ||||
296 | } else { | ||||
297 | qDebug() << "Subject was unable to authorize itself. Can not proceed further"; | ||||
298 | qApp->quit(); | ||||
299 | return false; | ||||
300 | } | ||||
301 | } | ||||
302 | | ||||
279 | void ExternalCommandHelper::onReadOutput() | 303 | void ExternalCommandHelper::onReadOutput() | ||
280 | { | 304 | { | ||
281 | /* const QByteArray s = cmd.readAllStandardOutput(); | 305 | /* const QByteArray s = cmd.readAllStandardOutput(); | ||
282 | 306 | | |||
283 | if(output.length() > 10*1024*1024) { // prevent memory overflow for badly corrupted file systems | 307 | if(output.length() > 10*1024*1024) { // prevent memory overflow for badly corrupted file systems | ||
284 | if (report()) | 308 | if (report()) | ||
285 | report()->line() << xi18nc("@info:status", "(Command is printing too much output)"); | 309 | report()->line() << xi18nc("@info:status", "(Command is printing too much output)"); | ||
286 | return; | 310 | return; | ||
Show All 9 Lines |
How is this method going to be called?