| 1 | package Net::Radius::SSG; | ||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||
| 3 | # $Revision: 34 $ | ||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||
| 5 | #use 5.008001; | ||||||||||||||||||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 7 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Net::Radius::Dictionary; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Net::Radius::Packet; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Net::Inet; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Net::UDP; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Fcntl; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 13 | 1 | ▶ | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||
| 15 | 1 | require Exporter; | |||||||||||||||||||||||||
| 16 | 1 | ▶ | use AutoLoader qw(AUTOLOAD); | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||
| 18 | 1 | @ISA = qw(Exporter); | |||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||
| 20 | # Items to export into callers namespace by default. Note: do not export | ||||||||||||||||||||||||||
| 21 | # names by default without a very good reason. Use EXPORT_OK instead. | ||||||||||||||||||||||||||
| 22 | # Do not simply export all your public functions/methods/constants. | ||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||
| 24 | # This allows declaration use Net::Radius::SSG ':all'; | ||||||||||||||||||||||||||
| 25 | # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK | ||||||||||||||||||||||||||
| 26 | # will save memory. | ||||||||||||||||||||||||||
| 27 | 1 | %EXPORT_TAGS = ( 'all' => [ qw( | |||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||
| 29 | ) ] ); | ||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||
| 31 | 1 | @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||
| 33 | 1 | @EXPORT = qw( | |||||||||||||||||||||||||
| 34 | SSG_ACCOUNT_PING SSG_ACCOUNT_LOGON | ||||||||||||||||||||||||||
| 35 | SSG_ACCOUNT_LOGOFF SSG_SERVICE_LOGON | ||||||||||||||||||||||||||
| 36 | SSG_SERVICE_LOGOFF | ||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||
| 39 | 1 | $VERSION = '0.04'; | |||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||
| 42 | # Preloaded methods go here. | ||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||
| 44 | 1 | ▶ | use constant VSA_CISCO => 9; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 45 | 1 | ▶ | use constant SECRET => 'cisco'; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 46 | 1 | ▶ | use constant SSG_ACCOUNT_PING => "\004 &"; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 47 | 1 | ▶ | use constant SSG_ACCOUNT_LOGON => "\001"; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 48 | 1 | ▶ | use constant SSG_ACCOUNT_LOGOFF => "\002"; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 49 | 1 | ▶ | use constant SSG_SERVICE_LOGON => "\013"; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 50 | 1 | ▶ | use constant SSG_SERVICE_LOGOFF => "\014"; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 51 | 1 | ▶ | use constant DEFAULT_TIMEOUT => 10; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub new { | ||||||||||||||||||||||||
|
Subroutine
new: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||
| 54 | 0 | my $class = shift; | |||||||||||||||||||||||||
| 55 | 0 | my $ssg_ip = shift; | |||||||||||||||||||||||||
| 56 | 0 | my $ssg_port = shift; | |||||||||||||||||||||||||
| 57 | 0 | my $secret = shift; | |||||||||||||||||||||||||
| 58 | 0 | my $dictionary = shift; | |||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||
| 60 | 0 | my $self = { }; | |||||||||||||||||||||||||
| 61 | 0 | ▶ | if (!defined $ssg_ip) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 62 | 0 | die "Please specify an IP for the SSG."; | |||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||
| 64 | 0 | $self->{'SSG_IP'} = $ssg_ip; | |||||||||||||||||||||||||
| 65 | 0 | ▶ | if (!defined $ssg_port) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 66 | 0 | die "Please specify a port for the SSG."; | |||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||
| 68 | 0 | $self->{'SSG_PORT'} = $ssg_port; | |||||||||||||||||||||||||
| 69 | 0 | ▶ | if (!defined $secret) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 70 | 0 | die "Please specify a shared secret for the SSG."; | |||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||
| 72 | 0 | $self->{'SECRET'} = $secret; | |||||||||||||||||||||||||
| 73 | 0 | ▶ | if (!defined $dictionary) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 74 | 0 | die "Please specify a dictionary file"; | |||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||
| 76 | 0 | ▶ | if ( ! -r $dictionary) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 77 | 0 | die "Unable to read dictionary file: $dictionary"; | |||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||
| 80 | 0 | $self->{'DICTIONARY'} = new Net::Radius::Dictionary($dictionary); | |||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||
| 82 | 0 | $self->{'SOCKET'} = &create_udp_handle($ssg_ip,$ssg_port); | |||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||
| 84 | 0 | bless $self,$class; | |||||||||||||||||||||||||
| 85 | 0 | return $self; | |||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||
| 88 | 0 | ▶ | sub create_udp_handle { | ||||||||||||||||||||||||
|
Subroutine
create_udp_handle: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||
| 89 | 0 | my $server = shift; | |||||||||||||||||||||||||
| 90 | 0 | my $port = shift; | |||||||||||||||||||||||||
| 91 | 0 | my $udp = new Net::UDP $server, $port; | |||||||||||||||||||||||||
| 92 | 0 | $udp->bind; | |||||||||||||||||||||||||
| 93 | 0 | ▶ | $udp->fcntl(F_SETFL, $udp->fcntl(F_GETFL,0) | O_NONBLOCK) or die "Failed to create a Non-blocking socket: $!"; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 94 | 0 | return $udp; | |||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||
| 97 | 0 | ▶ | sub action { | ||||||||||||||||||||||||
|
Subroutine
action: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||
| 98 | 0 | my $self = shift; | |||||||||||||||||||||||||
| 99 | 0 | my $action = shift; | |||||||||||||||||||||||||
| 100 | 0 | my $values = shift; | |||||||||||||||||||||||||
| 101 | 0 | my $data; | |||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||
| 103 | 0 | my $packet = new Net::Radius::Packet($self->{DICTIONARY}); | |||||||||||||||||||||||||
| 104 | 0 | $packet->set_authenticator('1234w6t890123a5c'); | |||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||
| 106 | 0 | ▶ | if ($action eq SSG_ACCOUNT_PING) { | ||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||
| 107 | 0 | &account_ping($packet,$values->{user_ip}); | |||||||||||||||||||||||||
| 108 | } elsif ($action eq SSG_ACCOUNT_LOGON) { | ||||||||||||||||||||||||||
| 109 | 0 | &account_logon($packet,$values->{user_ip},$values->{user_id},$values->{password}, $self->{SECRET}); | |||||||||||||||||||||||||
| 110 | } elsif ($action eq SSG_ACCOUNT_LOGOFF) { | ||||||||||||||||||||||||||
| 111 | 0 | &account_logoff($packet,$values->{user_ip},$values->{user_id}); | |||||||||||||||||||||||||
| 112 | } elsif ($action eq SSG_SERVICE_LOGON) { | ||||||||||||||||||||||||||
| 113 | 0 | &service($packet,$values->{user_ip},$values->{service}, SSG_SERVICE_LOGON); | |||||||||||||||||||||||||
| 114 | } elsif ($action eq SSG_SERVICE_LOGOFF) { | ||||||||||||||||||||||||||
| 115 | 0 | &service($packet,$values->{user_ip},$values->{service}, SSG_SERVICE_LOGOFF); | |||||||||||||||||||||||||
| 116 | } else { | ||||||||||||||||||||||||||
| 117 | 0 | die ("Unknown action"); | |||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||
| 119 | 0 | &send_packet($self->{SOCKET},$packet); | |||||||||||||||||||||||||
| 120 | 0 | my $reply = &receive_reply($self->{SOCKET}, $values->{timeout}); | |||||||||||||||||||||||||
| 121 | 0 | my $rp = new Net::Radius::Packet $self->{DICTIONARY}, $reply; | |||||||||||||||||||||||||
| 122 | 0 | return $rp; | |||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||
| 125 | 0 | ▶ | sub receive_reply { | ||||||||||||||||||||||||
|
Subroutine
receive_reply: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||
| 126 | 0 | my $udp = shift; | |||||||||||||||||||||||||
| 127 | 0 | my $timeout = shift; | |||||||||||||||||||||||||
| 128 | 0 | ▶ | $timeout = DEFAULT_TIMEOUT if (!defined $timeout); | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 129 | 0 | my ($rec, $whence); | |||||||||||||||||||||||||
| 130 | 0 | my $nfound = $udp->select(1, 0, 1, $timeout); | |||||||||||||||||||||||||
| 131 | 0 | ▶ | if ($nfound > 0) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 132 | 0 | $rec = $udp->recv(undef, undef, $whence); | |||||||||||||||||||||||||
| 133 | 0 | return $rec; | |||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||
| 137 | 0 | ▶ | sub send_packet { | ||||||||||||||||||||||||
|
Subroutine
send_packet: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||
| 138 | 0 | my $udp = shift; | |||||||||||||||||||||||||
| 139 | 0 | my $packet = shift; | |||||||||||||||||||||||||
| 140 | 0 | $udp->send($packet->pack()); | |||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||
| 144 | 0 | ▶ | sub account_ping { | ||||||||||||||||||||||||
|
Subroutine
account_ping: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||
| 145 | 0 | my $packet = shift; | |||||||||||||||||||||||||
| 146 | 0 | my $user_ip = shift; | |||||||||||||||||||||||||
| 147 | 0 | $packet->set_code('Access-Request'); | |||||||||||||||||||||||||
| 148 | 0 | $packet->set_identifier(57); | |||||||||||||||||||||||||
| 149 | 0 | $packet->set_vsattr(VSA_CISCO,'Account-Info','S'.$user_ip); | |||||||||||||||||||||||||
| 150 | 0 | $packet->set_vsattr(VSA_CISCO,'Command-Code', SSG_ACCOUNT_PING); | |||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||
| 153 | 0 | ▶ | sub account_logon { | ||||||||||||||||||||||||
|
Subroutine
account_logon: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||
| 154 | 0 | my $packet = shift; | |||||||||||||||||||||||||
| 155 | 0 | my $user_ip = shift; | |||||||||||||||||||||||||
| 156 | 0 | my $user_id = shift; | |||||||||||||||||||||||||
| 157 | 0 | my $password = shift; | |||||||||||||||||||||||||
| 158 | 0 | my $secret = shift; | |||||||||||||||||||||||||
| 159 | 0 | $packet->set_code('Access-Request'); | |||||||||||||||||||||||||
| 160 | 0 | $packet->set_identifier(57); | |||||||||||||||||||||||||
| 161 | 0 | $packet->set_attr('User-Name',$user_id); | |||||||||||||||||||||||||
| 162 | 0 | $packet->set_password($password,$secret); | |||||||||||||||||||||||||
| 163 | 0 | $packet->set_vsattr(VSA_CISCO,'Account-Info','S'.$user_ip); | |||||||||||||||||||||||||
| 164 | 0 | $packet->set_vsattr(VSA_CISCO,'Command-Code', SSG_ACCOUNT_LOGON."$user_id"); | |||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||
| 167 | 0 | ▶ | sub account_logoff { | ||||||||||||||||||||||||
|
Subroutine
account_logoff: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||
| 168 | 0 | my $packet = shift; | |||||||||||||||||||||||||
| 169 | 0 | my $user_ip = shift; | |||||||||||||||||||||||||
| 170 | 0 | my $user_id = shift; | |||||||||||||||||||||||||
| 171 | 0 | $packet->set_code('Access-Request'); | |||||||||||||||||||||||||
| 172 | 0 | $packet->set_identifier(57); | |||||||||||||||||||||||||
| 173 | 0 | $packet->set_attr('User-Name',$user_id); | |||||||||||||||||||||||||
| 174 | 0 | $packet->set_vsattr(VSA_CISCO,'Account-Info','S'.$user_ip); | |||||||||||||||||||||||||
| 175 | 0 | $packet->set_vsattr(VSA_CISCO,'Command-Code', SSG_ACCOUNT_LOGOFF."$user_id"); | |||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||
| 178 | 0 | ▶ | sub service { | ||||||||||||||||||||||||
|
Subroutine
service: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||
| 179 | 0 | my $packet = shift; | |||||||||||||||||||||||||
| 180 | 0 | my $user_ip = shift; | |||||||||||||||||||||||||
| 181 | 0 | my $service = shift; | |||||||||||||||||||||||||
| 182 | 0 | my $action = shift; | |||||||||||||||||||||||||
| 183 | 0 | $packet->set_code('Access-Request'); | |||||||||||||||||||||||||
| 184 | 0 | $packet->set_identifier(23); | |||||||||||||||||||||||||
| 185 | 0 | $packet->set_vsattr(VSA_CISCO,'Account-Info','S'.$user_ip); | |||||||||||||||||||||||||
| 186 | 0 | $packet->set_vsattr(VSA_CISCO,'Command-Code', $action."$service"); | |||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||
| 192 | # Autoload methods go after =cut, and are processed by the autosplit program. | ||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||
| 194 | 1 | 1; | |||||||||||||||||||||||||
| 195 | __END__ | ||||||||||||||||||||||||||