diff options
author | Jiří Klimeš <jklimes@redhat.com> | 2015-06-15 11:00:31 +0200 |
---|---|---|
committer | Jiří Klimeš <jklimes@redhat.com> | 2015-06-15 12:05:26 +0200 |
commit | 3aa957cb2e393e63c6107321dcc80750514dd58f (patch) | |
tree | a2d6254bdcfa2dc73be164f6017a280fcc8a6e37 | |
parent | 759918585e23e8db89e6699b60a1da4cae1f290e (diff) | |
download | NetworkManager-jk/strip-cfg-values-rh1229861-nm-1-0.tar.gz |
config: strip trailing/leading white spaces from config values (rh #1229861)jk/strip-cfg-values-rh1229861-nm-1-0
https://bugzilla.redhat.com/show_bug.cgi?id=1229861
(cherry picked from commit 116a92183ce0eaaf383608d50e4fd9185671a621)
-rw-r--r-- | src/nm-config-data.c | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/nm-config-data.c b/src/nm-config-data.c index 0c4545d87f..87addb0d43 100644 --- a/src/nm-config-data.c +++ b/src/nm-config-data.c @@ -163,6 +163,20 @@ nm_config_data_get_assume_ipv6ll_only (const NMConfigData *self, NMDevice *devic /************************************************************************/ +static char * +_key_file_get_value_strip (GKeyFile *key_file, + const char *group_name, + const char *key, + GError **error) +{ + char *valstr; + + valstr = g_key_file_get_value (key_file, group_name, key, error); + if (valstr) + valstr = g_strstrip (valstr); + return valstr; +} + static gboolean _keyfile_a_contains_all_in_b (GKeyFile *kf_a, GKeyFile *kf_b) { @@ -179,8 +193,8 @@ _keyfile_a_contains_all_in_b (GKeyFile *kf_a, GKeyFile *kf_b) keys = g_key_file_get_keys (kf_a, groups[i], NULL, NULL); if (keys) { for (j = 0; keys[j]; j++) { - gs_free char *key_a = g_key_file_get_value (kf_a, groups[i], keys[j], NULL); - gs_free char *key_b = g_key_file_get_value (kf_b, groups[i], keys[j], NULL); + gs_free char *key_a = _key_file_get_value_strip (kf_a, groups[i], keys[j], NULL); + gs_free char *key_b = _key_file_get_value_strip (kf_b, groups[i], keys[j], NULL); if (g_strcmp0 (key_a, key_b) != 0) return FALSE; @@ -344,18 +358,18 @@ constructed (GObject *object) NMConfigDataPrivate *priv = NM_CONFIG_DATA_GET_PRIVATE (self); char *interval; - priv->connectivity.uri = g_key_file_get_value (priv->keyfile, "connectivity", "uri", NULL); - priv->connectivity.response = g_key_file_get_value (priv->keyfile, "connectivity", "response", NULL); + priv->connectivity.uri = _key_file_get_value_strip (priv->keyfile, "connectivity", "uri", NULL); + priv->connectivity.response = _key_file_get_value_strip (priv->keyfile, "connectivity", "response", NULL); /* On missing config value, fallback to 300. On invalid value, disable connectivity checking by setting * the interval to zero. */ - interval = g_key_file_get_value (priv->keyfile, "connectivity", "interval", NULL); + interval = _key_file_get_value_strip (priv->keyfile, "connectivity", "interval", NULL); priv->connectivity.interval = interval ? nm_utils_ascii_str_to_int64 (interval, 10, 0, G_MAXUINT, 0) : NM_CONFIG_DEFAULT_CONNECTIVITY_INTERVAL; g_free (interval); - priv->dns_mode = g_key_file_get_value (priv->keyfile, "main", "dns", NULL); + priv->dns_mode = _key_file_get_value_strip (priv->keyfile, "main", "dns", NULL); priv->ignore_carrier = nm_config_get_device_match_spec (priv->keyfile, "main", "ignore-carrier"); priv->assume_ipv6ll_only = nm_config_get_device_match_spec (priv->keyfile, "main", "assume-ipv6ll-only"); |