Blame SOURCES/1002-cli-fix-reading-vpn.secrets.-from-passwd-file.patch

52f25a
From 948a03d2a28dae7bb975f6e64dc7b5a31f10d5b9 Mon Sep 17 00:00:00 2001
52f25a
From: Thomas Haller <thaller@redhat.com>
52f25a
Date: Fri, 14 Sep 2018 11:13:05 +0200
52f25a
Subject: [PATCH 1/1] cli: fix reading "vpn.secrets.*" from passwd-file
52f25a
52f25a
Due to a bug, we required VPN secrets to be prefixed with
52f25a
"vpn.secret." instead of "vpn.secrets.". This was a change
52f25a
in behavior with 1.12.0 release.
52f25a
52f25a
Fix it, to restore the old behavior. For backward compatibility
52f25a
to the broken behavior, adjust parse_passwords() to treat accept
52f25a
that as well.
52f25a
52f25a
https://bugzilla.redhat.com/show_bug.cgi?id=1628833
52f25a
https://github.com/NetworkManager/NetworkManager/pull/201
52f25a
52f25a
Fixes: 0601b5d725b072bd3ce4ec60be867898a16f85cd
52f25a
(cherry picked from commit 5815ae8c60961f088e4e54b41ddf8254cb83574a)
52f25a
(cherry picked from commit 6bfab6796f064c4f878e05476a60cd59fa8bf11e)
52f25a
(cherry picked from commit 10888abe96fedd3d6c5b99faea76465522f8e8e9)
52f25a
---
52f25a
 clients/cli/common.c                    |  6 +++---
52f25a
 clients/cli/connections.c               | 10 +++++++++-
52f25a
 clients/common/nm-secret-agent-simple.c |  2 +-
52f25a
 clients/common/nm-secret-agent-simple.h |  2 +-
52f25a
 clients/tui/nmtui-connect.c             |  6 +++---
52f25a
 5 files changed, 17 insertions(+), 9 deletions(-)
52f25a
52f25a
diff --git a/clients/cli/common.c b/clients/cli/common.c
52f25a
index 09c86334a..4aea0d5b2 100644
52f25a
--- a/clients/cli/common.c
52f25a
+++ b/clients/cli/common.c
52f25a
@@ -630,13 +630,13 @@ vpn_openconnect_get_secrets (NMConnection *connection, GPtrArray *secrets)
52f25a
 		if (!nm_streq0 (secret->vpn_type, NM_SECRET_AGENT_VPN_TYPE_OPENCONNECT))
52f25a
 			continue;
52f25a
 
52f25a
-		if (nm_streq0 (secret->entry_id, NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRET "cookie")) {
52f25a
+		if (nm_streq0 (secret->entry_id, NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRETS "cookie")) {
52f25a
 			g_free (secret->value);
52f25a
 			secret->value = g_steal_pointer (&cookie);
52f25a
-		} else if (nm_streq0 (secret->entry_id, NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRET "gateway")) {
52f25a
+		} else if (nm_streq0 (secret->entry_id, NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRETS "gateway")) {
52f25a
 			g_free (secret->value);
52f25a
 			secret->value = g_steal_pointer (&gateway);
52f25a
-		} else if (nm_streq0 (secret->entry_id, NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRET "gwcert")) {
52f25a
+		} else if (nm_streq0 (secret->entry_id, NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRETS "gwcert")) {
52f25a
 			g_free (secret->value);
52f25a
 			secret->value = g_steal_pointer (&gwcert);
52f25a
 		}
52f25a
diff --git a/clients/cli/connections.c b/clients/cli/connections.c
52f25a
index 1563178de..b547e34ca 100644
52f25a
--- a/clients/cli/connections.c
52f25a
+++ b/clients/cli/connections.c
52f25a
@@ -2565,7 +2565,15 @@ parse_passwords (const char *passwd_file, GError **error)
52f25a
 			return NULL;
52f25a
 		}
52f25a
 
52f25a
-		pwd_spec = g_strdup_printf ("%s.%s", setting, prop);
52f25a
+		if (   nm_streq (setting, "vpn")
52f25a
+		    && g_str_has_prefix (prop, "secret.")) {
52f25a
+			/* in 1.12.0, we wrongly required the VPN secrets to be named
52f25a
+			 * "vpn.secret". It should be "vpn.secrets". Work around it
52f25a
+			 * (rh#1628833). */
52f25a
+			pwd_spec = g_strdup_printf ("vpn.secrets.%s", &prop[NM_STRLEN ("secret.")]);
52f25a
+		} else
52f25a
+			pwd_spec = g_strdup_printf ("%s.%s", setting, prop);
52f25a
+
52f25a
 		g_hash_table_insert (pwds_hash, pwd_spec, g_strdup (pwd));
52f25a
 	}
52f25a
 	return g_steal_pointer (&pwds_hash);
52f25a
diff --git a/clients/common/nm-secret-agent-simple.c b/clients/common/nm-secret-agent-simple.c
52f25a
index 0856b51ff..3df8c0386 100644
52f25a
--- a/clients/common/nm-secret-agent-simple.c
52f25a
+++ b/clients/common/nm-secret-agent-simple.c
52f25a
@@ -195,7 +195,7 @@ nm_secret_agent_simple_secret_new (NMSecretAgentSecretType secret_type,
52f25a
 		real->base.is_secret = (secret_type != NM_SECRET_AGENT_SECRET_TYPE_PROPERTY);
52f25a
 		break;
52f25a
 	case NM_SECRET_AGENT_SECRET_TYPE_VPN_SECRET:
52f25a
-		vpn_prefix = NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRET;
52f25a
+		vpn_prefix = NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRETS;
52f25a
 		value = nm_setting_vpn_get_secret (NM_SETTING_VPN (setting), property);
52f25a
 		real->base.entry_id = g_strdup_printf ("%s%s", vpn_prefix, property);
52f25a
 		nm_assert (vpn_type);
52f25a
diff --git a/clients/common/nm-secret-agent-simple.h b/clients/common/nm-secret-agent-simple.h
52f25a
index 505987dfd..529aaeaca 100644
52f25a
--- a/clients/common/nm-secret-agent-simple.h
52f25a
+++ b/clients/common/nm-secret-agent-simple.h
52f25a
@@ -56,7 +56,7 @@ typedef struct {
52f25a
 	gboolean is_secret;
52f25a
 } NMSecretAgentSimpleSecret;
52f25a
 
52f25a
-#define NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRET "vpn.secret."
52f25a
+#define NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRETS "vpn.secrets."
52f25a
 
52f25a
 #define NM_SECRET_AGENT_VPN_TYPE_OPENCONNECT  NM_DBUS_INTERFACE".openconnect"
52f25a
 
52f25a
diff --git a/clients/tui/nmtui-connect.c b/clients/tui/nmtui-connect.c
52f25a
index 2a954fb8c..6f29e13e9 100644
52f25a
--- a/clients/tui/nmtui-connect.c
52f25a
+++ b/clients/tui/nmtui-connect.c
52f25a
@@ -121,13 +121,13 @@ secrets_requested (NMSecretAgentSimple *agent,
52f25a
 					continue;
52f25a
 				if (!nm_streq0 (secret->vpn_type, NM_SECRET_AGENT_VPN_TYPE_OPENCONNECT))
52f25a
 					continue;
52f25a
-				if (nm_streq0 (secret->entry_id, NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRET "cookie")) {
52f25a
+				if (nm_streq0 (secret->entry_id, NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRETS "cookie")) {
52f25a
 					g_free (secret->value);
52f25a
 					secret->value = g_steal_pointer (&cookie);
52f25a
-				} else if (nm_streq0 (secret->entry_id, NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRET "gateway")) {
52f25a
+				} else if (nm_streq0 (secret->entry_id, NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRETS "gateway")) {
52f25a
 					g_free (secret->value);
52f25a
 					secret->value = g_steal_pointer (&gateway);
52f25a
-				} else if (nm_streq0 (secret->entry_id, NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRET "gwcert")) {
52f25a
+				} else if (nm_streq0 (secret->entry_id, NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRETS "gwcert")) {
52f25a
 					g_free (secret->value);
52f25a
 					secret->value = g_steal_pointer (&gwcert);
52f25a
 				}
52f25a
-- 
52f25a
2.17.1
52f25a