mirror of https://github.com/pkg/sftp.git
review adjustments 4
This commit is contained in:
parent
38928181c7
commit
35c82d76eb
37
server.go
37
server.go
|
@ -34,39 +34,6 @@ type file interface {
|
|||
Close() error
|
||||
}
|
||||
|
||||
type dummyFile struct {
|
||||
}
|
||||
|
||||
func (f *dummyFile) Stat() (os.FileInfo, error) {
|
||||
return nil, os.ErrPermission
|
||||
}
|
||||
func (f *dummyFile) ReadAt(b []byte, off int64) (int, error) {
|
||||
return 0, os.ErrPermission
|
||||
}
|
||||
func (f *dummyFile) WriteAt(b []byte, off int64) (int, error) {
|
||||
return 0, os.ErrPermission
|
||||
}
|
||||
func (f *dummyFile) Readdir(int) ([]os.FileInfo, error) {
|
||||
return nil, os.ErrPermission
|
||||
}
|
||||
func (f *dummyFile) Name() string {
|
||||
return "dummyFile"
|
||||
}
|
||||
func (f *dummyFile) Truncate(int64) error {
|
||||
return os.ErrPermission
|
||||
}
|
||||
func (f *dummyFile) Chmod(mode fs.FileMode) error {
|
||||
return os.ErrPermission
|
||||
}
|
||||
func (f *dummyFile) Chown(uid, gid int) error {
|
||||
return os.ErrPermission
|
||||
}
|
||||
func (f *dummyFile) Close() error {
|
||||
return os.ErrPermission
|
||||
}
|
||||
|
||||
var _ = dummyFile{} // ignore unused
|
||||
|
||||
// Server is an SSH File Transfer Protocol (sftp) server.
|
||||
// This is intended to provide the sftp subsystem to an ssh server daemon.
|
||||
// This implementation currently supports most of sftp server protocol version 3,
|
||||
|
@ -163,8 +130,8 @@ func ReadOnly() ServerOption {
|
|||
}
|
||||
}
|
||||
|
||||
// WinRoot configures a Server to serve a virtual '/' for windows that lists all drives
|
||||
func WinRoot() ServerOption {
|
||||
// configures a Server to serve a virtual '/' for windows that lists all drives
|
||||
func WindowsRootEnumeratesDrives() ServerOption {
|
||||
return func(s *Server) error {
|
||||
s.winRoot = true
|
||||
return nil
|
||||
|
|
|
@ -86,7 +86,6 @@ func (i *driveInfo) Name() string {
|
|||
}
|
||||
|
||||
type winRoot struct {
|
||||
dummyFile
|
||||
drives []string
|
||||
}
|
||||
|
||||
|
@ -127,6 +126,31 @@ func (f *winRoot) Readdir(n int) ([]os.FileInfo, error) {
|
|||
return infos, nil
|
||||
}
|
||||
|
||||
func (f *winRoot) Stat() (os.FileInfo, error) {
|
||||
return nil, os.ErrPermission
|
||||
}
|
||||
func (f *winRoot) ReadAt(b []byte, off int64) (int, error) {
|
||||
return 0, os.ErrPermission
|
||||
}
|
||||
func (f *winRoot) WriteAt(b []byte, off int64) (int, error) {
|
||||
return 0, os.ErrPermission
|
||||
}
|
||||
func (f *winRoot) Name() string {
|
||||
return "/"
|
||||
}
|
||||
func (f *winRoot) Truncate(int64) error {
|
||||
return os.ErrPermission
|
||||
}
|
||||
func (f *winRoot) Chmod(mode fs.FileMode) error {
|
||||
return os.ErrPermission
|
||||
}
|
||||
func (f *winRoot) Chown(uid, gid int) error {
|
||||
return os.ErrPermission
|
||||
}
|
||||
func (f *winRoot) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) openfile(path string, flag int, mode fs.FileMode) (file, error) {
|
||||
if path == `\\.\` && s.winRoot {
|
||||
return newWinRoot()
|
||||
|
|
Loading…
Reference in New Issue