Commit 31f61218 authored by Lukas Appelhans's avatar Lukas Appelhans
Browse files

Fix multiple pwd dialogs

parent c400fe3d
......@@ -8,16 +8,20 @@
version 2 of the License, or (at your option) any later version.
*/
#include "archivehandlerhelper.h"
#include "polkithelper_global.h"
#include "libarchive++/archivehandler.h"
#include "libarchive++/archiveoperations.h"
#include "operations/akabeioperationutils.h"
#include "akabeihelpers_p.h"
#include "filesystemhelper.h"
#include <PolkitQt1/Authority>
#include <QDebug>
#include <QDBusMessage>
#include <QDBusConnection>
#include <QDBusConnectionInterface>
class InstallFunctorPriv : public Akabei::EntryHandlerFunctor
{
......@@ -195,7 +199,7 @@ QStringList ArchiveHandlerHelper::entries() const
PolkitQt1::Authority::Result auth = PolkitQt1::Authority::instance()->checkAuthorizationSync("org.chakraproject.akabeicorehelper.archive.read",
PolkitQt1::SystemBusNameSubject(message().service()),
PolkitQt1::Authority::AllowUserInteraction);
if (auth == PolkitQt1::Authority::Yes) {
if (auth == PolkitQt1::Authority::Yes && CHECK_PID) {
ArchiveHandler handler(m_filename);
return handler.getEntries();
} else {
......@@ -209,7 +213,7 @@ int ArchiveHandlerHelper::entrySize(const QString &file) const
PolkitQt1::Authority::Result auth = PolkitQt1::Authority::instance()->checkAuthorizationSync("org.chakraproject.akabeicorehelper.archive.read",
PolkitQt1::SystemBusNameSubject(message().service()),
PolkitQt1::Authority::AllowUserInteraction);
if (auth == PolkitQt1::Authority::Yes) {
if (auth == PolkitQt1::Authority::Yes && CHECK_PID) {
ArchiveHandler handler(m_filename);
return handler.getEntrySize(file);
} else {
......@@ -223,7 +227,7 @@ int ArchiveHandlerHelper::totalEntrySize() const
PolkitQt1::Authority::Result auth = PolkitQt1::Authority::instance()->checkAuthorizationSync("org.chakraproject.akabeicorehelper.archive.read",
PolkitQt1::SystemBusNameSubject(message().service()),
PolkitQt1::Authority::AllowUserInteraction);
if (auth == PolkitQt1::Authority::Yes) {
if (auth == PolkitQt1::Authority::Yes && CHECK_PID) {
ArchiveHandler handler(m_filename);
return handler.totalEntrySize();
} else {
......@@ -237,7 +241,7 @@ QString ArchiveHandlerHelper::readTextFile(const QString &file)
PolkitQt1::Authority::Result auth = PolkitQt1::Authority::instance()->checkAuthorizationSync("org.chakraproject.akabeicorehelper.archive.read",
PolkitQt1::SystemBusNameSubject(message().service()),
PolkitQt1::Authority::AllowUserInteraction);
if (auth == PolkitQt1::Authority::Yes) {
if (auth == PolkitQt1::Authority::Yes && CHECK_PID) {
ArchiveHandler handler(m_filename);
return handler.readTextFile(file);
} else {
......@@ -252,7 +256,7 @@ bool ArchiveHandlerHelper::write(const QVariantMap& files)
PolkitQt1::Authority::Result auth = PolkitQt1::Authority::instance()->checkAuthorizationSync("org.chakraproject.akabeicorehelper.archive.write",
PolkitQt1::SystemBusNameSubject(message().service()),
PolkitQt1::Authority::AllowUserInteraction);
if (auth == PolkitQt1::Authority::Yes) {
if (auth == PolkitQt1::Authority::Yes && CHECK_PID) {
qDebug() << "Auth gained to do the task";
QHash<QString, QString> hash; //FIXME: Optimize, aka make a method in archivehandler to take a qvariantmap
foreach (QString key, files.keys()) {
......@@ -271,7 +275,7 @@ void ArchiveHandlerHelper::install(const QString &root, const QVariantMap& backu
PolkitQt1::Authority::Result auth = PolkitQt1::Authority::instance()->checkAuthorizationSync("org.chakraproject.akabeicorehelper.archive.extract",
PolkitQt1::SystemBusNameSubject(message().service()),
PolkitQt1::Authority::AllowUserInteraction);
if (auth == PolkitQt1::Authority::Yes) {
if (auth == PolkitQt1::Authority::Yes && CHECK_PID) {
qDebug() << "Auth gained to do the task";
ArchiveHandler handler(m_filename);
QMap<QString, QString> map;
......@@ -290,7 +294,7 @@ void ArchiveHandlerHelper::upgrade(const QString &root, const QVariantMap& backu
PolkitQt1::Authority::Result auth = PolkitQt1::Authority::instance()->checkAuthorizationSync("org.chakraproject.akabeicorehelper.archive.extract",
PolkitQt1::SystemBusNameSubject(message().service()),
PolkitQt1::Authority::AllowUserInteraction);
if (auth == PolkitQt1::Authority::Yes) {
if (auth == PolkitQt1::Authority::Yes && CHECK_PID) {
qDebug() << "Auth gained to do the task";
ArchiveHandler handler(m_filename);
QMap<QString, QString> map;
......@@ -309,7 +313,7 @@ void ArchiveHandlerHelper::extract(const QString& source, const QString& destNam
PolkitQt1::Authority::Result auth = PolkitQt1::Authority::instance()->checkAuthorizationSync("org.chakraproject.akabeicorehelper.archive.extract",
PolkitQt1::SystemBusNameSubject(message().service()),
PolkitQt1::Authority::AllowUserInteraction);
if (auth == PolkitQt1::Authority::Yes) {
if (auth == PolkitQt1::Authority::Yes && CHECK_PID) {
qDebug() << "Auth gained to do the task";
ArchiveHandler handler(m_filename);
handler.extract(source, destName, overwrite);
......@@ -324,7 +328,7 @@ void ArchiveHandlerHelper::extractAll(const QString& pathPrefix, bool overwrite)
PolkitQt1::Authority::Result auth = PolkitQt1::Authority::instance()->checkAuthorizationSync("org.chakraproject.akabeicorehelper.archive.extract",
PolkitQt1::SystemBusNameSubject(message().service()),
PolkitQt1::Authority::AllowUserInteraction);
if (auth == PolkitQt1::Authority::Yes) {
if (auth == PolkitQt1::Authority::Yes && CHECK_PID) {
qDebug() << "Auth gained to do the task";
ArchiveHandler handler(m_filename);
handler.extractAll(pathPrefix, overwrite);
......@@ -338,7 +342,7 @@ QList<QByteArray> ArchiveHandlerHelper::md5(const QStringList &files)
PolkitQt1::Authority::Result auth = PolkitQt1::Authority::instance()->checkAuthorizationSync("org.chakraproject.akabeicorehelper.archive.read",
PolkitQt1::SystemBusNameSubject(message().service()),
PolkitQt1::Authority::AllowUserInteraction);
if (auth == PolkitQt1::Authority::Yes) {
if (auth == PolkitQt1::Authority::Yes && CHECK_PID) {
ArchiveHandler handler(m_filename);
return handler.md5(files);
} else {
......@@ -352,7 +356,7 @@ QByteArray ArchiveHandlerHelper::md5(const QString &file)
PolkitQt1::Authority::Result auth = PolkitQt1::Authority::instance()->checkAuthorizationSync("org.chakraproject.akabeicorehelper.archive.read",
PolkitQt1::SystemBusNameSubject(message().service()),
PolkitQt1::Authority::AllowUserInteraction);
if (auth == PolkitQt1::Authority::Yes) {
if (auth == PolkitQt1::Authority::Yes && CHECK_PID) {
ArchiveHandler handler(m_filename);
return handler.md5(file);
} else {
......
......@@ -8,12 +8,14 @@
version 2 of the License, or (at your option) any later version.
*/
#include "filesystemhelper.h"
#include "polkithelper_global.h"
#include "akabeihelpers.h"
#include <QFile>
#include <QDBusMessage>
#include <QDBusConnection>
#include <qdbusconnectioninterface.h>
#include <QDebug>
#include <QDir>
#include <PolkitQt1/Authority>
......@@ -24,6 +26,13 @@
#include <QtConcurrentRun>
static uint m_pid = 0;
uint FilesystemHelper::pid()
{
return m_pid;
}
FilesystemHelper::FilesystemHelper(QObject * parent)
: QObject(parent),
m_locked(false),
......@@ -40,7 +49,7 @@ bool FilesystemHelper::remove(const QStringList &files)
PolkitQt1::Authority::Result auth = PolkitQt1::Authority::instance()->checkAuthorizationSync("org.chakraproject.akabeicorehelper.filesystem.remove",
PolkitQt1::SystemBusNameSubject(message().service()),
PolkitQt1::Authority::AllowUserInteraction);
if (auth == PolkitQt1::Authority::Yes) {
if (auth == PolkitQt1::Authority::Yes && CHECK_PID) {
foreach (const QString &file, files) {
if (!QFile::remove(file))
return false;
......@@ -57,7 +66,7 @@ QByteArray FilesystemHelper::md5sumOfFile(const QString &file)
PolkitQt1::Authority::Result auth = PolkitQt1::Authority::instance()->checkAuthorizationSync("org.chakraproject.akabeicorehelper.filesystem.read",
PolkitQt1::SystemBusNameSubject(message().service()),
PolkitQt1::Authority::AllowUserInteraction);
if (auth == PolkitQt1::Authority::Yes) {
if (auth == PolkitQt1::Authority::Yes && CHECK_PID) {
return Akabei::Helpers::md5sumOfFile(file);
} else {
qDebug() << "No authorization" << auth;
......@@ -78,6 +87,7 @@ void FilesystemHelper::getLock(qint64 pid)
qDebug() << "Accepted" << m_lock;
if (m_locked && m_lock.empty()) {
m_pid = pid;
emit lockGranted(pid);
}
......@@ -106,7 +116,7 @@ void FilesystemHelper::removeLock(qint64 pid)
PolkitQt1::Authority::Result auth = PolkitQt1::Authority::instance()->checkAuthorizationSync("org.chakraproject.akabeicorehelper.filesystem.lock",
PolkitQt1::SystemBusNameSubject(message().service()),
PolkitQt1::Authority::AllowUserInteraction);
if (auth == PolkitQt1::Authority::No)
if (auth == PolkitQt1::Authority::No || !CHECK_PID)
return;
qDebug() << "REMOVE THE LOCK FOR " << pid << m_lock;
......@@ -116,6 +126,7 @@ void FilesystemHelper::removeLock(qint64 pid)
if (m_locked && !m_lock.isEmpty() && m_lock.head() != 0) {
qDebug() << "Lock granted to " << m_lock.head();
m_pid = m_lock.head();
emit lockGranted(m_lock.head());
}
}
......@@ -160,8 +171,10 @@ void FilesystemHelper::lockGranted()
{
qDebug() << "Grant lock";
m_locked = true;
if (!m_lock.isEmpty() && m_lock.head() != 0)
if (!m_lock.isEmpty() && m_lock.head() != 0) {
m_pid = m_lock.head();
emit lockGranted(m_lock.head());
}
}
......
......@@ -17,6 +17,7 @@
#include <QFutureWatcher>
#include <qqueue.h>
class FilesystemHelper : public QObject, public QDBusContext
{
Q_OBJECT
......@@ -27,6 +28,8 @@ public:
~FilesystemHelper();
public slots:
static uint pid();
bool remove(const QStringList &files);
QByteArray md5sumOfFile(const QString &file);
......
......@@ -10,27 +10,27 @@
<description>Extract an archive into the filesystem</description>
<message>Allows akabei to extract an archive into the filesystem, e.g. to install a package</message>
<defaults>
<allow_any>auth_admin_keep</allow_any>
<allow_active>auth_admin_keep</allow_active>
<allow_inactive>auth_admin_keep</allow_inactive>
<allow_any>yes</allow_any>
<allow_active>yes</allow_active>
<allow_inactive>yes</allow_inactive>
</defaults>
</action>
<action id="org.chakraproject.akabeicorehelper.archive.read">
<description>Read properties from an archive</description>
<message>Allows akabei to read properties from archive</message>
<defaults>
<allow_any>auth_admin_keep</allow_any>
<allow_active>auth_admin_keep</allow_active>
<allow_inactive>auth_admin_keep</allow_inactive>
<allow_any>yes</allow_any>
<allow_active>yes</allow_active>
<allow_inactive>yes</allow_inactive>
</defaults>
</action>
<action id="org.chakraproject.akabeicorehelper.archive.write">
<description>Write an archive into the filesystem</description>
<message>Allows akabei to write an archive into the filesystem, e.g. to create a compressed database</message>
<defaults>
<allow_any>auth_admin_keep</allow_any>
<allow_active>auth_admin_keep</allow_active>
<allow_inactive>auth_admin_keep</allow_inactive>
<allow_any>yes</allow_any>
<allow_active>yes</allow_active>
<allow_inactive>yes</allow_inactive>
</defaults>
</action>
......@@ -38,9 +38,9 @@
<description>Query an SQLite database</description>
<message>Allows akabei to query an SQLite database</message>
<defaults>
<allow_any>auth_admin_keep</allow_any>
<allow_active>auth_admin_keep</allow_active>
<allow_inactive>auth_admin_keep</allow_inactive>
<allow_any>yes</allow_any>
<allow_active>yes</allow_active>
<allow_inactive>yes</allow_inactive>
</defaults>
</action>
......@@ -48,27 +48,27 @@
<description>Remove a file from the filesystem</description>
<message>Allows akabei to remove a file from the filesystem</message>
<defaults>
<allow_any>auth_admin_keep</allow_any>
<allow_active>auth_admin_keep</allow_active>
<allow_inactive>auth_admin_keep</allow_inactive>
<allow_any>yes</allow_any>
<allow_active>yes</allow_active>
<allow_inactive>yes</allow_inactive>
</defaults>
</action>
<action id="org.chakraproject.akabeicorehelper.filesystem.read">
<description>Read a file from the filesystem</description>
<message>Allows akabei to read a file from the filesystem</message>
<defaults>
<allow_any>auth_admin_keep</allow_any>
<allow_active>auth_admin_keep</allow_active>
<allow_inactive>auth_admin_keep</allow_inactive>
<allow_any>yes</allow_any>
<allow_active>yes</allow_active>
<allow_inactive>yes</allow_inactive>
</defaults>
</action>
<action id="org.chakraproject.akabeicorehelper.filesystem.lock">
<description>Lock akabei</description>
<message>Allows akabei to create a lock file</message>
<defaults>
<allow_any>yes</allow_any>
<allow_active>yes</allow_active>
<allow_inactive>yes</allow_inactive>
<allow_any>auth_admin_keep</allow_any>
<allow_active>auth_admin_keep</allow_active>
<allow_inactive>auth_admin_keep</allow_inactive>
</defaults>
</action>
</policyconfig>
/* This file is part of the Chakra project
Copyright (C) 2013 Lukas Appelhans <boom1992@chakra-project.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
*/
#define CHECK_PID \
connection().interface()->servicePid(message().service()) == FilesystemHelper::pid()
......@@ -8,10 +8,14 @@
version 2 of the License, or (at your option) any later version.
*/
#include "sqlitehelper.h"
#include "polkithelper_global.h"
#include "filesystemhelper.h"
#include <QDBusMetaType>
#include <QDebug>
#include <QDBusMessage>
#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <PolkitQt1/Authority>
......@@ -74,7 +78,7 @@ SQL::Table SQLiteHelper::query(const QString &query)
PolkitQt1::Authority::Result auth = PolkitQt1::Authority::instance()->checkAuthorizationSync("org.chakraproject.akabeicorehelper.sqlite.query",
PolkitQt1::SystemBusNameSubject(message().service()),
PolkitQt1::Authority::AllowUserInteraction);
if (auth == PolkitQt1::Authority::Yes) {
if (auth == PolkitQt1::Authority::Yes && CHECK_PID) {
try {
return m_connection.rowQuery(query);
} catch (SQLiteException& e) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment