---
src/service/CMakeLists.txt | 1 +
src/service/org.matahariproject.Resources.policy | 78 +++++++++
src/service/org.matahariproject.Services.conf | 3 +
src/service/service-dbus.c | 190 ++++++++++++++++++++++
4 files changed, 272 insertions(+), 0 deletions(-)
create mode 100644 src/service/org.matahariproject.Resources.policy
diff --git a/src/service/CMakeLists.txt b/src/service/CMakeLists.txt
index 52781d5..c8b6f59 100644
--- a/src/service/CMakeLists.txt
+++ b/src/service/CMakeLists.txt
@@ -62,4 +62,5 @@ if(WITH-DBUS)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.matahariproject.Services.service
DESTINATION share/dbus-1/system-services)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.matahariproject.Services.conf
DESTINATION /etc/dbus-1/system.d)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.matahariproject.Services.policy
DESTINATION share/polkit-1/actions)
+ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.matahariproject.Resources.policy
DESTINATION share/polkit-1/actions)
endif(WITH-DBUS)
diff --git a/src/service/org.matahariproject.Resources.policy
b/src/service/org.matahariproject.Resources.policy
new file mode 100644
index 0000000..2af9626
--- /dev/null
+++ b/src/service/org.matahariproject.Resources.policy
@@ -0,0 +1,78 @@
+<?xml version="1.0"?>
+<!DOCTYPE policyconfig PUBLIC "-//freedesktop//DTD PolicyKit Policy Configuration
1.0//EN"
"http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd">
+<policyconfig>
+ <vendor>Matahari</vendor>
+ <
vendor_url>https://fedorahosted.org/matahari/</vendor_url>
+ <action id="org.matahariproject.Resources.uuid">
+ <message>Authentication required to allow Matahari to access
UUID</message>
+ <defaults>
+ <allow_any>no</allow_any>
+ <allow_inactive>no</allow_inactive>
+ <allow_active>yes</allow_active>
+ </defaults>
+ </action>
+ <action id="org.matahariproject.Resources.hostname">
+ <message>Authentication required to allow Matahari to access
hostname</message>
+ <defaults>
+ <allow_any>no</allow_any>
+ <allow_inactive>no</allow_inactive>
+ <allow_active>yes</allow_active>
+ </defaults>
+ </action>
+ <action id="org.matahariproject.Resources.list_standards">
+ <message>Authentication required to allow Matahari to list resource
standards</message>
+ <defaults>
+ <allow_any>no</allow_any>
+ <allow_inactive>no</allow_inactive>
+ <allow_active>auth_admin</allow_active>
+ </defaults>
+ </action>
+ <action id="org.matahariproject.Resources.list_providers">
+ <message>Authentication required to allow Matahari to list resource
providers</message>
+ <defaults>
+ <allow_any>no</allow_any>
+ <allow_inactive>no</allow_inactive>
+ <allow_active>auth_admin</allow_active>
+ </defaults>
+ </action>
+ <action id="org.matahariproject.Resources.list">
+ <message>Authentication required to allow Matahari to list
resources</message>
+ <defaults>
+ <allow_any>no</allow_any>
+ <allow_inactive>no</allow_inactive>
+ <allow_active>auth_admin</allow_active>
+ </defaults>
+ </action>
+ <action id="org.matahariproject.Resources.describe">
+ <message>Authentication required to allow Matahari to obtain resource
describtion</message>
+ <defaults>
+ <allow_any>no</allow_any>
+ <allow_inactive>no</allow_inactive>
+ <allow_active>auth_admin</allow_active>
+ </defaults>
+ </action>
+ <action id="org.matahariproject.Resources.invoke">
+ <message>Authentication required to allow Matahari to perform custom action on
resource</message>
+ <defaults>
+ <allow_any>no</allow_any>
+ <allow_inactive>no</allow_inactive>
+ <allow_active>auth_admin</allow_active>
+ </defaults>
+ </action>
+ <action id="org.matahariproject.Resources.cancel">
+ <message>Authentication required to allow Matahari to cancel action on
resource</message>
+ <defaults>
+ <allow_any>no</allow_any>
+ <allow_inactive>no</allow_inactive>
+ <allow_active>auth_admin</allow_active>
+ </defaults>
+ </action>
+ <action id="org.matahariproject.Resources.fail">
+ <message>Authentication required to allow Matahari to obtain indication of
failed resource</message>
+ <defaults>
+ <allow_any>no</allow_any>
+ <allow_inactive>no</allow_inactive>
+ <allow_active>auth_admin</allow_active>
+ </defaults>
+ </action>
+</policyconfig>
diff --git a/src/service/org.matahariproject.Services.conf
b/src/service/org.matahariproject.Services.conf
index 7bad5b8..d151ed3 100644
--- a/src/service/org.matahariproject.Services.conf
+++ b/src/service/org.matahariproject.Services.conf
@@ -15,6 +15,9 @@
send_interface="org.matahariproject.Services"/>
<allow send_destination="org.matahariproject.Services"
+ send_interface="org.matahariproject.Resources"/>
+
+ <allow send_destination="org.matahariproject.Services"
send_interface="org.freedesktop.DBus.Introspectable"/>
<allow send_destination="org.matahariproject.Services"
diff --git a/src/service/service-dbus.c b/src/service/service-dbus.c
index 0f63e9f..2b58f72 100644
--- a/src/service/service-dbus.c
+++ b/src/service/service-dbus.c
@@ -27,6 +27,7 @@
/* Services methods */
#include "matahari/services.h"
#include "matahari/utilities.h"
+#include "matahari/logging.h"
/* Generated properties list */
#include "service-dbus-properties.h"
@@ -35,6 +36,7 @@
#define SERVICES_BUS_NAME "org.matahariproject.Services"
#define SERVICES_OBJECT_PATH "/org/matahariproject/Services"
#define SERVICES_INTERFACE_NAME "org.matahariproject.Services"
+#define RESOURCES_INTERFACE_NAME "org.matahariproject.Resources"
#define TIMEOUT_MS 60000
@@ -214,6 +216,194 @@ Services_describe(Matahari *matahari, const char *name,
return TRUE;
}
+// TODO: This and same code in service-qmf.cpp should go to the library
+const char *standards[] = {
+#ifdef __linux__
+ "ocf",
+#endif
+ "lsb",
+#ifndef WIN32
+ "windows",
+#endif
+ NULL};
+
+
+gboolean
+Resources_list_standards(Matahari *matahari, DBusGMethodInvocation *context)
+{
+ GError* error = NULL;
+ if (!check_authorization(RESOURCES_INTERFACE_NAME ".list_standards",
+ &error, context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+
+ dbus_g_method_return(context, standards);
+ return TRUE;
+}
+
+gboolean
+Resources_list_providers(Matahari *matahari, const char *standard,
+ DBusGMethodInvocation *context)
+{
+ GError* error = NULL;
+ gchar **list;
+ int i = 0;
+ GList *providers;
+
+ if (!check_authorization(RESOURCES_INTERFACE_NAME ".list_providers",
+ &error, context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+
+ // Get list of providers
+ providers = resources_list_providers(standard);
+
+ // Convert GList to (char **)
+ list = g_new(char *, g_list_length(providers) + 1);
+ for (; providers != NULL; providers = providers->next)
+ list[i++] = strdup(providers->data);
+ list[i] = NULL; // Sentinel
+
+ dbus_g_method_return(context, list);
+ g_strfreev(list);
+ g_list_free_full(providers, free);
+ return TRUE;
+}
+
+gboolean
+Resources_list(Matahari *matahari, const char *standard, const char *provider,
+ DBusGMethodInvocation *context)
+{
+ GError* error = NULL;
+ int i = 0;
+ gchar **list;
+ GList *agents = NULL;
+
+ if (!check_authorization(RESOURCES_INTERFACE_NAME ".list",
+ &error, context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+
+ if (strlen(standard) == 0)
+ standard = "ocf";
+ if (strlen(provider) == 0)
+ provider = "heartbeat";
+
+ // Get list of agents
+ agents = resources_list_agents(standard, provider);
+
+ // Convert GList to (char **)
+ list = g_new(char *, g_list_length(agents) + 1);
+ for (; agents != NULL; agents = agents->next)
+ list[i++] = strdup(agents->data);
+ list[i] = NULL; // Sentinel
+
+ dbus_g_method_return(context, list);
+ g_strfreev(list);
+ g_list_free_full(agents, free);
+ return TRUE;
+}
+
+gboolean
+Resources_describe(Matahari *matahari, const char *standard,
+ const char *provider, const char *agent,
+ DBusGMethodInvocation *context)
+{
+ GError* error = NULL;
+ if (!check_authorization(RESOURCES_INTERFACE_NAME ".describe",
+ &error, context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+ // TODO: Implement when implemented in backend
+ error = g_error_new(MATAHARI_ERROR, MATAHARI_NOT_IMPLEMENTED,
+ "Action describe is not implemented yet!");
+ dbus_g_method_return_error(context, error);
+ return TRUE;
+}
+
+gboolean
+Resources_invoke(Matahari *matahari, const char *name, const char *standard,
+ const char *provider, const char *agent, const char *action,
+ unsigned int interval, GHashTable *parameters,
+ unsigned int timeout, unsigned int expected_rc,
+ const char *userdata_in, DBusGMethodInvocation *context)
+{
+ int i = 0;
+ GError* error = NULL;
+ svc_action_t *op = NULL;
+ gboolean valid_standard = FALSE;
+
+ if (!check_authorization(RESOURCES_INTERFACE_NAME ".invoke",
+ &error, context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+
+ // Check if standard is valid
+ while (standards[i] != NULL)
+ {
+ if (strcmp(standard, standards[i]) == 0)
+ {
+ valid_standard = TRUE;
+ break;
+ }
+ i++;
+ }
+ if (!valid_standard) {
+ mh_err("%s is not a known resource standard", standard);
+ error = g_error_new(MATAHARI_ERROR, MATAHARI_NOT_IMPLEMENTED,
+ "%s is not a known resource standard", standard);
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+
+ op = resources_action_create(name, standard, provider, agent, action,
+ interval, timeout, parameters);
+ op->expected_rc = expected_rc;
+
+ services_action_sync(op); //TODO: maybe async
+ dbus_g_method_return(context, op->rc, op->sequence, userdata_in);
+ return TRUE;
+}
+
+gboolean
+Resources_cancel(Matahari *matahari, const char *name, const char *action,
+ unsigned int interval, unsigned int timeout,
+ DBusGMethodInvocation *context)
+{
+ GError* error = NULL;
+ if (!check_authorization(RESOURCES_INTERFACE_NAME ".cancel",
+ &error, context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+
+ services_action_cancel(name, action, interval);
+ dbus_g_method_return(context);
+ return TRUE;
+}
+
+gboolean
+Resources_fail(Matahari *matahari, const char *name, unsigned int rc,
+ DBusGMethodInvocation *context)
+{
+ GError* error = NULL;
+ if (!check_authorization(RESOURCES_INTERFACE_NAME ".fail",
+ &error, context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+ // TODO: Implement when implemented in backend
+ error = g_error_new(MATAHARI_ERROR, MATAHARI_NOT_IMPLEMENTED,
+ "Action fail is not implemented yet!");
+ dbus_g_method_return_error(context, error);
+ return TRUE;
+}
+
/* Generated dbus stuff for services
* MUST be after declaration of user defined functions.
--
1.7.6