Skip to content

Commit 7564090

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

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

lib/LDAPUserManager.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ public function deleteUser($uid): bool {
339339
*
340340
* @return boolean either the user can or cannot
341341
*/
342-
public function canSetPassword() {
342+
public function canSetPassword(): bool {
343343
return $this->configuration->hasPasswordPermission();
344344
}
345345

@@ -366,20 +366,26 @@ public function setPassword($uid, $password, $connection = null) {
366366
if ($ldapConnect->hasPasswdExopSupport($connection)) {
367367
$ret = ldap_exop_passwd($connection, $userDN, '', $password);
368368
if ($ret === false) {
369-
$message = 'ldap_exop_passwd failed, falling back to ldap_mod_replace to to set password for new user';
369+
$message = 'Failed to set password for user {dn} using ldap_exop_passwd';
370370
$this->logger->log(ILogger::ERROR, $message, [
371-
'app' => Application::APP_ID,
372371
'ldap_error' => ldap_error($connection),
372+
'app' => Application::APP_ID,
373+
'dn' => $userDN,
373374
]);
374375
}
375-
}
376-
377-
// Fallback to `userPassword` in case the server does not support exop_passwd
378-
if ($ret === false) {
379-
$ret = ldap_mod_replace($connection, $userDN, ['userPassword' => $password]);
376+
} else {
377+
// Fallback to `userPassword` in case the server does not support exop_passwd
378+
$entry = [];
379+
if ($this->configuration->useUnicodePassword()) {
380+
$entry['unicodePwd'] = iconv('UTF-8', 'UTF-16LE', '"' . $password . '"');
381+
} else {
382+
$entry['userPassword' => $password]
383+
}
384+
$ret = ldap_mod_replace($connection, $userDN, $entry);
380385
if ($ret === false) {
381-
$message = 'Failed to set password for user {dn}';
386+
$message = 'Failed to set password for user {dn} using ldap_mod_replace';
382387
$this->logger->log(ILogger::ERROR, $message, [
388+
'ldap_error' => ldap_error($connection),
383389
'app' => Application::APP_ID,
384390
'dn' => $userDN,
385391
]);

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)