Commit 79c1e661 authored by Andrea Veri's avatar Andrea Veri

Improve the script removing some useless functions

parent 340ec2ae
......@@ -13,19 +13,7 @@ LDAP_GROUP_BASE='cn=groups,cn=accounts,dc=gnome,dc=org'
LDAP_USER_BASE='cn=users,cn=accounts,dc=gnome,dc=org'
file = open('/home/admin/secret/freeipa','r')
lines = file.readlines()
for line in lines:
if line.find("ldap_password") > -1:
dirty_password = line.split()
ldap_password = str(dirty_password)
sanitize_file=["ldap_password", "\"", "[", "]", "=", "'"]
for i in range(len(sanitize_file)):
ldap_password = ldap_password.replace(sanitize_file[i],"")
file.close()
execfile('/home/admin/secret/freeipa')
try:
l = ldap.open('localhost')
......@@ -41,10 +29,8 @@ def _parse_members_from_group(group):
results = l.search_s(LDAP_GROUP_BASE, ldap.SCOPE_SUBTREE, filter, ('memberUid', ))
members = set()
for entry in results:
id = entry[0]
attr = entry[1]
for _, attr in results:
members.update(attr['memberUid'])
......@@ -100,43 +86,17 @@ def check_existing_password(userid):
print 'You are not allowed to reset your password, please contact the GNOME Sysadmin Team to know why'
sys.exit(1)
try:
userpassword = _get_attributes_from_ldap(userid, 'userPassword')
except KeyError:
add_new_password(userid)
else:
update_existing_password(userid)
def update_existing_password(userid):
dn = 'uid=%s,%s' % (userid, LDAP_USER_BASE)
getattr_userpassword = _get_attributes_from_ldap(userid, 'userPassword')
getattr_name = _get_attributes_from_ldap(userid, 'cn')
getattr_mail = _get_attributes_from_ldap(userid, 'mail')
old_password = getattr_userpassword[userid]
password = {'userPassword': '%s' % (old_password)}
newpassword = {'userPassword': gen_passwd(length=20)}
ldif = modlist.modifyModlist(password, newpassword)
l.modify_s(dn, ldif)
send_password_to_user(getattr_name[userid], getattr_mail[userid], newpassword['userPassword'])
update_password(userid)
def add_new_password(userid):
dn = 'uid=%s,%s' % (userid, LDAP_USER_BASE)
def update_password(userid):
getattr_name = _get_attributes_from_ldap(userid, 'cn')
getattr_mail = _get_attributes_from_ldap(userid, 'mail')
nopassword = {'userPassword': ''}
newpassword = {'userPassword': gen_passwd(length=20)}
newpassword = {'userPassword': gen_passwd()}
ldif = modlist.modifyModlist(nopassword, newpassword)
l.modify_s(dn, ldif)
add_members = [(ldap.MOD_REPLACE, 'userPassword', newpassword['userPassword'])]
l.modify_s('uid=%s,cn=users,cn=accounts,dc=gnome,dc=org' % userid, add_members)
send_password_to_user(getattr_name[userid], getattr_mail[userid], newpassword['userPassword'])
......@@ -144,7 +104,7 @@ def add_new_password(userid):
def send_password_to_user(name, email, password):
form_letter = """
Hello %s, your password has been reset successfully and is available here:
Hello %s, your password has been reset successfully. Your temporary password is
%s
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment