From 09c22b23a7495b97907865aa2b5032f4a25d4d18 Mon Sep 17 00:00:00 2001 From: fram3d Date: Thu, 28 Mar 2024 19:25:56 +0100 Subject: [PATCH] fix all new ldapsync issues --- luser/models.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/luser/models.py b/luser/models.py index cda07e8..c7ab154 100644 --- a/luser/models.py +++ b/luser/models.py @@ -21,7 +21,7 @@ class LUSER(): if response == []: response = 0 else: - response = int(response['attributes']['uidNumber']) + response = int(response[0]['attributes']['uidNumber']) return response def setlastlog(self, newvalue: int): @@ -31,10 +31,12 @@ class LUSER(): self.ldapconnection.search(search_base=f'uid=total,{self.logbase}',search_filter='(objectClass=person)', attributes=['uidNumber']) response = self.ldapconnection.response - if response == []: - self.ldapconnection.add(f'uid=total,{self.logbase}', OBJECTCLASSES, { 'uid' : 'total', 'uidNumber' : 0 }) + attributes = {'cn' : 'total', 'sn' : 'total', 'givenName' : 'total', 'uid' : 'total', 'uidNumber' : newvalue, 'gidNumber' : newvalue, 'homeDirectory' : f'/home/total', 'loginShell' : '/usr/bin/git-shell', 'gecos' : 'SystemUser', 'shadowLastChange' : self.lastpwchangenow(), 'shadowMax' : '45', 'userPassword' : 'total', 'mail' : f'total@{self.domain}' } - self.ldapconnection.modify(f'uid=total,{self.logbase}', {'uidNumber' : (ldap3.MODIFY_REPLACE, [newvalue])}) + if response == []: + self.ldapconnection.add(f'uid=total,{self.logbase}', OBJECTCLASSES, attributes) + else: + self.ldapconnection.modify(f'uid=total,{self.logbase}', {'uidNumber' : (ldap3.MODIFY_REPLACE, [newvalue])}) return self.ldapconnection.response @@ -175,6 +177,7 @@ class LUSER(): # Return boolean value of new user entry rcode1 = self.ldapconnection.add(f'uid={user},{self.base}', objectClass, attributes) + # Add new user to log attributes['description'] = 'ADD' @@ -186,7 +189,7 @@ class LUSER(): # Return True only if both entries was successful return rcode1 and rcode2 - def changepassword(self, user, newpass, althash=''): + def changepassword(self, user, newpass): ''' Change password of user to newpass @@ -203,7 +206,7 @@ class LUSER(): OBJECTCLASSES = ['top', 'person', 'organizationalPerson', 'inetOrgPerson', 'posixAccount', 'shadowAccount'] - self.ldapconnection.search(search_base=f'uid=username,{self.base}',search_filter='(objectClass=person)', attributes=USERATTRIBUTES) + self.ldapconnection.search(search_base=f'uid={user},{self.base}',search_filter='(objectClass=person)', attributes=USERATTRIBUTES) userdata = self.ldapconnection.response[0] userdata['attributes']['description'] = 'CHANGEPASS'