Lines
38.71 %
Functions
66.67 %
Branches
100 %
use russh::ChannelId;
use russh::server::Session;
use server::command::user::Refusal;
use sqlx::types::Uuid;
use super::Session_;
impl Session_ {
/// Refuses a channel whose tenant database is withheld by the fleet
/// migrator, telling the user why rather than failing opaquely inside the
/// session.
///
/// Fails **closed**: a directory lookup that errors refuses too. Treating an
/// unreadable directory as "not quarantined" would hand a session to
/// exactly the tenant whose state could not be confirmed.
/// Every channel that can reach the tenant's database goes through here.
/// Guarding only the shell left `nomisync-eval` open, and that subsystem
/// evaluates scripts against the same database.
pub(super) async fn refuse_if_withheld(
&self,
user_id: Uuid,
channel: ChannelId,
session: &mut Session,
kind: &str,
) -> Result<bool, russh::Error> {
let refusal = match server::command::user::account_refusal(user_id).await {
Ok(refusal) => refusal,
Err(e) => {
if !e.is_unavailable() {
tracing::error!("{kind}_request refusing user_id={user_id}: {e}");
}
Some(Refusal::Quarantined)
};
let Some(refusal) = refusal else {
return Ok(false);
let notice = match refusal {
Refusal::Quarantined => {
tracing::warn!("{kind}_request refused user_id={user_id} reason=quarantined");
"\r\nThis account is undergoing maintenance and is temporarily \
unavailable. Please try again shortly.\r\n"
Refusal::Disabled => {
tracing::warn!("{kind}_request refused user_id={user_id} reason=disabled");
"\r\nThis account is disabled.\r\n"
.to_owned();
session.data(channel, notice.into_bytes())?;
session.close(channel)?;
Ok(true)
pub(super) fn refuse_request(&self, kind: &str) {
tracing::warn!(
"refused request kind={kind} peer={:?} user_id={:?}",
self.peer,
self.user_id
);