summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrien BUSTANY <madcat@mymadcat.com>2008-06-11 01:20:51 +0200
committerAdrien BUSTANY <madcat@mymadcat.com>2008-06-11 01:20:51 +0200
commite8ef0faf1a57b19102b1694182da3da1803cadb4 (patch)
tree5be8120874941611d39f483d975e6476c73a6de5
parentea8dc47ddb59a345d99a6d6113c102708b524381 (diff)
PolicyKit integration, so that we can actually do something
-rw-r--r--lib/Daemon.cpp6
-rw-r--r--lib/Daemon.h3
-rw-r--r--lib/PolkitClient.cpp19
-rw-r--r--lib/PolkitClient.h21
-rw-r--r--lib/Transaction.cpp49
-rw-r--r--lib/Transaction.h6
-rw-r--r--lib/constants.h17
-rw-r--r--lib/lib.pro7
8 files changed, 115 insertions, 13 deletions
diff --git a/lib/Daemon.cpp b/lib/Daemon.cpp
index 6948fa9..b7e536f 100644
--- a/lib/Daemon.cpp
+++ b/lib/Daemon.cpp
@@ -11,6 +11,7 @@
#include "Daemon.h"
#include "constants.h"
+#include "PolkitClient.h"
using namespace PackageKit;
@@ -21,6 +22,8 @@ Daemon::Daemon(QObject *parent) : QObject(parent) {
connect(proxy, SIGNAL(TransactionListChanged(const QStringList&)), this, SIGNAL(TransactionListChanged(const QStringList&)));
connect(proxy, SIGNAL(RestartSchedule()), this, SIGNAL(RestartSchedule()));
connect(proxy, SIGNAL(RepoListChanged()), this, SIGNAL(RepoListChanged()));
+
+ polkit = new PolkitClient(this);
}
Daemon::~Daemon() {
@@ -60,6 +63,9 @@ bool Daemon::getNetworkState() {
}
void Daemon::setProxy(const QString &http_proxy, const QString &ftp_proxy) {
+ qDebug() << "Trying to get authorization...";
+ if(!polkit->getAuth(AUTH_SETPROXY)) qFatal("Cannot get authorization to set proxy");;
+ qDebug() << "We're authentificated";
proxy->SetProxy(http_proxy, ftp_proxy);
}
diff --git a/lib/Daemon.h b/lib/Daemon.h
index 69c7115..cf2ab04 100644
--- a/lib/Daemon.h
+++ b/lib/Daemon.h
@@ -21,6 +21,8 @@
namespace PackageKit {
+class PolkitClient;
+
class Daemon : public QObject {
friend class Transaction;
@@ -52,6 +54,7 @@ protected:
private:
CentralProxy *proxy;
+ PolkitClient *polkit;
private slots:
void NetworkStateChanged_cb(const QString &status);
diff --git a/lib/PolkitClient.cpp b/lib/PolkitClient.cpp
new file mode 100644
index 0000000..8717f26
--- /dev/null
+++ b/lib/PolkitClient.cpp
@@ -0,0 +1,19 @@
+#include <polkit-dbus/polkit-dbus.h>
+
+#include "PolkitClient.h"
+#include "constants.h"
+
+using namespace PackageKit;
+
+PolkitClient::PolkitClient(QObject *parent) : QObject(parent) {
+}
+
+bool PolkitClient::getAuth(const QString &action) {
+ DBusError e;
+ dbus_error_init(&e);
+ bool auth = polkit_auth_obtain(action.toAscii().data(), 0, QCoreApplication::applicationPid(), &e);
+ if(!auth) {
+ qDebug() << "Authentification error :" << e.name << ":" << e.message;
+ }
+ return auth;
+}
diff --git a/lib/PolkitClient.h b/lib/PolkitClient.h
new file mode 100644
index 0000000..ea53f04
--- /dev/null
+++ b/lib/PolkitClient.h
@@ -0,0 +1,21 @@
+#ifndef POLKITCLIENT_H
+#define POLKITCLIENT_H
+
+#include <QtCore>
+
+namespace PackageKit {
+
+class PolkitClient : QObject{
+
+ Q_OBJECT
+
+public:
+ PolkitClient(QObject *parent = 0);
+ bool getAuth(const QString& action);
+private:
+
+};
+
+} // End namespace PackageKit
+
+#endif
diff --git a/lib/Transaction.cpp b/lib/Transaction.cpp
index 2867431..b97d658 100644
--- a/lib/Transaction.cpp
+++ b/lib/Transaction.cpp
@@ -12,12 +12,15 @@
#include "Transaction.h"
#include "Daemon.h"
#include "constants.h"
+#include "PolkitClient.h"
using namespace PackageKit;
Transaction::Transaction(Daemon *parent) : QObject(parent), parent(parent) {
_tid = QString();
proxy = NULL;
+
+ polkit = new PolkitClient(this);
}
Transaction::~Transaction() {
@@ -127,6 +130,9 @@ void Transaction::resolve(const QString &filter, Package *p) {
}
void Transaction::installPackages(const QList<Package*> &packages) {
+ qDebug() << "Trying to get authorization...";
+ if(!polkit->getAuth(AUTH_INSTALL)) qFatal("Cannot get authorization to install packages");
+ qDebug() << "We're authentificated";
renewTid();
QStringList pids;
for(int i = 0 ; i < packages.size() ; ++i) pids << packages.at(i)->id();
@@ -134,18 +140,23 @@ void Transaction::installPackages(const QList<Package*> &packages) {
}
void Transaction::installPackage(Package *p) {
- renewTid();
- QStringList pids;
- pids << p->id();
- proxy->InstallPackages(pids);
+ QList<Package*> packages;
+ packages << p;
+ installPackages(packages);
}
void Transaction::installSignature(const SignatureType::Value &type, const QString &key_id, Package *p) {
+ qDebug() << "Trying to get authorization...";
+ if(!polkit->getAuth(AUTH_INSTALLSIGNATURE)) qFatal("Cannot get authorization to install signature");
+ qDebug() << "We're authentificated";
renewTid();
proxy->InstallSignature(EnumToString<SignatureType>(type), key_id, p->id());
}
void Transaction::updatePackages(const QList<Package*> &packages) {
+ qDebug() << "Trying to get authorization...";
+ if(!polkit->getAuth(AUTH_UPDATEPACKAGE)) qFatal("Cannot get authorization to update packages");
+ qDebug() << "We're authentificated";
renewTid();
QStringList pids;
for(int i = 0 ; i < packages.size() ; ++i) pids << packages.at(i)->id();
@@ -160,11 +171,17 @@ void Transaction::updatePackage(Package *p) {
}
void Transaction::installFiles(const QStringList& files, bool trusted) {
+ qDebug() << "Trying to get authorization...";
+ if(!polkit->getAuth((trusted ? AUTH_LOCALINSTALLTRUSTED : AUTH_LOCALINSTALLUNTRUSTED))) qFatal("Cannot get authorization to install files");
+ qDebug() << "We're authentificated";
renewTid();
proxy->InstallFiles(trusted, files);
}
void Transaction::removePackages(const QList<Package*> &packages, bool allow_deps, bool autoremove) {
+ qDebug() << "Trying to get authorization...";
+ if(!polkit->getAuth(AUTH_REMOVE)) qFatal("Cannot get authorization to remove packages");
+ qDebug() << "We're authentificated";
renewTid();
QStringList pids;
for(int i = 0 ; i < packages.size() ; ++i) pids << packages.at(i)->id();
@@ -172,17 +189,23 @@ void Transaction::removePackages(const QList<Package*> &packages, bool allow_dep
}
void Transaction::removePackage(Package *p, bool allow_deps, bool autoremove) {
- QStringList pids;
- pids << p->id();
- proxy->RemovePackages(pids, allow_deps, autoremove);
+ QList<Package*> packages;
+ packages << p;
+ removePackages(packages, allow_deps, autoremove);
}
void Transaction::updateSystem() {
+ qDebug() << "Trying to get authorization...";
+ if(!polkit->getAuth(AUTH_UPDATESYSTEM)) qFatal("Cannot get authorization to update system");
+ qDebug() << "We're authentificated";
renewTid();
proxy->UpdateSystem();
}
void Transaction::rollback(const QString &tid) {
+ qDebug() << "Trying to get authorization...";
+ if(!polkit->getAuth(AUTH_ROLLBACK)) qFatal("Cannot get authorization to rollback a transaction");
+ qDebug() << "We're authentificated";
renewTid();
proxy->Rollback(tid);
}
@@ -198,6 +221,9 @@ void Transaction::getUpdateDetail(const QString& package_id) {
}
void Transaction::refreshCache(bool force) {
+ qDebug() << "Trying to get authorization...";
+ if(!polkit->getAuth(AUTH_REFRESHCACHE)) qFatal("Cannot get authorization to refresh cache");
+ qDebug() << "We're authentificated";
renewTid();
proxy->RefreshCache(force);
}
@@ -212,11 +238,17 @@ void Transaction::getRepoList(const QString &filter) {
}
void Transaction::repoEnable(const QString &repo_id, bool enabled) {
+ qDebug() << "Trying to get authorization...";
+ if(!polkit->getAuth(AUTH_REPOCHANGE)) qFatal("Cannot get authorization to change a repository");
+ qDebug() << "We're authentificated";
renewTid();
proxy->RepoEnable(repo_id, enabled);
}
void Transaction::repoSetData(const QString &repo_id, const QString &parameter, const QString &value) {
+ qDebug() << "Trying to get authorization...";
+ if(!polkit->getAuth(AUTH_REPOCHANGE)) qFatal("Cannot get authorization to change a repository");
+ qDebug() << "We're authentificated";
renewTid();
proxy->RepoSetData(repo_id, parameter, value);
}
@@ -232,6 +264,9 @@ void Transaction::getOldTransactions(uint number) {
}
void Transaction::acceptEula(const QString &id) {
+ qDebug() << "Trying to get authorization...";
+ if(!polkit->getAuth(AUTH_ACCEPTEULA)) qFatal("Cannot get authorization to accept an EULA");
+ qDebug() << "We're authentificated";
renewTid();
proxy->AcceptEula(id);
}
diff --git a/lib/Transaction.h b/lib/Transaction.h
index d7a640d..5832622 100644
--- a/lib/Transaction.h
+++ b/lib/Transaction.h
@@ -25,6 +25,7 @@
namespace PackageKit {
class Daemon;
+class PolkitClient;
class Transaction : public QObject {
@@ -35,7 +36,6 @@ public:
~Transaction();
// PackageKit functions
- void renewTid();
bool allowCancel();
void cancel();
Role::Value getRole(Package *p = NULL);
@@ -109,6 +109,10 @@ private:
TransactionProxy *proxy;
Daemon *parent;
QString _tid;
+ // Get a new TID if needed
+ void renewTid();
+
+ PolkitClient *polkit;
};
diff --git a/lib/constants.h b/lib/constants.h
index 5cb70f1..a988e59 100644
--- a/lib/constants.h
+++ b/lib/constants.h
@@ -9,5 +9,18 @@
*
*/
-#define PK_NAME "org.freedesktop.PackageKit"
-#define PK_PATH "/org/freedesktop/PackageKit"
+#define PK_NAME "org.freedesktop.PackageKit"
+#define PK_PATH "/org/freedesktop/PackageKit"
+
+#define AUTH_UPDATESYSTEM "org.freedesktop.packagekit.update-system"
+#define AUTH_UPDATEPACKAGE "org.freedesktop.packagekit.update-package"
+#define AUTH_SETPROXY "org.freedesktop.packagekit.set-proxy"
+#define AUTH_ROLLBACK "org.freedesktop.packagekit.rollback"
+#define AUTH_REPOCHANGE "org.freedesktop.packagekit.repo-change"
+#define AUTH_REMOVE "org.freedesktop.packagekit.remove"
+#define AUTH_REFRESHCACHE "org.freedesktop.packagekit.refresh-cache"
+#define AUTH_LOCALINSTALLUNTRUSTED "org.freedesktop.packagekit.localinstall-untrusted"
+#define AUTH_LOCALINSTALLTRUSTED "org.freedesktop.packagekit.localinstall-trusted"
+#define AUTH_INSTALLSIGNATURE "org.freedesktop.packagekit.install-signature"
+#define AUTH_INSTALL "org.freedesktop.packagekit.install"
+#define AUTH_ACCEPTEULA "org.freedesktop.packagekit.accept-eula"
diff --git a/lib/lib.pro b/lib/lib.pro
index 30f3792..0fe197a 100644
--- a/lib/lib.pro
+++ b/lib/lib.pro
@@ -6,10 +6,11 @@ TEMPLATE = lib
VERSION = 0.1
TARGET = packagekit-qt
DEPENDPATH += .
-INCLUDEPATH += .
+INCLUDEPATH += . /usr/include/PolicyKit /usr/include/dbus-1.0 /usr/lib64/dbus-1.0/include
+LIBS += -lpolkit -lpolkit-dbus
QT += dbus
# Input
-HEADERS += CentralProxy.h constants.h Status.h Exit.h Role.h Package.h Restart.h Daemon.h Transaction.h TransactionProxy.h Provides.h SignatureType.h
-SOURCES += CentralProxy.cpp Package.cpp Daemon.cpp TransactionProxy.cpp Transaction.cpp
+HEADERS += CentralProxy.h constants.h Status.h Exit.h Role.h Package.h Restart.h Daemon.h Transaction.h TransactionProxy.h Provides.h SignatureType.h PolkitClient.h
+SOURCES += CentralProxy.cpp Package.cpp Daemon.cpp TransactionProxy.cpp Transaction.cpp PolkitClient.cpp