IRC/Plugin/Auth.pm

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