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 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 gboolean nm_connection_editor_set_connection (NMConnectionEditor *editor, NMConnection *orig_connection, GError **error) { NMSettingConnection *s_con; const char *connection_type; const char *slave_type; gboolean success = FALSE; GSList *iter, *copy; g_return_val_if_fail (NM_IS_CONNECTION_EDITOR (editor), FALSE); g_return_val_if_fail (NM_IS_CONNECTION (orig_connection), FALSE); /* clean previous connection */ if (editor->connection) g_object_unref (editor->connection); editor->connection = nm_simple_connection_new_clone (orig_connection); editor->orig_connection = g_object_ref (orig_connection); nm_connection_editor_update_title (editor); /* Handle CA cert ignore stuff */ eap_method_ca_cert_ignore_load (editor->connection); s_con = nm_connection_get_setting_connection (editor->connection); g_assert (s_con); connection_type = nm_setting_connection_get_connection_type (s_con); if (!add_page (editor, ce_page_general_new, editor->connection, error)) goto out; if (!strcmp (connection_type, NM_SETTING_WIRED_SETTING_NAME)) { if (!add_page (editor, ce_page_ethernet_new, editor->connection, error)) goto out; if (!add_page (editor, ce_page_8021x_security_new, editor->connection, error)) goto out; if (!add_page (editor, ce_page_dcb_new, editor->connection, error)) goto out; } else if (!strcmp (connection_type, NM_SETTING_WIRELESS_SETTING_NAME)) { if (!add_page (editor, ce_page_wifi_new, editor->connection, error)) goto out; if (!add_page (editor, ce_page_wifi_security_new, editor->connection, error)) goto out; } else if (!strcmp (connection_type, NM_SETTING_VPN_SETTING_NAME)) { if (!add_page (editor, ce_page_vpn_new, editor->connection, error)) goto out; } else if (!strcmp (connection_type, NM_SETTING_IP_TUNNEL_SETTING_NAME)) { if (!add_page (editor, ce_page_ip_tunnel_new, editor->connection, error)) goto out; } else if (!strcmp (connection_type, NM_SETTING_PPPOE_SETTING_NAME)) { if (!add_page (editor, ce_page_dsl_new, editor->connection, error)) goto out; if (!add_page (editor, ce_page_ethernet_new, editor->connection, error)) goto out; if (!add_page (editor, ce_page_ppp_new, editor->connection, error)) goto out; } else if (!strcmp (connection_type, NM_SETTING_GSM_SETTING_NAME) || !strcmp (connection_type, NM_SETTING_CDMA_SETTING_NAME)) { if (!add_page (editor, ce_page_mobile_new, editor->connection, error)) goto out; if (!add_page (editor, ce_page_ppp_new, editor->connection, error)) goto out; } else if (!strcmp (connection_type, NM_SETTING_BLUETOOTH_SETTING_NAME)) { NMSettingBluetooth *s_bt = nm_connection_get_setting_bluetooth (editor->connection); const char *type = nm_setting_bluetooth_get_connection_type (s_bt); g_assert (type); if (!add_page (editor, ce_page_bluetooth_new, editor->connection, error)) goto out; if (!g_strcmp0 (type, "dun")) { if (!add_page (editor, ce_page_mobile_new, editor->connection, error)) goto out; if (!add_page (editor, ce_page_ppp_new, editor->connection, error)) goto out; } } else if (!strcmp (connection_type, NM_SETTING_INFINIBAND_SETTING_NAME)) { if (!add_page (editor, ce_page_infiniband_new, editor->connection, error)) goto out; } else if (!strcmp (connection_type, NM_SETTING_BOND_SETTING_NAME)) { if (!add_page (editor, ce_page_bond_new, editor->connection, error)) goto out; } else if (!strcmp (connection_type, NM_SETTING_TEAM_SETTING_NAME)) { if (!add_page (editor, ce_page_team_new, editor->connection, error)) goto out; } else if (!strcmp (connection_type, NM_SETTING_BRIDGE_SETTING_NAME)) { if (!add_page (editor, ce_page_bridge_new, editor->connection, error)) goto out; } else if (!strcmp (connection_type, NM_SETTING_VLAN_SETTING_NAME)) { if (!add_page (editor, ce_page_vlan_new, editor->connection, error)) goto out; } else { g_warning ("Unhandled setting type '%s'", connection_type); } slave_type = nm_setting_connection_get_slave_type (s_con); if (!g_strcmp0 (slave_type, NM_SETTING_TEAM_SETTING_NAME)) { if (!add_page (editor, ce_page_team_port_new, editor->connection, error)) goto out; } else if (!g_strcmp0 (slave_type, NM_SETTING_BRIDGE_SETTING_NAME)) { if (!add_page (editor, ce_page_bridge_port_new, editor->connection, error)) goto out; } if ( nm_connection_get_setting_ip4_config (editor->connection) && !add_page (editor, ce_page_ip4_new, editor->connection, error)) goto out; if ( nm_connection_get_setting_ip6_config (editor->connection) && !add_page (editor, ce_page_ip6_new, editor->connection, error)) goto out; /* After all pages are created, then kick off secrets requests that any * the pages may need to make; if they don't need any secrets, then let * them finish initialization. The list might get modified during the loop * which is why copy the list here. */ copy = g_slist_copy (editor->initializing_pages); for (iter = copy; iter; iter = g_slist_next (iter)) { CEPage *page = CE_PAGE (iter->data); const char *setting_name = g_object_get_data (G_OBJECT (page), SECRETS_TAG); if (!setting_name) { /* page doesn't need any secrets */ ce_page_complete_init (page, NULL, NULL, NULL); } else if (!NM_IS_REMOTE_CONNECTION (editor->orig_connection)) { /* We want to get secrets using ->orig_connection, since that's the * remote connection which can actually respond to secrets requests. * ->connection is a plain NMConnection copy of ->orig_connection * which is what gets changed when users modify anything. But when * creating or importing, ->orig_connection will be an NMConnection * since the new connection hasn't been added to NetworkManager yet. * So basically, skip requesting secrets if the connection can't * handle a secrets request. */ ce_page_complete_init (page, setting_name, NULL, NULL); } else { /* Page wants secrets, get them */ get_secrets_for_page (editor, page, setting_name); } g_object_set_data (G_OBJECT (page), SECRETS_TAG, NULL); } g_slist_free (copy); /* set the UI */ recheck_initialization (editor); success = TRUE; out: return success; }