display all host keys, remove DSA key support
[mirror/userdir-ldap.git] / userdir_ldap.py
index a8b62fe..827d8b1 100644 (file)
@@ -32,6 +32,7 @@ LastNamesPre = {"van": None, "le": None, "de": None, "di": None};
 # SSH Key splitting. The result is:
 # (options,size,modulous,exponent,comment)
 SSHAuthSplit = re.compile('^(.* )?(\d+) (\d+) (\d+) ?(.+)$');
+SSH2AuthSplit = re.compile('^(.* )?ssh-(dss|rsa) ([a-zA-Z0-9=/+]+) (.+)$');
 #'^([^\d](?:[^ "]+(?:".*")?)*)? ?(\d+) (\d+) (\d+) (.+)$');
 
 AddressSplit = re.compile("(.*).*<([^@]*)@([^>]*)>");
@@ -213,10 +214,20 @@ def DecDegree(Posn,Anon=0):
      return "+" + Str;
   return Str;
 
+def FormatSSH2Auth(Str):
+   Match = SSH2AuthSplit.match(Str);
+   if Match == None:
+      return "<unknown format>";
+   G = Match.groups();
+
+   if G[0] == None:
+      return "ssh-%s %s..%s %s"%(G[1],G[2][:8],G[2][-8:],G[3]);
+   return "%s ssh-%s %s..%s %s"%(G[0],G[1],G[2][:8],G[2][-8:],G[3]);
+
 def FormatSSHAuth(Str):
    Match = SSHAuthSplit.match(Str);
    if Match == None:
-      return "<unknown format>";
+      return FormatSSH2Auth(Str);
    G = Match.groups();
 
    # No options
@@ -251,6 +262,10 @@ def FormatPGPKey(Str):
 
 # Take an email address and split it into 3 parts, (Name,UID,Domain)
 def SplitEmail(Addr):
+   # Is not an email address at all
+   if string.find(Addr,'@') == -1:
+      return (Addr,"","");
+  
    Res1 = rfc822.AddrlistClass(Addr).getaddress();
    if len(Res1) != 1:
       return ("","",Addr);
@@ -290,6 +305,11 @@ def GetUID(l,Name,UnknownMap = {}):
       Stat = "unknown map hit for"+str(Name);
       return (UnknownMap[Name[2]],[Stat]);
 
+   # Then the name component (another ie there was no email address to match)
+   if UnknownMap.has_key(Name[0]):
+      Stat = "unknown map hit for"+str(Name);
+      return (UnknownMap[Name[0]],[Stat]);
+  
    # Search for a possible first/last name hit
    try:
       Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"(&(cn=%s)(sn=%s))"%(cn,sn),["uid"]);