feat(password-recovery): Add LDAP password recovery

This commit is contained in:
smizrahi
2022-10-16 14:46:19 +02:00
parent cddfdb90f9
commit d50080ea5b
5 changed files with 65 additions and 16 deletions
+61 -10
View File
@@ -708,6 +708,39 @@ groupObjectClasses: (NSArray *) newGroupObjectClasses
return didChange;
}
- (BOOL) _ldapAdminModifyAttribute: (NSString *) theAttribute
withValue: (NSString *) theValue
userDN: (NSString *) theUserDN
connection: (NGLdapConnection *) bindConnection
{
NGLdapModification *mod;
NGLdapAttribute *attr;
NSArray *changes;
BOOL didChange;
attr = [[NGLdapAttribute alloc] initWithAttributeName: theAttribute];
[attr addStringValue: theValue];
mod = [NGLdapModification replaceModification: attr];
changes = [NSArray arrayWithObject: mod];
if ([bindConnection bindWithMethod: @"simple"
binddn: _bindDN
credentials: _password])
{
didChange = [bindConnection modifyEntryWithDN: theUserDN
changes: changes];
}
else
didChange = NO;
RELEASE(attr);
return didChange;
}
/**
* Change a user's password.
* @param login the user's login name.
@@ -787,20 +820,38 @@ groupObjectClasses: (NSArray *) newGroupObjectClasses
if (encryptedPass != nil)
{
if ([bindConnection bindWithMethod: @"simple"
if (!passwordRecovery) {
if ([bindConnection bindWithMethod: @"simple"
binddn: userDN
credentials: oldPassword])
{
didChange = [self _ldapModifyAttribute: @"userPassword"
withValue: encryptedPass
userDN: userDN
password: oldPassword
connection: bindConnection];
if (didChange)
{
*perr = PolicyNoError;
didChange = [self _ldapModifyAttribute: @"userPassword"
withValue: encryptedPass
userDN: userDN
password: oldPassword
connection: bindConnection];
if (didChange)
{
*perr = PolicyNoError;
}
}
}
} else {
// Password recovery
// As old password is unknown, we use admin binding
if ([bindConnection bindWithMethod: @"simple"
binddn: _bindDN
credentials: _password])
{
didChange = [self _ldapAdminModifyAttribute: @"userPassword"
withValue: encryptedPass
userDN: userDN
connection: bindConnection];
if (didChange)
{
*perr = PolicyNoError;
}
}
}
}
}