【问题标题】:Bad search filter on LDAP when trying to get user data尝试获取用户数据时 LDAP 上的错误搜索过滤器
【发布时间】:2012-07-23 22:26:33
【问题描述】:

我刚开始使用 LDAP,所以如果我以完全错误的方式执行此操作,请告诉我。

我正在使用 bhLDAPAuthPlugin 插件使用 Symfony 1.4

我正在使用 LDAP 验证用户登录。但是,我想使用用户名查询 LDAP 表中的更多数据。所以我正在编写这个搜索功能来根据用户名过滤结果:

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);
}

我收到错误:

警告:ldap_search(): Search: Bad search filter in /... 搜索查询错误

当我运行查询时。

前三个“如果”只是为了确保我获得了正确的搜索参数。该条件在实际搜索中失败。

有什么建议吗?

更新

用户名变量是 jtesting

在将其放入搜索参数之前,我从函数中提取了 $username。它实际上是(jtesting)。我将删除括号,看看是否可以解决问题。

【问题讨论】:

  • $username 的值是多少?请显示您传入的实际值...
  • 我已将此添加到问题中。
  • 嗯...这不应该导致过滤器损坏 - 尝试更改将过滤器分配给$filter = '(samaccountname='.trim($username).')';的行
  • 在这里查看我的答案:stackoverflow.com/questions/8560874/…

标签: php ldap symfony-1.4 ldap-query


【解决方案1】:

为了在过滤器的断言值中使用括号,必须对括号进行转义。断言值为samAccountName=(jtesting) 的搜索过滤器应编码为samAccountName=\28jtesting\29。整个断言值可能包含在不转义的括号中,在这种情况下过滤器变为(samAccountName=\28jtesting\29)

更多信息

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-17
  • 1970-01-01
  • 2016-08-04
  • 2013-09-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多