You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2018/02/07 07:58:32 UTC
[4/5] mina-sshd git commit: [SSHD-799] Send
SSH_MSG_CHANNEL_OPEN_FAILURE if failed to open port forwarding connection
[SSHD-799] Send SSH_MSG_CHANNEL_OPEN_FAILURE if failed to open port forwarding connection
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/09dec8af
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/09dec8af
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/09dec8af
Branch: refs/heads/master
Commit: 09dec8af44e8081b42f85453ea87ce26d27c0ded
Parents: e077dae
Author: Goldstein Lyor <ly...@c-b4.com>
Authored: Sun Feb 4 16:31:56 2018 +0200
Committer: Goldstein Lyor <ly...@c-b4.com>
Committed: Wed Feb 7 09:41:25 2018 +0200
----------------------------------------------------------------------
.../helpers/AbstractConnectionService.java | 13 +++++++-----
.../sshd/server/forward/TcpipServerChannel.java | 21 ++++++++++++--------
2 files changed, 21 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/09dec8af/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractConnectionService.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractConnectionService.java b/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractConnectionService.java
index 262ba9d..68bf8db 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractConnectionService.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractConnectionService.java
@@ -639,19 +639,22 @@ public abstract class AbstractConnectionService<S extends AbstractSession>
buf.putInt(window.getPacketSize());
session.writePacket(buf);
} else {
+ int reasonCode = 0;
+ String message = "Generic error while opening channel: " + channelId;
Throwable exception = future.getException();
if (exception != null) {
- String message = exception.getMessage();
- int reasonCode = 0;
if (exception instanceof SshChannelOpenException) {
reasonCode = ((SshChannelOpenException) exception).getReasonCode();
} else {
message = exception.getClass().getSimpleName() + " while opening channel: " + message;
}
-
- Buffer buf = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_OPEN_FAILURE, message.length() + Long.SIZE);
- sendChannelOpenFailure(buf, sender, reasonCode, message, "");
+ } else {
+ log.warn("operationComplete({}) no exception on closed future={}",
+ AbstractConnectionService.this, future);
}
+
+ Buffer buf = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_OPEN_FAILURE, message.length() + Long.SIZE);
+ sendChannelOpenFailure(buf, sender, reasonCode, message, "");
}
} catch (IOException e) {
if (log.isDebugEnabled()) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/09dec8af/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java b/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java
index 2c16478..8e1c268 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java
@@ -142,8 +142,11 @@ public class TcpipServerChannel extends AbstractServerChannel {
if (log.isDebugEnabled()) {
log.debug("doInit(" + this + ")[" + type + "][haveFilter=" + (filter != null) + "] filtered out " + address);
}
- super.close(true);
- f.setException(new SshChannelOpenException(getId(), SshConstants.SSH_OPEN_ADMINISTRATIVELY_PROHIBITED, "Connection denied"));
+ try {
+ f.setException(new SshChannelOpenException(getId(), SshConstants.SSH_OPEN_ADMINISTRATIVELY_PROHIBITED, "Connection denied"));
+ } finally {
+ super.close(true);
+ }
return f;
}
} catch (Error e) {
@@ -244,12 +247,14 @@ public class TcpipServerChannel extends AbstractServerChannel {
protected void handleChannelOpenFailure(OpenFuture f, Throwable problem) {
signalChannelOpenFailure(problem);
notifyStateChanged(problem.getClass().getSimpleName());
- close(true);
-
- if (problem instanceof ConnectException) {
- f.setException(new SshChannelOpenException(getId(), SshConstants.SSH_OPEN_CONNECT_FAILED, problem.getMessage(), problem));
- } else {
- f.setException(problem);
+ try {
+ if (problem instanceof ConnectException) {
+ f.setException(new SshChannelOpenException(getId(), SshConstants.SSH_OPEN_CONNECT_FAILED, problem.getMessage(), problem));
+ } else {
+ f.setException(problem);
+ }
+ } finally {
+ close(true);
}
}