之前有写为sftpgo添加匿名访问支持,还有个问题不能访问链接文件,基于sftpgo2.2.2修改制作了个patch以支持软链接,linux下测试通过,windows未测试。
diff -urN -x .git sftpgo/common/connection.go sftpgo3/common/connection.go
--- sftpgo/common/connection.go 2022-04-04 15:06:39.542187282 +0800
+++ sftpgo3/common/connection.go 2022-04-04 14:57:31.027102136 +0800
@@ -242,6 +242,27 @@
c.Log(logger.LevelDebug, "error listing directory: %+v", err)
return nil, c.GetFsError(fs, err)
}
+ if c.protocol == ProtocolWebDAV || c.protocol == ProtocolFTP {
+ for k, file := range files {
+ if file.Mode()&os.ModeSymlink != 0 {
+ dst, err := os.Readlink(fsPath + "/" + file.Name())
+ if err != nil {
+ c.Log(logger.LevelError, "error readlink: %#v error: %+v", fsPath+"/"+file.Name(), err)
+ continue
+ }
+ dstinfo, err := os.Stat(dst)
+ if err != nil {
+ c.Log(logger.LevelError, "error stat: %#v error: %+v", dst, err)
+ continue
+ }
+ if dstinfo.IsDir() {
+ files[k] = vfs.NewFileInfo(file.Name(), true, 0, dstinfo.ModTime(), false)
+ } else {
+ files[k] = vfs.NewFileInfo(file.Name(), false, dstinfo.Size(), dstinfo.ModTime(), false)
+ }
+ }
+ }
+ }
return c.User.AddVirtualDirs(files, virtualPath), nil
}
diff -urN -x .git sftpgo/ftpd/handler.go sftpgo3/ftpd/handler.go
--- sftpgo/ftpd/handler.go 2022-04-04 15:06:39.550187152 +0800
+++ sftpgo3/ftpd/handler.go 2022-04-04 14:55:41.368885080 +0800
@@ -14,7 +14,7 @@
"github.com/drakkan/sftpgo/v2/common"
"github.com/drakkan/sftpgo/v2/dataprovider"
"github.com/drakkan/sftpgo/v2/logger"
- "github.com/drakkan/sftpgo/v2/util"
+ //"github.com/drakkan/sftpgo/v2/util"
"github.com/drakkan/sftpgo/v2/vfs"
)
@@ -288,10 +288,12 @@
if err != nil {
return files, err
}
- if name != "/" {
- files = util.PrependFileInfo(files, vfs.NewFileInfo("..", true, 0, time.Now(), false))
- }
- files = util.PrependFileInfo(files, vfs.NewFileInfo(".", true, 0, time.Now(), false))
+ /*
+ if name != "/" {
+ files = util.PrependFileInfo(files, vfs.NewFileInfo("..", true, 0, time.Now(), false))
+ }
+ files = util.PrependFileInfo(files, vfs.NewFileInfo(".", true, 0, time.Now(), false))
+ */
return files, nil
}
diff -urN -x .git sftpgo/vfs/osfs.go sftpgo3/vfs/osfs.go
--- sftpgo/vfs/osfs.go 2022-04-04 15:06:39.574186762 +0800
+++ sftpgo3/vfs/osfs.go 2022-04-04 14:59:06.413551648 +0800
@@ -291,6 +291,7 @@
virtualPath = strings.TrimPrefix(virtualPath, fs.mountPath)
}
r := filepath.Clean(filepath.Join(fs.rootDir, virtualPath))
+ return r, nil
p, err := filepath.EvalSymlinks(r)
if err != nil && !os.IsNotExist(err) {
return "", err
1.修改vfs/osfs.go文件取消对链接目标的校验是否在家目录内,这时部分客户端已正常,因为sftpgo返回链接目录属性为l而非d,导致有的客户端将链接目录识别为文件。
2.修改common/connection.go文件是修改返回的链接目录/文件的属性为标准目录和文件。
参考:
https://github.com/drakkan/sftpgo/issues/336