static NMConnection * build_edit_connection (NMConnection *orig_connection) { NMConnection *edit_connection; GHashTable *settings, *secrets; GHashTableIter iter; const char *setting_name; NmtSyncOp op; edit_connection = nm_connection_duplicate (orig_connection); if (!NM_IS_REMOTE_CONNECTION (orig_connection)) return edit_connection; settings = nm_connection_to_hash (orig_connection, NM_SETTING_HASH_FLAG_NO_SECRETS); g_hash_table_iter_init (&iter, settings); while (g_hash_table_iter_next (&iter, (gpointer) &setting_name, NULL)) { nmt_sync_op_init (&op); nm_remote_connection_get_secrets (NM_REMOTE_CONNECTION (orig_connection), setting_name, got_secrets, &op); /* FIXME: error handling */ secrets = nmt_sync_op_wait_pointer (&op, NULL); if (secrets) (void) nm_connection_update_secrets (edit_connection, setting_name, secrets, NULL); } g_hash_table_unref (settings); return edit_connection; }
static void get_secrets_cb (AppletAgent *self, GHashTable *secrets, GError *error, gpointer user_data) { Request *r = user_data; /* 'secrets' shouldn't be valid if there was an error */ if (error) { g_warn_if_fail (secrets == NULL); secrets = NULL; } if (!g_cancellable_is_cancelled (r->cancellable)) { /* Save updated secrets as long as user-interaction was allowed; otherwise * we'd be saving secrets we just pulled out of the keyring which is somewhat * redundant. */ if (secrets && (r->flags != NM_SECRET_AGENT_GET_SECRETS_FLAG_NONE)) { NMConnection *dupl; GHashTableIter iter; const char *setting_name; /* Copy the existing connection and update its secrets */ dupl = nm_connection_duplicate (r->connection); g_hash_table_iter_init (&iter, secrets); while (g_hash_table_iter_next (&iter, (gpointer) &setting_name, NULL)) nm_connection_update_secrets (dupl, setting_name, secrets, NULL); /* And save updated secrets to the keyring */ nm_secret_agent_save_secrets (NM_SECRET_AGENT (self), dupl, get_save_cb, NULL); g_object_unref (dupl); } r->get_callback (NM_SECRET_AGENT (r->agent), r->connection, secrets, error, r->callback_data); } request_free (r); }