Total rewite of fix.

This now re-looks up the username and returns that for use.

Signed-off-by: Insanemal <insanemal@gmail.com>
This commit is contained in:
Insanemal 2011-11-22 11:08:27 +10:00 committed by Robin Appelman
parent 8d092434ed
commit c945989a70
3 changed files with 30 additions and 19 deletions

View File

@ -22,16 +22,19 @@
*/
$params = array('ldap_host', 'ldap_port', 'ldap_dn', 'ldap_password', 'ldap_base', 'ldap_filter', 'ldap_display_name', 'ldap_tls', 'ldap_nocase');
foreach($params as $param){
if(isset($_POST[$param])){
OC_Appconfig::setValue('user_ldap', $param, $_POST[$param]);
}
elseif('ldap_tls' == $param) {
// unchecked checkboxes are not included in the post paramters
OC_Appconfig::setValue('user_ldap', $param, 0);
}
elseif('ldap_nocase' == $param) {
OC_Appconfig::setValue('user_ldap', $param, 0);
if ($_POST) {
foreach($params as $param){
if(isset($_POST[$param])){
OC_Appconfig::setValue('user_ldap', $param, $_POST[$param]);
}
elseif('ldap_tls' == $param) {
// unchecked checkboxes are not included in the post paramters
OC_Appconfig::setValue('user_ldap', $param, 0);
}
elseif('ldap_nocase' == $param) {
OC_Appconfig::setValue('user_ldap', $param, 0);
}
}
}

View File

@ -11,7 +11,7 @@
<p><label for="ldap_display_name"><?php echo $l->t('Display Name Field');?></label><input type="text" id="ldap_display_name" name="ldap_display_name" value="<?php echo $_['ldap_display_name']; ?>" />
<small><?php echo $l->t('Currently the display name field needs to be the same you matched %%uid against in the filter above, because ownCloud doesn\'t distinguish between user id and user name.');?></small></p>
<p><input type="checkbox" id="ldap_tls" name="ldap_tls" value="1"<?php if ($_['ldap_tls']) echo ' checked'; ?>><label for="ldap_tls"><?php echo $l->t('Use TLS');?></label></p>
<p><input type="checkbox" id="ldap_nocase" name="ldap_nocase" value="1"<?php if ($_['ldap_nocase']) echo ' checked'; ?>><label for="ldap_nocase"><?php echo $l->t('Conver UID lowercase');?></label></p>
<p><input type="checkbox" id="ldap_nocase" name="ldap_nocase" value="1"<?php if ($_['ldap_nocase']) echo ' checked'; ?>><label for="ldap_nocase"><?php echo $l->t('Case insensitve LDAP server (Windows)');?></label></p>
<input type="submit" value="Save" />
</fieldset>
</form>

View File

@ -117,7 +117,21 @@ class OC_USER_LDAP extends OC_User_Backend {
return false;
if($this->ldap_nocase) {
return strtolower($uid);
$filter = str_replace('%uid', $uid, $this->ldap_filter);
$sr = ldap_search( $this->getDs(), $this->ldap_base, $filter );
$entries = ldap_get_entries( $this->getDs(), $sr );
if( $entries['count'] == 1 ) {
foreach($entries as $row) {
$ldap_display_name = strtolower($this->ldap_display_name);
if(isset($row[$ldap_display_name])) {
return $row[$ldap_display_name][0];
}
}
}
else {
return $uid;
}
}
else {
return $uid;
@ -155,13 +169,7 @@ class OC_USER_LDAP extends OC_User_Backend {
// TODO ldap_get_entries() seems to lower all keys => needs review
$ldap_display_name = strtolower($this->ldap_display_name);
if(isset($row[$ldap_display_name])) {
if($this->ldap_nocase) {
$users[] = strtolower($row[$ldap_display_name][0]);
}
else
{
$users[] = $row[$ldap_display_name][0];
}
$users[] = $row[$ldap_display_name][0];
}
}
// TODO language specific sorting of user names