Authentication/Net/Milter.pm

filter: Statementstmt 73.2% 307 / 419 Branchbran 58.5% 137 / 234 Conditioncond 38.8% 7 / 18 MC/DCmcdc 16.6% 2 / 12 Subroutinesub 100% 31 / 31 Podpod 100% 14 / 14 totaltotal 68.4% 498 / 728 CC 125 SCAR 34.0
CC
125
Cov
67%
send_macros
70.6
_translate_response
53.1
protocol_negotiation
37.8
CRAP 30.1
« Authentication/Config.pm ↑ Summary Authentication/App/ProcessLog/App/Command/arex.pm »
1 package Mail::Milter::Authentication::Net::Milter;
2 ## no critic
3 114 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 114 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 114 ▶use vars qw($DEBUG);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 # ABSTRACT: Local modified copy of Net::Milter
7 114 our $VERSION = '4.20261116'; # VERSION
8 114 $DEBUG=0;
9  
10 114 ▶use constant PROTOCOL_NEGATION => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 ############
13 sub new
14 41 ▶{
Subroutine new: called CC=2 SCAR=7.1
Pod documented
15 # create new blank class
16 41 my $proto = shift;
17 41 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
0410
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
18 41 my $self= {};
19  
20 # define the various negotiation options
21 # we'll put them here and not touch them so we can loop through and do bit wise checks later
22 41 $self->{action_types} = ['SMFIF_ADDHDRS', 'SMFIF_CHGBODY', 'SMFIF_ADDRCPT', 'SMFIF_DELRCPT', 'SMFIF_CHGHDRS', 'SMFIF_QUARANTINE'];
23 41 $self->{content_types} = ['SMFIP_NOCONNECT', 'SMFIP_NOHELO', 'SMFIP_NOMAIL', 'SMFIP_NORCPT', 'SMFIP_NOBODY', 'SMFIP_NOHDRS', 'SMFIP_NOEOH'];
24  
25 41 bless($self,$class);
26 41 return $self;
27 } # end sub new
28 ############
29  
30 ############
31 33 ▶sub open {
Subroutine open: called CC=11 SCAR=30.5
Pod documented
32 # open the socket
33 114 ▶ use IO::Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 33 my $self = shift;
36 33 my ($addr,$port,$proto) = @_;
37  
38 0 ▶ if ($DEBUG==1) {print STDERR "open\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 33 33
39  
40 33 my $sock;
41  
42 33 ▶ if (lc($proto) eq 'tcp' || lc($proto) eq 'inet') {
Branch: 2 branches
BranchTrueFalseTotal
if (lc $proto eq 'tcp' or lc $proto eq 'inet') { } 0 33 33
elsif (lc $proto eq 'unix' or lc $proto eq 'local') { } 33 0 33
Condition33%1/3
lc $proto eq "tcp" or lc $proto eq "inet"
l!l&&r!l&&!r
0033
MC/DC0%0/2
lc $proto eq "tcp" or lc $proto eq "inet"
lc $proto eq "tcp" lc $proto eq "inet"
Truth table33%1/3
A or B
A= lc $proto eq "tcp"B= lc $proto eq "inet"
ABresult
1X1
011
000
43 0 ▶ if ($DEBUG==1) {print STDERR "\topen tcp socket\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 0 0
44 114 ▶ use IO::Socket::INET;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 0 ▶ $sock = new IO::Socket::INET (PeerAddr => $addr,
Branch: 1 branch
BranchTrueFalseTotal
$sock = "IO::Socket::INET"->new("PeerAddr", $addr, "PeerPort", $port, "Proto", "tcp", "Type", 1, "Timeout", 10) or carp("Couldn't connect to ${addr}:$port : $@\n") 0 0 0
46 PeerPort => $port,
47 Proto => 'tcp',
48 Type => SOCK_STREAM,
49 Timeout => 10,
50 ) or carp "Couldn't connect to $addr:$port : $@\n";
51 } # end if tcp
52 ▶ elsif (lc($proto) eq 'unix' || lc($proto) eq 'local') {
Condition33%1/3
lc $proto eq "unix" or lc $proto eq "local"
l!l&&r!l&&!r
3300
MC/DC0%0/2
lc $proto eq "unix" or lc $proto eq "local"
lc $proto eq "unix" lc $proto eq "local"
Truth table33%1/3
A or B
A= lc $proto eq "unix"B= lc $proto eq "local"
ABresult
1X1
011
000
53 0 ▶ if ($DEBUG==1) {print STDERR "\topen unix socket\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 33 33
54 114 ▶ use IO::Socket::UNIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
55 33 ▶ $sock = new IO::Socket::UNIX (Peer => $addr,
Branch: 1 branch
BranchTrueFalseTotal
$sock = "IO::Socket::UNIX"->new("Peer", $addr, "Type", 1, "Timeout", $port) or carp("Couldn't connect to unix socket on $addr : $@\n") 33 0 33
56 Type => SOCK_STREAM,
57 Timeout => $port
58 ) or carp "Couldn't connect to unix socket on $addr : $@\n";
59 } # end if unix
60 0 else {carp "$proto is unknown to me\n";}
61  
62 0 ▶ if (!defined($sock)) {return 0;}
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $sock) { } 0 33 33
63 else {
64 33 $self->{socket} = $sock;
65 33 return 1;
66 }
67  
68 } # end sub open
69 ############
70  
71 ############
72 33 ▶sub protocol_negotiation {
Subroutine protocol_negotiation: called CC=21 SCAR=36.3
Pod documented
73 # negotiate with the filter as to what options to use
74 33 my $self = shift;
75  
76 33 my (%options) = @_;
77  
78 0 ▶ if ($DEBUG==1) {print STDERR "protocol_negotiation\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 33 33
79  
80 # set up the bit mask of allowed actions
81 33 my (@action_types) = @{$self->{action_types}};
82 33 my (@content_types) = @{$self->{content_types}};
83  
84 33 my ($count,$action,$content);
85  
86 0 ▶ if ($DEBUG==1) {print STDERR "\tsetting bits\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 33 33
87  
88 33 my $action_field = 0;
89  
90 33 $count=0;
91 33 ▶ while ($action = shift(@action_types)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($action = shift @action_types) 198 33 231
92 198 ▶ if (defined($options{$action}) && $options{$action}==0) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options{$action} and $options{$action} == 0) { } 99 99 198
Condition100%3/3
defined $options{$action} and $options{$action} == 0
!ll&&!rl&&r
336699
MC/DC100%2/2
defined $options{$action} and $options{$action} == 0
defined $options{$action} $options{$action} == 0
Truth table100%3/3
A and B
A= defined $options{$action}B= $options{$action} == 0
ABresult
0X0
100
111
93 # do nothing
94 }
95 else {
96 99 $action_field = $action_field | (2**$count);
97 }
98  
99 198 $count++;
100 } # end while
101  
102  
103 # set up the bit mask for possible protocols
104 33 my $protocol_field = 0;
105  
106 33 $count=0;
107 33 ▶ while ($content = shift(@content_types)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content = shift @content_types) 231 33 264
108 231 ▶ if (defined($options{$content}) && $options{$content}==1) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options{$content} and $options{$content} == 1) { } 0 231 231
Condition33%1/3
defined $options{$content} and $options{$content} == 1
!ll&&!rl&&r
02310
MC/DC0%0/2
defined $options{$content} and $options{$content} == 1
defined $options{$content} $options{$content} == 1
Truth table33%1/3
A and B
A= defined $options{$content}B= $options{$content} == 1
ABresult
0X0
100
111
109 0 $protocol_field = $protocol_field | 2**$count;
110 }
111 else {
112 # do nothing
113 }
114  
115 231 $count++;
116 } # end while
117  
118 ### hmmm this bit might not be right on 64 bit architecture
119 # we want a 32 bit unsigned integer in network order
120 33 my $smfi_version = 2; # version of protocol
121 33 my $length = 13;
122  
123 0 ▶ if ($DEBUG==1) {print STDERR "\tpacking\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 33 33
124  
125 33 $action_field = $self->_pack_number($action_field);
126 33 $protocol_field = $self->_pack_number($protocol_field);
127 33 if (PROTOCOL_NEGATION == 1) {$protocol_field = ~$protocol_field;}
128 33 $smfi_version = $self->_pack_number($smfi_version);
129 33 $length = $self->_pack_number($length);
130  
131 0 ▶ if ($DEBUG==1) {print STDERR "\tsendsubing\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 33 33
132  
133 33 $self->{socket}->send($length);
134 33 $self->{socket}->send('O');
135 33 $self->{socket}->send($smfi_version);
136 33 $self->{socket}->send($action_field);
137 33 $self->{socket}->send($protocol_field);
138  
139 0 ▶ if ($DEBUG==1) {print STDERR "\treceiving\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 33 33
140  
141 33 my ($command,$data)=$self->_receive();
142  
143 0 ▶ if ($command ne 'O') {carp "error in protocol negotiation \n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($command ne "O") 0 33 33
144  
145 33 my($ret_version,$ret_actions,$ret_protocol)=unpack "NNN",$data;
146  
147 0 ▶ if ($DEBUG==1) {print STDERR "\treturned version : $ret_version\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 33 33
148 0 ▶ if ($DEBUG==1) {printf STDERR "\treturned actions : %8b\n", $ret_actions;}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 33 33
149 0 ▶ if ($DEBUG==1) {printf STDERR "\treturned protocol : %7b\n", $ret_protocol;}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 33 33
150  
151 # translate returned bit mask into fields
152 0 ▶ if ($DEBUG==1) {print STDERR "\ttranslating bit mask\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 33 33
153  
154 33 my (@returned_actions, @returned_protocol);
155  
156 33 $count=0;
157 33 ▶ while ($action = shift(@action_types)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($action = shift @action_types) 0 33 33
158 0 ▶ if ($ret_actions & 2**$count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret_actions & 2 ** $count) 0 0 0
159 0 push @returned_actions,$action;
160 }
161 0 $count++;
162 } # end while
163  
164 33 $count=0;
165 33 ▶ while ($content = shift(@content_types)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content = shift @content_types) 0 33 33
166 0 ▶ if ($ret_protocol & 2**$count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret_protocol & 2 ** $count) 0 0 0
167 0 push @returned_protocol,$content;
168 }
169 0 $count++;
170 } # end while
171  
172  
173  
174 33 return ($ret_version,\@returned_actions,\@returned_protocol);
175 } # end sub protocol_negotiation
176 ############
177  
178 ############
179 33 ▶sub send_abort {
Subroutine send_abort: called CC=2 SCAR=7.6
Pod documented
180 # send an abort command, SMFIC_ABORT
181 # no response expected
182 # but dont close the connection
183 0 ▶if ($DEBUG==1) {print STDERR "send_abort\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 33 33
184 33 my $self = shift;
185 33 $self->_send('A');
186  
187 } # end sub send_abort
188 ############
189  
190 ############
191 31 ▶sub send_body {
Subroutine send_body: called CC=5 SCAR=19.5
Pod documented
192 # send body chunk of message, SMFIC_BODY
193  
194 31 my $self = shift;
195 31 my $body = shift;
196 0 ▶ if ($DEBUG==1) {print STDERR "send_body\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 31 31
197 # restrict body size to max allowable
198  
199 0 ▶ if ($DEBUG==1) {print STDERR "\tsending".substr($body,0,5).'...'."\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 31 31
200  
201 31 ▶ if (length ($body)>65535) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $body > 65535) { } 0 31 31
202 0 warn "the message body is too big; its length must be less than 65536 bytes";
203 0 $self->_send('B',substr($body,0,65535));
204 0 $body = substr($body,65535);
205 }
206 else {
207 31 $self->_send('B',$body);
208 }
209  
210 0 ▶ if ($DEBUG==1) {print STDERR "\treceiving from body\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 31 31
211  
212 # get response
213 31 my (@replies)=$self->_retrieve_responses();
214 31 return(@replies);
215  
216 } # end sub send_body
217 ############
218  
219 ############
220 33 ▶sub send_end_body {
Subroutine send_end_body: called CC=3 SCAR=11.8
Pod documented
221 # send body chunk of message, SMFIC_BODY
222  
223 33 my $self = shift;
224 33 my $body = shift;
225 0 ▶ if ($DEBUG==1) {print STDERR "send end_body\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 33 33
226  
227 33 $self->_send('E');
228 0 ▶ if ($DEBUG==1) {print STDERR "\treceiving\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 33 33
229  
230 # get response
231 33 my (@replies)=$self->_retrieve_responses();
232 33 return(@replies);
233  
234 } # end sub send_end_body
235 ############
236  
237 ############
238 33 ▶sub send_connect {
Subroutine send_connect: called CC=6 SCAR=21.0
Pod documented
239 # send connect message, SMFIC_CONNECT
240  
241 33 my $self = shift;
242 33 my ($hostname,$family,$port,$ip_address) = @_;
243  
244 33 my ($protocol_family);
245  
246 33 $hostname .="\0";
247 33 $ip_address .="\0";
248  
249 0 ▶ if ($DEBUG==1) {print STDERR "send connect\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 33 33
250  
251 0 ▶ if (lc($family) eq 'unix') {$protocol_family='L';}
Branch: 3 branches
BranchTrueFalseTotal
if (lc $family eq 'unix') { } 0 33 33
elsif (lc $family eq 'tcp4') { } 33 0 33
elsif (lc $family eq 'tcp6') { } 0 0 0
252 33 elsif (lc($family) eq 'tcp4') {$protocol_family='4';}
253 0 elsif (lc($family) eq 'tcp6') {$protocol_family='6';}
254 0 else {$protocol_family='U';}
255  
256 33 $port = pack "n",$port;
257  
258 0 ▶ if ($DEBUG==1) {print STDERR "\tsending\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 33 33
259  
260 33 $self->_send('C',$hostname,$protocol_family,$port,$ip_address);
261  
262 33 my (@replies)=$self->_retrieve_responses();
263 33 return (@replies);
264 } # end sub send_connect
265 ############
266  
267 ############
268 33 ▶sub send_helo {
Subroutine send_helo: called CC=3 SCAR=11.7
Pod documented
269 # send helo string, SMFIC_HELO
270 33 my $self=shift;
271 33 my $helo_string = shift;
272 0 ▶ if ($DEBUG==1) {print STDERR "send_helo\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 33 33
273  
274 33 $helo_string .="\0";
275 33 $self->_send('H',$helo_string);
276  
277 0 ▶ if ($DEBUG==1) {print STDERR "\treceiving\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 33 33
278  
279 33 my (@replies)=$self->_retrieve_responses();
280 33 return (@replies);
281 } # end sub send_helo
282 ############
283  
284 ############
285 399 ▶sub send_header {
Subroutine send_header: called CC=2 SCAR=7.0
Pod documented
286 # send a header name and value from message, SMFIC_HEADER
287  
288 399 my $self=shift;
289 399 my $header_name = shift;
290 399 my $header_value = shift;
291  
292 0 ▶ if ($DEBUG==1) {print STDERR "send_header\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 399 399
293  
294 399 $header_name.="\0";
295 399 $header_value.="\0";
296  
297 399 $self->_send('L',$header_name,$header_value);
298  
299 399 my (@replies)=$self->_retrieve_responses();
300 399 return (@replies);
301 } # end sub send_header
302 ############
303  
304 ############
305 33 ▶sub send_mail_from {
Subroutine send_mail_from: called CC=2 SCAR=7.1
Pod documented
306 # send MAIL FROM information from message, SMFIC_MAIL
307  
308 33 my $self=shift;
309 33 my $mail_from = shift;
310  
311 0 ▶ if ($DEBUG==1) {print STDERR "send_mail_from\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 33 33
312  
313 33 $mail_from.="\0";
314  
315 33 $self->_send('M',$mail_from);
316  
317 33 my (@replies)=$self->_retrieve_responses();
318 33 return (@replies);
319 } # end sub send_mail_from
320 ############
321  
322 ############
323 33 ▶sub send_end_headers {
Subroutine send_end_headers: called CC=2 SCAR=7.2
Pod documented
324 # send end of headers marker, SMFIC_EOH
325  
326 33 my $self=shift;
327  
328 0 ▶ if ($DEBUG==1) {print STDERR "send_end_headers\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 33 33
329  
330 33 $self->_send('N');
331  
332 33 my (@replies)=$self->_retrieve_responses();
333 33 return (@replies);
334 } # end sub send_end_headers
335 ############
336  
337 ############
338 33 ▶sub send_rcpt_to {
Subroutine send_rcpt_to: called CC=2 SCAR=7.1
Pod documented
339 # send RCPT TO information from message, SMFIC_RCPT
340  
341 33 my $self=shift;
342 33 my $rcpt_to = shift;
343  
344 0 ▶ if ($DEBUG==1) {print STDERR "send_rcpt_to\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 33 33
345  
346 33 $rcpt_to.="\0";
347  
348 33 $self->_send('R',$rcpt_to);
349  
350 33 my (@replies)=$self->_retrieve_responses();
351 33 return (@replies);
352 } # end sub send_rcpt_to
353 ############
354  
355 ############
356 33 ▶sub send_quit {
Subroutine send_quit: called CC=2 SCAR=7.4
Pod documented
357 # send a quit command, SMFIC_QUIT
358 # no response expected
359 # close the connection
360 33 my $self=shift;
361  
362 0 ▶ if ($DEBUG==1) {print STDERR "send_quit\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 33 33
363  
364 33 $self->_send('Q');
365  
366 33 $self->{socket}->close;
367  
368 } # end sub send_quit
369 ############
370  
371 ############
372 890 ▶sub _send {
Subroutine _send: called CC=6 SCAR=20.8
373 # concerned with the details of sending stuff
374  
375 890 my $self = shift;
376 890 my $command = shift;
377 890 my (@data) = @_;
378  
379 0 ▶ if ($DEBUG==1) {print STDERR "send\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 890 890
380  
381 890 my $data = join '',@data;
382 890 my $length = length($data);
383 890 $length += 1;
384  
385 890 ▶ if ($DEBUG==1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 890 890
386 0 print STDERR "sending - command : $command\tlength : $length";
387 0 ▶ if (length($data)<100) {print STDERR "\tdata : $data\n";}
Branch: 1 branch
BranchTrueFalseTotal
if (length $data < 100) { } 0 0 0
388 0 else {print STDERR "\n";}
389 }
390  
391 890 $length = $self->_pack_number($length);
392  
393 0 ▶ if (!defined($self->{socket})) {carp "can't connect no connection defined !\n";}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"socket"}) 0 890 890
394 890 $self->_io_send($length);
395 890 $self->_io_send($command);
396 890 ▶ $self->_io_send($data) if (length($data) > 0);
Branch: 1 branch
BranchTrueFalseTotal
if length $data > 0 758 132 890
397  
398  
399 } # end sub _send
400 ############
401  
402 ############
403 747 ▶sub _receive {
Subroutine _receive: called CC=4 SCAR=14.1
404 # concerned with the details of receiving stuff
405  
406 114 ▶ use IO::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
407  
408 747 my $self = shift;
409  
410 0 ▶ if ($DEBUG==1) {print STDERR "_receive\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 747 747
411  
412 747 my $length = $self->_io_recv(4);
413 747 my $command = $self->_io_recv(1);
414 747 $length = $self->_unpack_number($length);
415 0 ▶ if ($DEBUG==1) {print STDERR "\tcommand : $command\n\tlength : $length\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 747 747
416 747 $length -= 1;
417  
418 747 my $data;
419 747 ▶ if ($length > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 0) 120 627 747
420 120 $data = $self->_io_recv($length);
421 }
422  
423 746 return ($command,$data);
424 } # end sub _receive
425 ############
426  
427 ############
428 1022 ▶sub _pack_number {
Subroutine _pack_number: called CC=2 SCAR=7.2
429 # single place to pack numbers
430 1022 my $self = shift;
431 1022 my $number = shift;
432  
433 0 ▶ if ($DEBUG==1) {print STDERR "_pack_number\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 1022 1022
434  
435 1022 my $ret_number = pack "N",$number;
436  
437 1022 return ($ret_number);
438 } # end sub _pack_number
439 ############
440  
441 ############
442 823 ▶sub _unpack_number {
Subroutine _unpack_number: called CC=2 SCAR=7.2
443 # single place to unpack numbers
444 823 my $self = shift;
445 823 my $number = shift;
446  
447 0 ▶ if ($DEBUG==1) {print STDERR "_unpack_number\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 823 823
448  
449 823 my $ret_number = unpack "N",$number;
450  
451 823 return ($ret_number);
452 } # end sub _unpack_number
453 ############
454  
455 ############
456 713 ▶sub _translate_response {
Subroutine _translate_response: called CC=17 SCAR=39.7
457 # turn what we get from the filter into something more manageable
458  
459 713 my $self = shift;
460 713 my ($command,$data)=@_;
461  
462 713 ▶ if ($DEBUG==1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 713 713
463 0 print STDERR "_translate_response\n";
464 0 print STDERR "\tcommand : $command\n";
465 0 ▶ if (defined($data) && $command !~/[hm]/) {print STDERR "\tdata : $data\n";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data and not $command =~ /[hm]/) 0 0 0
Condition0%0/3
defined $data and not $command =~ /[hm]/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $data and not $command =~ /[hm]/
defined $data not $command =~ /[hm]/
Truth table0%0/3
A and not(B)
A= defined $dataB= not $command =~ /[hm]/
ABresult
0X0
100
111
466 }
467  
468 713 my %reply=();
469  
470 713 $reply{command}=$command;
471  
472 713 ▶ if ($command eq '+') {
Branch: 13 branches
BranchTrueFalseTotal
if ($command eq '+') { } 0 713 713
elsif ($command eq '-') { } 0 713 713
elsif ($command eq 'a') { } 0 713 713
elsif ($command eq 'b') { } 0 713 713
elsif ($command eq 'c') { } 627 86 713
elsif ($command eq 'd') { } 0 86 86
elsif ($command eq 'h') { } 9 77 86
elsif ($command eq 'i') { } 63 14 77
elsif ($command eq 'm') { } 13 1 14
elsif ($command eq 'p') { } 0 1 1
elsif ($command eq 'r') { } 0 1 1
elsif ($command eq 't') { } 0 1 1
elsif ($command eq 'y') { } 1 0 1
473 0 $reply{explanation}='Add a recipient';
474 0 $reply{header}='To';
475 0 $reply{action}='add';
476 0 $reply{value}=$data;
477 }
478  
479 elsif ($command eq '-') {
480 0 $reply{explanation}='Remove a recipient';
481 0 $reply{header}='To';
482 0 $reply{action}='delete';
483 0 $reply{value}=$data;
484 }
485  
486 elsif ($command eq 'a') {
487 0 $reply{explanation}='Accept message completely';
488 0 $reply{action}='accept';
489 }
490  
491 elsif ($command eq 'b') {
492 0 $reply{explanation}='Replace body chunk';
493 0 $reply{header}='body';
494 0 $reply{action}='replace';
495 0 $reply{value}=$data;
496 }
497  
498 elsif ($command eq 'c') {
499 627 $reply{explanation}='Accept and continue';
500 627 $reply{action}='continue';
501 }
502  
503 elsif ($command eq 'd') {
504 0 $reply{explanation}='Reject message completely';
505 0 $reply{action}='reject';
506 }
507  
508 elsif ($command eq 'h') {
509 9 $reply{explanation}='Add header';
510 9 ($reply{header},$reply{value},undef)=split(/\0/,$data);
511 9 $reply{action}='add';
512 }
513  
514 elsif ($command eq 'i') {
515 63 $reply{explanation}='Insert header';
516 63 $reply{index}=$self->_unpack_number(substr($data,0,4));
517 63 $data = substr($data,4);
518 63 ($reply{header},$reply{value},undef)=split(/\0/,$data);
519 63 $reply{action}='insert';
520 }
521  
522 elsif ($command eq 'm') {
523 13 $reply{explanation}='Replace body header';
524 13 $reply{index}=$self->_unpack_number(substr($data,0,4));
525 13 $data = substr($data,4);
526 13 ($reply{header},$reply{value},undef)=split(/\0/,$data);
527 13 $reply{action}='replace';
528 }
529  
530 elsif ($command eq 'p') {
531 0 $reply{explanation}='Progress';
532 0 $reply{action}='continue';
533 }
534  
535 elsif ($command eq 'r') {
536 0 $reply{explanation}='Reject command with 5xx error';
537 0 $reply{action}='reject';
538 0 $reply{value}=5;
539 }
540  
541 elsif ($command eq 't') {
542 0 $reply{explanation}='Reject command with 4xx error';
543 0 $reply{action}='reject';
544 0 $reply{value}=4;
545 }
546  
547 elsif ($command eq 'y') {
548 1 $reply{explanation}='Reject command with xxx error';
549 1 $reply{action}='reject';
550 1 $reply{value}=$data;
551 }
552  
553  
554 713 return (\%reply);
555 } # end sub _translate_response
556 ############
557  
558 ############
559 628 ▶sub _retrieve_responses {
Subroutine _retrieve_responses: called CC=10 SCAR=27.1
560  
561 628 my $self = shift;
562  
563 628 my (@replies,$command,$data,$reply_ref);
564  
565 0 ▶ if ($DEBUG==1) {print STDERR "_retrieve_response\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 628 628
566  
567 628 while () {
568 0 ▶ if ($DEBUG==1) {print STDERR "\twaiting for response\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 713 713
569 713 ($command,$data)=$self->_receive();
570 713 ($reply_ref)=$self->_translate_response($command,$data);
571  
572 713 push @replies,$reply_ref;
573  
574 0 ▶ if ($DEBUG==1) {print STDERR "\tcommand : $$reply_ref{command}";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 713 713
575 713 ▶ if ($$reply_ref{command} eq 'c') {last;}
Branch: 6 branches
BranchTrueFalseTotal
if ($reply_ref->{'command'} eq 'c') { } 627 86 713
elsif ($reply_ref->{'command'} eq 'a') { } 0 86 86
elsif ($reply_ref->{'command'} eq 'r') { } 0 86 86
elsif ($reply_ref->{'command'} eq 't') { } 0 86 86
elsif ($reply_ref->{'command'} eq 'y') { } 1 85 86
elsif ($reply_ref->{'command'} eq 'd') { } 0 85 85
576 0 elsif ($$reply_ref{command} eq 'a') {last;}
577 0 elsif ($$reply_ref{command} eq 'r') {last;}
578 0 elsif ($$reply_ref{command} eq 't') {last;}
579 1 elsif ($$reply_ref{command} eq 'y') {last;}
580 0 elsif ($$reply_ref{command} eq 'd') {last;}
581 } # end while
582  
583 628 return (@replies);
584 } # end sub retrieve_responses
585 ############
586  
587 ############
588 196 ▶sub send_macros {
Subroutine send_macros: called CC=33 SCAR=42.6
Pod documented
589 196 my $self=shift;
590 196 my %macros = @_;
591  
592 0 ▶ if ($DEBUG==1) {print STDERR "retrieve_response\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 196 196
593  
594 196 my (@data);
595  
596 196 ▶ if ($DEBUG==1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 196 196
597 0 foreach (keys(%macros)) {
598 0 print STDERR "\tmacro : $_ = $macros{$_}\n";
599 }
600 } # end if DEBUG
601  
602 196 ▶ if (defined($macros{j})) {push @data,'j'."\0".$macros{j}."\0";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $macros{"j"}) 33 163 196
603 0 ▶ if (defined($macros{_})) {push @data,'_'."\0",$macros{_}."\0";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $macros{"_"}) 0 196 196
604 0 ▶ if (defined($macros{'{daemon_name}'})) {push @data,'{daemon_name}'."\0".$macros{'{daemon_name}'}."\0";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $macros{"{daemon_name}"}) 0 196 196
605 0 ▶ if (defined($macros{'{if_name}'})) {push @data,'{if_name}'."\0".$macros{'{if_name}'}."\0";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $macros{"{if_name}"}) 0 196 196
606 0 ▶ if (defined($macros{'{if_addr}'})) {push @data,'{if_addr}'."\0".$macros{'{if_addr}'}."\0";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $macros{"{if_addr}"}) 0 196 196
607  
608 196 ▶ if (@data) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data) 33 163 196
609 0 ▶ if ($DEBUG==1) {print STDERR "\tsending D,C\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 33 33
610 33 $self->_send('D','C',@data);
611 }
612  
613 196 @data=();
614 0 ▶ if (defined($macros{'{tls_version}'})) {push @data,'{tls_version}'."\0".$macros{'{tls_version}'}."\0";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $macros{"{tls_version}"}) 0 196 196
615 0 ▶ if (defined($macros{'{cipher}'})) {push @data,'{cipher}'."\0".$macros{'{cipher}'}."\0";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $macros{"{cipher}"}) 0 196 196
616 0 ▶ if (defined($macros{'{cipher_bits}'})) {push @data,'{cipher_bits}'."\0".$macros{'{cipher_bits}'}."\0";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $macros{"{cipher_bits}"}) 0 196 196
617 0 ▶ if (defined($macros{'{cert_subject}'})) {push @data,'{cert_subject}'."\0".$macros{'{cert_subject}'}."\0";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $macros{"{cert_subject}"}) 0 196 196
618 0 ▶ if (defined($macros{'{cert_issuer}'})) {push @data,'{cert_issuer}'."\0".$macros{'{cert_issuer}'}."\0";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $macros{"{cert_issuer}"}) 0 196 196
619  
620 196 ▶ if (@data) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data) 0 196 196
621 0 ▶ if ($DEBUG==1) {print STDERR "\tsending D,H\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 0 0
622 0 $self->_send('D','H',@data);
623 }
624  
625  
626  
627 196 @data=();
628 196 ▶ if (defined($macros{i})) {push @data,'i'."\0".$macros{i}."\0";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $macros{"i"}) 97 99 196
629 0 ▶ if (defined($macros{'{auth_type}'})) {push @data,'{auth_type}'."\0".$macros{'{auth_type}'}."\0";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $macros{"{auth_type}"}) 0 196 196
630 0 ▶ if (defined($macros{'{auth_authen}'})) {push @data,'{auth_authen}'."\0".$macros{'{auth_authen}'}."\0";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $macros{"{auth_authen}"}) 0 196 196
631 0 ▶ if (defined($macros{'{auth_ssf}'})) {push @data,'{auth_ssf}'."\0".$macros{'{auth_ssf}'}."\0";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $macros{"{auth_ssf}"}) 0 196 196
632 0 ▶ if (defined($macros{'{auth_author}'})) {push @data,'{auth_author}'."\0".$macros{'{auth_author}'}."\0";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $macros{"{auth_author}"}) 0 196 196
633 196 ▶ if (defined($macros{'{mail_mailer}'})) {push @data,'{mail_mailer}'."\0".$macros{'{mail_mailer}'}."\0";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $macros{"{mail_mailer}"}) 33 163 196
634 196 ▶ if (defined($macros{'{mail_host}'})) {push @data,'{mail_host}'."\0".$macros{'{mail_host}'}."\0";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $macros{"{mail_host}"}) 33 163 196
635 196 ▶ if (defined($macros{'{mail_addr}'})) {push @data,'{mail_addr}'."\0".$macros{'{mail_addr}'}."\0";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $macros{"{mail_addr}"}) 33 163 196
636  
637 196 ▶ if (@data) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data) 130 66 196
638 0 ▶ if ($DEBUG==1) {print STDERR "\tsending D,M\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 130 130
639 130 $self->_send('D','M',@data);
640 }
641  
642  
643 196 @data=();
644 196 ▶ if (defined($macros{'{rcpt_mailer}'})) {push @data,'{rcpt_mailer}'."\0".$macros{'{rcpt_mailer}'}."\0";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $macros{"{rcpt_mailer}"}) 33 163 196
645 196 ▶ if (defined($macros{'{rcpt_host}'})) {push @data,'{rcpt_host}'."\0".$macros{'{rcpt_host}'}."\0";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $macros{"{rcpt_host}"}) 33 163 196
646 196 ▶ if (defined($macros{'{rcpt_addr}'})) {push @data,'{rcpt_addr}'."\0".$macros{'{rcpt_addr}'}."\0";}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $macros{"{rcpt_addr}"}) 33 163 196
647  
648 196 ▶ if (@data) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data) 33 163 196
649 0 ▶ if ($DEBUG==1) {print STDERR "\tsending D,R\n";}
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::Net::Milter::DEBUG == 1) 0 33 33
650 33 $self->_send('D','R',@data);
651 }
652  
653  
654 # no response after sending macros
655 196 return 1;
656  
657 } # end sub send_macros
658 ############
659  
660 ############
661 2541 ▶sub _io_send {
Subroutine _io_send: called CC=4 SCAR=13.9
662 2541 my $self = shift;
663 2541 my ($data) = @_;
664  
665 2541 my $must_send = length($data);
666 2541 my $did_send = 0;
667 2541 ▶ while ($did_send < $must_send) {
Branch: 1 branch
BranchTrueFalseTotal
if ($did_send < $must_send) 2543 2539 5082
668 2543 my $len = $self->{socket}->send(substr($data, $did_send));
669 # An error or no progress would otherwise retry forever
670 2543 ▶ croak "Error while writing to the socket: $!" if ! defined $len;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $len 1 2542 2543
671 2542 ▶ croak "Unable to write to the socket" if $len == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $len == 0 1 2541 2542
672 2541 $did_send += $len;
673 }
674  
675 2539 return 1;
676 }
677 ############
678  
679 ############
680 1618 ▶sub _io_recv {
Subroutine _io_recv: called CC=4 SCAR=13.9
681 1618 my $self = shift;
682 1618 my ($must_recv) = @_;
683  
684 1618 my $did_recv = 0;
685 1618 my $data = "";
686 1618 ▶ while ($did_recv < $must_recv) {
Branch: 1 branch
BranchTrueFalseTotal
if ($did_recv < $must_recv) 1621 1614 3235
687 1621 my $len = $self->{socket}->sysread($data, $must_recv-$did_recv, $did_recv);
688 # An error or EOF would otherwise retry forever, and a short read is not a valid packet
689 1621 ▶ croak "Error while reading from the socket: $!" if ! defined $len;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $len 1 1620 1621
690 1620 ▶ croak "Unexpected EOF while reading from the socket" if $len == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $len == 0 3 1617 1620
691 1617 $did_recv += $len;
692 }
693  
694 1614 return $data;
695 }
696 ############
697  
698 ############
699 41 ▶sub DESTROY {
Subroutine DESTROY: called CC=2 SCAR=7.1
700 41 my $self = shift;
701 41 ▶ if (defined($self->{socket})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"socket"}) 41 0 41
702 41 $self->{socket}->close;
703 } # end if
704  
705 } # end sub DESTROY
706 ############
707  
708 114 1;
709  
710 __END__
« Authentication/Config.pm ↑ Summary Authentication/App/ProcessLog/App/Command/arex.pm »