[network-manager-openvpn] properties: add password type combo (saved, ask, not required)
- From: Dan Williams <dcbw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-openvpn] properties: add password type combo (saved, ask, not required)
- Date: Thu, 14 Jul 2011 03:13:58 +0000 (UTC)
commit 0f4daf4570f1777c84040053299fa8adb636bf74
Author: Dan Williams <dcbw redhat com>
Date: Wed Jul 13 21:53:29 2011 -0500
properties: add password type combo (saved, ask, not required)
Like vpnc has; they map directly to the NM internal secret flags and
allows better support for user preference or one-time-pad tokens.
properties/auth-helpers.c | 106 +++++++++++++++++++++++++++++++++++++++
properties/nm-openvpn-dialog.ui | 65 ++++++++++++++++++++----
2 files changed, 160 insertions(+), 11 deletions(-)
---
diff --git a/properties/auth-helpers.c b/properties/auth-helpers.c
index a52e727..9112e34 100644
--- a/properties/auth-helpers.c
+++ b/properties/auth-helpers.c
@@ -42,6 +42,10 @@
#include "src/nm-openvpn-service.h"
#include "common/utils.h"
+#define PW_TYPE_SAVE 0
+#define PW_TYPE_ASK 1
+#define PW_TYPE_UNUSED 2
+
static void
show_password (GtkToggleButton *togglebutton, GtkEntry *password_entry)
{
@@ -182,6 +186,87 @@ tls_setup (GtkBuilder *builder,
}
static void
+pw_type_combo_changed_cb (GtkWidget *combo, gpointer user_data)
+{
+ GtkWidget *entry = user_data;
+
+ /* If the user chose "Not required", desensitize and clear the correct
+ * password entry.
+ */
+ switch (gtk_combo_box_get_active (GTK_COMBO_BOX (combo))) {
+ case PW_TYPE_ASK:
+ case PW_TYPE_UNUSED:
+ gtk_entry_set_text (GTK_ENTRY (entry), "");
+ gtk_widget_set_sensitive (entry, FALSE);
+ break;
+ default:
+ gtk_widget_set_sensitive (entry, TRUE);
+ break;
+ }
+}
+
+static void
+init_one_pw_combo (GtkBuilder *builder,
+ NMSettingVPN *s_vpn,
+ const char *prefix,
+ const char *secret_key,
+ GtkWidget *entry_widget,
+ ChangedCallback changed_cb,
+ gpointer user_data)
+{
+ int active = -1;
+ GtkWidget *widget;
+ GtkListStore *store;
+ GtkTreeIter iter;
+ const char *value = NULL;
+ char *tmp;
+ guint32 default_idx = 1;
+ NMSettingSecretFlags pw_flags = NM_SETTING_SECRET_FLAG_NONE;
+
+ /* 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.
+ */
+ value = gtk_entry_get_text (GTK_ENTRY (entry_widget));
+ if (value && strlen (value))
+ default_idx = 0;
+
+ store = gtk_list_store_new (1, G_TYPE_STRING);
+ if (s_vpn)
+ nm_setting_get_secret_flags (NM_SETTING (s_vpn), secret_key, &pw_flags, NULL);
+
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter, 0, _("Saved"), -1);
+ if ( (active < 0)
+ && !(pw_flags & NM_SETTING_SECRET_FLAG_NOT_SAVED)
+ && !(pw_flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED)) {
+ active = PW_TYPE_SAVE;
+ }
+
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter, 0, _("Always Ask"), -1);
+ if ((active < 0) && (pw_flags & NM_SETTING_SECRET_FLAG_NOT_SAVED))
+ active = PW_TYPE_ASK;
+
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter, 0, _("Not Required"), -1);
+ if ((active < 0) && (pw_flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED))
+ active = PW_TYPE_UNUSED;
+
+ tmp = g_strdup_printf ("%s_pass_type_combo", prefix);
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, tmp));
+ g_assert (widget);
+ g_free (tmp);
+
+ 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 ? default_idx : active);
+ pw_type_combo_changed_cb (widget, entry_widget);
+
+ g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (pw_type_combo_changed_cb), entry_widget);
+ g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (changed_cb), user_data);
+}
+
+static void
pw_setup (GtkBuilder *builder,
GtkSizeGroup *group,
NMSettingVPN *s_vpn,
@@ -211,6 +296,8 @@ pw_setup (GtkBuilder *builder,
g_free (tmp);
gtk_size_group_add_widget (group, widget);
g_signal_connect (widget, "changed", G_CALLBACK (changed_cb), user_data);
+
+ init_one_pw_combo (builder, s_vpn, prefix, NM_OPENVPN_KEY_PASSWORD, widget, changed_cb, user_data);
}
void
@@ -593,7 +680,26 @@ update_pw (GtkBuilder *builder, const char *prefix, NMSettingVPN *s_vpn)
if (str && strlen (str))
nm_setting_vpn_add_secret (s_vpn, NM_OPENVPN_KEY_PASSWORD, str);
+ /* Update password flags */
pw_flags = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (widget), "flags"));
+ pw_flags &= ~(NM_SETTING_SECRET_FLAG_NOT_SAVED | NM_SETTING_SECRET_FLAG_NOT_REQUIRED);
+
+ tmp = g_strdup_printf ("%s_pass_type_combo", prefix);
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, tmp));
+ g_free (tmp);
+
+ switch (gtk_combo_box_get_active (GTK_COMBO_BOX (widget))) {
+ case PW_TYPE_SAVE:
+ break;
+ case PW_TYPE_UNUSED:
+ pw_flags |= NM_SETTING_SECRET_FLAG_NOT_REQUIRED;
+ break;
+ case PW_TYPE_ASK:
+ default:
+ pw_flags |= NM_SETTING_SECRET_FLAG_NOT_SAVED;
+ break;
+ }
+
nm_setting_set_secret_flags (NM_SETTING (s_vpn), NM_OPENVPN_KEY_PASSWORD, pw_flags, NULL);
}
diff --git a/properties/nm-openvpn-dialog.ui b/properties/nm-openvpn-dialog.ui
index 5b8acec..79381e8 100644
--- a/properties/nm-openvpn-dialog.ui
+++ b/properties/nm-openvpn-dialog.ui
@@ -32,6 +32,8 @@
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
+ <object class="GtkListStore" id="liststore1"/>
+ <object class="GtkListStore" id="liststore2"/>
<object class="GtkListStore" id="model1">
<columns>
<!-- column-name gchararray -->
@@ -1295,7 +1297,7 @@ Example: /CN=myvpn.company.com</i></property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="n_rows">3</property>
- <property name="n_columns">2</property>
+ <property name="n_columns">3</property>
<property name="column_spacing">6</property>
<property name="row_spacing">6</property>
<child>
@@ -1335,7 +1337,7 @@ Example: /CN=myvpn.company.com</i></property>
</object>
<packing>
<property name="left_attach">1</property>
- <property name="right_attach">2</property>
+ <property name="right_attach">3</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="y_options"></property>
@@ -1393,7 +1395,27 @@ Example: /CN=myvpn.company.com</i></property>
</object>
<packing>
<property name="left_attach">1</property>
- <property name="right_attach">2</property>
+ <property name="right_attach">3</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkComboBox" id="pw_pass_type_combo">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="model">liststore1</property>
+ <child>
+ <object class="GtkCellRendererText" id="renderer7"/>
+ <attributes>
+ <attribute name="text">0</attribute>
+ </attributes>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">2</property>
+ <property name="right_attach">3</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
<property name="y_options"></property>
</packing>
</child>
@@ -1418,7 +1440,7 @@ Example: /CN=myvpn.company.com</i></property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="n_rows">6</property>
- <property name="n_columns">2</property>
+ <property name="n_columns">3</property>
<property name="column_spacing">6</property>
<property name="row_spacing">6</property>
<child>
@@ -1437,7 +1459,7 @@ Example: /CN=myvpn.company.com</i></property>
</object>
<packing>
<property name="left_attach">1</property>
- <property name="right_attach">2</property>
+ <property name="right_attach">3</property>
<property name="top_attach">5</property>
<property name="bottom_attach">6</property>
<property name="y_options"></property>
@@ -1471,7 +1493,7 @@ Example: /CN=myvpn.company.com</i></property>
</object>
<packing>
<property name="left_attach">1</property>
- <property name="right_attach">2</property>
+ <property name="right_attach">3</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="y_options"></property>
@@ -1540,7 +1562,7 @@ Example: /CN=myvpn.company.com</i></property>
</object>
<packing>
<property name="left_attach">1</property>
- <property name="right_attach">2</property>
+ <property name="right_attach">3</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="y_options"></property>
@@ -1561,7 +1583,7 @@ Example: /CN=myvpn.company.com</i></property>
</object>
<packing>
<property name="left_attach">1</property>
- <property name="right_attach">2</property>
+ <property name="right_attach">3</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="y_options"></property>
@@ -1619,7 +1641,27 @@ Example: /CN=myvpn.company.com</i></property>
</object>
<packing>
<property name="left_attach">1</property>
- <property name="right_attach">2</property>
+ <property name="right_attach">3</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkComboBox" id="pw_tls_pass_type_combo">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="model">liststore2</property>
+ <child>
+ <object class="GtkCellRendererText" id="renderer8"/>
+ <attributes>
+ <attribute name="text">0</attribute>
+ </attributes>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">2</property>
+ <property name="right_attach">3</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
<property name="y_options"></property>
</packing>
</child>
@@ -1835,6 +1877,7 @@ Example: /CN=myvpn.company.com</i></property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
+ <property name="y_options">GTK_EXPAND</property>
</packing>
</child>
<child>
@@ -1878,8 +1921,8 @@ Example: /CN=myvpn.company.com</i></property>
</child>
</object>
<packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]