| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#! /usr/bin/perl |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
# $Id: Simple.pm 75 2009-08-12 22:08:28Z lem $ |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Net::Radius::Server::Match::Simple; |
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
1926
|
use 5.008; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
34
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
29
|
|
|
10
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
76
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = do { sprintf "%0.3f", 1+(q$Revision: 75 $ =~ /\d+/g)[0]/1000 }; |
|
13
|
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
1535
|
use NetAddr::IP 4; |
|
|
1
|
|
|
|
|
30308
|
|
|
|
1
|
|
|
|
|
7
|
|
|
15
|
1
|
|
|
1
|
|
113
|
use Net::Radius::Server::Base qw/:match/; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
14
|
|
|
16
|
1
|
|
|
1
|
|
33
|
use base qw/Net::Radius::Server::Match/; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
112
|
|
|
17
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/addr attr code peer_addr peer_port port/); |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub _match_addr |
|
20
|
|
|
|
|
|
|
{ |
|
21
|
|
|
|
|
|
|
my $self = shift; |
|
22
|
|
|
|
|
|
|
my $peer = shift; |
|
23
|
|
|
|
|
|
|
my $mpeer = shift; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
if (ref($mpeer) eq 'Regexp') |
|
26
|
|
|
|
|
|
|
{ |
|
27
|
|
|
|
|
|
|
if ($peer =~ m/$mpeer/) |
|
28
|
|
|
|
|
|
|
{ |
|
29
|
|
|
|
|
|
|
$self->log(4, "_match_addr ok: $mpeer matches $peer"); |
|
30
|
|
|
|
|
|
|
return NRS_MATCH_OK; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
elsif (ref($mpeer) eq 'NetAddr::IP') |
|
34
|
|
|
|
|
|
|
{ |
|
35
|
|
|
|
|
|
|
my $pip = NetAddr::IP->new($peer); |
|
36
|
|
|
|
|
|
|
if (!$pip) |
|
37
|
|
|
|
|
|
|
{ |
|
38
|
|
|
|
|
|
|
$self->log |
|
39
|
|
|
|
|
|
|
(4, |
|
40
|
|
|
|
|
|
|
"_match_addr fails: Cannot convert $peer to a NetAddr::IP"); |
|
41
|
|
|
|
|
|
|
return NRS_MATCH_FAIL; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
if ($mpeer->contains($pip)) |
|
45
|
|
|
|
|
|
|
{ |
|
46
|
|
|
|
|
|
|
$self->log(4, "_match_addr ok: $mpeer contains $pip"); |
|
47
|
|
|
|
|
|
|
return NRS_MATCH_OK; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
elsif ($peer eq $mpeer) |
|
51
|
|
|
|
|
|
|
{ |
|
52
|
|
|
|
|
|
|
$self->log(4, "_match_addr ok: $mpeer eq $peer"); |
|
53
|
|
|
|
|
|
|
return NRS_MATCH_OK; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
$self->log(3, "_match_addr fails: Don't know how to handle '$mpeer'"); |
|
57
|
|
|
|
|
|
|
return NRS_MATCH_FAIL; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _match_port |
|
61
|
|
|
|
|
|
|
{ |
|
62
|
|
|
|
|
|
|
my $self = shift; |
|
63
|
|
|
|
|
|
|
my $port = shift; |
|
64
|
|
|
|
|
|
|
my $mport = shift; |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
if (ref($mport) eq 'Regexp') |
|
67
|
|
|
|
|
|
|
{ |
|
68
|
|
|
|
|
|
|
if ($port =~ m/$mport/) |
|
69
|
|
|
|
|
|
|
{ |
|
70
|
|
|
|
|
|
|
$self->log(4, "_match_port ok: $mport matches $port"); |
|
71
|
|
|
|
|
|
|
return NRS_MATCH_OK; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
else |
|
75
|
|
|
|
|
|
|
{ |
|
76
|
|
|
|
|
|
|
if ($port == $mport) |
|
77
|
|
|
|
|
|
|
{ |
|
78
|
|
|
|
|
|
|
$self->log(4, "_match_port ok: $mport == $port"); |
|
79
|
|
|
|
|
|
|
return NRS_MATCH_OK; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
$self->log(3, "_match_port fails: Don't know how to handle '$mport'"); |
|
84
|
|
|
|
|
|
|
return NRS_MATCH_FAIL; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub match_peer_addr |
|
88
|
|
|
|
|
|
|
{ |
|
89
|
|
|
|
|
|
|
my $self = shift; |
|
90
|
|
|
|
|
|
|
my $peer = $_[0]->{peer_addr}; |
|
91
|
|
|
|
|
|
|
my $mpeer = $self->peer_addr; |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
$self->log(4, "Invoked match_peer_addr"); |
|
94
|
|
|
|
|
|
|
return $self->_match_addr($peer, $mpeer); |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub match_addr |
|
98
|
|
|
|
|
|
|
{ |
|
99
|
|
|
|
|
|
|
my $self = shift; |
|
100
|
|
|
|
|
|
|
my $peer = $_[0]->{addr}; |
|
101
|
|
|
|
|
|
|
my $mpeer = $self->addr; |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
$self->log(4, "Invoked match_addr"); |
|
104
|
|
|
|
|
|
|
return $self->_match_addr($peer, $mpeer); |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub match_port |
|
108
|
|
|
|
|
|
|
{ |
|
109
|
|
|
|
|
|
|
my $self = shift; |
|
110
|
|
|
|
|
|
|
my $port = $_[0]->{port}; |
|
111
|
|
|
|
|
|
|
my $mport = $self->port; |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
$self->log(4, "Invoked match_port"); |
|
114
|
|
|
|
|
|
|
return $self->_match_port($port, $mport); |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub match_peer_port |
|
118
|
|
|
|
|
|
|
{ |
|
119
|
|
|
|
|
|
|
my $self = shift; |
|
120
|
|
|
|
|
|
|
my $port = $_[0]->{peer_port}; |
|
121
|
|
|
|
|
|
|
my $mport = $self->peer_port; |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
$self->log(4, "Invoked match_peer_port"); |
|
124
|
|
|
|
|
|
|
return $self->_match_port($port, $mport); |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub match_attr |
|
128
|
|
|
|
|
|
|
{ |
|
129
|
|
|
|
|
|
|
my $self = shift; |
|
130
|
|
|
|
|
|
|
my $req = $_[0]->{request}; |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
my %conds = @{$self->attr}; |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
while (my ($a, $v) = each %conds) |
|
135
|
|
|
|
|
|
|
{ |
|
136
|
|
|
|
|
|
|
my $V = $req->attr($a); |
|
137
|
|
|
|
|
|
|
$self->log(4, "match_attr: ($a, $v, " . ($V || 'undef value') . ")"); |
|
138
|
|
|
|
|
|
|
if (defined $V) |
|
139
|
|
|
|
|
|
|
{ |
|
140
|
|
|
|
|
|
|
if (ref($v) eq 'Regexp') |
|
141
|
|
|
|
|
|
|
{ |
|
142
|
|
|
|
|
|
|
if ($V =~ m/$v/) |
|
143
|
|
|
|
|
|
|
{ |
|
144
|
|
|
|
|
|
|
$self->log(4, "match_attr: Regexp $v matches $V ($a)"); |
|
145
|
|
|
|
|
|
|
next; |
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
} |
|
148
|
|
|
|
|
|
|
elsif (ref($v) eq 'NetAddr::IP') |
|
149
|
|
|
|
|
|
|
{ |
|
150
|
|
|
|
|
|
|
my $ip = NetAddr::IP->new($V); |
|
151
|
|
|
|
|
|
|
if ($ip and $v->contains($ip)) |
|
152
|
|
|
|
|
|
|
{ |
|
153
|
|
|
|
|
|
|
$self->log(4, "match_attr: $v contains $ip ($a)"); |
|
154
|
|
|
|
|
|
|
next; |
|
155
|
|
|
|
|
|
|
} |
|
156
|
|
|
|
|
|
|
} |
|
157
|
|
|
|
|
|
|
else |
|
158
|
|
|
|
|
|
|
{ |
|
159
|
|
|
|
|
|
|
if ($V eq $v) |
|
160
|
|
|
|
|
|
|
{ |
|
161
|
|
|
|
|
|
|
$self->log(4, "match_attr: $V eq $v ($a)"); |
|
162
|
|
|
|
|
|
|
next; |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
} |
|
165
|
|
|
|
|
|
|
} |
|
166
|
|
|
|
|
|
|
$self->log(3, "match_attr: No match - Return FAIL"); |
|
167
|
|
|
|
|
|
|
return NRS_MATCH_FAIL; |
|
168
|
|
|
|
|
|
|
} |
|
169
|
|
|
|
|
|
|
$self->log(4, "match_attr: Default - Return OK"); |
|
170
|
|
|
|
|
|
|
return NRS_MATCH_OK; |
|
171
|
|
|
|
|
|
|
} |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub match_code |
|
174
|
|
|
|
|
|
|
{ |
|
175
|
|
|
|
|
|
|
my $self = shift; |
|
176
|
|
|
|
|
|
|
my $req = $_[0]->{request}; |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
if (ref($self->code) eq 'Regexp') |
|
179
|
|
|
|
|
|
|
{ |
|
180
|
|
|
|
|
|
|
my $re = $self->code; |
|
181
|
|
|
|
|
|
|
if ($req->code =~ m/$re/) |
|
182
|
|
|
|
|
|
|
{ |
|
183
|
|
|
|
|
|
|
$self->log(4, "match_code: match: $re did not match " |
|
184
|
|
|
|
|
|
|
. $req->code); |
|
185
|
|
|
|
|
|
|
return NRS_MATCH_OK; |
|
186
|
|
|
|
|
|
|
} |
|
187
|
|
|
|
|
|
|
} |
|
188
|
|
|
|
|
|
|
else |
|
189
|
|
|
|
|
|
|
{ |
|
190
|
|
|
|
|
|
|
if ($req->code eq $self->code) |
|
191
|
|
|
|
|
|
|
{ |
|
192
|
|
|
|
|
|
|
$self->log(4, "match_code: match: " |
|
193
|
|
|
|
|
|
|
. $self->code . " eq " |
|
194
|
|
|
|
|
|
|
. $req->code); |
|
195
|
|
|
|
|
|
|
return NRS_MATCH_OK; |
|
196
|
|
|
|
|
|
|
} |
|
197
|
|
|
|
|
|
|
} |
|
198
|
|
|
|
|
|
|
$self->log(3, "match_code: fail by default"); |
|
199
|
|
|
|
|
|
|
return NRS_MATCH_FAIL; |
|
200
|
|
|
|
|
|
|
} |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
# Preloaded methods go here. |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
42; |
|
205
|
|
|
|
|
|
|
__END__ |