Skip to content

Commit 835e708

Browse files
I. M. Buroalders
authored andcommitted
Implement URI::smb
Rework to enable updating user and authdomain disable fail-fast to troubleshoot builds Exclude Strawberry v5.16 URI::Heuristic recognizing UNC paths as SMB Add smb section to README Formal changes
1 parent 838ae63 commit 835e708

File tree

8 files changed

+159
-2
lines changed

8 files changed

+159
-2
lines changed

.github/workflows/dzil-build-and-test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,19 @@ jobs:
6868
- "5.32"
6969
- "5.34"
7070
- "5.36"
71+
- "5.38"
72+
- "5.40"
7173
exclude:
7274
- { os: windows-latest, distribution: default }
7375
- { os: macos-latest, distribution: strawberry }
7476
- { os: ubuntu-latest, distribution: strawberry }
75-
- { distribution: strawberry, perl-version: "5.8" }
7677
- { distribution: strawberry, perl-version: "5.10" }
7778
- { distribution: strawberry, perl-version: "5.12" }
7879
- { distribution: strawberry, perl-version: "5.14" }
7980
- { distribution: strawberry, perl-version: "5.16" }
8081
- { distribution: strawberry, perl-version: "5.34" }
8182
- { distribution: strawberry, perl-version: "5.36" }
83+
- { distribution: strawberry, perl-version: "5.8" }
8284
runs-on: ${{ matrix.os }}
8385
name: on ${{ matrix.os }} perl ${{ matrix.perl-version }}
8486
steps:

Changes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Revision history for URI
22

33
{{$NEXT}}
4+
- Add smb scheme (buralien)
45

56
5.31 2024-11-06 03:38:29Z
67
- Re-releasing with corrected module permissions. No changes since 5.31

dist.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ stopword = TOTP
157157
stopword = HOTP
158158
stopword = OTP
159159
stopword = cryptographic
160+
stopword = authdomain
161+
stopword = sharename
160162

161163
;;; pre-release actions
162164

lib/URI.pm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,13 @@ I<sip> parameters: $uri->params_form and $uri->params.
11531153
See I<sip> scheme. Its syntax is the same as sip, but the default
11541154
port is different.
11551155
1156+
=item B<smb>:
1157+
1158+
C<URI> objects belonging to the smb scheme support the common,
1159+
generic and server methods. In addition, they provide methods to
1160+
access the userinfo sub-components ($uri->user and $uri->password)
1161+
as well as $uri->authdomain and $uri->sharename methods.
1162+
11561163
=item B<snews>:
11571164
11581165
See I<news> scheme. Its syntax is the same as news, but the default

lib/URI/Heuristic.pm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ sub uf_uristr ($)
158158
} elsif (/^(ftp|gopher|news|wais|https|http)[a-z0-9-]*(?:\.|$)/i) {
159159
$_ = lc($1) . "://$_";
160160

161+
} elsif (
162+
m,^//, || m,^[\\][\\],) # UNC-like file name
163+
{
164+
s{[\\]}{/}g;
165+
$_ = "smb:$_";
161166
} elsif ($^O ne "MacOS" &&
162167
(m,^/, || # absolute file name
163168
m,^\.\.?/, || # relative file name

lib/URI/smb.pm

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package URI::smb;
2+
3+
use strict;
4+
use warnings;
5+
6+
use parent 'URI::_login';
7+
8+
our $VERSION = '5.32';
9+
10+
sub default_port { 445 }
11+
12+
sub user {
13+
my $self = shift;
14+
my $new = shift;
15+
my ($user, $authdomain) = _parse_user($self->SUPER::user());
16+
if ($new) {
17+
$self->SUPER::user($authdomain ? "$authdomain;$new" : $new);
18+
$user = $new;
19+
}
20+
return $user;
21+
}
22+
23+
sub authdomain {
24+
my $self = shift;
25+
my $new = shift;
26+
my ($user, $authdomain) = _parse_user($self->SUPER::user());
27+
28+
# it must not be possible to set authdomain without user
29+
if ($user && $new) {
30+
$self->SUPER::user("$new;$user");
31+
$authdomain = $new;
32+
}
33+
return $authdomain;
34+
}
35+
36+
sub sharename {
37+
return (shift->path_segments)[1];
38+
}
39+
40+
sub _parse_user {
41+
my $input = shift or return;
42+
my ($authdomain, $user) = split ';', $input, 2;
43+
return $user ? ($user, $authdomain) : $authdomain;
44+
}
45+
46+
1;
47+
__END__
48+
49+
=head1 NAME
50+
51+
URI::smb - Samba/CIFS URI scheme
52+
53+
=head1 SYNOPSIS
54+
55+
my $uri = URI->new('smb://authdomain;user:password@server/share/path');
56+
57+
=head1 DESCRIPTION
58+
59+
This module implements the (unofficial) C<smb:> URI scheme described in L<http://www.ubiqx.org/cifs/Appendix-D.html>.
60+
61+
=head1 SUBROUTINES/METHODS
62+
63+
=head2 default_port
64+
65+
The default port for accessing Samba/Windows File Servers is 445
66+
67+
=head2 user
68+
69+
Get or set the user part of the URI (without the authdomain)
70+
71+
=head2 authdomain
72+
73+
Get or set the authentication authdomain part of the URI. This value is only available if the user is already set.
74+
75+
=head2 sharename
76+
77+
Helper method to get the share name from path
78+
79+
=head1 DEPENDENCIES
80+
81+
None
82+
83+
=head1 BUGS AND LIMITATIONS
84+
85+
See L<URI|URI#BUGS>
86+
87+
=head1 SEE ALSO
88+
89+
L<http://www.ubiqx.org/cifs/Appendix-D.html>
90+
91+
=head1 AUTHOR
92+
93+
I. M. Bur <[email protected]>
94+
95+
=head1 LICENSE AND COPYRIGHT
96+
97+
This program is free software; you can redistribute it and/or modify it
98+
under the terms of either: the GNU General Public License as published
99+
by the Free Software Foundation; or the Artistic License.
100+
101+
See L<http://dev.perl.org/licenses/> for more information.

t/heuristic.t

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ BEGIN {
1313
};
1414
}
1515

16-
use Test::More tests => 26;
16+
use Test::More tests => 28;
1717

1818
use URI::Heuristic qw( uf_url uf_urlstr );
1919
if (shift) {
@@ -102,6 +102,10 @@ is(uf_urlstr("perl"), "http://www.perl.org");
102102

103103
is(uf_urlstr("123.3.3.3:21/foo"), "ftp://123.3.3.3:21/foo");
104104

105+
is(uf_urlstr("//server/share/dir"), "smb://server/share/dir");
106+
107+
is(uf_urlstr(qq(\\\\server\\share\\dir)), "smb://server/share/dir");
108+
105109
is(uf_url("FTP.example.com")->scheme, "ftp");
106110

107111
is(uf_url("ftp2.example.com")->scheme, "ftp");

t/smb.t

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use strict;
2+
use warnings;
3+
4+
use Test::More tests => 15;
5+
6+
use URI ();
7+
my $uri;
8+
9+
$uri = URI->new('smb://domain;user:password@server/share$/path');
10+
11+
is($uri->scheme, 'smb');
12+
is($uri->authdomain, 'domain');
13+
is($uri->user, 'user');
14+
is($uri->password, 'password');
15+
is($uri->host, 'server');
16+
is($uri->port, 445);
17+
is($uri->sharename, 'share$');
18+
is($uri->path, '/share$/path');
19+
20+
$uri->userinfo(undef);
21+
22+
is($uri->authdomain, undef);
23+
is($uri->user, undef);
24+
is($uri->password, undef);
25+
is($uri->as_string, 'smb://server/share$/path');
26+
27+
# test that domain without user is not allowed
28+
$uri->authdomain('DOMAIN');
29+
is($uri->as_string, 'smb://server/share$/path');
30+
31+
$uri->user('Administrator');
32+
is($uri->as_string, 'smb://Administrator@server/share$/path');
33+
34+
$uri->authdomain('DOMAIN');
35+
is($uri->as_string, 'smb://DOMAIN;Administrator@server/share$/path');

0 commit comments

Comments
 (0)