]> git.puffer.fish Git - mirror/frr.git/commitdiff
vtysh: Handle `en` better when in -u for vtysh 9116/head
authorDonald Sharp <sharpd@nvidia.com>
Thu, 22 Jul 2021 15:59:25 +0000 (11:59 -0400)
committerDonald Sharp <sharpd@nvidia.com>
Thu, 22 Jul 2021 16:00:58 +0000 (12:00 -0400)
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 <sharpd@nvidia.com>
vtysh/vtysh.c

index 0bc2c6ebd06fdb424bb108df36618fb3feed7ec7..a8906e72aea1c180db1a3833f5b3633407c2b48d 100644 (file)
@@ -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;
+                       }
                }
        }