Skip to content

Core\Ldap\Ad::bitOr

Returns a filter that matches the entries where a number attribute has at least 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 that are disabled or locked out.

Good to know: give several bits as one number, such as 2 | 16. The attribute name cannot be tainted. A name that is not an attribute name throws a LogicError.

Parameters

  • $attributestringThe attribute's name, such as sAMAccountName. It cannot be tainted.
  • $bitsintThe bits to test, as one number, such as 2 | 512.

Return value

Returns Core\Ldap\Filter. A Core\Ldap\Filter.

Errors

  • LogicError$attribute is not an attribute name.

Examples

Disabled or locked

<?nvs
// Shows the filter for accounts that are disabled or locked out.
// 2 is "disabled" and 16 is "locked out". One of the two is enough.
echo Core\Ldap\Ad::bitOr('userAccountControl', 2 | 16)->toString(), "\n";
Output
(userAccountControl:1.2.840.113556.1.4.804:=18)

Any group scope

<?nvs
// Shows the filter for groups that are global or universal.
// In `groupType`, 2 is a global group and 8 is a universal group.
var $filter = Core\Ldap\Filter::all(
Core\Ldap\Filter::equals('objectClass', 'group'),
Core\Ldap\Ad::bitOr('groupType', 2 | 8),
);
echo $filter->toString(), "\n";
Output
(&(objectClass=group)(groupType:1.2.840.113556.1.4.804:=10))

Check the name

<?nvs
// Shows what happens when the attribute name is not a name.
try {
Core\Ldap\Ad::bitOr('userAccountControl)(cn=*', 2);
echo "built\n";
} catch (LogicError $refusal) {
// A name has only letters, digits and `-`, so this prints not a name.
echo "not a name\n";
}
Output
not a name