diff --git a/misc/AqpmAuthorization_p.h b/misc/AqpmAuthorization_p.h
index e07a4f1..ca6bd6d 100644
--- a/misc/AqpmAuthorization_p.h
+++ b/misc/AqpmAuthorization_p.h
@@ -27,17 +27,18 @@
namespace Aqpm {
namespace Auth {
-bool authorize(const QString &action, const QString &service)
+inline bool authorize(const QString &action, const QString &service)
{
- PolkitQt1::SystemBusNameSubject subject(service);
- PolkitQt1::Authority *authority = PolkitQt1::Authority::instance();
+ PolkitQt1::SystemBusNameSubject *subject = new PolkitQt1::SystemBusNameSubject(service);
- switch (authority->checkAuthorizationSync(action, &subject, PolkitQt1::Authority::AllowUserInteraction)) {
+ switch (PolkitQt1::Authority::instance()->checkAuthorizationSync(action, subject,
+ PolkitQt1::Authority::AllowUserInteraction)) {
case PolkitQt1::Authority::Yes:
- qDebug() << service << QString(" authorized");
+ qDebug() << service << " authorized for " << action;
return true;
default:
- qDebug() << QString("Not authorized");
+ qDebug() << subject->toString() << "Not authorized for " << action;
+ qDebug() << "Last error: " << PolkitQt1::Authority::instance()->lastError();
return false;
}
diff --git a/misc/CMakeLists.txt b/misc/CMakeLists.txt
index 52dc5ff..dc7cae6 100644
--- a/misc/CMakeLists.txt
+++ b/misc/CMakeLists.txt
@@ -3,10 +3,33 @@ set(aqpm_misc_HEADERS
Visibility.h
)
+# I know, sucks extremely hard, but it's the only way.
+
+set(policy_gen_SRCS
+ policy-gen/policy-gen.cpp
+ policy-gen/kauth-policy-gen-polkit1.cpp )
+
+automoc4_add_executable(polkit-kde-helper-policy-gen ${policy_gen_SRCS})
+
+target_link_libraries(polkit-kde-helper-policy-gen ${QT_QTCORE_LIBRARY})
+
+## Execute it
+set(_output ${CMAKE_CURRENT_BINARY_DIR}/org.chakraproject.aqpm.policy)
+get_filename_component(_input org.chakraproject.aqpm.actions ABSOLUTE)
+
+add_custom_command(OUTPUT ${_output}
+ COMMAND ${CMAKE_CURRENT_BINARY_DIR}/polkit-kde-helper-policy-gen ${_input} > ${_output}
+ MAIN_DEPENDENCY ${_input}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ COMMENT "Generating org.chakraproject.aqpm.policy"
+ DEPENDS polkit-kde-helper-policy-gen)
+add_custom_target("actions for polkit-kde" ALL DEPENDS ${_output})
+
+install(CODE "message(STATUS \"Installing System Policies for Aqpm...\")")
+install(FILES ${_output} DESTINATION ${POLKITQT-1_POLICY_FILES_INSTALL_DIR})
+
install(CODE "message(STATUS \"Installing additional header files...\")")
install(FILES ${aqpm_misc_HEADERS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/aqpm)
-install(CODE "message(STATUS \"Installing System Policies for Aqpm...\")")
-install(FILES org.chakraproject.aqpm.policy DESTINATION ${POLKITQT-1_POLICY_FILES_INSTALL_DIR})
if (KDE4_INTEGRATION)
install( FILES settings-package-management.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
endif (KDE4_INTEGRATION)
diff --git a/misc/org.chakraproject.aqpm.actions b/misc/org.chakraproject.aqpm.actions
new file mode 100644
index 0000000..796d4ca
--- /dev/null
+++ b/misc/org.chakraproject.aqpm.actions
@@ -0,0 +1,66 @@
+[Domain]
+Name=Chakra Package Management
+Icon=chakra-shiny
+
+[org.chakraproject.aqpm.updatedatabase]
+Name=Update Database
+Description=Prevents the Package Manager from updating the Database
+Policy=auth_admin
+
+[org.chakraproject.aqpm.systemupgrade]
+Name=System Upgrade
+Description=Prevents the Package Manager from upgrading the system
+Policy=auth_admin
+Persistence=session
+
+[org.chakraproject.aqpm.processqueue]
+Name=Process queue
+Description=Prevents the Package Manager from processing a package queue
+Policy=auth_admin
+
+[org.chakraproject.aqpm.downloadqueue]
+Name=Process queue
+Description=Prevents the Package Manager from downloading a package queue
+Policy=yes
+
+[org.chakraproject.aqpm.saveconfiguration]
+Name=Save pacman configuration
+Description=Prevents the Package Manager from saving the configuration
+Policy=auth_admin
+
+[org.chakraproject.aqpm.convertconfiguration]
+Name=Convert pacman configuration
+Description=Prevents the Package Manager from converting Pacman configuration to Aqpm
+Policy=yes
+
+[org.chakraproject.aqpm.setmirrorlist]
+Name=Sets Aqpm mirrors
+Description=Prevents the Package Manager from modifying the mirrors
+Policy=auth_admin
+Persistence=always
+
+[org.chakraproject.aqpm.performmaintenance]
+Name=Performs a maintenance operation on the package system
+Description=Prevents the Package Manager from performing a maintenance action
+Policy=auth_admin
+
+[org.chakraproject.aqpm.setaqpmroot]
+Name=Changes the root directory for package management
+Description=Prevents the Package Manager from changing the root directory for package management
+Policy=yes
+
+[org.chakraproject.aqpm.retrievetargetsforqueue]
+Name=Retrieves additional targets for a queue
+Description=Prevents the Package Manager from retrieving additional targets for the current queue
+Policy=yes
+
+[org.chakraproject.aqpm.updateabs]
+Name=Updates the Abs tree
+Description=Prevents the Package Manager from updating the Abs tree
+Policy=auth_admin
+Persistence=session
+
+[org.chakraproject.aqpm.preparebuildenvironment]
+Name=Prepares a build environment in a privileged location
+Description=Prevents the Package Manager from preparing a build environment in a privileged location
+Policy=auth_admin
diff --git a/misc/org.chakraproject.aqpm.policy b/misc/org.chakraproject.aqpm.policy
deleted file mode 100644
index cc20196..0000000
--- a/misc/org.chakraproject.aqpm.policy
+++ /dev/null
@@ -1,117 +0,0 @@
-
-
-
- Aqpm - ArchLinux Package Management
- http://chakra-project.org/
- shaman
-
-
- Update Database
- Prevents the Package Manager from updating the Database
-
- no
- auth_admin_keep_session
-
-
-
-
- System Upgrade
- Prevents the Package Manager from upgrading the system
-
- no
- auth_admin_keep_session
-
-
-
-
- Process queue
- Prevents the Package Manager from processing a package queue
-
- no
- auth_admin
-
-
-
-
- Process queue
- Prevents the Package Manager from downloading a package queue
-
- no
- yes
-
-
-
-
- Save pacman configuration
- Prevents the Package Manager from saving the configuration
-
- no
- auth_admin
-
-
-
-
- Convert pacman configuration
- Prevents the Package Manager from converting Pacman configuration to Aqpm
-
- no
- yes
-
-
-
-
- Sets Aqpm mirrors
- Prevents the Package Manager from modifying the mirrors
-
- no
- auth_admin_keep_always
-
-
-
-
- Performs a maintenance operation on the package system
- Prevents the Package Manager from performing a maintenance action
-
- no
- auth_admin
-
-
-
-
- Changes the root directory for package management
- Prevents the Package Manager from changing the root directory for package management
-
- no
- no
-
-
-
-
- Retrieves additional targets for a queue
- Prevents the Package Manager from retrieving additional targets for the current queue
-
- no
- yes
-
-
-
-
- Updates the Abs tree
- Prevents the Package Manager from updating the Abs tree
-
- no
- auth_admin_keep_session
-
-
-
-
- Prepares a build environment in a privileged location
- Prevents the Package Manager from preparing a build environment in a privileged location
-
- no
- auth_admin
-
-
-
diff --git a/misc/policy-gen/kauth-policy-gen-polkit1.cpp b/misc/policy-gen/kauth-policy-gen-polkit1.cpp
new file mode 100644
index 0000000..5de8050
--- /dev/null
+++ b/misc/policy-gen/kauth-policy-gen-polkit1.cpp
@@ -0,0 +1,87 @@
+/*
+* Copyright (C) 2008 Nicola Gigante
+* Copyright (C) 2009 Dario Freddi
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License as published by
+* the Free Software Foundation; either version 2.1 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public License
+* along with this program; if not, write to the
+* Free Software Foundation, Inc.,
+* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA .
+*/
+
+#include "policy-gen.h"
+
+#include
+#include
+#include
+
+const char header[] = ""
+ "\n"
+ "\n"
+ "\n";
+
+const char policy_tag[] = ""
+ " \n"
+ " no\n"
+ " %1\n"
+ " \n";
+
+const char dent[] = " ";
+
+void output(QList actions, QHash domain)
+{
+ QTextStream out(stdout);
+
+ out << header;
+
+ if (domain.contains("vendor")) {
+ out << "" << domain["vendor"] << "\n";
+ }
+ if (domain.contains("vendorurl")) {
+ out << "" << domain["vendorurl"] << "\n";
+ }
+ if (domain.contains("icon")) {
+ out << "" << domain["icon"] << "\n";
+ }
+
+ foreach (const Action &action, actions) {
+ out << dent << "\n";
+
+ foreach (const QString &lang, action.descriptions.keys()) {
+ out << dent << dent << "' << action.messages.value(lang) << "\n";
+ }
+
+ foreach (const QString &lang, action.messages.keys()) {
+ out << dent << dent << "' << action.descriptions.value(lang) << "\n";
+ }
+
+ QString policy = action.policy;
+ if (!action.persistence.isEmpty() && policy != "yes" && policy != "no") {
+ policy += "_keep";
+ }
+
+ out << QString(policy_tag).arg(policy);
+
+ out << dent << "\n";
+ }
+
+ out << "\n";
+}
diff --git a/misc/policy-gen/policy-gen.cpp b/misc/policy-gen/policy-gen.cpp
new file mode 100644
index 0000000..f6dd8ab
--- /dev/null
+++ b/misc/policy-gen/policy-gen.cpp
@@ -0,0 +1,145 @@
+/*
+* Copyright (C) 2008 Nicola Gigante
+* Copyright (C) 2009 Dario Freddi
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License as published by
+* the Free Software Foundation; either version 2.1 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public License
+* along with this program; if not, write to the
+* Free Software Foundation, Inc.,
+* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA .
+*/
+
+#include "policy-gen.h"
+
+#include
+#include
+#include
+#include
+#include
+
+using namespace std;
+
+QList parse(QSettings &ini);
+QHash parseDomain(QSettings &ini);
+
+int main(int argc, char **argv)
+{
+ QCoreApplication app(argc, argv);
+
+ if (argc < 2) {
+ qCritical("Too few arguments");
+ return 1;
+ }
+
+ QSettings ini(argv[1], QSettings::IniFormat);
+ if (ini.status()) {
+ qCritical("Error loading file: %s", argv[1]);
+ return 1;
+ }
+
+ output(parse(ini), parseDomain(ini));
+}
+
+QList parse(QSettings &ini)
+{
+ QList actions;
+ QRegExp actionExp("[0-9a-z]+(\\.[0-9a-z]+)*");
+ QRegExp descriptionExp("description(?:\\[(\\w+)\\])?");
+ QRegExp nameExp("name(?:\\[(\\w+)\\])?");
+ QRegExp policyExp("yes|no|auth_self|auth_admin");
+
+ descriptionExp.setCaseSensitivity(Qt::CaseInsensitive);
+ nameExp.setCaseSensitivity(Qt::CaseInsensitive);
+
+ foreach(const QString &name, ini.childGroups()) {
+ Action action;
+
+ if (name == "Domain") {
+ continue;
+ }
+
+ if (!actionExp.exactMatch(name)) {
+ qCritical("Wrong action syntax: %s\n", name.toAscii().data());
+ exit(1);
+ }
+
+ action.name = name;
+ ini.beginGroup(name);
+
+ foreach(const QString &key, ini.childKeys()) {
+ if (descriptionExp.exactMatch(key)) {
+ QString lang = descriptionExp.capturedTexts().at(1);
+
+ if (lang.isEmpty())
+ lang = "en";
+
+ action.descriptions.insert(lang, ini.value(key).toString());
+
+ } else if (nameExp.exactMatch(key)) {
+ QString lang = nameExp.capturedTexts().at(1);
+
+ if (lang.isEmpty())
+ lang = "en";
+
+ action.messages.insert(lang, ini.value(key).toString());
+
+ } else if (key.toLower() == "policy") {
+ QString policy = ini.value(key).toString();
+ if (!policyExp.exactMatch(policy)) {
+ qCritical("Wrong policy: %s", policy.toAscii().data());
+ exit(1);
+ }
+ action.policy = policy;
+
+ } else if (key.toLower() == "persistence") {
+ QString persistence = ini.value(key).toString();
+ if (persistence != "session" && persistence != "always") {
+ qCritical("Wrong persistence: %s", persistence.toAscii().data());
+ exit(1);
+ }
+ action.persistence = persistence;
+ }
+ }
+
+ if (action.policy.isEmpty() || action.messages.isEmpty() || action.descriptions.isEmpty()) {
+ qCritical("Missing option in action: %s", name.toAscii().data());
+ exit(1);
+ }
+ ini.endGroup();
+
+ actions.append(action);
+ }
+
+ return actions;
+}
+
+
+QHash parseDomain(QSettings& ini)
+{
+ QHash rethash;
+
+ if (ini.childGroups().contains("Domain")) {
+ if (ini.contains("Domain/Name")) {
+ rethash["vendor"] = ini.value("Domain/Name").toString();
+ }
+ if (ini.contains("Domain/URL")) {
+ rethash["vendorurl"] = ini.value("Domain/URL").toString();
+ }
+ if (ini.contains("Domain/Icon")) {
+ rethash["icon"] = ini.value("Domain/Icon").toString();
+ }
+ }
+
+ return rethash;
+}
+
+
diff --git a/misc/policy-gen/policy-gen.h b/misc/policy-gen/policy-gen.h
new file mode 100644
index 0000000..e3a1a88
--- /dev/null
+++ b/misc/policy-gen/policy-gen.h
@@ -0,0 +1,41 @@
+/*
+* Copyright (C) 2008 Nicola Gigante
+* Copyright (C) 2009 Dario Freddi
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License as published by
+* the Free Software Foundation; either version 2.1 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public License
+* along with this program; if not, write to the
+* Free Software Foundation, Inc.,
+* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA .
+*/
+
+#ifndef _POLICY_GEN_H_
+#define _POLICY_GEN_H_
+
+#include
+#include
+#include
+
+struct Action {
+ QString name;
+
+ QHash descriptions;
+ QHash messages;
+
+ QString policy;
+ QString persistence;
+};
+
+extern void output(QList actions, QHash domain);
+
+
+#endif