mirror of
https://github.com/ViViDboarder/bitwarden_rs_ldap.git
synced 2024-12-22 17:17:34 +00:00
updated the ldap bind functions to provide for anonymous binds
This commit is contained in:
parent
95ce406c69
commit
0b25b61caf
@ -70,8 +70,8 @@ pub struct Config {
|
||||
ldap_port: Option<u16>,
|
||||
ldap_no_tls_verify: Option<bool>,
|
||||
// LDAP auth config
|
||||
ldap_bind_dn: String,
|
||||
ldap_bind_password: Pass,
|
||||
ldap_bind_dn: Option<String>,
|
||||
ldap_bind_password: Option<Pass>,
|
||||
// LDAP search config
|
||||
ldap_search_base_dn: String,
|
||||
ldap_search_filter: String,
|
||||
@ -155,11 +155,11 @@ impl Config {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_ldap_bind_dn(&self) -> String {
|
||||
pub fn get_ldap_bind_dn(&self) -> Option<String> {
|
||||
self.ldap_bind_dn.clone()
|
||||
}
|
||||
|
||||
pub fn get_ldap_bind_password(&self) -> String {
|
||||
pub fn get_ldap_bind_password(&self) -> Option<String> {
|
||||
self.ldap_bind_password.clone()
|
||||
}
|
||||
|
||||
|
11
src/main.rs
11
src/main.rs
@ -74,8 +74,8 @@ fn get_existing_users(client: &mut vw_admin::Client) -> Result<HashSet<String>,
|
||||
/// Creates an LDAP connection, authenticating if necessary
|
||||
fn ldap_client(
|
||||
ldap_url: String,
|
||||
bind_dn: String,
|
||||
bind_pw: String,
|
||||
bind_dn: Option<String>,
|
||||
bind_pw: Option<String>,
|
||||
no_tls_verify: bool,
|
||||
starttls: bool,
|
||||
) -> Result<LdapConn, AnyError> {
|
||||
@ -84,8 +84,11 @@ fn ldap_client(
|
||||
.set_no_tls_verify(no_tls_verify);
|
||||
let mut ldap = LdapConn::with_settings(settings, ldap_url.as_str())
|
||||
.context("Failed to connect to LDAP server")?;
|
||||
ldap.simple_bind(bind_dn.as_str(), bind_pw.as_str())
|
||||
.context("Could not bind to LDAP server")?;
|
||||
|
||||
if bind_dn.is_some() && bind_pw.is_some() {
|
||||
ldap.simple_bind(&bind_dn.unwrap(), &bind_pw.unwrap())
|
||||
.context("Could not bind to LDAP server")?;
|
||||
}
|
||||
|
||||
Ok(ldap)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user