Commit Graph

122 Commits

Author SHA1 Message Date
Cassondra Foesch d9ce3caa72 convert uses of uint8 instead of fxp to fxp 2025-05-30 13:30:46 +00:00
powellnorma 524cb6221d Merge branch 'master' into win-root 2025-01-01 16:23:41 +01:00
powellnorma 8dcbf480f2 windows root: add stat for '/' 2025-01-01 16:23:02 +01:00
Peter Verraedt c1f47ba1b9
Add WithMaxTxPacket server option
Add the WithMaxTxPacket and WithRSMaxTxPacket server options to increase
the maximum tx packet size to a value above 32K. This allows to send
bigger chunks of data to the client as response to a read request. As
the client specifies the wanted length, it should be safe to increase
the server maximum value.

This in particular allows the implemented Client with the
MaxPacketUnchecked option to retrieve data in larger chunks.

Signed-off-by: Peter Verraedt <peter@verraedt.be>
2024-04-26 09:04:33 +02:00
Nicola Murino e52de81b00
Fix merge with master 2024-04-09 18:08:42 +02:00
Nicola Murino 073d834b5c
Merge branch 'master' into win-root 2024-04-09 18:03:22 +02:00
Cassondra Foesch 5d66cdeb9a better cascading 2024-02-06 15:02:43 +00:00
Cassondra Foesch e21cd94805 move setting times to the last operation so chown doesn't have a chance to alter atime or mtime 2024-01-19 01:27:16 +00:00
Cassondra Foesch f3501dc6ba address code review 2024-01-19 01:23:22 +00:00
Cassondra Foesch d1903fbd46 rework client to prevent after-close usage, and support perm at open 2024-01-19 00:20:23 +00:00
powellnorma 0395c12789 review adjustments 5 2024-01-14 09:01:02 +01:00
powellnorma 35c82d76eb review adjustments 4 2024-01-11 10:16:37 +01:00
powellnorma 38928181c7 review adjustments 3 2024-01-10 13:38:40 +01:00
powellnorma 931e169fab review adjustments 2024-01-07 12:49:09 +01:00
powellnorma c7065eab39 server.go: "/" for windows 2024-01-06 13:16:32 +01:00
Joe Tsai e9377c8373 Properly handle io.EOF error conditions when reading
Previously, the Server.Serve method would never return nil,
because the infinite for-loop handling request packets would
only break if reading a packet reported an error.
A common termination condition is when the underlying connection
is closed and recvPacket returns io.EOF.
In which case Serve should ignore io.EOF and
treat it as a normal shutdown.

However, this means that recvPacket must correctly handle io.EOF
such that it never reports io.EOF if a packet is partially read.
There are two calls to io.ReadFull in recvPacket.
The first call correctly forwards an io.EOF error
if no additional bytes of the next packet are read.
However, the second call incorrectly forwards io.EOF
when no bytes of the payload could be read.
This is incorrect since we already read the length and
should convert the io.EOF into an io.ErrUnexpectedEOF.
2023-08-09 16:35:43 -07:00
Cassondra Foesch bd61319b07 refactor sshfx encoding, fix link rot, go fmt 2023-03-27 17:05:24 +00:00
Nicola Murino 08880975fb statusFromError: improve support for error wrapping 2022-12-25 17:21:42 +01:00
Mathias Fredriksson c93b0a0af2 Refactor tests and make `toLocalPath` a method on `Server` 2022-10-18 18:17:45 +03:00
Mathias Fredriksson 32ac60b179 Fix use of double-toLocalPath in `sshFxpOpendirPacket` 2022-10-17 17:11:18 +03:00
Mathias Fredriksson 78e59618f6 Revert unintended change 2022-10-17 17:09:17 +03:00
Mathias Fredriksson 6a7168cf46 Add support for working directory in Server
This commit allows the working directory for the (old) Server
implementation to be changed without doing a `os.Chdir` first.

The feature can be enabled with `sftp.WithServerWorkingDirectory(dir)`
passed as an option to `sftp.NewServer`.

It is useful when the `sftp` is used as part of a larger service that
does more than just serve `sftp` and using `os.Chdir` is not an option.

The fallback behavior (when the option is not specified) is that the
path remains unmodified (as before).
2022-10-14 15:54:59 +03:00
Cassondra Foesch b94f1ccedd NameLookupFileLister so that RequestServer does not automatically lookup system usernames 2021-08-17 11:40:30 +00:00
Cassondra Foesch 00dc491201 refactor ls formatting work 2021-08-11 15:09:43 +00:00
Cassondra Foesch d1599c6376 remove clamp function 2021-08-11 11:12:34 +00:00
Cassondra Foesch e683b3b6ed cleanup request mutex usage 2021-08-02 11:23:37 +00:00
Nicola Murino eaa697cc21
Merge pull request #441 from CiscoM31/migrate_to_go_errors
Use go errors instead of github.com/pkg/errors
2021-07-05 21:28:12 +02:00
Cassondra Foesch 71618243c4 deconvert encoded paths on windows servers 2021-06-29 15:16:15 +00:00
Sebastien Rosset (serosset) 3b8042dfc0 Use go errors instead of github.com/pkg/errors 2021-06-04 14:18:41 -07:00
Nicola Murino a88961882e remove some redundant types 2021-02-22 22:29:35 +01:00
Cassondra Foesch 861a8eaf5c pointer receivers and statusFromError(uint32, error) 2021-02-22 12:11:42 +00:00
Cassondra Foesch 5e8f9f4960 MarshalBinary now gives a 4-byte header for length, marshalPacket gives a two-stage write 2021-02-22 12:04:43 +00:00
Fazlul Shahriar bbd5cf2737
Merge branch 'master' into plan9 2020-09-15 12:06:10 -04:00
Will Norris 8df2eb9876 server: better handle IsNotExist errors
Return early from statusFromError if os.IsNotExist is true.
2020-09-14 07:58:12 -07:00
Will Norris 28f6fd9187 server: use os.IsNotExist to map sshFxNoSuchFile
Always use os.IsNotExist to identify any OS specific error types that
represent missing files or directories.  This resolves an issue on
Windows where some system errors (ENOTDIR) were not being identified as
'not found' errors and mapped to sshFxNoSuchFile.

fixes #381
2020-09-13 21:38:21 -07:00
Fazlul Shahriar 6120cae121
Fix build on Plan 9
All test are passing on Plan 9, and I've also verified
`examples/go-sftp-server` is working.
2020-09-10 18:18:22 -04:00
Nicola Murino 1f178f9671 the allocator can now be enabled per request
Other minor changes as per review comments
2020-03-18 09:36:07 +01:00
Nicola Murino 3f969fcd59 add optional AllocationModeOptimized
after processing a packet we keep in memory the allocated slices and we reuse
them for new packets.
Slices are allocated in:

- recvPacket
- when we receive a sshFxpReadPacket (downloads)

The allocated slices have a fixed size = maxMsgLength.

Allocated slices are referenced to the request order id and are marked for reuse
after a request is served in maybeSendPackets.

The allocator is added to the packetManager struct and it is cleaned at the end
of the Serve() function.

This allocation mode is optional and disabled by default
2020-03-14 19:42:19 +01:00
Nicola Murino 0f0e40a3a6 minor changes as requested in the review 2020-03-10 15:35:56 +01:00
Nicola Murino 3ea9f24c15 server: remove now unused maxTxPacket
maxTxPacket was only used to get the size for the read packet it is not
needed anymore
2020-03-10 11:48:52 +01:00
Nicola Murino eeafeeff60 FxpReadPacket: add an helper method for slice allocation
This way we can use the same method in both server and request-server
2020-03-10 11:46:46 +01:00
John Eikenberry 1bc3ea14d1 fix issue with file put resume/append
Fixes issue with append uploads. Was opening the file with O_APPEND, but
it uses WriteAt() to write the data which doesn't work with a file
opened in append mode. Removing the append flag fixes the issue as the
client is sending the offsets anyways.

Also added a note to the Request server's FileWriter interface on
handling append flags.
2020-01-05 14:23:49 -08:00
Nicola Murino b4ea0fd6f6 fix lint issues
These lint issues remain:

- request-errors.go, aliases for new error types
- request-attrs.go, UidGid. Changing this will break compatibility
2019-08-30 17:04:37 +02:00
Nicola Murino b519cb8db9 define supported extensions in one place and use for both server and request-server 2019-08-27 09:18:15 +02:00
Tommie Gannert 687cea6a44 Announce the posix-rename extension in the server. 2019-08-26 09:02:10 +02:00
John Eikenberry 5a2fe52342 Merge branch 'soopsio-master' into test 2019-08-25 20:32:04 -07:00
soopsio 55133952b5 gracefully handle unknown extended packets
Fixed a problem that caused secureFX to crash when
errUnknownExtendedPacket in SFTP server mode
2019-08-25 20:19:45 -07:00
Tommie Gannert 2c24eaad1c Implement the hardlink@openssh.com extension.
Both client and server. This is documented in

  https://github.com/openssh/openssh-portable/blob/master/PROTOCOL

Draft 7 of SFTP added support for SSH_FXP_LINK which supports both
symlinks and hardlinks, but unfortunately OpenSSH doesn't support
that:

  https://tools.ietf.org/html/draft-ietf-secsh-filexfer-07#section-7.7

Adding support for this as an option would be a nice extension to
this.
2019-08-25 20:16:37 -07:00
John Eikenberry 7f7e75b40d ensure packet responses in same order as requests
Previous code used the request ids to do ordering. This worked until a
client came along that used un-ordered request ids. This reworks the
ordering to use an internal counter (per session) to order all packets
ensuring that responses are sent in the same order as the requests were
received.

Fixes #260
2018-08-01 13:18:57 -07:00
John Eikenberry 1afc1d9a78 refactor server response to allow for extending
Instead of sendPacket/sendError being sprayed all over the place, this
change has all those places instead return a responsePacket (eventually)
back to the main handling function which then calls sendPacket in one
place.

Behaviour of the code should remain exactly the same.

This makes it much easier to work with the response packets (eg. for the
packet ordering issue I'm working on).
2018-07-25 15:01:43 -07:00