static void vpn_export_get_secrets_cb (GObject *object, GAsyncResult *result, gpointer user_data) { NMConnection *tmp; GVariant *secrets; GError *error = NULL; secrets = nm_remote_connection_get_secrets_finish (NM_REMOTE_CONNECTION (object), result, &error); /* We don't really care about errors; if the user couldn't authenticate * then just let them export everything except secrets. Duplicate the * connection so that we don't let secrets sit around in the original * one. */ tmp = nm_simple_connection_new_clone (NM_CONNECTION (object)); g_assert (tmp); if (secrets) nm_connection_update_secrets (tmp, NM_SETTING_VPN_SETTING_NAME, secrets, NULL); vpn_export (tmp); g_object_unref (tmp); if (secrets) g_variant_ref (secrets); g_clear_error (&error); }
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 remove_connections_read (NMRemoteSettings *settings, gpointer user_data) { RemoveInfo *info = user_data; GSList *list, *iter; g_source_remove (info->timeout_id); g_message ("Removing Bluetooth connections for %s", info->str_bdaddr); list = nm_remote_settings_list_connections (settings); for (iter = list; iter != NULL; iter = g_slist_next (iter)) { NMConnection *connection = iter->data; NMSettingBluetooth *s_bt; const GByteArray *tmp; s_bt = nm_connection_get_setting_bluetooth (connection); if (s_bt) { tmp = nm_setting_bluetooth_get_bdaddr (s_bt); if (tmp && memcmp (tmp->data, info->bdaddr->data, tmp->len) == 0) nm_remote_connection_delete (NM_REMOTE_CONNECTION (connection), delete_cb, NULL); } } g_slist_free (list); remove_cleanup (info); }
static void request_secrets (GetSecretsInfo *info) { g_return_if_fail (info != NULL); nm_remote_connection_get_secrets_async (NM_REMOTE_CONNECTION (info->self->orig_connection), info->setting_name, NULL, get_secrets_cb, info); }
static void clear_one_hash (GHashTable *table) { GHashTableIter iter; gpointer value; GSList *list = NULL, *list_iter; /* Build up the list of connections; we can't emit "removed" during hash * table iteration because emission of the "removed" signal may trigger code * that explicitly removes the the connection from the hash table somewhere * else. */ g_hash_table_iter_init (&iter, table); while (g_hash_table_iter_next (&iter, NULL, &value)) list = g_slist_prepend (list, NM_REMOTE_CONNECTION (value)); for (list_iter = list; list_iter; list_iter = g_slist_next (list_iter)) g_signal_emit_by_name (NM_REMOTE_CONNECTION (list_iter->data), NM_REMOTE_CONNECTION_REMOVED); g_slist_free (list); g_hash_table_remove_all (table); }
static GSList * list_connections (NMSettingsInterface *settings) { NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings); GSList *list = NULL; GHashTableIter iter; gpointer value; g_hash_table_iter_init (&iter, priv->connections); while (g_hash_table_iter_next (&iter, NULL, &value)) list = g_slist_prepend (list, NM_REMOTE_CONNECTION (value)); return list; }
static void apply_edits (NetConnectionEditor *editor) { update_connection (editor); if (editor->is_new_connection) { nm_remote_settings_add_connection (editor->settings, editor->orig_connection, added_connection_cb, editor); } else { nm_remote_connection_commit_changes (NM_REMOTE_CONNECTION (editor->orig_connection), updated_connection_cb, editor); } }
static void export_button_clicked_cb (GtkWidget *widget, gpointer user_data) { NMConnectionEditor *self = NM_CONNECTION_EDITOR (user_data); if (NM_IS_REMOTE_CONNECTION (self->orig_connection)) { /* Grab secrets if we can */ nm_remote_connection_get_secrets_async (NM_REMOTE_CONNECTION (self->orig_connection), NM_SETTING_VPN_SETTING_NAME, NULL, vpn_export_get_secrets_cb, self); } else vpn_export (self->connection); }
static gboolean remove_connections (gpointer user_data) { NMRemoteSettings *self = NM_REMOTE_SETTINGS (user_data); NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self); GHashTableIter iter; gpointer value; g_hash_table_iter_init (&iter, priv->connections); while (g_hash_table_iter_next (&iter, NULL, &value)) g_signal_emit_by_name (NM_REMOTE_CONNECTION (value), "removed"); g_hash_table_remove_all (priv->connections); return FALSE; }
static void edit_done_cb (NMConnectionEditor *editor, GtkResponseType response, gpointer user_data) { NMConnectionList *list = user_data; if (response == GTK_RESPONSE_OK) { NMRemoteConnection *connection = NM_REMOTE_CONNECTION (nm_connection_editor_get_connection (editor)); GtkTreeIter iter; if (get_iter_for_connection (list, connection, &iter)) update_connection_row (list, &iter, connection); } g_object_unref (editor); g_signal_emit (list, list_signals[EDITING_DONE], 0, 0); }
static void save_connection_and_exit (NmtNewtButton *button, gpointer user_data) { NmtEditor *editor = user_data; NmtEditorPrivate *priv = NMT_EDITOR_GET_PRIVATE (editor); NmtSyncOp op; GError *error = NULL; if (!nm_connection_replace_settings_from_connection (priv->orig_connection, priv->edit_connection, &error)) { nmt_newt_message_dialog (_("Error saving connection: %s"), error->message); g_error_free (error); return; } nmt_sync_op_init (&op); if (NM_IS_REMOTE_CONNECTION (priv->orig_connection)) { nm_remote_connection_commit_changes (NM_REMOTE_CONNECTION (priv->orig_connection), connection_updated, &op); if (!nmt_sync_op_wait_boolean (&op, &error)) { nmt_newt_message_dialog (_("Unable to save connection: %s"), error->message); g_error_free (error); return; } /* Clear secrets so they don't lay around in memory; they'll get * requested again anyway next time the connection is edited. */ nm_connection_clear_secrets (priv->orig_connection); } else { nm_remote_settings_add_connection (nm_settings, priv->orig_connection, connection_added, &op); if (!nmt_sync_op_wait_boolean (&op, &error)) { nmt_newt_message_dialog (_("Unable to add new connection: %s"), error->message); g_error_free (error); return; } } nmt_newt_form_quit (NMT_NEWT_FORM (editor)); }
static void updated_connection_cb (GObject *connection, GAsyncResult *result, gpointer user_data) { NMConnectionEditor *self = NM_CONNECTION_EDITOR (user_data); GError *error = NULL; nm_remote_connection_commit_changes_finish (NM_REMOTE_CONNECTION (connection), result, &error); /* Clear secrets so they don't lay around in memory; they'll get requested * again anyway next time the connection is edited. */ nm_connection_clear_secrets (NM_CONNECTION (connection)); update_complete (self, error); g_clear_error (&error); }
/** * nm_remote_settings_list_connections: * @settings: the %NMRemoteSettings * * Returns: (transfer container) (element-type NMClient.RemoteConnection): a * list containing all connections provided by the remote settings service. * Each element of the returned list is a %NMRemoteConnection instance, which is * owned by the %NMRemoteSettings object and should not be freed by the caller. * The returned list is, however, owned by the caller and should be freed * using g_slist_free() when no longer required. **/ GSList * nm_remote_settings_list_connections (NMRemoteSettings *settings) { NMRemoteSettingsPrivate *priv; GSList *list = NULL; GHashTableIter iter; gpointer value; g_return_val_if_fail (settings != NULL, NULL); g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), NULL); priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings); g_hash_table_iter_init (&iter, priv->connections); while (g_hash_table_iter_next (&iter, NULL, &value)) list = g_slist_prepend (list, NM_REMOTE_CONNECTION (value)); return list; }
static void ok_button_clicked_save_connection (NMConnectionEditor *self) { /* Copy the modified connection to the original connection */ nm_connection_replace_settings_from_connection (self->orig_connection, self->connection); nm_connection_editor_set_busy (self, TRUE); /* Save new CA cert ignore values to GSettings */ eap_method_ca_cert_ignore_save (self->connection); if (self->is_new_connection) { nm_client_add_connection_async (self->client, self->orig_connection, TRUE, NULL, added_connection_cb, self); } else { nm_remote_connection_commit_changes_async (NM_REMOTE_CONNECTION (self->orig_connection), TRUE, NULL, updated_connection_cb, self); } }
static void get_secrets_cb (GObject *object, GAsyncResult *result, gpointer user_data) { NMRemoteConnection *connection = NM_REMOTE_CONNECTION (object); GetSecretsInfo *info = user_data; NMConnectionEditor *self; GVariant *secrets; GError *error = NULL; if (info->canceled) { get_secrets_info_free (info); return; } secrets = nm_remote_connection_get_secrets_finish (connection, result, &error); self = info->self; /* Complete this secrets request; completion can actually dispose of the * dialog if there was an error. */ self->secrets_call = NULL; ce_page_complete_init (info->page, info->setting_name, secrets, error); get_secrets_info_free (info); /* Kick off the next secrets request if there is one queued; if the dialog * was disposed of by the completion above we don't need to do anything. */ if (!self->disposed && self->pending_secrets_calls) { self->secrets_call = g_slist_nth_data (self->pending_secrets_calls, 0); self->pending_secrets_calls = g_slist_remove (self->pending_secrets_calls, self->secrets_call); request_secrets (self->secrets_call); } }
static void visible_changed_cb (GObject *object, GParamSpec *pspec, gboolean *done) { if (!nm_remote_connection_get_visible (NM_REMOTE_CONNECTION (object))) *done = TRUE; }