Clause
← All documentation

eldap

Clause's eldap is OTP's LDAP client as MongooseIM calls it: mongoose_ldap_worker opens, binds and closes connections, and eldap_pool searches, adds, deletes and changes passwords through them with filters built by eldap_utils and eldap_filter. The module is Erlang, in library/eldap/, with the eldap.app resource and OTP's eldap.hrl.

Behaviour was observed on OTP 29 against a local server printing each request (the BER bytes eldap sends, results, errors, message identifiers, log calls, connections) and is checked by the eldap_requests golden.

Codec

The LDAPv3 messages are encoded and decoded by 'ELDAPv3', which clau generates at build time from ELDAPv3.asn1 into library-asn1/eldap/ with OTP's options (ber, legacy_erlang_types: octet strings decode as lists). The specification is RFC 4511's module with RFC 3062's password modify values and RFC 2696's paged results value, so the records eldap builds and logs are OTP's ('SearchRequest', 'AttributeValueAssertion', 'ModifyRequest_changes_SEQOF', 'Control', ...).

Connections

open/1,2 starts a connection process linked to the caller and tries the hosts in order, with the options port (389, also with ssl), timeout (a positive number of milliseconds for each request's answer; infinity without it), log (a fun of three arguments; other values are ignored), ssl (TLS from the start, with sslopts), tcpopts and anon_auth. A wrong option is {error, {wrong_option, Option}}; the socket options eldap sets itself (active, binary, deliver, list, mode, packet) are {error, {{forbidden_tcp_option, Option}, Text}}; when no host connects, each failure is logged (Connect: ~p failed ~p~n) and the result is {error, "connect failed"}.

Calls send a message to the connection and wait for its answer without a timeout: a call to a closed handle waits forever, as OTP's. close/1 sends the unbind request (with the current message identifier) and returns ok without waiting. controlling_process/2 links the caller to the new process and unlinks the connection from the caller. info/1 is the socket and socket_type (ssl for ssl connections, tcp otherwise, also after StartTLS). getopts/2 answers port, log, timeout and ssl; another name is {error, {error, {case_clause, Name}}}. start_tls/2,3,4 asks the server with the current message identifier, then upgrades with ssl: {error, tls_already_started}, {error, {response, Code}} for a refusal, the ssl error for a failed handshake (the connection is then closed).

Requests

Filters ('and'/1, 'or'/1, 'not'/1, equalityMatch/2, substrings/2, present/1, approxMatch/2, greaterOrEqual/2, lessOrEqual/2, extensibleMatch/2), scopes and dereference values are OTP's terms; invalid substrings and extensible match options throw {error, {substring_arg, X}} and {error, {extensibleMatch_arg, X}}. paged_result_control/1,2 and paged_result_cookie/1 handle RFC 2696's paged results.

Not provided: parse_dn/1 and parse_ldap_url/1 (OTP's DN and URL grammar) and the internal loop/2.