-
Notifications
You must be signed in to change notification settings - Fork 366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FileChannel.lock() doesn't work for read-only channels from SftpFileSystemProvider.newFileChannel() #384
Comments
tomaswolf
added a commit
to tomaswolf/mina-sshd
that referenced
this issue
Jun 3, 2023
SSH_FXP_BLOCK is available only in SFTPv6. It was introduced in draft 08. Throw an UnsupportedOperationException if the negotiated SFTP version is lower. Respect the contract of FileChannel.lock(): a shared lock can be requested only if the channel was opened for reading, and an exclusive lock only if the channel is writable. Check this, and throw appropriate exceptions if the condition is violated. Pass on the correct lock flags to the server. At the server, repeat the version check, and respect the flags passed. Since Java does not have delete locks we map them to write locks. The draft RFC[1] is silent on what to do if no flags are passed at all: we use an exclusive write lock if the handle was opened for writing, and a shared read lock otherwise. We cannot throw an exception since we must be able to support old Apache MINA sshd clients that sent zero as lock flags. [1] https://www.ietf.org/archive/id/draft-ietf-secsh-filexfer-13.txt Bug: apache#384
tomaswolf
added a commit
to tomaswolf/mina-sshd
that referenced
this issue
Jun 3, 2023
SSH_FXP_BLOCK is available only in SFTPv6. It was introduced in draft 08. Throw an UnsupportedOperationException if the negotiated SFTP version is lower. Respect the contract of FileChannel.lock(): a shared lock can be requested only if the channel was opened for reading, and an exclusive lock only if the channel is writable. Check this, and throw appropriate exceptions if the condition is violated. Pass on the correct lock flags to the server. At the server, repeat the version check, and respect the flags passed. Since Java does not have delete locks we map them to write locks. The draft RFC[1] is silent on what to do if no flags are passed at all: we use an exclusive write lock if the handle was opened for writing, and a shared read lock otherwise. We cannot throw an exception since we must be able to support old Apache MINA sshd clients that sent zero as lock flags. [1] https://www.ietf.org/archive/id/draft-ietf-secsh-filexfer-13.txt Bug: apache#384
tomaswolf
added a commit
to tomaswolf/mina-sshd
that referenced
this issue
Jun 5, 2023
SSH_FXP_BLOCK is available only in SFTPv6. It was introduced in draft 08. Throw an UnsupportedOperationException if the negotiated SFTP version is lower. Respect the contract of FileChannel.lock(): a shared lock can be requested only if the channel was opened for reading, and an exclusive lock only if the channel is writable. Check this, and throw appropriate exceptions if the condition is violated. Pass on the correct lock flags to the server. At the server, repeat the version check, and respect the flags passed. Since Java does not have delete locks we map them to write locks. The draft RFC[1] is silent on what to do if no flags are passed at all: we use an exclusive write lock if the handle was opened for writing, and a shared read lock otherwise. We cannot throw an exception since we must be able to support old Apache MINA sshd clients that sent zero as lock flags. [1] https://www.ietf.org/archive/id/draft-ietf-secsh-filexfer-13.txt Bug: apache#384
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Version
master
Bug description
The following code fails:
This creates a read-only file channel and tries to obtain a shared (read) lock. It fails with an Apache MINA sshd server returning a general failure.
Actual behavior
Obtaining the lock throws an exception.
Expected behavior
The lock can be obtained (if there are no conflicts).
Relevant log output
No response
Other information
The text was updated successfully, but these errors were encountered: