Skip to content

Commit

Permalink
Added optional ldap_no_tls_verify config that allows bypassiung ldap …
Browse files Browse the repository at this point in the history
…ssl certification check
  • Loading branch information
jerhat committed Jul 9, 2020
1 parent 9d7f226 commit 78be951
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Configuration values are as follows:
|`ldap_host`|String||The hostname or IP address for your ldap server|
|`ldap_scheme`|String|Optional|The that should be used to connect. `ldap` or `ldaps`. This is set by default based on SSL settings|
|`ldap_ssl`|Boolean|Optional|Indicates if SSL should be used. Defaults to `false`|
|`ldap_no_tls_verify`|Boolean|Optional|Indicates if certificate should be verified when using SSL. Defaults to `true`|
|`ldap_port`|Integer|Optional|Port used to connect to the LDAP server. This will default to 389 or 636, depending on your SSL settings|
|`ldap_bind_dn`|String||The dn for the bind user that will connect to LDAP. Eg. `cn=admin,dc=example,dc=org`|
|`ldap_bind_password`|String||The password for the provided bind user.|
Expand Down
6 changes: 6 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ pub struct Config {
ldap_scheme: Option<String>,
ldap_ssl: Option<bool>,
ldap_port: Option<u16>,
// LDAP skip tls verify
ldap_no_tls_verify: Option<bool>,
// LDAP auth config
ldap_bind_dn: String,
ldap_bind_password: Pass,
Expand Down Expand Up @@ -109,6 +111,10 @@ impl Config {
self.ldap_ssl.unwrap_or(false)
}

pub fn get_ldap_no_tls_verify(&self) -> bool {
self.ldap_no_tls_verify.unwrap_or(false)
}

pub fn get_ldap_port(&self) -> u16 {
match self.ldap_port {
Some(ldap_port) => ldap_port,
Expand Down
10 changes: 8 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::error::Error;
use std::thread::sleep;
use std::time::Duration;

use ldap3::{DerefAliases, LdapConn, Scope, SearchEntry, SearchOptions};
use ldap3::{DerefAliases, LdapConn, Scope, SearchEntry, SearchOptions, LdapConnSettings};

mod bw_admin;
mod config;
Expand Down Expand Up @@ -65,8 +65,13 @@ fn ldap_client(
ldap_url: String,
bind_dn: String,
bind_pw: String,
no_tls_verify: bool
) -> Result<LdapConn, Box<dyn Error>> {
let ldap = LdapConn::new(ldap_url.as_str())?;

let settings = LdapConnSettings::new()
.set_no_tls_verify(no_tls_verify);

let ldap = LdapConn::with_settings(settings, ldap_url.as_str())?;
match ldap.simple_bind(bind_dn.as_str(), bind_pw.as_str()) {
_ => {}
};
Expand All @@ -80,6 +85,7 @@ fn search_entries(config: &config::Config) -> Result<Vec<SearchEntry>, Box<dyn E
config.get_ldap_url(),
config.get_ldap_bind_dn(),
config.get_ldap_bind_password(),
config.get_ldap_no_tls_verify()
);

if ldap.is_err() {
Expand Down

0 comments on commit 78be951

Please sign in to comment.