/ldap3

A pure-Rust LDAP library using the Tokio stack

Primary LanguageRustApache License 2.0Apache-2.0

LDAP client library

A pure-Rust LDAP client library using the Tokio stack.

Compatibility with Tokio versions

Tokio 1.0 is the long-term stable version of the async runtime, and ldap3 0.9 is compatible with it. For the earlier Tokio releases, use ldap3 0.8 (Tokio 0.3) or 0.7 (Tokio 0.2).

All functional changes in 0.9.2 have been backported to 0.8.3 and 0.7.4. The plan is to limit further 0.8.x and 0.7.x changes to bug- and compatibility fixes until June 2021, and continue development solely on 0.9.x.

Documentation

Note

The library is client-only. One cannot make an LDAP server or a proxy with it. It supports only version 3 of the protocol over connection-oriented transports.

Usage

The library can be used either synchronously or asynchronously. The aim is to offer essentially the same call interface for both flavors, with the necessary differences in interaction and return values according to the nature of I/O.

Add this to your Cargo.toml:

[dependencies.ldap3]
version = "0.9"

Examples

The following two examples perform exactly the same operation and should produce identical results. They should be run against the example server in the data subdirectory of the crate source. Other sample programs expecting the same server setup can be found in the examples subdirectory.

Synchronous search

use ldap3::{LdapConn, Scope, SearchEntry};
use ldap3::result::Result;

fn main() -> Result<()> {
    let mut ldap = LdapConn::new("ldap://localhost:2389")?;
    let (rs, _res) = ldap.search(
        "ou=Places,dc=example,dc=org",
        Scope::Subtree,
        "(&(objectClass=locality)(l=ma*))",
        vec!["l"]
    )?.success()?;
    for entry in rs {
        println!("{:?}", SearchEntry::construct(entry));
    }
    Ok(ldap.unbind()?)
}

Asynchronous search

use ldap3::{LdapConnAsync, Scope, SearchEntry};
use ldap3::result::Result;

#[tokio::main]
async fn main() -> Result<()> {
    let (conn, mut ldap) = LdapConnAsync::new("ldap://localhost:2389").await?;
    ldap3::drive!(conn);
    let (rs, _res) = ldap.search(
        "ou=Places,dc=example,dc=org",
        Scope::Subtree,
        "(&(objectClass=locality)(l=ma*))",
        vec!["l"]
    ).await?.success()?;
    for entry in rs {
        println!("{:?}", SearchEntry::construct(entry));
    }
    Ok(ldap.unbind().await?)
}

Compile-time features

The following features are available at compile time:

  • sync (enabled by default): Synchronous API support.

  • tls (enabled by default): TLS support, backed by the native-tls crate, which uses a platform-specific TLS backend. This is an alias for tls-native.

  • tls-rustls (disabled by default): TLS support, backed by the Rustls library.

Without any features, only plain TCP connections (and Unix domain sockets on Unix-like platforms) are available. For TLS support, tls and tls-rustls are mutually exclusive: choosing both will produce a compile-time error.

License

Licensed under either of:

at your option.