From 008e901ad68a5cde4065b6cfaf43682de4b4ba2f Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Fri, 15 Mar 2019 13:35:12 -0400 Subject: [PATCH] (fix) we update the baseDN placeholders of all LDAP sources upon login --- SoObjects/SOGo/LDAPSource.m | 26 ++++++++++++++++---------- SoObjects/SOGo/SOGoUserManager.m | 5 ++++- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/SoObjects/SOGo/LDAPSource.m b/SoObjects/SOGo/LDAPSource.m index ede738a7f..3ce7fd027 100644 --- a/SoObjects/SOGo/LDAPSource.m +++ b/SoObjects/SOGo/LDAPSource.m @@ -529,10 +529,8 @@ groupObjectClasses: (NSArray *) newGroupObjectClasses grace: (int *) _grace { NGLdapConnection *bindConnection; - NSMutableString *s; NSString *userDN; BOOL didBind; - NSRange r; didBind = NO; @@ -542,14 +540,7 @@ groupObjectClasses: (NSArray *) newGroupObjectClasses // We check if SOGo admins have deviced a top-level SOGoUserSources with a dynamic base DN. // This is a supported multi-domain configuration. We alter the baseDN in this case by extracting // the domain from the login. - r = [_login rangeOfString: @"@"]; - if (r.location != NSNotFound && - [_pristineBaseDN rangeOfString: @"%d"].location != NSNotFound) - { - s = [NSMutableString stringWithString: _pristineBaseDN]; - [s replaceOccurrencesOfString: @"%d" withString: [_login substringFromIndex: r.location+1] options: 0 range: NSMakeRange(0, [s length])]; - ASSIGN(_baseDN, s); - } + [self updateBaseDNFromLogin: _login]; bindConnection = [[NGLdapConnection alloc] initWithHostName: _hostname port: _port]; @@ -1971,4 +1962,19 @@ _makeLDAPChanges (NGLdapConnection *ldapConnection, return result; } +- (void) updateBaseDNFromLogin: (NSString *) theLogin +{ + NSMutableString *s; + NSRange r; + + r = [theLogin rangeOfString: @"@"]; + if (r.location != NSNotFound && + [_pristineBaseDN rangeOfString: @"%d"].location != NSNotFound) + { + s = [NSMutableString stringWithString: _pristineBaseDN]; + [s replaceOccurrencesOfString: @"%d" withString: [theLogin substringFromIndex: r.location+1] options: 0 range: NSMakeRange(0, [s length])]; + ASSIGN(_baseDN, s); + } +} + @end diff --git a/SoObjects/SOGo/SOGoUserManager.m b/SoObjects/SOGo/SOGoUserManager.m index 7950bf7e6..ab280141e 100644 --- a/SoObjects/SOGo/SOGoUserManager.m +++ b/SoObjects/SOGo/SOGoUserManager.m @@ -683,7 +683,9 @@ static Class NSNullK; // We MUST, for all LDAP sources, update the bindDN and bindPassword // to the user's value if bindAsCurrentUser is set to true in the - // LDAP source configuration + // LDAP source configuration. + // + // We also update the baseDN of all sources. if (checkOK) { NSObject *currentSource; @@ -697,6 +699,7 @@ static Class NSNullK; { [currentSource setBindDN: [currentSource lookupDNByLogin: _login]]; [currentSource setBindPassword: _pwd]; + [currentSource updateBaseDNFromLogin: _login]; } }