diff --git a/luser/models.py b/luser/models.py index 6178a28..cda07e8 100644 --- a/luser/models.py +++ b/luser/models.py @@ -2,6 +2,9 @@ import ldap3 from ldap3 import Server,Connection,ALL,MODIFY_REPLACE from datetime import datetime +OBJECTCLASSES = ['top', 'person', 'organizationalPerson', 'inetOrgPerson', 'posixAccount', 'shadowAccount'] +USERATTRIBUTES = ['cn' , 'sn', 'givenName', 'uid', 'uidNumber' , 'gidNumber', 'homeDirectory', 'loginShell', 'gecos' , 'shadowLastChange', 'shadowMax', 'userPassword', 'mail', 'description'] + class LUSER(): ''' Class that represents secure connection to LDAP server @@ -161,6 +164,7 @@ class LUSER(): # Add user to base id = f"uid={user}" + lastlog = self.getlastlog() + 1 # Object classes of a user entry objectClass = ['top', 'person', 'organizationalPerson', 'inetOrgPerson', 'posixAccount', 'shadowAccount'] @@ -169,11 +173,10 @@ class LUSER(): attributes = {'cn' : user, 'sn' : user, 'givenName' : user, 'uid' : user, 'uidNumber' : self.lastuid, 'gidNumber' : self.lastgid, 'homeDirectory' : f'/home/{user}', 'loginShell' : '/usr/bin/git-shell', 'gecos' : 'SystemUser', 'shadowLastChange' : self.lastpwchangenow(), 'shadowMax' : '45', 'userPassword' : password, 'mail' : f'{user}@{self.domain}' } # Return boolean value of new user entry - rcode1 = self.ldapconnection.add(self.logbase, objectClass, attributes) + rcode1 = self.ldapconnection.add(f'uid={user},{self.base}', objectClass, attributes) # Add new user to log attributes['description'] = 'ADD' - lastlog = self.getlastlog() + 1 rcode2 = self.ldapconnection.add(f'uid={lastlog},{self.logbase}', objectClass, attributes)