diff --git a/bin/shell/osh.pl b/bin/shell/osh.pl index 216e588..11a7fdb 100755 --- a/bin/shell/osh.pl +++ b/bin/shell/osh.pl @@ -230,10 +230,9 @@ my $result = GetOptions( "c=s" => \$realOptions, # user command under -c '...' "debug" => \$opt_debug, ); - -if (not $result or not $realOptions) { +if (not $result) { help(); - main_exit OVH::Bastion::EXIT_UNKNOWN_COMMAND, "unknown_command", "Bad or empty command"; + main_exit OVH::Bastion::EXIT_UNKNOWN_COMMAND, "unknown_command", "Bad command"; } $osh_debug = 1 if $opt_debug; # osh_debug was already 1 if specified in config file @@ -258,7 +257,7 @@ my @toExecute; # special case: mosh, in that case we have something like this in $realOptions # mosh-server 'new' '-s' '-c' '256' '-l' 'LANG=en_US.UTF-8' '-l' 'LANGUAGE=en_US' '--' '--osh' 'info' -if ($realOptions =~ /^mosh-server (.+?) '--' (.*)/) { +if (defined $realOptions && $realOptions =~ /^mosh-server (.+?) '--' (.*)/) { osh_debug("MOSH DETECTED (with params)"); # remove mosh stuff and save it for later @@ -294,7 +293,7 @@ if ($realOptions =~ /^mosh-server (.+?) '--' (.*)/) { main_exit OVH::Bastion::EXIT_MOSH_DISABLED, "mosh_disabled", "Mosh support has been disabled on this bastion"; } } -elsif ($realOptions =~ /^mosh-server /) { +elsif (defined $realOptions && $realOptions =~ /^mosh-server /) { osh_debug("MOSH DETECTED (without any param)"); # we won't really use mosh, as we'll exit later with the bastion help anyway @@ -307,7 +306,7 @@ elsif ($realOptions =~ /^mosh-server /) { my $beforeOptions; my $afterOptions; -if ($realOptions =~ /^(.*?) -- (.*)$/) { +if (defined $realOptions && $realOptions =~ /^(.*?) -- (.*)$/) { $beforeOptions = $1; $afterOptions = $2; osh_debug("before <$beforeOptions> after <$afterOptions>"); @@ -362,6 +361,17 @@ my $remainingOptions; "use-key=s" => \my $useKey, "kbd-interactive" => \my $userKbdInteractive, ); +if (not defined $realOptions) { + help(); + if (OVH::Bastion::config('interactiveModeByDefault')->value) { + # nothing specified by the user, let's drop them to the interactive mode + osh_warn("No command specified, entering interactive mode by default"); + $interactive = 1; + } + else { + main_exit OVH::Bastion::EXIT_UNKNOWN_COMMAND, "unknown_command", "Missing command"; + } +} if (!$quiet && $realm && !$ENV{'OSH_NO_INTERACTIVE'}) { my $welcome = diff --git a/etc/bastion/bastion.conf.dist b/etc/bastion/bastion.conf.dist index 5cee36a..6096675 100644 --- a/etc/bastion/bastion.conf.dist +++ b/etc/bastion/bastion.conf.dist @@ -257,6 +257,11 @@ # DEFAULT: 60 "interactiveModeTimeout": 60, # +# interactiveModeByDefault (boolean-int) +# DESC: If true (1), drops the user to interactive mode if nothing is specified on the command line. If false (0), displays the help and exits with an error. Note that for `true' to have the expected effect, interactive mode must be enabled (see the `ìnteractiveModeAllowed' option above). +# DEFAULT: 1 +"interactiveModeByDefault": 1, +# # enableSyslog (boolean-int) # DESC: If set to 0, syslog will be disabled. If set to 1, we'll send logs through syslog (don't forget to setup your syslogd) # DEFAULT: 1 diff --git a/lib/perl/OVH/Bastion/configuration.inc b/lib/perl/OVH/Bastion/configuration.inc index 90324cc..0abf7ea 100644 --- a/lib/perl/OVH/Bastion/configuration.inc +++ b/lib/perl/OVH/Bastion/configuration.inc @@ -201,7 +201,10 @@ sub load_configuration { $C->{'idleLockTimeout'} = 0 if ($C->{'idleKillTimeout'} <= $C->{'idleLockTimeout'}); # booleans that can only be 0 or 1 and default to 1 - foreach my $key (qw{ enableSyslog enableGlobalAccessLog enableAccountAccessLog enableGlobalSqlLog enableAccountSqlLog displayLastLogin }) { + foreach my $key (qw{ + enableSyslog enableGlobalAccessLog enableAccountAccessLog enableGlobalSqlLog enableAccountSqlLog displayLastLogin + interactiveModeByDefault + }) { $C->{$key} = 1 if (not defined $C->{$key} or $C->{$key} !~ /^\d+$/); $C->{$key} > 1 and $C->{$key} = 1; }