mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-03-24 19:30:38 +01:00
libnm: pass serialization flags to settings synth_func()
We will need access to the serialization flags from within the synth_func(). That will be for WireGuard's peers. Peers are a list of complex, structured elements, and some fields (the peer's preshared-key) are secret and others are not. So when serializing the peers, we need to know whether to include secrets or not. Instead of letting _nm_setting_to_dbus() check the flags, pass them down. While at it, don't pass the property_name argument. Instead, pass the entire meta-data information we have. Most synth functions don't care about the property or the name either way. But we should not pre-filter information that we have at hand. Just pass it to the synth function. If the synth function would be public API, that would be a reason to be careful about what we pass. But it isn't and it only has one caller. So passing it along is fine. Also, do it now when adding the flags argument, as we touch all synth implementations anyway.
This commit is contained in:
parent
1b361aaea9
commit
e8bf89a906
8 changed files with 88 additions and 55 deletions
|
|
@ -582,9 +582,11 @@ typedef struct _NMSettInfoSetting NMSettInfoSetting;
|
|||
|
||||
typedef GVariant *(*NMSettingPropertyGetFunc) (NMSetting *setting,
|
||||
const char *property);
|
||||
typedef GVariant *(*NMSettingPropertySynthFunc) (NMSetting *setting,
|
||||
typedef GVariant *(*NMSettingPropertySynthFunc) (const NMSettInfoSetting *sett_info,
|
||||
guint property_idx,
|
||||
NMConnection *connection,
|
||||
const char *property);
|
||||
NMSetting *setting,
|
||||
NMConnectionSerializationFlags flags);
|
||||
typedef gboolean (*NMSettingPropertySetFunc) (NMSetting *setting,
|
||||
GVariant *connection_dict,
|
||||
const char *property,
|
||||
|
|
|
|||
|
|
@ -376,9 +376,11 @@ ip4_addresses_set (NMSetting *setting,
|
|||
}
|
||||
|
||||
static GVariant *
|
||||
ip4_address_labels_get (NMSetting *setting,
|
||||
ip4_address_labels_get (const NMSettInfoSetting *sett_info,
|
||||
guint property_idx,
|
||||
NMConnection *connection,
|
||||
const char *property)
|
||||
NMSetting *setting,
|
||||
NMConnectionSerializationFlags flags)
|
||||
{
|
||||
NMSettingIPConfig *s_ip = NM_SETTING_IP_CONFIG (setting);
|
||||
gboolean have_labels = FALSE;
|
||||
|
|
@ -386,6 +388,9 @@ ip4_address_labels_get (NMSetting *setting,
|
|||
GVariant *ret;
|
||||
int num_addrs, i;
|
||||
|
||||
if (flags & NM_CONNECTION_SERIALIZE_ONLY_SECRETS)
|
||||
return NULL;
|
||||
|
||||
num_addrs = nm_setting_ip_config_get_num_addresses (s_ip);
|
||||
for (i = 0; i < num_addrs; i++) {
|
||||
NMIPAddress *addr = nm_setting_ip_config_get_address (s_ip, i);
|
||||
|
|
@ -414,18 +419,19 @@ ip4_address_labels_get (NMSetting *setting,
|
|||
}
|
||||
|
||||
static GVariant *
|
||||
ip4_address_data_get (NMSetting *setting,
|
||||
ip4_address_data_get (const NMSettInfoSetting *sett_info,
|
||||
guint property_idx,
|
||||
NMConnection *connection,
|
||||
const char *property)
|
||||
NMSetting *setting,
|
||||
NMConnectionSerializationFlags flags)
|
||||
{
|
||||
GPtrArray *addrs;
|
||||
GVariant *ret;
|
||||
gs_unref_ptrarray GPtrArray *addrs = NULL;
|
||||
|
||||
if (flags & NM_CONNECTION_SERIALIZE_ONLY_SECRETS)
|
||||
return NULL;
|
||||
|
||||
g_object_get (setting, NM_SETTING_IP_CONFIG_ADDRESSES, &addrs, NULL);
|
||||
ret = nm_utils_ip_addresses_to_variant (addrs);
|
||||
g_ptr_array_unref (addrs);
|
||||
|
||||
return ret;
|
||||
return nm_utils_ip_addresses_to_variant (addrs);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
@ -486,18 +492,19 @@ ip4_routes_set (NMSetting *setting,
|
|||
}
|
||||
|
||||
static GVariant *
|
||||
ip4_route_data_get (NMSetting *setting,
|
||||
ip4_route_data_get (const NMSettInfoSetting *sett_info,
|
||||
guint property_idx,
|
||||
NMConnection *connection,
|
||||
const char *property)
|
||||
NMSetting *setting,
|
||||
NMConnectionSerializationFlags flags)
|
||||
{
|
||||
GPtrArray *routes;
|
||||
GVariant *ret;
|
||||
gs_unref_ptrarray GPtrArray *routes = NULL;
|
||||
|
||||
if (flags & NM_CONNECTION_SERIALIZE_ONLY_SECRETS)
|
||||
return NULL;
|
||||
|
||||
g_object_get (setting, NM_SETTING_IP_CONFIG_ROUTES, &routes, NULL);
|
||||
ret = nm_utils_ip_routes_to_variant (routes);
|
||||
g_ptr_array_unref (routes);
|
||||
|
||||
return ret;
|
||||
return nm_utils_ip_routes_to_variant (routes);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
|
|||
|
|
@ -374,18 +374,19 @@ ip6_addresses_set (NMSetting *setting,
|
|||
}
|
||||
|
||||
static GVariant *
|
||||
ip6_address_data_get (NMSetting *setting,
|
||||
ip6_address_data_get (const NMSettInfoSetting *sett_info,
|
||||
guint property_idx,
|
||||
NMConnection *connection,
|
||||
const char *property)
|
||||
NMSetting *setting,
|
||||
NMConnectionSerializationFlags flags)
|
||||
{
|
||||
GPtrArray *addrs;
|
||||
GVariant *ret;
|
||||
gs_unref_ptrarray GPtrArray *addrs = NULL;
|
||||
|
||||
if (flags & NM_CONNECTION_SERIALIZE_ONLY_SECRETS)
|
||||
return NULL;
|
||||
|
||||
g_object_get (setting, NM_SETTING_IP_CONFIG_ADDRESSES, &addrs, NULL);
|
||||
ret = nm_utils_ip_addresses_to_variant (addrs);
|
||||
g_ptr_array_unref (addrs);
|
||||
|
||||
return ret;
|
||||
return nm_utils_ip_addresses_to_variant (addrs);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
@ -446,18 +447,19 @@ ip6_routes_set (NMSetting *setting,
|
|||
}
|
||||
|
||||
static GVariant *
|
||||
ip6_route_data_get (NMSetting *setting,
|
||||
ip6_route_data_get (const NMSettInfoSetting *sett_info,
|
||||
guint property_idx,
|
||||
NMConnection *connection,
|
||||
const char *property)
|
||||
NMSetting *setting,
|
||||
NMConnectionSerializationFlags flags)
|
||||
{
|
||||
GPtrArray *routes;
|
||||
GVariant *ret;
|
||||
gs_unref_ptrarray GPtrArray *routes = NULL;
|
||||
|
||||
if (flags & NM_CONNECTION_SERIALIZE_ONLY_SECRETS)
|
||||
return NULL;
|
||||
|
||||
g_object_get (setting, NM_SETTING_IP_CONFIG_ROUTES, &routes, NULL);
|
||||
ret = nm_utils_ip_routes_to_variant (routes);
|
||||
g_ptr_array_unref (routes);
|
||||
|
||||
return ret;
|
||||
return nm_utils_ip_routes_to_variant (routes);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
|
|||
|
|
@ -82,9 +82,11 @@ gboolean _nm_setting_clear_secrets_with_flags (NMSetting *setting,
|
|||
|
||||
#define NM_SETTING_PARAM_GENDATA_BACKED (1 << (7 + G_PARAM_USER_SHIFT))
|
||||
|
||||
GVariant *_nm_setting_get_deprecated_virtual_interface_name (NMSetting *setting,
|
||||
GVariant *_nm_setting_get_deprecated_virtual_interface_name (const NMSettInfoSetting *sett_info,
|
||||
guint property_idx,
|
||||
NMConnection *connection,
|
||||
const char *property);
|
||||
NMSetting *setting,
|
||||
NMConnectionSerializationFlags flags);
|
||||
|
||||
NMSettingVerifyResult _nm_setting_verify (NMSetting *setting,
|
||||
NMConnection *connection,
|
||||
|
|
|
|||
|
|
@ -949,17 +949,22 @@ compare_property (NMSetting *setting,
|
|||
/*****************************************************************************/
|
||||
|
||||
static GVariant *
|
||||
nm_setting_wireless_get_security (NMSetting *setting,
|
||||
nm_setting_wireless_get_security (const NMSettInfoSetting *sett_info,
|
||||
guint property_idx,
|
||||
NMConnection *connection,
|
||||
const char *property_name)
|
||||
NMSetting *setting,
|
||||
NMConnectionSerializationFlags flags)
|
||||
{
|
||||
if (flags & NM_CONNECTION_SERIALIZE_ONLY_SECRETS)
|
||||
return NULL;
|
||||
|
||||
if (!connection)
|
||||
return NULL;
|
||||
|
||||
if (nm_connection_get_setting_wireless_security (connection))
|
||||
return g_variant_new_string (NM_SETTING_WIRELESS_SECURITY_SETTING_NAME);
|
||||
else
|
||||
if (!nm_connection_get_setting_wireless_security (connection))
|
||||
return NULL;
|
||||
|
||||
return g_variant_new_string (NM_SETTING_WIRELESS_SECURITY_SETTING_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -662,10 +662,13 @@ _nm_setting_to_dbus (NMSetting *setting, NMConnection *connection, NMConnectionS
|
|||
if (!prop_spec) {
|
||||
if (!property->synth_func)
|
||||
continue;
|
||||
|
||||
if (flags & NM_CONNECTION_SERIALIZE_ONLY_SECRETS)
|
||||
continue;
|
||||
} else {
|
||||
|
||||
/* For the moment, properties backed by a GObject property don't
|
||||
* define a synth function. There is no problem supporting that,
|
||||
* however, for now just disallow it. */
|
||||
nm_assert (!property->synth_func);
|
||||
|
||||
if (!(prop_spec->flags & G_PARAM_WRITABLE))
|
||||
continue;
|
||||
|
||||
|
|
@ -686,9 +689,10 @@ _nm_setting_to_dbus (NMSetting *setting, NMConnection *connection, NMConnectionS
|
|||
}
|
||||
|
||||
if (property->synth_func)
|
||||
dbus_value = property->synth_func (setting, connection, property->name);
|
||||
dbus_value = property->synth_func (sett_info, i, connection, setting, flags);
|
||||
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);
|
||||
|
|
@ -2031,9 +2035,11 @@ nm_setting_to_string (NMSetting *setting)
|
|||
}
|
||||
|
||||
GVariant *
|
||||
_nm_setting_get_deprecated_virtual_interface_name (NMSetting *setting,
|
||||
_nm_setting_get_deprecated_virtual_interface_name (const NMSettInfoSetting *sett_info,
|
||||
guint property_idx,
|
||||
NMConnection *connection,
|
||||
const char *property)
|
||||
NMSetting *setting,
|
||||
NMConnectionSerializationFlags flags)
|
||||
{
|
||||
NMSettingConnection *s_con;
|
||||
|
||||
|
|
|
|||
|
|
@ -56,9 +56,11 @@ gboolean _nm_utils_hwaddr_cloned_not_set (NMSetting *setting,
|
|||
const char *property,
|
||||
NMSettingParseFlags parse_flags,
|
||||
GError **error);
|
||||
GVariant * _nm_utils_hwaddr_cloned_data_synth (NMSetting *setting,
|
||||
GVariant * _nm_utils_hwaddr_cloned_data_synth (const NMSettInfoSetting *sett_info,
|
||||
guint property_idx,
|
||||
NMConnection *connection,
|
||||
const char *property);
|
||||
NMSetting *setting,
|
||||
NMConnectionSerializationFlags flags);
|
||||
gboolean _nm_utils_hwaddr_cloned_data_set (NMSetting *setting,
|
||||
GVariant *connection_dict,
|
||||
const char *property,
|
||||
|
|
|
|||
|
|
@ -4234,13 +4234,18 @@ _nm_utils_hwaddr_cloned_not_set (NMSetting *setting,
|
|||
}
|
||||
|
||||
GVariant *
|
||||
_nm_utils_hwaddr_cloned_data_synth (NMSetting *setting,
|
||||
_nm_utils_hwaddr_cloned_data_synth (const NMSettInfoSetting *sett_info,
|
||||
guint property_idx,
|
||||
NMConnection *connection,
|
||||
const char *property)
|
||||
NMSetting *setting,
|
||||
NMConnectionSerializationFlags flags)
|
||||
{
|
||||
gs_free char *addr = NULL;
|
||||
|
||||
nm_assert (nm_streq0 (property, "assigned-mac-address"));
|
||||
if (flags & NM_CONNECTION_SERIALIZE_ONLY_SECRETS)
|
||||
return NULL;
|
||||
|
||||
nm_assert (nm_streq0 (sett_info->property_infos[property_idx].name, "assigned-mac-address"));
|
||||
|
||||
g_object_get (setting,
|
||||
"cloned-mac-address",
|
||||
|
|
@ -4261,7 +4266,9 @@ _nm_utils_hwaddr_cloned_data_synth (NMSetting *setting,
|
|||
* To preserve that behavior, serialize "" as NULL.
|
||||
*/
|
||||
|
||||
return addr && addr[0] ? g_variant_new_string (addr) : NULL;
|
||||
return addr && addr[0]
|
||||
? g_variant_new_take_string (g_steal_pointer (&addr))
|
||||
: NULL;
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue