File Coverage

lib/SMB/v2/Command/Read.pm
Criterion Covered Total %
statement 12 41 29.2
branch 0 4 0.0
condition 0 4 0.0
subroutine 4 7 57.1
pod 0 3 0.0
total 16 59 27.1


line stmt bran cond sub pod time code
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 .
15              
16             package SMB::v2::Command::Read;
17              
18 1     1   6 use strict;
  1         2  
  1         40  
19 1     1   6 use warnings;
  1         2  
  1         28  
20              
21 1     1   7 use parent 'SMB::v2::Command';
  1         1  
  1         6  
22              
23             use constant {
24 1         499 FLAGS_READ_UNBUFFERED => 1, # SMB 3.02
25              
26             CHANNEL_NONE => 0,
27             CHANNEL_RDMA_V1 => 1, # SMB 3.*
28             CHANNEL_RDMA_V1_INVALIDATE => 2, # SMB 3.02
29 1     1   88 };
  1         2  
30              
31             sub init ($) {
32 0     0 0   $_[0]->set(
33             flags => 0,
34             length => 0,
35             offset => 0,
36             minimum_count => 0,
37             channel => 0,
38             remaining_bytes => 0,
39             fid => 0,
40             openfile => undef,
41             buffer => undef,
42             )
43             }
44              
45             sub parse ($$) {
46 0     0 0   my $self = shift;
47 0           my $parser = shift;
48              
49 0 0         if ($self->is_response) {
50 0           my $offset = $parser->uint8;
51 0           $parser->uint8; # reserved
52 0           my $length = $parser->uint32;
53 0           $self->length($length);
54 0           $self->remaining_bytes($parser->uint32);
55 0           $parser->uint32; # reserved
56 0           $self->buffer($parser->bytes($length));
57             } else {
58 0           $parser->uint8; # padding
59 0           $self->flags($parser->uint8);
60 0           $self->length($parser->uint32);
61 0           $self->offset($parser->uint64);
62 0           $self->fid($parser->fid2);
63 0           $self->minimum_count($parser->uint32);
64 0           $self->channel($parser->uint32);
65 0           $self->remaining_bytes($parser->uint32);
66 0           $parser->uint16; # channel info offset
67 0           $parser->uint16; # channel info length
68 0           $parser->uint8; # channel buffer
69             }
70              
71 0           return $self;
72             }
73              
74             sub pack ($$) {
75 0     0 0   my $self = shift;
76 0           my $packer = shift;
77              
78 0 0         if ($self->is_response) {
79 0   0       my $buffer = $self->buffer // die "No buffer";
80              
81 0           $packer
82             ->uint8($packer->diff('smb-header') + 14)
83             ->uint32(length $buffer)
84             ->uint32($self->remaining_bytes)
85             ->uint32(0) # reserved
86             ->bytes ($buffer)
87             ;
88             } else {
89 0   0       $packer
90             ->uint8(0) # padding
91             ->uint8($self->flags)
92             ->uint32($self->length)
93             ->uint64($self->offset)
94             ->fid2($self->fid || die "No fid set")
95             ->uint32($self->minimum_count)
96             ->uint32($self->channel)
97             ->uint32($self->remaining_bytes)
98             ->uint16(0) # channel info offset
99             ->uint16(0) # channel info length
100             ->uint8(0) # channel buffer
101             ;
102             }
103             }
104              
105             1;