summaryrefslogtreecommitdiff
path: root/src/settings
diff options
context:
space:
mode:
Diffstat (limited to 'src/settings')
-rw-r--r--src/settings/nm-settings-connection.c233
-rw-r--r--src/settings/nm-settings-connection.h12
-rw-r--r--src/settings/nm-settings.c124
-rw-r--r--src/settings/nm-settings.h2
-rw-r--r--src/settings/plugins/ibft/nms-ibft-plugin.c4
-rw-r--r--src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c6
-rw-r--r--src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c26
-rw-r--r--src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h4
-rw-r--r--src/settings/plugins/ifupdown/nms-ifupdown-connection.c15
-rw-r--r--src/settings/plugins/ifupdown/nms-ifupdown-plugin.c7
-rw-r--r--src/settings/plugins/keyfile/nms-keyfile-connection.c8
-rw-r--r--src/settings/plugins/keyfile/nms-keyfile-plugin.c10
-rw-r--r--src/settings/plugins/keyfile/nms-keyfile-utils.h4
13 files changed, 250 insertions, 205 deletions
diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c
index c09f680400..1b2edc8316 100644
--- a/src/settings/nm-settings-connection.c
+++ b/src/settings/nm-settings-connection.c
@@ -49,7 +49,26 @@
/*****************************************************************************/
-static void nm_settings_connection_connection_interface_init (NMConnectionInterface *iface);
+NMConnection **
+nm_settings_connections_array_to_connections (NMSettingsConnection *const*connections,
+ gssize n_connections)
+{
+ NMConnection **arr;
+ gssize i;
+
+ if (n_connections < 0)
+ n_connections = NM_PTRARRAY_LEN (connections);
+ if (n_connections == 0)
+ return NULL;
+
+ arr = g_new (NMConnection *, n_connections + 1);
+ for (i = 0; i < n_connections; i++)
+ arr[i] = nm_settings_connection_get_connection (connections[i]);
+ arr[i] = NULL;
+ return arr;
+}
+
+/*****************************************************************************/
NM_GOBJECT_PROPERTIES_DEFINE (NMSettingsConnection,
PROP_UNSAVED,
@@ -87,6 +106,8 @@ typedef struct _NMSettingsConnectionPrivate {
CList call_ids_lst_head; /* in-progress secrets requests */
+ NMConnection *connection;
+
/* Caches secrets from on-disk connections; were they not cached any
* call to nm_connection_clear_secrets() wipes them out and we'd have
* to re-read them from disk which defeats the purpose of having the
@@ -115,9 +136,7 @@ typedef struct _NMSettingsConnectionPrivate {
} NMSettingsConnectionPrivate;
-G_DEFINE_TYPE_WITH_CODE (NMSettingsConnection, nm_settings_connection, NM_TYPE_DBUS_OBJECT,
- G_IMPLEMENT_INTERFACE (NM_TYPE_CONNECTION, nm_settings_connection_connection_interface_init)
- )
+G_DEFINE_TYPE (NMSettingsConnection, nm_settings_connection, NM_TYPE_DBUS_OBJECT)
#define NM_SETTINGS_CONNECTION_GET_PRIVATE(self) _NM_GET_PRIVATE_PTR (self, NMSettingsConnection, NM_IS_SETTINGS_CONNECTION)
@@ -152,6 +171,16 @@ static const NMDBusInterfaceInfoExtended interface_info_settings_connection;
/*****************************************************************************/
+NMConnection *
+nm_settings_connection_get_connection (NMSettingsConnection *self)
+{
+ g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION (self), NULL);
+
+ return NM_SETTINGS_CONNECTION_GET_PRIVATE (self)->connection;
+}
+
+/*****************************************************************************/
+
gboolean
nm_settings_connection_has_unmodified_applied_connection (NMSettingsConnection *self,
NMConnection *applied_connection,
@@ -163,7 +192,8 @@ nm_settings_connection_has_unmodified_applied_connection (NMSettingsConnection *
/* for convenience, we *always* ignore certain settings. */
compare_flags |= NM_SETTING_COMPARE_FLAG_IGNORE_SECRETS | NM_SETTING_COMPARE_FLAG_IGNORE_TIMESTAMP;
- return nm_connection_compare (NM_CONNECTION (self), applied_connection, compare_flags);
+ return nm_connection_compare (nm_settings_connection_get_connection (self),
+ applied_connection, compare_flags);
}
/*****************************************************************************/
@@ -332,8 +362,7 @@ nm_settings_connection_recheck_visibility (NMSettingsConnection *self)
priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
- s_con = nm_connection_get_setting_connection (NM_CONNECTION (self));
- g_assert (s_con);
+ s_con = nm_connection_get_setting_connection (nm_settings_connection_get_connection (self));
/* Check every user in the ACL for a session */
num = nm_setting_connection_get_num_permissions (s_con);
@@ -362,9 +391,9 @@ nm_settings_connection_recheck_visibility (NMSettingsConnection *self)
}
static void
-session_changed_cb (NMSessionMonitor *self, gpointer user_data)
+session_changed_cb (NMSessionMonitor *self, NMSettingsConnection *sett_conn)
{
- nm_settings_connection_recheck_visibility (NM_SETTINGS_CONNECTION (user_data));
+ nm_settings_connection_recheck_visibility (sett_conn);
}
/*****************************************************************************/
@@ -390,8 +419,7 @@ nm_settings_connection_check_permission (NMSettingsConnection *self,
NM_SETTINGS_CONNECTION_INT_FLAGS_VISIBLE))
return FALSE;
- s_con = nm_connection_get_setting_connection (NM_CONNECTION (self));
- g_assert (s_con);
+ s_con = nm_connection_get_setting_connection (nm_settings_connection_get_connection (self));
/* Check every user in the ACL for a session */
num = nm_setting_connection_get_num_permissions (s_con);
@@ -447,7 +475,7 @@ update_system_secrets_cache (NMSettingsConnection *self)
if (priv->system_secrets)
g_object_unref (priv->system_secrets);
- priv->system_secrets = nm_simple_connection_new_clone (NM_CONNECTION (self));
+ priv->system_secrets = nm_simple_connection_new_clone (nm_settings_connection_get_connection (self));
/* Clear out non-system-owned and not-saved secrets */
nm_connection_clear_secrets_with_flags (priv->system_secrets,
@@ -463,7 +491,8 @@ update_agent_secrets_cache (NMSettingsConnection *self, NMConnection *new)
if (priv->agent_secrets)
g_object_unref (priv->agent_secrets);
- priv->agent_secrets = nm_simple_connection_new_clone (new ?: NM_CONNECTION(self));
+ priv->agent_secrets = nm_simple_connection_new_clone ( new
+ ?: nm_settings_connection_get_connection (self));
/* Clear out non-system-owned secrets */
nm_connection_clear_secrets_with_flags (priv->agent_secrets,
@@ -472,7 +501,7 @@ update_agent_secrets_cache (NMSettingsConnection *self, NMConnection *new)
}
static void
-secrets_cleared_cb (NMSettingsConnection *self)
+secrets_cleared_cb (NMConnection *connection, NMSettingsConnection *self)
{
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
@@ -533,7 +562,7 @@ _emit_updated (NMSettingsConnection *self, gboolean by_user)
}
static void
-connection_changed_cb (NMSettingsConnection *self, gpointer unused)
+connection_changed_cb (NMConnection *connection, NMSettingsConnection *self)
{
set_persist_mode (self, NM_SETTINGS_CONNECTION_PERSIST_MODE_UNSAVED);
_emit_updated (self, FALSE);
@@ -636,7 +665,7 @@ nm_settings_connection_update (NMSettingsConnection *self,
if (persist_mode == NM_SETTINGS_CONNECTION_PERSIST_MODE_DISK) {
if (!klass->commit_changes (self,
- new_connection ?: NM_CONNECTION (self),
+ new_connection ?: nm_settings_connection_get_connection (self),
commit_reason,
&reread_connection,
&logmsg_change,
@@ -655,30 +684,30 @@ nm_settings_connection_update (NMSettingsConnection *self,
/* Disconnect the changed signal to ensure we don't set Unsaved when
* it's not required.
*/
- g_signal_handlers_block_by_func (self, G_CALLBACK (connection_changed_cb), NULL);
+ g_signal_handlers_block_by_func (priv->connection, G_CALLBACK (connection_changed_cb), self);
/* Do nothing if there's nothing to update */
if ( replace_connection
- && !nm_connection_compare (NM_CONNECTION (self),
+ && !nm_connection_compare (nm_settings_connection_get_connection (self),
replace_connection,
NM_SETTING_COMPARE_FLAG_EXACT)) {
gs_unref_object NMConnection *simple = NULL;
if (log_diff_name) {
- nm_utils_log_connection_diff (replace_connection, NM_CONNECTION (self), LOGL_DEBUG, LOGD_CORE, log_diff_name, "++ ",
+ nm_utils_log_connection_diff (replace_connection, nm_settings_connection_get_connection (self), LOGL_DEBUG, LOGD_CORE, log_diff_name, "++ ",
nm_dbus_object_get_path (NM_DBUS_OBJECT (self)));
}
/* Make a copy of agent-owned secrets because they won't be present in
* the connection returned by plugins, as plugins return only what was
* reread from the file. */
- simple = nm_simple_connection_new_clone (NM_CONNECTION (self));
+ simple = nm_simple_connection_new_clone (nm_settings_connection_get_connection (self));
nm_connection_clear_secrets_with_flags (simple,
secrets_filter_cb,
GUINT_TO_POINTER (NM_SETTING_SECRET_FLAG_AGENT_OWNED));
con_agent_secrets = nm_connection_to_dbus (simple, NM_CONNECTION_SERIALIZE_ONLY_SECRETS);
- nm_connection_replace_settings_from_connection (NM_CONNECTION (self), replace_connection);
+ nm_connection_replace_settings_from_connection (nm_settings_connection_get_connection (self), replace_connection);
replaced = TRUE;
}
@@ -701,12 +730,12 @@ nm_settings_connection_update (NMSettingsConnection *self,
dict = nm_connection_to_dbus (priv->agent_secrets, NM_CONNECTION_SERIALIZE_ONLY_SECRETS);
if (dict) {
- (void) nm_connection_update_secrets (NM_CONNECTION (self), NULL, dict, NULL);
+ (void) nm_connection_update_secrets (nm_settings_connection_get_connection (self), NULL, dict, NULL);
g_variant_unref (dict);
}
}
if (con_agent_secrets)
- (void) nm_connection_update_secrets (NM_CONNECTION (self), NULL, con_agent_secrets, NULL);
+ (void) nm_connection_update_secrets (nm_settings_connection_get_connection (self), NULL, con_agent_secrets, NULL);
}
nm_settings_connection_recheck_visibility (self);
@@ -724,7 +753,7 @@ nm_settings_connection_update (NMSettingsConnection *self,
NM_SETTINGS_CONNECTION_PERSIST_MODE_VOLATILE_DETACHED))
nm_settings_connection_set_filename (self, NULL);
- g_signal_handlers_unblock_by_func (self, G_CALLBACK (connection_changed_cb), NULL);
+ g_signal_handlers_unblock_by_func (priv->connection, G_CALLBACK (connection_changed_cb), self);
_emit_updated (self, TRUE);
@@ -800,7 +829,7 @@ nm_settings_connection_delete (NMSettingsConnection *self,
set_visible (self, FALSE);
/* Tell agents to remove secrets for this connection */
- for_agents = nm_simple_connection_new_clone (NM_CONNECTION (self));
+ for_agents = nm_simple_connection_new_clone (nm_settings_connection_get_connection (self));
nm_connection_clear_secrets (for_agents);
nm_agent_manager_delete_secrets (priv->agent_mgr,
nm_dbus_object_get_path (NM_DBUS_OBJECT (self)),
@@ -920,7 +949,7 @@ get_cmp_flags (NMSettingsConnection *self, /* only needed for logging */
gboolean *agent_had_system,
ForEachSecretFlags *cmp_flags)
{
- gboolean is_self = (((NMConnection *) self) == connection);
+ gboolean is_self = (nm_settings_connection_get_connection (self) == connection);
g_return_if_fail (secrets);
@@ -1001,7 +1030,7 @@ nm_settings_connection_new_secrets (NMSettingsConnection *self,
return FALSE;
}
- if (!nm_connection_update_secrets (NM_CONNECTION (self), setting_name, secrets, error))
+ if (!nm_connection_update_secrets (nm_settings_connection_get_connection (self), setting_name, secrets, error))
return FALSE;
update_system_secrets_cache (self);
@@ -1073,7 +1102,7 @@ get_secrets_done_cb (NMAgentManager *manager,
goto out;
}
- if (!nm_connection_get_setting_by_name (NM_CONNECTION (self), setting_name)) {
+ if (!nm_connection_get_setting_by_name (nm_settings_connection_get_connection (self), setting_name)) {
g_set_error (&local, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_SETTING_NOT_FOUND,
"Connection didn't have requested setting '%s'.",
setting_name);
@@ -1083,7 +1112,7 @@ get_secrets_done_cb (NMAgentManager *manager,
get_cmp_flags (self,
call_id,
- NM_CONNECTION (self),
+ nm_settings_connection_get_connection (self),
agent_dbus_owner,
agent_has_modify,
setting_name,
@@ -1100,8 +1129,8 @@ get_secrets_done_cb (NMAgentManager *manager,
dict = nm_connection_to_dbus (priv->system_secrets, NM_CONNECTION_SERIALIZE_ONLY_SECRETS);
/* Update the connection with our existing secrets from backing storage */
- nm_connection_clear_secrets (NM_CONNECTION (self));
- if (!dict || nm_connection_update_secrets (NM_CONNECTION (self), setting_name, dict, &local)) {
+ nm_connection_clear_secrets (nm_settings_connection_get_connection (self));
+ if (!dict || nm_connection_update_secrets (nm_settings_connection_get_connection (self), setting_name, dict, &local)) {
GVariant *filtered_secrets;
/* Update the connection with the agent's secrets; by this point if any
@@ -1109,8 +1138,8 @@ get_secrets_done_cb (NMAgentManager *manager,
* will have been authenticated, so those secrets can replace the existing
* system secrets.
*/
- filtered_secrets = for_each_secret (NM_CONNECTION (self), secrets, TRUE, validate_secret_flags, &cmp_flags);
- if (nm_connection_update_secrets (NM_CONNECTION (self), setting_name, filtered_secrets, &local)) {
+ filtered_secrets = for_each_secret (nm_settings_connection_get_connection (self), secrets, TRUE, validate_secret_flags, &cmp_flags);
+ if (nm_connection_update_secrets (nm_settings_connection_get_connection (self), setting_name, filtered_secrets, &local)) {
/* Now that all secrets are updated, copy and cache new secrets,
* then save them to backing storage.
*/
@@ -1250,7 +1279,7 @@ nm_settings_connection_get_secrets (NMSettingsConnection *self,
g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION (self), NULL);
g_return_val_if_fail ( !applied_connection
|| ( NM_IS_CONNECTION (applied_connection)
- && (((NMConnection *) self) != applied_connection)), NULL);
+ && (nm_settings_connection_get_connection (self) != applied_connection)), NULL);
call_id = g_slice_new0 (NMSettingsConnectionCallId);
call_id->self = self;
@@ -1264,7 +1293,7 @@ nm_settings_connection_get_secrets (NMSettingsConnection *self,
c_list_link_tail (&priv->call_ids_lst_head, &call_id->call_ids_lst);
/* Make sure the request actually requests something we can return */
- if (!nm_connection_get_setting_by_name (NM_CONNECTION (self), setting_name)) {
+ if (!nm_connection_get_setting_by_name (nm_settings_connection_get_connection (self), setting_name)) {
g_set_error (&local, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_SETTING_NOT_FOUND,
"Connection didn't have requested setting '%s'.",
setting_name);
@@ -1295,7 +1324,7 @@ nm_settings_connection_get_secrets (NMSettingsConnection *self,
call_id_a = nm_agent_manager_get_secrets (priv->agent_mgr,
nm_dbus_object_get_path (NM_DBUS_OBJECT (self)),
- NM_CONNECTION (self),
+ nm_settings_connection_get_connection (self),
subject,
existing_secrets,
setting_name,
@@ -1465,7 +1494,7 @@ auth_start (NMSettingsConnection *self,
nm_assert (G_IS_DBUS_METHOD_INVOCATION (invocation));
nm_assert (NM_IS_AUTH_SUBJECT (subject));
- if (!nm_auth_is_subject_in_acl_set_error (NM_CONNECTION (self),
+ if (!nm_auth_is_subject_in_acl_set_error (nm_settings_connection_get_connection (self),
subject,
NM_SETTINGS_ERROR,
NM_SETTINGS_ERROR_PERMISSION_DENIED,
@@ -1539,15 +1568,14 @@ get_settings_auth_cb (NMSettingsConnection *self,
if (error)
g_dbus_method_invocation_return_gerror (context, error);
else {
+ gs_unref_object NMConnection *dupl_con = NULL;
GVariant *settings;
- NMConnection *dupl_con;
NMSettingConnection *s_con;
NMSettingWireless *s_wifi;
guint64 timestamp = 0;
- char **bssids;
+ gs_free char **bssids = NULL;
- dupl_con = nm_simple_connection_new_clone (NM_CONNECTION (self));
- g_assert (dupl_con);
+ 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
@@ -1557,8 +1585,7 @@ get_settings_auth_cb (NMSettingsConnection *self,
*/
nm_settings_connection_get_timestamp (self, &timestamp);
if (timestamp) {
- s_con = nm_connection_get_setting_connection (NM_CONNECTION (dupl_con));
- g_assert (s_con);
+ 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
@@ -1566,20 +1593,17 @@ get_settings_auth_cb (NMSettingsConnection *self,
* return settings too.
*/
bssids = nm_settings_connection_get_seen_bssids (self);
- s_wifi = nm_connection_get_setting_wireless (NM_CONNECTION (dupl_con));
+ s_wifi = nm_connection_get_setting_wireless (dupl_con);
if (bssids && bssids[0] && s_wifi)
g_object_set (s_wifi, NM_SETTING_WIRELESS_SEEN_BSSIDS, bssids, NULL);
- g_free (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 (NM_CONNECTION (dupl_con), NM_CONNECTION_SERIALIZE_NO_SECRETS);
- g_assert (settings);
+ 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));
- g_object_unref (dupl_con);
}
}
@@ -1734,7 +1758,7 @@ update_auth_cb (NMSettingsConnection *self,
gs_unref_hashtable GHashTable *diff = NULL;
gboolean same;
- same = nm_connection_diff (NM_CONNECTION (self), info->new_settings,
+ same = nm_connection_diff (nm_settings_connection_get_connection (self), info->new_settings,
NM_SETTING_COMPARE_FLAG_EXACT |
NM_SETTING_COMPARE_FLAG_DIFF_RESULT_NO_DEFAULT,
&diff);
@@ -1745,7 +1769,7 @@ update_auth_cb (NMSettingsConnection *self,
commit_reason = NM_SETTINGS_CONNECTION_COMMIT_REASON_USER_ACTION;
if ( info->new_settings
- && !nm_streq0 (nm_connection_get_id (NM_CONNECTION (self)),
+ && !nm_streq0 (nm_connection_get_id (nm_settings_connection_get_connection (self)),
nm_connection_get_id (info->new_settings)))
commit_reason |= NM_SETTINGS_CONNECTION_COMMIT_REASON_ID_CHANGED;
@@ -1791,7 +1815,7 @@ update_auth_cb (NMSettingsConnection *self,
* as agent-owned secrets are the only ones we send back be saved.
* Only send secrets to agents of the same UID that called update too.
*/
- for_agent = nm_simple_connection_new_clone (NM_CONNECTION (self));
+ for_agent = nm_simple_connection_new_clone (nm_settings_connection_get_connection (self));
nm_connection_clear_secrets_with_flags (for_agent,
secrets_filter_cb,
GUINT_TO_POINTER (NM_SETTING_SECRET_FLAG_AGENT_OWNED));
@@ -1811,11 +1835,9 @@ get_update_modify_permission (NMConnection *old, NMConnection *new)
guint32 orig_num = 0, new_num = 0;
s_con = nm_connection_get_setting_connection (old);
- g_assert (s_con);
orig_num = nm_setting_connection_get_num_permissions (s_con);
s_con = nm_connection_get_setting_connection (new);
- g_assert (s_con);
new_num = nm_setting_connection_get_num_permissions (s_con);
/* If the caller is the only user in either connection's permissions, then
@@ -1848,7 +1870,7 @@ settings_connection_update (NMSettingsConnection *self,
* the problem (ex a system settings plugin that can't write connections out)
* instead of over D-Bus.
*/
- if (!check_writable (NM_CONNECTION (self), &error))
+ if (!check_writable (nm_settings_connection_get_connection (self), &error))
goto error;
/* Check if the settings are valid first */
@@ -1879,7 +1901,7 @@ settings_connection_update (NMSettingsConnection *self,
* that's sending the update request. You can't make a connection
* invisible to yourself.
*/
- if (!nm_auth_is_subject_in_acl_set_error (tmp ?: NM_CONNECTION(self),
+ if (!nm_auth_is_subject_in_acl_set_error (tmp ?: nm_settings_connection_get_connection (self),
subject,
NM_SETTINGS_ERROR,
NM_SETTINGS_ERROR_PERMISSION_DENIED,
@@ -1894,8 +1916,8 @@ settings_connection_update (NMSettingsConnection *self,
info->flags = flags;
info->new_settings = tmp;
- permission = get_update_modify_permission (NM_CONNECTION (self),
- tmp ?: NM_CONNECTION(self));
+ permission = get_update_modify_permission (nm_settings_connection_get_connection (self),
+ tmp ?: nm_settings_connection_get_connection (self));
auth_start (self, context, subject, permission, update_auth_cb, info);
return;
@@ -2066,8 +2088,7 @@ get_modify_permission_basic (NMSettingsConnection *self)
* we use the 'modify.own' permission instead of 'modify.system'. If the
* request affects more than just the caller, require 'modify.system'.
*/
- s_con = nm_connection_get_setting_connection (NM_CONNECTION (self));
- nm_assert (s_con);
+ s_con = nm_connection_get_setting_connection (nm_settings_connection_get_connection (self));
if (nm_setting_connection_get_num_permissions (s_con) == 1)
return NM_AUTH_PERMISSION_SETTINGS_MODIFY_OWN;
@@ -2087,7 +2108,7 @@ impl_settings_connection_delete (NMDBusObject *obj,
gs_unref_object NMAuthSubject *subject = NULL;
GError *error = NULL;
- if (!check_writable (NM_CONNECTION (self), &error))
+ if (!check_writable (nm_settings_connection_get_connection (self), &error))
goto err;
subject = _new_auth_subject (invocation, &error);
@@ -2122,7 +2143,7 @@ dbus_get_agent_secrets_cb (NMSettingsConnection *self,
* secrets from backing storage and those returned from the agent
* by the time we get here.
*/
- dict = nm_connection_to_dbus (NM_CONNECTION (self), NM_CONNECTION_SERIALIZE_ONLY_SECRETS);
+ dict = nm_connection_to_dbus (nm_settings_connection_get_connection (self), NM_CONNECTION_SERIALIZE_ONLY_SECRETS);
if (!dict)
dict = g_variant_new_array (G_VARIANT_TYPE ("{sa{sv}}"), NULL, 0);
g_dbus_method_invocation_return_value (context, g_variant_new ("(@a{sa{sv}})", dict));
@@ -2204,7 +2225,7 @@ dbus_clear_secrets_auth_cb (NMSettingsConnection *self,
}
/* Clear secrets in connection and caches */
- nm_connection_clear_secrets (NM_CONNECTION (self));
+ nm_connection_clear_secrets (nm_settings_connection_get_connection (self));
if (priv->system_secrets)
nm_connection_clear_secrets (priv->system_secrets);
if (priv->agent_secrets)
@@ -2213,7 +2234,7 @@ dbus_clear_secrets_auth_cb (NMSettingsConnection *self,
/* Tell agents to remove secrets for this connection */
nm_agent_manager_delete_secrets (priv->agent_mgr,
nm_dbus_object_get_path (NM_DBUS_OBJECT (self)),
- NM_CONNECTION (self));
+ nm_settings_connection_get_connection (self));
nm_settings_connection_update (self,
NULL,
@@ -2388,15 +2409,8 @@ _cmp_timestamp (NMSettingsConnection *a, NMSettingsConnection *b)
static int
_cmp_last_resort (NMSettingsConnection *a, NMSettingsConnection *b)
{
- int c;
-
- nm_assert (NM_IS_SETTINGS_CONNECTION (a));
- nm_assert (NM_IS_SETTINGS_CONNECTION (b));
-
- c = g_strcmp0 (nm_connection_get_uuid (NM_CONNECTION (a)),
- nm_connection_get_uuid (NM_CONNECTION (b)));
- if (c)
- return c;
+ NM_CMP_DIRECT_STRCMP0 (nm_settings_connection_get_uuid (a),
+ nm_settings_connection_get_uuid (b));
/* hm, same UUID. Use their pointer value to give them a stable
* order. */
@@ -2411,19 +2425,11 @@ _cmp_last_resort (NMSettingsConnection *a, NMSettingsConnection *b)
int
nm_settings_connection_cmp_timestamp (NMSettingsConnection *a, NMSettingsConnection *b)
{
- int c;
+ NM_CMP_SELF (a, b);
- if (a == b)
- return 0;
- if (!a)
- return 1;
- if (!b)
- return -1;
-
- if ((c = _cmp_timestamp (a, b)))
- return c;
- if ((c = nm_utils_cmp_connection_by_autoconnect_priority (NM_CONNECTION (a), NM_CONNECTION (b))))
- return c;
+ NM_CMP_RETURN (_cmp_timestamp (a, b));
+ NM_CMP_RETURN (nm_utils_cmp_connection_by_autoconnect_priority (nm_settings_connection_get_connection (a),
+ nm_settings_connection_get_connection (b)));
return _cmp_last_resort (a, b);
}
@@ -2437,14 +2443,11 @@ nm_settings_connection_cmp_timestamp_p_with_data (gconstpointer pa, gconstpointe
int
nm_settings_connection_cmp_autoconnect_priority (NMSettingsConnection *a, NMSettingsConnection *b)
{
- int c;
-
if (a == b)
return 0;
- if ((c = nm_utils_cmp_connection_by_autoconnect_priority (NM_CONNECTION (a), NM_CONNECTION (b))))
- return c;
- if ((c = _cmp_timestamp (a, b)))
- return c;
+ NM_CMP_RETURN (nm_utils_cmp_connection_by_autoconnect_priority (nm_settings_connection_get_connection (a),
+ nm_settings_connection_get_connection (b)));
+ NM_CMP_RETURN (_cmp_timestamp (a, b));
return _cmp_last_resort (a, b);
}
@@ -2727,7 +2730,7 @@ nm_settings_connection_read_and_fill_seen_bssids (NMSettingsConnection *self)
* seen-bssids list from the deprecated seen-bssids property of the
* wifi setting.
*/
- s_wifi = nm_connection_get_setting_wireless (NM_CONNECTION (self));
+ s_wifi = nm_connection_get_setting_wireless (nm_settings_connection_get_connection (self));
if (s_wifi) {
len = nm_setting_wireless_get_num_seen_bssids (s_wifi);
for (i = 0; i < len; i++) {
@@ -2747,7 +2750,7 @@ _autoconnect_retries_initial (NMSettingsConnection *self)
NMSettingConnection *s_con;
int retries = -1;
- s_con = nm_connection_get_setting_connection ((NMConnection *) self);
+ s_con = nm_connection_get_setting_connection (nm_settings_connection_get_connection (self));
if (s_con)
retries = nm_setting_connection_get_autoconnect_retries (s_con);
@@ -2959,13 +2962,19 @@ nm_settings_connection_get_filename (NMSettingsConnection *self)
const char *
nm_settings_connection_get_id (NMSettingsConnection *self)
{
- return nm_connection_get_id (NM_CONNECTION (self));
+ return nm_connection_get_id (nm_settings_connection_get_connection (self));
}
const char *
nm_settings_connection_get_uuid (NMSettingsConnection *self)
{
- return nm_connection_get_uuid (NM_CONNECTION (self));
+ return nm_connection_get_uuid (nm_settings_connection_get_connection (self));
+}
+
+const char *
+nm_settings_connection_get_connection_type (NMSettingsConnection *self)
+{
+ return nm_connection_get_connection_type (nm_settings_connection_get_connection (self));
}
/*****************************************************************************/
@@ -2995,8 +3004,10 @@ nm_settings_connection_init (NMSettingsConnection *self)
priv->autoconnect_retries = AUTOCONNECT_RETRIES_UNSET;
- g_signal_connect (self, NM_CONNECTION_SECRETS_CLEARED, G_CALLBACK (secrets_cleared_cb), NULL);
- g_signal_connect (self, NM_CONNECTION_CHANGED, G_CALLBACK (connection_changed_cb), NULL);
+ priv->connection = nm_simple_connection_new ();
+
+ g_signal_connect (priv->connection, NM_CONNECTION_SECRETS_CLEARED, G_CALLBACK (secrets_cleared_cb), self);
+ g_signal_connect (priv->connection, NM_CONNECTION_CHANGED, G_CALLBACK (connection_changed_cb), self);
}
static void
@@ -3027,26 +3038,32 @@ dispose (GObject *object)
_get_secrets_cancel (self, call_id, TRUE);
}
- /* Disconnect handlers.
- * connection_changed_cb() has to be disconnected *before* nm_connection_clear_secrets(),
- * because nm_connection_clear_secrets() emits NM_CONNECTION_CHANGED signal.
- */
- g_signal_handlers_disconnect_by_func (self, G_CALLBACK (secrets_cleared_cb), NULL);
- g_signal_handlers_disconnect_by_func (self, G_CALLBACK (connection_changed_cb), NULL);
+ set_visible (self, FALSE);
+
+ if (priv->connection) {
+ /* Disconnect handlers.
+ * connection_changed_cb() has to be disconnected *before* nm_connection_clear_secrets(),
+ * because nm_connection_clear_secrets() emits NM_CONNECTION_CHANGED signal.
+ */
+ g_signal_handlers_disconnect_by_func (priv->connection, G_CALLBACK (secrets_cleared_cb), self);
+ g_signal_handlers_disconnect_by_func (priv->connection, G_CALLBACK (connection_changed_cb), self);
+
+ /* FIXME(copy-on-write-connection): avoid modifying NMConnection instances and share them via copy-on-write. */
+ nm_connection_clear_secrets (priv->connection);
+ }
- nm_connection_clear_secrets (NM_CONNECTION (self));
g_clear_object (&priv->system_secrets);
g_clear_object (&priv->agent_secrets);
g_clear_pointer (&priv->seen_bssids, g_hash_table_destroy);
- set_visible (self, FALSE);
-
nm_clear_g_signal_handler (priv->session_monitor, &priv->session_changed_id);
g_clear_object (&priv->session_monitor);
g_clear_object (&priv->agent_mgr);
+ g_clear_object (&priv->connection);
+
g_clear_pointer (&priv->filename, g_free);
G_OBJECT_CLASS (nm_settings_connection_parent_class)->dispose (object);
@@ -3264,9 +3281,3 @@ nm_settings_connection_class_init (NMSettingsConnectionClass *klass)
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
}
-
-static void
-nm_settings_connection_connection_interface_init (NMConnectionInterface *iface)
-{
-}
-
diff --git a/src/settings/nm-settings-connection.h b/src/settings/nm-settings-connection.h
index cd64f9762d..e796b71645 100644
--- a/src/settings/nm-settings-connection.h
+++ b/src/settings/nm-settings-connection.h
@@ -139,6 +139,8 @@ struct _NMSettingsConnectionClass {
GType nm_settings_connection_get_type (void);
+NMConnection *nm_settings_connection_get_connection (NMSettingsConnection *self);
+
guint64 nm_settings_connection_get_last_secret_agent_version_id (NMSettingsConnection *self);
gboolean nm_settings_connection_has_unmodified_applied_connection (NMSettingsConnection *self,
@@ -268,7 +270,13 @@ void nm_settings_connection_set_filename (NMSettingsConnection *self,
const char *filename);
const char *nm_settings_connection_get_filename (NMSettingsConnection *self);
-const char *nm_settings_connection_get_id (NMSettingsConnection *connection);
-const char *nm_settings_connection_get_uuid (NMSettingsConnection *connection);
+const char *nm_settings_connection_get_id (NMSettingsConnection *connection);
+const char *nm_settings_connection_get_uuid (NMSettingsConnection *connection);
+const char *nm_settings_connection_get_connection_type (NMSettingsConnection *connection);
+
+/*****************************************************************************/
+
+NMConnection **nm_settings_connections_array_to_connections (NMSettingsConnection *const*connections,
+ gssize n_connections);
#endif /* __NETWORKMANAGER_SETTINGS_CONNECTION_H__ */
diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c
index a4d47f5346..6ddc9a94ab 100644
--- a/src/settings/nm-settings.c
+++ b/src/settings/nm-settings.c
@@ -214,9 +214,9 @@ connection_ready_changed (NMSettingsConnection *conn,
static void
plugin_connection_added (NMSettingsPlugin *config,
NMSettingsConnection *connection,
- gpointer user_data)
+ NMSettings *self)
{
- claim_connection (NM_SETTINGS (user_data), connection);
+ claim_connection (self, connection);
}
static void
@@ -237,7 +237,7 @@ load_connections (NMSettings *self)
// priority plugin.
for (elt = plugin_connections; elt; elt = g_slist_next (elt))
- claim_connection (self, NM_SETTINGS_CONNECTION (elt->data));
+ claim_connection (self, elt->data);
g_slist_free (plugin_connections);
@@ -306,15 +306,15 @@ impl_settings_get_connection_by_uuid (NMDBusObject *obj,
GVariant *parameters)
{
NMSettings *self = NM_SETTINGS (obj);
- NMSettingsConnection *connection = NULL;
+ NMSettingsConnection *sett_conn;
gs_unref_object NMAuthSubject *subject = NULL;
GError *error = NULL;
const char *uuid;
g_variant_get (parameters, "(&s)", &uuid);
- connection = nm_settings_get_connection_by_uuid (self, uuid);
- if (!connection) {
+ sett_conn = nm_settings_get_connection_by_uuid (self, uuid);
+ if (!sett_conn) {
error = g_error_new_literal (NM_SETTINGS_ERROR,
NM_SETTINGS_ERROR_INVALID_CONNECTION,
"No connection with the UUID was found.");
@@ -329,7 +329,7 @@ impl_settings_get_connection_by_uuid (NMDBusObject *obj,
goto error;
}
- if (!nm_auth_is_subject_in_acl_set_error (NM_CONNECTION (connection),
+ if (!nm_auth_is_subject_in_acl_set_error (nm_settings_connection_get_connection (sett_conn),
subject,
NM_SETTINGS_ERROR,
NM_SETTINGS_ERROR_PERMISSION_DENIED,
@@ -338,7 +338,7 @@ impl_settings_get_connection_by_uuid (NMDBusObject *obj,
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(o)",
- nm_dbus_object_get_path (NM_DBUS_OBJECT (connection))));
+ nm_dbus_object_get_path (NM_DBUS_OBJECT (sett_conn))));
return;
error:
@@ -362,6 +362,7 @@ _clear_connections_cached_list (NMSettingsPrivate *priv)
0xdeaddead,
sizeof (NMSettingsConnection *) * (priv->connections_len + 1));
#endif
+
nm_clear_g_free (&priv->connections_cached_list);
}
@@ -480,8 +481,8 @@ nm_settings_get_connection_by_path (NMSettings *self, const char *path)
priv = NM_SETTINGS_GET_PRIVATE (self);
- connection = (NMSettingsConnection *) nm_dbus_manager_lookup_object (nm_dbus_object_get_manager (NM_DBUS_OBJECT (self)),
- path);
+ connection = nm_dbus_manager_lookup_object (nm_dbus_object_get_manager (NM_DBUS_OBJECT (self)),
+ path);
if ( !connection
|| !NM_IS_SETTINGS_CONNECTION (connection))
return NULL;
@@ -931,29 +932,33 @@ openconnect_migrate_hack (NMConnection *connection)
}
static void
-claim_connection (NMSettings *self, NMSettingsConnection *connection)
+claim_connection (NMSettings *self, NMSettingsConnection *sett_conn)
{
- NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
+ NMSettingsPrivate *priv;
GError *error = NULL;
const char *path;
NMSettingsConnection *existing;
- g_return_if_fail (NM_IS_SETTINGS_CONNECTION (connection));
- g_return_if_fail (!nm_dbus_object_is_exported (NM_DBUS_OBJECT (connection)));
+ g_return_if_fail (NM_IS_SETTINGS (self));
+ g_return_if_fail (NM_IS_SETTINGS_CONNECTION (sett_conn));
+ g_return_if_fail (!nm_dbus_object_is_exported (NM_DBUS_OBJECT (sett_conn)));
+
+ priv = NM_SETTINGS_GET_PRIVATE (self);
/* prevent duplicates */
- if (!c_list_is_empty (&connection->_connections_lst)) {
- nm_assert (c_list_contains (&priv->connections_lst_head, &connection->_connections_lst));
+ if (!c_list_is_empty (&sett_conn->_connections_lst)) {
+ nm_assert (c_list_contains (&priv->connections_lst_head, &sett_conn->_connections_lst));
return;
}
- if (!nm_connection_normalize (NM_CONNECTION (connection), NULL, NULL, &error)) {
+ /* FIXME(copy-on-write-connection): avoid modifying NMConnection instances and share them via copy-on-write. */
+ if (!nm_connection_normalize (nm_settings_connection_get_connection (sett_conn), NULL, NULL, &error)) {
_LOGW ("plugin provided invalid connection: %s", error->message);
g_error_free (error);
return;
}
- existing = nm_settings_get_connection_by_uuid (self, nm_settings_connection_get_uuid (connection));
+ existing = nm_settings_get_connection_by_uuid (self, nm_settings_connection_get_uuid (sett_conn));
if (existing) {
/* Cannot add duplicate connections per UUID. Just return without action and
* log a warning.
@@ -966,51 +971,56 @@ claim_connection (NMSettings *self, NMSettingsConnection *connection)
* error out. That should not happen unless the admin misconfigured the system
* to create conflicting connections. */
_LOGW ("plugin provided duplicate connection with UUID %s",
- nm_settings_connection_get_uuid (connection));
+ nm_settings_connection_get_uuid (sett_conn));
return;
}
/* Read timestamp from look-aside file and put it into the connection's data */
- nm_settings_connection_read_and_fill_timestamp (connection);
+ nm_settings_connection_read_and_fill_timestamp (sett_conn);
/* Read seen-bssids from look-aside file and put it into the connection's data */
- nm_settings_connection_read_and_fill_seen_bssids (connection);
+ nm_settings_connection_read_and_fill_seen_bssids (sett_conn);
/* Ensure its initial visibility is up-to-date */
- nm_settings_connection_recheck_visibility (connection);
+ nm_settings_connection_recheck_visibility (sett_conn);
/* Evil openconnect migration hack */
- openconnect_migrate_hack (NM_CONNECTION (connection));
+ /* FIXME(copy-on-write-connection): avoid modifying NMConnection instances and share them via copy-on-write. */
+ openconnect_migrate_hack (nm_settings_connection_get_connection (sett_conn));
/* This one unexports the connection, it needs to run late to give the active
* connection a chance to deal with its reference to this settings connection. */
- g_signal_connect_after (connection, NM_SETTINGS_CONNECTION_REMOVED,
+ g_signal_connect_after (sett_conn, NM_SETTINGS_CONNECTION_REMOVED,
G_CALLBACK (connection_removed), self);
- g_signal_connect (connection, NM_SETTINGS_CONNECTION_UPDATED_INTERNAL,
+ g_signal_connect (sett_conn, NM_SETTINGS_CONNECTION_UPDATED_INTERNAL,
G_CALLBACK (connection_updated), self);
- g_signal_connect (connection, NM_SETTINGS_CONNECTION_FLAGS_CHANGED,
+ g_signal_connect (sett_conn, NM_SETTINGS_CONNECTION_FLAGS_CHANGED,
G_CALLBACK (connection_flags_changed),
self);
if (!priv->startup_complete) {
- g_signal_connect (connection, "notify::" NM_SETTINGS_CONNECTION_READY,
+ g_signal_connect (sett_conn, "notify::" NM_SETTINGS_CONNECTION_READY,
G_CALLBACK (connection_ready_changed),
self);
}
_clear_connections_cached_list (priv);
- g_object_ref (connection);
+ g_object_ref (sett_conn);
/* FIXME(shutdown): The NMSettings instance can't be disposed
* while there is any exported connection. Ideally we should
* unexport all connections on NMSettings' disposal, but for now
* leak @self on termination when there are connections alive. */
g_object_ref (self);
priv->connections_len++;
- c_list_link_tail (&priv->connections_lst_head, &connection->_connections_lst);
+ c_list_link_tail (&priv->connections_lst_head, &sett_conn->_connections_lst);
- path = nm_dbus_object_export (NM_DBUS_OBJECT (connection));
+ path = nm_dbus_object_export (NM_DBUS_OBJECT (sett_conn));
- nm_utils_log_connection_diff (NM_CONNECTION (connection), NULL, LOGL_DEBUG, LOGD_CORE, "new connection", "++ ",
+ nm_utils_log_connection_diff (nm_settings_connection_get_connection (sett_conn),
+ NULL,
+ LOGL_DEBUG,
+ LOGD_CORE,
+ "new connection", "++ ",
path);
/* Only emit the individual connection-added signal after connections
@@ -1021,13 +1031,13 @@ claim_connection (NMSettings *self, NMSettingsConnection *connection)
&interface_info_settings,
&signal_info_new_connection,
"(o)",
- nm_dbus_object_get_path (NM_DBUS_OBJECT (connection)));
+ nm_dbus_object_get_path (NM_DBUS_OBJECT (sett_conn)));
- g_signal_emit (self, signals[CONNECTION_ADDED], 0, connection);
+ g_signal_emit (self, signals[CONNECTION_ADDED], 0, sett_conn);
_notify (self, PROP_CONNECTIONS);
}
- nm_settings_connection_added (connection);
+ nm_settings_connection_added (sett_conn);
}
static gboolean
@@ -1079,7 +1089,7 @@ nm_settings_add_connection (NMSettings *self,
/* Make sure a connection with this UUID doesn't already exist */
c_list_for_each_entry (candidate, &priv->connections_lst_head, _connections_lst) {
- if (nm_streq0 (uuid, nm_connection_get_uuid (NM_CONNECTION (candidate)))) {
+ if (nm_streq0 (uuid, nm_settings_connection_get_uuid (candidate))) {
g_set_error_literal (error,
NM_SETTINGS_ERROR,
NM_SETTINGS_ERROR_UUID_EXISTS,
@@ -1113,8 +1123,13 @@ nm_settings_add_connection (NMSettings *self,
added = nm_settings_plugin_add_connection (plugin, connection, save_to_disk, &add_error);
if (added) {
- if (secrets)
- nm_connection_update_secrets (NM_CONNECTION (added), NULL, secrets, NULL);
+ if (secrets) {
+ /* FIXME(copy-on-write-connection): avoid modifying NMConnection instances and share them via copy-on-write. */
+ nm_connection_update_secrets (nm_settings_connection_get_connection (added),
+ NULL,
+ secrets,
+ NULL);
+ }
claim_connection (self, added);
return added;
}
@@ -1132,7 +1147,7 @@ nm_settings_add_connection (NMSettings *self,
static void
send_agent_owned_secrets (NMSettings *self,
- NMSettingsConnection *connection,
+ NMSettingsConnection *sett_conn,
NMAuthSubject *subject)
{
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
@@ -1142,12 +1157,12 @@ send_agent_owned_secrets (NMSettings *self,
* as agent-owned secrets are the only ones we send back to be saved.
* Only send secrets to agents of the same UID that called update too.
*/
- for_agent = nm_simple_connection_new_clone (NM_CONNECTION (connection));
+ for_agent = nm_simple_connection_new_clone (nm_settings_connection_get_connection (sett_conn));
nm_connection_clear_secrets_with_flags (for_agent,
secrets_filter_cb,
GUINT_TO_POINTER (NM_SETTING_SECRET_FLAG_AGENT_OWNED));
nm_agent_manager_save_secrets (priv->agent_mgr,
- nm_dbus_object_get_path (NM_DBUS_OBJECT (connection)),
+ nm_dbus_object_get_path (NM_DBUS_OBJECT (sett_conn)),
for_agent,
subject);
}
@@ -1190,7 +1205,8 @@ pk_add_cb (NMAuthChain *chain,
} else {
/* Authorized */
connection = nm_auth_chain_get_data (chain, "connection");
- g_assert (connection);
+ nm_assert (connection);
+
save_to_disk = GPOINTER_TO_UINT (nm_auth_chain_get_data (chain, "save-to-disk"));
added = nm_settings_add_connection (self, connection, save_to_disk, &error);
}
@@ -1612,20 +1628,21 @@ have_connection_for_device (NMSettings *self, NMDevice *device)
NMSettingWired *s_wired;
const char *setting_hwaddr;
const char *perm_hw_addr;
- NMSettingsConnection *connection;
+ NMSettingsConnection *sett_conn;
g_return_val_if_fail (NM_IS_SETTINGS (self), FALSE);
perm_hw_addr = nm_device_get_permanent_hw_address (device);
/* Find a wired connection locked to the given MAC address, if any */
- c_list_for_each_entry (connection, &priv->connections_lst_head, _connections_lst) {
+ c_list_for_each_entry (sett_conn, &priv->connections_lst_head, _connections_lst) {
+ NMConnection *connection = nm_settings_connection_get_connection (sett_conn);
const char *ctype, *iface;
- if (!nm_device_check_connection_compatible (device, NM_CONNECTION (connection), NULL))
+ if (!nm_device_check_connection_compatible (device, connection, NULL))
continue;
- s_con = nm_connection_get_setting_connection (NM_CONNECTION (connection));
+ s_con = nm_connection_get_setting_connection (connection);
iface = nm_setting_connection_get_interface_name (s_con);
if (iface && strcmp (iface, nm_device_get_iface (device)) != 0)
@@ -1636,14 +1653,15 @@ have_connection_for_device (NMSettings *self, NMDevice *device)
&& strcmp (ctype, NM_SETTING_PPPOE_SETTING_NAME))
continue;
- s_wired = nm_connection_get_setting_wired (NM_CONNECTION (connection));
+ s_wired = nm_connection_get_setting_wired (connection);
- if (!s_wired && !strcmp (ctype, NM_SETTING_PPPOE_SETTING_NAME)) {
+ if ( !s_wired
+ && nm_streq (ctype, NM_SETTING_PPPOE_SETTING_NAME)) {
/* No wired setting; therefore the PPPoE connection applies to any device */
return TRUE;
}
- g_assert (s_wired != NULL);
+ nm_assert (s_wired);
setting_hwaddr = nm_setting_wired_get_mac_address (s_wired);
if (setting_hwaddr) {
@@ -1687,11 +1705,11 @@ default_wired_clear_tag (NMSettings *self,
NMSettingsConnection *connection,
gboolean add_to_no_auto_default)
{
- g_return_if_fail (NM_IS_SETTINGS (self));
- g_return_if_fail (NM_IS_DEVICE (device));
- g_return_if_fail (NM_IS_CONNECTION (connection));
- g_return_if_fail (device == g_object_get_qdata (G_OBJECT (connection), _default_wired_device_quark ()));
- g_return_if_fail (connection == g_object_get_qdata (G_OBJECT (device), _default_wired_connection_quark ()));
+ nm_assert (NM_IS_SETTINGS (self));
+ nm_assert (NM_IS_DEVICE (device));
+ nm_assert (NM_IS_SETTINGS_CONNECTION (connection));
+ nm_assert (device == g_object_get_qdata (G_OBJECT (connection), _default_wired_device_quark ()));
+ nm_assert (connection == g_object_get_qdata (G_OBJECT (device), _default_wired_connection_quark ()));
g_object_set_qdata (G_OBJECT (connection), _default_wired_device_quark (), NULL);
g_object_set_qdata (G_OBJECT (device), _default_wired_connection_quark (), NULL);
diff --git a/src/settings/nm-settings.h b/src/settings/nm-settings.h
index 021512fdaf..38d8ad4ed8 100644
--- a/src/settings/nm-settings.h
+++ b/src/settings/nm-settings.h
@@ -85,7 +85,7 @@ void nm_settings_add_connection_dbus (NMSettings *self,
NMSettingsAddCallback callback,
gpointer user_data);
-NMSettingsConnection *const* nm_settings_get_connections (NMSettings *settings, guint *out_len);
+NMSettingsConnection *const*nm_settings_get_connections (NMSettings *settings, guint *out_len);
NMSettingsConnection **nm_settings_get_connections_clone (NMSettings *self,
guint *out_len,
diff --git a/src/settings/plugins/ibft/nms-ibft-plugin.c b/src/settings/plugins/ibft/nms-ibft-plugin.c
index 77ce208f41..9785ba49c0 100644
--- a/src/settings/plugins/ibft/nms-ibft-plugin.c
+++ b/src/settings/plugins/ibft/nms-ibft-plugin.c
@@ -84,9 +84,9 @@ read_connections (NMSIbftPlugin *self)
connection = nms_ibft_connection_new (iter->data, &error);
if (connection) {
nm_log_info (LOGD_SETTINGS, "ibft: read connection '%s'",
- nm_connection_get_id (NM_CONNECTION (connection)));
+ nm_settings_connection_get_id (NM_SETTINGS_CONNECTION (connection)));
g_hash_table_insert (priv->connections,
- g_strdup (nm_connection_get_uuid (NM_CONNECTION (connection))),
+ g_strdup (nm_settings_connection_get_uuid (NM_SETTINGS_CONNECTION (connection))),
connection);
} else {
nm_log_warn (LOGD_SETTINGS, "ibft: failed to read iscsiadm record: %s", error->message);
diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c
index 6979fdaaaf..ca319ddc61 100644
--- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c
+++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c
@@ -143,7 +143,7 @@ devtimeout_expired (gpointer user_data)
NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE (self);
nm_log_info (LOGD_SETTINGS, "Device for connection '%s' did not appear before timeout",
- nm_connection_get_id (NM_CONNECTION (self)));
+ nm_settings_connection_get_id (NM_SETTINGS_CONNECTION (self)));
g_signal_handler_disconnect (NM_PLATFORM_GET, priv->devtimeout_link_changed_handler);
priv->devtimeout_link_changed_handler = 0;
@@ -163,7 +163,7 @@ nm_ifcfg_connection_check_devtimeout (NMIfcfgConnection *self)
guint devtimeout;
const NMPlatformLink *pllink;
- s_con = nm_connection_get_setting_connection (NM_CONNECTION (self));
+ s_con = nm_connection_get_setting_connection (nm_settings_connection_get_connection (NM_SETTINGS_CONNECTION (self)));
if (!nm_setting_connection_get_autoconnect (s_con))
return;
@@ -186,7 +186,7 @@ nm_ifcfg_connection_check_devtimeout (NMIfcfgConnection *self)
nm_settings_connection_set_ready (NM_SETTINGS_CONNECTION (self), FALSE);
nm_log_info (LOGD_SETTINGS, "Waiting %u seconds for %s to appear for connection '%s'",
- devtimeout, ifname, nm_connection_get_id (NM_CONNECTION (self)));
+ devtimeout, ifname, nm_settings_connection_get_id (NM_SETTINGS_CONNECTION (self)));
priv->devtimeout_link_changed_handler =
g_signal_connect (NM_PLATFORM_GET, NM_PLATFORM_SIGNAL_LINK_CHANGED,
diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c
index 0fb77b9d20..23856b1cd6 100644
--- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c
+++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c
@@ -139,7 +139,7 @@ static void
connection_removed_cb (NMSettingsConnection *obj, gpointer user_data)
{
g_hash_table_remove (SETTINGS_PLUGIN_IFCFG_GET_PRIVATE ((SettingsPluginIfcfg *) user_data)->connections,
- nm_connection_get_uuid (NM_CONNECTION (obj)));
+ nm_settings_connection_get_uuid (NM_SETTINGS_CONNECTION (obj)));
}
static void
@@ -157,7 +157,7 @@ remove_connection (SettingsPluginIfcfg *self, NMIfcfgConnection *connection)
unrecognized = !!nm_ifcfg_connection_get_unrecognized_spec (connection);
g_object_ref (connection);
- g_hash_table_remove (priv->connections, nm_connection_get_uuid (NM_CONNECTION (connection)));
+ g_hash_table_remove (priv->connections, nm_settings_connection_get_uuid (NM_SETTINGS_CONNECTION (connection)));
if (!unmanaged && !unrecognized)
nm_settings_connection_signal_remove (NM_SETTINGS_CONNECTION (connection));
g_object_unref (connection);
@@ -228,7 +228,7 @@ update_connection (SettingsPluginIfcfg *self,
return NULL;
}
- uuid = nm_connection_get_uuid (NM_CONNECTION (connection_new));
+ uuid = nm_settings_connection_get_uuid (NM_SETTINGS_CONNECTION (connection_new));
connection_by_uuid = g_hash_table_lookup (priv->connections, uuid);
if ( connection
@@ -285,12 +285,16 @@ update_connection (SettingsPluginIfcfg *self,
if ( !unmanaged_changed
&& !unrecognized_changed
- && nm_connection_compare (NM_CONNECTION (connection_by_uuid),
- NM_CONNECTION (connection_new),
+ && nm_connection_compare (nm_settings_connection_get_connection (NM_SETTINGS_CONNECTION (connection_by_uuid)),
+ nm_settings_connection_get_connection (NM_SETTINGS_CONNECTION (connection_new)),
NM_SETTING_COMPARE_FLAG_IGNORE_AGENT_OWNED_SECRETS |
NM_SETTING_COMPARE_FLAG_IGNORE_NOT_SAVED_SECRETS)) {
- if (old_path && g_strcmp0 (old_path, full_path) != 0)
- _LOGI ("rename \"%s\" to "NM_IFCFG_CONNECTION_LOG_FMT" without other changes", nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (connection_by_uuid)), NM_IFCFG_CONNECTION_LOG_ARG (connection_new));
+ if ( old_path
+ && !nm_streq0 (old_path, full_path)) {
+ _LOGI ("rename \"%s\" to "NM_IFCFG_CONNECTION_LOG_FMT" without other changes",
+ nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (connection_by_uuid)),
+ NM_IFCFG_CONNECTION_LOG_ARG (connection_new));
+ }
} else {
/*******************************************************
@@ -299,7 +303,7 @@ update_connection (SettingsPluginIfcfg *self,
if (source)
_LOGI ("update "NM_IFCFG_CONNECTION_LOG_FMT" from %s", NM_IFCFG_CONNECTION_LOG_ARG (connection_new), NM_IFCFG_CONNECTION_LOG_PATH (old_path));
- else if (!g_strcmp0 (old_path, nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (connection_new))))
+ else if (nm_streq0 (old_path, nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (connection_new))))
_LOGI ("update "NM_IFCFG_CONNECTION_LOG_FMT, NM_IFCFG_CONNECTION_LOG_ARG (connection_new));
else if (old_path)
_LOGI ("rename \"%s\" to "NM_IFCFG_CONNECTION_LOG_FMT, old_path, NM_IFCFG_CONNECTION_LOG_ARG (connection_new));
@@ -312,7 +316,7 @@ update_connection (SettingsPluginIfcfg *self,
NULL);
if (!nm_settings_connection_update (NM_SETTINGS_CONNECTION (connection_by_uuid),
- NM_CONNECTION (connection_new),
+ nm_settings_connection_get_connection (NM_SETTINGS_CONNECTION (connection_new)),
NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP_SAVED,
NM_SETTINGS_CONNECTION_COMMIT_REASON_NONE,
"ifcfg-update",
@@ -338,7 +342,7 @@ update_connection (SettingsPluginIfcfg *self,
* so add it back now.
*/
g_hash_table_insert (priv->connections,
- g_strdup (nm_connection_get_uuid (NM_CONNECTION (connection_by_uuid))),
+ g_strdup (nm_settings_connection_get_uuid (NM_SETTINGS_CONNECTION (connection_by_uuid))),
connection_by_uuid /* we took reference above and pass it on */);
}
} else {
@@ -731,7 +735,7 @@ impl_ifcfgrh_get_ifcfg_details (SettingsPluginIfcfg *plugin,
return;
}
- s_con = nm_connection_get_setting_connection (NM_CONNECTION (connection));
+ s_con = nm_connection_get_setting_connection (nm_settings_connection_get_connection (NM_SETTINGS_CONNECTION (connection)));
if (!s_con) {
g_dbus_method_invocation_return_error (context,
NM_SETTINGS_ERROR,
diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h
index d95b1f61cf..84c22094f3 100644
--- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h
+++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h
@@ -28,9 +28,9 @@
#define NM_IFCFG_CONNECTION_LOG_PATH(path) ((path) ?: "in-memory")
#define NM_IFCFG_CONNECTION_LOG_FMT "%s (%s,\"%s\")"
-#define NM_IFCFG_CONNECTION_LOG_ARG(con) NM_IFCFG_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_connection_get_uuid ((NMConnection *) (con)), nm_connection_get_id ((NMConnection *) (con))
+#define NM_IFCFG_CONNECTION_LOG_ARG(con) NM_IFCFG_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_settings_connection_get_uuid ((NMSettingsConnection *) (con)), nm_settings_connection_get_id ((NMSettingsConnection *) (con))
#define NM_IFCFG_CONNECTION_LOG_FMTD "%s (%s,\"%s\",%p)"
-#define NM_IFCFG_CONNECTION_LOG_ARGD(con) NM_IFCFG_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_connection_get_uuid ((NMConnection *) (con)), nm_connection_get_id ((NMConnection *) (con)), (con)
+#define NM_IFCFG_CONNECTION_LOG_ARGD(con) NM_IFCFG_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_settings_connection_get_uuid ((NMSettingsConnection *) (con)), nm_settings_connection_get_id ((NMSettingsConnection *) (con)), (con)
char *utils_cert_path (const char *parent, const char *suffix, const char *extension);
diff --git a/src/settings/plugins/ifupdown/nms-ifupdown-connection.c b/src/settings/plugins/ifupdown/nms-ifupdown-connection.c
index c3d231fe16..bdca91d66c 100644
--- a/src/settings/plugins/ifupdown/nms-ifupdown-connection.c
+++ b/src/settings/plugins/ifupdown/nms-ifupdown-connection.c
@@ -64,26 +64,29 @@ nm_ifupdown_connection_init (NMIfupdownConnection *connection)
{
}
-NMIfupdownConnection*
+NMIfupdownConnection *
nm_ifupdown_connection_new (if_block *block)
{
- GObject *object;
+ NMIfupdownConnection *connection;
GError *error = NULL;
g_return_val_if_fail (block != NULL, NULL);
- object = g_object_new (NM_TYPE_IFUPDOWN_CONNECTION, NULL);
+ connection = g_object_new (NM_TYPE_IFUPDOWN_CONNECTION, NULL);
- if (!ifupdown_update_connection_from_if_block (NM_CONNECTION (object), block, &error)) {
+ /* FIXME(copy-on-write-connection): avoid modifying NMConnection instances and share them via copy-on-write. */
+ if (!ifupdown_update_connection_from_if_block (nm_settings_connection_get_connection (NM_SETTINGS_CONNECTION (connection)),
+ block,
+ &error)) {
nm_log_warn (LOGD_SETTINGS, "%s.%d - invalid connection read from /etc/network/interfaces: %s",
__FILE__,
__LINE__,
error->message);
- g_object_unref (object);
+ g_object_unref (connection);
return NULL;
}
- return (NMIfupdownConnection *) object;
+ return connection;
}
static void
diff --git a/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c b/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c
index 8bd72d0268..a6b22de24d 100644
--- a/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c
+++ b/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c
@@ -126,8 +126,8 @@ bind_device_to_connection (SettingsPluginIfupdown *self,
return;
}
- s_wired = nm_connection_get_setting_wired (NM_CONNECTION (exported));
- s_wifi = nm_connection_get_setting_wireless (NM_CONNECTION (exported));
+ s_wired = nm_connection_get_setting_wired (nm_settings_connection_get_connection (NM_SETTINGS_CONNECTION (exported)));
+ s_wifi = nm_connection_get_setting_wireless (nm_settings_connection_get_connection (NM_SETTINGS_CONNECTION (exported)));
if (s_wired) {
nm_log_info (LOGD_SETTINGS, "locking wired connection setting");
g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, address, NULL);
@@ -415,7 +415,8 @@ init (NMSettingsPlugin *config)
NMSettingConnection *setting;
if (g_hash_table_lookup (auto_ifaces, block_name)) {
- setting = nm_connection_get_setting_connection (NM_CONNECTION (connection));
+ /* FIXME(copy-on-write-connection): avoid modifying NMConnection instances and share them via copy-on-write. */
+ setting = nm_connection_get_setting_connection (nm_settings_connection_get_connection (NM_SETTINGS_CONNECTION (connection)));
g_object_set (setting, NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NULL);
nm_log_info (LOGD_SETTINGS, "autoconnect");
}
diff --git a/src/settings/plugins/keyfile/nms-keyfile-connection.c b/src/settings/plugins/keyfile/nms-keyfile-connection.c
index 5f72a9fabe..2dbce4e0c9 100644
--- a/src/settings/plugins/keyfile/nms-keyfile-connection.c
+++ b/src/settings/plugins/keyfile/nms-keyfile-connection.c
@@ -142,7 +142,7 @@ nms_keyfile_connection_new (NMConnection *source,
if (!tmp)
return NULL;
- uuid = nm_connection_get_uuid (NM_CONNECTION (tmp));
+ uuid = nm_connection_get_uuid (tmp);
if (!uuid) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Connection in file %s had no UUID", full_path);
@@ -154,9 +154,9 @@ nms_keyfile_connection_new (NMConnection *source,
update_unsaved = FALSE;
}
- object = (GObject *) g_object_new (NMS_TYPE_KEYFILE_CONNECTION,
- NM_SETTINGS_CONNECTION_FILENAME, full_path,
- NULL);
+ object = g_object_new (NMS_TYPE_KEYFILE_CONNECTION,
+ NM_SETTINGS_CONNECTION_FILENAME, full_path,
+ NULL);
/* Update our settings with what was read from the file */
if (!nm_settings_connection_update (NM_SETTINGS_CONNECTION (object),
diff --git a/src/settings/plugins/keyfile/nms-keyfile-plugin.c b/src/settings/plugins/keyfile/nms-keyfile-plugin.c
index 3723db945c..7b2249460b 100644
--- a/src/settings/plugins/keyfile/nms-keyfile-plugin.c
+++ b/src/settings/plugins/keyfile/nms-keyfile-plugin.c
@@ -85,10 +85,10 @@ G_DEFINE_TYPE_EXTENDED (NMSKeyfilePlugin, nms_keyfile_plugin, G_TYPE_OBJECT, 0,
/*****************************************************************************/
static void
-connection_removed_cb (NMSettingsConnection *obj, gpointer user_data)
+connection_removed_cb (NMSettingsConnection *sett_conn, NMSKeyfilePlugin *self)
{
- g_hash_table_remove (NMS_KEYFILE_PLUGIN_GET_PRIVATE ((NMSKeyfilePlugin *) user_data)->connections,
- nm_connection_get_uuid (NM_CONNECTION (obj)));
+ g_hash_table_remove (NMS_KEYFILE_PLUGIN_GET_PRIVATE (self)->connections,
+ nm_settings_connection_get_uuid (sett_conn));
}
/* Monitoring */
@@ -106,7 +106,7 @@ remove_connection (NMSKeyfilePlugin *self, NMSKeyfileConnection *connection)
g_object_ref (connection);
g_signal_handlers_disconnect_by_func (connection, connection_removed_cb, self);
removed = g_hash_table_remove (NMS_KEYFILE_PLUGIN_GET_PRIVATE (self)->connections,
- nm_connection_get_uuid (NM_CONNECTION (connection)));
+ nm_settings_connection_get_uuid (NM_SETTINGS_CONNECTION (connection)));
nm_settings_connection_signal_remove (NM_SETTINGS_CONNECTION (connection));
g_object_unref (connection);
@@ -197,7 +197,7 @@ update_connection (NMSKeyfilePlugin *self,
return NULL;
}
- uuid = nm_connection_get_uuid (NM_CONNECTION (connection_new));
+ uuid = nm_settings_connection_get_uuid (NM_SETTINGS_CONNECTION (connection_new));
connection_by_uuid = g_hash_table_lookup (priv->connections, uuid);
if ( connection
diff --git a/src/settings/plugins/keyfile/nms-keyfile-utils.h b/src/settings/plugins/keyfile/nms-keyfile-utils.h
index cd3f42b9f9..d5ddb8d536 100644
--- a/src/settings/plugins/keyfile/nms-keyfile-utils.h
+++ b/src/settings/plugins/keyfile/nms-keyfile-utils.h
@@ -25,9 +25,9 @@
#define NMS_KEYFILE_CONNECTION_LOG_PATH(path) ((path) ?: "in-memory")
#define NMS_KEYFILE_CONNECTION_LOG_FMT "%s (%s,\"%s\")"
-#define NMS_KEYFILE_CONNECTION_LOG_ARG(con) NMS_KEYFILE_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_connection_get_uuid ((NMConnection *) (con)), nm_connection_get_id ((NMConnection *) (con))
+#define NMS_KEYFILE_CONNECTION_LOG_ARG(con) NMS_KEYFILE_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_settings_connection_get_uuid ((NMSettingsConnection *) (con)), nm_settings_connection_get_id ((NMSettingsConnection *) (con))
#define NMS_KEYFILE_CONNECTION_LOG_FMTD "%s (%s,\"%s\",%p)"
-#define NMS_KEYFILE_CONNECTION_LOG_ARGD(con) NMS_KEYFILE_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_connection_get_uuid ((NMConnection *) (con)), nm_connection_get_id ((NMConnection *) (con)), (con)
+#define NMS_KEYFILE_CONNECTION_LOG_ARGD(con) NMS_KEYFILE_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_settings_connection_get_uuid ((NMSettingsConnection *) (con)), nm_settings_connection_get_id ((NMSettingsConnection *) (con)), (con)
gboolean nms_keyfile_utils_should_ignore_file (const char *filename);