diff options
Diffstat (limited to 'src/settings/plugins/ifnet/wpa_parser.c')
| -rw-r--r-- | src/settings/plugins/ifnet/wpa_parser.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/settings/plugins/ifnet/wpa_parser.c b/src/settings/plugins/ifnet/wpa_parser.c index da2bc3bb..0fd7d16b 100644 --- a/src/settings/plugins/ifnet/wpa_parser.c +++ b/src/settings/plugins/ifnet/wpa_parser.c @@ -124,7 +124,7 @@ add_key_value (GHashTable * network, gchar * line) g_strstrip (key_value[0]); g_strstrip (key_value[1]); - /* Reserve quotes for psk, wep_key, ssid + /* Reserve quotes for psk, wep_key, ssid * Quotes will determine whether they are hex format */ if (strcmp (key_value[0], "psk") != 0 && !g_str_has_prefix (key_value[0], "wep_key") @@ -162,7 +162,7 @@ add_one_wep_key (GHashTable * table, int key_num, gchar * one_wep_key) } } -/* Reading wep security information from /etc/conf.d/net. +/* Reading wep security information from /etc/conf.d/net. * This should not be used in futre, use wpa_supplicant instead. */ static void add_keys_from_net () @@ -279,16 +279,21 @@ wpa_parser_init (const char *wpa_supplicant_conf) } else { GHashTable *network = g_hash_table_new (g_str_hash, g_str_equal); - gchar *tmp; do { + gchar *quote_start, *quote_end = NULL, *comment; + if (line[0] == '#' || line[0] == '\0') { g_free (line); continue; } - /* ignore inline comments */ - if ((tmp = strchr (line, '#')) != NULL) - *tmp = '\0'; + /* ignore inline comments unless inside + a double-quoted string */ + if ((quote_start = strchr (line, '"')) != NULL) + quote_end = strrchr (quote_start + 1, '"'); + if ((comment = strchr ((quote_end != NULL) ? + quote_end : line, '#')) != NULL) + *comment = '\0'; if (strstr (line, "}") != NULL) complete = TRUE; add_key_value (network, line); @@ -371,6 +376,8 @@ wpa_flush_to_file (const char *config_file) if (!wsec_table || !wsec_global_table) return FALSE; + backup_file (config_file); + channel = g_io_channel_new_file (config_file, "w", NULL); if (!channel) { PLUGIN_WARN (IFNET_PLUGIN_NAME, |