diff --git a/server/src/uds/core/util/ldaputil.py b/server/src/uds/core/util/ldaputil.py index cf2937fd8..cb77ecd13 100644 --- a/server/src/uds/core/util/ldaputil.py +++ b/server/src/uds/core/util/ldaputil.py @@ -169,3 +169,15 @@ def getFirst(con, base, objectClass, field, value, attributes=None, sizeLimit=50 return obj + +# Recursive delete +def recursive_delete(con, base_dn): + search = con.search_s(base_dn, ldap.SCOPE_ONELEVEL) + + for dn, _ in search: + # recursive_delete(conn, dn) + # RIGHT NOW IS NOT RECURSIVE, JUST 1 LEVEL BELOW!!! + con.delete_s(dn) + + con.delete_s(base_dn) + diff --git a/server/src/uds/osmanagers/WindowsOsManager/WinDomainOsManager.py b/server/src/uds/osmanagers/WindowsOsManager/WinDomainOsManager.py index 2a10bbc8b..f0b8f7b3d 100644 --- a/server/src/uds/osmanagers/WindowsOsManager/WinDomainOsManager.py +++ b/server/src/uds/osmanagers/WindowsOsManager/WinDomainOsManager.py @@ -209,10 +209,7 @@ class WinDomainOsManager(WindowsOsManager): res = self.__getMachine(l, service.friendly_name) if res is None: raise Exception('Machine {} not found on AD (permissions?)'.format(service.friendly_name)) - # # - # Direct LDAP operation "modify", maybe this need to be added to ldaputil? :) - # # - l.delete_s(res) # Remove by DN, SYNC + ldaputil.recursive_delete(l, res) except IndexError: logger.error('Error deleting {} from BASE {}'.format(service.friendly_name, self._ou)) except Exception: