From: Donald Sharp Date: Thu, 22 Jul 2021 15:59:25 +0000 (-0400) Subject: vtysh: Handle `en` better when in -u for vtysh X-Git-Tag: base_8.1~293^2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=refs%2Fpull%2F9116%2Fhead;p=mirror%2Ffrr.git vtysh: Handle `en` better when in -u for vtysh vtysh was unable to distinguish between end and ena. The code can now do so: sharpd@eva ~/frr5 (master)> sudo vtysh/vtysh -u sharpd Hello, this is FRRouting (version 8.1-dev). Copyright 1996-2005 Kunihiro Ishiguro, et al. eva> e % Ambiguous command: e eva> en % Command not allowed: enable eva> ena % Command not allowed: enable eva> enab % Command not allowed: enable eva> enabl % Command not allowed: enable eva> enable % Command not allowed: enable eva> enb % Unknown command: enb eva> enc % Unknown command: enc eva> end % Unknown command: end eva> ene % Unknown command: ene eva> quit Fixes: #2296 Signed-off-by: Donald Sharp --- diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 0bc2c6ebd0..a8906e72ae 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -479,10 +479,21 @@ static int vtysh_execute_func(const char *line, int pager) return CMD_SUCCESS; if (user_mode) { + bool allow = true; if (strncmp("en", vector_slot(vline, 0), 2) == 0) { - cmd_free_strvec(vline); - vty_out(vty, "%% Command not allowed: enable\n"); - return CMD_WARNING; + if (strlen(line) >= 3) { + if (strncmp("ena", vector_slot(vline, 0), 3) + == 0) + allow = false; + } else + allow = false; + + if (!allow) { + cmd_free_strvec(vline); + vty_out(vty, + "%% Command not allowed: enable\n"); + return CMD_WARNING; + } } }