From cd9592c7cb7c2ba03afcfb9de55cf848cf642edc Mon Sep 17 00:00:00 2001 From: fram3d Date: Thu, 11 Apr 2024 11:33:12 +0200 Subject: [PATCH] add clone function --- lgit.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lgit.py b/lgit.py index a4125ed..2465a74 100755 --- a/lgit.py +++ b/lgit.py @@ -303,6 +303,34 @@ l dc values from base return pushed + def clone(self, source)->int: + # Delete all users from this server + self.conn.search(search_base=source.base,search_filter='(objectClass=person)', attributes=USERATTRIBUTES) + response = self.conn.response + if response != []: + for user in response: + uid = user.attributes['uid'] + if isinstance(uid, list): + uid = uid[0] + self.conn.delete(f'uid={uid},{self.base}') + # Copy all users from source server + cloned = 0 + source.conn.search(search_base=source.base,search_filter='(objectClass=person)', attributes=USERATTRIBUTES) + response = source.conn.response + if response == []: + return 0 + else: + for user in response: + attributes = user.attributes + # If attribute returned as list, take only first element + for key in attributes: + if isinstance(attributes[key], list): + attributes[key] = attributes[key][0] + uid = attributes['uid'] + self.conn.add(f'uid={uid},{self.base}', OBJECTCLASSES, attributes) + cloned += 1 + return cloned + def lastpwchangenow(self): ''' Return time of last password change for the user set to current time