diff options
Diffstat (limited to 'src/settings/nm-secret-agent.c')
| -rw-r--r-- | src/settings/nm-secret-agent.c | 140 |
1 files changed, 79 insertions, 61 deletions
diff --git a/src/settings/nm-secret-agent.c b/src/settings/nm-secret-agent.c index 192e9877..af6d7017 100644 --- a/src/settings/nm-secret-agent.c +++ b/src/settings/nm-secret-agent.c @@ -26,13 +26,12 @@ #include <pwd.h> #include "nm-dbus-interface.h" -#include "nm-bus-manager.h" +#include "nm-dbus-manager.h" +#include "nm-core-internal.h" #include "nm-auth-subject.h" #include "nm-simple-connection.h" #include "NetworkManagerUtils.h" -#include "nm-utils/c-list.h" - -#include "introspection/org.freedesktop.NetworkManager.SecretAgent.h" +#include "c-list/src/c-list.h" /*****************************************************************************/ @@ -51,8 +50,8 @@ typedef struct { char *dbus_owner; NMSecretAgentCapabilities capabilities; GSList *permissions; - NMDBusSecretAgent *proxy; - NMBusManager *bus_mgr; + GDBusProxy *proxy; + NMDBusManager *bus_mgr; GDBusConnection *connection; CList requests; gulong on_disconnected_id; @@ -300,7 +299,7 @@ nm_secret_agent_add_permission (NMSecretAgent *agent, * @permission: The name of the permission to check for * * Returns whether or not the agent has the given permission. - * + * * Returns: %TRUE if the agent has the given permission, %FALSE if it does not * or if the permission was not previous recorded with * nm_secret_agent_add_permission(). @@ -336,11 +335,17 @@ get_callback (GObject *proxy, if (request_check_return (r)) { NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (r->agent); gs_free_error GError *error = NULL; + gs_unref_variant GVariant *ret = NULL; gs_unref_variant GVariant *secrets = NULL; - nmdbus_secret_agent_call_get_secrets_finish (priv->proxy, &secrets, result, &error); - if (error) + ret = _nm_dbus_proxy_call_finish (priv->proxy, result, G_VARIANT_TYPE ("(a{sa{sv}})"), &error); + if (!ret) g_dbus_error_strip_remote_error (error); + else { + g_variant_get (ret, + "(@a{sa{sv}})", + &secrets); + } r->callback (r->agent, r, secrets, error, r->callback_data); } @@ -358,7 +363,6 @@ nm_secret_agent_get_secrets (NMSecretAgent *self, gpointer callback_data) { NMSecretAgentPrivate *priv; - static const char *no_hints[] = { NULL }; GVariant *dict; NMSecretAgentCallId *r; @@ -379,16 +383,20 @@ nm_secret_agent_get_secrets (NMSecretAgent *self, r = request_new (self, "GetSecrets", path, setting_name, callback, callback_data); r->is_get_secrets = TRUE; - /* Increase the timeout only for this call */ - g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (priv->proxy), 120000); - nmdbus_secret_agent_call_get_secrets (priv->proxy, - dict, - path, - setting_name, - hints ? hints : no_hints, - flags, - r->cancellable, - get_callback, r); + g_dbus_proxy_call (priv->proxy, + "GetSecrets", + g_variant_new ("(@a{sa{sv}}os^asu)", + dict, + path, + setting_name, + hints ?: NM_PTRARRAY_EMPTY (const char *), + (guint32) flags), + G_DBUS_CALL_FLAGS_NONE, + 120000, + r->cancellable, + get_callback, + r); + g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (priv->proxy), -1); return r; @@ -399,17 +407,16 @@ nm_secret_agent_get_secrets (NMSecretAgent *self, static void cancel_done (GObject *proxy, GAsyncResult *result, gpointer user_data) { - char *description = user_data; - GError *error = NULL; + gs_free char *description = user_data; + gs_free_error GError *error = NULL; + gs_unref_variant GVariant *ret = NULL; - if (!nmdbus_secret_agent_call_cancel_get_secrets_finish (NMDBUS_SECRET_AGENT (proxy), result, &error)) { + ret = _nm_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, G_VARIANT_TYPE ("()"), &error); + if (!ret) { nm_log_dbg (LOGD_AGENTS, "%s%s%s: agent failed to cancel secrets: %s", NM_PRINT_FMT_QUOTED (description, "(", description, ")", "???"), error->message); - g_clear_error (&error); } - - g_free (description); } static void @@ -426,11 +433,16 @@ do_cancel_secrets (NMSecretAgent *self, NMSecretAgentCallId *r, gboolean disposi if ( r->is_get_secrets && priv->proxy) { /* for GetSecrets call, we must cancel the request. */ - 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))); + g_dbus_proxy_call (G_DBUS_PROXY (priv->proxy), + "CancelGetSecrets", + g_variant_new ("(os)", + r->path, + r->setting_name), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + cancel_done, + g_strdup (nm_secret_agent_get_description (self))); } cancellable = r->cancellable; @@ -494,11 +506,11 @@ agent_save_cb (GObject *proxy, NMSecretAgentCallId *r = user_data; if (request_check_return (r)) { - NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (r->agent); gs_free_error GError *error = NULL; + gs_unref_variant GVariant *ret = NULL; - nmdbus_secret_agent_call_save_secrets_finish (priv->proxy, result, &error); - if (error) + ret = _nm_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, G_VARIANT_TYPE ("()"), &error); + if (!ret) g_dbus_error_strip_remote_error (error); r->callback (r->agent, r, NULL, error, r->callback_data); } @@ -527,11 +539,16 @@ nm_secret_agent_save_secrets (NMSecretAgent *self, dict = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL); r = request_new (self, "SaveSecrets", path, NULL, callback, callback_data); - nmdbus_secret_agent_call_save_secrets (priv->proxy, - dict, - path, - NULL, /* cancelling the request does *not* cancel the D-Bus call. */ - agent_save_cb, r); + g_dbus_proxy_call (priv->proxy, + "SaveSecrets", + g_variant_new ("(@a{sa{sv}}o)", + dict, + path), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, /* cancelling the request does *not* cancel the D-Bus call. */ + agent_save_cb, + r); return r; } @@ -546,11 +563,11 @@ agent_delete_cb (GObject *proxy, NMSecretAgentCallId *r = user_data; if (request_check_return (r)) { - NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (r->agent); gs_free_error GError *error = NULL; + gs_unref_variant GVariant *ret = NULL; - nmdbus_secret_agent_call_delete_secrets_finish (priv->proxy, result, &error); - if (error) + ret = _nm_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, G_VARIANT_TYPE ("()"), &error); + if (!ret) g_dbus_error_strip_remote_error (error); r->callback (r->agent, r, NULL, error, r->callback_data); } @@ -579,12 +596,16 @@ nm_secret_agent_delete_secrets (NMSecretAgent *self, dict = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_NO_SECRETS); r = request_new (self, "DeleteSecrets", path, NULL, callback, callback_data); - nmdbus_secret_agent_call_delete_secrets (priv->proxy, - dict, - path, - NULL, /* cancelling the request does *not* cancel the D-Bus call. */ - agent_delete_cb, r); - + g_dbus_proxy_call (priv->proxy, + "DeleteSecrets", + g_variant_new ("(@a{sa{sv}}o)", + dict, + path), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, /* cancelling the request does *not* cancel the D-Bus call. */ + agent_delete_cb, + r); return r; } @@ -610,7 +631,7 @@ _on_disconnected_cleanup (NMSecretAgentPrivate *priv) } static void -_on_disconnected_private_connection (NMBusManager *mgr, +_on_disconnected_private_connection (NMDBusManager *mgr, GDBusConnection *connection, NMSecretAgent *self) { @@ -666,7 +687,6 @@ nm_secret_agent_new (GDBusMethodInvocation *context, NMSecretAgentPrivate *priv; const char *dbus_owner; struct passwd *pw; - GDBusProxy *proxy; char *owner_username = NULL; char *description = NULL; char buf_subject[64]; @@ -695,9 +715,9 @@ nm_secret_agent_new (GDBusMethodInvocation *context, priv = NM_SECRET_AGENT_GET_PRIVATE (self); - priv->bus_mgr = g_object_ref (nm_bus_manager_get ()); + priv->bus_mgr = g_object_ref (nm_dbus_manager_get ()); priv->connection = g_object_ref (connection); - priv->connection_is_private = !!nm_bus_manager_connection_get_private_name (priv->bus_mgr, 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", (description = _create_description (dbus_owner, identifier, uid)), @@ -714,20 +734,18 @@ nm_secret_agent_new (GDBusMethodInvocation *context, priv->capabilities = capabilities; priv->subject = g_object_ref (subject); - proxy = nm_bus_manager_new_proxy (priv->bus_mgr, - priv->connection, - NMDBUS_TYPE_SECRET_AGENT_PROXY, - priv->dbus_owner, - NM_DBUS_PATH_SECRET_AGENT, - NM_DBUS_INTERFACE_SECRET_AGENT); - g_assert (proxy); - priv->proxy = NMDBUS_SECRET_AGENT (proxy); + 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 = g_signal_connect (priv->bus_mgr, - NM_BUS_MANAGER_PRIVATE_CONNECTION_DISCONNECTED, + NM_DBUS_MANAGER_PRIVATE_CONNECTION_DISCONNECTED, G_CALLBACK (_on_disconnected_private_connection), self); } else { |