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

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