From 1c11c5cff15358026ea867a8127adb85173dfe5c Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Fri, 31 Jul 2015 12:33:07 -0400 Subject: [PATCH 01/14] core: fix NMManager in private-bus-only case NMManager was failing to initialize if there was only a private bus, despite the fact that this is exactly the use case that the private bus was added for. The only other potentially-failing code in nm_manager_new() was adding prop_filter to the D-Bus connection, but this can't really fail, so just assert that it doesn't. And now, nm_manager_new() always succeeds, so update the caller for that. --- src/main.c | 8 +------- src/nm-manager.c | 49 +++++++++++++----------------------------------- src/nm-manager.h | 3 +-- 3 files changed, 15 insertions(+), 45 deletions(-) diff --git a/src/main.c b/src/main.c index a8e8805040..3ea05bebf8 100644 --- a/src/main.c +++ b/src/main.c @@ -459,13 +459,7 @@ main (int argc, char *argv[]) net_enabled, wifi_enabled, wwan_enabled, - wimax_enabled, - &error); - if (manager == NULL) { - nm_log_err (LOGD_CORE, "failed to initialize the network manager: %s", - error && error->message ? error->message : "(unknown)"); - goto done; - } + wimax_enabled); g_signal_connect (manager, NM_MANAGER_CONFIGURE_QUIT, G_CALLBACK (manager_configure_quit), config); diff --git a/src/nm-manager.c b/src/nm-manager.c index b24b592317..3bda450930 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -165,7 +165,6 @@ typedef struct { NMPolicy *policy; NMBusManager *dbus_mgr; - gboolean prop_filter_added; NMRfkillManager *rfkill_mgr; NMSettings *settings; @@ -4724,17 +4723,13 @@ dbus_connection_changed_cb (NMBusManager *dbus_mgr, gpointer user_data) { NMManager *self = NM_MANAGER (user_data); - gboolean success = FALSE; + gboolean success; if (dbus_connection) { - /* Register property filter on new connection; there's no reason this - * should fail except out-of-memory or program error; if it does fail - * then there's no Manager property access control, which is bad. - */ + /* Only fails on ENOMEM */ success = dbus_connection_add_filter (dbus_connection, prop_filter, self, NULL); g_assert (success); } - NM_MANAGER_GET_PRIVATE (self)->prop_filter_added = success; } /**********************************************************************/ @@ -4762,11 +4757,9 @@ nm_manager_new (NMSettings *settings, gboolean initial_net_enabled, gboolean initial_wifi_enabled, gboolean initial_wwan_enabled, - gboolean initial_wimax_enabled, - GError **error) + gboolean initial_wimax_enabled) { NMManagerPrivate *priv; - DBusGConnection *bus; DBusConnection *dbus_connection; NMConfigData *config_data; @@ -4779,16 +4772,14 @@ nm_manager_new (NMSettings *settings, priv = NM_MANAGER_GET_PRIVATE (singleton); - bus = nm_bus_manager_get_connection (priv->dbus_mgr); - if (!bus) { - g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_FAILED, - "Failed to initialize D-Bus connection"); - g_object_unref (singleton); - return NULL; - } + dbus_connection = nm_bus_manager_get_dbus_connection (priv->dbus_mgr); + if (dbus_connection) { + gboolean success; - dbus_connection = dbus_g_connection_get_connection (bus); - g_assert (dbus_connection); + /* Only fails on ENOMEM */ + success = dbus_connection_add_filter (dbus_connection, prop_filter, singleton, NULL); + g_assert (success); + } priv->policy = nm_policy_new (singleton, settings); g_signal_connect (priv->policy, "notify::" NM_POLICY_DEFAULT_IP4_DEVICE, @@ -4813,14 +4804,6 @@ nm_manager_new (NMSettings *settings, g_signal_connect (priv->connectivity, "notify::" NM_CONNECTIVITY_STATE, G_CALLBACK (connectivity_changed), singleton); - if (!dbus_connection_add_filter (dbus_connection, prop_filter, singleton, NULL)) { - g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_FAILED, - "Failed to register DBus connection filter"); - g_object_unref (singleton); - return NULL; - } - priv->prop_filter_added = TRUE; - priv->settings = g_object_ref (settings); g_signal_connect (priv->settings, "notify::" NM_SETTINGS_STARTUP_COMPLETE, G_CALLBACK (settings_startup_complete_changed), singleton); @@ -5074,7 +5057,6 @@ dispose (GObject *object) { NMManager *manager = NM_MANAGER (object); NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager); - DBusGConnection *bus; DBusConnection *dbus_connection; g_slist_free_full (priv->auth_chains, (GDestroyNotify) nm_auth_chain_unref); @@ -5120,14 +5102,9 @@ dispose (GObject *object) /* Unregister property filter */ if (priv->dbus_mgr) { - bus = nm_bus_manager_get_connection (priv->dbus_mgr); - if (bus) { - dbus_connection = dbus_g_connection_get_connection (bus); - if (dbus_connection && priv->prop_filter_added) { - dbus_connection_remove_filter (dbus_connection, prop_filter, manager); - priv->prop_filter_added = FALSE; - } - } + dbus_connection = nm_bus_manager_get_dbus_connection (priv->dbus_mgr); + if (dbus_connection) + dbus_connection_remove_filter (dbus_connection, prop_filter, manager); g_signal_handlers_disconnect_by_func (priv->dbus_mgr, dbus_connection_changed_cb, manager); priv->dbus_mgr = NULL; } diff --git a/src/nm-manager.h b/src/nm-manager.h index d8b566851d..723f4822d0 100644 --- a/src/nm-manager.h +++ b/src/nm-manager.h @@ -81,8 +81,7 @@ NMManager * nm_manager_new (NMSettings *settings, gboolean initial_net_enabled, gboolean initial_wifi_enabled, gboolean initial_wwan_enabled, - gboolean initial_wimax_enabled, - GError **error); + gboolean initial_wimax_enabled); NMManager * nm_manager_get (void); From b7911bae516a5b4cbacd20886e33b4a63597d1e4 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Fri, 31 Jul 2015 13:00:22 -0400 Subject: [PATCH 02/14] core: better order the code at startup NM was calling nm_bus_manager_start_service() to claim its bus name before it exported any of its objects, but this didn't matter under dbus-glib, because no client connections would be accepted until the main loop was started later on, by which point we would have exported everything. But with gdbus, method calls are initially received in the gdbus worker thread, which means that clients would be able to connect right away and then be told that the expected interfaces don't exist. So move the nm_bus_manager_start_service() call to occur after creating NMSettings and NMManager (and, indirectly, NMAgentManager). This requires splitting out the slow parts of nm_settings_new() into a new nm_settings_start(), so that we can create and export it first, and then read the connections, etc afterward. (Likewise, there were still a few potentially-slow bits in nm_manager_new() which are now moved into nm_manager_start().) --- src/main.c | 25 ++++++++++++------------- src/nm-manager.c | 18 +++++++++--------- src/settings/nm-settings.c | 30 +++++++++++++++++++++++------- src/settings/nm-settings.h | 3 ++- 4 files changed, 46 insertions(+), 30 deletions(-) diff --git a/src/main.c b/src/main.c index 3ea05bebf8..3ba6518d2a 100644 --- a/src/main.c +++ b/src/main.c @@ -419,6 +419,16 @@ main (int argc, char *argv[]) #endif ); + nm_auth_manager_setup (nm_config_get_auth_polkit (config)); + + settings = nm_settings_new (); + manager = nm_manager_new (settings, + global_opt.state_file, + net_enabled, + wifi_enabled, + wwan_enabled, + wimax_enabled); + if (!nm_bus_manager_get_connection (nm_bus_manager_get ())) { #if HAVE_DBUS_GLIB_100 nm_log_warn (LOGD_CORE, "Failed to connect to D-Bus; only private bus is available"); @@ -443,24 +453,13 @@ main (int argc, char *argv[]) * NMPlatform. */ g_object_ref (NM_PLATFORM_GET); - nm_auth_manager_setup (nm_config_get_auth_polkit (config)); - nm_dispatcher_init (); - settings = nm_settings_new (&error); - if (!settings) { - nm_log_err (LOGD_CORE, "failed to initialize settings storage: %s", - error && error->message ? error->message : "(unknown)"); + if (!nm_settings_start (settings, &error)) { + nm_log_err (LOGD_CORE, "failed to initialize settings storage: %s", error->message); goto done; } - manager = nm_manager_new (settings, - global_opt.state_file, - net_enabled, - wifi_enabled, - wwan_enabled, - wimax_enabled); - g_signal_connect (manager, NM_MANAGER_CONFIGURE_QUIT, G_CALLBACK (manager_configure_quit), config); nm_manager_start (manager); diff --git a/src/nm-manager.c b/src/nm-manager.c index 3bda450930..3c5969aa40 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -4198,6 +4198,11 @@ nm_manager_start (NMManager *self) NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); guint i; + g_signal_connect (nm_platform_get (), + NM_PLATFORM_SIGNAL_LINK_CHANGED, + G_CALLBACK (platform_link_cb), + self); + /* Set initial radio enabled/disabled state */ for (i = 0; i < RFKILL_TYPE_MAX; i++) { RadioState *rstate = &priv->radio_states[i]; @@ -4227,10 +4232,14 @@ nm_manager_start (NMManager *self) system_hostname_changed_cb (priv->settings, NULL, self); /* Start device factories */ + nm_device_factory_manager_load_factories (_register_device_factory, self); nm_device_factory_manager_for_each_factory (start_factory, NULL); platform_query_devices (self); + /* Load VPN plugins */ + priv->vpn_manager = g_object_ref (nm_vpn_manager_get ()); + /* * Connections added before the manager is started do not emit * connection-added signals thus devices have to be created manually. @@ -4831,11 +4840,6 @@ nm_manager_new (NMSettings *settings, nm_exported_object_export (NM_EXPORTED_OBJECT (singleton)); - g_signal_connect (nm_platform_get (), - NM_PLATFORM_SIGNAL_LINK_CHANGED, - G_CALLBACK (platform_link_cb), - singleton); - priv->rfkill_mgr = nm_rfkill_manager_new (); g_signal_connect (priv->rfkill_mgr, "rfkill-changed", @@ -4850,8 +4854,6 @@ nm_manager_new (NMSettings *settings, rfkill_change (priv->radio_states[RFKILL_TYPE_WLAN].desc, RFKILL_TYPE_WLAN, initial_wifi_enabled); rfkill_change (priv->radio_states[RFKILL_TYPE_WWAN].desc, RFKILL_TYPE_WWAN, initial_wwan_enabled); - nm_device_factory_manager_load_factories (_register_device_factory, singleton); - return singleton; } @@ -4899,8 +4901,6 @@ nm_manager_init (NMManager *manager) G_CALLBACK (dbus_connection_changed_cb), manager); - priv->vpn_manager = g_object_ref (nm_vpn_manager_get ()); - /* sleep/wake handling */ priv->sleep_monitor = g_object_ref (nm_sleep_monitor_get ()); g_signal_connect (priv->sleep_monitor, NM_SLEEP_MONITOR_SLEEPING, diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c index d7b76c9cf6..0988e1cc0e 100644 --- a/src/settings/nm-settings.c +++ b/src/settings/nm-settings.c @@ -176,6 +176,7 @@ typedef struct { GSList *unrecognized_specs; GSList *get_connections_cache; + gboolean started; gboolean startup_complete; struct { @@ -561,6 +562,9 @@ nm_settings_get_hostname (NMSettings *self) NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); char *hostname = NULL; + if (!priv->started) + return NULL; + if (priv->hostname.hostnamed_proxy) { hostname = g_strdup (priv->hostname.value); goto out; @@ -2094,13 +2098,10 @@ setup_hostname_file_monitors (NMSettings *self) } NMSettings * -nm_settings_new (GError **error) +nm_settings_new (void) { NMSettings *self; NMSettingsPrivate *priv; - GDBusProxy *proxy; - GVariant *variant; - GError *local_error = NULL; self = g_object_new (NM_TYPE_SETTINGS, NULL); @@ -2109,10 +2110,24 @@ nm_settings_new (GError **error) priv->config = nm_config_get (); priv->dbus_mgr = nm_bus_manager_get (); + nm_exported_object_export (NM_EXPORTED_OBJECT (self)); + return self; +} + +gboolean +nm_settings_start (NMSettings *self, GError **error) +{ + NMSettingsPrivate *priv; + GDBusProxy *proxy; + GVariant *variant; + GError *local_error = NULL; + + priv = NM_SETTINGS_GET_PRIVATE (self); + /* Load the plugins; fail if a plugin is not found. */ if (!load_plugins (self, nm_config_get_plugins (priv->config), error)) { g_object_unref (self); - return NULL; + return FALSE; } load_connections (self); @@ -2143,8 +2158,9 @@ nm_settings_new (GError **error) if (!priv->hostname.hostnamed_proxy) setup_hostname_file_monitors (self); - nm_exported_object_export (NM_EXPORTED_OBJECT (self)); - return self; + priv->started = TRUE; + g_object_notify (G_OBJECT (self), NM_SETTINGS_HOSTNAME); + return TRUE; } static void diff --git a/src/settings/nm-settings.h b/src/settings/nm-settings.h index 4afa4dc250..8e2d328952 100644 --- a/src/settings/nm-settings.h +++ b/src/settings/nm-settings.h @@ -73,7 +73,8 @@ typedef struct { GType nm_settings_get_type (void); -NMSettings *nm_settings_new (GError **error); +NMSettings *nm_settings_new (void); +gboolean nm_settings_start (NMSettings *self, GError **error); typedef void (*NMSettingsForEachFunc) (NMSettings *settings, NMSettingsConnection *connection, From 284e15a8775e487e094be7e327582d45a903af99 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Mon, 3 Aug 2015 09:26:31 -0400 Subject: [PATCH 03/14] core: make NMManager singleton more like others Rename nm_manager_new() to nm_manager_setup(), and change the local @singleton variable to @singleton_instance. (Also, add a local @self variable inside nm_manager_setup().) Also, make NMManager own NMSettings rather than having them both owned by main(). --- src/main.c | 23 +++++------- src/nm-manager.c | 98 ++++++++++++++++++++++++------------------------ src/nm-manager.h | 8 ++-- 3 files changed, 63 insertions(+), 66 deletions(-) diff --git a/src/main.c b/src/main.c index 3ba6518d2a..4f83f849ba 100644 --- a/src/main.c +++ b/src/main.c @@ -261,7 +261,6 @@ main (int argc, char *argv[]) gboolean wifi_enabled = TRUE, net_enabled = TRUE, wwan_enabled = TRUE, wimax_enabled = TRUE; gboolean success = FALSE; NMManager *manager = NULL; - gs_unref_object NMSettings *settings = NULL; NMConfig *config; GError *error = NULL; gboolean wrote_pidfile = FALSE; @@ -421,13 +420,11 @@ main (int argc, char *argv[]) nm_auth_manager_setup (nm_config_get_auth_polkit (config)); - settings = nm_settings_new (); - manager = nm_manager_new (settings, - global_opt.state_file, - net_enabled, - wifi_enabled, - wwan_enabled, - wimax_enabled); + manager = nm_manager_setup (global_opt.state_file, + net_enabled, + wifi_enabled, + wwan_enabled, + wimax_enabled); if (!nm_bus_manager_get_connection (nm_bus_manager_get ())) { #if HAVE_DBUS_GLIB_100 @@ -455,14 +452,12 @@ main (int argc, char *argv[]) nm_dispatcher_init (); - if (!nm_settings_start (settings, &error)) { - nm_log_err (LOGD_CORE, "failed to initialize settings storage: %s", error->message); - goto done; - } - g_signal_connect (manager, NM_MANAGER_CONFIGURE_QUIT, G_CALLBACK (manager_configure_quit), config); - nm_manager_start (manager); + if (!nm_manager_start (manager, &error)) { + nm_log_err (LOGD_CORE, "failed to initialize: %s", error->message); + goto done; + } /* Make sure the loopback interface is up. If interface is down, we bring * it up and kernel will assign it link-local IPv4 and IPv6 addresses. If diff --git a/src/nm-manager.c b/src/nm-manager.c index 3c5969aa40..7301f64c77 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -4192,12 +4192,15 @@ start_factory (NMDeviceFactory *factory, gpointer user_data) nm_device_factory_start (factory); } -void -nm_manager_start (NMManager *self) +gboolean +nm_manager_start (NMManager *self, GError **error) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); guint i; + if (!nm_settings_start (priv->settings, error)) + return FALSE; + g_signal_connect (nm_platform_get (), NM_PLATFORM_SIGNAL_LINK_CHANGED, G_CALLBACK (platform_link_cb), @@ -4247,6 +4250,8 @@ nm_manager_start (NMManager *self) system_create_virtual_devices (self); check_if_startup_complete (self); + + return TRUE; } void @@ -4743,79 +4748,89 @@ dbus_connection_changed_cb (NMBusManager *dbus_mgr, /**********************************************************************/ -static NMManager *singleton = NULL; +static NMManager *singleton_instance = NULL; NMManager * nm_manager_get (void) { - g_assert (singleton); - return singleton; + g_assert (singleton_instance); + return singleton_instance; } NMConnectionProvider * nm_connection_provider_get (void) { - g_assert (singleton); - g_assert (NM_MANAGER_GET_PRIVATE (singleton)->settings); - return NM_CONNECTION_PROVIDER (NM_MANAGER_GET_PRIVATE (singleton)->settings); + g_assert (singleton_instance); + g_assert (NM_MANAGER_GET_PRIVATE (singleton_instance)->settings); + return NM_CONNECTION_PROVIDER (NM_MANAGER_GET_PRIVATE (singleton_instance)->settings); } NMManager * -nm_manager_new (NMSettings *settings, - const char *state_file, - gboolean initial_net_enabled, - gboolean initial_wifi_enabled, - gboolean initial_wwan_enabled, - gboolean initial_wimax_enabled) +nm_manager_setup (const char *state_file, + gboolean initial_net_enabled, + gboolean initial_wifi_enabled, + gboolean initial_wwan_enabled, + gboolean initial_wimax_enabled) { + NMManager *self; NMManagerPrivate *priv; DBusConnection *dbus_connection; NMConfigData *config_data; - g_assert (settings); - /* Can only be called once */ - g_assert (singleton == NULL); - singleton = (NMManager *) g_object_new (NM_TYPE_MANAGER, NULL); - g_assert (singleton); + g_assert (singleton_instance == NULL); + singleton_instance = self = (NMManager *) g_object_new (NM_TYPE_MANAGER, NULL); + g_assert (singleton_instance); - priv = NM_MANAGER_GET_PRIVATE (singleton); + priv = NM_MANAGER_GET_PRIVATE (self); dbus_connection = nm_bus_manager_get_dbus_connection (priv->dbus_mgr); if (dbus_connection) { gboolean success; /* Only fails on ENOMEM */ - success = dbus_connection_add_filter (dbus_connection, prop_filter, singleton, NULL); + success = dbus_connection_add_filter (dbus_connection, prop_filter, self, NULL); g_assert (success); } - priv->policy = nm_policy_new (singleton, settings); + priv->settings = nm_settings_new (); + g_signal_connect (priv->settings, "notify::" NM_SETTINGS_STARTUP_COMPLETE, + G_CALLBACK (settings_startup_complete_changed), self); + g_signal_connect (priv->settings, "notify::" NM_SETTINGS_UNMANAGED_SPECS, + G_CALLBACK (system_unmanaged_devices_changed_cb), self); + g_signal_connect (priv->settings, "notify::" NM_SETTINGS_HOSTNAME, + G_CALLBACK (system_hostname_changed_cb), self); + g_signal_connect (priv->settings, NM_SETTINGS_SIGNAL_CONNECTION_ADDED, + G_CALLBACK (connection_added), self); + g_signal_connect (priv->settings, NM_SETTINGS_SIGNAL_CONNECTION_UPDATED, + G_CALLBACK (connection_changed), self); + g_signal_connect (priv->settings, NM_SETTINGS_SIGNAL_CONNECTION_REMOVED, + G_CALLBACK (connection_removed), self); + g_signal_connect (priv->settings, NM_SETTINGS_SIGNAL_CONNECTION_VISIBILITY_CHANGED, + G_CALLBACK (connection_changed), self); + + priv->policy = nm_policy_new (self, priv->settings); g_signal_connect (priv->policy, "notify::" NM_POLICY_DEFAULT_IP4_DEVICE, - G_CALLBACK (policy_default_device_changed), singleton); + G_CALLBACK (policy_default_device_changed), self); g_signal_connect (priv->policy, "notify::" NM_POLICY_DEFAULT_IP6_DEVICE, - G_CALLBACK (policy_default_device_changed), singleton); + G_CALLBACK (policy_default_device_changed), self); g_signal_connect (priv->policy, "notify::" NM_POLICY_ACTIVATING_IP4_DEVICE, - G_CALLBACK (policy_activating_device_changed), singleton); + G_CALLBACK (policy_activating_device_changed), self); g_signal_connect (priv->policy, "notify::" NM_POLICY_ACTIVATING_IP6_DEVICE, - G_CALLBACK (policy_activating_device_changed), singleton); + G_CALLBACK (policy_activating_device_changed), self); priv->config = g_object_ref (nm_config_get ()); g_signal_connect (G_OBJECT (priv->config), NM_CONFIG_SIGNAL_CONFIG_CHANGED, G_CALLBACK (_config_changed_cb), - singleton); + self); config_data = nm_config_get_data (priv->config); priv->connectivity = nm_connectivity_new (nm_config_data_get_connectivity_uri (config_data), nm_config_data_get_connectivity_interval (config_data), nm_config_data_get_connectivity_response (config_data)); g_signal_connect (priv->connectivity, "notify::" NM_CONNECTIVITY_STATE, - G_CALLBACK (connectivity_changed), singleton); - - priv->settings = g_object_ref (settings); - g_signal_connect (priv->settings, "notify::" NM_SETTINGS_STARTUP_COMPLETE, - G_CALLBACK (settings_startup_complete_changed), singleton); + G_CALLBACK (connectivity_changed), self); priv->state_file = g_strdup (state_file); @@ -4825,26 +4840,13 @@ nm_manager_new (NMSettings *settings, priv->radio_states[RFKILL_TYPE_WWAN].user_enabled = initial_wwan_enabled; priv->radio_states[RFKILL_TYPE_WIMAX].user_enabled = initial_wimax_enabled; - g_signal_connect (priv->settings, "notify::" NM_SETTINGS_UNMANAGED_SPECS, - G_CALLBACK (system_unmanaged_devices_changed_cb), singleton); - g_signal_connect (priv->settings, "notify::" NM_SETTINGS_HOSTNAME, - G_CALLBACK (system_hostname_changed_cb), singleton); - g_signal_connect (priv->settings, NM_SETTINGS_SIGNAL_CONNECTION_ADDED, - G_CALLBACK (connection_added), singleton); - g_signal_connect (priv->settings, NM_SETTINGS_SIGNAL_CONNECTION_UPDATED, - G_CALLBACK (connection_changed), singleton); - g_signal_connect (priv->settings, NM_SETTINGS_SIGNAL_CONNECTION_REMOVED, - G_CALLBACK (connection_removed), singleton); - g_signal_connect (priv->settings, NM_SETTINGS_SIGNAL_CONNECTION_VISIBILITY_CHANGED, - G_CALLBACK (connection_changed), singleton); - - nm_exported_object_export (NM_EXPORTED_OBJECT (singleton)); + nm_exported_object_export (NM_EXPORTED_OBJECT (self)); priv->rfkill_mgr = nm_rfkill_manager_new (); g_signal_connect (priv->rfkill_mgr, "rfkill-changed", G_CALLBACK (rfkill_manager_rfkill_changed_cb), - singleton); + self); /* Force kernel WiFi/WWAN rfkill state to follow NM saved WiFi/WWAN state * in case the BIOS doesn't save rfkill state, and to be consistent with user @@ -4854,7 +4856,7 @@ nm_manager_new (NMSettings *settings, rfkill_change (priv->radio_states[RFKILL_TYPE_WLAN].desc, RFKILL_TYPE_WLAN, initial_wifi_enabled); rfkill_change (priv->radio_states[RFKILL_TYPE_WWAN].desc, RFKILL_TYPE_WWAN, initial_wwan_enabled); - return singleton; + return self; } static void diff --git a/src/nm-manager.h b/src/nm-manager.h index 723f4822d0..f14e65ff3c 100644 --- a/src/nm-manager.h +++ b/src/nm-manager.h @@ -75,9 +75,8 @@ typedef struct { GType nm_manager_get_type (void); -/* nm_manager_new() should only be used by main.c */ -NMManager * nm_manager_new (NMSettings *settings, - const char *state_file, +/* nm_manager_setup() should only be used by main.c */ +NMManager * nm_manager_setup (const char *state_file, gboolean initial_net_enabled, gboolean initial_wifi_enabled, gboolean initial_wwan_enabled, @@ -85,7 +84,8 @@ NMManager * nm_manager_new (NMSettings *settings, NMManager * nm_manager_get (void); -void nm_manager_start (NMManager *manager); +gboolean nm_manager_start (NMManager *manager, + GError **error); void nm_manager_stop (NMManager *manager); NMState nm_manager_get_state (NMManager *manager); const GSList *nm_manager_get_active_connections (NMManager *manager); From 073991f5a8271a1e7367ec330fc7c8cf54522ffb Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Wed, 15 Apr 2015 14:53:30 -0400 Subject: [PATCH 04/14] core: port NMExportedObject to gdbus Port NMExportedObject to gdbus, and make nm_exported_object_class_add_interface() deal with generating D-Bus skeleton objects and attaching signal handlers and property bindings as needed to properly handle methods, signals, and properties. --- src/nm-exported-object.c | 535 ++++++++++++++++++++++++++++++--------- src/nm-exported-object.h | 6 +- 2 files changed, 422 insertions(+), 119 deletions(-) diff --git a/src/nm-exported-object.c b/src/nm-exported-object.c index 9ad734d8af..83aecaca27 100644 --- a/src/nm-exported-object.c +++ b/src/nm-exported-object.c @@ -20,10 +20,10 @@ #include "config.h" +#include #include #include "nm-exported-object.h" -#include "nm-dbus-glib-types.h" #include "nm-bus-manager.h" #include "nm-default.h" @@ -34,85 +34,374 @@ G_DEFINE_ABSTRACT_TYPE_WITH_CODE (NMExportedObject, nm_exported_object, G_TYPE_O ) typedef struct { + GSList *interfaces; + char *path; - GHashTable *pending_notifies; + GVariantBuilder pending_notifies; guint notify_idle_id; } NMExportedObjectPrivate; #define NM_EXPORTED_OBJECT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_EXPORTED_OBJECT, NMExportedObjectPrivate)) -enum { - PROPERTIES_CHANGED, - - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; +typedef struct { + GType dbus_skeleton_type; + char *method_name; + GCallback impl; +} NMExportedObjectDBusMethodImpl; typedef struct { GHashTable *properties; + GSList *skeleton_types; + GArray *methods; } NMExportedObjectClassInfo; GQuark nm_exported_object_class_info_quark (void); G_DEFINE_QUARK (NMExportedObjectClassInfo, nm_exported_object_class_info) +/* "AddConnectionUnsaved" -> "handle-add-connection-unsaved" */ +static char * +skeletonify_method_name (const char *dbus_method_name) +{ + GString *out; + const char *p; + + out = g_string_new ("handle"); + for (p = dbus_method_name; *p; p++) { + if (g_ascii_isupper (*p) || p == dbus_method_name) { + g_string_append_c (out, '-'); + g_string_append_c (out, g_ascii_tolower (*p)); + } else + g_string_append_c (out, *p); + } + + return g_string_free (out, FALSE); +} + +/* "can-modify" -> "CanModify" */ +static char * +dbusify_name (const char *gobject_name) +{ + GString *out; + const char *p; + gboolean capitalize = TRUE; + + out = g_string_new (""); + for (p = gobject_name; *p; p++) { + if (capitalize) { + g_string_append_c (out, g_ascii_toupper (*p)); + capitalize = FALSE; + } else if (*p == '-') + capitalize = TRUE; + else + g_string_append_c (out, *p); + } + + return g_string_free (out, FALSE); +} + +/* "can_modify" -> "can-modify". Returns %NULL if @gobject_name contains no underscores */ +static char * +hyphenify_name (const char *gobject_name) +{ + char *hyphen_name, *p; + + if (!strchr (gobject_name, '_')) + return NULL; + + hyphen_name = g_strdup (gobject_name); + for (p = hyphen_name; *p; p++) { + if (*p == '_') + *p = '-'; + } + return hyphen_name; +} + +/* Called when an #NMExportedObject emits a signal that corresponds to a D-Bus + * signal, and re-emits that signal on the correct skeleton object as well. + */ +static gboolean +nm_exported_object_signal_hook (GSignalInvocationHint *ihint, + guint n_param_values, + const GValue *param_values, + gpointer data) +{ + NMExportedObject *self = g_value_get_object (¶m_values[0]); + NMExportedObjectPrivate *priv; + GSignalQuery *signal_info = data; + GDBusObjectSkeleton *interface = NULL; + GSList *iter; + GValue *dbus_param_values; + int i; + + priv = NM_EXPORTED_OBJECT_GET_PRIVATE (self); + if (!priv->path) + return TRUE; + + for (iter = priv->interfaces; iter; iter = iter->next) { + if (g_type_is_a (G_OBJECT_TYPE (iter->data), signal_info->itype)) { + interface = iter->data; + break; + } + } + g_return_val_if_fail (interface != NULL, TRUE); + + dbus_param_values = g_new0 (GValue, n_param_values); + g_value_init (&dbus_param_values[0], G_OBJECT_TYPE (interface)); + g_value_set_object (&dbus_param_values[0], interface); + for (i = 1; i < n_param_values; i++) { + if (g_type_is_a (param_values[i].g_type, NM_TYPE_EXPORTED_OBJECT)) { + NMExportedObject *arg = g_value_get_object (¶m_values[i]); + + g_value_init (&dbus_param_values[i], G_TYPE_STRING); + if (arg && nm_exported_object_is_exported (arg)) + g_value_set_string (&dbus_param_values[i], nm_exported_object_get_path (arg)); + else + g_value_set_string (&dbus_param_values[i], "/"); + } else { + g_value_init (&dbus_param_values[i], param_values[i].g_type); + g_value_copy (¶m_values[i], &dbus_param_values[i]); + } + } + + g_signal_emitv (dbus_param_values, signal_info->signal_id, 0, NULL); + + for (i = 0; i < n_param_values; i++) + g_value_unset (&dbus_param_values[i]); + g_free (dbus_param_values); + + return TRUE; +} + /** * nm_exported_object_class_add_interface: * @object_class: an #NMExportedObjectClass - * @info: generated #DBusGObjectInfo for the class + * @dbus_skeleton_type: the type of the #GDBusObjectSkeleton to add + * @...: method name / handler pairs, %NULL-terminated * - * Adds @info to the list of D-Bus interfaces implemented by @object_class and - * sets up automatic dbus-glib handling for instances of that class. + * Adds @dbus_skeleton_type to the list of D-Bus interfaces implemented by + * @object_class. Instances of @object_class will automatically have a skeleton + * of that type created, which will be exported when you call + * nm_exported_object_export(). * - * If @info includes any properties, then a "PropertiesChanged" signal will - * be emitted on @info's interface whenever any of those properties change on - * an exported instance of @object_class. + * The skeleton's properties will be initialized from the #NMExportedObject's, + * and bidirectional bindings will be set up between them. When exported + * properties change, both the org.freedesktop.DBus.Properties.PropertiesChanged + * signal and the traditional NetworkManager PropertiesChanged signal will be + * emitted. + * + * When a signal is emitted on an #NMExportedObject that has the same name as a + * signal on @dbus_skeleton_type, it will automatically be emitted on the + * skeleton as well; #NMExportedObject arguments in the signal will be converted + * to D-Bus object paths in the skeleton signal. + * + * The arguments after @dbus_skeleton_type are pairs of D-Bus method names (in + * CamelCase), and the corresponding handlers for them (which must have the same + * prototype as the corresponding "handle-..." signal on @dbus_skeleton_type, + * except with no return value, and with the first argument being an object of + * @object_class's type, not of @dbus_skeleton_type). + * + * It is a programmer error if: + * - @object_class does not define a property of the same name and type as + * each of @dbus_skeleton_type's properties. + * - @object_class does not define a signal with the same name and arguments + * as each of @dbus_skeleton_type's signals. + * - the list of method names includes any names that do not correspond to + * "handle-" signals on @dbus_skeleton_type. + * - the list of method names does not include every method defined by + * @dbus_skeleton_type. */ void nm_exported_object_class_add_interface (NMExportedObjectClass *object_class, - const DBusGObjectInfo *info) + GType dbus_skeleton_type, + ...) { - GType object_type = G_TYPE_FROM_CLASS (object_class); NMExportedObjectClassInfo *classinfo; - const char *properties_info, *dbus_name, *gobject_name, *tmp_access; - char *hyphen_name, *p; + NMExportedObjectDBusMethodImpl method; + va_list ap; + const char *method_name; + GCallback impl; + GType *interfaces; + guint n_interfaces; + guint *dbus_signals, n_signals, n_method_signals; + guint object_signal_id; + GSignalQuery query; + int i, s; + GObjectClass *dbus_object_class; + GParamSpec **dbus_properties, *object_property; + guint n_dbus_properties; - dbus_g_object_type_install_info (object_type, info); - if (!info->exported_properties) - return; + g_return_if_fail (NM_IS_EXPORTED_OBJECT_CLASS (object_class)); + g_return_if_fail (g_type_is_a (dbus_skeleton_type, G_TYPE_DBUS_INTERFACE_SKELETON)); - classinfo = g_type_get_qdata (object_type, nm_exported_object_class_info_quark ()); - if (!classinfo) { - classinfo = g_slice_new (NMExportedObjectClassInfo); - classinfo->properties = g_hash_table_new (g_str_hash, g_str_equal); - g_type_set_qdata (object_type, nm_exported_object_class_info_quark (), classinfo); + classinfo = g_slice_new (NMExportedObjectClassInfo); + classinfo->skeleton_types = NULL; + classinfo->methods = g_array_new (FALSE, FALSE, sizeof (NMExportedObjectDBusMethodImpl)); + classinfo->properties = g_hash_table_new (g_str_hash, g_str_equal); + g_type_set_qdata (G_TYPE_FROM_CLASS (object_class), + nm_exported_object_class_info_quark (), classinfo); + + classinfo->skeleton_types = g_slist_prepend (classinfo->skeleton_types, + GSIZE_TO_POINTER (dbus_skeleton_type)); + + /* Ensure @dbus_skeleton_type's class_init has run, so its signals/properties + * will be defined. + */ + dbus_object_class = g_type_class_ref (dbus_skeleton_type); + + /* Add method implementations from the varargs */ + va_start (ap, dbus_skeleton_type); + while ((method_name = va_arg (ap, const char *)) && (impl = va_arg (ap, GCallback))) { + method.dbus_skeleton_type = dbus_skeleton_type; + method.method_name = skeletonify_method_name (method_name); + g_assert (g_signal_lookup (method.method_name, dbus_skeleton_type) != 0); + method.impl = impl; + + g_array_append_val (classinfo->methods, method); } + va_end (ap); - properties_info = info->exported_properties; - while (*properties_info) { - /* The format is: "interface\0DBusPropertyName\0gobject_property_name\0access\0" */ - dbus_name = strchr (properties_info, '\0') + 1; - gobject_name = strchr (dbus_name, '\0') + 1; - tmp_access = strchr (gobject_name, '\0') + 1; - properties_info = strchr (tmp_access, '\0') + 1; + /* Properties */ + dbus_properties = g_object_class_list_properties (dbus_object_class, &n_dbus_properties); + for (i = 0; i < n_dbus_properties; i++) { + char *hyphen_name; - if (strchr (gobject_name, '_')) { - hyphen_name = g_strdup (gobject_name); - for (p = hyphen_name; *p; p++) { - if (*p == '_') - *p = '-'; - } + if (g_str_has_prefix (dbus_properties[i]->name, "g-")) + continue; + + object_property = g_object_class_find_property (G_OBJECT_CLASS (object_class), + dbus_properties[i]->name); + g_assert (object_property != NULL); + g_assert (object_property->value_type == dbus_properties[i]->value_type); + + g_assert (!g_hash_table_contains (classinfo->properties, dbus_properties[i]->name)); + g_hash_table_insert (classinfo->properties, + g_strdup (dbus_properties[i]->name), + dbusify_name (dbus_properties[i]->name)); + hyphen_name = hyphenify_name (dbus_properties[i]->name); + if (hyphen_name) { g_assert (!g_hash_table_contains (classinfo->properties, hyphen_name)); g_hash_table_insert (classinfo->properties, - (char *) g_intern_string (hyphen_name), - (char *) dbus_name); - g_free (hyphen_name); - } else { - g_assert (!g_hash_table_contains (classinfo->properties, (char *) gobject_name)); - g_hash_table_insert (classinfo->properties, - (char *) gobject_name, - (char *) dbus_name); + hyphen_name, + dbusify_name (dbus_properties[i]->name)); + } + } + + /* Signals. Unlike g_object_class_list_properties(), g_signal_list_ids() is + * "shallow", so we need to query each implemented gdbus-generated interface + * separately. + */ + interfaces = g_type_interfaces (dbus_skeleton_type, &n_interfaces); + n_method_signals = 0; + for (i = 0; i < n_interfaces; i++) { + dbus_signals = g_signal_list_ids (interfaces[i], &n_signals); + for (s = 0; s < n_signals; s++) { + g_signal_query (dbus_signals[s], &query); + + /* PropertiesChanged is handled specially */ + if (!strcmp (query.signal_name, "properties-changed")) + continue; + + if (g_str_has_prefix (query.signal_name, "handle-")) { + n_method_signals++; + continue; + } + + object_signal_id = g_signal_lookup (query.signal_name, G_TYPE_FROM_CLASS (object_class)); + g_assert (object_signal_id != 0); + + g_signal_add_emission_hook (object_signal_id, 0, + nm_exported_object_signal_hook, + g_memdup (&query, sizeof (query)), + g_free); + } + } + + g_assert_cmpint (n_method_signals, ==, classinfo->methods->len); + + g_type_class_unref (dbus_object_class); +} + +/* "meta-marshaller" that receives the skeleton "handle-foo" signal, replaces + * the skeleton object with an #NMExportedObject in the parameters, drops the + * user_data parameter, and adds a "TRUE" return value (indicating to gdbus that + * the signal was handled). + */ +static void +nm_exported_object_meta_marshal (GClosure *closure, GValue *return_value, + guint n_param_values, const GValue *param_values, + gpointer invocation_hint, gpointer marshal_data) +{ + GValue *local_param_values; + + local_param_values = g_new0 (GValue, n_param_values); + g_value_init (&local_param_values[0], G_TYPE_POINTER); + g_value_set_pointer (&local_param_values[0], closure->data); + memcpy (local_param_values + 1, param_values + 1, (n_param_values - 1) * sizeof (GValue)); + + g_cclosure_marshal_generic (closure, NULL, + n_param_values, local_param_values, + invocation_hint, + ((GCClosure *)closure)->callback); + g_value_set_boolean (return_value, TRUE); + + g_value_unset (&local_param_values[0]); + g_free (local_param_values); +} + +static void +nm_exported_object_create_skeletons (NMExportedObject *self, + GType object_type) +{ + NMExportedObjectPrivate *priv = NM_EXPORTED_OBJECT_GET_PRIVATE (self); + GObjectClass *object_class = g_type_class_peek (object_type); + NMExportedObjectClassInfo *classinfo; + GSList *iter; + GDBusObjectSkeleton *interface; + GParamSpec **properties; + guint n_properties; + int i; + + classinfo = g_type_get_qdata (object_type, nm_exported_object_class_info_quark ()); + if (!classinfo) + return; + + for (iter = classinfo->skeleton_types; iter; iter = iter->next) { + GType dbus_skeleton_type = GPOINTER_TO_SIZE (iter->data); + + interface = g_object_new (dbus_skeleton_type, NULL); + priv->interfaces = g_slist_prepend (priv->interfaces, interface); + + /* Bind properties */ + properties = g_object_class_list_properties (G_OBJECT_GET_CLASS (interface), &n_properties); + for (i = 0; i < n_properties; i++) { + GParamSpec *nm_property; + GBindingFlags flags; + + nm_property = g_object_class_find_property (object_class, properties[i]->name); + if (!nm_property) + continue; + + flags = G_BINDING_SYNC_CREATE; + if ( (nm_property->flags & G_PARAM_WRITABLE) + && !(nm_property->flags & G_PARAM_CONSTRUCT_ONLY)) + flags |= G_BINDING_BIDIRECTIONAL; + g_object_bind_property (self, properties[i]->name, + interface, properties[i]->name, + flags); + } + + /* Bind methods */ + for (i = 0; i < classinfo->methods->len; i++) { + NMExportedObjectDBusMethodImpl *method = &g_array_index (classinfo->methods, NMExportedObjectDBusMethodImpl, i); + GClosure *closure; + + if (method->dbus_skeleton_type != dbus_skeleton_type) + continue; + + closure = g_cclosure_new_swap (method->impl, self, NULL); + g_closure_set_meta_marshal (closure, NULL, nm_exported_object_meta_marshal); + g_signal_connect_closure (interface, method->method_name, closure, FALSE); } } } @@ -135,7 +424,10 @@ const char * nm_exported_object_export (NMExportedObject *self) { NMExportedObjectPrivate *priv; + NMBusManager *dbus_manager = nm_bus_manager_get (); const char *class_export_path, *p; + GSList *iter; + GType type; g_return_val_if_fail (NM_IS_EXPORTED_OBJECT (self), NULL); priv = NM_EXPORTED_OBJECT_GET_PRIVATE (self); @@ -160,7 +452,14 @@ nm_exported_object_export (NMExportedObject *self) } else priv->path = g_strdup (class_export_path); - nm_bus_manager_register_object (nm_bus_manager_get (), priv->path, self); + type = G_OBJECT_TYPE (self); + while (type != NM_TYPE_EXPORTED_OBJECT) { + nm_exported_object_create_skeletons (self, type); + type = g_type_parent (type); + } + + for (iter = priv->interfaces; iter; iter = iter->next) + nm_bus_manager_register_object (dbus_manager, priv->path, iter->data); return priv->path; } @@ -208,6 +507,7 @@ void nm_exported_object_unexport (NMExportedObject *self) { NMExportedObjectPrivate *priv; + GSList *iter; g_return_if_fail (NM_IS_EXPORTED_OBJECT (self)); priv = NM_EXPORTED_OBJECT_GET_PRIVATE (self); @@ -215,16 +515,11 @@ nm_exported_object_unexport (NMExportedObject *self) g_return_if_fail (priv->path != NULL); g_clear_pointer (&priv->path, g_free); - nm_bus_manager_unregister_object (nm_bus_manager_get (), self); -} -static void -destroy_value (gpointer data) -{ - GValue *val = (GValue *) data; - - g_value_unset (val); - g_slice_free (GValue, val); + for (iter = priv->interfaces; iter; iter = iter->next) + nm_bus_manager_unregister_object (nm_bus_manager_get (), iter->data); + g_slist_free_full (priv->interfaces, g_object_unref); + priv->interfaces = NULL; } static void @@ -232,63 +527,77 @@ nm_exported_object_init (NMExportedObject *self) { NMExportedObjectPrivate *priv = NM_EXPORTED_OBJECT_GET_PRIVATE (self); - priv->pending_notifies = g_hash_table_new_full (g_str_hash, g_str_equal, - NULL, destroy_value); -} - -static void -add_to_string (gpointer key, gpointer value, gpointer user_data) -{ - const char *name = (const char *) key; - GString *buf = user_data; - GValue str_val = G_VALUE_INIT; - - g_value_init (&str_val, G_TYPE_STRING); - if (!g_value_transform ((GValue *) value, &str_val)) { - if (G_VALUE_HOLDS_OBJECT (value)) { - GObject *obj = g_value_get_object (value); - - if (obj) { - g_string_append_printf (buf, "{%s: %p (%s)}, ", name, obj, - G_OBJECT_TYPE_NAME (obj)); - } else - g_string_append_printf (buf, "{%s: %p}, ", name, obj); - } else - g_string_append_printf (buf, "{%s: }, ", name); - } else - g_string_append_printf (buf, "{%s: %s}, ", name, g_value_get_string (&str_val)); - g_value_unset (&str_val); + g_variant_builder_init (&priv->pending_notifies, G_VARIANT_TYPE_VARDICT); } static gboolean idle_emit_properties_changed (gpointer self) { NMExportedObjectPrivate *priv = NM_EXPORTED_OBJECT_GET_PRIVATE (self); + GVariant *notifies; + GSList *iter; + GDBusObjectSkeleton *interface = NULL; + guint signal_id = 0; priv->notify_idle_id = 0; + notifies = g_variant_builder_end (&priv->pending_notifies); + g_variant_ref_sink (notifies); + g_variant_builder_init (&priv->pending_notifies, G_VARIANT_TYPE_VARDICT); + + for (iter = priv->interfaces; iter; iter = iter->next) { + signal_id = g_signal_lookup ("properties-changed", G_OBJECT_TYPE (iter->data)); + if (signal_id != 0) { + interface = iter->data; + break; + } + } + g_return_val_if_fail (signal_id != 0, FALSE); if (nm_logging_enabled (LOGL_DEBUG, LOGD_DBUS_PROPS)) { - GString *buf = g_string_new (NULL); + char *notification; - g_hash_table_foreach (priv->pending_notifies, add_to_string, buf); - nm_log_dbg (LOGD_DBUS_PROPS, "%s -> %s", G_OBJECT_TYPE_NAME (self), buf->str); - g_string_free (buf, TRUE); + notification = g_variant_print (notifies, TRUE); + nm_log_dbg (LOGD_DBUS_PROPS, "PropertiesChanged %s %p: %s", + G_OBJECT_TYPE_NAME (self), self, notification); + g_free (notification); } - g_signal_emit (self, signals[PROPERTIES_CHANGED], 0, priv->pending_notifies); - g_hash_table_remove_all (priv->pending_notifies); + g_signal_emit (interface, signal_id, 0, notifies); + g_variant_unref (notifies); return FALSE; } +static const GVariantType * +find_dbus_property_type (GDBusInterfaceSkeleton *skel, + const char *dbus_property_name) +{ + GDBusInterfaceInfo *iinfo; + int i; + + iinfo = g_dbus_interface_skeleton_get_info (skel); + for (i = 0; iinfo->properties[i]; i++) { + if (!strcmp (iinfo->properties[i]->name, dbus_property_name)) + return G_VARIANT_TYPE (iinfo->properties[i]->signature); + } + + return NULL; +} + static void nm_exported_object_notify (GObject *object, GParamSpec *pspec) { NMExportedObjectPrivate *priv = NM_EXPORTED_OBJECT_GET_PRIVATE (object); NMExportedObjectClassInfo *classinfo; - const char *dbus_property_name = NULL; - GValue *value; GType type; + const char *dbus_property_name = NULL; + GValue value = G_VALUE_INIT; + const GVariantType *vtype; + GVariant *variant; + GSList *iter; + + if (!priv->interfaces) + return; for (type = G_OBJECT_TYPE (object); type; type = g_type_parent (type)) { classinfo = g_type_get_qdata (type, nm_exported_object_class_info_quark ()); @@ -305,10 +614,19 @@ nm_exported_object_notify (GObject *object, GParamSpec *pspec) return; } - value = g_slice_new0 (GValue); - g_value_init (value, pspec->value_type); - g_object_get_property (object, pspec->name, value); - g_hash_table_insert (priv->pending_notifies, (char *) dbus_property_name, value); + g_value_init (&value, pspec->value_type); + g_object_get_property (G_OBJECT (object), pspec->name, &value); + + vtype = NULL; + for (iter = priv->interfaces; iter && !vtype; iter = iter->next) + vtype = find_dbus_property_type (iter->data, dbus_property_name); + g_return_if_fail (vtype != NULL); + + variant = g_dbus_gvalue_to_gvariant (&value, vtype); + g_variant_builder_add (&priv->pending_notifies, "{sv}", + dbus_property_name, + variant); + g_value_unset (&value); if (!priv->notify_idle_id) priv->notify_idle_id = g_idle_add (idle_emit_properties_changed, object); @@ -322,22 +640,15 @@ nm_exported_object_dispose (GObject *object) if (priv->path) nm_exported_object_unexport (NM_EXPORTED_OBJECT (object)); - g_hash_table_remove_all (priv->pending_notifies); + g_variant_builder_clear (&priv->pending_notifies); nm_clear_g_source (&priv->notify_idle_id); + g_slist_free_full (priv->interfaces, g_object_unref); + priv->interfaces = NULL; + G_OBJECT_CLASS (nm_exported_object_parent_class)->dispose (object); } -static void -nm_exported_object_finalize (GObject *object) -{ - NMExportedObjectPrivate *priv = NM_EXPORTED_OBJECT_GET_PRIVATE (object); - - g_hash_table_destroy (priv->pending_notifies); - - G_OBJECT_CLASS (nm_exported_object_parent_class)->finalize (object); -} - static void nm_exported_object_class_init (NMExportedObjectClass *klass) { @@ -345,14 +656,6 @@ nm_exported_object_class_init (NMExportedObjectClass *klass) g_type_class_add_private (object_class, sizeof (NMExportedObjectPrivate)); - object_class->notify = nm_exported_object_notify; + object_class->notify = nm_exported_object_notify; object_class->dispose = nm_exported_object_dispose; - object_class->finalize = nm_exported_object_finalize; - - signals[PROPERTIES_CHANGED] = g_signal_new ("properties-changed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - 0, NULL, NULL, NULL, - G_TYPE_NONE, 1, DBUS_TYPE_G_MAP_OF_VARIANT); - } diff --git a/src/nm-exported-object.h b/src/nm-exported-object.h index e0ffd9e06b..64e2a5b7a3 100644 --- a/src/nm-exported-object.h +++ b/src/nm-exported-object.h @@ -21,9 +21,8 @@ #ifndef NM_EXPORTED_OBJECT_H #define NM_EXPORTED_OBJECT_H -#include - #include "nm-default.h" +#include "nm-types.h" G_BEGIN_DECLS @@ -47,7 +46,8 @@ typedef struct { GType nm_exported_object_get_type (void); void nm_exported_object_class_add_interface (NMExportedObjectClass *object_class, - const DBusGObjectInfo *info); + GType dbus_skeleton_type, + ...) G_GNUC_NULL_TERMINATED; const char *nm_exported_object_export (NMExportedObject *self); const char *nm_exported_object_get_path (NMExportedObject *self); From 4b823a86c9d4c0c3ce857042cc37dfb480e69673 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Wed, 15 Apr 2015 14:53:30 -0400 Subject: [PATCH 05/14] core: port NMBusManager to gdbus Also remove some now-unused NMBusManager API --- include/nm-glib.h | 19 ++ src/nm-bus-manager.c | 583 +++++++++++++++++++------------------------ src/nm-bus-manager.h | 46 +--- 3 files changed, 295 insertions(+), 353 deletions(-) diff --git a/include/nm-glib.h b/include/nm-glib.h index b46feb7666..9b57c61331 100644 --- a/include/nm-glib.h +++ b/include/nm-glib.h @@ -258,4 +258,23 @@ _g_key_file_save_to_file (GKeyFile *key_file, #endif +#if GLIB_CHECK_VERSION (2, 36, 0) +#define g_credentials_get_unix_pid(creds, error) \ + G_GNUC_EXTENSION ({ \ + G_GNUC_BEGIN_IGNORE_DEPRECATIONS \ + (g_credentials_get_unix_pid) ((creds), (error)); \ + G_GNUC_END_IGNORE_DEPRECATIONS \ + }) +#else +#define g_credentials_get_unix_pid(creds, error) \ + G_GNUC_EXTENSION ({ \ + struct ucred *native_creds; \ + \ + native_creds = g_credentials_get_native ((creds), G_CREDENTIALS_TYPE_LINUX_UCRED); \ + g_assert (native_creds); \ + native_creds->pid; \ + }) +#endif + + #endif /* __NM_GLIB_H__ */ diff --git a/src/nm-bus-manager.c b/src/nm-bus-manager.c index 4ebc1666c5..584db5e8a6 100644 --- a/src/nm-bus-manager.c +++ b/src/nm-bus-manager.c @@ -29,10 +29,9 @@ #include "nm-default.h" #include "nm-dbus-interface.h" #include "nm-bus-manager.h" +#include "nm-core-internal.h" +#include "nm-dbus-compat.h" -#include -#include -#include #include #include "NetworkManagerUtils.h" @@ -41,7 +40,6 @@ enum { DBUS_CONNECTION_CHANGED = 0, - NAME_OWNER_CHANGED, PRIVATE_CONNECTION_NEW, PRIVATE_CONNECTION_DISCONNECTED, NUMBER_OF_SIGNALS @@ -58,22 +56,21 @@ G_DEFINE_TYPE(NMBusManager, nm_bus_manager, G_TYPE_OBJECT) typedef struct _PrivateServer PrivateServer; typedef struct { - DBusConnection *connection; - DBusGConnection *g_connection; + GDBusConnection *connection; GHashTable *exported; gboolean started; GSList *private_servers; PrivateServer *priv_server; - DBusGProxy *proxy; - guint proxy_destroy_id; + GDBusProxy *proxy; + guint bus_closed_id; guint reconnect_id; } NMBusManagerPrivate; static gboolean nm_bus_manager_init_bus (NMBusManager *self); -static void nm_bus_manager_cleanup (NMBusManager *self, gboolean dispose); +static void nm_bus_manager_cleanup (NMBusManager *self); static void start_reconnection_timeout (NMBusManager *self); static void object_destroyed (NMBusManager *self, gpointer object); @@ -111,82 +108,73 @@ struct _PrivateServer { const char *tag; GQuark detail; char *address; - DBusServer *server; + GDBusServer *server; GHashTable *connections; NMBusManager *manager; }; -static DBusHandlerResult -private_server_message_filter (DBusConnection *conn, - DBusMessage *message, - void *data) +static void +private_server_closed (GDBusConnection *conn, + gboolean remote_peer_vanished, + GError *error, + gpointer user_data) { - PrivateServer *s = data; - int fd; + PrivateServer *s = user_data; /* Clean up after the connection */ - if (dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL, "Disconnected")) { - nm_log_dbg (LOGD_CORE, "(%s) closed connection %p on private socket (fd %d).", - s->tag, conn, dbus_connection_get_unix_fd (conn, &fd) ? fd : -1); + nm_log_dbg (LOGD_CORE, "(%s) closed connection %p on private socket.", + s->tag, conn); - /* Emit this for the manager */ - g_signal_emit (s->manager, - signals[PRIVATE_CONNECTION_DISCONNECTED], - s->detail, - dbus_connection_get_g_connection (conn)); + /* Emit this for the manager */ + g_signal_emit (s->manager, + signals[PRIVATE_CONNECTION_DISCONNECTED], + s->detail, + conn); - g_hash_table_remove (s->connections, conn); - - /* Let dbus-glib process the message too */ - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - } - - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + g_hash_table_remove (s->connections, conn); } -static dbus_bool_t -allow_only_root (DBusConnection *connection, unsigned long uid, void *data) -{ - return uid == 0; -} - -static void -private_server_new_connection (DBusServer *server, - DBusConnection *conn, +static gboolean +private_server_new_connection (GDBusServer *server, + GDBusConnection *conn, gpointer user_data) { PrivateServer *s = user_data; static guint32 counter = 0; char *sender; - int fd; - if (!dbus_connection_add_filter (conn, private_server_message_filter, s, NULL)) { - dbus_connection_close (conn); - return; - } - dbus_connection_set_unix_user_function (conn, allow_only_root, NULL, NULL); - dbus_connection_setup_with_g_main (conn, NULL); + g_signal_connect (conn, "closed", G_CALLBACK (private_server_closed), s); /* Fake a sender since private connections don't have one */ sender = g_strdup_printf ("x:y:%d", counter++); - g_hash_table_insert (s->connections, dbus_connection_ref (conn), sender); + g_hash_table_insert (s->connections, g_object_ref (conn), sender); - nm_log_dbg (LOGD_CORE, "(%s) accepted connection %p on private socket (fd %d).", - s->tag, conn, dbus_connection_get_unix_fd (conn, &fd) ? fd : -1); + nm_log_dbg (LOGD_CORE, "(%s) accepted connection %p on private socket.", + s->tag, conn); /* Emit this for the manager */ g_signal_emit (s->manager, signals[PRIVATE_CONNECTION_NEW], s->detail, - dbus_connection_get_g_connection (conn)); + conn); + return TRUE; } static void -private_server_dbus_connection_destroy (DBusConnection *conn) +private_server_dbus_connection_destroy (GDBusConnection *conn) { - if (dbus_connection_get_is_connected (conn)) - dbus_connection_close (conn); - dbus_connection_unref (conn); + if (!g_dbus_connection_is_closed (conn)) + g_dbus_connection_close (conn, NULL, NULL, NULL); + g_object_unref (conn); +} + +static gboolean +private_server_authorize (GDBusAuthObserver *observer, + GIOStream *stream, + GCredentials *credentials, + gpointer user_data) +{ + return g_credentials_get_unix_user (credentials, NULL) == 0; } static PrivateServer * @@ -195,21 +183,32 @@ private_server_new (const char *path, NMBusManager *manager) { PrivateServer *s; - DBusServer *server; - DBusError error; - char *address; + GDBusAuthObserver *auth_observer; + GDBusServer *server; + GError *error = NULL; + char *address, *guid; unlink (path); address = g_strdup_printf ("unix:path=%s", path); nm_log_dbg (LOGD_CORE, "(%s) creating private socket %s.", tag, address); - dbus_error_init (&error); - server = dbus_server_listen (address, &error); + guid = g_dbus_generate_guid (); + auth_observer = g_dbus_auth_observer_new (); + g_signal_connect (auth_observer, "authorize-authenticated-peer", + G_CALLBACK (private_server_authorize), NULL); + server = g_dbus_server_new_sync (address, + G_DBUS_SERVER_FLAGS_NONE, + guid, + auth_observer, + NULL, &error); + g_free (guid); + g_object_unref (auth_observer); + if (!server) { nm_log_warn (LOGD_CORE, "(%s) failed to set up private socket %s: %s", - tag, address, error.message); - dbus_error_free (&error); + tag, address, error->message); + g_error_free (error); g_free (address); return NULL; } @@ -217,8 +216,8 @@ private_server_new (const char *path, s = g_malloc0 (sizeof (*s)); s->address = address; s->server = server; - dbus_server_setup_with_g_main (s->server, NULL); - dbus_server_set_new_connection_function (s->server, private_server_new_connection, s, NULL); + g_signal_connect (server, "new-connection", + G_CALLBACK (private_server_new_connection), s); s->connections = g_hash_table_new_full (g_direct_hash, g_direct_equal, (GDestroyNotify) private_server_dbus_connection_destroy, @@ -227,6 +226,8 @@ private_server_new (const char *path, s->detail = g_quark_from_string (tag); s->tag = g_quark_to_string (s->detail); + g_dbus_server_start (server); + return s; } @@ -238,8 +239,10 @@ private_server_free (gpointer ptr) unlink (s->address); g_free (s->address); g_hash_table_destroy (s->connections); - dbus_server_disconnect (s->server); - dbus_server_unref (s->server); + + g_dbus_server_stop (s->server); + g_object_unref (s->server); + memset (s, 0, sizeof (*s)); g_free (s); } @@ -253,10 +256,6 @@ nm_bus_manager_private_server_register (NMBusManager *self, PrivateServer *s; GSList *iter; -#if !HAVE_DBUS_GLIB_100 - g_assert_not_reached (); -#endif - g_return_if_fail (self != NULL); g_return_if_fail (path != NULL); g_return_if_fail (tag != NULL); @@ -274,12 +273,12 @@ nm_bus_manager_private_server_register (NMBusManager *self, } static const char * -private_server_get_connection_owner (PrivateServer *s, DBusGConnection *connection) +private_server_get_connection_owner (PrivateServer *s, GDBusConnection *connection) { g_return_val_if_fail (s != NULL, NULL); g_return_val_if_fail (connection != NULL, NULL); - return g_hash_table_lookup (s->connections, dbus_g_connection_get_connection (connection)); + return g_hash_table_lookup (s->connections, connection); } /**************************************************************/ @@ -291,52 +290,74 @@ _bus_get_unix_pid (NMBusManager *self, GError **error) { guint32 unix_pid = G_MAXUINT32; + GVariant *ret; - if (!dbus_g_proxy_call_with_timeout (NM_BUS_MANAGER_GET_PRIVATE (self)->proxy, - "GetConnectionUnixProcessID", 2000, error, - G_TYPE_STRING, sender, - G_TYPE_INVALID, - G_TYPE_UINT, &unix_pid, - G_TYPE_INVALID)) { + ret = _nm_dbus_proxy_call_sync (NM_BUS_MANAGER_GET_PRIVATE (self)->proxy, + "GetConnectionUnixProcessID", + g_variant_new ("(s)", sender), + G_VARIANT_TYPE ("(u)"), + G_DBUS_CALL_FLAGS_NONE, 2000, + NULL, error); + if (!ret) return FALSE; - } + + g_variant_get (ret, "(u)", &unix_pid); *out_pid = (gulong) unix_pid; return TRUE; } +static gboolean +_bus_get_unix_user (NMBusManager *self, + const char *sender, + gulong *out_user, + GError **error) +{ + guint32 unix_uid = G_MAXUINT32; + GVariant *ret; + + ret = _nm_dbus_proxy_call_sync (NM_BUS_MANAGER_GET_PRIVATE (self)->proxy, + "GetConnectionUnixUser", + g_variant_new ("(s)", sender), + G_VARIANT_TYPE ("(u)"), + G_DBUS_CALL_FLAGS_NONE, 2000, + NULL, error); + if (!ret) + return FALSE; + + g_variant_get (ret, "(u)", &unix_uid); + + *out_user = (gulong) unix_uid; + return TRUE; +} + /** - * _get_caller_info_from_context(): + * _get_caller_info(): * - * Given a dbus-glib method invocation, or a DBusConnection + DBusMessage, + * Given a GDBus method invocation, or a GDBusConnection + GDBusMessage, * return the sender and the UID of the sender. */ static gboolean _get_caller_info (NMBusManager *self, - DBusGMethodInvocation *context, - DBusConnection *connection, - DBusMessage *message, + GDBusMethodInvocation *context, + GDBusConnection *connection, + GDBusMessage *message, char **out_sender, gulong *out_uid, gulong *out_pid) { NMBusManagerPrivate *priv = NM_BUS_MANAGER_GET_PRIVATE (self); - DBusGConnection *gconn; - char *sender; - const char *priv_sender; - DBusError error; + const char *sender; GSList *iter; if (context) { - gconn = dbus_g_method_invocation_get_g_connection (context); - g_assert (gconn); - connection = dbus_g_connection_get_connection (gconn); + connection = g_dbus_method_invocation_get_connection (context); /* only bus connections will have a sender */ - sender = dbus_g_method_get_sender (context); + sender = g_dbus_method_invocation_get_sender (context); } else { g_assert (message); - sender = g_strdup (dbus_message_get_sender (message)); + sender = g_dbus_message_get_sender (message); } g_assert (connection); @@ -345,14 +366,25 @@ _get_caller_info (NMBusManager *self, for (iter = priv->private_servers; iter; iter = g_slist_next (iter)) { PrivateServer *s = iter->data; - priv_sender = g_hash_table_lookup (s->connections, connection); - if (priv_sender) { + sender = g_hash_table_lookup (s->connections, connection); + if (sender) { if (out_uid) *out_uid = 0; if (out_sender) - *out_sender = g_strdup (priv_sender); + *out_sender = g_strdup (sender); if (out_pid) { - if (!dbus_connection_get_unix_process_id (connection, out_pid)) + GCredentials *creds; + + creds = g_dbus_connection_get_peer_credentials (connection); + if (creds) { + pid_t pid; + + pid = g_credentials_get_unix_pid (creds, NULL); + if (pid == -1) + *out_pid = G_MAXULONG; + else + *out_pid = pid; + } else *out_pid = G_MAXULONG; } return TRUE; @@ -364,12 +396,8 @@ _get_caller_info (NMBusManager *self, /* Bus connections always have a sender */ g_assert (sender); if (out_uid) { - dbus_error_init (&error); - *out_uid = dbus_bus_get_unix_user (connection, sender, &error); - if (dbus_error_is_set (&error)) { - dbus_error_free (&error); + if (!_bus_get_unix_user (self, sender, out_uid, NULL)) { *out_uid = G_MAXULONG; - g_free (sender); return FALSE; } } @@ -377,7 +405,6 @@ _get_caller_info (NMBusManager *self, if (out_pid) { if (!_bus_get_unix_pid (self, sender, out_pid, NULL)) { *out_pid = G_MAXULONG; - g_free (sender); return FALSE; } } @@ -385,13 +412,12 @@ _get_caller_info (NMBusManager *self, if (out_sender) *out_sender = g_strdup (sender); - g_free (sender); return TRUE; } gboolean nm_bus_manager_get_caller_info (NMBusManager *self, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, char **out_sender, gulong *out_uid, gulong *out_pid) @@ -401,8 +427,8 @@ nm_bus_manager_get_caller_info (NMBusManager *self, gboolean nm_bus_manager_get_caller_info_from_message (NMBusManager *self, - DBusConnection *connection, - DBusMessage *message, + GDBusConnection *connection, + GDBusMessage *message, char **out_sender, gulong *out_uid, gulong *out_pid) @@ -417,7 +443,7 @@ nm_bus_manager_get_unix_user (NMBusManager *self, { NMBusManagerPrivate *priv = NM_BUS_MANAGER_GET_PRIVATE (self); GSList *iter; - DBusError error; + GError *error = NULL; g_return_val_if_fail (sender != NULL, FALSE); g_return_val_if_fail (out_uid != NULL, FALSE); @@ -438,11 +464,10 @@ nm_bus_manager_get_unix_user (NMBusManager *self, } /* Otherwise, a bus connection */ - dbus_error_init (&error); - *out_uid = dbus_bus_get_unix_user (priv->connection, sender, &error); - if (dbus_error_is_set (&error)) { + if (!_bus_get_unix_user (self, sender, out_uid, &error)) { nm_log_warn (LOGD_CORE, "Failed to get unix user for dbus sender '%s': %s", - sender, error.message); + sender, error->message); + g_error_free (error); return FALSE; } @@ -451,38 +476,30 @@ nm_bus_manager_get_unix_user (NMBusManager *self, /**************************************************************/ -#if HAVE_DBUS_GLIB_100 static void -private_connection_new (NMBusManager *self, DBusGConnection *connection) +private_connection_new (NMBusManager *self, GDBusConnection *connection) { NMBusManagerPrivate *priv = NM_BUS_MANAGER_GET_PRIVATE (self); GHashTableIter iter; - GObject *object; + GDBusInterfaceSkeleton *interface; const char *path; + GError *error = NULL; /* Register all exported objects on this private connection */ g_hash_table_iter_init (&iter, priv->exported); - while (g_hash_table_iter_next (&iter, (gpointer) &object, (gpointer) &path)) { - dbus_g_connection_register_g_object (connection, path, object); - nm_log_trace (LOGD_CORE, "(%s) registered %p (%s) at '%s' on private socket.", - PRIV_SOCK_TAG, object, G_OBJECT_TYPE_NAME (object), path); + while (g_hash_table_iter_next (&iter, (gpointer) &interface, (gpointer) &path)) { + if (g_dbus_interface_skeleton_export (interface, connection, path, &error)) { + nm_log_trace (LOGD_CORE, "(%s) registered %p (%s) at '%s' on private socket.", + PRIV_SOCK_TAG, interface, G_OBJECT_TYPE_NAME (interface), path); + } else { + nm_log_warn (LOGD_CORE, "(%s) could not register %p (%s) at '%s' on private socket: %s.", + PRIV_SOCK_TAG, interface, G_OBJECT_TYPE_NAME (interface), path, + error->message); + g_clear_error (&error); + } } } -static void -private_connection_disconnected (NMBusManager *self, DBusGConnection *connection) -{ - NMBusManagerPrivate *priv = NM_BUS_MANAGER_GET_PRIVATE (self); - const char *owner; - - owner = private_server_get_connection_owner (priv->priv_server, connection); - g_assert (owner); - - /* Fake a NameOwnerChanged to let listerners know this owner has quit */ - g_signal_emit (G_OBJECT (self), signals[NAME_OWNER_CHANGED], - 0, owner, owner, NULL); -} - static void private_server_setup (NMBusManager *self) { @@ -500,18 +517,12 @@ private_server_setup (NMBusManager *self) priv->priv_server = private_server_new (PRIV_SOCK_PATH, PRIV_SOCK_TAG, self); if (priv->priv_server) { priv->private_servers = g_slist_append (priv->private_servers, priv->priv_server); - g_signal_connect (self, NM_BUS_MANAGER_PRIVATE_CONNECTION_NEW "::" PRIV_SOCK_TAG, (GCallback) private_connection_new, NULL); - g_signal_connect (self, - NM_BUS_MANAGER_PRIVATE_CONNECTION_DISCONNECTED "::" PRIV_SOCK_TAG, - (GCallback) private_connection_disconnected, - NULL); } } -#endif /* HAVE_DBUS_GLIB_100 */ static void nm_bus_manager_init (NMBusManager *self) @@ -520,9 +531,7 @@ nm_bus_manager_init (NMBusManager *self) priv->exported = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free); -#if HAVE_DBUS_GLIB_100 private_server_setup (self); -#endif } static void @@ -546,7 +555,7 @@ nm_bus_manager_dispose (GObject *object) priv->private_servers = NULL; priv->priv_server = NULL; - nm_bus_manager_cleanup (self, TRUE); + nm_bus_manager_cleanup (self); if (priv->reconnect_id) { g_source_remove (priv->reconnect_id); @@ -573,14 +582,6 @@ nm_bus_manager_class_init (NMBusManagerClass *klass) NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_POINTER); - signals[NAME_OWNER_CHANGED] = - g_signal_new (NM_BUS_MANAGER_NAME_OWNER_CHANGED, - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (NMBusManagerClass, name_owner_changed), - NULL, NULL, NULL, - G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); - signals[PRIVATE_CONNECTION_NEW] = g_signal_new (NM_BUS_MANAGER_PRIVATE_CONNECTION_NEW, G_OBJECT_CLASS_TYPE (object_class), @@ -601,23 +602,16 @@ nm_bus_manager_class_init (NMBusManagerClass *klass) /* Only cleanup a specific dbus connection, not all our private data */ static void -nm_bus_manager_cleanup (NMBusManager *self, gboolean dispose) +nm_bus_manager_cleanup (NMBusManager *self) { NMBusManagerPrivate *priv = NM_BUS_MANAGER_GET_PRIVATE (self); - if (priv->proxy) { - if (dispose) { - g_signal_handler_disconnect (priv->proxy, priv->proxy_destroy_id); - priv->proxy_destroy_id = 0; - } - g_object_unref (priv->proxy); - priv->proxy = NULL; - } + g_clear_object (&priv->proxy); - if (priv->g_connection) { - dbus_g_connection_unref (priv->g_connection); - priv->g_connection = NULL; - priv->connection = NULL; + if (priv->connection) { + g_signal_handler_disconnect (priv->connection, priv->bus_closed_id); + priv->bus_closed_id = 0; + g_clear_object (&priv->connection); } priv->started = FALSE; @@ -642,7 +636,7 @@ nm_bus_manager_reconnect (gpointer user_data) } /* Try again */ - nm_bus_manager_cleanup (self, FALSE); + nm_bus_manager_cleanup (self); return TRUE; } @@ -658,81 +652,18 @@ start_reconnection_timeout (NMBusManager *self) priv->reconnect_id = g_timeout_add_seconds (3, nm_bus_manager_reconnect, self); } -char * -nm_bus_manager_get_name_owner (NMBusManager *self, - const char *name, - GError **error) -{ - char *owner = NULL; - - g_return_val_if_fail (NM_IS_BUS_MANAGER (self), NULL); - g_return_val_if_fail (name != NULL, NULL); - if (error) - g_return_val_if_fail (*error == NULL, NULL); - - if (!NM_BUS_MANAGER_GET_PRIVATE (self)->proxy) - return NULL; - - if (!dbus_g_proxy_call_with_timeout (NM_BUS_MANAGER_GET_PRIVATE (self)->proxy, - "GetNameOwner", 2000, error, - G_TYPE_STRING, name, - G_TYPE_INVALID, - G_TYPE_STRING, &owner, - G_TYPE_INVALID)) { - return NULL; - } - - return owner; -} - -gboolean -nm_bus_manager_name_has_owner (NMBusManager *self, - const char *name) -{ - gboolean has_owner = FALSE; - GError *err = NULL; - - g_return_val_if_fail (NM_IS_BUS_MANAGER (self), FALSE); - g_return_val_if_fail (name != NULL, FALSE); - - if (!NM_BUS_MANAGER_GET_PRIVATE (self)->proxy) - return FALSE; - - if (!dbus_g_proxy_call (NM_BUS_MANAGER_GET_PRIVATE (self)->proxy, - "NameHasOwner", &err, - G_TYPE_STRING, name, - G_TYPE_INVALID, - G_TYPE_BOOLEAN, &has_owner, - G_TYPE_INVALID)) { - nm_log_warn (LOGD_CORE, "NameHasOwner request failed: %s", - (err && err->message) ? err->message : "(unknown)"); - g_clear_error (&err); - } - - return has_owner; -} - static void -proxy_name_owner_changed (DBusGProxy *proxy, - const char *name, - const char *old_owner, - const char *new_owner, - gpointer user_data) -{ - g_signal_emit (G_OBJECT (user_data), signals[NAME_OWNER_CHANGED], - 0, name, old_owner, new_owner); -} - -static void -destroy_cb (DBusGProxy *proxy, gpointer user_data) +closed_cb (GDBusConnection *connection, + gboolean remote_peer_vanished, + GError *error, + gpointer user_data) { NMBusManager *self = NM_BUS_MANAGER (user_data); /* Clean up existing connection */ nm_log_warn (LOGD_CORE, "disconnected by the system bus."); - NM_BUS_MANAGER_GET_PRIVATE (self)->proxy = NULL; - nm_bus_manager_cleanup (self, FALSE); + nm_bus_manager_cleanup (self); g_signal_emit (G_OBJECT (self), signals[DBUS_CONNECTION_CHANGED], 0, NULL); @@ -743,43 +674,47 @@ static gboolean nm_bus_manager_init_bus (NMBusManager *self) { NMBusManagerPrivate *priv = NM_BUS_MANAGER_GET_PRIVATE (self); + GError *error = NULL; if (priv->connection) { nm_log_warn (LOGD_CORE, "DBus Manager already has a valid connection."); return FALSE; } - dbus_connection_set_change_sigpipe (TRUE); - - priv->g_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL); - if (!priv->g_connection) { + priv->connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); + if (!priv->connection) { /* Log with 'info' severity; there won't be a bus daemon in minimal * environments (eg, initrd) where we only want to use the private * socket. */ - nm_log_info (LOGD_CORE, "Could not connect to the system bus; only the " - "private D-Bus socket will be available."); + nm_log_info (LOGD_CORE, "Could not connect to the system bus (%s); only the " + "private D-Bus socket will be available.", + error->message); + g_error_free (error); return FALSE; } - priv->connection = dbus_g_connection_get_connection (priv->g_connection); - dbus_connection_set_exit_on_disconnect (priv->connection, FALSE); + g_dbus_connection_set_exit_on_close (priv->connection, FALSE); + priv->bus_closed_id = g_signal_connect (priv->connection, "closed", + G_CALLBACK (closed_cb), self); - priv->proxy = dbus_g_proxy_new_for_name (priv->g_connection, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS); + priv->proxy = g_dbus_proxy_new_sync (priv->connection, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | + G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, + NULL, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + NULL, &error); + if (!priv->proxy) { + g_clear_object (&priv->connection); + nm_log_warn (LOGD_CORE, "Could not create org.freedesktop.DBus proxy (%s); only the " + "private D-Bus socket will be available.", + error->message); + g_error_free (error); + return FALSE; + } - priv->proxy_destroy_id = g_signal_connect (priv->proxy, "destroy", - G_CALLBACK (destroy_cb), self); - - dbus_g_proxy_add_signal (priv->proxy, "NameOwnerChanged", - G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, - G_TYPE_INVALID); - dbus_g_proxy_connect_signal (priv->proxy, - "NameOwnerChanged", - G_CALLBACK (proxy_name_owner_changed), - self, NULL); return TRUE; } @@ -791,6 +726,7 @@ gboolean nm_bus_manager_start_service (NMBusManager *self) { NMBusManagerPrivate *priv; + GVariant *ret; int result; GError *err = NULL; @@ -807,19 +743,23 @@ nm_bus_manager_start_service (NMBusManager *self) if (!priv->proxy) return FALSE; - if (!dbus_g_proxy_call (priv->proxy, "RequestName", &err, - G_TYPE_STRING, NM_DBUS_SERVICE, - G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE, - G_TYPE_INVALID, - G_TYPE_UINT, &result, - G_TYPE_INVALID)) { + ret = _nm_dbus_proxy_call_sync (priv->proxy, + "RequestName", + g_variant_new ("(su)", + NM_DBUS_SERVICE, + DBUS_NAME_FLAG_DO_NOT_QUEUE), + G_VARIANT_TYPE ("(u)"), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, &err); + if (!ret) { nm_log_err (LOGD_CORE, "Could not acquire the NetworkManager service.\n" - " Error: '%s'", - (err && err->message) ? err->message : "(unknown)"); + " Error: '%s'", err->message); g_error_free (err); return FALSE; } + g_variant_get (ret, "(u)", &result); + if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { nm_log_err (LOGD_CORE, "Could not acquire the NetworkManager service as it is already taken."); return FALSE; @@ -829,20 +769,12 @@ nm_bus_manager_start_service (NMBusManager *self) return priv->started; } -DBusConnection * -nm_bus_manager_get_dbus_connection (NMBusManager *self) -{ - g_return_val_if_fail (NM_IS_BUS_MANAGER (self), NULL); - - return NM_BUS_MANAGER_GET_PRIVATE (self)->connection; -} - -DBusGConnection * +GDBusConnection * nm_bus_manager_get_connection (NMBusManager *self) { g_return_val_if_fail (NM_IS_BUS_MANAGER (self), NULL); - return NM_BUS_MANAGER_GET_PRIVATE (self)->g_connection; + return NM_BUS_MANAGER_GET_PRIVATE (self)->connection; } static void @@ -858,9 +790,9 @@ nm_bus_manager_register_object (NMBusManager *self, { NMBusManagerPrivate *priv = NM_BUS_MANAGER_GET_PRIVATE (self); GHashTableIter iter; - DBusConnection *connection; + GDBusConnection *connection; - g_assert (G_IS_OBJECT (object)); + g_assert (G_IS_DBUS_INTERFACE_SKELETON (object)); if (g_hash_table_lookup (priv->exported, G_OBJECT (object))) g_return_if_reached (); @@ -868,27 +800,43 @@ nm_bus_manager_register_object (NMBusManager *self, g_hash_table_insert (priv->exported, G_OBJECT (object), g_strdup (path)); g_object_weak_ref (G_OBJECT (object), (GWeakNotify) object_destroyed, self); - if (priv->g_connection) - dbus_g_connection_register_g_object (priv->g_connection, path, G_OBJECT (object)); + if (priv->connection) { + g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (object), + priv->connection, path, NULL); + } if (priv->priv_server) { g_hash_table_iter_init (&iter, priv->priv_server->connections); while (g_hash_table_iter_next (&iter, (gpointer) &connection, NULL)) { - dbus_g_connection_register_g_object (dbus_connection_get_g_connection (connection), - path, - G_OBJECT (object)); + g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (object), + connection, path, NULL); } } } +gpointer +nm_bus_manager_get_registered_object (NMBusManager *self, + const char *path) +{ + NMBusManagerPrivate *priv = NM_BUS_MANAGER_GET_PRIVATE (self); + GHashTableIter iter; + GObject *object; + const char *export_path; + + g_hash_table_iter_init (&iter, priv->exported); + while (g_hash_table_iter_next (&iter, (gpointer *) &object, (gpointer *) &export_path)) { + if (!strcmp (path, export_path)) + return object; + } + return NULL; +} + void nm_bus_manager_unregister_object (NMBusManager *self, gpointer object) { NMBusManagerPrivate *priv = NM_BUS_MANAGER_GET_PRIVATE (self); - GHashTableIter iter; - DBusConnection *connection; - g_assert (G_IS_OBJECT (object)); + g_assert (G_IS_DBUS_INTERFACE_SKELETON (object)); if (!g_hash_table_lookup (priv->exported, G_OBJECT (object))) g_return_if_reached (); @@ -896,74 +844,69 @@ nm_bus_manager_unregister_object (NMBusManager *self, gpointer object) g_hash_table_remove (priv->exported, G_OBJECT (object)); g_object_weak_unref (G_OBJECT (object), (GWeakNotify) object_destroyed, self); - if (priv->g_connection) - dbus_g_connection_unregister_g_object (priv->g_connection, G_OBJECT (object)); - - if (priv->priv_server) { - g_hash_table_iter_init (&iter, priv->priv_server->connections); - while (g_hash_table_iter_next (&iter, (gpointer) &connection, NULL)) { - dbus_g_connection_unregister_g_object (dbus_connection_get_g_connection (connection), - G_OBJECT (object)); - } - } + g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (object)); } /** * nm_bus_manager_new_proxy: * @self: the #NMBusManager * @context: the method call context this proxy should be created + * @proxy_type: the type of #GDBusProxy to create * @name: any name on the message bus * @path: name of the object instance to call methods on * @iface: name of the interface to call methods on * - * Creates a new proxy for a name on a given bus. Since the process which - * called the D-Bus method could be coming from a private connection or the - * system bus connection, differnet proxies must be created for each case. This - * function abstracts that. + * Creates a new proxy (of type @proxy_type) for a name on a given bus. Since + * the process which called the D-Bus method could be coming from a private + * connection or the system bus connection, different proxies must be created + * for each case. This function abstracts that. * - * Returns: a #DBusGProxy capable of calling D-Bus methods of the calling process + * Returns: a #GDBusProxy capable of calling D-Bus methods of the calling process */ -DBusGProxy * +GDBusProxy * nm_bus_manager_new_proxy (NMBusManager *self, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, + GType proxy_type, const char *name, const char *path, const char *iface) { NMBusManagerPrivate *priv = NM_BUS_MANAGER_GET_PRIVATE (self); - DBusGConnection *connection; + GDBusConnection *connection; GSList *iter; const char *owner; + GDBusProxy *proxy; + GError *error = NULL; - connection = dbus_g_method_invocation_get_g_connection (context); + g_return_val_if_fail (g_type_is_a (proxy_type, G_TYPE_DBUS_PROXY), NULL); + + connection = g_dbus_method_invocation_get_connection (context); g_assert (connection); - /* Might be a private connection, for which we fake a sender */ + /* Might be a private connection, for which @name is fake */ for (iter = priv->private_servers; iter; iter = g_slist_next (iter)) { PrivateServer *s = iter->data; owner = private_server_get_connection_owner (s, connection); if (owner) { g_assert_cmpstr (owner, ==, name); - return dbus_g_proxy_new_for_peer (connection, path, iface); + name = NULL; + break; } } - return dbus_g_proxy_new_for_name (connection, name, path, iface); + proxy = g_initable_new (proxy_type, NULL, &error, + "g-connection", connection, + "g-flags", (G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | + G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS), + "g-name", name, + "g-object-path", path, + "g-interface-name", iface, + NULL); + if (!proxy) { + nm_log_warn (LOGD_CORE, "Could not create proxy for %s on connection %s: %s", + iface, name, error->message); + g_error_free (error); + } + return proxy; } - -#if !HAVE_DBUS_GLIB_GMI_GET_CONNECTION -struct _HACKDBusGMethodInvocation { - DBusGConnection *connection; - /* ... */ -}; - -DBusGConnection * -dbus_g_method_invocation_get_g_connection (DBusGMethodInvocation *context) -{ - /* Evil hack; this method exists in dbus-glib >= 101, but if we don't - * have that, emulate it. - */ - return ((struct _HACKDBusGMethodInvocation *) context)->connection; -} -#endif /* HAVE_DBUS_GLIB_GMI_GET_CONNECTION */ diff --git a/src/nm-bus-manager.h b/src/nm-bus-manager.h index 53dbe4498a..cf6a701f1a 100644 --- a/src/nm-bus-manager.h +++ b/src/nm-bus-manager.h @@ -23,17 +23,11 @@ #define __NM_BUS_MANAGER_H__ #include "config.h" -#include -#include #include "nm-default.h" G_BEGIN_DECLS -typedef gboolean (* NMDBusSignalHandlerFunc) (DBusConnection * connection, - DBusMessage * message, - gpointer user_data); - #define NM_TYPE_BUS_MANAGER (nm_bus_manager_get_type ()) #define NM_BUS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), NM_TYPE_BUS_MANAGER, NMBusManager)) #define NM_BUS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), NM_TYPE_BUS_MANAGER, NMBusManagerClass)) @@ -42,7 +36,6 @@ typedef gboolean (* NMDBusSignalHandlerFunc) (DBusConnection * connection, #define NM_BUS_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), NM_TYPE_BUS_MANAGER, NMBusManagerClass)) #define NM_BUS_MANAGER_DBUS_CONNECTION_CHANGED "dbus-connection-changed" -#define NM_BUS_MANAGER_NAME_OWNER_CHANGED "name-owner-changed" #define NM_BUS_MANAGER_PRIVATE_CONNECTION_NEW "private-connection-new" #define NM_BUS_MANAGER_PRIVATE_CONNECTION_DISCONNECTED "private-connection-disconnected" @@ -55,18 +48,13 @@ typedef struct { /* Signals */ void (*dbus_connection_changed) (NMBusManager *mgr, - DBusConnection *connection); - - void (*name_owner_changed) (NMBusManager *mgr, - const char *name, - const char *old_owner, - const char *new_owner); + GDBusConnection *connection); void (*private_connection_new) (NMBusManager *mgr, - DBusGConnection *connection); + GDBusConnection *connection); void (*private_connection_disconnected) (NMBusManager *mgr, - DBusGConnection *connection); + GDBusConnection *connection); } NMBusManagerClass; GType nm_bus_manager_get_type (void); @@ -74,20 +62,12 @@ GType nm_bus_manager_get_type (void); NMBusManager * nm_bus_manager_get (void); void nm_bus_manager_setup (NMBusManager *instance); -char * nm_bus_manager_get_name_owner (NMBusManager *self, - const char *name, - GError **error); - gboolean nm_bus_manager_start_service (NMBusManager *self); -gboolean nm_bus_manager_name_has_owner (NMBusManager *self, - const char *name); - -DBusConnection * nm_bus_manager_get_dbus_connection (NMBusManager *self); -DBusGConnection * nm_bus_manager_get_connection (NMBusManager *self); +GDBusConnection * nm_bus_manager_get_connection (NMBusManager *self); gboolean nm_bus_manager_get_caller_info (NMBusManager *self, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, char **out_sender, gulong *out_uid, gulong *out_pid); @@ -97,8 +77,8 @@ gboolean nm_bus_manager_get_unix_user (NMBusManager *self, gulong *out_uid); gboolean nm_bus_manager_get_caller_info_from_message (NMBusManager *self, - DBusConnection *connection, - DBusMessage *message, + GDBusConnection *connection, + GDBusMessage *message, char **out_sender, gulong *out_uid, gulong *out_pid); @@ -109,20 +89,20 @@ void nm_bus_manager_register_object (NMBusManager *self, void nm_bus_manager_unregister_object (NMBusManager *self, gpointer object); +gpointer nm_bus_manager_get_registered_object (NMBusManager *self, + const char *path); + void nm_bus_manager_private_server_register (NMBusManager *self, const char *path, const char *tag); -DBusGProxy *nm_bus_manager_new_proxy (NMBusManager *self, - DBusGMethodInvocation *context, +GDBusProxy *nm_bus_manager_new_proxy (NMBusManager *self, + GDBusMethodInvocation *context, + GType proxy_type, const char *name, const char *path, const char *iface); -#if !HAVE_DBUS_GLIB_GMI_GET_CONNECTION -DBusGConnection *dbus_g_method_invocation_get_g_connection (DBusGMethodInvocation *context); -#endif - G_END_DECLS #endif /* __NM_BUS_MANAGER_H__ */ From 9f8de603e387d9ea1bbe93793bedbdfbb4923235 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Wed, 15 Apr 2015 14:53:30 -0400 Subject: [PATCH 06/14] ifcfg-rh: port to gdbus --- .gitignore | 1 + src/settings/plugins/ifcfg-rh/Makefile.am | 29 +++- src/settings/plugins/ifcfg-rh/nm-ifcfg-rh.xml | 1 - src/settings/plugins/ifcfg-rh/plugin.c | 163 ++++++++---------- .../plugins/ifcfg-rh/tests/Makefile.am | 1 - 5 files changed, 95 insertions(+), 100 deletions(-) diff --git a/.gitignore b/.gitignore index 4b0ad46a45..14a033232e 100644 --- a/.gitignore +++ b/.gitignore @@ -246,6 +246,7 @@ test-*.trs /src/rdisc/tests/test-rdisc-fake /src/rdisc/tests/test-rdisc-linux /src/settings/plugins/ibft/tests/test-ibft +/src/settings/plugins/ifcfg-rh/nmdbus-ifcfg-rh.[ch] /src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh /src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils /src/settings/plugins/ifnet/tests/test-ifnet diff --git a/src/settings/plugins/ifcfg-rh/Makefile.am b/src/settings/plugins/ifcfg-rh/Makefile.am index 7546538e36..34f04f91e7 100644 --- a/src/settings/plugins/ifcfg-rh/Makefile.am +++ b/src/settings/plugins/ifcfg-rh/Makefile.am @@ -2,15 +2,31 @@ SUBDIRS = . tests @GNOME_CODE_COVERAGE_RULES@ -nm-ifcfg-rh-glue.h: nm-ifcfg-rh.xml - $(AM_V_GEN) dbus-binding-tool --prefix=nm_ifcfg_rh --mode=glib-server --output=$@ $< +# See note about gdbus-codegen in introspection/Makefile.am -BUILT_SOURCES = \ - nm-ifcfg-rh-glue.h +noinst_LTLIBRARIES = libnmdbus-ifcfg-rh.la + +nodist_libnmdbus_ifcfg_rh_la_SOURCES = \ + nmdbus-ifcfg-rh.c \ + nmdbus-ifcfg-rh.h + +libnmdbus_ifcfg_rh_la_CPPFLAGS = $(filter-out -DGLIB_VERSION_MAX_ALLOWED%,$(AM_CPPFLAGS)) + +nmdbus-ifcfg-rh.h: nm-ifcfg-rh.xml + $(AM_V_GEN) gdbus-codegen \ + --generate-c-code $(basename $@) \ + --c-namespace NMDBus \ + --interface-prefix com.redhat \ + $< + +nmdbus-ifcfg-rh.c: nmdbus-ifcfg-rh.h + @true + +BUILT_SOURCES = nmdbus-ifcfg-rh.h nmdbus-ifcfg-rh.c pkglib_LTLIBRARIES = libnm-settings-plugin-ifcfg-rh.la -noinst_LTLIBRARIES = libifcfg-rh-io.la +noinst_LTLIBRARIES += libifcfg-rh-io.la libifcfg_rh_io_la_SOURCES = \ shvar.c \ @@ -33,7 +49,6 @@ AM_CPPFLAGS = \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ $(NSS_CFLAGS) \ -DG_LOG_DOMAIN=\""NetworkManager-ifcfg-rh"\" \ -DSYSCONFDIR=\"$(sysconfdir)\" \ @@ -46,7 +61,7 @@ libnm_settings_plugin_ifcfg_rh_la_SOURCES = \ nm-ifcfg-connection.h libnm_settings_plugin_ifcfg_rh_la_LDFLAGS = -module -avoid-version -libnm_settings_plugin_ifcfg_rh_la_LIBADD = libifcfg-rh-io.la +libnm_settings_plugin_ifcfg_rh_la_LIBADD = libifcfg-rh-io.la libnmdbus-ifcfg-rh.la dbusservicedir = $(DBUS_SYS_DIR) dbusservice_DATA = nm-ifcfg-rh.conf diff --git a/src/settings/plugins/ifcfg-rh/nm-ifcfg-rh.xml b/src/settings/plugins/ifcfg-rh/nm-ifcfg-rh.xml index 5279345297..1f308dd48a 100644 --- a/src/settings/plugins/ifcfg-rh/nm-ifcfg-rh.xml +++ b/src/settings/plugins/ifcfg-rh/nm-ifcfg-rh.xml @@ -10,7 +10,6 @@ Given an ifcfg file, return various internal information about it. - The full path to an ifcfg file. diff --git a/src/settings/plugins/ifcfg-rh/plugin.c b/src/settings/plugins/ifcfg-rh/plugin.c index 7e54833c91..ebed980e1e 100644 --- a/src/settings/plugins/ifcfg-rh/plugin.c +++ b/src/settings/plugins/ifcfg-rh/plugin.c @@ -31,10 +31,6 @@ #include -#include -#include -#include - #if HAVE_SELINUX #include #endif @@ -43,7 +39,6 @@ #include "nm-default.h" #include "common.h" -#include "nm-dbus-glib-types.h" #include "plugin.h" #include "nm-system-config-interface.h" #include "nm-config.h" @@ -54,6 +49,9 @@ #include "reader.h" #include "writer.h" #include "utils.h" +#include "nm-dbus-compat.h" + +#include "nmdbus-ifcfg-rh.h" #define IFCFGRH1_DBUS_SERVICE_NAME "com.redhat.ifcfgrh1" #define IFCFGRH1_DBUS_OBJECT_PATH "/com/redhat/ifcfgrh1" @@ -77,14 +75,6 @@ #define ERR_GET_MSG(err) (((err) && (err)->message) ? (err)->message : "(unknown)") -static gboolean impl_ifcfgrh_get_ifcfg_details (SCPluginIfcfg *plugin, - const char *in_ifcfg, - const char **out_uuid, - const char **out_path, - GError **error); - -#include "nm-ifcfg-rh-glue.h" - static NMIfcfgConnection *update_connection (SCPluginIfcfg *plugin, NMConnection *source, const char *full_path, @@ -109,7 +99,7 @@ typedef struct { GFileMonitor *ifcfg_monitor; guint ifcfg_monitor_id; - DBusGConnection *bus; + gboolean has_dbus_service; } SCPluginIfcfgPrivate; @@ -696,12 +686,10 @@ add_connection (NMSystemConfigInterface *config, return NM_SETTINGS_CONNECTION (update_connection (self, connection, path, NULL, FALSE, NULL, error)); } -static gboolean +static void impl_ifcfgrh_get_ifcfg_details (SCPluginIfcfg *plugin, - const char *in_ifcfg, - const char **out_uuid, - const char **out_path, - GError **error) + GDBusMethodInvocation *context, + const char *in_ifcfg) { NMIfcfgConnection *connection; NMSettingConnection *s_con; @@ -709,55 +697,53 @@ impl_ifcfgrh_get_ifcfg_details (SCPluginIfcfg *plugin, const char *path; if (!g_path_is_absolute (in_ifcfg)) { - g_set_error (error, - NM_SETTINGS_ERROR, - NM_SETTINGS_ERROR_INVALID_CONNECTION, - "ifcfg path '%s' is not absolute", in_ifcfg); - return FALSE; + g_dbus_method_invocation_return_error (context, + NM_SETTINGS_ERROR, + NM_SETTINGS_ERROR_INVALID_CONNECTION, + "ifcfg path '%s' is not absolute", in_ifcfg); + return; } connection = find_by_path (plugin, in_ifcfg); if ( !connection || nm_ifcfg_connection_get_unmanaged_spec (connection) || nm_ifcfg_connection_get_unrecognized_spec (connection)) { - g_set_error (error, - NM_SETTINGS_ERROR, - NM_SETTINGS_ERROR_INVALID_CONNECTION, - "ifcfg file '%s' unknown", in_ifcfg); - return FALSE; + g_dbus_method_invocation_return_error (context, + NM_SETTINGS_ERROR, + NM_SETTINGS_ERROR_INVALID_CONNECTION, + "ifcfg file '%s' unknown", in_ifcfg); + return; } s_con = nm_connection_get_setting_connection (NM_CONNECTION (connection)); if (!s_con) { - g_set_error (error, - NM_SETTINGS_ERROR, - NM_SETTINGS_ERROR_FAILED, - "unable to retrieve the connection setting"); - return FALSE; + g_dbus_method_invocation_return_error (context, + NM_SETTINGS_ERROR, + NM_SETTINGS_ERROR_FAILED, + "unable to retrieve the connection setting"); + return; } uuid = nm_setting_connection_get_uuid (s_con); if (!uuid) { - g_set_error (error, - NM_SETTINGS_ERROR, - NM_SETTINGS_ERROR_FAILED, - "unable to get the UUID"); - return FALSE; + g_dbus_method_invocation_return_error (context, + NM_SETTINGS_ERROR, + NM_SETTINGS_ERROR_FAILED, + "unable to get the UUID"); + return; } path = nm_connection_get_path (NM_CONNECTION (connection)); if (!path) { - g_set_error (error, - NM_SETTINGS_ERROR, - NM_SETTINGS_ERROR_FAILED, - "unable to get the connection D-Bus path"); - return FALSE; + g_dbus_method_invocation_return_error (context, + NM_SETTINGS_ERROR, + NM_SETTINGS_ERROR_FAILED, + "unable to get the connection D-Bus path"); + return; } - *out_uuid = g_strdup (uuid); - *out_path = g_strdup (path); - - return TRUE; + g_dbus_method_invocation_return_value (context, + g_variant_new ("(so)", uuid, path)); } static void @@ -770,46 +756,43 @@ sc_plugin_ifcfg_init (SCPluginIfcfg *plugin) { SCPluginIfcfgPrivate *priv = SC_PLUGIN_IFCFG_GET_PRIVATE (plugin); GError *error = NULL; - gboolean success = FALSE; + GDBusConnection *bus; + GVariant *ret; + guint32 result; priv->connections = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); - priv->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); - if (!priv->bus) { + bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); + if (!bus) { _LOGW ("Couldn't connect to D-Bus: %s", error->message); g_clear_error (&error); - } else { - DBusConnection *tmp; - DBusGProxy *proxy; - int result; - - tmp = dbus_g_connection_get_connection (priv->bus); - dbus_connection_set_exit_on_disconnect (tmp, FALSE); - - proxy = dbus_g_proxy_new_for_name (priv->bus, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS); - - if (!dbus_g_proxy_call (proxy, "RequestName", &error, - G_TYPE_STRING, IFCFGRH1_DBUS_SERVICE_NAME, - G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE, - G_TYPE_INVALID, - G_TYPE_UINT, &result, - G_TYPE_INVALID)) { - _LOGW ("Couldn't acquire D-Bus service: %s", error->message); - g_clear_error (&error); - } else if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { - _LOGW ("Couldn't acquire ifcfgrh1 D-Bus service (already taken)"); - } else - success = TRUE; + return; } - if (!success) { - if (priv->bus) { - dbus_g_connection_unref (priv->bus); - priv->bus = NULL; - } + ret = g_dbus_connection_call_sync (bus, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + "RequestName", + g_variant_new ("(su)", + IFCFGRH1_DBUS_SERVICE_NAME, + DBUS_NAME_FLAG_DO_NOT_QUEUE), + G_VARIANT_TYPE ("(u)"), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, &error); + g_object_unref (bus); + if (ret) { + g_variant_get (ret, "(u)", &result); + g_variant_unref (ret); + + if (result == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) + priv->has_dbus_service = TRUE; + else + _LOGW ("Couldn't acquire ifcfgrh1 D-Bus service (already taken)"); + } else { + _LOGW ("Couldn't acquire D-Bus service: %s", error->message); + g_clear_error (&error); } } @@ -819,11 +802,6 @@ dispose (GObject *object) SCPluginIfcfg *plugin = SC_PLUGIN_IFCFG (object); SCPluginIfcfgPrivate *priv = SC_PLUGIN_IFCFG_GET_PRIVATE (plugin); - if (priv->bus) { - dbus_g_connection_unref (priv->bus); - priv->bus = NULL; - } - if (priv->connections) { g_hash_table_destroy (priv->connections); priv->connections = NULL; @@ -875,9 +853,12 @@ static void sc_plugin_ifcfg_class_init (SCPluginIfcfgClass *req_class) { GObjectClass *object_class = G_OBJECT_CLASS (req_class); + NMExportedObjectClass *exported_object_class = NM_EXPORTED_OBJECT_CLASS (req_class); g_type_class_add_private (req_class, sizeof (SCPluginIfcfgPrivate)); + exported_object_class->export_path = IFCFGRH1_DBUS_OBJECT_PATH; + object_class->dispose = dispose; object_class->get_property = get_property; object_class->set_property = set_property; @@ -895,7 +876,9 @@ sc_plugin_ifcfg_class_init (SCPluginIfcfgClass *req_class) NM_SYSTEM_CONFIG_INTERFACE_CAPABILITIES); nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (req_class), - &dbus_glib_nm_ifcfg_rh_object_info); + NMDBUS_TYPE_IFCFGRH1_SKELETON, + "GetIfcfgDetails", impl_ifcfgrh_get_ifcfg_details, + NULL); } static void @@ -920,10 +903,8 @@ nm_system_config_factory (void) if (!singleton) { singleton = SC_PLUGIN_IFCFG (g_object_new (SC_TYPE_PLUGIN_IFCFG, NULL)); priv = SC_PLUGIN_IFCFG_GET_PRIVATE (singleton); - if (priv->bus) - dbus_g_connection_register_g_object (priv->bus, - IFCFGRH1_DBUS_OBJECT_PATH, - G_OBJECT (singleton)); + if (priv->has_dbus_service) + nm_exported_object_export (NM_EXPORTED_OBJECT (singleton)); _LOGD ("Acquired D-Bus service %s", IFCFGRH1_DBUS_SERVICE_NAME); } else g_object_ref (singleton); diff --git a/src/settings/plugins/ifcfg-rh/tests/Makefile.am b/src/settings/plugins/ifcfg-rh/tests/Makefile.am index 505601434b..4ac4eba929 100644 --- a/src/settings/plugins/ifcfg-rh/tests/Makefile.am +++ b/src/settings/plugins/ifcfg-rh/tests/Makefile.am @@ -24,7 +24,6 @@ AM_CPPFLAGS = \ AM_LDFLAGS = \ $(GLIB_LIBS) \ - $(DBUS_LIBS) \ $(CODE_COVERAGE_LDFLAGS) noinst_PROGRAMS = test-ifcfg-rh test-ifcfg-rh-utils From df6706813a698e7a697739b0940bd8f528713aab Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Wed, 15 Apr 2015 14:53:30 -0400 Subject: [PATCH 07/14] settings: port to gdbus --- introspection/nm-agent-manager.xml | 6 - introspection/nm-settings-connection.xml | 14 -- introspection/nm-settings.xml | 13 - src/settings/nm-agent-manager.c | 169 +++++++------ src/settings/nm-agent-manager.h | 4 +- src/settings/nm-secret-agent.c | 274 ++++++++++----------- src/settings/nm-secret-agent.h | 5 +- src/settings/nm-settings-connection.c | 289 ++++++++++------------- src/settings/nm-settings.c | 199 +++++++--------- src/settings/nm-settings.h | 4 +- 10 files changed, 427 insertions(+), 550 deletions(-) diff --git a/introspection/nm-agent-manager.xml b/introspection/nm-agent-manager.xml index d107442860..4b53675cfd 100644 --- a/introspection/nm-agent-manager.xml +++ b/introspection/nm-agent-manager.xml @@ -8,8 +8,6 @@ Called by secret Agents to register their ability to provide and save network secrets. - - Identifies this agent; only one agent in each user session may use the @@ -27,8 +25,6 @@ Like Register() but indicates agent capabilities to NetworkManager. - - See the Register() method's identifier argument. @@ -47,8 +43,6 @@ longer handle requests for network secrets. Agents are automatically unregistered when they disconnect from D-Bus. - - diff --git a/introspection/nm-settings-connection.xml b/introspection/nm-settings-connection.xml index b02762d6be..2d919619fd 100644 --- a/introspection/nm-settings-connection.xml +++ b/introspection/nm-settings-connection.xml @@ -15,8 +15,6 @@ stored in persistent storage or sent to a Secret Agent for storage, depending on the flags associated with each secret. - - New connection settings, properties, and (optionally) secrets. @@ -37,8 +35,6 @@ reloaded from disk (either automatically on file change or due to an explicit ReloadConnections call). - - New connection settings, properties, and (optionally) secrets. @@ -50,8 +46,6 @@ Delete the connection. - - @@ -61,8 +55,6 @@ to the network, as those are often protected. Secrets must be requested separately using the GetSecrets() call. - - The nested settings maps describing this object. @@ -77,8 +69,6 @@ the requestor's session will be returned. The user will never be prompted for secrets as a result of this request. - - Name of the setting to return secrets for. If empty, all @@ -97,8 +87,6 @@ Clear the secrets belonging to this network connection profile. - - @@ -106,8 +94,6 @@ Saves a "dirty" connection (that had previously been updated with UpdateUnsaved) to persistent storage. - - diff --git a/introspection/nm-settings.xml b/introspection/nm-settings.xml index 3a71959cb8..b6ab8260ea 100644 --- a/introspection/nm-settings.xml +++ b/introspection/nm-settings.xml @@ -10,7 +10,6 @@ List the saved network connections known to NetworkManager. - List of connections. @@ -22,8 +21,6 @@ Retrieve the object path of a connection, given that connection's UUID. - - The UUID to find the connection object path for. @@ -43,8 +40,6 @@ the network described by the new connection, and (2) the connection is allowed to be started automatically. - - Connection settings and properties. @@ -69,8 +64,6 @@ connection is reloaded from disk (either automatically on file change or due to an explicit ReloadConnections call). - - Connection settings and properties. @@ -93,8 +86,6 @@ harmless.) As with AddConnection(), this operation does not necessarily start the network connection. - - Array of paths to on-disk connection profiles in directories @@ -125,8 +116,6 @@ change, so you only need to use this command if you have set "monitor-connection-files=false" in NetworkManager.conf. - - Success or failure. @@ -138,8 +127,6 @@ Save the hostname to persistent configuration. - - The hostname to save to persistent configuration. If blank, the persistent hostname is cleared. diff --git a/src/settings/nm-agent-manager.c b/src/settings/nm-agent-manager.c index e1333bab53..087ed5eb1d 100644 --- a/src/settings/nm-agent-manager.c +++ b/src/settings/nm-agent-manager.c @@ -23,16 +23,11 @@ #include #include -#include -#include - #include "nm-default.h" #include "nm-dbus-interface.h" #include "nm-agent-manager.h" #include "nm-secret-agent.h" #include "nm-auth-utils.h" -#include "nm-dbus-glib-types.h" -#include "nm-auth-utils.h" #include "nm-setting-vpn.h" #include "nm-setting-connection.h" #include "nm-enum-types.h" @@ -41,6 +36,9 @@ #include "nm-session-monitor.h" #include "nm-simple-connection.h" #include "NetworkManagerUtils.h" +#include "nm-core-internal.h" + +#include "nmdbus-agent-manager.h" G_DEFINE_TYPE (NMAgentManager, nm_agent_manager, NM_TYPE_EXPORTED_OBJECT) @@ -78,20 +76,6 @@ static void request_remove_agent (Request *req, NMSecretAgent *agent, GSList **p static void request_next_agent (Request *req); -static void impl_agent_manager_register (NMAgentManager *self, - const char *identifier, - DBusGMethodInvocation *context); - -static void impl_agent_manager_register_with_capabilities (NMAgentManager *self, - const char *identifier, - NMSecretAgentCapabilities capabilities, - DBusGMethodInvocation *context); - -static void impl_agent_manager_unregister (NMAgentManager *self, - DBusGMethodInvocation *context); - -#include "nm-agent-manager-glue.h" - /*************************************************************/ static gboolean @@ -130,6 +114,17 @@ remove_agent (NMAgentManager *self, const char *owner) return TRUE; } +/* Call this *after* calling request_next_agent() */ +static void +maybe_remove_agent_on_error (NMSecretAgent *agent, + GError *error) +{ + if ( g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CLOSED) + || g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_DISCONNECTED) + || g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_NAME_HAS_NO_OWNER)) + remove_agent (nm_agent_manager_get (), nm_secret_agent_get_dbus_owner (agent)); +} + /*************************************************************/ static gboolean @@ -190,7 +185,7 @@ validate_identifier (const char *identifier, GError **error) static void agent_register_permissions_done (NMAuthChain *chain, GError *error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, gpointer user_data) { NMAgentManager *self = NM_AGENT_MANAGER (user_data); @@ -211,8 +206,7 @@ agent_register_permissions_done (NMAuthChain *chain, NM_AGENT_MANAGER_ERROR_PERMISSION_DENIED, "Failed to request agent permissions: (%d) %s", error->code, error->message); - dbus_g_method_return_error (context, local); - g_error_free (local); + g_dbus_method_invocation_take_error (context, local); } else { agent = nm_auth_chain_steal_data (chain, "agent"); g_assert (agent); @@ -229,7 +223,7 @@ agent_register_permissions_done (NMAuthChain *chain, g_hash_table_insert (priv->agents, g_strdup (sender), agent); nm_log_dbg (LOGD_AGENTS, "(%s) agent registered", nm_secret_agent_get_description (agent)); - dbus_g_method_return (context); + g_dbus_method_invocation_return_value (context, NULL); /* Signal an agent was registered */ g_signal_emit (self, signals[AGENT_REGISTERED], 0, agent); @@ -271,9 +265,9 @@ agent_disconnected_cb (NMSecretAgent *agent, gpointer user_data) static void impl_agent_manager_register_with_capabilities (NMAgentManager *self, + GDBusMethodInvocation *context, const char *identifier, - NMSecretAgentCapabilities capabilities, - DBusGMethodInvocation *context) + guint32 capabilities) { NMAgentManagerPrivate *priv = NM_AGENT_MANAGER_GET_PRIVATE (self); NMAuthSubject *subject; @@ -334,22 +328,21 @@ impl_agent_manager_register_with_capabilities (NMAgentManager *self, done: if (error) - dbus_g_method_return_error (context, error); - g_clear_error (&error); + g_dbus_method_invocation_take_error (context, error); g_clear_object (&subject); } static void impl_agent_manager_register (NMAgentManager *self, - const char *identifier, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context, + const char *identifier) { - impl_agent_manager_register_with_capabilities (self, identifier, 0, context); + impl_agent_manager_register_with_capabilities (self, context, identifier, 0); } static void impl_agent_manager_unregister (NMAgentManager *self, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context) { GError *error = NULL; char *sender = NULL; @@ -373,19 +366,18 @@ impl_agent_manager_unregister (NMAgentManager *self, goto done; } - dbus_g_method_return (context); + g_dbus_method_invocation_return_value (context, NULL); done: if (error) - dbus_g_method_return_error (context, error); - g_clear_error (&error); + g_dbus_method_invocation_take_error (context, error); g_free (sender); } /*************************************************************/ typedef void (*RequestCompleteFunc) (Request *req, - GHashTable *secrets, + GVariant *secrets, const char *agent_dbus_owner, const char *agent_username, GError *error, @@ -481,7 +473,7 @@ request_free (Request *req) static void req_complete_success (Request *req, - GHashTable *secrets, + GVariant *secrets, const char *agent_dbus_owner, const char *agent_uname) { @@ -658,7 +650,7 @@ typedef struct { char *setting_name; char **hints; - GHashTable *existing_secrets; + GVariant *existing_secrets; NMAgentSecretsResultFunc callback; gpointer callback_data; @@ -682,7 +674,7 @@ connection_request_free (gpointer data) g_free (req->setting_name); g_strfreev (req->hints); if (req->existing_secrets) - g_hash_table_unref (req->existing_secrets); + g_variant_unref (req->existing_secrets); if (req->chain) nm_auth_chain_unref (req->chain); } @@ -710,7 +702,7 @@ connection_request_add_agent (Request *parent, NMSecretAgent *agent) static ConnectionRequest * connection_request_new_get (NMConnection *connection, NMAuthSubject *subject, - GHashTable *existing_secrets, + GVariant *existing_secrets, const char *setting_name, const char *verb, NMSecretAgentGetSecretsFlags flags, @@ -740,7 +732,7 @@ connection_request_new_get (NMConnection *connection, req->connection = g_object_ref (connection); if (existing_secrets) - req->existing_secrets = g_hash_table_ref (existing_secrets); + req->existing_secrets = g_variant_ref (existing_secrets); req->setting_name = g_strdup (setting_name); req->hints = g_strdupv ((char **) hints); req->flags = flags; @@ -779,13 +771,13 @@ connection_request_new_other (NMConnection *connection, static void get_done_cb (NMSecretAgent *agent, gconstpointer call_id, - GHashTable *secrets, + GVariant *secrets, GError *error, gpointer user_data) { Request *parent = user_data; ConnectionRequest *req = user_data; - GHashTable *setting_secrets; + GVariant *setting_secrets; const char *agent_dbus_owner; struct passwd *pw; char *agent_uname = NULL; @@ -799,7 +791,7 @@ get_done_cb (NMSecretAgent *agent, error ? error->code : -1, (error && error->message) ? error->message : "(unknown)"); - if (dbus_g_error_has_name (error, NM_DBUS_INTERFACE_SECRET_AGENT ".UserCanceled")) { + if (_nm_dbus_error_has_name (error, NM_DBUS_INTERFACE_SECRET_AGENT ".UserCanceled")) { error = g_error_new_literal (NM_AGENT_MANAGER_ERROR, NM_AGENT_MANAGER_ERROR_USER_CANCELED, "User canceled the secrets request."); @@ -808,13 +800,14 @@ get_done_cb (NMSecretAgent *agent, } else { /* Try the next agent */ request_next_agent (parent); + maybe_remove_agent_on_error (agent, error); } return; } /* Ensure the setting we wanted secrets for got returned and has something in it */ - setting_secrets = g_hash_table_lookup (secrets, req->setting_name); - if (!setting_secrets || !g_hash_table_size (setting_secrets)) { + setting_secrets = g_variant_lookup_value (secrets, req->setting_name, NM_VARIANT_TYPE_SETTING); + if (!setting_secrets || !g_variant_n_children (setting_secrets)) { nm_log_dbg (LOGD_AGENTS, "(%s) agent returned no secrets for request %p/%s/%s", nm_secret_agent_get_description (agent), req, parent->detail, req->setting_name); @@ -841,40 +834,40 @@ get_done_cb (NMSecretAgent *agent, } static void -set_secrets_not_required (NMConnection *connection, GHashTable *hash) +set_secrets_not_required (NMConnection *connection, GVariant *dict) { - GHashTableIter iter, setting_iter; + GVariantIter iter, setting_iter; const char *setting_name = NULL; - GHashTable *setting_hash = NULL; + GVariant *setting_dict = NULL; - /* Iterate through the settings hashes */ - g_hash_table_iter_init (&iter, hash); - while (g_hash_table_iter_next (&iter, - (gpointer *) &setting_name, - (gpointer *) &setting_hash)) { + /* Iterate through the settings dicts */ + g_variant_iter_init (&iter, dict); + while (g_variant_iter_next (&iter, "{&s@a{sv}}", &setting_name, &setting_dict)) { const char *key_name = NULL; NMSetting *setting; - GValue *val; + GVariant *val; setting = nm_connection_get_setting_by_name (connection, setting_name); if (setting) { /* Now through each secret in the setting and mark it as not required */ - g_hash_table_iter_init (&setting_iter, setting_hash); - while (g_hash_table_iter_next (&setting_iter, (gpointer *) &key_name, (gpointer *) &val)) { + g_variant_iter_init (&setting_iter, setting_dict); + while (g_variant_iter_next (&setting_iter, "{&sv}", &key_name, &val)) { /* For each secret, set the flag that it's not required; VPN * secrets need slightly different treatment here since the - * "secrets" property is actually a hash table of secrets. + * "secrets" property is actually a dictionary of secrets. */ if ( strcmp (setting_name, NM_SETTING_VPN_SETTING_NAME) == 0 - && strcmp (key_name, NM_SETTING_VPN_SECRETS) == 0) { - GHashTableIter vpn_secret_iter; - const char *secret_name; + && strcmp (key_name, NM_SETTING_VPN_SECRETS) == 0 + && g_variant_is_of_type (val, G_VARIANT_TYPE ("a{ss}"))) { + GVariantIter vpn_secret_iter; + const char *secret_name, *secret; - g_hash_table_iter_init (&vpn_secret_iter, g_value_get_boxed (val)); - while (g_hash_table_iter_next (&vpn_secret_iter, (gpointer *) &secret_name, NULL)) + g_variant_iter_init (&vpn_secret_iter, val); + while (g_variant_iter_next (&vpn_secret_iter, "{&s&s}", &secret_name, &secret)) nm_setting_set_secret_flags (setting, secret_name, NM_SETTING_SECRET_FLAG_NOT_REQUIRED, NULL); } else nm_setting_set_secret_flags (setting, key_name, NM_SETTING_SECRET_FLAG_NOT_REQUIRED, NULL); + g_variant_unref (val); } } } @@ -889,13 +882,8 @@ get_agent_request_secrets (ConnectionRequest *req, gboolean include_system_secre tmp = nm_simple_connection_new_clone (req->connection); nm_connection_clear_secrets (tmp); if (include_system_secrets) { - if (req->existing_secrets) { - GVariant *secrets_dict; - - secrets_dict = nm_utils_connection_hash_to_dict (req->existing_secrets); - (void) nm_connection_update_secrets (tmp, req->setting_name, secrets_dict, NULL); - g_variant_unref (secrets_dict); - } + if (req->existing_secrets) + (void) nm_connection_update_secrets (tmp, req->setting_name, req->existing_secrets, NULL); } else { /* Update secret flags in the temporary connection to indicate that * the system secrets we're not sending to the agent aren't required, @@ -924,7 +912,7 @@ get_agent_request_secrets (ConnectionRequest *req, gboolean include_system_secre static void get_agent_modify_auth_cb (NMAuthChain *chain, GError *error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, gpointer user_data) { Request *parent = user_data; @@ -1058,19 +1046,18 @@ get_start (gpointer user_data) { Request *parent = user_data; ConnectionRequest *req = user_data; - GHashTable *setting_secrets = NULL; + GVariant *setting_secrets = NULL; parent->idle_id = 0; /* Check if there are any existing secrets */ if (req->existing_secrets) - setting_secrets = g_hash_table_lookup (req->existing_secrets, req->setting_name); + setting_secrets = g_variant_lookup_value (req->existing_secrets, req->setting_name, NM_VARIANT_TYPE_SETTING); - if (setting_secrets && g_hash_table_size (setting_secrets)) { + if (setting_secrets && g_variant_n_children (setting_secrets)) { NMConnection *tmp; GError *error = NULL; gboolean new_secrets = (req->flags & NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW); - GVariant *secrets_dict; /* The connection already had secrets; check if any more are required. * If no more are required, we're done. If secrets are still needed, @@ -1080,8 +1067,7 @@ get_start (gpointer user_data) tmp = nm_simple_connection_new_clone (req->connection); g_assert (tmp); - secrets_dict = nm_utils_connection_hash_to_dict (req->existing_secrets); - if (!nm_connection_update_secrets (tmp, req->setting_name, secrets_dict, &error)) { + if (!nm_connection_update_secrets (tmp, req->setting_name, req->existing_secrets, &error)) { req_complete_error (parent, error); g_clear_error (&error); } else { @@ -1107,7 +1093,6 @@ get_start (gpointer user_data) request_next_agent (parent); } } - g_variant_unref (secrets_dict); g_object_unref (tmp); } else { /* Couldn't get secrets from system settings, so now we ask the @@ -1117,12 +1102,15 @@ get_start (gpointer user_data) request_next_agent (parent); } + if (setting_secrets) + g_variant_unref (setting_secrets); + return FALSE; } static void get_complete_cb (Request *parent, - GHashTable *secrets, + GVariant *secrets, const char *agent_dbus_owner, const char *agent_username, GError *error, @@ -1163,7 +1151,7 @@ guint32 nm_agent_manager_get_secrets (NMAgentManager *self, NMConnection *connection, NMAuthSubject *subject, - GHashTable *existing_secrets, + GVariant *existing_secrets, const char *setting_name, NMSecretAgentGetSecretsFlags flags, const char **hints, @@ -1233,7 +1221,7 @@ nm_agent_manager_cancel_secrets (NMAgentManager *self, static void save_done_cb (NMSecretAgent *agent, gconstpointer call_id, - GHashTable *secrets, + GVariant *secrets, GError *error, gpointer user_data) { @@ -1251,6 +1239,7 @@ save_done_cb (NMSecretAgent *agent, (error && error->message) ? error->message : "(unknown)"); /* Try the next agent */ request_next_agent (parent); + maybe_remove_agent_on_error (agent, error); return; } @@ -1280,7 +1269,7 @@ save_next_cb (Request *parent) static void save_complete_cb (Request *req, - GHashTable *secrets, + GVariant *secrets, const char *agent_dbus_owner, const char *agent_username, GError *error, @@ -1327,7 +1316,7 @@ nm_agent_manager_save_secrets (NMAgentManager *self, static void delete_done_cb (NMSecretAgent *agent, gconstpointer call_id, - GHashTable *secrets, + GVariant *secrets, GError *error, gpointer user_data) { @@ -1347,6 +1336,8 @@ delete_done_cb (NMSecretAgent *agent, /* Tell the next agent to delete secrets */ request_next_agent (req); + if (error) + maybe_remove_agent_on_error (agent, error); } static void @@ -1367,7 +1358,7 @@ delete_next_cb (Request *parent) static void delete_complete_cb (Request *req, - GHashTable *secrets, + GVariant *secrets, const char *agent_dbus_owner, const char *agent_username, GError *error, @@ -1460,7 +1451,7 @@ nm_agent_manager_all_agents_have_capability (NMAgentManager *manager, static void agent_permissions_changed_done (NMAuthChain *chain, GError *error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, gpointer user_data) { NMAgentManager *self = NM_AGENT_MANAGER (user_data); @@ -1609,9 +1600,9 @@ nm_agent_manager_class_init (NMAgentManagerClass *agent_manager_class) G_TYPE_OBJECT); nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (agent_manager_class), - &dbus_glib_nm_agent_manager_object_info); - - dbus_g_error_domain_register (NM_AGENT_MANAGER_ERROR, - NM_DBUS_INTERFACE_AGENT_MANAGER, - NM_TYPE_AGENT_MANAGER_ERROR); + NMDBUS_TYPE_AGENT_MANAGER_SKELETON, + "Register", impl_agent_manager_register, + "RegisterWithCapabilities", impl_agent_manager_register_with_capabilities, + "Unregister", impl_agent_manager_unregister, + NULL); } diff --git a/src/settings/nm-agent-manager.h b/src/settings/nm-agent-manager.h index 4ece8940e0..792ee572d3 100644 --- a/src/settings/nm-agent-manager.h +++ b/src/settings/nm-agent-manager.h @@ -56,7 +56,7 @@ typedef void (*NMAgentSecretsResultFunc) (NMAgentManager *manager, gboolean agent_has_modify, const char *setting_name, NMSecretAgentGetSecretsFlags flags, - GHashTable *secrets, + GVariant *secrets, GError *error, gpointer user_data, gpointer other_data2, @@ -65,7 +65,7 @@ typedef void (*NMAgentSecretsResultFunc) (NMAgentManager *manager, guint32 nm_agent_manager_get_secrets (NMAgentManager *manager, NMConnection *connection, NMAuthSubject *subject, - GHashTable *existing_secrets, + GVariant *existing_secrets, const char *setting_name, NMSecretAgentGetSecretsFlags flags, const char **hints, diff --git a/src/settings/nm-secret-agent.c b/src/settings/nm-secret-agent.c index 43885fee41..c2c220fd41 100644 --- a/src/settings/nm-secret-agent.c +++ b/src/settings/nm-secret-agent.c @@ -23,17 +23,14 @@ #include #include -#include -#include - #include "nm-default.h" #include "nm-dbus-interface.h" #include "nm-secret-agent.h" #include "nm-bus-manager.h" -#include "nm-dbus-glib-types.h" #include "nm-auth-subject.h" #include "nm-simple-connection.h" -#include "NetworkManagerUtils.h" + +#include "nmdbus-secret-agent.h" G_DEFINE_TYPE (NMSecretAgent, nm_secret_agent, G_TYPE_OBJECT) @@ -52,7 +49,7 @@ typedef struct { GSList *permissions; - DBusGProxy *proxy; + NMDBusSecretAgent *proxy; GHashTable *requests; } NMSecretAgentPrivate; @@ -68,7 +65,7 @@ static guint signals[LAST_SIGNAL] = { 0 }; typedef struct { NMSecretAgent *agent; - DBusGProxyCall *call; + GCancellable *cancellable; char *path; char *setting_name; NMSecretAgentCallback callback; @@ -90,6 +87,7 @@ request_new (NMSecretAgent *agent, r->setting_name = g_strdup (setting_name); r->callback = callback; r->callback_data = callback_data; + r->cancellable = g_cancellable_new (); return r; } @@ -98,6 +96,7 @@ request_free (Request *r) { g_free (r->path); g_free (r->setting_name); + g_object_unref (r->cancellable); g_slice_free (Request, r); } @@ -258,25 +257,26 @@ nm_secret_agent_has_permission (NMSecretAgent *agent, const char *permission) /*************************************************************/ static void -get_callback (DBusGProxy *proxy, - DBusGProxyCall *call, - void *user_data) +get_callback (GObject *proxy, + GAsyncResult *result, + gpointer user_data) { Request *r = user_data; NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (r->agent); + GVariant *secrets = NULL; GError *error = NULL; - GHashTable *secrets = NULL; - g_return_if_fail (call == r->call); + if (!g_cancellable_is_cancelled (r->cancellable)) { + nmdbus_secret_agent_call_get_secrets_finish (priv->proxy, &secrets, result, &error); + if (error) + g_dbus_error_strip_remote_error (error); - dbus_g_proxy_end_call (proxy, call, &error, - DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &secrets, - G_TYPE_INVALID); - r->callback (r->agent, r->call, secrets, error, r->callback_data); - if (secrets) - g_hash_table_unref (secrets); - g_clear_error (&error); - g_hash_table_remove (priv->requests, call); + r->callback (r->agent, r, secrets, error, r->callback_data); + g_clear_pointer (&secrets, g_variant_unref); + g_clear_error (&error); + } + + g_hash_table_remove (priv->requests, r); } gconstpointer @@ -289,8 +289,8 @@ nm_secret_agent_get_secrets (NMSecretAgent *self, gpointer callback_data) { NMSecretAgentPrivate *priv; + static const char *no_hints[] = { NULL }; GVariant *dict; - GHashTable *hash; Request *r; g_return_val_if_fail (self != NULL, NULL); @@ -301,123 +301,81 @@ nm_secret_agent_get_secrets (NMSecretAgent *self, g_return_val_if_fail (priv->proxy != NULL, NULL); dict = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL); - hash = nm_utils_connection_dict_to_hash (dict); - g_variant_unref (dict); /* Mask off the private flags if present */ flags &= ~NM_SECRET_AGENT_GET_SECRETS_FLAG_ONLY_SYSTEM; flags &= ~NM_SECRET_AGENT_GET_SECRETS_FLAG_NO_ERRORS; r = request_new (self, nm_connection_get_path (connection), setting_name, callback, callback_data); - r->call = dbus_g_proxy_begin_call_with_timeout (priv->proxy, - "GetSecrets", - get_callback, - r, - NULL, - 120000, /* 120 seconds */ - DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, hash, - DBUS_TYPE_G_OBJECT_PATH, nm_connection_get_path (connection), - G_TYPE_STRING, setting_name, - G_TYPE_STRV, hints, - G_TYPE_UINT, flags, - G_TYPE_INVALID); - g_hash_table_insert (priv->requests, r->call, r); + nmdbus_secret_agent_call_get_secrets (priv->proxy, + dict, + nm_connection_get_path (connection), + setting_name, + hints ? hints : no_hints, + flags, + r->cancellable, + get_callback, r); + g_hash_table_insert (priv->requests, r, r); - g_hash_table_destroy (hash); - return r->call; + return r; } static void -cancel_done (DBusGProxy *proxy, DBusGProxyCall *call_id, void *user_data) +cancel_done (GObject *proxy, GAsyncResult *result, gpointer user_data) { + char *description = user_data; GError *error = NULL; - if (!dbus_g_proxy_end_call (proxy, call_id, &error, G_TYPE_INVALID)) { - nm_log_dbg (LOGD_AGENTS, "(%s): agent failed to cancel secrets: (%d) %s", - (const char *) user_data, - error ? error->code : -1, - error && error->message ? error->message : "(unknown)"); + if (!nmdbus_secret_agent_call_cancel_get_secrets_finish (NMDBUS_SECRET_AGENT (proxy), result, &error)) { + g_dbus_error_strip_remote_error (error); + nm_log_dbg (LOGD_AGENTS, "(%s): agent failed to cancel secrets: %s", + description, error->message); g_clear_error (&error); } + + g_free (description); } void nm_secret_agent_cancel_secrets (NMSecretAgent *self, gconstpointer call) { NMSecretAgentPrivate *priv; - Request *r; + Request *r = (gpointer) call; g_return_if_fail (self != NULL); priv = NM_SECRET_AGENT_GET_PRIVATE (self); g_return_if_fail (priv->proxy != NULL); - - r = g_hash_table_lookup (priv->requests, call); g_return_if_fail (r != NULL); - dbus_g_proxy_cancel_call (priv->proxy, (gpointer) call); + g_cancellable_cancel (r->cancellable); - dbus_g_proxy_begin_call (priv->proxy, - "CancelGetSecrets", - cancel_done, - g_strdup (nm_secret_agent_get_description (self)), - g_free, - DBUS_TYPE_G_OBJECT_PATH, r->path, - G_TYPE_STRING, r->setting_name, - G_TYPE_INVALID); - g_hash_table_remove (priv->requests, call); + nmdbus_secret_agent_call_cancel_get_secrets (priv->proxy, + r->path, r->setting_name, + NULL, + cancel_done, + g_strdup (nm_secret_agent_get_description (self))); } /*************************************************************/ static void -agent_save_delete_cb (DBusGProxy *proxy, - DBusGProxyCall *call, - void *user_data) +agent_save_cb (GObject *proxy, + GAsyncResult *result, + gpointer user_data) { Request *r = user_data; NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (r->agent); GError *error = NULL; - g_return_if_fail (call == r->call); + if (!g_cancellable_is_cancelled (r->cancellable)) { + nmdbus_secret_agent_call_save_secrets_finish (priv->proxy, result, &error); + if (error) + g_dbus_error_strip_remote_error (error); + r->callback (r->agent, r, NULL, error, r->callback_data); + g_clear_error (&error); + } - dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID); - r->callback (r->agent, r->call, NULL, error, r->callback_data); - g_clear_error (&error); - g_hash_table_remove (priv->requests, call); -} - -static gpointer -agent_new_save_delete (NMSecretAgent *self, - NMConnection *connection, - NMConnectionSerializationFlags flags, - const char *method, - NMSecretAgentCallback callback, - gpointer callback_data) -{ - NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self); - GVariant *dict; - GHashTable *hash; - Request *r; - const char *cpath = nm_connection_get_path (connection); - - dict = nm_connection_to_dbus (connection, flags); - hash = nm_utils_connection_dict_to_hash (dict); - g_variant_unref (dict); - - r = request_new (self, cpath, NULL, callback, callback_data); - r->call = dbus_g_proxy_begin_call_with_timeout (priv->proxy, - method, - agent_save_delete_cb, - r, - NULL, - 10000, /* 10 seconds */ - DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, hash, - DBUS_TYPE_G_OBJECT_PATH, cpath, - G_TYPE_INVALID); - g_hash_table_insert (priv->requests, r->call, r); - - g_hash_table_destroy (hash); - return r->call; + g_hash_table_remove (priv->requests, r); } gconstpointer @@ -426,16 +384,46 @@ nm_secret_agent_save_secrets (NMSecretAgent *self, NMSecretAgentCallback callback, gpointer callback_data) { + NMSecretAgentPrivate *priv; + GVariant *dict; + Request *r; + const char *cpath; + g_return_val_if_fail (self != NULL, NULL); g_return_val_if_fail (connection != NULL, NULL); + priv = NM_SECRET_AGENT_GET_PRIVATE (self); + cpath = nm_connection_get_path (connection); + /* Caller should have ensured that only agent-owned secrets exist in 'connection' */ - return agent_new_save_delete (self, - connection, - NM_CONNECTION_SERIALIZE_ALL, - "SaveSecrets", - callback, - callback_data); + dict = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL); + + r = request_new (self, cpath, NULL, callback, callback_data); + nmdbus_secret_agent_call_save_secrets (priv->proxy, + dict, cpath, + NULL, + agent_save_cb, r); + g_hash_table_insert (priv->requests, r, r); + + return r; +} + +static void +agent_delete_cb (GObject *proxy, + GAsyncResult *result, + gpointer user_data) +{ + Request *r = user_data; + NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (r->agent); + GError *error = NULL; + + if (!g_cancellable_is_cancelled (r->cancellable)) { + nmdbus_secret_agent_call_delete_secrets_finish (priv->proxy, result, &error); + r->callback (r->agent, r, NULL, error, r->callback_data); + g_clear_error (&error); + } + + g_hash_table_remove (priv->requests, r); } gconstpointer @@ -444,54 +432,54 @@ nm_secret_agent_delete_secrets (NMSecretAgent *self, NMSecretAgentCallback callback, gpointer callback_data) { + NMSecretAgentPrivate *priv; + GVariant *dict; + Request *r; + const char *cpath; + g_return_val_if_fail (self != NULL, NULL); g_return_val_if_fail (connection != NULL, NULL); + priv = NM_SECRET_AGENT_GET_PRIVATE (self); + cpath = nm_connection_get_path (connection); + /* No secrets sent; agents must be smart enough to track secrets using the UUID or something */ - return agent_new_save_delete (self, - connection, - NM_CONNECTION_SERIALIZE_NO_SECRETS, - "DeleteSecrets", - callback, - callback_data); + dict = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_NO_SECRETS); + + r = request_new (self, cpath, NULL, callback, callback_data); + nmdbus_secret_agent_call_delete_secrets (priv->proxy, + dict, cpath, + NULL, + agent_delete_cb, r); + g_hash_table_insert (priv->requests, r, r); + + return r; } -static void proxy_cleanup (NMSecretAgent *self); - static void -name_owner_changed_cb (NMBusManager *dbus_mgr, - const char *name, - const char *old_owner, - const char *new_owner, +name_owner_changed_cb (GObject *proxy, + GParamSpec *pspec, gpointer user_data) { NMSecretAgent *self = NM_SECRET_AGENT (user_data); NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self); + char *owner; - if (!new_owner && !g_strcmp0 (old_owner, priv->dbus_owner)) - proxy_cleanup (self); -} - -static void -proxy_cleanup (NMSecretAgent *self) -{ - NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self); - - if (priv->proxy) { - g_signal_handlers_disconnect_by_func (priv->proxy, proxy_cleanup, self); + owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (proxy)); + if (!owner) { + g_signal_handlers_disconnect_by_func (priv->proxy, name_owner_changed_cb, self); g_clear_object (&priv->proxy); - - g_signal_handlers_disconnect_by_func (nm_bus_manager_get (), name_owner_changed_cb, self); g_signal_emit (self, signals[DISCONNECTED], 0); g_clear_pointer (&priv->dbus_owner, g_free); - } + } else + g_free (owner); } /*************************************************************/ NMSecretAgent * -nm_secret_agent_new (DBusGMethodInvocation *context, +nm_secret_agent_new (GDBusMethodInvocation *context, NMAuthSubject *subject, const char *identifier, NMSecretAgentCapabilities capabilities) @@ -500,6 +488,7 @@ nm_secret_agent_new (DBusGMethodInvocation *context, NMSecretAgentPrivate *priv; char *hash_str; struct passwd *pw; + GDBusProxy *proxy; g_return_val_if_fail (context != NULL, NULL); g_return_val_if_fail (NM_IS_AUTH_SUBJECT (subject), NULL); @@ -523,18 +512,17 @@ nm_secret_agent_new (DBusGMethodInvocation *context, priv->hash = g_str_hash (hash_str); g_free (hash_str); - priv->proxy = nm_bus_manager_new_proxy (nm_bus_manager_get (), - context, - priv->dbus_owner, - NM_DBUS_PATH_SECRET_AGENT, - NM_DBUS_INTERFACE_SECRET_AGENT); - g_assert (priv->proxy); - g_signal_connect_swapped (priv->proxy, "destroy", - G_CALLBACK (proxy_cleanup), self); - g_signal_connect (nm_bus_manager_get (), - NM_BUS_MANAGER_NAME_OWNER_CHANGED, + proxy = nm_bus_manager_new_proxy (nm_bus_manager_get (), + context, + NMDBUS_TYPE_SECRET_AGENT_PROXY, + priv->dbus_owner, + NM_DBUS_PATH_SECRET_AGENT, + NM_DBUS_INTERFACE_SECRET_AGENT); + g_assert (proxy); + g_signal_connect (proxy, "notify::g-name-owner", G_CALLBACK (name_owner_changed_cb), self); + priv->proxy = NMDBUS_SECRET_AGENT (proxy); return self; } @@ -553,7 +541,7 @@ dispose (GObject *object) { NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (object); - proxy_cleanup (NM_SECRET_AGENT (object)); + g_clear_object (&priv->proxy); g_clear_object (&priv->subject); G_OBJECT_CLASS (nm_secret_agent_parent_class)->dispose (object); diff --git a/src/settings/nm-secret-agent.h b/src/settings/nm-secret-agent.h index aedc3d21f9..7883979d5b 100644 --- a/src/settings/nm-secret-agent.h +++ b/src/settings/nm-secret-agent.h @@ -21,7 +21,6 @@ #ifndef __NETWORKMANAGER_SECRET_AGENT_H__ #define __NETWORKMANAGER_SECRET_AGENT_H__ - #include #include "nm-default.h" @@ -46,7 +45,7 @@ typedef struct { GType nm_secret_agent_get_type (void); -NMSecretAgent *nm_secret_agent_new (DBusGMethodInvocation *context, +NMSecretAgent *nm_secret_agent_new (GDBusMethodInvocation *context, NMAuthSubject *subject, const char *identifier, NMSecretAgentCapabilities capabilities); @@ -78,7 +77,7 @@ gboolean nm_secret_agent_has_permission (NMSecretAgent *agent, typedef void (*NMSecretAgentCallback) (NMSecretAgent *agent, gconstpointer call, - GHashTable *new_secrets, /* NULL for save & delete */ + GVariant *new_secrets, /* NULL for save & delete */ GError *error, gpointer user_data); diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c index b4300e02c5..af5dbe4393 100644 --- a/src/settings/nm-settings-connection.c +++ b/src/settings/nm-settings-connection.c @@ -24,12 +24,10 @@ #include #include -#include #include "nm-default.h" #include "nm-settings-connection.h" #include "nm-session-monitor.h" -#include "nm-dbus-glib-types.h" #include "nm-auth-utils.h" #include "nm-auth-subject.h" #include "nm-agent-manager.h" @@ -37,10 +35,11 @@ #include "nm-core-internal.h" #include "nm-audit-manager.h" +#include "nmdbus-settings-connection.h" + #define SETTINGS_TIMESTAMPS_FILE NMSTATEDIR "/timestamps" #define SETTINGS_SEEN_BSSIDS_FILE NMSTATEDIR "/seen-bssids" - #define _LOG_DOMAIN LOGD_SETTINGS #define _LOG_PREFIX_NAME "settings-connection" @@ -81,33 +80,6 @@ #define _LOGW(...) _LOG (LOGL_WARN , _LOG_DOMAIN, self, __VA_ARGS__) #define _LOGE(...) _LOG (LOGL_ERR , _LOG_DOMAIN, self, __VA_ARGS__) - -static void impl_settings_connection_get_settings (NMSettingsConnection *self, - DBusGMethodInvocation *context); - -static void impl_settings_connection_update (NMSettingsConnection *self, - GHashTable *new_settings, - DBusGMethodInvocation *context); - -static void impl_settings_connection_update_unsaved (NMSettingsConnection *self, - GHashTable *new_settings, - DBusGMethodInvocation *context); - -static void impl_settings_connection_save (NMSettingsConnection *self, - DBusGMethodInvocation *context); - -static void impl_settings_connection_delete (NMSettingsConnection *self, - DBusGMethodInvocation *context); - -static void impl_settings_connection_get_secrets (NMSettingsConnection *self, - const gchar *setting_name, - DBusGMethodInvocation *context); - -static void impl_settings_connection_clear_secrets (NMSettingsConnection *self, - DBusGMethodInvocation *context); - -#include "nm-settings-connection-glue.h" - static void nm_settings_connection_connection_interface_init (NMConnectionInterface *iface); G_DEFINE_TYPE_WITH_CODE (NMSettingsConnection, nm_settings_connection, NM_TYPE_EXPORTED_OBJECT, @@ -183,88 +155,93 @@ typedef struct { typedef gboolean (*ForEachSecretFunc) (NMSettingSecretFlags flags, gpointer user_data); -static void +static GVariant * for_each_secret (NMConnection *self, - GHashTable *secrets, + GVariant *secrets, gboolean remove_non_secrets, ForEachSecretFunc callback, gpointer callback_data) { - GHashTableIter iter; + GVariantBuilder secrets_builder, setting_builder; + GVariantIter secrets_iter, *setting_iter; const char *setting_name; - GHashTable *setting_hash; - /* This function, given a hash of hashes representing new secrets of - * an NMConnection, walks through each toplevel hash (which represents a - * NMSetting), and for each setting, walks through that setting hash's + /* This function, given a dict of dicts representing new secrets of + * an NMConnection, walks through each toplevel dict (which represents a + * NMSetting), and for each setting, walks through that setting dict's * properties. For each property that's a secret, it will check that * secret's flags in the backing NMConnection object, and call a supplied * callback. * * The one complexity is that the VPN setting's 'secrets' property is - * *also* a hash table (since the key/value pairs are arbitrary and known + * *also* a dict (since the key/value pairs are arbitrary and known * only to the VPN plugin itself). That means we have three levels of - * GHashTables that we potentially have to traverse here. When we hit the + * dicts that we potentially have to traverse here. When we hit the * VPN setting's 'secrets' property, we special-case that and iterate over - * each item in that 'secrets' hash table, calling the supplied callback + * each item in that 'secrets' dict, calling the supplied callback * each time. */ - g_return_if_fail (callback); + g_return_val_if_fail (callback, NULL); - /* Walk through the list of setting hashes */ - g_hash_table_iter_init (&iter, secrets); - while (g_hash_table_iter_next (&iter, (gpointer) &setting_name, (gpointer) &setting_hash)) { + g_variant_iter_init (&secrets_iter, secrets); + g_variant_builder_init (&secrets_builder, NM_VARIANT_TYPE_CONNECTION); + while (g_variant_iter_next (&secrets_iter, "{&sa{sv}}", &setting_name, &setting_iter)) { NMSetting *setting; - GHashTableIter secret_iter; const char *secret_name; - GValue *val; + GVariant *val; - if (g_hash_table_size (setting_hash) == 0) - continue; - - /* Get the actual NMSetting from the connection so we can get secret flags - * from the connection data, since flags aren't secrets. What we're - * iterating here is just the secrets, not a whole connection. - */ setting = nm_connection_get_setting_by_name (self, setting_name); - if (setting == NULL) + if (setting == NULL) { + g_variant_iter_free (setting_iter); continue; + } - /* Walk through the list of keys in each setting hash */ - g_hash_table_iter_init (&secret_iter, setting_hash); - while (g_hash_table_iter_next (&secret_iter, (gpointer) &secret_name, (gpointer) &val)) { + g_variant_builder_init (&setting_builder, NM_VARIANT_TYPE_SETTING); + while (g_variant_iter_next (setting_iter, "{sv}", &secret_name, &val)) { NMSettingSecretFlags secret_flags = NM_SETTING_SECRET_FLAG_NONE; /* VPN secrets need slightly different treatment here since the * "secrets" property is actually a hash table of secrets. */ - if (NM_IS_SETTING_VPN (setting) && (g_strcmp0 (secret_name, NM_SETTING_VPN_SECRETS) == 0)) { - GHashTableIter vpn_secrets_iter; + if (NM_IS_SETTING_VPN (setting) && !g_strcmp0 (secret_name, NM_SETTING_VPN_SECRETS)) { + GVariantBuilder vpn_secrets_builder; + GVariantIter vpn_secrets_iter; + const char *vpn_secret_name, *secret; - /* Iterate through each secret from the VPN hash in the overall secrets hash */ - g_hash_table_iter_init (&vpn_secrets_iter, g_value_get_boxed (val)); - while (g_hash_table_iter_next (&vpn_secrets_iter, (gpointer) &secret_name, NULL)) { - secret_flags = NM_SETTING_SECRET_FLAG_NONE; - if (!nm_setting_get_secret_flags (setting, secret_name, &secret_flags, NULL)) { - if (remove_non_secrets) - g_hash_table_iter_remove (&vpn_secrets_iter); + /* Iterate through each secret from the VPN dict in the overall secrets dict */ + g_variant_builder_init (&vpn_secrets_builder, G_VARIANT_TYPE ("a{ss}")); + g_variant_iter_init (&vpn_secrets_iter, val); + while (g_variant_iter_next (&vpn_secrets_iter, "{&s&s}", &vpn_secret_name, &secret)) { + if (!nm_setting_get_secret_flags (setting, vpn_secret_name, &secret_flags, NULL)) { + if (!remove_non_secrets) + g_variant_builder_add (&vpn_secrets_builder, "{ss}", vpn_secret_name, secret); continue; } - if (!callback (secret_flags, callback_data)) - g_hash_table_iter_remove (&vpn_secrets_iter); + + if (callback (secret_flags, callback_data)) + g_variant_builder_add (&vpn_secrets_builder, "{ss}", vpn_secret_name, secret); } + + g_variant_builder_add (&setting_builder, "{sv}", + secret_name, g_variant_builder_end (&vpn_secrets_builder)); } else { if (!nm_setting_get_secret_flags (setting, secret_name, &secret_flags, NULL)) { - if (remove_non_secrets) - g_hash_table_iter_remove (&secret_iter); + if (!remove_non_secrets) + g_variant_builder_add (&setting_builder, "{sv}", secret_name, val); continue; } - if (!callback (secret_flags, callback_data)) - g_hash_table_iter_remove (&secret_iter); + if (callback (secret_flags, callback_data)) + g_variant_builder_add (&setting_builder, "{sv}", secret_name, val); } + g_variant_unref (val); } + + g_variant_iter_free (setting_iter); + g_variant_builder_add (&secrets_builder, "{sa{sv}}", setting_name, &setting_builder); } + + return g_variant_builder_end (&secrets_builder); } typedef gboolean (*FindSecretFunc) (NMSettingSecretFlags flags, @@ -284,22 +261,24 @@ find_secret_for_each_func (NMSettingSecretFlags flags, if (!data->found) data->found = data->find_func (flags, data->find_func_data); - return TRUE; + return FALSE; } static gboolean find_secret (NMConnection *self, - GHashTable *secrets, + GVariant *secrets, FindSecretFunc callback, gpointer callback_data) { FindSecretData data; + GVariant *dummy; data.find_func = callback; data.find_func_data = callback_data; data.found = FALSE; - for_each_secret (self, secrets, FALSE, find_secret_for_each_func, &data); + dummy = for_each_secret (self, secrets, FALSE, find_secret_for_each_func, &data); + g_variant_unref (dummy); return data.found; } @@ -836,7 +815,7 @@ agent_secrets_done_cb (NMAgentManager *manager, gboolean agent_has_modify, const char *setting_name, NMSecretAgentGetSecretsFlags flags, - GHashTable *secrets, + GVariant *secrets, GError *error, gpointer user_data, gpointer other_data2, @@ -925,21 +904,19 @@ agent_secrets_done_cb (NMAgentManager *manager, | NM_SETTING_SECRET_FLAG_NOT_REQUIRED); } - for_each_secret (NM_CONNECTION (self), secrets, TRUE, validate_secret_flags, &cmp_flags); - /* Update the connection with our existing secrets from backing storage */ nm_connection_clear_secrets (NM_CONNECTION (self)); dict = nm_connection_to_dbus (priv->system_secrets, NM_CONNECTION_SERIALIZE_ONLY_SECRETS); if (!dict || nm_connection_update_secrets (NM_CONNECTION (self), setting_name, dict, &local)) { - GVariant *secrets_dict; + GVariant *filtered_secrets; /* Update the connection with the agent's secrets; by this point if any * system-owned secrets exist in 'secrets' the agent that provided them * will have been authenticated, so those secrets can replace the existing * system secrets. */ - secrets_dict = nm_utils_connection_hash_to_dict (secrets); - if (nm_connection_update_secrets (NM_CONNECTION (self), setting_name, secrets_dict, &local)) { + filtered_secrets = for_each_secret (NM_CONNECTION (self), secrets, TRUE, validate_secret_flags, &cmp_flags); + if (nm_connection_update_secrets (NM_CONNECTION (self), setting_name, filtered_secrets, &local)) { /* Now that all secrets are updated, copy and cache new secrets, * then save them to backing storage. */ @@ -962,6 +939,8 @@ agent_secrets_done_cb (NMAgentManager *manager, setting_name, call_id); } + + g_variant_unref (filtered_secrets); } else { _LOGD ("(%s:%u) failed to update with agent secrets: (%d) %s", setting_name, @@ -969,7 +948,6 @@ agent_secrets_done_cb (NMAgentManager *manager, local ? local->code : -1, (local && local->message) ? local->message : "(unknown)"); } - g_variant_unref (secrets_dict); } else { _LOGD ("(%s:%u) failed to update with existing secrets: (%d) %s", setting_name, @@ -1012,7 +990,6 @@ nm_settings_connection_get_secrets (NMSettingsConnection *self, { NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); GVariant *existing_secrets; - GHashTable *existing_secrets_hash; guint32 call_id = 0; gs_free char *joined_hints = NULL; @@ -1035,11 +1012,12 @@ nm_settings_connection_get_secrets (NMSettingsConnection *self, } existing_secrets = nm_connection_to_dbus (priv->system_secrets, NM_CONNECTION_SERIALIZE_ONLY_SECRETS); - existing_secrets_hash = nm_utils_connection_dict_to_hash (existing_secrets); + if (existing_secrets) + g_variant_ref_sink (existing_secrets); call_id = nm_agent_manager_get_secrets (priv->agent_mgr, NM_CONNECTION (self), subject, - existing_secrets_hash, + existing_secrets, setting_name, flags, hints, @@ -1047,8 +1025,6 @@ nm_settings_connection_get_secrets (NMSettingsConnection *self, self, callback, callback_data); - if (existing_secrets_hash) - g_hash_table_unref (existing_secrets_hash); if (existing_secrets) g_variant_unref (existing_secrets); @@ -1077,7 +1053,7 @@ nm_settings_connection_cancel_secrets (NMSettingsConnection *self, /**** User authorization **************************************/ typedef void (*AuthCallback) (NMSettingsConnection *self, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, NMAuthSubject *subject, GError *error, gpointer data); @@ -1085,7 +1061,7 @@ typedef void (*AuthCallback) (NMSettingsConnection *self, static void pk_auth_cb (NMAuthChain *chain, GError *chain_error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, gpointer user_data) { NMSettingsConnection *self = NM_SETTINGS_CONNECTION (user_data); @@ -1134,7 +1110,7 @@ pk_auth_cb (NMAuthChain *chain, * Returns: the #NMAuthSubject on success, or %NULL on failure and sets @error */ static NMAuthSubject * -_new_auth_subject (DBusGMethodInvocation *context, GError **error) +_new_auth_subject (GDBusMethodInvocation *context, GError **error) { NMAuthSubject *subject; @@ -1151,7 +1127,7 @@ _new_auth_subject (DBusGMethodInvocation *context, GError **error) static void auth_start (NMSettingsConnection *self, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, NMAuthSubject *subject, const char *check_permission, AuthCallback callback, @@ -1239,16 +1215,15 @@ check_writable (NMConnection *self, GError **error) static void get_settings_auth_cb (NMSettingsConnection *self, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, NMAuthSubject *subject, GError *error, gpointer data) { if (error) - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); else { GVariant *settings; - GHashTable *settings_hash; NMConnection *dupl_con; NMSettingConnection *s_con; NMSettingWireless *s_wifi; @@ -1286,17 +1261,15 @@ get_settings_auth_cb (NMSettingsConnection *self, */ settings = nm_connection_to_dbus (NM_CONNECTION (dupl_con), NM_CONNECTION_SERIALIZE_NO_SECRETS); g_assert (settings); - settings_hash = nm_utils_connection_dict_to_hash (settings); - dbus_g_method_return (context, settings_hash); - g_hash_table_destroy (settings_hash); - g_variant_unref (settings); + g_dbus_method_invocation_return_value (context, + g_variant_new ("(@a{sa{sv}})", settings)); g_object_unref (dupl_con); } } static void impl_settings_connection_get_settings (NMSettingsConnection *self, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context) { NMAuthSubject *subject; GError *error = NULL; @@ -1305,14 +1278,12 @@ impl_settings_connection_get_settings (NMSettingsConnection *self, if (subject) { auth_start (self, context, subject, NULL, get_settings_auth_cb, NULL); g_object_unref (subject); - } else { - dbus_g_method_return_error (context, error); - g_error_free (error); - } + } else + g_dbus_method_invocation_take_error (context, error); } typedef struct { - DBusGMethodInvocation *context; + GDBusMethodInvocation *context; NMAgentManager *agent_mgr; NMAuthSubject *subject; NMConnection *new_settings; @@ -1320,7 +1291,7 @@ typedef struct { } UpdateInfo; typedef struct { - DBusGMethodInvocation *context; + GDBusMethodInvocation *context; NMAuthSubject *subject; } CallbackInfo; @@ -1384,9 +1355,9 @@ update_complete (NMSettingsConnection *self, GError *error) { if (error) - dbus_g_method_return_error (info->context, error); + g_dbus_method_invocation_return_gerror (info->context, error); else - dbus_g_method_return (info->context); + g_dbus_method_invocation_return_value (info->context, NULL); nm_audit_log_connection_op (NM_AUDIT_OP_CONN_UPDATE, NM_CONNECTION (self), !error, info->subject, error ? error->message : NULL); @@ -1424,7 +1395,7 @@ con_update_cb (NMSettingsConnection *self, static void update_auth_cb (NMSettingsConnection *self, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, NMAuthSubject *subject, GError *error, gpointer data) @@ -1492,8 +1463,8 @@ get_update_modify_permission (NMConnection *old, NMConnection *new) static void impl_settings_connection_update_helper (NMSettingsConnection *self, - GHashTable *new_settings, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, + GVariant *new_settings, gboolean save_to_disk) { NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); @@ -1515,14 +1486,9 @@ impl_settings_connection_update_helper (NMSettingsConnection *self, /* Check if the settings are valid first */ if (new_settings) { - GVariant *new_settings_dict = nm_utils_connection_hash_to_dict (new_settings); - - tmp = nm_simple_connection_new_from_dbus (new_settings_dict, &error); - g_variant_unref (new_settings_dict); - if (!tmp) { - g_assert (error); + tmp = nm_simple_connection_new_from_dbus (new_settings, &error); + if (!tmp) goto error; - } } subject = _new_auth_subject (context, &error); @@ -1562,37 +1528,34 @@ error: g_clear_object (&tmp); g_clear_object (&subject); - dbus_g_method_return_error (context, error); - g_clear_error (&error); + g_dbus_method_invocation_take_error (context, error); } static void impl_settings_connection_update (NMSettingsConnection *self, - GHashTable *new_settings, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context, + GVariant *new_settings) { - g_assert (new_settings); - impl_settings_connection_update_helper (self, new_settings, context, TRUE); + impl_settings_connection_update_helper (self, context, new_settings, TRUE); } static void impl_settings_connection_update_unsaved (NMSettingsConnection *self, - GHashTable *new_settings, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context, + GVariant *new_settings) { - g_assert (new_settings); - impl_settings_connection_update_helper (self, new_settings, context, FALSE); + impl_settings_connection_update_helper (self, context, new_settings, FALSE); } static void impl_settings_connection_save (NMSettingsConnection *self, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context) { /* Do nothing if the connection is already synced with disk */ if (nm_settings_connection_get_unsaved (self)) - impl_settings_connection_update_helper (self, NULL, context, TRUE); + impl_settings_connection_update_helper (self, context, NULL, TRUE); else - dbus_g_method_return (context); + g_dbus_method_invocation_return_value (context, NULL); } static void @@ -1603,9 +1566,9 @@ con_delete_cb (NMSettingsConnection *self, CallbackInfo *info = user_data; if (error) - dbus_g_method_return_error (info->context, error); + g_dbus_method_invocation_return_gerror (info->context, error); else - dbus_g_method_return (info->context); + g_dbus_method_invocation_return_value (info->context, NULL); nm_audit_log_connection_op (NM_AUDIT_OP_CONN_DELETE, NM_CONNECTION (self), !error, info->subject, error ? error->message : NULL); @@ -1614,7 +1577,7 @@ con_delete_cb (NMSettingsConnection *self, static void delete_auth_cb (NMSettingsConnection *self, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, NMAuthSubject *subject, GError *error, gpointer data) @@ -1624,7 +1587,7 @@ delete_auth_cb (NMSettingsConnection *self, if (error) { nm_audit_log_connection_op (NM_AUDIT_OP_CONN_DELETE, NM_CONNECTION (self), FALSE, subject, error->message); - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); return; } @@ -1654,7 +1617,7 @@ get_modify_permission_basic (NMSettingsConnection *self) static void impl_settings_connection_delete (NMSettingsConnection *self, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context) { NMAuthSubject *subject = NULL; GError *error = NULL; @@ -1671,9 +1634,8 @@ impl_settings_connection_delete (NMSettingsConnection *self, return; out_err: - dbus_g_method_return_error (context, error); nm_audit_log_connection_op (NM_AUDIT_OP_CONN_DELETE, NM_CONNECTION (self), FALSE, subject, error->message); - g_error_free (error); + g_dbus_method_invocation_take_error (context, error); } /**************************************************************/ @@ -1687,14 +1649,13 @@ dbus_get_agent_secrets_cb (NMSettingsConnection *self, gpointer user_data) { NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); - DBusGMethodInvocation *context = user_data; + GDBusMethodInvocation *context = user_data; GVariant *dict; - GHashTable *hash; priv->reqs = g_slist_remove (priv->reqs, GUINT_TO_POINTER (call_id)); if (error) - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); else { /* Return secrets from agent and backing storage to the D-Bus caller; * nm_settings_connection_get_secrets() will have updated itself with @@ -1702,20 +1663,15 @@ dbus_get_agent_secrets_cb (NMSettingsConnection *self, * by the time we get here. */ dict = nm_connection_to_dbus (NM_CONNECTION (self), NM_CONNECTION_SERIALIZE_ONLY_SECRETS); - if (dict) - hash = nm_utils_connection_dict_to_hash (dict); - else - hash = g_hash_table_new (NULL, NULL); - dbus_g_method_return (context, hash); - g_hash_table_destroy (hash); - if (dict) - g_variant_unref (dict); + if (!dict) + dict = g_variant_new_array (G_VARIANT_TYPE ("{sa{sv}}"), NULL, 0); + g_dbus_method_invocation_return_value (context, g_variant_new ("(@a{s{a{sv}}})", dict)); } } static void dbus_get_secrets_auth_cb (NMSettingsConnection *self, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, NMAuthSubject *subject, GError *error, gpointer user_data) @@ -1742,7 +1698,7 @@ dbus_get_secrets_auth_cb (NMSettingsConnection *self, } if (error || local) { - dbus_g_method_return_error (context, error ? error : local); + g_dbus_method_invocation_return_gerror (context, error ? error : local); g_clear_error (&local); } @@ -1751,8 +1707,8 @@ dbus_get_secrets_auth_cb (NMSettingsConnection *self, static void impl_settings_connection_get_secrets (NMSettingsConnection *self, - const gchar *setting_name, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context, + const gchar *setting_name) { NMAuthSubject *subject; GError *error = NULL; @@ -1766,10 +1722,8 @@ impl_settings_connection_get_secrets (NMSettingsConnection *self, dbus_get_secrets_auth_cb, g_strdup (setting_name)); g_object_unref (subject); - } else { - dbus_g_method_return_error (context, error); - g_error_free (error); - } + } else + g_dbus_method_invocation_take_error (context, error); } static void @@ -1780,9 +1734,9 @@ clear_secrets_cb (NMSettingsConnection *self, CallbackInfo *info = user_data; if (error) - dbus_g_method_return_error (info->context, error); + g_dbus_method_invocation_return_gerror (info->context, error); else - dbus_g_method_return (info->context); + g_dbus_method_invocation_return_value (info->context, NULL); nm_audit_log_connection_op (NM_AUDIT_OP_CONN_CLEAR_SECRETS, NM_CONNECTION (self), !error, info->subject, error ? error->message : NULL); @@ -1791,7 +1745,7 @@ clear_secrets_cb (NMSettingsConnection *self, static void dbus_clear_secrets_auth_cb (NMSettingsConnection *self, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, NMAuthSubject *subject, GError *error, gpointer user_data) @@ -1800,7 +1754,7 @@ dbus_clear_secrets_auth_cb (NMSettingsConnection *self, CallbackInfo *info; if (error) { - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); nm_audit_log_connection_op (NM_AUDIT_OP_CONN_CLEAR_SECRETS, NM_CONNECTION (self), FALSE, subject, error->message); } else { @@ -1824,7 +1778,7 @@ dbus_clear_secrets_auth_cb (NMSettingsConnection *self, static void impl_settings_connection_clear_secrets (NMSettingsConnection *self, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context) { NMAuthSubject *subject; GError *error = NULL; @@ -1839,10 +1793,9 @@ impl_settings_connection_clear_secrets (NMSettingsConnection *self, NULL); g_object_unref (subject); } else { - dbus_g_method_return_error (context, error); nm_audit_log_connection_op (NM_AUDIT_OP_CONN_CLEAR_SECRETS, NM_CONNECTION (self), FALSE, NULL, error->message); - g_error_free (error); + g_dbus_method_invocation_take_error (context, error); } } @@ -2586,7 +2539,15 @@ nm_settings_connection_class_init (NMSettingsConnectionClass *class) G_TYPE_NONE, 0); nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (class), - &dbus_glib_nm_settings_connection_object_info); + NMDBUS_TYPE_SETTINGS_CONNECTION_SKELETON, + "Update", impl_settings_connection_update, + "UpdateUnsaved", impl_settings_connection_update_unsaved, + "Delete", impl_settings_connection_delete, + "GetSettings", impl_settings_connection_get_settings, + "GetSecrets", impl_settings_connection_get_secrets, + "ClearSecrets", impl_settings_connection_clear_secrets, + "Save", impl_settings_connection_save, + NULL); } static void diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c index 0988e1cc0e..a7b37d5a1a 100644 --- a/src/settings/nm-settings.c +++ b/src/settings/nm-settings.c @@ -31,8 +31,6 @@ #include #include #include -#include -#include #if HAVE_SELINUX #include @@ -61,7 +59,6 @@ #include "nm-core-internal.h" #include "nm-device-ethernet.h" -#include "nm-dbus-glib-types.h" #include "nm-settings.h" #include "nm-settings-connection.h" #include "nm-system-config-interface.h" @@ -78,6 +75,8 @@ #include "NetworkManagerUtils.h" #include "nm-dispatcher.h" +#include "nmdbus-settings.h" + #define LOG(level, ...) \ G_STMT_START { \ nm_log ((level), LOGD_CORE, \ @@ -122,35 +121,6 @@ EXPORT(nm_settings_connection_replace_and_commit) static void claim_connection (NMSettings *self, NMSettingsConnection *connection); -static gboolean impl_settings_list_connections (NMSettings *self, - GPtrArray **connections, - GError **error); - -static void impl_settings_get_connection_by_uuid (NMSettings *self, - const char *uuid, - DBusGMethodInvocation *context); - -static void impl_settings_add_connection (NMSettings *self, - GHashTable *settings, - DBusGMethodInvocation *context); - -static void impl_settings_add_connection_unsaved (NMSettings *self, - GHashTable *settings, - DBusGMethodInvocation *context); - -static void impl_settings_load_connections (NMSettings *self, - char **filenames, - DBusGMethodInvocation *context); - -static void impl_settings_reload_connections (NMSettings *self, - DBusGMethodInvocation *context); - -static void impl_settings_save_hostname (NMSettings *self, - const char *hostname, - DBusGMethodInvocation *context); - -#include "nm-settings-glue.h" - static void unmanaged_specs_changed (NMSystemConfigInterface *config, gpointer user_data); static void unrecognized_specs_changed (NMSystemConfigInterface *config, gpointer user_data); @@ -161,8 +131,6 @@ G_DEFINE_TYPE_EXTENDED (NMSettings, nm_settings, NM_TYPE_EXPORTED_OBJECT, 0, typedef struct { - NMBusManager *dbus_mgr; - NMAgentManager *agent_mgr; NMConfig *config; @@ -310,20 +278,24 @@ nm_settings_for_each_connection (NMSettings *self, for_each_func (self, NM_SETTINGS_CONNECTION (data), user_data); } -static gboolean +static void impl_settings_list_connections (NMSettings *self, - GPtrArray **connections, - GError **error) + GDBusMethodInvocation *context) { NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); + GPtrArray *connections; GHashTableIter iter; gpointer key; - *connections = g_ptr_array_sized_new (g_hash_table_size (priv->connections) + 1); + connections = g_ptr_array_sized_new (g_hash_table_size (priv->connections) + 1); g_hash_table_iter_init (&iter, priv->connections); while (g_hash_table_iter_next (&iter, &key, NULL)) - g_ptr_array_add (*connections, g_strdup ((const char *) key)); - return TRUE; + g_ptr_array_add (connections, key); + g_ptr_array_add (connections, NULL); + + g_dbus_method_invocation_return_value (context, + g_variant_new ("(^ao)", connections->pdata)); + g_ptr_array_unref (connections); } NMSettingsConnection * @@ -349,8 +321,8 @@ nm_settings_get_connection_by_uuid (NMSettings *self, const char *uuid) static void impl_settings_get_connection_by_uuid (NMSettings *self, - const char *uuid, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context, + const char *uuid) { NMSettingsConnection *connection = NULL; NMAuthSubject *subject = NULL; @@ -384,13 +356,14 @@ impl_settings_get_connection_by_uuid (NMSettings *self, } g_clear_object (&subject); - dbus_g_method_return (context, nm_connection_get_path (NM_CONNECTION (connection))); + g_dbus_method_invocation_return_value ( + context, + g_variant_new ("(o)", nm_connection_get_path (NM_CONNECTION (connection)))); return; error: g_assert (error); - dbus_g_method_return_error (context, error); - g_error_free (error); + g_dbus_method_invocation_take_error (context, error); g_clear_object (&subject); } @@ -1189,7 +1162,7 @@ send_agent_owned_secrets (NMSettings *self, static void pk_add_cb (NMAuthChain *chain, GError *chain_error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, gpointer user_data) { NMSettings *self = NM_SETTINGS (user_data); @@ -1277,11 +1250,11 @@ is_adhoc_wpa (NMConnection *connection) void nm_settings_add_connection_dbus (NMSettings *self, - NMConnection *connection, - gboolean save_to_disk, - DBusGMethodInvocation *context, - NMSettingsAddCallback callback, - gpointer user_data) + NMConnection *connection, + gboolean save_to_disk, + GDBusMethodInvocation *context, + NMSettingsAddCallback callback, + gpointer user_data) { NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); NMSettingConnection *s_con; @@ -1385,15 +1358,17 @@ static void impl_settings_add_connection_add_cb (NMSettings *self, NMSettingsConnection *connection, GError *error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, NMAuthSubject *subject, gpointer user_data) { if (error) { - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); nm_audit_log_connection_op (NM_AUDIT_OP_CONN_ADD, NULL, FALSE, subject, error->message); } else { - dbus_g_method_return (context, nm_connection_get_path (NM_CONNECTION (connection))); + g_dbus_method_invocation_return_value ( + context, + g_variant_new ("(o)", nm_connection_get_path (NM_CONNECTION (connection)))); nm_audit_log_connection_op (NM_AUDIT_OP_CONN_ADD, NM_CONNECTION (connection), TRUE, subject, NULL); } @@ -1401,17 +1376,14 @@ impl_settings_add_connection_add_cb (NMSettings *self, static void impl_settings_add_connection_helper (NMSettings *self, - GHashTable *settings, - gboolean save_to_disk, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context, + GVariant *settings, + gboolean save_to_disk) { NMConnection *connection; - GVariant *dict; GError *error = NULL; - dict = nm_utils_connection_hash_to_dict (settings); - connection = nm_simple_connection_new_from_dbus (dict, &error); - g_variant_unref (dict); + connection = nm_simple_connection_new_from_dbus (settings, &error); if (connection) { nm_settings_add_connection_dbus (self, connection, @@ -1422,30 +1394,29 @@ impl_settings_add_connection_helper (NMSettings *self, g_object_unref (connection); } else { g_assert (error); - dbus_g_method_return_error (context, error); - g_error_free (error); + g_dbus_method_invocation_take_error (context, error); } } static void impl_settings_add_connection (NMSettings *self, - GHashTable *settings, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context, + GVariant *settings) { - impl_settings_add_connection_helper (self, settings, TRUE, context); + impl_settings_add_connection_helper (self, context, settings, TRUE); } static void impl_settings_add_connection_unsaved (NMSettings *self, - GHashTable *settings, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context, + GVariant *settings) { - impl_settings_add_connection_helper (self, settings, FALSE, context); + impl_settings_add_connection_helper (self, context, settings, FALSE); } static gboolean ensure_root (NMBusManager *dbus_mgr, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context) { gulong caller_uid; GError *error = NULL; @@ -1454,16 +1425,14 @@ ensure_root (NMBusManager *dbus_mgr, error = g_error_new_literal (NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_PERMISSION_DENIED, "Unable to determine request UID."); - dbus_g_method_return_error (context, error); - g_error_free (error); + g_dbus_method_invocation_take_error (context, error); return FALSE; } if (caller_uid != 0) { error = g_error_new_literal (NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_PERMISSION_DENIED, "Permission denied"); - dbus_g_method_return_error (context, error); - g_error_free (error); + g_dbus_method_invocation_take_error (context, error); return FALSE; } @@ -1472,15 +1441,15 @@ ensure_root (NMBusManager *dbus_mgr, static void impl_settings_load_connections (NMSettings *self, - char **filenames, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context, + char **filenames) { NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); GPtrArray *failures; GSList *iter; int i; - if (!ensure_root (priv->dbus_mgr, context)) + if (!ensure_root (nm_bus_manager_get (), context)) return; failures = g_ptr_array_new (); @@ -1501,18 +1470,22 @@ impl_settings_load_connections (NMSettings *self, } g_ptr_array_add (failures, NULL); - dbus_g_method_return (context, failures->len == 1, failures->pdata); + g_dbus_method_invocation_return_value ( + context, + g_variant_new ("(b^as)", + failures->len == 1, + failures->pdata)); g_ptr_array_unref (failures); } static void impl_settings_reload_connections (NMSettings *self, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context) { NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); GSList *iter; - if (!ensure_root (priv->dbus_mgr, context)) + if (!ensure_root (nm_bus_manager_get (), context)) return; for (iter = priv->plugins; iter; iter = g_slist_next (iter)) { @@ -1521,7 +1494,7 @@ impl_settings_reload_connections (NMSettings *self, nm_system_config_interface_reload_connections (plugin); } - dbus_g_method_return (context, TRUE); + g_dbus_method_invocation_return_value (context, g_variant_new ("(b)", TRUE)); } static gboolean @@ -1594,7 +1567,7 @@ write_hostname (NMSettingsPrivate *priv, const char *hostname) static void pk_hostname_cb (NMAuthChain *chain, GError *chain_error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, gpointer user_data) { NMSettings *self = NM_SETTINGS (user_data); @@ -1630,11 +1603,10 @@ pk_hostname_cb (NMAuthChain *chain, } if (error) - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_take_error (context, error); else - dbus_g_method_return (context); + g_dbus_method_invocation_return_value (context, NULL); - g_clear_error (&error); nm_auth_chain_unref (chain); } @@ -1667,8 +1639,8 @@ validate_hostname (const char *hostname) static void impl_settings_save_hostname (NMSettings *self, - const char *hostname, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context, + const char *hostname) { NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); NMAuthChain *chain; @@ -1696,8 +1668,7 @@ impl_settings_save_hostname (NMSettings *self, done: if (error) - dbus_g_method_return_error (context, error); - g_clear_error (&error); + g_dbus_method_invocation_take_error (context, error); } static void @@ -2108,7 +2079,6 @@ nm_settings_new (void) priv = NM_SETTINGS_GET_PRIVATE (self); priv->config = nm_config_get (); - priv->dbus_mgr = nm_bus_manager_get (); nm_exported_object_export (NM_EXPORTED_OBJECT (self)); return self; @@ -2198,8 +2168,6 @@ dispose (GObject *object) g_slist_free_full (priv->auths, (GDestroyNotify) nm_auth_chain_unref); priv->auths = NULL; - priv->dbus_mgr = NULL; - g_object_unref (priv->agent_mgr); if (priv->hostname.hostnamed_proxy) { @@ -2255,17 +2223,18 @@ get_property (GObject *object, guint prop_id, NMSettings *self = NM_SETTINGS (object); NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); const GSList *specs, *iter; - GSList *copy = NULL; GHashTableIter citer; GPtrArray *array; const char *path; switch (prop_id) { case PROP_UNMANAGED_SPECS: + array = g_ptr_array_new (); specs = nm_settings_get_unmanaged_specs (self); for (iter = specs; iter; iter = g_slist_next (iter)) - copy = g_slist_append (copy, g_strdup (iter->data)); - g_value_take_boxed (value, copy); + g_ptr_array_add (array, g_strdup (iter->data)); + g_ptr_array_add (array, NULL); + g_value_take_boxed (value, (char **) g_ptr_array_free (array, FALSE)); break; case PROP_HOSTNAME: g_value_take_string (value, nm_settings_get_hostname (self)); @@ -2278,11 +2247,12 @@ get_property (GObject *object, guint prop_id, g_value_set_boolean (value, !!get_plugin (self, NM_SYSTEM_CONFIG_INTERFACE_CAP_MODIFY_CONNECTIONS)); break; case PROP_CONNECTIONS: - array = g_ptr_array_sized_new (g_hash_table_size (priv->connections)); + array = g_ptr_array_sized_new (g_hash_table_size (priv->connections) + 1); g_hash_table_iter_init (&citer, priv->connections); while (g_hash_table_iter_next (&citer, (gpointer) &path, NULL)) g_ptr_array_add (array, g_strdup (path)); - g_value_take_boxed (value, array); + g_ptr_array_add (array, NULL); + g_value_take_boxed (value, (char **) g_ptr_array_free (array, FALSE)); break; case PROP_STARTUP_COMPLETE: g_value_set_boolean (value, nm_settings_get_startup_complete (self)); @@ -2313,7 +2283,7 @@ nm_settings_class_init (NMSettingsClass *class) g_object_class_install_property (object_class, PROP_UNMANAGED_SPECS, g_param_spec_boxed (NM_SETTINGS_UNMANAGED_SPECS, "", "", - DBUS_TYPE_G_LIST_OF_STRING, + G_TYPE_STRV, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); @@ -2334,7 +2304,7 @@ nm_settings_class_init (NMSettingsClass *class) g_object_class_install_property (object_class, PROP_CONNECTIONS, g_param_spec_boxed (NM_SETTINGS_CONNECTIONS, "", "", - DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH, + G_TYPE_STRV, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); @@ -2346,7 +2316,7 @@ nm_settings_class_init (NMSettingsClass *class) G_STRUCT_OFFSET (NMSettingsClass, connection_added), NULL, NULL, g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, G_TYPE_OBJECT); + G_TYPE_NONE, 1, NM_TYPE_SETTINGS_CONNECTION); signals[CONNECTION_UPDATED] = g_signal_new (NM_SETTINGS_SIGNAL_CONNECTION_UPDATED, @@ -2355,7 +2325,7 @@ nm_settings_class_init (NMSettingsClass *class) G_STRUCT_OFFSET (NMSettingsClass, connection_updated), NULL, NULL, g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, G_TYPE_OBJECT); + G_TYPE_NONE, 1, NM_TYPE_SETTINGS_CONNECTION); signals[CONNECTION_UPDATED_BY_USER] = g_signal_new (NM_SETTINGS_SIGNAL_CONNECTION_UPDATED_BY_USER, @@ -2364,7 +2334,7 @@ nm_settings_class_init (NMSettingsClass *class) 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, G_TYPE_OBJECT); + G_TYPE_NONE, 1, NM_TYPE_SETTINGS_CONNECTION); signals[CONNECTION_REMOVED] = g_signal_new (NM_SETTINGS_SIGNAL_CONNECTION_REMOVED, @@ -2373,7 +2343,7 @@ nm_settings_class_init (NMSettingsClass *class) G_STRUCT_OFFSET (NMSettingsClass, connection_removed), NULL, NULL, g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, G_TYPE_OBJECT); + G_TYPE_NONE, 1, NM_TYPE_SETTINGS_CONNECTION); signals[CONNECTION_VISIBILITY_CHANGED] = g_signal_new (NM_SETTINGS_SIGNAL_CONNECTION_VISIBILITY_CHANGED, @@ -2382,7 +2352,7 @@ nm_settings_class_init (NMSettingsClass *class) G_STRUCT_OFFSET (NMSettingsClass, connection_visibility_changed), NULL, NULL, g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, G_TYPE_OBJECT); + G_TYPE_NONE, 1, NM_TYPE_SETTINGS_CONNECTION); signals[AGENT_REGISTERED] = g_signal_new (NM_SETTINGS_SIGNAL_AGENT_REGISTERED, @@ -2391,7 +2361,7 @@ nm_settings_class_init (NMSettingsClass *class) G_STRUCT_OFFSET (NMSettingsClass, agent_registered), NULL, NULL, g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, G_TYPE_OBJECT); + G_TYPE_NONE, 1, NM_TYPE_SECRET_AGENT); signals[NEW_CONNECTION] = @@ -2399,16 +2369,17 @@ nm_settings_class_init (NMSettingsClass *class) G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, G_TYPE_OBJECT); + G_TYPE_NONE, 1, NM_TYPE_SETTINGS_CONNECTION); nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (class), - &dbus_glib_nm_settings_object_info); - - dbus_g_error_domain_register (NM_SETTINGS_ERROR, - NM_DBUS_INTERFACE_SETTINGS, - NM_TYPE_SETTINGS_ERROR); - dbus_g_error_domain_register (NM_CONNECTION_ERROR, - NM_DBUS_INTERFACE_SETTINGS_CONNECTION, - NM_TYPE_CONNECTION_ERROR); + NMDBUS_TYPE_SETTINGS_SKELETON, + "ListConnections", impl_settings_list_connections, + "GetConnectionByUuid", impl_settings_get_connection_by_uuid, + "AddConnection", impl_settings_add_connection, + "AddConnectionUnsaved", impl_settings_add_connection_unsaved, + "LoadConnections", impl_settings_load_connections, + "ReloadConnections", impl_settings_reload_connections, + "SaveHostname", impl_settings_save_hostname, + NULL); } diff --git a/src/settings/nm-settings.h b/src/settings/nm-settings.h index 8e2d328952..0801054d66 100644 --- a/src/settings/nm-settings.h +++ b/src/settings/nm-settings.h @@ -87,14 +87,14 @@ void nm_settings_for_each_connection (NMSettings *settings, typedef void (*NMSettingsAddCallback) (NMSettings *settings, NMSettingsConnection *connection, GError *error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, NMAuthSubject *subject, gpointer user_data); void nm_settings_add_connection_dbus (NMSettings *self, NMConnection *connection, gboolean save_to_disk, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, NMSettingsAddCallback callback, gpointer user_data); From c050fb7cd2160f0b74ba8a0760e717e3fe329066 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Wed, 15 Apr 2015 14:53:30 -0400 Subject: [PATCH 08/14] devices, active-connection: port to gdbus --- introspection/nm-access-point.xml | 4 + introspection/nm-device-wifi.xml | 4 - introspection/nm-device-wimax.xml | 1 - introspection/nm-device.xml | 4 - src/devices/adsl/Makefile.am | 9 +- src/devices/adsl/nm-device-adsl.c | 5 +- src/devices/bluetooth/Makefile.am | 11 +- src/devices/bluetooth/nm-bluez-manager.c | 1 + src/devices/bluetooth/nm-device-bt.c | 6 +- src/devices/nm-device-bond.c | 8 +- src/devices/nm-device-bridge.c | 8 +- src/devices/nm-device-ethernet.c | 5 +- src/devices/nm-device-generic.c | 5 +- src/devices/nm-device-gre.c | 13 +- src/devices/nm-device-infiniband.c | 5 +- src/devices/nm-device-macvlan.c | 13 +- src/devices/nm-device-tun.c | 5 +- src/devices/nm-device-veth.c | 13 +- src/devices/nm-device-vlan.c | 13 +- src/devices/nm-device-vxlan.c | 13 +- src/devices/nm-device.c | 104 ++++++++-------- src/devices/nm-device.h | 3 +- src/devices/team/Makefile.am | 14 +-- src/devices/team/nm-device-team.c | 9 +- src/devices/wifi/Makefile.am | 15 +-- src/devices/wifi/nm-device-olpc-mesh.c | 14 +-- src/devices/wifi/nm-device-wifi.c | 130 +++++++++----------- src/devices/wifi/nm-wifi-ap.c | 38 +++--- src/devices/wifi/tests/Makefile.am | 4 +- src/devices/wifi/tests/test-wifi-ap-utils.c | 1 - src/devices/wwan/Makefile.am | 19 ++- src/devices/wwan/nm-device-modem.c | 7 +- src/devices/wwan/nm-modem.c | 1 - src/nm-activation-request.c | 2 +- src/nm-active-connection.c | 88 ++++++------- src/vpn-manager/nm-vpn-connection.c | 6 +- 36 files changed, 291 insertions(+), 310 deletions(-) diff --git a/introspection/nm-access-point.xml b/introspection/nm-access-point.xml index ef5af6ab77..16eae04476 100644 --- a/introspection/nm-access-point.xml +++ b/introspection/nm-access-point.xml @@ -12,6 +12,10 @@ Flags describing the access point's capabilities according to the RSN (Robust Secure Network) protocol. + + The Service Set Identifier identifying the access point. diff --git a/introspection/nm-device-wifi.xml b/introspection/nm-device-wifi.xml index d1c5313ed4..1cdcadfd09 100644 --- a/introspection/nm-device-wifi.xml +++ b/introspection/nm-device-wifi.xml @@ -5,7 +5,6 @@ - List of access point object paths. @@ -20,7 +19,6 @@ - List of access point object paths. @@ -33,8 +31,6 @@ - - Options of scan (currently unused argument). diff --git a/introspection/nm-device-wimax.xml b/introspection/nm-device-wimax.xml index b48ffe94ed..3bad624530 100644 --- a/introspection/nm-device-wimax.xml +++ b/introspection/nm-device-wimax.xml @@ -3,7 +3,6 @@ - List of NSP object paths diff --git a/introspection/nm-device.xml b/introspection/nm-device.xml index 239358a1e7..ba1a8fa69b 100644 --- a/introspection/nm-device.xml +++ b/introspection/nm-device.xml @@ -153,16 +153,12 @@ - - Disconnects a device and prevents the device from automatically activating further connections without user intervention. - - Deletes a software device from NetworkManager and removes the interface from the system. The method returns an error when called for a hardware device. diff --git a/src/devices/adsl/Makefile.am b/src/devices/adsl/Makefile.am index 5454f9db5e..1bccf7dc04 100644 --- a/src/devices/adsl/Makefile.am +++ b/src/devices/adsl/Makefile.am @@ -7,13 +7,13 @@ AM_CPPFLAGS = \ -I${top_builddir}/src \ -I${top_srcdir}/src/devices \ -I${top_srcdir}/src/platform \ + -I${top_builddir}/introspection \ -I${top_srcdir}/include \ -I${top_builddir}/libnm-core \ -I${top_srcdir}/libnm-core \ -DG_LOG_DOMAIN=\""NetworkManager-adsl"\" \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ - $(DBUS_CFLAGS) \ $(GUDEV_CFLAGS) GLIB_GENERATED = nm-adsl-enum-types.h nm-adsl-enum-types.c @@ -21,10 +21,7 @@ GLIB_MKENUMS_H_FLAGS = --identifier-prefix NM GLIB_MKENUMS_C_FLAGS = --identifier-prefix NM nm_adsl_enum_types_sources = $(srcdir)/nm-device-adsl.h -nm-device-adsl-glue.h: $(top_srcdir)/introspection/nm-device-adsl.xml - dbus-binding-tool --prefix=nm_device_adsl --mode=glib-server --output=$@ $< - -BUILT_SOURCES = $(GLIB_GENERATED) nm-device-adsl-glue.h +BUILT_SOURCES = $(GLIB_GENERATED) pkglib_LTLIBRARIES = libnm-device-plugin-adsl.la @@ -43,7 +40,7 @@ libnm_device_plugin_adsl_la_LDFLAGS = \ -Wl,--version-script=$(SYMBOL_VIS_FILE) libnm_device_plugin_adsl_la_LIBADD = \ - $(DBUS_LIBS) \ + $(top_builddir)/introspection/libnmdbus.la \ $(GUDEV_LIBS) CLEANFILES = $(BUILT_SOURCES) diff --git a/src/devices/adsl/nm-device-adsl.c b/src/devices/adsl/nm-device-adsl.c index 19b970d791..8dfd0c8541 100644 --- a/src/devices/adsl/nm-device-adsl.c +++ b/src/devices/adsl/nm-device-adsl.c @@ -43,7 +43,7 @@ #include "nm-setting-adsl.h" #include "nm-utils.h" -#include "nm-device-adsl-glue.h" +#include "nmdbus-device-adsl.h" #include "nm-device-logging.h" _LOG_DECLARE_SELF (NMDeviceAdsl); @@ -613,5 +613,6 @@ nm_device_adsl_class_init (NMDeviceAdslClass *klass) parent_class->deactivate = deactivate; nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), - &dbus_glib_nm_device_adsl_object_info); + NMDBUS_TYPE_DEVICE_ADSL_SKELETON, + NULL); } diff --git a/src/devices/bluetooth/Makefile.am b/src/devices/bluetooth/Makefile.am index 3f92aedfe2..760632951d 100644 --- a/src/devices/bluetooth/Makefile.am +++ b/src/devices/bluetooth/Makefile.am @@ -9,23 +9,21 @@ AM_CPPFLAGS = \ -I${top_srcdir}/src/settings \ -I${top_srcdir}/src/platform \ -I${top_srcdir}/src/devices/wwan \ + -I${top_builddir}/introspection \ -I${top_srcdir}/include \ -I${top_builddir}/libnm-core \ -I${top_srcdir}/libnm-core \ -DG_LOG_DOMAIN=\""NetworkManager-bluetooth"\" \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ - $(DBUS_CFLAGS) + $(GLIB_CFLAGS) GLIB_GENERATED = nm-bt-enum-types.h nm-bt-enum-types.c GLIB_MKENUMS_H_FLAGS = --identifier-prefix NM GLIB_MKENUMS_C_FLAGS = --identifier-prefix NM nm_bt_enum_types_sources = $(srcdir)/nm-bt-error.h -nm-device-bt-glue.h: $(top_srcdir)/introspection/nm-device-bt.xml - dbus-binding-tool --prefix=nm_device_bt --mode=glib-server --output=$@ $< - -BUILT_SOURCES = $(GLIB_GENERATED) nm-device-bt-glue.h +BUILT_SOURCES = $(GLIB_GENERATED) pkglib_LTLIBRARIES = libnm-device-plugin-bluetooth.la @@ -56,8 +54,9 @@ libnm_device_plugin_bluetooth_la_LDFLAGS = \ -Wl,--version-script=$(SYMBOL_VIS_FILE) libnm_device_plugin_bluetooth_la_LIBADD = \ + $(top_builddir)/introspection/libnmdbus.la \ $(top_builddir)/src/devices/wwan/libnm-wwan.la \ - $(DBUS_LIBS) \ + $(GLIB_LIBS) \ $(GUDEV_LIBS) if WITH_BLUEZ5_DUN diff --git a/src/devices/bluetooth/nm-bluez-manager.c b/src/devices/bluetooth/nm-bluez-manager.c index 7550d4ed86..bd7c7cab33 100644 --- a/src/devices/bluetooth/nm-bluez-manager.c +++ b/src/devices/bluetooth/nm-bluez-manager.c @@ -37,6 +37,7 @@ #include "nm-device-bt.h" #include "nm-core-internal.h" #include "nm-platform.h" +#include "nm-dbus-compat.h" typedef struct { int bluez_version; diff --git a/src/devices/bluetooth/nm-device-bt.c b/src/devices/bluetooth/nm-device-bt.c index 05b1d4e7fd..408315bca9 100644 --- a/src/devices/bluetooth/nm-device-bt.c +++ b/src/devices/bluetooth/nm-device-bt.c @@ -35,13 +35,14 @@ #include "nm-setting-gsm.h" #include "nm-setting-serial.h" #include "nm-setting-ppp.h" -#include "nm-device-bt-glue.h" #include "NetworkManagerUtils.h" #include "nm-bt-enum-types.h" #include "nm-utils.h" #include "nm-bt-error.h" #include "nm-bt-enum-types.h" +#include "nmdbus-device-bt.h" + #define MM_DBUS_SERVICE "org.freedesktop.ModemManager1" #define MM_DBUS_PATH "/org/freedesktop/ModemManager1" #define MM_DBUS_INTERFACE "org.freedesktop.ModemManager1" @@ -1194,5 +1195,6 @@ nm_device_bt_class_init (NMDeviceBtClass *klass) G_TYPE_UINT, G_TYPE_UINT); nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), - &dbus_glib_nm_device_bt_object_info); + NMDBUS_TYPE_DEVICE_BLUETOOTH_SKELETON, + NULL); } diff --git a/src/devices/nm-device-bond.c b/src/devices/nm-device-bond.c index 3d2795fced..d7a0e9a408 100644 --- a/src/devices/nm-device-bond.c +++ b/src/devices/nm-device-bond.c @@ -28,13 +28,12 @@ #include "NetworkManagerUtils.h" #include "nm-device-private.h" #include "nm-platform.h" -#include "nm-dbus-glib-types.h" #include "nm-enum-types.h" #include "nm-device-factory.h" #include "nm-core-internal.h" #include "nm-ip4-config.h" -#include "nm-device-bond-glue.h" +#include "nmdbus-device-bond.h" #include "nm-device-logging.h" _LOG_DECLARE_SELF(NMDeviceBond); @@ -556,12 +555,13 @@ nm_device_bond_class_init (NMDeviceBondClass *klass) g_object_class_install_property (object_class, PROP_SLAVES, g_param_spec_boxed (NM_DEVICE_BOND_SLAVES, "", "", - DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH, + G_TYPE_STRV, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), - &dbus_glib_nm_device_bond_object_info); + NMDBUS_TYPE_DEVICE_BOND_SKELETON, + NULL); } /*************************************************************/ diff --git a/src/devices/nm-device-bridge.c b/src/devices/nm-device-bridge.c index d182d872fe..8d6caa94f4 100644 --- a/src/devices/nm-device-bridge.c +++ b/src/devices/nm-device-bridge.c @@ -26,13 +26,12 @@ #include "nm-device-bridge.h" #include "NetworkManagerUtils.h" #include "nm-device-private.h" -#include "nm-dbus-glib-types.h" #include "nm-enum-types.h" #include "nm-platform.h" #include "nm-device-factory.h" #include "nm-core-internal.h" -#include "nm-device-bridge-glue.h" +#include "nmdbus-device-bridge.h" #include "nm-device-logging.h" _LOG_DECLARE_SELF(NMDeviceBridge); @@ -501,12 +500,13 @@ nm_device_bridge_class_init (NMDeviceBridgeClass *klass) g_object_class_install_property (object_class, PROP_SLAVES, g_param_spec_boxed (NM_DEVICE_BRIDGE_SLAVES, "", "", - DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH, + G_TYPE_STRV, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), - &dbus_glib_nm_device_bridge_object_info); + NMDBUS_TYPE_DEVICE_BRIDGE_SKELETON, + NULL); } /*************************************************************/ diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c index 5f43a10dcf..16ca35e56f 100644 --- a/src/devices/nm-device-ethernet.c +++ b/src/devices/nm-device-ethernet.c @@ -50,7 +50,7 @@ #include "nm-core-internal.h" #include "NetworkManagerUtils.h" -#include "nm-device-ethernet-glue.h" +#include "nmdbus-device-ethernet.h" #include "nm-device-logging.h" _LOG_DECLARE_SELF(NMDeviceEthernet); @@ -1712,7 +1712,8 @@ nm_device_ethernet_class_init (NMDeviceEthernetClass *klass) G_PARAM_STATIC_STRINGS)); nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), - &dbus_glib_nm_device_ethernet_object_info); + NMDBUS_TYPE_DEVICE_ETHERNET_SKELETON, + NULL); } /*************************************************************/ diff --git a/src/devices/nm-device-generic.c b/src/devices/nm-device-generic.c index 5d092b98f7..029a706475 100644 --- a/src/devices/nm-device-generic.c +++ b/src/devices/nm-device-generic.c @@ -26,7 +26,7 @@ #include "nm-platform.h" #include "nm-core-internal.h" -#include "nm-device-generic-glue.h" +#include "nmdbus-device-generic.h" G_DEFINE_TYPE (NMDeviceGeneric, nm_device_generic, NM_TYPE_DEVICE) @@ -202,5 +202,6 @@ nm_device_generic_class_init (NMDeviceGenericClass *klass) G_PARAM_STATIC_STRINGS)); nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), - &dbus_glib_nm_device_generic_object_info); + NMDBUS_TYPE_DEVICE_GENERIC_SKELETON, + NULL); } diff --git a/src/devices/nm-device-gre.c b/src/devices/nm-device-gre.c index c26190ab56..ddd913b586 100644 --- a/src/devices/nm-device-gre.c +++ b/src/devices/nm-device-gre.c @@ -31,7 +31,7 @@ #include "nm-device-factory.h" #include "nm-core-internal.h" -#include "nm-device-gre-glue.h" +#include "nmdbus-device-gre.h" #include "nm-device-logging.h" _LOG_DECLARE_SELF(NMDeviceGre); @@ -187,10 +187,10 @@ nm_device_gre_class_init (NMDeviceGreClass *klass) /* properties */ g_object_class_install_property (object_class, PROP_PARENT, - g_param_spec_boxed (NM_DEVICE_GRE_PARENT, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_DEVICE_GRE_PARENT, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_INPUT_FLAGS, @@ -256,7 +256,8 @@ nm_device_gre_class_init (NMDeviceGreClass *klass) G_PARAM_STATIC_STRINGS)); nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), - &dbus_glib_nm_device_gre_object_info); + NMDBUS_TYPE_DEVICE_GRE_SKELETON, + NULL); } /*************************************************************/ diff --git a/src/devices/nm-device-infiniband.c b/src/devices/nm-device-infiniband.c index f52613b069..c4c21f9d1c 100644 --- a/src/devices/nm-device-infiniband.c +++ b/src/devices/nm-device-infiniband.c @@ -33,7 +33,7 @@ #include "nm-device-factory.h" #include "nm-core-internal.h" -#include "nm-device-infiniband-glue.h" +#include "nmdbus-device-infiniband.h" G_DEFINE_TYPE (NMDeviceInfiniband, nm_device_infiniband, NM_TYPE_DEVICE) @@ -350,7 +350,8 @@ nm_device_infiniband_class_init (NMDeviceInfinibandClass *klass) G_PARAM_STATIC_STRINGS)); nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), - &dbus_glib_nm_device_infiniband_object_info); + NMDBUS_TYPE_DEVICE_INFINIBAND_SKELETON, + NULL); } /*************************************************************/ diff --git a/src/devices/nm-device-macvlan.c b/src/devices/nm-device-macvlan.c index 6f331571ca..743e2db21e 100644 --- a/src/devices/nm-device-macvlan.c +++ b/src/devices/nm-device-macvlan.c @@ -29,7 +29,7 @@ #include "nm-platform.h" #include "nm-device-factory.h" -#include "nm-device-macvlan-glue.h" +#include "nmdbus-device-macvlan.h" #include "nm-device-logging.h" _LOG_DECLARE_SELF(NMDeviceMacvlan); @@ -144,10 +144,10 @@ nm_device_macvlan_class_init (NMDeviceMacvlanClass *klass) /* properties */ g_object_class_install_property (object_class, PROP_PARENT, - g_param_spec_boxed (NM_DEVICE_MACVLAN_PARENT, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_DEVICE_MACVLAN_PARENT, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_MODE, @@ -164,7 +164,8 @@ nm_device_macvlan_class_init (NMDeviceMacvlanClass *klass) G_PARAM_STATIC_STRINGS)); nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), - &dbus_glib_nm_device_macvlan_object_info); + NMDBUS_TYPE_DEVICE_MACVLAN_SKELETON, + NULL); } /*************************************************************/ diff --git a/src/devices/nm-device-tun.c b/src/devices/nm-device-tun.c index 6c6ed52113..e103363361 100644 --- a/src/devices/nm-device-tun.c +++ b/src/devices/nm-device-tun.c @@ -29,7 +29,7 @@ #include "nm-platform.h" #include "nm-device-factory.h" -#include "nm-device-tun-glue.h" +#include "nmdbus-device-tun.h" #include "nm-device-logging.h" _LOG_DECLARE_SELF(NMDeviceTun); @@ -232,7 +232,8 @@ nm_device_tun_class_init (NMDeviceTunClass *klass) G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), - &dbus_glib_nm_device_tun_object_info); + NMDBUS_TYPE_DEVICE_TUN_SKELETON, + NULL); } diff --git a/src/devices/nm-device-veth.c b/src/devices/nm-device-veth.c index c4666a217e..d80624857e 100644 --- a/src/devices/nm-device-veth.c +++ b/src/devices/nm-device-veth.c @@ -34,7 +34,7 @@ #include "nm-platform.h" #include "nm-device-factory.h" -#include "nm-device-veth-glue.h" +#include "nmdbus-device-veth.h" #include "nm-device-logging.h" _LOG_DECLARE_SELF(NMDeviceVeth); @@ -160,13 +160,14 @@ nm_device_veth_class_init (NMDeviceVethClass *klass) /* properties */ g_object_class_install_property (object_class, PROP_PEER, - g_param_spec_boxed (NM_DEVICE_VETH_PEER, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_DEVICE_VETH_PEER, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), - &dbus_glib_nm_device_veth_object_info); + NMDBUS_TYPE_DEVICE_VETH_SKELETON, + NULL); } /*************************************************************/ diff --git a/src/devices/nm-device-vlan.c b/src/devices/nm-device-vlan.c index 584d844e15..eb3b146e25 100644 --- a/src/devices/nm-device-vlan.c +++ b/src/devices/nm-device-vlan.c @@ -37,7 +37,7 @@ #include "nm-manager.h" #include "nm-core-internal.h" -#include "nm-device-vlan-glue.h" +#include "nmdbus-device-vlan.h" #include "nm-device-logging.h" _LOG_DECLARE_SELF(NMDeviceVlan); @@ -617,10 +617,10 @@ nm_device_vlan_class_init (NMDeviceVlanClass *klass) /* properties */ g_object_class_install_property (object_class, PROP_PARENT, - g_param_spec_boxed (NM_DEVICE_VLAN_PARENT, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_DEVICE_VLAN_PARENT, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_VLAN_ID, g_param_spec_uint (NM_DEVICE_VLAN_ID, "", "", @@ -628,7 +628,8 @@ nm_device_vlan_class_init (NMDeviceVlanClass *klass) G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), - &dbus_glib_nm_device_vlan_object_info); + NMDBUS_TYPE_DEVICE_VLAN_SKELETON, + NULL); } /*************************************************************/ diff --git a/src/devices/nm-device-vxlan.c b/src/devices/nm-device-vxlan.c index 68dbd952a1..b66f2368fb 100644 --- a/src/devices/nm-device-vxlan.c +++ b/src/devices/nm-device-vxlan.c @@ -30,7 +30,7 @@ #include "nm-utils.h" #include "nm-device-factory.h" -#include "nm-device-vxlan-glue.h" +#include "nmdbus-device-vxlan.h" #include "nm-device-logging.h" _LOG_DECLARE_SELF(NMDeviceVxlan); @@ -234,10 +234,10 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *klass) /* properties */ g_object_class_install_property (object_class, PROP_PARENT, - g_param_spec_boxed (NM_DEVICE_VXLAN_PARENT, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_DEVICE_VXLAN_PARENT, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_ID, @@ -345,7 +345,8 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *klass) G_PARAM_STATIC_STRINGS)); nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), - &dbus_glib_nm_device_vxlan_object_info); + NMDBUS_TYPE_DEVICE_VXLAN_SKELETON, + NULL); } /*************************************************************/ diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 88f63c1258..50e9a22c9d 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -21,7 +21,6 @@ #include "config.h" -#include #include #include #include @@ -55,7 +54,6 @@ #include "nm-settings-connection.h" #include "nm-connection-provider.h" #include "nm-auth-utils.h" -#include "nm-dbus-glib-types.h" #include "nm-dispatcher.h" #include "nm-config.h" #include "nm-dns-manager.h" @@ -68,13 +66,11 @@ #include "nm-device-logging.h" _LOG_DECLARE_SELF (NMDevice); -static void impl_device_disconnect (NMDevice *self, DBusGMethodInvocation *context); -static void impl_device_delete (NMDevice *self, DBusGMethodInvocation *context); +#include "nmdbus-device.h" + static void nm_device_update_metered (NMDevice *self); static void ip_check_ping_watch_cb (GPid pid, gint status, gpointer user_data); -#include "nm-device-glue.h" - G_DEFINE_ABSTRACT_TYPE (NMDevice, nm_device, NM_TYPE_EXPORTED_OBJECT) #define NM_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE, NMDevicePrivate)) @@ -6178,7 +6174,7 @@ delete_on_deactivate_check_and_schedule (NMDevice *self, int ifindex) static void disconnect_cb (NMDevice *self, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, NMAuthSubject *subject, GError *error, gpointer user_data) @@ -6187,7 +6183,7 @@ disconnect_cb (NMDevice *self, GError *local = NULL; if (error) { - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); nm_audit_log_device_op (NM_AUDIT_OP_DEVICE_DISCONNECT, self, FALSE, subject, error->message); return; } @@ -6197,16 +6193,15 @@ disconnect_cb (NMDevice *self, local = g_error_new_literal (NM_DEVICE_ERROR, NM_DEVICE_ERROR_NOT_ACTIVE, "Device is not active"); - dbus_g_method_return_error (context, local); nm_audit_log_device_op (NM_AUDIT_OP_DEVICE_DISCONNECT, self, FALSE, subject, local->message); - g_error_free (local); + g_dbus_method_invocation_take_error (context, local); } else { nm_device_set_autoconnect (self, FALSE); nm_device_state_changed (self, NM_DEVICE_STATE_DEACTIVATING, NM_DEVICE_STATE_REASON_USER_REQUESTED); - dbus_g_method_return (context); + g_dbus_method_invocation_return_value (context, NULL); nm_audit_log_device_op (NM_AUDIT_OP_DEVICE_DISCONNECT, self, TRUE, subject, NULL); } } @@ -6221,7 +6216,7 @@ _clear_queued_act_request (NMDevicePrivate *priv) } static void -impl_device_disconnect (NMDevice *self, DBusGMethodInvocation *context) +impl_device_disconnect (NMDevice *self, GDBusMethodInvocation *context) { NMConnection *connection; GError *error = NULL; @@ -6230,8 +6225,7 @@ impl_device_disconnect (NMDevice *self, DBusGMethodInvocation *context) error = g_error_new_literal (NM_DEVICE_ERROR, NM_DEVICE_ERROR_NOT_ACTIVE, "This device is not active"); - dbus_g_method_return_error (context, error); - g_error_free (error); + g_dbus_method_invocation_take_error (context, error); return; } @@ -6250,25 +6244,25 @@ impl_device_disconnect (NMDevice *self, DBusGMethodInvocation *context) static void delete_cb (NMDevice *self, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, NMAuthSubject *subject, GError *error, gpointer user_data) { if (error) { - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); nm_audit_log_device_op (NM_AUDIT_OP_DEVICE_DELETE, self, FALSE, subject, error->message); return; } /* Authorized */ nm_platform_link_delete (NM_PLATFORM_GET, nm_device_get_ifindex (self)); - dbus_g_method_return (context); + g_dbus_method_invocation_return_value (context, NULL); nm_audit_log_device_op (NM_AUDIT_OP_DEVICE_DELETE, self, TRUE, subject, NULL); } static void -impl_device_delete (NMDevice *self, DBusGMethodInvocation *context) +impl_device_delete (NMDevice *self, GDBusMethodInvocation *context) { GError *error = NULL; @@ -6276,8 +6270,7 @@ impl_device_delete (NMDevice *self, DBusGMethodInvocation *context) error = g_error_new_literal (NM_DEVICE_ERROR, NM_DEVICE_ERROR_NOT_SOFTWARE, "This device is not a software device"); - dbus_g_method_return_error (context, error); - g_error_free (error); + g_dbus_method_invocation_take_error (context, error); return; } @@ -9311,8 +9304,6 @@ set_property (GObject *object, guint prop_id, } } -#define DBUS_TYPE_STATE_REASON_STRUCT (dbus_g_type_get_struct ("GValueArray", G_TYPE_UINT, G_TYPE_UINT, G_TYPE_INVALID)) - static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) @@ -9376,8 +9367,8 @@ get_property (GObject *object, guint prop_id, g_value_set_uint (value, priv->state); break; case PROP_STATE_REASON: - g_value_take_boxed (value, dbus_g_type_specialized_construct (DBUS_TYPE_STATE_REASON_STRUCT)); - dbus_g_type_struct_set (value, 0, priv->state, 1, priv->state_reason, G_MAXUINT); + g_value_take_variant (value, + g_variant_new ("(uu)", priv->state, priv->state_reason)); break; case PROP_ACTIVE_CONNECTION: nm_utils_g_value_set_object_path (value, priv->act_request); @@ -9408,7 +9399,8 @@ get_property (GObject *object, guint prop_id, g_hash_table_iter_init (&iter, priv->available_connections); while (g_hash_table_iter_next (&iter, (gpointer) &connection, NULL)) g_ptr_array_add (array, g_strdup (nm_connection_get_path (connection))); - g_value_take_boxed (value, array); + g_ptr_array_add (array, NULL); + g_value_take_boxed (value, (char **) g_ptr_array_free (array, FALSE)); break; case PROP_PHYSICAL_PORT_ID: g_value_set_string (value, priv->physical_port_id); @@ -9548,31 +9540,31 @@ nm_device_class_init (NMDeviceClass *klass) g_object_class_install_property (object_class, PROP_IP4_CONFIG, - g_param_spec_boxed (NM_DEVICE_IP4_CONFIG, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_DEVICE_IP4_CONFIG, "", "", + NULL, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_DHCP4_CONFIG, - g_param_spec_boxed (NM_DEVICE_DHCP4_CONFIG, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_DEVICE_DHCP4_CONFIG, "", "", + NULL, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_IP6_CONFIG, - g_param_spec_boxed (NM_DEVICE_IP6_CONFIG, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_DEVICE_IP6_CONFIG, "", "", + NULL, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_DHCP6_CONFIG, - g_param_spec_boxed (NM_DEVICE_DHCP6_CONFIG, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_DEVICE_DHCP6_CONFIG, "", "", + NULL, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_STATE, @@ -9583,17 +9575,18 @@ nm_device_class_init (NMDeviceClass *klass) g_object_class_install_property (object_class, PROP_STATE_REASON, - g_param_spec_boxed (NM_DEVICE_STATE_REASON, "", "", - DBUS_TYPE_STATE_REASON_STRUCT, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_variant (NM_DEVICE_STATE_REASON, "", "", + G_VARIANT_TYPE ("(uu)"), + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_ACTIVE_CONNECTION, - g_param_spec_boxed (NM_DEVICE_ACTIVE_CONNECTION, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_DEVICE_ACTIVE_CONNECTION, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_DEVICE_TYPE, @@ -9656,7 +9649,7 @@ nm_device_class_init (NMDeviceClass *klass) g_object_class_install_property (object_class, PROP_AVAILABLE_CONNECTIONS, g_param_spec_boxed (NM_DEVICE_AVAILABLE_CONNECTIONS, "", "", - DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH, + G_TYPE_STRV, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); @@ -9732,8 +9725,8 @@ nm_device_class_init (NMDeviceClass *klass) G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL, - /* dbus-glib context, connection, permission, allow_interaction, callback, user_data */ - G_TYPE_NONE, 6, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_POINTER, G_TYPE_POINTER); + /* context, connection, permission, allow_interaction, callback, user_data */ + G_TYPE_NONE, 6, G_TYPE_DBUS_METHOD_INVOCATION, NM_TYPE_CONNECTION, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_POINTER, G_TYPE_POINTER); signals[IP4_CONFIG_CHANGED] = g_signal_new (NM_DEVICE_IP4_CONFIG_CHANGED, @@ -9771,7 +9764,8 @@ nm_device_class_init (NMDeviceClass *klass) G_TYPE_NONE, 0); nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), - &dbus_glib_nm_device_object_info); - - dbus_g_error_domain_register (NM_DEVICE_ERROR, NULL, NM_TYPE_DEVICE_ERROR); + NMDBUS_TYPE_DEVICE_SKELETON, + "Disconnect", impl_device_disconnect, + "Delete", impl_device_delete, + NULL); } diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index 8c26d161fb..0995377ad2 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -22,7 +22,6 @@ #ifndef __NETWORKMANAGER_DEVICE_H__ #define __NETWORKMANAGER_DEVICE_H__ -#include #include #include "nm-exported-object.h" @@ -310,7 +309,7 @@ typedef struct { } NMDeviceClass; typedef void (*NMDeviceAuthRequestFunc) (NMDevice *device, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, NMAuthSubject *subject, GError *error, gpointer user_data); diff --git a/src/devices/team/Makefile.am b/src/devices/team/Makefile.am index a30e953d79..b48ea56053 100644 --- a/src/devices/team/Makefile.am +++ b/src/devices/team/Makefile.am @@ -7,13 +7,14 @@ AM_CPPFLAGS = \ -I${top_builddir}/src \ -I${top_srcdir}/src/devices \ -I${top_srcdir}/src/platform \ + -I${top_builddir}/introspection \ -I${top_srcdir}/include \ -I${top_builddir}/libnm-core \ -I${top_srcdir}/libnm-core \ -DG_LOG_DOMAIN=\""NetworkManager-team"\" \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ - $(DBUS_CFLAGS) + $(GLIB_CFLAGS) if WITH_TEAMDCTL AM_CPPFLAGS += ${LIBTEAMDCTL_CFLAGS} @@ -24,13 +25,7 @@ GLIB_MKENUMS_H_FLAGS = --identifier-prefix NM GLIB_MKENUMS_C_FLAGS = --identifier-prefix NM nm_team_enum_types_sources = $(srcdir)/nm-device-team.h -glue_sources = \ - nm-device-team-glue.h - -%-glue.h: $(top_srcdir)/introspection/%.xml - $(AM_V_GEN) dbus-binding-tool --prefix=$(subst -,_,$(subst -glue.h,,$@)) --mode=glib-server --output=$@ $< - -BUILT_SOURCES = $(GLIB_GENERATED) $(glue_sources) +BUILT_SOURCES = $(GLIB_GENERATED) pkglib_LTLIBRARIES = libnm-device-plugin-team.la @@ -49,7 +44,8 @@ libnm_device_plugin_team_la_LDFLAGS = \ -Wl,--version-script=$(SYMBOL_VIS_FILE) libnm_device_plugin_team_la_LIBADD = \ - $(DBUS_LIBS) \ + $(top_builddir)/introspection/libnmdbus.la \ + $(GLIB_LIBS) \ $(GUDEV_LIBS) if WITH_TEAMDCTL diff --git a/src/devices/team/nm-device-team.c b/src/devices/team/nm-device-team.c index 626f808d60..66e77e65c1 100644 --- a/src/devices/team/nm-device-team.c +++ b/src/devices/team/nm-device-team.c @@ -32,12 +32,12 @@ #include "NetworkManagerUtils.h" #include "nm-device-private.h" #include "nm-platform.h" -#include "nm-dbus-glib-types.h" #include "nm-enum-types.h" #include "nm-team-enum-types.h" #include "nm-core-internal.h" +#include "nm-dbus-compat.h" -#include "nm-device-team-glue.h" +#include "nmdbus-device-team.h" #include "nm-device-logging.h" _LOG_DECLARE_SELF(NMDeviceTeam); @@ -809,11 +809,12 @@ nm_device_team_class_init (NMDeviceTeamClass *klass) g_object_class_install_property (object_class, PROP_SLAVES, g_param_spec_boxed (NM_DEVICE_TEAM_SLAVES, "", "", - DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH, + G_TYPE_STRV, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), - &dbus_glib_nm_device_team_object_info); + NMDBUS_TYPE_DEVICE_TEAM_SKELETON, + NULL); } diff --git a/src/devices/wifi/Makefile.am b/src/devices/wifi/Makefile.am index cf4bb23a59..9133e312d0 100644 --- a/src/devices/wifi/Makefile.am +++ b/src/devices/wifi/Makefile.am @@ -13,13 +13,14 @@ AM_CPPFLAGS = \ -I${top_srcdir}/src/settings \ -I${top_srcdir}/src/platform \ -I${top_srcdir}/src/supplicant-manager \ + -I${top_builddir}/introspection \ -I${top_srcdir}/include \ -I${top_builddir}/libnm-core \ -I${top_srcdir}/libnm-core \ -DG_LOG_DOMAIN=\""NetworkManager-wifi"\" \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ - $(DBUS_CFLAGS) + $(GLIB_CFLAGS) GLIB_GENERATED = nm-wifi-enum-types.h nm-wifi-enum-types.c GLIB_MKENUMS_H_FLAGS = --identifier-prefix NM @@ -29,14 +30,7 @@ nm_wifi_enum_types_sources = \ $(srcdir)/nm-wifi-ap.h \ $(srcdir)/nm-device-olpc-mesh.h -glue_sources = \ - nm-device-wifi-glue.h \ - nm-device-olpc-mesh-glue.h - -%-glue.h: $(top_srcdir)/introspection/%.xml - $(AM_V_GEN) dbus-binding-tool --prefix=$(subst -,_,$(subst -glue.h,,$@)) --mode=glib-server --output=$@ $< - -BUILT_SOURCES = $(GLIB_GENERATED) $(glue_sources) +BUILT_SOURCES = $(GLIB_GENERATED) pkglib_LTLIBRARIES = libnm-device-plugin-wifi.la @@ -60,7 +54,8 @@ libnm_device_plugin_wifi_la_LDFLAGS = \ -Wl,--version-script=$(SYMBOL_VIS_FILE) libnm_device_plugin_wifi_la_LIBADD = \ - $(DBUS_LIBS) \ + $(top_builddir)/introspection/libnmdbus.la \ + $(GLIB_LIBS) \ $(GUDEV_LIBS) CLEANFILES = $(BUILT_SOURCES) diff --git a/src/devices/wifi/nm-device-olpc-mesh.c b/src/devices/wifi/nm-device-olpc-mesh.c index 2718e20612..c3699da3a4 100644 --- a/src/devices/wifi/nm-device-olpc-mesh.c +++ b/src/devices/wifi/nm-device-olpc-mesh.c @@ -26,7 +26,6 @@ #include "config.h" -#include #include #include #include @@ -54,7 +53,7 @@ /* This is a bug; but we can't really change API now... */ #include "nm-vpn-dbus-interface.h" -#include "nm-device-olpc-mesh-glue.h" +#include "nmdbus-device-olpc-mesh.h" #include "nm-device-logging.h" _LOG_DECLARE_SELF(NMDeviceOlpcMesh); @@ -531,10 +530,10 @@ nm_device_olpc_mesh_class_init (NMDeviceOlpcMeshClass *klass) /* Properties */ g_object_class_install_property (object_class, PROP_COMPANION, - g_param_spec_boxed (NM_DEVICE_OLPC_MESH_COMPANION, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_DEVICE_OLPC_MESH_COMPANION, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_ACTIVE_CHANNEL, @@ -544,6 +543,7 @@ nm_device_olpc_mesh_class_init (NMDeviceOlpcMeshClass *klass) G_PARAM_STATIC_STRINGS)); nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), - &dbus_glib_nm_device_olpc_mesh_object_info); + NMDBUS_TYPE_DEVICE_OLPC_MESH_SKELETON, + NULL); } diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index 74ba055038..fb4b5fa40c 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -21,7 +21,6 @@ #include "config.h" -#include #include #include #include @@ -48,23 +47,10 @@ #include "nm-auth-utils.h" #include "nm-settings-connection.h" #include "nm-enum-types.h" -#include "nm-dbus-glib-types.h" #include "nm-wifi-enum-types.h" #include "nm-connection-provider.h" -static gboolean impl_device_get_access_points (NMDeviceWifi *device, - GPtrArray **aps, - GError **err); - -static gboolean impl_device_get_all_access_points (NMDeviceWifi *device, - GPtrArray **aps, - GError **err); - -static void impl_device_request_scan (NMDeviceWifi *device, - GHashTable *options, - DBusGMethodInvocation *context); - -#include "nm-device-wifi-glue.h" +#include "nmdbus-device-wifi.h" #include "nm-device-logging.h" _LOG_DECLARE_SELF(NMDeviceWifi); @@ -1017,102 +1003,108 @@ get_sorted_ap_list (NMDeviceWifi *self) return g_slist_sort (sorted, (GCompareFunc) ap_id_compare); } -static gboolean -impl_device_get_access_points (NMDeviceWifi *self, - GPtrArray **aps, - GError **err) +static void +impl_device_wifi_get_access_points (NMDeviceWifi *self, + GDBusMethodInvocation *context) { GSList *sorted, *iter; + GPtrArray *paths; - *aps = g_ptr_array_new (); + paths = g_ptr_array_new (); sorted = get_sorted_ap_list (self); for (iter = sorted; iter; iter = iter->next) { NMAccessPoint *ap = NM_AP (iter->data); if (nm_ap_get_ssid (ap)) - g_ptr_array_add (*aps, g_strdup (nm_exported_object_get_path (NM_EXPORTED_OBJECT (ap)))); + g_ptr_array_add (paths, g_strdup (nm_exported_object_get_path (NM_EXPORTED_OBJECT (ap)))); } + g_ptr_array_add (paths, NULL); g_slist_free (sorted); - return TRUE; + + g_dbus_method_invocation_return_value (context, g_variant_new ("(^ao)", (char **) paths->pdata)); + g_ptr_array_unref (paths); } -static gboolean -impl_device_get_all_access_points (NMDeviceWifi *self, - GPtrArray **aps, - GError **err) +static void +impl_device_wifi_get_all_access_points (NMDeviceWifi *self, + GDBusMethodInvocation *context) { GSList *sorted, *iter; + GPtrArray *paths; - *aps = g_ptr_array_new (); + paths = g_ptr_array_new (); sorted = get_sorted_ap_list (self); for (iter = sorted; iter; iter = iter->next) - g_ptr_array_add (*aps, g_strdup (nm_exported_object_get_path (NM_EXPORTED_OBJECT (iter->data)))); + g_ptr_array_add (paths, g_strdup (nm_exported_object_get_path (NM_EXPORTED_OBJECT (iter->data)))); + g_ptr_array_add (paths, NULL); g_slist_free (sorted); - return TRUE; + + g_dbus_method_invocation_return_value (context, g_variant_new ("(^ao)", (char **) paths->pdata)); + g_ptr_array_unref (paths); } static void request_scan_cb (NMDevice *device, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, NMAuthSubject *subject, GError *error, gpointer user_data) { NMDeviceWifi *self = NM_DEVICE_WIFI (device); - GError *local = NULL; if (error) { - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); return; } if (!check_scanning_allowed (self)) { - local = g_error_new_literal (NM_DEVICE_ERROR, - NM_DEVICE_ERROR_NOT_ALLOWED, - "Scanning not allowed at this time"); - dbus_g_method_return_error (context, local); - g_error_free (local); + g_dbus_method_invocation_return_error_literal (context, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_NOT_ALLOWED, + "Scanning not allowed at this time"); return; } cancel_pending_scan (self); request_wireless_scan (self); - dbus_g_method_return (context); + g_dbus_method_invocation_return_value (context, NULL); } static void -impl_device_request_scan (NMDeviceWifi *self, - GHashTable *options, - DBusGMethodInvocation *context) +impl_device_wifi_request_scan (NMDeviceWifi *self, + GDBusMethodInvocation *context, + GVariant *options) { NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); NMDevice *device = NM_DEVICE (self); gint32 last_scan; - GError *error; if ( !priv->enabled || !priv->sup_iface || nm_device_get_state (device) < NM_DEVICE_STATE_DISCONNECTED || nm_device_is_activating (device)) { - error = g_error_new_literal (NM_DEVICE_ERROR, - NM_DEVICE_ERROR_NOT_ALLOWED, - "Scanning not allowed while unavailable or activating"); - goto error; + g_dbus_method_invocation_return_error_literal (context, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_NOT_ALLOWED, + "Scanning not allowed while unavailable or activating"); + return; } if (nm_supplicant_interface_get_scanning (priv->sup_iface)) { - error = g_error_new_literal (NM_DEVICE_ERROR, - NM_DEVICE_ERROR_NOT_ALLOWED, - "Scanning not allowed while already scanning"); - goto error; + g_dbus_method_invocation_return_error_literal (context, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_NOT_ALLOWED, + "Scanning not allowed while already scanning"); + return; } last_scan = nm_supplicant_interface_get_last_scan_time (priv->sup_iface); if (last_scan && (nm_utils_get_monotonic_timestamp_s () - last_scan) < 10) { - error = g_error_new_literal (NM_DEVICE_ERROR, - NM_DEVICE_ERROR_NOT_ALLOWED, - "Scanning not allowed immediately following previous scan"); - goto error; + g_dbus_method_invocation_return_error_literal (context, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_NOT_ALLOWED, + "Scanning not allowed immediately following previous scan"); + return; } /* Ask the manager to authenticate this request for us */ @@ -1124,11 +1116,6 @@ impl_device_request_scan (NMDeviceWifi *self, TRUE, request_scan_cb, NULL); - return; - -error: - dbus_g_method_return_error (context, error); - g_error_free (error); } static gboolean @@ -2922,11 +2909,12 @@ get_property (GObject *object, guint prop_id, g_value_set_uint (value, priv->capabilities); break; case PROP_ACCESS_POINTS: - array = g_ptr_array_sized_new (g_hash_table_size (priv->aps)); + array = g_ptr_array_sized_new (g_hash_table_size (priv->aps) + 1); g_hash_table_iter_init (&iter, priv->aps); while (g_hash_table_iter_next (&iter, (gpointer) &dbus_path, NULL)) g_ptr_array_add (array, g_strdup (dbus_path)); - g_value_take_boxed (value, array); + g_ptr_array_add (array, NULL); + g_value_take_boxed (value, (char **) g_ptr_array_free (array, FALSE)); break; case PROP_ACTIVE_ACCESS_POINT: nm_utils_g_value_set_object_path (value, priv->current_ap); @@ -3011,16 +2999,16 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass) g_object_class_install_property (object_class, PROP_ACCESS_POINTS, g_param_spec_boxed (NM_DEVICE_WIFI_ACCESS_POINTS, "", "", - DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH, + G_TYPE_STRV, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_ACTIVE_ACCESS_POINT, - g_param_spec_boxed (NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_CAPABILITIES, @@ -3044,7 +3032,7 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass) G_STRUCT_OFFSET (NMDeviceWifiClass, access_point_added), NULL, NULL, NULL, G_TYPE_NONE, 1, - G_TYPE_OBJECT); + NM_TYPE_AP); signals[ACCESS_POINT_REMOVED] = g_signal_new ("access-point-removed", @@ -3053,7 +3041,7 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass) 0, NULL, NULL, NULL, G_TYPE_NONE, 1, - G_TYPE_OBJECT); + NM_TYPE_AP); signals[SCANNING_ALLOWED] = g_signal_new ("scanning-allowed", @@ -3064,7 +3052,11 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass) G_TYPE_BOOLEAN, 0); nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), - &dbus_glib_nm_device_wifi_object_info); + NMDBUS_TYPE_DEVICE_WIFI_SKELETON, + "GetAccessPoints", impl_device_wifi_get_access_points, + "GetAllAccessPoints", impl_device_wifi_get_all_access_points, + "RequestScan", impl_device_wifi_request_scan, + NULL); } diff --git a/src/devices/wifi/nm-wifi-ap.c b/src/devices/wifi/nm-wifi-ap.c index 6502e88326..71b17e65c2 100644 --- a/src/devices/wifi/nm-wifi-ap.c +++ b/src/devices/wifi/nm-wifi-ap.c @@ -33,7 +33,7 @@ #include "nm-setting-wireless.h" -#include "nm-access-point-glue.h" +#include "nmdbus-access-point.h" /* * Encapsulates Access Point information @@ -46,7 +46,7 @@ typedef struct GByteArray * ssid; char * address; NM80211Mode mode; - gint8 strength; + guint8 strength; guint32 freq; /* Frequency in MHz; ie 2412 (== 2.412 GHz) */ guint32 max_bitrate;/* Maximum bitrate of the AP in Kbit/s (ie 54000 Kb/s == 54Mbit/s) */ @@ -902,9 +902,7 @@ get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { NMAccessPointPrivate *priv = NM_AP_GET_PRIVATE (object); - GArray * ssid; - int len; - int i; + GVariant *ssid; switch (prop_id) { case PROP_FLAGS: @@ -917,12 +915,12 @@ get_property (GObject *object, guint prop_id, g_value_set_uint (value, priv->rsn_flags); break; case PROP_SSID: - len = priv->ssid ? priv->ssid->len : 0; - ssid = g_array_sized_new (FALSE, TRUE, sizeof (unsigned char), len); - for (i = 0; i < len; i++) - g_array_append_val (ssid, priv->ssid->data[i]); - g_value_set_boxed (value, ssid); - g_array_free (ssid, TRUE); + if (priv->ssid) { + ssid = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, + priv->ssid->data, priv->ssid->len, 1); + } else + ssid = g_variant_new_array (G_VARIANT_TYPE_BYTE, NULL, 0); + g_value_take_variant (value, ssid); break; case PROP_FREQUENCY: g_value_set_uint (value, priv->freq); @@ -937,7 +935,7 @@ get_property (GObject *object, guint prop_id, g_value_set_uint (value, priv->max_bitrate); break; case PROP_STRENGTH: - g_value_set_schar (value, priv->strength); + g_value_set_uchar (value, priv->strength); break; case PROP_LAST_SEEN: g_value_set_int (value, @@ -1004,9 +1002,10 @@ nm_ap_class_init (NMAccessPointClass *ap_class) g_object_class_install_property (object_class, PROP_SSID, - g_param_spec_boxed (NM_AP_SSID, "", "", - DBUS_TYPE_G_UCHAR_ARRAY, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + g_param_spec_variant (NM_AP_SSID, "", "", + G_VARIANT_TYPE ("ay"), + NULL, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_FREQUENCY, @@ -1034,9 +1033,9 @@ nm_ap_class_init (NMAccessPointClass *ap_class) g_object_class_install_property (object_class, PROP_STRENGTH, - g_param_spec_char (NM_AP_STRENGTH, "", "", - G_MININT8, G_MAXINT8, 0, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + g_param_spec_uchar (NM_AP_STRENGTH, "", "", + 0, G_MAXINT8, 0, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_LAST_SEEN, @@ -1045,6 +1044,7 @@ nm_ap_class_init (NMAccessPointClass *ap_class) G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (ap_class), - &dbus_glib_nm_access_point_object_info); + NMDBUS_TYPE_ACCESS_POINT_SKELETON, + NULL); } diff --git a/src/devices/wifi/tests/Makefile.am b/src/devices/wifi/tests/Makefile.am index 4cac07e8c0..bc342eaa46 100644 --- a/src/devices/wifi/tests/Makefile.am +++ b/src/devices/wifi/tests/Makefile.am @@ -1,4 +1,5 @@ AM_CPPFLAGS = \ + -I$(top_builddir)/introspection \ -I$(top_srcdir)/include \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ @@ -9,8 +10,7 @@ AM_CPPFLAGS = \ -DG_LOG_DOMAIN=\""NetworkManager-wifi"\" \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ - $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) + $(GLIB_CFLAGS) noinst_PROGRAMS = test-wifi-ap-utils diff --git a/src/devices/wifi/tests/test-wifi-ap-utils.c b/src/devices/wifi/tests/test-wifi-ap-utils.c index 9b0092c3d9..fa0aec0ed4 100644 --- a/src/devices/wifi/tests/test-wifi-ap-utils.c +++ b/src/devices/wifi/tests/test-wifi-ap-utils.c @@ -24,7 +24,6 @@ #include "nm-default.h" #include "nm-wifi-ap-utils.h" -#include "nm-dbus-glib-types.h" #include "nm-core-internal.h" diff --git a/src/devices/wwan/Makefile.am b/src/devices/wwan/Makefile.am index b382c2efa3..56d4fb6665 100644 --- a/src/devices/wwan/Makefile.am +++ b/src/devices/wwan/Makefile.am @@ -8,13 +8,14 @@ AM_CPPFLAGS = \ -I${top_srcdir}/src/devices \ -I${top_srcdir}/src/settings \ -I${top_srcdir}/src/platform \ + -I${top_builddir}/introspection \ -I${top_srcdir}/include \ -I${top_builddir}/libnm-core \ -I${top_srcdir}/libnm-core \ -DG_LOG_DOMAIN=\""NetworkManager-wwan"\" \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ - $(DBUS_CFLAGS) \ + $(GLIB_CFLAGS) \ $(MM_GLIB_CFLAGS) BUILT_SOURCES = $(null) @@ -45,31 +46,29 @@ WWAN_SYMBOL_VIS_FILE=$(srcdir)/wwan-exports.ver libnm_wwan_la_LDFLAGS = \ -avoid-version \ -Wl,--version-script=$(WWAN_SYMBOL_VIS_FILE) -libnm_wwan_la_LIBADD = $(DBUS_LIBS) $(MM_GLIB_LIBS) +libnm_wwan_la_LIBADD = \ + $(top_builddir)/introspection/libnmdbus.la \ + $(GLIB_LIBS) \ + $(MM_GLIB_LIBS) ########################################################### -nm-device-modem-glue.h: $(top_srcdir)/introspection/nm-device-modem.xml - dbus-binding-tool --prefix=nm_device_modem --mode=glib-server --output=$@ $< - -BUILT_SOURCES += nm-device-modem-glue.h - SYMBOL_VIS_FILE=$(srcdir)/exports.ver libnm_device_plugin_wwan_la_SOURCES = \ nm-wwan-factory.c \ nm-wwan-factory.h \ nm-device-modem.c \ - nm-device-modem.h \ - nm-device-modem-glue.h + nm-device-modem.h libnm_device_plugin_wwan_la_LDFLAGS = \ -module -avoid-version \ -Wl,--version-script=$(SYMBOL_VIS_FILE) libnm_device_plugin_wwan_la_LIBADD = \ + $(top_builddir)/introspection/libnmdbus.la \ libnm-wwan.la \ - $(DBUS_LIBS) + $(GLIB_LIBS) ########################################################### diff --git a/src/devices/wwan/nm-device-modem.c b/src/devices/wwan/nm-device-modem.c index 9fdcef46ea..b875080b4b 100644 --- a/src/devices/wwan/nm-device-modem.c +++ b/src/devices/wwan/nm-device-modem.c @@ -35,12 +35,12 @@ #include "nm-device-logging.h" _LOG_DECLARE_SELF(NMDeviceModem); +#include "nmdbus-device-modem.h" + G_DEFINE_TYPE (NMDeviceModem, nm_device_modem, NM_TYPE_DEVICE) #define NM_DEVICE_MODEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_MODEM, NMDeviceModemPrivate)) -#include "nm-device-modem-glue.h" - typedef struct { NMModem *modem; NMDeviceModemCapabilities caps; @@ -794,5 +794,6 @@ nm_device_modem_class_init (NMDeviceModemClass *mclass) G_PARAM_STATIC_STRINGS)); nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (mclass), - &dbus_glib_nm_device_modem_object_info); + NMDBUS_TYPE_DEVICE_MODEM_SKELETON, + NULL); } diff --git a/src/devices/wwan/nm-modem.c b/src/devices/wwan/nm-modem.c index be35ffd31f..d6433a085d 100644 --- a/src/devices/wwan/nm-modem.c +++ b/src/devices/wwan/nm-modem.c @@ -28,7 +28,6 @@ #include "nm-default.h" #include "NetworkManagerUtils.h" #include "nm-device-private.h" -#include "nm-dbus-glib-types.h" #include "nm-modem-enum-types.h" #include "nm-route-manager.h" diff --git a/src/nm-activation-request.c b/src/nm-activation-request.c index e10182c823..3ced2a3dcf 100644 --- a/src/nm-activation-request.c +++ b/src/nm-activation-request.c @@ -461,7 +461,7 @@ get_property (GObject *object, guint prop_id, device = nm_active_connection_get_device (NM_ACTIVE_CONNECTION (object)); if (!device) { - g_value_set_boxed (value, "/"); + g_value_set_string (value, "/"); return; } diff --git a/src/nm-active-connection.c b/src/nm-active-connection.c index aeb5bd7835..9a51e2e1fc 100644 --- a/src/nm-active-connection.c +++ b/src/nm-active-connection.c @@ -24,13 +24,13 @@ #include "nm-default.h" #include "nm-active-connection.h" #include "nm-dbus-interface.h" -#include "nm-dbus-glib-types.h" #include "nm-device.h" #include "nm-settings-connection.h" #include "nm-auth-utils.h" #include "nm-auth-subject.h" #include "NetworkManagerUtils.h" -#include "nm-active-connection-glue.h" + +#include "nmdbus-active-connection.h" /* Base class for anything implementing the Connection.Active D-Bus interface */ G_DEFINE_ABSTRACT_TYPE (NMActiveConnection, nm_active_connection, NM_TYPE_EXPORTED_OBJECT) @@ -586,7 +586,7 @@ nm_active_connection_get_assumed (NMActiveConnection *self) static void auth_done (NMAuthChain *chain, GError *error, - DBusGMethodInvocation *unused, + GDBusMethodInvocation *unused, gpointer user_data) { NMActiveConnection *self = NM_ACTIVE_CONNECTION (user_data); @@ -720,10 +720,10 @@ set_property (GObject *object, guint prop_id, nm_active_connection_set_master (NM_ACTIVE_CONNECTION (object), g_value_get_object (value)); break; case PROP_SPECIFIC_OBJECT: - tmp = g_value_get_boxed (value); + tmp = g_value_get_string (value); /* NM uses "/" to mean NULL */ if (g_strcmp0 (tmp, "/") != 0) - priv->specific_object = g_value_dup_boxed (value); + priv->specific_object = g_strdup (tmp); break; case PROP_DEFAULT: priv->is_default = !!g_value_get_boolean (value); @@ -752,7 +752,7 @@ get_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_CONNECTION: - g_value_set_boxed (value, nm_connection_get_path (priv->connection)); + g_value_set_string (value, nm_connection_get_path (priv->connection)); break; case PROP_ID: g_value_set_string (value, nm_connection_get_id (priv->connection)); @@ -764,13 +764,14 @@ get_property (GObject *object, guint prop_id, g_value_set_string (value, nm_connection_get_connection_type (priv->connection)); break; case PROP_SPECIFIC_OBJECT: - g_value_set_boxed (value, priv->specific_object ? priv->specific_object : "/"); + g_value_set_string (value, priv->specific_object ? priv->specific_object : "/"); break; case PROP_DEVICES: - devices = g_ptr_array_sized_new (1); + devices = g_ptr_array_sized_new (2); if (priv->device && priv->state < NM_ACTIVE_CONNECTION_STATE_DEACTIVATED) g_ptr_array_add (devices, g_strdup (nm_exported_object_get_path (NM_EXPORTED_OBJECT (priv->device)))); - g_value_take_boxed (value, devices); + g_ptr_array_add (devices, NULL); + g_value_take_boxed (value, (char **) g_ptr_array_free (devices, FALSE)); break; case PROP_STATE: if (priv->state_set) @@ -787,19 +788,19 @@ get_property (GObject *object, guint prop_id, break; case PROP_IP4_CONFIG: /* The IP and DHCP config properties may be overridden by a subclass */ - g_value_set_boxed (value, "/"); + g_value_set_string (value, "/"); break; case PROP_DHCP4_CONFIG: - g_value_set_boxed (value, "/"); + g_value_set_string (value, "/"); break; case PROP_DEFAULT6: g_value_set_boolean (value, priv->is_default6); break; case PROP_IP6_CONFIG: - g_value_set_boxed (value, "/"); + g_value_set_string (value, "/"); break; case PROP_DHCP6_CONFIG: - g_value_set_boxed (value, "/"); + g_value_set_string (value, "/"); break; case PROP_VPN: g_value_set_boolean (value, priv->vpn); @@ -888,10 +889,10 @@ nm_active_connection_class_init (NMActiveConnectionClass *ac_class) /* D-Bus exported properties */ g_object_class_install_property (object_class, PROP_CONNECTION, - g_param_spec_boxed (NM_ACTIVE_CONNECTION_CONNECTION, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_ACTIVE_CONNECTION_CONNECTION, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_ID, @@ -916,15 +917,15 @@ nm_active_connection_class_init (NMActiveConnectionClass *ac_class) g_object_class_install_property (object_class, PROP_SPECIFIC_OBJECT, - g_param_spec_boxed (NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT, "", "", + NULL, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_DEVICES, g_param_spec_boxed (NM_ACTIVE_CONNECTION_DEVICES, "", "", - DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH, + G_TYPE_STRV, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); @@ -946,17 +947,17 @@ nm_active_connection_class_init (NMActiveConnectionClass *ac_class) g_object_class_install_property (object_class, PROP_IP4_CONFIG, - g_param_spec_boxed (NM_ACTIVE_CONNECTION_IP4_CONFIG, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_ACTIVE_CONNECTION_IP4_CONFIG, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_DHCP4_CONFIG, - g_param_spec_boxed (NM_ACTIVE_CONNECTION_DHCP4_CONFIG, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_ACTIVE_CONNECTION_DHCP4_CONFIG, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_DEFAULT6, @@ -967,17 +968,17 @@ nm_active_connection_class_init (NMActiveConnectionClass *ac_class) g_object_class_install_property (object_class, PROP_IP6_CONFIG, - g_param_spec_boxed (NM_ACTIVE_CONNECTION_IP6_CONFIG, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_ACTIVE_CONNECTION_IP6_CONFIG, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_DHCP6_CONFIG, - g_param_spec_boxed (NM_ACTIVE_CONNECTION_DHCP6_CONFIG, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_ACTIVE_CONNECTION_DHCP6_CONFIG, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_VPN, @@ -988,10 +989,10 @@ nm_active_connection_class_init (NMActiveConnectionClass *ac_class) g_object_class_install_property (object_class, PROP_MASTER, - g_param_spec_boxed (NM_ACTIVE_CONNECTION_MASTER, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_ACTIVE_CONNECTION_MASTER, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); /* Internal properties */ g_object_class_install_property @@ -1045,6 +1046,7 @@ nm_active_connection_class_init (NMActiveConnectionClass *ac_class) G_TYPE_NONE, 1, G_TYPE_UINT); nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (ac_class), - &dbus_glib_nm_active_connection_object_info); + NMDBUS_TYPE_ACTIVE_CONNECTION_SKELETON, + NULL); } diff --git a/src/vpn-manager/nm-vpn-connection.c b/src/vpn-manager/nm-vpn-connection.c index 2a1a16a23a..ed3666328a 100644 --- a/src/vpn-manager/nm-vpn-connection.c +++ b/src/vpn-manager/nm-vpn-connection.c @@ -34,7 +34,6 @@ #include "nm-ip6-config.h" #include "nm-platform.h" #include "nm-active-connection.h" -#include "nm-dbus-glib-types.h" #include "NetworkManagerUtils.h" #include "settings/nm-settings-connection.h" #include "nm-dispatcher.h" @@ -44,7 +43,7 @@ #include "nm-route-manager.h" #include "nm-firewall-manager.h" -#include "nm-vpn-connection-glue.h" +#include "nmdbus-vpn-connection.h" G_DEFINE_TYPE (NMVpnConnection, nm_vpn_connection, NM_TYPE_ACTIVE_CONNECTION) @@ -2354,6 +2353,7 @@ nm_vpn_connection_class_init (NMVpnConnectionClass *connection_class) G_TYPE_NONE, 0); nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (connection_class), - &dbus_glib_nm_vpn_connection_object_info); + NMDBUS_TYPE_VPN_CONNECTION_SKELETON, + NULL); } From 8f36727ac86ff47b97ffc0c856c1738f8322aa9b Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Wed, 15 Apr 2015 14:53:30 -0400 Subject: [PATCH 09/14] ppp-manager: port to gdbus --- introspection/nm-ppp-manager.xml | 5 -- src/ppp-manager/nm-ppp-manager.c | 136 +++++++++++++------------------ 2 files changed, 57 insertions(+), 84 deletions(-) diff --git a/introspection/nm-ppp-manager.xml b/introspection/nm-ppp-manager.xml index 5ea1e8b16b..e4c6a2c869 100644 --- a/introspection/nm-ppp-manager.xml +++ b/introspection/nm-ppp-manager.xml @@ -5,24 +5,19 @@ - - - - - diff --git a/src/ppp-manager/nm-ppp-manager.c b/src/ppp-manager/nm-ppp-manager.c index e3739d95d5..dcc916902a 100644 --- a/src/ppp-manager/nm-ppp-manager.c +++ b/src/ppp-manager/nm-ppp-manager.c @@ -48,22 +48,7 @@ #include "nm-platform.h" #include "nm-core-internal.h" -static void impl_ppp_manager_need_secrets (NMPPPManager *manager, - DBusGMethodInvocation *context); - -static gboolean impl_ppp_manager_set_state (NMPPPManager *manager, - guint32 state, - GError **err); - -static gboolean impl_ppp_manager_set_ip4_config (NMPPPManager *manager, - GHashTable *config, - GError **err); - -static gboolean impl_ppp_manager_set_ip6_config (NMPPPManager *manager, - GHashTable *config, - GError **err); - -#include "nm-ppp-manager-glue.h" +#include "nmdbus-ppp-manager.h" static void _ppp_cleanup (NMPPPManager *manager); static void _ppp_kill (NMPPPManager *manager); @@ -77,7 +62,7 @@ typedef struct { char *parent_iface; NMActRequest *act_req; - DBusGMethodInvocation *pending_secrets_context; + GDBusMethodInvocation *pending_secrets_context; guint32 secrets_id; const char *secrets_setting_name; @@ -341,14 +326,13 @@ ppp_secrets_cb (NMActRequest *req, if (error) { nm_log_warn (LOGD_PPP, "%s", error->message); - dbus_g_method_return_error (priv->pending_secrets_context, error); + g_dbus_method_invocation_return_gerror (priv->pending_secrets_context, error); goto out; } if (!extract_details_from_connection (connection, priv->secrets_setting_name, &username, &password, &local)) { nm_log_warn (LOGD_PPP, "%s", local->message); - dbus_g_method_return_error (priv->pending_secrets_context, local); - g_clear_error (&local); + g_dbus_method_invocation_take_error (priv->pending_secrets_context, local); goto out; } @@ -358,7 +342,9 @@ ppp_secrets_cb (NMActRequest *req, * against libnm just to parse this. So instead, let's just send what * it needs. */ - dbus_g_method_return (priv->pending_secrets_context, username, password); + g_dbus_method_invocation_return_value ( + priv->pending_secrets_context, + g_variant_new ("(ss)", username, password)); out: priv->pending_secrets_context = NULL; @@ -368,7 +354,7 @@ ppp_secrets_cb (NMActRequest *req, static void impl_ppp_manager_need_secrets (NMPPPManager *manager, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context) { NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); NMConnection *connection; @@ -391,8 +377,7 @@ impl_ppp_manager_need_secrets (NMPPPManager *manager, ppp_secrets_cb (priv->act_req, priv->secrets_id, connection, NULL, manager); } else { nm_log_warn (LOGD_PPP, "%s", error->message); - dbus_g_method_return_error (priv->pending_secrets_context, error); - g_clear_error (&error); + g_dbus_method_invocation_take_error (priv->pending_secrets_context, error); } return; } @@ -418,33 +403,33 @@ impl_ppp_manager_need_secrets (NMPPPManager *manager, g_ptr_array_free (hints, TRUE); } -static gboolean impl_ppp_manager_set_state (NMPPPManager *manager, - guint32 state, - GError **err) +static void +impl_ppp_manager_set_state (NMPPPManager *manager, + GDBusMethodInvocation *context, + guint32 state) { g_signal_emit (manager, signals[STATE_CHANGED], 0, state); - return TRUE; + g_dbus_method_invocation_return_value (context, NULL); } static gboolean set_ip_config_common (NMPPPManager *self, - GHashTable *hash, + GVariant *config_dict, const char *iface_prop, guint32 *out_mtu) { NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (self); NMConnection *connection; NMSettingPpp *s_ppp; - GValue *val; + const char *iface; - val = g_hash_table_lookup (hash, iface_prop); - if (!val || !G_VALUE_HOLDS_STRING (val)) { + if (!g_variant_lookup (config_dict, iface_prop, "&s", &iface)) { nm_log_err (LOGD_PPP, "no interface received!"); return FALSE; } if (priv->ip_iface == NULL) - priv->ip_iface = g_value_dup_string (val); + priv->ip_iface = g_strdup (iface); /* Got successful IP config; obviously the secrets worked */ connection = nm_act_request_get_connection (priv->act_req); @@ -460,17 +445,16 @@ set_ip_config_common (NMPPPManager *self, return TRUE; } -static gboolean +static void impl_ppp_manager_set_ip4_config (NMPPPManager *manager, - GHashTable *config_hash, - GError **err) + GDBusMethodInvocation *context, + GVariant *config_dict) { NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); NMIP4Config *config; NMPlatformIP4Address address; - GValue *val; - int i; - guint32 mtu = 0; + guint32 u32; + GVariantIter *iter; nm_log_info (LOGD_PPP, "PPP manager (IPv4 Config Get) reply received."); @@ -481,19 +465,16 @@ impl_ppp_manager_set_ip4_config (NMPPPManager *manager, memset (&address, 0, sizeof (address)); address.plen = 32; - val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_GATEWAY); - if (val) { - nm_ip4_config_set_gateway (config, g_value_get_uint (val)); - address.peer_address = g_value_get_uint (val); + if (g_variant_lookup (config_dict, NM_PPP_IP4_CONFIG_GATEWAY, "u", &u32)) { + nm_ip4_config_set_gateway (config, u32); + address.peer_address = u32; } - val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_ADDRESS); - if (val) - address.address = g_value_get_uint (val); + if (g_variant_lookup (config_dict, NM_PPP_IP4_CONFIG_ADDRESS, "u", &u32)) + address.address = u32; - val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_PREFIX); - if (val) - address.plen = g_value_get_uint (val); + if (g_variant_lookup (config_dict, NM_PPP_IP4_CONFIG_PREFIX, "u", &u32)) + address.plen = u32; if (address.address && address.plen) { address.source = NM_IP_CONFIG_SOURCE_PPP; @@ -503,55 +484,47 @@ impl_ppp_manager_set_ip4_config (NMPPPManager *manager, goto out; } - val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_DNS); - if (val) { - GArray *dns = (GArray *) g_value_get_boxed (val); - - for (i = 0; i < dns->len; i++) - nm_ip4_config_add_nameserver (config, g_array_index (dns, guint, i)); + if (g_variant_lookup (config_dict, NM_PPP_IP4_CONFIG_DNS, "au", &iter)) { + while (g_variant_iter_next (iter, "u", &u32)) + nm_ip4_config_add_nameserver (config, u32); + g_variant_iter_free (iter); } - val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_WINS); - if (val) { - GArray *wins = (GArray *) g_value_get_boxed (val); - - for (i = 0; i < wins->len; i++) - nm_ip4_config_add_wins (config, g_array_index (wins, guint, i)); + if (g_variant_lookup (config_dict, NM_PPP_IP4_CONFIG_WINS, "au", &iter)) { + while (g_variant_iter_next (iter, "u", &u32)) + nm_ip4_config_add_wins (config, u32); + g_variant_iter_free (iter); } - if (!set_ip_config_common (manager, config_hash, NM_PPP_IP4_CONFIG_INTERFACE, &mtu)) + if (!set_ip_config_common (manager, config_dict, NM_PPP_IP4_CONFIG_INTERFACE, &u32)) goto out; - if (mtu) - nm_ip4_config_set_mtu (config, mtu, NM_IP_CONFIG_SOURCE_PPP); + if (u32) + nm_ip4_config_set_mtu (config, u32, NM_IP_CONFIG_SOURCE_PPP); /* Push the IP4 config up to the device */ g_signal_emit (manager, signals[IP4_CONFIG], 0, priv->ip_iface, config); out: g_object_unref (config); - return TRUE; + g_dbus_method_invocation_return_value (context, NULL); } /* Converts the named Interface Identifier item to an IPv6 LL address and * returns the IID. */ static gboolean -iid_value_to_ll6_addr (GHashTable *hash, +iid_value_to_ll6_addr (GVariant *dict, const char *prop, struct in6_addr *out_addr, NMUtilsIPv6IfaceId *out_iid) { - GValue *val; guint64 iid; - val = g_hash_table_lookup (hash, prop); - if (!val || !G_VALUE_HOLDS (val, G_TYPE_UINT64)) { + if (!g_variant_lookup (dict, prop, "t", &iid)) { nm_log_dbg (LOGD_PPP, "pppd plugin property '%s' missing or not a uint64", prop); return FALSE; } - - iid = g_value_get_uint64 (val); g_return_val_if_fail (iid != 0, FALSE); /* Construct an IPv6 LL address from the interface identifier. See @@ -566,10 +539,10 @@ iid_value_to_ll6_addr (GHashTable *hash, return TRUE; } -static gboolean +static void impl_ppp_manager_set_ip6_config (NMPPPManager *manager, - GHashTable *hash, - GError **err) + GDBusMethodInvocation *context, + GVariant *config_dict) { NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); NMIP6Config *config; @@ -586,15 +559,15 @@ impl_ppp_manager_set_ip6_config (NMPPPManager *manager, memset (&addr, 0, sizeof (addr)); addr.plen = 64; - if (iid_value_to_ll6_addr (hash, NM_PPP_IP6_CONFIG_PEER_IID, &a, NULL)) { + if (iid_value_to_ll6_addr (config_dict, NM_PPP_IP6_CONFIG_PEER_IID, &a, NULL)) { nm_ip6_config_set_gateway (config, &a); addr.peer_address = a; } - if (iid_value_to_ll6_addr (hash, NM_PPP_IP6_CONFIG_OUR_IID, &addr.address, &iid)) { + if (iid_value_to_ll6_addr (config_dict, NM_PPP_IP6_CONFIG_OUR_IID, &addr.address, &iid)) { nm_ip6_config_add_address (config, &addr); - if (set_ip_config_common (manager, hash, NM_PPP_IP6_CONFIG_INTERFACE, NULL)) { + if (set_ip_config_common (manager, config_dict, NM_PPP_IP6_CONFIG_INTERFACE, NULL)) { /* Push the IPv6 config and interface identifier up to the device */ g_signal_emit (manager, signals[IP6_CONFIG], 0, priv->ip_iface, &iid, config); } @@ -602,7 +575,7 @@ impl_ppp_manager_set_ip6_config (NMPPPManager *manager, nm_log_err (LOGD_PPP, "invalid IPv6 address received!"); g_object_unref (config); - return TRUE; + g_dbus_method_invocation_return_value (context, NULL); } static void @@ -667,7 +640,12 @@ nm_ppp_manager_class_init (NMPPPManagerClass *manager_class) G_TYPE_UINT, G_TYPE_UINT); nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (manager_class), - &dbus_glib_nm_ppp_manager_object_info); + NMDBUS_TYPE_PPP_MANAGER_SKELETON, + "NeedSecrets", impl_ppp_manager_need_secrets, + "SetIp4Config", impl_ppp_manager_set_ip4_config, + "SetIp6Config", impl_ppp_manager_set_ip6_config, + "SetState", impl_ppp_manager_set_state, + NULL); } /*******************************************/ From 7f6e39ec6ecc8c417603b39e6cc557bf79e593cf Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Mon, 23 Mar 2015 16:01:24 -0400 Subject: [PATCH 10/14] dhcp-manager: port to gdbus The existing code was somewhat confusing because it used string->GValue hash tables in some places, and string->string hash tables in other places. In the new version, the string->GValue hash tables become GVariants, but the string->string hash tables stay as hash tables, so you can tell them apart more easily. --- src/dhcp-manager/Makefile.am | 12 --- src/dhcp-manager/nm-dhcp-client.c | 43 +++++---- src/dhcp-manager/nm-dhcp-client.h | 2 +- src/dhcp-manager/nm-dhcp-helper.c | 78 +-------------- src/dhcp-manager/nm-dhcp-helper.conf | 13 --- src/dhcp-manager/nm-dhcp-listener.c | 139 +++++++++++---------------- src/dhcp-manager/nm-dhcp-manager.c | 5 +- 7 files changed, 88 insertions(+), 204 deletions(-) delete mode 100644 src/dhcp-manager/nm-dhcp-helper.conf diff --git a/src/dhcp-manager/Makefile.am b/src/dhcp-manager/Makefile.am index 32668d8dbc..6437dddd94 100644 --- a/src/dhcp-manager/Makefile.am +++ b/src/dhcp-manager/Makefile.am @@ -12,15 +12,3 @@ nm_dhcp_helper_CPPFLAGS = \ -DNMRUNDIR=\"$(nmrundir)\" nm_dhcp_helper_LDADD = $(GLIB_LIBS) - - -# FIXME: remove when dbus-glib >= 0.100 or GDBus is required -dhcp_helper_conf = nm-dhcp-helper.conf - -if !HAVE_DBUS_GLIB_100 -dbusservicedir = $(DBUS_SYS_DIR) -dbusservice_DATA = $(dhcp_helper_conf) -endif - -EXTRA_DIST = $(dhcp_helper_conf) - diff --git a/src/dhcp-manager/nm-dhcp-client.c b/src/dhcp-manager/nm-dhcp-client.c index 1032812b9f..805b2ea099 100644 --- a/src/dhcp-manager/nm-dhcp-client.c +++ b/src/dhcp-manager/nm-dhcp-client.c @@ -31,7 +31,6 @@ #include "nm-default.h" #include "NetworkManagerUtils.h" #include "nm-utils.h" -#include "nm-dbus-glib-types.h" #include "nm-dhcp-client.h" #include "nm-dhcp-utils.h" #include "nm-platform.h" @@ -648,21 +647,25 @@ nm_dhcp_client_stop (NMDhcpClient *self, gboolean release) /********************************************/ static char * -garray_to_string (GArray *array, const char *key) +bytearray_variant_to_string (GVariant *value, const char *key) { + const guint8 *array; + gsize length; GString *str; int i; unsigned char c; char *converted = NULL; - g_return_val_if_fail (array != NULL, NULL); + g_return_val_if_fail (value != NULL, NULL); + + array = g_variant_get_fixed_array (value, &length, 1); /* Since the DHCP options come through environment variables, they should * already be UTF-8 safe, but just make sure. */ - str = g_string_sized_new (array->len); - for (i = 0; i < array->len; i++) { - c = array->data[i]; + str = g_string_sized_new (length); + for (i = 0; i < length; i++) { + c = array[i]; /* Convert NULLs to spaces and non-ASCII characters to ? */ if (c == '\0') @@ -684,11 +687,10 @@ garray_to_string (GArray *array, const char *key) #define NEW_TAG "new_" static void -copy_option (const char * key, - GValue *value, - gpointer user_data) +maybe_add_option (GHashTable *hash, + const char *key, + GVariant *value) { - GHashTable *hash = user_data; char *str_value = NULL; const char **p; static const char *ignored_keys[] = { @@ -699,10 +701,7 @@ copy_option (const char * key, NULL }; - if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_UCHAR_ARRAY)) { - nm_log_warn (LOGD_DHCP, "key %s value type was not DBUS_TYPE_G_UCHAR_ARRAY", key); - return; - } + g_return_if_fail (g_variant_is_of_type (value, G_VARIANT_TYPE_BYTESTRING)); if (g_str_has_prefix (key, OLD_TAG)) return; @@ -718,7 +717,7 @@ copy_option (const char * key, if (!key[0]) return; - str_value = garray_to_string ((GArray *) g_value_get_boxed (value), key); + str_value = bytearray_variant_to_string (value, key); if (str_value) g_hash_table_insert (hash, g_strdup (key), str_value); } @@ -727,7 +726,7 @@ gboolean nm_dhcp_client_handle_event (gpointer unused, const char *iface, gint pid, - GHashTable *options, + GVariant *options, const char *reason, NMDhcpClient *self) { @@ -740,7 +739,7 @@ nm_dhcp_client_handle_event (gpointer unused, g_return_val_if_fail (NM_IS_DHCP_CLIENT (self), FALSE); g_return_val_if_fail (iface != NULL, FALSE); g_return_val_if_fail (pid > 0, FALSE); - g_return_val_if_fail (options != NULL, FALSE); + g_return_val_if_fail (g_variant_is_of_type (options, G_VARIANT_TYPE_VARDICT), FALSE); g_return_val_if_fail (reason != NULL, FALSE); priv = NM_DHCP_CLIENT_GET_PRIVATE (self); @@ -756,9 +755,17 @@ nm_dhcp_client_handle_event (gpointer unused, iface, reason, state_to_string (new_state)); if (new_state == NM_DHCP_STATE_BOUND) { + GVariantIter iter; + const char *name; + GVariant *value; + /* Copy options */ str_options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - g_hash_table_foreach (options, (GHFunc) copy_option, str_options); + g_variant_iter_init (&iter, options); + while (g_variant_iter_next (&iter, "{&sv}", &name, &value)) { + maybe_add_option (str_options, name, value); + g_variant_unref (value); + } /* Create the IP config */ g_warn_if_fail (g_hash_table_size (str_options)); diff --git a/src/dhcp-manager/nm-dhcp-client.h b/src/dhcp-manager/nm-dhcp-client.h index 6e6e0fe89d..ceabf13659 100644 --- a/src/dhcp-manager/nm-dhcp-client.h +++ b/src/dhcp-manager/nm-dhcp-client.h @@ -159,7 +159,7 @@ void nm_dhcp_client_set_state (NMDhcpClient *self, gboolean nm_dhcp_client_handle_event (gpointer unused, const char *iface, gint pid, - GHashTable *options, + GVariant *options, const char *reason, NMDhcpClient *self); diff --git a/src/dhcp-manager/nm-dhcp-helper.c b/src/dhcp-manager/nm-dhcp-helper.c index 4086094c90..dfef4dd8f4 100644 --- a/src/dhcp-manager/nm-dhcp-helper.c +++ b/src/dhcp-manager/nm-dhcp-helper.c @@ -75,69 +75,6 @@ build_signal_parameters (void) return g_variant_new ("(a{sv})", &builder); } -#if !HAVE_DBUS_GLIB_100 -/* It doesn't matter that nm-dhcp-helper doesn't use dbus-glib itself; the - * workaround code is for if the daemon is built with old dbus-glib. - */ - -static gboolean ever_acquired = FALSE; - -static void -on_name_acquired (GDBusConnection *connection, - const gchar *name, - gpointer user_data) -{ - GMainLoop *loop = user_data; - - ever_acquired = TRUE; - g_main_loop_quit (loop); -} - -static void -on_name_lost (GDBusConnection *connection, - const gchar *name, - gpointer user_data) -{ - if (ever_acquired) { - g_print ("Lost D-Bus name: exiting\n"); - exit (0); - } else { - g_printerr ("Error: Could not acquire the NM DHCP client service.\n"); - exit (1); - } -} - -static GDBusConnection * -shared_connection_init (void) -{ - GDBusConnection *connection; - GError *error = NULL; - GMainLoop *loop; - - connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); - if (!connection) { - g_dbus_error_strip_remote_error (error); - g_printerr ("Error: could not get the system bus. Make sure " - "the message bus daemon is running! Message: %s\n", - error->message); - g_error_free (error); - return NULL; - } - - loop = g_main_loop_new (NULL, FALSE); - g_bus_own_name_on_connection (connection, - "org.freedesktop.nm_dhcp_client", - 0, - on_name_acquired, - on_name_lost, - loop, NULL); - g_main_loop_run (loop); - g_main_loop_unref (loop); - - return connection; -} -#endif - static void fatal_error (void) { @@ -164,16 +101,11 @@ main (int argc, char *argv[]) G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT, NULL, NULL, &error); if (!connection) { -#if !HAVE_DBUS_GLIB_100 - connection = shared_connection_init (); -#endif - if (!connection) { - g_dbus_error_strip_remote_error (error); - g_printerr ("Error: could not connect to NetworkManager D-Bus socket: %s\n", - error->message); - g_error_free (error); - fatal_error (); - } + g_dbus_error_strip_remote_error (error); + g_printerr ("Error: could not connect to NetworkManager D-Bus socket: %s\n", + error->message); + g_error_free (error); + fatal_error (); } if (!g_dbus_connection_emit_signal (connection, diff --git a/src/dhcp-manager/nm-dhcp-helper.conf b/src/dhcp-manager/nm-dhcp-helper.conf deleted file mode 100644 index 0aeae6032c..0000000000 --- a/src/dhcp-manager/nm-dhcp-helper.conf +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - diff --git a/src/dhcp-manager/nm-dhcp-listener.c b/src/dhcp-manager/nm-dhcp-listener.c index 6fa53ff3e6..4ccf48c0aa 100644 --- a/src/dhcp-manager/nm-dhcp-listener.c +++ b/src/dhcp-manager/nm-dhcp-listener.c @@ -19,7 +19,6 @@ #include "config.h" -#include #include #include #include @@ -32,7 +31,6 @@ #include "nm-dhcp-listener.h" #include "nm-core-internal.h" #include "nm-bus-manager.h" -#include "nm-dbus-glib-types.h" #include "NetworkManagerUtils.h" #define NM_DHCP_CLIENT_DBUS_IFACE "org.freedesktop.nm_dhcp_client" @@ -43,8 +41,7 @@ typedef struct { NMBusManager * dbus_mgr; guint new_conn_id; guint dis_conn_id; - GHashTable * proxies; - DBusGProxy * proxy; + GHashTable * signal_handlers; } NMDhcpListenerPrivate; #define NM_DHCP_LISTENER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP_LISTENER, NMDhcpListenerPrivate)) @@ -60,61 +57,44 @@ static guint signals[LAST_SIGNAL] = { 0 }; /***************************************************/ static char * -garray_to_string (GArray *array, const char *key) +get_option (GVariant *options, const char *key) { - GString *str; - int i; - unsigned char c; - char *converted = NULL; + GVariant *value; + const guchar *bytes, *s; + gsize len; + char *converted, *d; - g_return_val_if_fail (array != NULL, NULL); + if (!g_variant_lookup (options, key, "@ay", &value)) + return NULL; + + bytes = g_variant_get_fixed_array (value, &len, 1); /* Since the DHCP options come through environment variables, they should * already be UTF-8 safe, but just make sure. */ - str = g_string_sized_new (array->len); - for (i = 0; i < array->len; i++) { - c = array->data[i]; - + converted = g_malloc (len + 1); + for (s = bytes, d = converted; s < bytes + len; s++, d++) { /* Convert NULLs to spaces and non-ASCII characters to ? */ - if (c == '\0') - c = ' '; - else if (c > 127) - c = '?'; - str = g_string_append_c (str, c); + if (*s == '\0') + *d = ' '; + else if (*s > 127) + *d = '?'; + else + *d = *s; } - str = g_string_append_c (str, '\0'); + *d = '\0'; - converted = str->str; - if (!g_utf8_validate (converted, -1, NULL)) - nm_log_warn (LOGD_DHCP, "DHCP option '%s' couldn't be converted to UTF-8", key); - g_string_free (str, FALSE); return converted; } -static char * -get_option (GHashTable *hash, const char *key) -{ - GValue *value; - - value = g_hash_table_lookup (hash, key); - if (value == NULL) - return NULL; - - if (G_VALUE_TYPE (value) != DBUS_TYPE_G_UCHAR_ARRAY) { - nm_log_warn (LOGD_DHCP, "unexpected key %s value type was not " - "DBUS_TYPE_G_UCHAR_ARRAY", - (char *) key); - return NULL; - } - - return garray_to_string ((GArray *) g_value_get_boxed (value), key); -} - static void -handle_event (DBusGProxy *proxy, - GHashTable *options, - gpointer user_data) +handle_event (GDBusConnection *connection, + const char *sender_name, + const char *object_path, + const char *interface_name, + const char *signal_name, + GVariant *parameters, + gpointer user_data) { NMDhcpListener *self = NM_DHCP_LISTENER (user_data); char *iface = NULL; @@ -122,6 +102,12 @@ handle_event (DBusGProxy *proxy, char *reason = NULL; gint pid; gboolean handled = FALSE; + GVariant *options; + + if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(a{sv})"))) + return; + + g_variant_get (parameters, "(@a{sv})", &options); iface = get_option (options, "interface"); if (iface == NULL) { @@ -155,39 +141,42 @@ out: g_free (iface); g_free (pid_str); g_free (reason); + g_variant_unref (options); } -#if HAVE_DBUS_GLIB_100 static void new_connection_cb (NMBusManager *mgr, - DBusGConnection *connection, + GDBusConnection *connection, NMDhcpListener *self) { - DBusGProxy *proxy; + NMDhcpListenerPrivate *priv = NM_DHCP_LISTENER_GET_PRIVATE (self); + guint id; - /* Create a new proxy for the client */ - proxy = dbus_g_proxy_new_for_peer (connection, "/", NM_DHCP_CLIENT_DBUS_IFACE); - dbus_g_proxy_add_signal (proxy, "Event", DBUS_TYPE_G_MAP_OF_VARIANT, G_TYPE_INVALID); - dbus_g_proxy_connect_signal (proxy, "Event", G_CALLBACK (handle_event), self, NULL); - - g_hash_table_insert (NM_DHCP_LISTENER_GET_PRIVATE (self)->proxies, connection, proxy); + id = g_dbus_connection_signal_subscribe (connection, + NULL, + NM_DHCP_CLIENT_DBUS_IFACE, + "Event", + NULL, + NULL, + G_DBUS_SIGNAL_FLAGS_NONE, + handle_event, self, NULL); + g_hash_table_insert (priv->signal_handlers, connection, GUINT_TO_POINTER (id)); } static void dis_connection_cb (NMBusManager *mgr, - DBusGConnection *connection, + GDBusConnection *connection, NMDhcpListener *self) { NMDhcpListenerPrivate *priv = NM_DHCP_LISTENER_GET_PRIVATE (self); - DBusGProxy *proxy; + guint id; - proxy = g_hash_table_lookup (priv->proxies, connection); - if (proxy) { - dbus_g_proxy_disconnect_signal (proxy, "Event", G_CALLBACK (handle_event), self); - g_hash_table_remove (priv->proxies, connection); + id = GPOINTER_TO_UINT (g_hash_table_lookup (priv->signal_handlers, connection)); + if (id) { + g_dbus_connection_signal_unsubscribe (connection, id); + g_hash_table_remove (priv->signal_handlers, connection); } } -#endif /***************************************************/ @@ -197,16 +186,12 @@ static void nm_dhcp_listener_init (NMDhcpListener *self) { NMDhcpListenerPrivate *priv = NM_DHCP_LISTENER_GET_PRIVATE (self); -#if !HAVE_DBUS_GLIB_100 - DBusGConnection *g_connection; -#endif - /* Maps DBusGConnection :: DBusGProxy */ - priv->proxies = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_object_unref); + /* Maps GDBusConnection :: GDBusProxy */ + priv->signal_handlers = g_hash_table_new (NULL, NULL); priv->dbus_mgr = nm_bus_manager_get (); -#if HAVE_DBUS_GLIB_100 /* Register the socket our DHCP clients will return lease info on */ nm_bus_manager_private_server_register (priv->dbus_mgr, PRIV_SOCK_PATH, PRIV_SOCK_TAG); priv->new_conn_id = g_signal_connect (priv->dbus_mgr, @@ -217,16 +202,6 @@ nm_dhcp_listener_init (NMDhcpListener *self) NM_BUS_MANAGER_PRIVATE_CONNECTION_DISCONNECTED "::" PRIV_SOCK_TAG, G_CALLBACK (dis_connection_cb), self); -#else - g_connection = nm_dbus_manager_get_connection (priv->dbus_mgr); - priv->proxy = dbus_g_proxy_new_for_name (g_connection, - "org.freedesktop.nm_dhcp_client", - "/", - NM_DHCP_CLIENT_DBUS_IFACE); - g_assert (priv->proxy); - dbus_g_proxy_add_signal (priv->proxy, "Event", DBUS_TYPE_G_MAP_OF_VARIANT, G_TYPE_INVALID); - dbus_g_proxy_connect_signal (priv->proxy, "Event", G_CALLBACK (handle_event), self, NULL); -#endif } static void @@ -244,11 +219,7 @@ dispose (GObject *object) } priv->dbus_mgr = NULL; - if (priv->proxies) { - g_hash_table_destroy (priv->proxies); - priv->proxies = NULL; - } - g_clear_object (&priv->proxy); + g_clear_pointer (&priv->signal_handlers, g_hash_table_destroy); G_OBJECT_CLASS (nm_dhcp_listener_parent_class)->dispose (object); } @@ -274,6 +245,6 @@ nm_dhcp_listener_class_init (NMDhcpListenerClass *listener_class) 4, G_TYPE_STRING, /* iface */ G_TYPE_INT, /* pid */ - G_TYPE_HASH_TABLE, /* options */ + G_TYPE_VARIANT, /* options */ G_TYPE_STRING); /* reason */ } diff --git a/src/dhcp-manager/nm-dhcp-manager.c b/src/dhcp-manager/nm-dhcp-manager.c index bea7032517..0737ab07d2 100644 --- a/src/dhcp-manager/nm-dhcp-manager.c +++ b/src/dhcp-manager/nm-dhcp-manager.c @@ -38,7 +38,6 @@ #include "nm-dhcp-dhcpcd.h" #include "nm-dhcp-systemd.h" #include "nm-config.h" -#include "nm-dbus-glib-types.h" #include "NetworkManagerUtils.h" #define DHCP_TIMEOUT 45 /* default DHCP timeout, in seconds */ @@ -180,7 +179,7 @@ get_client_type (const char *client, GError **error) static void client_state_changed (NMDhcpClient *client, NMDhcpState state, GObject *ip_config, - GHashTable *options, + GVariant *options, NMDhcpManager *self); static void @@ -200,7 +199,7 @@ static void client_state_changed (NMDhcpClient *client, NMDhcpState state, GObject *ip_config, - GHashTable *options, + GVariant *options, NMDhcpManager *self) { if (state >= NM_DHCP_STATE_TIMEOUT) From 6c8f860820a9d7a29e629b8d3d7f97145d385d33 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Wed, 15 Apr 2015 14:53:30 -0400 Subject: [PATCH 11/14] core: port IP/DHCP config to gdbus --- introspection/nm-ip6-config.xml | 4 + src/NetworkManagerUtils.c | 21 +++ src/NetworkManagerUtils.h | 1 + src/nm-dhcp4-config.c | 22 ++- src/nm-dhcp6-config.c | 22 ++- src/nm-ip4-config.c | 231 ++++++++++++++------------- src/nm-ip6-config.c | 266 +++++++++++++------------------- 7 files changed, 263 insertions(+), 304 deletions(-) diff --git a/introspection/nm-ip6-config.xml b/introspection/nm-ip6-config.xml index f2ef386ba1..1a107bf29f 100644 --- a/introspection/nm-ip6-config.xml +++ b/introspection/nm-ip6-config.xml @@ -35,6 +35,10 @@ + + The nameservers in use. diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c index 8f24ee0489..bab2755743 100644 --- a/src/NetworkManagerUtils.c +++ b/src/NetworkManagerUtils.c @@ -2991,3 +2991,24 @@ nm_utils_g_value_set_object_path_array (GValue *value, GSList *objects) } g_value_take_boxed (value, paths); } + +/** + * nm_utils_g_value_set_strv: + * @value: a #GValue, initialized to store a #G_TYPE_STRV + * @strings: a #GPtrArray of strings + * + * Converts @strings to a #GStrv and stores it in @value. + */ +void +nm_utils_g_value_set_strv (GValue *value, GPtrArray *strings) +{ + char **strv; + int i; + + strv = g_new (char *, strings->len + 1); + for (i = 0; i < strings->len; i++) + strv[i] = g_strdup (strings->pdata[i]); + strv[i] = NULL; + + g_value_take_boxed (value, strv); +} diff --git a/src/NetworkManagerUtils.h b/src/NetworkManagerUtils.h index 8eb4edf28c..a5a0563ba6 100644 --- a/src/NetworkManagerUtils.h +++ b/src/NetworkManagerUtils.h @@ -253,5 +253,6 @@ void _nm_utils_set_testing (NMUtilsTestFlags flags); void nm_utils_g_value_set_object_path (GValue *value, gpointer object); void nm_utils_g_value_set_object_path_array (GValue *value, GSList *objects); +void nm_utils_g_value_set_strv (GValue *value, GPtrArray *strings); #endif /* __NETWORKMANAGER_UTILS_H__ */ diff --git a/src/nm-dhcp4-config.c b/src/nm-dhcp4-config.c index 5b1345ceee..1aed32d9b6 100644 --- a/src/nm-dhcp4-config.c +++ b/src/nm-dhcp4-config.c @@ -25,10 +25,10 @@ #include "nm-default.h" #include "nm-dbus-interface.h" #include "nm-dhcp4-config.h" -#include "nm-dhcp4-config-glue.h" -#include "nm-dbus-glib-types.h" #include "nm-utils.h" +#include "nmdbus-dhcp4-config.h" + G_DEFINE_TYPE (NMDhcp4Config, nm_dhcp4_config, NM_TYPE_EXPORTED_OBJECT) #define NM_DHCP4_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP4_CONFIG, NMDhcp4ConfigPrivate)) @@ -128,11 +128,7 @@ get_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_OPTIONS: - /* dbus_g_value_parse_g_variant() will call g_value_init(), but - * @value is already inited. - */ - g_value_unset (value); - dbus_g_value_parse_g_variant (priv->options, value); + g_value_set_variant (value, priv->options); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -157,11 +153,13 @@ nm_dhcp4_config_class_init (NMDhcp4ConfigClass *config_class) /* properties */ g_object_class_install_property (object_class, PROP_OPTIONS, - g_param_spec_boxed (NM_DHCP4_CONFIG_OPTIONS, "", "", - DBUS_TYPE_G_MAP_OF_VARIANT, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_variant (NM_DHCP4_CONFIG_OPTIONS, "", "", + G_VARIANT_TYPE ("a{sv}"), + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (config_class), - &dbus_glib_nm_dhcp4_config_object_info); + NMDBUS_TYPE_DHCP4_CONFIG_SKELETON, + NULL); } diff --git a/src/nm-dhcp6-config.c b/src/nm-dhcp6-config.c index db7147a6a4..4855839275 100644 --- a/src/nm-dhcp6-config.c +++ b/src/nm-dhcp6-config.c @@ -25,10 +25,10 @@ #include "nm-default.h" #include "nm-dbus-interface.h" #include "nm-dhcp6-config.h" -#include "nm-dhcp6-config-glue.h" -#include "nm-dbus-glib-types.h" #include "nm-utils.h" +#include "nmdbus-dhcp6-config.h" + G_DEFINE_TYPE (NMDhcp6Config, nm_dhcp6_config, NM_TYPE_EXPORTED_OBJECT) #define NM_DHCP6_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP6_CONFIG, NMDhcp6ConfigPrivate)) @@ -128,11 +128,7 @@ get_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_OPTIONS: - /* dbus_g_value_parse_g_variant() will call g_value_init(), but - * @value is already inited. - */ - g_value_unset (value); - dbus_g_value_parse_g_variant (priv->options, value); + g_value_set_variant (value, priv->options); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -157,11 +153,13 @@ nm_dhcp6_config_class_init (NMDhcp6ConfigClass *config_class) /* properties */ g_object_class_install_property (object_class, PROP_OPTIONS, - g_param_spec_boxed (NM_DHCP6_CONFIG_OPTIONS, "", "", - DBUS_TYPE_G_MAP_OF_VARIANT, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_variant (NM_DHCP6_CONFIG_OPTIONS, "", "", + G_VARIANT_TYPE ("a{sv}"), + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (config_class), - &dbus_glib_nm_dhcp6_config_object_info); + NMDBUS_TYPE_DHCP6_CONFIG_SKELETON, + NULL); } diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c index f660407e39..02257d8c31 100644 --- a/src/nm-ip4-config.c +++ b/src/nm-ip4-config.c @@ -29,14 +29,14 @@ #include "nm-default.h" #include "nm-utils.h" #include "nm-platform.h" -#include "nm-dbus-glib-types.h" -#include "nm-ip4-config-glue.h" #include "NetworkManagerUtils.h" #include "nm-core-internal.h" #include "nm-route-manager.h" #include "nm-core-internal.h" #include "nm-macros-internal.h" +#include "nmdbus-ip4-config.h" + G_DEFINE_TYPE (NMIP4Config, nm_ip4_config, NM_TYPE_EXPORTED_OBJECT) #define NM_IP4_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_IP4_CONFIG, NMIP4ConfigPrivate)) @@ -2139,15 +2139,6 @@ finalize (GObject *object) G_OBJECT_CLASS (nm_ip4_config_parent_class)->finalize (object); } -static void -gvalue_destroy (gpointer data) -{ - GValue *value = (GValue *) data; - - g_value_unset (value); - g_slice_free (GValue, value); -} - static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) @@ -2161,127 +2152,116 @@ get_property (GObject *object, guint prop_id, break; case PROP_ADDRESS_DATA: { - GPtrArray *addresses = g_ptr_array_new (); + GVariantBuilder array_builder, addr_builder; int naddr = nm_ip4_config_get_num_addresses (config); int i; + g_variant_builder_init (&array_builder, G_VARIANT_TYPE ("aa{sv}")); for (i = 0; i < naddr; i++) { const NMPlatformIP4Address *address = nm_ip4_config_get_address (config, i); - GHashTable *addr_hash; - GValue *val; - addr_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, gvalue_destroy); - - val = g_slice_new0 (GValue); - g_value_init (val, G_TYPE_STRING); - g_value_set_string (val, nm_utils_inet4_ntop (address->address, NULL)); - g_hash_table_insert (addr_hash, "address", val); - - val = g_slice_new0 (GValue); - g_value_init (val, G_TYPE_UINT); - g_value_set_uint (val, address->plen); - g_hash_table_insert (addr_hash, "prefix", val); + g_variant_builder_init (&addr_builder, G_VARIANT_TYPE ("a{sv}")); + g_variant_builder_add (&addr_builder, "{sv}", + "address", + g_variant_new_string (nm_utils_inet4_ntop (address->address, NULL))); + g_variant_builder_add (&addr_builder, "{sv}", + "prefix", + g_variant_new_uint32 (address->plen)); if (*address->label) { - val = g_slice_new0 (GValue); - g_value_init (val, G_TYPE_STRING); - g_value_set_string (val, address->label); - g_hash_table_insert (addr_hash, "label", val); + g_variant_builder_add (&addr_builder, "{sv}", + "label", + g_variant_new_string (address->label)); } - g_ptr_array_add (addresses, addr_hash); + g_variant_builder_add (&array_builder, "a{sv}", &addr_builder); } - g_value_take_boxed (value, addresses); + g_value_take_variant (value, g_variant_builder_end (&array_builder)); } break; case PROP_ADDRESSES: { - GPtrArray *addresses = g_ptr_array_new (); + GVariantBuilder array_builder; int naddr = nm_ip4_config_get_num_addresses (config); int i; + g_variant_builder_init (&array_builder, G_VARIANT_TYPE ("aau")); for (i = 0; i < naddr; i++) { const NMPlatformIP4Address *address = nm_ip4_config_get_address (config, i); - GArray *array = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 3); - guint32 gateway = i == 0 ? priv->gateway : 0; + guint32 dbus_addr[3]; - g_array_append_val (array, address->address); - g_array_append_val (array, address->plen); - g_array_append_val (array, gateway); + dbus_addr[0] = address->address; + dbus_addr[1] = address->plen; + dbus_addr[2] = i == 0 ? priv->gateway : 0; - g_ptr_array_add (addresses, array); + g_variant_builder_add (&array_builder, "@au", + g_variant_new_fixed_array (G_VARIANT_TYPE_UINT32, + dbus_addr, 3, sizeof (guint32))); } - g_value_take_boxed (value, addresses); + g_value_take_variant (value, g_variant_builder_end (&array_builder)); } break; case PROP_ROUTE_DATA: { - GPtrArray *routes = g_ptr_array_new (); + GVariantBuilder array_builder, route_builder; guint nroutes = nm_ip4_config_get_num_routes (config); int i; + g_variant_builder_init (&array_builder, G_VARIANT_TYPE ("aa{sv}")); for (i = 0; i < nroutes; i++) { const NMPlatformIP4Route *route = nm_ip4_config_get_route (config, i); - GHashTable *route_hash; - GValue *val; - - route_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, gvalue_destroy); - - val = g_slice_new0 (GValue); - g_value_init (val, G_TYPE_STRING); - g_value_set_string (val, nm_utils_inet4_ntop (route->network, NULL)); - g_hash_table_insert (route_hash, "dest", val); - - val = g_slice_new0 (GValue); - g_value_init (val, G_TYPE_UINT); - g_value_set_uint (val, route->plen); - g_hash_table_insert (route_hash, "prefix", val); + g_variant_builder_init (&route_builder, G_VARIANT_TYPE ("a{sv}")); + g_variant_builder_add (&route_builder, "{sv}", + "dest", + g_variant_new_string (nm_utils_inet4_ntop (route->network, NULL))); + g_variant_builder_add (&route_builder, "{sv}", + "prefix", + g_variant_new_uint32 (route->plen)); if (route->gateway) { - val = g_slice_new0 (GValue); - g_value_init (val, G_TYPE_STRING); - g_value_set_string (val, nm_utils_inet4_ntop (route->gateway, NULL)); - g_hash_table_insert (route_hash, "next-hop", val); + g_variant_builder_add (&route_builder, "{sv}", + "next-hop", + g_variant_new_string (nm_utils_inet4_ntop (route->gateway, NULL))); } + g_variant_builder_add (&route_builder, "{sv}", + "metric", + g_variant_new_uint32 (route->metric)); - val = g_slice_new0 (GValue); - g_value_init (val, G_TYPE_UINT); - g_value_set_uint (val, route->metric); - g_hash_table_insert (route_hash, "metric", val); - - g_ptr_array_add (routes, route_hash); + g_variant_builder_add (&array_builder, "a{sv}", &route_builder); } - g_value_take_boxed (value, routes); + g_value_take_variant (value, g_variant_builder_end (&array_builder)); } break; case PROP_ROUTES: { - GPtrArray *routes = g_ptr_array_new (); + GVariantBuilder array_builder; guint nroutes = nm_ip4_config_get_num_routes (config); int i; + g_variant_builder_init (&array_builder, G_VARIANT_TYPE ("aau")); for (i = 0; i < nroutes; i++) { const NMPlatformIP4Route *route = nm_ip4_config_get_route (config, i); - GArray *array; + guint32 dbus_route[4]; /* legacy versions of nm_ip4_route_set_prefix() in libnm-util assert that the * plen is positive. Skip the default routes not to break older clients. */ if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT (route)) continue; - array = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 4); - g_array_append_val (array, route->network); - g_array_append_val (array, route->plen); - g_array_append_val (array, route->gateway); - g_array_append_val (array, route->metric); + dbus_route[0] = route->network; + dbus_route[1] = route->plen; + dbus_route[2] = route->gateway; + dbus_route[3] = route->metric; - g_ptr_array_add (routes, array); + g_variant_builder_add (&array_builder, "@au", + g_variant_new_fixed_array (G_VARIANT_TYPE_UINT32, + dbus_route, 4, sizeof (guint32))); } - g_value_take_boxed (value, routes); + g_value_take_variant (value, g_variant_builder_end (&array_builder)); } break; case PROP_GATEWAY: @@ -2291,19 +2271,27 @@ get_property (GObject *object, guint prop_id, g_value_set_string (value, NULL); break; case PROP_NAMESERVERS: - g_value_set_boxed (value, priv->nameservers); + g_value_take_variant (value, + g_variant_new_fixed_array (G_VARIANT_TYPE_UINT32, + priv->nameservers->data, + priv->nameservers->len, + sizeof (guint32))); break; case PROP_DOMAINS: - g_value_set_boxed (value, priv->domains); + nm_utils_g_value_set_strv (value, priv->domains); break; case PROP_SEARCHES: - g_value_set_boxed (value, priv->searches); + nm_utils_g_value_set_strv (value, priv->searches); break; case PROP_DNS_OPTIONS: - g_value_set_boxed (value, priv->dns_options); + nm_utils_g_value_set_strv (value, priv->dns_options); break; case PROP_WINS_SERVERS: - g_value_set_boxed (value, priv->wins); + g_value_take_variant (value, + g_variant_new_fixed_array (G_VARIANT_TYPE_UINT32, + priv->wins->data, + priv->wins->len, + sizeof (guint32))); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -2344,65 +2332,72 @@ nm_ip4_config_class_init (NMIP4ConfigClass *config_class) object_class->finalize = finalize; obj_properties[PROP_IFINDEX] = - g_param_spec_int (NM_IP4_CONFIG_IFINDEX, "", "", - -1, G_MAXINT, -1, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS); + g_param_spec_int (NM_IP4_CONFIG_IFINDEX, "", "", + -1, G_MAXINT, -1, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS); obj_properties[PROP_ADDRESS_DATA] = - g_param_spec_boxed (NM_IP4_CONFIG_ADDRESS_DATA, "", "", - DBUS_TYPE_NM_IP_ADDRESSES, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); + g_param_spec_variant (NM_IP4_CONFIG_ADDRESS_DATA, "", "", + G_VARIANT_TYPE ("aa{sv}"), + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); obj_properties[PROP_ADDRESSES] = - g_param_spec_boxed (NM_IP4_CONFIG_ADDRESSES, "", "", - DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); + g_param_spec_variant (NM_IP4_CONFIG_ADDRESSES, "", "", + G_VARIANT_TYPE ("aau"), + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); obj_properties[PROP_ROUTE_DATA] = - g_param_spec_boxed (NM_IP4_CONFIG_ROUTE_DATA, "", "", - DBUS_TYPE_NM_IP_ROUTES, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); + g_param_spec_variant (NM_IP4_CONFIG_ROUTE_DATA, "", "", + G_VARIANT_TYPE ("aa{sv}"), + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); obj_properties[PROP_ROUTES] = - g_param_spec_boxed (NM_IP4_CONFIG_ROUTES, "", "", - DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); + g_param_spec_variant (NM_IP4_CONFIG_ROUTES, "", "", + G_VARIANT_TYPE ("aau"), + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); obj_properties[PROP_GATEWAY] = g_param_spec_string (NM_IP4_CONFIG_GATEWAY, "", "", NULL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); obj_properties[PROP_NAMESERVERS] = - g_param_spec_boxed (NM_IP4_CONFIG_NAMESERVERS, "", "", - DBUS_TYPE_G_UINT_ARRAY, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); + g_param_spec_variant (NM_IP4_CONFIG_NAMESERVERS, "", "", + G_VARIANT_TYPE ("au"), + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); obj_properties[PROP_DOMAINS] = - g_param_spec_boxed (NM_IP4_CONFIG_DOMAINS, "", "", - DBUS_TYPE_G_ARRAY_OF_STRING, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); + g_param_spec_boxed (NM_IP4_CONFIG_DOMAINS, "", "", + G_TYPE_STRV, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); obj_properties[PROP_SEARCHES] = - g_param_spec_boxed (NM_IP4_CONFIG_SEARCHES, "", "", - DBUS_TYPE_G_ARRAY_OF_STRING, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); + g_param_spec_boxed (NM_IP4_CONFIG_SEARCHES, "", "", + G_TYPE_STRV, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); obj_properties[PROP_DNS_OPTIONS] = g_param_spec_boxed (NM_IP4_CONFIG_DNS_OPTIONS, "", "", - DBUS_TYPE_G_ARRAY_OF_STRING, + G_TYPE_STRV, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); obj_properties[PROP_WINS_SERVERS] = - g_param_spec_boxed (NM_IP4_CONFIG_WINS_SERVERS, "", "", - DBUS_TYPE_G_UINT_ARRAY, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); + g_param_spec_variant (NM_IP4_CONFIG_WINS_SERVERS, "", "", + G_VARIANT_TYPE ("au"), + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); g_object_class_install_properties (object_class, LAST_PROP, obj_properties); nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (config_class), - &dbus_glib_nm_ip4_config_object_info); + NMDBUS_TYPE_IP4_CONFIG_SKELETON, + NULL); } diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c index 4e37a73b17..20bc3fed80 100644 --- a/src/nm-ip6-config.c +++ b/src/nm-ip6-config.c @@ -29,13 +29,13 @@ #include "nm-utils.h" #include "nm-platform.h" -#include "nm-dbus-glib-types.h" -#include "nm-ip6-config-glue.h" #include "nm-route-manager.h" #include "nm-core-internal.h" #include "NetworkManagerUtils.h" #include "nm-macros-internal.h" +#include "nmdbus-ip6-config.h" + G_DEFINE_TYPE (NMIP6Config, nm_ip6_config, NM_TYPE_EXPORTED_OBJECT) #define NM_IP6_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_IP6_CONFIG, NMIP6ConfigPrivate)) @@ -1891,31 +1891,21 @@ finalize (GObject *object) static void nameservers_to_gvalue (GArray *array, GValue *value) { - GPtrArray *dns; + GVariantBuilder builder; guint i = 0; - dns = g_ptr_array_new (); + g_variant_builder_init (&builder, G_VARIANT_TYPE ("aay")); while (array && (i < array->len)) { struct in6_addr *addr; - GByteArray *bytearray; - addr = &g_array_index (array, struct in6_addr, i++); - bytearray = g_byte_array_sized_new (16); - g_byte_array_append (bytearray, (guint8 *) addr->s6_addr, 16); - g_ptr_array_add (dns, bytearray); + addr = &g_array_index (array, struct in6_addr, i++); + g_variant_builder_add (&builder, "@ay", + g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, + &addr, 16, 1)); } - g_value_take_boxed (value, dns); -} - -static void -gvalue_destroy (gpointer data) -{ - GValue *value = (GValue *) data; - - g_value_unset (value); - g_slice_free (GValue, value); + g_value_take_variant (value, g_variant_builder_end (&builder)); } static void @@ -1931,163 +1921,109 @@ get_property (GObject *object, guint prop_id, break; case PROP_ADDRESS_DATA: { - GPtrArray *addresses = g_ptr_array_new (); + GVariantBuilder array_builder, addr_builder; int naddr = nm_ip6_config_get_num_addresses (config); int i; + g_variant_builder_init (&array_builder, G_VARIANT_TYPE ("aa{sv}")); for (i = 0; i < naddr; i++) { const NMPlatformIP6Address *address = nm_ip6_config_get_address (config, i); - GHashTable *addr_hash; - GValue *val; - addr_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, gvalue_destroy); + g_variant_builder_init (&addr_builder, G_VARIANT_TYPE ("a{sv}")); + g_variant_builder_add (&addr_builder, "{sv}", + "address", + g_variant_new_string (nm_utils_inet6_ntop (&address->address, NULL))); + g_variant_builder_add (&addr_builder, "{sv}", + "prefix", + g_variant_new_uint32 (address->plen)); - val = g_slice_new0 (GValue); - g_value_init (val, G_TYPE_STRING); - g_value_set_string (val, nm_utils_inet6_ntop (&address->address, NULL)); - g_hash_table_insert (addr_hash, "address", val); - - val = g_slice_new0 (GValue); - g_value_init (val, G_TYPE_UINT); - g_value_set_uint (val, address->plen); - g_hash_table_insert (addr_hash, "prefix", val); - - g_ptr_array_add (addresses, addr_hash); + g_variant_builder_add (&array_builder, "a{sv}", &addr_builder); } - g_value_take_boxed (value, addresses); + g_value_take_variant (value, g_variant_builder_end (&array_builder)); } break; case PROP_ADDRESSES: { - GPtrArray *addresses = g_ptr_array_new (); + GVariantBuilder array_builder; const struct in6_addr *gateway = nm_ip6_config_get_gateway (config); int naddr = nm_ip6_config_get_num_addresses (config); int i; + g_variant_builder_init (&array_builder, G_VARIANT_TYPE ("a(ayuay)")); for (i = 0; i < naddr; i++) { const NMPlatformIP6Address *address = nm_ip6_config_get_address (config, i); - GValueArray *array = g_value_array_new (3); - GValue element = G_VALUE_INIT; - GByteArray *ba; - - /* IP address */ - g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY); - ba = g_byte_array_new (); - g_byte_array_append (ba, (guint8 *) &address->address, 16); - g_value_take_boxed (&element, ba); - g_value_array_append (array, &element); - g_value_unset (&element); - - /* Prefix */ - g_value_init (&element, G_TYPE_UINT); - g_value_set_uint (&element, address->plen); - g_value_array_append (array, &element); - g_value_unset (&element); - - /* Gateway */ - g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY); - ba = g_byte_array_new (); - g_byte_array_append (ba, (guint8 *) (i == 0 && gateway ? gateway : &in6addr_any), sizeof (*gateway)); - g_value_take_boxed (&element, ba); - g_value_array_append (array, &element); - g_value_unset (&element); - - g_ptr_array_add (addresses, array); + g_variant_builder_add (&array_builder, "(@ayu@ay)", + g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, + &address->address, 16, 1), + address->plen, + g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, + (i == 0 && gateway ? gateway : &in6addr_any), + 16, 1)); } - g_value_take_boxed (value, addresses); + g_value_take_variant (value, g_variant_builder_end (&array_builder)); } break; case PROP_ROUTE_DATA: { - GPtrArray *routes = g_ptr_array_new (); + GVariantBuilder array_builder, route_builder; guint nroutes = nm_ip6_config_get_num_routes (config); int i; + g_variant_builder_init (&array_builder, G_VARIANT_TYPE ("aa{sv}")); for (i = 0; i < nroutes; i++) { const NMPlatformIP6Route *route = nm_ip6_config_get_route (config, i); - GHashTable *route_hash; - GValue *val; - - route_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, gvalue_destroy); - - val = g_slice_new0 (GValue); - g_value_init (val, G_TYPE_STRING); - g_value_set_string (val, nm_utils_inet6_ntop (&route->network, NULL)); - g_hash_table_insert (route_hash, "dest", val); - - val = g_slice_new0 (GValue); - g_value_init (val, G_TYPE_UINT); - g_value_set_uint (val, route->plen); - g_hash_table_insert (route_hash, "prefix", val); + g_variant_builder_init (&route_builder, G_VARIANT_TYPE ("a{sv}")); + g_variant_builder_add (&route_builder, "{sv}", + "dest", + g_variant_new_string (nm_utils_inet6_ntop (&route->network, NULL))); + g_variant_builder_add (&route_builder, "{sv}", + "prefix", + g_variant_new_uint32 (route->plen)); if (!IN6_IS_ADDR_UNSPECIFIED (&route->gateway)) { - val = g_slice_new0 (GValue); - g_value_init (val, G_TYPE_STRING); - g_value_set_string (val, nm_utils_inet6_ntop (&route->gateway, NULL)); - g_hash_table_insert (route_hash, "next-hop", val); + g_variant_builder_add (&route_builder, "{sv}", + "next-hop", + g_variant_new_string (nm_utils_inet6_ntop (&route->gateway, NULL))); } - val = g_slice_new0 (GValue); - g_value_init (val, G_TYPE_UINT); - g_value_set_uint (val, route->metric); - g_hash_table_insert (route_hash, "metric", val); + g_variant_builder_add (&route_builder, "{sv}", + "metric", + g_variant_new_uint32 (route->metric)); - g_ptr_array_add (routes, route_hash); + g_variant_builder_add (&array_builder, "a{sv}", &route_builder); } - g_value_take_boxed (value, routes); + g_value_take_variant (value, g_variant_builder_end (&array_builder)); } break; case PROP_ROUTES: { - GPtrArray *routes = g_ptr_array_new (); + GVariantBuilder array_builder; int nroutes = nm_ip6_config_get_num_routes (config); int i; + g_variant_builder_init (&array_builder, G_VARIANT_TYPE ("a(ayuayu)")); for (i = 0; i < nroutes; i++) { - GValueArray *array; const NMPlatformIP6Route *route = nm_ip6_config_get_route (config, i); - GByteArray *ba; - GValue element = G_VALUE_INIT; /* legacy versions of nm_ip6_route_set_prefix() in libnm-util assert that the * plen is positive. Skip the default routes not to break older clients. */ if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT (route)) continue; - array = g_value_array_new (4); - - g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY); - ba = g_byte_array_new (); - g_byte_array_append (ba, (guint8 *) &route->network, sizeof (route->network)); - g_value_take_boxed (&element, ba); - g_value_array_append (array, &element); - g_value_unset (&element); - - g_value_init (&element, G_TYPE_UINT); - g_value_set_uint (&element, route->plen); - g_value_array_append (array, &element); - g_value_unset (&element); - - g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY); - ba = g_byte_array_new (); - g_byte_array_append (ba, (guint8 *) &route->gateway, sizeof (route->gateway)); - g_value_take_boxed (&element, ba); - g_value_array_append (array, &element); - g_value_unset (&element); - - g_value_init (&element, G_TYPE_UINT); - g_value_set_uint (&element, route->metric); - g_value_array_append (array, &element); - g_value_unset (&element); - - g_ptr_array_add (routes, array); + g_variant_builder_add (&array_builder, "(@ayu@ayu)", + g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, + &route->network, 16, 1), + g_variant_new_uint32 (route->plen), + g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, + &route->gateway, 16, 1), + g_variant_new_uint32 (route->metric)); } - g_value_take_boxed (value, routes); + g_value_take_variant (value, g_variant_builder_end (&array_builder)); } break; case PROP_GATEWAY: @@ -2100,13 +2036,13 @@ get_property (GObject *object, guint prop_id, nameservers_to_gvalue (priv->nameservers, value); break; case PROP_DOMAINS: - g_value_set_boxed (value, priv->domains); + nm_utils_g_value_set_strv (value, priv->domains); break; case PROP_SEARCHES: - g_value_set_boxed (value, priv->searches); + nm_utils_g_value_set_strv (value, priv->searches); break; case PROP_DNS_OPTIONS: - g_value_set_boxed (value, priv->dns_options); + nm_utils_g_value_set_strv (value, priv->dns_options); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -2149,59 +2085,65 @@ nm_ip6_config_class_init (NMIP6ConfigClass *config_class) /* properties */ obj_properties[PROP_IFINDEX] = - g_param_spec_int (NM_IP6_CONFIG_IFINDEX, "", "", - -1, G_MAXINT, -1, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS); + g_param_spec_int (NM_IP6_CONFIG_IFINDEX, "", "", + -1, G_MAXINT, -1, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS); obj_properties[PROP_ADDRESS_DATA] = - g_param_spec_boxed (NM_IP6_CONFIG_ADDRESS_DATA, "", "", - DBUS_TYPE_NM_IP_ADDRESSES, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); + g_param_spec_variant (NM_IP6_CONFIG_ADDRESS_DATA, "", "", + G_VARIANT_TYPE ("aa{sv}"), + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); obj_properties[PROP_ADDRESSES] = - g_param_spec_boxed (NM_IP6_CONFIG_ADDRESSES, "", "", - DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); + g_param_spec_variant (NM_IP6_CONFIG_ADDRESSES, "", "", + G_VARIANT_TYPE ("a(ayuay)"), + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); obj_properties[PROP_ROUTE_DATA] = - g_param_spec_boxed (NM_IP6_CONFIG_ROUTE_DATA, "", "", - DBUS_TYPE_NM_IP_ROUTES, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); + g_param_spec_variant (NM_IP6_CONFIG_ROUTE_DATA, "", "", + G_VARIANT_TYPE ("aa{sv}"), + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); obj_properties[PROP_ROUTES] = - g_param_spec_boxed (NM_IP6_CONFIG_ROUTES, "", "", - DBUS_TYPE_G_ARRAY_OF_IP6_ROUTE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); + g_param_spec_variant (NM_IP6_CONFIG_ROUTES, "", "", + G_VARIANT_TYPE ("a(ayuayu)"), + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); obj_properties[PROP_GATEWAY] = g_param_spec_string (NM_IP6_CONFIG_GATEWAY, "", "", NULL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); obj_properties[PROP_NAMESERVERS] = - g_param_spec_boxed (NM_IP6_CONFIG_NAMESERVERS, "", "", - DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UCHAR, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); + g_param_spec_variant (NM_IP6_CONFIG_NAMESERVERS, "", "", + G_VARIANT_TYPE ("aay"), + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); obj_properties[PROP_DOMAINS] = - g_param_spec_boxed (NM_IP6_CONFIG_DOMAINS, "", "", - DBUS_TYPE_G_ARRAY_OF_STRING, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); + g_param_spec_boxed (NM_IP6_CONFIG_DOMAINS, "", "", + G_TYPE_STRV, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); obj_properties[PROP_SEARCHES] = - g_param_spec_boxed (NM_IP6_CONFIG_SEARCHES, "", "", - DBUS_TYPE_G_ARRAY_OF_STRING, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); + g_param_spec_boxed (NM_IP6_CONFIG_SEARCHES, "", "", + G_TYPE_STRV, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); obj_properties[PROP_DNS_OPTIONS] = - g_param_spec_boxed (NM_IP6_CONFIG_DNS_OPTIONS, "", "", - DBUS_TYPE_G_ARRAY_OF_STRING, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS); + g_param_spec_boxed (NM_IP6_CONFIG_DNS_OPTIONS, "", "", + G_TYPE_STRV, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); g_object_class_install_properties (object_class, LAST_PROP, obj_properties); nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (config_class), - &dbus_glib_nm_ip6_config_object_info); + NMDBUS_TYPE_IP6_CONFIG_SKELETON, + NULL); } From 34ba4e14b8674dc74327975159e101710ebd5403 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Wed, 15 Apr 2015 14:53:30 -0400 Subject: [PATCH 12/14] core: port NMManager to gdbus --- introspection/nm-manager.xml | 20 - src/nm-manager.c | 695 +++++++++++++++++------------------ 2 files changed, 330 insertions(+), 385 deletions(-) diff --git a/introspection/nm-manager.xml b/introspection/nm-manager.xml index d0682e5cac..9f9a84d7ed 100644 --- a/introspection/nm-manager.xml +++ b/introspection/nm-manager.xml @@ -8,7 +8,6 @@ Get the list of network devices. - List of object paths of network devices known to the system. @@ -22,7 +21,6 @@ interface name. Note that some devices (usually modems) only have an IP interface name when they are connected. - Interface name of the device to find. @@ -36,8 +34,6 @@ - - Activate a connection using the supplied device. @@ -76,8 +72,6 @@ - - Adds a new connection using the given details (if any) as a template (automatically filling in missing settings with the capabilities of the @@ -121,8 +115,6 @@ Deactivate an active connection. - - The currently active connection to deactivate. @@ -131,8 +123,6 @@ - - Control the NetworkManager daemon's sleep state. When asleep, all interfaces that it manages are deactivated. When awake, devices are @@ -147,8 +137,6 @@ - - Control whether overall networking is enabled or disabled. When disabled, all interfaces that NM manages are deactivated. When enabled, @@ -165,8 +153,6 @@ - - Returns the permissions a caller has for various authenticated operations that NetworkManager provides, like Enable/Disable networking, changing @@ -193,8 +179,6 @@ - - Set logging verbosity and which operations are logged. @@ -223,7 +207,6 @@ - Get current logging verbosity level and operations domains. @@ -240,8 +223,6 @@ - - Re-check the network connectivity state. @@ -257,7 +238,6 @@ The overall networking state as determined by the NetworkManager daemon, based on the state of network devices under it's management. - diff --git a/src/nm-manager.c b/src/nm-manager.c index 7301f64c77..f56f62150e 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -26,8 +26,6 @@ #include #include #include -#include -#include #include "nm-default.h" #include "nm-manager.h" @@ -35,7 +33,6 @@ #include "nm-vpn-manager.h" #include "nm-device.h" #include "nm-device-generic.h" -#include "nm-dbus-glib-types.h" #include "nm-platform.h" #include "nm-rfkill-manager.h" #include "nm-dhcp-manager.h" @@ -55,60 +52,9 @@ #include "nm-core-internal.h" #include "nm-config.h" #include "nm-audit-manager.h" +#include "nm-dbus-compat.h" -static gboolean impl_manager_get_devices (NMManager *manager, - GPtrArray **devices, - GError **err); - -static gboolean impl_manager_get_device_by_ip_iface (NMManager *self, - const char *iface, - char **out_object_path, - GError **error); - -static void impl_manager_activate_connection (NMManager *manager, - const char *connection_path, - const char *device_path, - const char *specific_object_path, - DBusGMethodInvocation *context); - -static void impl_manager_add_and_activate_connection (NMManager *manager, - GHashTable *settings, - const char *device_path, - const char *specific_object_path, - DBusGMethodInvocation *context); - -static void impl_manager_deactivate_connection (NMManager *manager, - const char *connection_path, - DBusGMethodInvocation *context); - -static void impl_manager_sleep (NMManager *manager, - gboolean do_sleep, - DBusGMethodInvocation *context); - -static void impl_manager_enable (NMManager *manager, - gboolean enable, - DBusGMethodInvocation *context); - -static void impl_manager_get_permissions (NMManager *manager, - DBusGMethodInvocation *context); - -static gboolean impl_manager_get_state (NMManager *manager, - guint32 *state, - GError **error); - -static void impl_manager_set_logging (NMManager *manager, - const char *level, - const char *domains, - DBusGMethodInvocation *context); - -static void impl_manager_get_logging (NMManager *manager, - char **level, - char **domains); - -static void impl_manager_check_connectivity (NMManager *manager, - DBusGMethodInvocation *context); - -#include "nm-manager-glue.h" +#include "nmdbus-manager.h" static void add_device (NMManager *self, NMDevice *device, gboolean try_assume); @@ -165,6 +111,7 @@ typedef struct { NMPolicy *policy; NMBusManager *dbus_mgr; + guint prop_filter; NMRfkillManager *rfkill_mgr; NMSettings *settings; @@ -1344,7 +1291,7 @@ nm_manager_rfkill_update (NMManager *self, RfKillType rtype) static void device_auth_done_cb (NMAuthChain *chain, GError *auth_error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, gpointer user_data) { NMManager *self = NM_MANAGER (user_data); @@ -1399,7 +1346,7 @@ device_auth_done_cb (NMAuthChain *chain, static void device_auth_request_cb (NMDevice *device, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, NMConnection *connection, const char *permission, gboolean allow_interaction, @@ -2063,43 +2010,46 @@ nm_manager_get_best_device_for_connection (NMManager *self, return NULL; } -static gboolean -impl_manager_get_devices (NMManager *manager, GPtrArray **devices, GError **err) +static void +impl_manager_get_devices (NMManager *self, + GDBusMethodInvocation *context) { - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); + GPtrArray *paths; GSList *iter; - *devices = g_ptr_array_sized_new (g_slist_length (priv->devices)); + paths = g_ptr_array_sized_new (g_slist_length (priv->devices) + 1); for (iter = priv->devices; iter; iter = iter->next) - g_ptr_array_add (*devices, g_strdup (nm_exported_object_get_path (NM_EXPORTED_OBJECT (iter->data)))); - return TRUE; + g_ptr_array_add (paths, g_strdup (nm_exported_object_get_path (NM_EXPORTED_OBJECT (iter->data)))); + g_ptr_array_add (paths, NULL); + + g_dbus_method_invocation_return_value (context, + g_variant_new ("(^ao)", (char **) paths->pdata)); + g_ptr_array_unref (paths); } -static gboolean +static void impl_manager_get_device_by_ip_iface (NMManager *self, - const char *iface, - char **out_object_path, - GError **error) + GDBusMethodInvocation *context, + const char *iface) { NMDevice *device; const char *path = NULL; device = find_device_by_ip_iface (self, iface); - if (device) { + if (device) path = nm_exported_object_get_path (NM_EXPORTED_OBJECT (device)); - if (path) - *out_object_path = g_strdup (path); - } if (path == NULL) { - g_set_error_literal (error, - NM_MANAGER_ERROR, - NM_MANAGER_ERROR_UNKNOWN_DEVICE, - "No device found for the requested iface."); + g_dbus_method_invocation_return_error (context, + NM_MANAGER_ERROR, + NM_MANAGER_ERROR_UNKNOWN_DEVICE, + "No device found for the requested iface."); + } else { + g_dbus_method_invocation_return_value (context, + g_variant_new ("(o)", path)); } - - return path ? TRUE : FALSE; } static gboolean @@ -2972,7 +2922,7 @@ nm_manager_activate_connection (NMManager *self, static NMAuthSubject * validate_activation_request (NMManager *self, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, NMConnection *connection, const char *device_path, NMDevice **out_device, @@ -3088,7 +3038,7 @@ _activation_auth_done (NMActiveConnection *active, gpointer user_data2) { NMManager *self = user_data1; - DBusGMethodInvocation *context = user_data2; + GDBusMethodInvocation *context = user_data2; GError *error = NULL; NMAuthSubject *subject; NMConnection *connection; @@ -3098,7 +3048,9 @@ _activation_auth_done (NMActiveConnection *active, if (success) { if (_internal_activate_generic (self, active, &error)) { - dbus_g_method_return (context, nm_exported_object_get_path (NM_EXPORTED_OBJECT (active))); + g_dbus_method_invocation_return_value ( + context, + g_variant_new ("(o)", nm_exported_object_get_path (NM_EXPORTED_OBJECT (active)))); nm_audit_log_connection_op (NM_AUDIT_OP_CONN_ACTIVATE, connection, TRUE, subject, NULL); g_object_unref (active); @@ -3111,21 +3063,20 @@ _activation_auth_done (NMActiveConnection *active, } g_assert (error); - dbus_g_method_return_error (context, error); nm_audit_log_connection_op (NM_AUDIT_OP_CONN_ACTIVATE, connection, FALSE, subject, error->message); _internal_activation_failed (self, active, error->message); g_object_unref (active); - g_error_free (error); + g_dbus_method_invocation_take_error (context, error); } static void impl_manager_activate_connection (NMManager *self, + GDBusMethodInvocation *context, const char *connection_path, const char *device_path, - const char *specific_object_path, - DBusGMethodInvocation *context) + const char *specific_object_path) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); NMActiveConnection *active = NULL; @@ -3230,8 +3181,7 @@ error: g_clear_object (&subject); g_assert (error); - dbus_g_method_return_error (context, error); - g_error_free (error); + g_dbus_method_invocation_take_error (context, error); } /***********************************************************************/ @@ -3245,7 +3195,7 @@ static void activation_add_done (NMSettings *self, NMSettingsConnection *new_connection, GError *error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, NMAuthSubject *subject, gpointer user_data) { @@ -3259,9 +3209,11 @@ activation_add_done (NMSettings *self, nm_settings_connection_commit_changes (new_connection, NM_SETTINGS_CONNECTION_COMMIT_REASON_USER_ACTION | NM_SETTINGS_CONNECTION_COMMIT_REASON_ID_CHANGED, NULL, NULL); - dbus_g_method_return (context, - nm_connection_get_path (NM_CONNECTION (new_connection)), - nm_exported_object_get_path (NM_EXPORTED_OBJECT (info->active))); + g_dbus_method_invocation_return_value ( + context, + g_variant_new ("(oo)", + nm_connection_get_path (NM_CONNECTION (new_connection)), + nm_exported_object_get_path (NM_EXPORTED_OBJECT (info->active)))); nm_audit_log_connection_op (NM_AUDIT_OP_CONN_ADD_ACTIVATE, nm_active_connection_get_connection (info->active), TRUE, @@ -3275,7 +3227,7 @@ activation_add_done (NMSettings *self, g_assert (error); _internal_activation_failed (info->manager, info->active, error->message); nm_settings_connection_delete (new_connection, NULL, NULL); - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); nm_audit_log_connection_op (NM_AUDIT_OP_CONN_ADD_ACTIVATE, nm_active_connection_get_connection (info->active), FALSE, @@ -3297,7 +3249,7 @@ _add_and_activate_auth_done (NMActiveConnection *active, { NMManager *self = user_data1; NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); - DBusGMethodInvocation *context = user_data2; + GDBusMethodInvocation *context = user_data2; AddAndActivateInfo *info; GError *error = NULL; @@ -3318,13 +3270,12 @@ _add_and_activate_auth_done (NMActiveConnection *active, error = g_error_new_literal (NM_MANAGER_ERROR, NM_MANAGER_ERROR_PERMISSION_DENIED, error_desc); - dbus_g_method_return_error (context, error); nm_audit_log_connection_op (NM_AUDIT_OP_CONN_ADD_ACTIVATE, nm_active_connection_get_connection (active), FALSE, nm_active_connection_get_subject (active), error->message); - g_error_free (error); + g_dbus_method_invocation_take_error (context, error); } g_object_unref (active); @@ -3332,10 +3283,10 @@ _add_and_activate_auth_done (NMActiveConnection *active, static void impl_manager_add_and_activate_connection (NMManager *self, - GHashTable *settings, + GDBusMethodInvocation *context, + GVariant *settings, const char *device_path, - const char *specific_object_path, - DBusGMethodInvocation *context) + const char *specific_object_path) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); NMConnection *connection = NULL; @@ -3360,12 +3311,8 @@ impl_manager_add_and_activate_connection (NMManager *self, * validate_activation_request()). */ connection = nm_simple_connection_new (); - if (settings && g_hash_table_size (settings)) { - GVariant *settings_dict = nm_utils_connection_hash_to_dict (settings); - - nm_connection_replace_settings (connection, settings_dict, NULL); - g_variant_unref (settings_dict); - } + if (settings && g_variant_n_children (settings)) + nm_connection_replace_settings (connection, settings, NULL); subject = validate_activation_request (self, context, @@ -3437,8 +3384,7 @@ error: g_clear_object (&active); g_assert (error); - dbus_g_method_return_error (context, error); - g_error_free (error); + g_dbus_method_invocation_take_error (context, error); } /***********************************************************************/ @@ -3487,7 +3433,7 @@ nm_manager_deactivate_connection (NMManager *manager, static void deactivate_net_auth_done_cb (NMAuthChain *chain, GError *auth_error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, gpointer user_data) { NMManager *self = NM_MANAGER (user_data); @@ -3524,11 +3470,6 @@ deactivate_net_auth_done_cb (NMAuthChain *chain, g_assert (error); } - if (error) - dbus_g_method_return_error (context, error); - else - dbus_g_method_return (context); - if (active) { nm_audit_log_connection_op (NM_AUDIT_OP_CONN_DEACTIVATE, nm_active_connection_get_connection (active), @@ -3537,14 +3478,18 @@ deactivate_net_auth_done_cb (NMAuthChain *chain, error ? error->message : NULL); } - g_clear_error (&error); + if (error) + g_dbus_method_invocation_take_error (context, error); + else + g_dbus_method_invocation_return_value (context, NULL); + nm_auth_chain_unref (chain); } static void impl_manager_deactivate_connection (NMManager *self, - const char *active_path, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context, + const char *active_path) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); NMConnection *connection = NULL; @@ -3606,14 +3551,13 @@ impl_manager_deactivate_connection (NMManager *self, done: if (error) { - dbus_g_method_return_error (context, error); if (connection) { nm_audit_log_connection_op (NM_AUDIT_OP_CONN_DEACTIVATE, connection, FALSE, subject, error->message); } + g_dbus_method_invocation_take_error (context, error); } g_clear_object (&subject); - g_clear_error (&error); } static gboolean @@ -3730,7 +3674,7 @@ _internal_sleep (NMManager *self, gboolean do_sleep) static void sleep_auth_done_cb (NMAuthChain *chain, GError *error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, gpointer user_data) { NMManager *self = NM_MANAGER (user_data); @@ -3748,19 +3692,17 @@ sleep_auth_done_cb (NMAuthChain *chain, NM_MANAGER_ERROR_PERMISSION_DENIED, "Sleep/wake request failed: %s", error->message); - dbus_g_method_return_error (context, ret_error); - g_error_free (ret_error); + g_dbus_method_invocation_take_error (context, ret_error); } else if (result != NM_AUTH_CALL_RESULT_YES) { ret_error = g_error_new_literal (NM_MANAGER_ERROR, NM_MANAGER_ERROR_PERMISSION_DENIED, "Not authorized to sleep/wake"); - dbus_g_method_return_error (context, ret_error); - g_error_free (ret_error); + g_dbus_method_invocation_take_error (context, ret_error); } else { /* Auth success */ do_sleep = GPOINTER_TO_UINT (nm_auth_chain_get_data (chain, "sleep")); _internal_sleep (self, do_sleep); - dbus_g_method_return (context); + g_dbus_method_invocation_return_value (context, NULL); } nm_auth_chain_unref (chain); @@ -3769,8 +3711,8 @@ sleep_auth_done_cb (NMAuthChain *chain, static void impl_manager_sleep (NMManager *self, - gboolean do_sleep, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context, + gboolean do_sleep) { NMManagerPrivate *priv; GError *error = NULL; @@ -3789,10 +3731,9 @@ impl_manager_sleep (NMManager *self, error = g_error_new (NM_MANAGER_ERROR, NM_MANAGER_ERROR_ALREADY_ASLEEP_OR_AWAKE, "Already %s", do_sleep ? "asleep" : "awake"); - dbus_g_method_return_error (context, error); nm_audit_log_control_op (NM_AUDIT_OP_SLEEP_CONTROL, do_sleep ? "on" : "off", FALSE, subject, error->message); - g_error_free (error); + g_dbus_method_invocation_take_error (context, error); return; } @@ -3806,7 +3747,7 @@ impl_manager_sleep (NMManager *self, */ _internal_sleep (self, do_sleep); nm_audit_log_control_op (NM_AUDIT_OP_SLEEP_CONTROL, do_sleep ? "on" : "off", TRUE, subject, NULL); - dbus_g_method_return (context); + g_dbus_method_invocation_return_value (context, NULL); return; #if 0 @@ -3819,8 +3760,7 @@ impl_manager_sleep (NMManager *self, error = g_error_new_literal (NM_MANAGER_ERROR, NM_MANAGER_ERROR_PERMISSION_DENIED, error_desc); - dbus_g_method_return_error (context, error); - g_error_free (error); + g_dbus_method_invocation_take_error (context, error); } #endif } @@ -3874,7 +3814,7 @@ _internal_enable (NMManager *self, gboolean enable) static void enable_net_done_cb (NMAuthChain *chain, GError *error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, gpointer user_data) { NMManager *self = NM_MANAGER (user_data); @@ -3904,16 +3844,15 @@ enable_net_done_cb (NMAuthChain *chain, } else { /* Auth success */ _internal_enable (self, enable); - dbus_g_method_return (context); + g_dbus_method_invocation_return_value (context, NULL); nm_audit_log_control_op (NM_AUDIT_OP_NET_CONTROL, enable ? "on" : "off", TRUE, subject, NULL); } if (ret_error) { - dbus_g_method_return_error (context, ret_error); nm_audit_log_control_op (NM_AUDIT_OP_NET_CONTROL, enable ? "on" : "off", FALSE, subject, ret_error->message); - g_error_free (ret_error); + g_dbus_method_invocation_take_error (context, ret_error); } nm_auth_chain_unref (chain); @@ -3921,8 +3860,8 @@ enable_net_done_cb (NMAuthChain *chain, static void impl_manager_enable (NMManager *self, - gboolean enable, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context, + gboolean enable) { NMManagerPrivate *priv; NMAuthChain *chain; @@ -3953,24 +3892,23 @@ impl_manager_enable (NMManager *self, done: if (error) - dbus_g_method_return_error (context, error); - g_clear_error (&error); + g_dbus_method_invocation_take_error (context, error); } /* Permissions */ static void -get_perm_add_result (NMAuthChain *chain, GHashTable *results, const char *permission) +get_perm_add_result (NMAuthChain *chain, GVariantBuilder *results, const char *permission) { NMAuthCallResult result; result = nm_auth_chain_get_result (chain, permission); if (result == NM_AUTH_CALL_RESULT_YES) - g_hash_table_insert (results, (char *) permission, "yes"); + g_variant_builder_add (results, "{ss}", permission, "yes"); else if (result == NM_AUTH_CALL_RESULT_NO) - g_hash_table_insert (results, (char *) permission, "no"); + g_variant_builder_add (results, "{ss}", permission, "no"); else if (result == NM_AUTH_CALL_RESULT_AUTH) - g_hash_table_insert (results, (char *) permission, "auth"); + g_variant_builder_add (results, "{ss}", permission, "auth"); else { nm_log_dbg (LOGD_CORE, "unknown auth chain result %d", result); } @@ -3979,13 +3917,13 @@ get_perm_add_result (NMAuthChain *chain, GHashTable *results, const char *permis static void get_permissions_done_cb (NMAuthChain *chain, GError *error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, gpointer user_data) { NMManager *self = NM_MANAGER (user_data); NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); GError *ret_error; - GHashTable *results; + GVariantBuilder results; g_assert (context); @@ -3996,25 +3934,24 @@ get_permissions_done_cb (NMAuthChain *chain, NM_MANAGER_ERROR_PERMISSION_DENIED, "Permissions request failed: %s", error->message); - dbus_g_method_return_error (context, ret_error); - g_error_free (ret_error); + g_dbus_method_invocation_take_error (context, ret_error); } else { - results = g_hash_table_new (g_str_hash, g_str_equal); + g_variant_builder_init (&results, G_VARIANT_TYPE ("a{ss}")); - get_perm_add_result (chain, results, NM_AUTH_PERMISSION_ENABLE_DISABLE_NETWORK); - get_perm_add_result (chain, results, NM_AUTH_PERMISSION_SLEEP_WAKE); - get_perm_add_result (chain, results, NM_AUTH_PERMISSION_ENABLE_DISABLE_WIFI); - get_perm_add_result (chain, results, NM_AUTH_PERMISSION_ENABLE_DISABLE_WWAN); - get_perm_add_result (chain, results, NM_AUTH_PERMISSION_ENABLE_DISABLE_WIMAX); - get_perm_add_result (chain, results, NM_AUTH_PERMISSION_NETWORK_CONTROL); - get_perm_add_result (chain, results, NM_AUTH_PERMISSION_WIFI_SHARE_PROTECTED); - get_perm_add_result (chain, results, NM_AUTH_PERMISSION_WIFI_SHARE_OPEN); - get_perm_add_result (chain, results, NM_AUTH_PERMISSION_SETTINGS_MODIFY_SYSTEM); - get_perm_add_result (chain, results, NM_AUTH_PERMISSION_SETTINGS_MODIFY_OWN); - get_perm_add_result (chain, results, NM_AUTH_PERMISSION_SETTINGS_MODIFY_HOSTNAME); + get_perm_add_result (chain, &results, NM_AUTH_PERMISSION_ENABLE_DISABLE_NETWORK); + get_perm_add_result (chain, &results, NM_AUTH_PERMISSION_SLEEP_WAKE); + get_perm_add_result (chain, &results, NM_AUTH_PERMISSION_ENABLE_DISABLE_WIFI); + get_perm_add_result (chain, &results, NM_AUTH_PERMISSION_ENABLE_DISABLE_WWAN); + get_perm_add_result (chain, &results, NM_AUTH_PERMISSION_ENABLE_DISABLE_WIMAX); + get_perm_add_result (chain, &results, NM_AUTH_PERMISSION_NETWORK_CONTROL); + get_perm_add_result (chain, &results, NM_AUTH_PERMISSION_WIFI_SHARE_PROTECTED); + get_perm_add_result (chain, &results, NM_AUTH_PERMISSION_WIFI_SHARE_OPEN); + get_perm_add_result (chain, &results, NM_AUTH_PERMISSION_SETTINGS_MODIFY_SYSTEM); + get_perm_add_result (chain, &results, NM_AUTH_PERMISSION_SETTINGS_MODIFY_OWN); + get_perm_add_result (chain, &results, NM_AUTH_PERMISSION_SETTINGS_MODIFY_HOSTNAME); - dbus_g_method_return (context, results); - g_hash_table_destroy (results); + g_dbus_method_invocation_return_value (context, + g_variant_new ("(a{ss})", &results)); } nm_auth_chain_unref (chain); @@ -4022,7 +3959,7 @@ get_permissions_done_cb (NMAuthChain *chain, static void impl_manager_get_permissions (NMManager *self, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); NMAuthChain *chain; @@ -4033,8 +3970,7 @@ impl_manager_get_permissions (NMManager *self, error = g_error_new_literal (NM_MANAGER_ERROR, NM_MANAGER_ERROR_PERMISSION_DENIED, "Unable to authenticate request."); - dbus_g_method_return_error (context, error); - g_clear_error (&error); + g_dbus_method_invocation_take_error (context, error); return; } @@ -4052,21 +3988,22 @@ impl_manager_get_permissions (NMManager *self, nm_auth_chain_add_call (chain, NM_AUTH_PERMISSION_SETTINGS_MODIFY_HOSTNAME, FALSE); } -static gboolean -impl_manager_get_state (NMManager *manager, guint32 *state, GError **error) +static void +impl_manager_get_state (NMManager *self, + GDBusMethodInvocation *context) { - nm_manager_update_state (manager); - *state = NM_MANAGER_GET_PRIVATE (manager)->state; - return TRUE; + nm_manager_update_state (self); + g_dbus_method_invocation_return_value (context, + g_variant_new ("(u)", NM_MANAGER_GET_PRIVATE (self)->state)); } static void -impl_manager_set_logging (NMManager *manager, +impl_manager_set_logging (NMManager *self, + GDBusMethodInvocation *context, const char *level, - const char *domains, - DBusGMethodInvocation *context) + const char *domains) { - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); GError *error = NULL; gulong caller_uid = G_MAXULONG; @@ -4090,20 +4027,20 @@ impl_manager_set_logging (NMManager *manager, } done: - if (error) { - dbus_g_method_return_error (context, error); - g_error_free (error); - } else - dbus_g_method_return (context); + if (error) + g_dbus_method_invocation_take_error (context, error); + else + g_dbus_method_invocation_return_value (context, NULL); } static void impl_manager_get_logging (NMManager *manager, - char **level, - char **domains) + GDBusMethodInvocation *context) { - *level = g_strdup (nm_logging_level_to_string ()); - *domains = g_strdup (nm_logging_domains_to_string ()); + g_dbus_method_invocation_return_value (context, + g_variant_new ("(ss)", + nm_logging_level_to_string (), + nm_logging_domains_to_string ())); } static void @@ -4111,23 +4048,24 @@ connectivity_check_done (GObject *object, GAsyncResult *result, gpointer user_data) { - DBusGMethodInvocation *context = user_data; + GDBusMethodInvocation *context = user_data; NMConnectivityState state; GError *error = NULL; state = nm_connectivity_check_finish (NM_CONNECTIVITY (object), result, &error); - if (error) { - dbus_g_method_return_error (context, error); - g_error_free (error); - } else - dbus_g_method_return (context, state); + if (error) + g_dbus_method_invocation_take_error (context, error); + else { + g_dbus_method_invocation_return_value (context, + g_variant_new ("(u)", state)); + } } static void check_connectivity_auth_done_cb (NMAuthChain *chain, GError *auth_error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, gpointer user_data) { NMManager *self = NM_MANAGER (user_data); @@ -4156,29 +4094,26 @@ check_connectivity_auth_done_cb (NMAuthChain *chain, context); } - if (error) { - dbus_g_method_return_error (context, error); - g_error_free (error); - } + if (error) + g_dbus_method_invocation_take_error (context, error); nm_auth_chain_unref (chain); } static void -impl_manager_check_connectivity (NMManager *manager, - DBusGMethodInvocation *context) +impl_manager_check_connectivity (NMManager *self, + GDBusMethodInvocation *context) { - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager); + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); NMAuthChain *chain; GError *error = NULL; /* Validate the request */ - chain = nm_auth_chain_new_context (context, check_connectivity_auth_done_cb, manager); + chain = nm_auth_chain_new_context (context, check_connectivity_auth_done_cb, self); if (!chain) { error = g_error_new_literal (NM_MANAGER_ERROR, NM_MANAGER_ERROR_PERMISSION_DENIED, "Unable to authenticate request."); - dbus_g_method_return_error (context, error); - g_clear_error (&error); + g_dbus_method_invocation_take_error (context, error); return; } @@ -4421,170 +4356,195 @@ policy_activating_device_changed (GObject *object, GParamSpec *pspec, gpointer u } #define NM_PERM_DENIED_ERROR "org.freedesktop.NetworkManager.PermissionDenied" -#define DEV_PERM_DENIED_ERROR "org.freedesktop.NetworkManager.Device.PermissionDenied" + +typedef struct { + NMManager *self; + GDBusConnection *connection; + GDBusMessage *message; + NMAuthSubject *subject; + const char *permission; + const char *audit_op; + GObject *object; + const char *property; + gboolean set_enable; +} PropertyFilterData; + +static void +free_property_filter_data (PropertyFilterData *pfd) +{ + g_object_unref (pfd->self); + g_object_unref (pfd->connection); + g_object_unref (pfd->message); + g_object_unref (pfd->subject); + g_object_unref (pfd->object); + g_free (pfd); +} static void prop_set_auth_done_cb (NMAuthChain *chain, GError *error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, /* NULL */ gpointer user_data) { - NMManager *self = NM_MANAGER (user_data); - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); - DBusConnection *connection; + PropertyFilterData *pfd = user_data; + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (pfd->self); NMAuthCallResult result; - DBusMessage *reply = NULL, *message; - const char *permission, *prop, *audit_op; - GObject *obj; - gboolean set_enabled = TRUE; - NMAuthSubject *subject; gs_free char *prop_value = NULL; + GDBusMessage *reply; + + prop_value = g_strdup_printf ("%s:%d", pfd->property, pfd->set_enable); priv->auth_chains = g_slist_remove (priv->auth_chains, chain); - - message = nm_auth_chain_get_data (chain, "message"); - permission = nm_auth_chain_get_data (chain, "permission"); - prop = nm_auth_chain_get_data (chain, "prop"); - set_enabled = GPOINTER_TO_UINT (nm_auth_chain_get_data (chain, "enabled")); - obj = nm_auth_chain_get_data (chain, "object"); - audit_op = nm_auth_chain_get_data (chain, "audit-op"); - - prop_value = g_strdup_printf ("%s:%d", prop, set_enabled); - - result = nm_auth_chain_get_result (chain, permission); - subject = nm_auth_chain_get_subject (chain); + result = nm_auth_chain_get_result (chain, pfd->permission); if (error || (result != NM_AUTH_CALL_RESULT_YES)) { - reply = dbus_message_new_error (message, - NM_IS_DEVICE (obj) ? DEV_PERM_DENIED_ERROR : NM_PERM_DENIED_ERROR, - "Not authorized to perform this operation"); - nm_audit_log_control_op (audit_op, prop_value, FALSE, subject, error ? error->message : NULL); + reply = g_dbus_message_new_method_error (pfd->message, + NM_PERM_DENIED_ERROR, + "Not authorized to perform this operation"); + nm_audit_log_control_op (pfd->audit_op, prop_value, FALSE, pfd->subject, error ? error->message : NULL); } else { - g_object_set (obj, prop, set_enabled, NULL); - reply = dbus_message_new_method_return (message); - nm_audit_log_control_op (audit_op, prop_value, TRUE, subject, NULL); + g_object_set (pfd->object, pfd->property, pfd->set_enable, NULL); + reply = g_dbus_message_new_method_reply (pfd->message); + g_dbus_message_set_body (reply, g_variant_new_tuple (NULL, 0)); + nm_audit_log_control_op (pfd->audit_op, prop_value, TRUE, pfd->subject, NULL); } - g_assert (reply); - connection = nm_auth_chain_get_data (chain, "connection"); - g_assert (connection); - dbus_connection_send (connection, reply, NULL); - dbus_message_unref (reply); - + g_dbus_connection_send_message (pfd->connection, reply, + G_DBUS_SEND_MESSAGE_FLAGS_NONE, + NULL, NULL); + g_object_unref (reply); nm_auth_chain_unref (chain); + + free_property_filter_data (pfd); } -static DBusHandlerResult -prop_filter (DBusConnection *connection, - DBusMessage *message, - void *user_data) +static gboolean +do_set_property_check (gpointer user_data) { - NMManager *self = NM_MANAGER (user_data); - NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); - DBusMessageIter iter; - DBusMessageIter sub; - const char *propiface = NULL; - const char *propname = NULL; - const char *glib_propname = NULL, *permission = NULL; - DBusMessage *reply = NULL; - gboolean set_enabled = FALSE; - NMAuthSubject *subject = NULL; + PropertyFilterData *pfd = user_data; + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (pfd->self); + GDBusMessage *reply = NULL; NMAuthChain *chain; - GObject *obj; - const char *audit_op = NULL; - /* The sole purpose of this function is to validate property accesses - * on the NMManager object since dbus-glib doesn't yet give us this - * functionality. - */ - - if (!dbus_message_is_method_call (message, DBUS_INTERFACE_PROPERTIES, "Set")) - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - - dbus_message_iter_init (message, &iter); - - /* Get the D-Bus interface of the property to set */ - if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING) - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - dbus_message_iter_get_basic (&iter, &propiface); - if (!propiface || (strcmp (propiface, NM_DBUS_INTERFACE) && strcmp (propiface, NM_DBUS_INTERFACE_DEVICE))) - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - dbus_message_iter_next (&iter); - - /* Get the property name that's going to be set */ - if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING) - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - dbus_message_iter_get_basic (&iter, &propname); - dbus_message_iter_next (&iter); - - if (!strcmp (propname, "WirelessEnabled")) { - glib_propname = NM_MANAGER_WIRELESS_ENABLED; - permission = NM_AUTH_PERMISSION_ENABLE_DISABLE_WIFI; - audit_op = NM_AUDIT_OP_RADIO_CONTROL; - } else if (!strcmp (propname, "WwanEnabled")) { - glib_propname = NM_MANAGER_WWAN_ENABLED; - permission = NM_AUTH_PERMISSION_ENABLE_DISABLE_WWAN; - audit_op = NM_AUDIT_OP_RADIO_CONTROL; - } else if (!strcmp (propname, "WimaxEnabled")) { - glib_propname = NM_MANAGER_WIMAX_ENABLED; - permission = NM_AUTH_PERMISSION_ENABLE_DISABLE_WIMAX; - audit_op = NM_AUDIT_OP_RADIO_CONTROL; - } else if (!strcmp (propname, "Autoconnect")) { - glib_propname = NM_DEVICE_AUTOCONNECT; - permission = NM_AUTH_PERMISSION_NETWORK_CONTROL; - audit_op = NM_AUDIT_OP_DEVICE_AUTOCONNECT; - } else - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - - /* Get the new value for the property */ - if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - dbus_message_iter_recurse (&iter, &sub); - if (dbus_message_iter_get_arg_type (&sub) != DBUS_TYPE_BOOLEAN) - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - dbus_message_iter_get_basic (&sub, &set_enabled); - - /* Make sure the object exists */ - obj = dbus_g_connection_lookup_g_object (dbus_connection_get_g_connection (connection), - dbus_message_get_path (message)); - if (!obj) { - reply = dbus_message_new_error (message, NM_PERM_DENIED_ERROR, - "Object does not exist"); - goto out; - } - - subject = nm_auth_subject_new_unix_process_from_message (connection, message); - if (!subject) { - reply = dbus_message_new_error (message, NM_PERM_DENIED_ERROR, - "Could not determine request UID."); + pfd->subject = nm_auth_subject_new_unix_process_from_message (pfd->connection, pfd->message); + if (!pfd->subject) { + reply = g_dbus_message_new_method_error (pfd->message, + NM_PERM_DENIED_ERROR, + "Could not determine request UID."); goto out; } /* Validate the user request */ - chain = nm_auth_chain_new_subject (subject, NULL, prop_set_auth_done_cb, self); + chain = nm_auth_chain_new_subject (pfd->subject, NULL, prop_set_auth_done_cb, pfd); if (!chain) { - reply = dbus_message_new_error (message, NM_PERM_DENIED_ERROR, - "Could not authenticate request."); + reply = g_dbus_message_new_method_error (pfd->message, + NM_PERM_DENIED_ERROR, + "Could not authenticate request."); goto out; } priv->auth_chains = g_slist_append (priv->auth_chains, chain); - nm_auth_chain_set_data (chain, "prop", g_strdup (glib_propname), g_free); - nm_auth_chain_set_data (chain, "permission", g_strdup (permission), g_free); - nm_auth_chain_set_data (chain, "enabled", GUINT_TO_POINTER (set_enabled), NULL); - nm_auth_chain_set_data (chain, "message", dbus_message_ref (message), (GDestroyNotify) dbus_message_unref); - nm_auth_chain_set_data (chain, "connection", dbus_connection_ref (connection), (GDestroyNotify) dbus_connection_unref); - nm_auth_chain_set_data (chain, "object", g_object_ref (obj), (GDestroyNotify) g_object_unref); - nm_auth_chain_set_data (chain, "audit-op", (char *) audit_op, NULL); - nm_auth_chain_add_call (chain, permission, TRUE); + nm_auth_chain_add_call (chain, pfd->permission, TRUE); out: if (reply) { - dbus_connection_send (connection, reply, NULL); - dbus_message_unref (reply); + g_dbus_connection_send_message (pfd->connection, reply, + G_DBUS_SEND_MESSAGE_FLAGS_NONE, + NULL, NULL); + g_object_unref (reply); + free_property_filter_data (pfd); } - g_clear_object (&subject); - return DBUS_HANDLER_RESULT_HANDLED; + return FALSE; +} + +static GDBusMessage * +prop_filter (GDBusConnection *connection, + GDBusMessage *message, + gboolean incoming, + gpointer user_data) +{ + NMManager *self = NM_MANAGER (user_data); + GVariant *args, *value = NULL; + const char *propiface = NULL; + const char *propname = NULL; + const char *glib_propname = NULL, *permission = NULL; + const char *audit_op = NULL; + gboolean set_enable; + gpointer obj; + PropertyFilterData *pfd; + + /* The sole purpose of this function is to validate property accesses on the + * NMManager object since gdbus doesn't give us this functionality. + */ + + /* Only filter org.freedesktop.DBus.Properties.Set calls */ + if ( !incoming + || g_dbus_message_get_message_type (message) != G_DBUS_MESSAGE_TYPE_METHOD_CALL + || strcmp (g_dbus_message_get_interface (message), DBUS_INTERFACE_PROPERTIES) != 0 + || strcmp (g_dbus_message_get_member (message), "Set") != 0) + return message; + + /* Only filter calls with correct arguments (all filtered properties are boolean) */ + args = g_dbus_message_get_body (message); + if (!g_variant_is_of_type (args, G_VARIANT_TYPE ("(ssv)"))) + return message; + g_variant_get (args, "(&s&sv)", &propiface, &propname, &value); + if (!g_variant_is_of_type (value, G_VARIANT_TYPE_BOOLEAN)) { + g_variant_unref (value); + return message; + } + set_enable = g_variant_get_boolean (value); + g_variant_unref (value); + + /* Only filter calls to filtered properties, on existing objects */ + if (!strcmp (propiface, NM_DBUS_INTERFACE)) { + if (!strcmp (propname, "WirelessEnabled")) { + glib_propname = NM_MANAGER_WIRELESS_ENABLED; + permission = NM_AUTH_PERMISSION_ENABLE_DISABLE_WIFI; + audit_op = NM_AUDIT_OP_RADIO_CONTROL; + } else if (!strcmp (propname, "WwanEnabled")) { + glib_propname = NM_MANAGER_WWAN_ENABLED; + permission = NM_AUTH_PERMISSION_ENABLE_DISABLE_WWAN; + audit_op = NM_AUDIT_OP_RADIO_CONTROL; + } else if (!strcmp (propname, "WimaxEnabled")) { + glib_propname = NM_MANAGER_WIMAX_ENABLED; + permission = NM_AUTH_PERMISSION_ENABLE_DISABLE_WIMAX; + audit_op = NM_AUDIT_OP_RADIO_CONTROL; + } else + return message; + + obj = self; + } else if (!strcmp (propiface, NM_DBUS_INTERFACE_DEVICE)) { + if (!strcmp (propname, "Autoconnect")) { + glib_propname = NM_DEVICE_AUTOCONNECT; + permission = NM_AUTH_PERMISSION_NETWORK_CONTROL; + audit_op = NM_AUDIT_OP_DEVICE_AUTOCONNECT; + } else + return message; + + obj = nm_bus_manager_get_registered_object (nm_bus_manager_get (), + g_dbus_message_get_path (message)); + if (!obj) + return message; + } else + return message; + + /* This filter function is called from a gdbus worker thread which we can't + * make other D-Bus calls from. In particular, we cannot call + * org.freedesktop.DBus.GetConnectionUnixUser to find the remote UID. + */ + pfd = g_new0 (PropertyFilterData, 1); + pfd->self = g_object_ref (self); + pfd->connection = g_object_ref (connection); + pfd->message = message; + pfd->permission = permission; + pfd->object = g_object_ref (obj); + pfd->property = glib_propname; + pfd->set_enable = set_enable; + pfd->audit_op = audit_op; + g_idle_add (do_set_property_check, pfd); + + return NULL; } static void @@ -4733,17 +4693,14 @@ periodic_update_active_connection_timestamps (gpointer user_data) static void dbus_connection_changed_cb (NMBusManager *dbus_mgr, - DBusConnection *dbus_connection, + GDBusConnection *connection, gpointer user_data) { NMManager *self = NM_MANAGER (user_data); - gboolean success; + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); - if (dbus_connection) { - /* Only fails on ENOMEM */ - success = dbus_connection_add_filter (dbus_connection, prop_filter, self, NULL); - g_assert (success); - } + if (connection) + priv->prop_filter = g_dbus_connection_add_filter (connection, prop_filter, self, NULL); } /**********************************************************************/ @@ -4774,7 +4731,7 @@ nm_manager_setup (const char *state_file, { NMManager *self; NMManagerPrivate *priv; - DBusConnection *dbus_connection; + GDBusConnection *bus; NMConfigData *config_data; /* Can only be called once */ @@ -4784,14 +4741,9 @@ nm_manager_setup (const char *state_file, priv = NM_MANAGER_GET_PRIVATE (self); - dbus_connection = nm_bus_manager_get_dbus_connection (priv->dbus_mgr); - if (dbus_connection) { - gboolean success; - - /* Only fails on ENOMEM */ - success = dbus_connection_add_filter (dbus_connection, prop_filter, self, NULL); - g_assert (success); - } + bus = nm_bus_manager_get_connection (priv->dbus_mgr); + if (bus) + priv->prop_filter = g_dbus_connection_add_filter (bus, prop_filter, self, NULL); priv->settings = nm_settings_new (); g_signal_connect (priv->settings, "notify::" NM_SETTINGS_STARTUP_COMPLETE, @@ -5059,7 +5011,7 @@ dispose (GObject *object) { NMManager *manager = NM_MANAGER (object); NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager); - DBusConnection *dbus_connection; + GDBusConnection *bus; g_slist_free_full (priv->auth_chains, (GDestroyNotify) nm_auth_chain_unref); priv->auth_chains = NULL; @@ -5104,9 +5056,11 @@ dispose (GObject *object) /* Unregister property filter */ if (priv->dbus_mgr) { - dbus_connection = nm_bus_manager_get_dbus_connection (priv->dbus_mgr); - if (dbus_connection) - dbus_connection_remove_filter (dbus_connection, prop_filter, manager); + bus = nm_bus_manager_get_connection (priv->dbus_mgr); + if (bus && priv->prop_filter) { + g_dbus_connection_remove_filter (bus, priv->prop_filter); + priv->prop_filter = 0; + } g_signal_handlers_disconnect_by_func (priv->dbus_mgr, dbus_connection_changed_cb, manager); priv->dbus_mgr = NULL; } @@ -5228,7 +5182,7 @@ nm_manager_class_init (NMManagerClass *manager_class) g_object_class_install_property (object_class, PROP_ACTIVE_CONNECTIONS, g_param_spec_boxed (NM_MANAGER_ACTIVE_CONNECTIONS, "", "", - DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH, + G_TYPE_STRV, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); @@ -5241,10 +5195,10 @@ nm_manager_class_init (NMManagerClass *manager_class) g_object_class_install_property (object_class, PROP_PRIMARY_CONNECTION, - g_param_spec_boxed (NM_MANAGER_PRIMARY_CONNECTION, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_MANAGER_PRIMARY_CONNECTION, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_PRIMARY_CONNECTION_TYPE, @@ -5256,10 +5210,10 @@ nm_manager_class_init (NMManagerClass *manager_class) g_object_class_install_property (object_class, PROP_ACTIVATING_CONNECTION, - g_param_spec_boxed (NM_MANAGER_ACTIVATING_CONNECTION, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_MANAGER_ACTIVATING_CONNECTION, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); /* Hostname is not exported over D-Bus */ g_object_class_install_property @@ -5280,7 +5234,7 @@ nm_manager_class_init (NMManagerClass *manager_class) g_object_class_install_property (object_class, PROP_DEVICES, g_param_spec_boxed (NM_MANAGER_DEVICES, "", "", - DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH, + G_TYPE_STRV, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); @@ -5305,7 +5259,7 @@ nm_manager_class_init (NMManagerClass *manager_class) G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (NMManagerClass, device_added), NULL, NULL, NULL, - G_TYPE_NONE, 1, G_TYPE_OBJECT); + G_TYPE_NONE, 1, NM_TYPE_DEVICE); signals[DEVICE_REMOVED] = g_signal_new ("device-removed", @@ -5313,7 +5267,7 @@ nm_manager_class_init (NMManagerClass *manager_class) G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (NMManagerClass, device_removed), NULL, NULL, NULL, - G_TYPE_NONE, 1, G_TYPE_OBJECT); + G_TYPE_NONE, 1, NM_TYPE_DEVICE); signals[STATE_CHANGED] = g_signal_new ("state-changed", @@ -5342,14 +5296,14 @@ nm_manager_class_init (NMManagerClass *manager_class) G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL, - G_TYPE_NONE, 1, G_TYPE_OBJECT); + G_TYPE_NONE, 1, NM_TYPE_ACTIVE_CONNECTION); signals[ACTIVE_CONNECTION_REMOVED] = g_signal_new (NM_MANAGER_ACTIVE_CONNECTION_REMOVED, G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL, - G_TYPE_NONE, 1, G_TYPE_OBJECT); + G_TYPE_NONE, 1, NM_TYPE_ACTIVE_CONNECTION); signals[CONFIGURE_QUIT] = g_signal_new (NM_MANAGER_CONFIGURE_QUIT, @@ -5359,8 +5313,19 @@ nm_manager_class_init (NMManagerClass *manager_class) G_TYPE_NONE, 0); nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (manager_class), - &dbus_glib_nm_manager_object_info); - - dbus_g_error_domain_register (NM_MANAGER_ERROR, NM_DBUS_INTERFACE, NM_TYPE_MANAGER_ERROR); + NMDBUS_TYPE_MANAGER_SKELETON, + "GetDevices", impl_manager_get_devices, + "GetDeviceByIpIface", impl_manager_get_device_by_ip_iface, + "ActivateConnection", impl_manager_activate_connection, + "AddAndActivateConnection", impl_manager_add_and_activate_connection, + "DeactivateConnection", impl_manager_deactivate_connection, + "Sleep", impl_manager_sleep, + "Enable", impl_manager_enable, + "GetPermissions", impl_manager_get_permissions, + "SetLogging", impl_manager_set_logging, + "GetLogging", impl_manager_get_logging, + "CheckConnectivity", impl_manager_check_connectivity, + "state", impl_manager_get_state, + NULL); } From 1cf35cb26b6cc04f8b2c51c3cde4bc08ef311062 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Thu, 16 Apr 2015 12:34:55 -0400 Subject: [PATCH 13/14] core: final gdbus porting Port remaining bits to gdbus and remove stray dbus-glib references Drop the dbus-glib version check from configure, since nothing depends on new dbus-glib any more. Move nm-dbus-glib-types.h and nm-gvaluearray-compat.h from include/ to libnm-util/ since they are now only used by libnm-util and libnm-glib. --- .gitignore | 3 +- callouts/Makefile.am | 1 - callouts/tests/Makefile.am | 6 +- configure.ac | 14 ----- include/Makefile.am | 2 - include/nm-glib.h | 3 - libnm-util/Makefile.am | 6 +- {include => libnm-util}/nm-dbus-glib-types.h | 0 .../nm-gvaluearray-compat.h | 0 libnm-util/nm-param-spec-specialized.c | 1 + libnm-util/nm-utils.c | 1 + libnm-util/nm-value-transforms.c | 1 + libnm-util/tests/test-general.c | 1 + src/Makefile.am | 60 +++---------------- src/NetworkManagerUtils.c | 49 ++------------- src/NetworkManagerUtils.h | 3 - src/dhcp-manager/tests/Makefile.am | 1 - src/main.c | 15 ----- src/nm-auth-subject.c | 12 ++-- src/nm-auth-subject.h | 6 +- src/nm-auth-utils.c | 6 +- src/nm-auth-utils.h | 8 +-- src/nm-dispatcher.c | 1 - src/rdisc/tests/Makefile.am | 1 - src/settings/plugins/ibft/Makefile.am | 1 - src/settings/plugins/ibft/plugin.c | 1 - src/settings/plugins/ibft/tests/Makefile.am | 1 - src/settings/plugins/ifnet/Makefile.am | 1 - src/settings/plugins/ifnet/tests/Makefile.am | 1 - src/settings/plugins/ifupdown/Makefile.am | 1 - src/settings/plugins/keyfile/Makefile.am | 1 - .../plugins/keyfile/nm-keyfile-connection.c | 1 - .../plugins/keyfile/tests/Makefile.am | 2 - src/supplicant-manager/nm-supplicant-config.c | 1 - .../nm-supplicant-manager.c | 1 - src/supplicant-manager/tests/Makefile.am | 3 +- .../tests/test-supplicant-config.c | 2 - src/tests/Makefile.am | 3 +- src/tests/config/Makefile.am | 1 - 39 files changed, 41 insertions(+), 181 deletions(-) rename {include => libnm-util}/nm-dbus-glib-types.h (100%) rename {include => libnm-util}/nm-gvaluearray-compat.h (100%) diff --git a/.gitignore b/.gitignore index 14a033232e..59dc2dee30 100644 --- a/.gitignore +++ b/.gitignore @@ -31,7 +31,6 @@ cscope.*out valgrind-*.log test-*.log test-*.trs -*-glue.h /ABOUT-NLS /COPYING @@ -156,6 +155,8 @@ test-*.trs /libnm-core/tests/test-setting-8021x /libnm-core/tests/test-setting-dcb +/libnm-glib/nm-secret-agent-glue.h +/libnm-glib/nm-vpn-plugin-glue.h /libnm-glib/libnm-glib-test /libnm-glib/tests/test-nm-client /libnm-glib/tests/test-remote-settings-client diff --git a/callouts/Makefile.am b/callouts/Makefile.am index 7bc7273032..1f89356fa3 100644 --- a/callouts/Makefile.am +++ b/callouts/Makefile.am @@ -5,7 +5,6 @@ AM_CPPFLAGS = \ -I${top_srcdir}/libnm-core \ -I${top_builddir}/libnm-core \ $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ -DNMCONFDIR=\"$(nmconfdir)\" \ diff --git a/callouts/tests/Makefile.am b/callouts/tests/Makefile.am index a0ed40159f..9e851805a0 100644 --- a/callouts/tests/Makefile.am +++ b/callouts/tests/Makefile.am @@ -9,8 +9,7 @@ AM_CPPFLAGS = \ -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ -DSRCDIR=\"$(abs_srcdir)\" \ - $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) + $(GLIB_CFLAGS) noinst_PROGRAMS = \ test-dispatcher-envp @@ -23,8 +22,7 @@ test_dispatcher_envp_SOURCES = \ test_dispatcher_envp_LDADD = \ $(top_builddir)/libnm/libnm.la \ $(top_builddir)/callouts/libtest-dispatcher-envp.la \ - $(GLIB_LIBS) \ - $(DBUS_LIBS) + $(GLIB_LIBS) ########################################### diff --git a/configure.ac b/configure.ac index 9fce12bb4d..aad7f4c6f3 100644 --- a/configure.ac +++ b/configure.ac @@ -273,20 +273,6 @@ dnl Checks for dbus-glib dnl PKG_CHECK_MODULES(DBUS, dbus-1 >= 1.1 dbus-glib-1 >= 0.94) -AC_CHECK_LIB([dbus-glib-1], [dbus_g_method_invocation_get_g_connection], ac_have_gmi_get_con="1", ac_have_gmi_get_con="0") -AC_DEFINE_UNQUOTED(HAVE_DBUS_GLIB_GMI_GET_CONNECTION, $ac_have_gmi_get_con, [Define if you have a dbus-glib with dbus_g_method_invocation_get_g_connection()]) - -dnl -dnl Only dbus-glib >= 0.100 can use private dbus connections -dnl -PKG_CHECK_MODULES(DBUS_GLIB_100, [dbus-glib-1 >= 0.100], [have_dbus_glib_100=yes],[have_dbus_glib_100=no]) -if (test "${have_dbus_glib_100}" = "yes"); then - AC_DEFINE(HAVE_DBUS_GLIB_100, 1, [Define if you have dbus-glib >= 0.100]) -else - AC_DEFINE(HAVE_DBUS_GLIB_100, 0, [Define if you have dbus-glib >= 0.100]) -fi -AM_CONDITIONAL(HAVE_DBUS_GLIB_100, test "${have_dbus_glib_100}" = "yes") - PKG_CHECK_MODULES(GLIB, [gio-unix-2.0 >= 2.37.6 gmodule-2.0], [AC_SUBST(LOG_DRIVER, '$(top_srcdir)/build-aux/tap-driver.sh'), AC_SUBST(AM_TESTS_FD_REDIRECT, '--tap')], diff --git a/include/Makefile.am b/include/Makefile.am index b9b80cb024..2ebd172838 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,10 +1,8 @@ EXTRA_DIST = \ gsystem-local-alloc.h \ nm-dbus-compat.h \ - nm-dbus-glib-types.h \ nm-default.h \ nm-glib.h \ - nm-gvaluearray-compat.h \ nm-test-utils.h \ nm-macros-internal.h diff --git a/include/nm-glib.h b/include/nm-glib.h index 9b57c61331..9a5bc058e2 100644 --- a/include/nm-glib.h +++ b/include/nm-glib.h @@ -38,9 +38,6 @@ #endif - -#include "nm-gvaluearray-compat.h" - static inline void __g_type_ensure (GType type) { diff --git a/libnm-util/Makefile.am b/libnm-util/Makefile.am index d7d3ba8206..14c6ccacb6 100644 --- a/libnm-util/Makefile.am +++ b/libnm-util/Makefile.am @@ -62,9 +62,11 @@ nodist_libnm_util_include_HEADERS = \ libnm_util_la_private_headers = \ crypto.h \ + nm-dbus-glib-types.h \ + nm-gvaluearray-compat.h \ nm-param-spec-specialized.h \ - nm-utils-private.h \ - nm-setting-private.h + nm-setting-private.h \ + nm-utils-private.h libnm_util_la_csources = \ crypto.c \ diff --git a/include/nm-dbus-glib-types.h b/libnm-util/nm-dbus-glib-types.h similarity index 100% rename from include/nm-dbus-glib-types.h rename to libnm-util/nm-dbus-glib-types.h diff --git a/include/nm-gvaluearray-compat.h b/libnm-util/nm-gvaluearray-compat.h similarity index 100% rename from include/nm-gvaluearray-compat.h rename to libnm-util/nm-gvaluearray-compat.h diff --git a/libnm-util/nm-param-spec-specialized.c b/libnm-util/nm-param-spec-specialized.c index 50903b067d..7f242acfca 100644 --- a/libnm-util/nm-param-spec-specialized.c +++ b/libnm-util/nm-param-spec-specialized.c @@ -23,6 +23,7 @@ #include "config.h" #include "nm-default.h" +#include "nm-gvaluearray-compat.h" #include "nm-param-spec-specialized.h" struct _NMParamSpecSpecialized { diff --git a/libnm-util/nm-utils.c b/libnm-util/nm-utils.c index ab19f2a68d..1659a1a3c9 100644 --- a/libnm-util/nm-utils.c +++ b/libnm-util/nm-utils.c @@ -30,6 +30,7 @@ #include #include "nm-default.h" +#include "nm-gvaluearray-compat.h" #include "nm-utils.h" #include "nm-utils-private.h" #include "nm-dbus-glib-types.h" diff --git a/libnm-util/nm-value-transforms.c b/libnm-util/nm-value-transforms.c index cc7bc50bfa..fd4aaf6069 100644 --- a/libnm-util/nm-value-transforms.c +++ b/libnm-util/nm-value-transforms.c @@ -24,6 +24,7 @@ #include #include "nm-default.h" +#include "nm-gvaluearray-compat.h" #include "nm-utils.h" #include "nm-utils-private.h" #include "nm-dbus-glib-types.h" diff --git a/libnm-util/tests/test-general.c b/libnm-util/tests/test-general.c index 73c9dd8b5d..2dfa0b6dc1 100644 --- a/libnm-util/tests/test-general.c +++ b/libnm-util/tests/test-general.c @@ -30,6 +30,7 @@ #include #include "nm-default.h" +#include "nm-gvaluearray-compat.h" #include "nm-setting-private.h" #include "nm-setting-connection.h" diff --git a/src/Makefile.am b/src/Makefile.am index fbd64722ec..0a60fb9745 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -33,6 +33,7 @@ endif AM_CPPFLAGS = \ -I$(top_srcdir)/include \ + -I$(top_builddir)/introspection \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ -I$(top_srcdir)/callouts \ @@ -190,7 +191,7 @@ nm_dhcp_client_headers = \ dhcp-manager/nm-dhcp-dhcpcd.h \ dhcp-manager/nm-dhcp-systemd.h -nm_sources = \ +libNetworkManager_la_SOURCES = \ $(nm_device_headers) \ $(nm_dhcp_client_headers) \ devices/nm-device.c \ @@ -362,14 +363,14 @@ nm_sources = \ if SUSPEND_RESUME_UPOWER -nm_sources += nm-sleep-monitor-upower.c +libNetworkManager_la_SOURCES += nm-sleep-monitor-upower.c else # systemd/consolekit suspend/resume used whenever upower is not enabled -nm_sources += nm-sleep-monitor-systemd.c +libNetworkManager_la_SOURCES += nm-sleep-monitor-systemd.c endif if WITH_WEXT -nm_sources += \ +libNetworkManager_la_SOURCES += \ platform/wifi/wifi-utils-wext.c \ platform/wifi/wifi-utils-wext.h endif @@ -378,45 +379,11 @@ endif GLIB_GENERATED = nm-enum-types.h nm-enum-types.c GLIB_MKENUMS_H_FLAGS = --identifier-prefix NM --fhead '\#include \n' GLIB_MKENUMS_C_FLAGS = --identifier-prefix NM -nm_enum_types_sources = $(nm_sources) +nm_enum_types_sources = $(libNetworkManager_la_SOURCES) BUILT_SOURCES = $(GLIB_GENERATED) - -glue_sources = \ - nm-access-point-glue.h \ - nm-active-connection-glue.h \ - nm-agent-manager-glue.h \ - nm-device-bond-glue.h \ - nm-device-bridge-glue.h \ - nm-device-ethernet-glue.h \ - nm-device-generic-glue.h \ - nm-device-glue.h \ - nm-device-gre-glue.h \ - nm-device-infiniband-glue.h \ - nm-device-macvlan-glue.h \ - nm-device-tun-glue.h \ - nm-device-veth-glue.h \ - nm-device-vlan-glue.h \ - nm-device-vxlan-glue.h \ - nm-dhcp4-config-glue.h \ - nm-dhcp6-config-glue.h \ - nm-ip4-config-glue.h \ - nm-ip6-config-glue.h \ - nm-manager-glue.h \ - nm-ppp-manager-glue.h \ - nm-settings-connection-glue.h \ - nm-settings-glue.h \ - nm-vpn-connection-glue.h - -BUILT_SOURCES += $(glue_sources) - -%-glue.h: $(top_srcdir)/introspection/%.xml - $(AM_V_GEN) dbus-binding-tool --prefix=$(subst -,_,$(subst -glue.h,,$@)) --mode=glib-server --output=$@ $< - - AM_CPPFLAGS += \ - $(DBUS_CFLAGS) \ $(GLIB_CFLAGS) \ $(GUDEV_CFLAGS) \ $(LIBNL_CFLAGS) \ @@ -450,14 +417,10 @@ AM_CPPFLAGS += \ \ $(NULL) -libNetworkManager_la_SOURCES = \ - $(nm_sources) \ - $(glue_sources) - libNetworkManager_la_LIBADD = \ $(top_builddir)/libnm-core/libnm-core.la \ + $(top_builddir)/introspection/libnmdbus.la \ libsystemd-nm.la \ - $(DBUS_LIBS) \ $(GLIB_LIBS) \ $(GUDEV_LIBS) \ $(LIBNL_LIBS) \ @@ -533,8 +496,8 @@ endif libnm_iface_helper_la_LIBADD = \ $(top_builddir)/libnm-core/libnm-core.la \ + $(top_builddir)/introspection/libnmdbus.la \ libsystemd-nm.la \ - $(DBUS_LIBS) \ $(GLIB_LIBS) \ $(GUDEV_LIBS) \ $(LIBNL_LIBS) \ @@ -555,7 +518,6 @@ nm_iface_helper_LDADD = \ $(top_builddir)/libnm-core/libnm-core.la \ libsystemd-nm.la \ libnm-iface-helper.la \ - $(DBUS_LIBS) \ $(GLIB_LIBS) \ $(GUDEV_LIBS) \ $(SYSTEMD_JOURNAL_LIBS) \ @@ -582,8 +544,4 @@ install-data-hook: $(mkinstalldirs) -m 0755 $(DESTDIR)$(pkglibdir) CLEANFILES = \ - $(BUILT_SOURCES) \ - settings/*-glue.h \ - devices/*-glue.h \ - devices/*/*-glue.h - + $(BUILT_SOURCES) diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c index bab2755743..eae6812f63 100644 --- a/src/NetworkManagerUtils.c +++ b/src/NetworkManagerUtils.c @@ -44,7 +44,6 @@ #include "nm-setting-wireless.h" #include "nm-setting-wireless-security.h" #include "nm-auth-utils.h" -#include "nm-dbus-glib-types.h" /* * Some toolchains (E.G. uClibc 0.9.33 and earlier) don't export @@ -2890,47 +2889,6 @@ nm_utils_ipv6_interface_identfier_get_from_addr (NMUtilsIPv6IfaceId *iid, memcpy (iid, addr->s6_addr + 8, 8); } -/** - * nm_utils_connection_hash_to_dict: - * @hash: a hashed #NMConnection - * - * Returns: a (floating) #GVariant equivalent to @hash. - */ -GVariant * -nm_utils_connection_hash_to_dict (GHashTable *hash) -{ - GValue val = { 0, }; - GVariant *variant; - - if (!hash) - return NULL; - - g_value_init (&val, DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT); - g_value_set_boxed (&val, hash); - variant = dbus_g_value_build_g_variant (&val); - g_value_unset (&val); - - return variant; -} - -/** - * nm_utils_connection_dict_to_hash: - * @dict: a #GVariant-serialized #NMConnection - * - * Returns: a #GHashTable equivalent to @dict. - */ -GHashTable * -nm_utils_connection_dict_to_hash (GVariant *dict) -{ - GValue val = { 0, }; - - if (!dict) - return NULL; - - dbus_g_value_parse_g_variant (dict, &val); - return g_value_get_boxed (&val); -} - /** * nm_utils_setpgid: * @unused: unused @@ -2963,9 +2921,9 @@ nm_utils_g_value_set_object_path (GValue *value, gpointer object) g_return_if_fail (!object || NM_IS_EXPORTED_OBJECT (object)); if (object && nm_exported_object_is_exported (object)) - g_value_set_boxed (value, nm_exported_object_get_path (object)); + g_value_set_string (value, nm_exported_object_get_path (object)); else - g_value_set_boxed (value, "/"); + g_value_set_string (value, "/"); } /** @@ -2989,7 +2947,8 @@ nm_utils_g_value_set_object_path_array (GValue *value, GSList *objects) continue; g_ptr_array_add (paths, g_strdup (nm_exported_object_get_path (object))); } - g_value_take_boxed (value, paths); + g_ptr_array_add (paths, NULL); + g_value_take_boxed (value, (char **) g_ptr_array_free (paths, FALSE)); } /** diff --git a/src/NetworkManagerUtils.h b/src/NetworkManagerUtils.h index a5a0563ba6..0d47bce9b6 100644 --- a/src/NetworkManagerUtils.h +++ b/src/NetworkManagerUtils.h @@ -224,9 +224,6 @@ void nm_utils_ipv6_addr_set_interface_identfier (struct in6_addr *addr, void nm_utils_ipv6_interface_identfier_get_from_addr (NMUtilsIPv6IfaceId *iid, const struct in6_addr *addr); -GVariant *nm_utils_connection_hash_to_dict (GHashTable *hash); -GHashTable *nm_utils_connection_dict_to_hash (GVariant *dict); - void nm_utils_array_remove_at_indexes (GArray *array, const guint *indexes_to_delete, gsize len); void nm_utils_setpgid (gpointer unused); diff --git a/src/dhcp-manager/tests/Makefile.am b/src/dhcp-manager/tests/Makefile.am index 8fec6972c2..16a11db3ba 100644 --- a/src/dhcp-manager/tests/Makefile.am +++ b/src/dhcp-manager/tests/Makefile.am @@ -9,7 +9,6 @@ AM_CPPFLAGS = \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ -DTESTDIR="\"$(abs_srcdir)\"" noinst_PROGRAMS = \ diff --git a/src/main.c b/src/main.c index 4f83f849ba..59d39f763a 100644 --- a/src/main.c +++ b/src/main.c @@ -21,9 +21,6 @@ #include "config.h" -#include -#include -#include #include #include #include @@ -401,13 +398,6 @@ main (int argc, char *argv[]) } g_clear_error (&error); - dbus_threads_init_default (); - - /* Ensure that non-exported properties don't leak out, and that the - * introspection 'access' permissions are respected. - */ - dbus_glib_global_set_disable_legacy_property_access (); - nm_log_info (LOGD_CORE, "Read config: %s", nm_config_data_get_config_description (nm_config_get_data (config))); nm_config_data_log (nm_config_get_data (config), "CONFIG: "); nm_log_dbg (LOGD_CORE, "WEXT support is %s", @@ -427,12 +417,7 @@ main (int argc, char *argv[]) wimax_enabled); if (!nm_bus_manager_get_connection (nm_bus_manager_get ())) { -#if HAVE_DBUS_GLIB_100 nm_log_warn (LOGD_CORE, "Failed to connect to D-Bus; only private bus is available"); -#else - nm_log_err (LOGD_CORE, "Failed to connect to D-Bus, exiting..."); - goto done; -#endif } else { /* Start our DBus service */ if (!nm_bus_manager_start_service (nm_bus_manager_get ())) { diff --git a/src/nm-auth-subject.c b/src/nm-auth-subject.c index 5e2eaa7250..c4b6e579ac 100644 --- a/src/nm-auth-subject.c +++ b/src/nm-auth-subject.c @@ -167,9 +167,9 @@ nm_auth_subject_get_unix_process_dbus_sender (NMAuthSubject *subject) /**************************************************************/ static NMAuthSubject * -_new_unix_process (DBusGMethodInvocation *context, - DBusConnection *connection, - DBusMessage *message) +_new_unix_process (GDBusMethodInvocation *context, + GDBusConnection *connection, + GDBusMessage *message) { NMAuthSubject *self; gboolean success = FALSE; @@ -221,14 +221,14 @@ _new_unix_process (DBusGMethodInvocation *context, } NMAuthSubject * -nm_auth_subject_new_unix_process_from_context (DBusGMethodInvocation *context) +nm_auth_subject_new_unix_process_from_context (GDBusMethodInvocation *context) { return _new_unix_process (context, NULL, NULL); } NMAuthSubject * -nm_auth_subject_new_unix_process_from_message (DBusConnection *connection, - DBusMessage *message) +nm_auth_subject_new_unix_process_from_message (GDBusConnection *connection, + GDBusMessage *message) { return _new_unix_process (NULL, connection, message); } diff --git a/src/nm-auth-subject.h b/src/nm-auth-subject.h index 3205ced720..1682ba7f1a 100644 --- a/src/nm-auth-subject.h +++ b/src/nm-auth-subject.h @@ -22,8 +22,6 @@ #define __NETWORKMANAGER_AUTH_SUBJECT_H__ #include "config.h" -#include -#include #include "nm-default.h" @@ -57,9 +55,9 @@ GType nm_auth_subject_get_type (void); NMAuthSubject *nm_auth_subject_new_internal (void); -NMAuthSubject *nm_auth_subject_new_unix_process_from_context (DBusGMethodInvocation *context); +NMAuthSubject *nm_auth_subject_new_unix_process_from_context (GDBusMethodInvocation *context); -NMAuthSubject *nm_auth_subject_new_unix_process_from_message (DBusConnection *connection, DBusMessage *message); +NMAuthSubject *nm_auth_subject_new_unix_process_from_message (GDBusConnection *connection, GDBusMessage *message); NMAuthSubjectType nm_auth_subject_get_subject_type (NMAuthSubject *subject); diff --git a/src/nm-auth-utils.c b/src/nm-auth-utils.c index 969accb7ba..1ed01b6c8d 100644 --- a/src/nm-auth-utils.c +++ b/src/nm-auth-utils.c @@ -34,7 +34,7 @@ struct NMAuthChain { GSList *calls; GHashTable *data; - DBusGMethodInvocation *context; + GDBusMethodInvocation *context; NMAuthSubject *subject; GError *error; @@ -83,7 +83,7 @@ auth_chain_finish (gpointer user_data) /* Creates the NMAuthSubject automatically */ NMAuthChain * -nm_auth_chain_new_context (DBusGMethodInvocation *context, +nm_auth_chain_new_context (GDBusMethodInvocation *context, NMAuthChainResultFunc done_func, gpointer user_data) { @@ -107,7 +107,7 @@ nm_auth_chain_new_context (DBusGMethodInvocation *context, /* Requires an NMAuthSubject */ NMAuthChain * nm_auth_chain_new_subject (NMAuthSubject *subject, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, NMAuthChainResultFunc done_func, gpointer user_data) { diff --git a/src/nm-auth-utils.h b/src/nm-auth-utils.h index 4071b12154..c6cad52a6d 100644 --- a/src/nm-auth-utils.h +++ b/src/nm-auth-utils.h @@ -21,8 +21,6 @@ #ifndef __NETWORKMANAGER_MANAGER_AUTH_H__ #define __NETWORKMANAGER_MANAGER_AUTH_H__ -#include - #include #include "nm-default.h" @@ -50,15 +48,15 @@ typedef enum { typedef void (*NMAuthChainResultFunc) (NMAuthChain *chain, GError *error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, gpointer user_data); -NMAuthChain *nm_auth_chain_new_context (DBusGMethodInvocation *context, +NMAuthChain *nm_auth_chain_new_context (GDBusMethodInvocation *context, NMAuthChainResultFunc done_func, gpointer user_data); NMAuthChain *nm_auth_chain_new_subject (NMAuthSubject *subject, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, NMAuthChainResultFunc done_func, gpointer user_data); diff --git a/src/nm-dispatcher.c b/src/nm-dispatcher.c index 57fb0249c1..60560da705 100644 --- a/src/nm-dispatcher.c +++ b/src/nm-dispatcher.c @@ -34,7 +34,6 @@ #include "nm-dhcp6-config.h" #include "nm-ip4-config.h" #include "nm-ip6-config.h" -#include "nm-dbus-glib-types.h" #include "nm-settings-connection.h" #include "nm-platform.h" #include "nm-core-internal.h" diff --git a/src/rdisc/tests/Makefile.am b/src/rdisc/tests/Makefile.am index 12e047b39c..b5b09f1979 100644 --- a/src/rdisc/tests/Makefile.am +++ b/src/rdisc/tests/Makefile.am @@ -15,7 +15,6 @@ AM_CPPFLAGS = \ AM_CFLAGS = $(CODE_COVERAGE_CFLAGS) AM_LDFLAGS = \ $(GLIB_LIBS) \ - $(DBUS_LIBS) \ $(CODE_COVERAGE_LDFLAGS) @GNOME_CODE_COVERAGE_RULES@ diff --git a/src/settings/plugins/ibft/Makefile.am b/src/settings/plugins/ibft/Makefile.am index d34ee6eab9..3f9e934645 100644 --- a/src/settings/plugins/ibft/Makefile.am +++ b/src/settings/plugins/ibft/Makefile.am @@ -20,7 +20,6 @@ AM_CPPFLAGS = \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ -DG_LOG_DOMAIN=\""NetworkManager-ibft"\" \ -DSYSCONFDIR=\"$(sysconfdir)\" \ -DSBINDIR=\"$(sbindir)\" diff --git a/src/settings/plugins/ibft/plugin.c b/src/settings/plugins/ibft/plugin.c index 944209285b..71ccd70554 100644 --- a/src/settings/plugins/ibft/plugin.c +++ b/src/settings/plugins/ibft/plugin.c @@ -29,7 +29,6 @@ #include #include "nm-default.h" -#include "nm-dbus-glib-types.h" #include "nm-system-config-interface.h" #include "NetworkManagerUtils.h" diff --git a/src/settings/plugins/ibft/tests/Makefile.am b/src/settings/plugins/ibft/tests/Makefile.am index 083c66568e..257a3a5a01 100644 --- a/src/settings/plugins/ibft/tests/Makefile.am +++ b/src/settings/plugins/ibft/tests/Makefile.am @@ -20,7 +20,6 @@ AM_CPPFLAGS = \ AM_LDFLAGS = \ $(GLIB_LIBS) \ - $(DBUS_LIBS) \ $(CODE_COVERAGE_LDFLAGS) noinst_PROGRAMS = test-ibft diff --git a/src/settings/plugins/ifnet/Makefile.am b/src/settings/plugins/ifnet/Makefile.am index f9a5a4d53c..0be0cc6cab 100644 --- a/src/settings/plugins/ifnet/Makefile.am +++ b/src/settings/plugins/ifnet/Makefile.am @@ -13,7 +13,6 @@ AM_CPPFLAGS = \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ -DSYSCONFDIR=\"$(sysconfdir)\" -DSBINDIR=\"$(sbindir)\" diff --git a/src/settings/plugins/ifnet/tests/Makefile.am b/src/settings/plugins/ifnet/tests/Makefile.am index 359894e32e..8d97f56f28 100644 --- a/src/settings/plugins/ifnet/tests/Makefile.am +++ b/src/settings/plugins/ifnet/tests/Makefile.am @@ -15,7 +15,6 @@ AM_CPPFLAGS= \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(CHECK_CFLAGS) \ $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ $(CODE_COVERAGE_CFLAGS) \ -DTEST_IFNET_DIR=\"$(abs_srcdir)\" \ -DTEST_SCRATCH_DIR=\"$(abs_builddir)/\" \ diff --git a/src/settings/plugins/ifupdown/Makefile.am b/src/settings/plugins/ifupdown/Makefile.am index bec8de06c4..dfa64e051b 100644 --- a/src/settings/plugins/ifupdown/Makefile.am +++ b/src/settings/plugins/ifupdown/Makefile.am @@ -12,7 +12,6 @@ AM_CPPFLAGS = \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ $(GUDEV_CFLAGS) \ -DSYSCONFDIR=\"$(sysconfdir)\" diff --git a/src/settings/plugins/keyfile/Makefile.am b/src/settings/plugins/keyfile/Makefile.am index dc14261c80..f146e7bdd3 100644 --- a/src/settings/plugins/keyfile/Makefile.am +++ b/src/settings/plugins/keyfile/Makefile.am @@ -12,7 +12,6 @@ AM_CPPFLAGS = \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ -DNMCONFDIR=\"$(nmconfdir)\" noinst_LTLIBRARIES = \ diff --git a/src/settings/plugins/keyfile/nm-keyfile-connection.c b/src/settings/plugins/keyfile/nm-keyfile-connection.c index 06504a99b6..9504df72f4 100644 --- a/src/settings/plugins/keyfile/nm-keyfile-connection.c +++ b/src/settings/plugins/keyfile/nm-keyfile-connection.c @@ -29,7 +29,6 @@ #include "nm-default.h" #include "nm-system-config-interface.h" -#include "nm-dbus-glib-types.h" #include "nm-keyfile-connection.h" #include "reader.h" #include "writer.h" diff --git a/src/settings/plugins/keyfile/tests/Makefile.am b/src/settings/plugins/keyfile/tests/Makefile.am index 221c1de0fe..80f934e798 100644 --- a/src/settings/plugins/keyfile/tests/Makefile.am +++ b/src/settings/plugins/keyfile/tests/Makefile.am @@ -12,7 +12,6 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/src/settings \ -I$(srcdir)/../ \ $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ $(CODE_COVERAGE_CFLAGS) \ -DG_LOG_DOMAIN=\""NetworkManager-keyfile"\" \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ @@ -31,7 +30,6 @@ test_keyfile_SOURCES = \ test_keyfile_LDADD = \ $(top_builddir)/src/libNetworkManager.la \ - $(DBUS_LIBS) \ $(CODE_COVERAGE_LDFLAGS) @VALGRIND_RULES@ diff --git a/src/supplicant-manager/nm-supplicant-config.c b/src/supplicant-manager/nm-supplicant-config.c index 722645dd9c..7dbd4b774d 100644 --- a/src/supplicant-manager/nm-supplicant-config.c +++ b/src/supplicant-manager/nm-supplicant-config.c @@ -23,7 +23,6 @@ #include #include -#include #include "nm-default.h" #include "nm-supplicant-config.h" diff --git a/src/supplicant-manager/nm-supplicant-manager.c b/src/supplicant-manager/nm-supplicant-manager.c index e0b132e8bd..8afddeec7f 100644 --- a/src/supplicant-manager/nm-supplicant-manager.c +++ b/src/supplicant-manager/nm-supplicant-manager.c @@ -22,7 +22,6 @@ #include "config.h" #include -#include #include "nm-default.h" #include "nm-supplicant-manager.h" diff --git a/src/supplicant-manager/tests/Makefile.am b/src/supplicant-manager/tests/Makefile.am index 032d97071b..63193a1b35 100644 --- a/src/supplicant-manager/tests/Makefile.am +++ b/src/supplicant-manager/tests/Makefile.am @@ -7,8 +7,7 @@ AM_CPPFLAGS = \ -DG_LOG_DOMAIN=\""NetworkManager"\" \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ - $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) + $(GLIB_CFLAGS) noinst_PROGRAMS = test-supplicant-config diff --git a/src/supplicant-manager/tests/test-supplicant-config.c b/src/supplicant-manager/tests/test-supplicant-config.c index 9e163606ce..24bfbfdb1c 100644 --- a/src/supplicant-manager/tests/test-supplicant-config.c +++ b/src/supplicant-manager/tests/test-supplicant-config.c @@ -30,8 +30,6 @@ #include #include -#include - #include "nm-core-internal.h" #include "nm-supplicant-config.h" diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index c008385f1c..8e06a54799 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -12,8 +12,7 @@ AM_CPPFLAGS = \ -DG_LOG_DOMAIN=\""NetworkManager"\" \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ - $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) + $(GLIB_CFLAGS) noinst_PROGRAMS = \ test-general \ diff --git a/src/tests/config/Makefile.am b/src/tests/config/Makefile.am index a8e2905c80..e0e3e13218 100644 --- a/src/tests/config/Makefile.am +++ b/src/tests/config/Makefile.am @@ -9,7 +9,6 @@ AM_CPPFLAGS = \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ -DSRCDIR=\""$(srcdir)"\" \ -DBUILDDIR=\""$(builddir)"\" From 753e81d21f15bb9cba0bb41493b5bda4b4f625f8 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Wed, 29 Jul 2015 15:37:43 -0400 Subject: [PATCH 14/14] build: make libnm-util/libnm-glib optional Add --without-libnm-glib, for people who don't want to build the legacy client libraries. When building with this option, dbus-glib and libdbus are not required. --- Makefile.am | 14 ++++++++++---- configure.ac | 16 +++++++++++----- docs/Makefile.am | 7 ++++++- vapi/Makefile.am | 2 ++ 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/Makefile.am b/Makefile.am index 3ce59e1352..00e703cc1c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -6,8 +6,6 @@ SUBDIRS = \ introspection \ libnm-core \ libnm \ - libnm-util \ - libnm-glib \ src \ callouts \ clients \ @@ -15,9 +13,17 @@ SUBDIRS = \ policy \ data \ po \ - docs \ man \ - examples \ + examples + +if WITH_LEGACY_LIBRARIES +SUBDIRS += \ + libnm-util \ + libnm-glib +endif + +SUBDIRS += \ + docs \ vapi @GNOME_CODE_COVERAGE_RULES@ diff --git a/configure.ac b/configure.ac index aad7f4c6f3..6c87154f2d 100644 --- a/configure.ac +++ b/configure.ac @@ -268,11 +268,6 @@ dnl AC_CHECK_LIB([dl], [dladdr], LIBDL="-ldl", LIBDL="") AC_SUBST(LIBDL) -dnl -dnl Checks for dbus-glib -dnl -PKG_CHECK_MODULES(DBUS, dbus-1 >= 1.1 dbus-glib-1 >= 0.94) - PKG_CHECK_MODULES(GLIB, [gio-unix-2.0 >= 2.37.6 gmodule-2.0], [AC_SUBST(LOG_DRIVER, '$(top_srcdir)/build-aux/tap-driver.sh'), AC_SUBST(AM_TESTS_FD_REDIRECT, '--tap')], @@ -288,6 +283,16 @@ GLIB_CFLAGS="$GLIB_CFLAGS -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_32 -DGLIB_V AC_SUBST(GLIB_CFLAGS) AC_SUBST(GLIB_LIBS) +AC_ARG_WITH(libnm-glib, AS_HELP_STRING([--without-libnm-glib], [don't build legacy libraries])) +if test "$with_libnm_glib" != "no"; then + PKG_CHECK_MODULES(DBUS, dbus-1 >= 1.1 dbus-glib-1 >= 0.94, :, + [AC_MSG_FAILURE([$DBUS_PKG_ERRORS + +Configure with --without-libnm-glib if you do not need the legacy libraries])]) + with_libnm_glib=yes +fi +AM_CONDITIONAL(WITH_LEGACY_LIBRARIES, test "$with_libnm_glib" != "no") + PKG_CHECK_MODULES(GUDEV, gudev-1.0 >= 165) GOBJECT_INTROSPECTION_CHECK([0.9.6]) @@ -1140,6 +1145,7 @@ echo " ppp: $enable_ppp" echo " modemmanager-1: $with_modem_manager_1" echo " concheck: $enable_concheck" echo " libteamdctl: $enable_teamdctl" +echo " libnm-glib: $with_libnm_glib" echo " nmtui: $build_nmtui" echo diff --git a/docs/Makefile.am b/docs/Makefile.am index 5fdeff62b4..52cbe5286d 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -1,2 +1,7 @@ -SUBDIRS = libnm-glib libnm-util libnm api +SUBDIRS = libnm api +if WITH_LEGACY_LIBRARIES +SUBDIRS += \ + libnm-util \ + libnm-glib +endif diff --git a/vapi/Makefile.am b/vapi/Makefile.am index e154554893..4913d1a580 100644 --- a/vapi/Makefile.am +++ b/vapi/Makefile.am @@ -4,7 +4,9 @@ EXTRA_DIST = \ libnm-util.deps \ libnm-glib.deps +if WITH_LEGACY_LIBRARIES VAPIGEN_VAPIS = libnm-util.vapi libnm-glib.vapi +endif if ENABLE_VAPIGEN include Makefile.vapigen