diff --git a/apps/protocols/radius/mode/login.pm b/apps/protocols/radius/mode/login.pm index 6fdd95c8d..8d0e3264f 100644 --- a/apps/protocols/radius/mode/login.pm +++ b/apps/protocols/radius/mode/login.pm @@ -78,22 +78,21 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', default => 1812 }, - "secret:s" => { name => 'secret' }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - "timeout:s" => { name => 'timeout', default => 5 }, - "retry:s" => { name => 'retry', default => 0 }, - 'radius-attribute:s%' => { name => 'radius_attribute' }, - 'radius-dictionary:s' => { name => 'radius_dictionary' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} ne "accepted"' }, - }); + $options{options}->add_options(arguments => { + 'hostname:s' => { name => 'hostname' }, + 'port:s' => { name => 'port', default => 1812 }, + 'secret:s' => { name => 'secret' }, + 'username:s' => { name => 'username' }, + 'password:s' => { name => 'password' }, + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' }, + 'timeout:s' => { name => 'timeout', default => 5 }, + 'retry:s' => { name => 'retry', default => 0 }, + 'radius-attribute:s%' => { name => 'radius_attribute' }, + 'radius-dictionary:s@' => { name => 'radius_dictionary' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} ne "accepted"' } + }); return $self; } @@ -110,11 +109,10 @@ sub check_options { $self->{output}->option_exit(); } } - - if (defined($self->{option_results}->{radius_attribute}) && - (!defined($self->{option_results}->{radius_dictionary}) || $self->{option_results}->{radius_dictionary} eq '')) { - $self->{output}->add_option_msg(short_msg => "Please set radius-dictionary option"); - $self->{output}->option_exit(); + + $self->{radius_dictionary} = []; + if (defined($self->{option_results}->{radius_attribute})) { + $self->{radius_dictionary} = $self->{option_results}->{radius_attribute}; } $self->{option_results}->{retry} = 0 if (!defined($self->{option_results}->{retry}) || $self->{option_results}->{retry} !~ /^\d+$/); @@ -151,7 +149,11 @@ sub radius_attr_connection { local $SIG{__WARN__} = sub { $message = join(' - ', @_); }; local $SIG{__DIE__} = sub { $message = join(' - ', @_); }; - Authen::Radius->load_dictionary($self->{option_results}->{radius_dictionary}); + foreach my $dic (@{$self->{radius_dictionary}}) { + next if ($dic eq ''); + Authen::Radius->load_dictionary($dic); + } + foreach (keys %{$self->{option_results}->{radius_attribute}}) { $self->{radius_session}->add_attributes({ Name => $_, Value => $self->{option_results}->{radius_attribute}->{$_} }); } @@ -192,7 +194,11 @@ sub manage_selection { Secret => $self->{option_results}->{secret}, TimeOut => $self->{option_results}->{timeout}, ); - + if (!defined($self->{radius_session})) { + $self->{output}->add_option_msg(short_msg => 'failure: ' . Authen::Radius::strerror()); + $self->{output}->option_exit(); + } + if (defined($self->{option_results}->{radius_attribute})) { $self->radius_attr_connection(); } else { @@ -257,7 +263,7 @@ Example: --radius-attribute="User-Password=test" =item B<--radius-dictionary> -Set radius-dictionary file (mandatory with --radius-attribute). +Set radius-dictionary file (mandatory with --radius-attribute) (multiple option). =item B<--warning-status>