cli: deny removing values of nmcli-unchangable properties
nmc_setting_reset_property() function checks whether we allow changing the property (set_func != NULL) and if so, the property value is reset to default.
This commit is contained in:
@@ -5318,8 +5318,13 @@ property_edit_submenu (NmCli *nmc,
|
|||||||
g_clear_error (&tmp_err);
|
g_clear_error (&tmp_err);
|
||||||
}
|
}
|
||||||
g_free (option);
|
g_free (option);
|
||||||
} else
|
} else {
|
||||||
nmc_property_set_default_value (curr_setting, prop_name);
|
if (!nmc_setting_reset_property (curr_setting, prop_name, &tmp_err)) {
|
||||||
|
printf (_("Error: failed to remove value of '%s': %s\n"), prop_name,
|
||||||
|
tmp_err->message);
|
||||||
|
g_clear_error (&tmp_err);
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NMC_EDITOR_SUB_CMD_DESCRIBE:
|
case NMC_EDITOR_SUB_CMD_DESCRIBE:
|
||||||
@@ -5775,6 +5780,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||||||
/* Remove setting from connection, or delete value of a property */
|
/* Remove setting from connection, or delete value of a property */
|
||||||
if (!cmd_arg) {
|
if (!cmd_arg) {
|
||||||
if (menu_ctx.level == 1) {
|
if (menu_ctx.level == 1) {
|
||||||
|
GError *tmp_err = NULL;
|
||||||
const char *prop_name;
|
const char *prop_name;
|
||||||
|
|
||||||
prop_name = ask_check_property (cmd_arg,
|
prop_name = ask_check_property (cmd_arg,
|
||||||
@@ -5784,7 +5790,11 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
/* Delete property value */
|
/* Delete property value */
|
||||||
nmc_property_set_default_value (menu_ctx.curr_setting, prop_name);
|
if (!nmc_setting_reset_property (menu_ctx.curr_setting, prop_name, &tmp_err)) {
|
||||||
|
printf (_("Error: failed to remove value of '%s': %s\n"), prop_name,
|
||||||
|
tmp_err->message);
|
||||||
|
g_clear_error (&tmp_err);
|
||||||
|
}
|
||||||
} else
|
} else
|
||||||
printf (_("Error: no argument given; valid are [%s]\n"), valid_settings_str);
|
printf (_("Error: no argument given; valid are [%s]\n"), valid_settings_str);
|
||||||
} else {
|
} else {
|
||||||
@@ -5821,7 +5831,11 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||||||
char *prop_name = is_property_valid (ss, cmd_arg_p, &tmp_err);
|
char *prop_name = is_property_valid (ss, cmd_arg_p, &tmp_err);
|
||||||
if (prop_name) {
|
if (prop_name) {
|
||||||
/* Delete property value */
|
/* Delete property value */
|
||||||
nmc_property_set_default_value (ss, prop_name);
|
if (!nmc_setting_reset_property (ss, prop_name, &tmp_err)) {
|
||||||
|
printf (_("Error: failed to remove value of '%s': %s\n"), prop_name,
|
||||||
|
tmp_err->message);
|
||||||
|
g_clear_error (&tmp_err);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
/* If the string is not a property, try it as a setting */
|
/* If the string is not a property, try it as a setting */
|
||||||
NMSetting *s_tmp;
|
NMSetting *s_tmp;
|
||||||
|
@@ -4769,6 +4769,32 @@ nmc_property_set_default_value (NMSetting *setting, const char *prop)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Generic function for reseting (single value) properties.
|
||||||
|
*
|
||||||
|
* The function resets the property value to the default one. It respects
|
||||||
|
* nmcli restrictions for changing properties. So if 'set_func' is NULL,
|
||||||
|
* reseting the value is denied.
|
||||||
|
*
|
||||||
|
* Returns: TRUE on success; FALSE on failure and sets error
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
nmc_setting_reset_property (NMSetting *setting, const char *prop, GError **error)
|
||||||
|
{
|
||||||
|
const NmcPropertyFuncs *item;
|
||||||
|
|
||||||
|
g_return_val_if_fail (NM_IS_SETTING (setting), FALSE);
|
||||||
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||||
|
|
||||||
|
item = nmc_properties_find (nm_setting_get_name (setting), prop);
|
||||||
|
if (item && item->set_func) {
|
||||||
|
nmc_property_set_default_value (setting, prop);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
g_set_error_literal (error, 1, 0, _("the property can't be changed"));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generic function for removing items for collection-type properties.
|
* Generic function for removing items for collection-type properties.
|
||||||
*
|
*
|
||||||
|
@@ -66,6 +66,9 @@ gboolean nmc_setting_set_property (NMSetting *setting,
|
|||||||
const char *prop,
|
const char *prop,
|
||||||
const char *val,
|
const char *val,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
gboolean nmc_setting_reset_property (NMSetting *setting,
|
||||||
|
const char *prop,
|
||||||
|
GError **error);
|
||||||
gboolean nmc_setting_remove_property_option (NMSetting *setting,
|
gboolean nmc_setting_remove_property_option (NMSetting *setting,
|
||||||
const char *prop,
|
const char *prop,
|
||||||
const char *option,
|
const char *option,
|
||||||
|
Reference in New Issue
Block a user