line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Radius::SSG; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Revision: 34 $ |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
#use 5.008001; |
6
|
1
|
|
|
1
|
|
30689
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
7
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
8
|
1
|
|
|
1
|
|
1269
|
use Net::Radius::Dictionary; |
|
1
|
|
|
|
|
2773
|
|
|
1
|
|
|
|
|
42
|
|
9
|
1
|
|
|
1
|
|
946
|
use Net::Radius::Packet; |
|
1
|
|
|
|
|
12474
|
|
|
1
|
|
|
|
|
98
|
|
10
|
1
|
|
|
1
|
|
1388
|
use Net::Inet; |
|
1
|
|
|
|
|
65216
|
|
|
1
|
|
|
|
|
235
|
|
11
|
1
|
|
|
1
|
|
1030
|
use Net::UDP; |
|
1
|
|
|
|
|
2951
|
|
|
1
|
|
|
|
|
64
|
|
12
|
1
|
|
|
1
|
|
9
|
use Fcntl; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
494
|
|
13
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
101
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
require Exporter; |
16
|
1
|
|
|
1
|
|
5
|
use AutoLoader qw(AUTOLOAD); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
@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
|
|
|
|
|
|
|
%EXPORT_TAGS = ( 'all' => [ qw( |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
) ] ); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
@EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
@EXPORT = qw( |
34
|
|
|
|
|
|
|
SSG_ACCOUNT_PING SSG_ACCOUNT_LOGON |
35
|
|
|
|
|
|
|
SSG_ACCOUNT_LOGOFF SSG_SERVICE_LOGON |
36
|
|
|
|
|
|
|
SSG_SERVICE_LOGOFF |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
$VERSION = '0.04'; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Preloaded methods go here. |
43
|
|
|
|
|
|
|
|
44
|
1
|
|
|
1
|
|
93
|
use constant VSA_CISCO => 9; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
79
|
|
45
|
1
|
|
|
1
|
|
5
|
use constant SECRET => 'cisco'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
47
|
|
46
|
1
|
|
|
1
|
|
4
|
use constant SSG_ACCOUNT_PING => "\004 &"; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
55
|
|
47
|
1
|
|
|
1
|
|
5
|
use constant SSG_ACCOUNT_LOGON => "\001"; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
59
|
|
48
|
1
|
|
|
1
|
|
12
|
use constant SSG_ACCOUNT_LOGOFF => "\002"; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
52
|
|
49
|
1
|
|
|
1
|
|
5
|
use constant SSG_SERVICE_LOGON => "\013"; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
48
|
|
50
|
1
|
|
|
1
|
|
4
|
use constant SSG_SERVICE_LOGOFF => "\014"; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
38
|
|
51
|
1
|
|
|
1
|
|
5
|
use constant DEFAULT_TIMEOUT => 10; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1234
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub new { |
54
|
0
|
|
|
0
|
1
|
|
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
|
0
|
|
|
|
|
if (!defined $ssg_ip) { |
62
|
0
|
|
|
|
|
|
die "Please specify an IP for the SSG."; |
63
|
|
|
|
|
|
|
} |
64
|
0
|
|
|
|
|
|
$self->{'SSG_IP'} = $ssg_ip; |
65
|
0
|
0
|
|
|
|
|
if (!defined $ssg_port) { |
66
|
0
|
|
|
|
|
|
die "Please specify a port for the SSG."; |
67
|
|
|
|
|
|
|
} |
68
|
0
|
|
|
|
|
|
$self->{'SSG_PORT'} = $ssg_port; |
69
|
0
|
0
|
|
|
|
|
if (!defined $secret) { |
70
|
0
|
|
|
|
|
|
die "Please specify a shared secret for the SSG."; |
71
|
|
|
|
|
|
|
} |
72
|
0
|
|
|
|
|
|
$self->{'SECRET'} = $secret; |
73
|
0
|
0
|
|
|
|
|
if (!defined $dictionary) { |
74
|
0
|
|
|
|
|
|
die "Please specify a dictionary file"; |
75
|
|
|
|
|
|
|
} |
76
|
0
|
0
|
|
|
|
|
if ( ! -r $dictionary) { |
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
|
|
|
|
|
|
|
sub create_udp_handle { |
89
|
0
|
|
|
0
|
0
|
|
my $server = shift; |
90
|
0
|
|
|
|
|
|
my $port = shift; |
91
|
0
|
|
|
|
|
|
my $udp = new Net::UDP $server, $port; |
92
|
0
|
|
|
|
|
|
$udp->bind; |
93
|
0
|
0
|
|
|
|
|
$udp->fcntl(F_SETFL, $udp->fcntl(F_GETFL,0) | O_NONBLOCK) or die "Failed to create a Non-blocking socket: $!"; |
94
|
0
|
|
|
|
|
|
return $udp; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub action { |
98
|
0
|
|
|
0
|
1
|
|
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
|
0
|
|
|
|
|
if ($action eq SSG_ACCOUNT_PING) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub receive_reply { |
126
|
0
|
|
|
0
|
0
|
|
my $udp = shift; |
127
|
0
|
|
|
|
|
|
my $timeout = shift; |
128
|
0
|
0
|
|
|
|
|
$timeout = DEFAULT_TIMEOUT if (!defined $timeout); |
129
|
0
|
|
|
|
|
|
my ($rec, $whence); |
130
|
0
|
|
|
|
|
|
my $nfound = $udp->select(1, 0, 1, $timeout); |
131
|
0
|
0
|
|
|
|
|
if ($nfound > 0) { |
132
|
0
|
|
|
|
|
|
$rec = $udp->recv(undef, undef, $whence); |
133
|
0
|
|
|
|
|
|
return $rec; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub send_packet { |
138
|
0
|
|
|
0
|
0
|
|
my $udp = shift; |
139
|
0
|
|
|
|
|
|
my $packet = shift; |
140
|
0
|
|
|
|
|
|
$udp->send($packet->pack()); |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub account_ping { |
145
|
0
|
|
|
0
|
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
|
|
|
|
|
|
|
sub account_logon { |
154
|
0
|
|
|
0
|
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
|
|
|
|
|
|
|
sub account_logoff { |
168
|
0
|
|
|
0
|
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
|
|
|
|
|
|
|
sub service { |
179
|
0
|
|
|
0
|
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; |
195
|
|
|
|
|
|
|
__END__ |