3 # check password quality using cracklib given a new password, optionally the
4 # old password, and a list of ldap/gecos words via stdin, each on a line by
5 # itself (send an empty line if you want to skip the old password check)
7 # Copyright (c) 2008 Peter Palfrader
9 import crack, sys, tempfile, os
12 if not dir.startswith('/tmp/pwcheck-'):
13 raise ValueError, 'cleanup got a weird dir to remove: '+dir
14 for f in 'dict.hwm dict.pwd dict.pwi wordlist wordlist-cleaned'.split(' '):
18 if os.path.exists(dir):
23 newpass = sys.stdin.readline().strip()
24 oldpass = sys.stdin.readline().strip()
25 ldapwords = map( lambda x: x.strip(), sys.stdin.readlines())
33 # check against the default dictionary
35 crack.VeryFascistCheck(newpass, oldpass)
40 # and against a dictionary created from the ldap info on this user
41 if len(ldapwords) > 0:
42 tmpdir = tempfile.mkdtemp('', 'pwcheck-')
43 F = open(tmpdir+'/wordlist', "w")
49 F.write(w1[0]+w2+"\n");
52 r = os.system("/usr/sbin/crack_mkdict "+tmpdir+"/wordlist > "+tmpdir+"/wordlist-cleaned")
54 print "crack_mkdict returned non-zero exit status %d."%(r)
57 r = os.system("/usr/sbin/crack_packer "+tmpdir+"/dict < "+tmpdir+"/wordlist-cleaned > /dev/null")
59 print "crack_packer returned non-zero exit status %d."%(r)
64 crack.VeryFascistCheck(newpass, None, tmpdir+"/dict")
66 print "ldap data based check: "+str(e)