Skip to content

Commit

Permalink
fix/simplify emergency access initialization
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Volk <[email protected]>
  • Loading branch information
jevolk committed Jun 3, 2024
1 parent 1181046 commit d1b6485
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 34 deletions.
47 changes: 17 additions & 30 deletions src/service/globals/emerg_access.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,18 @@
use conduit::Result;
use ruma::{
events::{
push_rules::PushRulesEventContent, room::message::RoomMessageEventContent, GlobalAccountDataEvent,
GlobalAccountDataEventType,
},
events::{push_rules::PushRulesEventContent, GlobalAccountDataEvent, GlobalAccountDataEventType},
push::Ruleset,
UserId,
};
use tracing::{error, warn};

use crate::services;

pub(crate) async fn init_emergency_access() {
// Set emergency access for the conduit user
match set_emergency_access() {
Ok(pwd_set) => {
if pwd_set {
warn!(
"The Conduit account emergency password is set! Please unset it as soon as you finish admin \
account recovery!"
);
services()
.admin
.send_message(RoomMessageEventContent::text_plain(
"The Conduit account emergency password is set! Please unset it as soon as you finish admin \
account recovery!",
))
.await;
}
},
Err(e) => {
error!("Could not set the configured emergency password for the conduit user: {}", e);
},
};
/// Set emergency access for the conduit user
pub(crate) fn init_emergency_access() {
if let Err(e) = set_emergency_access() {
error!("Could not set the configured emergency password for the conduit user: {e}");
}
}

/// Sets the emergency password and push rules for the @conduit account in case
Expand All @@ -45,9 +25,9 @@ fn set_emergency_access() -> Result<bool> {
.users
.set_password(&conduit_user, services().globals.emergency_password().as_deref())?;

let (ruleset, res) = match services().globals.emergency_password() {
Some(_) => (Ruleset::server_default(&conduit_user), Ok(true)),
None => (Ruleset::new(), Ok(false)),
let (ruleset, pwd_set) = match services().globals.emergency_password() {
Some(_) => (Ruleset::server_default(&conduit_user), true),
None => (Ruleset::new(), false),
};

services().account_data.update(
Expand All @@ -62,5 +42,12 @@ fn set_emergency_access() -> Result<bool> {
.expect("to json value always works"),
)?;

res
if pwd_set {
warn!(
"The Conduit account emergency password is set! Please unset it as soon as you finish admin account \
recovery!"
);
}

Ok(pwd_set)
}
6 changes: 2 additions & 4 deletions src/service/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,12 @@ bad_signature_ratelimiter: {bad_signature_ratelimiter}

pub async fn start(&self) -> Result<()> {
debug_info!("Starting services");

globals::migrations::migrations(&self.db, &self.globals.config).await?;
globals::emerg_access::init_emergency_access();

self.admin.start_handler().await;

globals::emerg_access::init_emergency_access().await;

self.sending.start_handler().await;

if self.globals.config.allow_local_presence {
self.presence.start_handler().await;
}
Expand Down

0 comments on commit d1b6485

Please sign in to comment.