From 2b8c5ea453b6f1e656aa82a8c736101f5bb25506 Mon Sep 17 00:00:00 2001 From: fram3d Date: Fri, 5 Apr 2024 15:48:10 +0200 Subject: [PATCH] fix log numbering --- luser/models.py | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/luser/models.py b/luser/models.py index c7ab154..7d8ae21 100644 --- a/luser/models.py +++ b/luser/models.py @@ -181,7 +181,10 @@ class LUSER(): # Add new user to log attributes['description'] = 'ADD' - rcode2 = self.ldapconnection.add(f'uid={lastlog},{self.logbase}', objectClass, attributes) + if rcode1: + rcode2 = self.ldapconnection.add(f'uid={lastlog},{self.logbase}', objectClass, attributes) + else: + return False if rcode2: self.setlastlog(lastlog) @@ -213,16 +216,19 @@ class LUSER(): lastlog = self.getlastlog() + 1 - rcode1 = self.ldapconnection.add(f'uid={lastlog},{self.logbase}', OBJECTCLASSES, userdata['attributes']) + chpassbool = self.ldapconnection.modify(f'uid={user},{self.base}', {'userPassword': (MODIFY_REPLACE,[newpass])}) + chlastchangebool = self.ldapconnection.modify(f'uid={user},{self.base}', {'shadowLastChange' : (MODIFY_REPLACE,[self.lastpwchangenow()])}) - if rcode1: - self.setlastlog(lastlog) - chpassbool = self.ldapconnection.modify(f'uid={user},{self.base}', {'userPassword': (MODIFY_REPLACE,[newpass])}) + if chpassbool and chlastchangebool: + rcode1 = self.ldapconnection.add(f'uid={lastlog},{self.logbase}', OBJECTCLASSES, userdata['attributes']) - chlastchangebool = self.ldapconnection.modify(f'uid={user},{self.base}', {'shadowLastChange' : (MODIFY_REPLACE,[self.lastpwchangenow()])}) - - # Return True only if changing of both password and time of last password change was successful - return chpassbool and chlastchangebool + if rcode1: + self.setlastlog(lastlog) + return True + else: + return False + else: + return False def delete(self, user): ''' @@ -242,13 +248,19 @@ class LUSER(): lastlog = self.getlastlog() + 1 - rcode1 = self.ldapconnection.add(f'uid={lastlog},{self.logbase}', OBJECTCLASSES, userdata['attributes']) + + rcode1 = self.ldapconnection.delete(f'uid={user},{self.base}') if rcode1: - self.setlastlog(lastlog) - rcode2 = self.ldapconnection.delete(f'uid={user},{self.base}') + rcode2 = self.ldapconnection.add(f'uid={lastlog},{self.logbase}', OBJECTCLASSES, userdata['attributes']) - return rcode1 and rcode2 + if rcode2: + self.setlastlog(lastlog) + return True + else: + return False + else: + return False def getpassword(self, user): '''