如何使用 CodeIgniter 和 adLDAP v2.1 库排除 LDAP 域下的特定文件夹
How can I exclude specific folders under the LDAP domain with CodeIgniter and the adLDAP v2.1 library
我正在使用 adLDAP 和 CodeIgniter 在我的 LDAP 服务器上执行搜索。我要搜索的基本上是已从 LDAP 服务器停用的帐户。在我的 PHP 代码中,我有以下调用 adLDAP 库的代码:
$searchCriteria = array(
"givenname" => $values['givenName'],
"sn" => $values['sn'],
"title" => $values['title'],
"mail" => $values['mail'],
"telephonenumber" => $values['telephonenumber'],
);
// echo "<pre>"; print_r($searchCriteria); echo "</pre>";
// create the search filter
$noOfFieldsSet = 0;
$searchFilterA = '(objectClass=user)(samaccounttype='. ADLDAP_NORMAL_ACCOUNT .')(objectCategory=person)';
$searchFilterB = '';
foreach ($searchCriteria AS $key => $value)
{
if ($value)
{
$searchFilterB .= "(".$key."=".$wildcard.$value."*)";
++$noOfFieldsSet;
}
}
// We perform a logical AND or OR (depending on $logic) on all
// specified search criteria to create the final search filter:
if ($logic == "&")
{
$searchFilter = "(".$logic." ".$searchFilterA.$searchFilterB.")";
}
else // logic = OR
{
$searchFilter = "(& ".$searchFilterA."(".$logic." ".$searchFilterB."))";
}
// echo $searchFilter."<br>";
// define what attributes we want to get
$attribs = array("displayname", "samaccountname", "mail", "telephonenumber", "title", "physicaldeliveryofficename");
$resultEntries = $this->ad_ldap->search_directory($searchFilter, $attribs);
然后在最后一行中,函数 ad_ldap-> 从 adLDAP 库中搜索目录被调用,这个函数:
function search_directory($filter, $fields, $sorted = true)
{
if ( ! $this->_bind)
return (false);
$sr = ldap_search($this->_conn, $this->_base_dn, $filter, $fields);
$entries = ldap_get_entries($this->_conn, $sr);
// echo "<pre>"; print_r($entries); echo "</pre>";
return $entries;
}
这是我的 LDAP 树结构的样子:
我想知道如何排除那些目录(由黑色箭头指向)和另一个 "users" 文件夹内的另一个 Inactive 文件夹。
我在这里不确定的是如何排除目录或指定我想排除的目录。
如有任何帮助,我们将不胜感激。
您应该向 $searchFilterB
添加排除过滤器:
$searchFilterA = '(objectClass=user)(samaccounttype='. ADLDAP_NORMAL_ACCOUNT .')(objectCategory=person)';
$searchFilterB = '(!(UserAccountControl:1.2.840.113556.1.4.803:=2))';
这是特定于 AD 的查询语言:查找所有 不 的帐户都打开了 UF_ACCOUNTDISABLED
标志(您可以通过翻转在 AD 用户控件中编辑禁用的开关)。
我正在使用 adLDAP 和 CodeIgniter 在我的 LDAP 服务器上执行搜索。我要搜索的基本上是已从 LDAP 服务器停用的帐户。在我的 PHP 代码中,我有以下调用 adLDAP 库的代码:
$searchCriteria = array(
"givenname" => $values['givenName'],
"sn" => $values['sn'],
"title" => $values['title'],
"mail" => $values['mail'],
"telephonenumber" => $values['telephonenumber'],
);
// echo "<pre>"; print_r($searchCriteria); echo "</pre>";
// create the search filter
$noOfFieldsSet = 0;
$searchFilterA = '(objectClass=user)(samaccounttype='. ADLDAP_NORMAL_ACCOUNT .')(objectCategory=person)';
$searchFilterB = '';
foreach ($searchCriteria AS $key => $value)
{
if ($value)
{
$searchFilterB .= "(".$key."=".$wildcard.$value."*)";
++$noOfFieldsSet;
}
}
// We perform a logical AND or OR (depending on $logic) on all
// specified search criteria to create the final search filter:
if ($logic == "&")
{
$searchFilter = "(".$logic." ".$searchFilterA.$searchFilterB.")";
}
else // logic = OR
{
$searchFilter = "(& ".$searchFilterA."(".$logic." ".$searchFilterB."))";
}
// echo $searchFilter."<br>";
// define what attributes we want to get
$attribs = array("displayname", "samaccountname", "mail", "telephonenumber", "title", "physicaldeliveryofficename");
$resultEntries = $this->ad_ldap->search_directory($searchFilter, $attribs);
然后在最后一行中,函数 ad_ldap-> 从 adLDAP 库中搜索目录被调用,这个函数:
function search_directory($filter, $fields, $sorted = true)
{
if ( ! $this->_bind)
return (false);
$sr = ldap_search($this->_conn, $this->_base_dn, $filter, $fields);
$entries = ldap_get_entries($this->_conn, $sr);
// echo "<pre>"; print_r($entries); echo "</pre>";
return $entries;
}
这是我的 LDAP 树结构的样子:
我想知道如何排除那些目录(由黑色箭头指向)和另一个 "users" 文件夹内的另一个 Inactive 文件夹。
我在这里不确定的是如何排除目录或指定我想排除的目录。
如有任何帮助,我们将不胜感激。
您应该向 $searchFilterB
添加排除过滤器:
$searchFilterA = '(objectClass=user)(samaccounttype='. ADLDAP_NORMAL_ACCOUNT .')(objectCategory=person)';
$searchFilterB = '(!(UserAccountControl:1.2.840.113556.1.4.803:=2))';
这是特定于 AD 的查询语言:查找所有 不 的帐户都打开了 UF_ACCOUNTDISABLED
标志(您可以通过翻转在 AD 用户控件中编辑禁用的开关)。