mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-18 22:16:18 -05:00
fix: restore GUI callback desktop handler
This commit is contained in:
12 files changed
+202
-45
No files matched your search
@@ -164,7 +164,6 @@ install:
|
||||
install -Dm755 packaging/files/usr/lib/NetworkManager/dispatcher.d/gpclient-nm-hook $(DESTDIR)/usr/lib/NetworkManager/dispatcher.d/gpclient-nm-hook
|
||||
|
||||
install -Dm644 packaging/files/usr/share/applications/gpgui.desktop $(DESTDIR)/usr/share/applications/gpgui.desktop
|
||||
install -Dm644 packaging/files/usr/share/applications/gpauth.desktop $(DESTDIR)/usr/share/applications/gpauth.desktop
|
||||
install -Dm644 packaging/files/usr/share/icons/hicolor/scalable/apps/gpgui.svg $(DESTDIR)/usr/share/icons/hicolor/scalable/apps/gpgui.svg
|
||||
install -Dm644 packaging/files/usr/share/icons/hicolor/32x32/apps/gpgui.png $(DESTDIR)/usr/share/icons/hicolor/32x32/apps/gpgui.png
|
||||
install -Dm644 packaging/files/usr/share/icons/hicolor/128x128/apps/gpgui.png $(DESTDIR)/usr/share/icons/hicolor/128x128/apps/gpgui.png
|
||||
@@ -195,7 +194,6 @@ install-bsd:
|
||||
|
||||
install -d $(DESTDIR)$(PREFIX)/share/applications
|
||||
install -m 644 packaging/bsd/gpgui.desktop $(DESTDIR)$(PREFIX)/share/applications/gpgui.desktop
|
||||
install -m 644 packaging/bsd/gpauth.desktop $(DESTDIR)$(PREFIX)/share/applications/gpauth.desktop
|
||||
install -d $(DESTDIR)$(PREFIX)/share/icons/hicolor/scalable/apps
|
||||
install -d $(DESTDIR)$(PREFIX)/share/icons/hicolor/32x32/apps
|
||||
install -d $(DESTDIR)$(PREFIX)/share/icons/hicolor/128x128/apps
|
||||
@@ -294,7 +292,6 @@ uninstall:
|
||||
rm -f $(DESTDIR)/usr/lib/NetworkManager/dispatcher.d/gpclient-nm-hook
|
||||
|
||||
rm -f $(DESTDIR)/usr/share/applications/gpgui.desktop
|
||||
rm -f $(DESTDIR)/usr/share/applications/gpauth.desktop
|
||||
rm -f $(DESTDIR)/usr/share/icons/hicolor/scalable/apps/gpgui.svg
|
||||
rm -f $(DESTDIR)/usr/share/icons/hicolor/32x32/apps/gpgui.png
|
||||
rm -f $(DESTDIR)/usr/share/icons/hicolor/128x128/apps/gpgui.png
|
||||
|
||||
@@ -102,6 +102,14 @@ impl Args for Cli {
|
||||
}
|
||||
|
||||
impl Cli {
|
||||
fn can_run_alongside_client(&self) -> bool {
|
||||
match &self.command {
|
||||
CliCommand::Disconnect(_) => true,
|
||||
CliCommand::LaunchGui(args) => args.is_auth_callback(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
async fn is_running(&self) -> bool {
|
||||
let Ok(c) = fs::read_to_string(&self.lock_file).await else {
|
||||
return false;
|
||||
@@ -132,7 +140,7 @@ impl Cli {
|
||||
|
||||
async fn run(&self) -> anyhow::Result<()> {
|
||||
// check if an instance is running
|
||||
if !matches!(self.command, CliCommand::Disconnect(_)) && self.is_running().await {
|
||||
if !self.can_run_alongside_client() && self.is_running().await {
|
||||
bail!("Another instance of the client is already running");
|
||||
}
|
||||
|
||||
@@ -203,4 +211,33 @@ mod tests {
|
||||
|
||||
assert_eq!(cli.lock_file, PathBuf::from("/tmp/gpclient-portal.lock"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))]
|
||||
fn launch_gui_accepts_auth_callback() {
|
||||
let cli = Cli::try_parse_from([
|
||||
"gpclient",
|
||||
"launch-gui",
|
||||
"globalprotectcallback:cas-as=1&[email protected]&token=token",
|
||||
])
|
||||
.expect("authentication callback should parse");
|
||||
|
||||
assert!(matches!(
|
||||
&cli.command,
|
||||
CliCommand::LaunchGui(args) if args.is_auth_callback()
|
||||
));
|
||||
assert!(cli.can_run_alongside_client());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))]
|
||||
fn launch_gui_rejects_callback_with_minimized() {
|
||||
assert!(Cli::try_parse_from(["gpclient", "launch-gui", "globalprotectcallback:token", "--minimized",]).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))]
|
||||
fn launch_gui_rejects_non_callback_positional() {
|
||||
assert!(Cli::try_parse_from(["gpclient", "launch-gui", "https://example.com/callback"]).is_err());
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,15 @@
|
||||
use std::{collections::HashMap, fs, path::PathBuf};
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd", test))]
|
||||
use std::process::{Command, ExitStatus};
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))]
|
||||
use anyhow::Context;
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd", test))]
|
||||
use anyhow::bail;
|
||||
use clap::Args;
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd", test))]
|
||||
use common::binary_paths;
|
||||
use directories::ProjectDirs;
|
||||
use gpapi::{
|
||||
process::service_launcher::ServiceLauncher,
|
||||
@@ -10,10 +19,30 @@ use log::info;
|
||||
|
||||
#[derive(Args)]
|
||||
pub(crate) struct LaunchGuiArgs {
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))]
|
||||
#[arg(
|
||||
required = false,
|
||||
conflicts_with = "minimized",
|
||||
value_parser = parse_auth_callback,
|
||||
help = "The external-browser authentication callback URL"
|
||||
)]
|
||||
callback: Option<String>,
|
||||
#[arg(long, help = "Launch the GUI minimized")]
|
||||
minimized: bool,
|
||||
}
|
||||
|
||||
impl LaunchGuiArgs {
|
||||
pub(crate) fn is_auth_callback(&self) -> bool {
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))]
|
||||
{
|
||||
return self.callback.is_some();
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd")))]
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct LaunchGuiHandler<'a> {
|
||||
args: &'a LaunchGuiArgs,
|
||||
}
|
||||
@@ -30,6 +59,11 @@ impl<'a> LaunchGuiHandler<'a> {
|
||||
anyhow::bail!("`launch-gui` cannot be run as root");
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))]
|
||||
if let Some(callback) = &self.args.callback {
|
||||
return forward_auth_callback(callback);
|
||||
}
|
||||
|
||||
if try_active_gui().await.is_ok() {
|
||||
info!("The GUI is already running");
|
||||
return Ok(());
|
||||
@@ -66,6 +100,38 @@ impl<'a> LaunchGuiHandler<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))]
|
||||
fn forward_auth_callback(callback: &str) -> anyhow::Result<()> {
|
||||
let status = auth_callback_command(callback)
|
||||
.status()
|
||||
.context("Failed to start the authentication callback handler")?;
|
||||
ensure_auth_callback_succeeded(status)
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd", test))]
|
||||
fn auth_callback_command(callback: &str) -> Command {
|
||||
let mut command = Command::new(binary_paths::gpauth());
|
||||
command.args(["auth-callback", callback]);
|
||||
command
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd", test))]
|
||||
fn ensure_auth_callback_succeeded(status: ExitStatus) -> anyhow::Result<()> {
|
||||
if !status.success() {
|
||||
bail!("Authentication callback handler exited with {status}");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd", test))]
|
||||
fn parse_auth_callback(callback: &str) -> Result<String, String> {
|
||||
callback
|
||||
.starts_with("globalprotectcallback:")
|
||||
.then(|| callback.to_owned())
|
||||
.ok_or_else(|| "callback URL must use the globalprotectcallback scheme".to_owned())
|
||||
}
|
||||
|
||||
async fn try_active_gui() -> anyhow::Result<()> {
|
||||
let service_endpoint = http_endpoint().await?;
|
||||
|
||||
@@ -86,3 +152,34 @@ fn get_log_file() -> anyhow::Result<PathBuf> {
|
||||
|
||||
Ok(dirs.data_dir().join("gpclient.log"))
|
||||
}
|
||||
|
||||
#[cfg(all(test, unix))]
|
||||
mod tests {
|
||||
use std::os::unix::process::ExitStatusExt;
|
||||
|
||||
use super::*;
|
||||
|
||||
const CALLBACK: &str = "globalprotectcallback:cas-as=1&[email protected]&token=token";
|
||||
|
||||
#[test]
|
||||
fn callback_command_preserves_callback_argument() {
|
||||
let command = auth_callback_command(CALLBACK);
|
||||
let args = command
|
||||
.get_args()
|
||||
.map(|argument| argument.to_str().unwrap())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
assert_eq!(args, ["auth-callback", CALLBACK]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn callback_command_status_is_propagated() {
|
||||
assert!(ensure_auth_callback_succeeded(ExitStatus::from_raw(0)).is_ok());
|
||||
assert!(ensure_auth_callback_succeeded(ExitStatus::from_raw(1 << 8)).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_non_callback_url() {
|
||||
assert!(parse_auth_callback("https://example.com/callback").is_err());
|
||||
}
|
||||
}
|
||||
@@ -97,7 +97,7 @@ pub async fn forward_auth_callback(callback: &str) -> anyhow::Result<()> {
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))]
|
||||
pub fn ensure_auth_callback_handler() -> anyhow::Result<()> {
|
||||
const MIME_TYPE: &str = "x-scheme-handler/globalprotectcallback";
|
||||
const HANDLER: &str = "gpauth.desktop";
|
||||
const HANDLER: &str = "gpgui.desktop";
|
||||
|
||||
let current_handler = query_callback_handler(MIME_TYPE)?;
|
||||
if !should_register_handler(¤t_handler) {
|
||||
@@ -147,7 +147,7 @@ pub fn ensure_auth_callback_handler() -> anyhow::Result<()> {
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd", test))]
|
||||
fn should_register_handler(current_handler: &str) -> bool {
|
||||
current_handler != "gpauth.desktop"
|
||||
current_handler != "gpgui.desktop"
|
||||
}
|
||||
|
||||
async fn forward_auth_callback_to(callback: &str, socket_path: &Path) -> anyhow::Result<()> {
|
||||
@@ -334,9 +334,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn replaces_any_other_callback_handler() {
|
||||
assert!(!should_register_handler("gpauth.desktop"));
|
||||
assert!(!should_register_handler("gpgui.desktop"));
|
||||
assert!(should_register_handler(""));
|
||||
assert!(should_register_handler("gpgui.desktop"));
|
||||
assert!(should_register_handler("gpauth.desktop"));
|
||||
assert!(should_register_handler("other-vpn.desktop"));
|
||||
}
|
||||
|
||||
|
||||
@@ -98,9 +98,6 @@
|
||||
substituteInPlace $out/share/applications/gpgui.desktop \
|
||||
--replace-fail /usr/bin/gpclient $out/bin/gpclient
|
||||
|
||||
substituteInPlace $out/share/applications/gpauth.desktop \
|
||||
--replace-fail /usr/bin/gpauth $out/bin/gpauth
|
||||
|
||||
substituteInPlace $out/share/polkit-1/actions/com.yuezk.gpgui.policy \
|
||||
--replace-fail /usr/bin/gpservice $out/bin/gpservice \
|
||||
--replace-fail /usr/libexec/gpclient/gp-vpnc-script-installer $out/bin/gp-vpnc-script-installer
|
||||
@@ -115,9 +112,6 @@
|
||||
substituteInPlace $out/share/applications/gpgui.desktop \
|
||||
--replace-fail /usr/bin/gpclient $out/bin/gpclient
|
||||
|
||||
substituteInPlace $out/share/applications/gpauth.desktop \
|
||||
--replace-fail /usr/bin/gpauth $out/bin/gpauth
|
||||
|
||||
substituteInPlace $out/share/polkit-1/actions/com.yuezk.gpgui.policy \
|
||||
--replace-fail /usr/bin/gpservice $out/bin/gpservice \
|
||||
--replace-fail /usr/libexec/gpclient/gp-vpnc-script-installer ${prebuiltFiles}/libexec/gpclient/gp-vpnc-script-installer
|
||||
@@ -342,16 +336,25 @@
|
||||
|
||||
gpclient_fhs='${prebuiltCommands.gpclient}/bin/gpclient'
|
||||
gpservice_public='@gpservice_public@'
|
||||
gpauth_public='@gpauth_public@'
|
||||
|
||||
if [ "''${1:-}" = "launch-gui" ]; then
|
||||
shift
|
||||
|
||||
minimized=
|
||||
callback=
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--minimized)
|
||||
minimized=--minimized
|
||||
;;
|
||||
globalprotectcallback:*)
|
||||
if [ -n "$callback" ]; then
|
||||
echo "Multiple authentication callback URLs were provided" >&2
|
||||
exit 2
|
||||
fi
|
||||
callback=$arg
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported launch-gui argument: $arg" >&2
|
||||
exit 2
|
||||
@@ -359,6 +362,14 @@
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -n "$callback" ]; then
|
||||
if [ -n "$minimized" ]; then
|
||||
echo "An authentication callback cannot be combined with --minimized" >&2
|
||||
exit 2
|
||||
fi
|
||||
exec "$gpauth_public" auth-callback "$callback"
|
||||
fi
|
||||
|
||||
if [ -n "''${XDG_DATA_HOME:-}" ]; then
|
||||
data_home=$XDG_DATA_HOME
|
||||
elif [ -n "''${HOME:-}" ]; then
|
||||
@@ -395,7 +406,8 @@
|
||||
exec "$gpclient_fhs" "$@"
|
||||
EOF
|
||||
substituteInPlace $out/bin/gpclient \
|
||||
--replace-fail '@gpservice_public@' "$out/bin/gpservice"
|
||||
--replace-fail '@gpservice_public@' "$out/bin/gpservice" \
|
||||
--replace-fail '@gpauth_public@' "$out/bin/gpauth"
|
||||
chmod +x $out/bin/gpclient
|
||||
|
||||
cat > $out/bin/gpservice <<'EOF'
|
||||
|
||||
@@ -19,7 +19,6 @@ install:
|
||||
install -Dm755 artifacts/usr/lib/NetworkManager/dispatcher.d/gpclient-nm-hook $(DESTDIR)/usr/lib/NetworkManager/dispatcher.d/gpclient-nm-hook
|
||||
|
||||
install -Dm644 artifacts/usr/share/applications/gpgui.desktop $(DESTDIR)/usr/share/applications/gpgui.desktop
|
||||
install -Dm644 artifacts/usr/share/applications/gpauth.desktop $(DESTDIR)/usr/share/applications/gpauth.desktop
|
||||
install -Dm644 artifacts/usr/share/icons/hicolor/scalable/apps/gpgui.svg $(DESTDIR)/usr/share/icons/hicolor/scalable/apps/gpgui.svg
|
||||
install -Dm644 artifacts/usr/share/icons/hicolor/32x32/apps/gpgui.png $(DESTDIR)/usr/share/icons/hicolor/32x32/apps/gpgui.png
|
||||
install -Dm644 artifacts/usr/share/icons/hicolor/128x128/apps/gpgui.png $(DESTDIR)/usr/share/icons/hicolor/128x128/apps/gpgui.png
|
||||
@@ -44,7 +43,6 @@ uninstall:
|
||||
rm -f $(DESTDIR)/usr/lib/NetworkManager/dispatcher.d/gpclient-nm-hook
|
||||
|
||||
rm -f $(DESTDIR)/usr/share/applications/gpgui.desktop
|
||||
rm -f $(DESTDIR)/usr/share/applications/gpauth.desktop
|
||||
rm -f $(DESTDIR)/usr/share/icons/hicolor/scalable/apps/gpgui.svg
|
||||
rm -f $(DESTDIR)/usr/share/icons/hicolor/32x32/apps/gpgui.png
|
||||
rm -f $(DESTDIR)/usr/share/icons/hicolor/128x128/apps/gpgui.png
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=GP Connect Login
|
||||
Comment=Authenticate GP Connect VPN connections
|
||||
NoDisplay=true
|
||||
Terminal=false
|
||||
TryExec=/usr/local/bin/gpauth
|
||||
Exec=/usr/local/bin/gpauth auth-callback %u
|
||||
MimeType=x-scheme-handler/globalprotectcallback;
|
||||
Icon=gpgui
|
||||
Categories=Network;
|
||||
@@ -4,6 +4,7 @@ Name=GP Connect
|
||||
Comment=A GUI client for GlobalProtect VPN
|
||||
GenericName=GlobalProtect VPN Client
|
||||
Categories=Network;Dialup;
|
||||
Exec=/usr/local/bin/gpclient launch-gui
|
||||
Exec=/usr/local/bin/gpclient launch-gui %u
|
||||
MimeType=x-scheme-handler/globalprotectcallback;
|
||||
Icon=gpgui
|
||||
Keywords=GlobalProtect;Openconnect;SAML;connection;VPN;
|
||||
@@ -1,11 +0,0 @@
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=GP Connect Login
|
||||
Comment=Authenticate GP Connect VPN connections
|
||||
NoDisplay=true
|
||||
Terminal=false
|
||||
TryExec=/usr/bin/gpauth
|
||||
Exec=/usr/bin/gpauth auth-callback %u
|
||||
MimeType=x-scheme-handler/globalprotectcallback;
|
||||
Icon=gpgui
|
||||
Categories=Network;
|
||||
@@ -5,6 +5,7 @@ Name=GP Connect
|
||||
Comment=A GUI client for GlobalProtect VPN
|
||||
GenericName=GlobalProtect VPN Client
|
||||
Categories=Network;Dialup;
|
||||
Exec=/usr/bin/gpclient launch-gui
|
||||
Exec=/usr/bin/gpclient launch-gui %u
|
||||
MimeType=x-scheme-handler/globalprotectcallback;
|
||||
Icon=gpgui
|
||||
Keywords=GlobalProtect;Openconnect;SAML;connection;VPN;
|
||||
@@ -75,7 +75,6 @@ make build
|
||||
%{_libexecdir}/gpclient/hipreport.sh
|
||||
%{_libexecdir}/gpclient/gp-vpnc-script-installer
|
||||
%{_datadir}/applications/gpgui.desktop
|
||||
%{_datadir}/applications/gpauth.desktop
|
||||
%{_datadir}/icons/hicolor/32x32/apps/gpgui.png
|
||||
%{_datadir}/icons/hicolor/128x128/apps/gpgui.png
|
||||
%{_datadir}/icons/hicolor/256x256/apps/gpgui.png
|
||||
|
||||
@@ -22,6 +22,25 @@ verify_same_file() {
|
||||
fi
|
||||
}
|
||||
|
||||
verify_contains() {
|
||||
local file="$1"
|
||||
local expected="$2"
|
||||
|
||||
if ! grep -Fqx "$expected" "$file"; then
|
||||
echo "Linux desktop asset is missing '$expected': $file" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
verify_absent() {
|
||||
local file="$1"
|
||||
|
||||
if [[ -e "$file" ]]; then
|
||||
echo "Obsolete Linux desktop asset is still present: $file" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
verify_same_file \
|
||||
"$GPGUI_DIR/app/src-tauri/icons/32x32.png" \
|
||||
"$GP_DIR/packaging/files/usr/share/icons/hicolor/32x32/apps/gpgui.png"
|
||||
@@ -73,8 +92,26 @@ verify_same_file \
|
||||
verify_same_file \
|
||||
"$GPGUI_DIR/app/src-tauri/icons/icon-small.svg" \
|
||||
"$GP_DIR/apps/gpgui-helper/src/assets/icon-small.svg"
|
||||
verify_same_file \
|
||||
"$GPGUI_DIR/app/gpauth.desktop" \
|
||||
"$GP_DIR/packaging/files/usr/share/applications/gpauth.desktop"
|
||||
verify_contains \
|
||||
"$GPGUI_DIR/app/gpgui.desktop.in" \
|
||||
"Exec=/usr/bin/gpclient launch-gui %u"
|
||||
verify_contains \
|
||||
"$GPGUI_DIR/app/gpgui.desktop.in" \
|
||||
"MimeType=x-scheme-handler/globalprotectcallback;"
|
||||
verify_contains \
|
||||
"$GP_DIR/packaging/files/usr/share/applications/gpgui.desktop" \
|
||||
"Exec=/usr/bin/gpclient launch-gui %u"
|
||||
verify_contains \
|
||||
"$GP_DIR/packaging/files/usr/share/applications/gpgui.desktop" \
|
||||
"MimeType=x-scheme-handler/globalprotectcallback;"
|
||||
verify_contains \
|
||||
"$GP_DIR/packaging/bsd/gpgui.desktop" \
|
||||
"Exec=/usr/local/bin/gpclient launch-gui %u"
|
||||
verify_contains \
|
||||
"$GP_DIR/packaging/bsd/gpgui.desktop" \
|
||||
"MimeType=x-scheme-handler/globalprotectcallback;"
|
||||
verify_absent "$GPGUI_DIR/app/gpauth.desktop"
|
||||
verify_absent "$GP_DIR/packaging/files/usr/share/applications/gpauth.desktop"
|
||||
verify_absent "$GP_DIR/packaging/bsd/gpauth.desktop"
|
||||
|
||||
echo "Linux desktop assets are synchronized"
|
||||
Reference in new issue
Block a user