smb: save the user name in the config even if it matches the current user - fixes #9356
The default for --smb-user was the name of the user running rclone config, and rclone does not write defaults to the config file, so entering your own user name left it out. A remote made that way then logged in as whoever ran it later, e.g. root under systemd. Make the default blank and look up the current user when the remote is used, as the ftp backend does. Existing configs work as before.
This commit is contained in:
1 parent
dc98c216f2
commit
3c51b96774
2 files changed
+34
-2
No files matched your search
+4
-2
@@ -51,8 +51,7 @@ func init() {
|
||||
Sensitive: true,
|
||||
}, {
|
||||
Name: "user",
|
||||
Help: "SMB username.",
|
||||
Default: currentUser,
|
||||
Help: "SMB username.\n\nLeave blank to use the current user name.",
|
||||
Sensitive: true,
|
||||
}, {
|
||||
Name: "port",
|
||||
@@ -205,6 +204,9 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if opt.User == "" {
|
||||
opt.User = currentUser
|
||||
}
|
||||
|
||||
// if root is empty or ends with / (must be a directory)
|
||||
isRootDir := isPathDir(root)
|
||||
|
||||
@@ -158,3 +158,33 @@ func TestIsPathDir(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewFsUser(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
for _, test := range []struct {
|
||||
user string
|
||||
want string
|
||||
}{
|
||||
{user: "", want: currentUser},
|
||||
{user: currentUser, want: currentUser},
|
||||
{user: "someone", want: "someone"},
|
||||
} {
|
||||
m := configmap.Simple{"host": "localhost", "user": test.user}
|
||||
f, err := NewFs(ctx, "TestSMB", "", m)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, test.want, f.(*Fs).opt.User, "user=%q", test.user)
|
||||
}
|
||||
|
||||
// No user in the config at all
|
||||
f, err := NewFs(ctx, "TestSMB", "", configmap.Simple{"host": "localhost"})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, currentUser, f.(*Fs).opt.User)
|
||||
}
|
||||
|
||||
// The default is blank so that a user name which happens to match the
|
||||
// current user is still written to the config file.
|
||||
func TestUserDefault(t *testing.T) {
|
||||
ri, err := fs.Find("smb")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "", ri.Options.Get("user").Default)
|
||||
}
|
||||
Reference in new issue
Block a user