File Coverage

lib/SMB/v2/Command/TreeConnect.pm
Criterion Covered Total %
statement 9 31 29.0
branch 0 6 0.0
condition n/a
subroutine 3 7 42.8
pod 0 4 0.0
total 12 48 25.0


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::TreeConnect;
17              
18 1     1   6 use strict;
  1         1  
  1         36  
19 1     1   6 use warnings;
  1         2  
  1         35  
20              
21 1     1   6 use parent 'SMB::v2::Command';
  1         1  
  1         4  
22              
23             sub init ($) {
24 0     0 0   $_[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 0     0 0   my $self = shift;
35              
36 0 0         die "Tree connect $self misses share uri\n"
37             unless $self->parse_share_uri($self->uri);
38              
39 0           return $self->uri;
40             }
41              
42             sub parse ($$) {
43 0     0 0   my $self = shift;
44 0           my $parser = shift;
45              
46 0 0         if ($self->is_response) {
47 0           $self->share_type($parser->uint8);
48 0           $parser->uint8; # reserved
49 0           $self->share_flags($parser->uint32);
50 0           $self->capabilities($parser->uint32);
51 0           $self->access_mask($parser->uint32);
52             } else {
53 0           $parser->uint16; # reserved
54 0           $parser->uint16;
55 0           my $uri_len = $parser->uint16;
56 0           $self->uri($parser->utf16($uri_len));
57             }
58              
59 0           return $self;
60             }
61              
62             sub pack ($$) {
63 0     0 0   my $self = shift;
64 0           my $packer = shift;
65              
66 0 0         if ($self->is_response) {
67 0           $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 0           $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;