PHP、事件目录、用户帐户控制

标签 php active-directory ldap

如果这应该是服务器故障,首先表示抱歉,但它也与 PHP 有关,所以我认为这是最适合它的站点。

我正在创建一些方法来将我们的 Intranet 与 Active Directory 集成。其中一种方法将自动在我们的数据库中搜索新用户,如果找到新用户,则在 AD 中创建用户帐户。

同样,如果用户在数据库中被标记为离开,它会自动禁用事件目录中的帐户。

我一直在查看从事件目录传递的属​​性,尤其是用户帐户控制字段。

关于 microsoft website它在其属性列表下说明了这一点:

The following table lists possible flags that you can assign. You cannot set some 
of the values on a user or computer object because these values can be set or 
reset only by the directory service. The flags are cumulative. To disable a 
user's account, set the UserAccountControl attribute to 0x0202 (0x002 + 0x0200). In 
decimal, this is 514 (2 + 512).

问题 我的问题是,如果我们使用上面的例子,将记录标记为用户(512)和禁用(2),这最终使 AD 返回的字段值为 514。

在 PHP 中,如何提取记录中标记了哪些标志?例如,如果给定 514,我如何使用 PHP 计算出它是一个普通用户帐户,并且还被禁用(2 和 512)?

例如分割如下:

Flag    | Splits into      | Flag Meaning
--------+------------------+---------------------------------------------------------
514     | 512 + 2          | Normal User Account + Disabled
522     | 512 + 2 + 8      | Normal User Account + Disabled + Home Directory Required
8389120 | 8388608 + 512    | Password Expired + Normal User Account

我希望您能理解我的问题,但请随时询问确认或更多详细信息。

非常感谢

最佳答案

添加到 James Sloan 的回答中,这是标志列表:

public function findFlags($flag) {

    $flags    = array();
    $flaglist = array(
               1 => 'SCRIPT',
               2 => 'ACCOUNTDISABLE',
               8 => 'HOMEDIR_REQUIRED',
              16 => 'LOCKOUT',
              32 => 'PASSWD_NOTREQD',
              64 => 'PASSWD_CANT_CHANGE',
             128 => 'ENCRYPTED_TEXT_PWD_ALLOWED',
             256 => 'TEMP_DUPLICATE_ACCOUNT',
             512 => 'NORMAL_ACCOUNT',
            2048 => 'INTERDOMAIN_TRUST_ACCOUNT',
            4096 => 'WORKSTATION_TRUST_ACCOUNT',
            8192 => 'SERVER_TRUST_ACCOUNT',
           65536 => 'DONT_EXPIRE_PASSWORD',
          131072 => 'MNS_LOGON_ACCOUNT',
          262144 => 'SMARTCARD_REQUIRED',
          524288 => 'TRUSTED_FOR_DELEGATION',
         1048576 => 'NOT_DELEGATED',
         2097152 => 'USE_DES_KEY_ONLY',
         4194304 => 'DONT_REQ_PREAUTH',
         8388608 => 'PASSWORD_EXPIRED',
        16777216 => 'TRUSTED_TO_AUTH_FOR_DELEGATION',
        67108864 => 'PARTIAL_SECRETS_ACCOUNT'
    );
    for ($i=0; $i<=26; $i++){
        if ($flag & (1 << $i)){
            array_push($flags, 1 << $i);
        }
    }
    foreach($flags as $k=>&$v) {
        $v = $v . ' '  . $flaglist[$v];
    }
    return $flags;
}

关于PHP、事件目录、用户帐户控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21698305/

相关文章:

ldap - 在 inetOrgPerson 的 userSMIMECertificate 属性中添加证书

javascript - ajax成功未获取php记录

php - CodeIgniter 表单验证错误重定向

active-directory - Spring LDAP AD 分页支持不起作用 - LDAP : error code 12 - 00000057: LdapErr: DSID-0C09079A

linux - 包含 ldapmodify 的 shell 脚本 - 硬编码命令

ldap - 尝试查找不存在的条目 : uid=dhruv@xyz. com,ou=users,o=xyz,dc=xyz,dc=com:

php - 如何使用 PHP 对范围内的数字进行分组

php - 查找接下来的 13 个星期一和最后一个星期一

powershell - 将变量的原始内容粘贴到另一个命令的过滤器中

search - ldap 返回子树和一级,但不返回基础