From 237e7bd14eecc9d5982dd5e86ae91d0a6edc8822 Mon Sep 17 00:00:00 2001 From: fram3d Date: Tue, 20 Jun 2023 20:25:57 +0200 Subject: [PATCH] add all functionality for basealt --- luser/models.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/luser/models.py b/luser/models.py index e86aba6..b4244e5 100644 --- a/luser/models.py +++ b/luser/models.py @@ -13,12 +13,15 @@ class LUSER(): ''' - def expandbase(self): + def expandbase(self, basealt = ''): ''' Extract orgnaization, name of dc object and full domain part with all dc values from base ''' # Split base string with commas to find values of organization and dc - baselist = self.base.split(",") + if basealt == '': + baselist = self.base.split(",") + else: + baselist = self.basealt.split(",") organization = '' dc = '' @@ -54,8 +57,9 @@ class LUSER(): self.admin_user = admin_user self.admin_pass = admin_pass self.base = base - self.organization, self.dc, self.dcfull, self.domain = self.expandbase() self.basealt = basealt + self.organization, self.dc, self.dcfull, self.domain = self.expandbase() + self.organizationalt, self.dcalt, self.dcfullalt, self.domainalt = self.expandbase(self.basealt) self.alt = True self.autoconnect = autoconnect ldapserver = Server(ldap_host, use_ssl=True) @@ -82,9 +86,14 @@ class LUSER(): rcode2 = self.ldapconnection.add(self.base, ['top', 'organizationalUnit'], {'ou' : self.organization}) - # Return True only if all return values are true + # Add dcobject and organizational units as above for base alt + rcode3 = True + rcode4 = True + if self.alt: + rcode3 = self.ldapconnection.add(f'dc={self.dcfull}', ['dcObject', 'organization'], {'o' : self.dc, 'dc' : self.dc}) + rcode4 = self.ldapconnection.add(self.base, ['top', 'organizationalUnit'], {'ou' : self.organization}) - return rcode1 and rcode2 + return rcode1 and rcode2 and rcode3 and rcode4 def lastpwchangenow(self): ''' @@ -116,7 +125,7 @@ class LUSER(): # Attributes for a user entry 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}' } - attributesalt = {'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' : althash, 'mail' : f'{user}@{self.domain}'} + attributesalt = {'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' : althash, 'mail' : f'{user}@{self.domainalt}'} # Return boolean value of new user entry rcode1 = self.ldapconnection.add(f'{id},{self.base}', objectClass, attributes)