Subject: Bug#1469: But wait; there is more... patches!

From: Melroy van den Berg <[email-masked]>
Date: Tue, 19 May 2020 21:24:09 +0000

Hi Mike & Uli,

As Mike suggested, I redone all changes (plus even some more bonus items).
Since I was in a separate git branch I could run the format-patch easily via:git format-patch master. Thanks for the suggestion.

@Uli I'm using the auto-formatter for C++ built-in in VS Code.

I think the end-result with all the separate patches makes more sense now, sorry I didn't do it right away. I think once I have a wiki account, I will add all these best practices your x2go wiki. Instead of Attachment: <your-patch.diff>: https://wiki.x2go.org/doku.php/wiki:bugs?s[]=git&s[]=patch#bug_submission_with_a_patch.

See the attachments for all the patches in this mail (11 in total). Thanks in advance.

Best regards,
Melroy van den Berg

From c633f110532587e1568e93735688d926bce99cb7 Mon Sep 17 00:00:00 2001
From: Melroy van den Berg <[email-masked]>
Date: Tue, 19 May 2020 22:40:06 +0200
Subject: [PATCH 02/11] endl for every debug line..

---
 src/sshmasterconnection.cpp | 140 ++++++++++++++++++------------------
 1 file changed, 68 insertions(+), 72 deletions(-)

diff --git a/src/sshmasterconnection.cpp b/src/sshmasterconnection.cpp
index 424cad2..f598e9c 100644
--- a/src/sshmasterconnection.cpp
+++ b/src/sshmasterconnection.cpp
@@ -161,7 +161,7 @@ SshMasterConnection::SshMasterConnection(QObject *parent, QString host, int port
     kerberosDelegation = false;
     x2goDebug << "SshMasterConnection, host " << host << "; port " << port << "; user " << user
               << "; useproxy " << useproxy << "; proxyserver " << proxyserver
-              << "; proxyport " << proxyport;
+              << "; proxyport " << proxyport << endl;
     this->host = host;
     // If the hostname starts with "!" do not perform loginCheck() for this connection
     if (this->host.indexOf("!") == 0)
@@ -202,7 +202,7 @@ SshMasterConnection::SshMasterConnection(QObject *parent, QString host, int port
         {
             QString error_msg = tr("Cannot create SSH session.");
             error_msg += " " + tr("Using environment-provided username.");
-            x2goDebug << error_msg;
+            x2goDebug << error_msg << endl;
         }
         else
         {
@@ -214,12 +214,12 @@ SshMasterConnection::SshMasterConnection(QObject *parent, QString host, int port
 
             if (ssh_options_parse_config(tmp_session, NULL) < 0)
             {
-                x2goDebug << "Warning: unable to parse the SSH config file.";
+                x2goDebug << "Warning: unable to parse the SSH config file." << endl;
             }
 
             char *inferred_username = NULL;
             ssh_options_get(tmp_session, SSH_OPTIONS_USER, &inferred_username);
-            x2goDebug << "Temporary session user name after config file parse: " << inferred_username;
+            x2goDebug << "Temporary session user name after config file parse: " << inferred_username << endl;
 
             this->user = QString::fromLocal8Bit(inferred_username);
 
@@ -240,18 +240,18 @@ SshMasterConnection::SshMasterConnection(QObject *parent, QString host, int port
 
     if (kerberos)
     {
-        x2goDebug << "Starting SSH connection with Kerberos authentication.";
+        x2goDebug << "Starting SSH connection with Kerberos authentication." << endl;
     }
     else
     {
-        x2goDebug << "Starting SSH connection without Kerberos authentication.";
+        x2goDebug << "Starting SSH connection without Kerberos authentication." << endl;
     }
-    x2goDebug << "SshMasterConnection, instance " << this << " created.";
+    x2goDebug << "SshMasterConnection, instance " << this << " created." << endl;
 }
 
 void SshMasterConnection::slotSshProxyConnectionOk()
 {
-    x2goDebug << "SSH proxy connected.";
+    x2goDebug << "SSH proxy connected." << endl;
 
     localProxyPort = PROXYTUNNELPORT;
     while (ONMainWindow::isServerRunning(localProxyPort))
@@ -319,12 +319,12 @@ void SshMasterConnection::addReverseTunnelConnections()
                 if (rc == SSH_OK)
                 {
                     emit reverseTunnelOk(reverseTunnelRequest[i].creator);
-                    x2goDebug << "Listening for TCP/IP connections on " << reverseTunnelRequest[i].forwardPort;
+                    x2goDebug << "Listening for TCP/IP connections on " << reverseTunnelRequest[i].forwardPort << endl;
                 }
                 if (rc == SSH_ERROR)
                 {
                     QString err = ssh_get_error(my_ssh_session);
-                    x2goDebug << "Forward port " << reverseTunnelRequest[i].forwardPort << " failed:" << err;
+                    x2goDebug << "Forward port " << reverseTunnelRequest[i].forwardPort << " failed:" << err << endl;
                     emit reverseTunnelFailed(reverseTunnelRequest[i].creator, err);
                 }
             }
@@ -339,7 +339,7 @@ void SshMasterConnection::checkReverseTunnelConnections()
     ssh_channel chan = ssh_channel_accept_forward(my_ssh_session, 0, &port);
     if (chan)
     {
-        x2goDebug << "New reverse connection on port " << port;
+        x2goDebug << "New reverse connection on port " << port << endl;
 
         reverseTunnelRequestMutex.lock();
         for (int i = 0; i < reverseTunnelRequest.count(); ++i)
@@ -347,7 +347,7 @@ void SshMasterConnection::checkReverseTunnelConnections()
             ReverseTunnelRequest req = reverseTunnelRequest[i];
             if (static_cast<int>(req.forwardPort) == port)
             {
-                x2goDebug << "Creating new channel for reverse tunnel " << port;
+                x2goDebug << "Creating new channel for reverse tunnel " << port << endl;
                 int sock = socket(AF_INET, SOCK_STREAM, 0);
 #ifndef Q_OS_WIN
                 const int y = 1;
@@ -383,7 +383,7 @@ void SshMasterConnection::checkReverseTunnelConnections()
                 channelConnectionsMutex.lock();
                 channelConnections << con;
                 channelConnectionsMutex.unlock();
-                x2goDebug << "New channel created";
+                x2goDebug << "New channel created" << endl;
                 break;
             }
         }
@@ -414,7 +414,7 @@ int SshMasterConnection::startTunnel(const QString &forwardHost, uint forwardPor
         req.localHost = localHost;
         req.forwardPort = forwardPort;
         req.listen = false;
-        x2goDebug << "Requesting reverse tunnel from port " << forwardPort << " to " << localPort;
+        x2goDebug << "Requesting reverse tunnel from port " << forwardPort << " to " << localPort << endl;
         reverseTunnelRequestMutex.lock();
         reverseTunnelRequest << req;
         reverseTunnelRequestMutex.unlock();
@@ -425,7 +425,7 @@ int SshMasterConnection::startTunnel(const QString &forwardHost, uint forwardPor
 
 void SshMasterConnection::slotSshProxyInteractionFinish(SshMasterConnection *connection)
 {
-    x2goDebug << "SSH proxy interaction finished";
+    x2goDebug << "SSH proxy interaction finished" << endl;
     slotSshProxyUserAuthError("NO_ERROR");
 }
 
@@ -461,7 +461,7 @@ void SshMasterConnection::slotSshProxyUserAuthError(QString err)
 
 void SshMasterConnection::slotSshProxyTunnelOk(int)
 {
-    x2goDebug << "SSH proxy tunnel established.";
+    x2goDebug << "SSH proxy tunnel established." << endl;
     sshProxyReady = true;
 }
 
@@ -479,10 +479,10 @@ void SshMasterConnection::slotSshProxyServerAuthAborted()
 
 void SshMasterConnection::run()
 {
-    x2goDebug << "SshMasterConnection, instance " << this << " entering thread.";
+    x2goDebug << "SshMasterConnection, instance " << this << " entering thread." << endl;
     if (useproxy && proxytype == PROXYSSH)
     {
-        x2goDebug << "proxyserver: " << proxyserver << "; proxyport: " << proxyport << "; proxylogin: " << proxylogin;
+        x2goDebug << "proxyserver: " << proxyserver << "; proxyport: " << proxyport << "; proxylogin: " << proxylogin << endl;
         sshProxy = new SshMasterConnection(0, proxyserver, proxyport, acceptUnknownServers,
                                            proxylogin, proxypassword, proxykey, proxyautologin, proxyKrbLogin, false);
 
@@ -608,7 +608,7 @@ void SshMasterConnection::run()
         }
         QString err = ssh_get_error(my_ssh_session);
         QString message = tr("Cannot connect to ") + host + ":" + QString::number(port);
-        x2goDebug << message << " - " << err;
+        x2goDebug << message << " - " << err << endl;
         emit connectionError(message, err);
         ssh_free(my_ssh_session);
         quit();
@@ -673,7 +673,7 @@ void SshMasterConnection::run()
             x2goDebug << "Session is already disconnected, exiting." << endl;
             return;
         }
-        x2goDebug << "User authentication OK.";
+        x2goDebug << "User authentication OK." << endl;
         // checkLogin() is currently specific to libssh.
         if (kerberos)
         {
@@ -681,19 +681,19 @@ void SshMasterConnection::run()
         }
         else if (this->loginCheck == false)
         {
-            x2goDebug << "Skipping Login Check as requested by configuration";
+            x2goDebug << "Skipping Login Check as requested by configuration" << endl;
             emit connectionOk(host);
         }
         else
         {
             if (checkLogin())
             {
-                x2goDebug << "Login Check - OK";
+                x2goDebug << "Login Check - OK" << endl;
                 emit connectionOk(host);
             }
             else
             {
-                x2goDebug << "Login Check - Failed";
+                x2goDebug << "Login Check - Failed" << endl;
                 //          if(!interactionInterrupt)
                 {
                     emit finishInteraction(this);
@@ -722,7 +722,7 @@ void SshMasterConnection::run()
             err = sshProcErrString;
         }
         QString message = tr("Authentication failed.");
-        x2goDebug << message << " - " << err;
+        x2goDebug << message << " - " << err << endl;
         emit userAuthError(authErrors.join("\n"));
         ssh_disconnect(my_ssh_session);
         ssh_free(my_ssh_session);
@@ -747,14 +747,14 @@ SshMasterConnection::~SshMasterConnection()
     disconnectFlagMutex.lock();
     disconnectSessionFlag = true;
     disconnectFlagMutex.unlock();
-    x2goDebug << "SshMasterConnection, instance " << this << " waiting for thread to finish.";
+    x2goDebug << "SshMasterConnection, instance " << this << " waiting for thread to finish." << endl;
     wait(15000);
-    x2goDebug << "SshMasterConnection, instance " << this << " thread finished.";
+    x2goDebug << "SshMasterConnection, instance " << this << " thread finished." << endl;
     for (int i = processes.count() - 1; i >= 0; --i)
     {
         delete processes[i];
     }
-    x2goDebug << "SshMasterConnection, instance " << this << " finished destructor.";
+    x2goDebug << "SshMasterConnection, instance " << this << " finished destructor." << endl;
 }
 
 bool SshMasterConnection::sshConnect()
@@ -781,7 +781,7 @@ bool SshMasterConnection::sshConnect()
 #if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 6, 0)
     unsigned int cur_port = 0;
     ssh_options_get_port(my_ssh_session, &cur_port);
-    x2goDebug << "Session port before config file parse: " << cur_port;
+    x2goDebug << "Session port before config file parse: " << cur_port << endl;
 #endif
 
     /* Parse ~/.ssh/config. */
@@ -792,7 +792,7 @@ bool SshMasterConnection::sshConnect()
 
 #if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 6, 0)
     ssh_options_get_port(my_ssh_session, &cur_port);
-    x2goDebug << "Session port after config file parse: " << cur_port;
+    x2goDebug << "Session port after config file parse: " << cur_port << endl;
 #endif
 
     rc = ssh_connect(my_ssh_session);
@@ -803,7 +803,7 @@ bool SshMasterConnection::sshConnect()
     //set values for remote host for proper server authentication
     if (useproxy && proxytype == PROXYSSH)
     {
-        x2goDebug << "Connected via proxy, resetting connection values on session to " << tmpBA.data() << ":" << port;
+        x2goDebug << "Connected via proxy, resetting connection values on session to " << tmpBA.data() << ":" << port << endl;
         ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, tmpBA.data());
 
         /*
@@ -830,7 +830,7 @@ bool SshMasterConnection::sshConnect()
             if (!tmp_session)
             {
                 QString error_msg = tr("Cannot create SSH session.");
-                x2goDebug << error_msg;
+                x2goDebug << error_msg << endl;
                 return (false);
             }
             else
@@ -840,12 +840,12 @@ bool SshMasterConnection::sshConnect()
                 /* Parse ~/.ssh/config. */
                 if (ssh_options_parse_config(tmp_session, NULL) < 0)
                 {
-                    x2goDebug << "Warning: unable to parse the SSH config file.";
+                    x2goDebug << "Warning: unable to parse the SSH config file." << endl;
                 }
 
                 unsigned int inferred_port = 0;
                 ssh_options_get_port(tmp_session, &inferred_port);
-                x2goDebug << "Fetched inferred session port: " << inferred_port;
+                x2goDebug << "Fetched inferred session port: " << inferred_port << endl;
 
                 work_port = inferred_port & 0xFFFF;
 
@@ -859,7 +859,7 @@ bool SshMasterConnection::sshConnect()
 
 #if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 6, 0)
     ssh_options_get_port(my_ssh_session, &cur_port);
-    x2goDebug << "Session port before config file parse (part 2): " << cur_port;
+    x2goDebug << "Session port before config file parse (part 2): " << cur_port << endl;
 #endif
 
     /* Parse ~/.ssh/config. */
@@ -870,7 +870,7 @@ bool SshMasterConnection::sshConnect()
 
 #if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 6, 0)
     ssh_options_get_port(my_ssh_session, &cur_port);
-    x2goDebug << "Session port after config file parse (part 2): " << cur_port;
+    x2goDebug << "Session port after config file parse (part 2): " << cur_port << endl;
 #endif
 
     return true;
@@ -891,7 +891,7 @@ void SshMasterConnection::writeKnownHosts(bool write)
 
 int SshMasterConnection::serverAuth(QString &errorMsg)
 {
-    x2goDebug << "cserverAuth";
+    x2goDebug << "cserverAuth" << endl;
 
     int state = SSH_SERVER_ERROR;
     unsigned char *hash = NULL;
@@ -974,7 +974,7 @@ void SshMasterConnection::setVerficationCode(QString code)
 
 bool SshMasterConnection::userAuthKeyboardInteractive(QString prompt)
 {
-    x2goDebug << "Open Interaction dialog to complete authentication";
+    x2goDebug << "Open Interaction dialog to complete authentication" << endl;
     emit startInteraction(this, prompt);
     interactionInterrupt = false;
     interactionInputText = QString::null;
@@ -1013,14 +1013,14 @@ bool SshMasterConnection::userAuthKeyboardInteractive(QString prompt)
                 interactionInputMutex.unlock();
                 if (textToSend.length() > 0)
                 {
-                    x2goDebug << "SEND Input to SERVER";
+                    x2goDebug << "SEND Input to SERVER" << endl;
                     textToSend.replace("\n", "");
                     ssh_userauth_kbdint_setanswer(my_ssh_session, 0, textToSend.toLocal8Bit());
                     break;
                 }
                 if (interrupt)
                 {
-                    x2goDebug << "Keyboard authentication failed";
+                    x2goDebug << "Keyboard authentication failed" << endl;
                     //         QString err=ssh_get_error ( my_ssh_session );
                     authErrors << "NO_ERROR";
                     emit finishInteraction(this);
@@ -1035,13 +1035,13 @@ bool SshMasterConnection::userAuthKeyboardInteractive(QString prompt)
     }
     if (rez == SSH_AUTH_SUCCESS)
     {
-        x2goDebug << "Keyboard authentication successful";
+        x2goDebug << "Keyboard authentication successful" << endl;
         emit finishInteraction(this);
         return true;
     }
     if (rez == SSH_AUTH_DENIED)
     {
-        x2goDebug << "Keyboard authentication failed";
+        x2goDebug << "Keyboard authentication failed" << endl;
         QString err = ssh_get_error(my_ssh_session);
         if (instruction.length() > 0)
         {
@@ -1324,7 +1324,7 @@ void SshMasterConnection::setKeyPhrase(QString phrase)
 
 bool SshMasterConnection::userAuthWithKey()
 {
-    x2goDebug << "Trying to authenticate user with private key.";
+    x2goDebug << "Trying to authenticate user with private key." << endl;
     QString keyName = key;
     bool autoRemove = false;
     if (key.indexOf("PRIVATE KEY") != -1)
@@ -1340,7 +1340,7 @@ bool SshMasterConnection::userAuthWithKey()
         out << key;
         fl.close();
         autoRemove = true;
-        x2goDebug << "Temporarily saved key in " << keyName;
+        x2goDebug << "Temporarily saved key in " << keyName << endl;
     }
 
     QByteArray tmp_ba = keyName.toLocal8Bit();
@@ -1363,7 +1363,7 @@ bool SshMasterConnection::userAuthWithKey()
 
     if (SSH_EOF == rc)
     {
-        x2goDebug << "Failed to get private key from " << keyName << "; file does not exist.";
+        x2goDebug << "Failed to get private key from " << keyName << "; file does not exist." << endl;
 
         ssh_key_free(priv_key);
 
@@ -1371,7 +1371,7 @@ bool SshMasterConnection::userAuthWithKey()
     }
     else if (SSH_OK != rc)
     {
-        x2goDebug << "Failed to get private key from " << keyName << "; trying to query passphrase.";
+        x2goDebug << "Failed to get private key from " << keyName << "; trying to query passphrase." << endl;
 
         ssh_key_free(priv_key);
         priv_key = NULL;
@@ -1441,7 +1441,7 @@ bool SshMasterConnection::userAuthWithKey()
     if (!priv_key)
 #endif
     {
-        x2goDebug << "Failed to get private key from " << keyName;
+        x2goDebug << "Failed to get private key from " << keyName << endl;
         if (autoRemove)
             QFile::remove(keyName);
         return false;
@@ -1461,7 +1461,7 @@ bool SshMasterConnection::userAuthWithKey()
     if (!pub_key)
 #endif
     {
-        x2goDebug << "Failed to get public key from private key.";
+        x2goDebug << "Failed to get public key from private key." << endl;
 #if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 6, 0)
         ssh_key_free(priv_key);
         priv_key = NULL;
@@ -1488,7 +1488,7 @@ bool SshMasterConnection::userAuthWithKey()
     /* FIXME: handle SSH_AUTH_PARTIAL correctly! */
     if (SSH_AUTH_SUCCESS != rc)
     {
-        x2goDebug << "Unable to authenticate with public key.";
+        x2goDebug << "Unable to authenticate with public key." << endl;
 
         ssh_key_free(priv_key);
         priv_key = NULL;
@@ -1612,7 +1612,7 @@ bool SshMasterConnection::userAuthKrb()
     }
     QString outp = ssh.readAllStandardOutput();
     QString err = ssh.readAllStandardError();
-    x2goDebug << "SSH exited.";
+    x2goDebug << "SSH exited." << endl;
     x2goDebug << "stdout: " << outp << endl;
     x2goDebug << "stderr: " << err << endl;
     x2goDebug << "Exit code: " << ssh.exitCode() << "; status: " << ssh.exitStatus() << endl;
@@ -1705,7 +1705,6 @@ bool SshMasterConnection::checkLogin()
         char buffer[1024 * 512]; //512K buffer
         bool hasInterraction = true;
         bool interactionStarted = false;
-        //         x2goDebug<<"CHECK LOGIN channel created."<<endl;
         while (ssh_channel_is_open(channel) &&
                !ssh_channel_is_eof(channel))
         {
@@ -1718,10 +1717,10 @@ bool SshMasterConnection::checkLogin()
             if (nbytes > 0)
             {
                 QString inf = QByteArray(buffer, nbytes);
-                x2goDebug << "LOGIN CHECK:" << inf;
+                x2goDebug << "LOGIN CHECK:" << inf << endl;
                 if (inf.indexOf("LOGIN OK") != -1)
                 {
-                    x2goDebug << "don't have interaction";
+                    x2goDebug << "don't have interaction" << endl;
                     hasInterraction = false;
                     break;
                 }
@@ -1744,7 +1743,6 @@ bool SshMasterConnection::checkLogin()
             interactionInputMutex.unlock();
             if (textToSend.length() > 0)
             {
-                // 	        x2goDebug<<"SEND Input to SERVER";
                 ssh_channel_write(channel, textToSend.toLocal8Bit().constData(), textToSend.length());
             }
             if (interrupt)
@@ -1754,17 +1752,17 @@ bool SshMasterConnection::checkLogin()
             this->usleep(30);
         }
 
-        x2goDebug << "LOOP FINISHED";
+        x2goDebug << "LOOP FINISHED" << endl;
         bool retVal = false;
         if (!hasInterraction)
         {
-            x2goDebug << "No interaction needed, continue session";
+            x2goDebug << "No interaction needed, continue session" << endl;
             retVal = true;
         }
         else
         {
             sshProcErrString = tr("Reconnect session");
-            x2goDebug << "Reconnect session";
+            x2goDebug << "Reconnect session" << endl;
         }
         ssh_channel_close(channel);
         ssh_channel_send_eof(channel);
@@ -1816,11 +1814,11 @@ void SshMasterConnection::addChannelConnection(SshProcess *creator, QString uuid
     con.command = cmd;
     con.uuid = uuid;
 
-    x2goDebug << "Locking SSH channel connection MUTEX.";
+    x2goDebug << "Locking SSH channel connection MUTEX." << endl;
     channelConnectionsMutex.lock();
-    x2goDebug << "Passing new channel connection object to channelConnections.";
+    x2goDebug << "Passing new channel connection object to channelConnections." << endl;
     channelConnections << con;
-    x2goDebug << "Unlocking SSH channel connection MUTEX.";
+    x2goDebug << "Unlocking SSH channel connection MUTEX." << endl;
     channelConnectionsMutex.unlock();
 }
 
@@ -1962,7 +1960,7 @@ void SshMasterConnection::channelLoop()
         channelConnectionsMutex.lock();
         if (channelConnections.size() <= 0)
         {
-            //             x2goDebug<<"no channel connections, waiting\n";
+            // x2goDebug<<"no channel connections, waiting\n";
             channelConnectionsMutex.unlock();
             usleep(500);
             continue;
@@ -2001,7 +1999,7 @@ void SshMasterConnection::channelLoop()
                     x2goDebug << "Forwarding parameters: from remote (" << channelConnections.at(i).forwardHost << ":"
                               << channelConnections.at(i).forwardPort << ") to local ("
                               << channelConnections.at(i).localHost << ":" << channelConnections.at(i).localPort
-                              << ")";
+                              << ")" << endl;
 
                     /*
                      * Cannot support config file parsing here with pre-0.6.0 libssh versions.
@@ -2013,7 +2011,7 @@ void SshMasterConnection::channelLoop()
                     if (!tmp_session)
                     {
                         QString error_msg = tr("Cannot create SSH session.");
-                        x2goDebug << error_msg;
+                        x2goDebug << error_msg << endl;
                         emit ioErr(channelConnections[i].creator, error_msg, "");
                     }
                     else
@@ -2031,16 +2029,16 @@ void SshMasterConnection::channelLoop()
                         /* The host and port might be a shorthand and zero, so fetch the actual data. */
                         if (ssh_options_parse_config(tmp_session, NULL) < 0)
                         {
-                            x2goDebug << "Warning: unable to parse the SSH config file.";
+                            x2goDebug << "Warning: unable to parse the SSH config file." << endl;
                         }
 
                         unsigned int inferred_port = 0;
                         ssh_options_get_port(tmp_session, &inferred_port);
-                        x2goDebug << "Temporary session port after config file parse: " << inferred_port;
+                        x2goDebug << "Temporary session port after config file parse: " << inferred_port << endl;
 
                         char *inferred_host = NULL;
                         ssh_options_get(tmp_session, SSH_OPTIONS_HOST, &inferred_host);
-                        x2goDebug << "Temporary session host after config file parse: " << inferred_host;
+                        x2goDebug << "Temporary session host after config file parse: " << inferred_host << endl;
 
                         channelConnections[i].forwardHost = QString(inferred_host);
                         channelConnections[i].forwardPort = static_cast<int>(inferred_port);
@@ -2105,12 +2103,10 @@ void SshMasterConnection::channelLoop()
 
         if (retval == -1)
         {
-            x2goDebug << "select() error.";
+            x2goDebug << "select() error." << endl;
             continue;
         }
 
-        //         x2goDebug<<"select exited"<<endl;
-
         channelConnectionsMutex.lock();
         for (int i = channelConnections.size() - 1; i >= 0; --i)
         {
@@ -2128,7 +2124,7 @@ void SshMasterConnection::channelLoop()
             int rez = ssh_channel_poll(channel, 0);
             if (rez == SSH_EOF)
             {
-                x2goDebug << "EOF on channel " << channel << "; SshProcess object: " << channelConnections[i].creator->pid;
+                x2goDebug << "EOF on channel " << channel << "; SshProcess object: " << channelConnections[i].creator->pid << endl;
 
                 //////Finished////////
                 finalize(i);
@@ -2172,7 +2168,7 @@ void SshMasterConnection::channelLoop()
 
                 if (ssh_channel_is_eof(channel))
                 {
-                    x2goDebug << "EOF on channel " << channel << "; SshProcess object: " << channelConnections[i].creator->pid;
+                    x2goDebug << "EOF on channel " << channel << "; SshProcess object: " << channelConnections[i].creator->pid << endl;
 
                     //////Finished////////
                     finalize(i);
@@ -2229,9 +2225,9 @@ void SshMasterConnection::finalize(int item)
     if (channel)
     {
         ssh_channel_send_eof(channel);
-        x2goDebug << "EOF sent.";
+        x2goDebug << "EOF sent." << endl;
         ssh_channel_close(channel);
-        x2goDebug << "Channel closed.";
+        x2goDebug << "Channel closed." << endl;
         ssh_channel_free(channel);
     }
     if (tcpSocket > 0)
-- 
2.17.1

From 9bfc1728baa444a088d567fa484fdcffce629db1 Mon Sep 17 00:00:00 2001
From: Melroy van den Berg <[email-masked]>
Date: Tue, 19 May 2020 22:40:44 +0200
Subject: [PATCH 03/11] send eof before close

---
 src/sshmasterconnection.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/sshmasterconnection.cpp b/src/sshmasterconnection.cpp
index f598e9c..d8f894d 100644
--- a/src/sshmasterconnection.cpp
+++ b/src/sshmasterconnection.cpp
@@ -1764,8 +1764,8 @@ bool SshMasterConnection::checkLogin()
             sshProcErrString = tr("Reconnect session");
             x2goDebug << "Reconnect session" << endl;
         }
-        ssh_channel_close(channel);
         ssh_channel_send_eof(channel);
+        ssh_channel_close(channel);
         ssh_channel_free(channel);
         return retVal;
     }
-- 
2.17.1

From 863c8a2c79e9b912a2fc8759bbccd104f398f57e Mon Sep 17 00:00:00 2001
From: Melroy van den Berg <[email-masked]>
Date: Tue, 19 May 2020 22:42:18 +0200
Subject: [PATCH 04/11] return false in all bad cases

---
 src/sshmasterconnection.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/sshmasterconnection.cpp b/src/sshmasterconnection.cpp
index d8f894d..aa75ec1 100644
--- a/src/sshmasterconnection.cpp
+++ b/src/sshmasterconnection.cpp
@@ -1699,6 +1699,7 @@ bool SshMasterConnection::checkLogin()
         QString errorMsg = tr("%1 failed.").arg("ssh_channel_request_exec");
         x2goDebug << errorMsg.left(errorMsg.size() - 1) << ": " << err << endl;
         ssh_channel_free(channel);
+        return false;
     }
     else
     {
-- 
2.17.1

From 78f23042d6203c88edf8f3befde15f4dc6429fc7 Mon Sep 17 00:00:00 2001
From: Melroy van den Berg <[email-masked]>
Date: Tue, 19 May 2020 22:59:15 +0200
Subject: [PATCH 06/11] Remove deprecated call and use new libssh API call.
 Plus some minor formatting.

---
 src/sshmasterconnection.cpp | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/sshmasterconnection.cpp b/src/sshmasterconnection.cpp
index c068c89..022f710 100644
--- a/src/sshmasterconnection.cpp
+++ b/src/sshmasterconnection.cpp
@@ -571,7 +571,6 @@ void SshMasterConnection::run()
 #endif
 
     ssh_options_set(my_ssh_session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
-
     ssh_options_set(my_ssh_session, SSH_OPTIONS_TIMEOUT, &timeout);
 
     if (useproxy && proxytype == PROXYHTTP)
@@ -912,7 +911,11 @@ int SshMasterConnection::serverAuth(QString &errorMsg)
 #if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 8, 0)
     rc = ssh_get_server_publickey(my_ssh_session, &srv_pubkey);
 #else  /* LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 8, 0) */
-    rc = ssh_get_publickey(my_ssh_session, &srv_pubkey);
+    rc = ssh_get_server_publickey(my_ssh_session, &srv_pubkey);
+    if (SSH_OK != rc)
+    {
+        return (SSH_SERVER_ERROR);
+    }
 #endif /* LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 8, 0) */
 
     if (SSH_OK != rc)
-- 
2.17.1

From bfbb2f3d22b687df4d7e073b42d3ce1409f49574 Mon Sep 17 00:00:00 2001
From: Melroy van den Berg <[email-masked]>
Date: Tue, 19 May 2020 22:57:19 +0200
Subject: [PATCH 05/11] Refactor and fix channel/session closes

---
 src/sshmasterconnection.cpp | 272 ++++++++++++++++++++----------------
 src/sshmasterconnection.h   |  13 +-
 2 files changed, 156 insertions(+), 129 deletions(-)

diff --git a/src/sshmasterconnection.cpp b/src/sshmasterconnection.cpp
index aa75ec1..c068c89 100644
--- a/src/sshmasterconnection.cpp
+++ b/src/sshmasterconnection.cpp
@@ -544,6 +544,7 @@ void SshMasterConnection::run()
 #endif
     }
 
+    // Set time-out to 1 min.
     long timeout = 60;
 
     my_ssh_session = ssh_new();
@@ -694,7 +695,7 @@ void SshMasterConnection::run()
             else
             {
                 x2goDebug << "Login Check - Failed" << endl;
-                //          if(!interactionInterrupt)
+                // if(!interactionInterrupt)
                 {
                     emit finishInteraction(this);
                 }
@@ -787,7 +788,7 @@ bool SshMasterConnection::sshConnect()
     /* Parse ~/.ssh/config. */
     if (ssh_options_parse_config(my_ssh_session, NULL) < 0)
     {
-        x2goDebug << "Warning: unable to parse the SSH config file.";
+        x2goDebug << "Warning: unable to parse the SSH config file." << endl;
     }
 
 #if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 6, 0)
@@ -849,6 +850,7 @@ bool SshMasterConnection::sshConnect()
 
                 work_port = inferred_port & 0xFFFF;
 
+                ssh_disconnect(tmp_session);
                 ssh_free(tmp_session);
             }
         }
@@ -1974,129 +1976,16 @@ void SshMasterConnection::channelLoop()
 
         for (int i = 0; i < channelConnections.size(); ++i)
         {
-            int tcpSocket = channelConnections.at(i).sock;
-            if (tcpSocket > 0)
-                FD_SET(tcpSocket, &rfds);
-            if (channelConnections.at(i).channel == 0l)
+            // Try to make a channel connection
+            // TODO: Mabye a retry?
+            bool res = createChannelConnection(i, maxsock, rfds, read_chan);
+            if (!res)
             {
-                x2goDebug << "Creating new channel." << endl;
-                ssh_channel channel = ssh_channel_new(my_ssh_session);
-
-                if (!channel)
-                {
-                    QString err = ssh_get_error(my_ssh_session);
-                    /*: Argument in this context will be a function name. */
-                    QString error_msg = tr("%1 failed.").arg("ssh_channel_new");
-                    emit ioErr(channelConnections[i].creator, error_msg, err);
-
-                    x2goDebug << error_msg.left(error_msg.size() - 1) << ": " << err << endl;
-
-                    continue;
-                }
-                x2goDebug << "New channel:" << channel << endl;
-                channelConnections[i].channel = channel;
-                if (tcpSocket > 0)
-                {
-                    x2goDebug << "Forwarding parameters: from remote (" << channelConnections.at(i).forwardHost << ":"
-                              << channelConnections.at(i).forwardPort << ") to local ("
-                              << channelConnections.at(i).localHost << ":" << channelConnections.at(i).localPort
-                              << ")" << endl;
-
-                    /*
-                     * Cannot support config file parsing here with pre-0.6.0 libssh versions.
-                     * There's just no way to get the inferred host and port values.
-                     */
-#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 6, 0)
-                    ssh_session tmp_session = ssh_new();
-
-                    if (!tmp_session)
-                    {
-                        QString error_msg = tr("Cannot create SSH session.");
-                        x2goDebug << error_msg << endl;
-                        emit ioErr(channelConnections[i].creator, error_msg, "");
-                    }
-                    else
-                    {
-                        QByteArray tmp_BA = channelConnections.at(i).forwardHost.toLocal8Bit();
-                        const int tmp_port = channelConnections.at(i).forwardPort;
-
-                        ssh_options_set(tmp_session, SSH_OPTIONS_HOST, tmp_BA.data());
-
-                        if (tmp_port)
-                        {
-                            ssh_options_set(tmp_session, SSH_OPTIONS_PORT, &tmp_port);
-                        }
-
-                        /* The host and port might be a shorthand and zero, so fetch the actual data. */
-                        if (ssh_options_parse_config(tmp_session, NULL) < 0)
-                        {
-                            x2goDebug << "Warning: unable to parse the SSH config file." << endl;
-                        }
-
-                        unsigned int inferred_port = 0;
-                        ssh_options_get_port(tmp_session, &inferred_port);
-                        x2goDebug << "Temporary session port after config file parse: " << inferred_port << endl;
-
-                        char *inferred_host = NULL;
-                        ssh_options_get(tmp_session, SSH_OPTIONS_HOST, &inferred_host);
-                        x2goDebug << "Temporary session host after config file parse: " << inferred_host << endl;
-
-                        channelConnections[i].forwardHost = QString(inferred_host);
-                        channelConnections[i].forwardPort = static_cast<int>(inferred_port);
-
-                        ssh_string_free_char(inferred_host);
-                        ssh_free(tmp_session);
-                    }
-#endif
-
-                    {
-                        QByteArray tmp_BA_forward = channelConnections.at(i).forwardHost.toLocal8Bit();
-                        QByteArray tmp_BA_local = channelConnections.at(i).localHost.toLocal8Bit();
-
-                        if (ssh_channel_open_forward(channel,
-                                                     tmp_BA_forward.data(),
-                                                     channelConnections.at(i).forwardPort,
-                                                     tmp_BA_local.data(),
-                                                     channelConnections.at(i).localPort) != SSH_OK)
-                        {
-                            QString err = ssh_get_error(my_ssh_session);
-                            QString errorMsg = tr("%1 failed.").arg("ssh_channel_open_forward");
-                            emit ioErr(channelConnections[i].creator, errorMsg, err);
-                            x2goDebug << errorMsg.left(errorMsg.size() - 1) << ": " << err << endl;
-                        }
-                        else
-                        {
-                            x2goDebug << "New channel forwarded." << endl;
-                        }
-                    }
-                }
-                else
-                {
-                    x2goDebug << "Executing remote: " << channelConnections.at(i).command << endl;
-                    if (ssh_channel_open_session(channel) != SSH_OK)
-                    {
-                        QString err = ssh_get_error(my_ssh_session);
-                        QString errorMsg = tr("%1 failed.").arg("ssh_channel_open_session");
-                        emit ioErr(channelConnections[i].creator, errorMsg, err);
-                        x2goDebug << errorMsg.left(errorMsg.size() - 1) << ": " << err << endl;
-                    }
-                    else if (ssh_channel_request_exec(channel, channelConnections[i].command.toLatin1()) != SSH_OK)
-                    {
-                        QString err = ssh_get_error(my_ssh_session);
-                        QString errorMsg = tr("%1 failed.").arg("ssh_channel_request_exec");
-                        emit ioErr(channelConnections[i].creator, errorMsg, err);
-                        x2goDebug << errorMsg.left(errorMsg.size() - 1) << ": " << err << endl;
-                    }
-                    else
-                    {
-                        x2goDebug << "New exec channel created." << endl;
-                    }
-                }
+                x2goDebug << "Connection to channel went wrong.";
+                continue;
             }
-            read_chan[i] = channelConnections.at(i).channel;
-            if (tcpSocket > maxsock)
-                maxsock = tcpSocket;
         }
+
         channelConnectionsMutex.unlock();
         retval = ssh_select(read_chan, out_chan, maxsock + 1, &rfds, &tv);
         delete[] read_chan;
@@ -2219,6 +2108,145 @@ void SshMasterConnection::channelLoop()
     }
 }
 
+/**
+ * Create SSH channel connection (used within a loop of channels)
+ */
+bool SshMasterConnection::createChannelConnection(int i, int &maxsock, fd_set &rfds, ssh_channel read_chan[])
+{
+    int tcpSocket = channelConnections.at(i).sock;
+    if (tcpSocket > 0)
+        FD_SET(tcpSocket, &rfds);
+    if (channelConnections.at(i).channel == 0l)
+    {
+        x2goDebug << "Creating new channel." << endl;
+
+        ssh_channel channel = ssh_channel_new(my_ssh_session);
+        if (!channel)
+        {
+            QString err = ssh_get_error(my_ssh_session);
+            /*: Argument in this context will be a function name. */
+            QString error_msg = tr("%1 failed.").arg("ssh_channel_new");
+            emit ioErr(channelConnections[i].creator, error_msg, err);
+
+            x2goDebug << error_msg.left(error_msg.size() - 1) << ": " << err << endl;
+            return false;
+        }
+        x2goDebug << "New channel:" << channel << endl;
+        channelConnections[i].channel = channel;
+        if (tcpSocket > 0)
+        {
+            x2goDebug << "Forwarding parameters: from remote (" << channelConnections.at(i).forwardHost << ":"
+                      << channelConnections.at(i).forwardPort << ") to local ("
+                      << channelConnections.at(i).localHost << ":" << channelConnections.at(i).localPort
+                      << ")";
+
+            /*
+                * Cannot support config file parsing here with pre-0.6.0 libssh versions.
+                * There's just no way to get the inferred host and port values.
+                */
+#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 6, 0)
+            ssh_session tmp_session = ssh_new();
+
+            if (!tmp_session)
+            {
+                QString error_msg = tr("Cannot create SSH session.");
+                x2goDebug << error_msg << endl;
+                emit ioErr(channelConnections[i].creator, error_msg, "");
+            }
+            else
+            {
+                QByteArray tmp_BA = channelConnections.at(i).forwardHost.toLocal8Bit();
+                const int tmp_port = channelConnections.at(i).forwardPort;
+
+                ssh_options_set(tmp_session, SSH_OPTIONS_HOST, tmp_BA.data());
+
+                if (tmp_port)
+                {
+                    ssh_options_set(tmp_session, SSH_OPTIONS_PORT, &tmp_port);
+                }
+
+                /* The host and port might be a shorthand and zero, so fetch the actual data. */
+                if (ssh_options_parse_config(tmp_session, NULL) < 0)
+                {
+                    x2goDebug << "Warning: unable to parse the SSH config file." << endl;
+                }
+
+                unsigned int inferred_port = 0;
+                ssh_options_get_port(tmp_session, &inferred_port);
+                x2goDebug << "Temporary session port after config file parse: " << inferred_port << endl;
+
+                char *inferred_host = NULL;
+                ssh_options_get(tmp_session, SSH_OPTIONS_HOST, &inferred_host);
+                x2goDebug << "Temporary session host after config file parse: " << inferred_host << endl;
+
+                channelConnections[i].forwardHost = QString(inferred_host);
+                channelConnections[i].forwardPort = static_cast<int>(inferred_port);
+
+                ssh_string_free_char(inferred_host);
+                ssh_free(tmp_session);
+            }
+#endif
+
+            {
+                QByteArray tmp_BA_forward = channelConnections.at(i).forwardHost.toLocal8Bit();
+                QByteArray tmp_BA_local = channelConnections.at(i).localHost.toLocal8Bit();
+
+                if (ssh_channel_open_forward(channel,
+                                             tmp_BA_forward.data(),
+                                             channelConnections.at(i).forwardPort,
+                                             tmp_BA_local.data(),
+                                             channelConnections.at(i).localPort) != SSH_OK)
+                {
+                    QString err = ssh_get_error(my_ssh_session);
+                    QString errorMsg = tr("%1 failed.").arg("ssh_channel_open_forward");
+                    emit ioErr(channelConnections[i].creator, errorMsg, err);
+                    x2goDebug << errorMsg.left(errorMsg.size() - 1) << ": " << err << endl;
+                }
+                else
+                {
+                    x2goDebug << "New channel forwarded." << endl;
+                }
+            }
+        }
+        else
+        {
+            x2goDebug << "Executing remote: " << channelConnections.at(i).command << endl;
+            if (ssh_channel_open_session(channel) != SSH_OK)
+            {
+                QString err = ssh_get_error(my_ssh_session);
+                QString errorMsg = tr("%1 failed.").arg("ssh_channel_open_session");
+
+                // Free channel
+                ssh_channel_free(channel);
+                emit ioErr(channelConnections[i].creator, errorMsg, err);
+                x2goDebug << errorMsg.left(errorMsg.size() - 1) << ": " << err << endl;
+                return false;
+            }
+            else if (ssh_channel_request_exec(channel, channelConnections[i].command.toLatin1()) != SSH_OK)
+            {
+                QString err = ssh_get_error(my_ssh_session);
+                QString errorMsg = tr("%1 failed.").arg("ssh_channel_request_exec");
+
+                // Free close connection and free channel
+                ssh_channel_close(channel);
+                ssh_channel_free(channel);
+                emit ioErr(channelConnections[i].creator, errorMsg, err);
+                x2goDebug << errorMsg.left(errorMsg.size() - 1) << ": " << err << endl;
+                return false;
+            }
+            else
+            {
+                // Everything is OK
+                x2goDebug << "New exec channel created." << endl;
+            }
+        }
+    }
+    read_chan[i] = channelConnections.at(i).channel;
+    if (tcpSocket > maxsock)
+        maxsock = tcpSocket;
+    return true;
+}
+
 void SshMasterConnection::finalize(int item)
 {
     int tcpSocket = channelConnections.at(item).sock;
diff --git a/src/sshmasterconnection.h b/src/sshmasterconnection.h
index c7883be..effae16 100644
--- a/src/sshmasterconnection.h
+++ b/src/sshmasterconnection.h
@@ -27,13 +27,11 @@
 #include <QTcpSocket>
 #include <QNetworkProxy>
 
-#define PROPERTY(TYPE, NAME)           \
-private:                               \
-    TYPE NAME;                         \
-                                       \
-public:                                \
-    TYPE get_##NAME() { return NAME; } \
-    void set_##NAME(TYPE VAL) { NAME = VAL; }
+
+#define PROPERTY(TYPE,NAME)  private: TYPE NAME; \
+public: TYPE get_##NAME(){return NAME;} \
+void set_##NAME(TYPE VAL){NAME=VAL;}
+
 
 class ONMainWindow;
 class SshProcess;
@@ -141,6 +139,7 @@ private:
     bool userAuthKrb();
     bool userAuthKeyboardInteractive(QString prompt);
     void channelLoop();
+    bool createChannelConnection(int i, int& maxsock, fd_set& rfds, ssh_channel read_chan[]);
     void finalize(int arg1);
     void copy();
     int serverAuth(QString &errorMsg);
-- 
2.17.1

From ff56cc7dad1f99e20dc9ffad8641bd3cb03236fa Mon Sep 17 00:00:00 2001
From: Melroy van den Berg <[email-masked]>
Date: Tue, 19 May 2020 23:00:10 +0200
Subject: [PATCH 07/11] Fix 'when not' password auth. Otherwise you get double
 error messages. return ret iso return (ret)

---
 src/sshmasterconnection.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/sshmasterconnection.cpp b/src/sshmasterconnection.cpp
index 022f710..7192574 100644
--- a/src/sshmasterconnection.cpp
+++ b/src/sshmasterconnection.cpp
@@ -1263,7 +1263,7 @@ bool SshMasterConnection::userAuthWithPass()
         }
     }
 
-    if ((!ret) && (method & ~SSH_AUTH_METHOD_PASSWORD))
+    if ((!ret) && !(method & SSH_AUTH_METHOD_PASSWORD))
     {
         /* In case password auth is disabled, make sure the error message is not empty. */
         QString err = ssh_get_error(my_ssh_session);
@@ -1271,7 +1271,7 @@ bool SshMasterConnection::userAuthWithPass()
         x2goDebug << "Password authentication not available: " << err << endl;
     }
 
-    return (ret);
+    return ret;
 }
 
 bool SshMasterConnection::userAuthAuto()
-- 
2.17.1

From 5e757709ac03c397d6a0cb462d2eacaeb0f0d735 Mon Sep 17 00:00:00 2001
From: Melroy van den Berg <[email-masked]>
Date: Tue, 19 May 2020 23:13:27 +0200
Subject: [PATCH 10/11] Mark as unused explicitly

---
 src/sshmasterconnection.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/sshmasterconnection.cpp b/src/sshmasterconnection.cpp
index 63bf507..401d778 100644
--- a/src/sshmasterconnection.cpp
+++ b/src/sshmasterconnection.cpp
@@ -423,18 +423,18 @@ int SshMasterConnection::startTunnel(const QString &forwardHost, uint forwardPor
     return proc->pid;
 }
 
-void SshMasterConnection::slotSshProxyInteractionFinish(SshMasterConnection *connection)
+void SshMasterConnection::slotSshProxyInteractionFinish(SshMasterConnection *connection /* unused */)
 {
     x2goDebug << "SSH proxy interaction finished" << endl;
     slotSshProxyUserAuthError("NO_ERROR");
 }
 
-void SshMasterConnection::slotSshProxyInteractionStart(SshMasterConnection *connection, QString prompt)
+void SshMasterConnection::slotSshProxyInteractionStart(SshMasterConnection *connection /* unused */, QString prompt)
 {
     emit startInteraction(this, prompt);
 }
 
-void SshMasterConnection::slotSshProxyInteractionUpdate(SshMasterConnection *connection, QString output)
+void SshMasterConnection::slotSshProxyInteractionUpdate(SshMasterConnection *connection /* unused */, QString output)
 {
     emit updateInteraction(this, output);
 }
-- 
2.17.1

From e3c7479aaaacbdfe0f82d794583396dde2f7abd6 Mon Sep 17 00:00:00 2001
From: Melroy van den Berg <[email-masked]>
Date: Tue, 19 May 2020 23:14:20 +0200
Subject: [PATCH 11/11] improve gitignore, why not

---
 .gitignore | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/.gitignore b/.gitignore
index eafee6a..36c8558 100644
--- a/.gitignore
+++ b/.gitignore
@@ -29,5 +29,5 @@ x2goclient.dmg
 
 x2goclient.pro.user
 
-# This file.
-.gitignore
+# Editors
+.vscode/
-- 
2.17.1

From fef431576853ec1359dcef879507b8e99d6e71c2 Mon Sep 17 00:00:00 2001
From: Melroy van den Berg <[email-masked]>
Date: Tue, 19 May 2020 23:01:05 +0200
Subject: [PATCH 08/11] Correct retval check. Plus some minor formatting.

---
 src/sshmasterconnection.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/sshmasterconnection.cpp b/src/sshmasterconnection.cpp
index 7192574..feaff4c 100644
--- a/src/sshmasterconnection.cpp
+++ b/src/sshmasterconnection.cpp
@@ -1665,7 +1665,6 @@ bool SshMasterConnection::checkLogin()
     interactionInputText = QString::null;
 
     ssh_channel channel = ssh_channel_new(my_ssh_session);
-
     if (!channel)
     {
         QString err = ssh_get_error(my_ssh_session);
@@ -1994,7 +1993,7 @@ void SshMasterConnection::channelLoop()
         delete[] read_chan;
         delete[] out_chan;
 
-        if (retval == -1)
+        if (SSH_OK != retval)
         {
             x2goDebug << "select() error." << endl;
             continue;
-- 
2.17.1

From b873eb172bf09f54476ed1f2184361e02b35bc50 Mon Sep 17 00:00:00 2001
From: Melroy van den Berg <[email-masked]>
Date: Tue, 19 May 2020 23:09:40 +0200
Subject: [PATCH 09/11] Another missing endl

---
 src/sshmasterconnection.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/sshmasterconnection.cpp b/src/sshmasterconnection.cpp
index feaff4c..63bf507 100644
--- a/src/sshmasterconnection.cpp
+++ b/src/sshmasterconnection.cpp
@@ -2140,7 +2140,7 @@ bool SshMasterConnection::createChannelConnection(int i, int &maxsock, fd_set &r
             x2goDebug << "Forwarding parameters: from remote (" << channelConnections.at(i).forwardHost << ":"
                       << channelConnections.at(i).forwardPort << ") to local ("
                       << channelConnections.at(i).localHost << ":" << channelConnections.at(i).localPort
-                      << ")";
+                      << ")" << endl;
 
             /*
                 * Cannot support config file parsing here with pre-0.6.0 libssh versions.
-- 
2.17.1

From c71fded919855314cbd9d1554777fb9b4ddac548 Mon Sep 17 00:00:00 2001
From: Melroy van den Berg <[email-masked]>
Date: Tue, 19 May 2020 22:28:58 +0200
Subject: [PATCH 01/11] First auto-format the code, for readability and
 humankind

---
 src/sshmasterconnection.cpp | 1940 ++++++++++++++++++-----------------
 src/sshmasterconnection.h   |  119 ++-
 2 files changed, 1035 insertions(+), 1024 deletions(-)

diff --git a/src/sshmasterconnection.cpp b/src/sshmasterconnection.cpp
index 8b59fe7..424cad2 100644
--- a/src/sshmasterconnection.cpp
+++ b/src/sshmasterconnection.cpp
@@ -23,7 +23,6 @@
 #include <stddef.h>
 #include "sshprocess.h"
 
-
 #include <QStringList>
 #include <QFile>
 #include <QDir>
@@ -43,36 +42,33 @@
 #include <QtNetwork/qabstractsocket.h>
 #endif
 
-
 #include "onmainwindow.h"
 
-
 #define PROXYTUNNELPORT 44444
 
 const QString SshMasterConnection::challenge_auth_code_prompts_[] = {
-  "Verification code:",            // GA      (http://github.com/google/google-authenticator)
-  "One-time password (OATH) for",  // OATH    (http://www.nongnu.org/oath-toolkit/pam_oath.html)
-  "passcode:",                     // MOTP    (http://motp.sourceforge.net)
-  "Enter PASSCODE:",               // SecurID
-  "YubiKey for"                    // YubiKey (https://en.wikipedia.org/wiki/YubiKey)
+    "Verification code:",           // GA      (http://github.com/google/google-authenticator)
+    "One-time password (OATH) for", // OATH    (http://www.nongnu.org/oath-toolkit/pam_oath.html)
+    "passcode:",                    // MOTP    (http://motp.sourceforge.net)
+    "Enter PASSCODE:",              // SecurID
+    "YubiKey for"                   // YubiKey (https://en.wikipedia.org/wiki/YubiKey)
 };
 
-
 #ifdef Q_OS_WIN
 #include <QSettings>
 // parse known_hosts file from libssh and export keys in registry to use with plink.exe
 void SshMasterConnection::parseKnownHosts()
 {
-    QFile fl(mainWnd->getHomeDirectory()+"/ssh/known_hosts");
+    QFile fl(mainWnd->getHomeDirectory() + "/ssh/known_hosts");
     if (!fl.open(QFile::ReadOnly))
         return;
     QSettings settings("HKEY_CURRENT_USER\\Software\\SimonTatham\\PuTTY\\SshHostKeys",
                        QSettings::NativeFormat);
     while (!fl.atEnd())
     {
-        QString line=fl.readLine();
-        QStringList parts=line.split(' ',QString::SkipEmptyParts);
-        if (parts.count()!=3)
+        QString line = fl.readLine();
+        QStringList parts = line.split(' ', QString::SkipEmptyParts);
+        if (parts.count() != 3)
             continue;
 
         //lines in known_hosts have format:
@@ -80,257 +76,255 @@ void SshMasterConnection::parseKnownHosts()
         //we proceeding only lines from libssh - no hashed hostnames
         //or patterns are allowed
 
-        QString type="unknown";
-        QString port="22";
-        if (parts[1]=="ssh-dss")
-            type="dss";
-        if (parts[1]=="ssh-rsa")
-            type="rsa2";
-
+        QString type = "unknown";
+        QString port = "22";
+        if (parts[1] == "ssh-dss")
+            type = "dss";
+        if (parts[1] == "ssh-rsa")
+            type = "rsa2";
 
-        QStringList hostParts=parts[0].split(":",QString::SkipEmptyParts);
-        if (hostParts.count()>1)
-            port=hostParts[1];
-        hostParts[0].replace("[","");
-        hostParts[0].replace("]","");
+        QStringList hostParts = parts[0].split(":", QString::SkipEmptyParts);
+        if (hostParts.count() > 1)
+            port = hostParts[1];
+        hostParts[0].replace("[", "");
+        hostParts[0].replace("]", "");
 
-        QString keyName=type+"@"+port+":"+hostParts[0];
+        QString keyName = type + "@" + port + ":" + hostParts[0];
 
-        QByteArray bytes=QByteArray::fromBase64(parts[2].toLatin1());
+        QByteArray bytes = QByteArray::fromBase64(parts[2].toLatin1());
         QStringList fields;
 
         //key is a set of data fields:
         //[size][data][size][data].....[size][data]
 
-        for (int i=0; i<bytes.count();)
+        for (int i = 0; i < bytes.count();)
         {
-            int size=0;
+            int size = 0;
             //first 4 bytes are for size of data field (big-endian)
-            for (int j=0; j<4; ++j)
+            for (int j = 0; j < 4; ++j)
             {
-                size+=((uchar)(bytes[i])) * pow((float)256,3-j);
+                size += ((uchar)(bytes[i])) * pow((float)256, 3 - j);
                 i++;
             }
             QByteArray data;
-            data=bytes.mid(i,size);
+            data = bytes.mid(i, size);
             QString hex;
 
-            for (int j=0; j<data.count(); ++j)
+            for (int j = 0; j < data.count(); ++j)
             {
                 QString byte;
-                byte.sprintf("%02x",(uchar)(data[j]));
-                hex+=byte;
+                byte.sprintf("%02x", (uchar)(data[j]));
+                hex += byte;
             }
             //remove leading '0'
             for (;;)
             {
-                if (hex.length()==0)
+                if (hex.length() == 0)
                     break;
-                if (hex[0]=='0')
-                    hex.remove(0,1);
+                if (hex[0] == '0')
+                    hex.remove(0, 1);
                 else
                     break;
             }
-            hex="0x"+hex;
-            fields<<hex;
-            i+=size;
+            hex = "0x" + hex;
+            fields << hex;
+            i += size;
         }
         //first element is a type of key, we don't need it
         fields.removeFirst();
-        settings.setValue(keyName,fields.join(","));
-        x2goDebug<<"Writing key to registry: HKEY_CURRENT_USER\\Software\\SimonTatham\\PuTTY\\SshHostKeys"<<endl;
-        x2goDebug<<keyName<<"="<<fields.join(",")<<endl;
+        settings.setValue(keyName, fields.join(","));
+        x2goDebug << "Writing key to registry: HKEY_CURRENT_USER\\Software\\SimonTatham\\PuTTY\\SshHostKeys" << endl;
+        x2goDebug << keyName << "=" << fields.join(",") << endl;
     }
     settings.sync();
 }
 #endif
 
-
-SshMasterConnection::SshMasterConnection (QObject* parent, QString host, int port, bool acceptUnknownServers, QString user,
-        QString pass, QString key, bool autologin, bool krblogin,
-        bool useproxy, ProxyType type, QString proxyserver, quint16 proxyport,
-        QString proxylogin, QString proxypassword, QString proxykey,
-        bool proxyautologin, bool proxyKrbLogin ) : QThread ( parent )
+SshMasterConnection::SshMasterConnection(QObject *parent, QString host, int port, bool acceptUnknownServers, QString user,
+                                         QString pass, QString key, bool autologin, bool krblogin,
+                                         bool useproxy, ProxyType type, QString proxyserver, quint16 proxyport,
+                                         QString proxylogin, QString proxypassword, QString proxykey,
+                                         bool proxyautologin, bool proxyKrbLogin) : QThread(parent)
 {
-#if defined ( Q_OS_DARWIN )
+#if defined(Q_OS_DARWIN)
     // Mac OS X provides only 512KB stack space for secondary threads.
     // As we put a 512KB buffer on the stack later on, we need a bigger stack space.
-    setStackSize (sizeof (char) * 1024 * 1024 * 2);
+    setStackSize(sizeof(char) * 1024 * 1024 * 2);
 #endif
     tcpProxySocket = NULL;
     tcpNetworkProxy = NULL;
-    sshProxy= NULL;
-    sshProxyReady=false;
-    nextPid=0;
+    sshProxy = NULL;
+    sshProxyReady = false;
+    nextPid = 0;
 
-    breakLoop=false;
-    kerberosDelegation=false;
+    breakLoop = false;
+    kerberosDelegation = false;
     x2goDebug << "SshMasterConnection, host " << host << "; port " << port << "; user " << user
               << "; useproxy " << useproxy << "; proxyserver " << proxyserver
               << "; proxyport " << proxyport;
-    this->host=host;
+    this->host = host;
     // If the hostname starts with "!" do not perform loginCheck() for this connection
     if (this->host.indexOf("!") == 0)
     {
-        this->loginCheck=false;
+        this->loginCheck = false;
         this->host.remove(0, 1);
     }
     else
     {
-        this->loginCheck=true;
-    }
-    this->port=port;
-    this->user=user;
-    this->pass=pass;
-    this->key=key;
-    this->autologin=autologin;
-    this->acceptUnknownServers=acceptUnknownServers;
-    this->useproxy=useproxy;
-    this->proxytype=type;
-    this->proxyautologin=proxyautologin;
-    this->proxykey=proxykey;
-    this->proxyserver=proxyserver;
-    this->proxyport=proxyport;
-    this->proxylogin=proxylogin;
-    this->proxypassword=proxypassword;
-    this->proxyKrbLogin=proxyKrbLogin;
-    mainWnd=(ONMainWindow*) parent;
-    kerberos=krblogin;
-    challengeAuthVerificationCode=QString::null;
-
-#if LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 6, 0)
-    if (this->user.isEmpty ()) {
+        this->loginCheck = true;
+    }
+    this->port = port;
+    this->user = user;
+    this->pass = pass;
+    this->key = key;
+    this->autologin = autologin;
+    this->acceptUnknownServers = acceptUnknownServers;
+    this->useproxy = useproxy;
+    this->proxytype = type;
+    this->proxyautologin = proxyautologin;
+    this->proxykey = proxykey;
+    this->proxyserver = proxyserver;
+    this->proxyport = proxyport;
+    this->proxylogin = proxylogin;
+    this->proxypassword = proxypassword;
+    this->proxyKrbLogin = proxyKrbLogin;
+    mainWnd = (ONMainWindow *)parent;
+    kerberos = krblogin;
+    challengeAuthVerificationCode = QString::null;
+
+#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 6, 0)
+    if (this->user.isEmpty())
+    {
         /* We might have a config file request pending, honor this. */
-        ssh_session tmp_session = ssh_new ();
+        ssh_session tmp_session = ssh_new();
 
-        if (!tmp_session) {
-            QString error_msg = tr ("Cannot create SSH session.");
-            error_msg += " " + tr ("Using environment-provided username.");
+        if (!tmp_session)
+        {
+            QString error_msg = tr("Cannot create SSH session.");
+            error_msg += " " + tr("Using environment-provided username.");
             x2goDebug << error_msg;
         }
-        else {
+        else
+        {
             QByteArray tmp_BA;
 
-            tmp_BA = this->host.toLocal8Bit ();
+            tmp_BA = this->host.toLocal8Bit();
 
-            ssh_options_set (tmp_session, SSH_OPTIONS_HOST, tmp_BA.data ());
+            ssh_options_set(tmp_session, SSH_OPTIONS_HOST, tmp_BA.data());
 
-            if (ssh_options_parse_config (tmp_session, NULL) < 0) {
+            if (ssh_options_parse_config(tmp_session, NULL) < 0)
+            {
                 x2goDebug << "Warning: unable to parse the SSH config file.";
             }
 
             char *inferred_username = NULL;
-            ssh_options_get (tmp_session, SSH_OPTIONS_USER, &inferred_username);
+            ssh_options_get(tmp_session, SSH_OPTIONS_USER, &inferred_username);
             x2goDebug << "Temporary session user name after config file parse: " << inferred_username;
 
-            this->user = QString::fromLocal8Bit (inferred_username);
+            this->user = QString::fromLocal8Bit(inferred_username);
 
-            ssh_string_free_char (inferred_username);
-            ssh_free (tmp_session);
+            ssh_string_free_char(inferred_username);
+            ssh_free(tmp_session);
         }
     }
 #endif
 
-    if (this->user.isEmpty ()) {
+    if (this->user.isEmpty())
+    {
 #ifdef Q_OS_WIN
-        this->user = getenv ("USERNAME");
+        this->user = getenv("USERNAME");
 #else
-        this->user = getenv ("USER");
+        this->user = getenv("USER");
 #endif
     }
 
     if (kerberos)
     {
-        x2goDebug<<"Starting SSH connection with Kerberos authentication.";
+        x2goDebug << "Starting SSH connection with Kerberos authentication.";
     }
     else
     {
-        x2goDebug<<"Starting SSH connection without Kerberos authentication.";
+        x2goDebug << "Starting SSH connection without Kerberos authentication.";
     }
-    x2goDebug<<"SshMasterConnection, instance "<<this<<" created.";
+    x2goDebug << "SshMasterConnection, instance " << this << " created.";
 }
 
-
 void SshMasterConnection::slotSshProxyConnectionOk()
 {
-    x2goDebug<<"SSH proxy connected.";
+    x2goDebug << "SSH proxy connected.";
 
-
-    localProxyPort=PROXYTUNNELPORT;
-    while ( ONMainWindow::isServerRunning ( localProxyPort ) )
+    localProxyPort = PROXYTUNNELPORT;
+    while (ONMainWindow::isServerRunning(localProxyPort))
         ++localProxyPort;
 
-    sshProxy->startTunnel ( host, port, "127.0.0.1",localProxyPort,false,this, SLOT ( slotSshProxyTunnelOk(int)),
-                            SLOT ( slotSshProxyTunnelFailed(bool,QString,int)));
-
+    sshProxy->startTunnel(host, port, "127.0.0.1", localProxyPort, false, this, SLOT(slotSshProxyTunnelOk(int)),
+                          SLOT(slotSshProxyTunnelFailed(bool, QString, int)));
 }
 
-
-int SshMasterConnection::copyFile(const QString& src, const QString dst, QObject* receiver, const char* slotFinished)
+int SshMasterConnection::copyFile(const QString &src, const QString dst, QObject *receiver, const char *slotFinished)
 {
-    SshProcess* proc=new SshProcess(this, nextPid++);
-    if(receiver && slotFinished)
+    SshProcess *proc = new SshProcess(this, nextPid++);
+    if (receiver && slotFinished)
     {
-        connect(proc, SIGNAL(sshFinished(bool,QString,int)), receiver, slotFinished);
+        connect(proc, SIGNAL(sshFinished(bool, QString, int)), receiver, slotFinished);
     }
-    proc->start_cp(src,dst);
-    processes<<proc;
+    proc->start_cp(src, dst);
+    processes << proc;
     return proc->pid;
 }
 
-int SshMasterConnection::executeCommand(const QString& command, QObject* receiver, const char* slotFinished, bool overridePath)
+int SshMasterConnection::executeCommand(const QString &command, QObject *receiver, const char *slotFinished, bool overridePath)
 {
-    SshProcess* proc=new SshProcess(this, nextPid++);
-    if(receiver && slotFinished)
+    SshProcess *proc = new SshProcess(this, nextPid++);
+    if (receiver && slotFinished)
     {
-        connect(proc, SIGNAL(sshFinished(bool,QString,int)), receiver, slotFinished);
+        connect(proc, SIGNAL(sshFinished(bool, QString, int)), receiver, slotFinished);
     }
     proc->startNormal(command, overridePath);
-    processes<<proc;
+    processes << proc;
     return proc->pid;
-
 }
 
 QString SshMasterConnection::getSourceFile(int pid)
 {
-    foreach (SshProcess* proc, processes)
+    foreach (SshProcess *proc, processes)
     {
-        if(proc->pid==pid)
+        if (proc->pid == pid)
             return proc->getSource();
     }
     return QString ::null;
 }
 
-
 void SshMasterConnection::addReverseTunnelConnections()
 {
     reverseTunnelRequestMutex.lock();
-    for(int i=0; i<reverseTunnelRequest.count(); ++i)
+    for (int i = 0; i < reverseTunnelRequest.count(); ++i)
     {
-        if(!reverseTunnelRequest[i].listen)
+        if (!reverseTunnelRequest[i].listen)
         {
-            reverseTunnelRequest[i].listen=true;
+            reverseTunnelRequest[i].listen = true;
 
             int rc = SSH_AGAIN;
 
-#if LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 7, 0)
+#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 7, 0)
             /* Non-blocking mode may return SSH_AGAIN, so try again if neceassary. */
-            while (SSH_AGAIN == rc) {
+            while (SSH_AGAIN == rc)
+            {
                 rc = ssh_channel_listen_forward(my_ssh_session, NULL, reverseTunnelRequest[i].forwardPort, NULL);
 #else
             {
                 rc = ssh_forward_listen(my_ssh_session, NULL, reverseTunnelRequest[i].forwardPort, NULL);
 #endif
 
-                if(rc==SSH_OK)
+                if (rc == SSH_OK)
                 {
                     emit reverseTunnelOk(reverseTunnelRequest[i].creator);
-                    x2goDebug<<"Listening for TCP/IP connections on "<<reverseTunnelRequest[i].forwardPort;
+                    x2goDebug << "Listening for TCP/IP connections on " << reverseTunnelRequest[i].forwardPort;
                 }
-                if(rc==SSH_ERROR)
+                if (rc == SSH_ERROR)
                 {
-                    QString err=ssh_get_error(my_ssh_session);
-                    x2goDebug<<"Forward port "<<reverseTunnelRequest[i].forwardPort<<" failed:"<<err;
+                    QString err = ssh_get_error(my_ssh_session);
+                    x2goDebug << "Forward port " << reverseTunnelRequest[i].forwardPort << " failed:" << err;
                     emit reverseTunnelFailed(reverseTunnelRequest[i].creator, err);
                 }
             }
@@ -342,192 +336,185 @@ void SshMasterConnection::addReverseTunnelConnections()
 void SshMasterConnection::checkReverseTunnelConnections()
 {
     int port;
-    ssh_channel chan=ssh_channel_accept_forward(my_ssh_session, 0, &port);
-    if(chan)
+    ssh_channel chan = ssh_channel_accept_forward(my_ssh_session, 0, &port);
+    if (chan)
     {
-        x2goDebug<<"New reverse connection on port "<<port;
+        x2goDebug << "New reverse connection on port " << port;
 
         reverseTunnelRequestMutex.lock();
-        for(int i=0; i<reverseTunnelRequest.count(); ++i)
+        for (int i = 0; i < reverseTunnelRequest.count(); ++i)
         {
-            ReverseTunnelRequest req=reverseTunnelRequest[i];
-            if (static_cast<int> (req.forwardPort) == port)
+            ReverseTunnelRequest req = reverseTunnelRequest[i];
+            if (static_cast<int>(req.forwardPort) == port)
             {
-                x2goDebug<<"Creating new channel for reverse tunnel "<<port;
-                int sock=socket ( AF_INET, SOCK_STREAM,0 );
+                x2goDebug << "Creating new channel for reverse tunnel " << port;
+                int sock = socket(AF_INET, SOCK_STREAM, 0);
 #ifndef Q_OS_WIN
-                const int y=1;
+                const int y = 1;
 #else
-                const char y=1;
+                const char y = 1;
 #endif
-                setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,&y, sizeof(int));
+                setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &y, sizeof(int));
 
                 struct sockaddr_in address;
-                address.sin_family=AF_INET;
-                address.sin_port=htons ( req.localPort );
-                x2goDebug<<"Connecting to "<<req.localHost<<":"<<req.localPort<<endl;
+                address.sin_family = AF_INET;
+                address.sin_port = htons(req.localPort);
+                x2goDebug << "Connecting to " << req.localHost << ":" << req.localPort << endl;
 #ifndef Q_OS_WIN
-                inet_aton ( req.localHost.toLatin1(), &address.sin_addr );
+                inet_aton(req.localHost.toLatin1(), &address.sin_addr);
 #else
-                address.sin_addr.s_addr=inet_addr (
-                                            req.localHost.toLatin1() );
+                address.sin_addr.s_addr = inet_addr(
+                    req.localHost.toLatin1());
 #endif
 
-                if ( ::connect ( sock, ( struct sockaddr * ) &address,sizeof ( address ) ) !=0 )
+                if (::connect(sock, (struct sockaddr *)&address, sizeof(address)) != 0)
                 {
-                    QString errMsg=tr ( "Cannot connect to " ) +
-                                   req.localHost+":"+QString::number ( req.localPort );
-                    x2goDebug<<errMsg<<endl;
-                    emit ioErr ( req.creator, errMsg, "" );
+                    QString errMsg = tr("Cannot connect to ") +
+                                     req.localHost + ":" + QString::number(req.localPort);
+                    x2goDebug << errMsg << endl;
+                    emit ioErr(req.creator, errMsg, "");
                     break;
                 }
 
                 ChannelConnection con;
-                con.channel=chan;
-                con.sock=sock;
-                con.creator=req.creator;
+                con.channel = chan;
+                con.sock = sock;
+                con.creator = req.creator;
                 channelConnectionsMutex.lock();
-                channelConnections<<con;
+                channelConnections << con;
                 channelConnectionsMutex.unlock();
-                x2goDebug<<"New channel created";
+                x2goDebug << "New channel created";
                 break;
             }
         }
         reverseTunnelRequestMutex.unlock();
-
-
     }
 }
 
-
-int SshMasterConnection::startTunnel(const QString& forwardHost, uint forwardPort, const QString& localHost, uint localPort, bool reverse,
-                                     QObject* receiver, const char* slotTunnelOk, const char* slotFinished)
+int SshMasterConnection::startTunnel(const QString &forwardHost, uint forwardPort, const QString &localHost, uint localPort, bool reverse,
+                                     QObject *receiver, const char *slotTunnelOk, const char *slotFinished)
 {
-    SshProcess* proc=new SshProcess(this, nextPid++);
-    if(receiver && slotFinished)
+    SshProcess *proc = new SshProcess(this, nextPid++);
+    if (receiver && slotFinished)
     {
-        connect(proc, SIGNAL(sshFinished(bool,QString,int)), receiver, slotFinished);
+        connect(proc, SIGNAL(sshFinished(bool, QString, int)), receiver, slotFinished);
     }
-    if(receiver && slotTunnelOk)
+    if (receiver && slotTunnelOk)
     {
         connect(proc, SIGNAL(sshTunnelOk(int)), receiver, slotTunnelOk);
     }
     proc->startTunnel(forwardHost, forwardPort, localHost, localPort, reverse);
-    if(reverse && !kerberos)
+    if (reverse && !kerberos)
     {
-        connect(this, SIGNAL(reverseTunnelOk(SshProcess*)), proc, SLOT(slotReverseTunnelOk(SshProcess*)));
-        connect(this, SIGNAL(reverseTunnelFailed(SshProcess*,QString)), proc, SLOT(slotReverseTunnelFailed(SshProcess*,QString)));
+        connect(this, SIGNAL(reverseTunnelOk(SshProcess *)), proc, SLOT(slotReverseTunnelOk(SshProcess *)));
+        connect(this, SIGNAL(reverseTunnelFailed(SshProcess *, QString)), proc, SLOT(slotReverseTunnelFailed(SshProcess *, QString)));
         ReverseTunnelRequest req;
-        req.creator=proc;
-        req.localPort=localPort;
-        req.localHost=localHost;
-        req.forwardPort=forwardPort;
-        req.listen=false;
-        x2goDebug<<"Requesting reverse tunnel from port "<<forwardPort<< " to "<<localPort;
+        req.creator = proc;
+        req.localPort = localPort;
+        req.localHost = localHost;
+        req.forwardPort = forwardPort;
+        req.listen = false;
+        x2goDebug << "Requesting reverse tunnel from port " << forwardPort << " to " << localPort;
         reverseTunnelRequestMutex.lock();
-        reverseTunnelRequest<<req;
+        reverseTunnelRequest << req;
         reverseTunnelRequestMutex.unlock();
     }
-    processes<<proc;
+    processes << proc;
     return proc->pid;
 }
 
-void SshMasterConnection::slotSshProxyInteractionFinish(SshMasterConnection* connection)
+void SshMasterConnection::slotSshProxyInteractionFinish(SshMasterConnection *connection)
 {
-    x2goDebug<<"SSH proxy interaction finished";
+    x2goDebug << "SSH proxy interaction finished";
     slotSshProxyUserAuthError("NO_ERROR");
 }
 
-void SshMasterConnection::slotSshProxyInteractionStart(SshMasterConnection* connection, QString prompt)
+void SshMasterConnection::slotSshProxyInteractionStart(SshMasterConnection *connection, QString prompt)
 {
     emit startInteraction(this, prompt);
 }
 
-void SshMasterConnection::slotSshProxyInteractionUpdate(SshMasterConnection* connection, QString output)
+void SshMasterConnection::slotSshProxyInteractionUpdate(SshMasterConnection *connection, QString output)
 {
     emit updateInteraction(this, output);
 }
 
-
 void SshMasterConnection::slotSshProxyConnectionError(QString err1, QString err2)
 {
-    breakLoop=true;
-    emit connectionError(tr("SSH proxy connection error."),err1+" "+err2);
+    breakLoop = true;
+    emit connectionError(tr("SSH proxy connection error."), err1 + " " + err2);
 }
 
-void SshMasterConnection::slotSshProxyServerAuthError(int errCode, QString err, SshMasterConnection* con)
+void SshMasterConnection::slotSshProxyServerAuthError(int errCode, QString err, SshMasterConnection *con)
 {
-    emit serverAuthError(errCode, tr("SSH proxy connection error: ")+err, con);
+    emit serverAuthError(errCode, tr("SSH proxy connection error: ") + err, con);
 }
 
 void SshMasterConnection::slotSshProxyUserAuthError(QString err)
 {
-    breakLoop=true;
-    if(err=="NO_ERROR" || err=="NO_PROXY_ERROR")
-      emit userAuthError(err);
+    breakLoop = true;
+    if (err == "NO_ERROR" || err == "NO_PROXY_ERROR")
+        emit userAuthError(err);
     else
-      emit userAuthError(tr("SSH proxy connection error: ")+err);
+        emit userAuthError(tr("SSH proxy connection error: ") + err);
 }
 
-
 void SshMasterConnection::slotSshProxyTunnelOk(int)
 {
-    x2goDebug<<"SSH proxy tunnel established.";
-    sshProxyReady=true;
+    x2goDebug << "SSH proxy tunnel established.";
+    sshProxyReady = true;
 }
 
-void SshMasterConnection::slotSshProxyTunnelFailed(bool ,  QString output,
-        int)
+void SshMasterConnection::slotSshProxyTunnelFailed(bool, QString output,
+                                                   int)
 {
-    breakLoop=true;
+    breakLoop = true;
     emit connectionError(tr("Failed to create SSH proxy tunnel."), output);
 }
 
-
-
 void SshMasterConnection::slotSshProxyServerAuthAborted()
 {
-    breakLoop=true;
+    breakLoop = true;
 }
 
 void SshMasterConnection::run()
 {
-    x2goDebug<<"SshMasterConnection, instance "<<this<<" entering thread.";
-    if(useproxy && proxytype==PROXYSSH)
+    x2goDebug << "SshMasterConnection, instance " << this << " entering thread.";
+    if (useproxy && proxytype == PROXYSSH)
     {
         x2goDebug << "proxyserver: " << proxyserver << "; proxyport: " << proxyport << "; proxylogin: " << proxylogin;
-        sshProxy=new SshMasterConnection (0, proxyserver, proxyport,acceptUnknownServers,
-                                          proxylogin, proxypassword, proxykey, proxyautologin, proxyKrbLogin, false);
-
-        qRegisterMetaType<SshMasterConnection::passphrase_types> ("SshMasterConnection::passphrase_types");
-
-        connect ( sshProxy, SIGNAL ( connectionOk(QString) ), this, SLOT ( slotSshProxyConnectionOk() ) );
-
-        connect ( sshProxy, SIGNAL ( serverAuthError ( int,QString,SshMasterConnection* ) ),this,
-                  SLOT ( slotSshProxyServerAuthError ( int,QString, SshMasterConnection* ) ) );
-        connect ( sshProxy, SIGNAL ( needPassPhrase(SshMasterConnection*, SshMasterConnection::passphrase_types)),this,
-                  SIGNAL ( needPassPhrase(SshMasterConnection*, SshMasterConnection::passphrase_types)) );
-        connect ( sshProxy, SIGNAL ( serverAuthAborted()),this,
-                  SLOT ( slotSshProxyServerAuthAborted()) );
-        connect ( sshProxy, SIGNAL ( userAuthError ( QString ) ),this,SLOT ( slotSshProxyUserAuthError ( QString ) ) );
-        connect ( sshProxy, SIGNAL ( connectionError ( QString,QString ) ), this,
-                  SLOT ( slotSshProxyConnectionError ( QString,QString ) ) );
-
-        connect ( sshProxy, SIGNAL(startInteraction(SshMasterConnection*,QString)),this,
-                  SLOT(slotSshProxyInteractionStart(SshMasterConnection*,QString)) );
-        connect ( sshProxy, SIGNAL(updateInteraction(SshMasterConnection*,QString)),this,
-                  SLOT(slotSshProxyInteractionUpdate(SshMasterConnection*,QString)) );
-        connect ( sshProxy, SIGNAL(finishInteraction(SshMasterConnection*)),this,
-		  SLOT(slotSshProxyInteractionFinish(SshMasterConnection*)));
-//         connect ( interDlg, SIGNAL(textEntered(QString)), con, SLOT(interactionTextEnter(QString)));
-//         connect ( interDlg, SIGNAL(interrupt()), con, SLOT(interactionInterruptSlot()));
-
-        sshProxyReady=false;
+        sshProxy = new SshMasterConnection(0, proxyserver, proxyport, acceptUnknownServers,
+                                           proxylogin, proxypassword, proxykey, proxyautologin, proxyKrbLogin, false);
+
+        qRegisterMetaType<SshMasterConnection::passphrase_types>("SshMasterConnection::passphrase_types");
+
+        connect(sshProxy, SIGNAL(connectionOk(QString)), this, SLOT(slotSshProxyConnectionOk()));
+
+        connect(sshProxy, SIGNAL(serverAuthError(int, QString, SshMasterConnection *)), this,
+                SLOT(slotSshProxyServerAuthError(int, QString, SshMasterConnection *)));
+        connect(sshProxy, SIGNAL(needPassPhrase(SshMasterConnection *, SshMasterConnection::passphrase_types)), this,
+                SIGNAL(needPassPhrase(SshMasterConnection *, SshMasterConnection::passphrase_types)));
+        connect(sshProxy, SIGNAL(serverAuthAborted()), this,
+                SLOT(slotSshProxyServerAuthAborted()));
+        connect(sshProxy, SIGNAL(userAuthError(QString)), this, SLOT(slotSshProxyUserAuthError(QString)));
+        connect(sshProxy, SIGNAL(connectionError(QString, QString)), this,
+                SLOT(slotSshProxyConnectionError(QString, QString)));
+
+        connect(sshProxy, SIGNAL(startInteraction(SshMasterConnection *, QString)), this,
+                SLOT(slotSshProxyInteractionStart(SshMasterConnection *, QString)));
+        connect(sshProxy, SIGNAL(updateInteraction(SshMasterConnection *, QString)), this,
+                SLOT(slotSshProxyInteractionUpdate(SshMasterConnection *, QString)));
+        connect(sshProxy, SIGNAL(finishInteraction(SshMasterConnection *)), this,
+                SLOT(slotSshProxyInteractionFinish(SshMasterConnection *)));
+        //         connect ( interDlg, SIGNAL(textEntered(QString)), con, SLOT(interactionTextEnter(QString)));
+        //         connect ( interDlg, SIGNAL(interrupt()), con, SLOT(interactionInterruptSlot()));
+
+        sshProxyReady = false;
         sshProxy->start();
 
-        while(! sshProxyReady)
+        while (!sshProxyReady)
         {
-            if(breakLoop)
+            if (breakLoop)
             {
                 quit();
                 return;
@@ -535,44 +522,46 @@ void SshMasterConnection::run()
             this->usleep(200);
         }
     }
-    disconnectSessionFlag=false;
+    disconnectSessionFlag = false;
 
     int verbosity = SSH_LOG_NOLOG;
 
-    if (ONMainWindow::libssh_debugging) {
-#if LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 6, 0)
-      verbosity = SSH_LOG_INFO;
+    if (ONMainWindow::libssh_debugging)
+    {
+#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 6, 0)
+        verbosity = SSH_LOG_INFO;
 #else
-      verbosity = SSH_LOG_PROTOCOL;
+        verbosity = SSH_LOG_PROTOCOL;
 #endif
     }
 
-    if (ONMainWindow::libssh_packetlog) {
-#if LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 6, 0)
-      verbosity = SSH_LOG_DEBUG;
+    if (ONMainWindow::libssh_packetlog)
+    {
+#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 6, 0)
+        verbosity = SSH_LOG_DEBUG;
 #else
-      verbosity = SSH_LOG_PACKET;
+        verbosity = SSH_LOG_PACKET;
 #endif
     }
 
     long timeout = 60;
 
     my_ssh_session = ssh_new();
-    if ( my_ssh_session == NULL )
+    if (my_ssh_session == NULL)
     {
-        QString err=tr ( "Cannot create SSH session." );
-        x2goDebug<<err<<endl;
-        emit connectionError ( err,"" );
+        QString err = tr("Cannot create SSH session.");
+        x2goDebug << err << endl;
+        emit connectionError(err, "");
         quit();
         return;
     }
 
 #ifdef Q_OS_WIN
     {
-        QByteArray tmp_BA = (mainWnd->getHomeDirectory () + "/ssh").toLocal8Bit ();
+        QByteArray tmp_BA = (mainWnd->getHomeDirectory() + "/ssh").toLocal8Bit();
 
-        ssh_options_set ( my_ssh_session, SSH_OPTIONS_SSH_DIR, tmp_BA.data ());
-        x2goDebug << "Setting SSH directory to " << tmp_BA.data ();
+        ssh_options_set(my_ssh_session, SSH_OPTIONS_SSH_DIR, tmp_BA.data());
+        x2goDebug << "Setting SSH directory to " << tmp_BA.data();
         if (kerberos)
         {
             parseKnownHosts();
@@ -588,129 +577,129 @@ void SshMasterConnection::run()
     {
         socket_t proxysocket = SSH_INVALID_SOCKET;
 
-        tcpNetworkProxy = new QNetworkProxy( QNetworkProxy::HttpProxy,
-                                             proxyserver, proxyport, proxylogin, proxypassword);
+        tcpNetworkProxy = new QNetworkProxy(QNetworkProxy::HttpProxy,
+                                            proxyserver, proxyport, proxylogin, proxypassword);
         tcpProxySocket = new QTcpSocket();
-        tcpProxySocket->setProxy( *tcpNetworkProxy );
+        tcpProxySocket->setProxy(*tcpNetworkProxy);
         tcpProxySocket->connectToHost(host, port);
         if (!tcpProxySocket->waitForConnected(30000))
         {
-            QString message=tr ( "Cannot connect to proxy server." );
-            x2goDebug<<message<<endl;
-            emit connectionError ( "Proxy", message );
-            ssh_free ( my_ssh_session );
+            QString message = tr("Cannot connect to proxy server.");
+            x2goDebug << message << endl;
+            emit connectionError("Proxy", message);
+            ssh_free(my_ssh_session);
             quit();
             return;
         }
         proxysocket = tcpProxySocket->socketDescriptor();
         x2goDebug << "Created HTTP proxy socket: " << proxysocket << endl;
-        ssh_options_set( my_ssh_session, SSH_OPTIONS_FD, &proxysocket);
-        ssh_set_fd_toread( my_ssh_session);
-        x2goDebug<<"Connected to HTTP proxy server: " << proxyserver << ":"
-                 << proxyport <<endl;
+        ssh_options_set(my_ssh_session, SSH_OPTIONS_FD, &proxysocket);
+        ssh_set_fd_toread(my_ssh_session);
+        x2goDebug << "Connected to HTTP proxy server: " << proxyserver << ":"
+                  << proxyport << endl;
     }
 
-    if ( !sshConnect() )
+    if (!sshConnect())
     {
-        if(disconnectSessionFlag)
+        if (disconnectSessionFlag)
         {
-            x2goDebug<<"Session is already disconnected, exiting."<<endl;
+            x2goDebug << "Session is already disconnected, exiting." << endl;
             return;
         }
-        QString err=ssh_get_error ( my_ssh_session );
-        QString message=tr ( "Cannot connect to " ) +host+":"+QString::number ( port );
-        x2goDebug<<message<<" - "<<err;
-        emit connectionError ( message, err );
-        ssh_free ( my_ssh_session );
+        QString err = ssh_get_error(my_ssh_session);
+        QString message = tr("Cannot connect to ") + host + ":" + QString::number(port);
+        x2goDebug << message << " - " << err;
+        emit connectionError(message, err);
+        ssh_free(my_ssh_session);
         quit();
         return;
     }
-    if(disconnectSessionFlag)
+    if (disconnectSessionFlag)
     {
-        x2goDebug<<"Session is already disconnected, exiting."<<endl;
+        x2goDebug << "Session is already disconnected, exiting." << endl;
         return;
     }
     QString errMsg;
-    int state=serverAuth ( errMsg );
-    if ( state != SSH_SERVER_KNOWN_OK )
+    int state = serverAuth(errMsg);
+    if (state != SSH_SERVER_KNOWN_OK)
     {
-        if(disconnectSessionFlag)
+        if (disconnectSessionFlag)
         {
-            x2goDebug<<"Session is already disconnected, exiting."<<endl;
+            x2goDebug << "Session is already disconnected, exiting." << endl;
             return;
         }
-        writeHostKey=writeHostKeyReady=false;
-        emit serverAuthError ( state,errMsg, this );
-        for(;;)
+        writeHostKey = writeHostKeyReady = false;
+        emit serverAuthError(state, errMsg, this);
+        for (;;)
         {
             this->usleep(100);
             writeHostKeyMutex.lock();
-            if(writeHostKeyReady)
+            if (writeHostKeyReady)
             {
-                if(writeHostKey)
+                if (writeHostKey)
                     ssh_write_knownhost(my_ssh_session);
                 writeHostKeyMutex.unlock();
                 break;
             }
             writeHostKeyMutex.unlock();
         }
-        ssh_disconnect ( my_ssh_session );
-        ssh_free ( my_ssh_session );
+        ssh_disconnect(my_ssh_session);
+        ssh_free(my_ssh_session);
         return;
     }
 
-    if(disconnectSessionFlag)
+    if (disconnectSessionFlag)
     {
-        x2goDebug<<"Session is already disconnected, exiting."<<endl;
+        x2goDebug << "Session is already disconnected, exiting." << endl;
         return;
     }
 
-    QByteArray tmp_BA = user.toLocal8Bit ();
-    ssh_options_set ( my_ssh_session, SSH_OPTIONS_USER, tmp_BA.data () );
+    QByteArray tmp_BA = user.toLocal8Bit();
+    ssh_options_set(my_ssh_session, SSH_OPTIONS_USER, tmp_BA.data());
 
 #ifdef Q_OS_WIN
     {
-        QByteArray tmp_BA = (mainWnd->getHomeDirectory () + "/ssh").toLocal8Bit ();
+        QByteArray tmp_BA = (mainWnd->getHomeDirectory() + "/ssh").toLocal8Bit();
 
-        ssh_options_set ( my_ssh_session, SSH_OPTIONS_SSH_DIR, tmp_BA.data () );
-        x2goDebug << "Setting SSH directory to " << tmp_BA.data ();
+        ssh_options_set(my_ssh_session, SSH_OPTIONS_SSH_DIR, tmp_BA.data());
+        x2goDebug << "Setting SSH directory to " << tmp_BA.data();
     }
 #endif
 
-    if ( userAuth() )
+    if (userAuth())
     {
-        if(disconnectSessionFlag)
+        if (disconnectSessionFlag)
         {
-            x2goDebug<<"Session is already disconnected, exiting."<<endl;
+            x2goDebug << "Session is already disconnected, exiting." << endl;
             return;
         }
-        x2goDebug<<"User authentication OK.";
+        x2goDebug << "User authentication OK.";
         // checkLogin() is currently specific to libssh.
-        if(kerberos)
+        if (kerberos)
         {
             emit connectionOk(host);
         }
-        else if(this->loginCheck == false)
+        else if (this->loginCheck == false)
         {
-            x2goDebug<<"Skipping Login Check as requested by configuration";
+            x2goDebug << "Skipping Login Check as requested by configuration";
             emit connectionOk(host);
         }
         else
         {
-            if(checkLogin())
+            if (checkLogin())
             {
-                x2goDebug<<"Login Check - OK";
+                x2goDebug << "Login Check - OK";
                 emit connectionOk(host);
             }
             else
             {
-                x2goDebug<<"Login Check - Failed";
-//          if(!interactionInterrupt)
+                x2goDebug << "Login Check - Failed";
+                //          if(!interactionInterrupt)
                 {
-                  emit finishInteraction(this);
+                    emit finishInteraction(this);
                 }
-                ssh_disconnect ( my_ssh_session );
-                ssh_free ( my_ssh_session );
+                ssh_disconnect(my_ssh_session);
+                ssh_free(my_ssh_session);
                 quit();
                 return;
             }
@@ -718,105 +707,104 @@ void SshMasterConnection::run()
     }
     else
     {
-        if(disconnectSessionFlag)
+        if (disconnectSessionFlag)
         {
-            x2goDebug<<"Session is already disconnected, exiting."<<endl;
+            x2goDebug << "Session is already disconnected, exiting." << endl;
             return;
         }
         QString err;
         if (!kerberos)
         {
-            err=ssh_get_error ( my_ssh_session );
+            err = ssh_get_error(my_ssh_session);
         }
         else
         {
-            err=sshProcErrString;
+            err = sshProcErrString;
         }
-        QString message=tr ( "Authentication failed." );
-        x2goDebug<<message<<" - "<<err;
-        emit userAuthError ( authErrors.join ( "\n" ) );
-        ssh_disconnect ( my_ssh_session );
-        ssh_free ( my_ssh_session );
+        QString message = tr("Authentication failed.");
+        x2goDebug << message << " - " << err;
+        emit userAuthError(authErrors.join("\n"));
+        ssh_disconnect(my_ssh_session);
+        ssh_free(my_ssh_session);
         quit();
         return;
     }
 
-
 #ifndef Q_OS_WIN
-    const int y=1;
+    const int y = 1;
 #else
-    const char y=1;
+    const char y = 1;
 #endif
-    socket_t session_sock=ssh_get_fd(my_ssh_session);
-    setsockopt(session_sock, IPPROTO_TCP, TCP_NODELAY,&y, sizeof(int));
-
+    socket_t session_sock = ssh_get_fd(my_ssh_session);
+    setsockopt(session_sock, IPPROTO_TCP, TCP_NODELAY, &y, sizeof(int));
 
     channelLoop();
 }
 
-
 SshMasterConnection::~SshMasterConnection()
 {
 
     disconnectFlagMutex.lock();
-    disconnectSessionFlag=true;
+    disconnectSessionFlag = true;
     disconnectFlagMutex.unlock();
-    x2goDebug<<"SshMasterConnection, instance "<<this<<" waiting for thread to finish.";
+    x2goDebug << "SshMasterConnection, instance " << this << " waiting for thread to finish.";
     wait(15000);
-    x2goDebug<<"SshMasterConnection, instance "<<this<<" thread finished.";
-    for(int i=processes.count()-1; i>=0; --i)
+    x2goDebug << "SshMasterConnection, instance " << this << " thread finished.";
+    for (int i = processes.count() - 1; i >= 0; --i)
     {
         delete processes[i];
     }
-    x2goDebug<<"SshMasterConnection, instance "<<this<<" finished destructor.";
+    x2goDebug << "SshMasterConnection, instance " << this << " finished destructor.";
 }
 
-
 bool SshMasterConnection::sshConnect()
 {
     int rc;
     QByteArray tmpBA = host.toLocal8Bit();
-    if(useproxy && proxytype==PROXYSSH)
+    if (useproxy && proxytype == PROXYSSH)
     {
-        ssh_options_set ( my_ssh_session, SSH_OPTIONS_HOST, "127.0.0.1" );
-        if (localProxyPort) {
-            ssh_options_set ( my_ssh_session, SSH_OPTIONS_PORT, &localProxyPort );
+        ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, "127.0.0.1");
+        if (localProxyPort)
+        {
+            ssh_options_set(my_ssh_session, SSH_OPTIONS_PORT, &localProxyPort);
         }
     }
     else
     {
-        ssh_options_set ( my_ssh_session, SSH_OPTIONS_HOST, tmpBA.data() );
-        if (port) {
-            ssh_options_set ( my_ssh_session, SSH_OPTIONS_PORT, &port );
+        ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, tmpBA.data());
+        if (port)
+        {
+            ssh_options_set(my_ssh_session, SSH_OPTIONS_PORT, &port);
         }
     }
 
-#if LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 6, 0)
+#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 6, 0)
     unsigned int cur_port = 0;
-    ssh_options_get_port (my_ssh_session, &cur_port);
+    ssh_options_get_port(my_ssh_session, &cur_port);
     x2goDebug << "Session port before config file parse: " << cur_port;
 #endif
 
     /* Parse ~/.ssh/config. */
-    if (ssh_options_parse_config (my_ssh_session, NULL) < 0) {
+    if (ssh_options_parse_config(my_ssh_session, NULL) < 0)
+    {
         x2goDebug << "Warning: unable to parse the SSH config file.";
     }
 
-#if LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 6, 0)
-    ssh_options_get_port (my_ssh_session, &cur_port);
+#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 6, 0)
+    ssh_options_get_port(my_ssh_session, &cur_port);
     x2goDebug << "Session port after config file parse: " << cur_port;
 #endif
 
-    rc = ssh_connect ( my_ssh_session );
-    if ( rc != SSH_OK )
+    rc = ssh_connect(my_ssh_session);
+    if (rc != SSH_OK)
     {
         return false;
     }
-//set values for remote host for proper server authentication
-    if(useproxy && proxytype==PROXYSSH)
+    //set values for remote host for proper server authentication
+    if (useproxy && proxytype == PROXYSSH)
     {
         x2goDebug << "Connected via proxy, resetting connection values on session to " << tmpBA.data() << ":" << port;
-        ssh_options_set ( my_ssh_session, SSH_OPTIONS_HOST, tmpBA.data() );
+        ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, tmpBA.data());
 
         /*
          * The SSH port might be 0, which indicates to use the default port
@@ -834,205 +822,207 @@ bool SshMasterConnection::sshConnect()
         int work_port = port;
 
         /* Oh, yeah, and we don't really support port values of 0 for pre-0.6.0 libssh. Sorry. */
-#if LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 6, 0)
-        if (!work_port) {
-            ssh_session tmp_session = ssh_new ();
+#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 6, 0)
+        if (!work_port)
+        {
+            ssh_session tmp_session = ssh_new();
 
-            if (!tmp_session) {
-                QString error_msg = tr ("Cannot create SSH session.");
+            if (!tmp_session)
+            {
+                QString error_msg = tr("Cannot create SSH session.");
                 x2goDebug << error_msg;
                 return (false);
             }
-            else {
-                ssh_options_set (tmp_session, SSH_OPTIONS_HOST, tmpBA.data ());
+            else
+            {
+                ssh_options_set(tmp_session, SSH_OPTIONS_HOST, tmpBA.data());
 
                 /* Parse ~/.ssh/config. */
-                if (ssh_options_parse_config (tmp_session, NULL) < 0) {
+                if (ssh_options_parse_config(tmp_session, NULL) < 0)
+                {
                     x2goDebug << "Warning: unable to parse the SSH config file.";
                 }
 
                 unsigned int inferred_port = 0;
-                ssh_options_get_port (tmp_session, &inferred_port);
+                ssh_options_get_port(tmp_session, &inferred_port);
                 x2goDebug << "Fetched inferred session port: " << inferred_port;
 
                 work_port = inferred_port & 0xFFFF;
 
-                ssh_free (tmp_session);
+                ssh_free(tmp_session);
             }
         }
 #endif
 
-        ssh_options_set ( my_ssh_session, SSH_OPTIONS_PORT, &work_port );
+        ssh_options_set(my_ssh_session, SSH_OPTIONS_PORT, &work_port);
     }
 
-#if LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 6, 0)
-    ssh_options_get_port (my_ssh_session, &cur_port);
+#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 6, 0)
+    ssh_options_get_port(my_ssh_session, &cur_port);
     x2goDebug << "Session port before config file parse (part 2): " << cur_port;
 #endif
 
     /* Parse ~/.ssh/config. */
-    if (ssh_options_parse_config (my_ssh_session, NULL) < 0) {
+    if (ssh_options_parse_config(my_ssh_session, NULL) < 0)
+    {
         x2goDebug << "Warning: unable to parse the SSH config file.";
     }
 
-#if LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 6, 0)
-    ssh_options_get_port (my_ssh_session, &cur_port);
+#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 6, 0)
+    ssh_options_get_port(my_ssh_session, &cur_port);
     x2goDebug << "Session port after config file parse (part 2): " << cur_port;
 #endif
 
     return true;
 }
 
-
 void SshMasterConnection::writeKnownHosts(bool write)
 {
     writeHostKeyMutex.lock();
-    writeHostKeyReady=true;
-    writeHostKey=write;
-    if(!write)
+    writeHostKeyReady = true;
+    writeHostKey = write;
+    if (!write)
     {
-        breakLoop=true;
+        breakLoop = true;
         emit serverAuthAborted();
     }
     writeHostKeyMutex.unlock();
-
 }
 
-
-int SshMasterConnection::serverAuth ( QString& errorMsg )
+int SshMasterConnection::serverAuth(QString &errorMsg)
 {
-    x2goDebug<<"cserverAuth";
+    x2goDebug << "cserverAuth";
 
     int state = SSH_SERVER_ERROR;
     unsigned char *hash = NULL;
     char *hexa = NULL;
-#if LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 6, 0)
-    ssh_key srv_pubkey = { 0 };
+#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 6, 0)
+    ssh_key srv_pubkey = {0};
     int rc = SSH_ERROR;
     size_t hlen = 0;
 #else
     int hlen = 0;
 #endif
 
-    state = ssh_is_server_known ( my_ssh_session );
+    state = ssh_is_server_known(my_ssh_session);
 
-#if LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 6, 0)
-#if LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 8, 0)
-    rc = ssh_get_server_publickey (my_ssh_session, &srv_pubkey);
-#else /* LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 8, 0) */
-    rc = ssh_get_publickey (my_ssh_session, &srv_pubkey);
+#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 6, 0)
+#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 8, 0)
+    rc = ssh_get_server_publickey(my_ssh_session, &srv_pubkey);
+#else  /* LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 8, 0) */
+    rc = ssh_get_publickey(my_ssh_session, &srv_pubkey);
 #endif /* LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 8, 0) */
 
-    if (SSH_OK != rc) {
+    if (SSH_OK != rc)
+    {
         return (SSH_SERVER_ERROR);
     }
 
-    rc = ssh_get_publickey_hash (srv_pubkey, SSH_PUBLICKEY_HASH_SHA1, &hash, &hlen);
-    ssh_key_free (srv_pubkey);
+    rc = ssh_get_publickey_hash(srv_pubkey, SSH_PUBLICKEY_HASH_SHA1, &hash, &hlen);
+    ssh_key_free(srv_pubkey);
 
-    if (0 != rc) {
+    if (0 != rc)
+    {
         return (SSH_SERVER_ERROR);
     }
 #else
-    hlen = ssh_get_pubkey_hash ( my_ssh_session, &hash );
+    hlen = ssh_get_pubkey_hash(my_ssh_session, &hash);
 #endif
 
-    if ( 0 >= hlen )
+    if (0 >= hlen)
         return SSH_SERVER_ERROR;
 
-    x2goDebug<<"state: "<<state<<endl;
+    x2goDebug << "state: " << state << endl;
 
-    switch ( state )
+    switch (state)
     {
     case SSH_SERVER_KNOWN_OK:
         break; /* ok */
 
     case SSH_SERVER_KNOWN_CHANGED:
-        hexa = ssh_get_hexa ( hash, hlen );
-        errorMsg=host+":"+QString::number(port)+" - "+hexa;
-        ssh_string_free_char ( hexa );
+        hexa = ssh_get_hexa(hash, hlen);
+        errorMsg = host + ":" + QString::number(port) + " - " + hexa;
+        ssh_string_free_char(hexa);
         break;
     case SSH_SERVER_FOUND_OTHER:
         break;
     case SSH_SERVER_FILE_NOT_FOUND:
     case SSH_SERVER_NOT_KNOWN:
-        if ( !acceptUnknownServers )
+        if (!acceptUnknownServers)
         {
-            hexa = ssh_get_hexa ( hash, hlen );
-            errorMsg=host+":"+QString::number(port)+" - "+hexa;
-            ssh_string_free_char ( hexa );
+            hexa = ssh_get_hexa(hash, hlen);
+            errorMsg = host + ":" + QString::number(port) + " - " + hexa;
+            ssh_string_free_char(hexa);
             break;
         }
-        ssh_write_knownhost ( my_ssh_session );
-        state=SSH_SERVER_KNOWN_OK;
+        ssh_write_knownhost(my_ssh_session);
+        state = SSH_SERVER_KNOWN_OK;
         break;
 
     case SSH_SERVER_ERROR:
-        errorMsg=host+":"+QString::number(port)+" - "+ssh_get_error ( my_ssh_session );
+        errorMsg = host + ":" + QString::number(port) + " - " + ssh_get_error(my_ssh_session);
         break;
     }
-    ssh_clean_pubkey_hash ( &hash );
+    ssh_clean_pubkey_hash(&hash);
     return state;
 }
 
 void SshMasterConnection::setVerficationCode(QString code)
 {
-    challengeAuthVerificationCode=code;
+    challengeAuthVerificationCode = code;
 }
 
-
-
 bool SshMasterConnection::userAuthKeyboardInteractive(QString prompt)
 {
-    x2goDebug<<"Open Interaction dialog to complete authentication";
+    x2goDebug << "Open Interaction dialog to complete authentication";
     emit startInteraction(this, prompt);
-    interactionInterrupt=false;
-    interactionInputText=QString::null;
-    int rez=SSH_AUTH_INFO;
-    bool firstLoop=true;
-    int prompts=1;
+    interactionInterrupt = false;
+    interactionInputText = QString::null;
+    int rez = SSH_AUTH_INFO;
+    bool firstLoop = true;
+    int prompts = 1;
     QString instruction;
-    while (rez==SSH_AUTH_INFO)
+    while (rez == SSH_AUTH_INFO)
     {
 
-        if(firstLoop)
+        if (firstLoop)
         {
-            firstLoop=false;
+            firstLoop = false;
         }
         else
         {
-            prompts=ssh_userauth_kbdint_getnprompts(my_ssh_session);
-            if(prompts>0)
-                emit updateInteraction(this, ssh_userauth_kbdint_getprompt(my_ssh_session,0,NULL));
+            prompts = ssh_userauth_kbdint_getnprompts(my_ssh_session);
+            if (prompts > 0)
+                emit updateInteraction(this, ssh_userauth_kbdint_getprompt(my_ssh_session, 0, NULL));
 
-            QString name= ssh_userauth_kbdint_getname(my_ssh_session);
+            QString name = ssh_userauth_kbdint_getname(my_ssh_session);
             instruction = ssh_userauth_kbdint_getinstruction(my_ssh_session);
-            x2goDebug<<"Have prompts: "<<prompts<<endl;
-            x2goDebug<<"Name: "<<name<<endl;
-            x2goDebug<<"Instruction: "<<instruction<<endl;
+            x2goDebug << "Have prompts: " << prompts << endl;
+            x2goDebug << "Name: " << name << endl;
+            x2goDebug << "Instruction: " << instruction << endl;
         }
-        if(prompts>0)
+        if (prompts > 0)
         {
-            while(true)
+            while (true)
             {
                 bool interrupt;
                 interactionInputMutex.lock();
-                interrupt=interactionInterrupt;
-                QString textToSend=interactionInputText;
-                interactionInputText=QString::null;
+                interrupt = interactionInterrupt;
+                QString textToSend = interactionInputText;
+                interactionInputText = QString::null;
                 interactionInputMutex.unlock();
-                if(textToSend.length()>0)
+                if (textToSend.length() > 0)
                 {
-                    x2goDebug<<"SEND Input to SERVER";
-                    textToSend.replace("\n","");
-                    ssh_userauth_kbdint_setanswer(my_ssh_session,0,textToSend.toLocal8Bit());
+                    x2goDebug << "SEND Input to SERVER";
+                    textToSend.replace("\n", "");
+                    ssh_userauth_kbdint_setanswer(my_ssh_session, 0, textToSend.toLocal8Bit());
                     break;
                 }
-                if(interrupt)
+                if (interrupt)
                 {
-                    x2goDebug<<"Keyboard authentication failed";
-//         QString err=ssh_get_error ( my_ssh_session );
-                    authErrors<<"NO_ERROR";
+                    x2goDebug << "Keyboard authentication failed";
+                    //         QString err=ssh_get_error ( my_ssh_session );
+                    authErrors << "NO_ERROR";
                     emit finishInteraction(this);
 
                     return false;
@@ -1041,159 +1031,163 @@ bool SshMasterConnection::userAuthKeyboardInteractive(QString prompt)
             }
         }
 
-        rez=ssh_userauth_kbdint(my_ssh_session, NULL, NULL);
-
+        rez = ssh_userauth_kbdint(my_ssh_session, NULL, NULL);
     }
-    if(rez==SSH_AUTH_SUCCESS)
+    if (rez == SSH_AUTH_SUCCESS)
     {
-        x2goDebug<<"Keyboard authentication successful";
+        x2goDebug << "Keyboard authentication successful";
         emit finishInteraction(this);
         return true;
     }
-    if(rez==SSH_AUTH_DENIED)
+    if (rez == SSH_AUTH_DENIED)
     {
-        x2goDebug<<"Keyboard authentication failed";
-        QString err=ssh_get_error ( my_ssh_session );
-        if(instruction.length()>0)
+        x2goDebug << "Keyboard authentication failed";
+        QString err = ssh_get_error(my_ssh_session);
+        if (instruction.length() > 0)
         {
-            authErrors<<instruction;
+            authErrors << instruction;
         }
-        authErrors<<err;
+        authErrors << err;
         emit finishInteraction(this);
 
         return false;
     }
 
-    QString err=ssh_get_error ( my_ssh_session );
-    authErrors<<err;
+    QString err = ssh_get_error(my_ssh_session);
+    authErrors << err;
 
     return false;
-
 }
 
-
-
 bool SshMasterConnection::userChallengeAuth()
 {
-    int rez=ssh_userauth_kbdint(my_ssh_session, NULL, NULL);
+    int rez = ssh_userauth_kbdint(my_ssh_session, NULL, NULL);
     int prompts;
 
-    switch( rez)
+    switch (rez)
     {
     case SSH_AUTH_INFO:
-        prompts=ssh_userauth_kbdint_getnprompts(my_ssh_session);
-        x2goDebug<<"Have prompts: "<<prompts<<endl;
-        if(prompts)
+        prompts = ssh_userauth_kbdint_getnprompts(my_ssh_session);
+        x2goDebug << "Have prompts: " << prompts << endl;
+        if (prompts)
         {
-            const char *prompt= ssh_userauth_kbdint_getprompt(my_ssh_session,0,NULL);
-            x2goDebug<<"Prompt[0]: |"<<prompt<<"|"<<endl;
-            QString pr=prompt;
-            if(pr.startsWith ("Password:"))
+            const char *prompt = ssh_userauth_kbdint_getprompt(my_ssh_session, 0, NULL);
+            x2goDebug << "Prompt[0]: |" << prompt << "|" << endl;
+            QString pr = prompt;
+            if (pr.startsWith("Password:"))
             {
-                x2goDebug<<"Password request"<<endl;
-                ssh_userauth_kbdint_setanswer(my_ssh_session,0,pass.toLatin1());
+                x2goDebug << "Password request" << endl;
+                ssh_userauth_kbdint_setanswer(my_ssh_session, 0, pass.toLatin1());
                 return userChallengeAuth();
             }
 
             bool has_challenge_auth_code_prompt = false;
             bool need_to_display_auth_code_prompt = false;
-            const std::size_t challenge_auth_code_prompts_size = (sizeof (challenge_auth_code_prompts_)/sizeof (*challenge_auth_code_prompts_));
+            const std::size_t challenge_auth_code_prompts_size = (sizeof(challenge_auth_code_prompts_) / sizeof(*challenge_auth_code_prompts_));
 
-            if (pr.contains ("challenge", Qt::CaseInsensitive)) {
-              x2goDebug << "prompt contains 'challenge': " << pr << endl;
-              has_challenge_auth_code_prompt = true;
-              need_to_display_auth_code_prompt = true;
+            if (pr.contains("challenge", Qt::CaseInsensitive))
+            {
+                x2goDebug << "prompt contains 'challenge': " << pr << endl;
+                has_challenge_auth_code_prompt = true;
+                need_to_display_auth_code_prompt = true;
             }
-            else {
-              for (std::size_t i = 0; i < challenge_auth_code_prompts_size; ++i) {
-                x2goDebug << "Checking against known prompt #" << i << ": " << challenge_auth_code_prompts_[i] << endl;
+            else
+            {
+                for (std::size_t i = 0; i < challenge_auth_code_prompts_size; ++i)
+                {
+                    x2goDebug << "Checking against known prompt #" << i << ": " << challenge_auth_code_prompts_[i] << endl;
 
-                /* Ignore "garbage" at the start of the string, but require at least one line to start with a known prompt. */
-                QStringList tmp_str_list = pr.split ("\n", QString::SkipEmptyParts);
+                    /* Ignore "garbage" at the start of the string, but require at least one line to start with a known prompt. */
+                    QStringList tmp_str_list = pr.split("\n", QString::SkipEmptyParts);
 
-                for (QStringList::const_iterator cit = tmp_str_list.constBegin (); cit != tmp_str_list.constEnd (); ++cit) {
-                  if ((*cit).startsWith (challenge_auth_code_prompts_[i])) {
-                    has_challenge_auth_code_prompt = true;
-                    break;
-                  }
-                }
+                    for (QStringList::const_iterator cit = tmp_str_list.constBegin(); cit != tmp_str_list.constEnd(); ++cit)
+                    {
+                        if ((*cit).startsWith(challenge_auth_code_prompts_[i]))
+                        {
+                            has_challenge_auth_code_prompt = true;
+                            break;
+                        }
+                    }
 
-                /* Skip over other challenge auth code prompts if we found one already. */
-                if (has_challenge_auth_code_prompt) {
-                  break;
+                    /* Skip over other challenge auth code prompts if we found one already. */
+                    if (has_challenge_auth_code_prompt)
+                    {
+                        break;
+                    }
                 }
-              }
             }
 
-            if (has_challenge_auth_code_prompt) {
-                x2goDebug<<"Verification code request"<<endl;
+            if (has_challenge_auth_code_prompt)
+            {
+                x2goDebug << "Verification code request" << endl;
 
-                challengeAuthPasswordAccepted=true;
-                if(challengeAuthVerificationCode == QString::null)
+                challengeAuthPasswordAccepted = true;
+                if (challengeAuthVerificationCode == QString::null)
                 {
-                    keyPhraseReady=false;
-                    if (need_to_display_auth_code_prompt) {
-                      emit needChallengeResponse(this, pr);
-                    } else {
-                      emit needPassPhrase(this, PASSPHRASE_CHALLENGE);
+                    keyPhraseReady = false;
+                    if (need_to_display_auth_code_prompt)
+                    {
+                        emit needChallengeResponse(this, pr);
                     }
-                    for(;;)
+                    else
                     {
-                        bool ready=false;
+                        emit needPassPhrase(this, PASSPHRASE_CHALLENGE);
+                    }
+                    for (;;)
+                    {
+                        bool ready = false;
                         this->usleep(200);
                         keyPhraseMutex.lock();
-                        if(keyPhraseReady)
-                            ready=true;
+                        if (keyPhraseReady)
+                            ready = true;
                         keyPhraseMutex.unlock();
-                        if(ready)
+                        if (ready)
                             break;
                     }
-                    challengeAuthVerificationCode=keyPhrase;
-                    if(challengeAuthVerificationCode==QString::null)
+                    challengeAuthVerificationCode = keyPhrase;
+                    if (challengeAuthVerificationCode == QString::null)
                     {
-                        authErrors<<tr("Authentication failed.");
+                        authErrors << tr("Authentication failed.");
                         return false;
                     }
                 }
-                ssh_userauth_kbdint_setanswer(my_ssh_session,0,challengeAuthVerificationCode.toLatin1());
+                ssh_userauth_kbdint_setanswer(my_ssh_session, 0, challengeAuthVerificationCode.toLatin1());
                 return userChallengeAuth();
             }
             else
-	    {
-	        return userAuthKeyboardInteractive(prompt);
-	    }
+            {
+                return userAuthKeyboardInteractive(prompt);
+            }
         }
         else
         {
             return userChallengeAuth();
         }
     case SSH_AUTH_SUCCESS:
-        x2goDebug<<"Challenge authentication OK."<<endl;
+        x2goDebug << "Challenge authentication OK." << endl;
         return true;
     case SSH_AUTH_DENIED:
-        if(!challengeAuthPasswordAccepted )
+        if (!challengeAuthPasswordAccepted)
         {
-            QString err=ssh_get_error ( my_ssh_session );
-            authErrors<<err;
+            QString err = ssh_get_error(my_ssh_session);
+            authErrors << err;
             return false;
         }
         else
         {
-            challengeAuthVerificationCode=QString::null;
+            challengeAuthVerificationCode = QString::null;
             //try with another verification code
             return userChallengeAuth();
         }
     default:
-        QString err=ssh_get_error ( my_ssh_session );
-        authErrors<<err;
+        QString err = ssh_get_error(my_ssh_session);
+        authErrors << err;
 
         return false;
     }
     return false;
-
 }
 
-
 bool SshMasterConnection::userAuthWithPass()
 {
     bool ret = false;
@@ -1203,61 +1197,71 @@ bool SshMasterConnection::userAuthWithPass()
 
     int method = ssh_userauth_list(my_ssh_session, NULL);
 
-    if (method & SSH_AUTH_METHOD_INTERACTIVE) {
+    if (method & SSH_AUTH_METHOD_INTERACTIVE)
+    {
         x2goDebug << "Challenge authentication requested." << endl;
 
         challengeAuthPasswordAccepted = false;
-        ret = userChallengeAuth ();
+        ret = userChallengeAuth();
 
-        if (!ret) {
+        if (!ret)
+        {
             x2goDebug << "Challenge authentication failed." << endl;
         }
     }
 
-    if (!ret) {
+    if (!ret)
+    {
         x2goDebug << "Trying password mechanism if available." << endl;
     }
 
-    if ((!ret) && (method & SSH_AUTH_METHOD_PASSWORD)) {
+    if ((!ret) && (method & SSH_AUTH_METHOD_PASSWORD))
+    {
         x2goDebug << "Password mechanism available. Continuing." << endl;
 
         QString auth_password = pass;
 
-        if (auth_password.isEmpty ()) {
+        if (auth_password.isEmpty())
+        {
             keyPhraseReady = false;
-            emit needPassPhrase (this, PASSPHRASE_PASSWORD);
+            emit needPassPhrase(this, PASSPHRASE_PASSWORD);
 
-            for (bool ready = false; !ready;) {
-                this->usleep (200);
+            for (bool ready = false; !ready;)
+            {
+                this->usleep(200);
 
-                keyPhraseMutex.lock ();
+                keyPhraseMutex.lock();
                 ready = keyPhraseReady;
-                keyPhraseMutex.unlock ();
+                keyPhraseMutex.unlock();
             }
 
-            if (keyPhrase.isNull ()) {
+            if (keyPhrase.isNull())
+            {
                 authErrors << "No password provided.";
                 return (ret);
             }
-            else {
+            else
+            {
                 auth_password = keyPhrase;
             }
         }
-        int rc = ssh_userauth_password (my_ssh_session, NULL, auth_password.toLatin1 ());
-        if ( rc != SSH_AUTH_SUCCESS )
+        int rc = ssh_userauth_password(my_ssh_session, NULL, auth_password.toLatin1());
+        if (rc != SSH_AUTH_SUCCESS)
         {
-            QString err=ssh_get_error ( my_ssh_session );
-            authErrors<<err;
+            QString err = ssh_get_error(my_ssh_session);
+            authErrors << err;
             x2goDebug << "Password authentication failed: " << err << endl;
         }
-        else {
+        else
+        {
             ret = true;
         }
     }
 
-    if ((!ret) && (method & ~SSH_AUTH_METHOD_PASSWORD)) {
+    if ((!ret) && (method & ~SSH_AUTH_METHOD_PASSWORD))
+    {
         /* In case password auth is disabled, make sure the error message is not empty. */
-        QString err = ssh_get_error (my_ssh_session);
+        QString err = ssh_get_error(my_ssh_session);
         authErrors << err;
         x2goDebug << "Password authentication not available: " << err << endl;
     }
@@ -1265,45 +1269,45 @@ bool SshMasterConnection::userAuthWithPass()
     return (ret);
 }
 
-
 bool SshMasterConnection::userAuthAuto()
 {
-    int rc = ssh_userauth_autopubkey ( my_ssh_session, "" );
-    int i=0;
-    while(rc != SSH_AUTH_SUCCESS)
+    int rc = ssh_userauth_autopubkey(my_ssh_session, "");
+    int i = 0;
+    while (rc != SSH_AUTH_SUCCESS)
     {
-        if (SSH_AUTH_DENIED == rc) {
-          /* No need to continue, all keys have been rejected by the server. */
-          break;
+        if (SSH_AUTH_DENIED == rc)
+        {
+            /* No need to continue, all keys have been rejected by the server. */
+            break;
         }
 
         /* This section should only be executed if rc is SSH_AUTH_ERROR. */
-        keyPhraseReady=false;
+        keyPhraseReady = false;
         emit needPassPhrase(this, PASSPHRASE_PRIVKEY);
-        for(;;)
+        for (;;)
         {
-            bool ready=false;
+            bool ready = false;
             this->usleep(200);
             keyPhraseMutex.lock();
-            if(keyPhraseReady)
-                ready=true;
+            if (keyPhraseReady)
+                ready = true;
             keyPhraseMutex.unlock();
-            if(ready)
+            if (ready)
                 break;
         }
-        if(keyPhrase==QString::null)
+        if (keyPhrase == QString::null)
             break;
-        rc = ssh_userauth_autopubkey ( my_ssh_session, keyPhrase.toLatin1() );
-        if(i++==2)
+        rc = ssh_userauth_autopubkey(my_ssh_session, keyPhrase.toLatin1());
+        if (i++ == 2)
         {
             break;
         }
     }
 
-    if ( rc != SSH_AUTH_SUCCESS )
+    if (rc != SSH_AUTH_SUCCESS)
     {
-        QString err=ssh_get_error ( my_ssh_session );
-        authErrors<<err;
+        QString err = ssh_get_error(my_ssh_session);
+        authErrors << err;
         x2goDebug << "userAuthAuto failed:" << err << " (code " << rc << ")" << endl;
         return false;
     }
@@ -1313,37 +1317,36 @@ bool SshMasterConnection::userAuthAuto()
 void SshMasterConnection::setKeyPhrase(QString phrase)
 {
     keyPhraseMutex.lock();
-    keyPhrase=phrase;
-    keyPhraseReady=true;
+    keyPhrase = phrase;
+    keyPhraseReady = true;
     keyPhraseMutex.unlock();
 }
 
-
 bool SshMasterConnection::userAuthWithKey()
 {
-    x2goDebug<<"Trying to authenticate user with private key.";
-    QString keyName=key;
-    bool autoRemove=false;
-    if ( key.indexOf ( "PRIVATE KEY" ) !=-1 )
+    x2goDebug << "Trying to authenticate user with private key.";
+    QString keyName = key;
+    bool autoRemove = false;
+    if (key.indexOf("PRIVATE KEY") != -1)
     {
         QDir dr;
-        QString keyPath=mainWnd->getHomeDirectory() +"/.x2go/ssh/gen";
-        dr.mkpath ( keyPath );
-        QTemporaryFile fl ( keyPath+"/key" );
+        QString keyPath = mainWnd->getHomeDirectory() + "/.x2go/ssh/gen";
+        dr.mkpath(keyPath);
+        QTemporaryFile fl(keyPath + "/key");
         fl.open();
-        keyName=fl.fileName();
-        fl.setAutoRemove ( false );
-        QTextStream out ( &fl );
-        out<<key;
+        keyName = fl.fileName();
+        fl.setAutoRemove(false);
+        QTextStream out(&fl);
+        out << key;
         fl.close();
-        autoRemove=true;
-        x2goDebug<<"Temporarily saved key in "<<keyName;
+        autoRemove = true;
+        x2goDebug << "Temporarily saved key in " << keyName;
     }
 
-    QByteArray tmp_ba = keyName.toLocal8Bit ();
+    QByteArray tmp_ba = keyName.toLocal8Bit();
 
-#if LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 6, 0)
-    ssh_key priv_key = { 0 };
+#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 6, 0)
+    ssh_key priv_key = {0};
 
     /*
      * Passing an empty string as a passphrase parameter is a workaround for inconsistent
@@ -1356,166 +1359,175 @@ bool SshMasterConnection::userAuthWithKey()
      * passphrase on a terminal (and the client not reacting to any input while this
      * happens), so work around this inconsistency by providing an empty passphrase.
      */
-    int rc = ssh_pki_import_privkey_file (tmp_ba.data (), "", NULL, NULL, &priv_key);
+    int rc = ssh_pki_import_privkey_file(tmp_ba.data(), "", NULL, NULL, &priv_key);
 
-    if (SSH_EOF == rc) {
+    if (SSH_EOF == rc)
+    {
         x2goDebug << "Failed to get private key from " << keyName << "; file does not exist.";
 
-        ssh_key_free (priv_key);
+        ssh_key_free(priv_key);
 
         return (false);
     }
-    else if (SSH_OK != rc) {
+    else if (SSH_OK != rc)
+    {
         x2goDebug << "Failed to get private key from " << keyName << "; trying to query passphrase.";
 
-        ssh_key_free (priv_key);
+        ssh_key_free(priv_key);
         priv_key = NULL;
     }
 #else
     /* This is TOCTU, but forced upon us by libssh's legacy function. */
     {
-      QFile tmp_file (keyName);
-      if (tmp_file.open (QIODevice::ReadOnly)) {
-        tmp_file.close ();
-      }
-      else {
-        /* Don't pass invalid files to privatekey_from_file () - it crashes in this case. */
-        return (false);
-      }
+        QFile tmp_file(keyName);
+        if (tmp_file.open(QIODevice::ReadOnly))
+        {
+            tmp_file.close();
+        }
+        else
+        {
+            /* Don't pass invalid files to privatekey_from_file () - it crashes in this case. */
+            return (false);
+        }
     }
-    ssh_private_key priv_key = privatekey_from_file (my_ssh_session, tmp_ba.data (), 0, NULL);
+    ssh_private_key priv_key = privatekey_from_file(my_ssh_session, tmp_ba.data(), 0, NULL);
 #endif
 
-    int i=0;
-#if LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 6, 0)
+    int i = 0;
+#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 6, 0)
     while (SSH_OK != rc)
 #else
     while (!priv_key)
 #endif
     {
-        keyPhraseReady=false;
+        keyPhraseReady = false;
         emit needPassPhrase(this, PASSPHRASE_PRIVKEY);
-        for(;;)
+        for (;;)
         {
-            bool ready=false;
+            bool ready = false;
             this->usleep(200);
             keyPhraseMutex.lock();
-            if(keyPhraseReady)
-                ready=true;
+            if (keyPhraseReady)
+                ready = true;
             keyPhraseMutex.unlock();
-            if(ready)
+            if (ready)
                 break;
         }
-        if(keyPhrase==QString::null)
+        if (keyPhrase == QString::null)
             break;
 
-        QByteArray tmp_ba_passphrase = keyPhrase.toLocal8Bit ();
+        QByteArray tmp_ba_passphrase = keyPhrase.toLocal8Bit();
 
-#if LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 6, 0)
-        rc = ssh_pki_import_privkey_file (tmp_ba.data (), tmp_ba_passphrase.data (), NULL, NULL, &priv_key);
+#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 6, 0)
+        rc = ssh_pki_import_privkey_file(tmp_ba.data(), tmp_ba_passphrase.data(), NULL, NULL, &priv_key);
 
-        if (SSH_OK != rc) {
-            ssh_key_free (priv_key);
+        if (SSH_OK != rc)
+        {
+            ssh_key_free(priv_key);
             priv_key = NULL;
         }
 #else
-        priv_key = privatekey_from_file (my_ssh_session, tmp_ba.data (), 0, tmp_ba_passphrase.data ());
+        priv_key = privatekey_from_file(my_ssh_session, tmp_ba.data(), 0, tmp_ba_passphrase.data());
 #endif
 
-        if(i++==2)
+        if (i++ == 2)
         {
             break;
         }
     }
-#if LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 6, 0)
+#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 6, 0)
     if (SSH_OK != rc)
 #else
     if (!priv_key)
 #endif
     {
-        x2goDebug<<"Failed to get private key from "<<keyName;
-        if ( autoRemove )
-            QFile::remove ( keyName );
+        x2goDebug << "Failed to get private key from " << keyName;
+        if (autoRemove)
+            QFile::remove(keyName);
         return false;
     }
 
-#if LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 6, 0)
-    ssh_key pub_key = { 0 };
+#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 6, 0)
+    ssh_key pub_key = {0};
 
-    rc = ssh_pki_export_privkey_to_pubkey (priv_key, &pub_key);
+    rc = ssh_pki_export_privkey_to_pubkey(priv_key, &pub_key);
 #else
-    ssh_public_key pub_key = publickey_from_privatekey (priv_key);
+    ssh_public_key pub_key = publickey_from_privatekey(priv_key);
 #endif
 
-#if LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 6, 0)
+#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 6, 0)
     if (SSH_OK != rc)
 #else
     if (!pub_key)
 #endif
     {
-        x2goDebug<<"Failed to get public key from private key.";
-#if LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 6, 0)
-        ssh_key_free (priv_key);
+        x2goDebug << "Failed to get public key from private key.";
+#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 6, 0)
+        ssh_key_free(priv_key);
         priv_key = NULL;
 
-        ssh_key_free (pub_key);
+        ssh_key_free(pub_key);
         pub_key = NULL;
 #else
         privatekey_free(priv_key);
 #endif
-        if ( autoRemove )
-            QFile::remove ( keyName );
+        if (autoRemove)
+            QFile::remove(keyName);
         return false;
     }
 
-#if LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 6, 0)
-    do {
-        rc = ssh_userauth_try_publickey (my_ssh_session, NULL, pub_key);
+#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 6, 0)
+    do
+    {
+        rc = ssh_userauth_try_publickey(my_ssh_session, NULL, pub_key);
     } while (SSH_AUTH_AGAIN == rc);
 
-    ssh_key_free (pub_key);
+    ssh_key_free(pub_key);
     pub_key = NULL;
 
     /* FIXME: handle SSH_AUTH_PARTIAL correctly! */
-    if (SSH_AUTH_SUCCESS != rc) {
+    if (SSH_AUTH_SUCCESS != rc)
+    {
         x2goDebug << "Unable to authenticate with public key.";
 
-        ssh_key_free (priv_key);
+        ssh_key_free(priv_key);
         priv_key = NULL;
 
-        if (autoRemove) {
-            QFile::remove (keyName);
+        if (autoRemove)
+        {
+            QFile::remove(keyName);
         }
 
         return (false);
     }
 
-    do {
-        rc = ssh_userauth_publickey (my_ssh_session, NULL, priv_key);
+    do
+    {
+        rc = ssh_userauth_publickey(my_ssh_session, NULL, priv_key);
     } while (SSH_AUTH_AGAIN == rc);
 
-    ssh_key_free (priv_key);
+    ssh_key_free(priv_key);
     priv_key = NULL;
 #else
-    ssh_string pubkeyStr=publickey_to_string(pub_key);
+    ssh_string pubkeyStr = publickey_to_string(pub_key);
     publickey_free(pub_key);
-    int rc=ssh_userauth_pubkey(my_ssh_session, NULL, pubkeyStr, priv_key);
+    int rc = ssh_userauth_pubkey(my_ssh_session, NULL, pubkeyStr, priv_key);
     privatekey_free(priv_key);
     ssh_string_free(pubkeyStr);
 #endif
 
-    x2goDebug<<"Authenticating with key: "<<rc<<endl;
+    x2goDebug << "Authenticating with key: " << rc << endl;
 
-    if ( autoRemove )
-        QFile::remove ( keyName );
+    if (autoRemove)
+        QFile::remove(keyName);
 
     /* FIXME: handle SSH_AUTH_PARTIAL correctly! */
-    if ( rc != SSH_AUTH_SUCCESS )
+    if (rc != SSH_AUTH_SUCCESS)
     {
-        QString err=ssh_get_error ( my_ssh_session );
-        authErrors<<err;
+        QString err = ssh_get_error(my_ssh_session);
+        authErrors << err;
 
-        x2goDebug<<"userAuthWithKey failed:" <<err<<endl;
+        x2goDebug << "userAuthWithKey failed:" << err << endl;
 
         return false;
     }
@@ -1556,14 +1568,17 @@ bool SshMasterConnection::userAuthKrb()
     local_cmd = "ssh";
 
     /* Kerberos options. */
-    local_args << "-o" << "GSSApiAuthentication=yes"
-               << "-o" << "PasswordAuthentication=no"
-               << "-o" << "PubkeyAuthentication=no";
+    local_args << "-o"
+               << "GSSApiAuthentication=yes"
+               << "-o"
+               << "PasswordAuthentication=no"
+               << "-o"
+               << "PubkeyAuthentication=no";
 
     /* Port option. Must be the last one added! */
     local_args << "-p";
 #endif
-    local_args << QString::number (port)
+    local_args << QString::number(port)
                << "-l" << user
                << host;
 
@@ -1576,125 +1591,123 @@ bool SshMasterConnection::userAuthKrb()
      */
     local_args << shcmd;
 
-    x2goDebug << "Starting ssh:" << local_cmd << " " << local_args.join (" ") << endl;
-    ssh.start (local_cmd, local_args);
-
+    x2goDebug << "Starting ssh:" << local_cmd << " " << local_args.join(" ") << endl;
+    ssh.start(local_cmd, local_args);
 
     if (!ssh.waitForStarted(5000))
     {
-        sshProcErrString=ssh.errorString();
-        authErrors<<sshProcErrString;
-        x2goDebug<<"SSH start failed:" <<sshProcErrString<<endl;
+        sshProcErrString = ssh.errorString();
+        authErrors << sshProcErrString;
+        x2goDebug << "SSH start failed:" << sshProcErrString << endl;
         return false;
     }
     if (!ssh.waitForFinished(20000))
     {
-        sshProcErrString=ssh.errorString();
-        authErrors<<tr("Failed to start SSH client. Please check your installation and GSSApi configuration.");
-        authErrors<<sshProcErrString;
-        x2goDebug<<"SSH did not finish:" <<sshProcErrString<<endl;
+        sshProcErrString = ssh.errorString();
+        authErrors << tr("Failed to start SSH client. Please check your installation and GSSApi configuration.");
+        authErrors << sshProcErrString;
+        x2goDebug << "SSH did not finish:" << sshProcErrString << endl;
 
         return false;
     }
-    QString outp=ssh.readAllStandardOutput();
-    QString err=ssh.readAllStandardError();
-    x2goDebug<<"SSH exited.";
-    x2goDebug<<"stdout: "<<outp<<endl;
-    x2goDebug<<"stderr: "<<err<<endl;
-    x2goDebug<<"Exit code: "<<ssh.exitCode()<<"; status: "<<ssh.exitStatus()<<endl;
-
-    QString begin_marker = "X2GODATABEGIN:"+uuidStr+"\n";
-    QString end_marker = "X2GODATAEND:"+uuidStr+"\n";
-    int output_begin=outp.indexOf(begin_marker) + begin_marker.length();
-    int output_end=outp.indexOf(end_marker);
-    outp = outp.mid(output_begin, output_end-output_begin);
-    outp.replace("\n","");
-
-    if (ssh.exitCode() == 0 && ssh.exitStatus() == 0 && outp== user)
+    QString outp = ssh.readAllStandardOutput();
+    QString err = ssh.readAllStandardError();
+    x2goDebug << "SSH exited.";
+    x2goDebug << "stdout: " << outp << endl;
+    x2goDebug << "stderr: " << err << endl;
+    x2goDebug << "Exit code: " << ssh.exitCode() << "; status: " << ssh.exitStatus() << endl;
+
+    QString begin_marker = "X2GODATABEGIN:" + uuidStr + "\n";
+    QString end_marker = "X2GODATAEND:" + uuidStr + "\n";
+    int output_begin = outp.indexOf(begin_marker) + begin_marker.length();
+    int output_end = outp.indexOf(end_marker);
+    outp = outp.mid(output_begin, output_end - output_begin);
+    outp.replace("\n", "");
+
+    if (ssh.exitCode() == 0 && ssh.exitStatus() == 0 && outp == user)
         return true;
-    authErrors<<tr("Check your GSSApi configuration or choose another authentication method.");
+    authErrors << tr("Check your GSSApi configuration or choose another authentication method.");
     return false;
 }
 
-
 void SshMasterConnection::interactionTextEnter(QString text)
 {
-    if(sshProxy && ! sshProxyReady)
+    if (sshProxy && !sshProxyReady)
     {
         sshProxy->interactionTextEnter(text);
-	return;
+        return;
     }
     interactionInputMutex.lock();
-    interactionInputText=text;
+    interactionInputText = text;
     interactionInputMutex.unlock();
 }
 
 void SshMasterConnection::interactionInterruptSlot()
 {
-    if(sshProxy && ! sshProxyReady)
+    if (sshProxy && !sshProxyReady)
     {
         sshProxy->interactionInterruptSlot();
-	return;
+        return;
     }
     interactionInputMutex.lock();
-    interactionInterrupt=true;
+    interactionInterrupt = true;
     interactionInputMutex.unlock();
 }
 
 bool SshMasterConnection::checkLogin()
 {
-    interactionInterrupt=false;
-    interactionInputText=QString::null;
+    interactionInterrupt = false;
+    interactionInputText = QString::null;
 
+    ssh_channel channel = ssh_channel_new(my_ssh_session);
 
-    ssh_channel channel = ssh_channel_new ( my_ssh_session );
-
-    if (!channel) {
-        QString err = ssh_get_error (my_ssh_session);
-        QString error_msg = tr ("%1 failed.").arg ("ssh_channel_new");
+    if (!channel)
+    {
+        QString err = ssh_get_error(my_ssh_session);
+        QString error_msg = tr("%1 failed.").arg("ssh_channel_new");
 
-        x2goDebug << error_msg.left (error_msg.size () - 1) << ": " << err << endl;
+        x2goDebug << error_msg.left(error_msg.size() - 1) << ": " << err << endl;
         return false;
     }
-    if ( ssh_channel_open_session ( channel ) !=SSH_OK )
+    if (ssh_channel_open_session(channel) != SSH_OK)
     {
-        QString err=ssh_get_error ( my_ssh_session );
-        QString errorMsg=tr ( "%1 failed." ).arg ("ssh_channel_open_session");
-        x2goDebug<<errorMsg.left (errorMsg.size () - 1)<<": "<<err<<endl;
+        QString err = ssh_get_error(my_ssh_session);
+        QString errorMsg = tr("%1 failed.").arg("ssh_channel_open_session");
+        x2goDebug << errorMsg.left(errorMsg.size() - 1) << ": " << err << endl;
         ssh_channel_free(channel);
         return false;
     }
-    if (ssh_channel_request_pty(channel)!=SSH_OK)
+    if (ssh_channel_request_pty(channel) != SSH_OK)
     {
-        QString err=ssh_get_error ( my_ssh_session );
-        QString errorMsg=tr ( "%1 failed." ).arg ("ssh_channel_request_pty");
-        x2goDebug<<errorMsg.left (errorMsg.size () - 1)<<": "<<err<<endl;
+        QString err = ssh_get_error(my_ssh_session);
+        QString errorMsg = tr("%1 failed.").arg("ssh_channel_request_pty");
+        x2goDebug << errorMsg.left(errorMsg.size() - 1) << ": " << err << endl;
         ssh_channel_free(channel);
         return false;
     }
-    if(ssh_channel_change_pty_size(channel, 80, 24)!=SSH_OK)
+    if (ssh_channel_change_pty_size(channel, 80, 24) != SSH_OK)
     {
-        QString err=ssh_get_error ( my_ssh_session );
-        QString errorMsg=tr ( "%1 failed." ).arg ("ssh_channel_change_pty_size");
-        x2goDebug<<errorMsg.left (errorMsg.size () - 1)<<": "<<err<<endl;
+        QString err = ssh_get_error(my_ssh_session);
+        QString errorMsg = tr("%1 failed.").arg("ssh_channel_change_pty_size");
+        x2goDebug << errorMsg.left(errorMsg.size() - 1) << ": " << err << endl;
         ssh_channel_free(channel);
         return false;
     }
-    if ( ssh_channel_request_exec ( channel, "echo \"LOGIN OK\"" ) != SSH_OK )
+    if (ssh_channel_request_exec(channel, "echo \"LOGIN OK\"") != SSH_OK)
     {
-        QString err=ssh_get_error ( my_ssh_session );
-        QString errorMsg=tr ( "%1 failed." ).arg ("ssh_channel_request_exec");
-        x2goDebug<<errorMsg.left (errorMsg.size () - 1)<<": "<<err<<endl;
+        QString err = ssh_get_error(my_ssh_session);
+        QString errorMsg = tr("%1 failed.").arg("ssh_channel_request_exec");
+        x2goDebug << errorMsg.left(errorMsg.size() - 1) << ": " << err << endl;
         ssh_channel_free(channel);
     }
     else
     {
-        char buffer[1024*512]; //512K buffer
-        bool hasInterraction=true;
-	bool interactionStarted=false;
-//         x2goDebug<<"CHECK LOGIN channel created."<<endl;
+        char buffer[1024 * 512]; //512K buffer
+        bool hasInterraction = true;
+        bool interactionStarted = false;
+        //         x2goDebug<<"CHECK LOGIN channel created."<<endl;
         while (ssh_channel_is_open(channel) &&
-                !ssh_channel_is_eof(channel))
+               !ssh_channel_is_eof(channel))
         {
             int nbytes = ssh_channel_read_nonblocking(channel, buffer, sizeof(buffer), 0);
             if (nbytes < 0)
@@ -1704,194 +1717,188 @@ bool SshMasterConnection::checkLogin()
             }
             if (nbytes > 0)
             {
-                QString inf=QByteArray ( buffer,nbytes );
-                x2goDebug<<"LOGIN CHECK:"<<inf;
-                if(inf.indexOf("LOGIN OK")!=-1)
+                QString inf = QByteArray(buffer, nbytes);
+                x2goDebug << "LOGIN CHECK:" << inf;
+                if (inf.indexOf("LOGIN OK") != -1)
                 {
-		    x2goDebug<<"don't have interaction";
-                    hasInterraction=false;
-		    break;
+                    x2goDebug << "don't have interaction";
+                    hasInterraction = false;
+                    break;
                 }
                 else
-		{
-		  if(!interactionStarted)
-		  {
-		     interactionStarted=true;
-		     emit startInteraction(this, inf);
-		  }
-		  else
-		     emit updateInteraction(this,inf);
-		}
+                {
+                    if (!interactionStarted)
+                    {
+                        interactionStarted = true;
+                        emit startInteraction(this, inf);
+                    }
+                    else
+                        emit updateInteraction(this, inf);
+                }
             }
             bool interrupt;
             interactionInputMutex.lock();
-	    interrupt=interactionInterrupt;
-	    QString textToSend=interactionInputText;
-	    interactionInputText=QString::null;
-	    interactionInputMutex.unlock();
-	    if(textToSend.length()>0)
-	    {
-// 	        x2goDebug<<"SEND Input to SERVER";
-	        ssh_channel_write(channel, textToSend.toLocal8Bit().constData(), textToSend.length());
-	    }
-	    if(interrupt)
-	    {
-	        break;
-	    }
+            interrupt = interactionInterrupt;
+            QString textToSend = interactionInputText;
+            interactionInputText = QString::null;
+            interactionInputMutex.unlock();
+            if (textToSend.length() > 0)
+            {
+                // 	        x2goDebug<<"SEND Input to SERVER";
+                ssh_channel_write(channel, textToSend.toLocal8Bit().constData(), textToSend.length());
+            }
+            if (interrupt)
+            {
+                break;
+            }
             this->usleep(30);
         }
 
-        x2goDebug<<"LOOP FINISHED";
-	bool retVal=false;
-        if(!hasInterraction)
-	{
-	    x2goDebug<<"No interaction needed, continue session";
-            retVal=true;
-	}
-	else
+        x2goDebug << "LOOP FINISHED";
+        bool retVal = false;
+        if (!hasInterraction)
         {
-            sshProcErrString=tr("Reconnect session");
-            x2goDebug<<"Reconnect session";
+            x2goDebug << "No interaction needed, continue session";
+            retVal = true;
+        }
+        else
+        {
+            sshProcErrString = tr("Reconnect session");
+            x2goDebug << "Reconnect session";
         }
         ssh_channel_close(channel);
         ssh_channel_send_eof(channel);
         ssh_channel_free(channel);
-	return retVal;
-
+        return retVal;
     }
     return false;
-
 }
 
 bool SshMasterConnection::userAuth()
 {
     if (kerberos)
         return userAuthKrb();
-    if ( autologin && key=="" )
-        if ( userAuthAuto() )
+    if (autologin && key == "")
+        if (userAuthAuto())
             return true;
-    if ( key!="" )
+    if (key != "")
     {
-        if ( userAuthWithKey() )
+        if (userAuthWithKey())
             return true;
     }
     return userAuthWithPass();
 }
 
-
-void SshMasterConnection::addChannelConnection ( SshProcess* creator, int sock, QString forwardHost, int forwardPort,
-        QString localHost, int localPort, void* channel )
+void SshMasterConnection::addChannelConnection(SshProcess *creator, int sock, QString forwardHost, int forwardPort,
+                                               QString localHost, int localPort, void *channel)
 {
     ChannelConnection con;
-    con.channel= ( ssh_channel ) channel;
-    con.sock=sock;
-    con.creator=creator;
-    con.forwardHost=forwardHost;
-    con.forwardPort=forwardPort;
-    con.localHost=localHost;
-    con.localPort=localPort;
+    con.channel = (ssh_channel)channel;
+    con.sock = sock;
+    con.creator = creator;
+    con.forwardHost = forwardHost;
+    con.forwardPort = forwardPort;
+    con.localHost = localHost;
+    con.localPort = localPort;
 
     channelConnectionsMutex.lock();
-    channelConnections<<con;
+    channelConnections << con;
     channelConnectionsMutex.unlock();
 }
 
-
-void SshMasterConnection::addChannelConnection ( SshProcess* creator, QString uuid, QString cmd )
+void SshMasterConnection::addChannelConnection(SshProcess *creator, QString uuid, QString cmd)
 {
 
     ChannelConnection con;
-    con.channel=NULL;
-    con.sock=-1;
-    con.creator=creator;
-    con.command=cmd;
-    con.uuid=uuid;
+    con.channel = NULL;
+    con.sock = -1;
+    con.creator = creator;
+    con.command = cmd;
+    con.uuid = uuid;
 
     x2goDebug << "Locking SSH channel connection MUTEX.";
     channelConnectionsMutex.lock();
     x2goDebug << "Passing new channel connection object to channelConnections.";
-    channelConnections<<con;
+    channelConnections << con;
     x2goDebug << "Unlocking SSH channel connection MUTEX.";
     channelConnectionsMutex.unlock();
 }
 
-
-void SshMasterConnection::addCopyRequest ( SshProcess* creator, QString src, QString dst )
+void SshMasterConnection::addCopyRequest(SshProcess *creator, QString src, QString dst)
 {
     CopyRequest req;
-    req.src=src;
-    req.dst=dst;
-    req.creator=creator;
+    req.src = src;
+    req.dst = dst;
+    req.creator = creator;
     copyRequestMutex.lock();
-    copyRequests<<req;
+    copyRequests << req;
     copyRequestMutex.unlock();
 }
 
-
 void SshMasterConnection::copy()
 {
 
-    for ( int i=copyRequests.size()-1; i>=0; --i )
+    for (int i = copyRequests.size() - 1; i >= 0; --i)
     {
-        QStringList lst=copyRequests[i].dst.split ( "/" );
-        QString dstFile=lst.last();
+        QStringList lst = copyRequests[i].dst.split("/");
+        QString dstFile = lst.last();
         lst.removeLast();
-        QString dstPath=lst.join ( "/" );
-        x2goDebug<<"SSH Master Connection copy - dst path:"<<dstPath<<" file:"<<dstFile<<endl;
-        ssh_scp scp=ssh_scp_new ( my_ssh_session, SSH_SCP_WRITE|SSH_SCP_RECURSIVE, dstPath.toLatin1() );
-        if ( scp == NULL )
+        QString dstPath = lst.join("/");
+        x2goDebug << "SSH Master Connection copy - dst path:" << dstPath << " file:" << dstFile << endl;
+        ssh_scp scp = ssh_scp_new(my_ssh_session, SSH_SCP_WRITE | SSH_SCP_RECURSIVE, dstPath.toLatin1());
+        if (scp == NULL)
         {
-            x2goDebug<<"Error allocating SCP session: "<< ssh_get_error ( my_ssh_session ) <<endl;
+            x2goDebug << "Error allocating SCP session: " << ssh_get_error(my_ssh_session) << endl;
             return;
         }
-        int rc = ssh_scp_init ( scp );
-        if ( rc != SSH_OK )
+        int rc = ssh_scp_init(scp);
+        if (rc != SSH_OK)
         {
-            x2goDebug<<"Error initializing SCP session: "<< ssh_get_error ( my_ssh_session ) <<endl;
-            ssh_scp_free ( scp );
+            x2goDebug << "Error initializing SCP session: " << ssh_get_error(my_ssh_session) << endl;
+            ssh_scp_free(scp);
             return;
         }
-        QFile file ( copyRequests[i].src );
-        if ( !file.open ( QIODevice::ReadOnly ) )
+        QFile file(copyRequests[i].src);
+        if (!file.open(QIODevice::ReadOnly))
         {
-            QString errMsg=tr ( "Cannot open file " ) +copyRequests[i].src;
-            emit copyErr ( copyRequests[i].creator, errMsg, "" );
-            copyRequests.removeAt ( i );
-            ssh_scp_close ( scp );
-            ssh_scp_free ( scp );
+            QString errMsg = tr("Cannot open file ") + copyRequests[i].src;
+            emit copyErr(copyRequests[i].creator, errMsg, "");
+            copyRequests.removeAt(i);
+            ssh_scp_close(scp);
+            ssh_scp_free(scp);
             continue;
         }
-        QByteArray arr=file.readAll();
+        QByteArray arr = file.readAll();
         file.close();
-        rc=ssh_scp_push_file ( scp,dstFile.toLatin1(),arr.size(), 0600 );
-        if ( rc != SSH_OK )
+        rc = ssh_scp_push_file(scp, dstFile.toLatin1(), arr.size(), 0600);
+        if (rc != SSH_OK)
         {
-            QString errMsg=tr ( "Cannot create remote file " ) +copyRequests[i].dst;
-            QString serr=ssh_get_error ( my_ssh_session );
-            x2goDebug<<errMsg<<" - "<<serr<<endl;
-            emit copyErr ( copyRequests[i].creator, errMsg, serr );
-            copyRequests.removeAt ( i );
-            ssh_scp_close ( scp );
-            ssh_scp_free ( scp );
+            QString errMsg = tr("Cannot create remote file ") + copyRequests[i].dst;
+            QString serr = ssh_get_error(my_ssh_session);
+            x2goDebug << errMsg << " - " << serr << endl;
+            emit copyErr(copyRequests[i].creator, errMsg, serr);
+            copyRequests.removeAt(i);
+            ssh_scp_close(scp);
+            ssh_scp_free(scp);
             continue;
         }
-        rc=ssh_scp_write ( scp,arr.data(),arr.size() );
-        if ( rc != SSH_OK )
+        rc = ssh_scp_write(scp, arr.data(), arr.size());
+        if (rc != SSH_OK)
         {
-            QString serr=ssh_get_error ( my_ssh_session );
-            QString errMsg=tr ( "Cannot write to remote file " ) +copyRequests[i].dst;
-            x2goDebug<<errMsg<<" - "<<serr<<endl;
-            emit copyErr ( copyRequests[i].creator, errMsg, serr );
-            copyRequests.removeAt ( i );
-            ssh_scp_close ( scp );
-            ssh_scp_free ( scp );
+            QString serr = ssh_get_error(my_ssh_session);
+            QString errMsg = tr("Cannot write to remote file ") + copyRequests[i].dst;
+            x2goDebug << errMsg << " - " << serr << endl;
+            emit copyErr(copyRequests[i].creator, errMsg, serr);
+            copyRequests.removeAt(i);
+            ssh_scp_close(scp);
+            ssh_scp_free(scp);
             continue;
         }
-        emit copyOk ( copyRequests[i].creator );
-        x2goDebug<<"scp ok: "<<copyRequests[i].src<<" -> "<<user<<"@"<<host<<":"<<copyRequests[i].dst<<endl;
-        copyRequests.removeAt ( i );
-        ssh_scp_close ( scp );
-        ssh_scp_free ( scp );
+        emit copyOk(copyRequests[i].creator);
+        x2goDebug << "scp ok: " << copyRequests[i].src << " -> " << user << "@" << host << ":" << copyRequests[i].dst << endl;
+        copyRequests.removeAt(i);
+        ssh_scp_close(scp);
+        ssh_scp_free(scp);
     }
 }
 
@@ -1900,47 +1907,47 @@ void SshMasterConnection::channelLoop()
     forever
     {
         disconnectFlagMutex.lock();
-        bool disconnect=disconnectSessionFlag;
+        bool disconnect = disconnectSessionFlag;
         disconnectFlagMutex.unlock();
 
-        if ( disconnect )
+        if (disconnect)
         {
-            x2goDebug<<"Disconnecting ..."<<endl;
+            x2goDebug << "Disconnecting ..." << endl;
 
-            if (useproxy && proxytype==PROXYSSH&&sshProxy)
+            if (useproxy && proxytype == PROXYSSH && sshProxy)
             {
                 delete sshProxy;
-                sshProxy=0;
+                sshProxy = 0;
             }
 
             channelConnectionsMutex.lock();
-            x2goDebug<<"Deleting channel connections."<<endl;
-            for ( int i=0; i<channelConnections.size(); ++i )
+            x2goDebug << "Deleting channel connections." << endl;
+            for (int i = 0; i < channelConnections.size(); ++i)
             {
-                finalize ( i );
+                finalize(i);
             }
             channelConnectionsMutex.unlock();
-            x2goDebug<<"Disconnecting session."<<endl;
-            ssh_disconnect ( my_ssh_session );
-            ssh_free ( my_ssh_session );
+            x2goDebug << "Disconnecting session." << endl;
+            ssh_disconnect(my_ssh_session);
+            ssh_free(my_ssh_session);
 
-            x2goDebug<<"Deleting sockets."<<endl;
+            x2goDebug << "Deleting sockets." << endl;
             if (tcpProxySocket != NULL)
                 delete tcpProxySocket;
             if (tcpNetworkProxy != NULL)
                 delete tcpNetworkProxy;
-            x2goDebug<<"All channels closed and session disconnected. Quitting session loop."<<endl;
+            x2goDebug << "All channels closed and session disconnected. Quitting session loop." << endl;
             quit();
             return;
         }
         addReverseTunnelConnections();
         checkReverseTunnelConnections();
         copyRequestMutex.lock();
-        if ( copyRequests.size() >0 )
+        if (copyRequests.size() > 0)
             copy();
         copyRequestMutex.unlock();
 
-        char buffer[1024*512]; //512K buffer
+        char buffer[1024 * 512]; //512K buffer
         int nbytes;
         fd_set rfds;
 
@@ -1950,260 +1957,263 @@ void SshMasterConnection::channelLoop()
         tv.tv_usec = 500000;
 
         int retval;
-        int maxsock=-1;
-
+        int maxsock = -1;
 
         channelConnectionsMutex.lock();
-        if ( channelConnections.size() <=0 )
+        if (channelConnections.size() <= 0)
         {
             //             x2goDebug<<"no channel connections, waiting\n";
             channelConnectionsMutex.unlock();
-            usleep ( 500 );
+            usleep(500);
             continue;
         }
-        ssh_channel* read_chan=new ssh_channel[channelConnections.size() +1];
-        ssh_channel* out_chan=new ssh_channel[channelConnections.size() +1];
-        read_chan[channelConnections.size() ]=NULL;
+        ssh_channel *read_chan = new ssh_channel[channelConnections.size() + 1];
+        ssh_channel *out_chan = new ssh_channel[channelConnections.size() + 1];
+        read_chan[channelConnections.size()] = NULL;
 
-        FD_ZERO ( &rfds );
+        FD_ZERO(&rfds);
 
-        for ( int i=0; i<channelConnections.size(); ++i )
+        for (int i = 0; i < channelConnections.size(); ++i)
         {
-            int tcpSocket=channelConnections.at ( i ).sock;
-            if ( tcpSocket>0 )
-                FD_SET ( tcpSocket, &rfds );
-            if ( channelConnections.at ( i ).channel==0l )
+            int tcpSocket = channelConnections.at(i).sock;
+            if (tcpSocket > 0)
+                FD_SET(tcpSocket, &rfds);
+            if (channelConnections.at(i).channel == 0l)
             {
-                x2goDebug<<"Creating new channel."<<endl;
-                ssh_channel channel = ssh_channel_new ( my_ssh_session );
+                x2goDebug << "Creating new channel." << endl;
+                ssh_channel channel = ssh_channel_new(my_ssh_session);
 
-                if (!channel) {
-                    QString err = ssh_get_error (my_ssh_session);
+                if (!channel)
+                {
+                    QString err = ssh_get_error(my_ssh_session);
                     /*: Argument in this context will be a function name. */
-                    QString error_msg = tr ("%1 failed.").arg ("ssh_channel_new");
-                    emit ioErr (channelConnections[i].creator, error_msg, err);
+                    QString error_msg = tr("%1 failed.").arg("ssh_channel_new");
+                    emit ioErr(channelConnections[i].creator, error_msg, err);
 
-                    x2goDebug << error_msg.left (error_msg.size () - 1) << ": " << err << endl;
+                    x2goDebug << error_msg.left(error_msg.size() - 1) << ": " << err << endl;
 
                     continue;
                 }
-                x2goDebug<<"New channel:"<<channel<<endl;
-                channelConnections[i].channel=channel;
-                if ( tcpSocket>0 )
+                x2goDebug << "New channel:" << channel << endl;
+                channelConnections[i].channel = channel;
+                if (tcpSocket > 0)
                 {
-                    x2goDebug << "Forwarding parameters: from remote (" << channelConnections.at (i).forwardHost << ":"
-                              << channelConnections.at (i).forwardPort << ") to local ("
-                              << channelConnections.at (i).localHost << ":" << channelConnections.at (i).localPort
+                    x2goDebug << "Forwarding parameters: from remote (" << channelConnections.at(i).forwardHost << ":"
+                              << channelConnections.at(i).forwardPort << ") to local ("
+                              << channelConnections.at(i).localHost << ":" << channelConnections.at(i).localPort
                               << ")";
 
                     /*
                      * Cannot support config file parsing here with pre-0.6.0 libssh versions.
                      * There's just no way to get the inferred host and port values.
                      */
-#if LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 6, 0)
-                    ssh_session tmp_session = ssh_new ();
+#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 6, 0)
+                    ssh_session tmp_session = ssh_new();
 
-                    if (!tmp_session) {
-                        QString error_msg = tr ("Cannot create SSH session.");
+                    if (!tmp_session)
+                    {
+                        QString error_msg = tr("Cannot create SSH session.");
                         x2goDebug << error_msg;
-                        emit ioErr (channelConnections[i].creator, error_msg, "");
+                        emit ioErr(channelConnections[i].creator, error_msg, "");
                     }
-                    else {
-                        QByteArray tmp_BA = channelConnections.at (i).forwardHost.toLocal8Bit ();
-                        const int tmp_port = channelConnections.at (i).forwardPort;
+                    else
+                    {
+                        QByteArray tmp_BA = channelConnections.at(i).forwardHost.toLocal8Bit();
+                        const int tmp_port = channelConnections.at(i).forwardPort;
 
-                        ssh_options_set (tmp_session, SSH_OPTIONS_HOST, tmp_BA.data ());
+                        ssh_options_set(tmp_session, SSH_OPTIONS_HOST, tmp_BA.data());
 
-                        if (tmp_port) {
-                            ssh_options_set (tmp_session, SSH_OPTIONS_PORT, &tmp_port);
+                        if (tmp_port)
+                        {
+                            ssh_options_set(tmp_session, SSH_OPTIONS_PORT, &tmp_port);
                         }
 
                         /* The host and port might be a shorthand and zero, so fetch the actual data. */
-                        if (ssh_options_parse_config (tmp_session, NULL) < 0) {
+                        if (ssh_options_parse_config(tmp_session, NULL) < 0)
+                        {
                             x2goDebug << "Warning: unable to parse the SSH config file.";
                         }
 
                         unsigned int inferred_port = 0;
-                        ssh_options_get_port (tmp_session, &inferred_port);
+                        ssh_options_get_port(tmp_session, &inferred_port);
                         x2goDebug << "Temporary session port after config file parse: " << inferred_port;
 
                         char *inferred_host = NULL;
-                        ssh_options_get (tmp_session, SSH_OPTIONS_HOST, &inferred_host);
+                        ssh_options_get(tmp_session, SSH_OPTIONS_HOST, &inferred_host);
                         x2goDebug << "Temporary session host after config file parse: " << inferred_host;
 
-                        channelConnections[i].forwardHost = QString (inferred_host);
-                        channelConnections[i].forwardPort = static_cast<int> (inferred_port);
+                        channelConnections[i].forwardHost = QString(inferred_host);
+                        channelConnections[i].forwardPort = static_cast<int>(inferred_port);
 
-                        ssh_string_free_char (inferred_host);
-                        ssh_free (tmp_session);
+                        ssh_string_free_char(inferred_host);
+                        ssh_free(tmp_session);
                     }
 #endif
 
                     {
-                        QByteArray tmp_BA_forward = channelConnections.at (i).forwardHost.toLocal8Bit ();
-                        QByteArray tmp_BA_local = channelConnections.at (i).localHost.toLocal8Bit ();
-
-                        if ( ssh_channel_open_forward ( channel,
-                                                        tmp_BA_forward.data (),
-                                                        channelConnections.at ( i ).forwardPort,
-                                                        tmp_BA_local.data (),
-                                                        channelConnections.at ( i ).localPort ) != SSH_OK )
+                        QByteArray tmp_BA_forward = channelConnections.at(i).forwardHost.toLocal8Bit();
+                        QByteArray tmp_BA_local = channelConnections.at(i).localHost.toLocal8Bit();
+
+                        if (ssh_channel_open_forward(channel,
+                                                     tmp_BA_forward.data(),
+                                                     channelConnections.at(i).forwardPort,
+                                                     tmp_BA_local.data(),
+                                                     channelConnections.at(i).localPort) != SSH_OK)
                         {
-                            QString err=ssh_get_error ( my_ssh_session );
-                            QString errorMsg=tr ( "%1 failed." ).arg ("ssh_channel_open_forward");
-                            emit ioErr ( channelConnections[i].creator, errorMsg, err );
-                            x2goDebug<<errorMsg.left (errorMsg.size () - 1)<<": "<<err<<endl;
+                            QString err = ssh_get_error(my_ssh_session);
+                            QString errorMsg = tr("%1 failed.").arg("ssh_channel_open_forward");
+                            emit ioErr(channelConnections[i].creator, errorMsg, err);
+                            x2goDebug << errorMsg.left(errorMsg.size() - 1) << ": " << err << endl;
                         }
                         else
                         {
-                            x2goDebug<<"New channel forwarded."<<endl;
+                            x2goDebug << "New channel forwarded." << endl;
                         }
                     }
                 }
                 else
                 {
-                    x2goDebug<<"Executing remote: "<<channelConnections.at ( i ).command<<endl;
-                    if ( ssh_channel_open_session ( channel ) !=SSH_OK )
+                    x2goDebug << "Executing remote: " << channelConnections.at(i).command << endl;
+                    if (ssh_channel_open_session(channel) != SSH_OK)
                     {
-                        QString err=ssh_get_error ( my_ssh_session );
-                        QString errorMsg=tr ( "%1 failed." ).arg ("ssh_channel_open_session");
-                        emit ioErr ( channelConnections[i].creator, errorMsg, err );
-                        x2goDebug<<errorMsg.left (errorMsg.size () - 1)<<": "<<err<<endl;
+                        QString err = ssh_get_error(my_ssh_session);
+                        QString errorMsg = tr("%1 failed.").arg("ssh_channel_open_session");
+                        emit ioErr(channelConnections[i].creator, errorMsg, err);
+                        x2goDebug << errorMsg.left(errorMsg.size() - 1) << ": " << err << endl;
                     }
-                    else if ( ssh_channel_request_exec ( channel, channelConnections[i].command.toLatin1() ) != SSH_OK )
+                    else if (ssh_channel_request_exec(channel, channelConnections[i].command.toLatin1()) != SSH_OK)
                     {
-                        QString err=ssh_get_error ( my_ssh_session );
-                        QString errorMsg=tr ( "%1 failed." ).arg ("ssh_channel_request_exec");
-                        emit ioErr ( channelConnections[i].creator, errorMsg, err );
-                        x2goDebug<<errorMsg.left (errorMsg.size () - 1)<<": "<<err<<endl;
+                        QString err = ssh_get_error(my_ssh_session);
+                        QString errorMsg = tr("%1 failed.").arg("ssh_channel_request_exec");
+                        emit ioErr(channelConnections[i].creator, errorMsg, err);
+                        x2goDebug << errorMsg.left(errorMsg.size() - 1) << ": " << err << endl;
                     }
                     else
                     {
-                        x2goDebug<<"New exec channel created."<<endl;
+                        x2goDebug << "New exec channel created." << endl;
                     }
                 }
-
             }
-            read_chan[i]=channelConnections.at ( i ).channel;
-            if ( tcpSocket>maxsock )
-                maxsock=tcpSocket;
+            read_chan[i] = channelConnections.at(i).channel;
+            if (tcpSocket > maxsock)
+                maxsock = tcpSocket;
         }
         channelConnectionsMutex.unlock();
-        retval=ssh_select ( read_chan,out_chan,maxsock+1,&rfds,&tv );
-        delete [] read_chan;
-        delete [] out_chan;
+        retval = ssh_select(read_chan, out_chan, maxsock + 1, &rfds, &tv);
+        delete[] read_chan;
+        delete[] out_chan;
 
-        if ( retval == -1 )
+        if (retval == -1)
         {
-            x2goDebug<<"select() error.";
+            x2goDebug << "select() error.";
             continue;
         }
 
         //         x2goDebug<<"select exited"<<endl;
 
         channelConnectionsMutex.lock();
-        for ( int i=channelConnections.size()-1; i>=0; --i )
+        for (int i = channelConnections.size() - 1; i >= 0; --i)
         {
-            int tcpSocket=channelConnections.at ( i ).sock;
-            ssh_channel channel=channelConnections.at ( i ).channel;
-            if ( channel==0l )
+            int tcpSocket = channelConnections.at(i).sock;
+            ssh_channel channel = channelConnections.at(i).channel;
+            if (channel == 0l)
                 continue;
-            if ( ssh_channel_poll ( channel,1 ) > 0 )
+            if (ssh_channel_poll(channel, 1) > 0)
             {
                 //              x2goDebug<<"read err data from channel\n";
-                nbytes = ssh_channel_read ( channel, buffer, sizeof ( buffer )-1, 1 );
-                emit stdErr ( channelConnections[i].creator, QByteArray ( buffer,nbytes ) );
+                nbytes = ssh_channel_read(channel, buffer, sizeof(buffer) - 1, 1);
+                emit stdErr(channelConnections[i].creator, QByteArray(buffer, nbytes));
                 //              x2goDebug<<nbytes<<" err from channel"<<endl;
             }
-            int rez = ssh_channel_poll ( channel, 0 );
-            if ( rez==SSH_EOF )
+            int rez = ssh_channel_poll(channel, 0);
+            if (rez == SSH_EOF)
             {
-                x2goDebug<<"EOF on channel "<<channel<<"; SshProcess object: "<<channelConnections[i].creator->pid;
+                x2goDebug << "EOF on channel " << channel << "; SshProcess object: " << channelConnections[i].creator->pid;
 
                 //////Finished////////
-                finalize ( i );
+                finalize(i);
                 continue;
             }
-            if ( rez>0 )
+            if (rez > 0)
             {
                 //                  x2goDebug<<"read data from channel "<<channel<<endl;
-                nbytes = ssh_channel_read ( channel, buffer, sizeof ( buffer )-1, 0 );
+                nbytes = ssh_channel_read(channel, buffer, sizeof(buffer) - 1, 0);
                 //                  x2goDebug<<nbytes<<" from channel "<<channel<<endl;
-                if ( nbytes > 0 )
+                if (nbytes > 0)
                 {
-                    if ( tcpSocket>0 )
+                    if (tcpSocket > 0)
                     {
-                        if ( send ( tcpSocket,buffer, nbytes,0 ) != nbytes )
+                        if (send(tcpSocket, buffer, nbytes, 0) != nbytes)
                         {
-                            QString errMsg=tr ( "Error writing to socket." );
-                            x2goDebug<<"Error writing "<<nbytes<<" to TCP socket"<<tcpSocket<<endl;
-                            emit ioErr ( channelConnections[i].creator,errMsg,"" );
-                            finalize ( i );
+                            QString errMsg = tr("Error writing to socket.");
+                            x2goDebug << "Error writing " << nbytes << " to TCP socket" << tcpSocket << endl;
+                            emit ioErr(channelConnections[i].creator, errMsg, "");
+                            finalize(i);
                             continue;
                         }
                         //                      x2goDebug<<"wrote "<<nbytes<<" to tcp socket "<<tcpSocket<<endl;
                     }
                     else
                     {
-                        emit stdOut ( channelConnections[i].creator, QByteArray ( buffer,nbytes ) );
+                        emit stdOut(channelConnections[i].creator, QByteArray(buffer, nbytes));
                     }
                 }
 
-                if ( nbytes < 0 )
+                if (nbytes < 0)
                 {
                     //////ERROR!!!!!////////
-                    QString err=ssh_get_error ( my_ssh_session );
-                    QString errorMsg=tr ( "Error reading channel." );
-                    emit ioErr ( channelConnections[i].creator, errorMsg, err );
-                    x2goDebug<<errorMsg<<" - "<<err<<endl;
-                    finalize ( i );
+                    QString err = ssh_get_error(my_ssh_session);
+                    QString errorMsg = tr("Error reading channel.");
+                    emit ioErr(channelConnections[i].creator, errorMsg, err);
+                    x2goDebug << errorMsg << " - " << err << endl;
+                    finalize(i);
                     continue;
                 }
 
-                if ( ssh_channel_is_eof ( channel ) )
+                if (ssh_channel_is_eof(channel))
                 {
-                    x2goDebug<<"EOF on channel "<<channel<<"; SshProcess object: "<<channelConnections[i].creator->pid;
+                    x2goDebug << "EOF on channel " << channel << "; SshProcess object: " << channelConnections[i].creator->pid;
 
                     //////Finished////////
-                    finalize ( i );
+                    finalize(i);
                     continue;
                 }
             }
-            if ( tcpSocket<=0 )
+            if (tcpSocket <= 0)
             {
                 continue;
             }
-            if ( FD_ISSET ( tcpSocket,&rfds ) )
+            if (FD_ISSET(tcpSocket, &rfds))
             {
-                nbytes = recv ( tcpSocket, buffer, sizeof ( buffer )-1,0 );
+                nbytes = recv(tcpSocket, buffer, sizeof(buffer) - 1, 0);
                 //                  x2goDebug<<nbytes<<" bytes from tcp socket "<<tcpSocket<<endl;
-                if ( nbytes > 0 )
+                if (nbytes > 0)
                 {
-                    if ( ssh_channel_write ( channel, buffer, nbytes ) !=nbytes )
+                    if (ssh_channel_write(channel, buffer, nbytes) != nbytes)
                     {
-                        QString err=ssh_get_error ( my_ssh_session );
-                        QString errorMsg=tr ( "%1 failed." ).arg ("ssh_channel_write");
-                        emit ioErr ( channelConnections[i].creator, errorMsg, err );
-                        x2goDebug<<errorMsg.left (errorMsg.size () - 1)<<": "<<err<<endl;
-                        finalize ( i );
+                        QString err = ssh_get_error(my_ssh_session);
+                        QString errorMsg = tr("%1 failed.").arg("ssh_channel_write");
+                        emit ioErr(channelConnections[i].creator, errorMsg, err);
+                        x2goDebug << errorMsg.left(errorMsg.size() - 1) << ": " << err << endl;
+                        finalize(i);
                         continue;
                     }
                     //                      x2goDebug<<nbytes<<" bytes wrote to channel"<<channel<<endl;
                 }
-                if ( nbytes < 0 )
+                if (nbytes < 0)
                 {
                     //////ERROR!!!!!////////
-                    QString err="";
-                    QString errorMsg=tr ( "Error reading from TCP socket." );
-                    emit ioErr ( channelConnections[i].creator, errorMsg, err );
-                    x2goDebug<<errorMsg<<" - "<<err<<endl;
-                    finalize ( i );
+                    QString err = "";
+                    QString errorMsg = tr("Error reading from TCP socket.");
+                    emit ioErr(channelConnections[i].creator, errorMsg, err);
+                    x2goDebug << errorMsg << " - " << err << endl;
+                    finalize(i);
                     continue;
                 }
-                if ( nbytes==0 )
+                if (nbytes == 0)
                 {
-                    x2goDebug<<"Socket "<<tcpSocket<<" closed."<<endl;
-                    finalize ( i );
+                    x2goDebug << "Socket " << tcpSocket << " closed." << endl;
+                    finalize(i);
                     continue;
                 }
             }
@@ -2212,34 +2222,30 @@ void SshMasterConnection::channelLoop()
     }
 }
 
-void SshMasterConnection::finalize ( int item )
+void SshMasterConnection::finalize(int item)
 {
-    int tcpSocket=channelConnections.at ( item ).sock;
-    ssh_channel channel=channelConnections.at ( item ).channel;
-    if ( channel )
+    int tcpSocket = channelConnections.at(item).sock;
+    ssh_channel channel = channelConnections.at(item).channel;
+    if (channel)
     {
-        ssh_channel_send_eof ( channel );
-        x2goDebug<<"EOF sent.";
-        ssh_channel_close ( channel );
-        x2goDebug<<"Channel closed.";
-        ssh_channel_free ( channel );
+        ssh_channel_send_eof(channel);
+        x2goDebug << "EOF sent.";
+        ssh_channel_close(channel);
+        x2goDebug << "Channel closed.";
+        ssh_channel_free(channel);
     }
-    if ( tcpSocket>0 )
+    if (tcpSocket > 0)
     {
 #ifndef Q_OS_WIN
         shutdown(tcpSocket, SHUT_RDWR);
-        close ( tcpSocket );
+        close(tcpSocket);
 #else
         shutdown(tcpSocket, SD_BOTH);
-        closesocket ( tcpSocket );
+        closesocket(tcpSocket);
 #endif
     }
-    SshProcess* proc=channelConnections[item].creator;
-    QString uuid=channelConnections[item].uuid;
-    channelConnections.removeAt ( item );
-    emit channelClosed ( proc, uuid );
+    SshProcess *proc = channelConnections[item].creator;
+    QString uuid = channelConnections[item].uuid;
+    channelConnections.removeAt(item);
+    emit channelClosed(proc, uuid);
 }
-
-
-
-
diff --git a/src/sshmasterconnection.h b/src/sshmasterconnection.h
index ffb853b..c7883be 100644
--- a/src/sshmasterconnection.h
+++ b/src/sshmasterconnection.h
@@ -27,11 +27,13 @@
 #include <QTcpSocket>
 #include <QNetworkProxy>
 
-
-#define PROPERTY(TYPE,NAME)  private: TYPE NAME; \
-public: TYPE get_##NAME(){return NAME;} \
-void set_##NAME(TYPE VAL){NAME=VAL;}
-
+#define PROPERTY(TYPE, NAME)           \
+private:                               \
+    TYPE NAME;                         \
+                                       \
+public:                                \
+    TYPE get_##NAME() { return NAME; } \
+    void set_##NAME(TYPE VAL) { NAME = VAL; }
 
 class ONMainWindow;
 class SshProcess;
@@ -39,16 +41,16 @@ struct ChannelConnection
 {
     ssh_channel channel;
     int sock;
-    SshProcess* creator;
+    SshProcess *creator;
     int forwardPort;
     int localPort;
     QString forwardHost;
     QString localHost;
     QString command;
     QString uuid;
-    bool operator==(ChannelConnection& t)
+    bool operator==(ChannelConnection &t)
     {
-        return (channel==t.channel);
+        return (channel == t.channel);
     }
 };
 
@@ -57,25 +59,30 @@ struct ReverseTunnelRequest
     uint localPort;
     uint forwardPort;
     QString localHost;
-    SshProcess* creator;
+    SshProcess *creator;
     bool listen;
 };
 
 struct CopyRequest
 {
-    SshProcess* creator;
+    SshProcess *creator;
     QString src;
     QString dst;
 };
 
-class SshMasterConnection: public QThread
+class SshMasterConnection : public QThread
 {
     Q_OBJECT
     PROPERTY(bool, kerberosDelegation)
 public:
-    enum ProxyType {PROXYSSH, PROXYHTTP};
+    enum ProxyType
+    {
+        PROXYSSH,
+        PROXYHTTP
+    };
 
-    enum passphrase_types {
+    enum passphrase_types
+    {
         PASSPHRASE_PRIVKEY,
         PASSPHRASE_CHALLENGE,
         PASSPHRASE_PASSWORD,
@@ -83,28 +90,28 @@ public:
     };
 
     void run();
-    SshMasterConnection(QObject* parent, QString host, int port, bool acceptUnknownServers, QString user,
-                        QString pass, QString key, bool autologin, bool krblogin=false,
-                        bool useproxy=false, ProxyType type=PROXYSSH, QString proxyserver=QString::null, quint16 proxyport=0,
-                        QString proxylogin=QString::null, QString proxypassword=QString::null, QString proxyKey=QString::null,
-                        bool proxyAutologin=false, bool proxyKrbLogin=false);
+    SshMasterConnection(QObject *parent, QString host, int port, bool acceptUnknownServers, QString user,
+                        QString pass, QString key, bool autologin, bool krblogin = false,
+                        bool useproxy = false, ProxyType type = PROXYSSH, QString proxyserver = QString::null, quint16 proxyport = 0,
+                        QString proxylogin = QString::null, QString proxypassword = QString::null, QString proxyKey = QString::null,
+                        bool proxyAutologin = false, bool proxyKrbLogin = false);
     ~SshMasterConnection();
-    void addChannelConnection(SshProcess* creator, int sock, QString forwardHost,
-                              int forwardPort, QString localHost, int localPort, void* channel=0l);
-    void addChannelConnection(SshProcess* creator, QString uuid, QString cmd);
-    void addCopyRequest(SshProcess* creator, QString src, QString dst);
+    void addChannelConnection(SshProcess *creator, int sock, QString forwardHost,
+                              int forwardPort, QString localHost, int localPort, void *channel = 0l);
+    void addChannelConnection(SshProcess *creator, QString uuid, QString cmd);
+    void addCopyRequest(SshProcess *creator, QString src, QString dst);
     void writeKnownHosts(bool);
     void setKeyPhrase(QString);
 
-    int executeCommand(const QString& command, QObject* receiver=0, const char* slotFinished=0, bool overridePath=true);
-    int startTunnel(const QString& forwardHost, uint forwardPort, const QString& localHost,
-                    uint localPort, bool reverse=false, QObject* receiver=0, const char* slotTunnelOk=0, const char* slotFinished=0);
-    int copyFile(const QString& src, const QString dst, QObject* receiver=0, const char* slotFinished=0);
+    int executeCommand(const QString &command, QObject *receiver = 0, const char *slotFinished = 0, bool overridePath = true);
+    int startTunnel(const QString &forwardHost, uint forwardPort, const QString &localHost,
+                    uint localPort, bool reverse = false, QObject *receiver = 0, const char *slotTunnelOk = 0, const char *slotFinished = 0);
+    int copyFile(const QString &src, const QString dst, QObject *receiver = 0, const char *slotFinished = 0);
     QString getSourceFile(int pid);
 
     void setAcceptUnknownServers(bool accept)
     {
-        acceptUnknownServers=accept;
+        acceptUnknownServers = accept;
     }
     QString getHost()
     {
@@ -136,7 +143,7 @@ private:
     void channelLoop();
     void finalize(int arg1);
     void copy();
-    int serverAuth(QString& errorMsg);
+    int serverAuth(QString &errorMsg);
     void setVerficationCode(QString code);
     void checkReverseTunnelConnections();
     void addReverseTunnelConnections();
@@ -146,19 +153,18 @@ private:
 
 private slots:
 
-    void slotSshProxyServerAuthError ( int,QString, SshMasterConnection* );
-    void slotSshProxyServerAuthAborted ();
-    void slotSshProxyUserAuthError ( QString );
-    void slotSshProxyConnectionError ( QString,QString );
-
+    void slotSshProxyServerAuthError(int, QString, SshMasterConnection *);
+    void slotSshProxyServerAuthAborted();
+    void slotSshProxyUserAuthError(QString);
+    void slotSshProxyConnectionError(QString, QString);
 
     void slotSshProxyConnectionOk();
     void slotSshProxyTunnelOk(int);
-    void slotSshProxyTunnelFailed(bool result,  QString output,
+    void slotSshProxyTunnelFailed(bool result, QString output,
                                   int);
-    void slotSshProxyInteractionStart ( SshMasterConnection* connection, QString prompt );
-    void slotSshProxyInteractionUpdate ( SshMasterConnection* connection, QString output );
-    void slotSshProxyInteractionFinish ( SshMasterConnection* connection);
+    void slotSshProxyInteractionStart(SshMasterConnection *connection, QString prompt);
+    void slotSshProxyInteractionUpdate(SshMasterConnection *connection, QString output);
+    void slotSshProxyInteractionFinish(SshMasterConnection *connection);
 
 public slots:
     void interactionTextEnter(QString text);
@@ -180,7 +186,7 @@ private:
     bool writeHostKey;
     bool writeHostKeyReady;
     int nextPid;
-    QList<SshProcess*> processes;
+    QList<SshProcess *> processes;
 
     QString keyPhrase;
     bool keyPhraseReady;
@@ -205,12 +211,12 @@ private:
     bool disconnectSessionFlag;
     int localProxyPort;
     bool acceptUnknownServers;
-    ONMainWindow* mainWnd;
+    ONMainWindow *mainWnd;
     bool kerberos;
     QString sshProcErrString;
     QTcpSocket *tcpProxySocket;
     QNetworkProxy *tcpNetworkProxy;
-    SshMasterConnection* sshProxy;
+    SshMasterConnection *sshProxy;
     bool sshProxyReady;
     bool breakLoop;
     bool loginCheck;
@@ -221,30 +227,29 @@ private:
     static const QString challenge_auth_code_prompts_[];
 
 signals:
-    void stdErr(SshProcess* caller, QByteArray data);
-    void stdOut(SshProcess* caller, QByteArray data);
-    void ioErr(SshProcess* caller, QString error, QString lastSessionError);
-    void copyErr(SshProcess* caller, QString error, QString lastSessionError);
-    void copyOk(SshProcess* caller);
-    void channelClosed(SshProcess* caller, QString uuid);
-    void reverseTunnelOk(SshProcess* caller);
-    void reverseTunnelFailed(SshProcess* caller, QString error);
+    void stdErr(SshProcess *caller, QByteArray data);
+    void stdOut(SshProcess *caller, QByteArray data);
+    void ioErr(SshProcess *caller, QString error, QString lastSessionError);
+    void copyErr(SshProcess *caller, QString error, QString lastSessionError);
+    void copyOk(SshProcess *caller);
+    void channelClosed(SshProcess *caller, QString uuid);
+    void reverseTunnelOk(SshProcess *caller);
+    void reverseTunnelFailed(SshProcess *caller, QString error);
 
     void connectionError(QString message, QString lastSessionError);
-    void serverAuthError(int errCode, QString lastSessionError, SshMasterConnection*);
+    void serverAuthError(int errCode, QString lastSessionError, SshMasterConnection *);
     void serverAuthAborted();
     void userAuthError(QString error);
 
-    void connectionOk( QString host);
+    void connectionOk(QString host);
 
-    void needPassPhrase(SshMasterConnection*, SshMasterConnection::passphrase_types);
-    void needChallengeResponse(SshMasterConnection*, QString Challenge);
-    void startInteraction(SshMasterConnection*, QString prompt);
-    void finishInteraction(SshMasterConnection*);
-    void updateInteraction(SshMasterConnection*, QString output);
+    void needPassPhrase(SshMasterConnection *, SshMasterConnection::passphrase_types);
+    void needChallengeResponse(SshMasterConnection *, QString Challenge);
+    void startInteraction(SshMasterConnection *, QString prompt);
+    void finishInteraction(SshMasterConnection *);
+    void updateInteraction(SshMasterConnection *, QString output);
 };
 
-Q_DECLARE_METATYPE (SshMasterConnection::passphrase_types)
+Q_DECLARE_METATYPE(SshMasterConnection::passphrase_types)
 
 #endif // SSHMASTERCONNECTION_H
-
-- 
2.17.1