You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cloudstack.apache.org by Wido den Hollander <wi...@widodh.nl> on 2012/05/21 15:03:19 UTC

[PATCH] Make the creating and inserting of the SSH key pair of the management server more reliable.

On systems where sudo is used you can't always rely on ~ for the homedir of the user cloud.

We should use the property of "user.name" as a basis and use that throughout the code instead of heaving ~ or ~cloud hardcoded.

Although we are not able to run under a different user yet, the code should be prepared for it as far as we can.

Signed-off-by: Wido den Hollander <wi...@widodh.nl>
---
 .../com/cloud/server/ConfigurationServerImpl.java  |   16 ++++------------
 1 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java
index 81ca96e..304d510 100755
--- a/server/src/com/cloud/server/ConfigurationServerImpl.java
+++ b/server/src/com/cloud/server/ConfigurationServerImpl.java
@@ -583,16 +583,9 @@ public class ConfigurationServerImpl implements ConfigurationServer {
         }
         String already = _configDao.getValue("ssh.privatekey");
         String homeDir = null;
-        if (devel) {
-        	homeDir = Script.runSimpleBashScript("echo ~");
-        	if (homeDir == null) {
-        		throw new CloudRuntimeException("Cannot get home directory for account: cloud");
-        	}
-        } else {
-        	homeDir = Script.runSimpleBashScript("echo ~cloud");
-        	if (homeDir == null) {
-        		throw new CloudRuntimeException("Cannot get home directory for account: cloud");
-        	}
+        homeDir = Script.runSimpleBashScript("echo ~" + userid);
+        if (homeDir == null) {
+            throw new CloudRuntimeException("Cannot get home directory for account: " + userid);
         }
         
         if (s_logger.isInfoEnabled()) {
@@ -611,7 +604,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
                 s_logger.info("Systemvm keypairs not found in database. Need to store them in the database");
             }
             // FIXME: take a global database lock here for safety.
-            Script.runSimpleBashScript("if [ -f ~/.ssh/id_rsa ] ; then rm -f ~/.ssh/id_rsa ; fi; ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa -q");
+            Script.runSimpleBashScript("if [ -f " + privkeyfile + " ] ; then rm -f " + privkeyfile + "; fi; ssh-keygen -t rsa -N '' -f " + privkeyfile + " -q");
 
             byte[] arr1 = new byte[4094]; // configuration table column value size
             try {
@@ -680,7 +673,6 @@ public class ConfigurationServerImpl implements ConfigurationServer {
     }
 
     private void writeKeyToDisk(String key, String keyPath) {
-        Script.runSimpleBashScript("mkdir -p ~/.ssh");
         File keyfile = new File(keyPath);
         if (!keyfile.exists()) {
             try {
-- 
1.7.5.4