Crate ldap3 [] [src]

A pure-Rust LDAP library using the Tokio stack.

Usage

In Cargo.toml:

[dependencies.ldap3]
version = "0.6"

In the crate root (src/lib.rs or src/main.rs):

extern crate ldap3;

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 connection handle used by both.

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

Since the library is still in development, none of the interfaces should be considered stable. If a breaking change of some component is planned, it will be noted in the documentation with a bolded Note, and a link to the GitHub issue discussing the change, if applicable. General, crate-level issues with the documentation can be discussed here.

The documentation is written for readers familiar with LDAP concepts and terminology, which it won't attempt to explain.

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.

extern crate ldap3;

use std::error::Error;

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

fn main() {
    match do_search() {
        Ok(_) => (),
        Err(e) => println!("{}", e),
    }
}

fn do_search() -> Result<(), Box<Error>> {
    let 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(())
}
extern crate futures;
extern crate ldap3;
extern crate tokio_core;

use std::error::Error;

use futures::Future;
use ldap3::{LdapConnAsync, Scope, SearchEntry};
use tokio_core::reactor::Core;

fn main() {
    match do_search() {
        Ok(_) => (),
        Err(e) => println!("{}", e),
    }
}

fn do_search() -> Result<(), Box<Error>> {
    let mut core = Core::new()?;
    let handle = core.handle();
    let ldap = LdapConnAsync::new("ldap://localhost:2389", &handle)?;
    let srch = ldap.and_then(|ldap|
        ldap.search(
            "ou=Places,dc=example,dc=org",
            Scope::Subtree,
            "(&(objectClass=locality)(l=ma*))",
            vec!["l"]
        ))
        .and_then(|response| response.success())
        .and_then(|(rs, _res)| Ok(rs));
    let rs = core.run(srch)?;
    for entry in rs {
        println!("{:?}", SearchEntry::construct(entry));
    }
    Ok(())
}

Re-exports

pub use result::LdapResult;

Modules

asn1

ASN.1 structure construction and parsing.

controls

Control construction and parsing.

exop

Extended operation construction and parsing.

result

Operation result structures and helpers.

Structs

EntryStream

Handle for obtaining a stream of search results.

Ldap

LDAP connection. *

LdapConn

Handle for LDAP operations.

LdapConnAsync

Asynchronous handle for LDAP operations; analogue of LdapConn. *

LdapConnSettings

Additional settings for an LDAP connection.

ResultEntry

Wrapper for the internal structure of a result entry.

SearchEntry

Parsed search result entry.

SearchOptions

Additional parameters for the Search operation.

SearchStream

Stream of search results. *

Enums

DerefAliases

Possible values for alias dereferencing during search.

Mod

Possible sub-operations for the Modify operation.

Scope

Possible values for search scope.

Functions

dn_escape

Escape an attribute value in a relative distinguished name (RDN).

ldap_escape

Escape a filter literal.