PHP,Active Directory中,用户帐户控制
首先appologies这应该是对服务器故障的,但它是做与PHP一样,所以我认为这为它的最佳地点。PHP,Active Directory中,用户帐户控制
我正在创建一些方法来将我们的Intranet与Active Directory集成。其中一种方法会自动在我们的数据库中搜索新用户,并在AD中创建用户帐户(如果发现新用户)。
同样地,如果在数据库中留下了用户被标记,它会自动禁用在活动目录的帐户。
我一直在寻找从Active Directory中传递的属性,特别是用户帐户控制领域。
在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),这最终使得公元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
我希望你能理解我的问题,但随时请求确认以上信息。
非常感谢
今天在相同的形势下应运而生,它是更简洁有:
$flag_to_find = 530;
$flags = array();
for ($i=0; $i<=26; $i++){
if ($flag_to_find & (1 << $i)){
array_push($flags, 1 << $i);
}
}
print_r($flags);
我喜欢这种方法比我自己更多!感谢您的额外(更好)答案:) –
这真棒,到处寻找这个,谢谢! –
好了,大量的试验和错误之后,我摸索出如何做到这一点!
$bits = array(
'27' => 1, '26' => 2, '25' => 4, '24' => 8, '23' => 16, '22' => 32,
'21' => 64, '20' => 128, '19' => 256, '18' => 512, '17' => 1024,
'16' => 2048, '15' => 4096, '14' => 8192, '13' => 16328,
'12' => 32768, '11' => 65536, '10' => 131072, '9' => 262144,
'8' => 524288, '7' => 1048576, '6' => 2097152, '5' => 4194304,
'4' => 8388608, '3' => 16777216, '2' => 33554432, '1' => 67108864
);
$flag_to_find = 530; // Indicates a normal user account, which is disabled, and locked out
$binary = str_pad(decbin($flag_to_find), count($bits), 0, STR_PAD_LEFT);
$flags = array();
for($i=0; $i<strlen($binary); $i++)
{
if($binary[$i]==1)
{
$flags[] = $bits[$i+1];
}
}
print_r($flags);
// Outputs: 512: Normal User Account
16: Locked Out Account
2: Disabled Accout
它通过获取UAC中所有可能标志的十进制值来工作。有27个 - 我已将所有值分配给$bits
阵列。
然后指定一个标志来查找。
然后将该标志的十进制值转换为二进制,并用0
将其填充。
循环遍历二进制字符串中的每个值。如果迭代值为1
,则从$bits
阵列中获取其关联的标志十进制值。
然后将所有可能的标志存储在$flags
数组中。
希望这可以帮助任何人在将来遇到类似的问题!
添加到詹姆斯·斯隆的回答,这里是标志列表:
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;
}
像魅力一样工作!谢谢 – Meloman
什么PHP工具是您使用访问活动目录?我想知道我有一个类似的内联网要求。 –