mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-07 23:00:55 +03:00
sftpd: fix relative symlinks handling
Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
@@ -546,6 +546,13 @@ func (c *BaseConnection) Rename(virtualSourcePath, virtualTargetPath string) err
|
||||
|
||||
// CreateSymlink creates fsTargetPath as a symbolic link to fsSourcePath
|
||||
func (c *BaseConnection) CreateSymlink(virtualSourcePath, virtualTargetPath string) error {
|
||||
var relativePath string
|
||||
if !path.IsAbs(virtualSourcePath) {
|
||||
relativePath = virtualSourcePath
|
||||
virtualSourcePath = path.Join(path.Dir(virtualTargetPath), relativePath)
|
||||
c.Log(logger.LevelDebug, "link relative path %q resolved as %q, target path %q",
|
||||
relativePath, virtualSourcePath, virtualTargetPath)
|
||||
}
|
||||
if c.isCrossFoldersRequest(virtualSourcePath, virtualTargetPath) {
|
||||
c.Log(logger.LevelWarn, "cross folder symlink is not supported, src: %v dst: %v", virtualSourcePath, virtualTargetPath)
|
||||
return c.GetOpUnsupportedError()
|
||||
@@ -579,6 +586,9 @@ func (c *BaseConnection) CreateSymlink(virtualSourcePath, virtualTargetPath stri
|
||||
c.Log(logger.LevelError, "symlink target path %#v is not allowed", virtualTargetPath)
|
||||
return c.GetPermissionDeniedError()
|
||||
}
|
||||
if relativePath != "" {
|
||||
fsSourcePath = relativePath
|
||||
}
|
||||
if err := fs.Symlink(fsSourcePath, fsTargetPath); err != nil {
|
||||
c.Log(logger.LevelError, "failed to create symlink %#v -> %#v: %+v", fsSourcePath, fsTargetPath, err)
|
||||
return c.GetFsError(fs, err)
|
||||
|
||||
Reference in New Issue
Block a user