inejge / ldap3

A pure-Rust LDAP library using the Tokio stack
Apache License 2.0
220 stars 38 forks source link

Bug? simple_bind does not return error if credentials are wrong #113

Closed c-antin closed 11 months ago

c-antin commented 11 months ago

minimal reproducible example:

use ldap3::result::Result;
use ldap3::LdapConn;

fn main() -> Result<()> {
    let password = rpassword::read_password().unwrap();
    let mut ldap = LdapConn::new("ldaps://domain.local")?;
    ldap.simple_bind("username@domain.local", &password)?;
    Ok(ldap.unbind()?)
}
inejge commented 11 months ago

Try:

ldap.simple_bind("username@domain.local", &password)?.success()?;

The first ? gives you the result of the protocol operation. An error there is usually a problem with I/O. A successful return is an LdapResult structure, which you can turn into a Result with success(). Don't use it blindly, there are situations where a non-zero result code indicates a kind of success.