libnm-core: don't serialize synthetic properties in nm_setting_to_string()

Fixes: f957ea2b34

https://github.com/NetworkManager/NetworkManager/pull/245
This commit is contained in:
Lubomir Rintel
2018-11-02 10:33:27 +01:00
parent 32857a093b
commit 395c385b9b
3 changed files with 19 additions and 4 deletions

View File

@@ -121,6 +121,8 @@ typedef enum { /*< flags >*/
NM_CONNECTION_SERIALIZE_ALL = 0x00000000, NM_CONNECTION_SERIALIZE_ALL = 0x00000000,
NM_CONNECTION_SERIALIZE_NO_SECRETS = 0x00000001, NM_CONNECTION_SERIALIZE_NO_SECRETS = 0x00000001,
NM_CONNECTION_SERIALIZE_ONLY_SECRETS = 0x00000002, NM_CONNECTION_SERIALIZE_ONLY_SECRETS = 0x00000002,
/* 0x80000000 is used for a private flag */
} NMConnectionSerializationFlags; } NMConnectionSerializationFlags;
GVariant *nm_connection_to_dbus (NMConnection *connection, GVariant *nm_connection_to_dbus (NMConnection *connection,

View File

@@ -174,6 +174,13 @@ NMSettingPriority _nm_setting_get_setting_priority (NMSetting *setting);
gboolean _nm_setting_get_property (NMSetting *setting, const char *name, GValue *value); 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, GHashTable *_nm_setting_gendata_hash (NMSetting *setting,

View File

@@ -685,10 +685,15 @@ _nm_setting_to_dbus (NMSetting *setting, NMConnection *connection, NMConnectionS
continue; continue;
} }
if (property->synth_func) if (property->synth_func) {
if (!(flags & NM_CONNECTION_SERIALIZE_NO_SYNTH))
dbus_value = property->synth_func (setting, connection, property->name); dbus_value = property->synth_func (setting, connection, property->name);
else else
dbus_value = NULL;
} else {
dbus_value = get_property_for_dbus (setting, property, TRUE); dbus_value = get_property_for_dbus (setting, property, TRUE);
}
if (dbus_value) { if (dbus_value) {
/* Allow dbus_value to be either floating or not. */ /* Allow dbus_value to be either floating or not. */
g_variant_take_ref (dbus_value); 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)); string = g_string_new (nm_setting_get_name (setting));
g_string_append_c (string, '\n'); 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); g_variant_iter_init (&iter, variant);
while ((child = g_variant_iter_next_value (&iter))) { while ((child = g_variant_iter_next_value (&iter))) {