mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-06-11 04:58:29 +02:00
settings: add "plugin" argument to AddAndActivate2()
This will confine a newly added connection to a particular settings plugin.
This commit is contained in:
parent
18b4ea7468
commit
f4f165f945
7 changed files with 61 additions and 5 deletions
|
|
@ -67,7 +67,7 @@
|
||||||
AddConnection2:
|
AddConnection2:
|
||||||
@settings: New connection settings, properties, and (optionally) secrets.
|
@settings: New connection settings, properties, and (optionally) secrets.
|
||||||
@flags: Flags. Unknown flags cause the call to fail.
|
@flags: Flags. Unknown flags cause the call to fail.
|
||||||
@args: Optional arguments dictionary, for extentibility. Currently, no arguments are accepted. Specifying unknown keys causes the call to fail.
|
@args: Optional arguments dictionary, for extentibility. Specifying unknown keys causes the call to fail.
|
||||||
@path: Object path of the new connection that was just added.
|
@path: Object path of the new connection that was just added.
|
||||||
@result: Output argument, currently no additional results are returned.
|
@result: Output argument, currently no additional results are returned.
|
||||||
@since: 1.20
|
@since: 1.20
|
||||||
|
|
@ -100,6 +100,17 @@
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
</variablelist>
|
</variablelist>
|
||||||
|
|
||||||
|
The %args argument accepts the following keys:
|
||||||
|
|
||||||
|
<variablelist>
|
||||||
|
<varlistentry>
|
||||||
|
<term><literal>plugin</literal>:</term>
|
||||||
|
<listitem><para>The settings plugin the newly added connection will
|
||||||
|
use, such as "keyfile" or "ifcfg-rh".</para>
|
||||||
|
<para role="since">Since 1.38</para></listitem>
|
||||||
|
</varlistentry>
|
||||||
|
</variablelist>
|
||||||
|
|
||||||
Either the flags 0x1 (to-disk) or 0x2 (in-memory) must be specified.
|
Either the flags 0x1 (to-disk) or 0x2 (in-memory) must be specified.
|
||||||
The effect is whether to behave like
|
The effect is whether to behave like
|
||||||
<link linkend="gdbus-method-org-freedesktop-NetworkManager-Settings.AddConnection">AddConnection</link> or
|
<link linkend="gdbus-method-org-freedesktop-NetworkManager-Settings.AddConnection">AddConnection</link> or
|
||||||
|
|
|
||||||
|
|
@ -1352,6 +1352,7 @@ _conn_create_panu_connection(NMBluezManager *self, BzDBusObj *bzobj)
|
||||||
bzobj->d_device.address);
|
bzobj->d_device.address);
|
||||||
|
|
||||||
nm_settings_add_connection(priv->settings,
|
nm_settings_add_connection(priv->settings,
|
||||||
|
NULL,
|
||||||
connection,
|
connection,
|
||||||
NM_SETTINGS_CONNECTION_PERSIST_MODE_IN_MEMORY_ONLY,
|
NM_SETTINGS_CONNECTION_PERSIST_MODE_IN_MEMORY_ONLY,
|
||||||
NM_SETTINGS_CONNECTION_ADD_REASON_NONE,
|
NM_SETTINGS_CONNECTION_ADD_REASON_NONE,
|
||||||
|
|
|
||||||
|
|
@ -948,6 +948,7 @@ mirror_connection(NMIwdManager *self,
|
||||||
|
|
||||||
if (!nm_settings_add_connection(
|
if (!nm_settings_add_connection(
|
||||||
priv->settings,
|
priv->settings,
|
||||||
|
NULL,
|
||||||
connection,
|
connection,
|
||||||
NM_SETTINGS_CONNECTION_PERSIST_MODE_IN_MEMORY_ONLY,
|
NM_SETTINGS_CONNECTION_PERSIST_MODE_IN_MEMORY_ONLY,
|
||||||
NM_SETTINGS_CONNECTION_ADD_REASON_NONE,
|
NM_SETTINGS_CONNECTION_ADD_REASON_NONE,
|
||||||
|
|
|
||||||
|
|
@ -247,6 +247,7 @@ restore_and_activate_connection(NMCheckpoint *self, DeviceCheckpoint *dev_checkp
|
||||||
|
|
||||||
persist_mode = NM_SETTINGS_CONNECTION_PERSIST_MODE_TO_DISK;
|
persist_mode = NM_SETTINGS_CONNECTION_PERSIST_MODE_TO_DISK;
|
||||||
if (!nm_settings_add_connection(NM_SETTINGS_GET,
|
if (!nm_settings_add_connection(NM_SETTINGS_GET,
|
||||||
|
NULL,
|
||||||
dev_checkpoint->settings_connection,
|
dev_checkpoint->settings_connection,
|
||||||
persist_mode,
|
persist_mode,
|
||||||
NM_SETTINGS_CONNECTION_ADD_REASON_NONE,
|
NM_SETTINGS_CONNECTION_ADD_REASON_NONE,
|
||||||
|
|
|
||||||
|
|
@ -2939,6 +2939,7 @@ get_existing_connection(NMManager *self, NMDevice *device, gboolean *out_generat
|
||||||
nm_device_assume_state_reset(device);
|
nm_device_assume_state_reset(device);
|
||||||
|
|
||||||
if (!nm_settings_add_connection(priv->settings,
|
if (!nm_settings_add_connection(priv->settings,
|
||||||
|
NULL,
|
||||||
connection,
|
connection,
|
||||||
NM_SETTINGS_CONNECTION_PERSIST_MODE_IN_MEMORY_ONLY,
|
NM_SETTINGS_CONNECTION_PERSIST_MODE_IN_MEMORY_ONLY,
|
||||||
NM_SETTINGS_CONNECTION_ADD_REASON_NONE,
|
NM_SETTINGS_CONNECTION_ADD_REASON_NONE,
|
||||||
|
|
@ -5915,6 +5916,7 @@ _add_and_activate_auth_done(NMManager *self,
|
||||||
* shutdown. */
|
* shutdown. */
|
||||||
nm_settings_add_connection_dbus(
|
nm_settings_add_connection_dbus(
|
||||||
priv->settings,
|
priv->settings,
|
||||||
|
NULL,
|
||||||
connection,
|
connection,
|
||||||
persist_mode,
|
persist_mode,
|
||||||
NM_SETTINGS_CONNECTION_ADD_REASON_NONE,
|
NM_SETTINGS_CONNECTION_ADD_REASON_NONE,
|
||||||
|
|
|
||||||
|
|
@ -1463,6 +1463,7 @@ _plugin_connections_reload(NMSettings *self)
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
_add_connection_to_first_plugin(NMSettings *self,
|
_add_connection_to_first_plugin(NMSettings *self,
|
||||||
|
const char *plugin_name,
|
||||||
SettConnEntry *sett_conn_entry,
|
SettConnEntry *sett_conn_entry,
|
||||||
NMConnection *new_connection,
|
NMConnection *new_connection,
|
||||||
gboolean in_memory,
|
gboolean in_memory,
|
||||||
|
|
@ -1477,6 +1478,7 @@ _add_connection_to_first_plugin(NMSettings *self,
|
||||||
gs_free_error GError *first_error = NULL;
|
gs_free_error GError *first_error = NULL;
|
||||||
GSList *iter;
|
GSList *iter;
|
||||||
const char *uuid;
|
const char *uuid;
|
||||||
|
gboolean no_plugin = TRUE;
|
||||||
|
|
||||||
uuid = nm_connection_get_uuid(new_connection);
|
uuid = nm_connection_get_uuid(new_connection);
|
||||||
|
|
||||||
|
|
@ -1493,6 +1495,11 @@ _add_connection_to_first_plugin(NMSettings *self,
|
||||||
gboolean success;
|
gboolean success;
|
||||||
const char *filename;
|
const char *filename;
|
||||||
|
|
||||||
|
if (plugin_name && strcmp(plugin_name, nm_settings_plugin_get_plugin_name(plugin))) {
|
||||||
|
/* Not the plugin we're confined to. Ignore. */
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!in_memory) {
|
if (!in_memory) {
|
||||||
NMSettingsStorage *conflicting_storage;
|
NMSettingsStorage *conflicting_storage;
|
||||||
|
|
||||||
|
|
@ -1545,6 +1552,8 @@ _add_connection_to_first_plugin(NMSettings *self,
|
||||||
&add_error);
|
&add_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
no_plugin = FALSE;
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
_LOGT("add-connection: failed to add %s/'%s': %s",
|
_LOGT("add-connection: failed to add %s/'%s': %s",
|
||||||
nm_connection_get_uuid(new_connection),
|
nm_connection_get_uuid(new_connection),
|
||||||
|
|
@ -1588,8 +1597,18 @@ _add_connection_to_first_plugin(NMSettings *self,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
nm_assert(first_error);
|
if (no_plugin) {
|
||||||
g_propagate_error(error, g_steal_pointer(&first_error));
|
nm_assert(plugin_name);
|
||||||
|
nm_assert(!first_error);
|
||||||
|
g_set_error(error,
|
||||||
|
NM_SETTINGS_ERROR,
|
||||||
|
NM_SETTINGS_ERROR_INVALID_ARGUMENTS,
|
||||||
|
"a plugin by the name of '%s' is not available",
|
||||||
|
plugin_name);
|
||||||
|
} else {
|
||||||
|
nm_assert(first_error);
|
||||||
|
g_propagate_error(error, g_steal_pointer(&first_error));
|
||||||
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1704,6 +1723,7 @@ _set_nmmeta_tombstone(NMSettings *self,
|
||||||
*/
|
*/
|
||||||
gboolean
|
gboolean
|
||||||
nm_settings_add_connection(NMSettings *self,
|
nm_settings_add_connection(NMSettings *self,
|
||||||
|
const char *plugin,
|
||||||
NMConnection *connection,
|
NMConnection *connection,
|
||||||
NMSettingsConnectionPersistMode persist_mode,
|
NMSettingsConnectionPersistMode persist_mode,
|
||||||
NMSettingsConnectionAddReason add_reason,
|
NMSettingsConnectionAddReason add_reason,
|
||||||
|
|
@ -1824,6 +1844,7 @@ again_add_connection:
|
||||||
|
|
||||||
if (!update_storage) {
|
if (!update_storage) {
|
||||||
success = _add_connection_to_first_plugin(self,
|
success = _add_connection_to_first_plugin(self,
|
||||||
|
plugin,
|
||||||
sett_conn_entry,
|
sett_conn_entry,
|
||||||
connection,
|
connection,
|
||||||
new_in_memory,
|
new_in_memory,
|
||||||
|
|
@ -2176,6 +2197,7 @@ nm_settings_update_connection(NMSettings *self,
|
||||||
|
|
||||||
if (!update_storage) {
|
if (!update_storage) {
|
||||||
success = _add_connection_to_first_plugin(self,
|
success = _add_connection_to_first_plugin(self,
|
||||||
|
NULL,
|
||||||
sett_conn_entry,
|
sett_conn_entry,
|
||||||
connection,
|
connection,
|
||||||
new_in_memory,
|
new_in_memory,
|
||||||
|
|
@ -2462,6 +2484,7 @@ pk_add_cb(NMAuthChain *chain, GDBusMethodInvocation *context, gpointer user_data
|
||||||
nm_assert(NM_IS_CONNECTION(connection));
|
nm_assert(NM_IS_CONNECTION(connection));
|
||||||
|
|
||||||
nm_settings_add_connection(self,
|
nm_settings_add_connection(self,
|
||||||
|
nm_auth_chain_get_data(chain, "plugin"),
|
||||||
connection,
|
connection,
|
||||||
GPOINTER_TO_UINT(nm_auth_chain_get_data(chain, "persist-mode")),
|
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, "add-reason")),
|
||||||
|
|
@ -2489,6 +2512,7 @@ pk_add_cb(NMAuthChain *chain, GDBusMethodInvocation *context, gpointer user_data
|
||||||
|
|
||||||
void
|
void
|
||||||
nm_settings_add_connection_dbus(NMSettings *self,
|
nm_settings_add_connection_dbus(NMSettings *self,
|
||||||
|
const char *plugin,
|
||||||
NMConnection *connection,
|
NMConnection *connection,
|
||||||
NMSettingsConnectionPersistMode persist_mode,
|
NMSettingsConnectionPersistMode persist_mode,
|
||||||
NMSettingsConnectionAddReason add_reason,
|
NMSettingsConnectionAddReason add_reason,
|
||||||
|
|
@ -2549,6 +2573,7 @@ nm_settings_add_connection_dbus(NMSettings *self,
|
||||||
nm_auth_chain_set_data(chain, "persist-mode", GUINT_TO_POINTER(persist_mode), NULL);
|
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, "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_set_data(chain, "sett-flags", GUINT_TO_POINTER(sett_flags), NULL);
|
||||||
|
nm_auth_chain_set_data(chain, "plugin", g_strdup(plugin), g_free);
|
||||||
nm_auth_chain_add_call_unsafe(chain, perm, TRUE);
|
nm_auth_chain_add_call_unsafe(chain, perm, TRUE);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -2601,6 +2626,7 @@ settings_add_connection_helper(NMSettings *self,
|
||||||
GDBusMethodInvocation *context,
|
GDBusMethodInvocation *context,
|
||||||
gboolean is_add_connection_2,
|
gboolean is_add_connection_2,
|
||||||
GVariant *settings,
|
GVariant *settings,
|
||||||
|
const char *plugin,
|
||||||
NMSettingsAddConnection2Flags flags)
|
NMSettingsAddConnection2Flags flags)
|
||||||
{
|
{
|
||||||
gs_unref_object NMConnection *connection = NULL;
|
gs_unref_object NMConnection *connection = NULL;
|
||||||
|
|
@ -2636,6 +2662,7 @@ settings_add_connection_helper(NMSettings *self,
|
||||||
|
|
||||||
nm_settings_add_connection_dbus(
|
nm_settings_add_connection_dbus(
|
||||||
self,
|
self,
|
||||||
|
plugin,
|
||||||
connection,
|
connection,
|
||||||
persist_mode,
|
persist_mode,
|
||||||
NM_FLAGS_HAS(flags, NM_SETTINGS_ADD_CONNECTION2_FLAG_BLOCK_AUTOCONNECT)
|
NM_FLAGS_HAS(flags, NM_SETTINGS_ADD_CONNECTION2_FLAG_BLOCK_AUTOCONNECT)
|
||||||
|
|
@ -2665,6 +2692,7 @@ impl_settings_add_connection(NMDBusObject *obj,
|
||||||
invocation,
|
invocation,
|
||||||
FALSE,
|
FALSE,
|
||||||
settings,
|
settings,
|
||||||
|
NULL,
|
||||||
NM_SETTINGS_ADD_CONNECTION2_FLAG_TO_DISK);
|
NM_SETTINGS_ADD_CONNECTION2_FLAG_TO_DISK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2685,6 +2713,7 @@ impl_settings_add_connection_unsaved(NMDBusObject *obj,
|
||||||
invocation,
|
invocation,
|
||||||
FALSE,
|
FALSE,
|
||||||
settings,
|
settings,
|
||||||
|
NULL,
|
||||||
NM_SETTINGS_ADD_CONNECTION2_FLAG_IN_MEMORY);
|
NM_SETTINGS_ADD_CONNECTION2_FLAG_IN_MEMORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2700,8 +2729,10 @@ impl_settings_add_connection2(NMDBusObject *obj,
|
||||||
NMSettings *self = NM_SETTINGS(obj);
|
NMSettings *self = NM_SETTINGS(obj);
|
||||||
gs_unref_variant GVariant *settings = NULL;
|
gs_unref_variant GVariant *settings = NULL;
|
||||||
gs_unref_variant GVariant *args = NULL;
|
gs_unref_variant GVariant *args = NULL;
|
||||||
|
gs_free char *plugin = NULL;
|
||||||
NMSettingsAddConnection2Flags flags;
|
NMSettingsAddConnection2Flags flags;
|
||||||
const char *args_name;
|
const char *args_name;
|
||||||
|
GVariant *args_value;
|
||||||
GVariantIter iter;
|
GVariantIter iter;
|
||||||
guint32 flags_u;
|
guint32 flags_u;
|
||||||
|
|
||||||
|
|
@ -2745,7 +2776,13 @@ impl_settings_add_connection2(NMDBusObject *obj,
|
||||||
nm_assert(g_variant_is_of_type(args, G_VARIANT_TYPE("a{sv}")));
|
nm_assert(g_variant_is_of_type(args, G_VARIANT_TYPE("a{sv}")));
|
||||||
|
|
||||||
g_variant_iter_init(&iter, args);
|
g_variant_iter_init(&iter, args);
|
||||||
while (g_variant_iter_next(&iter, "{&sv}", &args_name, NULL)) {
|
while (g_variant_iter_next(&iter, "{&sv}", &args_name, &args_value)) {
|
||||||
|
if (plugin == NULL && nm_streq(args_name, "plugin")
|
||||||
|
&& g_variant_is_of_type(args_value, G_VARIANT_TYPE_STRING)) {
|
||||||
|
plugin = g_variant_dup_string(args_value, NULL);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
g_dbus_method_invocation_take_error(invocation,
|
g_dbus_method_invocation_take_error(invocation,
|
||||||
g_error_new(NM_SETTINGS_ERROR,
|
g_error_new(NM_SETTINGS_ERROR,
|
||||||
NM_SETTINGS_ERROR_INVALID_ARGUMENTS,
|
NM_SETTINGS_ERROR_INVALID_ARGUMENTS,
|
||||||
|
|
@ -2754,7 +2791,7 @@ impl_settings_add_connection2(NMDBusObject *obj,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
settings_add_connection_helper(self, invocation, TRUE, settings, flags);
|
settings_add_connection_helper(self, invocation, TRUE, settings, plugin, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
@ -3606,6 +3643,7 @@ device_realized(NMDevice *device, GParamSpec *pspec, NMSettings *self)
|
||||||
nm_device_get_iface(device));
|
nm_device_get_iface(device));
|
||||||
|
|
||||||
nm_settings_add_connection(self,
|
nm_settings_add_connection(self,
|
||||||
|
NULL,
|
||||||
connection,
|
connection,
|
||||||
NM_SETTINGS_CONNECTION_PERSIST_MODE_IN_MEMORY_ONLY,
|
NM_SETTINGS_CONNECTION_PERSIST_MODE_IN_MEMORY_ONLY,
|
||||||
NM_SETTINGS_CONNECTION_ADD_REASON_NONE,
|
NM_SETTINGS_CONNECTION_ADD_REASON_NONE,
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,7 @@ typedef void (*NMSettingsAddCallback)(NMSettings *settings,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
|
|
||||||
void nm_settings_add_connection_dbus(NMSettings *self,
|
void nm_settings_add_connection_dbus(NMSettings *self,
|
||||||
|
const char *plugin,
|
||||||
NMConnection *connection,
|
NMConnection *connection,
|
||||||
NMSettingsConnectionPersistMode persist_mode,
|
NMSettingsConnectionPersistMode persist_mode,
|
||||||
NMSettingsConnectionAddReason add_reason,
|
NMSettingsConnectionAddReason add_reason,
|
||||||
|
|
@ -90,6 +91,7 @@ NMSettingsConnection **nm_settings_get_connections_clone(NMSettings
|
||||||
gpointer sort_data);
|
gpointer sort_data);
|
||||||
|
|
||||||
gboolean nm_settings_add_connection(NMSettings *settings,
|
gboolean nm_settings_add_connection(NMSettings *settings,
|
||||||
|
const char *plugin,
|
||||||
NMConnection *connection,
|
NMConnection *connection,
|
||||||
NMSettingsConnectionPersistMode persist_mode,
|
NMSettingsConnectionPersistMode persist_mode,
|
||||||
NMSettingsConnectionAddReason add_reason,
|
NMSettingsConnectionAddReason add_reason,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue