Ticket #588: patch

File patch, 1.3 KB (added by [email protected]…, 15 years ago)
  • src/lib/Server/Plugins/SSHbase.py

    diff -r 3e2a61e4832c -r 0fa973130581 src/lib/Server/Plugins/SSHbase.py
    a b  
    11'''This module manages ssh key files for bcfg2''' 
    22__revision__ = '$Revision: 4680 $' 
    33 
    4 import binascii, os, socket 
     4import binascii, os, socket, tempfile 
    55import Bcfg2.Server.Plugin 
    66 
    77class SSHbase(Bcfg2.Server.Plugin.GeneratorPlugin,  Bcfg2.Server.Plugin.DirectoryBacked): 
     
    176176            if hostkey not in self.entries.keys(): 
    177177                fileloc = "%s/%s" % (self.data, hostkey) 
    178178                publoc = self.data + '/' + ".".join([hostkey.split('.')[0]]+['pub', "H_%s" % client]) 
    179                 temploc =  "/tmp/%s" % hostkey 
     179                tempdir = tempfile.mkdtemp() 
     180                temploc = "%s/%s" % (tempdir, hostkey) 
    180181                os.system('ssh-keygen -q -f %s -N "" -t %s -C [email protected]%s < /dev/null' % 
    181182                          (temploc, keytype, client)) 
    182183                open(fileloc, 'w').write(open(temploc).read()) 
     
    186187                try: 
    187188                    os.unlink(temploc) 
    188189                    os.unlink("%s.pub" % temploc) 
     190                    os.rmdir(tempdir) 
    189191                except OSError: 
    190192                    self.logger.error("Failed to unlink temporary ssh keys") 
    191193