Skip to content

Commit

Permalink
implement some ClientOptions rename OpSupported, and godoc the client.
Browse files Browse the repository at this point in the history
  • Loading branch information
puellanivis committed Oct 29, 2024
1 parent 5839350 commit 4ff6adb
Show file tree
Hide file tree
Showing 8 changed files with 414 additions and 111 deletions.
478 changes: 390 additions & 88 deletions client.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions encoding/ssh/filexfer/fx.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (
StatusBadMessage
StatusNoConnection
StatusConnectionLost
StatusOPUnsupported
StatusOpUnsupported

// https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-03.txt#section-7
StatusV4InvalidHandle
Expand Down Expand Up @@ -113,7 +113,7 @@ func (s Status) String() string {
return "SSH_FX_NO_CONNECTION"
case StatusConnectionLost:
return "SSH_FX_CONNECTION_LOST"
case StatusOPUnsupported:
case StatusOpUnsupported:
return "SSH_FX_OP_UNSUPPORTED"
case StatusV4InvalidHandle:
return "SSH_FX_INVALID_HANDLE"
Expand Down
2 changes: 1 addition & 1 deletion errno_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func translateErrno(errno syscall.Errno) sshfx.Status {
case syscall.EACCES, syscall.EPERM:
return sshfx.StatusPermissionDenied
case syscall.ENOTSUP:
return sshfx.StatusOPUnsupported
return sshfx.StatusOpUnsupported
}

return sshfx.StatusFailure
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/pkg/sftp/v2

go 1.22
go 1.23

require (
github.com/google/go-cmp v0.6.0
Expand Down
2 changes: 1 addition & 1 deletion localfs/localfs_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func runClient(m *testing.M, rd io.Reader, wr io.WriteCloser) error {
defer cl.Close()

defer func() {
cl.ReportMetrics(os.Stdout)
cl.ReportPoolMetrics(os.Stdout)
}()

cwd, err = cl.RealPath(".")
Expand Down
1 change: 1 addition & 0 deletions longname.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
sshfx "github.com/pkg/sftp/v2/encoding/ssh/filexfer"
)

// NameLookup defines an interface to lookup user names and group names in a portable manner.
type NameLookup interface {
LookupUserName(string) string
LookupGroupName(string) string
Expand Down
6 changes: 3 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,13 +490,13 @@ func (srv *Server) handle(req sshfx.Packet, hint []byte, maxDataLen uint32) (ssh
// Return a different message when it is entirely unregisted into the system.
// This allows one to more easily identify the sitaution.
return nil, &sshfx.StatusPacket{
StatusCode: sshfx.StatusOPUnsupported,
StatusCode: sshfx.StatusOpUnsupported,
ErrorMessage: fmt.Sprintf("unregistered extended packet: %s", req.ExtendedRequest),
}
}

return nil, &sshfx.StatusPacket{
StatusCode: sshfx.StatusOPUnsupported,
StatusCode: sshfx.StatusOpUnsupported,
ErrorMessage: fmt.Sprintf("unsupported extended packet: %s", req.ExtendedRequest),
}

Expand Down Expand Up @@ -602,7 +602,7 @@ func (srv *Server) handle(req sshfx.Packet, hint []byte, maxDataLen uint32) (ssh
}

return nil, &sshfx.StatusPacket{
StatusCode: sshfx.StatusOPUnsupported,
StatusCode: sshfx.StatusOpUnsupported,
ErrorMessage: fmt.Sprintf("unsupported packet: %s", req.Type()),
}
}
Expand Down
30 changes: 15 additions & 15 deletions unimplemented.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,87 +11,87 @@ type UnimplementedHandler struct{}

func (UnimplementedHandler) Mkdir(_ context.Context, req *sshfx.MkdirPacket) error {
return &sshfx.StatusPacket{
StatusCode: sshfx.StatusOPUnsupported,
StatusCode: sshfx.StatusOpUnsupported,
ErrorMessage: fmt.Sprint(req.Type()),
}
}

func (UnimplementedHandler) Remove(_ context.Context, req *sshfx.RemovePacket) error {
return &sshfx.StatusPacket{
StatusCode: sshfx.StatusOPUnsupported,
StatusCode: sshfx.StatusOpUnsupported,
ErrorMessage: fmt.Sprint(req.Type()),
}
}

func (UnimplementedHandler) Rename(_ context.Context, req *sshfx.RenamePacket) error {
return &sshfx.StatusPacket{
StatusCode: sshfx.StatusOPUnsupported,
StatusCode: sshfx.StatusOpUnsupported,
ErrorMessage: fmt.Sprint(req.Type()),
}
}

func (UnimplementedHandler) Rmdir(_ context.Context, req *sshfx.RmdirPacket) error {
return &sshfx.StatusPacket{
StatusCode: sshfx.StatusOPUnsupported,
StatusCode: sshfx.StatusOpUnsupported,
ErrorMessage: fmt.Sprint(req.Type()),
}
return sshfx.StatusOPUnsupported
return sshfx.StatusOpUnsupported
}

func (UnimplementedHandler) SetStat(_ context.Context, req *sshfx.SetStatPacket) error {
return &sshfx.StatusPacket{
StatusCode: sshfx.StatusOPUnsupported,
StatusCode: sshfx.StatusOpUnsupported,
ErrorMessage: fmt.Sprint(req.Type()),
}
return sshfx.StatusOPUnsupported
return sshfx.StatusOpUnsupported
}

func (UnimplementedHandler) Symlink(_ context.Context, req *sshfx.SymlinkPacket) error {
return &sshfx.StatusPacket{
StatusCode: sshfx.StatusOPUnsupported,
StatusCode: sshfx.StatusOpUnsupported,
ErrorMessage: fmt.Sprint(req.Type()),
}
return sshfx.StatusOPUnsupported
return sshfx.StatusOpUnsupported
}

func (UnimplementedHandler) LStat(_ context.Context, req *sshfx.LStatPacket) (*sshfx.Attributes, error) {
return nil, &sshfx.StatusPacket{
StatusCode: sshfx.StatusOPUnsupported,
StatusCode: sshfx.StatusOpUnsupported,
ErrorMessage: fmt.Sprint(req.Type()),
}
}

func (UnimplementedHandler) Stat(_ context.Context, req *sshfx.StatPacket) (*sshfx.Attributes, error) {
return nil, &sshfx.StatusPacket{
StatusCode: sshfx.StatusOPUnsupported,
StatusCode: sshfx.StatusOpUnsupported,
ErrorMessage: fmt.Sprint(req.Type()),
}
}

func (UnimplementedHandler) ReadLink(_ context.Context, req *sshfx.ReadLinkPacket) (string, error) {
return "", &sshfx.StatusPacket{
StatusCode: sshfx.StatusOPUnsupported,
StatusCode: sshfx.StatusOpUnsupported,
ErrorMessage: fmt.Sprint(req.Type()),
}
}

func (UnimplementedHandler) RealPath(_ context.Context, req *sshfx.RealPathPacket) (string, error) {
return "", &sshfx.StatusPacket{
StatusCode: sshfx.StatusOPUnsupported,
StatusCode: sshfx.StatusOpUnsupported,
ErrorMessage: fmt.Sprint(req.Type()),
}
}

func (UnimplementedHandler) Open(_ context.Context, req *sshfx.OpenPacket) (FileHandler, error) {
return nil, &sshfx.StatusPacket{
StatusCode: sshfx.StatusOPUnsupported,
StatusCode: sshfx.StatusOpUnsupported,
ErrorMessage: fmt.Sprint(req.Type()),
}
}

func (UnimplementedHandler) OpenDir(_ context.Context, req *sshfx.OpenDirPacket) (DirHandler, error) {
return nil, &sshfx.StatusPacket{
StatusCode: sshfx.StatusOPUnsupported,
StatusCode: sshfx.StatusOpUnsupported,
ErrorMessage: fmt.Sprint(req.Type()),
}
}
Expand Down

0 comments on commit 4ff6adb

Please sign in to comment.