File nma-eap-tls-subject-probe.patch of Package NetworkManager-gnome.import5627

diff --git a/src/applet.glade b/src/applet.glade
index c194cfa..6f3ea80 100644
--- a/src/applet.glade
+++ b/src/applet.glade
@@ -845,7 +845,7 @@ Shared Key</property>
         <child>
           <widget class="GtkTable" id="table8">
             <property name="visible">True</property>
-            <property name="n_rows">6</property>
+            <property name="n_rows">7</property>
             <property name="n_columns">2</property>
             <property name="column_spacing">12</property>
             <property name="row_spacing">6</property>
@@ -889,12 +889,12 @@ Shared Key</property>
               </packing>
             </child>
             <child>
-              <widget class="GtkLabel" id="eap_tls_ca_cert_label">
+              <widget class="GtkLabel" id="eap_tls_subject_label">
                 <property name="visible">True</property>
                 <property name="xalign">0</property>
-                <property name="label" translatable="yes">C_A certificate:</property>
+                <property name="label" translatable="yes">CA _subject:</property>
                 <property name="use_underline">True</property>
-                <property name="mnemonic_widget">eap_tls_ca_cert_button</property>
+                <property name="mnemonic_widget">eap_tls_private_key_password_entry</property>
               </widget>
               <packing>
                 <property name="top_attach">2</property>
@@ -904,14 +904,43 @@ Shared Key</property>
               </packing>
             </child>
             <child>
-              <widget class="GtkFileChooserButton" id="eap_tls_ca_cert_button">
+              <widget class="GtkEntry" id="eap_tls_subject_entry">
                 <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="visibility">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="y_options"></property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkLabel" id="eap_tls_ca_cert_label">
+                <property name="visible">True</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">C_A certificate:</property>
+                <property name="use_underline">True</property>
+                <property name="mnemonic_widget">eap_tls_ca_cert_button</property>
+              </widget>
+              <packing>
+                <property name="top_attach">3</property>
+                <property name="bottom_attach">4</property>
+                <property name="x_options">GTK_FILL</property>
+                <property name="y_options"></property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkFileChooserButton" id="eap_tls_ca_cert_button">
+                <property name="visible">True</property>
+              </widget>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="right_attach">2</property>
+                <property name="top_attach">3</property>
+                <property name="bottom_attach">4</property>
                 <property name="x_options">GTK_FILL</property>
                 <property name="y_options">GTK_FILL</property>
               </packing>
@@ -925,8 +954,8 @@ Shared Key</property>
                 <property name="mnemonic_widget">eap_tls_private_key_button</property>
               </widget>
               <packing>
-                <property name="top_attach">3</property>
-                <property name="bottom_attach">4</property>
+                <property name="top_attach">4</property>
+                <property name="bottom_attach">5</property>
                 <property name="x_options">GTK_FILL</property>
                 <property name="y_options"></property>
               </packing>
@@ -938,8 +967,8 @@ Shared Key</property>
               <packing>
                 <property name="left_attach">1</property>
                 <property name="right_attach">2</property>
-                <property name="top_attach">3</property>
-                <property name="bottom_attach">4</property>
+                <property name="top_attach">4</property>
+                <property name="bottom_attach">5</property>
                 <property name="x_options">GTK_FILL</property>
                 <property name="y_options">GTK_FILL</property>
               </packing>
@@ -953,8 +982,8 @@ Shared Key</property>
                 <property name="mnemonic_widget">eap_tls_private_key_password_entry</property>
               </widget>
               <packing>
-                <property name="top_attach">4</property>
-                <property name="bottom_attach">5</property>
+                <property name="top_attach">5</property>
+                <property name="bottom_attach">6</property>
                 <property name="x_options">GTK_FILL</property>
                 <property name="y_options"></property>
               </packing>
@@ -968,8 +997,8 @@ Shared Key</property>
               <packing>
                 <property name="left_attach">1</property>
                 <property name="right_attach">2</property>
-                <property name="top_attach">4</property>
-                <property name="bottom_attach">5</property>
+                <property name="top_attach">5</property>
+                <property name="bottom_attach">6</property>
                 <property name="y_options"></property>
               </packing>
             </child>
@@ -985,8 +1014,8 @@ Shared Key</property>
               <packing>
                 <property name="left_attach">1</property>
                 <property name="right_attach">2</property>
-                <property name="top_attach">5</property>
-                <property name="bottom_attach">6</property>
+                <property name="top_attach">6</property>
+                <property name="bottom_attach">7</property>
                 <property name="x_options">GTK_FILL</property>
                 <property name="y_options"></property>
               </packing>
diff --git a/src/wireless-dialog.c b/src/wireless-dialog.c
index a9a8f5a..bff8ebb 100644
--- a/src/wireless-dialog.c
+++ b/src/wireless-dialog.c
@@ -142,7 +142,9 @@ nma_wireless_dialog_need_ca_cert_probe (NMAWirelessDialog *self)
 	for (i = 0; i < num_eap; i++) {
 		const char *eap;
 		eap = nm_setting_802_1x_get_eap_method (s_8021x, i);
-		if (g_strcmp0 (eap, "ttls") == 0 || g_strcmp0 (eap, "peap") == 0) {
+		if (   g_strcmp0 (eap, "ttls") == 0
+		    || g_strcmp0 (eap, "peap") == 0
+		    || g_strcmp0 (eap, "tls") == 0) {
 			need_ca = TRUE;
 			break;
 		}
diff --git a/src/wireless-security/eap-method-tls.c b/src/wireless-security/eap-method-tls.c
index fe34ff6..15327d0 100644
--- a/src/wireless-security/eap-method-tls.c
+++ b/src/wireless-security/eap-method-tls.c
@@ -34,6 +34,8 @@
 #include "utils.h"
 #include "helpers.h"
 
+#define SUBJECT_NOTE _("<will be filled automatically>")
+
 static void
 show_toggled_cb (GtkCheckButton *button, EAPMethod *method)
 {
@@ -109,6 +111,10 @@ add_to_size_group (EAPMethod *parent, GtkSizeGroup *group)
 	g_assert (widget);
 	gtk_size_group_add_widget (group, widget);
 
+	widget = glade_xml_get_widget (parent->xml, "eap_tls_subject_label");
+	g_assert (widget);
+	gtk_size_group_add_widget (group, widget);
+
 	widget = glade_xml_get_widget (parent->xml, "eap_tls_private_key_label");
 	g_assert (widget);
 	gtk_size_group_add_widget (group, widget);
@@ -128,6 +134,7 @@ fill_connection (EAPMethod *parent, NMConnection *connection)
 	GtkWidget *widget;
 	char *ca_filename, *pk_filename, *cc_filename;
 	const char *password = NULL;
+	const char *text;
 	GError *error = NULL;
 
 	s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
@@ -212,6 +219,12 @@ fill_connection (EAPMethod *parent, NMConnection *connection)
 		}
 	}
 
+	widget = glade_xml_get_widget (parent->xml, "eap_tls_subject_entry");
+	g_assert (widget);
+	text = gtk_entry_get_text (GTK_ENTRY (widget));
+	if (text && strlen (text) && g_strcmp0 (text, SUBJECT_NOTE) != 0)
+		g_object_set (s_8021x, NM_SETTING_802_1X_SUBJECT_MATCH, text, NULL);
+
 	nm_gconf_set_ignore_ca_cert (nm_setting_connection_get_uuid (s_con),
 	                             method->phase2,
 	                             eap_method_get_ignore_ca_cert (parent));
@@ -388,6 +401,43 @@ update_secrets (EAPMethod *parent, NMConnection *connection)
 	}
 }
 
+static gboolean
+subject_entry_focus_in_cb (GtkWidget *widget,
+                           GdkEvent  *event,
+                           gpointer user_data)
+{
+	const char *text = gtk_entry_get_text (GTK_ENTRY (widget));
+	if (g_strcmp0 (text, SUBJECT_NOTE) == 0) {
+		gtk_entry_set_text (GTK_ENTRY (widget), "");
+		gtk_widget_modify_text (GTK_WIDGET (widget), GTK_STATE_NORMAL, NULL);
+	}
+	return FALSE;
+}
+
+static gboolean
+subject_entry_focus_out_cb (GtkWidget *widget,
+                            GdkEvent  *event,
+                            gpointer user_data)
+{
+	NMSetting8021x *s_8021x = (NMSetting8021x *)user_data;
+	const char *text = gtk_entry_get_text (GTK_ENTRY (widget));
+	GtkStyle *style;
+
+	if (!text || !strlen (text)) {
+		/* Since we save/restore the subject in ws_802_1x_fill_connection()
+		 * to prevent the probed result from being erased, we have to clear
+		 * the subject here to trigger the probe later. */
+		g_object_set (s_8021x, NM_SETTING_802_1X_SUBJECT_MATCH, NULL, NULL);
+		gtk_entry_set_text (GTK_ENTRY (widget), SUBJECT_NOTE);
+		style = gtk_widget_get_style (widget);
+		gtk_widget_modify_text (GTK_WIDGET (widget),
+		                        GTK_STATE_NORMAL,
+		                        &style->text[GTK_STATE_INSENSITIVE]);
+	}
+
+	return FALSE;
+}
+
 EAPMethodTLS *
 eap_method_tls_new (const char *glade_file,
                     WirelessSecurity *parent,
@@ -482,6 +532,30 @@ eap_method_tls_new (const char *glade_file,
 	                  (GCallback) show_toggled_cb,
 	                  method);
 
+	widget = glade_xml_get_widget (xml, "eap_tls_subject_entry");
+	if (s_8021x) {
+		const char *text = nm_setting_802_1x_get_subject_match (s_8021x);
+		if (!text) {
+			GtkStyle *style;
+			style = gtk_widget_get_style (widget);
+			gtk_widget_modify_text (widget,
+			                        GTK_STATE_NORMAL,
+			                        &style->text[GTK_STATE_INSENSITIVE]);
+			gtk_entry_set_text (GTK_ENTRY (widget), SUBJECT_NOTE);
+		} else {
+			gtk_entry_set_text (GTK_ENTRY (widget), text);
+		}
+		g_signal_connect (G_OBJECT (widget), "focus-in-event",
+		                  (GCallback) subject_entry_focus_in_cb,
+		                  NULL);
+		g_signal_connect (G_OBJECT (widget), "focus-out-event",
+		                  (GCallback) subject_entry_focus_out_cb,
+		                  s_8021x);
+	}
+	g_signal_connect (G_OBJECT (widget), "changed",
+	                  (GCallback) wireless_security_changed_cb,
+	                  parent);
+
 	return method;
 }
 
openSUSE Build Service is sponsored by