Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Nextcloud
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Nextcloud
Commits
cfc2d0b8
Commit
cfc2d0b8
authored
9 years ago
by
Robin Appelman
Browse files
Options
Downloads
Plain Diff
Merge pull request #20534 from owncloud/sftp-parse-host
Fix parsing of sftp hosts when using ipv6
parents
8169e4fd
67710e62
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
apps/files_external/lib/sftp.php
+24
-14
24 additions, 14 deletions
apps/files_external/lib/sftp.php
apps/files_external/tests/backends/sftp.php
+38
-0
38 additions, 0 deletions
apps/files_external/tests/backends/sftp.php
with
62 additions
and
14 deletions
apps/files_external/lib/sftp.php
+
24
−
14
View file @
cfc2d0b8
...
@@ -51,6 +51,27 @@ class SFTP extends \OC\Files\Storage\Common {
...
@@ -51,6 +51,27 @@ class SFTP extends \OC\Files\Storage\Common {
*/
*/
protected
$client
;
protected
$client
;
/**
* @param string $host protocol://server:port
* @return array [$server, $port]
*/
private
function
splitHost
(
$host
)
{
$input
=
$host
;
if
(
strpos
(
$host
,
'://'
)
===
false
)
{
// add a protocol to fix parse_url behavior with ipv6
$host
=
'http://'
.
$host
;
}
$parsed
=
parse_url
(
$host
);
if
(
is_array
(
$parsed
)
&&
isset
(
$parsed
[
'port'
]))
{
return
[
$parsed
[
'host'
],
$parsed
[
'port'
]];
}
else
if
(
is_array
(
$parsed
))
{
return
[
$parsed
[
'host'
],
22
];
}
else
{
return
[
$input
,
22
];
}
}
/**
/**
* {@inheritdoc}
* {@inheritdoc}
*/
*/
...
@@ -58,21 +79,10 @@ class SFTP extends \OC\Files\Storage\Common {
...
@@ -58,21 +79,10 @@ class SFTP extends \OC\Files\Storage\Common {
// Register sftp://
// Register sftp://
Stream
::
register
();
Stream
::
register
();
$
this
->
host
=
$params
[
'host'
];
$
parsedHost
=
$this
->
splitHost
(
$params
[
'host'
]
)
;
//deals with sftp://server example
$this
->
host
=
$parsedHost
[
0
];
$proto
=
strpos
(
$this
->
host
,
'://'
);
$this
->
port
=
$parsedHost
[
1
];
if
(
$proto
!=
false
)
{
$this
->
host
=
substr
(
$this
->
host
,
$proto
+
3
);
}
//deals with server:port
$hasPort
=
strpos
(
$this
->
host
,
':'
);
if
(
$hasPort
!=
false
)
{
$pieces
=
explode
(
":"
,
$this
->
host
);
$this
->
host
=
$pieces
[
0
];
$this
->
port
=
$pieces
[
1
];
}
$this
->
user
=
$params
[
'user'
];
$this
->
user
=
$params
[
'user'
];
...
...
This diff is collapsed.
Click to expand it.
apps/files_external/tests/backends/sftp.php
+
38
−
0
View file @
cfc2d0b8
...
@@ -26,6 +26,11 @@
...
@@ -26,6 +26,11 @@
namespace
Test\Files\Storage
;
namespace
Test\Files\Storage
;
class
SFTP
extends
Storage
{
class
SFTP
extends
Storage
{
/**
* @var \OC\Files\Storage\SFTP instance
*/
protected
$instance
;
private
$config
;
private
$config
;
protected
function
setUp
()
{
protected
function
setUp
()
{
...
@@ -103,6 +108,39 @@ class SFTP extends Storage {
...
@@ -103,6 +108,39 @@ class SFTP extends Storage {
],
],
'sftp::someuser@somehost:8822//remotedir/subdir/'
,
'sftp::someuser@somehost:8822//remotedir/subdir/'
,
],
],
[
// ipv6 with port
[
'run'
=>
true
,
'host'
=>
'FE80:0000:0000:0000:0202:B3FF:FE1E:8329'
,
'user'
=>
'someuser'
,
'password'
=>
'somepassword'
,
'root'
=>
'remotedir/subdir/'
,
],
'sftp::someuser@FE80:0000:0000:0000:0202:B3FF:FE1E:8329//remotedir/subdir/'
,
],
[
// ipv6 without port
[
'run'
=>
true
,
'host'
=>
'FE80:0000:0000:0000:0202:B3FF:FE1E:8329:8822'
,
'user'
=>
'someuser'
,
'password'
=>
'somepassword'
,
'root'
=>
'remotedir/subdir/'
,
],
'sftp::someuser@FE80:0000:0000:0000:0202:B3FF:FE1E:8329:8822//remotedir/subdir/'
,
],
[
// collapsed ipv6 with port
[
'run'
=>
true
,
'host'
=>
'FE80::0202:B3FF:FE1E:8329:8822'
,
'user'
=>
'someuser'
,
'password'
=>
'somepassword'
,
'root'
=>
'remotedir/subdir/'
,
],
'sftp::someuser@FE80::0202:B3FF:FE1E:8329:8822//remotedir/subdir/'
,
],
];
];
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment