๐Ÿ” LDAP Learning Center

Master the Lightweight Directory Access Protocol with interactive lessons and hands-on practice

What is LDAP?

The Lightweight Directory Access Protocol (LDAP) is an open, vendor-neutral protocol used to access and maintain distributed directory information services over an IP network. Think of it as a specialized database optimized for reading user accounts, groups, and organizational data.

๐Ÿ”‘ Key fact: LDAP runs on TCP/UDP port 389 (plaintext) and port 636 for LDAPS (SSL/TLS encrypted). It was standardized as RFC 4511.

Why Do We Need LDAP?

Organizations need a centralized way to store and retrieve information about users, computers, printers, and policies. LDAP provides a lightweight, standardized way to do this โ€” powering Active Directory, OpenLDAP, and countless authentication systems.

๐Ÿข

Centralized Auth

One place to manage all user credentials and access rights

โšก

Fast Reads

Optimized for millions of read queries; ideal for authentication

๐ŸŒ

Open Standard

Vendor-neutral RFC standard supported by every major OS

๐Ÿ”’

Secure (LDAPS)

Supports TLS encryption and SASL authentication

๐Ÿ“

Hierarchical

Tree structure mirrors real-world organizational charts

๐Ÿ”—

Integration

Used by AD, Linux PAM, web apps, VPNs, and more

Common LDAP Implementations

ProductVendorUse Case
Active DirectoryMicrosoftEnterprise Windows environments
OpenLDAPOpen SourceLinux/Unix directory services
389 Directory ServerRed HatEnterprise Linux environments
Oracle Internet DirectoryOracleOracle middleware stack
ApacheDSApacheJava-based embedded LDAP

How LDAP Works

LDAP follows a client-server model. The client sends operations (bind, search, modify, add, delete) and the server responds. Every session begins with authentication (bind) and ends with an unbind.

LDAP Session Flow

1. ConnectTCP to port 389/636
โ†’
2. BindAuthenticate to server
โ†’
3. OperationSearch / Add / Modify
โ†’
4. ResponseServer returns result
โ†’
5. UnbindEnd the session

LDAP Operations

OperationCodeDescription
Bind0Authenticate (Simple or SASL) โ€” starts a session
Unbind2Terminate the session gracefully
Search3Query the directory with filters and scope
Modify6Add, delete, or replace attribute values
Add8Add a new entry to the directory
Delete10Remove an entry from the directory
ModifyDN12Rename or move an entry
Compare14Test whether an attribute value exists
Abandon16Cancel a previously sent request

Bind Types

๐Ÿ‘ค

Anonymous Bind

No credentials โ€” read-only access to public directory info. Common for lookups.

๐Ÿ”‘

Simple Bind

DN + password in plaintext. Must use LDAPS/TLS to protect credentials.

๐Ÿ›ก๏ธ

SASL Bind

Kerberos, DIGEST-MD5, or GSSAPI. Most secure โ€” used in enterprise AD.

โš ๏ธ Security Note: Simple bind over plain LDAP (port 389) sends credentials in cleartext. Always use LDAPS (port 636) or STARTTLS to encrypt credentials in transit.

Search Scope

ScopeMeaning
baseObjectOnly the base DN entry itself
singleLevelDirect children of the base DN (one level down)
wholeSubtreeBase DN and all descendants โ€” most common

Directory Structure

LDAP organizes information in a Directory Information Tree (DIT) โ€” a hierarchical structure similar to a file system. Each node is an entry identified by a Distinguished Name (DN).

Distinguished Name (DN)

A DN is the unique identifier for an entry, reading from specific (left) to general (right):

cn=John Smith
,
ou=Users
,
ou=IT
,
dc=example
,
dc=com

DN Component Types (RDN)

AbbreviationFull NameExample
cnCommon Namecn=John Smith
snSurnamesn=Smith
ouOrganizational Unitou=Engineering
oOrganizationo=Acme Corp
dcDomain Componentdc=example
uidUser IDuid=jsmith
cCountryc=US

Example Directory Tree

dc=example,dc=com (Root) โ”œโ”€โ”€ ou=Users โ”‚ โ”œโ”€โ”€ cn=Alice Johnson โ†’ uid=ajohnson, mail=alice@example.com โ”‚ โ”œโ”€โ”€ cn=Bob Martinez โ†’ uid=bmartinez, mail=bob@example.com โ”‚ โ””โ”€โ”€ cn=Carol White โ†’ uid=cwhite, mail=carol@example.com โ”œโ”€โ”€ ou=Groups โ”‚ โ”œโ”€โ”€ cn=IT-Admins โ†’ member: cn=Alice Johnson,... โ”‚ โ””โ”€โ”€ cn=HR-Staff โ†’ member: cn=Carol White,... โ”œโ”€โ”€ ou=Computers โ”‚ โ”œโ”€โ”€ cn=WS001 โ†’ operatingSystem: Windows 11 โ”‚ โ””โ”€โ”€ cn=SRV-DC01 โ†’ operatingSystem: Windows Server 2022 โ””โ”€โ”€ ou=ServiceAccounts โ””โ”€โ”€ cn=svc-backup โ†’ uid=svcbackup

Common LDAP Attributes

AttributeOID ShortDescription
objectClass2.5.4.*Defines schema rules for the entry (e.g., inetOrgPerson)
uid0.9.2342โ€ฆUser login name
cn2.5.4.3Common name (display name)
sn2.5.4.4Surname / family name
mail0.9.2342โ€ฆEmail address
userPassword2.5.4.35Hashed password (SSHA, bcrypt, etc.)
telephoneNumber2.5.4.20Phone number
memberOfโ€”Groups this entry belongs to
givenName2.5.4.42First name
title2.5.4.12Job title

Object Classes

Every LDAP entry must have an objectClass that defines which attributes are required and permitted:

๐Ÿ‘ค

inetOrgPerson

Standard user account โ€” includes uid, mail, cn, sn

๐Ÿ‘ฅ

groupOfNames

Group entry containing a list of member DNs

๐Ÿ–ฅ๏ธ

device

Represents computers, printers, and network devices

๐Ÿข

organization

Top-level org entry with the 'o' attribute required

LDAP Message Format

LDAP messages are encoded using ASN.1 BER (Basic Encoding Rules). Every message โ€” request or response โ€” wraps in a common envelope called the LDAPMessage.

LDAPMessage Envelope

Tag (SEQUENCE)
Length
messageID (Integer)
protocolOp (Operation)
controls (Optional)

Search Request โ€” protocolOp breakdown:
baseObject (DN)
scope (0/1/2)
derefAliases
sizeLimit
timeLimit
filter
attributes

Field Descriptions

FieldDescription
messageIDUnique integer to match requests with asynchronous responses (1โ€“2,147,483,647)
protocolOpThe actual LDAP operation (e.g., SearchRequest, BindRequest, SearchResultEntry)
controlsOptional extensions โ€” paging, sort, LDAP transactions, etc.
baseObjectThe DN where the search starts (e.g., dc=example,dc=com)
scope0=baseObject, 1=singleLevel, 2=wholeSubtree
derefAliasesHow to handle alias entries (never, inSearching, findingBaseObj, always)
sizeLimitMax number of entries to return (0=no limit)
timeLimitMax seconds to execute (0=no limit)
filterBoolean expression selecting which entries to return
attributesList of attribute types to return (empty = return all)

LDAP Result Codes

CodeNameMeaning
0successOperation completed successfully
1operationsErrorServer encountered an internal processing error
2protocolErrorMalformed request sent by client
3timeLimitExceededOperation exceeded the time limit
4sizeLimitExceededMore results exist than the size limit allows
10referralServer cannot handle request; refers to another server
32noSuchObjectThe target DN does not exist
34invalidDNSyntaxThe provided DN is malformed
49invalidCredentialsWrong password / bad credentials (auth failure)
50insufficientAccessRightsCaller lacks permission for the operation
53unwillingToPerformServer refuses (e.g., password policy)

LDAP Filter Syntax

Search filters use prefix (Polish) notation wrapped in parentheses:

FilterExampleMeaning
Equality(cn=Alice)cn equals "Alice"
Substring(mail=*@example.com)mail ends with @example.com
Present(telephoneNumber=*)telephoneNumber attribute exists
AND(&(uid=jsmith)(objectClass=person))Both conditions true
OR(|(cn=Alice)(cn=Bob))Either condition true
NOT(!(accountLocked=TRUE))Condition is false
Approx(cn~=Alyss)Approximately equal (soundex)
Greater/Less(uidNumber>=1000)Numeric/lexicographic comparison

LDAP Query Builder

Build and simulate LDAP search queries interactively. Construct a filter and see the generated query string plus a simulated response.

๐Ÿ”ง Build a Search Filter

(objectClass=inetOrgPerson)

๐Ÿ“ LDIF Entry Creator

LDIF (LDAP Data Interchange Format) is the standard text format for importing/exporting LDAP entries.

LDAP Knowledge Quiz

Test your understanding of LDAP concepts!

10 questions covering LDAP fundamentals, message format, directory structure, and security.