import string, re, time, ldap, getopt, sys, os, pwd, posix, socket;
from userdir_ldap import *;
+global Allowed;
+global CurrentHost;
+
PasswdAttrs = None;
GroupIDMap = {};
Allowed = None;
# See if this user is in the group list
def IsInGroup(DnRecord):
- global Allowed,CurrentHost;
if Allowed == None:
return 1;
def GenPasswd(l,File,HomePrefix):
F = None;
try:
- F = open(File + ".tmp","w");
+ F = open(File + ".tdb.tmp","w");
# Fetch all the users
global PasswdAttrs;
if PasswdAttrs == None:
raise "No Users";
+ I = 0;
for x in PasswdAttrs:
if x[1].has_key("uidnumber") == 0 or IsInGroup(x) == 0:
continue;
if len(GetAttr(x,"gecos")) > 100 or len(GetAttr(x,"loginshell")) > 50:
continue;
- Line = "%s:x:%s:%s:%s:%s%s:%s\n" % (GetAttr(x,"uid"),\
+ Line = "%s:x:%s:%s:%s:%s%s:%s" % (GetAttr(x,"uid"),\
GetAttr(x,"uidnumber"),GetAttr(x,"gidnumber"),\
GetAttr(x,"gecos"),HomePrefix,GetAttr(x,"uid"),\
GetAttr(x,"loginshell"));
- F.write(Line);
+
+ Line = Sanitize(Line) + "\n";
+ F.write("0%u %s" % (I,Line));
+ F.write(".%s %s" % (GetAttr(x,"uid"),Line));
+ F.write("=%s %s" % (GetAttr(x,"uidnumber"),Line));
+ I = I + 1;
# Oops, something unspeakable happened.
except:
- Die(File,F,None);
+ Die(File,None,F);
raise;
- Done(File,F,None);
+ Done(File,None,F);
# Generate the shadow list
def GenShadow(l,File):
F = None;
try:
OldMask = os.umask(0077);
- F = open(File + ".tmp","w",0600);
+ F = open(File + ".tdb.tmp","w",0600);
os.umask(OldMask);
# Fetch all the users
if PasswdAttrs == None:
raise "No Users";
+ I = 0;
for x in PasswdAttrs:
if x[1].has_key("uidnumber") == 0 or IsInGroup(x) == 0:
continue;
GetAttr(x,"shadowwarning"),GetAttr(x,"shadowinactive"),\
GetAttr(x,"shadowexpire"));
Line = Sanitize(Line) + "\n";
- F.write(Line);
+ F.write("0%u %s" % (I,Line));
+ F.write(".%s %s" % (GetAttr(x,"uid"),Line));
+ I = I + 1;
# Oops, something unspeakable happened.
except:
- Die(File,F,None);
+ Die(File,None,F);
raise;
- Done(File,F,None);
+ Done(File,None,F);
# Generate the shadow list
def GenSSHShadow(l,File):
def GenGroup(l,File):
F = None;
try:
- F = open(File + ".tmp","w");
+ F = open(File + ".tdb.tmp","w");
# Generate the GroupMap
GroupMap = {};
print "Group does not exist ",I,"but",GetAttr(x,"uid"),"is in it";
# Output the group file.
+ J = 0;
for x in GroupMap.keys():
if GroupIDMap.has_key(x) == 0:
continue;
Line = Line + ("%s%s" % (Comma,I));
Comma = ',';
Line = Sanitize(Line) + "\n";
- F.write(Line);
+ F.write("0%u %s" % (J,Line));
+ F.write(".%s %s" % (x,Line));
+ F.write("=%u %s" % (GroupIDMap[x],Line));
+ J = J + 1;
# Oops, something unspeakable happened.
except:
- Die(File,F,None);
+ Die(File,None,F);
raise;
- Done(File,F,None);
+ Done(File,None,F);
# Generate the email forwarding list
def GenForward(l,File):
Done(File,F,Fdb);
# Generate the DNS Zone file
-def GenDNS(l,File,BSMTPFile,HomePrefix):
+def GenDNS(l,File,HomePrefix):
F = None;
- FB = None;
try:
F = open(File + ".tmp","w");
- FB = open(BSMTPFile + ".tmp","w");
# Fetch all the users
global PasswdAttrs;
Host = Split[0] + DNSZone;
if BSMTPCheck.match(Line) != None:
F.write("; Has BSMTP\n");
- FB.write("%s: user=%s group=Debian file=%s%s/bsmtp/%s\n"%(Host,
- GetAttr(x,"uid"),HomePrefix,GetAttr(x,"uid"),Host));
# Write some identification information
if string.lower(Split[2]) == "a":
# Oops, something unspeakable happened.
except:
Die(File,F,None);
- Die(BSMTPFile,FB,None);
raise;
Done(File,F,None);
- Done(BSMTPFile,FB,None);
+
+# Generate the BSMTP file
+def GenBSMTP(l,File,HomePrefix):
+ F = None;
+ try:
+ F = open(File + ".tmp","w");
+
+ # Fetch all the users
+ global PasswdAttrs;
+ if PasswdAttrs == None:
+ raise "No Users";
+
+ # Write out the zone file entry for each user
+ for x in PasswdAttrs:
+ if x[1].has_key("dnszoneentry") == 0:
+ continue;
+ try:
+ for z in x[1]["dnszoneentry"]:
+ Split = string.split(string.lower(z));
+ if string.lower(Split[1]) == 'in':
+ for y in range(0,len(Split)):
+ if Split[y] == "$":
+ Split[y] = "\n\t";
+ Line = string.join(Split," ") + "\n";
+
+ Host = Split[0] + DNSZone;
+ if BSMTPCheck.match(Line) != None:
+ F.write("%s: user=%s group=Debian file=%s%s/bsmtp/%s\n"%(Host,
+ GetAttr(x,"uid"),HomePrefix,GetAttr(x,"uid"),Host));
+
+ except:
+ F.write("; Errors\n");
+ pass;
+
+ # Oops, something unspeakable happened.
+ except:
+ Die(File,F,None);
+ raise;
+ Done(File,F,None);
# Generate the shadow list
def GenSSHKnown(l,File):
if GroupIDMap.has_key(I):
GroupList[str(GroupIDMap[I])] = None;
- global Allowed,CurrentHost;
Allowed = GroupList;
CurrentHost = Split[0];
DoLink(GlobalDir,OutDir,"forward-alias");
if ExtraList.has_key("[DNS]"):
- GenDNS(l,OutDir+"dns-zone",OutDir+"bsmtp",Split[1]);
+ GenDNS(l,OutDir+"dns-zone",Split[1]);
+ if ExtraList.has_key("[BSMTP]"):
+ GenBSMTP(l,OutDir+"bsmtp",Split[1]);
+
if ExtraList.has_key("[PRIVATE]"):
DoLink(GlobalDir,OutDir,"debian-private");
+