[network-manager-vpnc] properties: save group password and flags



commit 6a6b506494d14356be12314876fab1bdc3327334
Author: Dan Williams <dcbw redhat com>
Date:   Thu Jul 14 17:25:48 2011 -0500

    properties: save group password and flags
    
    Save the group password (if provided) and whether or not the group
    password should be saved or always asked for.

 properties/nm-vpnc.c                  |   40 ++++++++++++++++++++++++++++++++-
 properties/tests/test-import-export.c |   31 +++++++------------------
 2 files changed, 48 insertions(+), 23 deletions(-)
---
diff --git a/properties/nm-vpnc.c b/properties/nm-vpnc.c
index a87fbdf..271fccf 100644
--- a/properties/nm-vpnc.c
+++ b/properties/nm-vpnc.c
@@ -1128,6 +1128,25 @@ import (NMVpnPluginUiInterface *iface, const char *path, GError **error)
 		}
 	}
 
+	/* Group Password Flags */
+	if (pcf_file_lookup_bool (pcf, "main", "X-NM-SaveGroupPassword", &bool_value)) {
+		NMSettingSecretFlags flags = NM_SETTING_SECRET_FLAG_AGENT_OWNED;
+
+		if (bool_value) {
+			nm_setting_vpn_add_data_item (s_vpn,
+			                              NM_VPNC_KEY_SECRET_TYPE,
+			                              NM_VPNC_PW_TYPE_SAVE);
+		} else
+			flags |= NM_SETTING_SECRET_FLAG_NOT_SAVED;
+
+		nm_setting_set_secret_flags (NM_SETTING (s_vpn), NM_VPNC_KEY_SECRET, flags, NULL);
+	} else {
+		/* If the key isn't present, assume "saved" */
+		nm_setting_vpn_add_data_item (s_vpn,
+		                              NM_VPNC_KEY_SECRET_TYPE,
+		                              NM_VPNC_PW_TYPE_SAVE);
+	}
+
 	if (pcf_file_lookup_string (pcf, "main", "NTDomain", &buf))
 		nm_setting_vpn_add_data_item (s_vpn, NM_VPNC_KEY_DOMAIN, buf);
 
@@ -1253,11 +1272,13 @@ export (NMVpnPluginUiInterface *iface,
 	const char *domain = NULL;
 	const char *peertimeout = NULL;
 	const char *dhgroup = NULL;
+	const char *group_pw = NULL;
 	GString *routes = NULL;
 	GString *uselegacyikeport = NULL;
 	gboolean success = FALSE;
 	guint32 routes_count = 0;
 	gboolean save_password = FALSE;
+	gboolean save_group_password = FALSE;
 	gboolean use_natt = FALSE;
 	gboolean use_force_natt = FALSE;
 	NMSettingSecretFlags flags = NM_SETTING_SECRET_FLAG_NONE;
@@ -1336,6 +1357,20 @@ export (NMVpnPluginUiInterface *iface,
 		}
 	}
 
+	/* Group password stuff */
+	if (nm_setting_get_secret_flags (NM_SETTING (s_vpn), NM_VPNC_KEY_SECRET, &flags, NULL)) {
+		if (!(flags & NM_SETTING_SECRET_FLAG_NOT_SAVED))
+			save_group_password = TRUE;
+	} else {
+		value = nm_setting_vpn_get_data_item (s_vpn, NM_VPNC_KEY_SECRET_TYPE);
+		if (value && strlen (value)) {
+			if (!strcmp (value, NM_VPNC_PW_TYPE_SAVE))
+				save_group_password = TRUE;
+		}
+	}
+	if (save_group_password)
+		group_pw = nm_setting_vpn_get_secret (s_vpn, NM_VPNC_KEY_SECRET);
+
 	routes = g_string_new ("X-NM-Routes=");
 	if (s_ip4 && nm_setting_ip4_config_get_num_routes (s_ip4)) {
 		int i;
@@ -1371,7 +1406,7 @@ export (NMVpnPluginUiInterface *iface,
 		 "Host=%s\n"
 		 "AuthType=1\n"
 		 "GroupName=%s\n"
-		 "GroupPwd=\n"
+		 "GroupPwd=%s\n"
 		 "EnableISPConnect=0\n"
 		 "ISPConnectType=0\n"
 		 "ISPConnect=\n"
@@ -1406,10 +1441,12 @@ export (NMVpnPluginUiInterface *iface,
 		 "%s"
 		 "X-NM-Use-NAT-T=%s\n"
 		 "X-NM-Force-NAT-T=%s\n"
+		 "X-NM-SaveGroupPassword=%s\n"
 		 "%s\n",
 		 /* Description */   nm_setting_connection_get_id (s_con),
 		 /* Host */          gateway,
 		 /* GroupName */     groupname,
+		 /* GroupPassword */ group_pw ? group_pw : "",
 		 /* Username */      username != NULL ? username : "",
 		 /* Save Password */ save_password ? "1" : "0",
 		 /* EnableNat */     enablenat ? "1" : "0",
@@ -1420,6 +1457,7 @@ export (NMVpnPluginUiInterface *iface,
 		 /* UseLegacyIKEPort */ (uselegacyikeport->len) ? uselegacyikeport->str : "",
 		 /* X-NM-Use-NAT-T */ use_natt ? "1" : "0",
 		 /* X-NM-Force-NAT-T */ use_force_natt ? "1" : "0",
+		 /* X-NM-SaveGroupPassword */ save_group_password ? "1" : "0",
 		 /* X-NM-Routes */   (routes && routes->str) ? routes->str : "");
 
 	success = TRUE;
diff --git a/properties/tests/test-import-export.c b/properties/tests/test-import-export.c
index aa3eade..628d026 100644
--- a/properties/tests/test-import-export.c
+++ b/properties/tests/test-import-export.c
@@ -50,9 +50,9 @@ item_count_func (const char *key, const char *value, gpointer user_data)
 }
 
 static void
-test_items (const char *detail, NMSettingVPN *s_vpn, Item *items, gboolean secrets)
+test_items (const char *detail, NMSettingVPN *s_vpn, const Item *items, gboolean secrets)
 {
-	Item *iter;
+	const Item *iter;
 	guint32 expected_count = 0, actual_count = 0;
 	const char *value;
 
@@ -82,10 +82,10 @@ test_items (const char *detail, NMSettingVPN *s_vpn, Item *items, gboolean secre
 }
 
 
-static Item basic_items[] = {
+static const Item basic_items[] = {
 	{ NM_VPNC_KEY_GATEWAY,               "10.20.30.40" },
 	{ NM_VPNC_KEY_ID,                    "blahblah" },
-	{ NM_VPNC_KEY_SECRET_TYPE,           NULL },
+	{ NM_VPNC_KEY_SECRET_TYPE,           NM_VPNC_PW_TYPE_SAVE },
 	{ NM_VPNC_KEY_XAUTH_USER,            "bsmith" },
 	{ NM_VPNC_KEY_XAUTH_PASSWORD_TYPE,   NM_VPNC_PW_TYPE_SAVE },
 	{ NM_VPNC_KEY_DOMAIN,                "COMPANY" },
@@ -240,29 +240,16 @@ test_basic_import (NMVpnPluginUiInterface *plugin, const char *dir)
 }
 
 static void
-save_one_key (const char *key, const char *value, gpointer user_data)
-{
-	GSList **list = user_data;
-
-	*list = g_slist_append (*list, g_strdup (key));
-}
-
-static void
-remove_secrets (NMConnection *connection)
+remove_user_password (NMConnection *connection)
 {
 	NMSettingVPN *s_vpn;
-	GSList *keys = NULL, *iter;
 
 	s_vpn = (NMSettingVPN *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN);
 	if (!s_vpn)
 		return;
 
-	nm_setting_vpn_foreach_secret (s_vpn, save_one_key, &keys);
-	for (iter = keys; iter; iter = g_slist_next (iter))
-		nm_setting_vpn_remove_secret (s_vpn, (const char *) iter->data);
-
-	g_slist_foreach (keys, (GFunc) g_free, NULL);
-	g_slist_free (keys);
+	if (nm_setting_vpn_get_secret (s_vpn, NM_VPNC_KEY_XAUTH_PASSWORD))
+		nm_setting_vpn_remove_secret (s_vpn, NM_VPNC_KEY_XAUTH_PASSWORD);
 }
 
 #define BASIC_EXPORTED_NAME "basic-export-test.pcf"
@@ -297,7 +284,7 @@ test_basic_export (NMVpnPluginUiInterface *plugin, const char *dir, const char *
 	/* Clear secrets first, since they don't get exported, and thus would
 	 * make the connection comparison below fail.
 	 */
-	remove_secrets (connection);
+	remove_user_password (connection);
 
 	/* Since we don't export the user password, but the original connection
 	 * had one, we need to add secret flags to the re-imported connection.
@@ -356,7 +343,7 @@ test_nat_export (NMVpnPluginUiInterface *plugin,
 	/* Clear secrets first, since they don't get exported, and thus would
 	 * make the connection comparison below fail.
 	 */
-	remove_secrets (connection);
+	remove_user_password (connection);
 
 	/* Since we don't export the user password, but the original connection
 	 * had one, we need to add secret flags to the re-imported connection.



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