From 883f2c74aa2eb6552fcf1efc42b77e2b340539b1 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Mon, 21 Feb 2022 11:00:13 +0100 Subject: [PATCH] cli: don't reset default values in interactive add Since commit 40032f461415 ('cli: fix resetting values via property alias'), nmcli sets NULL properties during interactive add (nmcli -a connection add) when the user leaves the field blank. This can lead to an invalid connection for properties that can't be empty like infiniband.transport-mode; they should be left to the default value in case of no value entered. Fixes: 40032f461415 ('cli: fix resetting values via property alias') Fixes-test: @inf_create_port_novice_mode https://bugzilla.redhat.com/show_bug.cgi?id=2053603 https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1111 (cherry picked from commit 5b4ce608d4db331cad0a891976a0bbce975e61f0) --- src/nmcli/connections.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/nmcli/connections.c b/src/nmcli/connections.c index 5a66b82f68..559dc7dbc0 100644 --- a/src/nmcli/connections.c +++ b/src/nmcli/connections.c @@ -4189,6 +4189,7 @@ set_option(NmCli *nmc, NMConnection *connection, const NMMetaAbstractInfo *abstract_info, const char *value, + gboolean allow_reset, GError **error) { const char *setting_name, *property_name, *option_name; @@ -4209,7 +4210,7 @@ set_option(NmCli *nmc, NULL); if (option && option->check_and_set) { return option->check_and_set(nmc, connection, option, value, error); - } else { + } else if (value || allow_reset) { set_property(nmc->client, connection, setting_name, @@ -5199,7 +5200,7 @@ nmc_process_connection_properties(NmCli *nmc, if (!*argc && nmc->complete) complete_option(nmc, chosen, value ?: "", connection); - if (!set_option(nmc, connection, chosen, value, error)) + if (!set_option(nmc, connection, chosen, value, TRUE, error)) return FALSE; } while (*argc); @@ -5410,7 +5411,7 @@ again: if (multi && !value) return; - if (!set_option(nmc, connection, abstract_info, value, &error)) { + if (!set_option(nmc, connection, abstract_info, value, FALSE, &error)) { g_printerr("%s\n", error->message); g_clear_error(&error); goto again;