--- matahari.spec.in | 8 + src/sysconfig/CMakeLists.txt | 34 ++++ src/sysconfig/org.matahariproject.Sysconfig.conf | 18 ++ src/sysconfig/org.matahariproject.Sysconfig.policy | 62 +++++++ .../org.matahariproject.Sysconfig.service | 4 + src/sysconfig/sysconfig-dbus.c | 171 ++++++++++++++++++++ 6 files changed, 297 insertions(+), 0 deletions(-) create mode 100644 src/sysconfig/org.matahariproject.Sysconfig.conf create mode 100644 src/sysconfig/org.matahariproject.Sysconfig.policy create mode 100644 src/sysconfig/org.matahariproject.Sysconfig.service create mode 100644 src/sysconfig/sysconfig-dbus.c
diff --git a/matahari.spec.in b/matahari.spec.in index 732d028..c792193 100644 --- a/matahari.spec.in +++ b/matahari.spec.in @@ -463,6 +463,14 @@ test "x%{buildroot}" != "x" && rm -rf %{buildroot} %{_mandir}/man8/matahari-qmf-sysconfigd.8* %endif
+%if %{with dbus} +%attr(755, root, root) %{_sbindir}/matahari-dbus-sysconfigd +%config %{_sysconfdir}/dbus-1/system.d/org.matahariproject.Sysconfig.conf +%{_datadir}/dbus-1/interfaces/org.matahariproject.Sysconfig.xml +%{_datadir}/dbus-1/system-services/org.matahariproject.Sysconfig.service +%{_datadir}/polkit-1/actions/org.matahariproject.Sysconfig.policy +%endif + %files consoles %defattr(644, root, root, 755) %doc AUTHORS COPYING diff --git a/src/sysconfig/CMakeLists.txt b/src/sysconfig/CMakeLists.txt index 61db973..9a491d1 100644 --- a/src/sysconfig/CMakeLists.txt +++ b/src/sysconfig/CMakeLists.txt @@ -2,6 +2,7 @@ set(BASE "sysconfig") set(BASE_LIB "m${BASE}") set(QMF_AGENT "matahari-qmf-${BASE}d") set(QMF_CONSOLE "matahari-qmf-${BASE}-consoled") +set(DBUS_AGENT "matahari-dbus-${BASE}d")
# QMF daemon if(WITH-QMF) @@ -26,3 +27,36 @@ if(WITH-QMF) install(TARGETS ${QMF_AGENT} DESTINATION sbin) install(TARGETS ${QMF_CONSOLE} DESTINATION sbin) endif(WITH-QMF) + +# DBus daemon +if(WITH-DBUS) + # Auto-generated stuff + generate_dbus_headers(${BASE} ${CMAKE_CURRENT_BINARY_DIR}/org.matahariproject.xml) + # Create src/dbus directory and generate DBus XML definition files into it + generate_dbus_interface(${CMAKE_CURRENT_SOURCE_DIR}/schema.xml) + + # Check if all properties|statistics|methods have PolicyKit action defined + check_policies_for_schema(${CMAKE_CURRENT_SOURCE_DIR}/schema.xml) + + # Must be included to find matahari-API-dbus-properties.h + include_directories(${CMAKE_CURRENT_BINARY_DIR}) + + set(DBUS_AGENT_SOURCE + ${BASE}-dbus.c + ${BASE}-dbus-glue.h + ${BASE}-dbus-properties.h + ) + + add_executable(${DBUS_AGENT} ${DBUS_AGENT_SOURCE}) + + target_link_libraries(${DBUS_AGENT} ${BASE_LIB} mcommon_dbus ${dbus-glib_LIBRARIES}) + include_directories(${dbus-glib_INCLUDE_DIRS}) + + # Install targets + # TODO: fix hardcoded paths, should go to libexec + install(TARGETS ${DBUS_AGENT} DESTINATION sbin) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.matahariproject.xml DESTINATION share/dbus-1/interfaces RENAME org.matahariproject.Sysconfig.xml) + install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.matahariproject.Sysconfig.service DESTINATION share/dbus-1/system-services) + install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.matahariproject.Sysconfig.conf DESTINATION /etc/dbus-1/system.d) + install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.matahariproject.Sysconfig.policy DESTINATION share/polkit-1/actions) +endif(WITH-DBUS) diff --git a/src/sysconfig/org.matahariproject.Sysconfig.conf b/src/sysconfig/org.matahariproject.Sysconfig.conf new file mode 100644 index 0000000..7c822f8 --- /dev/null +++ b/src/sysconfig/org.matahariproject.Sysconfig.conf @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!DOCTYPE busconfig PUBLIC + "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" + "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> +<busconfig> + + <!-- Only root can own the service --> + <policy user="root"> + <allow own="org.matahariproject.Sysconfig"/> + </policy> + + <!-- Allow anyone to invoke methods on the interfaces --> + <policy context="default"> + <allow send_destination="org.matahariproject.Sysconfig"/> + </policy> + +</busconfig> diff --git a/src/sysconfig/org.matahariproject.Sysconfig.policy b/src/sysconfig/org.matahariproject.Sysconfig.policy new file mode 100644 index 0000000..3460300 --- /dev/null +++ b/src/sysconfig/org.matahariproject.Sysconfig.policy @@ -0,0 +1,62 @@ +<?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.Sysconfig.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.Sysconfig.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.Sysconfig.run_uri"> + <message>Authentication required to allow Matahari to query/alter system configuration</message> + <defaults> + <allow_any>no</allow_any> + <allow_inactive>no</allow_inactive> + <allow_active>auth_admin</allow_active> + </defaults> + </action> + <action id="org.matahariproject.Sysconfig.run_string"> + <message>Authentication required to allow Matahari to query/alter system configuration</message> + <defaults> + <allow_any>no</allow_any> + <allow_inactive>no</allow_inactive> + <allow_active>auth_admin</allow_active> + </defaults> + </action> + <action id="org.matahariproject.Sysconfig.query"> + <message>Authentication required to allow Matahari to query system configuration</message> + <defaults> + <allow_any>no</allow_any> + <allow_inactive>no</allow_inactive> + <allow_active>auth_admin</allow_active> + </defaults> + </action> + <action id="org.matahariproject.Sysconfig.is_configured"> + <message>Authentication required to allow Matahari to check if the system has been configured</message> + <defaults> + <allow_any>no</allow_any> + <allow_inactive>no</allow_inactive> + <allow_active>auth_admin</allow_active> + </defaults> + </action> + <action id="org.matahariproject.Sysconfig.is_postboot_configured"> + <message>Authentication required to allow Matahari to check if the system has been postboot configured</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/sysconfig/org.matahariproject.Sysconfig.service b/src/sysconfig/org.matahariproject.Sysconfig.service new file mode 100644 index 0000000..3196663 --- /dev/null +++ b/src/sysconfig/org.matahariproject.Sysconfig.service @@ -0,0 +1,4 @@ +[D-BUS Service] +Name=org.matahariproject.Sysconfig +Exec=/usr/sbin/matahari-sysconfig-dbusd +User=root diff --git a/src/sysconfig/sysconfig-dbus.c b/src/sysconfig/sysconfig-dbus.c new file mode 100644 index 0000000..a83fdf4 --- /dev/null +++ b/src/sysconfig/sysconfig-dbus.c @@ -0,0 +1,171 @@ +/* + * sysconfig-dbus.c + * + * Copyright (C) 2011 Red Hat, Inc. + * Written by Radek Novacek rnovacek@redhat.com + * + * 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. + * + * 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 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 "config.h" +#include "matahari/sysconfig.h" +#include "matahari/utilities.h" +#include "matahari/dbus_common.h" + +/* Generated properties list */ +#include "sysconfig-dbus-properties.h" + +/* DBus names */ +#define SYSCONFIG_BUS_NAME "org.matahariproject.Sysconfig" +#define SYSCONFIG_OBJECT_PATH "/org/matahariproject/Sysconfig" +#define SYSCONFIG_INTERFACE_NAME "org.matahariproject.Sysconfig" +#define DBUS_PROPERTY_INTERAFACE_NAME "org.freedesktop.DBus.Properties" + +void result_cb(void *data, int result) +{ +} + +gboolean +Sysconfig_run_uri(Matahari* matahari, const char *uri, uint flags, + const char *scheme, const char *key, + DBusGMethodInvocation *context) +{ + GError* error = NULL; + char *status; + if (!check_authorization(SYSCONFIG_BUS_NAME ".run_uri", &error, context)) { + dbus_g_method_return_error(context, error); + return FALSE; + } + enum mh_result res = mh_sysconfig_run_uri(uri, flags, scheme, key, + result_cb, NULL); + if (res == MH_RES_SUCCESS) { + status = mh_sysconfig_is_configured(key); + dbus_g_method_return(context, status); + free(status); + } else { + error = g_error_new(MATAHARI_ERROR, abs(res), mh_result_to_str(res)); + dbus_g_method_return_error(context, error); + g_error_free(error); + return FALSE; + } + return TRUE; +} + +gboolean +Sysconfig_run_string(Matahari* matahari, const char *text, uint flags, + const char *scheme, const char *key, + DBusGMethodInvocation *context) +{ + GError* error = NULL; + char *status; + if (!check_authorization(SYSCONFIG_BUS_NAME ".run_string", &error, + context)) { + dbus_g_method_return_error(context, error); + return FALSE; + } + enum mh_result res = mh_sysconfig_run_string(text, flags, scheme, key, + result_cb, NULL); + if (res == MH_RES_SUCCESS) { + status = mh_sysconfig_is_configured(key); + dbus_g_method_return(context, status); + free(status); + } else { + error = g_error_new(MATAHARI_ERROR, abs(res), mh_result_to_str(res)); + dbus_g_method_return_error(context, error); + g_error_free(error); + return FALSE; + } + return TRUE; +} + +gboolean +Sysconfig_query(Matahari* matahari, const char *text, uint flags, + const char *scheme, DBusGMethodInvocation *context) +{ + GError* error = NULL; + char *status; + if (!check_authorization(SYSCONFIG_BUS_NAME ".query", &error, context)) { + dbus_g_method_return_error(context, error); + return FALSE; + } + status = mh_sysconfig_query(text, flags, scheme); + dbus_g_method_return(context, status); + free(status); + return TRUE; +} + +gboolean +Sysconfig_is_configured(Matahari* matahari, const char *key, + DBusGMethodInvocation *context) +{ + GError* error = NULL; + char *status; + if (!check_authorization(SYSCONFIG_BUS_NAME ".is_configured", &error, + context)) { + dbus_g_method_return_error(context, error); + return FALSE; + } + status = mh_sysconfig_is_configured(key); + dbus_g_method_return(context, status); + free(status); + return TRUE; +} + +/* Generated dbus stuff for sysconfig + * MUST be after declaration of user defined functions. + */ +#include "sysconfig-dbus-glue.h" + +void +matahari_set_property(GObject *object, guint property_id, const GValue *value, + GParamSpec *pspec) +{ + /* We don't have any other property... */ + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +void +matahari_get_property(GObject *object, guint property_id, GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_SYSCONFIG_UUID: + g_value_set_string (value, mh_uuid()); + break; + case PROP_SYSCONFIG_HOSTNAME: + g_value_set_string (value, mh_hostname()); + break; + default: + /* We don't have any other property... */ + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +GType +matahari_dict_type(int prop) +{ + g_printerr("Type of property %s is map of unknown types\n", + properties[prop].name); + return G_TYPE_VALUE; +} + +int +main(int argc, char** argv) +{ + g_type_init(); + return run_dbus_server(SYSCONFIG_BUS_NAME, SYSCONFIG_OBJECT_PATH); +}