Skip to content

Commit a94c138

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 a94c138

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed

lib/LDAPConnect.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function hasPasswordPolicy(): bool {
155155
* @param LDAP\Connection $connection LDAP connection to check
156156
* @return boolean either the user can or cannot
157157
*/
158-
public function hasPasswdExopSupport():bool {
158+
public function hasPasswdExopSupport($connection):bool {
159159
if (is_null($this->passwdSupport)) {
160160
$ret = ldap_read($connection, '', '(objectclass=*)', ['supportedExtension']);
161161
if ($ret === false) {

lib/LDAPUserManager.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
use OCA\User_LDAP\IUserLDAP;
3838
use OCP\IImage;
3939
use OCP\IL10N;
40+
use OCP\ILogger;
4041
use OCP\IUser;
4142
use OCP\IUserManager;
4243
use OCP\IUserSession;
@@ -376,7 +377,11 @@ public function setPassword($uid, $password, $connection = null) {
376377
} else {
377378
// Fallback to `userPassword` in case the server does not support exop_passwd
378379
$entry = [];
379-
$entry['userPassword' => $password]
380+
if ($this->configuration->useUnicodePassword()) {
381+
$entry['unicodePwd'] = iconv('UTF-8', 'UTF-16LE', '"' . $password . '"');
382+
} else {
383+
$entry['userPassword'] = $password;
384+
}
380385
$ret = ldap_mod_replace($connection, $userDN, $entry);
381386
if ($ret === false) {
382387
$message = 'Failed to set password for user {dn} using ldap_mod_replace';
@@ -389,7 +394,11 @@ public function setPassword($uid, $password, $connection = null) {
389394
}
390395
return $ret;
391396
} catch (\Exception $e) {
392-
$this->logger->error($e, ['app' => Application::APP_ID]);
397+
$this->logger->log(ILogger::ERROR, 'Exception occured while setting the password of user {dn}', [
398+
'app' => Application::APP_ID,
399+
'exception' => $e,
400+
'dn' => $uid
401+
]);
393402
return false;
394403
}
395404
}

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)