summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-07-09 15:22:01 +0200
committerThomas Haller <thaller@redhat.com>2019-07-25 15:26:49 +0200
commit22c8721f35ec111335be0acc36bb0cc7b89bf97d (patch)
tree87f4576ae17008edd4d09594444f37ef0e41dc07
parent0aa323fb2887fc4b5decfb5360d7384bf774e6db (diff)
downloadNetworkManager-22c8721f35ec111335be0acc36bb0cc7b89bf97d.tar.gz
core,libnm: add AddConnection2() D-Bus API to block autoconnect from the start
It should be possible to add a profile with autoconnect blocked form the start. Update2() has a %NM_SETTINGS_UPDATE2_FLAG_BLOCK_AUTOCONNECT flag to block autoconnect, and so we need something similar when adding a connection. As the existing AddConnection() and AddConnectionUnsaved() API is not extensible, add AddConnection2() that has flags and room for additional arguments. Then add and implement the new flag %NM_SETTINGS_ADD_CONNECTION2_FLAG_BLOCK_AUTOCONNECT for AddConnection2(). Note that libnm's nm_client_add_connection2() API can completely replace the existing nm_client_add_connection_async() call. In particular, it will automatically prefer to call the D-Bus methods AddConnection() and AddConnectionUnsaved(), in order to work with server versions older than 1.20. The purpose of this is that when upgrading the package, the running NetworkManager might still be older than the installed libnm. Anyway, so since nm_client_add_connection2_finish() also has a result output, the caller needs to decide whether he cares about that result. Hence it has an argument ignore_out_result, which allows to fallback to the old API. One might argue that a caller who doesn't care about the output results while still wanting to be backward compatible, should itself choose to call nm_client_add_connection_async() or nm_client_add_connection2(). But instead, it's more convenient if the new function can fully replace the old one, so that the caller does not need to switch which start/finish method to call. https://bugzilla.redhat.com/show_bug.cgi?id=1677068
-rw-r--r--introspection/org.freedesktop.NetworkManager.Settings.xml35
-rw-r--r--libnm-core/nm-dbus-interface.h21
-rw-r--r--libnm/libnm.ver3
-rw-r--r--libnm/nm-client.c174
-rw-r--r--libnm/nm-client.h16
-rw-r--r--libnm/nm-remote-settings.c257
-rw-r--r--libnm/nm-remote-settings.h23
-rw-r--r--src/devices/bluetooth/nm-bluez-device.c1
-rw-r--r--src/devices/wifi/nm-iwd-manager.c1
-rw-r--r--src/nm-checkpoint.c1
-rw-r--r--src/nm-manager.c2
-rw-r--r--src/settings/nm-settings-connection.c21
-rw-r--r--src/settings/nm-settings-connection.h10
-rw-r--r--src/settings/nm-settings.c133
-rw-r--r--src/settings/nm-settings.h2
15 files changed, 553 insertions, 147 deletions
diff --git a/introspection/org.freedesktop.NetworkManager.Settings.xml b/introspection/org.freedesktop.NetworkManager.Settings.xml
index 73da345ceb..f7be2717b8 100644
--- a/introspection/org.freedesktop.NetworkManager.Settings.xml
+++ b/introspection/org.freedesktop.NetworkManager.Settings.xml
@@ -64,6 +64,41 @@
</method>
<!--
+ AddConnection2:
+ @settings: New connection settings, properties, and (optionally) secrets.
+ @flags: optional flags argument. Currently the following flags are supported:
+ "0x1" (to-disk),
+ "0x2" (in-memory),
+ "0x20" (block-autoconnect).
+ Unknown flags cause the call to fail.
+ @args: optional arguments dictionary, for extensibility. Currently no
+ arguments are accepted. Specifying unknown keys causes the call
+ to fail.
+ @path: Object path of the new connection that was just added.
+ @result: output argument, currently no additional results are returned.
+
+ Add a new connection profile.
+
+ Either the flags 0x1 (to-disk) or 0x2 (in-memory) must be specified.
+ The effect is whether to behave like AddConnection or AddConnectionUnsaved.
+ If 0x20 (block-autoconnect) is specified, autoconnect for the new profile
+ is blocked from the beginnin. Otherwise, the profile might automatically
+ connect if a suitable device is around.
+
+ AddConnection2 is a extensible alternative to AddConnection, and AddConnectionUnsaved.
+ The new variant can do everything that the older variants could, and more.
+
+ Since: 1.20
+ -->
+ <method name="AddConnection2">
+ <arg name="settings" type="a{sa{sv}}" direction="in"/>
+ <arg name="flags" type="u" direction="in"/>
+ <arg name="args" type="a{sv}" direction="in"/>
+ <arg name="path" type="o" direction="out"/>
+ <arg name="result" type="a{sv}" direction="out"/>
+ </method>
+
+ <!--
LoadConnections:
@filenames: Array of paths to on-disk connection profiles in directories monitored by NetworkManager.
@status: Success or failure of the operation as a whole. True if NetworkManager at least tried to load the indicated connections, even if it did not succeed. False if an error occurred before trying to load the connections (eg, permission denied).
diff --git a/libnm-core/nm-dbus-interface.h b/libnm-core/nm-dbus-interface.h
index 42c3319025..b2569af1ef 100644
--- a/libnm-core/nm-dbus-interface.h
+++ b/libnm-core/nm-dbus-interface.h
@@ -1006,6 +1006,27 @@ typedef enum { /*< flags >*/
} NMActivationStateFlags;
/**
+ * NMSettingsAddConnection2Flags:
+ * @NM_SETTINGS_ADD_CONNECTION2_FLAG_NONE: an alias for numeric zero, no flags set.
+ * @NM_SETTINGS_ADD_CONNECTION2_FLAG_TO_DISK: to persist the connection to disk.
+ * @NM_SETTINGS_ADD_CONNECTION2_FLAG_IN_MEMORY: to make the connection in-memory only.
+ * @NM_SETTINGS_ADD_CONNECTION2_FLAG_BLOCK_AUTOCONNECT: usually, when the connection
+ * has autoconnect enabled and gets added, it becomes eligible to autoconnect
+ * right away. Setting this flag, disables autoconnect until the connection
+ * is manually activated.
+ *
+ * Numeric flags for the "flags" argument of AddConnection2() D-Bus API.
+ *
+ * Since: 1.20
+ */
+typedef enum { /*< flags >*/
+ NM_SETTINGS_ADD_CONNECTION2_FLAG_NONE = 0,
+ NM_SETTINGS_ADD_CONNECTION2_FLAG_TO_DISK = 0x1,
+ NM_SETTINGS_ADD_CONNECTION2_FLAG_IN_MEMORY = 0x2,
+ NM_SETTINGS_ADD_CONNECTION2_FLAG_BLOCK_AUTOCONNECT = 0x20,
+} NMSettingsAddConnection2Flags;
+
+/**
* NMSettingsUpdate2Flags:
* @NM_SETTINGS_UPDATE2_FLAG_NONE: an alias for numeric zero, no flags set.
* @NM_SETTINGS_UPDATE2_FLAG_TO_DISK: to persist the connection to disk.
diff --git a/libnm/libnm.ver b/libnm/libnm.ver
index 7118bf2bc8..fb5c06b6e6 100644
--- a/libnm/libnm.ver
+++ b/libnm/libnm.ver
@@ -1611,6 +1611,8 @@ global:
libnm_1_20_0 {
global:
+ nm_client_add_connection2;
+ nm_client_add_connection2_finish;
nm_client_connectivity_check_get_uri;
nm_device_modem_get_apn;
nm_device_modem_get_device_id;
@@ -1622,4 +1624,5 @@ global:
nm_setting_ovs_dpdk_get_devargs;
nm_setting_ovs_dpdk_get_type;
nm_setting_ovs_dpdk_new;
+ nm_settings_add_connection2_flags_get_type;
} libnm_1_18_0;
diff --git a/libnm/nm-client.c b/libnm/nm-client.c
index a95540ed19..c39f62675b 100644
--- a/libnm/nm-client.c
+++ b/libnm/nm-client.c
@@ -1631,23 +1631,55 @@ nm_client_get_connection_by_uuid (NMClient *client, const char *uuid)
return nm_remote_settings_get_connection_by_uuid (NM_CLIENT_GET_PRIVATE (client)->settings, uuid);
}
+typedef struct {
+ NMRemoteConnection *connection;
+ GVariant *results;
+} AddConnection2CbData;
+
static void
-add_connection_cb (GObject *object,
- GAsyncResult *result,
- gpointer user_data)
+add_connection2_cb_data_destroy (gpointer user_data)
{
- GSimpleAsyncResult *simple = user_data;
- NMRemoteConnection *conn;
- GError *error = NULL;
+ AddConnection2CbData *data = user_data;
- conn = nm_remote_settings_add_connection_finish (NM_REMOTE_SETTINGS (object), result, &error);
- if (conn)
- g_simple_async_result_set_op_res_gpointer (simple, conn, g_object_unref);
- else
- g_simple_async_result_take_error (simple, error);
+ g_object_unref (data->connection);
+ nm_g_variant_unref (data->results);
+ nm_g_slice_free (data);
+}
+
+static void
+add_connection2_cb (NMRemoteSettings *self,
+ NMRemoteConnection *connection,
+ GVariant *results,
+ GError *error,
+ gpointer user_data)
+{
+ gs_unref_object GSimpleAsyncResult *simple = user_data;
+
+ if (error) {
+ g_simple_async_result_take_error (simple,
+ g_error_new_literal (error->domain,
+ error->code,
+ error->message));
+ } else if (g_simple_async_result_get_source_tag (simple) == nm_client_add_connection_async) {
+ g_simple_async_result_set_op_res_gpointer (simple,
+ g_object_ref (connection),
+ g_object_unref);
+ } else {
+ AddConnection2CbData *data;
+
+ nm_assert (g_simple_async_result_get_source_tag (simple) == nm_client_add_connection2);
+
+ data = g_slice_new (AddConnection2CbData);
+ *data = (AddConnection2CbData) {
+ .connection = g_object_ref (connection),
+ .results = nm_g_variant_ref (results),
+ };
+ g_simple_async_result_set_op_res_gpointer (simple,
+ data,
+ add_connection2_cb_data_destroy);
+ }
g_simple_async_result_complete (simple);
- g_object_unref (simple);
}
/**
@@ -1698,9 +1730,17 @@ nm_client_add_connection_async (NMClient *client,
nm_client_add_connection_async);
if (cancellable)
g_simple_async_result_set_check_cancellable (simple, cancellable);
- nm_remote_settings_add_connection_async (NM_CLIENT_GET_PRIVATE (client)->settings,
- connection, save_to_disk,
- cancellable, add_connection_cb, simple);
+
+ nm_remote_settings_add_connection2 (NM_CLIENT_GET_PRIVATE (client)->settings,
+ nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL),
+ save_to_disk
+ ? NM_SETTINGS_ADD_CONNECTION2_FLAG_TO_DISK
+ : NM_SETTINGS_ADD_CONNECTION2_FLAG_IN_MEMORY,
+ NULL,
+ TRUE,
+ cancellable,
+ add_connection2_cb,
+ simple);
}
/**
@@ -1722,13 +1762,111 @@ nm_client_add_connection_finish (NMClient *client,
GSimpleAsyncResult *simple;
g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
- g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL);
+ g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (client), nm_client_add_connection_async), NULL);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
return NULL;
- else
- return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple));
+ return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple));
+}
+
+/**
+ * nm_client_add_connection2:
+ * @client: the %NMClient
+ * @settings: the "a{sa{sv}}" #GVariant with the content of the setting.
+ * @flags: the %NMSettingsAddConnection2Flags argument.
+ * @args: (allow-none): the "a{sv}" #GVariant with extra argument or %NULL
+ * for no extra arguments.
+ * @ignore_out_result: this function wraps AddConnection2(), which has an
+ * additional result "a{sv}" output parameter. By setting this to %TRUE,
+ * you signal that you are not interested in that output parameter.
+ * This allows the function to fall back to AddConnection() and AddConnectionUnsaved(),
+ * which is interesting if you run against an older server version that does
+ * not yet provide AddConnection2(). By setting this to %FALSE, the function
+ * under the hood always calls AddConnection2().
+ * @cancellable: a #GCancellable, or %NULL
+ * @callback: (scope async): callback to be called when the add operation completes
+ * @user_data: (closure): caller-specific data passed to @callback
+ *
+ * Call AddConnection2() D-Bus API asynchronously.
+ *
+ * Since: 1.20
+ **/
+void
+nm_client_add_connection2 (NMClient *client,
+ GVariant *settings,
+ NMSettingsAddConnection2Flags flags,
+ GVariant *args,
+ gboolean ignore_out_result,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *simple;
+ GError *error = NULL;
+
+ g_return_if_fail (NM_IS_CLIENT (client));
+ g_return_if_fail (g_variant_is_of_type (settings, G_VARIANT_TYPE ("a{sa{sv}}")));
+ g_return_if_fail (!args || g_variant_is_of_type (args, G_VARIANT_TYPE ("a{sv}")));
+
+ if (!_nm_client_check_nm_running (client, &error)) {
+ g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error);
+ return;
+ }
+
+ simple = g_simple_async_result_new (G_OBJECT (client),
+ callback,
+ user_data,
+ nm_client_add_connection2);
+ if (cancellable)
+ g_simple_async_result_set_check_cancellable (simple, cancellable);
+
+ nm_remote_settings_add_connection2 (NM_CLIENT_GET_PRIVATE (client)->settings,
+ settings,
+ flags,
+ args,
+ ignore_out_result,
+ cancellable,
+ add_connection2_cb,
+ simple);
+}
+
+/**
+ * nm_client_add_connection2_finish:
+ * @client: the #NMClient
+ * @result: the #GAsyncResult
+ * @out_result: (allow-none) (transfer full) (out): the output #GVariant
+ * from AddConnection2().
+ * If you care about the output result, then the "ignore_out_result"
+ * parameter of nm_client_add_connection2() must not be set to %TRUE.
+ * @error: (allow-none): the error argument.
+ *
+ * Returns: (transfer full): on success, a pointer to the added
+ * #NMRemoteConnection.
+ *
+ * Since: 1.20
+ */
+NMRemoteConnection *
+nm_client_add_connection2_finish (NMClient *client,
+ GAsyncResult *result,
+ GVariant **out_result,
+ GError **error)
+{
+ GSimpleAsyncResult *simple;
+ AddConnection2CbData *data;
+
+ g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
+ g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (client), nm_client_add_connection2), NULL);
+
+ simple = G_SIMPLE_ASYNC_RESULT (result);
+ if (g_simple_async_result_propagate_error (simple, error)) {
+ NM_SET_OUT (out_result, NULL);
+ return NULL;
+ }
+
+ data = g_simple_async_result_get_op_res_gpointer (simple);
+ NM_SET_OUT (out_result, g_variant_ref (data->results));
+ return g_object_ref (data->connection);
}
/**
diff --git a/libnm/nm-client.h b/libnm/nm-client.h
index f3835864c8..ec7022ff6b 100644
--- a/libnm/nm-client.h
+++ b/libnm/nm-client.h
@@ -389,6 +389,22 @@ NMRemoteConnection *nm_client_add_connection_finish (NMClient *client,
GAsyncResult *result,
GError **error);
+NM_AVAILABLE_IN_1_20
+void nm_client_add_connection2 (NMClient *client,
+ GVariant *settings,
+ NMSettingsAddConnection2Flags flags,
+ GVariant *args,
+ gboolean ignore_out_result,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+NM_AVAILABLE_IN_1_20
+NMRemoteConnection *nm_client_add_connection2_finish (NMClient *client,
+ GAsyncResult *result,
+ GVariant **out_result,
+ GError **error);
+
gboolean nm_client_load_connections (NMClient *client,
char **filenames,
char ***failures,
diff --git a/libnm/nm-remote-settings.c b/libnm/nm-remote-settings.c
index 6b1d4c264e..916884ea08 100644
--- a/libnm/nm-remote-settings.c
+++ b/libnm/nm-remote-settings.c
@@ -22,6 +22,7 @@
#include "nm-remote-settings.h"
+#include "c-list/src/c-list.h"
#include "nm-dbus-interface.h"
#include "nm-connection.h"
#include "nm-client.h"
@@ -43,7 +44,7 @@ typedef struct {
GPtrArray *visible_connections;
/* AddConnectionInfo objects that are waiting for the connection to become initialized */
- GSList *add_list;
+ CList add_lst_head;
char *hostname;
gboolean can_modify;
@@ -70,51 +71,78 @@ static guint signals[LAST_SIGNAL] = { 0 };
/*****************************************************************************/
typedef struct {
+ CList add_lst;
NMRemoteSettings *self;
- GSimpleAsyncResult *simple;
+ NMRemoteSettingAddConnection2Callback callback;
+ gpointer user_data;
+ GCancellable *cancellable;
char *path;
- gboolean saved;
+ GVariant *results;
+ gulong cancellable_id;
+ NMSettingsAddConnection2Flags flags;
+ bool ignore_out_result:1;
} AddConnectionInfo;
static AddConnectionInfo *
-add_connection_info_find (NMRemoteSettings *self, const char *path)
+_add_connection_info_find (NMRemoteSettings *self, const char *path)
{
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
- GSList *iter;
-
- for (iter = priv->add_list; iter; iter = g_slist_next (iter)) {
- AddConnectionInfo *info = iter->data;
+ AddConnectionInfo *info;
- if (!g_strcmp0 (info->path, path))
+ c_list_for_each_entry (info, &priv->add_lst_head, add_lst) {
+ if (nm_streq0 (info->path, path))
return info;
}
-
return NULL;
}
static void
-add_connection_info_complete (NMRemoteSettings *self,
- AddConnectionInfo *info,
- NMRemoteConnection *connection,
- GError *error)
+_add_connection_info_complete (AddConnectionInfo *info,
+ NMRemoteConnection *connection,
+ GError *error_take)
{
- NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
+ nm_assert (info);
+
+ c_list_unlink_stale (&info->add_lst);
+
+ nm_clear_g_signal_handler (info->cancellable, &info->cancellable_id);
+
+ if ( info->cancellable
+ && !nm_utils_error_is_cancelled (error_take, FALSE)) {
+ GError *error2 = NULL;
+
+ if (g_cancellable_set_error_if_cancelled (info->cancellable, &error2)) {
+ g_clear_error (&error_take);
+ error_take = error2;
+ connection = NULL;
+ }
+ }
+
+ info->callback (info->self,
+ connection,
+ connection ? info->results : NULL,
+ error_take,
+ info->user_data);
- g_return_if_fail (info != NULL);
+ g_clear_error (&error_take);
- if (connection) {
- g_simple_async_result_set_op_res_gpointer (info->simple,
- g_object_ref (connection),
- g_object_unref);
- } else
- g_simple_async_result_set_from_error (info->simple, error);
- g_simple_async_result_complete (info->simple);
+ g_object_unref (info->self);
+ nm_g_object_unref (info->cancellable);
+ nm_clear_g_free (&info->path);
+ nm_g_variant_unref (info->results);
- g_object_unref (info->simple);
- priv->add_list = g_slist_remove (priv->add_list, info);
+ nm_g_slice_free (info);
+}
- g_free (info->path);
- g_slice_free (AddConnectionInfo, info);
+static void
+_add_connection_info_cancelled (GCancellable *cancellable,
+ AddConnectionInfo *info)
+{
+ _add_connection_info_complete (info,
+ NULL,
+ g_error_new_literal (G_IO_ERROR,
+ G_IO_ERROR_CANCELLED,
+ "Operation was cancelled"));
}
typedef const char * (*ConnectionStringGetter) (NMConnection *);
@@ -216,7 +244,7 @@ connection_added (NMRemoteSettings *self,
NMRemoteConnection *remote)
{
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
- AddConnectionInfo *addinfo;
+ AddConnectionInfo *info;
const char *path;
if (!g_signal_handler_find (remote, G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, 0, 0, NULL,
@@ -233,26 +261,27 @@ connection_added (NMRemoteSettings *self,
g_signal_stop_emission (self, signals[CONNECTION_ADDED], 0);
path = nm_connection_get_path (NM_CONNECTION (remote));
- addinfo = add_connection_info_find (self, path);
- if (addinfo)
- add_connection_info_complete (self, addinfo, remote, NULL);
+ info = _add_connection_info_find (self, path);
+ if (info)
+ _add_connection_info_complete (info, remote, NULL);
}
static void
-object_creation_failed (NMObject *object, const char *failed_path)
+object_creation_failed (NMObject *object,
+ const char *failed_path)
{
NMRemoteSettings *self = NM_REMOTE_SETTINGS (object);
- AddConnectionInfo *addinfo;
- GError *add_error;
-
- addinfo = add_connection_info_find (self, failed_path);
- if (addinfo) {
- add_error = g_error_new_literal (NM_CLIENT_ERROR,
- NM_CLIENT_ERROR_OBJECT_CREATION_FAILED,
- _("Connection removed before it was initialized"));
- add_connection_info_complete (self, addinfo, NULL, add_error);
- g_error_free (add_error);
- }
+ AddConnectionInfo *info;
+
+ info = _add_connection_info_find (self, failed_path);
+ if (!info)
+ return;
+
+ _add_connection_info_complete (info,
+ NULL,
+ g_error_new_literal (NM_CLIENT_ERROR,
+ NM_CLIENT_ERROR_OBJECT_CREATION_FAILED,
+ _("Connection removed before it was initialized")));
}
const GPtrArray *
@@ -269,83 +298,114 @@ add_connection_done (GObject *proxy, GAsyncResult *result, gpointer user_data)
AddConnectionInfo *info = user_data;
GError *error = NULL;
- if (info->saved) {
+ if ( info->ignore_out_result
+ && info->flags == NM_SETTINGS_ADD_CONNECTION2_FLAG_TO_DISK) {
nmdbus_settings_call_add_connection_finish (NMDBUS_SETTINGS (proxy),
&info->path,
- result, &error);
- } else {
+ result,
+ &error);
+ } else if ( info->ignore_out_result
+ && info->flags == NM_SETTINGS_ADD_CONNECTION2_FLAG_IN_MEMORY) {
nmdbus_settings_call_add_connection_unsaved_finish (NMDBUS_SETTINGS (proxy),
&info->path,
- result, &error);
+ result,
+ &error);
+ } else {
+ nmdbus_settings_call_add_connection2_finish (NMDBUS_SETTINGS (proxy),
+ &info->path,
+ &info->results,
+ result,
+ &error);
+ if (info->ignore_out_result) {
+ /* despite we have the result, the caller didn't ask for it.
+ * Through it away, so we consistently don't return a result. */
+ nm_clear_pointer (&info->results, g_variant_unref);
+ }
}
if (error) {
g_dbus_error_strip_remote_error (error);
- add_connection_info_complete (info->self, info, NULL, error);
- g_clear_error (&error);
+ _add_connection_info_complete (info, NULL, error);
+ return;
}
/* On success, we still have to wait until the connection is fully
* initialized before calling the callback.
*/
+ if (info->cancellable) {
+ gulong id;
+
+ id = g_cancellable_connect (info->cancellable,
+ G_CALLBACK (_add_connection_info_cancelled),
+ info,
+ NULL);
+ if (id == 0) {
+ /* the callback was invoked synchronously, which destroyed @info.
+ * We must not touch @info anymore. */
+ } else
+ info->cancellable_id = id;
+ }
}
void
-nm_remote_settings_add_connection_async (NMRemoteSettings *settings,
- NMConnection *connection,
- gboolean save_to_disk,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+nm_remote_settings_add_connection2 (NMRemoteSettings *self,
+ GVariant *settings,
+ NMSettingsAddConnection2Flags flags,
+ GVariant *args,
+ gboolean ignore_out_result,
+ GCancellable *cancellable,
+ NMRemoteSettingAddConnection2Callback callback,
+ gpointer user_data)
{
NMRemoteSettingsPrivate *priv;
AddConnectionInfo *info;
- GVariant *new_settings;
- g_return_if_fail (NM_IS_REMOTE_SETTINGS (settings));
- g_return_if_fail (NM_IS_CONNECTION (connection));
-
- priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings);
-
- info = g_slice_new0 (AddConnectionInfo);
- info->self = settings;
- info->simple = g_simple_async_result_new (G_OBJECT (settings), callback, user_data,
- nm_remote_settings_add_connection_async);
- if (cancellable)
- g_simple_async_result_set_check_cancellable (info->simple, cancellable);
- info->saved = save_to_disk;
-
- new_settings = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL);
-
- if (save_to_disk) {
+ nm_assert (NM_IS_REMOTE_SETTINGS (self));
+ nm_assert (g_variant_is_of_type (settings, G_VARIANT_TYPE ("a{sa{sv}}")));
+ nm_assert (!args || g_variant_is_of_type (args, G_VARIANT_TYPE ("a{sv}")));
+ nm_assert (callback);
+
+ priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
+
+ info = g_slice_new (AddConnectionInfo);
+ *info = (AddConnectionInfo) {
+ .self = g_object_ref (self),
+ .cancellable = nm_g_object_ref (cancellable),
+ .flags = flags,
+ .ignore_out_result = ignore_out_result,
+ .callback = callback,
+ .user_data = user_data,
+ };
+ c_list_link_tail (&priv->add_lst_head, &info->add_lst);
+
+ /* Although AddConnection2() being capable to handle also AddConnection() and
+ * AddConnectionUnsaved() variants, we prefer to use the old D-Bus methods when
+ * they are sufficient. The reason is that libnm should avoid hard dependencies
+ * on 1.20 API whenever possible. */
+ if ( ignore_out_result
+ && flags == NM_SETTINGS_ADD_CONNECTION2_FLAG_TO_DISK) {
nmdbus_settings_call_add_connection (priv->proxy,
- new_settings,
- NULL,
- add_connection_done, info);
- } else {
+ settings,
+ cancellable,
+ add_connection_done,
+ info);
+ } else if ( ignore_out_result
+ && flags == NM_SETTINGS_ADD_CONNECTION2_FLAG_IN_MEMORY) {
nmdbus_settings_call_add_connection_unsaved (priv->proxy,
- new_settings,
- NULL,
- add_connection_done, info);
+ settings,
+ cancellable,
+ add_connection_done,
+ info);
+ } else {
+ nmdbus_settings_call_add_connection2 (priv->proxy,
+ settings,
+ flags,
+ args
+ ?: g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0),
+ cancellable,
+ add_connection_done,
+ info);
}
-
- priv->add_list = g_slist_append (priv->add_list, info);
-}
-
-NMRemoteConnection *
-nm_remote_settings_add_connection_finish (NMRemoteSettings *settings,
- GAsyncResult *result,
- GError **error)
-{
- GSimpleAsyncResult *simple;
-
- g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (settings), nm_remote_settings_add_connection_async), NULL);
-
- simple = G_SIMPLE_ASYNC_RESULT (result);
- if (g_simple_async_result_propagate_error (simple, error))
- return NULL;
- else
- return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple));
}
gboolean
@@ -606,6 +666,7 @@ nm_remote_settings_init (NMRemoteSettings *self)
{
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
+ c_list_init (&priv->add_lst_head);
priv->all_connections = g_ptr_array_new ();
priv->visible_connections = g_ptr_array_new ();
}
@@ -664,7 +725,7 @@ dispose (GObject *object)
{
NMRemoteSettings *self = NM_REMOTE_SETTINGS (object);
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
- int i;
+ guint i;
if (priv->all_connections) {
for (i = 0; i < priv->all_connections->len; i++)
diff --git a/libnm/nm-remote-settings.h b/libnm/nm-remote-settings.h
index ac0008a942..bd89cf8c68 100644
--- a/libnm/nm-remote-settings.h
+++ b/libnm/nm-remote-settings.h
@@ -73,15 +73,20 @@ NMRemoteConnection *nm_remote_settings_get_connection_by_path (NMRemoteSettings
NMRemoteConnection *nm_remote_settings_get_connection_by_uuid (NMRemoteSettings *settings,
const char *uuid);
-void nm_remote_settings_add_connection_async (NMRemoteSettings *settings,
- NMConnection *connection,
- gboolean save_to_disk,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-NMRemoteConnection *nm_remote_settings_add_connection_finish (NMRemoteSettings *settings,
- GAsyncResult *result,
- GError **error);
+typedef void (*NMRemoteSettingAddConnection2Callback) (NMRemoteSettings *self,
+ NMRemoteConnection *connection,
+ GVariant *results,
+ GError *error,
+ gpointer user_data);
+
+void nm_remote_settings_add_connection2 (NMRemoteSettings *self,
+ GVariant *settings,
+ NMSettingsAddConnection2Flags flags,
+ GVariant *args,
+ gboolean ignore_out_result,
+ GCancellable *cancellable,
+ NMRemoteSettingAddConnection2Callback callback,
+ gpointer user_data);
gboolean nm_remote_settings_load_connections (NMRemoteSettings *settings,
char **filenames,
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 d2cc52e7af..1f7723c539 100644
--- a/src/nm-checkpoint.c
+++ b/src/nm-checkpoint.c
@@ -258,6 +258,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 93bfb14720..4f114e4d13 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -2674,6 +2674,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,
@@ -5419,6 +5420,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 c789ec0826..2093342c9c 100644
--- a/src/settings/nm-settings-connection.c
+++ b/src/settings/nm-settings-connection.c
@@ -1438,7 +1438,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);
@@ -1514,12 +1514,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,
@@ -1533,7 +1527,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);
@@ -1760,13 +1757,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 f3d6e35e51..ab23dc1ff5 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 e24814b1d8..6961134c6c 100644
--- a/src/settings/nm-settings.c
+++ b/src/settings/nm-settings.c
@@ -923,7 +923,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;
@@ -1371,6 +1376,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
@@ -1385,6 +1391,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)
@@ -1408,6 +1415,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);
@@ -1486,7 +1495,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));
@@ -1972,6 +1984,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);
@@ -1999,6 +2012,7 @@ void
nm_settings_add_connection_dbus (NMSettings *self,
NMConnection *connection,
NMSettingsConnectionPersistMode persist_mode,
+ NMSettingsConnectionAddReason add_reason,
NMSettingsConnectionIntFlags sett_flags,
NMAuthSubject *subject,
GDBusMethodInvocation *context,
@@ -2073,6 +2087,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;
@@ -2091,27 +2106,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
@@ -2133,14 +2163,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
@@ -2156,7 +2196,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
@@ -2172,7 +2212,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);
}
/*****************************************************************************/
@@ -2941,6 +3044,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);
@@ -3440,6 +3544,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);