From 8999c249ccc3d93f08060fbfb0b7598e7e15cfda Mon Sep 17 00:00:00 2001 From: Sol Jerome Date: Fri, 26 Mar 2010 00:24:16 +0000 Subject: SSHbase: Use shutil as per Lee's suggestion in Ticket #866 From the ticket: --- From what I can tell, there is an os.system call (line #214 of Bcfg2/Server/Plugins/SSHbase.py) that is supposed to fire off ssh-keygen to generate the keys in a temporary directory. It seems that this call isn't generating the keys correctly. Adding in some debug os.listdir(tempdir) calls before and after the os.system call, shows that there are no files before and after the os.system call. Running the command manually generates valid key pairs. --- So, while this commit won't fix the os.system call, it should at least prevent the plugin from generating empty ssh keys. Signed-off-by: Sol Jerome git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5794 ce84e21b-d406-0410-9b95-82705330c041 --- src/lib/Server/Plugins/SSHbase.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/lib/Server/Plugins/SSHbase.py b/src/lib/Server/Plugins/SSHbase.py index 4e26001c1..e5cabfbd5 100644 --- a/src/lib/Server/Plugins/SSHbase.py +++ b/src/lib/Server/Plugins/SSHbase.py @@ -4,6 +4,7 @@ __revision__ = '$Revision$' import binascii import os import socket +import shutil import tempfile from subprocess import Popen, PIPE import Bcfg2.Server.Plugin @@ -252,8 +253,8 @@ class SSHbase(Bcfg2.Server.Plugin.Plugin, temploc = "%s/%s" % (tempdir, hostkey) cmd = 'ssh-keygen -q -f %s -N "" -t %s -C root@%s < /dev/null' os.system(cmd % (temploc, keytype, client)) - open(fileloc, 'w').write(open(temploc).read()) - open(publoc, 'w').write(open("%s.pub" % temploc).read()) + shutil.copy(temploc, fileloc) + shutil.copy("%s.pub" % temploc, publoc) self.AddEntry(hostkey) self.AddEntry(".".join([hostkey.split('.')[0]]+['pub', "H_%s" \ % client])) -- cgit v1.2.3-1-g7c22