@@ -692,15 +692,10 @@ impl AuthAgentBackend for PolkitAgent { |
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | 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". |
| 704 | 699 | let mut details = HashMap::new(); |
| 705 | 700 | details.insert("pid".to_string(), OwnedValue::from(std::process::id())); |
| 706 | 701 | details.insert( |
@@ -722,23 +717,6 @@ fn process_start_time_ticks() -> Option<u64> { |
| 722 | 717 | fields.nth(19)?.parse::<u64>().ok() |
| 723 | 718 | } |
| 724 | 719 | |
| 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 | | - |
| 742 | 720 | #[cfg(test)] |
| 743 | 721 | mod tests { |
| 744 | 722 | use super::*; |
@@ -769,15 +747,10 @@ mod tests { |
| 769 | 747 | #[test] |
| 770 | 748 | fn subject_uses_unix_process_kind() { |
| 771 | 749 | 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")); |
| 781 | 754 | } |
| 782 | 755 | |
| 783 | 756 | #[test] |