Commit Graph

93 Commits

Author SHA1 Message Date
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
John Eikenberry b50b1f9eaf fix sendError usage to match packet type signature
sendError takes a requestPacket but was simplifying it to an ider
interface. Future work needed it to be requestPacket but I wanted to fix
didn't up type usage in its own commit.
2018-07-23 16:53:51 -07:00
John Eikenberry 523bded012 replace interface{} with more specific type 2018-07-23 16:38:21 -07:00
John Eikenberry 048358fb96 use correct param type instead of asserting
Instead of accepting a more general type and then asserting it to the
proper type, just take the proper type as the argument.
Also clean up some of the use of it where it checked old direct sending
code's return error (error is now always nil).
2018-07-23 15:53:41 -07:00
John Eikenberry 4cad28be43 eliminate bare values in composite literals
Using key-value pairs is much more future proof.
2018-07-23 14:49:12 -07:00
John Eikenberry d0a1c8098b remove unnecessary type
Added to shorten code text, but not used enough to be worth the extra type.
2018-07-23 12:18:00 -07:00
John Eikenberry 218c0d4148 Opendir return an error status when not found
The initial Opendir packet is supposed to repond with an error status if
the directory wasn't found. It was just returning a handle without
checking, now it does a Stat on the path and only returns the handle if
the Stat is successful and it indicates it is a directory, otherwise it
returns an error.
2018-05-26 13:59:55 -07:00
Allan Feid 820ccceeef Send unsupported error on extended packets.
Following the rules outlined here:

https://tools.ietf.org/html/draft-ietf-secsh-filexfer-extensions-00

Return an SSH_FXP_STATUS with appropriate status error for extended
packets that we do not support.
2018-03-19 10:32:22 -04:00
John Eikenberry 9649a986f0 remove unused variables 2018-02-15 11:00:22 -08:00
John Eikenberry 738e088bbd support handlers returning explicit error codes
Add errors for all the SSH_FXP_STATUS codes to give the developer
implementing request server handlers greater control over the returned
codes. Most helpful in cases where nothing currently would work (eg.
unsupported).

Fixes #223
2018-01-26 17:26:44 -08:00
John Eikenberry 4ab81b0271 improve statusFromError readability 2018-01-25 17:29:36 -08:00
John Eikenberry bc6b56aae0 packageManager to use pointer receivers everywhere
Had a problem with getting a copy because a value receiver called a
pointer receiver.
2017-08-20 15:23:55 -07:00
John Eikenberry 26ceac758e add os.ErrNotExist handling into statusFromError
And remove errorAdapter() as this makes it unnecessary.
2017-08-20 14:54:45 -07:00
andreas 4d7bb970c4 Resolved conflict with SftpServerWorkerCount
Splitted cleanPath into cleanPacketPath and cleanPath for better handling of slashes in file paths
Added test for cleanPath func
Removed code duplication => filepath.ToSlash(filepath.Clean(...)) => cleanPath(...)
Fixed tests for runLs to match year or time
Renamed constants to fit hound rules
2017-08-13 14:00:08 +02:00
andreas ec08c0d53b Moved permission detection for runLs to server.go
Make runLs return the recommended format in stubs, even if it does not contain all information
Removed unused parameter
2017-08-10 07:34:48 +02:00
John Eikenberry e97b9a47e1 avoid data race in worker creation
There is a data race with the waitgroup (wg) object used to synchronize
the workers with the server exit. The workers called wg.Add()
asynchronously and it was possible for the Wait() to get hit before any
of the Add() calls were made in certain conditions. I only ever saw this
sporatically in the travis tests.

This fixes it by making the wg.Add() calls synchronous.
2017-07-03 17:53:55 -07:00
John Eikenberry 07d4ed1b5c don't copy lock
govet pointed out that I was copying a lock when creating/assigning the
connection object. It didn't cause any issues, but was a bad practice.
2017-07-03 17:45:58 -07:00
John Eikenberry 5024cb048c Move packer ordering code into packet-manager
The worker/packet mangement code needs to be in the packet manager so
the request-server can utilize it as well. This also improves the
encapsulation of the method as it relied on internal data that should be
better isolated inside the file/struct.
2017-04-23 13:47:05 -07:00
John Eikenberry d1bd7b3f9c ensure packets are processed in order
File operations that happen after the open packet has been received,
like reading/writing, can be done with the pool as the order they are
run in doesn't matter (the packets contain the file offsets).

Command operations, on the other hand, need to be serialized.

This flips between a pool of workers for file operations and a single
worker for everything else. It flips on Open and Close packets.
2017-04-17 17:24:15 -07:00
John Eikenberry 5fd073bcc3 decouple packet channel from server struct
looking to create 2 pools, so I want to pass the channel in
2017-04-17 17:24:15 -07:00
Pavel Borzenkov 9aa225fc15 Don't copy Server struct in sendPacket/sendError
Server struct contains Mutex which might be copied in inconsistent
state. Avoid this by declaring methods on pointer receiver.

This calms down go race detector.

Signed-off-by: Pavel Borzenkov <pavel.borzenkov@gmail.com>
2017-04-05 14:15:57 -07:00
John Eikenberry 5152c21cf9 integrate packageManager into servers 2017-03-23 16:15:04 -07:00
John Eikenberry 51cb116815 better name: packet -> requestPacket 2017-03-23 16:15:04 -07:00
John Eikenberry 89c474ca1d new name for id (now ider) interface
more in line with go naming scheme for interfaces
better greppability
2017-03-23 16:15:04 -07:00
John Eikenberry 0b42971846 packet unmarshalling code into main server loop
This means we are now passing full packets to the workers. This makes
the request id's available which is required for fixing packet ordering.
Benchmark tests weren't affected at all.
2017-03-23 16:15:03 -07:00
John Eikenberry 4f1fe4fe3b Use common packet typing code
Remove duplication due to request code being separate.
2017-03-23 16:15:03 -07:00
John Eikenberry 890b9f1a4a change readonly checks to interface type checks 2017-03-23 16:15:03 -07:00
George Xie 725c6ac61d make path more Unix like on windows servers 2017-03-01 20:04:44 -08:00
Dave Cheney d4c18e7ffd Integrate readPacket and writePacket into handlePacket (#120) 2016-06-15 21:17:20 +10:00
Dave Cheney 3a7eae5fbb Introduce serverConn (#119) 2016-06-15 21:08:29 +10:00