# -*- mode: python -*-
# Generates passwd, shadow and group files from the ldap directory.
-import string, re, time, ldap, getopt, sys, os, pwd, posix;
+import string, re, time, ldap, getopt, sys, os, pwd, posix, socket;
from userdir_ldap import *;
PasswdAttrs = None;
Done(File,F,None);
Done(BSMTPFile,FB,None);
+# Generate the shadow list
+def GenSSHKnown(l,File):
+ F = None;
+ Fdb = None;
+ try:
+ OldMask = os.umask(0022);
+ F = open(File + ".tmp","w",0644);
+ Fdb = os.popen("cdbmake %s.cdb %s.cdb.tmp"%(File,File),"w");
+ os.umask(OldMask);
+
+ # Fetch all the hosts
+ HostKeys = l.search_s(HostBaseDn,ldap.SCOPE_ONELEVEL,"sshrsahostkey=*",\
+ ["hostname","sshrsahostkey"]);
+
+ if HostKeys == None:
+ raise "No Hosts";
+
+ I = 0;
+ for x in HostKeys:
+ if x[1].has_key("hostname") == 0 or \
+ x[1].has_key("sshrsahostkey") == 0:
+ continue;
+ Host = GetAttr(x,"hostname");
+ SHost = string.find(Host,".");
+ 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 = Sanitize(Line) + "\n";
+ F.write(Line);
+ Fdb.write("+%d,%d:%s->%s\n"%(len(Host),len(I),Host,I));
+ Fdb.write("\n");
+ # Oops, something unspeakable happened.
+ except:
+ Die(File,F,Fdb);
+ raise;
+ if Fdb.close() != None:
+ raise "cdbmake gave an error";
+ Done(File,F,None);
+
+
# Connect to the ldap server
l = ldap.open(LDAPServer);
F = open(PassDir+"/pass-"+pwd.getpwuid(os.getuid())[0],"r");
GenAllForward(l,GlobalDir+"mail-forward.cdb");
GenMarkers(l,GlobalDir+"markers");
GenPrivate(l,GlobalDir+"debian-private");
+GenSSHKnown(l,GlobalDir+"ssh_known_hosts");
# Compatibility.
GenForward(l,GlobalDir+"forward-alias");
DoLink(GlobalDir,OutDir,"ssh-rsa-shadow.cdb");
DoLink(GlobalDir,OutDir,"markers");
DoLink(GlobalDir,OutDir,"mail-forward.cdb");
+ DoLink(GlobalDir,OutDir,"ssh_known_hosts");
# Compatibility.
DoLink(GlobalDir,OutDir,"forward-alias");