From 1a9587bf5c27df5afc5465d6b76c73761504d15e Mon Sep 17 00:00:00 2001 From: rmurray <> Date: Wed, 27 Dec 2006 12:51:53 +0000 Subject: [PATCH] add dns-sshfp file containing SSHFP DNS records for each host. --- ud-generate | 61 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 13 deletions(-) diff --git a/ud-generate b/ud-generate index ba282b9..45aa00c 100755 --- a/ud-generate +++ b/ud-generate @@ -3,9 +3,9 @@ # Generates passwd, shadow and group files from the ldap directory. # Copyright (c) 2000-2001 Jason Gunthorpe -# Copyright (c) 2001-2005 Ryan Murray # Copyright (c) 2003-2004 James Troup # Copyright (c) 2004-2005 Joey Schulze +# Copyright (c) 2001-2006 Ryan Murray # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,7 +21,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -import string, re, time, ldap, getopt, sys, os, pwd, posix, socket; +import string, re, time, ldap, getopt, sys, os, pwd, posix, socket, base64, sha; from userdir_ldap import *; global Allowed; @@ -33,7 +33,7 @@ Allowed = None; CurrentHost = ""; EmailCheck = re.compile("^([^ <>@]+@[^ ,<>@]+)?$"); -BSMTPCheck = re.compile(".*mx 0 (klecker|gluck)\.debian\.org\..*",re.DOTALL); +BSMTPCheck = re.compile(".*mx 0 (gluck)\.debian\.org\..*",re.DOTALL); DNSZone = ".debian.net" def Sanitize(Str): @@ -448,6 +448,41 @@ def GenDNS(l,File,HomePrefix): raise; Done(File,F,None); +# Generate the DNS SSHFP records +def GenSSHFP(l,File,HomePrefix): + F = None + try: + F = open(File + ".tmp","w") + + # Fetch all the hosts + global HostAttrs + if HostAttrs == None: + raise "No Hosts" + + for x in HostAttrs: + if x[1].has_key("hostname") == 0 or \ + x[1].has_key("sshRSAHostKey") == 0: + continue + Host = GetAttr(x,"hostname"); + Algorithm = None + for I in x[1]["sshRSAHostKey"]: + Split = string.split(I) + if Split[0] == 'ssh-rsa': + Algorithm = 1 + if Split[0] == 'ssh-dss': + Algorithm = 2 + if Algorithm == None: + continue + Fingerprint = sha.new(base64.decodestring(Split[1])).hexdigest() + Line = "%s. IN SSHFP %u 1 %s" % (Host,Algorithm,Fingerprint) + Line = Sanitize(Line) + "\n" + F.write(Line) + # Oops, something unspeakable happened. + except: + Die(File,F,None) + raise; + Done(File,F,None) + # Generate the BSMTP file def GenBSMTP(l,File,HomePrefix): F = None; @@ -499,14 +534,11 @@ def GenSSHKnown(l,File): F = open(File + ".tmp","w",0644); os.umask(OldMask); - # Fetch all the hosts - HostKeys = l.search_s(HostBaseDn,ldap.SCOPE_ONELEVEL,"sshRSAHostKey=*",\ - ["hostname","sshRSAHostKey"]); - - if HostKeys == None: + global HostAttrs + if HostAttrs == None: raise "No Hosts"; - - for x in HostKeys: + + for x in HostAttrs: if x[1].has_key("hostname") == 0 or \ x[1].has_key("sshRSAHostKey") == 0: continue; @@ -581,6 +613,9 @@ PasswdAttrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"uid=*",\ "shadowexpire","emailForward","latitude","longitude",\ "allowedHost","sshRSAAuthKey","dnsZoneEntry","cn","sn",\ "keyFingerPrint","privateSub"]); +# Fetch all the hosts +HostAttrs = l.search_s(HostBaseDn,ldap.SCOPE_ONELEVEL,"sshRSAHostKey=*",\ + ["hostname","sshRSAHostKey"]); # Open the control file if len(sys.argv) == 1: @@ -651,10 +686,10 @@ while(1): if ExtraList.has_key("[DNS]"): GenDNS(l,OutDir+"dns-zone",Split[1]); + GenSSHFP(l,OutDir+"dns-sshfp",Split[1]) if ExtraList.has_key("[BSMTP]"): - GenBSMTP(l,OutDir+"bsmtp",Split[1]); + GenBSMTP(l,OutDir+"bsmtp",Split[1]) if ExtraList.has_key("[PRIVATE]"): - DoLink(GlobalDir,OutDir,"debian-private"); - + DoLink(GlobalDir,OutDir,"debian-private") -- 2.20.1