]> source.dussan.org Git - tigervnc.git/commitdiff
Fix for issue #796
authorBrian P. Hinz <bphinz@users.sf.net>
Sun, 3 Nov 2019 21:00:50 +0000 (16:00 -0500)
committerBrian P. Hinz <bphinz@users.sf.net>
Sun, 3 Nov 2019 21:02:24 +0000 (16:02 -0500)
java/com/tigervnc/vncviewer/CConn.java
java/com/tigervnc/vncviewer/Parameters.java
java/com/tigervnc/vncviewer/Tunnel.java

index 3aee46d570fa0935022c24959bce1f520fd64ab7..75f6b74b9cfb75ff0ebe615bb2d0d8dbfc4099be 100644 (file)
@@ -128,15 +128,20 @@ public class CConn extends CConnection implements
           int localPort = TcpSocket.findFreeTcpPort();
           if (localPort == 0)
             throw new Exception("Could not obtain free TCP port");
-          Tunnel.createTunnel(this, localPort);
+          String gatewayHost = Tunnel.getSshHost();
+          if (gatewayHost.isEmpty())
+            gatewayHost = getServerName();
+          Tunnel.createTunnel(gatewayHost, getServerName(),
+                              getServerPort(), localPort);
           sock = new TcpSocket("localhost", localPort);
+          vlog.info("connected to localhost port "+localPort);
         } else {
           sock = new TcpSocket(getServerName(), getServerPort());
+          vlog.info("connected to host "+getServerName()+" port "+getServerPort());
         }
       } catch (java.lang.Exception e) {
         throw new Exception(e.getMessage());
       }
-      vlog.info("connected to host "+getServerName()+" port "+getServerPort());
     } else {
       String name = sock.getPeerEndpoint();
       if (listenMode.getValue())
index 2f8a585f83f1b4e03bbd94aa3e4b7c7ee31f64fe..aa4be90a149132c548088f4ce32ac5657242720b 100644 (file)
@@ -183,11 +183,6 @@ public class Parameters {
     "specified in an applet parameter or on the command line",
     false);
 
-  public static StringParameter vncServerName
-  = new StringParameter("Server",
-    "The VNC server <host>[:<dpyNum>] or <host>::<port>",
-    "");
-
   public static BoolParameter acceptBell
   = new BoolParameter("AcceptBell",
     "Produce a system beep when requested to by the server.",
index 2e19160ae9aa4676977aebb2bb47949221ee1752..ecb048b712a85bef3521aa698d15996f31d0b8b0 100644 (file)
@@ -52,18 +52,10 @@ public class Tunnel {
   private final static String DEFAULT_VIA_TEMPLATE
     = "-f -L %L:%H:%R %G sleep 20";
 
-  public static void createTunnel(CConn cc, int localPort) throws Exception {
-    int remotePort;
-    String gatewayHost;
-    String remoteHost;
-
-    remotePort = cc.getServerPort();
-    gatewayHost = cc.getServerName();
-    remoteHost = "localhost";
-    if (!via.getValue().isEmpty()) {
-      gatewayHost = getSshHost();
-      remoteHost = cc.getServerName();
-    }
+  public static void createTunnel(String gatewayHost,
+                                  String remoteHost,
+                                  int remotePort,
+                                  int localPort) throws Exception {
 
     String pattern = extSSHArgs.getValue();
     if (pattern == null || pattern.isEmpty()) {
@@ -102,12 +94,12 @@ public class Tunnel {
 
   public static String getSshHost() {
     String sshHost = via.getValue();
-    if (sshHost.isEmpty())
-      return vncServerName.getValue();
-    int end = sshHost.indexOf(":");
-    if (end < 0)
-      end = sshHost.length();
-    sshHost = sshHost.substring(sshHost.indexOf("@")+1, end);
+    if (!sshHost.isEmpty()) {
+      int end = sshHost.indexOf(":");
+      if (end < 0)
+        end = sshHost.length();
+      sshHost = sshHost.substring(sshHost.indexOf("@")+1, end);
+    }
     return sshHost;
   }
 
@@ -132,7 +124,8 @@ public class Tunnel {
       return sshKeyFile.getValue();
     String[] ids = { "id_dsa", "id_rsa" };
     for (String id : ids) {
-      File f = new File(FileUtils.getHomeDir()+".ssh/"+id);
+      File f = new File(FileUtils.getHomeDir()+".ssh"+
+                        FileUtils.getFileSeparator()+id);
       if (f.exists() && f.canRead())
         return(f.getAbsolutePath());
     }
@@ -154,7 +147,8 @@ public class Tunnel {
       // NOTE: jsch does not support all ciphers.  User may be
       //       prompted to accept host key authenticy even if
       //       the key is in the known_hosts file.
-      File knownHosts = new File(FileUtils.getHomeDir()+".ssh/known_hosts");
+      File knownHosts = new File(FileUtils.getHomeDir()+".ssh"+
+                                 FileUtils.getFileSeparator()+"known_hosts");
       if (knownHosts.exists() && knownHosts.canRead())
            jsch.setKnownHosts(knownHosts.getAbsolutePath());
       ArrayList<File> privateKeys = new ArrayList<File>();
@@ -196,7 +190,10 @@ public class Tunnel {
       if (session.getConfig("StrictHostKeyChecking") == null)
         session.setConfig("StrictHostKeyChecking", "ask");
       session.connect();
-      session.setPortForwardingL(localPort, remoteHost, remotePort);
+      if (gatewayHost.equals(remoteHost))
+        session.setPortForwardingL(localPort, new String("localhost"), remotePort);
+      else
+        session.setPortForwardingL(localPort, remoteHost, remotePort);
     } catch (java.lang.Exception e) {
       throw new Exception(e.getMessage()); 
     }