| 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::Close; | ||
| 17 | |||
| 18 | use strict; | ||
| 19 | use warnings; | ||
| 20 | |||
| 21 | use parent 'SMB::v2::Command'; | ||
| 22 | |||
| 23 | use constant { | ||
| 24 | FLAGS_POSTQUERY_ATTRIB => 1, | ||
| 25 | }; | ||
| 26 | |||
| 27 | sub init ($) { | ||
| 28 | $_[0]->set( | ||
| 29 | flags => 0, | ||
| 30 | fid => 0, | ||
| 31 | openfile => undef, | ||
| 32 | ) | ||
| 33 | } | ||
| 34 | |||
| 35 | sub parse ($$) { | ||
| 36 | my $self = shift; | ||
| 37 | my $parser = shift; | ||
| 38 | |||
| 39 | if ($self->is_response) { | ||
| 40 | my $openfile = $self->openfile; | ||
| 41 | my $file = $openfile && $openfile->file; | ||
| 42 | |||
| 43 | $self->flags($parser->uint16); | ||
| 44 | $parser->uint32; # reserved | ||
| 45 | my @values = ((map { $parser->uint64 } 1 .. 6), $parser->uint32); | ||
| 46 | $file->update(@values) if $file; | ||
| 47 | } else { | ||
| 48 | $self->flags($parser->uint16); | ||
| 49 | $parser->uint32; # reserved | ||
| 50 | $self->fid($parser->fid2); | ||
| 51 | } | ||
| 52 | |||
| 53 | return $self; | ||
| 54 | } | ||
| 55 | |||
| 56 | sub pack ($$) { | ||
| 57 | my $self = shift; | ||
| 58 | my $packer = shift; | ||
| 59 | |||
| 60 | if ($self->is_response) { | ||
| 61 | my $openfile = $self->openfile; | ||
| 62 | my $file = $openfile && $openfile->file; | ||
| 63 | |||
| 64 | return $self->abort_pack($packer, SMB::STATUS_FILE_CLOSED) | ||
| 65 | unless $file && $file->exists; | ||
| 66 | |||
| 67 | my $skip_attr = !($self->flags & FLAGS_POSTQUERY_ATTRIB); | ||
| 68 | |||
| 69 | $packer | ||
| 70 | ->uint16($self->flags) | ||
| 71 | ->uint32(0) # reserved | ||
| 72 | ->uint64($skip_attr ? 0 : $file->creation_time) | ||
| 73 | ->uint64($skip_attr ? 0 : $file->last_access_time) | ||
| 74 | ->uint64($skip_attr ? 0 : $file->last_write_time) | ||
| 75 | ->uint64($skip_attr ? 0 : $file->change_time) | ||
| 76 | ->uint64($skip_attr ? 0 : $file->allocation_size) | ||
| 77 | ->uint64($skip_attr ? 0 : $file->end_of_file) | ||
| 78 | ->uint32($skip_attr ? 0 : $file->attributes) | ||
| 79 | ; | ||
| 80 | } else { | ||
| 81 | $packer | ||
| 82 | ->uint16($self->flags) | ||
| 83 | ->uint32(0) # reserved | ||
| 84 | ->fid2($self->fid || die "No fid set") | ||
| 85 | ; | ||
| 86 | } | ||
| 87 | } | ||
| 88 | |||
| 89 | 1; |