blib/lib/SMB/v2/Command/TreeConnect.pm untested

filter: Statementstmt 0.0% 0 / 32 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 56 CC 6 SCAR 22.3
CC
6
Cov
0%
pack
20.0
verify_uri
6.0
parse
6.0
CRAP 9.3
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::TreeConnect;
17  
18 use strict;
19 use warnings;
20  
21 use parent 'SMB::v2::Command';
22  
23 sub init ($) {
24 $_[0]->set(
25 share_type => 1,
26 share_flags => 0x800,
27 capabilities => 0,
28 access_mask => 0x1f01ff,
29 uri => undef,
30 tree => undef,
31 )
32 }
33  
34 sub verify_uri ($) {
35 my $self = shift;
36  
37 die "Tree connect $self misses share uri\n"
38 unless $self->parse_share_uri($self->uri);
39  
40 return $self->uri;
41 }
42  
43 sub parse ($$) {
44 my $self = shift;
45 my $parser = shift;
46  
47 if ($self->is_response) {
48 $self->share_type($parser->uint8);
49 $parser->uint8; # reserved
50 $self->share_flags($parser->uint32);
51 $self->capabilities($parser->uint32);
52 $self->access_mask($parser->uint32);
53 } else {
54 $parser->uint16; # reserved
55 $parser->uint16;
56 my $uri_len = $parser->uint16;
57 $self->uri($parser->utf16($uri_len));
58 }
59  
60 return $self;
61 }
62  
63 sub pack ($$) {
64 my $self = shift;
65 my $packer = shift;
66  
67 if ($self->is_response) {
68 my $is_ipc = $self->tree && $self->tree->is_ipc;
69 $packer
70 ->uint8($is_ipc ? 2 : $self->share_type)
71 ->uint8(0) # reserved
72 ->uint32($is_ipc ? 0x30 : $self->share_flags)
73 ->uint32($self->capabilities)
74 ->uint32($self->access_mask)
75 ;
76 } else {
77 $packer
78 ->uint16(0) # reserved
79 ->uint16($packer->diff('smb-header') + 4)
80 ->stub('uri-len', 'uint16')
81 ->mark('uri')
82 ->utf16($self->verify_uri)
83 ->fill('uri-len', $packer->diff('uri'))
84 ;
85 }
86 }
87  
88 1;