mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-19 22:46:14 -05:00
fix: report missing LXQt browser SSO support
This commit is contained in:
1 file changed
+62
-4
@@ -14,6 +14,13 @@ use tokio::{
|
|||||||
time::timeout,
|
time::timeout,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))]
|
||||||
|
use log::warn;
|
||||||
|
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd", test))]
|
||||||
|
use std::ffi::OsStr;
|
||||||
|
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))]
|
||||||
|
use std::process::{Command, Output};
|
||||||
|
|
||||||
const CALLBACK_SCHEME: &str = "globalprotectcallback";
|
const CALLBACK_SCHEME: &str = "globalprotectcallback";
|
||||||
const PROTOCOL_MAGIC: &[u8; 4] = b"GPAC";
|
const PROTOCOL_MAGIC: &[u8; 4] = b"GPAC";
|
||||||
const PROTOCOL_VERSION: u8 = 1;
|
const PROTOCOL_VERSION: u8 = 1;
|
||||||
@@ -99,16 +106,19 @@ pub fn ensure_auth_callback_handler() -> anyhow::Result<()> {
|
|||||||
const MIME_TYPE: &str = "x-scheme-handler/globalprotectcallback";
|
const MIME_TYPE: &str = "x-scheme-handler/globalprotectcallback";
|
||||||
const HANDLER: &str = "gpgui.desktop";
|
const HANDLER: &str = "gpgui.desktop";
|
||||||
|
|
||||||
|
ensure_lxqt_mime_tool()?;
|
||||||
|
|
||||||
let current_handler = query_callback_handler(MIME_TYPE)?;
|
let current_handler = query_callback_handler(MIME_TYPE)?;
|
||||||
if !should_register_handler(¤t_handler) {
|
if !should_register_handler(¤t_handler) {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let status = std::process::Command::new("xdg-mime")
|
let output = Command::new("xdg-mime")
|
||||||
.args(["default", HANDLER, MIME_TYPE])
|
.args(["default", HANDLER, MIME_TYPE])
|
||||||
.status()
|
.output()
|
||||||
.context("xdg-mime is required for external-browser authentication")?;
|
.context("xdg-mime is required for external-browser authentication")?;
|
||||||
if !status.success() {
|
if !output.status.success() {
|
||||||
|
log_command_failure("register callback handler", &output);
|
||||||
bail!("Failed to register the globalprotectcallback URL handler");
|
bail!("Failed to register the globalprotectcallback URL handler");
|
||||||
}
|
}
|
||||||
if query_callback_handler(MIME_TYPE)? != HANDLER {
|
if query_callback_handler(MIME_TYPE)? != HANDLER {
|
||||||
@@ -120,16 +130,55 @@ pub fn ensure_auth_callback_handler() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))]
|
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))]
|
||||||
fn query_callback_handler(mime_type: &str) -> anyhow::Result<String> {
|
fn query_callback_handler(mime_type: &str) -> anyhow::Result<String> {
|
||||||
let output = std::process::Command::new("xdg-mime")
|
let output = Command::new("xdg-mime")
|
||||||
.args(["query", "default", mime_type])
|
.args(["query", "default", mime_type])
|
||||||
.output()
|
.output()
|
||||||
.context("xdg-mime is required for external-browser authentication")?;
|
.context("xdg-mime is required for external-browser authentication")?;
|
||||||
if !output.status.success() {
|
if !output.status.success() {
|
||||||
|
log_command_failure("query callback handler", &output);
|
||||||
bail!("Failed to query the globalprotectcallback URL handler");
|
bail!("Failed to query the globalprotectcallback URL handler");
|
||||||
}
|
}
|
||||||
Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
|
Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))]
|
||||||
|
fn ensure_lxqt_mime_tool() -> anyhow::Result<()> {
|
||||||
|
if !is_lxqt_desktop(std::env::var_os("XDG_CURRENT_DESKTOP").as_deref()) {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let result = Command::new("qtxdg-mat").args(["defapp", "--help"]).output();
|
||||||
|
match result {
|
||||||
|
Ok(output) if output.status.success() => Ok(()),
|
||||||
|
Ok(output) => {
|
||||||
|
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||||
|
warn!(
|
||||||
|
"qtxdg-mat readiness check failed with {}: {}",
|
||||||
|
output.status,
|
||||||
|
stderr.trim()
|
||||||
|
);
|
||||||
|
bail!("Install qtxdg-tools for browser SSO.")
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
warn!("Failed to run qtxdg-mat readiness check: {err}");
|
||||||
|
bail!("Install qtxdg-tools for browser SSO.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd", test))]
|
||||||
|
fn is_lxqt_desktop(current_desktop: Option<&OsStr>) -> bool {
|
||||||
|
current_desktop
|
||||||
|
.and_then(OsStr::to_str)
|
||||||
|
.is_some_and(|desktop| desktop.split(':').any(|name| name.eq_ignore_ascii_case("lxqt")))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))]
|
||||||
|
fn log_command_failure(action: &str, output: &Output) {
|
||||||
|
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||||
|
warn!("xdg-mime failed to {action} with {}: {}", output.status, stderr.trim());
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
pub fn ensure_auth_callback_handler() -> anyhow::Result<()> {
|
pub fn ensure_auth_callback_handler() -> anyhow::Result<()> {
|
||||||
macos::ensure_auth_callback_handler()
|
macos::ensure_auth_callback_handler()
|
||||||
@@ -340,6 +389,15 @@ mod tests {
|
|||||||
assert!(should_register_handler("other-vpn.desktop"));
|
assert!(should_register_handler("other-vpn.desktop"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn detects_lxqt_desktop_session() {
|
||||||
|
assert!(is_lxqt_desktop(Some(OsStr::new("LXQt"))));
|
||||||
|
assert!(is_lxqt_desktop(Some(OsStr::new("LXQt:KDE"))));
|
||||||
|
assert!(is_lxqt_desktop(Some(OsStr::new("lxqt"))));
|
||||||
|
assert!(!is_lxqt_desktop(Some(OsStr::new("LXDE"))));
|
||||||
|
assert!(!is_lxqt_desktop(None));
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn forwards_callback_to_waiting_receiver() {
|
async fn forwards_callback_to_waiting_receiver() {
|
||||||
let directory = tempdir().unwrap();
|
let directory = tempdir().unwrap();
|
||||||
|
|||||||
Reference in new issue
Block a user