Skip to content

Commit

Permalink
Fix action generation
Browse files Browse the repository at this point in the history
Signed-off-by: Dario Freddi <drf@kde.org>
  • Loading branch information
drf committed Feb 11, 2010
1 parent 9e7081f commit 77e1222
Show file tree
Hide file tree
Showing 7 changed files with 371 additions and 125 deletions.
13 changes: 7 additions & 6 deletions misc/AqpmAuthorization_p.h
Expand Up @@ -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;
}

Expand Down
27 changes: 25 additions & 2 deletions misc/CMakeLists.txt
Expand Up @@ -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)
Expand Down
66 changes: 66 additions & 0 deletions 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
117 changes: 0 additions & 117 deletions misc/org.chakraproject.aqpm.policy

This file was deleted.

87 changes: 87 additions & 0 deletions misc/policy-gen/kauth-policy-gen-polkit1.cpp
@@ -0,0 +1,87 @@
/*
* Copyright (C) 2008 Nicola Gigante <nicola.gigante@gmail.com>
* Copyright (C) 2009 Dario Freddi <drf@kde.org>
*
* 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 <cstdio>
#include <QDebug>
#include <QTextStream>

const char header[] = ""
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<!DOCTYPE policyconfig PUBLIC\n"
"\"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN\"\n"
"\"http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd\">\n"
"<policyconfig>\n";

const char policy_tag[] = ""
" <defaults>\n"
" <allow_inactive>no</allow_inactive>\n"
" <allow_active>%1</allow_active>\n"
" </defaults>\n";

const char dent[] = " ";

void output(QList<Action> actions, QHash<QString, QString> domain)
{
QTextStream out(stdout);

out << header;

if (domain.contains("vendor")) {
out << "<vendor>" << domain["vendor"] << "</vendor>\n";
}
if (domain.contains("vendorurl")) {
out << "<vendor_url>" << domain["vendorurl"] << "</vendor_url>\n";
}
if (domain.contains("icon")) {
out << "<icon_name>" << domain["icon"] << "</icon_name>\n";
}

foreach (const Action &action, actions) {
out << dent << "<action id=\"" << action.name << "\" >\n";

foreach (const QString &lang, action.descriptions.keys()) {
out << dent << dent << "<description";
if (lang != "en")
out << " xml:lang=\"" << lang << '"';
out << '>' << action.messages.value(lang) << "</description>\n";
}

foreach (const QString &lang, action.messages.keys()) {
out << dent << dent << "<message";
if (lang != "en") {
out << " xml:lang=\"" << lang << '"';
}
out << '>' << action.descriptions.value(lang) << "</message>\n";
}

QString policy = action.policy;
if (!action.persistence.isEmpty() && policy != "yes" && policy != "no") {
policy += "_keep";
}

out << QString(policy_tag).arg(policy);

out << dent << "</action>\n";
}

out << "</policyconfig>\n";
}

0 comments on commit 77e1222

Please sign in to comment.