chore: check for spurious args in all helpers

This commit is contained in:
Stéphane Lesimple 2021-12-15 17:11:03 +00:00 committed by Stéphane Lesimple
parent 90dbe04dde
commit 7cc350b40d
29 changed files with 66 additions and 3 deletions

View file

@ -39,6 +39,8 @@ if (!$result) {
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
}
OVH::Bastion::Helper::check_spurious_args();
if (not $action or not $ip or not $account or not $group) {
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'action' or 'ip' or 'account' or 'group'");
}

View file

@ -40,6 +40,8 @@ eval {
};
if ($@) { die $@ }
OVH::Bastion::Helper::check_spurious_args();
if (!$result) {
local $" = ", ";
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");

View file

@ -35,6 +35,8 @@ if (!$result) {
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
}
OVH::Bastion::Helper::check_spurious_args();
if (!$account || !$type) {
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'account' or 'type'");
}

View file

@ -33,6 +33,8 @@ if (!$result) {
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
}
OVH::Bastion::Helper::check_spurious_args();
if (not $size or not $account) {
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'size' or 'account'");
}

View file

@ -33,6 +33,8 @@ if (!$result) {
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
}
OVH::Bastion::Helper::check_spurious_args();
if (!$account && !$all) {
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'account' or 'all'");
}

View file

@ -29,6 +29,8 @@ if (!$result) {
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
}
OVH::Bastion::Helper::check_spurious_args();
if (!$account) {
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'account'");
}

View file

@ -32,6 +32,8 @@ if (!$result) {
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
}
OVH::Bastion::Helper::check_spurious_args();
if (!$account) {
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'account'");
}

View file

@ -29,6 +29,8 @@ if (!$result) {
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
}
OVH::Bastion::Helper::check_spurious_args();
if (!$account) {
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'account'");
}

View file

@ -30,6 +30,8 @@ if (!$result) {
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
}
OVH::Bastion::Helper::check_spurious_args();
if (not $account) {
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'account'");
}

View file

@ -30,6 +30,8 @@ if (!$result) {
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
}
OVH::Bastion::Helper::check_spurious_args();
if (not $account) {
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'account'");
}

View file

@ -34,6 +34,8 @@ if (!$result) {
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
}
OVH::Bastion::Helper::check_spurious_args();
if (!$account || !@modify) {
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'account' or 'modify'");
}

View file

@ -37,6 +37,8 @@ if (!$result) {
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
}
OVH::Bastion::Helper::check_spurious_args();
if (not $account or not $command or not $action) {
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'account', 'command' or 'action'");
}

View file

@ -50,6 +50,8 @@ eval {
};
if ($@) { die $@ }
OVH::Bastion::Helper::check_spurious_args();
if (!$result) {
local $" = ", ";
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");

View file

@ -37,6 +37,8 @@ if (!$result) {
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
}
OVH::Bastion::Helper::check_spurious_args();
if (!$account || !$policy || !$step) {
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'account' or 'modify' or 'step'");
}

View file

@ -29,6 +29,8 @@ if (!$result) {
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
}
OVH::Bastion::Helper::check_spurious_args();
if (!$account) {
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'account'");
}

View file

@ -32,6 +32,8 @@ if (!$result) {
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
}
OVH::Bastion::Helper::check_spurious_args();
if (not $action) {
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'action'");
}

View file

@ -42,6 +42,8 @@ if (!$result) {
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
}
OVH::Bastion::Helper::check_spurious_args();
if (not $ip or not $group or not $action) {
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'ip' or 'group' or 'action'");
}

View file

@ -33,6 +33,8 @@ if (!$result) {
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
}
OVH::Bastion::Helper::check_spurious_args();
if (not $account or not $group or not $action) {
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'account', 'group' or 'action'");
}

View file

@ -39,6 +39,8 @@ if (!$result) {
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
}
OVH::Bastion::Helper::check_spurious_args();
if (!$group || !$owner) {
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'group' or 'owner'");
}

View file

@ -33,6 +33,8 @@ if (!$result) {
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
}
OVH::Bastion::Helper::check_spurious_args();
if (!$group || !$id) {
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'group' or 'id'");
}

View file

@ -32,6 +32,8 @@ if (!$result) {
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
}
OVH::Bastion::Helper::check_spurious_args();
if (!$group) {
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'group'");
}

View file

@ -35,6 +35,8 @@ if (!$result) {
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
}
OVH::Bastion::Helper::check_spurious_args();
if (!$size || !$algo || !$group) {
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'size', 'algo' or 'group'");
}

View file

@ -33,6 +33,8 @@ if (!$result) {
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
}
OVH::Bastion::Helper::check_spurious_args();
if (not $size or not $group) {
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'size' or 'group'");
}

View file

@ -34,6 +34,8 @@ if (!$result) {
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
}
OVH::Bastion::Helper::check_spurious_args();
if (!$group) {
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'group'");
}

View file

@ -44,6 +44,8 @@ if (!$result) {
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
}
OVH::Bastion::Helper::check_spurious_args();
osh_debug("groupSetRole: checking preconditions");
$fnret = OVH::Bastion::Plugin::groupSetRole::preconditions(self => $self, account => $account, group => $group, action => $action, type => $type, sudo => 1, silentoverride => 1);
osh_debug("groupSetRole: checking preconditions result: $fnret");

View file

@ -31,6 +31,8 @@ if (!$result) {
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
}
OVH::Bastion::Helper::check_spurious_args();
if (!$account || !defined $step) {
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'account' or 'step'");
}

View file

@ -29,6 +29,8 @@ if (!$result) {
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
}
OVH::Bastion::Helper::check_spurious_args();
if (not $account) {
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'account'");
}

View file

@ -134,9 +134,9 @@ push @command, "--type", "normal";
push @command, "--account", $account;
push @command, "--pubKey", $pubKey if !$noKey;
push @command, "--always-active" if $alwaysActive;
push @command, "--comment", $comment if $comment;
push @command, "--uid", $uid if defined $uid;
push @command, "--osh-only", $oshOnly if $oshOnly;
push @command, "--comment", $comment if $comment;
push @command, "--uid", $uid if defined $uid;
push @command, "--osh-only", if $oshOnly;
push @command, "--max-inactive-days", $maxInactiveDays if defined $maxInactiveDays;
push @command, "--uid-auto" if $uidAuto;
push @command, "--immutable-key" if $immutableKey;

View file

@ -37,6 +37,15 @@ sub HEXIT { ## no critic (ArgUnpacking)
exit 0;
}
# Used after Getopt::Long::GetOptions() in each helper, to ensure there are no unparsed/spurious args
sub check_spurious_args {
if (@ARGV) {
local $" = ", ";
warn_syslog("Spurious arguments on command line: @ARGV");
HEXIT('ERR_BAD_OPTIONS', msg => "Spurious arguments on command line: @ARGV");
}
}
#
# This code has to be ran for all helpers before they attempt to do anything useful,
# and as we're only use'd by helpers, we include it here directly on top-level.