| 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::Create; | ||||||||||||||||||||||||||||||||||||||||||
| 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 | 1 | ▶ | use SMB::OpenFile; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | use constant { | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | OPTIONS_DIRECTORY_FILE => 0x00000001, | |||||||||||||||||||||||||||||||||||||||||
| 27 | OPTIONS_WRITE_THROUGH => 0x00000002, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | OPTIONS_SEQUENTIAL_ONLY => 0x00000004, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | OPTIONS_NO_INTERMEDIATE_BUFFERING => 0x00000008, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | OPTIONS_SYNCHRONOUS_IO_ALERT => 0x00000010, | ||||||||||||||||||||||||||||||||||||||||||
| 31 | OPTIONS_SYNCRHONOUS_IO_NONALERT => 0x00000020, | ||||||||||||||||||||||||||||||||||||||||||
| 32 | OPTIONS_NON_DIRECTORY_FILE => 0x00000040, | ||||||||||||||||||||||||||||||||||||||||||
| 33 | OPTIONS_COMPLETE_IF_OPLOCKED => 0x00000100, | ||||||||||||||||||||||||||||||||||||||||||
| 34 | OPTIONS_NO_EA_KNOWLEDGE => 0x00000200, | ||||||||||||||||||||||||||||||||||||||||||
| 35 | OPTIONS_RANDOM_ACCESS => 0x00000800, | ||||||||||||||||||||||||||||||||||||||||||
| 36 | OPTIONS_DELETE_ON_CLOSE => 0x00001000, | ||||||||||||||||||||||||||||||||||||||||||
| 37 | OPTIONS_OPEN_BY_FILE_ID => 0x00002000, | ||||||||||||||||||||||||||||||||||||||||||
| 38 | OPTIONS_OPEN_FOR_BACKUP_INTENT => 0x00004000, | ||||||||||||||||||||||||||||||||||||||||||
| 39 | OPTIONS_NO_COMPRESSION => 0x00008000, | ||||||||||||||||||||||||||||||||||||||||||
| 40 | OPTIONS_RESERVE_OPFILTER => 0x00100000, | ||||||||||||||||||||||||||||||||||||||||||
| 41 | OPTIONS_OPEN_REPARSE_POINT => 0x00200000, | ||||||||||||||||||||||||||||||||||||||||||
| 42 | OPTIONS_OPEN_NO_RECALL => 0x00400000, | ||||||||||||||||||||||||||||||||||||||||||
| 43 | OPTIONS_OPEN_FOR_FREE_SPACE_QUERY => 0x00800000, | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | ▶ | }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | sub init ($) { | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | $_[0]->set( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | security_flags => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 49 | oplock => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 50 | impersonation => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 51 | create_flags => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 52 | access_mask => 0x81, | ||||||||||||||||||||||||||||||||||||||||||
| 53 | file_attributes => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 54 | share_access => 3, | ||||||||||||||||||||||||||||||||||||||||||
| 55 | disposition => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 56 | options => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 57 | file_name => '', | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | flags => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 60 | fid => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 61 | openfile => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 62 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | sub parse ($$) { | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | my $parser = shift; | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if ($self->is_response) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | my $file = SMB::File->new(name => $self->file_name); | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | $self->oplock($parser->uint8); | |||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | $self->flags($parser->uint8); | |||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | my $action = $parser->uint32; | |||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | my @file_params = ( | |||||||||||||||||||||||||||||||||||||||||
| 77 | $parser->uint64, # creation_time | ||||||||||||||||||||||||||||||||||||||||||
| 78 | $parser->uint64, # last_access_time | ||||||||||||||||||||||||||||||||||||||||||
| 79 | $parser->uint64, # last_write_time | ||||||||||||||||||||||||||||||||||||||||||
| 80 | $parser->uint64, # change_time | ||||||||||||||||||||||||||||||||||||||||||
| 81 | $parser->uint64, # allocation_size | ||||||||||||||||||||||||||||||||||||||||||
| 82 | $parser->uint64, # end_of_file | ||||||||||||||||||||||||||||||||||||||||||
| 83 | $parser->uint32, # attributes | ||||||||||||||||||||||||||||||||||||||||||
| 84 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $file->update(@file_params); | |||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | $parser->uint32; # reserved | |||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $self->fid($parser->fid2); | |||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $self->openfile(SMB::OpenFile->new($file, 0, $action)); | |||||||||||||||||||||||||||||||||||||||||
| 90 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | $self->security_flags($parser->uint8); | |||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $self->oplock($parser->uint8); | |||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | $self->impersonation($parser->uint32); | |||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | $self->create_flags($parser->uint64); | |||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | $parser->uint64; # reserved | |||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | $self->access_mask($parser->uint32); | |||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | $self->file_attributes($parser->uint32); | |||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | $self->share_access($parser->uint32); | |||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | $self->disposition($parser->uint32); | |||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | $self->options($parser->uint32); | |||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | my $name_offset = $parser->uint16; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | my $name_len = $parser->uint16; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $parser->uint32(0); # contexts | |||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $parser->uint32(0); | |||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | $self->file_name($parser->utf16($name_len)); | |||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | sub pack ($$) { | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pack: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | my $packer = shift; | |||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | if ($self->is_response) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | my $openfile = $self->openfile; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | my $file = $openfile && $openfile->file; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$openfile && $openfile->file
MC/DC0%0/2
$openfile && $openfile->file
$openfile
$openfile->file
Truth table0%0/3
A && B
A= $openfileB= $openfile->file
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | return $self->abort_pack($packer, SMB::STATUS_NO_SUCH_FILE) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$file and $file->exists and $self->fid
$file and $file->exists
MC/DC0%0/3
$file and $file->exists and $self->fid
$file
$file->exists
$self->fid
Truth table0%0/4
A and B and C
A= $fileB= $file->existsC= $self->fid
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | unless $file && $file->exists && $self->fid; | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $packer | |||||||||||||||||||||||||||||||||||||||||
| 123 | ->uint8($self->oplock) | ||||||||||||||||||||||||||||||||||||||||||
| 124 | ->uint8($self->flags) | ||||||||||||||||||||||||||||||||||||||||||
| 125 | ->uint32($openfile->action) | ||||||||||||||||||||||||||||||||||||||||||
| 126 | ->uint64($file->creation_time) | ||||||||||||||||||||||||||||||||||||||||||
| 127 | ->uint64($file->last_access_time) | ||||||||||||||||||||||||||||||||||||||||||
| 128 | ->uint64($file->last_write_time) | ||||||||||||||||||||||||||||||||||||||||||
| 129 | ->uint64($file->change_time) | ||||||||||||||||||||||||||||||||||||||||||
| 130 | ->uint64($file->allocation_size) | ||||||||||||||||||||||||||||||||||||||||||
| 131 | ->uint64($file->end_of_file) | ||||||||||||||||||||||||||||||||||||||||||
| 132 | ->uint32($file->attributes) | ||||||||||||||||||||||||||||||||||||||||||
| 133 | ->uint32(0) # reserved | ||||||||||||||||||||||||||||||||||||||||||
| 134 | ->fid2($self->fid) | ||||||||||||||||||||||||||||||||||||||||||
| 135 | ->uint32(0) # contexts | ||||||||||||||||||||||||||||||||||||||||||
| 136 | ->uint32(0) | ||||||||||||||||||||||||||||||||||||||||||
| 137 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 138 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | $packer | |||||||||||||||||||||||||||||||||||||||||
| 140 | ->uint8($self->security_flags) | ||||||||||||||||||||||||||||||||||||||||||
| 141 | ->uint8($self->oplock) | ||||||||||||||||||||||||||||||||||||||||||
| 142 | ->uint32($self->impersonation) | ||||||||||||||||||||||||||||||||||||||||||
| 143 | ->uint64($self->create_flags) | ||||||||||||||||||||||||||||||||||||||||||
| 144 | ->uint64(0) # reserved | ||||||||||||||||||||||||||||||||||||||||||
| 145 | ->uint32($self->access_mask) | ||||||||||||||||||||||||||||||||||||||||||
| 146 | ->uint32($self->file_attributes) | ||||||||||||||||||||||||||||||||||||||||||
| 147 | ->uint32($self->share_access) | ||||||||||||||||||||||||||||||||||||||||||
| 148 | ->uint32($self->disposition) | ||||||||||||||||||||||||||||||||||||||||||
| 149 | ->uint32($self->options) | ||||||||||||||||||||||||||||||||||||||||||
| 150 | ->uint16($packer->diff('smb-header') + 12) | ||||||||||||||||||||||||||||||||||||||||||
| 151 | ->uint16(length($self->file_name) * 2) | ||||||||||||||||||||||||||||||||||||||||||
| 152 | ->uint32(0) # contexts | ||||||||||||||||||||||||||||||||||||||||||
| 153 | ->uint32(0) | ||||||||||||||||||||||||||||||||||||||||||
| 154 | ->utf16($self->file_name) | ||||||||||||||||||||||||||||||||||||||||||
| 155 | ->uint8(0) | ||||||||||||||||||||||||||||||||||||||||||
| 156 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | sub requested_directory ($) { | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
requested_directory: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | return $self->options & OPTIONS_DIRECTORY_FILE ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | sub requested_non_directory ($) { | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
requested_non_directory: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | return $self->options & OPTIONS_NON_DIRECTORY_FILE ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||