diff options
Diffstat (limited to 'src/nm-activation-request.c')
-rw-r--r-- | src/nm-activation-request.c | 169 |
1 files changed, 154 insertions, 15 deletions
diff --git a/src/nm-activation-request.c b/src/nm-activation-request.c index d3eb920d26..c3b93fe803 100644 --- a/src/nm-activation-request.c +++ b/src/nm-activation-request.c @@ -39,6 +39,7 @@ #include "nm-dbus-glib-types.h" #include "nm-active-connection-glue.h" #include "nm-settings-connection.h" +#include "compat/nm-compat-act-request.h" G_DEFINE_TYPE (NMActRequest, nm_act_request, G_TYPE_OBJECT) @@ -79,6 +80,8 @@ typedef struct { char *ac_path; gboolean assumed; + + NMCompatActRequest *compat; } NMActRequestPrivate; enum { @@ -102,9 +105,128 @@ typedef struct { guint32 call_id; NMActRequestSecretsFunc callback; gpointer callback_data; + + char *setting_name; + DBusGProxy *user_proxy; } GetSecretsInfo; static void +free_get_secrets_info (GetSecretsInfo *info) +{ + g_free (info->setting_name); + if (info->user_proxy) + g_object_unref (info->user_proxy); + memset (info, 0, sizeof (*info)); + g_free (info); +} + +static void +user_get_secrets_cb (DBusGProxy *proxy, + DBusGProxyCall *call, + gpointer user_data) +{ + GetSecretsInfo *info = user_data; + NMActRequestPrivate *priv; + GHashTable *settings = NULL; + GError *error = NULL; + + nm_log_dbg (LOGD_SETTINGS, "(%p) user secrets request reply", info); + + g_return_if_fail (info != NULL); + g_return_if_fail (info->setting_name); + + priv = NM_ACT_REQUEST_GET_PRIVATE (info->self); + + if (dbus_g_proxy_end_call (proxy, call, &error, + DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &settings, + G_TYPE_INVALID)) { + nm_log_dbg (LOGD_SETTINGS, "got user connection secrets size %d", g_hash_table_size (settings)); + nm_connection_update_secrets (priv->connection, info->setting_name, settings, &error); + +#if 0 + if (g_hash_table_lookup (settings, info->setting_name)) { + GHashTableIter iter; + const char *setting_name = NULL; + GHashTable *setting = NULL; + g_hash_table_iter_init (&iter, settings); + while (g_hash_table_iter_next (&iter, (gpointer) &setting_name, (gpointer) &setting)) { + GHashTableIter setting_iter; + const char *key = NULL; + GValue *val = NULL; + + g_hash_table_iter_init (&setting_iter, setting); + while (g_hash_table_iter_next (&setting_iter, (gpointer) &key, (gpointer) &val)) + g_message (" %s => %s", key, g_strdup_value_contents (val)); + } + } else { + GHashTableIter iter; + const char *key = NULL; + GValue *val = NULL; + + g_hash_table_iter_init (&iter, settings); + while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &val)) + g_message (" %s => %s", key, g_strdup_value_contents (val)); + } +#endif + g_hash_table_destroy (settings); + } else { + nm_log_warn (LOGD_SETTINGS, "failed to get user connection secrets: %s", error->message); + } + + priv->secrets_calls = g_slist_remove (priv->secrets_calls, info); + info->callback (info->self, info->call_id, priv->connection, error, info->callback_data); + g_clear_error (&error); + + free_get_secrets_info (info); +} + +static guint32 +user_get_secrets (NMActRequest *self, + const char *setting_name, + guint32 flags, + const char *hint, + GetSecretsInfo *info) +{ + NMActRequestPrivate *priv = NM_ACT_REQUEST_GET_PRIVATE (self); + NMDBusManager *dbus_mgr; + DBusGConnection *bus; + GPtrArray *hints; + static guint32 counter = 3000000000u; /* start high to avoid collision with system connections */ + + /* User connection */ + dbus_mgr = nm_dbus_manager_get (); + bus = nm_dbus_manager_get_connection (dbus_mgr); + info->user_proxy = dbus_g_proxy_new_for_name (bus, + "org.freedesktop.NetworkManagerUserSettings", + nm_connection_get_path (priv->connection), + NM_DBUS_IFACE_SETTINGS_CONNECTION_SECRETS); + g_object_unref (dbus_mgr); + + if (!info->user_proxy) { + nm_log_warn (LOGD_SETTINGS, "could not create user connection secrets proxy"); + return 0; + } + + hints = g_ptr_array_sized_new (1); + if (hint) + g_ptr_array_add (hints, (gpointer) hint); + + dbus_g_proxy_begin_call_with_timeout (info->user_proxy, "GetSecrets", + user_get_secrets_cb, + info, + NULL, + 120000, + G_TYPE_STRING, setting_name, + DBUS_TYPE_G_ARRAY_OF_STRING, hints, + G_TYPE_BOOLEAN, (flags & NM_SETTINGS_GET_SECRETS_FLAG_REQUEST_NEW), + G_TYPE_INVALID); + nm_log_dbg (LOGD_SETTINGS, "(%p) new user secrets request", info); + + g_ptr_array_free (hints, TRUE); + return counter++; +} + +static void get_secrets_cb (NMSettingsConnection *connection, guint32 call_id, const char *agent_username, @@ -119,7 +241,7 @@ get_secrets_cb (NMSettingsConnection *connection, priv->secrets_calls = g_slist_remove (priv->secrets_calls, info); info->callback (info->self, call_id, NM_CONNECTION (connection), error, info->callback_data); - g_free (info); + free_get_secrets_info (info); } guint32 @@ -143,21 +265,26 @@ nm_act_request_get_secrets (NMActRequest *self, info->self = self; info->callback = callback; info->callback_data = callback_data; + info->setting_name = g_strdup (setting_name); + + if (NM_IS_SETTINGS_CONNECTION (priv->connection)) { + call_id = nm_settings_connection_get_secrets (NM_SETTINGS_CONNECTION (priv->connection), + priv->user_requested, + priv->user_uid, + setting_name, + flags, + hint, + get_secrets_cb, + info, + NULL); + } else + call_id = user_get_secrets (self, setting_name, flags, hint, info); - call_id = nm_settings_connection_get_secrets (NM_SETTINGS_CONNECTION (priv->connection), - priv->user_requested, - priv->user_uid, - setting_name, - flags, - hint, - get_secrets_cb, - info, - NULL); if (call_id > 0) { info->call_id = call_id; priv->secrets_calls = g_slist_append (priv->secrets_calls, info); } else - g_free (info); + free_get_secrets_info (info); return call_id; } @@ -182,8 +309,10 @@ nm_act_request_cancel_secrets (NMActRequest *self, guint32 call_id) priv->secrets_calls = g_slist_remove_link (priv->secrets_calls, iter); g_slist_free (iter); - nm_settings_connection_cancel_secrets (NM_SETTINGS_CONNECTION (priv->connection), call_id); - g_free (info); + if (NM_IS_SETTINGS_CONNECTION (priv->connection)) + nm_settings_connection_cancel_secrets (NM_SETTINGS_CONNECTION (priv->connection), call_id); + /* For user connections destroying the proxy cancels the request */ + free_get_secrets_info (info); break; } } @@ -467,6 +596,12 @@ device_state_changed (NMDevice *device, } } +gpointer +nm_act_request_get_compat (NMActRequest *req) +{ + return NM_ACT_REQUEST_GET_PRIVATE (req)->compat; +} + /********************************************************************/ NMActRequest * @@ -518,6 +653,8 @@ nm_act_request_init (NMActRequest *req) dbus_g_connection_register_g_object (nm_dbus_manager_get_connection (dbus_mgr), priv->ac_path, G_OBJECT (req)); + + priv->compat = nm_compat_act_request_new (req, nm_dbus_manager_get_connection (dbus_mgr)); g_object_unref (dbus_mgr); } @@ -588,12 +725,14 @@ dispose (GObject *object) for (iter = priv->secrets_calls; iter; iter = g_slist_next (iter)) { GetSecretsInfo *info = iter->data; - nm_settings_connection_cancel_secrets (NM_SETTINGS_CONNECTION (priv->connection), info->call_id); - g_free (info); + if (NM_IS_SETTINGS_CONNECTION (priv->connection)) + nm_settings_connection_cancel_secrets (NM_SETTINGS_CONNECTION (priv->connection), info->call_id); + free_get_secrets_info (info); } g_slist_free (priv->secrets_calls); g_object_unref (priv->connection); + g_object_unref (priv->compat); G_OBJECT_CLASS (nm_act_request_parent_class)->dispose (object); } |