Core\Ldap\Ad::bitAnd
Core\Ldap\Ad::bitAnd(string $attribute, int $bits): Core\Ldap\FilterCore\Ldap\Ad::bitAnd( string $attribute, int $bits, ): Core\Ldap\Filter
Returns a filter that matches the entries where a number attribute has every one of the given bits set. Active Directory keeps many settings as bits in one number, such as userAccountControl and groupType.
Use it to find, for example, the accounts whose password never expires (bit 65536).
Good to know: give several bits as one number, such as 2 | 512. The attribute name cannot be tainted. A name that is not an attribute name throws a LogicError.
Parameters
$attributestringThe attribute's name, such assAMAccountName. It cannot betainted.$bitsintThe bits to test, as one number, such as2 | 512.
Return value
Returns Core\Ldap\Filter. A Core\Ldap\Filter.
Errors
LogicError$attributeis not an attribute name.
Examples
Password never expires
<?nvs// Shows the filter for accounts whose password never expires.
// 65536 is the bit for "password never expires" in `userAccountControl`.echo Core\Ldap\Ad::bitAnd('userAccountControl', 65536)->toString(), "\n";(userAccountControl:1.2.840.113556.1.4.803:=65536)Security groups
<?nvs// Shows the filter for security groups.
// 2147483648 is the bit for a security group in `groupType`.var $filter = Core\Ldap\Filter::all( Core\Ldap\Filter::equals('objectClass', 'group'), Core\Ldap\Ad::bitAnd('groupType', 2147483648),);echo $filter->toString(), "\n";(&(objectClass=group)(groupType:1.2.840.113556.1.4.803:=2147483648))Every bit
<?nvs// Shows a test of two bits at once. Both bits must be set.
// 2 is "disabled" and 16 is "locked out". The number in the filter is 18.echo Core\Ldap\Ad::bitAnd('userAccountControl', 2 | 16)->toString(), "\n";(userAccountControl:1.2.840.113556.1.4.803:=18)