| 1 | package POE::Component::Client::NSCA; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use POE qw(Wheel::SocketFactory Filter::Stream Wheel::ReadWrite); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use Socket; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use integer; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 6 | $VERSION = '0.16'; | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 6 | ▶ | use constant PROGRAM_VERSION => "1.2.0b4-Perl"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 6 | ▶ | use constant MODIFICATION_DATE => "16-03-2006"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 6 | ▶ | use constant OK => 0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 6 | ▶ | use constant ERROR => -1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 6 | ▶ | use constant TRUE => 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 6 | ▶ | use constant FALSE => 0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 6 | ▶ | use constant STATE_CRITICAL => 2 ; # /* service state return codes */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 6 | ▶ | use constant STATE_WARNING => 1 ; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 6 | ▶ | use constant STATE_OK => 0 ; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 6 | ▶ | use constant STATE_UNKNOWN => 3 ; # Updated for Nagios. | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 6 | ▶ | use constant DEFAULT_SOCKET_TIMEOUT => 10 ; # /* timeout after 10 seconds */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 6 | ▶ | use constant DEFAULT_SERVER_PORT => 5667 ; # /* default port to use */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 6 | ▶ | use constant MAX_INPUT_BUFFER => 2048 ; # /* max size of most buffers we use */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 6 | ▶ | use constant MAX_HOST_ADDRESS_LENGTH => 256 ; # /* max size of a host address */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 6 | ▶ | use constant MAX_HOSTNAME_LENGTH => 64 ; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 6 | ▶ | use constant MAX_DESCRIPTION_LENGTH => 128; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 6 | ▶ | use constant MAX_PLUGINOUTPUT_LENGTH => 512; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 6 | ▶ | use constant MAX_PASSWORD_LENGTH => 512; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 6 | ▶ | use constant ENCRYPT_NONE => 0 ; # /* no encryption */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 6 | ▶ | use constant ENCRYPT_XOR => 1 ; # /* not really encrypted, just obfuscated */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 6 | ▶ | use constant ENCRYPT_DES => 2 ; # /* DES */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 6 | ▶ | use constant ENCRYPT_3DES => 3 ; # /* 3DES or Triple DES */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 6 | ▶ | use constant ENCRYPT_CAST128 => 4 ; # /* CAST-128 */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 6 | ▶ | use constant ENCRYPT_CAST256 => 5 ; # /* CAST-256 */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 6 | ▶ | use constant ENCRYPT_XTEA => 6 ; # /* xTEA */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 6 | ▶ | use constant ENCRYPT_3WAY => 7 ; # /* 3-WAY */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 6 | ▶ | use constant ENCRYPT_BLOWFISH => 8 ; # /* SKIPJACK */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 6 | ▶ | use constant ENCRYPT_TWOFISH => 9 ; # /* TWOFISH */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 6 | ▶ | use constant ENCRYPT_LOKI97 => 10 ; # /* LOKI97 */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 6 | ▶ | use constant ENCRYPT_RC2 => 11 ; # /* RC2 */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 6 | ▶ | use constant ENCRYPT_ARCFOUR => 12 ; # /* RC4 */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 6 | ▶ | use constant ENCRYPT_RC6 => 13 ; # /* RC6 */ ; # /* UNUSED */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 6 | ▶ | use constant ENCRYPT_RIJNDAEL128 => 14 ; # /* RIJNDAEL-128 */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 6 | ▶ | use constant ENCRYPT_RIJNDAEL192 => 15 ; # /* RIJNDAEL-192 */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 6 | ▶ | use constant ENCRYPT_RIJNDAEL256 => 16 ; # /* RIJNDAEL-256 */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 6 | ▶ | use constant ENCRYPT_MARS => 17 ; # /* MARS */ ; # /* UNUSED */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 6 | ▶ | use constant ENCRYPT_PANAMA => 18 ; # /* PANAMA */ ; # /* UNUSED */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 6 | ▶ | use constant ENCRYPT_WAKE => 19 ; # /* WAKE */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 6 | ▶ | use constant ENCRYPT_SERPENT => 20 ; # /* SERPENT */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 6 | ▶ | use constant ENCRYPT_IDEA => 21 ; # /* IDEA */ ; # /* UNUSED */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 6 | ▶ | use constant ENCRYPT_ENIGMA => 22 ; # /* ENIGMA (Unix crypt) */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 6 | ▶ | use constant ENCRYPT_GOST => 23 ; # /* GOST */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 6 | ▶ | use constant ENCRYPT_SAFER64 => 24 ; # /* SAFER-sk64 */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 6 | ▶ | use constant ENCRYPT_SAFER128 => 25 ; # /* SAFER-sk128 */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 6 | ▶ | use constant ENCRYPT_SAFERPLUS => 26 ; # /* SAFER+ */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 6 | ▶ | use constant TRANSMITTED_IV_SIZE => 128 ; # /* size of IV to transmit - must be as big as largest IV needed for any crypto algorithm */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 6 | ▶ | use constant NSCA_PACKET_VERSION_3 => 3 ; # /* packet version identifier */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 6 | ▶ | use constant NSCA_PACKET_VERSION_2 => 2 ; # /* packet version identifier */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 6 | ▶ | use constant NSCA_PACKET_VERSION_1 => 1 ; # /* older packet version identifier */ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 6 | ▶ | use constant SIZEOF_U_INT32_T => 4; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 6 | ▶ | use constant SIZEOF_INT16_T => 2; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 6 | ▶ | use constant SIZEOF_INIT_PACKET => TRANSMITTED_IV_SIZE + SIZEOF_U_INT32_T; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 6 | ▶ | use constant PROBABLY_ALIGNMENT_ISSUE => 4; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 6 | ▶ | use constant SIZEOF_DATA_PACKET => SIZEOF_INT16_T + SIZEOF_U_INT32_T + SIZEOF_U_INT32_T + SIZEOF_INT16_T + MAX_HOSTNAME_LENGTH + MAX_DESCRIPTION_LENGTH + MAX_PLUGINOUTPUT_LENGTH + PROBABLY_ALIGNMENT_ISSUE; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | # Work out whether we have the mcrypt libraries on board. | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 6 | my $HAVE_MCRYPT = 0; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 6 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 83 | 6 | require Mcrypt; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $HAVE_MCRYPT++; | |||||||||||||||||||||||||||||||||||||||||
| 85 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | # Lookups for loading. | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 6 | my %mcrypts = ( ENCRYPT_DES, "des", | |||||||||||||||||||||||||||||||||||||||||
| 89 | ENCRYPT_3DES, "3des", | ||||||||||||||||||||||||||||||||||||||||||
| 90 | ENCRYPT_CAST128, "cast-128", | ||||||||||||||||||||||||||||||||||||||||||
| 91 | ENCRYPT_CAST256, "cast-256", | ||||||||||||||||||||||||||||||||||||||||||
| 92 | ENCRYPT_XTEA, "xtea", | ||||||||||||||||||||||||||||||||||||||||||
| 93 | ENCRYPT_3WAY, "threeway", | ||||||||||||||||||||||||||||||||||||||||||
| 94 | ENCRYPT_BLOWFISH, "blowfish", | ||||||||||||||||||||||||||||||||||||||||||
| 95 | ENCRYPT_TWOFISH, "twofish", | ||||||||||||||||||||||||||||||||||||||||||
| 96 | ENCRYPT_LOKI97, "loki97", | ||||||||||||||||||||||||||||||||||||||||||
| 97 | ENCRYPT_RC2, "rc2", | ||||||||||||||||||||||||||||||||||||||||||
| 98 | ENCRYPT_ARCFOUR, "arcfour", | ||||||||||||||||||||||||||||||||||||||||||
| 99 | ENCRYPT_RC6, "rc6", | ||||||||||||||||||||||||||||||||||||||||||
| 100 | ENCRYPT_RIJNDAEL128, "rijndael-128", | ||||||||||||||||||||||||||||||||||||||||||
| 101 | ENCRYPT_RIJNDAEL192, "rijndael-192", | ||||||||||||||||||||||||||||||||||||||||||
| 102 | ENCRYPT_RIJNDAEL256, "rijndael-256", | ||||||||||||||||||||||||||||||||||||||||||
| 103 | ENCRYPT_MARS, "mars", | ||||||||||||||||||||||||||||||||||||||||||
| 104 | ENCRYPT_PANAMA, "panama", | ||||||||||||||||||||||||||||||||||||||||||
| 105 | ENCRYPT_WAKE, "wake", | ||||||||||||||||||||||||||||||||||||||||||
| 106 | ENCRYPT_SERPENT, "serpent", | ||||||||||||||||||||||||||||||||||||||||||
| 107 | ENCRYPT_IDEA, "idea", | ||||||||||||||||||||||||||||||||||||||||||
| 108 | ENCRYPT_ENIGMA, "engima", | ||||||||||||||||||||||||||||||||||||||||||
| 109 | ENCRYPT_GOST, "gost", | ||||||||||||||||||||||||||||||||||||||||||
| 110 | ENCRYPT_SAFER64, "safer-sk64", | ||||||||||||||||||||||||||||||||||||||||||
| 111 | ENCRYPT_SAFER128, "safer-sk128", | ||||||||||||||||||||||||||||||||||||||||||
| 112 | ENCRYPT_SAFERPLUS, "saferplus", | ||||||||||||||||||||||||||||||||||||||||||
| 113 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | sub send_nsca { | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 4 | ▶ | my $package = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_nsca: called CC=15 SCAR=31.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 4 | my %params = @_; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 4 | $params{lc $_} = delete $params{$_} for keys %params; | |||||||||||||||||||||||||||||||||||||||||
| 119 | croak "$package requires a 'host' argument\n" | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 4 | ▶ | unless $params{host}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | croak "$package requires an 'event' argument\n" | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 4 | ▶ | unless $params{event}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | croak "$package requires a 'password' argument\n" | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 4 | ▶ | unless $params{password} || $params{encryption} eq ENCRYPT_XOR; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$params{"password"} or $params{"encryption"} eq 1
MC/DC0%0/2
$params{"password"} or $params{"encryption"} eq 1
$params{"password"}
$params{"encryption"} eq 1
Truth table33%1/3
A or B
A= $params{"password"}B= $params{"encryption"} eq 1
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | croak "$package requires an 'encryption' argument\n" | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 4 | ▶ | unless defined $params{encryption}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | croak "$package requires a 'message' argument and it must be a hashref\n" | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 4 | ▶ | unless $params{message} and ref $params{message} eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$params{"message"} and ref $params{"message"} eq "HASH"
MC/DC0%0/2
$params{"message"} and ref $params{"message"} eq "HASH"
$params{"message"}
ref $params{"message"} eq "HASH"
Truth table33%1/3
A and B
A= $params{"message"}B= ref $params{"message"} eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 4 | foreach my $item ( qw(host_name return_code plugin_output) ) { | |||||||||||||||||||||||||||||||||||||||||
| 130 | croak "'message' hashref must have a '$item' key\n" | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 12 | ▶ | unless defined $params{message}->{$item}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 4 | _correct_message( $params{message} ); | |||||||||||||||||||||||||||||||||||||||||
| 134 | 4 | ▶ | $params{port} = 5667 unless defined $params{port}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 4 | ▶ | $params{timeout} = 10 unless defined $params{timeout} and $params{timeout} =~ /^\d+$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $params{"timeout"} and $params{"timeout"} =~ /^\d+$/
MC/DC0%0/2
defined $params{"timeout"} and $params{"timeout"} =~ /^\d+$/
defined $params{"timeout"}
$params{"timeout"} =~ /^\d+$/
Truth table33%1/3
A and B
A= defined $params{"timeout"}B= $params{"timeout"} =~ /^\d+$/
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 4 | my $options = delete $params{options}; | |||||||||||||||||||||||||||||||||||||||||
| 137 | 4 | my $self = bless \%params, $package; | |||||||||||||||||||||||||||||||||||||||||
| 138 | 4 | ▶ | $self->{session_id} = POE::Session->create( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | object_states => [ | ||||||||||||||||||||||||||||||||||||||||||
| 140 | $self => [ qw(_start _connect _sock_up _sock_err _sock_in _sock_flush _sock_down _send_response _timeout) ], | ||||||||||||||||||||||||||||||||||||||||||
| 141 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 142 | heap => $self, | ||||||||||||||||||||||||||||||||||||||||||
| 143 | ( ref($options) eq 'HASH' ? ( options => $options ) : () ), | ||||||||||||||||||||||||||||||||||||||||||
| 144 | )->ID(); | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 4 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | sub _start { | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 4 | ▶ | my ($kernel,$sender,$self) = @_[KERNEL,SENDER,OBJECT]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_start: called CC=5 SCAR=19.2
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 4 | $self->{session_id} = $_[SESSION]->ID(); | |||||||||||||||||||||||||||||||||||||||||
| 151 | 4 | $self->{filter} = POE::Filter::Stream->new(); | |||||||||||||||||||||||||||||||||||||||||
| 152 | 4 | ▶ | if ( $kernel == $sender and !$self->{session} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$kernel == $sender and not $self->{"session"}
MC/DC0%0/2
$kernel == $sender and not $self->{"session"}
$kernel == $sender
not $self->{"session"}
Truth table33%1/3
A and not(B)
A= $kernel == $senderB= not $self->{"session"}
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | croak "Not called from another POE session and 'session' wasn't set\n"; | |||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 4 | my $sender_id; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 4 | ▶ | if ( $self->{session} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | if ( my $ref = $kernel->alias_resolve( $self->{session} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | $sender_id = $ref->ID(); | |||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | croak "Could not resolve 'session' to a valid POE session\n"; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 165 | 4 | $sender_id = $sender->ID(); | |||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 4 | $kernel->refcount_increment( $sender_id, __PACKAGE__ ); | |||||||||||||||||||||||||||||||||||||||||
| 168 | 4 | $self->{sender_id} = $sender_id; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 4 | $kernel->yield( '_connect' ); | |||||||||||||||||||||||||||||||||||||||||
| 170 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | sub _connect { | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 4 | ▶ | my ($kernel,$self) = @_[KERNEL,OBJECT]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_connect: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | $self->{sockfactory} = POE::Wheel::SocketFactory->new( | ||||||||||||||||||||||||||||||||||||||||||
| 176 | SocketProtocol => 'tcp', | ||||||||||||||||||||||||||||||||||||||||||
| 177 | RemoteAddress => $self->{host}, | ||||||||||||||||||||||||||||||||||||||||||
| 178 | RemotePort => $self->{port}, | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 4 | SuccessEvent => '_sock_up', | |||||||||||||||||||||||||||||||||||||||||
| 180 | FailureEvent => '_sock_err', | ||||||||||||||||||||||||||||||||||||||||||
| 181 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 182 | 4 | $kernel->delay( '_timeout', $self->{timeout} ); | |||||||||||||||||||||||||||||||||||||||||
| 183 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | sub _timeout { | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | my ($kernel,$self) = @_[KERNEL,OBJECT]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_timeout: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | delete $self->{sockfactory}; | |||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | delete $self->{socket}; | |||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | $kernel->yield( '_send_response', 'timeout' ); | |||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | sub _sock_err { | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 2 | ▶ | my ($kernel,$self) = @_[KERNEL,OBJECT]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sock_err: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 2 | $kernel->delay( '_timeout' ); | |||||||||||||||||||||||||||||||||||||||||
| 197 | 2 | delete $self->{sockfactory}; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 2 | $kernel->yield( '_send_response', 'sockerr', @_[ARG0..ARG2] ); | |||||||||||||||||||||||||||||||||||||||||
| 199 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | sub _sock_up { | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 2 | ▶ | my ($kernel,$self,$socket) = @_[KERNEL,OBJECT,ARG0]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sock_up: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 2 | $kernel->delay( '_timeout' ); | |||||||||||||||||||||||||||||||||||||||||
| 205 | 2 | delete $self->{sockfactory}; | |||||||||||||||||||||||||||||||||||||||||
| 206 | $self->{socket} = new POE::Wheel::ReadWrite | ||||||||||||||||||||||||||||||||||||||||||
| 207 | ( Handle => $socket, | ||||||||||||||||||||||||||||||||||||||||||
| 208 | Filter => $self->{filter}, | ||||||||||||||||||||||||||||||||||||||||||
| 209 | 2 | InputEvent => '_sock_in', | |||||||||||||||||||||||||||||||||||||||||
| 210 | ErrorEvent => '_sock_down', | ||||||||||||||||||||||||||||||||||||||||||
| 211 | FlushedEvent => '_sock_flush', | ||||||||||||||||||||||||||||||||||||||||||
| 212 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 213 | 2 | $self->{state} = 'init'; | |||||||||||||||||||||||||||||||||||||||||
| 214 | 2 | $kernel->delay( '_timeout', $self->{timeout} ); | |||||||||||||||||||||||||||||||||||||||||
| 215 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | sub _sock_down { | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | my ($kernel,$self) = @_[KERNEL,OBJECT]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sock_down: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | delete $self->{socket}; | |||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | $kernel->delay( '_timeout' ); | |||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | sub _sock_in { | ||||||||||||||||||||||||||||||||||||||||||
| 226 | 2 | ▶ | my ($kernel,$self,$input) = @_[KERNEL,OBJECT,ARG0]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sock_in: called CC=4 SCAR=16.0
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | 2 | ▶ | unless ( length( $input ) == SIZEOF_INIT_PACKET ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | $kernel->yield( '_send_response', 'badinit', length( $input ) ); | |||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | delete $self->{socket}; | |||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | 2 | my $init_packet = { | |||||||||||||||||||||||||||||||||||||||||
| 233 | iv => substr($input, 0, TRANSMITTED_IV_SIZE), | ||||||||||||||||||||||||||||||||||||||||||
| 234 | timestamp => substr($input, TRANSMITTED_IV_SIZE, SIZEOF_U_INT32_T), | ||||||||||||||||||||||||||||||||||||||||||
| 235 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 2 | my $data_packet_string_a = pack('n', NSCA_PACKET_VERSION_3) . "\000\000"; | |||||||||||||||||||||||||||||||||||||||||
| 237 | my $data_packet_string_b = | ||||||||||||||||||||||||||||||||||||||||||
| 238 | $init_packet->{timestamp} . | ||||||||||||||||||||||||||||||||||||||||||
| 239 | pack('n', $self->{message}->{return_code}) . | ||||||||||||||||||||||||||||||||||||||||||
| 240 | pack(('a'.MAX_HOSTNAME_LENGTH), $self->{message}->{host_name}) . | ||||||||||||||||||||||||||||||||||||||||||
| 241 | pack(('a'.MAX_DESCRIPTION_LENGTH), $self->{message}->{svc_description} || '') . | ||||||||||||||||||||||||||||||||||||||||||
| 242 | 2 | ▶ | pack(('a'.MAX_PLUGINOUTPUT_LENGTH), $self->{message}->{plugin_output}) . | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'message'}{'svc_description'} || ''
MC/DC0%0/1
$self->{'message'}{'svc_description'} || ''
$self->{'message'}{'svc_description'}
Truth table50%1/2
A
A= $self->{'message'}{'svc_description'}
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | "\000\000"; | ||||||||||||||||||||||||||||||||||||||||||
| 244 | 2 | my $crc = _calculate_crc32( $data_packet_string_a . pack( 'N', 0 ) . $data_packet_string_b); | |||||||||||||||||||||||||||||||||||||||||
| 245 | 2 | my $data_packet_string = $data_packet_string_a . pack('N', $crc) . $data_packet_string_b; | |||||||||||||||||||||||||||||||||||||||||
| 246 | 2 | my $data_packet_string_crypt = _encrypt($data_packet_string, $self->{encryption}, $init_packet->{iv}, $self->{password} ); | |||||||||||||||||||||||||||||||||||||||||
| 247 | 2 | ▶ | unless ( $data_packet_string_crypt ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | $kernel->yield( '_send_response', 'badencrypt' ); | |||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | delete $self->{socket}; | |||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | 2 | $self->{socket}->put( $data_packet_string_crypt ); | |||||||||||||||||||||||||||||||||||||||||
| 253 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | sub _sock_flush { | ||||||||||||||||||||||||||||||||||||||||||
| 257 | 2 | ▶ | my ($kernel,$self) = @_[KERNEL,OBJECT]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sock_flush: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 2 | $kernel->delay( '_timeout' ); | |||||||||||||||||||||||||||||||||||||||||
| 259 | 2 | delete $self->{socket}; | |||||||||||||||||||||||||||||||||||||||||
| 260 | 2 | $kernel->yield( '_send_response', 'success' ); | |||||||||||||||||||||||||||||||||||||||||
| 261 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | sub _send_response { | ||||||||||||||||||||||||||||||||||||||||||
| 265 | 4 | ▶ | my ($kernel,$self,$type) = @_[KERNEL,OBJECT,ARG0]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_send_response: called CC=6 SCAR=19.6
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | 4 | my $response = { }; | |||||||||||||||||||||||||||||||||||||||||
| 267 | 4 | $response->{$_} = $self->{$_} for qw(host message context); | |||||||||||||||||||||||||||||||||||||||||
| 268 | SWITCH: { | ||||||||||||||||||||||||||||||||||||||||||
| 269 | 4 | ▶ | if ( $type eq 'badinit' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | $response->{error} = 'Error: bad initialisation string from peer expected' . SIZEOF_INIT_PACKET . ' got ' . $_[ARG1]; | |||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||
| 273 | 4 | ▶ | if ( $type eq 'badencrypt' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | $response->{error} = 'Error: There was a problem with the encryption'; | |||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | 4 | ▶ | if ( $type eq 'sockerr' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | 2 | $response->{error} = 'Error: socket error: ' . join(' ', @_[ARG1..$#_]); | |||||||||||||||||||||||||||||||||||||||||
| 279 | 2 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 2 | ▶ | if ( $type eq 'timeout' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | $response->{error} = sprintf("Error: Socket timeout after %d seconds.", $self->{timeout} ); | |||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | 2 | $response->{success} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||
| 287 | 4 | $kernel->post( $self->{sender_id}, $self->{event}, $response ); | |||||||||||||||||||||||||||||||||||||||||
| 288 | 4 | $kernel->refcount_decrement( $self->{sender_id}, __PACKAGE__ ); | |||||||||||||||||||||||||||||||||||||||||
| 289 | 4 | $kernel->alarm_remove_all(); | |||||||||||||||||||||||||||||||||||||||||
| 290 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | # truncates long fields | ||||||||||||||||||||||||||||||||||||||||||
| 294 | sub _correct_message { | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 4 | ▶ | my $message = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_correct_message: called CC=5 SCAR=20.9
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | 4 | ▶ | $message->{'svc_description'} = '' unless defined $message->{'svc_description'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | 4 | ▶ | if (length( $message->{'host_name'} ) >= MAX_HOSTNAME_LENGTH) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | warn("Hostname too long - truncated"); | |||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | $message->{'host_name'} = substr($message->{'host_name'}, 0, MAX_HOSTNAME_LENGTH-1); | |||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||
| 302 | 4 | ▶ | if (length( $message->{'svc_description'} ) >= MAX_DESCRIPTION_LENGTH) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | warn("Description too long - truncated"); | |||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | $message->{'svc_description'} = substr($message->{'svc_description'}, 0, MAX_DESCRIPTION_LENGTH-1); | |||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||
| 306 | 4 | ▶ | if (length( $message->{'plugin_output'} ) >= MAX_PLUGINOUTPUT_LENGTH) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | warn("Plugin Output too long - truncated"); | |||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | $message->{'plugin_output'} = substr($message->{'plugin_output'}, 0, MAX_PLUGINOUTPUT_LENGTH-1); | |||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | 4 | return $message; | |||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | #/* calculates the CRC 32 value for a buffer */ | ||||||||||||||||||||||||||||||||||||||||||
| 315 | sub _calculate_crc32 { | ||||||||||||||||||||||||||||||||||||||||||
| 316 | 2 | ▶ | my $string = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_calculate_crc32: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | 2 | my $crc32_table = _generate_crc32_table(); | |||||||||||||||||||||||||||||||||||||||||
| 319 | 2 | my $crc = 0xFFFFFFFF; | |||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 2 | foreach my $tchar (split(//, $string)) { | |||||||||||||||||||||||||||||||||||||||||
| 322 | 1440 | my $char = ord($tchar); | |||||||||||||||||||||||||||||||||||||||||
| 323 | 1440 | $crc = (($crc >> 8) & 0x00FFFFFF) ^ $crc32_table->[($crc ^ $char) & 0xFF]; | |||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | 2 | return ($crc ^ 0xFFFFFFFF); | |||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | #/* build the crc table - must be called before calculating the crc value */ | ||||||||||||||||||||||||||||||||||||||||||
| 330 | sub _generate_crc32_table { | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 2 | ▶ | my $crc32_table = []; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_crc32_table: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | 2 | my $poly = 0xEDB88320; | |||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | 2 | ▶ | for (my $i = 0; $i < 256; $i++){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | 512 | my $crc = $i; | |||||||||||||||||||||||||||||||||||||||||
| 336 | 512 | ▶ | for (my $j = 8; $j > 0; $j--) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | 4096 | ▶ | if ($crc & 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 338 | 2048 | $crc = ($crc >> 1) ^ $poly; | |||||||||||||||||||||||||||||||||||||||||
| 339 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 340 | 2048 | $crc = ($crc >> 1); | |||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||
| 343 | 512 | $crc32_table->[$i] = $crc; | |||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||
| 345 | 2 | return $crc32_table; | |||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | # central switchboard for encryption methods. | ||||||||||||||||||||||||||||||||||||||||||
| 349 | sub _encrypt { | ||||||||||||||||||||||||||||||||||||||||||
| 350 | 2 | ▶ | my ($data_packet_string, $encryption_method, $iv_salt, $password) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_encrypt: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | 2 | my $crypted; | |||||||||||||||||||||||||||||||||||||||||
| 353 | 2 | ▶ | if ($encryption_method == ENCRYPT_NONE) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 354 | 1 | $crypted = $data_packet_string; | |||||||||||||||||||||||||||||||||||||||||
| 355 | } elsif ($encryption_method == ENCRYPT_XOR) { | ||||||||||||||||||||||||||||||||||||||||||
| 356 | 1 | $crypted = _encrypt_xor($data_packet_string, $iv_salt, $password); | |||||||||||||||||||||||||||||||||||||||||
| 357 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | $crypted = _encrypt_mcrypt( $data_packet_string, $encryption_method, $iv_salt, $password ); | |||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||
| 360 | 2 | return $crypted; | |||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | sub _encrypt_xor { | ||||||||||||||||||||||||||||||||||||||||||
| 364 | 1 | ▶ | my ($data_packet_string, $iv_salt, $password) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_encrypt_xor: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | 1 | my @out = split(//, $data_packet_string); | |||||||||||||||||||||||||||||||||||||||||
| 367 | 1 | my @salt_iv = split(//, $iv_salt); | |||||||||||||||||||||||||||||||||||||||||
| 368 | 1 | my @salt_pw = split(//, $password); | |||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | 1 | my $y = 0; | |||||||||||||||||||||||||||||||||||||||||
| 371 | 1 | my $x = 0; | |||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||
| 373 | #/* rotate over IV we received from the server... */ | ||||||||||||||||||||||||||||||||||||||||||
| 374 | 1 | ▶ | while ($y < SIZEOF_DATA_PACKET) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | #/* keep rotating over IV */ | ||||||||||||||||||||||||||||||||||||||||||
| 376 | 720 | $out[$y] = $out[$y] ^ $salt_iv[$x % scalar(@salt_iv)]; | |||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | 720 | $y++; | |||||||||||||||||||||||||||||||||||||||||
| 379 | 720 | $x++; | |||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | 1 | ▶ | if ($password) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | #/* rotate over password... */ | ||||||||||||||||||||||||||||||||||||||||||
| 384 | 1 | $y=0; | |||||||||||||||||||||||||||||||||||||||||
| 385 | 1 | $x=0; | |||||||||||||||||||||||||||||||||||||||||
| 386 | 1 | ▶ | while ($y < SIZEOF_DATA_PACKET){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 387 | #/* keep rotating over password */ | ||||||||||||||||||||||||||||||||||||||||||
| 388 | 720 | $out[$y] = $out[$y] ^ $salt_pw[$x % scalar(@salt_pw)]; | |||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||
| 390 | 720 | $y++; | |||||||||||||||||||||||||||||||||||||||||
| 391 | 720 | $x++; | |||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||
| 394 | 1 | return( join('',@out) ); | |||||||||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||
| 397 | sub _encrypt_mcrypt { | ||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | ▶ | my ( $data_packet_string, $encryption_method, $iv_salt, $password ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_encrypt_mcrypt: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | my $crypted; | |||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | my $evalok = 0; | |||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | if( $HAVE_MCRYPT ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | # Initialise the routine | ||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | ▶ | if( defined( $mcrypts{$encryption_method} ) ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 404 | # Load the routine. | ||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | my $routine = $mcrypts{$encryption_method}; | |||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 407 | # This sometimes dies with 'mcrypt is not of type MCRYPT'. | ||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | my $td = Mcrypt->new( algorithm => $routine, mode => 'cfb', verbose => 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | my $key = $password; | |||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | my $iv = substr $iv_salt, 0, $td->{IV_SIZE}; | |||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | ▶ | if( defined( $td ) ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | $td->init($key, $iv); | |||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | ▶ | for (my $i = 0; $i < length( $data_packet_string ); $i++ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | $crypted .= $td->encrypt( substr $data_packet_string, 0+$i, 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | $td->end(); | |||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | $evalok++; | |||||||||||||||||||||||||||||||||||||||||
| 419 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | warn "$@\n" if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | # Mcrypt is fastest, but for some routines, there are alternatives if | ||||||||||||||||||||||||||||||||||||||||||
| 425 | # your perl Mcrypt <-> libmcrypt linkage isn't working. | ||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | ▶ | if( ! $evalok && ! defined( $crypted ) && defined( $encryption_method )){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not $evalok || defined $crypted and defined $encryption_method
$evalok || defined $crypted
MC/DC0%0/3
not $evalok || defined $crypted and defined $encryption_method
$evalok
defined $crypted
defined $encryption_method
Truth table0%0/4
not(A || B) and C
A= $evalokB= defined $cryptedC= defined $encryption_method
| |||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | ▶ | if( defined( $mcrypts{$encryption_method} ) && 1 == 2 ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
defined $mcrypts{$encryption_method} and
MC/DC0%0/1
defined $mcrypts{$encryption_method} and
defined $mcrypts{$encryption_method}
Truth table0%0/2
A
A= defined $mcrypts{$encryption_method}
| |||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | my $routine = '_encrypt_' . $mcrypts{$encryption_method}; | |||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | ▶ | if( $routine !~ /_$/ ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | $crypted = $routine->( $data_packet_string, $encryption_method, $iv_salt, $password ); | |||||||||||||||||||||||||||||||||||||||||
| 432 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | return( $crypted ); | |||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||
| 440 | 6 | 'Yn anfon i maes an SOS'; | |||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||
| 442 | __END__ | ||||||||||||||||||||||||||||||||||||||||||