ipnetns: do not check netns NAME when -all is specified

When `-all' argument is specified netns runs cmd on all namespaces
and NAME is not used, but netns nevertheless checks if argv[1] is a
valid namespace name ignoring the fact that argv[1] contains cmd
and not NAME. This results in bug where user cannot specify
absolute path to command.

    # ip -all netns exec /usr/bin/whoami
    Invalid netns name "/usr/bin/whoami"

This forces user to have his command in PATH.

Solution is simply to not validate argv[1] when `-all' argument is
specified.

Signed-off-by: Michał Łyszczek <michal.lyszczek@bofc.pl>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
This commit is contained in:
Michał Łyszczek 2019-10-22 22:09:23 +02:00 committed by Stephen Hemminger
parent d49e5c2437
commit b7f28e0bd9
1 changed files with 1 additions and 1 deletions

View File

@ -994,7 +994,7 @@ int do_netns(int argc, char **argv)
return netns_list(0, NULL);
}
if (argc > 1 && invalid_name(argv[1])) {
if (!do_all && argc > 1 && invalid_name(argv[1])) {
fprintf(stderr, "Invalid netns name \"%s\"\n", argv[1]);
exit(-1);
}