1
- use ldap3:: { LdapConnAsync , LdapConnSettings } ;
2
1
use crate :: errors:: { ClientIdentifier , Error } ;
3
2
use crate :: pool:: BanReason ;
4
3
/// Handle clients by pretending to be a PostgreSQL server.
5
4
use bytes:: { Buf , BufMut , BytesMut } ;
5
+ use ldap3:: { LdapConnAsync , LdapConnSettings } ;
6
6
use log:: { debug, error, info, trace, warn} ;
7
7
use once_cell:: sync:: Lazy ;
8
8
use std:: collections:: { HashMap , VecDeque } ;
@@ -414,14 +414,18 @@ pub async fn startup_tls(
414
414
}
415
415
}
416
416
417
-
418
417
// Pass in username and password to authenticate against LDAP
419
- async fn authenticate_ldap ( username : & str , password : & str , ldapurl : & str , ldapsuffix : & str ) -> bool {
418
+ async fn authenticate_ldap (
419
+ username : & str ,
420
+ password : & str ,
421
+ ldapurl : & str ,
422
+ ldapsuffix : & str ,
423
+ ) -> bool {
420
424
// Connection to the LDAP Server
421
425
let ldap_conn_settings = LdapConnSettings :: new ( ) ;
422
- let ( conn, mut ldap) =
423
- LdapConnAsync :: with_settings (
424
- ldap_conn_settings , ldapurl ) . await . unwrap ( ) ;
426
+ let ( conn, mut ldap) = LdapConnAsync :: with_settings ( ldap_conn_settings , ldapurl )
427
+ . await
428
+ . unwrap ( ) ;
425
429
ldap3:: drive!( conn) ;
426
430
427
431
// 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
430
434
431
435
// Attempts a simple bind using the passed in values of username and Password
432
436
println ! ( "{:?}" , password) ;
433
- let result = ldap. simple_bind ( email. as_str ( ) , & password) . await . unwrap ( ) . success ( ) ;
437
+ let result = ldap
438
+ . simple_bind ( email. as_str ( ) , & password)
439
+ . await
440
+ . unwrap ( )
441
+ . success ( ) ;
434
442
ldap. unbind ( ) . await . unwrap ( ) ;
435
443
436
444
// 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
440
448
}
441
449
}
442
450
443
-
444
451
impl < S , T > Client < S , T >
445
452
where
446
453
S : tokio:: io:: AsyncRead + std:: marker:: Unpin ,
@@ -575,8 +582,7 @@ where
575
582
576
583
return Err ( error) ;
577
584
}
578
- }
579
- else if let "ldap" = config. general . admin_auth_type . as_str ( ) {
585
+ } else if let "ldap" = config. general . admin_auth_type . as_str ( ) {
580
586
clear_text_challenge ( & mut write) . await ?;
581
587
let code = match read. read_u8 ( ) . await {
582
588
Ok ( p) => p,
@@ -624,14 +630,15 @@ where
624
630
& str_password,
625
631
& config. general . admin_auth_ldapurl . unwrap ( ) ,
626
632
& config. general . admin_auth_ldapsuffix . unwrap ( ) ,
627
- ) . await ;
633
+ )
634
+ . await ;
628
635
if unsuccessful_auth {
629
- wrong_password ( & mut write, username) . await ?;
636
+ wrong_password ( & mut write, username) . await ?;
630
637
631
- return Err ( Error :: ClientGeneralError (
632
- "Invalid password" . into ( ) ,
633
- client_identifier,
634
- ) ) ;
638
+ return Err ( Error :: ClientGeneralError (
639
+ "Invalid password" . into ( ) ,
640
+ client_identifier,
641
+ ) ) ;
635
642
}
636
643
}
637
644
( false , generate_server_parameters_for_admin ( ) )
@@ -790,9 +797,7 @@ where
790
797
) ) ;
791
798
}
792
799
}
793
- }
794
-
795
- else if let "ldap" = pool. settings . user . auth_type . as_str ( ) {
800
+ } else if let "ldap" = pool. settings . user . auth_type . as_str ( ) {
796
801
clear_text_challenge ( & mut write) . await ?;
797
802
let code = match read. read_u8 ( ) . await {
798
803
Ok ( p) => p,
@@ -840,16 +845,16 @@ where
840
845
& str_password,
841
846
& pool. settings . user . auth_ldapurl . clone ( ) . unwrap ( ) ,
842
847
& pool. settings . user . auth_ldapsuffix . clone ( ) . unwrap ( ) ,
843
- ) . await ;
848
+ )
849
+ . await ;
844
850
if unsuccessful_auth {
845
- wrong_password ( & mut write, username) . await ?;
851
+ wrong_password ( & mut write, username) . await ?;
846
852
847
- return Err ( Error :: ClientGeneralError (
848
- "Invalid password" . into ( ) ,
849
- client_identifier,
850
- ) ) ;
853
+ return Err ( Error :: ClientGeneralError (
854
+ "Invalid password" . into ( ) ,
855
+ client_identifier,
856
+ ) ) ;
851
857
}
852
-
853
858
}
854
859
let transaction_mode = pool. settings . pool_mode == PoolMode :: Transaction ;
855
860
prepared_statements_enabled =
0 commit comments