LDAP filter builder and explainer
Paste a filter, such as (cn=*bob*) or a long one from a script, to read it in plain words, with Active Directory's bitwise and nested-group rules spelled out. Or build one from the common filters below.
Build a filter
| What it finds | Filter |
|---|---|
| User accounts | (&(objectCategory=person) |
| Disabled user accounts | (&(objectCategory=person) |
| Enabled user accounts | (&(objectCategory=person) |
| Users whose password never expires | (&(objectCategory=person) |
| Users who must change their password at next logon | (&(objectCategory=person) |
| Computer accounts | (objectCategory=computer) |
| Domain controllers | (&(objectCategory=computer) |
| Security groups | (&(objectCategory=group) |
| Distribution groups | (&(objectCategory=group) |
| Members of a group, nested groups included | (memberOf:1.2.840.113556.1.4.1941:={dn}) |
| Direct members of a group | (memberOf={dn}) |
| Groups an account is in, nested groups included | (&(objectCategory=group) |
Escape a value
Escaped:
RFC 4515 writes five characters as a backslash and two hexadecimal digits wherever they are meant as themselves, and any byte may be written that way:
| Character | Written as |
|---|---|
* | \2a |
( | \28 |
) | \29 |
\ | \5c |
NUL | \00 |
/ | \2f |
Microsoft's list adds the slash, for filters used in an ADsPath.
Operators
| Operator | Meaning |
|---|---|
= | Equals. With a * in the value it is a substring test; attr=* alone means the attribute has a value. |
~= | Approximately equal, as the server defines it. |
>= | Greater than or equal to. |
<= | Less than or equal to. |
& | And: every filter after it matches. |
| | Or: at least one filter after it matches. |
! | Not: the one filter after it does not match. |
:rule:= | An extensible match with the matching rule named by its OID. |
Active Directory matching rules
Active Directory takes these matching rules in an extensible match, attribute:rule:=value. For the two bitwise rules the value must be a decimal number, not a hexadecimal one or a constant name.
| OID | Name | What it does | Since |
|---|---|---|---|
1.2.840.113556.1.4.803 | LDAP_ | Matches when every bit of the value is set in the attribute: a bitwise AND. | Windows 2000 and later |
1.2.840.113556.1.4.804 | LDAP_ | Matches when any bit of the value is set in the attribute: a bitwise OR. | Windows 2000 and later |
1.2.840.113556.1.4.1941 | LDAP_ | For attributes that hold a DN, such as member and memberOf: follows the chain of links, so nested groups count. | Windows Server 2008 and later |
1.2.840.113556.1.4.2253 | LDAP_ | Matches values of DN-with-data attributes by their DN part. | Windows Server 2012 R2 and later |
The flags the explainer names
A bitwise test on userAccountControl or groupType, or a test of sAMAccountType, is read with these names, the same as on the userAccountControl and groupType pages.
| Bit | userAccountControl flag | Meaning |
|---|---|---|
| 1 | SCRIPT | The logon script runs. |
| 2 | ACCOUNTDISABLE | The account is disabled: nobody can log on with it. |
| 8 | HOMEDIR_ | A home folder is required. |
| 16 | LOCKOUT | The account is locked out. Windows does not keep this flag up to date in userAccountControl: read msDS-User-Account-Control-Computed or lockoutTime instead. |
| 32 | PASSWD_ | No password is required: the password length policy does not apply, so the password can be empty. |
| 64 | PASSWD_ | The user cannot change the password. Windows does not keep this here: the option is a permission on the account, and setting the bit has no effect. |
| 128 | ENCRYPTED_ | Store password using reversible encryption: the password is kept in a form that can be turned back into clear text. |
| 256 | TEMP_ | An account for a user whose main account is in another domain. |
| 512 | NORMAL_ | A typical user account. |
| 2048 | INTERDOMAIN_ | The account of a trust with another domain. |
| 4096 | WORKSTATION_ | The computer account of a workstation or member server of this domain. |
| 8192 | SERVER_ | The computer account of a domain controller of this domain. |
| 65536 | DONT_ | The password never expires. |
| 131072 | MNS_ | An MNS logon account. |
| 262144 | SMARTCARD_ | The user must log on with a smart card. |
| 524288 | TRUSTED_ | Trusted for delegation to any service (unconstrained delegation): its tickets carry the OK as Delegate flag. Normal on domain controllers. |
| 1048576 | NOT_ | Account is sensitive and cannot be delegated: its tickets are not forwardable, so no service can act as this account. |
| 2097152 | USE_ | Kerberos uses only DES keys for this account. |
| 4194304 | DONT_ | Kerberos pre-authentication is not required. |
| 8388608 | PASSWORD_ | The password is older than the maximum password age. Not kept here: Windows shows it in msDS-User-Account-Control-Computed. |
| 16777216 | TRUSTED_ | Trusted to authenticate for delegation: a service running as this account gets forwardable tickets for users who did not log on with Kerberos (protocol transition). Normal on read-only domain controllers. |
| 33554432 | NO_ | Service tickets for this account carry no PAC, the part that lists the user's groups. |
| 67108864 | PARTIAL_ | The computer account of a read-only domain controller (RODC). WORKSTATION_TRUST_ACCOUNT is always set with it. |
| 134217728 | USE_ | Defined in lmaccess.h, but Windows clients and servers ignore it. |
| Bit | groupType flag | Meaning |
|---|---|---|
| 1 | GROUP_ | A group the system created in the Builtin container, such as Administrators. Only the system sets this flag. |
| 2 | GROUP_ | Global scope: members come from the group's own domain. |
| 4 | GROUP_ | Domain local scope: members can come from any trusted domain, and the group grants access only in its own domain. |
| 8 | GROUP_ | Universal scope: members can come from any domain in the forest, and the group can grant access anywhere in it. |
| 16 | GROUP_ | An application basic group of Authorization Manager. Active Directory itself does not use it. |
| 32 | GROUP_ | An application query group of Authorization Manager. Active Directory itself does not use it. |
| 2147483648 | GROUP_ | A security group: its membership goes into the access token, so it can be given permissions. Without this flag the group is a distribution group. |
| Value | sAMAccountType | Meaning |
|---|---|---|
| 0 | SAM_ | The domain object itself. |
| 268435456 | SAM_ | A global or universal security group. |
| 268435457 | SAM_ | A global or universal distribution group. |
| 536870912 | SAM_ | An alias: a domain local security group, the built-in groups included. |
| 536870913 | SAM_ | A domain local distribution group. |
| 805306368 | SAM_ | A user account. The same value is also named SAM_USER_OBJECT. |
| 805306369 | SAM_ | A computer account. |
| 805306370 | SAM_ | The account of a trust with another domain. |
| 1073741824 | SAM_ | An application basic group of Authorization Manager. |
| 1073741825 | SAM_ | An application query group of Authorization Manager. |
Sources
- Grammar and escapes: RFC 4515, LDAP: String Representation of Search Filters (as shipped in OpenLDAP's source at commit 732f0bf).
- Operators, matching rules and the slash: Microsoft's page Search Filter Syntax; the Windows versions: Microsoft's open specification [MS-ADTS] section 3.1.1.3.4.4.
- Common filters: Microsoft's TechNet Wiki article Active Directory: LDAP Syntax Filters.
- Flag names and meanings: the userAccountControl and groupType pages of this site, from Microsoft's documentation of those attributes.
More Active Directory tools
-
Logon failure decoder
Read failed logon events 4625, 4771 and 4776: Status and Sub Status, Kerberos failure codes and logon types.
-
LDAP error decoder
Read an LDAP error from Active Directory: result code 49 and data 52e, 775, 773 or 532.
-
userAccountControl decoder
Read 512, 514, 66048 or any other userAccountControl value flag by flag, or tick flags to build one.
-
AD rights GUID lookup
Name the GUIDs in an ACL or event 4662: extended rights, property sets, classes and attributes.
-
groupType and sAMAccountType decoder
Turn -2147483646 or 805306368 into a group scope, a group type or an account type.
-
Kerberos encryption types decoder
Decode msDS-SupportedEncryptionTypes and ticket encryption types, and see where RC4 is still allowed.
-
Active Directory timestamp converter
Convert lastLogonTimestamp, pwdLastSet and other 18-digit values to dates and back.
-
SDDL and SID decoder
Read a security descriptor string in plain words and look up well-known SIDs.
-
GUID and SID converter
Turn an objectGUID or objectSid from base64, bytes or an immutableId into its GUID or S-1-5-21 form and back.