| 1 | package URI::smb; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use parent 'URI::_login'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use URI::Escape qw(uri_escape uri_unescape); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | our $VERSION = '5.40'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | sub default_port {445} | ||||||||||||||||||||||||||
|
Subroutine
default_port: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 18 | ▶ | sub user { | ||||||||||||||||||||||||||
|
Subroutine
user: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 15 | 18 | my $self = shift; | |||||||||||||||||||||||||||
| 16 | 18 | my $new = shift; | |||||||||||||||||||||||||||
| 17 | 18 | my ($user, $authdomain) = _parse_user($self->_raw_user); | |||||||||||||||||||||||||||
| 18 | 18 | ▶ | if ($new) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 7 | ▶ | $self->_raw_user($authdomain | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | ? _smb_escape($authdomain) . ';' . _smb_escape($new) | ||||||||||||||||||||||||||||
| 21 | : _smb_escape($new)); | ||||||||||||||||||||||||||||
| 22 | 7 | $user = $new; | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | 18 | return $user; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 13 | ▶ | sub authdomain { | ||||||||||||||||||||||||||
|
Subroutine
authdomain: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | 13 | my $self = shift; | |||||||||||||||||||||||||||
| 29 | 13 | my $new = shift; | |||||||||||||||||||||||||||
| 30 | 13 | my ($user, $authdomain) = _parse_user($self->_raw_user); | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | # it must not be possible to set authdomain without user | ||||||||||||||||||||||||||||
| 33 | 13 | ▶ | if ($user && $new) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$user and $new
MC/DC100%2/2
$user and $new
$user
$new
Truth table100%3/3
A and B
A= $userB= $new
| |||||||||||||||||||||||||||||
| 34 | 3 | $self->_raw_user(_smb_escape($new) . ';' . _smb_escape($user)); | |||||||||||||||||||||||||||
| 35 | 3 | $authdomain = $new; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | 13 | return $authdomain; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 1 | ▶ | sub sharename { | ||||||||||||||||||||||||||
|
Subroutine
sharename: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | 1 | return (shift->path_segments)[1]; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | # The 'authdomain;user' slice of userinfo, still percent-encoded, so that ';' | ||||||||||||||||||||||||||||
| 45 | # is split before it is decoded (a %3B in a username is data, not a delimiter). | ||||||||||||||||||||||||||||
| 46 | 41 | ▶ | sub _raw_user { | ||||||||||||||||||||||||||
|
Subroutine
_raw_user: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 47 | 41 | my $self = shift; | |||||||||||||||||||||||||||
| 48 | 41 | my $info = $self->userinfo; | |||||||||||||||||||||||||||
| 49 | 41 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 10 | ▶ | my $pass = defined($info) ? $info : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 10 | $pass =~ s/^[^:]*//; | |||||||||||||||||||||||||||
| 52 | 10 | $self->userinfo(shift(@_) . $pass); | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | 41 | ▶ | return undef unless defined $info; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 30 | $info =~ s/:.*//; | |||||||||||||||||||||||||||
| 56 | 30 | return $info; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | # userinfo() escapes everything except '%', ';' and ':', which here start an | ||||||||||||||||||||||||||||
| 60 | # escape or delimit authdomain;user:password, so escape those ourselves. | ||||||||||||||||||||||||||||
| 61 | 15 | ▶ | sub _smb_escape { | ||||||||||||||||||||||||||
|
Subroutine
_smb_escape: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 62 | 15 | my $str = shift; | |||||||||||||||||||||||||||
| 63 | 15 | return uri_escape($str, '%;:'); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 31 | ▶ | sub _parse_user { | ||||||||||||||||||||||||||
|
Subroutine
_parse_user: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 67 | 31 | ▶ | my $input = shift or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 23 | my ($authdomain, $user) = split ';', $input, 2; | |||||||||||||||||||||||||||
| 69 | 23 | ▶ | return $user | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | ? (uri_unescape($user), uri_unescape($authdomain)) | ||||||||||||||||||||||||||||
| 71 | : uri_unescape($authdomain); | ||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 1 | 1; | |||||||||||||||||||||||||||
| 75 | __END__ | ||||||||||||||||||||||||||||