From 5ef09fb1a2c9ee7e78dbc0e74e723c667e087bcb Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Fri, 6 Sep 2024 12:20:39 +0200 Subject: [PATCH] casadm: A generic mechanism to disable commands Signed-off-by: Michal Mielewczyk --- casadm/argp.c | 15 ++++++++++++++- casadm/argp.h | 4 +++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/casadm/argp.c b/casadm/argp.c index 9bacd5f73..1ad53f207 100644 --- a/casadm/argp.c +++ b/casadm/argp.c @@ -1,5 +1,6 @@ /* * Copyright(c) 2012-2021 Intel Corporation +* Copyright(c) 2024 Huawei Technologies * SPDX-License-Identifier: BSD-3-Clause */ @@ -26,6 +27,11 @@ static int is_command_hidden(const cli_command* commands, int cmd) return commands[cmd].flags & CLI_COMMAND_HIDDEN; } +static int is_command_blocked(const cli_command* commands, int cmd) +{ + return commands[cmd].flags & CLI_COMMAND_BLOCKED; +} + static void print_short_usage(const app *app_values) { cas_printf(LOG_INFO, "Usage: %s %s\n", app_values->name, app_values->info); @@ -313,8 +319,10 @@ void print_help(const app *app_values, const cli_command *commands) break; } - if (is_command_hidden(commands, i)) + if (is_command_hidden(commands, i) || + is_command_blocked(commands, i)) { continue; + } get_short_name_string(commands[i].short_name, short_name); @@ -614,6 +622,11 @@ int args_parse(app *app_values, cli_command *commands, int argc, const char **ar } } + if (is_command_blocked(commands, i)) { + cas_printf(LOG_ERR, "The command is not supported\n"); + return FAILURE; + } + configure_cli_commands(commands); if (argc >= 3 && get_help_position(argc, argv) != -1) { diff --git a/casadm/argp.h b/casadm/argp.h index b73fa3248..38280252b 100644 --- a/casadm/argp.h +++ b/casadm/argp.h @@ -1,5 +1,6 @@ /* * Copyright(c) 2012-2021 Intel Corporation +* Copyright(c) 2024 Huawei Technologies * SPDX-License-Identifier: BSD-3-Clause */ @@ -22,7 +23,8 @@ enum CLI_OPTION_FLAGS { enum CLI_COMMAND_FLAGS { CLI_SU_REQUIRED = 1 << 0, - CLI_COMMAND_HIDDEN = 1 << 1 + CLI_COMMAND_HIDDEN = 1 << 1, + CLI_COMMAND_BLOCKED = 1 << 2 }; #define ERROR -1