Use the common routine from userdir_ldap.py which asks for the
[mirror/userdir-ldap.git] / ud-killcrypt
1 #!/usr/bin/env python
2 # -*- mode: python -*-
3
4 import string, re, time, ldap, getopt, sys, pwd, os, posix;
5 from userdir_ldap import *;
6
7 # Main program starts here
8 User = pwd.getpwuid(posix.getuid())[0];
9 BindUser = User;
10 (options, arguments) = getopt.getopt(sys.argv[1:], "au:")
11 for (switch, val) in options:
12     if (switch == '-u'):
13         User = val;
14     if (switch == '-a'):
15         Anon = 1;
16                               
17 # Connect to the ldap server
18 l = passwdAccessLDAP(LDAPServer, BaseDn, User)
19
20 Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"userpassword=*",\
21          ["uid","cn","mn","sn","userpassword"]);
22
23 Attrs.sort();
24 for x in Attrs:
25     if x[1].has_key("userpassword") == 0: continue;
26     Passwd = x[1]["userpassword"][0];
27     if string.find(Passwd,"*LK*") != -1 or string.find(Passwd,"}*") != -1:
28         continue;
29     if len(Passwd) > 21: continue;
30     
31     print EmailAddress(x);
32
33     UserDn = "uid=" + x[1]["uid"][0] + "," + BaseDn;
34     Password = GenPass();
35     Pass = "{crypt}" + HashPass(Password);
36     l.modify_s(UserDn,[(ldap.MOD_REPLACE,"userpassword",Pass)]);