summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Plugins/SSHbase.py
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2008-08-05 17:29:20 +0000
committerNarayan Desai <desai@mcs.anl.gov>2008-08-05 17:29:20 +0000
commit9ef9c703159404dba311e18624d2fdd5fb399020 (patch)
treeebd19c69f8b96ca5b3c48444d0194de9815a828c /src/lib/Server/Plugins/SSHbase.py
parent3e55be9beb131b33b56985053f05272918ecb4b8 (diff)
downloadbcfg2-9ef9c703159404dba311e18624d2fdd5fb399020.tar.gz
bcfg2-9ef9c703159404dba311e18624d2fdd5fb399020.tar.bz2
bcfg2-9ef9c703159404dba311e18624d2fdd5fb399020.zip
SSHbase: improve tempfile handling (patch from f.pauget) (Resolves Ticket #588)
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@4854 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Server/Plugins/SSHbase.py')
-rw-r--r--src/lib/Server/Plugins/SSHbase.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/lib/Server/Plugins/SSHbase.py b/src/lib/Server/Plugins/SSHbase.py
index cdd95181b..8da2f4429 100644
--- a/src/lib/Server/Plugins/SSHbase.py
+++ b/src/lib/Server/Plugins/SSHbase.py
@@ -1,7 +1,7 @@
'''This module manages ssh key files for bcfg2'''
__revision__ = '$Revision$'
-import binascii, os, socket
+import binascii, os, socket, tempfile
import Bcfg2.Server.Plugin
class SSHbase(Bcfg2.Server.Plugin.GeneratorPlugin, Bcfg2.Server.Plugin.DirectoryBacked):
@@ -176,7 +176,8 @@ class SSHbase(Bcfg2.Server.Plugin.GeneratorPlugin, Bcfg2.Server.Plugin.Director
if hostkey not in self.entries.keys():
fileloc = "%s/%s" % (self.data, hostkey)
publoc = self.data + '/' + ".".join([hostkey.split('.')[0]]+['pub', "H_%s" % client])
- temploc = "/tmp/%s" % hostkey
+ tempdir = tempfile.mkdtemp()
+ temploc = "%s/%s" % (tempdir, hostkey)
os.system('ssh-keygen -q -f %s -N "" -t %s -C root@%s < /dev/null' %
(temploc, keytype, client))
open(fileloc, 'w').write(open(temploc).read())
@@ -186,6 +187,7 @@ class SSHbase(Bcfg2.Server.Plugin.GeneratorPlugin, Bcfg2.Server.Plugin.Director
try:
os.unlink(temploc)
os.unlink("%s.pub" % temploc)
+ os.rmdir(tempdir)
except OSError:
self.logger.error("Failed to unlink temporary ssh keys")