Forked from
smradius / smradius
739 commits behind the upstream repository.
-
Nigel Kukard authoredNigel Kukard authored
Packet.pm 17.56 KiB
package Radius::Packet;
use strict;
require Exporter;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $VSA);
@ISA = qw(Exporter);
@EXPORT = qw(auth_resp auth_acct_verify auth_req_verify);
@EXPORT_OK = qw( );
$VERSION = '1.55';
$VSA = 26; # Type assigned in RFC2138 to the
# Vendor-Specific Attributes
# Be sure our dictionaries are current
use Radius::Dictionary 1.50;
use Carp;
use Socket;
use Digest::MD5;
my (%unkvprinted, %unkgprinted);
sub new {
my ($class, $dict, $data) = @_;
my $self = { unknown_entries => 1 };
bless $self, $class;
$self->set_dict($dict) if defined($dict);
$self->unpack($data) if defined($data);
return $self;
}
# Set the dictionary
sub set_dict {
my ($self, $dict) = @_;
$self->{Dict} = $dict;
}
# Functions for accessing data structures
sub code { $_[0]->{Code}; }
sub identifier { $_[0]->{Identifier}; }
sub authenticator { $_[0]->{Authenticator}; }
sub set_code { $_[0]->{Code} = $_[1]; }
sub set_identifier { $_[0]->{Identifier} = $_[1]; }
sub set_authenticator { $_[0]->{Authenticator} = substr($_[1]
. "\x0" x 16,
0, 16); }
sub vendors { keys %{$_[0]->{VSAttributes}}; }
sub vsattributes { keys %{$_[0]->{VSAttributes}->{$_[1]}}; }
sub vsattr { $_[0]->{VSAttributes}->{$_[1]}->{$_[2]}; }
sub set_vsattr {
my ($self, $vendor, $name, $value, $rewrite_flag, $rawValue) = @_;
$self->{VSAttributes}->{$vendor} = {} unless exists($self->{VSAttributes}->{$vendor});
my $attr = $self->{VSAttributes}->{$vendor};
if ($rewrite_flag) {
my $found = 0;
if (exists($attr->{$name})) {
$found = $#{$attr->{$name}} + 1;
}
if ($found == 1) {
$attr->{$name}[0] = $value;
return;
}
}
# Check if we should be adding the raw value or not