55use crate :: errors:: Error ;
66use crate :: tokio:: io:: AsyncReadExt ;
77use crate :: {
8+ auth_passthrough:: AuthPassthrough ,
89 config:: get_config,
9- messages:: { error_response, md5_hash_password, write_all, wrong_password, md5_hash_second_pass} ,
10+ messages:: {
11+ error_response, md5_hash_password, md5_hash_second_pass, write_all, wrong_password,
12+ } ,
1013 pool:: { get_pool, ConnectionPool } ,
11- auth_passthrough:: AuthPassthrough ,
1214} ;
1315use bytes:: { BufMut , BytesMut } ;
1416use log:: debug;
1517
16- async fn refetch_auth_hash < S > ( pool : & ConnectionPool , stream : & mut S , username : & str , pool_name : & str ) -> Result < String , Error >
17- where S : tokio:: io:: AsyncWrite + std:: marker:: Unpin + std:: marker:: Send
18+ async fn refetch_auth_hash < S > (
19+ pool : & ConnectionPool ,
20+ stream : & mut S ,
21+ username : & str ,
22+ pool_name : & str ,
23+ ) -> Result < String , Error >
24+ where
25+ S : tokio:: io:: AsyncWrite + std:: marker:: Unpin + std:: marker:: Send ,
1826{
1927 let address = pool. address ( 0 , 0 ) ;
2028 if let Some ( apt) = AuthPassthrough :: from_pool_settings ( & pool. settings ) {
@@ -29,7 +37,8 @@ where S: tokio::io::AsyncWrite + std::marker::Unpin + std::marker::Send
2937 "No password set and auth passthrough failed for database: {}, user: {}" ,
3038 pool_name, username
3139 ) ,
32- ) . await ?;
40+ )
41+ . await ?;
3342
3443 Err ( Error :: ClientError ( format ! (
3544 "Could not obtain hash for {{ username: {:?}, database: {:?} }}. Auth passthrough not enabled." ,
@@ -174,8 +183,7 @@ impl ClearText {
174183 "Invalid password {{ username: {:?}, pool_name: {:?}, application_name: {:?} }}" ,
175184 self . username, self . pool_name, self . application_name
176185 ) ) )
177- }
178- else {
186+ } else {
179187 validate_pool ( write, pool, & self . username , & self . pool_name ) . await ?;
180188
181189 Ok ( None )
@@ -305,7 +313,7 @@ impl Md5 {
305313 Some ( ref password) => {
306314 let our_hash = md5_hash_password ( & self . username , password, & self . salt ) ;
307315
308- if our_hash != password_hash {
316+ if our_hash != password_hash {
309317 wrong_password ( write, & self . username ) . await ?;
310318
311319 Err ( Error :: ClientError ( format ! (
@@ -324,15 +332,24 @@ impl Md5 {
324332
325333 let hash = match hash {
326334 Some ( hash) => hash. to_string ( ) ,
327- None => refetch_auth_hash ( & pool, write, & self . username , & self . pool_name ) . await ?,
335+ None => {
336+ refetch_auth_hash ( & pool, write, & self . username , & self . pool_name )
337+ . await ?
338+ }
328339 } ;
329340
330341 let our_hash = md5_hash_second_pass ( & hash, & self . salt ) ;
331342
332343 // Compare hashes
333344 if our_hash != password_hash {
334345 // Server hash maybe changed
335- let hash = refetch_auth_hash ( & pool, write, & self . username , & self . pool_name ) . await ?;
346+ let hash = refetch_auth_hash (
347+ & pool,
348+ write,
349+ & self . username ,
350+ & self . pool_name ,
351+ )
352+ . await ?;
336353 let our_hash = md5_hash_second_pass ( & hash, & self . salt ) ;
337354
338355 if our_hash != password_hash {
@@ -345,7 +362,13 @@ impl Md5 {
345362 } else {
346363 ( * pool. auth_hash . write ( ) ) = Some ( hash) ;
347364
348- validate_pool ( write, pool. clone ( ) , & self . username , & self . pool_name ) . await ?;
365+ validate_pool (
366+ write,
367+ pool. clone ( ) ,
368+ & self . username ,
369+ & self . pool_name ,
370+ )
371+ . await ?;
349372
350373 Ok ( ( ) )
351374 }
0 commit comments