Skip to main content

LdapConnection

Struct LdapConnection 

Source
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

Source

pub async fn connect(config: &LdapConfig) -> Result<LdapConnection>

Open a connection and get it encrypted, if the configuration says so.

Source

pub fn is_encrypted(&self) -> bool

Whether this connection is encrypted right now.

Source

pub fn bound_as(&self) -> Option<&str>

The DN of the last successful non-anonymous bind, if there was one.

Source

pub fn config(&self) -> &LdapConfig

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.