From 40032f4614153d1775744267302dd79287f73b84 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 26 Apr 2021 11:45:39 +0200 Subject: [PATCH] cli: fix resetting values via property alias Property aliases should really just be shortcuts for one fully spelled out property (sometimes, they do more like "master"). Anyway, we must also handle resetting the value, otherwise: $ nmcli connection add type gsm apn "" will still result in "gsm.apn=internet", unlike $ nmcli connection add type gsm gsm.apn "" --- NEWS | 4 +++- src/nmcli/connections.c | 28 +++++++++++----------------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/NEWS b/NEWS index b5cf8d0a11..368e8de6b3 100644 --- a/NEWS +++ b/NEWS @@ -10,7 +10,9 @@ USE AT YOUR OWN RISK. NOT RECOMMENDED FOR PRODUCTION USE! * Add an 'accept-all-mac-addresses' property to the ethernet setting to accept frames with any MAC address (also known as promiscuous - mode) + mode). +* nmcli: fix setting property aliases to empty value to reset the + default value. ============================================= NetworkManager-1.30 diff --git a/src/nmcli/connections.c b/src/nmcli/connections.c index afa8569753..5918b5c27f 100644 --- a/src/nmcli/connections.c +++ b/src/nmcli/connections.c @@ -4182,23 +4182,17 @@ set_option(NmCli * nmc, NULL); if (option && option->check_and_set) { return option->check_and_set(nmc, connection, option, value, error); - } else if (value) { - return set_property(nmc->client, - connection, - setting_name, - property_name, - value, - inf_flags & NM_META_PROPERTY_INF_FLAG_MULTI - ? NM_META_ACCESSOR_MODIFIER_ADD - : NM_META_ACCESSOR_MODIFIER_SET, - error); - } else if (inf_flags & NM_META_PROPERTY_INF_FLAG_REQD) { - g_set_error(error, - NMCLI_ERROR, - NMC_RESULT_ERROR_USER_INPUT, - _("Error: '%s' is mandatory."), - option_name); - return FALSE; + } else { + set_property(nmc->client, + connection, + setting_name, + property_name, + value, + !value ? NM_META_ACCESSOR_MODIFIER_DEL + : (inf_flags & NM_META_PROPERTY_INF_FLAG_MULTI + ? NM_META_ACCESSOR_MODIFIER_ADD + : NM_META_ACCESSOR_MODIFIER_SET), + error); } return TRUE;