From 4be803c469f9254d43646365b2e9c817ae47a840 Mon Sep 17 00:00:00 2001 From: CommanderKeynes Date: Mon, 26 Aug 2024 12:41:27 -0500 Subject: [PATCH] Format --- src/client.rs | 57 ++++++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/src/client.rs b/src/client.rs index 39e93fea..8e5c707a 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,8 +1,8 @@ -use ldap3::{LdapConnAsync, LdapConnSettings}; use crate::errors::{ClientIdentifier, Error}; use crate::pool::BanReason; /// Handle clients by pretending to be a PostgreSQL server. use bytes::{Buf, BufMut, BytesMut}; +use ldap3::{LdapConnAsync, LdapConnSettings}; use log::{debug, error, info, trace, warn}; use once_cell::sync::Lazy; use std::collections::{HashMap, VecDeque}; @@ -414,14 +414,18 @@ pub async fn startup_tls( } } - // Pass in username and password to authenticate against LDAP -async fn authenticate_ldap(username: &str, password: &str, ldapurl: &str, ldapsuffix: &str) -> bool { +async fn authenticate_ldap( + username: &str, + password: &str, + ldapurl: &str, + ldapsuffix: &str, +) -> bool { // Connection to the LDAP Server let ldap_conn_settings = LdapConnSettings::new(); - let (conn, mut ldap) = - LdapConnAsync::with_settings( - ldap_conn_settings, ldapurl).await.unwrap(); + let (conn, mut ldap) = LdapConnAsync::with_settings(ldap_conn_settings, ldapurl) + .await + .unwrap(); ldap3::drive!(conn); // Takes the username provided and converts it into an email for validation @@ -430,7 +434,11 @@ async fn authenticate_ldap(username: &str, password: &str, ldapurl: &str, ldapsu // Attempts a simple bind using the passed in values of username and Password println!("{:?}", password); - let result = ldap.simple_bind(email.as_str(), &password).await.unwrap().success(); + let result = ldap + .simple_bind(email.as_str(), &password) + .await + .unwrap() + .success(); ldap.unbind().await.unwrap(); // If the authentication is successful return true, else return false. @@ -440,7 +448,6 @@ async fn authenticate_ldap(username: &str, password: &str, ldapurl: &str, ldapsu } } - impl Client where S: tokio::io::AsyncRead + std::marker::Unpin, @@ -575,8 +582,7 @@ where return Err(error); } - } - else if let "ldap" = config.general.admin_auth_type.as_str() { + } else if let "ldap" = config.general.admin_auth_type.as_str() { clear_text_challenge(&mut write).await?; let code = match read.read_u8().await { Ok(p) => p, @@ -624,14 +630,15 @@ where &str_password, &config.general.admin_auth_ldapurl.unwrap(), &config.general.admin_auth_ldapsuffix.unwrap(), - ).await; + ) + .await; if unsuccessful_auth { - wrong_password(&mut write, username).await?; + wrong_password(&mut write, username).await?; - return Err(Error::ClientGeneralError( - "Invalid password".into(), - client_identifier, - )); + return Err(Error::ClientGeneralError( + "Invalid password".into(), + client_identifier, + )); } } (false, generate_server_parameters_for_admin()) @@ -790,9 +797,7 @@ where )); } } - } - - else if let "ldap" = pool.settings.user.auth_type.as_str() { + } else if let "ldap" = pool.settings.user.auth_type.as_str() { clear_text_challenge(&mut write).await?; let code = match read.read_u8().await { Ok(p) => p, @@ -840,16 +845,16 @@ where &str_password, &pool.settings.user.auth_ldapurl.clone().unwrap(), &pool.settings.user.auth_ldapsuffix.clone().unwrap(), - ).await; + ) + .await; if unsuccessful_auth { - wrong_password(&mut write, username).await?; + wrong_password(&mut write, username).await?; - return Err(Error::ClientGeneralError( - "Invalid password".into(), - client_identifier, - )); + return Err(Error::ClientGeneralError( + "Invalid password".into(), + client_identifier, + )); } - } let transaction_mode = pool.settings.pool_mode == PoolMode::Transaction; prepared_statements_enabled =