summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Plugins/SSHbase.py
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2006-04-25 21:03:18 +0000
committerNarayan Desai <desai@mcs.anl.gov>2006-04-25 21:03:18 +0000
commit2e63008c4830e5a91c8d680cf0e55e3faad0a87c (patch)
tree7c2ae8356bc5a4f1c560d37172c7f7dcdc6bb78d /src/lib/Server/Plugins/SSHbase.py
parent1c445056e1b7868dffc6d566d14eaa806f11f926 (diff)
downloadbcfg2-2e63008c4830e5a91c8d680cf0e55e3faad0a87c.tar.gz
bcfg2-2e63008c4830e5a91c8d680cf0e55e3faad0a87c.tar.bz2
bcfg2-2e63008c4830e5a91c8d680cf0e55e3faad0a87c.zip
* Remove tmp files created during ssh key generation (resolves ticket #46)
* Pylint cleanups * Simplify the host resolver git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@1851 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Server/Plugins/SSHbase.py')
-rw-r--r--src/lib/Server/Plugins/SSHbase.py27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/lib/Server/Plugins/SSHbase.py b/src/lib/Server/Plugins/SSHbase.py
index da7623cd3..d35dfa7a8 100644
--- a/src/lib/Server/Plugins/SSHbase.py
+++ b/src/lib/Server/Plugins/SSHbase.py
@@ -48,7 +48,7 @@ class SSHbase(Bcfg2.Server.Plugin.Plugin):
self.ipcache = {}
self.__rmi__ = ['GetPubKeys']
- def GetPubKeys(self, client):
+ def GetPubKeys(self, _):
'''Export public key data'''
if not hasattr(self, 'static_skn'):
self.cache_skn()
@@ -65,16 +65,12 @@ class SSHbase(Bcfg2.Server.Plugin.Plugin):
self.ipcache[client] = (ipaddr, client)
return (ipaddr, client)
except socket.gaierror:
- pass
- try:
- ipaddr = os.popen("getent hosts %s" % client).read().strip().split()
- except:
- ipaddr = ''
- if ipaddr:
- self.ipcache[client] = (ipaddr, client)
- return (ipaddr, client)
- self.logger.error("Failed to find IP address for %s" % client)
- raise socket.gaierror
+ ipaddr = os.popen("getent hosts %s" % client).read().strip().split()
+ if ipaddr:
+ self.ipcache[client] = (ipaddr, client)
+ return (ipaddr, client)
+ self.logger.error("Failed to find IP address for %s" % client)
+ raise socket.gaierror
def cache_skn(self):
'''build memory cache of the ssh known hosts file'''
@@ -100,7 +96,7 @@ class SSHbase(Bcfg2.Server.Plugin.Plugin):
entry.text += "localhost,localhost.localdomain,127.0.0.1 %s" % (
self.repository.entries[hostkey].data)
permdata = {'owner':'root', 'group':'root', 'perms':'0644'}
- [entry.attrib.__setitem__(x, permdata[x]) for x in permdata]
+ [entry.attrib.__setitem__(key, permdata[key]) for key in permdata]
def build_hk(self, entry, metadata):
'''This binds host key data into entries'''
@@ -118,7 +114,7 @@ class SSHbase(Bcfg2.Server.Plugin.Plugin):
permdata['perms'] = '0600'
if entry.get('name')[-4:] == '.pub':
permdata['perms'] = '0644'
- [entry.attrib.__setitem__(x, permdata[x]) for x in permdata]
+ [entry.attrib.__setitem__(key, permdata[key]) for key in permdata]
if "ssh_host_key.H_" == filename[:15]:
entry.attrib['encoding'] = 'base64'
entry.text = binascii.b2a_base64(keydata)
@@ -146,3 +142,8 @@ class SSHbase(Bcfg2.Server.Plugin.Plugin):
open(publoc, 'w').write(open("%s.pub" % temploc).read())
self.repository.AddEntry(hostkey)
self.repository.AddEntry(".".join([hostkey.split('.')[0]]+['pub', "H_%s" % client]))
+ try:
+ os.unlink(fileloc)
+ os.unlink(publoc)
+ except OSError:
+ self.logger.error("Failed to unlink temporary ssh keys")