Commit 13acae44 authored by Imran Hussain's avatar Imran Hussain
Browse files

Add some sanity checks to the delete function

parent 5a4d53a7
......@@ -262,10 +262,22 @@ def deleteUser(peopleList):
cur.execute("SELECT * from members WHERE username=%(user)s",{"user" : person[0]})
userDBinfo = cur.fetchall()
cur.close()
# fail safe, if the DB username we just got isn't the one we are
# messing with, die
if str(person[0]) != userDBinfo[0][1]:
print("Something went wrong getting info from DB, quitting! NO CHNAGES MADE")
sys.exit(9)
# get all their info from the ldap
userLDAPinfo = ldapconn.search_s(ldap_base,ldap.SCOPE_SUBTREE,"uid="+str(person[0]))
# fail safe, if the ldap username we just got isn't the one we
# are messing with, die
if str(person[0]) != userLDAPinfo[0][1]["uid"][0]:
print("Something went wrong getting info from LDAP, quitting! NO CHNAGES MADE")
sys.exit(9)
# declare some easy to use vars
username = str(person[0])
persondir = basedir+"/"+username
......@@ -281,12 +293,23 @@ def deleteUser(peopleList):
ldapbackupfile = open("./ldap-ldif", "w")
subprocess.call(["sudo", "ldapsearch", "-x", "-D", ldap_manager, "-y", ldap_manager_pass, "-L", "(uid="+username+")"], stdout=ldapbackupfile)
ldapbackupfile.close()
# sanity check we have a legit backup
if "# numEntries: 1" not in open("./ldap-ldif").read():
print("Something went wrong getting a backup LDAP entry, quitting! NO CHNAGES MADE")
sys.exit(9)
else:
print("LDAP Backup made!")
subprocess.call(['sudo', 'mv', "-f", "./ldap-ldif", persondir+"/ldap-ldif"])
# delete them from ldap
# ldapconn.delete_s(ldap_base,ldap.SCOPE_SUBTREE,"uid="+str(person[0]))
# sudo ldapdelete -D "cn=Manager,dc=sucs,dc=org" -y /etc/ldap.secret "uid=imran,ou=people,dc=sucs,dc=org"
subprocess.call(["sudo", "ldapdelete", "-D", ldap_manager, "-y", ldap_manager_pass, userLDAPinfo[0][0]])
rc = subprocess.call(["sudo", "ldapdelete", "-D", ldap_manager, "-y", ldap_manager_pass, userLDAPinfo[0][0]])
# sanity check ldap delete happened
if int(rc) != 0:
print("Something went wrong deleting the LDAP entry, quitting! NO CHNAGES MADE")
sys.exit(9)
# move their homedir to the deleted folder
subprocess.call(['sudo', 'mv', "-f", userLDAPinfo[0][1]["homeDirectory"][0], persondir+"/homedir"])
......
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