[network-manager-applet] core: better support for OTP (one-time-pad) devices



commit c0c2a74a3d78779b050d54387fe3a0562d07d7cc
Author: Huzaifa S. Sidhpurwala <huzaifas redhat com>
Date:   Wed Feb 24 18:08:14 2010 -0800

    core: better support for OTP (one-time-pad) devices
    
    Add a checkbox telling the applet to ask the user for the password
    every time NM asks for it.  OTP devices change the password often
    and thus saving the password makes no sense.
    
    (lots of cleanups by dcbw)

 src/applet.glade                          |   58 ++++++++++++++++++-----
 src/gconf-helpers/gconf-helpers.c         |   45 +++++++++++++++++
 src/gconf-helpers/gconf-helpers.h         |    3 +
 src/gconf-helpers/nma-gconf-connection.c  |   41 ++++++++++++++++
 src/wireless-security/eap-method-simple.c |   75 ++++++++++++++++++++++++++++-
 5 files changed, 208 insertions(+), 14 deletions(-)
---
diff --git a/src/applet.glade b/src/applet.glade
index 4dfc5d9..8f0ded8 100644
--- a/src/applet.glade
+++ b/src/applet.glade
@@ -1300,32 +1300,60 @@ Shared Key</property>
               </packing>
             </child>
             <child>
-              <widget class="GtkCheckButton" id="show_checkbutton">
-                <property name="label" translatable="yes">Sho_w password</property>
+              <widget class="GtkEntry" id="eap_simple_username_entry">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
-                <property name="receives_default">False</property>
-                <property name="use_underline">True</property>
-                <property name="draw_indicator">True</property>
               </widget>
               <packing>
                 <property name="left_attach">1</property>
                 <property name="right_attach">2</property>
-                <property name="top_attach">2</property>
-                <property name="bottom_attach">3</property>
-                <property name="x_options">GTK_FILL</property>
                 <property name="y_options"></property>
               </packing>
             </child>
             <child>
-              <widget class="GtkEntry" id="eap_simple_username_entry">
+              <widget class="GtkAlignment" id="alignment1">
                 <property name="visible">True</property>
-                <property name="can_focus">True</property>
+                <child>
+                  <widget class="GtkVBox" id="vbox1">
+                    <property name="visible">True</property>
+                    <property name="orientation">vertical</property>
+                    <child>
+                      <widget class="GtkCheckButton" id="eap_password_always_ask">
+                        <property name="label" translatable="yes">As_k for this password every time</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="use_underline">True</property>
+                        <property name="draw_indicator">True</property>
+                      </widget>
+                      <packing>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkCheckButton" id="show_checkbutton">
+                        <property name="label" translatable="yes">Sho_w password</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="use_underline">True</property>
+                        <property name="draw_indicator">True</property>
+                      </widget>
+                      <packing>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                  </widget>
+                </child>
               </widget>
               <packing>
                 <property name="left_attach">1</property>
                 <property name="right_attach">2</property>
-                <property name="y_options"></property>
+                <property name="top_attach">2</property>
+                <property name="bottom_attach">3</property>
               </packing>
             </child>
             <child>
@@ -1356,7 +1384,7 @@ Shared Key</property>
         <child>
           <widget class="GtkTable" id="table12">
             <property name="visible">True</property>
-            <property name="n_rows">2</property>
+            <property name="n_rows">3</property>
             <property name="n_columns">2</property>
             <property name="column_spacing">12</property>
             <property name="row_spacing">6</property>
@@ -1399,6 +1427,12 @@ Shared Key</property>
                 <property name="x_options">GTK_FILL</property>
               </packing>
             </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
           </widget>
         </child>
         <child>
diff --git a/src/gconf-helpers/gconf-helpers.c b/src/gconf-helpers/gconf-helpers.c
index 3170e68..48f7dee 100644
--- a/src/gconf-helpers/gconf-helpers.c
+++ b/src/gconf-helpers/gconf-helpers.c
@@ -2613,3 +2613,48 @@ nm_gconf_set_ignore_ca_cert (const char *uuid, gboolean phase2, gboolean ignore)
 	g_object_unref (client);
 }
 
+static char *
+get_always_ask_path (const char *uuid)
+{
+	return g_strdup_printf (APPLET_PREFS_PATH "/8021x-password-always-ask/%s", uuid);
+}
+
+gboolean
+nm_gconf_get_8021x_password_always_ask (const char *uuid)
+{
+	GConfClient *client;
+	char *key = NULL;
+	gboolean ask = FALSE;
+
+	g_return_val_if_fail (uuid != NULL, FALSE);
+
+	client = gconf_client_get_default ();
+
+	key = get_always_ask_path (uuid);
+	ask = gconf_client_get_bool (client, key, NULL);
+	g_free (key);
+
+	g_object_unref (client);
+	return ask;
+}
+
+void
+nm_gconf_set_8021x_password_always_ask (const char *uuid, gboolean ask)
+{
+	GConfClient *client;
+	char *key = NULL;
+
+	g_return_if_fail (uuid != NULL);
+
+	client = gconf_client_get_default ();
+
+	key = get_always_ask_path (uuid);
+	if (ask)
+		gconf_client_set_bool (client, key, TRUE, NULL);
+	else
+		gconf_client_unset (client, key, NULL);
+	g_free (key);
+
+	g_object_unref (client);
+}
+
diff --git a/src/gconf-helpers/gconf-helpers.h b/src/gconf-helpers/gconf-helpers.h
index 942acc8..cee0cc6 100644
--- a/src/gconf-helpers/gconf-helpers.h
+++ b/src/gconf-helpers/gconf-helpers.h
@@ -258,5 +258,8 @@ void pre_keyring_callback (void);
 gboolean nm_gconf_get_ignore_ca_cert (const char *uuid, gboolean phase2);
 void nm_gconf_set_ignore_ca_cert (const char *uuid, gboolean phase2, gboolean ignore);
 
+gboolean nm_gconf_get_8021x_password_always_ask (const char *uuid);
+void nm_gconf_set_8021x_password_always_ask (const char *uuid, gboolean always_ask);
+
 #endif	/* GCONF_HELPERS_H */
 
diff --git a/src/gconf-helpers/nma-gconf-connection.c b/src/gconf-helpers/nma-gconf-connection.c
index 753cc96..8b6cf5a 100644
--- a/src/gconf-helpers/nma-gconf-connection.c
+++ b/src/gconf-helpers/nma-gconf-connection.c
@@ -479,6 +479,43 @@ do_delete (NMSettingsConnectionInterface *connection,
 }
 
 static gboolean
+is_otp_always_ask (NMConnection *connection)
+{
+	NMSetting8021x *s_8021x;
+	NMSettingConnection *s_con;
+	const char *uuid, *eap_method, *phase2;
+
+	s_8021x = (NMSetting8021x *) nm_connection_get_setting (connection, NM_TYPE_SETTING_802_1X);
+	if (s_8021x) {
+		gboolean can_always_ask = FALSE;
+
+		/* Check if PEAP or TTLS is used */
+		eap_method = nm_setting_802_1x_get_eap_method (s_8021x, 0);
+		s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
+		if (!strcmp (eap_method, "peap"))
+			can_always_ask = TRUE;
+		else if (!strcmp (eap_method, "ttls")) {
+			/* Now make sure the phase2 method isn't TLS */
+			phase2 = nm_setting_802_1x_get_phase2_auth (s_8021x);
+			if (phase2 && strcmp (phase2, "tls"))
+				can_always_ask = TRUE;
+			else {
+				phase2 = nm_setting_802_1x_get_phase2_autheap (s_8021x);
+				if (phase2 && strcmp (phase2, "tls"))
+					can_always_ask = TRUE;
+			}
+		}
+
+		if (can_always_ask) {
+			uuid = nm_setting_connection_get_uuid (s_con);
+			if (nm_gconf_get_8021x_password_always_ask (uuid))
+				return TRUE;
+		}
+	}
+	return FALSE;
+}
+
+static gboolean
 internal_get_secrets (NMSettingsConnectionInterface *connection,
                       const char *setting_name,
                       const char **hints,
@@ -539,6 +576,10 @@ internal_get_secrets (NMSettingsConnectionInterface *connection,
 			goto get_secrets;
 		}
 
+		/* OTP connections marked as always ask */
+		if (is_otp_always_ask (NM_CONNECTION (self)))
+			goto get_secrets;
+
 		secrets = nma_gconf_connection_get_keyring_items (self, setting_name, error);
 		if (!secrets) {
 			if (error && *error)
diff --git a/src/wireless-security/eap-method-simple.c b/src/wireless-security/eap-method-simple.c
index 0eea74a..247757f 100644
--- a/src/wireless-security/eap-method-simple.c
+++ b/src/wireless-security/eap-method-simple.c
@@ -24,6 +24,7 @@
 #include <ctype.h>
 #include <string.h>
 #include <nm-setting-8021x.h>
+#include <nm-setting-connection.h>
 
 #include "eap-method.h"
 #include "wireless-security.h"
@@ -63,6 +64,12 @@ validate (EAPMethod *parent)
 	if (!text || !strlen (text))
 		return FALSE;
 
+	/* Check if the password should always be requested */
+	widget = glade_xml_get_widget (parent->xml, "eap_password_always_ask");
+	g_assert (widget);
+	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
+		return TRUE;
+
 	widget = glade_xml_get_widget (parent->xml, "eap_simple_password_entry");
 	g_assert (widget);
 	text = gtk_entry_get_text (GTK_ENTRY (widget));
@@ -92,6 +99,8 @@ fill_connection (EAPMethod *parent, NMConnection *connection)
 	EAPMethodSimple *method = (EAPMethodSimple *) parent;
 	NMSetting8021x *s_8021x;
 	GtkWidget *widget;
+	NMSettingConnection *s_con;
+	gboolean always_ask;
 
 	s_8021x = NM_SETTING_802_1X (nm_connection_get_setting (connection, NM_TYPE_SETTING_802_1X));
 	g_assert (s_8021x);
@@ -124,9 +133,19 @@ fill_connection (EAPMethod *parent, NMConnection *connection)
 	g_assert (widget);
 	g_object_set (s_8021x, NM_SETTING_802_1X_IDENTITY, gtk_entry_get_text (GTK_ENTRY (widget)), NULL);
 
-	widget = glade_xml_get_widget (parent->xml, "eap_simple_password_entry");
+	widget = glade_xml_get_widget (parent->xml, "eap_password_always_ask");
 	g_assert (widget);
-	g_object_set (s_8021x, NM_SETTING_802_1X_PASSWORD, gtk_entry_get_text (GTK_ENTRY (widget)), NULL);
+	always_ask = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
+	if (always_ask) {
+		widget = glade_xml_get_widget (parent->xml, "eap_simple_password_entry");
+		g_assert (widget);
+		g_object_set (s_8021x, NM_SETTING_802_1X_PASSWORD, gtk_entry_get_text (GTK_ENTRY (widget)), NULL);
+	}
+
+	/* Save the password always ask setting */
+	s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
+	g_assert (s_con);
+	nm_gconf_set_8021x_password_always_ask (nm_setting_connection_get_uuid (s_con), always_ask);
 }
 
 static void
@@ -139,6 +158,32 @@ update_secrets (EAPMethod *parent, NMConnection *connection)
 	                          (HelperSecretFunc) nm_setting_802_1x_get_password);
 }
 
+static void
+password_always_ask_changed (GtkButton *button, EAPMethodSimple *method)
+{
+	EAPMethod *parent = (EAPMethod *) method;
+	GtkWidget *password_entry;
+	GtkWidget *show_checkbox;
+	gboolean always_ask;
+
+	always_ask = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+
+	password_entry = glade_xml_get_widget (parent->xml, "eap_simple_password_entry");
+	g_assert (password_entry);
+
+	show_checkbox = glade_xml_get_widget (parent->xml, "show_checkbutton");
+	g_assert (show_checkbox);
+
+	if (always_ask) {
+		gtk_entry_set_text (GTK_ENTRY (password_entry), "");
+		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (show_checkbox), FALSE);
+	}
+
+	gtk_widget_set_sensitive (password_entry, !always_ask);
+	gtk_widget_set_sensitive (show_checkbox, !always_ask);
+}
+
+
 EAPMethodSimple *
 eap_method_simple_new (const char *glade_file,
                        WirelessSecurity *parent,
@@ -148,6 +193,7 @@ eap_method_simple_new (const char *glade_file,
 	EAPMethodSimple *method;
 	GtkWidget *widget;
 	GladeXML *xml;
+	gboolean always_ask = FALSE;
 
 	g_return_val_if_fail (glade_file != NULL, NULL);
 
@@ -209,6 +255,31 @@ eap_method_simple_new (const char *glade_file,
 	                  (GCallback) show_toggled_cb,
 	                  method);
 
+	/* Sensitize/desensitize the password entry based on whether it should
+	 * always be asked for when connecting or not.
+	 */
+	widget = glade_xml_get_widget (xml, "eap_password_always_ask");
+	g_assert (widget);
+	g_signal_connect (G_OBJECT (widget), "toggled",
+	                  (GCallback) wireless_security_changed_cb,
+	                  parent);
+	g_signal_connect (G_OBJECT (widget), "toggled",
+	                  G_CALLBACK (password_always_ask_changed),
+	                  method);
+
+	if (connection) {
+		NMSettingConnection *s_con;
+		const char *uuid;
+
+		s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
+		g_assert (s_con);
+
+		uuid = nm_setting_connection_get_uuid (s_con);
+		always_ask = nm_gconf_get_8021x_password_always_ask (uuid);
+	}
+
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), always_ask);
+
 	return method;
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]