summaryrefslogtreecommitdiffstats
path: root/src/lib/Server
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2004-08-11 20:40:57 +0000
committerNarayan Desai <desai@mcs.anl.gov>2004-08-11 20:40:57 +0000
commitdf518646884aa8a9649855ceb47aaadedabf0ded (patch)
tree213160916d05c18d24ec5cf1528dc863a24549d7 /src/lib/Server
parent6d27b404061ea02ab11cf3e8a59a9f197ead43f5 (diff)
downloadbcfg2-df518646884aa8a9649855ceb47aaadedabf0ded.tar.gz
bcfg2-df518646884aa8a9649855ceb47aaadedabf0ded.tar.bz2
bcfg2-df518646884aa8a9649855ceb47aaadedabf0ded.zip
Rename: generators/sshbase.py -> src/lib/Server/Generators/sshbase.py
(Logical change 1.37) git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@214 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Server')
-rw-r--r--src/lib/Server/Generators/sshbase.py85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/lib/Server/Generators/sshbase.py b/src/lib/Server/Generators/sshbase.py
index e69de29bb..cef9cb672 100644
--- a/src/lib/Server/Generators/sshbase.py
+++ b/src/lib/Server/Generators/sshbase.py
@@ -0,0 +1,85 @@
+#!/usr/bin/env python
+
+from binascii import b2a_base64
+from glob import glob
+from os import rename, stat, system
+from socket import gethostbyname
+from string import strip
+from syslog import syslog, LOG_INFO
+
+from Types import ConfigFile
+from Generator import Generator
+from GeneratorUtils import DirectoryBacked
+
+from elementtree.ElementTree import Element
+
+class sshbase(Generator):
+ __name__ = 'sshbase'
+ __version__ = '$Id$'
+ __author__ = 'bcfg-dev@mcs.anl.gov'
+
+ def __setup__(self):
+ self.repository = DirectoryBacked(self.data, self.core.fam)
+ self.__provides__ = {'ConfigFile':{'/etc/ssh/ssh_known_hosts':self.build_skn,
+ '/etc/ssh/ssh_host_dsa_key':self.build_hk,
+ '/etc/ssh/ssh_host_rsa_key':self.build_hk,
+ '/etc/ssh/ssh_host_dsa_key.pub':self.build_hk,
+ '/etc/ssh/ssh_host_rsa_key.pub':self.build_hk,
+ '/etc/ssh/ssh_host_key':self.build_hk,
+ '/etc/ssh/ssh_host_key.pub':self.build_hk}}
+
+ def build_skn(self,entry,metadata):
+ client = metadata.hostname
+ filedata = self.repository.entries['ssh_known_hosts'].data
+ ip=gethostbyname(client)
+ keylist = map(lambda x:x%(client), ["ssh_host_dsa_key.pub.H_%s","ssh_host_rsa_key.pub.H_%s","ssh_host_key.pub.H_%s"])
+ for hostkey in keylist:
+ filedata += "%s,%s,%s %s"%(client,"%s.mcs.anl.gov"%(client),ip,self.repository.entries[hostkey].data)
+ entry.attrib.update({'owner':'root', 'group':'root', 'perms':'0644'})
+ entry.text = filedata
+
+ def build_hk(self,entry,metadata):
+ client = metadata.hostname
+ filename = "%s.H_%s"%(entry.attrib['name'].split('/')[-1],client)
+ if filename not in self.repository.entries.keys():
+ self.GenerateHostKeys(client)
+ self.GenerateKnownHosts()
+ keydata = self.repository.entries[filename].data
+ entry.attrib.update({'owner':'root', 'group':'root', 'perms':'0600'})
+ entry.text = keydata
+ if "ssh_host_key.H_" in filename:
+ entry.attrib['encoding'] = 'base64'
+ entry.text = b2a_base64(keydata)
+
+ def GenerateKnownHosts(self):
+ output = ''
+ for f in self.repository.entries.keys():
+ if ".pub.H_" in f:
+ h = f.split('_')[-1]
+ output += "%s,%s.mcs.anl.gov,%s %s"%(h, h, gethostbyname(h), self.repository.entries[f].data)
+ self.repository.entries['ssh_known_hosts'].data = output
+
+ def GenerateHostKeys(self,client):
+ keylist = map(lambda x:x%client, ["ssh_host_dsa_key.H_%s","ssh_host_rsa_key.H_%s","ssh_host_key.H_%s"])
+ for hostkey in keylist:
+ if 'ssh_host_rsa_key.H_' in hostkey:
+ keytype = 'rsa'
+ elif 'ssh_host_dsa_key.H_' in hostkey:
+ keytype = 'dsa'
+ else:
+ keytype = 'rsa1'
+
+ if hostkey not in self.repository.entries.keys():
+ system('ssh-keygen -f %s/%s -N "" -t %s -C root@%s'%(self.data,hostkey,keytype,client))
+ rename("%s/%s.pub"%(self.data,hostkey),"%s/"%(self.data)+".".join(hostkey.split('.')[:-1]+['pub']+hostkey.split('.')[-1]))
+ # call the notifier for global
+
+ def GetProbes(self, metadata):
+ p = Element("probe", name='hostname', interpreter='/bin/sh', source='sshbase')
+ p.text = 'hostname'
+ return [p]
+
+ def AcceptProbeData(self, client, probedata):
+ p = strip(probedata.text)
+ #syslog(LOG_INFO, "Got hostname %s for client %s"%(p, client))
+