diff options
author | Thomas Haller <thaller@redhat.com> | 2019-06-27 09:09:29 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-06-28 16:48:17 +0200 |
commit | 0d58cab4a096e5c9e909aceebb065a2e2eee748a (patch) | |
tree | bba7bdee05864d591600ca0b5cc089f946684641 | |
parent | df2ba4226dfbd1b8b36150758bdbe0579b6a3935 (diff) | |
download | NetworkManager-0d58cab4a096e5c9e909aceebb065a2e2eee748a.tar.gz |
settings: use nm_connection_to_dbus_full() to avoid cloning the connection during GetSettings()
-rw-r--r-- | src/settings/nm-settings-connection.c | 73 |
1 files changed, 33 insertions, 40 deletions
diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c index 5f3f6498a4..6368b3d5a0 100644 --- a/src/settings/nm-settings-connection.c +++ b/src/settings/nm-settings-connection.c @@ -1398,48 +1398,41 @@ get_settings_auth_cb (NMSettingsConnection *self, GError *error, gpointer data) { - if (error) - g_dbus_method_invocation_return_gerror (context, error); - else { - gs_unref_object NMConnection *dupl_con = NULL; - GVariant *settings; - NMSettingConnection *s_con; - NMSettingWireless *s_wifi; - guint64 timestamp = 0; - gs_free const char **bssids = NULL; - - dupl_con = nm_simple_connection_new_clone (nm_settings_connection_get_connection (self)); - - /* Timestamp is not updated in connection's 'timestamp' property, - * because it would force updating the connection and in turn - * writing to /etc periodically, which we want to avoid. Rather real - * timestamps are kept track of in a private variable. So, substitute - * timestamp property with the real one here before returning the settings. - */ - nm_settings_connection_get_timestamp (self, ×tamp); - if (timestamp) { - s_con = nm_connection_get_setting_connection (dupl_con); - g_object_set (s_con, NM_SETTING_CONNECTION_TIMESTAMP, timestamp, NULL); - } - /* Seen BSSIDs are not updated in 802-11-wireless 'seen-bssids' property - * from the same reason as timestamp. Thus we put it here to GetSettings() - * return settings too. - */ - bssids = nm_settings_connection_get_seen_bssids (self); - if (bssids) { - s_wifi = nm_connection_get_setting_wireless (dupl_con); - if (s_wifi) - g_object_set (s_wifi, NM_SETTING_WIRELESS_SEEN_BSSIDS, bssids, NULL); - } + gs_free const char **seen_bssids = NULL; + NMConnectionSerializationOptions options = { + }; + GVariant *settings; - /* Secrets should *never* be returned by the GetSettings method, they - * get returned by the GetSecrets method which can be better - * protected against leakage of secrets to unprivileged callers. - */ - settings = nm_connection_to_dbus (dupl_con, NM_CONNECTION_SERIALIZE_NO_SECRETS); - g_dbus_method_invocation_return_value (context, - g_variant_new ("(@a{sa{sv}})", settings)); + if (error) { + g_dbus_method_invocation_return_gerror (context, error); + return; } + + /* Timestamp is not updated in connection's 'timestamp' property, + * because it would force updating the connection and in turn + * writing to /etc periodically, which we want to avoid. Rather real + * timestamps are kept track of in a private variable. So, substitute + * timestamp property with the real one here before returning the settings. + */ + options.timestamp.has = TRUE; + nm_settings_connection_get_timestamp (self, &options.timestamp.val); + + /* Seen BSSIDs are not updated in 802-11-wireless 'seen-bssids' property + * from the same reason as timestamp. Thus we put it here to GetSettings() + * return settings too. + */ + seen_bssids = nm_settings_connection_get_seen_bssids (self); + options.seen_bssids = seen_bssids; + + /* Secrets should *never* be returned by the GetSettings method, they + * get returned by the GetSecrets method which can be better + * protected against leakage of secrets to unprivileged callers. + */ + settings = nm_connection_to_dbus_full (nm_settings_connection_get_connection (self), + NM_CONNECTION_SERIALIZE_NO_SECRETS, + &options); + g_dbus_method_invocation_return_value (context, + g_variant_new ("(@a{sa{sv}})", settings)); } static void |