| 1 | # SMB Perl library, Copyright (C) 2014-2018 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::QueryInfo; | ||
| 17 | |||
| 18 | use strict; | ||
| 19 | use warnings; | ||
| 20 | |||
| 21 | use parent 'SMB::v2::Command'; | ||
| 22 | |||
| 23 | use constant { | ||
| 24 | TYPE_FILE => 1, | ||
| 25 | TYPE_FILESYSTEM => 2, | ||
| 26 | TYPE_SECURITY => 3, | ||
| 27 | TYPE_QUOTA => 4, | ||
| 28 | |||
| 29 | FILE_LEVEL_DIRECTORY => 1, | ||
| 30 | FILE_LEVEL_FULLDIRECTORY => 2, | ||
| 31 | FILE_LEVEL_BOTHDIRECTORY => 3, | ||
| 32 | FILE_LEVEL_BASIC => 4, | ||
| 33 | FILE_LEVEL_STANDARD => 5, | ||
| 34 | FILE_LEVEL_INTERNAL => 6, | ||
| 35 | FILE_LEVEL_EA => 7, | ||
| 36 | FILE_LEVEL_ACCESS => 8, | ||
| 37 | FILE_LEVEL_NAMES => 12, | ||
| 38 | FILE_LEVEL_POSITION => 14, | ||
| 39 | FILE_LEVEL_FULLEA => 15, | ||
| 40 | FILE_LEVEL_MODE => 16, | ||
| 41 | FILE_LEVEL_ALIGNMENT => 17, | ||
| 42 | FILE_LEVEL_ALL => 18, | ||
| 43 | FILE_LEVEL_ALTERNATENAME => 21, | ||
| 44 | FILE_LEVEL_STREAM => 22, | ||
| 45 | FILE_LEVEL_PIPE => 23, | ||
| 46 | FILE_LEVEL_PIPELOCAL => 24, | ||
| 47 | FILE_LEVEL_PIPEREMOTE => 25, | ||
| 48 | FILE_LEVEL_COMPRESSION => 28, | ||
| 49 | FILE_LEVEL_QUOTA => 32, | ||
| 50 | FILE_LEVEL_NETWORKOPEN => 34, | ||
| 51 | FILE_LEVEL_ATTRIBUTETAG => 35, | ||
| 52 | FILE_LEVEL_IDBOTHDIRECTORY => 37, | ||
| 53 | FILE_LEVEL_IDFULLDIRECTORY => 38, | ||
| 54 | |||
| 55 | FS_LEVEL_VOLUMEINFORMATION => 1, | ||
| 56 | FS_LEVEL_SIZEINFORMATION => 3, | ||
| 57 | FS_LEVEL_DEVICEINFORMATION => 4, | ||
| 58 | FS_LEVEL_ATTRIBUTEINFORMATION => 5, | ||
| 59 | FS_LEVEL_CONTROLINFORMATION => 6, | ||
| 60 | FS_LEVEL_FULLSIZEINFORMATION => 7, | ||
| 61 | FS_LEVEL_OBJECTIDINFORMATION => 8, | ||
| 62 | FS_LEVEL_SECTORSIZEINFORMATION => 11, | ||
| 63 | }; | ||
| 64 | |||
| 65 | sub init ($) { | ||
| 66 | $_[0]->set( | ||
| 67 | type => 0, | ||
| 68 | level => 0, | ||
| 69 | max_length => 65536, | ||
| 70 | additional => 0, | ||
| 71 | flags => 0, | ||
| 72 | buffer => undef, | ||
| 73 | fid => 0, | ||
| 74 | openfile => undef, | ||
| 75 | files => undef, | ||
| 76 | ) | ||
| 77 | } | ||
| 78 | |||
| 79 | sub parse ($$) { | ||
| 80 | my $self = shift; | ||
| 81 | my $parser = shift; | ||
| 82 | |||
| 83 | if ($self->is_response) { | ||
| 84 | my $offset = $parser->uint16; | ||
| 85 | my $length = $parser->uint32; | ||
| 86 | $self->buffer($parser->bytes($length)); | ||
| 87 | } else { | ||
| 88 | $self->type($parser->uint8); | ||
| 89 | $self->level($parser->uint8); | ||
| 90 | $self->max_length($parser->uint32); | ||
| 91 | my $offset = $parser->uint16; | ||
| 92 | $parser->skip(2); # reserved | ||
| 93 | my $length = $parser->uint32; | ||
| 94 | $self->additional($parser->uint32); | ||
| 95 | $self->flags($parser->uint32); | ||
| 96 | $self->fid($parser->fid2); | ||
| 97 | $self->buffer($parser->bytes($length)); | ||
| 98 | } | ||
| 99 | |||
| 100 | return $self; | ||
| 101 | } | ||
| 102 | |||
| 103 | sub pack ($$) { | ||
| 104 | my $self = shift; | ||
| 105 | my $packer = shift; | ||
| 106 | |||
| 107 | my $buffer = $self->buffer; | ||
| 108 | |||
| 109 | if ($self->is_response) { | ||
| 110 | $packer | ||
| 111 | ->uint16($packer->diff('smb-header') + 6) | ||
| 112 | ->uint32(defined $buffer ? length($buffer) : 0) | ||
| 113 | ->bytes($buffer // '') | ||
| 114 | ; | ||
| 115 | } else { | ||
| 116 | $packer | ||
| 117 | ->uint8($self->type) | ||
| 118 | ->uint8($self->level) | ||
| 119 | ->uint32($self->max_length) | ||
| 120 | ->uint16($packer->diff('smb-header') + 32) | ||
| 121 | ->uint16(0) # reserved | ||
| 122 | ->uint32(defined $buffer ? length($buffer) : 0) | ||
| 123 | ->uint32($self->additional) | ||
| 124 | ->uint32($self->flags) | ||
| 125 | ->fid2($self->fid || die "No fid set") | ||
| 126 | ->bytes($buffer // '') | ||
| 127 | ; | ||
| 128 | } | ||
| 129 | } | ||
| 130 | |||
| 131 | 1; |