| 1 | # SMB Perl library, Copyright (C) 2014 Mikhael Goikhman, migo@cpan.org | ||||||||||||||||||||
| 2 | # | ||||||||||||||||||||
| 3 | # This program is free software: you can redistribute it and/or modify | ||||||||||||||||||||
| 4 | # it under the terms of the GNU General Public License as published by | ||||||||||||||||||||
| 5 | # the Free Software Foundation, either version 3 of the License, or | ||||||||||||||||||||
| 6 | # (at your option) any later version. | ||||||||||||||||||||
| 7 | # | ||||||||||||||||||||
| 8 | # This program is distributed in the hope that it will be useful, | ||||||||||||||||||||
| 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||
| 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||||||||||
| 11 | # GNU General Public License for more details. | ||||||||||||||||||||
| 12 | # | ||||||||||||||||||||
| 13 | # You should have received a copy of the GNU General Public License | ||||||||||||||||||||
| 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | package SMB::v2::Command::Negotiate; | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 1 | ▶ | use parent 'SMB::v2::Command'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | sub new_from_v1 ($$) { | ||||||||||||||||||||
| 24 | 0 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
new_from_v1: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||
| 25 | 0 | my $command1 = shift; | |||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 0 | my $header1 = $command1->header; | |||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 0 | ▶ | my $flags = $header1->{flags} & SMB::v1::Header::FLAGS_RESPONSE ? SMB::v2::Header::FLAGS_RESPONSE : 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 30 | my $security_mode = | ||||||||||||||||||||
| 31 | ($header1->{flags2} & SMB::v1::Header::FLAGS2_SECURITY_SIGNATURE ? 1 : 0) | | ||||||||||||||||||||
| 32 | 0 | ▶ | ($header1->{flags2} & SMB::v1::Header::FLAGS2_SECURITY_SIGNATURE_REQUIRED ? 2 : 0); | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 0 | my $header = SMB::v2::Header->new( | |||||||||||||||||||
| 35 | code => 0, | ||||||||||||||||||||
| 36 | mid => 0, | ||||||||||||||||||||
| 37 | flags => $flags, | ||||||||||||||||||||
| 38 | status => $command1->status, | ||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 0 | my $self = $class->SUPER::new($header); | |||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 0 | $self->set( | |||||||||||||||||||
| 44 | security_mode => $security_mode, | ||||||||||||||||||||
| 45 | dialects => [ 0x0202, 0x02ff ], | ||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 0 | return $self; | |||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | sub init ($) { | ||||||||||||||||||||
| 52 | 0 | ▶ | $_[0]->set( | ||||||||||||||||||
|
Subroutine
init: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 53 | dialects => [ 0x0202 ], | ||||||||||||||||||||
| 54 | dialect => 0x0202, | ||||||||||||||||||||
| 55 | security_mode => 0, | ||||||||||||||||||||
| 56 | capabilities => 0x7, | ||||||||||||||||||||
| 57 | guid => "\5" x 16, | ||||||||||||||||||||
| 58 | max_transact_size => 1 << 20, | ||||||||||||||||||||
| 59 | max_read_size => 1 << 16, | ||||||||||||||||||||
| 60 | max_write_size => 1 << 16, | ||||||||||||||||||||
| 61 | current_time => 0, | ||||||||||||||||||||
| 62 | boot_time => 0, | ||||||||||||||||||||
| 63 | security_buffer => undef, | ||||||||||||||||||||
| 64 | ) | ||||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | sub parse ($$%) { | ||||||||||||||||||||
| 68 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
parse: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 69 | 0 | my $parser = shift; | |||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 0 | ▶ | if ($self->is_response) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 72 | 0 | $self->security_mode($parser->uint16); | |||||||||||||||||||
| 73 | 0 | $self->dialect($parser->uint16); | |||||||||||||||||||
| 74 | 0 | $parser->uint16; # reserved | |||||||||||||||||||
| 75 | 0 | $self->guid($parser->bytes(16)); | |||||||||||||||||||
| 76 | 0 | $self->capabilities($parser->uint32); | |||||||||||||||||||
| 77 | 0 | $self->max_transact_size($parser->uint32); | |||||||||||||||||||
| 78 | 0 | $self->max_read_size($parser->uint32); | |||||||||||||||||||
| 79 | 0 | $self->max_write_size($parser->uint32); | |||||||||||||||||||
| 80 | 0 | $self->current_time($parser->uint64); | |||||||||||||||||||
| 81 | 0 | $self->boot_time($parser->uint64); | |||||||||||||||||||
| 82 | 0 | my $offset = $parser->uint16; | |||||||||||||||||||
| 83 | 0 | my $length = $parser->uint16; | |||||||||||||||||||
| 84 | 0 | $parser->uint32; # reserved2 | |||||||||||||||||||
| 85 | 0 | $self->security_buffer($parser->bytes($length)); | |||||||||||||||||||
| 86 | } else { | ||||||||||||||||||||
| 87 | 0 | my $num_dialects = $parser->uint16; | |||||||||||||||||||
| 88 | 0 | $self->security_mode($parser->uint16); | |||||||||||||||||||
| 89 | 0 | $parser->uint16; # reserved | |||||||||||||||||||
| 90 | 0 | $self->capabilities($parser->uint32); | |||||||||||||||||||
| 91 | 0 | $self->guid($parser->bytes(16)); | |||||||||||||||||||
| 92 | 0 | $self->boot_time($parser->uint64); | |||||||||||||||||||
| 93 | 0 | $self->dialects([ map { $parser->uint16 } 1 .. $num_dialects ]); | |||||||||||||||||||
| 94 | } | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | 0 | return $self; | |||||||||||||||||||
| 97 | } | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | sub pack ($$) { | ||||||||||||||||||||
| 100 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
pack: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||
| 101 | 0 | my $packer = shift; | |||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | 0 | ▶ | if ($self->is_response) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 104 | 0 | ▶ | my $security_buffer = $self->security_buffer // die 'No security_buffer'; | ||||||||||||||||||
|
Condition0%0/2
$self->security_buffer // die("No security_buffer")
MC/DC0%0/1
$self->security_buffer // die("No security_buffer")
$self->security_buffer
Truth table0%0/2
A
A= $self->security_buffer
| |||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | 0 | ▶ | $packer | ||||||||||||||||||
|
Condition0%0/3
$self->dialects->[1] || $self->dialect
MC/DC0%0/2
$self->dialects->[1] || $self->dialect
$self->dialects->[1]
$self->dialect
Truth table0%0/3
A || B
A= $self->dialects->[1]B= $self->dialect
| |||||||||||||||||||||
| 107 | ->uint16($self->security_mode) | ||||||||||||||||||||
| 108 | ->uint16($self->dialects->[1] || $self->dialect) | ||||||||||||||||||||
| 109 | ->uint16(0) # reserved | ||||||||||||||||||||
| 110 | ->bytes ($self->guid) | ||||||||||||||||||||
| 111 | ->uint32($self->capabilities) | ||||||||||||||||||||
| 112 | ->uint32($self->max_transact_size) | ||||||||||||||||||||
| 113 | ->uint32($self->max_read_size) | ||||||||||||||||||||
| 114 | ->uint32($self->max_write_size) | ||||||||||||||||||||
| 115 | ->uint64($self->current_time) | ||||||||||||||||||||
| 116 | ->uint64($self->boot_time) | ||||||||||||||||||||
| 117 | ->uint16($packer->diff('smb-header') + 8) | ||||||||||||||||||||
| 118 | ->uint16(length $security_buffer) | ||||||||||||||||||||
| 119 | ->uint32(0) # reserved2 | ||||||||||||||||||||
| 120 | ->bytes ($security_buffer) | ||||||||||||||||||||
| 121 | ; | ||||||||||||||||||||
| 122 | } else { | ||||||||||||||||||||
| 123 | 0 | my $dialects = $self->dialects; | |||||||||||||||||||
| 124 | 0 | $packer | |||||||||||||||||||
| 125 | ->uint16(scalar @$dialects) | ||||||||||||||||||||
| 126 | ->uint16($self->security_mode) | ||||||||||||||||||||
| 127 | ->uint16(0) # reserved | ||||||||||||||||||||
| 128 | ->uint32($self->capabilities) | ||||||||||||||||||||
| 129 | ->bytes ($self->guid) | ||||||||||||||||||||
| 130 | ->uint64($self->boot_time) | ||||||||||||||||||||
| 131 | ; | ||||||||||||||||||||
| 132 | 0 | $packer->uint16($_) for @$dialects; | |||||||||||||||||||
| 133 | } | ||||||||||||||||||||
| 134 | } | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | sub supports_protocol ($$) { | ||||||||||||||||||||
| 137 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
supports_protocol: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | 0 | return 1; | |||||||||||||||||||
| 140 | } | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | 1 | 1; | |||||||||||||||||||