forked from lavina/lavina
1
0
Fork 0

keep todos for uncertain behaviour

This commit is contained in:
G1ng3r 2024-02-05 21:03:45 +03:00
parent d6da40e4ff
commit bb09e8bb21
1 changed files with 33 additions and 20 deletions

View File

@ -181,17 +181,17 @@ async fn handle_registration<'a>(
} }
CapabilitySubcommand::End => { CapabilitySubcommand::End => {
let Some((ref username, ref realname)) = future_username else { let Some((ref username, ref realname)) = future_username else {
break Err(anyhow::Error::msg("Protocol violated")); todo!();
}; };
let Some(nickname) = future_nickname.clone() else { let Some(nickname) = future_nickname.clone() else {
break Err(anyhow::Error::msg("Protocol violated")); todo!();
}; };
let username = username.clone(); let username = username.clone();
let realname = realname.clone(); let realname = realname.clone();
let candidate_user = RegisteredUser { let candidate_user = RegisteredUser {
nickname: nickname.clone(), nickname: nickname.clone(),
username, username,
realname realname,
}; };
if enabled_capabilities.contains(Capabilities::Sasl) if enabled_capabilities.contains(Capabilities::Sasl)
&& validated_user.as_ref() == Some(&candidate_user.nickname) && validated_user.as_ref() == Some(&candidate_user.nickname)
@ -202,8 +202,10 @@ async fn handle_registration<'a>(
sasl_fail_message( sasl_fail_message(
config.server_name.clone(), config.server_name.clone(),
nickname.clone(), nickname.clone(),
"User credentials was not provided".into() "User credentials was not provided".into(),
).write_async(writer).await?; )
.write_async(writer)
.await?;
writer.flush().await?; writer.flush().await?;
continue; continue;
}; };
@ -225,8 +227,10 @@ async fn handle_registration<'a>(
sasl_fail_message( sasl_fail_message(
config.server_name.clone(), config.server_name.clone(),
nickname.clone(), nickname.clone(),
"User credentials was not provided".into() "User credentials was not provided".into(),
).write_async(writer).await?; )
.write_async(writer)
.await?;
writer.flush().await?; writer.flush().await?;
continue; continue;
}; };
@ -249,8 +253,10 @@ async fn handle_registration<'a>(
sasl_fail_message( sasl_fail_message(
config.server_name.clone(), config.server_name.clone(),
nickname.clone(), nickname.clone(),
"User credentials was not provided".into() "User credentials was not provided".into(),
).write_async(writer).await?; )
.write_async(writer)
.await?;
writer.flush().await?; writer.flush().await?;
continue; continue;
}; };
@ -276,7 +282,13 @@ async fn handle_registration<'a>(
writer.flush().await?; writer.flush().await?;
} else { } else {
if let Some(nickname) = future_nickname.clone() { if let Some(nickname) = future_nickname.clone() {
sasl_fail_message(config.server_name.clone(), nickname.clone(), "Unsupported mechanism".into()).write_async(writer).await?; sasl_fail_message(
config.server_name.clone(),
nickname.clone(),
"Unsupported mechanism".into(),
)
.write_async(writer)
.await?;
writer.flush().await?; writer.flush().await?;
} else { } else {
break Err(anyhow::Error::msg("Wrong authentication sequence")); break Err(anyhow::Error::msg("Wrong authentication sequence"));
@ -287,10 +299,11 @@ async fn handle_registration<'a>(
if let Err(e) = auth_user(storage, &body.login, &body.password).await { if let Err(e) = auth_user(storage, &body.login, &body.password).await {
tracing::warn!("Authentication failed: {:?}", e); tracing::warn!("Authentication failed: {:?}", e);
if let Some(nickname) = future_nickname.clone() { if let Some(nickname) = future_nickname.clone() {
sasl_fail_message(config.server_name.clone(), nickname.clone(), "Bad credentials".into()).write_async(writer).await?; sasl_fail_message(config.server_name.clone(), nickname.clone(), "Bad credentials".into())
.write_async(writer)
.await?;
writer.flush().await?; writer.flush().await?;
} else { } else {
} }
} else { } else {
let login: Str = body.login.into(); let login: Str = body.login.into();
@ -335,7 +348,7 @@ fn sasl_fail_message(sender: Str, nick: Str, text: Str) -> ServerMessage {
ServerMessage { ServerMessage {
tags: vec![], tags: vec![],
sender: Some(sender), sender: Some(sender),
body: ServerMessageBody::N904SaslFail { nick, text } body: ServerMessageBody::N904SaslFail { nick, text },
} }
} }