diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/devices/bluetooth/nm-bluez-device.c | 1 | ||||
-rw-r--r-- | src/devices/wifi/nm-iwd-manager.c | 1 | ||||
-rw-r--r-- | src/nm-checkpoint.c | 1 | ||||
-rw-r--r-- | src/nm-manager.c | 2 | ||||
-rw-r--r-- | src/settings/nm-settings-connection.c | 21 | ||||
-rw-r--r-- | src/settings/nm-settings-connection.h | 10 | ||||
-rw-r--r-- | src/settings/nm-settings.c | 133 | ||||
-rw-r--r-- | src/settings/nm-settings.h | 2 |
8 files changed, 149 insertions, 22 deletions
diff --git a/src/devices/bluetooth/nm-bluez-device.c b/src/devices/bluetooth/nm-bluez-device.c index e8ca6dd159..fb0a72c40f 100644 --- a/src/devices/bluetooth/nm-bluez-device.c +++ b/src/devices/bluetooth/nm-bluez-device.c @@ -238,6 +238,7 @@ pan_connection_check_create (NMBluezDevice *self) nm_settings_add_connection (priv->settings, connection, NM_SETTINGS_CONNECTION_PERSIST_MODE_IN_MEMORY_ONLY, + NM_SETTINGS_CONNECTION_ADD_REASON_NONE, NM_SETTINGS_CONNECTION_INT_FLAGS_NM_GENERATED, &added, &error); diff --git a/src/devices/wifi/nm-iwd-manager.c b/src/devices/wifi/nm-iwd-manager.c index 8889bb204a..b696f128a7 100644 --- a/src/devices/wifi/nm-iwd-manager.c +++ b/src/devices/wifi/nm-iwd-manager.c @@ -472,6 +472,7 @@ mirror_8021x_connection (NMIwdManager *self, if (!nm_settings_add_connection (priv->settings, connection, NM_SETTINGS_CONNECTION_PERSIST_MODE_IN_MEMORY_ONLY, + NM_SETTINGS_CONNECTION_ADD_REASON_NONE, NM_SETTINGS_CONNECTION_INT_FLAGS_NM_GENERATED, &settings_connection, &error)) { diff --git a/src/nm-checkpoint.c b/src/nm-checkpoint.c index b8277539e3..08a93fd378 100644 --- a/src/nm-checkpoint.c +++ b/src/nm-checkpoint.c @@ -257,6 +257,7 @@ restore_and_activate_connection (NMCheckpoint *self, if (!nm_settings_add_connection (NM_SETTINGS_GET, dev_checkpoint->settings_connection, persist_mode, + NM_SETTINGS_CONNECTION_ADD_REASON_NONE, sett_flags, &connection, &local_error)) { diff --git a/src/nm-manager.c b/src/nm-manager.c index 605e04e238..c56d798092 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -2668,6 +2668,7 @@ get_existing_connection (NMManager *self, if (!nm_settings_add_connection (priv->settings, connection, NM_SETTINGS_CONNECTION_PERSIST_MODE_IN_MEMORY_ONLY, + NM_SETTINGS_CONNECTION_ADD_REASON_NONE, NM_SETTINGS_CONNECTION_INT_FLAGS_VOLATILE | NM_SETTINGS_CONNECTION_INT_FLAGS_NM_GENERATED, &added, @@ -5413,6 +5414,7 @@ _add_and_activate_auth_done (NMManager *self, nm_settings_add_connection_dbus (priv->settings, connection, persist_mode, + NM_SETTINGS_CONNECTION_ADD_REASON_NONE, ( is_volatile ? NM_SETTINGS_CONNECTION_INT_FLAGS_VOLATILE : NM_SETTINGS_CONNECTION_INT_FLAGS_NONE), diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c index 781c9977a9..dbe775c720 100644 --- a/src/settings/nm-settings-connection.c +++ b/src/settings/nm-settings-connection.c @@ -1419,7 +1419,7 @@ update_complete (NMSettingsConnection *self, g_variant_builder_init (&result, G_VARIANT_TYPE ("a{sv}")); g_dbus_method_invocation_return_value (info->context, - g_variant_new ("(@a{sv})", g_variant_builder_end (&result))); + g_variant_new ("(a{sv})", &result)); } else g_dbus_method_invocation_return_value (info->context, NULL); @@ -1495,12 +1495,6 @@ update_auth_cb (NMSettingsConnection *self, } else persist_mode = NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP; - if (NM_FLAGS_HAS (info->flags, NM_SETTINGS_UPDATE2_FLAG_BLOCK_AUTOCONNECT)) { - nm_settings_connection_autoconnect_blocked_reason_set (self, - NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_USER_REQUEST, - TRUE); - } - nm_settings_connection_update (self, info->new_settings, persist_mode, @@ -1514,7 +1508,10 @@ update_auth_cb (NMSettingsConnection *self, ? NM_SETTINGS_CONNECTION_UPDATE_REASON_NONE : NM_SETTINGS_CONNECTION_UPDATE_REASON_REAPPLY_PARTIAL) | NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_SYSTEM_SECRETS - | NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_AGENT_SECRETS, + | NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_AGENT_SECRETS + | ( NM_FLAGS_HAS (info->flags, NM_SETTINGS_UPDATE2_FLAG_BLOCK_AUTOCONNECT) + ? NM_SETTINGS_CONNECTION_UPDATE_REASON_BLOCK_AUTOCONNECT + : NM_SETTINGS_CONNECTION_UPDATE_REASON_NONE), "update-from-dbus", &local); @@ -1741,13 +1738,7 @@ impl_settings_connection_update2 (NMDBusObject *obj, return; } - if (!g_variant_is_of_type (args, G_VARIANT_TYPE ("a{sv}"))) { - error = g_error_new_literal (NM_SETTINGS_ERROR, - NM_SETTINGS_ERROR_INVALID_ARGUMENTS, - "args is of invalid type"); - g_dbus_method_invocation_take_error (invocation, error); - return; - } + nm_assert (g_variant_is_of_type (args, G_VARIANT_TYPE ("a{sv}"))); g_variant_iter_init (&iter, args); while (g_variant_iter_next (&iter, "{&sv}", &args_name, NULL)) { diff --git a/src/settings/nm-settings-connection.h b/src/settings/nm-settings-connection.h index 978ece9621..5d46369b75 100644 --- a/src/settings/nm-settings-connection.h +++ b/src/settings/nm-settings-connection.h @@ -30,6 +30,14 @@ typedef enum { + NM_SETTINGS_CONNECTION_ADD_REASON_NONE = 0, + + NM_SETTINGS_CONNECTION_ADD_REASON_BLOCK_AUTOCONNECT = (1u << 0), + +} NMSettingsConnectionAddReason; + +typedef enum { + NM_SETTINGS_CONNECTION_UPDATE_REASON_NONE = 0, /* with persist-mode != NM_SETTINGS_CONNECTION_PERSIST_MODE_IN_MEMORY_ONLY, and @@ -67,6 +75,8 @@ typedef enum { * to disk and it the purpose why the profile was created should be forgotten. */ NM_SETTINGS_CONNECTION_UPDATE_REASON_CLEAR_DEFAULT_WIRED = (1u << 7), + NM_SETTINGS_CONNECTION_UPDATE_REASON_BLOCK_AUTOCONNECT = (1u << 8), + } NMSettingsConnectionUpdateReason; typedef enum { diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c index b91e67d5ae..57fd0359a8 100644 --- a/src/settings/nm-settings.c +++ b/src/settings/nm-settings.c @@ -922,7 +922,12 @@ _connection_changed_update (NMSettings *self, priv->connections_generation++; g_signal_connect (sett_conn, NM_SETTINGS_CONNECTION_FLAGS_CHANGED, G_CALLBACK (connection_flags_changed), self); + } + if (NM_FLAGS_HAS (update_reason, NM_SETTINGS_CONNECTION_UPDATE_REASON_BLOCK_AUTOCONNECT)) { + nm_settings_connection_autoconnect_blocked_reason_set (sett_conn, + NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_USER_REQUEST, + TRUE); } sett_mask |= NM_SETTINGS_CONNECTION_INT_FLAGS_VISIBLE; @@ -1370,6 +1375,7 @@ _add_connection_to_first_plugin (NMSettings *self, * @self: the #NMSettings object * @connection: the source connection to create a new #NMSettingsConnection from * @persist_mode: the persist-mode for this profile. + * @add_reason: the add-reason flags. * @sett_flags: the settings flags to set. * @out_sett_conn: (allow-none) (transfer none): the added settings connection on success. * @error: on return, a location to store any errors that may occur @@ -1384,6 +1390,7 @@ gboolean nm_settings_add_connection (NMSettings *self, NMConnection *connection, NMSettingsConnectionPersistMode persist_mode, + NMSettingsConnectionAddReason add_reason, NMSettingsConnectionIntFlags sett_flags, NMSettingsConnection **out_sett_conn, GError **error) @@ -1407,6 +1414,8 @@ nm_settings_add_connection (NMSettings *self, nm_assert ( !NM_FLAGS_HAS (sett_flags, NM_SETTINGS_CONNECTION_INT_FLAGS_VOLATILE) || persist_mode == NM_SETTINGS_CONNECTION_PERSIST_MODE_IN_MEMORY_ONLY); + nm_assert (!NM_FLAGS_ANY (add_reason, ~NM_SETTINGS_CONNECTION_ADD_REASON_BLOCK_AUTOCONNECT)); + NM_SET_OUT (out_sett_conn, NULL); uuid = nm_connection_get_uuid (connection); @@ -1485,7 +1494,10 @@ nm_settings_add_connection (NMSettings *self, _NM_SETTINGS_CONNECTION_INT_FLAGS_PERSISTENT_MASK, FALSE, NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_SYSTEM_SECRETS - | NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_AGENT_SECRETS); + | NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_AGENT_SECRETS + | ( NM_FLAGS_HAS (add_reason, NM_SETTINGS_CONNECTION_ADD_REASON_BLOCK_AUTOCONNECT) + ? NM_SETTINGS_CONNECTION_UPDATE_REASON_BLOCK_AUTOCONNECT + : NM_SETTINGS_CONNECTION_UPDATE_REASON_NONE)); nm_assert (sett_conn_entry == _sett_conn_entries_get (self, sett_conn_entry->uuid)); nm_assert (NM_IS_SETTINGS_CONNECTION (sett_conn_entry->sett_conn)); @@ -1952,6 +1964,7 @@ pk_add_cb (NMAuthChain *chain, nm_settings_add_connection (self, connection, GPOINTER_TO_UINT (nm_auth_chain_get_data (chain, "persist-mode")), + GPOINTER_TO_UINT (nm_auth_chain_get_data (chain, "add-reason")), GPOINTER_TO_UINT (nm_auth_chain_get_data (chain, "sett-flags")), &added, &error); @@ -1979,6 +1992,7 @@ void nm_settings_add_connection_dbus (NMSettings *self, NMConnection *connection, NMSettingsConnectionPersistMode persist_mode, + NMSettingsConnectionAddReason add_reason, NMSettingsConnectionIntFlags sett_flags, NMAuthSubject *subject, GDBusMethodInvocation *context, @@ -2053,6 +2067,7 @@ nm_settings_add_connection_dbus (NMSettings *self, nm_auth_chain_set_data (chain, "callback-data", user_data, NULL); nm_auth_chain_set_data (chain, "subject", g_object_ref (subject), g_object_unref); nm_auth_chain_set_data (chain, "persist-mode", GUINT_TO_POINTER (persist_mode), NULL); + nm_auth_chain_set_data (chain, "add-reason", GUINT_TO_POINTER (add_reason), NULL); nm_auth_chain_set_data (chain, "sett-flags", GUINT_TO_POINTER (sett_flags), NULL); nm_auth_chain_add_call_unsafe (chain, perm, TRUE); return; @@ -2071,27 +2086,42 @@ settings_add_connection_add_cb (NMSettings *self, NMAuthSubject *subject, gpointer user_data) { + gboolean is_add_connection_2 = GPOINTER_TO_INT (user_data); + if (error) { g_dbus_method_invocation_return_gerror (context, error); nm_audit_log_connection_op (NM_AUDIT_OP_CONN_ADD, NULL, FALSE, NULL, subject, error->message); + return; + } + + if (is_add_connection_2) { + GVariantBuilder builder; + + g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT); + g_dbus_method_invocation_return_value (context, + g_variant_new ("(oa{sv})", + nm_dbus_object_get_path (NM_DBUS_OBJECT (connection)), + &builder)); } else { g_dbus_method_invocation_return_value (context, g_variant_new ("(o)", nm_dbus_object_get_path (NM_DBUS_OBJECT (connection)))); - nm_audit_log_connection_op (NM_AUDIT_OP_CONN_ADD, connection, TRUE, NULL, - subject, NULL); } + nm_audit_log_connection_op (NM_AUDIT_OP_CONN_ADD, connection, TRUE, NULL, + subject, NULL); } static void settings_add_connection_helper (NMSettings *self, GDBusMethodInvocation *context, + gboolean is_add_connection_2, GVariant *settings, - NMSettingsConnectionPersistMode persist_mode) + NMSettingsAddConnection2Flags flags) { gs_unref_object NMConnection *connection = NULL; GError *error = NULL; gs_unref_object NMAuthSubject *subject = NULL; + NMSettingsConnectionPersistMode persist_mode; connection = _nm_simple_connection_new_from_dbus (settings, NM_SETTING_PARSE_FLAGS_STRICT @@ -2113,14 +2143,24 @@ settings_add_connection_helper (NMSettings *self, return; } + if (NM_FLAGS_HAS (flags, NM_SETTINGS_ADD_CONNECTION2_FLAG_TO_DISK)) + persist_mode = NM_SETTINGS_CONNECTION_PERSIST_MODE_DISK; + else { + nm_assert (NM_FLAGS_HAS (flags, NM_SETTINGS_ADD_CONNECTION2_FLAG_IN_MEMORY)); + persist_mode = NM_SETTINGS_CONNECTION_PERSIST_MODE_IN_MEMORY_ONLY; + } + nm_settings_add_connection_dbus (self, connection, persist_mode, + NM_FLAGS_HAS (flags, NM_SETTINGS_ADD_CONNECTION2_FLAG_BLOCK_AUTOCONNECT) + ? NM_SETTINGS_CONNECTION_ADD_REASON_BLOCK_AUTOCONNECT + : NM_SETTINGS_CONNECTION_ADD_REASON_NONE, NM_SETTINGS_CONNECTION_INT_FLAGS_NONE, subject, context, settings_add_connection_add_cb, - NULL); + GINT_TO_POINTER (!!is_add_connection_2)); } static void @@ -2136,7 +2176,7 @@ impl_settings_add_connection (NMDBusObject *obj, gs_unref_variant GVariant *settings = NULL; g_variant_get (parameters, "(@a{sa{sv}})", &settings); - settings_add_connection_helper (self, invocation, settings, NM_SETTINGS_CONNECTION_PERSIST_MODE_DISK); + settings_add_connection_helper (self, invocation, FALSE, settings, NM_SETTINGS_ADD_CONNECTION2_FLAG_TO_DISK); } static void @@ -2152,7 +2192,70 @@ impl_settings_add_connection_unsaved (NMDBusObject *obj, gs_unref_variant GVariant *settings = NULL; g_variant_get (parameters, "(@a{sa{sv}})", &settings); - settings_add_connection_helper (self, invocation, settings, NM_SETTINGS_CONNECTION_PERSIST_MODE_IN_MEMORY_ONLY); + settings_add_connection_helper (self, invocation, FALSE, settings, NM_SETTINGS_ADD_CONNECTION2_FLAG_IN_MEMORY); +} + +static void +impl_settings_add_connection2 (NMDBusObject *obj, + const NMDBusInterfaceInfoExtended *interface_info, + const NMDBusMethodInfoExtended *method_info, + GDBusConnection *connection, + const char *sender, + GDBusMethodInvocation *invocation, + GVariant *parameters) +{ + NMSettings *self = NM_SETTINGS (obj); + gs_unref_variant GVariant *settings = NULL; + gs_unref_variant GVariant *args = NULL; + NMSettingsAddConnection2Flags flags; + const char *args_name; + GVariantIter iter; + guint32 flags_u; + + g_variant_get (parameters, "(@a{sa{sv}}u@a{sv})", &settings, &flags_u, &args); + + if (NM_FLAGS_ANY (flags_u, ~((guint32) ( NM_SETTINGS_ADD_CONNECTION2_FLAG_TO_DISK + | NM_SETTINGS_ADD_CONNECTION2_FLAG_IN_MEMORY + | NM_SETTINGS_ADD_CONNECTION2_FLAG_BLOCK_AUTOCONNECT)))) { + g_dbus_method_invocation_take_error (invocation, + g_error_new_literal (NM_SETTINGS_ERROR, + NM_SETTINGS_ERROR_INVALID_ARGUMENTS, + "Unknown flags")); + return; + } + + flags = flags_u; + + if (!NM_FLAGS_ANY (flags, NM_SETTINGS_ADD_CONNECTION2_FLAG_TO_DISK + | NM_SETTINGS_ADD_CONNECTION2_FLAG_IN_MEMORY)) { + g_dbus_method_invocation_take_error (invocation, + g_error_new_literal (NM_SETTINGS_ERROR, + NM_SETTINGS_ERROR_INVALID_ARGUMENTS, + "Requires either to-disk (0x1) or in-memory (0x2) flags")); + return; + } + + if (NM_FLAGS_ALL (flags, NM_SETTINGS_ADD_CONNECTION2_FLAG_TO_DISK + | NM_SETTINGS_ADD_CONNECTION2_FLAG_IN_MEMORY)) { + g_dbus_method_invocation_take_error (invocation, + g_error_new_literal (NM_SETTINGS_ERROR, + NM_SETTINGS_ERROR_INVALID_ARGUMENTS, + "Cannot set to-disk (0x1) and in-memory (0x2) flags together")); + return; + } + + nm_assert (g_variant_is_of_type (args, G_VARIANT_TYPE ("a{sv}"))); + + g_variant_iter_init (&iter, args); + while (g_variant_iter_next (&iter, "{&sv}", &args_name, NULL)) { + g_dbus_method_invocation_take_error (invocation, + g_error_new (NM_SETTINGS_ERROR, + NM_SETTINGS_ERROR_INVALID_ARGUMENTS, + "Unsupported argument '%s'", args_name)); + return; + } + + settings_add_connection_helper (self, invocation, TRUE, settings, flags); } /*****************************************************************************/ @@ -2900,6 +3003,7 @@ device_realized (NMDevice *device, GParamSpec *pspec, NMSettings *self) nm_settings_add_connection (self, connection, NM_SETTINGS_CONNECTION_PERSIST_MODE_IN_MEMORY_ONLY, + NM_SETTINGS_CONNECTION_ADD_REASON_NONE, NM_SETTINGS_CONNECTION_INT_FLAGS_NM_GENERATED, &added, &error); @@ -3399,6 +3503,21 @@ static const NMDBusInterfaceInfoExtended interface_info_settings = { ), NM_DEFINE_DBUS_METHOD_INFO_EXTENDED ( NM_DEFINE_GDBUS_METHOD_INFO_INIT ( + "AddConnection2", + .in_args = NM_DEFINE_GDBUS_ARG_INFOS ( + NM_DEFINE_GDBUS_ARG_INFO ("settings", "a{sa{sv}}"), + NM_DEFINE_GDBUS_ARG_INFO ("flags", "u"), + NM_DEFINE_GDBUS_ARG_INFO ("args", "a{sv}"), + ), + .out_args = NM_DEFINE_GDBUS_ARG_INFOS ( + NM_DEFINE_GDBUS_ARG_INFO ("path", "o"), + NM_DEFINE_GDBUS_ARG_INFO ("result", "a{sv}"), + ), + ), + .handle = impl_settings_add_connection2, + ), + NM_DEFINE_DBUS_METHOD_INFO_EXTENDED ( + NM_DEFINE_GDBUS_METHOD_INFO_INIT ( "LoadConnections", .in_args = NM_DEFINE_GDBUS_ARG_INFOS ( NM_DEFINE_GDBUS_ARG_INFO ("filenames", "as"), diff --git a/src/settings/nm-settings.h b/src/settings/nm-settings.h index bcb30dff2a..d2bf72d693 100644 --- a/src/settings/nm-settings.h +++ b/src/settings/nm-settings.h @@ -82,6 +82,7 @@ typedef void (*NMSettingsAddCallback) (NMSettings *settings, void nm_settings_add_connection_dbus (NMSettings *self, NMConnection *connection, NMSettingsConnectionPersistMode persist_mode, + NMSettingsConnectionAddReason add_reason, NMSettingsConnectionIntFlags sett_flags, NMAuthSubject *subject, GDBusMethodInvocation *context, @@ -100,6 +101,7 @@ NMSettingsConnection **nm_settings_get_connections_clone (NMSettings *self, gboolean nm_settings_add_connection (NMSettings *settings, NMConnection *connection, NMSettingsConnectionPersistMode persist_mode, + NMSettingsConnectionAddReason add_reason, NMSettingsConnectionIntFlags sett_flags, NMSettingsConnection **out_sett_conn, GError **error); |