diff options
| author | Shireesh Anjal <shireesh@gluster.com> | 2011-08-09 18:29:48 +0530 |
|---|---|---|
| committer | Shireesh Anjal <shireesh@gluster.com> | 2011-08-09 18:29:48 +0530 |
| commit | 45b12625bea311f4599672b359467b184bf6e250 (patch) | |
| tree | c5223f60e61b59aad6778d55ab1bfea0208de280 /src | |
| parent | 77c32a439727a91972986d18698f27fc46f62e83 (diff) | |
Modified to close the ssh connections after executing commands remotely if they are created using passwords and not using public key.
Diffstat (limited to 'src')
| -rw-r--r-- | src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/SshUtil.java | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/SshUtil.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/SshUtil.java index 9f5e1072..a5735cae 100644 --- a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/SshUtil.java +++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/SshUtil.java @@ -73,7 +73,7 @@ public class SshUtil { public boolean hasDefaultPassword(String serverName) { try { - getConnectionWithPassword(serverName); + getConnectionWithPassword(serverName).close(); return true; } catch(ConnectionException e) { return false; @@ -120,6 +120,7 @@ public class SshUtil { try { publicKeyData = FileUtil.readFileAsByteArray(PUBLIC_KEY_FILE); } catch (Exception e) { + conn.close(); throw new GlusterRuntimeException("Couldn't load public key file [" + PUBLIC_KEY_FILE + "]", e); } @@ -130,6 +131,7 @@ public class SshUtil { outputStream.write(publicKeyData); outputStream.close(); } catch (Exception e) { + conn.close(); throw new GlusterRuntimeException("Couldnt append file [" + localTempFile + "] with public key!", e); } @@ -138,6 +140,7 @@ public class SshUtil { } catch (IOException e) { throw new GlusterRuntimeException("Couldn't add public key to server [" + serverName + "]", e); } finally { + conn.close(); localTempFile.delete(); } @@ -331,7 +334,11 @@ public class SshUtil { * @return Result of remote execution */ public ProcessResult executeRemoteWithPassword(String serverName, String command) { - return executeCommand(getConnectionWithPassword(serverName), command); + Connection conn = getConnectionWithPassword(serverName); + ProcessResult result = executeCommand(conn, command); + // we don't cache password based connections. hence the connection must be closed. + conn.close(); + return result; } private ProcessResult executeRemoteWithPubKey(String serverName, String command) { |
