Skip to content

Commit 58e4fa7

Browse files
committed
If the passwd exop is not supported allow setting unicodePwd for AD
Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent 3f56c40 commit 58e4fa7

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

lib/LDAPUserManager.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,11 @@ public function setPassword($uid, $password, $connection = null) {
376376
} else {
377377
// Fallback to `userPassword` in case the server does not support exop_passwd
378378
$entry = [];
379-
$entry['userPassword' => $password]
379+
if ($this->configuration->useUnicodePassword()) {
380+
$entry['unicodePwd'] = iconv('UTF-8', 'UTF-16LE', '"' . $password . '"');
381+
} else {
382+
$entry['userPassword'] = $password;
383+
}
380384
$ret = ldap_mod_replace($connection, $userDN, $entry);
381385
if ($ret === false) {
382386
$message = 'Failed to set password for user {dn} using ldap_mod_replace';
@@ -389,7 +393,11 @@ public function setPassword($uid, $password, $connection = null) {
389393
}
390394
return $ret;
391395
} catch (\Exception $e) {
392-
$this->logger->error($e, ['app' => Application::APP_ID]);
396+
$this->logger->log(ILogger::ERROR, 'Exception occured while setting the password of user {dn}', [
397+
'app' => Application::APP_ID,
398+
'exception' => $e,
399+
'dn' => $uid
400+
]);
393401
return false;
394402
}
395403
}

lib/Service/Configuration.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ public function hasPasswordPermission(): bool {
5252
return $this->config->getAppValue('ldap_write_support', 'hasPasswordPermission', '1') === '1';
5353
}
5454

55+
public function useUnicodePassword(): bool {
56+
return $this->config->getAppValue('ldap_write_support', 'useUnicodePassword', '0') === '1';
57+
}
58+
5559
public function getUserTemplate() {
5660
return $this->config->getAppValue(
5761
Application::APP_ID,

lib/Settings/Admin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public function getForm() {
6464
'hasPasswordPermission' => $this->config->hasPasswordPermission(),
6565
'newUserRequireEmail' => $this->config->isRequireEmail(),
6666
'newUserGenerateUserID' => $this->config->isGenerateUserId(),
67+
'useUnicodePassword' => $this->config->useUnicodePassword(),
6768
]
6869
);
6970
return new TemplateResponse(Application::APP_ID, 'settings-admin');

src/components/AdminSettings.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@
4848
@change.stop.prevent="toggleSwitch('hasPasswordPermission', !switches.hasPasswordPermission)">
4949
{{ t('ldap_write_support', 'Allow users to set their password') }}
5050
</ActionCheckbox>
51+
<ActionCheckbox :checked="switches.useUnicodePassword"
52+
:title="t('ldap_write_support', 'If the server does not support the modify password extended operation use the `unicodePwd` instead of the `userPassword` attribute for setting the password')"
53+
@change.stop.prevent="toggleSwitch('useUnicodePassword', !switches.useUnicodePassword)">
54+
{{ t('ldap_write_support', 'Use the `unicodePwd` attribute for setting the user password') }}
55+
</ActionCheckbox>
5156
</ul>
5257
<h3>{{ t('ldap_write_support', 'User template') }}</h3>
5358
<p>{{ t('ldap_write_support', 'LDIF template for creating users. Following placeholders may be used') }}</p>

0 commit comments

Comments
 (0)