1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Demonstrates:
//
// 1. Using a synchronous streaming Search.
// 2. A commented-out invalid use of LdapConn while
// a derived EntryStream is active.
// 3. The technique for abandoning the search, with
// directions for the ordering of steps to avoid
// double-borrowing.
use ldap3::result::Result;
use ldap3::{LdapConn, Scope, SearchEntry};
fn main() -> Result<()> {
let mut ldap = LdapConn::new("ldap://localhost:2389")?;
let mut search = ldap.streaming_search(
"ou=Places,dc=example,dc=org",
Scope::Subtree,
"(&(l=ma*)(objectClass=locality))",
vec!["l"],
)?;
while let Some(entry) = search.next()? {
let entry = SearchEntry::construct(entry);
println!("{:?}", entry);
}
// The following two statements show how one would
// Abandon a Search. The statements are commented out
// because the ldap handle shouldn't be used before result()
// is called on the streaming hanlde. To work, a) abandon()
// should follow result(), b) there should be no error
// handling of result(), because a prematurely finished
// stream will always return an error.
//
//let msgid = search.last_id();
//ldap.abandon(msgid)?;
let _res = search.result().success()?;
Ok(ldap.unbind()?)
}