[network-manager-vpnc] properties: fix handling of secret flags



commit f5930e88a23fb3076a5cf22ad9ef210b19861f61
Author: Dan Williams <dcbw redhat com>
Date:   Thu Mar 10 00:38:25 2011 -0600

    properties: fix handling of secret flags
    
    The wrong key name got written into the connection's data,
    which didn't pass validation.

 properties/nm-vpnc.c |   58 ++++++++++++++++++++++++++++++++++---------------
 1 files changed, 40 insertions(+), 18 deletions(-)
---
diff --git a/properties/nm-vpnc.c b/properties/nm-vpnc.c
index adc927c..05f70de 100644
--- a/properties/nm-vpnc.c
+++ b/properties/nm-vpnc.c
@@ -310,15 +310,17 @@ secret_flags_to_pw_type (NMSettingVPN *s_vpn, const char *key)
 			return NM_VPNC_PW_TYPE_UNUSED;
 		if (flags & NM_SETTING_SECRET_FLAG_NOT_SAVED)
 			return NM_VPNC_PW_TYPE_ASK;
+		return NM_VPNC_PW_TYPE_SAVE;
 	}
-	return NM_VPNC_PW_TYPE_SAVE;
+	return NULL;
 }
 
 static void
 init_one_pw_combo (VpncPluginUiWidget *self,
                    NMSettingVPN *s_vpn,
                    const char *combo_name,
-                   const char *key,
+                   const char *secret_key,
+                   const char *type_key,
                    const char *entry_name)
 {
 	VpncPluginUiWidgetPrivate *priv = VPNC_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
@@ -342,10 +344,11 @@ init_one_pw_combo (VpncPluginUiWidget *self,
 	}
 
 	store = gtk_list_store_new (1, G_TYPE_STRING);
-	if (s_vpn)
-		value = nm_setting_vpn_get_data_item (s_vpn, key);
-	if (!value)
-		value = secret_flags_to_pw_type (s_vpn, key);
+	if (s_vpn) {
+		value = secret_flags_to_pw_type (s_vpn, secret_key);
+		if (!value)
+			value = nm_setting_vpn_get_data_item (s_vpn, type_key);
+	}
 
 	gtk_list_store_append (store, &iter);
 	gtk_list_store_set (store, &iter, 0, _("Saved"), -1);
@@ -450,10 +453,18 @@ init_plugin_ui (VpncPluginUiWidget *self, NMConnection *connection, GError **err
 	 */
 	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");
+	init_one_pw_combo (self,
+	                   s_vpn,
+	                   "user_pass_type_combo",
+	                   NM_VPNC_KEY_XAUTH_PASSWORD,
+	                   NM_VPNC_KEY_XAUTH_PASSWORD_TYPE,
+	                   "user_password_entry");
+	init_one_pw_combo (self,
+	                   s_vpn,
+	                   "group_pass_type_combo",
+	                   NM_VPNC_KEY_SECRET,
+	                   NM_VPNC_KEY_SECRET_TYPE,
+	                   "group_password_entry");
 
 	widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "user_entry"));
 	g_return_val_if_fail (widget != NULL, FALSE);
@@ -587,18 +598,21 @@ get_widget (NMVpnPluginUiWidgetInterface *iface)
 }
 
 static guint32
-handle_one_pw_type (NMSettingVPN *s_vpn, GtkBuilder *builder, const char *name, const char *key)
+handle_one_pw_type (NMSettingVPN *s_vpn,
+                    GtkBuilder *builder,
+                    const char *combo_name,
+                    const char *secret_key,
+                    const char *type_key)
 {
 	NMSettingSecretFlags flags = NM_SETTING_SECRET_FLAG_NONE;
 	GtkWidget *widget;
 	guint32 pw_type;
 	const char *data_val = NULL;
 
-	widget = GTK_WIDGET (gtk_builder_get_object (builder, name));
-
-	nm_setting_get_secret_flags (NM_SETTING (s_vpn), key, &flags, NULL);
+	nm_setting_get_secret_flags (NM_SETTING (s_vpn), secret_key, &flags, NULL);
 	flags &= ~(NM_SETTING_SECRET_FLAG_NOT_SAVED | NM_SETTING_SECRET_FLAG_NOT_REQUIRED);
 
+	widget = GTK_WIDGET (gtk_builder_get_object (builder, combo_name));
 	pw_type = gtk_combo_box_get_active (GTK_COMBO_BOX (widget));
 	switch (pw_type) {
 	case PW_TYPE_SAVE:
@@ -616,8 +630,8 @@ handle_one_pw_type (NMSettingVPN *s_vpn, GtkBuilder *builder, const char *name,
 		break;
 	}
 
-	nm_setting_vpn_add_data_item (s_vpn, key, data_val);
-	nm_setting_set_secret_flags (NM_SETTING (s_vpn), key, flags, NULL);
+	nm_setting_vpn_add_data_item (s_vpn, type_key, data_val);
+	nm_setting_set_secret_flags (NM_SETTING (s_vpn), secret_key, flags, NULL);
 	return pw_type;
 }
 
@@ -711,8 +725,16 @@ update_connection (NMVpnPluginUiWidgetInterface *iface,
 		}
 	}
 
-	upw_type = handle_one_pw_type (s_vpn, priv->builder, "user_pass_type_combo", NM_VPNC_KEY_XAUTH_PASSWORD_TYPE);
-	gpw_type = handle_one_pw_type (s_vpn, priv->builder, "group_pass_type_combo", NM_VPNC_KEY_SECRET_TYPE);
+	upw_type = handle_one_pw_type (s_vpn,
+	                               priv->builder,
+	                               "user_pass_type_combo",
+	                               NM_VPNC_KEY_XAUTH_PASSWORD,
+	                               NM_VPNC_KEY_XAUTH_PASSWORD_TYPE);
+	gpw_type = handle_one_pw_type (s_vpn,
+	                               priv->builder,
+	                               "group_pass_type_combo",
+	                               NM_VPNC_KEY_SECRET,
+	                               NM_VPNC_KEY_SECRET_TYPE);
 
 	/* User password */
 	widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "user_password_entry"));



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