2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-12 08:16:37 +00:00

Merge pull request #2423 from streambinder/master

sftp: support user@domain parsing as user
This commit is contained in:
rawtaz 2019-12-19 22:39:36 +01:00 committed by GitHub
commit 4557881066
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 3 deletions

View 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

View File

@ -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 beginning) directory, in this case the dir is relative to the remote
user's home directory. 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 .. 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 (``~``) 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 want to specify a path relative to the user's home directory, pass a

View File

@ -56,8 +56,11 @@ func ParseConfig(s string) (interface{}, error) {
host = data[0] host = data[0]
dir = data[1] dir = data[1]
// split user and host at the "@" // split user and host at the "@"
data = strings.SplitN(host, "@", 2) data = strings.SplitN(host, "@", 3)
if len(data) == 2 { if len(data) == 3 {
user = data[0] + "@" + data[1]
host = data[2]
} else if len(data) == 2 {
user = data[0] user = data[0]
host = data[1] host = data[1]
} }

View File

@ -1,6 +1,8 @@
package sftp package sftp
import "testing" import (
"testing"
)
var configTests = []struct { var configTests = []struct {
in string in string
@ -41,6 +43,10 @@ var configTests = []struct {
"sftp:user@host:/dir/subdir", "sftp:user@host:/dir/subdir",
Config{User: "user", Host: "host", Path: "/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", "sftp:host:../dir/subdir",
Config{Host: "host", Path: "../dir/subdir"}, Config{Host: "host", Path: "../dir/subdir"},