-#!/usr/bin/env python
+y#!/usr/bin/env python
# -*- mode: python -*-
import string, re, time, ldap, getopt, sys, os, pwd;
# so we can only cut the search down slightly
def GetFreeID(l):
HighestUID = 1400;
- Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,
+ Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,
"uidnumber>="+str(HighestUID),["uidnumber"]);
HighestUID = 0;
for I in Attrs:
ID = int(GetAttr(I,"uidnumber","0"));
- if ID > HighestUID:
+ if ID > HighestUID:
HighestUID = ID;
return HighestUID + 1;
print "A matching key was found:"
GPGPrintKeyInfo(Keys[0]);
break;
-
-# Crack up the email address from the key into a best guess
+
+# Crack up the email address from the key into a best guess
# first/middle/last name
Addr = SplitEmail(Keys[0][2]);
(cn,mn,sn) = NameSplit(re.sub('["]','',Addr[0]))
if Res == "":
break;
+Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"keyfingerprint=" + Keys[0][1]);
+if len(Attrs) != 0:
+ print "*** This key already belongs to",GetAttr(Attrs[0],"uid");
+ account = GetAttr(Attrs[0],"uid");
+
# Try to get a uniq account name
Update=0
while 1:
print "Randomizing and encrypting password"
Password = GenPass();
Pass = HashPass(Password);
- print "PASS: ", Password;
# Use GPG to encrypt it, pass the fingerprint to ID it
CryptedPass = GPGEncrypt("Your new password is '" + Password + "'\n",\
Pass = None;
# Now we have all the bits of information.
-if mn != "":
+if mn != "":
FullName = "%s %s %s" % (cn,mn,sn);
else:
FullName = "%s %s" % (cn,sn);
Subst["__PRIVATE__"] = privsub;
Subst["__EMAIL__"] = email;
Subst["__PASSWORD__"] = CryptedPass;
-Subst["__LISTPASS__"] = string.strip(open(pwd.getpwuid(os.getuid())[5]+"/.debian-lists_passwd","r").read());
+#Subst["__LISTPASS__"] = string.strip(open(pwd.getpwuid(os.getuid())[5]+"/.debian-lists_passwd","r").read());
# Generate the LDAP request
Rec = [(ldap.MOD_REPLACE,"uid",account),
if Pass != None:
Rec.append((ldap.MOD_REPLACE,"userPassword","{crypt}"+Pass));
-# Submit the modification request
+# Submit the modification request
Dn = "uid=" + account + "," + BaseDn;
print "Updating LDAP directory..",
sys.stdout.flush();
# Child.write(Sub);
# if Child.close() != None:
# raise Error, "Sendmail gave a non-zero return code";
-
+
# Send the Welcome message
print "Sending Welcome Email"
Reply = TemplateSubst(Subst,open(TemplatesDir+"/welcome-message-"+gidnumber,"r").read());