Added proper copyright notice
[mirror/userdir-ldap.git] / ud-killcrypt
1 #!/usr/bin/env python
2 # -*- mode: python -*-
3
4 #   Copyright (c) 2001       Jason Gunthorpe <jgg@debian.org>
5 #   Copyright (c) 2004       Joey Schulze <joey@debian.org>
6 #
7 #   This program is free software; you can redistribute it and/or modify
8 #   it under the terms of the GNU General Public License as published by
9 #   the Free Software Foundation; either version 2 of the License, or
10 #   (at your option) any later version.
11 #
12 #   This program is distributed in the hope that it will be useful,
13 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #   GNU General Public License for more details.
16 #
17 #   You should have received a copy of the GNU General Public License
18 #   along with this program; if not, write to the Free Software
19 #   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 import string, re, time, ldap, getopt, sys, pwd, os, posix;
22 from userdir_ldap import *;
23
24 # Main program starts here
25 User = pwd.getpwuid(posix.getuid())[0];
26 BindUser = User;
27 (options, arguments) = getopt.getopt(sys.argv[1:], "au:")
28 for (switch, val) in options:
29     if (switch == '-u'):
30         User = val;
31     if (switch == '-a'):
32         Anon = 1;
33                               
34 # Connect to the ldap server
35 l = passwdAccessLDAP(LDAPServer, BaseDn, User)
36
37 Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"userpassword=*",\
38          ["uid","cn","mn","sn","userpassword"]);
39
40 Attrs.sort();
41 for x in Attrs:
42     if x[1].has_key("userpassword") == 0: continue;
43     Passwd = x[1]["userpassword"][0];
44     if string.find(Passwd,"*LK*") != -1 or string.find(Passwd,"}*") != -1:
45         continue;
46     if len(Passwd) > 21: continue;
47     
48     print EmailAddress(x);
49
50     UserDn = "uid=" + x[1]["uid"][0] + "," + BaseDn;
51     Password = GenPass();
52     Pass = "{crypt}" + HashPass(Password);
53     l.modify_s(UserDn,[(ldap.MOD_REPLACE,"userpassword",Pass)]);