diff --git a/src/util/dbus.service b/src/util/dbus.service new file mode 100644 --- /dev/null +++ b/src/util/dbus.service @@ -0,0 +1,4 @@ +[D-BUS Service] +Name=org.kde.kpmcore.externalcommand +Exec=@LIBEXEC_INSTALL_DIR@/foohelper +User=root diff --git a/src/util/externalcommandhelper.h b/src/util/externalcommandhelper.h --- a/src/util/externalcommandhelper.h +++ b/src/util/externalcommandhelper.h @@ -23,20 +23,26 @@ #include +#include #include #include #include +#include + using namespace KAuth; -class ExternalCommandHelper : public QObject +using namespace PolkitQt1; + +class ExternalCommandHelper : public QObject, protected QDBusContext { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.kde.kpmcore.externalcommand") Q_SIGNALS: void progress(int); void quit(); + void actionAuthorized(); public: bool readData(const QString& sourceDevice, QByteArray& buffer, const qint64 offset, const qint64 size); @@ -48,6 +54,8 @@ Q_SCRIPTABLE QVariantMap copyblocks(const QString& sourceDevice, const qint64 sourceFirstByte, const qint64 sourceLength, const QString& targetDevice, const qint64 targetFirstByte, const qint64 blockSize); Q_SCRIPTABLE bool writeData(const QByteArray& buffer, const QString& targetDevice, const qint64 targetFirstByte); Q_SCRIPTABLE void exit(); + Q_SCRIPTABLE bool authorize(const QString &actionId, const Subject &subject, + const Authority::AuthorizationFlags flags); private: void onReadOutput(); diff --git a/src/util/externalcommandhelper.cpp b/src/util/externalcommandhelper.cpp --- a/src/util/externalcommandhelper.cpp +++ b/src/util/externalcommandhelper.cpp @@ -19,14 +19,19 @@ #include "externalcommand_whitelist.h" #include +#include #include #include #include #include #include #include +#include + +using namespace PolkitQt1; + /** Initialize ExternalCommandHelper Daemon and prepare DBus interface * * KAuth helper runs in the background until application exits. @@ -276,6 +281,26 @@ QDBusConnection::systemBus().unregisterService(QStringLiteral("org.kde.kpmcore.helperinterface")); } +bool ExternalCommandHelper::authorize(const QString &actionId, const Subject &subject, + const Authority::AuthorizationFlags flags) +{ + qDebug() << "Authorizing actions through ExternalCommand Helper"; + + const Authority::Result result = Authority::instance()->checkAuthorizationSync(actionId, subject, flags); + //SystemBusNameSubject subject(message().service()); + + if (result == Authority::Yes) { + qDebug() << "Subject is authorized to perform previliged tasks. You can proceed further now"; + return true; + } else { + qDebug() << "Subject was unable to authorize itself. Can not proceed further"; + qApp->quit(); + return false; + } + + emit actionAuthorized(); +} + void ExternalCommandHelper::onReadOutput() { /* const QByteArray s = cmd.readAllStandardOutput();