mirror of
https://github.com/octoleo/restic.git
synced 2024-11-26 14:56:29 +00:00
Merge pull request #2423 from streambinder/master
sftp: support user@domain parsing as user
This commit is contained in:
commit
4557881066
5
changelog/unreleased/pull-2423
Normal file
5
changelog/unreleased/pull-2423
Normal file
@ -0,0 +1,5 @@
|
||||
Enhancement: support user@domain parsing as user
|
||||
|
||||
Added the ability for user@domain-like users to be authenticated over SFTP servers.
|
||||
|
||||
https://github.com/restic/restic/pull/2423
|
@ -78,6 +78,9 @@ You can also specify a relative (read: no slash (``/``) character at the
|
||||
beginning) directory, in this case the dir is relative to the remote
|
||||
user's home directory.
|
||||
|
||||
Also, if the SFTP server is enforcing domain-confined users, you can
|
||||
specify the user this way: ``user@domain@host``.
|
||||
|
||||
.. note:: Please be aware that sftp servers do not expand the tilde character
|
||||
(``~``) normally used as an alias for a user's home directory. If you
|
||||
want to specify a path relative to the user's home directory, pass a
|
||||
|
@ -56,8 +56,11 @@ func ParseConfig(s string) (interface{}, error) {
|
||||
host = data[0]
|
||||
dir = data[1]
|
||||
// split user and host at the "@"
|
||||
data = strings.SplitN(host, "@", 2)
|
||||
if len(data) == 2 {
|
||||
data = strings.SplitN(host, "@", 3)
|
||||
if len(data) == 3 {
|
||||
user = data[0] + "@" + data[1]
|
||||
host = data[2]
|
||||
} else if len(data) == 2 {
|
||||
user = data[0]
|
||||
host = data[1]
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package sftp
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
var configTests = []struct {
|
||||
in string
|
||||
@ -41,6 +43,10 @@ var configTests = []struct {
|
||||
"sftp:user@host:/dir/subdir",
|
||||
Config{User: "user", Host: "host", Path: "/dir/subdir"},
|
||||
},
|
||||
{
|
||||
"sftp:user@domain@host:/dir/subdir",
|
||||
Config{User: "user@domain", Host: "host", Path: "/dir/subdir"},
|
||||
},
|
||||
{
|
||||
"sftp:host:../dir/subdir",
|
||||
Config{Host: "host", Path: "../dir/subdir"},
|
||||
|
Loading…
Reference in New Issue
Block a user