From ed72963e6c888cde93500297378310c7e5fc6e13 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Thu, 30 Jul 2026 21:24:28 +0900 Subject: [PATCH] walld: add enable toggle in config --- nix/module.nix | 6 +++++ src/bin/roowhod.rs | 3 +++ src/server/config.rs | 9 +++++++ src/server/varlink_api.rs | 54 ++++++++++++++++++++++++++++----------- 4 files changed, 57 insertions(+), 15 deletions(-) diff --git a/nix/module.nix b/nix/module.nix index f0f004a..9dbd4c4 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -190,6 +190,12 @@ in { # }; # }; }; + + walld = { + enable = lib.mkEnableOption "the walld service" // { + default = true; + }; + }; }; }; default = { }; diff --git a/src/bin/roowhod.rs b/src/bin/roowhod.rs index 3642ce7..e33c30d 100644 --- a/src/bin/roowhod.rs +++ b/src/bin/roowhod.rs @@ -138,6 +138,7 @@ async fn main() -> anyhow::Result<()> { whod_status_store.clone(), config.rwhod.enable, config.fingerd.enable, + config.walld.enable, finger_ignore_list, client_server_token, )); @@ -201,6 +202,7 @@ async fn client_server( whod_status_store: RwhodStatusStore, rwhod_enabled: bool, fingerd_enabled: bool, + walld_enabled: bool, finger_ignore_list: Option, startup_token: CancellationToken, ) -> anyhow::Result<()> { @@ -214,6 +216,7 @@ async fn client_server( whod_status_store, rwhod_enabled, fingerd_enabled, + walld_enabled, finger_ignore_list, ); diff --git a/src/server/config.rs b/src/server/config.rs index a9a97e3..aa72cdd 100644 --- a/src/server/config.rs +++ b/src/server/config.rs @@ -21,6 +21,9 @@ pub struct Config { /// Configuration for the fingerd server. pub fingerd: FingerdConfig, + /// Configuration for the walld server. + pub walld: WalldConfig, + /// Path to the Unix domain socket for client-server communication. /// /// If left as `None`, the server expects to be served a file descriptor to the socket named 'client'. @@ -115,3 +118,9 @@ pub struct FingerdConfig { /// Path to the ignore list for users that should be hidden from fingerd. pub ignore_list_path: Option, } + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct WalldConfig { + /// Enable or disable the walld server functionality. + pub enable: bool, +} diff --git a/src/server/varlink_api.rs b/src/server/varlink_api.rs index ca303ee..21bc1d6 100644 --- a/src/server/varlink_api.rs +++ b/src/server/varlink_api.rs @@ -51,6 +51,7 @@ pub struct VarlinkRoowhoo2ClientServer { whod_status_store: RwhodStatusStore, rwhod_enabled: bool, fingerd_enabled: bool, + walld_enabled: bool, finger_ignore_list: Option, polkit: Option, } @@ -60,6 +61,7 @@ impl VarlinkRoowhoo2ClientServer { whod_status_store: RwhodStatusStore, rwhod_enabled: bool, fingerd_enabled: bool, + walld_enabled: bool, finger_ignore_list: Option, polkit: Option, ) -> Self { @@ -67,6 +69,7 @@ impl VarlinkRoowhoo2ClientServer { whod_status_store, rwhod_enabled, fingerd_enabled, + walld_enabled, finger_ignore_list, polkit, } @@ -280,7 +283,14 @@ impl zlink::Service for VarlinkRoowhoo2ClientServer { nobanner, timeout_secs, }) => { - // TODO: add walld toggle to config + if !self.walld_enabled { + return ( + MethodReply::Error(VarlinkReplyError::Walld( + VarlinkWalldClientError::Disabled, + )), + Default::default(), + ); + } // TODO: ensure the outer duration is more than the inner duration. let result = match timeout( @@ -329,7 +339,15 @@ impl zlink::Service for VarlinkRoowhoo2ClientServer { target_tty, message, }) => { - // TODO: add walld toggle to config + if !self.walld_enabled { + return ( + MethodReply::Error(VarlinkReplyError::Walld( + VarlinkWalldClientError::Disabled, + )), + Default::default(), + ); + } + let result = match timeout( Duration::from_secs(2), handle_write_request( @@ -378,21 +396,26 @@ pub async fn varlink_client_server_task( whod_status_store: RwhodStatusStore, rwhod_enabled: bool, fingerd_enabled: bool, + walld_enabled: bool, finger_ignore_list: Option, ) -> anyhow::Result<()> { - let polkit = match timeout(Duration::from_secs(5), PolkitAuthority::connect()).await { - Ok(Ok(polkit)) => Some(polkit), - Ok(Err(e)) => { - tracing::warn!( - "Failed to connect to polkit; Wall/Write requests will be denied: {e:#}" - ); - None - } - Err(_) => { - tracing::warn!( - "Timed out connecting to polkit after 5 seconds; Wall/Write requests will be denied" - ); - None + let polkit = if !walld_enabled { + None + } else { + match timeout(Duration::from_secs(5), PolkitAuthority::connect()).await { + Ok(Ok(polkit)) => Some(polkit), + Ok(Err(e)) => { + tracing::warn!( + "Failed to connect to polkit; Wall/Write requests will be denied: {e:#}" + ); + None + } + Err(_) => { + tracing::warn!( + "Timed out connecting to polkit after 5 seconds; Wall/Write requests will be denied" + ); + None + } } }; @@ -400,6 +423,7 @@ pub async fn varlink_client_server_task( whod_status_store, rwhod_enabled, fingerd_enabled, + walld_enabled, finger_ignore_list, polkit, );