From 378d07af734740ee2eb3d699383046bd332ea73b Mon Sep 17 00:00:00 2001 From: bvulaj Date: Mon, 9 Oct 2017 14:03:36 -0400 Subject: [PATCH 1/2] Updated to work on some non-OpenBSD based systems --- jsch-agent-proxy-sshj/pom.xml | 2 +- .../jsch/agentproxy/usocket/NCUSocketFactory.java | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/jsch-agent-proxy-sshj/pom.xml b/jsch-agent-proxy-sshj/pom.xml index e520298..6c9e85d 100644 --- a/jsch-agent-proxy-sshj/pom.xml +++ b/jsch-agent-proxy-sshj/pom.xml @@ -14,7 +14,7 @@ - net.schmizz + com.hierynomus sshj [0.8.1,) diff --git a/jsch-agent-proxy-usocket-nc/src/main/java/com/jcraft/jsch/agentproxy/usocket/NCUSocketFactory.java b/jsch-agent-proxy-usocket-nc/src/main/java/com/jcraft/jsch/agentproxy/usocket/NCUSocketFactory.java index 2a24efa..bace2b6 100644 --- a/jsch-agent-proxy-usocket-nc/src/main/java/com/jcraft/jsch/agentproxy/usocket/NCUSocketFactory.java +++ b/jsch-agent-proxy-usocket-nc/src/main/java/com/jcraft/jsch/agentproxy/usocket/NCUSocketFactory.java @@ -8,8 +8,8 @@ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The names of the authors may not be used to endorse or promote products @@ -43,12 +43,13 @@ public NCUSocketFactory() throws AgentProxyException { StringBuilder sb = new StringBuilder(); try { p = Runtime.getRuntime().exec("nc -h"); - InputStream is = p.getErrorStream(); + InputStream is = p.getErrorStream().available() > 0 ? p.getErrorStream() : p.getInputStream(); byte[] buf = new byte[1024]; int i = 0; while((i = is.read(buf, 0, buf.length))>0){ sb.append(new String(buf, 0, i)); } + is.close(); } catch(IOException e){ } @@ -76,8 +77,9 @@ public class MySocket extends Socket { private InputStream is; private OutputStream os; + @Override public int readFull(byte[] buf, int s, int len) throws IOException { - int _len = len; + int _len = len; while(len>0){ int j = is.read(buf, s, len); if(j<=0) @@ -90,6 +92,7 @@ public int readFull(byte[] buf, int s, int len) throws IOException { return _len; } + @Override public void write(byte[] buf, int s, int len) throws IOException { os.write(buf, s, len); os.flush(); @@ -101,6 +104,7 @@ public void write(byte[] buf, int s, int len) throws IOException { this.is = p.getInputStream(); } + @Override public void close() throws IOException { p.getErrorStream().close(); p.getInputStream().close(); From 69520a3620a269e6c9161e9fdbd926dea4e61f4e Mon Sep 17 00:00:00 2001 From: bvulaj Date: Mon, 9 Oct 2017 14:06:56 -0400 Subject: [PATCH 2/2] Reverted some unecessary changes --- .../jcraft/jsch/agentproxy/usocket/NCUSocketFactory.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/jsch-agent-proxy-usocket-nc/src/main/java/com/jcraft/jsch/agentproxy/usocket/NCUSocketFactory.java b/jsch-agent-proxy-usocket-nc/src/main/java/com/jcraft/jsch/agentproxy/usocket/NCUSocketFactory.java index bace2b6..78f6e28 100644 --- a/jsch-agent-proxy-usocket-nc/src/main/java/com/jcraft/jsch/agentproxy/usocket/NCUSocketFactory.java +++ b/jsch-agent-proxy-usocket-nc/src/main/java/com/jcraft/jsch/agentproxy/usocket/NCUSocketFactory.java @@ -8,8 +8,8 @@ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The names of the authors may not be used to endorse or promote products @@ -77,9 +77,8 @@ public class MySocket extends Socket { private InputStream is; private OutputStream os; - @Override public int readFull(byte[] buf, int s, int len) throws IOException { - int _len = len; + int _len = len; while(len>0){ int j = is.read(buf, s, len); if(j<=0) @@ -92,7 +91,6 @@ public int readFull(byte[] buf, int s, int len) throws IOException { return _len; } - @Override public void write(byte[] buf, int s, int len) throws IOException { os.write(buf, s, len); os.flush(); @@ -104,7 +102,6 @@ public void write(byte[] buf, int s, int len) throws IOException { this.is = p.getInputStream(); } - @Override public void close() throws IOException { p.getErrorStream().close(); p.getInputStream().close();