From b34220a0844b02ff4efeee635e496e7d7f2ed4a2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 29 Jun 2021 22:28:07 +0200 Subject: [PATCH] libnm: explicitly ignore to-dbus for "name" property NM_SETTING_NAME is also a GObject property, but it's not supposed to be serialized to/from D-Bus. It also is irrelevant for comparison. Hence, it's operations are all NOPs. Make an explicit property type for that case instead of checking the GParamSpec flags. --- src/libnm-core-impl/nm-setting-private.h | 8 +++ src/libnm-core-impl/nm-setting.c | 70 +++++++++++++++--------- src/libnm-core-impl/tests/test-setting.c | 5 ++ 3 files changed, 58 insertions(+), 25 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-private.h b/src/libnm-core-impl/nm-setting-private.h index eb106b05ec..dd47e32158 100644 --- a/src/libnm-core-impl/nm-setting-private.h +++ b/src/libnm-core-impl/nm-setting-private.h @@ -280,6 +280,7 @@ gboolean _nm_setting_clear_secrets(NMSetting * setting, */ #define NM_SETTING_PARAM_TO_DBUS_IGNORE_FLAGS (1 << (7 + G_PARAM_USER_SHIFT)) +extern const NMSettInfoPropertType nm_sett_info_propert_type_setting_name; extern const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_interface_name; extern const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_ignore_i; extern const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_ignore_u; @@ -342,6 +343,13 @@ void _nm_setting_property_set_property_direct(GObject * object, const GValue *value, GParamSpec * pspec); +GVariant *_nm_setting_property_to_dbus_fcn_ignore(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty * property_info, + NMConnection * connection, + NMSetting * setting, + NMConnectionSerializationFlags flags, + const NMConnectionSerializationOptions *options); + GVariant *_nm_setting_property_to_dbus_fcn_gprop(const NMSettInfoSetting * sett_info, const NMSettInfoProperty * property_info, NMConnection * connection, diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index 69cef95229..ee55e1249f 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -390,11 +390,11 @@ _nm_setting_class_commit(NMSettingClass * setting_class, G_VARIANT_TYPE_UINT64, .compare_fcn = _nm_setting_property_compare_fcn_default); else if (vtype == G_TYPE_STRING) { - if (nm_streq(p->name, NM_SETTING_NAME)) { - p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( - G_VARIANT_TYPE_STRING, - .compare_fcn = _nm_setting_property_compare_fcn_ignore); - } else { + nm_assert(nm_streq(p->name, NM_SETTING_NAME) + == (!NM_FLAGS_HAS(p->param_spec->flags, G_PARAM_WRITABLE))); + if (!NM_FLAGS_HAS(p->param_spec->flags, G_PARAM_WRITABLE)) + p->property_type = &nm_sett_info_propert_type_setting_name; + else { p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( G_VARIANT_TYPE_STRING, .compare_fcn = _nm_setting_property_compare_fcn_default); @@ -928,6 +928,17 @@ _nm_setting_property_to_dbus_fcn_direct(const NMSettInfoSetting * } } +GVariant * +_nm_setting_property_to_dbus_fcn_ignore(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty * property_info, + NMConnection * connection, + NMSetting * setting, + NMConnectionSerializationFlags flags, + const NMConnectionSerializationOptions *options) +{ + return NULL; +} + GVariant * _nm_setting_property_to_dbus_fcn_gprop(const NMSettInfoSetting * sett_info, const NMSettInfoProperty * property_info, @@ -996,13 +1007,12 @@ property_to_dbus(const NMSettInfoSetting * sett_info, return NULL; } - if (property_info->param_spec - && (!ignore_flags - && !NM_FLAGS_HAS(property_info->param_spec->flags, - NM_SETTING_PARAM_TO_DBUS_IGNORE_FLAGS))) { - if (!NM_FLAGS_HAS(property_info->param_spec->flags, G_PARAM_WRITABLE)) - return NULL; + nm_assert(!property_info->param_spec + || NM_FLAGS_HAS(property_info->param_spec->flags, G_PARAM_WRITABLE) + || property_info->property_type == &nm_sett_info_propert_type_setting_name); + if (property_info->param_spec && !ignore_flags + && !NM_FLAGS_HAS(property_info->param_spec->flags, NM_SETTING_PARAM_TO_DBUS_IGNORE_FLAGS)) { if (NM_FLAGS_HAS(property_info->param_spec->flags, NM_SETTING_PARAM_LEGACY) && !_nm_utils_is_manager_process) return NULL; @@ -1286,9 +1296,12 @@ init_from_dbus(NMSetting * setting, gs_unref_variant GVariant *value = NULL; gs_free_error GError *local = NULL; - if (property_info->param_spec && !(property_info->param_spec->flags & G_PARAM_WRITABLE)) + if (property_info->property_type == &nm_sett_info_propert_type_setting_name) continue; + nm_assert(!property_info->param_spec + || NM_FLAGS_HAS(property_info->param_spec->flags, G_PARAM_WRITABLE)); + value = g_variant_lookup_value(setting_dict, property_info->name, NULL); if (!value) { @@ -1505,21 +1518,23 @@ duplicate_copy_properties(const NMSettInfoSetting *sett_info, NMSetting *src, NM for (i = 0; i < sett_info->property_infos_len; i++) { const NMSettInfoProperty *property_info = &sett_info->property_infos[i]; - if (property_info->param_spec) { - if ((property_info->param_spec->flags & (G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)) - != G_PARAM_WRITABLE) - continue; - - if (!frozen) { - g_object_freeze_notify(G_OBJECT(dst)); - frozen = TRUE; - } - _gobject_copy_property(G_OBJECT(src), - G_OBJECT(dst), - property_info->param_spec->name, - G_PARAM_SPEC_VALUE_TYPE(property_info->param_spec)); + if (!property_info->param_spec) continue; + + nm_assert(!NM_FLAGS_HAS(property_info->param_spec->flags, G_PARAM_CONSTRUCT_ONLY)); + if (property_info->property_type == &nm_sett_info_propert_type_setting_name) + continue; + + nm_assert(NM_FLAGS_HAS(property_info->param_spec->flags, G_PARAM_WRITABLE)); + + if (!frozen) { + g_object_freeze_notify(G_OBJECT(dst)); + frozen = TRUE; } + _gobject_copy_property(G_OBJECT(src), + G_OBJECT(dst), + property_info->param_spec->name, + G_PARAM_SPEC_VALUE_TYPE(property_info->param_spec)); } if (frozen) @@ -2799,6 +2814,11 @@ const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_interface_name .to_dbus_fcn = _nm_setting_get_deprecated_virtual_interface_name, ); +const NMSettInfoPropertType nm_sett_info_propert_type_setting_name = + NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_STRING, + .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_ignore, + .compare_fcn = _nm_setting_property_compare_fcn_ignore); + const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_ignore_i = NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT( G_VARIANT_TYPE_INT32, diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index 3823922f94..4af74d0037 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -4566,6 +4566,11 @@ check_done:; g_assert_cmpstr(sip->name, ==, sip->param_spec->name); + g_assert(NM_FLAGS_HAS(sip->param_spec->flags, G_PARAM_WRITABLE) + != nm_streq(sip->name, NM_SETTING_NAME)); + g_assert((sip->property_type == &nm_sett_info_propert_type_setting_name) + == nm_streq(sip->name, NM_SETTING_NAME)); + g_value_init(&val, sip->param_spec->value_type); g_object_get_property(G_OBJECT(setting), sip->name, &val);