diff --git a/auth-ldap/authentication.php b/auth-ldap/authentication.php index 944d363..47703ba 100644 --- a/auth-ldap/authentication.php +++ b/auth-ldap/authentication.php @@ -228,6 +228,8 @@ function($match) use ($username, $domain, $config) { if (!$this->_bind($c)) return null; + $auth_filter = $this->getConfig()->get('use_custom_filters')?($this->getConfig()->get('auth_filter')):($schema['lookup']); + $r = $c->search( $this->getSearchBase(), str_replace( @@ -235,7 +237,7 @@ function($match) use ($username, $domain, $config) { // Assume email address if the $username contains an @ sign array(strpos($username, '@') ? $schema['email'] : $schema['username'], $username), - $schema['lookup']), + $auth_filter), array('sizelimit' => 1) ); if (PEAR::isError($r) || !$r->count()) @@ -307,9 +309,12 @@ function search($query) { $schema = static::$schemas[$this->getSchema($c)]; $schema = $schema['user']; + + $search_filter = ($this->getConfig()->get('use_custom_filters'))?($this->getConfig()->get('search_filter')):($schema['search']); + $r = $c->search( $this->getSearchBase(), - str_replace('{q}', $query, $schema['search']), + str_replace('{q}', $query, $search_filter), array('attributes' => array_filter(flatten(array( $schema['first'], $schema['last'], $schema['full'], $schema['phone'], $schema['mobile'], $schema['email'], diff --git a/auth-ldap/config.php b/auth-ldap/config.php index ca3380a..646eb2f 100644 --- a/auth-ldap/config.php +++ b/auth-ldap/config.php @@ -106,6 +106,27 @@ function($self, $val) use ($__) { '2307' => 'Posix Account (rfc 2307)', ), )), + 'search_filter_options' => new SectionBreakField(array( + 'label' => $__('Custom search filters'), + 'hint' => $__('Custom search filter options in case the pre-supplied ones are non-sufficient.') + )), + 'use_custom_filters' => new BooleanField(array( + 'label' => $__('Use Custom Filters'), + 'default' => false, + 'configuration' => array( + 'desc' => $__('Use Custom Search and Authentication Filters') + ) + )), + 'search_filter' => new TextboxField(array( + 'label' => $__('LDAP Filter for searching users'), + 'hint' => $__('Used when searching for users. {q} will be replaced with the search term.'), + 'configuration' => array('size'=>70, 'length'=>160), + )), + 'auth_filter' => new TextboxField(array( + 'label' => $__('LDAP Filter for authentication'), + 'hint' => $__('Used when authenticating. {q} will be replaced with the user id.'), + 'configuration' => array('size'=>70, 'length'=>160), + )), 'auth' => new SectionBreakField(array( 'label' => $__('Authentication Modes'),