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

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 48 SCAR 30.0
CC
4
Cov
0%
verify_uri
6.0
parse
6.0
pack
6.0
CRAP 20.0
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::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 )
31 }
32  
33 sub verify_uri ($) {
34 my $self = shift;
35  
36 die "Tree connect $self misses share uri\n"
37 unless $self->parse_share_uri($self->uri);
38  
39 return $self->uri;
40 }
41  
42 sub parse ($$) {
43 my $self = shift;
44 my $parser = shift;
45  
46 if ($self->is_response) {
47 $self->share_type($parser->uint8);
48 $parser->uint8; # reserved
49 $self->share_flags($parser->uint32);
50 $self->capabilities($parser->uint32);
51 $self->access_mask($parser->uint32);
52 } else {
53 $parser->uint16; # reserved
54 $parser->uint16;
55 my $uri_len = $parser->uint16;
56 $self->uri($parser->utf16($uri_len));
57 }
58  
59 return $self;
60 }
61  
62 sub pack ($$) {
63 my $self = shift;
64 my $packer = shift;
65  
66 if ($self->is_response) {
67 $packer
68 ->uint8($self->share_type)
69 ->uint8(0) # reserved
70 ->uint32($self->share_flags)
71 ->uint32($self->capabilities)
72 ->uint32($self->access_mask)
73 ;
74 } else {
75 $packer
76 ->uint16(0) # reserved
77 ->uint16($packer->diff('smb-header') + 4)
78 ->stub('uri-len', 'uint16')
79 ->mark('uri')
80 ->utf16($self->verify_uri)
81 ->fill('uri-len', $packer->diff('uri'))
82 ;
83 }
84 }
85  
86 1;