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