summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-08-29 10:13:28 +0200
committerThomas Haller <thaller@redhat.com>2022-08-31 19:20:12 +0200
commit130479c8b2689acc4284743675418bab6634d66c (patch)
tree631a6a86ecb518131289daa403bb80ab4afbc233
parentfcf32d81bd883c6756cc66d24c46ef8a39d43b63 (diff)
downloadNetworkManager-130479c8b2689acc4284743675418bab6634d66c.tar.gz
nmcli: allow setting the "connection.uuid" for new profiles
Because, why not? The client side determines the UUID, so there is no security implication by letting the nmcli user explicitly choose it. $ nmcli connection add type ethernet con-name x connection.uuid 6965f79c-4424-4918-98e8-3c0982434011 Connection 'x' (6965f79c-4424-4918-98e8-3c0982434011) successfully added. $ nmcli connection add type ethernet con-name x connection.uuid 6965f79c-4424-4918-98e8-3c0982434011 Error: Failed to add 'x' connection: a connection with this UUID already exists $ nmcli connection modify x connection.uuid 6965f79c-4424-4918-98e8-3c0982434011 $ nmcli connection modify x connection.uuid 6965f79c-4424-4918-98e8-3c0982434012 Error: failed to modify connection.uuid: the property can't be changed.
-rw-r--r--src/libnmc-setting/nm-meta-setting-desc.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/libnmc-setting/nm-meta-setting-desc.c b/src/libnmc-setting/nm-meta-setting-desc.c
index 234ce40e61..2e471d66a5 100644
--- a/src/libnmc-setting/nm-meta-setting-desc.c
+++ b/src/libnmc-setting/nm-meta-setting-desc.c
@@ -2636,8 +2636,18 @@ _get_fcn_connection_permissions(ARGS_GET_FCN)
static gboolean
_set_fcn_connection_uuid(ARGS_SET_FCN)
{
- if (!NM_FLAGS_HAS(nm_meta_environment_get_env_flags(environment, environment_user_data),
- NM_META_ENV_FLAGS_OFFLINE)) {
+ const char *uuid;
+
+ uuid = nm_setting_connection_get_uuid(NM_SETTING_CONNECTION(setting));
+
+ if (!uuid) {
+ /* No UUID yet, we are about to create a new profile. We can set the UUID. */
+ } else if (NM_FLAGS_HAS(nm_meta_environment_get_env_flags(environment, environment_user_data),
+ NM_META_ENV_FLAGS_OFFLINE)) {
+ /* In offline mode, we can change it. */
+ } else if (nm_uuid_is_valid_nmlegacy(value) && nm_streq(uuid, value)) {
+ /* Setting the same value does not actually trigger an error. */
+ } else {
/* The UUID is the unchanging ID of a profile. It cannot change, unless
* we are in offline mode (in which case, it can be useful to do just that). */
nm_utils_error_set(error, NM_UTILS_ERROR_INVALID_ARGUMENT, "the property can't be changed");
@@ -2685,14 +2695,6 @@ _set_fcn_connection_type(ARGS_SET_FCN)
return TRUE;
}
- if (!nm_setting_connection_get_uuid(NM_SETTING_CONNECTION(setting))) {
- /* If we so far have not UUID set, set it together with the connection type. */
- g_object_set(G_OBJECT(setting),
- NM_SETTING_CONNECTION_UUID,
- nm_uuid_generate_random_str_a(),
- NULL);
- }
-
g_object_set(G_OBJECT(setting), property_info->property_name, value, NULL);
return TRUE;
}