From b39b17bc5a613b9a04d4f0b2962cf61e3b0515aa Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 29 Nov 2026 14:02:19 +0000 Subject: [PATCH] chore(deps): Bump github.com/pkg/sftp from 1.13.12 to 1.13.13 Bumps [github.com/pkg/sftp](https://github.com/pkg/sftp) from 1.13.12 to 1.13.13. - [Release notes](https://github.com/pkg/sftp/releases) - [Commits](https://github.com/pkg/sftp/compare/v1.13.12...v1.13.13) --- updated-dependencies: - dependency-name: github.com/pkg/sftp dependency-version: 1.13.12 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 +- vendor/github.com/pkg/sftp/attrs.go | 2 +- vendor/github.com/pkg/sftp/client.go | 116 ++++++++++++++++-- vendor/github.com/pkg/sftp/conn.go | 25 +++- .../internal/encoding/ssh/filexfer/attrs.go | 4 +- .../internal/encoding/ssh/filexfer/buffer.go | 2 +- .../encoding/ssh/filexfer/extensions.go | 2 +- .../encoding/ssh/filexfer/filexfer.go | 2 +- .../sftp/internal/encoding/ssh/filexfer/fx.go | 18 +-- .../internal/encoding/ssh/filexfer/fxp.go | 10 +- .../internal/encoding/ssh/filexfer/packets.go | 4 +- .../encoding/ssh/filexfer/response_packets.go | 2 +- vendor/github.com/pkg/sftp/match.go | 7 +- vendor/github.com/pkg/sftp/request-attrs.go | 4 +- vendor/github.com/pkg/sftp/request-readme.md | 2 +- vendor/github.com/pkg/sftp/request-server.go | 20 +-- vendor/github.com/pkg/sftp/request.go | 8 ++ vendor/github.com/pkg/sftp/server.go | 30 ++++- vendor/github.com/pkg/sftp/server_plan9.go | 6 +- vendor/github.com/pkg/sftp/server_unix.go | 10 +- vendor/github.com/pkg/sftp/server_windows.go | 6 +- vendor/github.com/pkg/sftp/sftp.go | 4 +- vendor/modules.txt | 2 +- 24 files changed, 213 insertions(+), 79 deletions(-) diff --git a/go.mod b/go.mod index ee4004f80..d22c32960 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/mattn/go-isatty v0.0.24 github.com/onsi/ginkgo/v2 v2.34.0 github.com/onsi/gomega v1.44.0 - github.com/pkg/sftp v1.13.12 + github.com/pkg/sftp v1.13.13 github.com/stretchr/testify v1.12.1 github.com/urfave/cli/v3 v3.14.0 golang.org/x/crypto v0.58.0 diff --git a/go.sum b/go.sum index 524e5c5d5..7876ca2d3 100644 --- a/go.sum +++ b/go.sum @@ -83,8 +83,8 @@ github.com/onsi/ginkgo/v2 v2.34.0 h1:aN3Us823mHHTSWMIi8WIQTdYuSPhl2lWY46E/w3SiAk github.com/onsi/ginkgo/v2 v2.34.0/go.mod h1:+aXOY+vzZ5mu2iI2HpTZUPmM//oQfsNFX6gU9kNcA44= github.com/onsi/gomega v1.44.0 h1:eAiGl3Pw5jz5GQdDff0BcxYpAX1JxW8xD7mFUuwNfZQ= github.com/onsi/gomega v1.44.0/go.mod h1:e/C2HwaZ1DhvjzXXuFhcR7hY7Sh9pl7MmoWKEjzwcdA= -github.com/pkg/sftp v1.13.12 h1:Myhzy/ZzLPnCtE2F2WtDHsgs8RfgMnH2gfbHuCJhkMU= -github.com/pkg/sftp v1.13.12/go.mod h1:uNkH9roSXglNJqM+glJJi+TQXQUm0fXFWqCFmT8hsN0= +github.com/pkg/sftp v1.13.13 h1:lfbNTnT3zEilT8XxmwBBb5sdqJJBTunll5OVNCZPwrs= +github.com/pkg/sftp v1.13.13/go.mod h1:uNkH9roSXglNJqM+glJJi+TQXQUm0fXFWqCFmT8hsN0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= diff --git a/vendor/github.com/pkg/sftp/attrs.go b/vendor/github.com/pkg/sftp/attrs.go index c995534e8..8590a1603 100644 --- a/vendor/github.com/pkg/sftp/attrs.go +++ b/vendor/github.com/pkg/sftp/attrs.go @@ -1,7 +1,7 @@ package sftp // ssh_FXP_ATTRS support -// see https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-02.txt#section-5 +// see https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-02#section-5 import ( "os" diff --git a/vendor/github.com/pkg/sftp/client.go b/vendor/github.com/pkg/sftp/client.go index 8e027d208..6a452af39 100644 --- a/vendor/github.com/pkg/sftp/client.go +++ b/vendor/github.com/pkg/sftp/client.go @@ -101,6 +101,17 @@ func MaxConcurrentRequestsPerFile(n int) ClientOption { } } +// ForceSingleFile restricts the client to one open file or directory at a time. +// A second open returns an SSH_FX_FAILURE status until the current handle is closed. +// Use this with servers that return the same handle for multiple opens: +// clients cannot safely keep two files or directories open at once with such servers. +func ForceSingleFile() ClientOption { + return func(c *Client) error { + c.forceSingleFile = true + return nil + } +} + // UseConcurrentWrites allows the Client to perform concurrent Writes. // // Using concurrency while doing writes, requires special consideration. @@ -181,6 +192,10 @@ type Client struct { ext map[string]string // Extensions (name -> data). + handlesMu sync.Mutex + handles map[string]struct{} // Handles of open files and directories. + singleFileOpen atomic.Bool + maxPacket int // max packet size read or written. maxConcurrentRequests int nextid uint32 @@ -190,6 +205,7 @@ type Client struct { useConcurrentWrites bool useFstat bool disableConcurrentReads bool + forceSingleFile bool } // NewClient creates a new SFTP client on conn, using zero or more option @@ -202,22 +218,32 @@ func NewClient(conn *ssh.Client, opts ...ClientOption) (*Client, error) { pw, err := s.StdinPipe() if err != nil { + s.Close() return nil, err } pr, err := s.StdoutPipe() if err != nil { + s.Close() return nil, err } perr, err := s.StderrPipe() if err != nil { + s.Close() return nil, err } if err := s.RequestSubsystem("sftp"); err != nil { + s.Close() + return nil, err + } + + c, err := newClientPipe(pr, perr, pw, s.Wait, opts...) + if err != nil { + s.Close() return nil, err } - return newClientPipe(pr, perr, pw, s.Wait, opts...) + return c, nil } // NewClientPipe creates a new SFTP client given a Reader and a WriteCloser. @@ -239,7 +265,8 @@ func newClientPipe(rd, stderr io.Reader, wr io.WriteCloser, wait func() error, o wait: wait, }, - ext: make(map[string]string), + ext: make(map[string]string), + handles: make(map[string]struct{}), maxPacket: 1 << 15, maxConcurrentRequests: 64, @@ -304,11 +331,11 @@ func (c *Client) Create(path string) (*File, error) { return c.open(path, toPflags(os.O_RDWR|os.O_CREATE|os.O_TRUNC)) } -const sftpProtocolVersion = 3 // https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-02.txt +const sftpProtocolVersion = 3 // https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-02 func (c *Client) sendInit() error { return c.clientConn.conn.sendPacket(&sshFxInitPacket{ - Version: sftpProtocolVersion, // https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-02.txt + Version: sftpProtocolVersion, // https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-02 }) } @@ -440,7 +467,16 @@ func (c *Client) ReadDirContext(ctx context.Context, p string) ([]os.FileInfo, e return entries, err } -func (c *Client) opendir(ctx context.Context, path string) (string, error) { +func (c *Client) opendir(ctx context.Context, path string) (handle string, err error) { + if err = c.lockOpenSlot(); err != nil { + return "", err + } + defer func() { + if err != nil { + c.singleFileOpen.Store(false) + } + }() + id := c.nextID() typ, data, err := c.sendPacket(ctx, nil, &sshFxpOpendirPacket{ ID: id, @@ -459,6 +495,9 @@ func (c *Client) opendir(ctx context.Context, path string) (string, error) { if err != nil { return "", err } + if err := c.addHandle(handle); err != nil { + return "", err + } return handle, nil case sshFxpStatus: return "", normaliseError(unmarshalStatus(id, data)) @@ -684,7 +723,16 @@ func (c *Client) OpenFile(path string, f int) (*File, error) { return c.open(path, toPflags(f)) } -func (c *Client) open(path string, pflags uint32) (*File, error) { +func (c *Client) open(path string, pflags uint32) (file *File, err error) { + if err = c.lockOpenSlot(); err != nil { + return nil, err + } + defer func() { + if err != nil { + c.singleFileOpen.Store(false) + } + }() + id := c.nextID() typ, data, err := c.sendPacket(context.Background(), nil, &sshFxpOpenPacket{ ID: id, @@ -704,6 +752,9 @@ func (c *Client) open(path string, pflags uint32) (*File, error) { if err != nil { return nil, err } + if err := c.addHandle(handle); err != nil { + return nil, err + } return &File{c: c, path: path, handle: handle}, nil case sshFxpStatus: return nil, normaliseError(unmarshalStatus(id, data)) @@ -716,6 +767,11 @@ func (c *Client) open(path string, pflags uint32) (*File, error) { // to SSH_FXP_OPEN or SSH_FXP_OPENDIR. The handle becomes invalid // immediately after this request has been sent. func (c *Client) close(handle string) error { + // Forget the handle before sending the request: the handle's state is + // unspecified after a close error, and the server may already have reused it. + c.removeHandle(handle) + defer c.singleFileOpen.Store(false) + id := c.nextID() typ, data, err := c.sendPacket(context.Background(), nil, &sshFxpClosePacket{ ID: id, @@ -732,6 +788,52 @@ func (c *Client) close(handle string) error { } } +// addHandle records handle as open. It returns an error if the handle is +// already open: some servers return the same handle for every open, and +// using it would also read, write or close the other file. +func (c *Client) addHandle(handle string) error { + c.handlesMu.Lock() + defer c.handlesMu.Unlock() + + if _, ok := c.handles[handle]; ok { + err := &duplicateHandleError{handle: handle} + c.clientConn.broadcastErr(err) + _ = c.clientConn.conn.Close() + return err + } + c.handles[handle] = struct{}{} + return nil +} + +type duplicateHandleError struct { + handle string +} + +func (e *duplicateHandleError) Error() string { + return fmt.Sprintf("sftp: server returned handle %q which is already open; the server may not support multiple open files, use ForceSingleFile", e.handle) +} + +func (c *Client) lockOpenSlot() error { + if !c.forceSingleFile { + return nil + } + + if !c.singleFileOpen.CompareAndSwap(false, true) { + return &StatusError{ + Code: sshFxFailure, + msg: "ForceSingleFile allows only one open file or directory at a time", + } + } + + return nil +} + +func (c *Client) removeHandle(handle string) { + c.handlesMu.Lock() + delete(c.handles, handle) + c.handlesMu.Unlock() +} + func (c *Client) stat(path string) (*FileStat, error) { id := c.nextID() typ, data, err := c.sendPacket(context.Background(), nil, &sshFxpStatPacket{ @@ -2110,7 +2212,7 @@ func (f *File) ReadFrom(r io.Reader) (int64, error) { } if err != nil { - if errors.Is(err, io.EOF) { + if errors.Is(err, io.EOF) && !errors.Is(err, ErrSSHFxConnectionLost) { return read, nil // return nil explicitly. } diff --git a/vendor/github.com/pkg/sftp/conn.go b/vendor/github.com/pkg/sftp/conn.go index e68a2bd06..73706afec 100644 --- a/vendor/github.com/pkg/sftp/conn.go +++ b/vendor/github.com/pkg/sftp/conn.go @@ -16,6 +16,9 @@ type conn struct { // this is the same allocator used in packet manager alloc *allocator sync.Mutex // used to serialise writes to sendPacket + + closeOnce sync.Once + closeErr error } // the orderID is used in server mode if the allocator is enabled. @@ -36,7 +39,10 @@ func (c *conn) sendPacket(m encoding.BinaryMarshaler) error { func (c *conn) Close() error { c.Lock() defer c.Unlock() - return c.WriteCloser.Close() + c.closeOnce.Do(func() { + c.closeErr = c.WriteCloser.Close() + }) + return c.closeErr } type clientConn struct { @@ -121,7 +127,7 @@ func (c *clientConn) putChannel(ch chan<- result, sid uint32) bool { select { case <-c.closed: // already closed with broadcastErr, return error on chan. - ch <- result{err: ErrSSHFxConnectionLost} + ch <- result{err: connectionLostError(c.err)} return false default: } @@ -189,7 +195,13 @@ func (c *clientConn) broadcastErr(err error) { c.Lock() defer c.Unlock() - bcastRes := result{err: ErrSSHFxConnectionLost} + select { + case <-c.closed: + return + default: + } + + bcastRes := result{err: connectionLostError(err)} for sid, ch := range c.inflight { ch <- bcastRes @@ -203,6 +215,13 @@ func (c *clientConn) broadcastErr(err error) { close(c.closed) } +func connectionLostError(err error) error { + if err == nil { + return ErrSSHFxConnectionLost + } + return fmt.Errorf("%w: %w", ErrSSHFxConnectionLost, err) +} + type serverConn struct { conn } diff --git a/vendor/github.com/pkg/sftp/internal/encoding/ssh/filexfer/attrs.go b/vendor/github.com/pkg/sftp/internal/encoding/ssh/filexfer/attrs.go index 3aec937f0..347d4a85a 100644 --- a/vendor/github.com/pkg/sftp/internal/encoding/ssh/filexfer/attrs.go +++ b/vendor/github.com/pkg/sftp/internal/encoding/ssh/filexfer/attrs.go @@ -12,7 +12,7 @@ const ( // Attributes defines the file attributes type defined in draft-ietf-secsh-filexfer-02 // -// Defined in: https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-02.txt#section-5 +// Defined in: https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-02#section-5 type Attributes struct { Flags uint32 @@ -210,7 +210,7 @@ func (a *Attributes) UnmarshalBinary(data []byte) error { // ExtendedAttribute defines the extended file attribute type defined in draft-ietf-secsh-filexfer-02 // -// Defined in: https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-02.txt#section-5 +// Defined in: https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-02#section-5 type ExtendedAttribute struct { Type string Data string diff --git a/vendor/github.com/pkg/sftp/internal/encoding/ssh/filexfer/buffer.go b/vendor/github.com/pkg/sftp/internal/encoding/ssh/filexfer/buffer.go index bd4783bb8..b64c5c1d9 100644 --- a/vendor/github.com/pkg/sftp/internal/encoding/ssh/filexfer/buffer.go +++ b/vendor/github.com/pkg/sftp/internal/encoding/ssh/filexfer/buffer.go @@ -13,7 +13,7 @@ var ( // Buffer wraps up the various encoding details of the SSH format. // -// Data types are encoded as per section 4 from https://tools.ietf.org/html/draft-ietf-secsh-architecture-09#page-8 +// Data types are encoded as per section 4 from https://datatracker.ietf.org/doc/html/draft-ietf-secsh-architecture-09#page-8 type Buffer struct { b []byte off int diff --git a/vendor/github.com/pkg/sftp/internal/encoding/ssh/filexfer/extensions.go b/vendor/github.com/pkg/sftp/internal/encoding/ssh/filexfer/extensions.go index c425780ca..84b44f684 100644 --- a/vendor/github.com/pkg/sftp/internal/encoding/ssh/filexfer/extensions.go +++ b/vendor/github.com/pkg/sftp/internal/encoding/ssh/filexfer/extensions.go @@ -3,7 +3,7 @@ package sshfx // ExtensionPair defines the extension-pair type defined in draft-ietf-secsh-filexfer-13. // This type is backwards-compatible with how draft-ietf-secsh-filexfer-02 defines extensions. // -// Defined in: https://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#section-4.2 +// Defined in: https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-13#section-4.2 type ExtensionPair struct { Name string Data string diff --git a/vendor/github.com/pkg/sftp/internal/encoding/ssh/filexfer/filexfer.go b/vendor/github.com/pkg/sftp/internal/encoding/ssh/filexfer/filexfer.go index d3009994a..a6ad08e32 100644 --- a/vendor/github.com/pkg/sftp/internal/encoding/ssh/filexfer/filexfer.go +++ b/vendor/github.com/pkg/sftp/internal/encoding/ssh/filexfer/filexfer.go @@ -1,4 +1,4 @@ -// Package sshfx implements the wire encoding for secsh-filexfer as described in https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-02.txt +// Package sshfx implements the wire encoding for secsh-filexfer as described in https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-02 package sshfx // PacketMarshaller narrowly defines packets that will only be transmitted. diff --git a/vendor/github.com/pkg/sftp/internal/encoding/ssh/filexfer/fx.go b/vendor/github.com/pkg/sftp/internal/encoding/ssh/filexfer/fx.go index 9abcbafcb..ff8dcd437 100644 --- a/vendor/github.com/pkg/sftp/internal/encoding/ssh/filexfer/fx.go +++ b/vendor/github.com/pkg/sftp/internal/encoding/ssh/filexfer/fx.go @@ -10,7 +10,7 @@ type Status uint32 // Defines the various SSH_FX_* values. const ( // see draft-ietf-secsh-filexfer-02 - // https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-02.txt#section-7 + // https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-02#section-7 StatusOK = Status(iota) StatusEOF StatusNoSuchFile @@ -21,28 +21,28 @@ const ( StatusConnectionLost StatusOPUnsupported - // https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-03.txt#section-7 + // https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-03#section-7 StatusV4InvalidHandle StatusV4NoSuchPath StatusV4FileAlreadyExists StatusV4WriteProtect - // https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-04.txt#section-7 + // https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-04#section-7 StatusV4NoMedia - // https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-05.txt#section-7 + // https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-05#section-7 StatusV5NoSpaceOnFilesystem StatusV5QuotaExceeded StatusV5UnknownPrincipal StatusV5LockConflict - // https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-06.txt#section-8 + // https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-06#section-8 StatusV6DirNotEmpty StatusV6NotADirectory StatusV6InvalidFilename StatusV6LinkLoop - // https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-07.txt#section-8 + // https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-07#section-8 StatusV6CannotDelete StatusV6InvalidParameter StatusV6FileIsADirectory @@ -50,14 +50,14 @@ const ( StatusV6ByteRangeLockRefused StatusV6DeletePending - // https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-08.txt#section-8.1 + // https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-08#section-8.1 StatusV6FileCorrupt - // https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-10.txt#section-9.1 + // https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-10#section-9.1 StatusV6OwnerInvalid StatusV6GroupInvalid - // https://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#section-9.1 + // https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-13#section-9.1 StatusV6NoMatchingByteRangeLock ) diff --git a/vendor/github.com/pkg/sftp/internal/encoding/ssh/filexfer/fxp.go b/vendor/github.com/pkg/sftp/internal/encoding/ssh/filexfer/fxp.go index 780800215..473473431 100644 --- a/vendor/github.com/pkg/sftp/internal/encoding/ssh/filexfer/fxp.go +++ b/vendor/github.com/pkg/sftp/internal/encoding/ssh/filexfer/fxp.go @@ -9,7 +9,7 @@ type PacketType uint8 // Request packet types. const ( - // https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-02.txt#section-3 + // https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-02#section-3 PacketTypeInit = PacketType(iota + 1) PacketTypeVersion PacketTypeOpen @@ -31,17 +31,17 @@ const ( PacketTypeReadLink PacketTypeSymlink - // https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-07.txt#section-3.3 + // https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-07#section-3.3 PacketTypeV6Link - // https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-08.txt#section-3.3 + // https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-08#section-3.3 PacketTypeV6Block PacketTypeV6Unblock ) // Response packet types. const ( - // https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-02.txt#section-3 + // https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-02#section-3 PacketTypeStatus = PacketType(iota + 101) PacketTypeHandle PacketTypeData @@ -51,7 +51,7 @@ const ( // Extended packet types. const ( - // https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-02.txt#section-3 + // https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-02#section-3 PacketTypeExtended = PacketType(iota + 200) PacketTypeExtendedReply ) diff --git a/vendor/github.com/pkg/sftp/internal/encoding/ssh/filexfer/packets.go b/vendor/github.com/pkg/sftp/internal/encoding/ssh/filexfer/packets.go index fdf65d057..1ebee60e4 100644 --- a/vendor/github.com/pkg/sftp/internal/encoding/ssh/filexfer/packets.go +++ b/vendor/github.com/pkg/sftp/internal/encoding/ssh/filexfer/packets.go @@ -17,7 +17,7 @@ const smallBufferSize = 64 // For servers expecting to receive arbitrary request packet types, // use RequestPacket. // -// Defined in https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-02.txt#section-3 +// Defined in https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-02#section-3 type RawPacket struct { PacketType PacketType RequestID uint32 @@ -174,7 +174,7 @@ func (p *RawPacket) ReadFrom(r io.Reader, b []byte, maxPacketLength uint32) erro // where automatic unmarshaling of the packet body does not make sense, // use RawPacket. // -// Defined in https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-02.txt#section-3 +// Defined in https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-02#section-3 type RequestPacket struct { RequestID uint32 diff --git a/vendor/github.com/pkg/sftp/internal/encoding/ssh/filexfer/response_packets.go b/vendor/github.com/pkg/sftp/internal/encoding/ssh/filexfer/response_packets.go index 311708ffe..7789bdb88 100644 --- a/vendor/github.com/pkg/sftp/internal/encoding/ssh/filexfer/response_packets.go +++ b/vendor/github.com/pkg/sftp/internal/encoding/ssh/filexfer/response_packets.go @@ -6,7 +6,7 @@ import ( // StatusPacket defines the SSH_FXP_STATUS packet. // -// Specified in https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-02.txt#section-7 +// Specified in https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-02#section-7 type StatusPacket struct { StatusCode Status ErrorMessage string diff --git a/vendor/github.com/pkg/sftp/match.go b/vendor/github.com/pkg/sftp/match.go index 875006afd..1621b0b3a 100644 --- a/vendor/github.com/pkg/sftp/match.go +++ b/vendor/github.com/pkg/sftp/match.go @@ -42,13 +42,10 @@ func Split(p string) (dir, file string) { // is malformed. func (c *Client) Glob(pattern string) (matches []string, err error) { if !hasMeta(pattern) { - file, err := c.Lstat(pattern) - if err != nil { + if _, err := c.Lstat(pattern); err != nil { return nil, nil } - dir, _ := Split(pattern) - dir = cleanGlobPath(dir) - return []string{Join(dir, file.Name())}, nil + return []string{pattern}, nil } dir, file := Split(pattern) diff --git a/vendor/github.com/pkg/sftp/request-attrs.go b/vendor/github.com/pkg/sftp/request-attrs.go index 476c56518..b888e89f9 100644 --- a/vendor/github.com/pkg/sftp/request-attrs.go +++ b/vendor/github.com/pkg/sftp/request-attrs.go @@ -46,12 +46,12 @@ func newFileAttrFlags(flags uint32) FileAttrFlags { // AttrFlags returns a FileAttrFlags boolean struct based on the // bitmap/uint32 file attribute flags from the SFTP packaet. func (r *Request) AttrFlags() FileAttrFlags { - return newFileAttrFlags(r.Flags) + return newFileAttrFlags(r.attrFlags) } // Attributes parses file attributes byte blob and return them in a // FileStat object. func (r *Request) Attributes() *FileStat { - fs, _, _ := unmarshalFileStat(r.Flags, r.Attrs) + fs, _, _ := unmarshalFileStat(r.attrFlags, r.Attrs) return fs } diff --git a/vendor/github.com/pkg/sftp/request-readme.md b/vendor/github.com/pkg/sftp/request-readme.md index f8b81f3aa..0ed167a02 100644 --- a/vendor/github.com/pkg/sftp/request-readme.md +++ b/vendor/github.com/pkg/sftp/request-readme.md @@ -28,7 +28,7 @@ then sends to the client. Handler for "Put" method and returns an io.Writer for the file which the server then writes the uploaded file to. The file opening "pflags" are currently preserved in the Request.Flags field as a 32bit bitmask value. See the [SFTP -spec](https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-02.txt#section-6.3) for +spec](https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-02#section-6.3) for details. ### Filecmd(*Request) error diff --git a/vendor/github.com/pkg/sftp/request-server.go b/vendor/github.com/pkg/sftp/request-server.go index 08c24d7f6..5286aabf9 100644 --- a/vendor/github.com/pkg/sftp/request-server.go +++ b/vendor/github.com/pkg/sftp/request-server.go @@ -254,19 +254,23 @@ func (rs *RequestServer) packetWorker(ctx context.Context, pktChan chan orderedR } case *sshFxpOpendirPacket: request := requestFromPacket(ctx, pkt, rs.startDirectory) - handle := rs.nextRequest(request) rpkt = request.opendir(rs.Handlers, pkt) - if _, ok := rpkt.(*sshFxpHandlePacket); !ok { - // if we return an error we have to remove the handle from the active ones - rs.closeRequest(handle) + if hpkt, ok := rpkt.(*sshFxpHandlePacket); ok { + // Only publish the handle once the Request is fully set up: + // a pipelined READ/WRITE on it is handled concurrently. + hpkt.Handle = rs.nextRequest(request) + } else { + request.close() } case *sshFxpOpenPacket: request := requestFromPacket(ctx, pkt, rs.startDirectory) - handle := rs.nextRequest(request) rpkt = request.open(rs.Handlers, pkt) - if _, ok := rpkt.(*sshFxpHandlePacket); !ok { - // if we return an error we have to remove the handle from the active ones - rs.closeRequest(handle) + if hpkt, ok := rpkt.(*sshFxpHandlePacket); ok { + // Only publish the handle once the Request is fully set up: + // a pipelined READ/WRITE on it is handled concurrently. + hpkt.Handle = rs.nextRequest(request) + } else { + request.close() } case *sshFxpFstatPacket: handle := pkt.getHandle() diff --git a/vendor/github.com/pkg/sftp/request.go b/vendor/github.com/pkg/sftp/request.go index e01cad7a7..f81f1ba0a 100644 --- a/vendor/github.com/pkg/sftp/request.go +++ b/vendor/github.com/pkg/sftp/request.go @@ -148,6 +148,9 @@ type Request struct { Target string // for renames and sym-links handle string + // attribute flags of an open, where Flags holds the pflags + attrFlags uint32 + // reader/writer/readdir from handlers state @@ -176,6 +179,8 @@ func (r *Request) copy() *Request { Target: r.Target, handle: r.handle, + attrFlags: r.attrFlags, + state: r.state.copy(), ctx: r.ctx, @@ -194,9 +199,11 @@ func requestFromPacket(ctx context.Context, pkt hasPath, baseDir string) *Reques switch p := pkt.(type) { case *sshFxpOpenPacket: request.Flags = p.Pflags + request.attrFlags = p.Flags request.Attrs = p.Attrs.([]byte) case *sshFxpSetstatPacket: request.Flags = p.Flags + request.attrFlags = p.Flags request.Attrs = p.Attrs.([]byte) case *sshFxpRenamePacket: request.Target = cleanPathWithBase(baseDir, p.Newpath) @@ -476,6 +483,7 @@ func filecmd(h FileCmder, r *Request, pkt requestPacket) responsePacket { switch p := pkt.(type) { case *sshFxpFsetstatPacket: r.Flags = p.Flags + r.attrFlags = p.Flags r.Attrs = p.Attrs.([]byte) } diff --git a/vendor/github.com/pkg/sftp/server.go b/vendor/github.com/pkg/sftp/server.go index c3d3364b7..24e5667ba 100644 --- a/vendor/github.com/pkg/sftp/server.go +++ b/vendor/github.com/pkg/sftp/server.go @@ -10,6 +10,7 @@ import ( "io/fs" "io/ioutil" "os" + "path" "path/filepath" "strconv" "sync" @@ -37,7 +38,7 @@ type file interface { // 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, -// as specified at https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-02.txt +// as specified at https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-02 type Server struct { *serverConn debugStream io.Writer @@ -269,11 +270,9 @@ func handlePacket(s *Server, p orderedRequest) error { case *sshFxpRemovePacket: err := os.Remove(s.toLocalPath(p.Filename)) rpkt = statusFromError(p.ID, err) - case *sshFxpRenamePacket: - err := os.Rename(s.toLocalPath(p.Oldpath), s.toLocalPath(p.Newpath)) - rpkt = statusFromError(p.ID, err) case *sshFxpSymlinkPacket: - err := os.Symlink(s.toLocalPath(p.Targetpath), s.toLocalPath(p.Linkpath)) + // Relative targets are resolved from the link's directory, not workDir. + err := os.Symlink(s.toLocalTarget(p.Targetpath), s.toLocalPath(p.Linkpath)) rpkt = statusFromError(p.ID, err) case *sshFxpClosePacket: rpkt = statusFromError(p.ID, s.closeHandle(p.Handle)) @@ -368,6 +367,14 @@ func handlePacket(s *Server, p orderedRequest) error { return nil } +func (s *Server) toLocalPath(p string) string { + if s.workDir != "" && !path.IsAbs(p) { + p = path.Join(s.workDir, p) + } + + return s.toLocalTarget(p) +} + // Serve serves SFTP connections until the streams stop or the SFTP subsystem // is stopped. It returns nil if the server exits cleanly. func (svr *Server) Serve() error { @@ -550,6 +557,19 @@ func (p *sshFxpReaddirPacket) respond(svr *Server) responsePacket { return ret } +func (p *sshFxpRenamePacket) respond(svr *Server) responsePacket { + oldpath := svr.toLocalPath(p.Oldpath) + newpath := svr.toLocalPath(p.Newpath) + + // SSH_FXP_RENAME may not replace an existing file; posix-rename@openssh.com is the overwriting form. + // Like OpenSSH, refuse the request when newpath already exists rather than letting os.Rename clobber it. + if _, err := svr.lstat(newpath); err == nil { + return statusFromError(p.ID, &os.LinkError{Op: "rename", Old: oldpath, New: newpath, Err: syscall.EEXIST}) + } + + return statusFromError(p.ID, os.Rename(oldpath, newpath)) +} + func (p *sshFxpSetstatPacket) respond(svr *Server) responsePacket { path := svr.toLocalPath(p.Path) diff --git a/vendor/github.com/pkg/sftp/server_plan9.go b/vendor/github.com/pkg/sftp/server_plan9.go index 4e8ed0678..e34bcee8a 100644 --- a/vendor/github.com/pkg/sftp/server_plan9.go +++ b/vendor/github.com/pkg/sftp/server_plan9.go @@ -5,11 +5,7 @@ import ( "path/filepath" ) -func (s *Server) toLocalPath(p string) string { - if s.workDir != "" && !path.IsAbs(p) { - p = path.Join(s.workDir, p) - } - +func (s *Server) toLocalTarget(p string) string { lp := filepath.FromSlash(p) if path.IsAbs(p) { diff --git a/vendor/github.com/pkg/sftp/server_unix.go b/vendor/github.com/pkg/sftp/server_unix.go index 495b397c0..d4d735e9f 100644 --- a/vendor/github.com/pkg/sftp/server_unix.go +++ b/vendor/github.com/pkg/sftp/server_unix.go @@ -3,14 +3,6 @@ package sftp -import ( - "path" -) - -func (s *Server) toLocalPath(p string) string { - if s.workDir != "" && !path.IsAbs(p) { - p = path.Join(s.workDir, p) - } - +func (s *Server) toLocalTarget(p string) string { return p } diff --git a/vendor/github.com/pkg/sftp/server_windows.go b/vendor/github.com/pkg/sftp/server_windows.go index e14620398..d4c45b8c3 100644 --- a/vendor/github.com/pkg/sftp/server_windows.go +++ b/vendor/github.com/pkg/sftp/server_windows.go @@ -12,11 +12,7 @@ import ( "golang.org/x/sys/windows" ) -func (s *Server) toLocalPath(p string) string { - if s.workDir != "" && !path.IsAbs(p) { - p = path.Join(s.workDir, p) - } - +func (s *Server) toLocalTarget(p string) string { lp := filepath.FromSlash(p) if path.IsAbs(p) { // starts with '/' diff --git a/vendor/github.com/pkg/sftp/sftp.go b/vendor/github.com/pkg/sftp/sftp.go index 1e698bb27..7f62d1b7a 100644 --- a/vendor/github.com/pkg/sftp/sftp.go +++ b/vendor/github.com/pkg/sftp/sftp.go @@ -1,5 +1,5 @@ // Package sftp implements the SSH File Transfer Protocol as described in -// https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-02.txt +// https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-02 package sftp import ( @@ -48,7 +48,7 @@ const ( sshFxOPUnsupported = 8 // see draft-ietf-secsh-filexfer-13 - // https://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#section-9.1 + // https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-13#section-9.1 sshFxInvalidHandle = 9 sshFxNoSuchPath = 10 sshFxFileAlreadyExists = 11 diff --git a/vendor/modules.txt b/vendor/modules.txt index 21008deb2..c01c68c99 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -215,7 +215,7 @@ github.com/onsi/gomega/matchers/support/goraph/edge github.com/onsi/gomega/matchers/support/goraph/node github.com/onsi/gomega/matchers/support/goraph/util github.com/onsi/gomega/types -# github.com/pkg/sftp v1.13.12 +# github.com/pkg/sftp v1.13.13 ## explicit; go 1.25.0 github.com/pkg/sftp github.com/pkg/sftp/internal/encoding/ssh/filexfer