summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-08-24 09:59:06 +0200
committerThomas Haller <thaller@redhat.com>2016-08-24 10:58:02 +0200
commit476810c29016d569ac3885542a6c91e7af8a7f6d (patch)
tree41cdc9e3e6f77f37f6fb6114686b974b7ba6e9d8
parent0fc8b856c37374daaf3ec4d95e25e2e670d8d3f5 (diff)
downloadNetworkManager-476810c29016d569ac3885542a6c91e7af8a7f6d.tar.gz
libnm-core/team: normalize invalid config to NULL
A user may very well have connections on disk with bogus json. Such connections may have failed to activate before, but rejecting them now as invalid means that we stop loading them from disk. That is, they disappear after upgrade. Instead of doing that, also accept invalid json (beside "") and normalize/coerce it to NULL. https://bugzilla.redhat.com/show_bug.cgi?id=1366300
-rw-r--r--libnm-core/nm-connection.c5
-rw-r--r--libnm-core/nm-setting-team-port.c12
-rw-r--r--libnm-core/nm-setting-team.c12
3 files changed, 23 insertions, 6 deletions
diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c
index 57f964095e..f39d41c58e 100644
--- a/libnm-core/nm-connection.c
+++ b/libnm-core/nm-connection.c
@@ -28,6 +28,7 @@
#include "nm-connection.h"
#include "nm-connection-private.h"
#include "nm-utils.h"
+#include "nm-utils-private.h"
#include "nm-setting-private.h"
#include "nm-core-internal.h"
@@ -915,7 +916,7 @@ _normalize_team_config (NMConnection *self, GHashTable *parameters)
if (s_team) {
const char *config = nm_setting_team_get_config (s_team);
- if (config && !*config) {
+ if (config && !_nm_utils_check_valid_json (config, NULL)) {
g_object_set (s_team, NM_SETTING_TEAM_CONFIG, NULL, NULL);
return TRUE;
}
@@ -931,7 +932,7 @@ _normalize_team_port_config (NMConnection *self, GHashTable *parameters)
if (s_team_port) {
const char *config = nm_setting_team_port_get_config (s_team_port);
- if (config && !*config) {
+ if (config && !_nm_utils_check_valid_json (config, NULL)) {
g_object_set (s_team_port, NM_SETTING_TEAM_PORT_CONFIG, NULL, NULL);
return TRUE;
}
diff --git a/libnm-core/nm-setting-team-port.c b/libnm-core/nm-setting-team-port.c
index 123304fee6..0d175d5ebd 100644
--- a/libnm-core/nm-setting-team-port.c
+++ b/libnm-core/nm-setting-team-port.c
@@ -122,11 +122,19 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
"%s.%s: ",
NM_SETTING_TEAM_PORT_SETTING_NAME,
NM_SETTING_TEAM_PORT_CONFIG);
- /* We treat an empty string as no config for compatibility. */
- return *priv->config ? FALSE : NM_SETTING_VERIFY_NORMALIZABLE;
+ /* for backward compatibility, we accept invalid json and normalize it */
+ if (!priv->config[0]) {
+ /* be more forgiving to "" and let it verify() as valid because
+ * at least anaconda used to write such configs */
+ return NM_SETTING_VERIFY_NORMALIZABLE;
+ }
+ return NM_SETTING_VERIFY_NORMALIZABLE_ERROR;
}
}
+ /* NOTE: normalizable/normalizable-errors must appear at the end with decreasing severity.
+ * Take care to properly order statements with priv->config above. */
+
return TRUE;
}
diff --git a/libnm-core/nm-setting-team.c b/libnm-core/nm-setting-team.c
index df89694f66..a559e0db78 100644
--- a/libnm-core/nm-setting-team.c
+++ b/libnm-core/nm-setting-team.c
@@ -94,11 +94,19 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
"%s.%s: ",
NM_SETTING_TEAM_SETTING_NAME,
NM_SETTING_TEAM_CONFIG);
- /* We treat an empty string as no config for compatibility. */
- return *priv->config ? FALSE : NM_SETTING_VERIFY_NORMALIZABLE;
+ /* for backward compatibility, we accept invalid json and normalize it */
+ if (!priv->config[0]) {
+ /* be more forgiving to "" and let it verify() as valid because
+ * at least anaconda used to write such configs */
+ return NM_SETTING_VERIFY_NORMALIZABLE;
+ }
+ return NM_SETTING_VERIFY_NORMALIZABLE_ERROR;
}
}
+ /* NOTE: normalizable/normalizable-errors must appear at the end with decreasing severity.
+ * Take care to properly order statements with priv->config above. */
+
return TRUE;
}