diff --git a/src/settings/nm-secret-agent.c b/src/settings/nm-secret-agent.c index a9c32d7b3..ba9f88be3 100644 --- a/src/settings/nm-secret-agent.c +++ b/src/settings/nm-secret-agent.c @@ -26,7 +26,6 @@ #include "nm-glib-aux/nm-dbus-aux.h" #include "nm-dbus-interface.h" -#include "nm-dbus-manager.h" #include "nm-core-internal.h" #include "nm-auth-subject.h" #include "nm-simple-connection.h" @@ -51,14 +50,9 @@ typedef struct { NMSecretAgentCapabilities capabilities; GSList *permissions; GDBusProxy *proxy; - NMDBusManager *bus_mgr; GDBusConnection *connection; CList requests; - union { - gulong obj_signal; - guint dbus_signal; - } on_disconnected_id; - bool connection_is_private:1; + guint on_disconnected_id; } NMSecretAgentPrivate; struct _NMSecretAgent { @@ -617,33 +611,10 @@ nm_secret_agent_delete_secrets (NMSecretAgent *self, static void _on_disconnected_cleanup (NMSecretAgentPrivate *priv) { - if (priv->connection_is_private) { - nm_clear_g_signal_handler (priv->bus_mgr, - &priv->on_disconnected_id.obj_signal); - } else { - nm_clear_g_dbus_connection_signal (priv->connection, - &priv->on_disconnected_id.dbus_signal); - } - + nm_clear_g_dbus_connection_signal (priv->connection, + &priv->on_disconnected_id); g_clear_object (&priv->connection); g_clear_object (&priv->proxy); - g_clear_object (&priv->bus_mgr); -} - -static void -_on_disconnected_private_connection (NMDBusManager *mgr, - GDBusConnection *connection, - NMSecretAgent *self) -{ - NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self); - - if (priv->connection != connection) - return; - - _LOGt ("private connection disconnected"); - - _on_disconnected_cleanup (priv); - g_signal_emit (self, signals[DISCONNECTED], 0); } static void @@ -693,6 +664,7 @@ nm_secret_agent_new (GDBusMethodInvocation *context, char buf_caps[150]; gulong uid; GDBusConnection *connection; + gs_free_error GError *error = NULL; g_return_val_if_fail (context != NULL, NULL); g_return_val_if_fail (NM_IS_AUTH_SUBJECT (subject), NULL); @@ -715,15 +687,12 @@ nm_secret_agent_new (GDBusMethodInvocation *context, priv = NM_SECRET_AGENT_GET_PRIVATE (self); - priv->bus_mgr = g_object_ref (nm_dbus_manager_get ()); priv->connection = g_object_ref (connection); - priv->connection_is_private = !!nm_dbus_manager_connection_get_private_name (priv->bus_mgr, connection); - _LOGT ("constructed: %s, owner=%s%s%s (%s), private-connection=%d, unique-name=%s%s%s, capabilities=%s", + _LOGT ("constructed: %s, owner=%s%s%s (%s), unique-name=%s%s%s, capabilities=%s", (description = _create_description (dbus_owner, identifier, uid)), NM_PRINT_FMT_QUOTE_STRING (owner_username), nm_auth_subject_to_string (subject, buf_subject, sizeof (buf_subject)), - priv->connection_is_private, NM_PRINT_FMT_QUOTE_STRING (g_dbus_connection_get_unique_name (priv->connection)), _capabilities_to_string (capabilities, buf_caps, sizeof (buf_caps))); @@ -734,28 +703,29 @@ nm_secret_agent_new (GDBusMethodInvocation *context, priv->capabilities = capabilities; priv->subject = g_object_ref (subject); - priv->proxy = nm_dbus_manager_new_proxy (priv->bus_mgr, - priv->connection, - G_TYPE_DBUS_PROXY, - priv->dbus_owner, - NM_DBUS_PATH_SECRET_AGENT, - NM_DBUS_INTERFACE_SECRET_AGENT); - - /* we cannot subscribe to notify::g-name-owner because that doesn't work - * for unique names and it doesn't work for private connections. */ - if (priv->connection_is_private) { - priv->on_disconnected_id.obj_signal = g_signal_connect (priv->bus_mgr, - NM_DBUS_MANAGER_PRIVATE_CONNECTION_DISCONNECTED, - G_CALLBACK (_on_disconnected_private_connection), - self); - } else { - priv->on_disconnected_id.dbus_signal = nm_dbus_connection_signal_subscribe_name_owner_changed (priv->connection, - priv->dbus_owner, - _on_disconnected_name_owner_changed, - self, - NULL); + 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, + priv->dbus_owner, + NM_DBUS_PATH_SECRET_AGENT, + NM_DBUS_INTERFACE_SECRET_AGENT, + NULL, + &error); + if (!priv->proxy) { + _LOGW ("could not create proxy for %s on connection %s: %s", + NM_DBUS_INTERFACE_SECRET_AGENT, + priv->dbus_owner, + error->message); + g_clear_error (&error); } + priv->on_disconnected_id = nm_dbus_connection_signal_subscribe_name_owner_changed (priv->connection, + priv->dbus_owner, + _on_disconnected_name_owner_changed, + self, + NULL); + return self; } @@ -823,4 +793,3 @@ nm_secret_agent_class_init (NMSecretAgentClass *config_class) g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); } -