gardesk/garcard / 048963a

Browse files

Add direct helper transport mode

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
048963a7f736c9a3e005cce5aeb8da8365a55a17
Parents
61cd420
Tree
54fe347

1 changed file

StatusFile+-
M garcard/src/polkit_helper.rs 37 0
garcard/src/polkit_helper.rsmodified
@@ -5,6 +5,7 @@ use std::path::PathBuf;
55
 use std::process::{Command, Stdio};
66
 
77
 pub const DEFAULT_HELPER_SOCKET: &str = "/run/polkit/agent-helper.socket";
8
+const HELPER_TRANSPORT_ENV: &str = "GARCARD_POLKIT_HELPER_TRANSPORT";
89
 
910
 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
1011
 pub enum HelperOutcome {
@@ -80,6 +81,16 @@ impl HelperSocketClient {
8081
     ) -> Result<HelperOutcome> {
8182
         let username_line = sanitize_control_line(username);
8283
         let cookie_line = sanitize_control_line(cookie);
84
+        let transport = helper_transport_mode();
85
+        tracing::debug!(
86
+            transport = %transport.as_str(),
87
+            env_key = HELPER_TRANSPORT_ENV,
88
+            "Selected polkit helper transport mode"
89
+        );
90
+        if matches!(transport, HelperTransportMode::Direct) {
91
+            return self.authenticate_via_helper_process(&username_line, &cookie_line, prompts);
92
+        }
93
+
8394
         let mut stream = UnixStream::connect(&self.socket_path).with_context(|| {
8495
             format!(
8596
                 "failed to connect to polkit helper socket at {}",
@@ -413,6 +424,32 @@ fn command_in_path(command: &str) -> Option<PathBuf> {
413424
     None
414425
 }
415426
 
427
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
428
+enum HelperTransportMode {
429
+    Auto,
430
+    Direct,
431
+}
432
+
433
+impl HelperTransportMode {
434
+    fn as_str(self) -> &'static str {
435
+        match self {
436
+            Self::Auto => "auto",
437
+            Self::Direct => "direct",
438
+        }
439
+    }
440
+}
441
+
442
+fn helper_transport_mode() -> HelperTransportMode {
443
+    match std::env::var(HELPER_TRANSPORT_ENV)
444
+        .ok()
445
+        .map(|value| value.trim().to_ascii_lowercase())
446
+        .as_deref()
447
+    {
448
+        Some("direct") => HelperTransportMode::Direct,
449
+        _ => HelperTransportMode::Auto,
450
+    }
451
+}
452
+
416453
 fn scrub_string(value: &mut String) {
417454
     if value.is_empty() {
418455
         return;