From bc80722484f8655ee17cb30d3dc22470dbfa7652 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Fri, 2 Nov 2018 10:33:27 +0100 Subject: [PATCH] libnm-core: don't serialize synthetic properties in nm_setting_to_string() Fixes: f957ea2b343828ad1fa2014bc7a4dedaf854f3bc https://github.com/NetworkManager/NetworkManager/pull/245 (cherry picked from commit 395c385b9b3dfd469c50144ab7a53b2adf72c2c8) --- libnm-core/nm-connection.h | 2 ++ libnm-core/nm-core-internal.h | 7 +++++++ libnm-core/nm-setting.c | 14 ++++++++++---- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/libnm-core/nm-connection.h b/libnm-core/nm-connection.h index 802f68ba5a..b6e00977d7 100644 --- a/libnm-core/nm-connection.h +++ b/libnm-core/nm-connection.h @@ -121,6 +121,8 @@ typedef enum { /*< flags >*/ NM_CONNECTION_SERIALIZE_ALL = 0x00000000, NM_CONNECTION_SERIALIZE_NO_SECRETS = 0x00000001, NM_CONNECTION_SERIALIZE_ONLY_SECRETS = 0x00000002, + + /* 0x80000000 is used for a private flag */ } NMConnectionSerializationFlags; GVariant *nm_connection_to_dbus (NMConnection *connection, diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h index f0d4e40f93..6a59d5be73 100644 --- a/libnm-core/nm-core-internal.h +++ b/libnm-core/nm-core-internal.h @@ -174,6 +174,13 @@ NMSettingPriority _nm_setting_get_setting_priority (NMSetting *setting); gboolean _nm_setting_get_property (NMSetting *setting, const char *name, GValue *value); +/* NM_CONNECTION_SERIALIZE_NO_SYNTH: This flag is passed to _nm_setting_to_dbus() + * by nm_setting_to_string() to let it know that it shouldn't serialize the + * synthetic properties. It wouldn't be able to do so, since the full connection + * is not available, only the setting alone. + */ +#define NM_CONNECTION_SERIALIZE_NO_SYNTH ((NMConnectionSerializationFlags) 0x80000000) + /*****************************************************************************/ GHashTable *_nm_setting_gendata_hash (NMSetting *setting, diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c index 6b9681b539..047391cee2 100644 --- a/libnm-core/nm-setting.c +++ b/libnm-core/nm-setting.c @@ -685,10 +685,15 @@ _nm_setting_to_dbus (NMSetting *setting, NMConnection *connection, NMConnectionS continue; } - if (property->synth_func) - dbus_value = property->synth_func (setting, connection, property->name); - else + if (property->synth_func) { + if (!(flags & NM_CONNECTION_SERIALIZE_NO_SYNTH)) + dbus_value = property->synth_func (setting, connection, property->name); + else + dbus_value = NULL; + } else { dbus_value = get_property_for_dbus (setting, property, TRUE); + } + if (dbus_value) { /* Allow dbus_value to be either floating or not. */ g_variant_take_ref (dbus_value); @@ -2013,7 +2018,8 @@ nm_setting_to_string (NMSetting *setting) string = g_string_new (nm_setting_get_name (setting)); g_string_append_c (string, '\n'); - variant = _nm_setting_to_dbus (setting, NULL, NM_CONNECTION_SERIALIZE_ALL); + variant = _nm_setting_to_dbus (setting, NULL, NM_CONNECTION_SERIALIZE_ALL + | NM_CONNECTION_SERIALIZE_NO_SYNTH); g_variant_iter_init (&iter, variant); while ((child = g_variant_iter_next_value (&iter))) {