pub struct LdapConnection { /* private fields */ }Expand description
A live connection to a directory.
No Debug. The bytes it writes hold a password whenever a simple bind
goes out, and a type that can be printed is a type that ends up in a log.
Implementations§
Source§impl LdapConnection
impl LdapConnection
Sourcepub async fn connect(config: &LdapConfig) -> Result<LdapConnection>
pub async fn connect(config: &LdapConfig) -> Result<LdapConnection>
Open a connection and get it encrypted, if the configuration says so.
Sourcepub fn is_encrypted(&self) -> bool
pub fn is_encrypted(&self) -> bool
Whether this connection is encrypted right now.
Sourcepub fn bound_as(&self) -> Option<&str>
pub fn bound_as(&self) -> Option<&str>
The DN of the last successful non-anonymous bind, if there was one.
pub fn config(&self) -> &LdapConfig
Sourcepub async fn bind(&mut self, dn: &str, password: &str) -> Result<LdapResult>
pub async fn bind(&mut self, dn: &str, password: &str) -> Result<LdapResult>
A simple bind: name plus password.
Refuses two things before writing a byte. An empty password, because
LDAP would answer it with success — see Operation::simple_bind.
And an unencrypted connection, because a simple bind puts the password
on the wire verbatim and there is no way to un-send it.
Sourcepub async fn bind_anonymous(&mut self) -> Result<LdapResult>
pub async fn bind_anonymous(&mut self) -> Result<LdapResult>
An anonymous bind — no name and no password, and no authentication.
Spelled out so it cannot be arrived at by leaving a field empty.
Sourcepub async fn search(&mut self, request: &SearchRequest) -> Result<SearchOutcome>
pub async fn search(&mut self, request: &SearchRequest) -> Result<SearchOutcome>
Run a search to completion, collecting every entry.
Entries are collected rather than streamed because the searches this package exists for return one entry. A search that could return thousands wants a paged control and an iterator, and should not pretend this is that.
Sourcepub async fn unbind(self) -> Result<()>
pub async fn unbind(self) -> Result<()>
Say goodbye and close.
UnbindRequest has no response — it means “I am closing this”, not
“please reply” — so this writes and shuts down without waiting. Consumes
the connection, because there is nothing left to do with it.
Sourcepub async fn send(&mut self, operation: &Operation) -> Result<i64>
pub async fn send(&mut self, operation: &Operation) -> Result<i64>
Write one operation and return the message id it went out under.
This is where the transport rule is enforced, because it is the single place every request passes through.
Sourcepub async fn receive(&mut self, expected_id: i64) -> Result<LdapMessage>
pub async fn receive(&mut self, expected_id: i64) -> Result<LdapMessage>
Read the response to a particular message id.
LDAP lets several operations be outstanding at once, and the id is the only thing that says which answer belongs to which question. This client asks one thing at a time, so anything else arriving means either the directory is confused or something is injecting messages — and in both cases carrying on with the wrong answer is worse than stopping.