Commit 66b6d14f authored by Lukas Appelhans's avatar Lukas Appelhans
Browse files

Fix SQLite queries with polkit

parent 97a95aa8
......@@ -13,6 +13,7 @@
#include <QCoreApplication>
#include <QDBusMessage>
#include <QDBusInterface>
#include <qdbusargument.h>
#include <akabeiconfig.h>
#include <akabeihelpers.h>
......@@ -68,7 +69,7 @@ void PolKitSQLiteConnection::connectToDB(QString const& name, bool readonly)
d->access = Akabei::Helpers::permissionsOfPath(name);
if (d->access != Akabei::Helpers::NoPermission) {
d->connection = new SQLiteConnection(name, readonly && d->access.testFlag(Akabei::Helpers::WritePermission));
d->connection = new SQLiteConnection(name, readonly || !d->access.testFlag(Akabei::Helpers::WritePermission));
}
d->filename = name;
......@@ -77,16 +78,21 @@ void PolKitSQLiteConnection::connectToDB(QString const& name, bool readonly)
SQLiteResource PolKitSQLiteConnection::query(const QString &q)
{
qDebug() << q;
if ((d->access.testFlag(Akabei::Helpers::ReadWritePermission)) || ((d->access.testFlag(Akabei::Helpers::ReadPermission)) && q.startsWith("SELECT"))) {
return d->connection->query(q);
}
if (Akabei::Helpers::checkAuthorizationSync("org.chakraproject.akabeicorehelper.sqlite.query")) {
QDBusInterface iface("org.chakraproject.akabeicorehelper", "/archive", "org.chakraproject.akabeicorehelper.sqlite", QDBusConnection::systemBus());
QDBusInterface iface("org.chakraproject.akabeicorehelper", "/sqlite", "org.chakraproject.akabeicorehelper.sqlite", QDBusConnection::systemBus());
SETUP_DBUS_DATABASE
QDBusMessage mes = iface.call("query", q);
if (!mes.arguments().isEmpty())
return SQLiteResource(mes.arguments().first().value< QList<Row> >());
if (!mes.arguments().isEmpty()) {
const QDBusArgument arg = mes.arguments().first().value<QDBusArgument>();
QList<QVariantMap> list;
arg >> list;
return SQLiteResource(list);
}
} else {
qDebug() << "Authorization not granted" << PolkitQt1::Authority::instance()->errorDetails();//TODO: error handling
}
......@@ -98,7 +104,7 @@ qint64 PolKitSQLiteConnection::getLastRowId()
if (d->access.testFlag(Akabei::Helpers::ReadPermission))
return d->connection->getLastRowId();
QDBusInterface iface("org.chakraproject.akabeicorehelper", "/archive", "org.chakraproject.akabeicorehelper.sqlite", QDBusConnection::systemBus());
QDBusInterface iface("org.chakraproject.akabeicorehelper", "/sqlite", "org.chakraproject.akabeicorehelper.sqlite", QDBusConnection::systemBus());
SETUP_DBUS_DATABASE
......@@ -118,7 +124,7 @@ void PolKitSQLiteConnection::bind(QString const& key, int value)
//We bind to both databases, as we have no information yet if we have a read or write query
QDBusInterface iface("org.chakraproject.akabeicorehelper", "/archive", "org.chakraproject.akabeicorehelper.sqlite", QDBusConnection::systemBus());
QDBusInterface iface("org.chakraproject.akabeicorehelper", "/sqlite", "org.chakraproject.akabeicorehelper.sqlite", QDBusConnection::systemBus());
SETUP_DBUS_DATABASE
......@@ -135,7 +141,7 @@ void PolKitSQLiteConnection::bind(QString const& key, QString const& value)
//We bind to both databases, as we have no information yet if we have a read or write query
QDBusInterface iface("org.chakraproject.akabeicorehelper", "/archive", "org.chakraproject.akabeicorehelper.sqlite", QDBusConnection::systemBus());
QDBusInterface iface("org.chakraproject.akabeicorehelper", "/sqlite", "org.chakraproject.akabeicorehelper.sqlite", QDBusConnection::systemBus());
SETUP_DBUS_DATABASE
......@@ -152,7 +158,7 @@ void PolKitSQLiteConnection::bind(QString const& key, QByteArray const& value)
//We bind to both databases, as we have no information yet if we have a read or write query
QDBusInterface iface("org.chakraproject.akabeicorehelper", "/archive", "org.chakraproject.akabeicorehelper.sqlite", QDBusConnection::systemBus());
QDBusInterface iface("org.chakraproject.akabeicorehelper", "/sqlite", "org.chakraproject.akabeicorehelper.sqlite", QDBusConnection::systemBus());
SETUP_DBUS_DATABASE
......
......@@ -30,6 +30,7 @@
#include <QCoreApplication>
#include <QDBusInterface>
#include <QDBusConnectionInterface>
#include <QDBusMetaType>
#include <libarchive++/archivehandler.h>
#include <akabeihook.h>
......@@ -488,6 +489,7 @@ Backend::Backend(QObject* parent)
qRegisterMetaType< QList< Akabei::Group* > >();
qRegisterMetaType< Akabei::Error::List >();
qRegisterMetaType< Akabei::Backend::Status >();
qDBusRegisterMetaType< QList< QVariantMap > >();
qInstallMsgHandler(akabeiDebug);
......@@ -631,25 +633,25 @@ QUuid Backend::searchGroups(const QString& token)
QUuid Backend::searchPackages(const QString& token, SearchType type)
{
QString sql;
switch (type) {
case SearchNameLike:
sql = Queries::selectPackages("name", "LIKE", "%" + token + "%");
break;
case SearchNameEqual:
sql = Queries::selectPackages("name", "=", "%" + token + "%");
sql = Queries::selectPackages("name", "=", token);
break;
case SearchDescriptionLike:
sql = Queries::selectPackages("description", "LIKE", "%" + token + "%");
break;
case SearchDescriptionEqual:
sql = Queries::selectPackages("description", "=", "%" + token + "%");
sql = Queries::selectPackages("description", "=", token);
break;
case SearchNameAndDescriptionLike:
sql = Queries::selectPackagesNameOrDescription("%" + token + "%", "LIKE");
break;
case SearchNameAndDescriptionEqual:
sql = Queries::selectPackagesNameOrDescription("%" + token + "%", "=");
sql = Queries::selectPackagesNameOrDescription(token, "=");
break;
}
return queryPackages(sql);
......
......@@ -142,7 +142,7 @@ Package* DatabasePrivate::packageFromRow(SQLiteResource& table, int row)
foreach (const QVariant& v, res.getColumn("dependency")) {
package->d_func()->addDependency(v.toString());
}
res = dbConnection.query(QString("SELECT dependency FROM makedepends WHERE package=%1").arg(id));
foreach (const QVariant& v, res.getColumn("dependency")) {
package->d_func()->addMakeDependency(v.toString());
......@@ -334,25 +334,25 @@ Package::List Database::packages()
Package::List Database::searchPackages(QString const& token, SearchType type)
{
QString sql;
switch (type) {
case SearchNameLike:
sql = Queries::selectPackages("name", "LIKE", "%" + token + "%");
break;
case SearchNameEqual:
sql = Queries::selectPackages("name", "=", "%" + token + "%");
sql = Queries::selectPackages("name", "=", token);
break;
case SearchDescriptionLike:
sql = Queries::selectPackages("description", "LIKE", "%" + token + "%");
break;
case SearchDescriptionEqual:
sql = Queries::selectPackages("description", "=", "%" + token + "%");
sql = Queries::selectPackages("description", "=", token);
break;
case SearchNameAndDescriptionLike:
sql = Queries::selectPackagesNameOrDescription("%" + token + "%", "LIKE");
break;
case SearchNameAndDescriptionEqual:
sql = Queries::selectPackagesNameOrDescription("%" + token + "%", "=");
sql = Queries::selectPackagesNameOrDescription(token, "=");
break;
}
return queryPackages(sql);
......
......@@ -25,11 +25,11 @@ SQLiteHelper::SQLiteHelper(QObject * parent)
SQLiteHelper::~SQLiteHelper()
{
}
void SQLiteHelper::setFilename(const QString &filename)
{
m_filename = filename;
try {
m_connection.connectToDB(filename, false);
} catch (SQLiteException& e) {
......@@ -45,7 +45,7 @@ QString SQLiteHelper::filename() const
void SQLiteHelper::bind(const QString &key, int value)
{
try {
m_connection.bind(key, value);
m_connection.bind(key, value);
} catch (SQLiteException& e) {
qDebug() << "bind failed:" << e.what();
}
......@@ -54,7 +54,7 @@ void SQLiteHelper::bind(const QString &key, int value)
void SQLiteHelper::bind(const QString &key, const QString &value)
{
try {
m_connection.bind(key, value);
m_connection.bind(key, value);
} catch (SQLiteException& e) {
qDebug() << "bind failed:" << e.what();
}
......@@ -63,7 +63,7 @@ void SQLiteHelper::bind(const QString &key, const QString &value)
void SQLiteHelper::bind(const QString &key, const QByteArray &value)
{
try {
m_connection.bind(key, value);
m_connection.bind(key, value);
} catch (SQLiteException& e) {
qDebug() << "bind failed:" << e.what();
}
......@@ -72,11 +72,11 @@ void SQLiteHelper::bind(const QString &key, const QByteArray &value)
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::SystemBusNameSubject(message().service()),
PolkitQt1::Authority::AllowUserInteraction);
if (auth == PolkitQt1::Authority::Yes) {
try {
return m_connection.rowQuery(query);
return m_connection.rowQuery(query);
} catch (SQLiteException& e) {
qDebug() << "query failed:" << e.what();
}
......
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