[SUCS Devel] [Git][sucs/accountmanager][master] 2 commits: fix a bug and add a deletion completion message

Imran Hussain imranh at sucs.org
Sun Mar 10 17:14:21 GMT 2019


Imran Hussain pushed to branch master at sucs / accountmanager


Commits:
5a4d53a7 by Imran Hussain at 2019-03-10T16:50:20Z
fix a bug and add a deletion completion message

- - - - -
13acae44 by Imran Hussain at 2019-03-10T17:14:04Z
Add some sanity checks to the delete function

- - - - -


1 changed file:

- sucsam.py


Changes:

=====================================
sucsam.py
=====================================
@@ -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"])
@@ -325,6 +348,8 @@ def deleteUser(peopleList):
 		cur.close()
 
 		# notify people
+		# us
+		print(username + " was successfully deleted on " + str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")))
 		# them
 		emailDeletedUser(userDBinfo)
 		# logs@
@@ -424,7 +449,7 @@ def deleteMenu(deleteArray):
 				print("Adding " + str(soc[0]) + " to the list because the DB says: " + str(soc[1]))
 				deleteArray.append(soc[0])
 		for ass in associatesBad:
-			if ass == "delete":
+			if ass[1] == "delete":
 				print("Adding " + str(ass[0]) + " to the list because the DB says: " + str(ass[1]))
 				deleteArray.append(ass[0])
 		deleteMenu(deleteArray)



View it on GitLab: https://projects.sucs.org/sucs/accountmanager/compare/2d57b684f5d88d02d891c5b391f5bdcfbed734e9...13acae440cf45eb31df7947df1afce17ba98ebf4

-- 
View it on GitLab: https://projects.sucs.org/sucs/accountmanager/compare/2d57b684f5d88d02d891c5b391f5bdcfbed734e9...13acae440cf45eb31df7947df1afce17ba98ebf4
You're receiving this email because of your account on projects.sucs.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sucs.org/pipermail/devel/attachments/20190310/1fbf3c84/attachment-0001.html>


More information about the Devel mailing list