From 15e4c949d33a321d06babdba6850103faad582f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Thu, 10 May 2018 12:32:10 +0200 Subject: [PATCH] Now the machine removal on windows takes care of child nodes.. (We have noticed that Hyperv server 2016 creates a "node" behind machines on domain) --- server/src/uds/core/util/ldaputil.py | 12 ++++++++++++ .../WindowsOsManager/WinDomainOsManager.py | 5 +---- 2 files changed, 13 insertions(+), 4 deletions(-) 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: