gardesk/garcard / f2eb902

Browse files

Register polkit agent as unix-process

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
f2eb902479dcb73636840a081f9f07c1f2bf6e13
Parents
b3a2717
Tree
8d814df

1 changed file

StatusFile+-
M garcard/src/agent.rs 8 35
garcard/src/agent.rsmodified
@@ -692,15 +692,10 @@ impl AuthAgentBackend for PolkitAgent {
692692
 }
693693
 
694694
 fn build_subject() -> Subject {
695
-    if let Some(session_id) = current_session_id() {
696
-        let mut details = HashMap::new();
697
-        let value = zbus::zvariant::Value::from(session_id.as_str());
698
-        if let Ok(session_value) = OwnedValue::try_from(value) {
699
-            details.insert("session-id".to_string(), session_value);
700
-            return ("unix-session".to_string(), details);
701
-        }
702
-    }
703
-
695
+    // Keep registration subject aligned with helper response subject
696
+    // (`polkit-agent-helper-1 --socket-activated` replies as unix-process with
697
+    // pidfd+uid). Registering as unix-process avoids subject-type mismatches
698
+    // that can surface as "No session for cookie".
704699
     let mut details = HashMap::new();
705700
     details.insert("pid".to_string(), OwnedValue::from(std::process::id()));
706701
     details.insert(
@@ -722,23 +717,6 @@ fn process_start_time_ticks() -> Option<u64> {
722717
     fields.nth(19)?.parse::<u64>().ok()
723718
 }
724719
 
725
-fn current_session_id() -> Option<String> {
726
-    if let Ok(raw) = std::env::var("XDG_SESSION_ID") {
727
-        let trimmed = raw.trim();
728
-        if !trimmed.is_empty() {
729
-            return Some(trimmed.to_string());
730
-        }
731
-    }
732
-
733
-    let raw = std::fs::read_to_string("/proc/self/sessionid").ok()?;
734
-    let trimmed = raw.trim();
735
-    if trimmed.is_empty() || trimmed == "4294967295" {
736
-        return None;
737
-    }
738
-
739
-    Some(trimmed.to_string())
740
-}
741
-
742720
 #[cfg(test)]
743721
 mod tests {
744722
     use super::*;
@@ -769,15 +747,10 @@ mod tests {
769747
     #[test]
770748
     fn subject_uses_unix_process_kind() {
771749
         let subject = build_subject();
772
-        match subject.0.as_str() {
773
-            "unix-session" => assert!(subject.1.contains_key("session-id")),
774
-            "unix-process" => {
775
-                assert!(subject.1.contains_key("pid"));
776
-                assert!(subject.1.contains_key("uid"));
777
-                assert!(subject.1.contains_key("start-time"));
778
-            }
779
-            other => panic!("unexpected subject kind: {other}"),
780
-        }
750
+        assert_eq!(subject.0.as_str(), "unix-process");
751
+        assert!(subject.1.contains_key("pid"));
752
+        assert!(subject.1.contains_key("uid"));
753
+        assert!(subject.1.contains_key("start-time"));
781754
     }
782755
 
783756
     #[test]