You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by gn...@apache.org on 2014/09/17 08:19:33 UTC
git commit: [SSHD-349] Add support for Putty channel requests
Repository: mina-sshd
Updated Branches:
refs/heads/master 247f5e4d1 -> 356a4dee8
[SSHD-349] Add support for Putty channel requests
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/356a4dee
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/356a4dee
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/356a4dee
Branch: refs/heads/master
Commit: 356a4dee8f32eba5fef2fc1e07970fc49677f198
Parents: 247f5e4
Author: Guillaume Nodet <gn...@apache.org>
Authored: Wed Sep 17 08:04:37 2014 +0200
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Wed Sep 17 08:04:37 2014 +0200
----------------------------------------------------------------------
.../sshd/server/channel/ChannelSession.java | 2 +-
.../server/channel/PuttyRequestHandler.java | 68 ++++++++++++++++++++
2 files changed, 69 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/356a4dee/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSession.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSession.java b/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSession.java
index b797346..fa8abba 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSession.java
@@ -39,7 +39,6 @@ import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.PtyMode;
import org.apache.sshd.common.RequestHandler;
import org.apache.sshd.common.SshConstants;
-import org.apache.sshd.common.channel.ChannelAsyncInputStream;
import org.apache.sshd.common.channel.ChannelAsyncOutputStream;
import org.apache.sshd.common.channel.ChannelOutputStream;
import org.apache.sshd.common.future.CloseFuture;
@@ -188,6 +187,7 @@ public class ChannelSession extends AbstractServerChannel {
public ChannelSession() {
addRequestHandler(new ChannelSessionRequestHandler());
+ addRequestHandler(new PuttyRequestHandler());
}
@Override
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/356a4dee/sshd-core/src/main/java/org/apache/sshd/server/channel/PuttyRequestHandler.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/channel/PuttyRequestHandler.java b/sshd-core/src/main/java/org/apache/sshd/server/channel/PuttyRequestHandler.java
new file mode 100644
index 0000000..4f2e980
--- /dev/null
+++ b/sshd-core/src/main/java/org/apache/sshd/server/channel/PuttyRequestHandler.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sshd.server.channel;
+
+import org.apache.sshd.common.Channel;
+import org.apache.sshd.common.RequestHandler;
+import org.apache.sshd.common.util.Buffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Handles Putty specific channel requests as indicated by
+ * <A HREF="http://tartarus.org/~simon/putty-snapshots/htmldoc/AppendixF.html">Appendix F: SSH-2 names specified for PuTTY</A>
+ */
+public class PuttyRequestHandler implements RequestHandler<Channel> {
+
+ public static final String REQUEST_SUFFIX = "@putty.projects.tartarus.org";
+
+ protected final Logger log = LoggerFactory.getLogger(getClass());
+
+ public Result process(Channel channel, String request, boolean wantReply, Buffer buffer) throws Exception {
+ // make sure proper suffix
+ if ((request == null)
+ || (request.length() <= REQUEST_SUFFIX.length())
+ || (!request.endsWith(REQUEST_SUFFIX))) {
+ return Result.Unsupported;
+ }
+
+ String opcode = request.substring(0, request.length() - REQUEST_SUFFIX.length());
+ return processPuttyOpcode(channel, request, opcode, wantReply, buffer);
+ }
+
+ protected Result processPuttyOpcode(Channel channel, String request, String opcode, boolean wantReply, Buffer buffer) throws Exception {
+ if ("simple".equalsIgnoreCase(opcode)) {
+ // Quote: "There is no message-specific data"
+ return Result.ReplySuccess;
+ } else if ("winadj".equalsIgnoreCase(opcode)) {
+ // Quote: "Servers MUST treat it as an unrecognized request and respond with SSH_MSG_CHANNEL_FAILURE"
+ return Result.ReplyFailure;
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("processPuttyOpcode(" + opcode + ")"
+ + "[buffer size=" + buffer.available() + "]"
+ + "[reply=" + wantReply + "]"
+ + " Unknown request: " + request);
+ }
+
+ return Result.ReplyFailure;
+ }
+
+}