static gboolean std_ask_user (const char *vpn_name, const char *prompt, gboolean need_password, const char *existing_password, char **out_new_password, gboolean need_user_certpass, const char *existing_user_certpass, char **out_new_user_certpass, gboolean need_machine_certpass, const char *existing_machine_certpass, char **out_new_machine_certpass) { NMAVpnPasswordDialog *dialog; gboolean success = FALSE; g_return_val_if_fail (vpn_name != NULL, FALSE); g_return_val_if_fail (prompt != NULL, FALSE); g_return_val_if_fail (out_new_password != NULL, FALSE); g_return_val_if_fail (out_new_user_certpass != NULL, FALSE); g_return_val_if_fail (out_new_machine_certpass != NULL, FALSE); gtk_init (NULL, NULL); dialog = NMA_VPN_PASSWORD_DIALOG (nma_vpn_password_dialog_new (_("Authenticate VPN"), prompt, NULL)); /* pre-fill dialog with existing passwords */ nma_vpn_password_dialog_set_show_password (dialog, need_password); if (need_password) nma_vpn_password_dialog_set_password (dialog, existing_password); nma_vpn_password_dialog_set_show_password_secondary (dialog, need_user_certpass); if (need_user_certpass) { nma_vpn_password_dialog_set_password_secondary_label (dialog, _("_User Certificate password:"******"_Machine Certificate password:")); nma_vpn_password_dialog_set_password_ternary (dialog, existing_machine_certpass); } gtk_widget_show (GTK_WIDGET (dialog)); if (nma_vpn_password_dialog_run_and_block (dialog)) { if (need_password) *out_new_password = g_strdup (nma_vpn_password_dialog_get_password (dialog)); if (need_user_certpass) *out_new_user_certpass = g_strdup (nma_vpn_password_dialog_get_password_secondary (dialog)); if (need_machine_certpass) *out_new_machine_certpass = g_strdup (nma_vpn_password_dialog_get_password_ternary (dialog)); success = TRUE; } gtk_widget_destroy (GTK_WIDGET (dialog)); return success; }
/* Public NMAVpnPasswordDialog methods */ GtkWidget * nma_vpn_password_dialog_new (const char *title, const char *message, const char *password) { GtkWidget *dialog; NMAVpnPasswordDialogPrivate *priv; GtkLabel *message_label; GtkWidget *hbox; GtkWidget *vbox; GtkWidget *main_vbox; GtkWidget *dialog_icon; GtkBox *content, *action_area; dialog = gtk_widget_new (NMA_VPN_TYPE_PASSWORD_DIALOG, NULL); if (!dialog) return NULL; priv = NMA_VPN_PASSWORD_DIALOG_GET_PRIVATE (dialog); gtk_window_set_title (GTK_WINDOW (dialog), title); gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); gtk_dialog_add_buttons (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); content = GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))); action_area = GTK_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dialog))); /* Set up the dialog */ gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); gtk_box_set_spacing (content, 2); /* 2 * 5 + 2 = 12 */ gtk_container_set_border_width (GTK_CONTAINER (action_area), 5); gtk_box_set_spacing (action_area, 6); gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER); gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); g_signal_connect (dialog, "show", G_CALLBACK (dialog_show_callback), dialog); g_signal_connect (dialog, "close", G_CALLBACK (dialog_close_callback), dialog); /* The grid that holds the captions */ priv->grid_alignment = gtk_alignment_new (0.0, 0.0, 0.0, 0.0); priv->group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); priv->grid = gtk_grid_new (); gtk_grid_set_column_spacing (GTK_GRID (priv->grid), 12); gtk_grid_set_row_spacing (GTK_GRID (priv->grid), 6); gtk_container_add (GTK_CONTAINER (priv->grid_alignment), priv->grid); priv->password_entry = gtk_entry_new (); priv->password_entry_secondary = gtk_entry_new (); priv->password_entry_ternary = gtk_entry_new (); priv->show_passwords_checkbox = gtk_check_button_new_with_mnemonic (_("Sh_ow passwords")); /* We want to hold on to these during the grid rearrangement */ g_object_ref_sink (priv->password_entry); g_object_ref_sink (priv->password_entry_secondary); g_object_ref_sink (priv->password_entry_ternary); g_object_ref_sink (priv->show_passwords_checkbox); gtk_entry_set_visibility (GTK_ENTRY (priv->password_entry), FALSE); gtk_entry_set_visibility (GTK_ENTRY (priv->password_entry_secondary), FALSE); gtk_entry_set_visibility (GTK_ENTRY (priv->password_entry_ternary), FALSE); g_signal_connect_swapped (priv->password_entry, "activate", G_CALLBACK (gtk_window_activate_default), dialog); g_signal_connect_swapped (priv->password_entry_secondary, "activate", G_CALLBACK (gtk_window_activate_default), dialog); g_signal_connect_swapped (priv->password_entry_ternary, "activate", G_CALLBACK (gtk_window_activate_default), dialog); g_signal_connect (priv->show_passwords_checkbox, "toggled", G_CALLBACK (show_passwords_toggled_cb), dialog); add_grid_rows (NMA_VPN_PASSWORD_DIALOG (dialog)); /* Adds some eye-candy to the dialog */ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); gtk_container_set_border_width (GTK_CONTAINER (hbox), 5); dialog_icon = gtk_image_new_from_stock (GTK_STOCK_DIALOG_AUTHENTICATION, GTK_ICON_SIZE_DIALOG); gtk_misc_set_alignment (GTK_MISC (dialog_icon), 0.5, 0.0); gtk_box_pack_start (GTK_BOX (hbox), dialog_icon, FALSE, FALSE, 0); /* Fills the vbox */ main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 18); if (message) { message_label = GTK_LABEL (gtk_label_new (message)); gtk_label_set_justify (message_label, GTK_JUSTIFY_LEFT); gtk_label_set_line_wrap (message_label, TRUE); gtk_label_set_max_width_chars (message_label, 35); gtk_size_group_add_widget (priv->group, GTK_WIDGET (message_label)); gtk_box_pack_start (GTK_BOX (main_vbox), GTK_WIDGET (message_label), FALSE, FALSE, 0); gtk_size_group_add_widget (priv->group, priv->grid_alignment); } vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); gtk_box_pack_start (GTK_BOX (main_vbox), vbox, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), priv->grid_alignment, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox), main_vbox, FALSE, FALSE, 0); gtk_box_pack_start (content, hbox, FALSE, FALSE, 0); gtk_widget_show_all (GTK_WIDGET (content)); nma_vpn_password_dialog_set_password (NMA_VPN_PASSWORD_DIALOG (dialog), password); return GTK_WIDGET (dialog); }
static gboolean get_secrets (const char *vpn_uuid, const char *vpn_name, gboolean retry, gboolean allow_interaction, gboolean external_ui_mode, const char *in_pw, char **out_pw, NMSettingSecretFlags pw_flags) { NMAVpnPasswordDialog *dialog; char *prompt, *pw = NULL; const char *new_password = NULL; g_return_val_if_fail (vpn_uuid != NULL, FALSE); g_return_val_if_fail (vpn_name != NULL, FALSE); g_return_val_if_fail (out_pw != NULL, FALSE); g_return_val_if_fail (*out_pw == NULL, FALSE); /* Get the existing secret, if any */ if ( !(pw_flags & NM_SETTING_SECRET_FLAG_NOT_SAVED) && !(pw_flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED)) { if (in_pw) pw = g_strdup (in_pw); else pw = keyring_lookup_secret (vpn_uuid, NM_FORTISSLVPN_KEY_PASSWORD); } /* Don't ask if the passwords is unused */ if (pw_flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED) { g_free (pw); return TRUE; } /* Otherwise, we have no saved password, or the password flags indicated * that the password should never be saved. */ prompt = g_strdup_printf (_("You need to authenticate to access the Virtual Private Network “%s”."), vpn_name); if (external_ui_mode) { GKeyFile *keyfile; keyfile = g_key_file_new (); g_key_file_set_integer (keyfile, UI_KEYFILE_GROUP, "Version", 2); g_key_file_set_string (keyfile, UI_KEYFILE_GROUP, "Description", prompt); g_key_file_set_string (keyfile, UI_KEYFILE_GROUP, "Title", _("Authenticate VPN")); keyfile_add_entry_info (keyfile, NM_FORTISSLVPN_KEY_PASSWORD, pw ? pw : "", _("Password:"******"Authenticate VPN"), prompt, NULL); nma_vpn_password_dialog_set_show_password_secondary (dialog, FALSE); /* pre-fill dialog with the password */ if (pw && !(pw_flags & NM_SETTING_SECRET_FLAG_NOT_SAVED)) nma_vpn_password_dialog_set_password (dialog, pw); gtk_widget_show (GTK_WIDGET (dialog)); if (nma_vpn_password_dialog_run_and_block (dialog)) { new_password = nma_vpn_password_dialog_get_password (dialog); if (new_password) *out_pw = g_strdup (new_password); } gtk_widget_hide (GTK_WIDGET (dialog)); gtk_widget_destroy (GTK_WIDGET (dialog)); out: g_free (prompt); return TRUE; }