Add support for starttls

Fixes #18
This commit is contained in:
Ian 2020-12-27 10:50:10 -05:00 committed by ViViDboarder
parent be227a638d
commit 402fff84fd
2 changed files with 10 additions and 1 deletions

View File

@ -43,6 +43,7 @@ pub struct Config {
ldap_host: String, ldap_host: String,
ldap_scheme: Option<String>, ldap_scheme: Option<String>,
ldap_ssl: Option<bool>, ldap_ssl: Option<bool>,
ldap_starttls: Option<bool>,
ldap_port: Option<u16>, ldap_port: Option<u16>,
ldap_no_tls_verify: Option<bool>, ldap_no_tls_verify: Option<bool>,
// LDAP auth config // LDAP auth config
@ -110,6 +111,10 @@ impl Config {
self.ldap_ssl.unwrap_or(false) self.ldap_ssl.unwrap_or(false)
} }
pub fn get_ldap_starttls(&self) -> bool {
self.ldap_starttls.unwrap_or(false)
}
pub fn get_ldap_no_tls_verify(&self) -> bool { pub fn get_ldap_no_tls_verify(&self) -> bool {
self.ldap_no_tls_verify.unwrap_or(false) self.ldap_no_tls_verify.unwrap_or(false)
} }

View File

@ -66,8 +66,11 @@ fn ldap_client(
bind_dn: String, bind_dn: String,
bind_pw: String, bind_pw: String,
no_tls_verify: bool, no_tls_verify: bool,
starttls: bool,
) -> Result<LdapConn, Box<dyn Error>> { ) -> Result<LdapConn, Box<dyn Error>> {
let settings = LdapConnSettings::new().set_no_tls_verify(no_tls_verify); let settings = LdapConnSettings::new()
.set_starttls(starttls)
.set_no_tls_verify(no_tls_verify);
let ldap = LdapConn::with_settings(settings, ldap_url.as_str())?; let ldap = LdapConn::with_settings(settings, ldap_url.as_str())?;
match ldap.simple_bind(bind_dn.as_str(), bind_pw.as_str()) { match ldap.simple_bind(bind_dn.as_str(), bind_pw.as_str()) {
_ => {} _ => {}
@ -83,6 +86,7 @@ fn search_entries(config: &config::Config) -> Result<Vec<SearchEntry>, Box<dyn E
config.get_ldap_bind_dn(), config.get_ldap_bind_dn(),
config.get_ldap_bind_password(), config.get_ldap_bind_password(),
config.get_ldap_no_tls_verify(), config.get_ldap_no_tls_verify(),
config.get_ldap_starttls(),
); );
if ldap.is_err() { if ldap.is_err() {