Add IPv6-Adresses (and IPv4 in v6 notation - ::ffff:192.0.2.1) to ssh_known_hosts...
authorPeter Palfrader <peter@palfrader.org>
Wed, 14 May 2008 15:37:21 +0000 (17:37 +0200)
committerPeter Palfrader <peter@palfrader.org>
Wed, 14 May 2008 15:37:21 +0000 (17:37 +0200)
debian/changelog
ud-generate

index 38afa81..d937a98 100644 (file)
@@ -2,8 +2,10 @@ userdir-ldap (0.3.21+X) Xunstable; urgency=low
 
   * Add VoIP fiels to the LDAP shema and teach ud-info and ud-mailgate
     about it. [zobel]
+  * Add IPv6-Adresses (and IPv4 in v6 notation - ::ffff:192.0.2.1) to
+    ssh_known_hosts. [aba]
 
- -- Peter Palfrader <weasel@debian.org>  Wed, 14 May 2008 17:31:22 +0200
+ -- Peter Palfrader <weasel@debian.org>  Wed, 14 May 2008 17:33:47 +0200
 
 userdir-ldap (0.3.21) unstable; urgency=low
 
index b5594fe..d2f00ab 100755 (executable)
@@ -718,12 +718,23 @@ def GenSSHKnown(l,File):
          x[1].has_key("sshRSAHostKey") == 0:
          continue;
       Host = GetAttr(x,"hostname");
+      HostNames = [ Host ]
       SHost = Host.find(".")
+      if SHost != None: HostNames += [Host[0:SHost]]
+
+      IPAdressesT = None
+      IPAdresses = []
+      # get IP adresses back as "proto adress" to distinguish between v4 and v6
+      try:
+         IPAdressesT = set([ (a[0],a[4][0]) for a in socket.getaddrinfo(Host, None)])
+      except:
+         if code[0] != -2: raise
+      for addr in IPAdressesT:
+         if addr[0] == socket.AF_INET: IPAdresses += [addr[1], "::ffff:"+addr[1]]
+        else: IPAdresses += [addr[1]]
+
       for I in x[1]["sshRSAHostKey"]:
-         if SHost == None:
-            Line = "%s,%s %s" %(Host,socket.gethostbyname(Host),I);
-         else:
-            Line = "%s,%s,%s %s" %(Host,Host[0:SHost],socket.gethostbyname(Host),I);
+         Line = "%s,%s %s" %(",".join(HostNames + IPAdresses), I);
          Line = Sanitize(Line) + "\n";
          F.write(Line);
   # Oops, something unspeakable happened.