From 4f6eef9e77265484555663cf666cde4fa8323469 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 28 Sep 2009 13:34:42 -0700 Subject: [PATCH] ifcfg-rh: quote WPA passphrases when writing connections The reader requires passphrases to be quoted, but the writer wasn't doing that. Hex PSKs were fine though. --- system-settings/plugins/ifcfg-rh/writer.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/system-settings/plugins/ifcfg-rh/writer.c b/system-settings/plugins/ifcfg-rh/writer.c index b20fab5a33..e39d172b4b 100644 --- a/system-settings/plugins/ifcfg-rh/writer.c +++ b/system-settings/plugins/ifcfg-rh/writer.c @@ -645,8 +645,22 @@ write_wireless_security_setting (NMConnection *connection, g_string_free (str, TRUE); /* WPA Passphrase */ - psk = nm_setting_wireless_security_get_psk (s_wsec); - set_secret (ifcfg, "WPA_PSK", (wpa && psk) ? psk : NULL); + if (wpa) { + GString *quoted = NULL; + + psk = nm_setting_wireless_security_get_psk (s_wsec); + if (psk && (strlen (psk) != 64)) { + /* Quote the PSK since it's a passphrase */ + quoted = g_string_sized_new (strlen (psk) + 2); /* 2 for quotes */ + g_string_append_c (quoted, '"'); + g_string_append (quoted, psk); + g_string_append_c (quoted, '"'); + } + set_secret (ifcfg, "WPA_PSK", quoted ? quoted->str : psk); + if (quoted) + g_string_free (quoted, TRUE); + } else + set_secret (ifcfg, "WPA_PSK", NULL); return TRUE; }