mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-19 05:40:23 +01:00
2008-12-05 Dan Williams <dcbw@redhat.com>
* auth-dialog/gnome-two-password-dialog.c auth-dialog/gnome-two-password-dialog.h - Simplify to only what the VPN plugin actually needs * auth-dialog/main.c - (find_connection_path): split out into separate function - (get_secrets): be more intelligent about requesting password when the password type cannot be found in the VPN details; use new VPN password dialog stuff - (get_connection_info): rename from get_password_types(); get connection name too - (main): don't require a connection name too; it's pointless * properties/nm-vpnc.c - (init_one_pw_combo): if the password was found, but the password type wasn't, default to saving the password in the keyring. Otherwise if both the type and the password couldn't be found, default to always asking for it. - (init_plugin_ui): get VPN passwords before setting up the type combos git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/branches/NETWORKMANAGER_0_7@4367 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
parent
ffdd6e2948
commit
cceead5567
5 changed files with 540 additions and 734 deletions
|
|
@ -1,3 +1,25 @@
|
|||
2008-12-05 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* auth-dialog/gnome-two-password-dialog.c
|
||||
auth-dialog/gnome-two-password-dialog.h
|
||||
- Simplify to only what the VPN plugin actually needs
|
||||
|
||||
* auth-dialog/main.c
|
||||
- (find_connection_path): split out into separate function
|
||||
- (get_secrets): be more intelligent about requesting password when
|
||||
the password type cannot be found in the VPN details; use new VPN
|
||||
password dialog stuff
|
||||
- (get_connection_info): rename from get_password_types(); get
|
||||
connection name too
|
||||
- (main): don't require a connection name too; it's pointless
|
||||
|
||||
* properties/nm-vpnc.c
|
||||
- (init_one_pw_combo): if the password was found, but the password type
|
||||
wasn't, default to saving the password in the keyring. Otherwise
|
||||
if both the type and the password couldn't be found, default to
|
||||
always asking for it.
|
||||
- (init_plugin_ui): get VPN passwords before setting up the type combos
|
||||
|
||||
2008-11-14 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* src/nm-vpnc-service.c
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@
|
|||
*/
|
||||
|
||||
#include <config.h>
|
||||
//#include "gnome-i18nP.h"
|
||||
#include "gnome-two-password-dialog.h"
|
||||
#include <gtk/gtkbox.h>
|
||||
#include <gtk/gtkcheckbutton.h>
|
||||
|
|
@ -38,20 +37,22 @@
|
|||
#include <gtk/gtkvbox.h>
|
||||
#include <gtk/gtkradiobutton.h>
|
||||
#include <gtk/gtkstock.h>
|
||||
#include <gtk/gtkcombobox.h>
|
||||
#include <gnome-keyring-memory.h>
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "src/nm-vpnc-service.h"
|
||||
|
||||
struct GnomeTwoPasswordDialogDetails
|
||||
{
|
||||
G_DEFINE_TYPE (VpnPasswordDialog, vpn_password_dialog, GTK_TYPE_DIALOG)
|
||||
|
||||
#define VPN_PASSWORD_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
|
||||
VPN_TYPE_PASSWORD_DIALOG, \
|
||||
VpnPasswordDialogPrivate))
|
||||
|
||||
typedef struct {
|
||||
/* Attributes */
|
||||
gboolean readonly_username;
|
||||
gboolean readonly_domain;
|
||||
|
||||
gboolean show_username;
|
||||
gboolean show_domain;
|
||||
gboolean show_password;
|
||||
gboolean show_password_secondary;
|
||||
|
||||
|
|
@ -60,131 +61,74 @@ struct GnomeTwoPasswordDialogDetails
|
|||
char *remember_label_text;
|
||||
|
||||
/* Internal widgetry and flags */
|
||||
GtkWidget *username_entry;
|
||||
GtkWidget *password_entry;
|
||||
GtkWidget *password_entry_secondary;
|
||||
GtkWidget *domain_entry;
|
||||
GtkWidget *show_passwords_checkbox;
|
||||
|
||||
GtkWidget *table_alignment;
|
||||
GtkWidget *table;
|
||||
GtkSizeGroup *group;
|
||||
|
||||
GtkWidget *remember_session_button;
|
||||
GtkWidget *remember_forever_button;
|
||||
|
||||
GtkWidget *radio_vbox;
|
||||
GtkWidget *connect_with_no_userpass_button;
|
||||
GtkWidget *connect_with_userpass_button;
|
||||
|
||||
gboolean anon_support_on;
|
||||
|
||||
char *secondary_password_label;
|
||||
};
|
||||
|
||||
/* Caption table rows indices */
|
||||
static const guint CAPTION_TABLE_USERNAME_ROW = 0;
|
||||
static const guint CAPTION_TABLE_PASSWORD_ROW = 1;
|
||||
|
||||
/* GnomeTwoPasswordDialogClass methods */
|
||||
static void gnome_two_password_dialog_class_init (GnomeTwoPasswordDialogClass *password_dialog_class);
|
||||
static void gnome_two_password_dialog_init (GnomeTwoPasswordDialog *password_dialog);
|
||||
|
||||
/* GObjectClass methods */
|
||||
static void gnome_two_password_dialog_finalize (GObject *object);
|
||||
} VpnPasswordDialogPrivate;
|
||||
|
||||
/* VpnPasswordDialogClass methods */
|
||||
static void vpn_password_dialog_class_init (VpnPasswordDialogClass *password_dialog_class);
|
||||
static void vpn_password_dialog_init (VpnPasswordDialog *password_dialog);
|
||||
|
||||
/* GtkDialog callbacks */
|
||||
static void dialog_show_callback (GtkWidget *widget,
|
||||
gpointer callback_data);
|
||||
static void dialog_close_callback (GtkWidget *widget,
|
||||
gpointer callback_data);
|
||||
|
||||
static gpointer parent_class;
|
||||
|
||||
GType
|
||||
gnome_two_password_dialog_get_type (void)
|
||||
{
|
||||
static GType type = 0;
|
||||
|
||||
if (!type) {
|
||||
static const GTypeInfo info = {
|
||||
sizeof (GnomeTwoPasswordDialogClass),
|
||||
NULL, NULL,
|
||||
(GClassInitFunc) gnome_two_password_dialog_class_init,
|
||||
NULL, NULL,
|
||||
sizeof (GnomeTwoPasswordDialog), 0,
|
||||
(GInstanceInitFunc) gnome_two_password_dialog_init,
|
||||
NULL
|
||||
};
|
||||
|
||||
type = g_type_register_static (gtk_dialog_get_type(),
|
||||
"GnomeTwoPasswordDialog",
|
||||
&info, 0);
|
||||
|
||||
parent_class = g_type_class_ref (gtk_dialog_get_type());
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
static void dialog_show_callback (GtkWidget *widget, gpointer callback_data);
|
||||
static void dialog_close_callback (GtkWidget *widget, gpointer callback_data);
|
||||
|
||||
static void
|
||||
gnome_two_password_dialog_class_init (GnomeTwoPasswordDialogClass * klass)
|
||||
finalize (GObject *object)
|
||||
{
|
||||
G_OBJECT_CLASS (klass)->finalize = gnome_two_password_dialog_finalize;
|
||||
}
|
||||
|
||||
static void
|
||||
gnome_two_password_dialog_init (GnomeTwoPasswordDialog *password_dialog)
|
||||
{
|
||||
password_dialog->details = g_new0 (GnomeTwoPasswordDialogDetails, 1);
|
||||
password_dialog->details->show_username = TRUE;
|
||||
password_dialog->details->show_password = TRUE;
|
||||
password_dialog->details->show_password_secondary = TRUE;
|
||||
password_dialog->details->anon_support_on = FALSE;
|
||||
|
||||
password_dialog->details->secondary_password_label = g_strdup ( _("_Secondary Password:") );
|
||||
}
|
||||
|
||||
/* GObjectClass methods */
|
||||
static void
|
||||
gnome_two_password_dialog_finalize (GObject *object)
|
||||
{
|
||||
GnomeTwoPasswordDialog *password_dialog;
|
||||
VpnPasswordDialogPrivate *priv = VPN_PASSWORD_DIALOG_GET_PRIVATE (object);
|
||||
|
||||
password_dialog = GNOME_TWO_PASSWORD_DIALOG (object);
|
||||
g_object_unref (priv->password_entry);
|
||||
g_object_unref (priv->password_entry_secondary);
|
||||
g_object_unref (priv->group);
|
||||
|
||||
g_object_unref (password_dialog->details->username_entry);
|
||||
g_object_unref (password_dialog->details->domain_entry);
|
||||
g_object_unref (password_dialog->details->password_entry);
|
||||
g_object_unref (password_dialog->details->password_entry_secondary);
|
||||
g_free (priv->remember_label_text);
|
||||
g_free (priv->secondary_password_label);
|
||||
|
||||
g_free (password_dialog->details->remember_label_text);
|
||||
g_free (password_dialog->details->secondary_password_label);
|
||||
g_free (password_dialog->details);
|
||||
G_OBJECT_CLASS (vpn_password_dialog_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
if (G_OBJECT_CLASS (parent_class)->finalize != NULL)
|
||||
(* G_OBJECT_CLASS (parent_class)->finalize) (object);
|
||||
static void
|
||||
vpn_password_dialog_class_init (VpnPasswordDialogClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
g_type_class_add_private (object_class, sizeof (VpnPasswordDialogPrivate));
|
||||
|
||||
object_class->finalize = finalize;
|
||||
}
|
||||
|
||||
static void
|
||||
vpn_password_dialog_init (VpnPasswordDialog *dialog)
|
||||
{
|
||||
VpnPasswordDialogPrivate *priv = VPN_PASSWORD_DIALOG_GET_PRIVATE (dialog);
|
||||
|
||||
priv->show_password = TRUE;
|
||||
priv->show_password_secondary = TRUE;
|
||||
priv->secondary_password_label = g_strdup ( _("_Secondary Password:") );
|
||||
}
|
||||
|
||||
/* GtkDialog callbacks */
|
||||
static void
|
||||
dialog_show_callback (GtkWidget *widget, gpointer callback_data)
|
||||
{
|
||||
GnomeTwoPasswordDialog *password_dialog;
|
||||
VpnPasswordDialog *dialog = VPN_PASSWORD_DIALOG (callback_data);
|
||||
VpnPasswordDialogPrivate *priv = VPN_PASSWORD_DIALOG_GET_PRIVATE (dialog);
|
||||
|
||||
password_dialog = GNOME_TWO_PASSWORD_DIALOG (callback_data);
|
||||
|
||||
if (GTK_WIDGET_VISIBLE (password_dialog->details->username_entry) &&
|
||||
!password_dialog->details->readonly_username) {
|
||||
gtk_widget_grab_focus (password_dialog->details->username_entry);
|
||||
} else if (GTK_WIDGET_VISIBLE (password_dialog->details->domain_entry) &&
|
||||
!password_dialog->details->readonly_domain) {
|
||||
gtk_widget_grab_focus (password_dialog->details->domain_entry);
|
||||
} else if (GTK_WIDGET_VISIBLE (password_dialog->details->password_entry)) {
|
||||
gtk_widget_grab_focus (password_dialog->details->password_entry);
|
||||
} else if (GTK_WIDGET_VISIBLE (password_dialog->details->password_entry_secondary)) {
|
||||
gtk_widget_grab_focus (password_dialog->details->password_entry_secondary);
|
||||
}
|
||||
if (GTK_WIDGET_VISIBLE (priv->password_entry))
|
||||
gtk_widget_grab_focus (priv->password_entry);
|
||||
else if (GTK_WIDGET_VISIBLE (priv->password_entry_secondary))
|
||||
gtk_widget_grab_focus (priv->password_entry_secondary);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -193,23 +137,6 @@ dialog_close_callback (GtkWidget *widget, gpointer callback_data)
|
|||
gtk_widget_hide (widget);
|
||||
}
|
||||
|
||||
static void
|
||||
userpass_radio_button_clicked (GtkWidget *widget, gpointer callback_data)
|
||||
{
|
||||
GnomeTwoPasswordDialog *password_dialog;
|
||||
|
||||
password_dialog = GNOME_TWO_PASSWORD_DIALOG (callback_data);
|
||||
|
||||
if (widget == password_dialog->details->connect_with_no_userpass_button) {
|
||||
gtk_widget_set_sensitive (
|
||||
password_dialog->details->table, FALSE);
|
||||
}
|
||||
else { /* the other button */
|
||||
gtk_widget_set_sensitive (
|
||||
password_dialog->details->table, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
add_row (GtkWidget *table, int row, const char *label_text, GtkWidget *entry)
|
||||
{
|
||||
|
|
@ -218,10 +145,8 @@ add_row (GtkWidget *table, int row, const char *label_text, GtkWidget *entry)
|
|||
label = gtk_label_new_with_mnemonic (label_text);
|
||||
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
|
||||
|
||||
gtk_table_attach_defaults (GTK_TABLE (table), label,
|
||||
0, 1, row, row + 1);
|
||||
gtk_table_attach_defaults (GTK_TABLE (table), entry,
|
||||
1, 2, row, row + 1);
|
||||
gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, row, row + 1);
|
||||
gtk_table_attach_defaults (GTK_TABLE (table), entry, 1, 2, row, row + 1);
|
||||
|
||||
gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
|
||||
}
|
||||
|
|
@ -233,86 +158,49 @@ remove_child (GtkWidget *child, GtkWidget *table)
|
|||
}
|
||||
|
||||
static void
|
||||
add_table_rows (GnomeTwoPasswordDialog *password_dialog)
|
||||
add_table_rows (VpnPasswordDialog *dialog)
|
||||
{
|
||||
VpnPasswordDialogPrivate *priv = VPN_PASSWORD_DIALOG_GET_PRIVATE (dialog);
|
||||
int row;
|
||||
GtkWidget *table;
|
||||
int offset;
|
||||
int offset = 0;
|
||||
|
||||
if (password_dialog->details->anon_support_on) {
|
||||
offset = 12;
|
||||
}
|
||||
else {
|
||||
offset = 0;
|
||||
}
|
||||
gtk_alignment_set_padding (GTK_ALIGNMENT (priv->table_alignment), 0, 0, offset, 0);
|
||||
|
||||
gtk_alignment_set_padding (GTK_ALIGNMENT (password_dialog->details->table_alignment),
|
||||
0, 0, offset, 0);
|
||||
|
||||
table = password_dialog->details->table;
|
||||
/* This will not kill the entries, since they are ref:ed */
|
||||
gtk_container_foreach (GTK_CONTAINER (table),
|
||||
(GtkCallback)remove_child, table);
|
||||
gtk_container_foreach (GTK_CONTAINER (priv->table), (GtkCallback) remove_child, priv->table);
|
||||
|
||||
row = 0;
|
||||
if (password_dialog->details->show_username)
|
||||
add_row (table, row++, _("_Username:"), password_dialog->details->username_entry);
|
||||
if (password_dialog->details->show_domain)
|
||||
add_row (table, row++, _("_Domain:"), password_dialog->details->domain_entry);
|
||||
if (password_dialog->details->show_password)
|
||||
add_row (table, row++, _("_Password:"), password_dialog->details->password_entry);
|
||||
if (password_dialog->details->show_password_secondary)
|
||||
add_row (table, row++, password_dialog->details->secondary_password_label,
|
||||
password_dialog->details->password_entry_secondary);
|
||||
if (priv->show_password)
|
||||
add_row (priv->table, row++, _("_Password:"), priv->password_entry);
|
||||
if (priv->show_password_secondary)
|
||||
add_row (priv->table, row++, priv->secondary_password_label, priv->password_entry_secondary);
|
||||
|
||||
gtk_widget_show_all (table);
|
||||
gtk_table_attach_defaults (GTK_TABLE (priv->table), priv->show_passwords_checkbox, 1, 2, row, row + 1);
|
||||
|
||||
gtk_widget_show_all (priv->table);
|
||||
}
|
||||
|
||||
static void
|
||||
username_entry_activate (GtkWidget *widget, GtkWidget *dialog)
|
||||
show_passwords_toggled_cb (GtkWidget *widget, gpointer user_data)
|
||||
{
|
||||
GnomeTwoPasswordDialog *password_dialog;
|
||||
VpnPasswordDialog *dialog = VPN_PASSWORD_DIALOG (user_data);
|
||||
VpnPasswordDialogPrivate *priv = VPN_PASSWORD_DIALOG_GET_PRIVATE (dialog);
|
||||
gboolean visible;
|
||||
|
||||
password_dialog = GNOME_TWO_PASSWORD_DIALOG (dialog);
|
||||
|
||||
if (GTK_WIDGET_VISIBLE (password_dialog->details->domain_entry) &&
|
||||
GTK_WIDGET_SENSITIVE (password_dialog->details->domain_entry))
|
||||
gtk_widget_grab_focus (password_dialog->details->domain_entry);
|
||||
else if (GTK_WIDGET_VISIBLE (password_dialog->details->password_entry) &&
|
||||
GTK_WIDGET_SENSITIVE (password_dialog->details->password_entry))
|
||||
gtk_widget_grab_focus (password_dialog->details->password_entry);
|
||||
else if (GTK_WIDGET_VISIBLE (password_dialog->details->password_entry_secondary) &&
|
||||
GTK_WIDGET_SENSITIVE (password_dialog->details->password_entry_secondary))
|
||||
gtk_widget_grab_focus (password_dialog->details->password_entry_secondary);
|
||||
visible = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
|
||||
|
||||
gtk_entry_set_visibility (GTK_ENTRY (priv->password_entry), visible);
|
||||
gtk_entry_set_visibility (GTK_ENTRY (priv->password_entry_secondary), visible);
|
||||
}
|
||||
|
||||
static void
|
||||
domain_entry_activate (GtkWidget *widget, GtkWidget *dialog)
|
||||
{
|
||||
GnomeTwoPasswordDialog *password_dialog;
|
||||
|
||||
password_dialog = GNOME_TWO_PASSWORD_DIALOG (dialog);
|
||||
|
||||
if (GTK_WIDGET_VISIBLE (password_dialog->details->password_entry) &&
|
||||
GTK_WIDGET_SENSITIVE (password_dialog->details->password_entry))
|
||||
gtk_widget_grab_focus (password_dialog->details->password_entry);
|
||||
else if (GTK_WIDGET_VISIBLE (password_dialog->details->password_entry_secondary) &&
|
||||
GTK_WIDGET_SENSITIVE (password_dialog->details->password_entry_secondary))
|
||||
gtk_widget_grab_focus (password_dialog->details->password_entry_secondary);
|
||||
}
|
||||
|
||||
|
||||
/* Public GnomeTwoPasswordDialog methods */
|
||||
/* Public VpnPasswordDialog methods */
|
||||
GtkWidget *
|
||||
gnome_two_password_dialog_new (const char *dialog_title,
|
||||
const char *message,
|
||||
const char *username,
|
||||
const char *password,
|
||||
gboolean readonly_username)
|
||||
vpn_password_dialog_new (const char *title,
|
||||
const char *message,
|
||||
const char *password)
|
||||
{
|
||||
GnomeTwoPasswordDialog *password_dialog;
|
||||
GtkDialog *dialog;
|
||||
GtkWidget *table;
|
||||
GtkWidget *dialog;
|
||||
VpnPasswordDialogPrivate *priv;
|
||||
GtkLabel *message_label;
|
||||
GtkWidget *hbox;
|
||||
GtkWidget *vbox;
|
||||
|
|
@ -320,110 +208,83 @@ gnome_two_password_dialog_new (const char *dialog_title,
|
|||
GtkWidget *dialog_icon;
|
||||
GSList *group;
|
||||
|
||||
password_dialog = GNOME_TWO_PASSWORD_DIALOG (gtk_widget_new (gnome_two_password_dialog_get_type (), NULL));
|
||||
dialog = GTK_DIALOG (password_dialog);
|
||||
dialog = gtk_widget_new (VPN_TYPE_PASSWORD_DIALOG, NULL);
|
||||
if (!dialog)
|
||||
return NULL;
|
||||
priv = VPN_PASSWORD_DIALOG_GET_PRIVATE (dialog);
|
||||
|
||||
gtk_window_set_title (GTK_WINDOW (password_dialog), dialog_title);
|
||||
gtk_window_set_title (GTK_WINDOW (dialog), title);
|
||||
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
|
||||
|
||||
gtk_dialog_add_buttons (dialog,
|
||||
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
||||
GTK_STOCK_OK, GTK_RESPONSE_OK,
|
||||
NULL);
|
||||
gtk_dialog_set_default_response (GTK_DIALOG (password_dialog), GTK_RESPONSE_OK);
|
||||
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);
|
||||
|
||||
/* Setup the dialog */
|
||||
gtk_dialog_set_has_separator (dialog, FALSE);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
|
||||
gtk_box_set_spacing (GTK_BOX (dialog->vbox), 2); /* 2 * 5 + 2 = 12 */
|
||||
gtk_container_set_border_width (GTK_CONTAINER (dialog->action_area), 5);
|
||||
gtk_box_set_spacing (GTK_BOX (dialog->action_area), 6);
|
||||
gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
|
||||
gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 2); /* 2 * 5 + 2 = 12 */
|
||||
gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area), 5);
|
||||
gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->action_area), 6);
|
||||
|
||||
gtk_window_set_position (GTK_WINDOW (password_dialog), GTK_WIN_POS_CENTER);
|
||||
gtk_window_set_modal (GTK_WINDOW (password_dialog), TRUE);
|
||||
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
|
||||
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
||||
|
||||
g_signal_connect (password_dialog, "show",
|
||||
G_CALLBACK (dialog_show_callback), password_dialog);
|
||||
g_signal_connect (password_dialog, "close",
|
||||
G_CALLBACK (dialog_close_callback), password_dialog);
|
||||
|
||||
/* the radio buttons for anonymous login */
|
||||
password_dialog->details->connect_with_no_userpass_button =
|
||||
gtk_radio_button_new_with_mnemonic (NULL, _("Connect _anonymously"));
|
||||
group = gtk_radio_button_get_group (
|
||||
GTK_RADIO_BUTTON (password_dialog->details->connect_with_no_userpass_button));
|
||||
password_dialog->details->connect_with_userpass_button =
|
||||
gtk_radio_button_new_with_mnemonic (
|
||||
group, _("Connect as _user:"));
|
||||
|
||||
if (username != NULL && *username != 0) {
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (password_dialog->details->connect_with_userpass_button), TRUE);
|
||||
} else {
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (password_dialog->details->connect_with_no_userpass_button), TRUE);
|
||||
}
|
||||
|
||||
password_dialog->details->radio_vbox = gtk_vbox_new (FALSE, 6);
|
||||
gtk_box_pack_start (GTK_BOX (password_dialog->details->radio_vbox),
|
||||
password_dialog->details->connect_with_no_userpass_button,
|
||||
FALSE, FALSE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (password_dialog->details->radio_vbox),
|
||||
password_dialog->details->connect_with_userpass_button,
|
||||
FALSE, FALSE, 0);
|
||||
g_signal_connect (password_dialog->details->connect_with_no_userpass_button, "clicked",
|
||||
G_CALLBACK (userpass_radio_button_clicked), password_dialog);
|
||||
g_signal_connect (password_dialog->details->connect_with_userpass_button, "clicked",
|
||||
G_CALLBACK (userpass_radio_button_clicked), password_dialog);
|
||||
g_signal_connect (dialog, "show",
|
||||
G_CALLBACK (dialog_show_callback),
|
||||
dialog);
|
||||
g_signal_connect (dialog, "close",
|
||||
G_CALLBACK (dialog_close_callback),
|
||||
dialog);
|
||||
|
||||
/* The table that holds the captions */
|
||||
password_dialog->details->table_alignment = gtk_alignment_new (0.0, 0.0, 0.0, 0.0);
|
||||
priv->table_alignment = gtk_alignment_new (0.0, 0.0, 0.0, 0.0);
|
||||
|
||||
password_dialog->details->table = table = gtk_table_new (3, 2, FALSE);
|
||||
gtk_table_set_col_spacings (GTK_TABLE (table), 12);
|
||||
gtk_table_set_row_spacings (GTK_TABLE (table), 6);
|
||||
gtk_container_add (GTK_CONTAINER (password_dialog->details->table_alignment), table);
|
||||
priv->group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
|
||||
|
||||
password_dialog->details->username_entry = gtk_entry_new ();
|
||||
password_dialog->details->domain_entry = gtk_entry_new ();
|
||||
password_dialog->details->password_entry = gtk_entry_new ();
|
||||
password_dialog->details->password_entry_secondary = gtk_entry_new ();
|
||||
priv->table = gtk_table_new (4, 2, FALSE);
|
||||
gtk_table_set_col_spacings (GTK_TABLE (priv->table), 12);
|
||||
gtk_table_set_row_spacings (GTK_TABLE (priv->table), 6);
|
||||
gtk_container_add (GTK_CONTAINER (priv->table_alignment), priv->table);
|
||||
|
||||
priv->password_entry = gtk_entry_new ();
|
||||
priv->password_entry_secondary = 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 table rearrangement */
|
||||
#if GLIB_CHECK_VERSION (2, 10, 0)
|
||||
g_object_ref_sink (password_dialog->details->username_entry);
|
||||
g_object_ref_sink (password_dialog->details->domain_entry);
|
||||
g_object_ref_sink (password_dialog->details->password_entry);
|
||||
g_object_ref_sink (password_dialog->details->password_entry_secondary);
|
||||
g_object_ref_sink (priv->password_entry);
|
||||
g_object_ref_sink (priv->password_entry_secondary);
|
||||
g_object_ref_sink (priv->show_passwords_checkbox);
|
||||
#else
|
||||
g_object_ref (password_dialog->details->username_entry);
|
||||
gtk_object_sink (GTK_OBJECT (password_dialog->details->username_entry));
|
||||
g_object_ref (password_dialog->details->domain_entry);
|
||||
gtk_object_sink (GTK_OBJECT (password_dialog->details->domain_entry));
|
||||
g_object_ref (password_dialog->details->password_entry);
|
||||
gtk_object_sink (GTK_OBJECT (password_dialog->details->password_entry));
|
||||
g_object_ref (password_dialog->details->password_entry_secondary);
|
||||
gtk_object_sink (GTK_OBJECT (password_dialog->details->password_entry_secondary));
|
||||
g_object_ref (priv->password_entry);
|
||||
gtk_object_sink (GTK_OBJECT (priv->password_entry));
|
||||
|
||||
g_object_ref (priv->password_entry_secondary);
|
||||
gtk_object_sink (GTK_OBJECT (priv->password_entry_secondary));
|
||||
|
||||
g_object_ref (priv->show_passwords_checkbox);
|
||||
gtk_object_sink (GTK_OBJECT (priv->show_passwords_checkbox));
|
||||
#endif
|
||||
|
||||
gtk_entry_set_visibility (GTK_ENTRY (password_dialog->details->password_entry), FALSE);
|
||||
gtk_entry_set_visibility (GTK_ENTRY (password_dialog->details->password_entry_secondary), FALSE);
|
||||
gtk_entry_set_visibility (GTK_ENTRY (priv->password_entry), FALSE);
|
||||
gtk_entry_set_visibility (GTK_ENTRY (priv->password_entry_secondary), FALSE);
|
||||
|
||||
g_signal_connect (password_dialog->details->username_entry,
|
||||
"activate",
|
||||
G_CALLBACK (username_entry_activate),
|
||||
password_dialog);
|
||||
g_signal_connect (password_dialog->details->domain_entry,
|
||||
"activate",
|
||||
G_CALLBACK (domain_entry_activate),
|
||||
password_dialog);
|
||||
g_signal_connect_swapped (password_dialog->details->password_entry,
|
||||
"activate",
|
||||
G_CALLBACK (gtk_window_activate_default),
|
||||
password_dialog);
|
||||
g_signal_connect_swapped (password_dialog->details->password_entry_secondary,
|
||||
"activate",
|
||||
G_CALLBACK (gtk_window_activate_default),
|
||||
password_dialog);
|
||||
add_table_rows (password_dialog);
|
||||
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 (priv->show_passwords_checkbox, "toggled",
|
||||
G_CALLBACK (show_passwords_toggled_cb),
|
||||
dialog);
|
||||
|
||||
add_table_rows (VPN_PASSWORD_DIALOG (dialog));
|
||||
|
||||
/* Adds some eye-candy to the dialog */
|
||||
hbox = gtk_hbox_new (FALSE, 12);
|
||||
|
|
@ -439,326 +300,224 @@ gnome_two_password_dialog_new (const char *dialog_title,
|
|||
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_box_pack_start (GTK_BOX (main_vbox), GTK_WIDGET (message_label),
|
||||
FALSE, FALSE, 0);
|
||||
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->table_alignment);
|
||||
}
|
||||
|
||||
vbox = gtk_vbox_new (FALSE, 6);
|
||||
gtk_box_pack_start (GTK_BOX (main_vbox), vbox, FALSE, FALSE, 0);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (vbox), password_dialog->details->radio_vbox,
|
||||
FALSE, FALSE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), password_dialog->details->table_alignment,
|
||||
FALSE, FALSE, 0);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (vbox), priv->table_alignment, FALSE, FALSE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), main_vbox, FALSE, FALSE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, FALSE, FALSE, 0);
|
||||
gtk_widget_show_all (GTK_DIALOG (dialog)->vbox);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (password_dialog)->vbox),
|
||||
hbox,
|
||||
TRUE, /* expand */
|
||||
TRUE, /* fill */
|
||||
0); /* padding */
|
||||
priv->remember_session_button = gtk_check_button_new_with_mnemonic (_("_Remember passwords for this session"));
|
||||
priv->remember_forever_button = gtk_check_button_new_with_mnemonic (_("_Save passwords in keyring"));
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (vbox), priv->remember_session_button, FALSE, FALSE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), priv->remember_forever_button, FALSE, FALSE, 0);
|
||||
|
||||
vpn_password_dialog_set_password (VPN_PASSWORD_DIALOG (dialog), password);
|
||||
|
||||
gtk_widget_show_all (GTK_DIALOG (password_dialog)->vbox);
|
||||
|
||||
password_dialog->details->remember_session_button =
|
||||
gtk_check_button_new_with_mnemonic (_("_Remember passwords for this session"));
|
||||
password_dialog->details->remember_forever_button =
|
||||
gtk_check_button_new_with_mnemonic (_("_Save passwords in keyring"));
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (vbox), password_dialog->details->remember_session_button,
|
||||
FALSE, FALSE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), password_dialog->details->remember_forever_button,
|
||||
FALSE, FALSE, 0);
|
||||
|
||||
gnome_two_password_dialog_set_username (password_dialog, username);
|
||||
gnome_two_password_dialog_set_password (password_dialog, password);
|
||||
gnome_two_password_dialog_set_readonly_domain (password_dialog, readonly_username);
|
||||
|
||||
return GTK_WIDGET (password_dialog);
|
||||
return GTK_WIDGET (dialog);
|
||||
}
|
||||
|
||||
gboolean
|
||||
gnome_two_password_dialog_run_and_block (GnomeTwoPasswordDialog *password_dialog)
|
||||
vpn_password_dialog_run_and_block (VpnPasswordDialog *dialog)
|
||||
{
|
||||
gint button_clicked;
|
||||
|
||||
g_return_val_if_fail (password_dialog != NULL, FALSE);
|
||||
g_return_val_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog), FALSE);
|
||||
g_return_val_if_fail (dialog != NULL, FALSE);
|
||||
g_return_val_if_fail (VPN_IS_PASSWORD_DIALOG (dialog), FALSE);
|
||||
|
||||
button_clicked = gtk_dialog_run (GTK_DIALOG (password_dialog));
|
||||
gtk_widget_hide (GTK_WIDGET (password_dialog));
|
||||
button_clicked = gtk_dialog_run (GTK_DIALOG (dialog));
|
||||
gtk_widget_hide (GTK_WIDGET (dialog));
|
||||
|
||||
return button_clicked == GTK_RESPONSE_OK;
|
||||
}
|
||||
|
||||
void
|
||||
gnome_two_password_dialog_set_username (GnomeTwoPasswordDialog *password_dialog,
|
||||
const char *username)
|
||||
vpn_password_dialog_set_password (VpnPasswordDialog *dialog,
|
||||
const char *password)
|
||||
{
|
||||
g_return_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog));
|
||||
g_return_if_fail (password_dialog->details->username_entry != NULL);
|
||||
VpnPasswordDialogPrivate *priv;
|
||||
|
||||
gtk_entry_set_text (GTK_ENTRY (password_dialog->details->username_entry),
|
||||
username?username:"");
|
||||
g_return_if_fail (VPN_IS_PASSWORD_DIALOG (dialog));
|
||||
|
||||
priv = VPN_PASSWORD_DIALOG_GET_PRIVATE (dialog);
|
||||
gtk_entry_set_text (GTK_ENTRY (priv->password_entry), password ? password : "");
|
||||
}
|
||||
|
||||
void
|
||||
gnome_two_password_dialog_set_password (GnomeTwoPasswordDialog *password_dialog,
|
||||
const char *password)
|
||||
vpn_password_dialog_set_password_secondary (VpnPasswordDialog *dialog,
|
||||
const char *password_secondary)
|
||||
{
|
||||
g_return_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog));
|
||||
VpnPasswordDialogPrivate *priv;
|
||||
|
||||
gtk_entry_set_text (GTK_ENTRY (password_dialog->details->password_entry),
|
||||
password ? password : "");
|
||||
g_return_if_fail (VPN_IS_PASSWORD_DIALOG (dialog));
|
||||
|
||||
priv = VPN_PASSWORD_DIALOG_GET_PRIVATE (dialog);
|
||||
gtk_entry_set_text (GTK_ENTRY (priv->password_entry_secondary),
|
||||
password_secondary ? password_secondary : "");
|
||||
}
|
||||
|
||||
void
|
||||
gnome_two_password_dialog_set_password_secondary (GnomeTwoPasswordDialog *password_dialog,
|
||||
const char *password_secondary)
|
||||
vpn_password_dialog_set_show_password (VpnPasswordDialog *dialog, gboolean show)
|
||||
{
|
||||
g_return_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog));
|
||||
VpnPasswordDialogPrivate *priv;
|
||||
|
||||
gtk_entry_set_text (GTK_ENTRY (password_dialog->details->password_entry_secondary),
|
||||
password_secondary ? password_secondary : "");
|
||||
}
|
||||
g_return_if_fail (dialog != NULL);
|
||||
g_return_if_fail (VPN_IS_PASSWORD_DIALOG (dialog));
|
||||
|
||||
void
|
||||
gnome_two_password_dialog_set_domain (GnomeTwoPasswordDialog *password_dialog,
|
||||
const char *domain)
|
||||
{
|
||||
g_return_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog));
|
||||
g_return_if_fail (password_dialog->details->domain_entry != NULL);
|
||||
|
||||
gtk_entry_set_text (GTK_ENTRY (password_dialog->details->domain_entry),
|
||||
domain ? domain : "");
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
gnome_two_password_dialog_set_show_username (GnomeTwoPasswordDialog *password_dialog,
|
||||
gboolean show)
|
||||
{
|
||||
g_return_if_fail (password_dialog != NULL);
|
||||
g_return_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog));
|
||||
priv = VPN_PASSWORD_DIALOG_GET_PRIVATE (dialog);
|
||||
|
||||
show = !!show;
|
||||
if (password_dialog->details->show_username != show) {
|
||||
password_dialog->details->show_username = show;
|
||||
add_table_rows (password_dialog);
|
||||
if (priv->show_password != show) {
|
||||
priv->show_password = show;
|
||||
add_table_rows (dialog);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gnome_two_password_dialog_set_show_domain (GnomeTwoPasswordDialog *password_dialog,
|
||||
gboolean show)
|
||||
vpn_password_dialog_set_show_password_secondary (VpnPasswordDialog *dialog,
|
||||
gboolean show)
|
||||
{
|
||||
g_return_if_fail (password_dialog != NULL);
|
||||
g_return_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog));
|
||||
VpnPasswordDialogPrivate *priv;
|
||||
|
||||
g_return_if_fail (dialog != NULL);
|
||||
g_return_if_fail (VPN_IS_PASSWORD_DIALOG (dialog));
|
||||
|
||||
priv = VPN_PASSWORD_DIALOG_GET_PRIVATE (dialog);
|
||||
|
||||
show = !!show;
|
||||
if (password_dialog->details->show_domain != show) {
|
||||
password_dialog->details->show_domain = show;
|
||||
add_table_rows (password_dialog);
|
||||
if (priv->show_password_secondary != show) {
|
||||
priv->show_password_secondary = show;
|
||||
add_table_rows (dialog);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gnome_two_password_dialog_set_show_password (GnomeTwoPasswordDialog *password_dialog,
|
||||
gboolean show)
|
||||
vpn_password_dialog_focus_password (VpnPasswordDialog *dialog)
|
||||
{
|
||||
g_return_if_fail (password_dialog != NULL);
|
||||
g_return_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog));
|
||||
VpnPasswordDialogPrivate *priv;
|
||||
|
||||
show = !!show;
|
||||
if (password_dialog->details->show_password != show) {
|
||||
password_dialog->details->show_password = show;
|
||||
add_table_rows (password_dialog);
|
||||
}
|
||||
g_return_if_fail (dialog != NULL);
|
||||
g_return_if_fail (VPN_IS_PASSWORD_DIALOG (dialog));
|
||||
|
||||
priv = VPN_PASSWORD_DIALOG_GET_PRIVATE (dialog);
|
||||
if (priv->show_password)
|
||||
gtk_widget_grab_focus (priv->password_entry);
|
||||
}
|
||||
|
||||
void
|
||||
gnome_two_password_dialog_set_show_password_secondary (GnomeTwoPasswordDialog *password_dialog,
|
||||
gboolean show)
|
||||
vpn_password_dialog_focus_password_secondary (VpnPasswordDialog *dialog)
|
||||
{
|
||||
g_return_if_fail (password_dialog != NULL);
|
||||
g_return_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog));
|
||||
VpnPasswordDialogPrivate *priv;
|
||||
|
||||
show = !!show;
|
||||
if (password_dialog->details->show_password_secondary != show) {
|
||||
password_dialog->details->show_password_secondary = show;
|
||||
add_table_rows (password_dialog);
|
||||
}
|
||||
g_return_if_fail (dialog != NULL);
|
||||
g_return_if_fail (VPN_IS_PASSWORD_DIALOG (dialog));
|
||||
|
||||
priv = VPN_PASSWORD_DIALOG_GET_PRIVATE (dialog);
|
||||
if (priv->show_password_secondary)
|
||||
gtk_widget_grab_focus (priv->password_entry_secondary);
|
||||
}
|
||||
|
||||
const char *
|
||||
vpn_password_dialog_get_password (VpnPasswordDialog *dialog)
|
||||
{
|
||||
VpnPasswordDialogPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (VPN_IS_PASSWORD_DIALOG (dialog), NULL);
|
||||
|
||||
priv = VPN_PASSWORD_DIALOG_GET_PRIVATE (dialog);
|
||||
return gtk_entry_get_text (GTK_ENTRY (priv->password_entry));
|
||||
}
|
||||
|
||||
const char *
|
||||
vpn_password_dialog_get_password_secondary (VpnPasswordDialog *dialog)
|
||||
{
|
||||
VpnPasswordDialogPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (VPN_IS_PASSWORD_DIALOG (dialog), NULL);
|
||||
|
||||
priv = VPN_PASSWORD_DIALOG_GET_PRIVATE (dialog);
|
||||
return gtk_entry_get_text (GTK_ENTRY (priv->password_entry_secondary));
|
||||
}
|
||||
|
||||
void
|
||||
gnome_two_password_dialog_focus_password (GnomeTwoPasswordDialog *password_dialog)
|
||||
vpn_password_dialog_set_show_remember (VpnPasswordDialog *dialog,
|
||||
gboolean show_remember)
|
||||
{
|
||||
g_return_if_fail (password_dialog != NULL);
|
||||
g_return_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog));
|
||||
VpnPasswordDialogPrivate *priv;
|
||||
|
||||
if (password_dialog->details->show_password)
|
||||
gtk_widget_grab_focus (password_dialog->details->password_entry);
|
||||
}
|
||||
g_return_if_fail (VPN_IS_PASSWORD_DIALOG (dialog));
|
||||
|
||||
void
|
||||
gnome_two_password_dialog_focus_password_secondary (GnomeTwoPasswordDialog *password_dialog)
|
||||
{
|
||||
g_return_if_fail (password_dialog != NULL);
|
||||
g_return_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog));
|
||||
|
||||
if (password_dialog->details->show_password_secondary)
|
||||
gtk_widget_grab_focus (password_dialog->details->password_entry_secondary);
|
||||
}
|
||||
|
||||
void
|
||||
gnome_two_password_dialog_set_readonly_username (GnomeTwoPasswordDialog *password_dialog,
|
||||
gboolean readonly)
|
||||
{
|
||||
g_return_if_fail (password_dialog != NULL);
|
||||
g_return_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog));
|
||||
|
||||
password_dialog->details->readonly_username = readonly;
|
||||
|
||||
gtk_widget_set_sensitive (password_dialog->details->username_entry,
|
||||
!readonly);
|
||||
}
|
||||
|
||||
void
|
||||
gnome_two_password_dialog_set_readonly_domain (GnomeTwoPasswordDialog *password_dialog,
|
||||
gboolean readonly)
|
||||
{
|
||||
g_return_if_fail (password_dialog != NULL);
|
||||
g_return_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog));
|
||||
|
||||
password_dialog->details->readonly_domain = readonly;
|
||||
|
||||
gtk_widget_set_sensitive (password_dialog->details->domain_entry,
|
||||
!readonly);
|
||||
}
|
||||
|
||||
char *
|
||||
gnome_two_password_dialog_get_username (GnomeTwoPasswordDialog *password_dialog)
|
||||
{
|
||||
g_return_val_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog), NULL);
|
||||
|
||||
return g_strdup (gtk_entry_get_text (GTK_ENTRY (password_dialog->details->username_entry)));
|
||||
}
|
||||
|
||||
char *
|
||||
gnome_two_password_dialog_get_domain (GnomeTwoPasswordDialog *password_dialog)
|
||||
{
|
||||
g_return_val_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog), NULL);
|
||||
|
||||
return g_strdup (gtk_entry_get_text (GTK_ENTRY (password_dialog->details->domain_entry)));
|
||||
}
|
||||
|
||||
char *
|
||||
gnome_two_password_dialog_get_password (GnomeTwoPasswordDialog *password_dialog)
|
||||
{
|
||||
g_return_val_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog), NULL);
|
||||
|
||||
return gnome_keyring_memory_strdup (gtk_entry_get_text (GTK_ENTRY (password_dialog->details->password_entry)));
|
||||
}
|
||||
|
||||
char *
|
||||
gnome_two_password_dialog_get_password_secondary (GnomeTwoPasswordDialog *password_dialog)
|
||||
{
|
||||
g_return_val_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog), NULL);
|
||||
|
||||
return gnome_keyring_memory_strdup (gtk_entry_get_text (GTK_ENTRY (password_dialog->details->password_entry_secondary)));
|
||||
}
|
||||
|
||||
void
|
||||
gnome_two_password_dialog_set_show_userpass_buttons (GnomeTwoPasswordDialog *password_dialog,
|
||||
gboolean show_userpass_buttons)
|
||||
{
|
||||
if (show_userpass_buttons) {
|
||||
password_dialog->details->anon_support_on = TRUE;
|
||||
gtk_widget_show (password_dialog->details->radio_vbox);
|
||||
if (gtk_toggle_button_get_active (
|
||||
GTK_TOGGLE_BUTTON (password_dialog->details->connect_with_no_userpass_button))) {
|
||||
gtk_widget_set_sensitive (password_dialog->details->table, FALSE);
|
||||
}
|
||||
else {
|
||||
gtk_widget_set_sensitive (password_dialog->details->table, TRUE);
|
||||
}
|
||||
} else {
|
||||
password_dialog->details->anon_support_on = FALSE;
|
||||
gtk_widget_hide (password_dialog->details->radio_vbox);
|
||||
gtk_widget_set_sensitive (password_dialog->details->table, TRUE);
|
||||
}
|
||||
|
||||
add_table_rows (password_dialog);
|
||||
}
|
||||
|
||||
gboolean
|
||||
gnome_two_password_dialog_anon_selected (GnomeTwoPasswordDialog *password_dialog)
|
||||
{
|
||||
return password_dialog->details->anon_support_on &&
|
||||
gtk_toggle_button_get_active (
|
||||
GTK_TOGGLE_BUTTON (
|
||||
password_dialog->details->connect_with_no_userpass_button));
|
||||
}
|
||||
|
||||
void
|
||||
gnome_two_password_dialog_set_show_remember (GnomeTwoPasswordDialog *password_dialog,
|
||||
gboolean show_remember)
|
||||
{
|
||||
priv = VPN_PASSWORD_DIALOG_GET_PRIVATE (dialog);
|
||||
if (show_remember) {
|
||||
gtk_widget_show (password_dialog->details->remember_session_button);
|
||||
gtk_widget_show (password_dialog->details->remember_forever_button);
|
||||
gtk_widget_show (priv->remember_session_button);
|
||||
gtk_widget_show (priv->remember_forever_button);
|
||||
} else {
|
||||
gtk_widget_hide (password_dialog->details->remember_session_button);
|
||||
gtk_widget_hide (password_dialog->details->remember_forever_button);
|
||||
gtk_widget_hide (priv->remember_session_button);
|
||||
gtk_widget_hide (priv->remember_forever_button);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gnome_two_password_dialog_set_remember (GnomeTwoPasswordDialog *password_dialog,
|
||||
GnomeTwoPasswordDialogRemember remember)
|
||||
vpn_password_dialog_set_remember (VpnPasswordDialog *dialog,
|
||||
VpnPasswordRemember remember)
|
||||
{
|
||||
gboolean session, forever;
|
||||
VpnPasswordDialogPrivate *priv;
|
||||
gboolean session = FALSE, forever = FALSE;
|
||||
|
||||
session = FALSE;
|
||||
forever = FALSE;
|
||||
if (remember == GNOME_TWO_PASSWORD_DIALOG_REMEMBER_SESSION) {
|
||||
g_return_if_fail (VPN_IS_PASSWORD_DIALOG (dialog));
|
||||
|
||||
priv = VPN_PASSWORD_DIALOG_GET_PRIVATE (dialog);
|
||||
|
||||
if (remember == VPN_PASSWORD_REMEMBER_SESSION)
|
||||
session = TRUE;
|
||||
} else if (remember == GNOME_TWO_PASSWORD_DIALOG_REMEMBER_FOREVER){
|
||||
else if (remember == VPN_PASSWORD_REMEMBER_FOREVER)
|
||||
forever = TRUE;
|
||||
}
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (password_dialog->details->remember_session_button),
|
||||
session);
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (password_dialog->details->remember_forever_button),
|
||||
forever);
|
||||
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->remember_session_button), session);
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->remember_forever_button), forever);
|
||||
}
|
||||
|
||||
GnomeTwoPasswordDialogRemember
|
||||
gnome_two_password_dialog_get_remember (GnomeTwoPasswordDialog *password_dialog)
|
||||
VpnPasswordRemember
|
||||
vpn_password_dialog_get_remember (VpnPasswordDialog *dialog)
|
||||
{
|
||||
VpnPasswordDialogPrivate *priv;
|
||||
gboolean session, forever;
|
||||
|
||||
session = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (password_dialog->details->remember_session_button));
|
||||
forever = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (password_dialog->details->remember_forever_button));
|
||||
if (forever) {
|
||||
return GNOME_TWO_PASSWORD_DIALOG_REMEMBER_FOREVER;
|
||||
} else if (session) {
|
||||
return GNOME_TWO_PASSWORD_DIALOG_REMEMBER_SESSION;
|
||||
}
|
||||
return GNOME_TWO_PASSWORD_DIALOG_REMEMBER_NOTHING;
|
||||
g_return_val_if_fail (dialog != NULL, VPN_PASSWORD_REMEMBER_NOTHING);
|
||||
g_return_val_if_fail (VPN_IS_PASSWORD_DIALOG (dialog), VPN_PASSWORD_REMEMBER_NOTHING);
|
||||
|
||||
priv = VPN_PASSWORD_DIALOG_GET_PRIVATE (dialog);
|
||||
|
||||
session = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->remember_session_button));
|
||||
forever = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->remember_forever_button));
|
||||
if (forever)
|
||||
return VPN_PASSWORD_REMEMBER_FOREVER;
|
||||
else if (session)
|
||||
return VPN_PASSWORD_REMEMBER_SESSION;
|
||||
|
||||
return VPN_PASSWORD_REMEMBER_NOTHING;
|
||||
}
|
||||
|
||||
void gnome_two_password_dialog_set_password_secondary_label (GnomeTwoPasswordDialog *password_dialog,
|
||||
const char *password_secondary_label)
|
||||
void vpn_password_dialog_set_password_secondary_label (VpnPasswordDialog *dialog,
|
||||
const char *label)
|
||||
{
|
||||
g_return_if_fail (password_dialog != NULL);
|
||||
g_return_if_fail (GNOME_IS_TWO_PASSWORD_DIALOG (password_dialog));
|
||||
VpnPasswordDialogPrivate *priv;
|
||||
|
||||
g_free (password_dialog->details->secondary_password_label);
|
||||
password_dialog->details->secondary_password_label = g_strdup (password_secondary_label);
|
||||
g_return_if_fail (dialog != NULL);
|
||||
g_return_if_fail (VPN_IS_PASSWORD_DIALOG (dialog));
|
||||
|
||||
if (password_dialog->details->show_password_secondary) {
|
||||
add_table_rows (password_dialog);
|
||||
}
|
||||
priv = VPN_PASSWORD_DIALOG_GET_PRIVATE (dialog);
|
||||
|
||||
g_free (priv->secondary_password_label);
|
||||
priv->secondary_password_label = g_strdup (label);
|
||||
|
||||
if (priv->show_password_secondary)
|
||||
add_table_rows (dialog);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,94 +25,70 @@
|
|||
Authors: Ramiro Estrugo <ramiro@eazel.com>
|
||||
*/
|
||||
|
||||
#ifndef GNOME_TWO_PASSWORD_DIALOG_H
|
||||
#define GNOME_TWO_PASSWORD_DIALOG_H
|
||||
#ifndef VPN_PASSWORD_DIALOG_H
|
||||
#define VPN_PASSWORD_DIALOG_H
|
||||
|
||||
#include <gtk/gtkdialog.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GNOME_TYPE_TWO_PASSWORD_DIALOG (gnome_two_password_dialog_get_type ())
|
||||
#define GNOME_TWO_PASSWORD_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNOME_TYPE_TWO_PASSWORD_DIALOG, GnomeTwoPasswordDialog))
|
||||
#define GNOME_TWO_PASSWORD_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GNOME_TYPE_TWO_PASSWORD_DIALOG, GnomeTwoPasswordDialogClass))
|
||||
#define GNOME_IS_TWO_PASSWORD_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNOME_TYPE_TWO_PASSWORD_DIALOG))
|
||||
#define GNOME_IS_TWO_PASSWORD_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNOME_TYPE_TWO_PASSWORD_DIALOG))
|
||||
#define VPN_TYPE_PASSWORD_DIALOG (vpn_password_dialog_get_type ())
|
||||
#define VPN_PASSWORD_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VPN_TYPE_PASSWORD_DIALOG, VpnPasswordDialog))
|
||||
#define VPN_PASSWORD_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VPN_TYPE_PASSWORD_DIALOG, VpnPasswordDialogClass))
|
||||
#define VPN_IS_PASSWORD_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VPN_TYPE_PASSWORD_DIALOG))
|
||||
#define VPN_IS_PASSWORD_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VPN_TYPE_PASSWORD_DIALOG))
|
||||
|
||||
typedef struct GnomeTwoPasswordDialog GnomeTwoPasswordDialog;
|
||||
typedef struct GnomeTwoPasswordDialogClass GnomeTwoPasswordDialogClass;
|
||||
typedef struct GnomeTwoPasswordDialogDetails GnomeTwoPasswordDialogDetails;
|
||||
typedef struct VpnPasswordDialog VpnPasswordDialog;
|
||||
typedef struct VpnPasswordDialogClass VpnPasswordDialogClass;
|
||||
|
||||
struct GnomeTwoPasswordDialog
|
||||
{
|
||||
GtkDialog gtk_dialog;
|
||||
|
||||
GnomeTwoPasswordDialogDetails *details;
|
||||
struct VpnPasswordDialog {
|
||||
GtkDialog parent;
|
||||
};
|
||||
|
||||
struct GnomeTwoPasswordDialogClass
|
||||
{
|
||||
struct VpnPasswordDialogClass {
|
||||
GtkDialogClass parent_class;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
GNOME_TWO_PASSWORD_DIALOG_REMEMBER_NOTHING,
|
||||
GNOME_TWO_PASSWORD_DIALOG_REMEMBER_SESSION,
|
||||
GNOME_TWO_PASSWORD_DIALOG_REMEMBER_FOREVER
|
||||
} GnomeTwoPasswordDialogRemember;
|
||||
VPN_PASSWORD_REMEMBER_NOTHING,
|
||||
VPN_PASSWORD_REMEMBER_SESSION,
|
||||
VPN_PASSWORD_REMEMBER_FOREVER
|
||||
} VpnPasswordRemember;
|
||||
|
||||
|
||||
GType gnome_two_password_dialog_get_type (void);
|
||||
GtkWidget* gnome_two_password_dialog_new (const char *dialog_title,
|
||||
const char *message,
|
||||
const char *username,
|
||||
const char *password,
|
||||
gboolean readonly_username);
|
||||
GType vpn_password_dialog_get_type (void);
|
||||
GtkWidget* vpn_password_dialog_new (const char *title,
|
||||
const char *message,
|
||||
const char *password);
|
||||
|
||||
gboolean gnome_two_password_dialog_run_and_block (GnomeTwoPasswordDialog *password_dialog);
|
||||
gboolean vpn_password_dialog_run_and_block (VpnPasswordDialog *dialog);
|
||||
|
||||
/* Attribute mutators */
|
||||
void gnome_two_password_dialog_set_show_username (GnomeTwoPasswordDialog *password_dialog,
|
||||
gboolean show);
|
||||
void gnome_two_password_dialog_set_show_domain (GnomeTwoPasswordDialog *password_dialog,
|
||||
gboolean show);
|
||||
void gnome_two_password_dialog_set_show_password (GnomeTwoPasswordDialog *password_dialog,
|
||||
gboolean show);
|
||||
void gnome_two_password_dialog_focus_password (GnomeTwoPasswordDialog *password_dialog);
|
||||
void gnome_two_password_dialog_set_show_password_secondary (GnomeTwoPasswordDialog *password_dialog,
|
||||
gboolean show);
|
||||
void gnome_two_password_dialog_focus_password_secondary (GnomeTwoPasswordDialog *password_dialog);
|
||||
void gnome_two_password_dialog_set_username (GnomeTwoPasswordDialog *password_dialog,
|
||||
const char *username);
|
||||
void gnome_two_password_dialog_set_domain (GnomeTwoPasswordDialog *password_dialog,
|
||||
const char *domain);
|
||||
void gnome_two_password_dialog_set_password (GnomeTwoPasswordDialog *password_dialog,
|
||||
const char *password);
|
||||
void gnome_two_password_dialog_set_password_secondary (GnomeTwoPasswordDialog *password_dialog,
|
||||
const char *password_secondary);
|
||||
void gnome_two_password_dialog_set_readonly_username (GnomeTwoPasswordDialog *password_dialog,
|
||||
gboolean readonly);
|
||||
void gnome_two_password_dialog_set_readonly_domain (GnomeTwoPasswordDialog *password_dialog,
|
||||
gboolean readonly);
|
||||
void vpn_password_dialog_set_show_password (VpnPasswordDialog *dialog,
|
||||
gboolean show);
|
||||
void vpn_password_dialog_focus_password (VpnPasswordDialog *dialog);
|
||||
void vpn_password_dialog_set_password (VpnPasswordDialog *dialog,
|
||||
const char *password);
|
||||
|
||||
void gnome_two_password_dialog_set_password_secondary_label (GnomeTwoPasswordDialog *password_dialog,
|
||||
const char *password_secondary_description);
|
||||
void vpn_password_dialog_set_show_password_secondary (VpnPasswordDialog *dialog,
|
||||
gboolean show);
|
||||
void vpn_password_dialog_focus_password_secondary (VpnPasswordDialog *dialog);
|
||||
void vpn_password_dialog_set_password_secondary (VpnPasswordDialog *dialog,
|
||||
const char *password_secondary);
|
||||
void vpn_password_dialog_set_password_secondary_label (VpnPasswordDialog *dialog,
|
||||
const char *label);
|
||||
|
||||
void gnome_two_password_dialog_set_show_remember (GnomeTwoPasswordDialog *password_dialog,
|
||||
gboolean show_remember);
|
||||
void gnome_two_password_dialog_set_remember (GnomeTwoPasswordDialog *password_dialog,
|
||||
GnomeTwoPasswordDialogRemember remember);
|
||||
GnomeTwoPasswordDialogRemember gnome_two_password_dialog_get_remember (GnomeTwoPasswordDialog *password_dialog);
|
||||
void gnome_two_password_dialog_set_show_userpass_buttons (GnomeTwoPasswordDialog *password_dialog,
|
||||
gboolean show_userpass_buttons);
|
||||
void vpn_password_dialog_set_show_remember (VpnPasswordDialog *dialog,
|
||||
gboolean show_remember);
|
||||
void vpn_password_dialog_set_remember (VpnPasswordDialog *dialog,
|
||||
VpnPasswordRemember remember);
|
||||
VpnPasswordRemember vpn_password_dialog_get_remember (VpnPasswordDialog *dialog);
|
||||
|
||||
/* Attribute accessors */
|
||||
char * gnome_two_password_dialog_get_username (GnomeTwoPasswordDialog *password_dialog);
|
||||
char * gnome_two_password_dialog_get_domain (GnomeTwoPasswordDialog *password_dialog);
|
||||
char * gnome_two_password_dialog_get_password (GnomeTwoPasswordDialog *password_dialog);
|
||||
char * gnome_two_password_dialog_get_password_secondary (GnomeTwoPasswordDialog *password_dialog);
|
||||
const char *vpn_password_dialog_get_password (VpnPasswordDialog *dialog);
|
||||
|
||||
gboolean gnome_two_password_dialog_anon_selected (GnomeTwoPasswordDialog *password_dialog);
|
||||
const char *vpn_password_dialog_get_password_secondary (VpnPasswordDialog *dialog);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* GNOME_TWO_PASSWORD_DIALOG_H */
|
||||
#endif /* VPN_PASSWORD_DIALOG_H */
|
||||
|
|
|
|||
|
|
@ -42,139 +42,13 @@
|
|||
#define KEYRING_SN_TAG "setting-name"
|
||||
#define KEYRING_SK_TAG "setting-key"
|
||||
|
||||
static gboolean
|
||||
get_secrets (const char *vpn_uuid,
|
||||
const char *vpn_name,
|
||||
gboolean retry,
|
||||
char **upw,
|
||||
const char *upw_type,
|
||||
char **gpw,
|
||||
const char *gpw_type)
|
||||
{
|
||||
GnomeTwoPasswordDialog *dialog;
|
||||
gboolean is_session = TRUE;
|
||||
gboolean found_upw = FALSE;
|
||||
gboolean found_gpw = FALSE;
|
||||
char *prompt;
|
||||
gboolean success = FALSE;
|
||||
|
||||
g_return_val_if_fail (vpn_uuid != NULL, FALSE);
|
||||
g_return_val_if_fail (vpn_name != NULL, FALSE);
|
||||
g_return_val_if_fail (upw != NULL, FALSE);
|
||||
g_return_val_if_fail (*upw == NULL, FALSE);
|
||||
g_return_val_if_fail (gpw != NULL, FALSE);
|
||||
g_return_val_if_fail (*gpw == NULL, FALSE);
|
||||
|
||||
/* Default to 'save' to keep same behavior as previous versions before
|
||||
* password types were added.
|
||||
*/
|
||||
if (!upw_type)
|
||||
upw_type = NM_VPNC_PW_TYPE_SAVE;
|
||||
if (!gpw_type)
|
||||
gpw_type = NM_VPNC_PW_TYPE_SAVE;
|
||||
|
||||
if (strcmp (upw_type, NM_VPNC_PW_TYPE_ASK))
|
||||
found_upw = keyring_helpers_get_one_secret (vpn_uuid, VPNC_USER_PASSWORD, upw, &is_session);
|
||||
|
||||
if (strcmp (gpw_type, NM_VPNC_PW_TYPE_ASK))
|
||||
found_gpw = keyring_helpers_get_one_secret (vpn_uuid, VPNC_GROUP_PASSWORD, gpw, &is_session);
|
||||
|
||||
if (!retry) {
|
||||
gboolean need_upw = TRUE, need_gpw = TRUE;
|
||||
|
||||
/* Don't ask if both passwords are either saved and present, or unused */
|
||||
if ( (!strcmp (upw_type, NM_VPNC_PW_TYPE_SAVE) && found_upw && *upw)
|
||||
|| (!upw_type && found_upw && *upw) /* treat unknown type as "save" */
|
||||
|| !strcmp (upw_type, NM_VPNC_PW_TYPE_UNUSED))
|
||||
need_upw = FALSE;
|
||||
|
||||
if ( (!strcmp (gpw_type, NM_VPNC_PW_TYPE_SAVE) && found_gpw && *gpw)
|
||||
|| (!gpw_type && found_gpw && *gpw) /* treat unknown type as "save" */
|
||||
|| !strcmp (gpw_type, NM_VPNC_PW_TYPE_UNUSED))
|
||||
need_gpw = FALSE;
|
||||
|
||||
if (!need_upw && !need_gpw)
|
||||
return TRUE;
|
||||
} else {
|
||||
/* Don't ask if both passwords are unused */
|
||||
if ( !strcmp (upw_type, NM_VPNC_PW_TYPE_UNUSED)
|
||||
&& !strcmp (gpw_type, NM_VPNC_PW_TYPE_UNUSED))
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
prompt = g_strdup_printf (_("You need to authenticate to access the Virtual Private Network '%s'."), vpn_name);
|
||||
dialog = GNOME_TWO_PASSWORD_DIALOG (gnome_two_password_dialog_new (_("Authenticate VPN"), prompt, NULL, NULL, FALSE));
|
||||
g_free (prompt);
|
||||
|
||||
gnome_two_password_dialog_set_show_username (dialog, FALSE);
|
||||
gnome_two_password_dialog_set_show_userpass_buttons (dialog, FALSE);
|
||||
gnome_two_password_dialog_set_show_domain (dialog, FALSE);
|
||||
gnome_two_password_dialog_set_show_remember (dialog, FALSE);
|
||||
gnome_two_password_dialog_set_password_secondary_label (dialog, _("_Group Password:"));
|
||||
|
||||
if (!strcmp (upw_type, NM_VPNC_PW_TYPE_UNUSED))
|
||||
gnome_two_password_dialog_set_show_password (dialog, FALSE);
|
||||
else if (!retry && found_upw && strcmp (upw_type, NM_VPNC_PW_TYPE_ASK))
|
||||
gnome_two_password_dialog_set_show_password (dialog, FALSE);
|
||||
|
||||
if (!strcmp (gpw_type, NM_VPNC_PW_TYPE_UNUSED))
|
||||
gnome_two_password_dialog_set_show_password_secondary (dialog, FALSE);
|
||||
else if (!retry && found_gpw && strcmp (gpw_type, NM_VPNC_PW_TYPE_ASK))
|
||||
gnome_two_password_dialog_set_show_password_secondary (dialog, FALSE);
|
||||
|
||||
/* On reprompt the first entry of type 'ask' gets the focus */
|
||||
if (retry) {
|
||||
if (!strcmp (upw_type, NM_VPNC_PW_TYPE_ASK))
|
||||
gnome_two_password_dialog_focus_password (dialog);
|
||||
else if (!strcmp (gpw_type, NM_VPNC_PW_TYPE_ASK))
|
||||
gnome_two_password_dialog_focus_password_secondary (dialog);
|
||||
}
|
||||
|
||||
/* if retrying, pre-fill dialog with the password */
|
||||
if (*upw) {
|
||||
gnome_two_password_dialog_set_password (dialog, *upw);
|
||||
gnome_keyring_memory_free (*upw);
|
||||
*upw = NULL;
|
||||
}
|
||||
if (*gpw) {
|
||||
gnome_two_password_dialog_set_password_secondary (dialog, *gpw);
|
||||
gnome_keyring_memory_free (*gpw);
|
||||
*gpw = NULL;
|
||||
}
|
||||
|
||||
gtk_widget_show (GTK_WIDGET (dialog));
|
||||
|
||||
success = gnome_two_password_dialog_run_and_block (dialog);
|
||||
if (success) {
|
||||
*upw = gnome_two_password_dialog_get_password (dialog);
|
||||
*gpw = gnome_two_password_dialog_get_password_secondary (dialog);
|
||||
|
||||
if (!strcmp (upw_type, NM_VPNC_PW_TYPE_SAVE))
|
||||
keyring_helpers_save_secret (vpn_uuid, vpn_name, NULL, VPNC_USER_PASSWORD, *upw);
|
||||
|
||||
if (!strcmp (gpw_type, NM_VPNC_PW_TYPE_SAVE))
|
||||
keyring_helpers_save_secret (vpn_uuid, vpn_name, NULL, VPNC_GROUP_PASSWORD, *gpw);
|
||||
}
|
||||
|
||||
gtk_widget_hide (GTK_WIDGET (dialog));
|
||||
gtk_widget_destroy (GTK_WIDGET (dialog));
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
get_password_types (const char *vpn_uuid,
|
||||
char **out_upw_type,
|
||||
char **out_gpw_type)
|
||||
static char *
|
||||
find_connection_path (const char *vpn_uuid)
|
||||
{
|
||||
char *key, *str, *connection_path = NULL;
|
||||
GConfClient *gconf_client = NULL;
|
||||
GSList *conf_list;
|
||||
GSList *iter;
|
||||
char *key;
|
||||
char *str;
|
||||
char *connection_path = NULL;
|
||||
gboolean success = FALSE;
|
||||
char *upw_type = NULL, *gpw_type = NULL;
|
||||
|
||||
/* FIXME: This whole thing sucks: we should not go around poking gconf
|
||||
directly, but there's nothing that does it for us right now */
|
||||
|
|
@ -183,7 +57,7 @@ get_password_types (const char *vpn_uuid,
|
|||
|
||||
conf_list = gconf_client_all_dirs (gconf_client, "/system/networking/connections", NULL);
|
||||
if (!conf_list)
|
||||
goto out;
|
||||
return NULL;
|
||||
|
||||
for (iter = conf_list; iter; iter = iter->next) {
|
||||
const char *path = (const char *) iter->data;
|
||||
|
|
@ -222,8 +96,167 @@ get_password_types (const char *vpn_uuid,
|
|||
g_slist_foreach (conf_list, (GFunc) g_free, NULL);
|
||||
g_slist_free (conf_list);
|
||||
|
||||
g_object_unref (gconf_client);
|
||||
return connection_path;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
get_secrets (const char *vpn_uuid,
|
||||
const char *vpn_name,
|
||||
gboolean retry,
|
||||
char **upw,
|
||||
const char *upw_type,
|
||||
char **gpw,
|
||||
const char *gpw_type)
|
||||
{
|
||||
VpnPasswordDialog *dialog;
|
||||
gboolean is_session = TRUE;
|
||||
gboolean found_upw = FALSE;
|
||||
gboolean found_gpw = FALSE;
|
||||
char *prompt;
|
||||
gboolean success = FALSE;
|
||||
|
||||
g_return_val_if_fail (vpn_uuid != NULL, FALSE);
|
||||
g_return_val_if_fail (vpn_name != NULL, FALSE);
|
||||
g_return_val_if_fail (upw != NULL, FALSE);
|
||||
g_return_val_if_fail (*upw == NULL, FALSE);
|
||||
g_return_val_if_fail (gpw != NULL, FALSE);
|
||||
g_return_val_if_fail (*gpw == NULL, FALSE);
|
||||
|
||||
/* If a password type wasn't present in the VPN connection details, then
|
||||
* default to saving the password if it was found in the keyring. But if
|
||||
* it wasn't found in the keyring, default to always asking for the password.
|
||||
*/
|
||||
|
||||
found_upw = keyring_helpers_get_one_secret (vpn_uuid, VPNC_USER_PASSWORD, upw, &is_session);
|
||||
if (!upw_type)
|
||||
upw_type = found_upw ? NM_VPNC_PW_TYPE_SAVE : NM_VPNC_PW_TYPE_ASK;
|
||||
else if (!strcmp (upw_type, NM_VPNC_PW_TYPE_UNUSED)) {
|
||||
gnome_keyring_memory_free (*upw);
|
||||
*upw = NULL;
|
||||
}
|
||||
|
||||
found_gpw = keyring_helpers_get_one_secret (vpn_uuid, VPNC_GROUP_PASSWORD, gpw, &is_session);
|
||||
if (!gpw_type)
|
||||
gpw_type = found_gpw ? NM_VPNC_PW_TYPE_SAVE : NM_VPNC_PW_TYPE_ASK;
|
||||
else if (!strcmp (gpw_type, NM_VPNC_PW_TYPE_UNUSED)) {
|
||||
gnome_keyring_memory_free (*gpw);
|
||||
*gpw = NULL;
|
||||
}
|
||||
|
||||
if (!retry) {
|
||||
gboolean need_upw = TRUE, need_gpw = TRUE;
|
||||
|
||||
/* Don't ask if both passwords are either saved and present, or unused */
|
||||
if ( (!strcmp (upw_type, NM_VPNC_PW_TYPE_SAVE) && found_upw && *upw)
|
||||
|| (!upw_type && found_upw && *upw) /* treat unknown type as "save" */
|
||||
|| !strcmp (upw_type, NM_VPNC_PW_TYPE_UNUSED))
|
||||
need_upw = FALSE;
|
||||
|
||||
if ( (!strcmp (gpw_type, NM_VPNC_PW_TYPE_SAVE) && found_gpw && *gpw)
|
||||
|| (!gpw_type && found_gpw && *gpw) /* treat unknown type as "save" */
|
||||
|| !strcmp (gpw_type, NM_VPNC_PW_TYPE_UNUSED))
|
||||
need_gpw = FALSE;
|
||||
|
||||
if (!need_upw && !need_gpw)
|
||||
return TRUE;
|
||||
} else {
|
||||
/* Don't ask if both passwords are unused */
|
||||
if ( !strcmp (upw_type, NM_VPNC_PW_TYPE_UNUSED)
|
||||
&& !strcmp (gpw_type, NM_VPNC_PW_TYPE_UNUSED))
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
prompt = g_strdup_printf (_("You need to authenticate to access the Virtual Private Network '%s'."), vpn_name);
|
||||
dialog = VPN_PASSWORD_DIALOG (vpn_password_dialog_new (_("Authenticate VPN"), prompt, NULL));
|
||||
g_free (prompt);
|
||||
|
||||
vpn_password_dialog_set_show_remember (dialog, FALSE);
|
||||
vpn_password_dialog_set_password_secondary_label (dialog, _("_Group Password:"));
|
||||
|
||||
if (!strcmp (upw_type, NM_VPNC_PW_TYPE_UNUSED))
|
||||
vpn_password_dialog_set_show_password (dialog, FALSE);
|
||||
else if (!retry && found_upw && strcmp (upw_type, NM_VPNC_PW_TYPE_ASK))
|
||||
vpn_password_dialog_set_show_password (dialog, FALSE);
|
||||
|
||||
if (!strcmp (gpw_type, NM_VPNC_PW_TYPE_UNUSED))
|
||||
vpn_password_dialog_set_show_password_secondary (dialog, FALSE);
|
||||
else if (!retry && found_gpw && strcmp (gpw_type, NM_VPNC_PW_TYPE_ASK))
|
||||
vpn_password_dialog_set_show_password_secondary (dialog, FALSE);
|
||||
|
||||
/* On reprompt the first entry of type 'ask' gets the focus */
|
||||
if (retry) {
|
||||
if (!strcmp (upw_type, NM_VPNC_PW_TYPE_ASK))
|
||||
vpn_password_dialog_focus_password (dialog);
|
||||
else if (!strcmp (gpw_type, NM_VPNC_PW_TYPE_ASK))
|
||||
vpn_password_dialog_focus_password_secondary (dialog);
|
||||
}
|
||||
|
||||
/* if retrying, pre-fill dialog with the password */
|
||||
if (*upw) {
|
||||
vpn_password_dialog_set_password (dialog, *upw);
|
||||
gnome_keyring_memory_free (*upw);
|
||||
*upw = NULL;
|
||||
}
|
||||
if (*gpw) {
|
||||
vpn_password_dialog_set_password_secondary (dialog, *gpw);
|
||||
gnome_keyring_memory_free (*gpw);
|
||||
*gpw = NULL;
|
||||
}
|
||||
|
||||
gtk_widget_show (GTK_WIDGET (dialog));
|
||||
|
||||
success = vpn_password_dialog_run_and_block (dialog);
|
||||
if (success) {
|
||||
*upw = gnome_keyring_memory_strdup (vpn_password_dialog_get_password (dialog));
|
||||
*gpw = gnome_keyring_memory_strdup (vpn_password_dialog_get_password_secondary (dialog));
|
||||
|
||||
if (!strcmp (upw_type, NM_VPNC_PW_TYPE_SAVE)) {
|
||||
if (*upw)
|
||||
keyring_helpers_save_secret (vpn_uuid, vpn_name, NULL, VPNC_USER_PASSWORD, *upw);
|
||||
} else if ( !strcmp (upw_type, NM_VPNC_PW_TYPE_ASK)
|
||||
|| !strcmp (upw_type, NM_VPNC_PW_TYPE_UNUSED)) {
|
||||
/* Clear the password from the keyring */
|
||||
keyring_helpers_delete_secret (vpn_uuid, VPNC_USER_PASSWORD);
|
||||
}
|
||||
|
||||
if (!strcmp (gpw_type, NM_VPNC_PW_TYPE_SAVE)) {
|
||||
if (*gpw)
|
||||
keyring_helpers_save_secret (vpn_uuid, vpn_name, NULL, VPNC_GROUP_PASSWORD, *gpw);
|
||||
} else if ( !strcmp (gpw_type, NM_VPNC_PW_TYPE_ASK)
|
||||
|| !strcmp (gpw_type, NM_VPNC_PW_TYPE_UNUSED)) {
|
||||
/* Clear the password from the keyring */
|
||||
keyring_helpers_delete_secret (vpn_uuid, VPNC_GROUP_PASSWORD);
|
||||
}
|
||||
}
|
||||
|
||||
gtk_widget_hide (GTK_WIDGET (dialog));
|
||||
gtk_widget_destroy (GTK_WIDGET (dialog));
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
get_connection_info (const char *vpn_uuid,
|
||||
char **out_name,
|
||||
char **out_upw_type,
|
||||
char **out_gpw_type)
|
||||
{
|
||||
char *key, *str;
|
||||
char *connection_path = NULL;
|
||||
char *upw_type = NULL, *gpw_type = NULL;
|
||||
GConfClient *gconf_client;
|
||||
|
||||
connection_path = find_connection_path (vpn_uuid);
|
||||
if (!connection_path)
|
||||
goto out;
|
||||
return FALSE;
|
||||
|
||||
gconf_client = gconf_client_get_default ();
|
||||
key = g_strdup_printf ("%s/%s/%s", connection_path,
|
||||
NM_SETTING_CONNECTION_SETTING_NAME,
|
||||
NM_SETTING_CONNECTION_ID);
|
||||
*out_name = gconf_client_get_string (gconf_client, key, NULL);
|
||||
g_free (key);
|
||||
|
||||
key = g_strdup_printf ("%s/%s/%s", connection_path,
|
||||
NM_SETTING_VPN_SETTING_NAME,
|
||||
|
|
@ -238,20 +271,16 @@ get_password_types (const char *vpn_uuid,
|
|||
g_free (key);
|
||||
|
||||
g_free (connection_path);
|
||||
success = TRUE;
|
||||
|
||||
out:
|
||||
g_object_unref (gconf_client);
|
||||
return success;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
gboolean retry = FALSE;
|
||||
gchar *vpn_name = NULL;
|
||||
gchar *vpn_uuid = NULL;
|
||||
gchar *vpn_service = NULL;
|
||||
char *vpn_name = NULL, *vpn_uuid = NULL, *vpn_service = NULL;
|
||||
char *ignored;
|
||||
char *password = NULL, *group_password = NULL;
|
||||
char *upw_type = NULL, *gpw_type = NULL;
|
||||
char buf[1];
|
||||
|
|
@ -261,7 +290,7 @@ main (int argc, char *argv[])
|
|||
GOptionEntry entries[] = {
|
||||
{ "reprompt", 'r', 0, G_OPTION_ARG_NONE, &retry, "Reprompt for passwords", NULL},
|
||||
{ "uuid", 'u', 0, G_OPTION_ARG_STRING, &vpn_uuid, "UUID of VPN connection", NULL},
|
||||
{ "name", 'n', 0, G_OPTION_ARG_STRING, &vpn_name, "Name of VPN connection", NULL},
|
||||
{ "name", 'n', 0, G_OPTION_ARG_STRING, &ignored, "Name of VPN connection", NULL},
|
||||
{ "service", 's', 0, G_OPTION_ARG_STRING, &vpn_service, "VPN service type", NULL},
|
||||
{ NULL }
|
||||
};
|
||||
|
|
@ -282,8 +311,8 @@ main (int argc, char *argv[])
|
|||
|
||||
g_option_context_free (context);
|
||||
|
||||
if (vpn_uuid == NULL || vpn_name == NULL || vpn_service == NULL) {
|
||||
fprintf (stderr, "Have to supply UUID, name, and service\n");
|
||||
if (vpn_uuid == NULL || vpn_service == NULL) {
|
||||
fprintf (stderr, "A connection UUID and VPN plugin service name are required.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -292,10 +321,11 @@ main (int argc, char *argv[])
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (!get_password_types (vpn_uuid, &upw_type, &gpw_type)) {
|
||||
if (!get_connection_info (vpn_uuid, &vpn_name, &upw_type, &gpw_type)) {
|
||||
g_free (upw_type);
|
||||
g_free (gpw_type);
|
||||
fprintf (stderr, "This VPN connection '%s' (%s) could not be found in GConf.", vpn_name, vpn_uuid);
|
||||
fprintf (stderr, "This VPN connection '%s' (%s) could not be found in GConf.",
|
||||
vpn_name ? vpn_name : "(unknown)", vpn_uuid);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -308,7 +308,8 @@ static void
|
|||
init_one_pw_combo (VpncPluginUiWidget *self,
|
||||
NMSettingVPN *s_vpn,
|
||||
const char *combo_name,
|
||||
const char *key)
|
||||
const char *key,
|
||||
const char *entry_name)
|
||||
{
|
||||
VpncPluginUiWidgetPrivate *priv = VPNC_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
|
||||
int active = -1;
|
||||
|
|
@ -316,6 +317,19 @@ init_one_pw_combo (VpncPluginUiWidget *self,
|
|||
GtkListStore *store;
|
||||
GtkTreeIter iter;
|
||||
const char *value = NULL;
|
||||
guint32 default_idx = 1;
|
||||
|
||||
/* If there's already a password and the password type can't be found in
|
||||
* the VPN settings, default to saving it. Otherwise, always ask for it.
|
||||
*/
|
||||
widget = glade_xml_get_widget (priv->xml, entry_name);
|
||||
if (widget) {
|
||||
const char *tmp;
|
||||
|
||||
tmp = gtk_entry_get_text (GTK_ENTRY (widget));
|
||||
if (tmp && strlen (tmp))
|
||||
default_idx = 0;
|
||||
}
|
||||
|
||||
store = gtk_list_store_new (1, G_TYPE_STRING);
|
||||
if (s_vpn)
|
||||
|
|
@ -346,7 +360,7 @@ init_one_pw_combo (VpncPluginUiWidget *self,
|
|||
g_assert (widget);
|
||||
gtk_combo_box_set_model (GTK_COMBO_BOX (widget), GTK_TREE_MODEL (store));
|
||||
g_object_unref (store);
|
||||
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), active < 0 ? 0 : active);
|
||||
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), active < 0 ? default_idx : active);
|
||||
pw_type_changed_helper (self, widget);
|
||||
|
||||
g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (pw_type_combo_changed_cb), self);
|
||||
|
|
@ -418,8 +432,15 @@ init_plugin_ui (VpncPluginUiWidget *self, NMConnection *connection, GError **err
|
|||
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), active < 0 ? 0 : active);
|
||||
g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (stuff_changed_cb), self);
|
||||
|
||||
init_one_pw_combo (self, s_vpn, "user_pass_type_combo", NM_VPNC_KEY_XAUTH_PASSWORD_TYPE);
|
||||
init_one_pw_combo (self, s_vpn, "group_pass_type_combo", NM_VPNC_KEY_SECRET_TYPE);
|
||||
/* Fill the VPN passwords *before* initializing the PW type combos, since
|
||||
* knowing if there are passwords when initializing the combos is helpful.
|
||||
*/
|
||||
fill_vpn_passwords (self, connection);
|
||||
|
||||
init_one_pw_combo (self, s_vpn, "user_pass_type_combo",
|
||||
NM_VPNC_KEY_XAUTH_PASSWORD_TYPE, "user_password_entry");
|
||||
init_one_pw_combo (self, s_vpn, "group_pass_type_combo",
|
||||
NM_VPNC_KEY_SECRET_TYPE, "group_password_entry");
|
||||
|
||||
widget = glade_xml_get_widget (priv->xml, "user_entry");
|
||||
g_return_val_if_fail (widget != NULL, FALSE);
|
||||
|
|
@ -493,8 +514,6 @@ init_plugin_ui (VpncPluginUiWidget *self, NMConnection *connection, GError **err
|
|||
}
|
||||
g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (stuff_changed_cb), self);
|
||||
|
||||
fill_vpn_passwords (self, connection);
|
||||
|
||||
widget = glade_xml_get_widget (priv->xml, "show_passwords_checkbutton");
|
||||
g_return_val_if_fail (widget != NULL, FALSE);
|
||||
g_signal_connect (G_OBJECT (widget), "toggled",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue