【问题标题】:PHP ActiveDirectory through LDAP - How to find the name of a users primary group?PHP ActiveDirectory 通过 LDAP - 如何找到用户主要组的名称?
【发布时间】:2016-08-27 14:15:30
【问题描述】:

所以我想检索用户主要组的组名。

我已经知道如何检索primaryGroupID,但我没有在组类中找到包含这样一个ID的字段。

这就是我检索primaryGroupID的方式:

$filter = "(sAMAccountName=" . $username . ")";
$attr = array ( "primaryGroupID", "sAMAccountName" );
$result = ldap_search( $ldap, "DC=ad,DC=test,DC=local", $filter, $attr ) or exit( "Unable to search LDAP server" . ldap_error( $ldap ) );
$entries = ldap_get_entries( $ldap, $result );

提前致谢!

【问题讨论】:

标签: php ldap


【解决方案1】:

primaryGroupID其实就是你需要获取的组的RID。基本上你需要做的是确定实际组如下:

  1. 从用户处获取objectSidprimaryGroupID 属性。
  2. 将用户的objectSid 转换为其字符串形式。
  3. 将字符串 SID 中的最后一组数字替换为 primaryGroupID
  4. 搜索objectSid 等于上一步中的 SID 的组。

对于几乎永远不会改变的东西来说,这是一项相当乏味的任务。但这是我目前从 LDAP 解码 objectSid 的方式:

https://github.com/ldaptools/ldaptools/blob/master/src/LdapTools/AttributeConverter/ConvertWindowsSid.php

只需将值传递给fromLdap($value) 函数。然后使用 SID 的字符串版本获取组的 SID,如下所示:

$groupSid = preg_replace('/\d+$/', $primaryGroupId, $userSid);

现在使用上面的$groupSid,您可以搜索objectSid 等于该值的组。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-02
    • 1970-01-01
    相关资源
    最近更新 更多