blib/lib/POE/Component/Server/IRC/Plugin/Auth.pm

filter: Statementstmt 53.2% 73 / 137 Branchbran 18.4% 7 / 38 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 72.7% 16 / 22 Podpod 0.0% 0 / 10 totaltotal 46.0% 98 / 213 CC 24 SCAR 30.3
CC
24
Cov
46%
got_hostname
72.0
got_ip
42.0
got_ident
12.0
CRAP 20.6
« blib/lib/POE/Component/Server/IRC.pm ↑ Summary blib/lib/POE/Component/Server/IRC/Plugin/OperServ.pm »
1 package POE::Component::Server::IRC::Plugin::Auth;
2 2 our $AUTHORITY = 'cpan:BINGOS';
3 2 $POE::Component::Server::IRC::Plugin::Auth::VERSION = '1.62';
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use POE;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use POE::Component::Client::Ident::Agent;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use POE::Component::Client::DNS;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use POE::Component::Server::IRC::Plugin 'PCSI_EAT_NONE';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Net::IP::Minimal qw[ip_is_ipv6];
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 sub new {
14 1 ▶ my ($package, %args) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
15 1 return bless \%args, $package;
16 }
17  
18 sub PCSI_register {
19 1 ▶ my ($self, $ircd) = splice @_, 0, 2;
Subroutine PCSI_register: called CC=1 SCAR=0.0
Pod undocumented
20  
21 1 $self->{ircd} = $ircd;
22  
23 1 POE::Session->create(
24 object_states => [
25 $self => [qw(
26 _start
27 resolve_hostname
28 resolve_ident
29 got_hostname
30 got_ip
31 )],
32 $self => {
33 ident_agent_reply => 'got_ident',
34 ident_agent_error => 'got_ident_error',
35 }
36 ],
37 );
38  
39 1 $ircd->plugin_register($self, 'SERVER', qw(connection));
40 1 return 1;
41 }
42  
43 sub PCSI_unregister {
44 1 ▶ my ($self, $ircd) = splice @_, 0, 2;
Subroutine PCSI_unregister: called CC=2 SCAR=7.1
Pod undocumented
45 1 ▶ $self->{resolver}->shutdown() if $self->{resolver};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"resolver"} 1 0 1
46 1 return 1;
47 }
48  
49 sub _start {
50 1 ▶ my ($self, $session) = @_[OBJECT, SESSION];
Subroutine _start: called CC=1 SCAR=0.0
51 1 $self->{session_id} = $session->ID;
52  
53 1 $self->{resolver} = POE::Component::Client::DNS->spawn(
54 Timeout => 10,
55 );
56 1 return;
57 }
58  
59 sub IRCD_connection {
60 1 ▶ my ($self, $ircd) = splice @_, 0, 2;
Subroutine IRCD_connection: called CC=4 SCAR=14.1
Pod undocumented
61 1 my $server = $ircd->server_name();
62 1 pop @_;
63 my ($conn_id, $peeraddr, $peerport, $sockaddr, $sockport, $needs_auth)
64 1 = map { $$_ } @_;
65  
66 1 ▶ return PCSI_EAT_NONE if !$needs_auth;
Branch: 1 branch
BranchTrueFalseTotal
unless $needs_auth 0 1 1
67 1 ▶ return PCSI_EAT_NONE if !$ircd->connection_exists($conn_id);
Branch: 1 branch
BranchTrueFalseTotal
unless $ircd->connection_exists($conn_id) 0 1 1
68  
69 1 $self->{conns}{$conn_id} = {
70 hostname => '',
71 ident => '',
72 done => 0,
73 };
74  
75 1 $ircd->send_output(
76 {
77 prefix => $server,
78 command => 'NOTICE',
79 params => ['*', '*** Checking Ident'],
80 },
81 $conn_id,
82 );
83  
84 1 $ircd->send_output(
85 {
86 prefix => $server,
87 command => 'NOTICE',
88 params => ['*', '*** Checking Hostname'],
89 },
90 $conn_id,
91 );
92  
93 1 ▶ if ($peeraddr =~ /^127\./) {
Branch: 1 branch
BranchTrueFalseTotal
if ($peeraddr =~ /^127\./) { } 1 0 1
94 1 $ircd->send_output(
95 {
96 prefix => $server,
97 command => 'NOTICE',
98 params => ['*', '*** Found your hostname']
99 },
100 $conn_id,
101 );
102 1 $self->{conns}{$conn_id}{hostname} = 'localhost';
103 1 $self->_auth_done($conn_id);
104 }
105 else {
106 $poe_kernel->call(
107 0 $self->{session_id}, 'resolve_hostname',
108 $conn_id, $peeraddr,
109 );
110 }
111  
112 $poe_kernel->call(
113 1 $self->{session_id}, 'resolve_ident',
114 $conn_id, $peeraddr, $peerport, $sockaddr, $sockport,
115 );
116  
117 1 return PCSI_EAT_NONE;
118 }
119  
120 sub resolve_hostname {
121 0 ▶ my ($self, $conn_id, $peeraddr) = @_[OBJECT, ARG0, ARG1];
Subroutine resolve_hostname: not called CC=2 SCAR=17.9
Pod undocumented
122  
123 my $response = $self->{resolver}->resolve(
124 0 event => 'got_hostname',
125 host => $peeraddr,
126 type => 'PTR',
127 context => {
128 conn_id => $conn_id,
129 peeraddr => $peeraddr,
130 },
131 );
132  
133 0 ▶ $poe_kernel->call('got_hostname', $response) if $response;
Branch: 1 branch
BranchTrueFalseTotal
if $response 0 0 0
134 0 return;
135 }
136  
137 sub resolve_ident {
138 1 ▶ my ($kernel, $self, $conn_id, $peeraddr, $peerport, $sockaddr, $sockport)
Subroutine resolve_ident: called CC=3 SCAR=11.7
Pod undocumented
139 = @_[KERNEL, OBJECT, ARG0..$#_];
140  
141 POE::Component::Client::Ident::Agent->spawn(
142 PeerAddr => $peeraddr,
143 PeerPort => $peerport,
144 SockAddr => $sockaddr,
145 SockPort => $sockport,
146 BuggyIdentd => 1,
147 TimeOut => ( $self->{ircd}{config}{ident_timeout} || 10 ),
148 Reference => $conn_id,
149 1 ▶ IdentPort => ( $self->{identport} || '' ),
Condition50%2/4
$self->{'ircd'}{'config'}{'ident_timeout'} || 10
l!l
01
$self->{'identport'} || ''
l!l
01
MC/DC0%0/1
$self->{'ircd'}{'config'}{'ident_timeout'} || 10
$self->{'ircd'}{'config'}{'ident_timeout'}
MC/DC0%0/1
$self->{'identport'} || ''
$self->{'identport'}
Truth table50%1/2
A
A= $self->{'ircd'}{'config'}{'ident_timeout'}
Aresult
11
00
Truth table50%1/2
A
A= $self->{'identport'}
Aresult
11
00
150 );
151 1 return;
152 }
153  
154 sub got_hostname {
155 0 ▶ my ($kernel, $self, $response) = @_[KERNEL, OBJECT, ARG0];
Subroutine got_hostname: not called CC=8 SCAR=42.8
Pod undocumented
156 0 my $conn_id = $response->{context}{conn_id};
157 0 my $peer_ip = $response->{context}{peeraddr};
158 0 my $ircd = $self->{ircd};
159  
160 0 ▶ if (!$ircd->connection_exists($conn_id)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ircd->connection_exists($conn_id)) 0 0 0
161 0 delete $self->{conns}{$conn_id};
162 0 return;
163 }
164  
165 my $fail = sub {
166 $ircd->send_output(
167 {
168 0 ▶ prefix => $self->{ircd}->server_name(),
Subroutine __ANON__: not called CC=1 SCAR=6.9
169 command => 'NOTICE',
170 params => [
171 '*',
172 "*** Couldn\'t look up your hostname",
173 ],
174 },
175 $conn_id,
176 );
177  
178 0 $self->_auth_done($conn_id);
179 0 };
180  
181 0 ▶ return $fail->() if !defined $response->{response};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $response->{"response"} 0 0 0
182 0 my @answers = $response->{response}->answer();
183 0 ▶ return $fail->() if !@answers;
Branch: 1 branch
BranchTrueFalseTotal
unless @answers 0 0 0
184  
185 0 for my $answer (@answers) {
186 0 my $context = $response->{context};
187 0 $context->{hostname} = $answer->rdatastr();
188  
189 0 ▶ chop $context->{hostname} if $context->{hostname} =~ /\.$/;
Branch: 1 branch
BranchTrueFalseTotal
if $context->{"hostname"} =~ /\.$/ 0 0 0
190 my $query = $self->{resolver}->resolve(
191 0 ▶ event => 'got_ip',
Branch: 1 branch
BranchTrueFalseTotal
ip_is_ipv6($peer_ip) ? : 0 0 0
192 host => $answer->rdatastr(),
193 context => $context,
194 type => ( ip_is_ipv6( $peer_ip ) ? 'AAAA' : 'A' ),
195 );
196 0 ▶ if (defined $query) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $query) 0 0 0
197 0 $kernel->call($self->{session_id}, 'got_ip', $query);
198 }
199 }
200  
201 0 return;
202 }
203  
204 sub got_ip {
205 0 ▶ my ($kernel, $self, $response) = @_[KERNEL, OBJECT, ARG0];
Subroutine got_ip: not called CC=6 SCAR=37.4
Pod undocumented
206 0 my $conn_id = $response->{context}{conn_id};
207 0 my $ircd = $self->{ircd};
208 0 my $server = $ircd->server_name();
209  
210 0 ▶ if (!$ircd->connection_exists($conn_id)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ircd->connection_exists($conn_id)) 0 0 0
211 0 delete $self->{conns}{$conn_id};
212 0 return;
213 }
214  
215 my $fail = sub {
216 0 ▶ $ircd->send_output(
Subroutine __ANON__: not called CC=1 SCAR=6.9
217 {
218 prefix => $server,
219 command => 'NOTICE',
220 params => [
221 '*',
222 "*** Couldn't look up your hostname",
223 ],
224 },
225 $conn_id,
226 );
227 0 $self->_auth_done($conn_id);
228 0 };
229  
230 0 ▶ return $fail->() if !defined $response->{response};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $response->{"response"} 0 0 0
231 0 my @answers = $response->{response}->answer();
232 0 ▶ return $fail->() if !@answers;
Branch: 1 branch
BranchTrueFalseTotal
unless @answers 0 0 0
233  
234 0 my $peeraddr = $response->{context}{peeraddr};
235 0 my $hostname = $response->{context}{hostname};
236 0 for my $answer (@answers) {
237 0 ▶ if ($answer->rdatastr() eq $peeraddr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($answer->rdatastr eq $peeraddr) 0 0 0
238 0 $ircd->send_output(
239 {
240 prefix => $server,
241 command => 'NOTICE',
242 params => ['*', '*** Found your hostname'],
243 },
244 $conn_id,
245 );
246 0 $self->{conns}{$conn_id}{hostname} = $hostname;
247 0 $self->_auth_done($conn_id);
248 0 return;
249 }
250 }
251  
252 $ircd->send_output(
253 {
254 0 prefix => $server,
255 command => 'NOTICE',
256 params => [
257 '*',
258 '*** Your forward and reverse DNS do not match',
259 ],
260 },
261 $conn_id,
262 );
263 0 $self->_auth_done($conn_id);
264 0 return;
265 }
266  
267 sub _auth_done {
268 2 ▶ my ($self, $conn_id) = @_;
Subroutine _auth_done: called CC=2 SCAR=6.9
269  
270 2 $self->{conns}{$conn_id}{done}++;
271 2 ▶ return if $self->{conns}{$conn_id}{done} != 2;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"conns"}{$conn_id}{"done"} != 2 1 1 2
272  
273 1 my $auth = delete $self->{conns}{$conn_id};
274 $self->{ircd}->send_event(
275 'auth_done',
276 $conn_id,
277 {
278 ident => $auth->{ident},
279 hostname => $auth->{hostname},
280 },
281 1 );
282 1 return;
283 }
284  
285 sub got_ident_error {
286 1 ▶ my ($kernel, $self, $ref, $error) = @_[KERNEL, OBJECT, ARG0, ARG1];
Subroutine got_ident_error: called CC=2 SCAR=7.3
Pod undocumented
287 1 my $conn_id = $ref->{Reference};
288 1 my $ircd = $self->{ircd};
289  
290 1 ▶ if (!$ircd->connection_exists($conn_id)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ircd->connection_exists($conn_id)) 0 1 1
291 0 delete $self->{conns}{$conn_id};
292 0 return;
293 }
294  
295 $ircd->send_output(
296 {
297 1 prefix => $ircd->server_name(),
298 command => 'NOTICE',
299 params => ['*', "*** No Ident response"],
300 },
301 $conn_id,
302 );
303 1 $self->_auth_done($conn_id);
304 1 return;
305 }
306  
307 sub got_ident {
308 0 ▶ my ($kernel, $self, $ref, $opsys, $other)
Subroutine got_ident: not called CC=3 SCAR=24.8
Pod undocumented
309 = @_[KERNEL, OBJECT, ARG0, ARG1, ARG2];
310 0 my $conn_id = $ref->{Reference};
311 0 my $ircd = $self->{ircd};
312  
313 0 ▶ if (!$ircd->connection_exists($conn_id)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ircd->connection_exists($conn_id)) 0 0 0
314 0 delete $self->{conns}{$conn_id};
315 0 return;
316 }
317  
318 0 my $ident = '';
319 0 ▶ $ident = $other if uc $opsys ne 'OTHER';
Branch: 1 branch
BranchTrueFalseTotal
if uc $opsys ne "OTHER" 0 0 0
320 0 $ircd->send_output(
321 {
322 prefix => $ircd->server_name(),
323 command => 'NOTICE',
324 params => ['*', "*** Got Ident response"],
325 },
326 $conn_id,
327 );
328 0 $self->{conns}{$conn_id}{ident} = $ident;
329 0 $self->_auth_done($conn_id);
330 0 return;
331 }
332  
333 2 1;
334  
335 =encoding utf8
336  
337 =head1 NAME
338  
339 POE::Component::Server::IRC::Plugin::Auth - Authentication subsystem of POE::Component::Server::IRC::Backend
340  
341 =head1 DESCRIPTION
342  
343 This module is used internally by
344 L<POE::Component::Server::IRC::Backend|POE::Component::Server::IRC::Backend>.
345 No need for you to use it.
346  
347 =head1 AUTHOR
348  
349 Hinrik E<Ouml>rn SigurE<eth>sson <hinrik.sig@gmail.com>
350  
351 Chris 'BinGOs' Williams
352  
353 =cut
« blib/lib/POE/Component/Server/IRC.pm ↑ Summary blib/lib/POE/Component/Server/IRC/Plugin/OperServ.pm »