Crate ldap3

source ·
Expand description

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

Usage

In Cargo.toml:

[dependencies.ldap3]
version = "0.11.3"

Summary

The library provides both synchronous and asynchronous interfaces. The LdapConn structure is the starting point for all synchronous operations. LdapConnAsync is its asynchronous analogue, and Ldap is the low-level asynchronous handle used internally by LdapConn, and explicitly by the users of the asynchronous interface.

In the struct list, async-related structs have an asterisk (*) after the short description.

The documentation is written for readers familiar with LDAP concepts and terminology, which it won’t attempt to explain. If you need an introductory text, you can try the primer included in this library.

Compile-time features

The following features are available at compile time:

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

  • gssapi (disabled by default): Kerberos/GSSAPI support. On Windows, system support crates and SDK libraries are used. Elsewhere, the feature needs Clang and its development libraries (for bindgen), as well as the Kerberos development libraries. On Debian/Ubuntu, that means clang-N, libclang-N-dev and libkrb5-dev. It should be clear from these requirements that GSSAPI support uses FFI to C libraries; you should consider the security implications of this fact.

    For usage notes and caveats, see the documentation for Ldap::sasl_gssapi_bind().

  • 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.

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.

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()?)
}
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?)
}

Re-exports

Modules

  • Search operation adapters.
  • ASN.1 structure construction and parsing.
  • Control construction and parsing.
  • Extended operation construction and parsing.
  • Operation result structures and helpers.

Macros

  • Drive the connection until its completion. *

Structs

Enums

  • Possible values for alias dereferencing during search.
  • LDAP URL extensions.
  • Possible sub-operations for the Modify operation.
  • Possible values for search scope.
  • Possible states of a SearchStream.

Functions

Type Definitions