Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bad search filter on LDAP when trying to get user data

I am fresh out of the box here with LDAP, so let me know if I am doing this in the completely wrong fashion.

I am working with Symfony 1.4 using the bhLDAPAuthPlugin plugin

I am verifying user login with LDAP. However, there is more data in the LDAP table that I would like to query using the username. So I am writing this search function to filter results according to the username:

function user_values($username) {
if (!$username) {
    die ("Username is not there man!");
}

if (!$this->_conn) {
    die ("No Connection.");
}
if (!$this->_base_dn) {
    die ("No Base.");
}
$filter="samaccountname=".$username;

$attributes_ad = array("name");
$result = ldap_search($this->_conn, $this->_base_dn, $filter, $attributes_ad) 
or die ("Error in search query");
$entries = ldap_get_entries($this->_conn, $result);
    return($entries);
}

I am getting the error:

Warning: ldap_search(): Search: Bad search filter in /... Error in search query

when i run the query.

The first three "if's" are there just to assure I was getting the correct parameters for the search. The condition fails on the actual search.

Any suggestions?

UPDATE

The username variable is jtesting

I pulled the $username from the function, before it gets put in the search parameter. It is actually (jtesting). I am going to remove the parenthesis, and see if that remedies the problem.

like image 704
Carey Estes Avatar asked Jul 23 '12 22:07

Carey Estes


People also ask

What is user filter in LDAP?

LDAP filter used to search for users according a search criteria. Searches for users can be done using the user-search command or in the web administration console. $ SEARCH_STRING is the place holder for the search criteria. User ID Attributes. ldap.userid.attributes.

What is LDAP search filter?

1. Search Filter is a basic LDAP Query for searching users based on mapping of username to a particular LDAP attribute. 2. The following are some commonly used Search Filters. You will need to use a search filter which uses the attributes specific to your LDAP environment.


1 Answers

In order to use parentheses in the assertion value of a filter the parenthese must be escaped. A search filter where the assertion value is samAccountName=(jtesting) should be encoded as samAccountName=\28jtesting\29. The entire assertion value may be enclosed in parentheses which are not escaped, in which case the filter becomes (samAccountName=\28jtesting\29).

More Information

  • LDAP: Search Filters
  • String Representation of Search Filters
like image 191
Terry Gardner Avatar answered Sep 19 '22 12:09

Terry Gardner