[PATCH] Build: Install config.h and errors.h
by Zane Bitter
It was previously impossible for an external agent to include the logging.h
header, since that includes utilities.h which includes config.h, which was
not exported. config.h is now installed in include/matahari.
The header agent.h includes definitions for backward-compatibilty that
rely on the inclusion of errors.h.
Signed-off-by: Zane Bitter <zbitter(a)redhat.com>
---
matahari.spec.in | 2 ++
src/CMakeLists.txt | 7 +++++--
src/include/matahari/agent.h | 3 ++-
src/include/matahari/utilities.h | 2 +-
4 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/matahari.spec.in b/matahari.spec.in
index 4bafef7..cabc6ba 100644
--- a/matahari.spec.in
+++ b/matahari.spec.in
@@ -517,8 +517,10 @@ test "x%{buildroot}" != "x" && rm -rf %{buildroot}
%{_libdir}/libm*.so
%{_includedir}/matahari.h
+%{_includedir}/matahari/config.h
%{_includedir}/matahari/logging.h
%{_includedir}/matahari/utilities.h
+%{_includedir}/matahari/errors.h
%{_includedir}/matahari/dnssrv.h
%{_includedir}/matahari/host.h
%{_includedir}/matahari/network.h
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e9d3396..bcc2ca5 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -35,7 +35,8 @@ set(CONSOLE_MAN_DESC "Console for the Matahari suite of remote agents")
set(DAEMON_TYPE "AGENT")
include(FindPkgConfig)
-include_directories("${CMAKE_CURRENT_BINARY_DIR}")
+include_directories("${CMAKE_CURRENT_BINARY_DIR}/include")
+include_directories("${CMAKE_CURRENT_BINARY_DIR}/include/matahari")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/common")
@@ -182,8 +183,10 @@ add_subdirectory(unittests)
### Installation
install(FILES ${SCHEMAS} DESTINATION share/matahari)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/matahari.h DESTINATION include)
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/matahari/config.h DESTINATION include/matahari)
install(FILES include/matahari/logging.h DESTINATION include/matahari)
install(FILES include/matahari/utilities.h DESTINATION include/matahari)
+install(FILES include/matahari/errors.h DESTINATION include/matahari)
install(FILES include/matahari/dnssrv.h DESTINATION include/matahari)
install(FILES include/matahari/host.h DESTINATION include/matahari)
install(FILES include/matahari/network.h DESTINATION include/matahari)
@@ -206,6 +209,6 @@ if(WITH-DBUS)
install(FILES include/matahari/gobject_class.h DESTINATION include/matahari)
endif(WITH-DBUS)
-configure_file (${CMAKE_CURRENT_SOURCE_DIR}/include/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
+configure_file (${CMAKE_CURRENT_SOURCE_DIR}/include/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/matahari/config.h)
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/include/matahari.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/matahari.h)
diff --git a/src/include/matahari/agent.h b/src/include/matahari/agent.h
index 6004814..7108c2a 100644
--- a/src/include/matahari/agent.h
+++ b/src/include/matahari/agent.h
@@ -42,11 +42,12 @@ int required_argument = 1;
#else
# include <getopt.h>
#endif
-}
// For backward compatibility
+#include "matahari/errors.h"
#define MH_NOT_IMPLEMENTED (mh_result_to_str(MH_RES_NOT_IMPLEMENTED))
#define MH_INVALID_ARGS (mh_result_to_str(MH_RES_INVALID_ARGS))
+}
#ifndef NS_MAXDNAME
# define NS_MAXDNAME 1025
diff --git a/src/include/matahari/utilities.h b/src/include/matahari/utilities.h
index b6cce84..893d068 100644
--- a/src/include/matahari/utilities.h
+++ b/src/include/matahari/utilities.h
@@ -25,7 +25,7 @@
#ifndef __MH_UTILITIES__
#define __MH_UTILITIES__
-#include "config.h"
+#include "matahari/config.h"
#include <stdlib.h>
#include <sys/types.h>
12 years, 7 months
[PATCH] tests: Allow augeaus test to run as non-root.
by Russell Bryant
Add the API call that tells the sysconfig lib to put the key files in
/tmp instead of /var/lib/matahari.
Signed-off-by: Russell Bryant <rbryant(a)redhat.com>
---
src/unittests/mh_api_sysconfig_linux.h | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/src/unittests/mh_api_sysconfig_linux.h b/src/unittests/mh_api_sysconfig_linux.h
index 1020dbe..1c78183 100644
--- a/src/unittests/mh_api_sysconfig_linux.h
+++ b/src/unittests/mh_api_sysconfig_linux.h
@@ -66,6 +66,8 @@ class MhApiSysconfigLinuxSuite : public CxxTest::TestSuite
int fd = mkstemp(tmp_file);
TS_ASSERT(fd >= 0);
+ mh_sysconfig_keys_dir_set("/tmp/matahari-sysconfig-keys/");
+
// test query function
query_result = mh_sysconfig_query(query, 0, "augeas");
TS_ASSERT(query_result != NULL);
--
1.7.6.4
12 years, 7 months
[PATCH 0/6] Run host QMF API functional tests in autobuild
by Russell Bryant
Greetings,
I have started looking at the QMF API functional tests that were
recently merged by Dave Johnson for how we can get them running
in autobuild. This first set of changes get the Host QMF API tests
running in autobuild. Patches 4 and 6 are the important parts.
The rest is just random cleanup that I did along the way.
[PATCH 1/6] tests: add a file that lists test dependencies.
[PATCH 2/6] tests: strip trailing whitespace.
[PATCH 3/6] core: Localize k5start related code.
[PATCH 4/6] tests: Make host API test more mock compatible.
[PATCH 5/6] tests: Tweak indentation.
[PATCH 6/6] autobuild: Run Host API functional tests.
autobuild.sh | 60 ++++++++++----
src/lib/mh_agent.cpp | 43 +++++-----
src/tests/deps.sh | 5 +
src/tests/matahariTest.py | 51 ++++++++++++
src/tests/test_host_api.py | 164 +++++++++++++++++++++-------------------
src/tests/test_network_api.py | 24 ++---
src/tests/test_resource_api.py | 20 ++--
src/tests/test_service_api.py | 12 +-
src/tests/test_sysconfig_api.py | 22 ++---
9 files changed, 248 insertions(+), 153 deletions(-)
Thanks,
--
Russell Bryant
12 years, 7 months
Re: [Matahari] Scrum 2011-09-23
by Zane Bitter
(Moving this discussion to the mailing list.)
On 24/09/11 03:24, ajs(a)redhat.com wrote:
> - WRT: Vios-Proxy:
> https://github.com/matahari/matahari/wiki/Vios-Proxy
> Use cases A,B are do-able.
> Use case C !do-able:
> Brokers are designed to create sockets rather than bind to them.
> Which is bad in our case since only our agents are able to bind to
> the virtioserial devices. So federated brokers outside of tcp connections
> does not seem feasible at this time. In conclusion, qpid broker code will
> need to be updated in order to use vios in a federated environment.
>
> For verification, I used this script to start up my guests
>
> #!/bin/bash
> # $1 - location of qemu img
> QPID_BROKER_ROOT="/tmp/qpid"
> for gnameseq in `seq 1 2`
> do
> GUEST_NAME="guest"$gnameseq
> mkdir -p ${QPID_BROKER_ROOT}/${GUEST_NAME}
> sudo qemu-kvm -name "${GUEST_NAME}" \
> -m 512M \
> -smp 2 \
> -snapshot $1 \
> -device virtio-serial \
> -chardev socket,path=${QPID_BROKER_ROOT}/${GUEST_NAME}/0,server,nowait,id=${GUEST_NAME}_0 \
> -chardev socket,path=${QPID_BROKER_ROOT}/${GUEST_NAME}/1,server,nowait,id=${GUEST_NAME}_1 \
> -device virtserialport,chardev=${GUEST_NAME}_0,name=qpid.0 \
> -device virtserialport,chardev=${GUEST_NAME}_1,name=qpid.1 \
> &
> PID=$!
> echo "started ${GUEST_NAME} pid = $PID"
> done
>
> Next startup `vios-proxy-host /tmp/qpid 49000`
> Startup broker on host `service matahari-broker start`
>
> On guest(s) startup `vios-proxy-guest /dev/virtio-devs/ 49000`
> Just for sanity sake, used qpidd on the guest to attempt to bind to our
> virtioserial devices `qpidd -p 49000 --auth no`
> Experience unable to bind to port 49000, port in use .. etc.
> Verify communication actually works, startup a agent on either guest
> `service matahari-host start` and do the normal querying via qmf-tool.
I think C is do-able but only using two separate ports. i.e.
`vios-proxy-guest /dev/virtio-devs 48999` then have the broker federate
with localhost:48999.
It doesn't seem like there's a way to make that configuration easy out
of the box, though.
cheers,
Zane.
12 years, 7 months
[PATCH 1/5] sysconfig: add DBus agent v2
by Radek Novacek
Signed-off-by: Radek Novacek <rnovacek(a)redhat.com>
---
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 | 181 ++++++++++++++++++++
6 files changed, 307 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 666c1da..4bafef7 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..0d3fe12
--- /dev/null
+++ b/src/sysconfig/sysconfig-dbus.c
@@ -0,0 +1,181 @@
+/*
+ * sysconfig-dbus.c
+ *
+ * Copyright (C) 2011 Red Hat, Inc.
+ * Written by Radek Novacek <rnovacek(a)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;
+ enum mh_result res;
+
+ if (!check_authorization(SYSCONFIG_BUS_NAME ".run_uri", &error, context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+
+ 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;
+ enum mh_result res;
+
+ if (!check_authorization(SYSCONFIG_BUS_NAME ".run_string", &error,
+ context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+
+ 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);
+}
--
1.7.6.2
12 years, 7 months
[PATCH 1/2] - Split sysconfig unittests into its proper variant
by Adam Stokes
- CXXTEST doesn't honor #ifdef/ifndef etc
see
http://cxxtest.tigris.org/ds/viewMessage.do?dsForumId=8401&dsMessageId=61400
At this point we decided to keep things less
magical and split up the unittests for sysconfig
keeping all common tests together and variant
specifics in their own test suite.
Signed-off-by: Adam Stokes <astokes(a)fedoraproject.org>
---
src/unittests/CMakeLists.txt | 4 +-
src/unittests/mh_api_sysconfig.h | 132 ------------------------------
src/unittests/mh_api_sysconfig_common.h | 58 +++++++++++++
src/unittests/mh_api_sysconfig_linux.h | 109 ++++++++++++++++++++++++
src/unittests/mh_api_sysconfig_windows.h | 42 ++++++++++
5 files changed, 212 insertions(+), 133 deletions(-)
delete mode 100644 src/unittests/mh_api_sysconfig.h
create mode 100644 src/unittests/mh_api_sysconfig_common.h
create mode 100644 src/unittests/mh_api_sysconfig_linux.h
create mode 100644 src/unittests/mh_api_sysconfig_windows.h
diff --git a/src/unittests/CMakeLists.txt b/src/unittests/CMakeLists.txt
index 331481b..0e1c389 100644
--- a/src/unittests/CMakeLists.txt
+++ b/src/unittests/CMakeLists.txt
@@ -5,13 +5,15 @@ if(CXXTEST_FOUND)
ENABLE_TESTING()
CXXTEST_ADD_TEST(mh_api_network_unittest network_unittest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mh_api_network.h)
CXXTEST_ADD_TEST(mh_api_host_unittest host_unittest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mh_api_host.h)
- CXXTEST_ADD_TEST(mh_api_sysconfig_unittest sysconfig_unittest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mh_api_sysconfig.h)
+ CXXTEST_ADD_TEST(mh_api_sysconfig_common_unittest sysconfig_common_unittest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mh_api_sysconfig_common.h)
+ CXXTEST_ADD_TEST(mh_api_sysconfig_unittest sysconfig_unittest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mh_api_sysconfig_${VARIANT}.h)
CXXTEST_ADD_TEST(mh_api_utilities_unittest utilities_unittest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mh_api_utilities.h)
CXXTEST_ADD_TEST(mh_hsa_unittest hsa_unittest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mh_hsa_${VARIANT}.h)
add_library(mh_tester SHARED test_utilities.c)
target_link_libraries(mh_tester ${pcre_LIBRARIES} mcommon mnetwork mhost msysconfig)
target_link_libraries(mh_api_network_unittest mh_tester)
target_link_libraries(mh_api_host_unittest mh_tester)
+ target_link_libraries(mh_api_sysconfig_common_unittest mh_tester)
target_link_libraries(mh_api_sysconfig_unittest mh_tester)
target_link_libraries(mh_api_utilities_unittest mh_tester)
target_link_libraries(mh_hsa_unittest mh_tester)
diff --git a/src/unittests/mh_api_sysconfig.h b/src/unittests/mh_api_sysconfig.h
deleted file mode 100644
index 8d9d512..0000000
--- a/src/unittests/mh_api_sysconfig.h
+++ /dev/null
@@ -1,132 +0,0 @@
-#ifndef __MH_API_NETWORK_UNITTEST_H
-#define __MH_API_NETWORK_UNITTEST_H
-#include <iostream>
-#include <cstring>
-#include <string>
-#include <sstream>
-#include <utility>
-#include <vector>
-#include <cstdlib>
-#include <cstdio>
-#include <sys/stat.h>
-#include <dirent.h>
-#include <cxxtest/TestSuite.h>
-
-extern "C" {
-#include <glib.h>
-
-#include "matahari/sysconfig.h"
-#include "matahari/sysconfig_internal.h"
-#include "matahari/utilities.h"
-#include "mh_test_utilities.h"
-};
-
-using namespace std;
-
-/**
- * Callback function, doesn't do anything
- */
-void f(void *, int)
-{
-}
-
-/**
- * Result from run_string and run_uri functions is in the form "query = result\n"
- * This function will extract the "result"
- *
- * \note The return of this routine must be freed with free()
- */
-char *strip(const char *result)
-{
- char *stripped;
- // strip the "query = " part
- stripped = strdup(strstr(result, " = ") + 3);
- // and the line end
- stripped[strlen(stripped) - 1] = '\0';
- return stripped;
-}
-
-class MhApiSysconfigSuite : public CxxTest::TestSuite
-{
- public:
-
- void testIsConfigured(void)
- {
- const char key[] = "org.matahariproject.test.unittest"; // Unimportant key defined
- const char *invalid_keys[3] = {"../etc/passwd",
- "./../etc/passwd#",
- "HAPPY#HAMMY,@"};
- char *key_res;
-
- mh_sysconfig_keys_dir_set("/tmp/matahari-sysconfig-keys/");
-
- TS_ASSERT((mh_sysconfig_set_configured(key, "OK")) == MH_RES_SUCCESS);
- TS_ASSERT(((key_res = mh_sysconfig_is_configured(key))) != NULL);
- TS_ASSERT(!strcmp("OK", key_res));
-
- free(key_res);
- for (int i = 0; i < DIMOF(invalid_keys); i++) {
- TS_ASSERT((mh_sysconfig_set_configured(invalid_keys[i], "OK")) == MH_RES_INVALID_ARGS);
- }
- }
-
- /**
- * This test compares result of mh_sysconfig_query, mh_sysconfig_run_string
- * and mh_sysconfig_run_uri commands. This test is linux-only (no augeas
- * on windows).
- */
-#ifndef WIN32
- void testAugeasQuery(void)
- {
- const char key[] = "org.matahariproject.test.unittest.augeas";
- const char query[] = "/files/etc/mtab/1/spec";
- const char command[] = "get /files/etc/mtab/1/spec";
- char tmp_file[] = "matahari-sysconfig-test_XXXXXX";
- char *query_result, *run_string_result, *run_string_result_stripped;
- char *run_uri_result, *run_uri_result_stripped;
- char *uri, *abs_path;
- int fd = mkstemp(tmp_file);
- TS_ASSERT(fd >= 0);
-
- // test query function
- query_result = mh_sysconfig_query(query, 0, "augeas");
- TS_ASSERT(query_result != NULL);
- TS_ASSERT(strlen(query_result) > 0);
-
- // test run_string function
- TS_ASSERT(mh_sysconfig_run_string(command, MH_SYSCONFIG_FLAG_FORCE, "augeas", key, f, NULL) == MH_RES_SUCCESS);
- run_string_result = mh_sysconfig_is_configured(key);
- TS_ASSERT(run_string_result != NULL);
-
- run_string_result_stripped = strip(run_string_result);
- free(run_string_result);
-
- // test run_uri function
- write(fd, command, strlen(command));
- write(fd, "\n", 1);
- close(fd);
-
- abs_path = realpath(tmp_file, NULL);
- asprintf(&uri, "file://%s", abs_path);
- TS_ASSERT(mh_sysconfig_run_uri(uri, MH_SYSCONFIG_FLAG_FORCE, "augeas", key, f, NULL) == MH_RES_SUCCESS);
- run_uri_result = mh_sysconfig_is_configured(key);
- TS_ASSERT(run_uri_result != NULL);
-
- run_uri_result_stripped = strip(run_uri_result);
- free(run_uri_result);
- unlink(tmp_file);
-
- // compare the results of all functions above
- TS_ASSERT(strcmp(query_result, run_string_result_stripped) == 0);
- TS_ASSERT(strcmp(query_result, run_uri_result_stripped) == 0);
-
- free(query_result);
- free(run_string_result_stripped);
- free(run_uri_result_stripped);
- free(abs_path);
- free(uri);
- }
-#endif
-};
-
-#endif
diff --git a/src/unittests/mh_api_sysconfig_common.h b/src/unittests/mh_api_sysconfig_common.h
new file mode 100644
index 0000000..7efc63a
--- /dev/null
+++ b/src/unittests/mh_api_sysconfig_common.h
@@ -0,0 +1,58 @@
+#ifndef __MH_API_SYSCONFIG_COMMON_UNITTEST_H
+#define __MH_API_SYSCONFIG_COMMON_UNITTEST_H
+#include <iostream>
+#include <cstring>
+#include <string>
+#include <sstream>
+#include <utility>
+#include <vector>
+#include <cstdlib>
+#include <cstdio>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <cxxtest/TestSuite.h>
+
+extern "C" {
+#include <glib.h>
+
+#include "matahari/sysconfig.h"
+#include "matahari/sysconfig_internal.h"
+#include "matahari/utilities.h"
+#include "mh_test_utilities.h"
+};
+
+using namespace std;
+
+/**
+ * Callback function, doesn't do anything
+ */
+void f(void *, int)
+{
+}
+
+class MhApiSysconfigCommonSuite : public CxxTest::TestSuite
+{
+ public:
+
+ void testIsConfigured(void)
+ {
+ const char key[] = "org.matahariproject.test.unittest"; // Unimportant key defined
+ const char *invalid_keys[3] = {"../etc/passwd",
+ "./../etc/passwd#",
+ "HAPPY#HAMMY,@"};
+ char *key_res;
+
+ mh_sysconfig_keys_dir_set("/tmp/matahari-sysconfig-keys/");
+
+ TS_ASSERT((mh_sysconfig_set_configured(key, "OK")) == MH_RES_SUCCESS);
+ TS_ASSERT(((key_res = mh_sysconfig_is_configured(key))) != NULL);
+ TS_ASSERT(!strcmp("OK", key_res));
+
+ free(key_res);
+ for (int i = 0; i < DIMOF(invalid_keys); i++) {
+ TS_ASSERT((mh_sysconfig_set_configured(invalid_keys[i], "OK")) == MH_RES_INVALID_ARGS);
+ }
+ }
+};
+
+#endif
diff --git a/src/unittests/mh_api_sysconfig_linux.h b/src/unittests/mh_api_sysconfig_linux.h
new file mode 100644
index 0000000..1020dbe
--- /dev/null
+++ b/src/unittests/mh_api_sysconfig_linux.h
@@ -0,0 +1,109 @@
+#ifndef __MH_API_SYSCONFIG_LINUX_UNITTEST_H
+#define __MH_API_SYSCONFIG_LINUX_UNITTEST_H
+#include <iostream>
+#include <cstring>
+#include <string>
+#include <sstream>
+#include <utility>
+#include <vector>
+#include <cstdlib>
+#include <cstdio>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <cxxtest/TestSuite.h>
+
+extern "C" {
+#include <glib.h>
+
+#include "matahari/sysconfig.h"
+#include "matahari/sysconfig_internal.h"
+#include "matahari/utilities.h"
+#include "mh_test_utilities.h"
+};
+
+using namespace std;
+
+/**
+ * Callback function, doesn't do anything
+ */
+void f(void *, int)
+{
+}
+
+/**
+ * Result from run_string and run_uri functions is in the form "query = result\n"
+ * This function will extract the "result"
+ *
+ * \note The return of this routine must be freed with free()
+ */
+char *strip(const char *result)
+{
+ char *stripped;
+ // strip the "query = " part
+ stripped = strdup(strstr(result, " = ") + 3);
+ // and the line end
+ stripped[strlen(stripped) - 1] = '\0';
+ return stripped;
+}
+
+class MhApiSysconfigLinuxSuite : public CxxTest::TestSuite
+{
+ public:
+ /**
+ * This test compares result of mh_sysconfig_query, mh_sysconfig_run_string
+ * and mh_sysconfig_run_uri commands. This test is linux-only (no augeas
+ * on windows).
+ */
+ void testAugeasQuery(void)
+ {
+ const char key[] = "org.matahariproject.test.unittest.augeas";
+ const char query[] = "/files/etc/mtab/1/spec";
+ const char command[] = "get /files/etc/mtab/1/spec";
+ char tmp_file[] = "matahari-sysconfig-test_XXXXXX";
+ char *query_result, *run_string_result, *run_string_result_stripped;
+ char *run_uri_result, *run_uri_result_stripped;
+ char *uri, *abs_path;
+ int fd = mkstemp(tmp_file);
+ TS_ASSERT(fd >= 0);
+
+ // test query function
+ query_result = mh_sysconfig_query(query, 0, "augeas");
+ TS_ASSERT(query_result != NULL);
+ TS_ASSERT(strlen(query_result) > 0);
+
+ // test run_string function
+ TS_ASSERT(mh_sysconfig_run_string(command, MH_SYSCONFIG_FLAG_FORCE, "augeas", key, f, NULL) == MH_RES_SUCCESS);
+ run_string_result = mh_sysconfig_is_configured(key);
+ TS_ASSERT(run_string_result != NULL);
+
+ run_string_result_stripped = strip(run_string_result);
+ free(run_string_result);
+
+ // test run_uri function
+ write(fd, command, strlen(command));
+ write(fd, "\n", 1);
+ close(fd);
+
+ abs_path = realpath(tmp_file, NULL);
+ asprintf(&uri, "file://%s", abs_path);
+ TS_ASSERT(mh_sysconfig_run_uri(uri, MH_SYSCONFIG_FLAG_FORCE, "augeas", key, f, NULL) == MH_RES_SUCCESS);
+ run_uri_result = mh_sysconfig_is_configured(key);
+ TS_ASSERT(run_uri_result != NULL);
+
+ run_uri_result_stripped = strip(run_uri_result);
+ free(run_uri_result);
+ unlink(tmp_file);
+
+ // compare the results of all functions above
+ TS_ASSERT(strcmp(query_result, run_string_result_stripped) == 0);
+ TS_ASSERT(strcmp(query_result, run_uri_result_stripped) == 0);
+
+ free(query_result);
+ free(run_string_result_stripped);
+ free(run_uri_result_stripped);
+ free(abs_path);
+ free(uri);
+ }
+};
+
+#endif
diff --git a/src/unittests/mh_api_sysconfig_windows.h b/src/unittests/mh_api_sysconfig_windows.h
new file mode 100644
index 0000000..e65522b
--- /dev/null
+++ b/src/unittests/mh_api_sysconfig_windows.h
@@ -0,0 +1,42 @@
+#ifndef __MH_API_NETWORK_UNITTEST_H
+#define __MH_API_NETWORK_UNITTEST_H
+#include <iostream>
+#include <cstring>
+#include <string>
+#include <sstream>
+#include <utility>
+#include <vector>
+#include <cstdlib>
+#include <cstdio>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <cxxtest/TestSuite.h>
+
+extern "C" {
+#include <glib.h>
+
+#include "matahari/sysconfig.h"
+#include "matahari/sysconfig_internal.h"
+#include "matahari/utilities.h"
+#include "mh_test_utilities.h"
+};
+
+using namespace std;
+
+/**
+ * Callback function, doesn't do anything
+ */
+void f(void *, int)
+{
+}
+
+class MhApiSysconfigWindowsSuite : public CxxTest::TestSuite
+{
+ public:
+ void testPlaceHolder(void)
+ {
+ TS_ASSERT( 1 + 1 > 1);
+ }
+};
+
+#endif
--
1.7.6.4
12 years, 7 months
[PATCH 1/2] Sysconfig DBus agent
by Radek Novacek
---
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(a)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);
+}
--
1.7.6.2
12 years, 7 months
[PATCH] - Do not BuildRequires sigar-devel <version>
by Adam Stokes
- This is not necessary in upstream/Fedora
since we are building against latest sigar
anyways.
Signed-off-by: Adam Stokes <astokes(a)fedoraproject.org>
---
matahari.spec.in | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/matahari.spec.in b/matahari.spec.in
index 732d028..666c1da 100644
--- a/matahari.spec.in
+++ b/matahari.spec.in
@@ -51,7 +51,7 @@ BuildRequires: libuuid-devel
BuildRequires: gcc-c++
BuildRequires: pcre-devel
BuildRequires: glib2-devel
-BuildRequires: sigar-devel > 1.6.5-0.2
+BuildRequires: sigar-devel
BuildRequires: libcurl-devel
BuildRequires: help2man
BuildRequires: augeas-devel >= 0.9.0
--
1.7.6.4
12 years, 7 months
tests directory structure
by Adam Stokes
Hi,
We've got a matahari/tests and matahari/src/tests directory and was
curious if this was intentional? If not, could we do something like
matahari/tests
matahari/tests/python/
Keep all cxxtest in toplevel directory and obviously the python in its
own directory?
Thanks
Adam
12 years, 7 months
[PATCH] Add test for augeas support in sysconfig agent
by Radek Novacek
The test compares results from mh_sysconfig_query,
mh_sysconfig_run_string and mh_sysconfig_run_uri.
---
src/tests/mh_api_sysconfig.h | 78 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 78 insertions(+), 0 deletions(-)
diff --git a/src/tests/mh_api_sysconfig.h b/src/tests/mh_api_sysconfig.h
index 5eb4fe7..1cbe18a 100644
--- a/src/tests/mh_api_sysconfig.h
+++ b/src/tests/mh_api_sysconfig.h
@@ -23,6 +23,29 @@ extern "C" {
using namespace std;
+/**
+ * Callback function, doesn't do anything
+ */
+void f(void *, int)
+{
+}
+
+/**
+ * Result from run_string and run_uri functions is in the form "query = result\n"
+ * This function will extract the "result"
+ *
+ * \note The return of this routine must be freed with free()
+ */
+char *strip(const char *result)
+{
+ char *stripped;
+ // strip the "query = " part
+ stripped = strdup(strstr(result, " = ") + 3);
+ // and the line end
+ stripped[strlen(stripped) - 1] = '\0';
+ return stripped;
+}
+
class MhApiSysconfigSuite : public CxxTest::TestSuite
{
public:
@@ -46,6 +69,61 @@ class MhApiSysconfigSuite : public CxxTest::TestSuite
TS_ASSERT((mh_sysconfig_set_configured(invalid_keys[i], "OK")) == FALSE);
}
}
+
+ /**
+ * This test compares result of mh_sysconfig_query, mh_sysconfig_run_string
+ * and mh_sysconfig_run_uri commands.
+ */
+ void testAugeasQuery(void)
+ {
+ const char key[] = "org.matahariproject.test.unittest.augeas";
+ const char query[] = "/files/etc/fstab/1/spec";
+ const char command[] = "get /files/etc/fstab/1/spec";
+ char tmp_file[] = "matahari-sysconfig-test_XXXXXX";
+ char *query_result, *run_string_result, *run_string_result_stripped;
+ char *run_uri_result, *run_uri_result_stripped;
+ char *uri, *abs_path;
+ int fd = mkstemp(tmp_file);
+ TS_ASSERT(fd >= 0);
+
+ // test query function
+ query_result = mh_sysconfig_query(query, 0, "augeas");
+ TS_ASSERT(query_result != NULL);
+ TS_ASSERT(strlen(query_result) > 0);
+
+ // test run_string function
+ TS_ASSERT(mh_sysconfig_run_string(command, MH_SYSCONFIG_FLAG_FORCE, "augeas", key, f, NULL) == MH_RES_SUCCESS);
+ run_string_result = mh_sysconfig_is_configured(key);
+ TS_ASSERT(run_string_result != NULL);
+
+ run_string_result_stripped = strip(run_string_result);
+ free(run_string_result);
+
+ // test run_uri function
+ write(fd, command, strlen(command));
+ write(fd, "\n", 1);
+ close(fd);
+
+ abs_path = realpath(tmp_file, NULL);
+ asprintf(&uri, "file://%s", abs_path);
+ TS_ASSERT(mh_sysconfig_run_uri(uri, MH_SYSCONFIG_FLAG_FORCE, "augeas", key, f, NULL) == MH_RES_SUCCESS);
+ run_uri_result = mh_sysconfig_is_configured(key);
+ TS_ASSERT(run_uri_result != NULL);
+
+ run_uri_result_stripped = strip(run_uri_result);
+ free(run_uri_result);
+ unlink(tmp_file);
+
+ // compare the results of all functions above
+ TS_ASSERT(strcmp(query_result, run_string_result_stripped) == 0);
+ TS_ASSERT(strcmp(query_result, run_uri_result_stripped) == 0);
+
+ free(query_result);
+ free(run_string_result_stripped);
+ free(run_uri_result_stripped);
+ free(abs_path);
+ free(uri);
+ }
};
#endif
--
1.7.6.2
12 years, 7 months