summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2010-06-25 09:56:53 -0700
committerDan Williams <dcbw@redhat.com>2010-06-25 09:57:54 -0700
commit95ded22a4f8ac51702262c4a15eccddad4dbbf3d (patch)
treeae43c34d692ef5e93116dc5bba365c314cc3fb8a
parent00a9f4ac71b0f992ea5c7f57d0c8c855215fcffc (diff)
downloadNetworkManager-95ded22a4f8ac51702262c4a15eccddad4dbbf3d.tar.gz
ifcfg-rh: ensure SSIDs don't get double-quoted when written out (rh #606518)
-rw-r--r--system-settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c18
-rw-r--r--system-settings/plugins/ifcfg-rh/writer.c17
2 files changed, 30 insertions, 5 deletions
diff --git a/system-settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/system-settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
index 59d32bcdce..a755eb5d5a 100644
--- a/system-settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
+++ b/system-settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
@@ -5044,6 +5044,8 @@ test_write_wifi_open (void)
guint32 channel = 9, mtu = 1345;
GByteArray *mac;
const unsigned char mac_data[] = { 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };
+ shvarFile *ifcfg;
+ char *tmp;
connection = nm_connection_new ();
ASSERT (connection != NULL,
@@ -5127,6 +5129,22 @@ test_write_wifi_open (void)
&routefile,
&error,
&ignore_error);
+
+ /* Now make sure that the ESSID item isn't double-quoted (rh #606518) */
+ ifcfg = svNewFile (testfile);
+ ASSERT (ifcfg != NULL,
+ "wifi-open-write-reread", "failed to load %s as shvarfile", testfile);
+
+ tmp = svGetValue (ifcfg, "ESSID", TRUE);
+ ASSERT (tmp != NULL,
+ "wifi-open-write-reread", "failed to read ESSID key from %s", testfile);
+
+ g_message (tmp);
+ ASSERT (strncmp (tmp, "\"\"", 2) != 0,
+ "wifi-open-write-reread", "unexpected ESSID double-quote in %s", testfile);
+
+ svCloseFile (ifcfg);
+
unlink (testfile);
ASSERT (reread != NULL,
diff --git a/system-settings/plugins/ifcfg-rh/writer.c b/system-settings/plugins/ifcfg-rh/writer.c
index b870662b62..bd3b6bd31e 100644
--- a/system-settings/plugins/ifcfg-rh/writer.c
+++ b/system-settings/plugins/ifcfg-rh/writer.c
@@ -746,13 +746,20 @@ write_wireless_setting (NMConnection *connection,
svSetValue (ifcfg, "ESSID", str->str, TRUE);
g_string_free (str, TRUE);
} else {
- /* Printable SSIDs get quoted */
+ /* Printable SSIDs always get quoted */
memset (buf, 0, sizeof (buf));
memcpy (buf, ssid->data, ssid->len);
- tmp2 = svEscape (buf);
- tmp = g_strdup_printf ("\"%s\"", tmp2);
- svSetValue (ifcfg, "ESSID", tmp, TRUE);
- g_free (tmp2);
+ tmp = svEscape (buf);
+
+ /* svEscape will usually quote the string, but just for consistency,
+ * if svEscape doesn't quote the ESSID, we quote it ourselves.
+ */
+ if (tmp[0] != '"' && tmp[strlen (tmp) - 1] != '"') {
+ tmp2 = g_strdup_printf ("\"%s\"", tmp);
+ svSetValue (ifcfg, "ESSID", tmp2, TRUE);
+ g_free (tmp2);
+ } else
+ svSetValue (ifcfg, "ESSID", tmp, TRUE);
g_free (tmp);
}