From 0b25b61cafef7dd3a701b757731d177a953f122d Mon Sep 17 00:00:00 2001 From: Shaun See Tow Date: Sat, 26 Oct 2024 14:12:46 +0800 Subject: [PATCH] updated the ldap bind functions to provide for anonymous binds --- src/config.rs | 8 ++++---- src/main.rs | 11 +++++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/config.rs b/src/config.rs index e25d3ab..7649b86 100644 --- a/src/config.rs +++ b/src/config.rs @@ -70,8 +70,8 @@ pub struct Config { ldap_port: Option, ldap_no_tls_verify: Option, // LDAP auth config - ldap_bind_dn: String, - ldap_bind_password: Pass, + ldap_bind_dn: Option, + ldap_bind_password: Option, // 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 { self.ldap_bind_dn.clone() } - pub fn get_ldap_bind_password(&self) -> String { + pub fn get_ldap_bind_password(&self) -> Option { self.ldap_bind_password.clone() } diff --git a/src/main.rs b/src/main.rs index 27f85fb..cb9a583 100644 --- a/src/main.rs +++ b/src/main.rs @@ -74,8 +74,8 @@ fn get_existing_users(client: &mut vw_admin::Client) -> Result, /// Creates an LDAP connection, authenticating if necessary fn ldap_client( ldap_url: String, - bind_dn: String, - bind_pw: String, + bind_dn: Option, + bind_pw: Option, no_tls_verify: bool, starttls: bool, ) -> Result { @@ -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) }