Skip to content

New plugin: LDAP driver - #1357

Closed
standa wants to merge 1 commit into
vrana:mainfrom
standa:ldap
Closed

standa wants to merge 1 commit into
vrana:mainfrom
standa:ldap

Conversation

@standa

@standa standa commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

A plugin driver for browsing and editing LDAP directories based on the flattened tree -> db tables design described below. I use it internally but other people may find it useful too.

Mapping

  • database = naming context from the RootDSE, row = entry identified by dn, column = attribute
  • two kinds of tables:
    • an entry with children, named by its dn – its rows are its direct children (one-level search); these come first in the menu, each shown as its RDN indented under its parent, so the menu reads as the directory tree
    • a structural objectClass – its rows are its entries in the whole naming context
  • the columns are the MUST attributes of the class plus the attributes populated in the first 50 rows (a class can allow dozens)
  • multi-valued attributes are edited one value per line, binary ones (by schema syntax, ;binary, or the Active Directory GUID/SID) as base64
  • saving sends only the changed attributes; changing dn is a modrdn, which can also move the entry
  • search translates the operators to RFC 4515 filters, dn = becomes the search base

Connection

  • uses the ldap extension; without it, or with ext=socket, a built-in client speaks the needed subset of RFC 4511 over a socket (like the Redis driver), so it also works on hosts without the extension
  • ldaps:// connects by TLS; plugin login-ssl switches ldap:// to StartTLS and sets its certificates – with the ldap extension only for StartTLS, because libldap ignores the per-connection TLS options of ldaps:// and uses ldap.conf / LDAPTLS_CACERT there

Limitations

  • LDAP has no offset, so the previous pages are read and skipped; sorting is done in PHP
  • the table list is built from the first 10000 entries
  • creating, altering, dropping and truncating tables are not offered – an objectClass is defined by the server schema and an entry is not a table

Open question: login-ssl options are global, so a setup using login-ssl for e.g. MySQL also switches LDAP to StartTLS. I chose it because there is no standard URL scheme for StartTLS – happy to change it.

Tested against OpenLDAP 2.6.10 on PHP 8.5 with both clients giving identical results: login, menu tree, select with search, sort and paging, row count, edit (including a no-op save of binary values), insert, multi-valued update with a move to another parent, delete, the non-leaf delete error, and StartTLS and ldaps:// with and without a trusted CA. php compile.php ldap and php compile.php drivers build without the missing-function warning, phpcs is clean and composer test passes.

Note for the pepa-linha design: it lays out the menu correctly only for table names that are links to a structure page, so drivers without one (this one, IMAP) get misaligned select links; that is a separate CSS fix.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011pgUiWfMnyGW1NXQHhV6qE
Copilot AI balanced review requested due to automatic review settings October 7, 2026 12:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

It is a 1257-line new driver implementing a binary protocol (BER/RFC 4511) and RFC 4515 filter translation whose correctness cannot be fully verified without a live LDAP server, so it warrants human review.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

This PR adds a new plugin LDAP driver (plugins/drivers/ldap.php) that lets Adminer browse and edit LDAP directories by mapping the directory tree onto Adminer's database/table/row/column model (naming context = database, entry = row keyed by dn, attribute = column). It follows the established plugin-driver pattern (like redis.php/simpledb.php): a Db connection class, a Driver, a Result, and the driver-level override functions. It ships two interchangeable clients — one using the PHP ldap extension, and a dependency-free client that speaks the needed subset of RFC 4511 over a socket (BER encoding/decoding plus an RFC 4515 filter translator). The change also extends the login-ssl plugin documentation to cover LDAP and records the new plugin in the changelog.

Changes:

  • New plugins/drivers/ldap.php implementing LDAP browsing/editing with two clients (extension and raw-socket), schema parsing, tree/class table mapping, search/sort/paging, and CRUD via modify/modrdn.
  • Documented LDAP SSL options in plugins/login-ssl.php (StartTLS switch for ldap://).
  • Added New plugin ldap: LDAP driver under the ### Plugins changelog subsection.
File Description
plugins/​drivers/​ldap.php New LDAP plugin driver: dual clients (ldap ext + socket/BER), schema parsing, table/tree mapping, select with filters/sort/paging, insert/update/delete.
plugins/​login-ssl.php Adds an LDAP line to the SSL-options doc-comment describing the StartTLS behavior.
CHANGELOG.md Records the new LDAP plugin driver under ### Plugins.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread plugins/drivers/ldap.php
Comment on lines +1037 to +1039
foreach (preg_split('~\r\n|\r|\n~', (string) $value, -1, PREG_SPLIT_NO_EMPTY) as $val) {
$return[] = ($binary ? (string) base64_decode($val, true) : $val);
}
@vrana

vrana commented Oct 8, 2026

Copy link
Copy Markdown
Owner

Thanks! Is there a way for me to try it? Is there some public LDAP playground, similar to e.g. https://play.clickhouse.com/?

@standa

standa commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

Hi!

There are public ldap servers that work with this code, e.g. forumsys:

image

http://127.0.0.1:8000/adminer/?ext=socket&ldap=ldap.forumsys.com&username=cn%3Dread-only-admin,dc%3Dexample,dc%3Dcom&db=dc%3Dexample,dc%3Dcom&select=ou%3Dscientists,dc%3Dexample,dc%3Dcom

  • Host: ldap.forumsys.com
  • Port: 389 (nezabezpečené připojení)
  • Username: cn=read-only-admin,dc=example,dc=com
  • Password: password
image
  • I choose a table structure that worked for us internally but obviously there are more ways to visualize the tree structure as flat tables/rows.

But I developed it locally using random sample data inserted into openldap server. These were the basic steps.

1. Start a demo LDAP server

docker run -d --name ldap-demo -p 1389:1389 \
  -e LDAP_ROOT=dc=example,dc=org \
  -e LDAP_ADMIN_USERNAME=admin -e LDAP_ADMIN_PASSWORD=adminpassword \
  -e LDAP_SKIP_DEFAULT_TREE=yes \
  bitnamilegacy/openldap:latest

# wait until it accepts connections
until docker exec ldap-demo ldapsearch -x -H ldap://127.0.0.1:1389 -b "" -s base >/dev/null 2>&1; do sleep 1; done

2. Load sample data

This command creates demo.ldif (a small nested tree with non-ASCII names, a user with several emails, a DN with an escaped comma, and a group) and loads it:

cat > demo.ldif <<'EOF'
dn: dc=example,dc=org
objectClass: dcObject
objectClass: organization
dc: example
o: Example Inc.

dn: ou=people,dc=example,dc=org
objectClass: organizationalUnit
ou: people

dn: ou=engineering,ou=people,dc=example,dc=org
objectClass: organizationalUnit
ou: engineering

dn: ou=backend,ou=engineering,ou=people,dc=example,dc=org
objectClass: organizationalUnit
ou: backend

dn: ou=groups,dc=example,dc=org
objectClass: organizationalUnit
ou: groups

dn: uid=jnovak,ou=backend,ou=engineering,ou=people,dc=example,dc=org
objectClass: inetOrgPerson
uid: jnovak
cn:: SmnFmcOtIE5vdsOhaw==
sn:: Tm92w6Fr
title: Backend Lead
mail: jnovak@example.org
mail: jiri.novak@example.org

dn: uid=alice,ou=engineering,ou=people,dc=example,dc=org
objectClass: inetOrgPerson
uid: alice
cn: Alice Johnson
sn: Johnson
mail: alice@example.org

dn: cn=Doe\, John,ou=people,dc=example,dc=org
objectClass: inetOrgPerson
cn: Doe, John
sn: Doe

dn: cn=engineering,ou=groups,dc=example,dc=org
objectClass: groupOfNames
cn: engineering
member: uid=jnovak,ou=backend,ou=engineering,ou=people,dc=example,dc=org
member: uid=alice,ou=engineering,ou=people,dc=example,dc=org
EOF

docker exec -i ldap-demo ldapadd -c -x -H ldap://127.0.0.1:1389 \
  -D "cn=admin,dc=example,dc=org" -w adminpassword < demo.ldif

It should print adding new entry 9 times.

3. Start Adminer

From the adminer folder, run the command below and leave that terminal open:

php -S 127.0.0.1:8000

4. Log in

Open http://127.0.0.1:8000/adminer/?ldap=127.0.0.1%3A1389&username=cn%3Dadmin%2Cdc%3Dexample%2Cdc%3Dorg

The system, server and user are already filled in. Enter the password adminpassword and pick the database dc=example,dc=org. The menu should show the tree (ou=people › ou=engineering › ou=backend, then ou=groups) above the class tables.

To try the built-in client instead of the PHP extension, add ext=socket to the URL: http://127.0.0.1:8000/adminer/?ext=socket&ldap=127.0.0.1%3A1389&username=cn%3Dadmin%2Cdc%3Dexample%2Cdc%3Dorg

Connecting to your own LDAP server

On the login page, choose the system LDAP and fill in:

  • Server: host, host:port, ldap://host or ldaps://host
  • Username: the bind DN, for example cn=admin,dc=company,dc=com
  • Password: that DN's password. Adminer won't log in without one, so anonymous login isn't possible.

Stop and clean up

Press Ctrl+C in the Adminer terminal, then run docker rm -f ldap-demo.

If something goes wrong

  • "Address already in use": pick other ports, for example php -S 127.0.0.1:8001 or -p 1390:1389, and change the link to match.
  • "Can't contact LDAP server": the container isn't ready yet, or the port in the link is wrong. Check with docker logs ldap-demo.
  • Port 3389: the demo uses 1389 on purpose, because 3389 is Windows' Remote Desktop port and is often taken there.
image image

@vrana

vrana commented Oct 10, 2026 •

Copy link
Copy Markdown
Owner

Thanks a lot for the driver and for the detailed instructions on trying it. I won't merge it into the repository, because I don't want to take on maintaining another driver. Please publish it as your own plugin (a repository with the single file is enough) and I'll link it from https://www.adminer.org/plugins/. There are already driver plugins published like this, e.g. https://www.adminer.org/plugins/#user-duckdb. I've taken only the change to login-ssl.php.

Here is some feedback that might help the plugin. Line numbers are in plugins/drivers/ldap.php.

Bugs

  1. The socket client accepts any reply as an LDAP response (call() / read(), ~268–276). It doesn't check the 0x30 envelope, the message ID or the reply tag. If you log in to 127.0.0.1:3306 (MySQL) with ext=socket:

    • the compiled build accepts the MySQL greeting as a successful bind and logs in;
    • the dev build dies with TypeError: LdapClient::items(): Argument #1 ($data) must be of type string, null given.

    The error message is also parsed from the target's bytes and printed before login, which is the CVE-2021-21311 class of problem. Please return a generic error unless the reply is a well-formed response to the request. The ldap extension client correctly says "Can't contact LDAP server" here.

  2. Values containing newlines are changed by an unrelated save (splitValues() ~1034, comparison ~899). An attribute with a multi-line value, e.g. description, is posted unchanged, split into several values, no longer equals the stored value, and gets replaced. Single-value fields are rendered as <input>, which drops the newline, so they change the same way. Empty values are dropped by PREG_SPLIT_NO_EMPTY too.

  3. NOT LIKE %% is silently ignored. Adminer expands only LIKE %%, so the condition comes as "cn" NOT LIKE %% 'foo'. conditionToFilter() doesn't match that, and all rows are shown. LIKE and NOT LIKE without %% would avoid it.

  4. Search anywhere breaks on " or " in the value. The OR split in parseWhere() (~1057) ignores quotes, so searching for Smith or Jones produces no filter and shows all rows. In general, a condition the driver can't translate should be an error, not a wider result.

  5. Invalid base64 in a binary attribute is saved as an empty value (~1038).

  6. Size limits are hidden (~199, ~445). Result codes 4 and 11 are treated as success. With OpenLDAP's default limit of 500 or Active Directory's 1000, the row count, sorting and the table list stop at the limit without any notice.

  7. The table name in the edit form's title and breadcrumb is the indented RDN. The fast status (~689) overloads Name for the menu, and the edit form reads the fast status too.

  8. Changing both dn and the naming attribute (e.g. cn) is likely to fail with "not allowed on RDN", because the modify is sent before the rename (~903–913).

  9. Every page with the menu runs a subtree search of up to 10000 entries and parses the whole schema. That may be slow on large directories.

Login-ssl

  • StartTLS is turned on by unrelated settings. Any login-ssl configuration switches LDAP to StartTLS, including one with only PostgreSQL's mode. MySQL uses SSL only if key, cert, ca or verify is set (adminer/drivers/mysql.inc.php:24). Doing the same answers your open question.

Other

  • allFields() can be deleted. The parent implementation no longer sends a SQL query in non-SQL drivers.
  • Consider declaring support("table"). The structure page looks fine with LDAP, and the menu then links table names to it, which should also fix the pepa-linha alignment you mentioned.
  • Consider a trivial syntax highlighter for the printed queries (base/scope/filter). See jush-simpledb.js in https://github.com/vrana/jush for a small example. An external plugin can return the module straight from static function jushModule(): string.
  • <textarea> vs. <input> in the edit form. The form shows <textarea> for multi-valued attributes, but <input> after an error. The textarea is correct. fields() falls back to fields_from_edit(), which is meant for drivers without a schema and builds the columns from $_POST with an empty type. Returning just connection()->fieldsFor($table) should fix it, along with the NULL selects that appear after an error.

@vrana vrana closed this Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants