mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-19 06:26:14 -05:00
Merge branch 'fix/settings-crash-wayland-thread-safety'
This commit is contained in:
97 files changed
+10148
-2879
No files matched your search
@@ -143,6 +143,13 @@ fn build_openconnect(deps_dir: &PathBuf, out_dir: &PathBuf) -> PathBuf {
|
||||
config.env("LIBS", "-liconv");
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "freebsd", target_os = "openbsd"))]
|
||||
{
|
||||
config.ldflag("-L/usr/local/lib");
|
||||
config.ldflag("-liconv");
|
||||
config.env("LIBS", "-liconv");
|
||||
}
|
||||
|
||||
let dst = config.build();
|
||||
|
||||
let lib_dir = dst.join("lib");
|
||||
@@ -190,6 +197,12 @@ fn main() {
|
||||
println!("cargo:rerun-if-changed=src/ffi/vpn.c");
|
||||
println!("cargo:rerun-if-changed=src/ffi/vpn.h");
|
||||
|
||||
#[cfg(any(target_os = "freebsd", target_os = "openbsd"))]
|
||||
{
|
||||
println!("cargo:rustc-link-search=native=/usr/local/lib");
|
||||
println!("cargo:rustc-link-lib=iconv");
|
||||
}
|
||||
|
||||
// Prevent silent fallback to dynamic libraries
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
From 78078b21f53801b31fef352ec0de40d319edcae9 Mon Sep 17 00:00:00 2001
|
||||
From: Kevin Yue <[email protected]>
|
||||
Date: Sat, 13 Jun 2026 12:00:00 +0800
|
||||
Subject: [PATCH 6/6] Add host ID to GlobalProtect HIP script arguments
|
||||
|
||||
---
|
||||
gpst.c | 4 ++++
|
||||
library.c | 15 +++++++++++++++
|
||||
openconnect-internal.h | 4 ++++
|
||||
openconnect.h | 3 +++
|
||||
4 files changed, 26 insertions(+)
|
||||
|
||||
diff --git a/gpst.c b/gpst.c
|
||||
index 78c16d1c..f1e1f6bb 100644
|
||||
--- a/gpst.c
|
||||
+++ b/gpst.c
|
||||
@@ -1019,6 +1019,10 @@ static int run_hip_script(struct openconnect_info *vpninfo)
|
||||
hip_argv[i++] = "--client-os";
|
||||
hip_argv[i++] = gpst_os_name(vpninfo);
|
||||
hip_argv[i++] = "--os-version";
|
||||
hip_argv[i++] = openconnect_get_gp_os_version(vpninfo);
|
||||
+ if (openconnect_get_gp_host_id(vpninfo)) {
|
||||
+ hip_argv[i++] = "--host-id";
|
||||
+ hip_argv[i++] = openconnect_get_gp_host_id(vpninfo);
|
||||
+ }
|
||||
hip_argv[i++] = "--cookie";
|
||||
hip_argv[i++] = vpninfo->cookie;
|
||||
if (vpninfo->ip_info.addr) {
|
||||
diff --git a/library.c b/library.c
|
||||
index 03f47004..9e585119 100644
|
||||
--- a/library.c
|
||||
+++ b/library.c
|
||||
@@ -900,6 +900,7 @@ void openconnect_vpninfo_free(struct openconnect_info *vpninfo)
|
||||
free(vpninfo->useragent);
|
||||
free(vpninfo->gp_app_version);
|
||||
free(vpninfo->gp_os_version);
|
||||
+ free(vpninfo->gp_host_id);
|
||||
free(vpninfo->authgroup);
|
||||
#ifdef HAVE_LIBSTOKEN
|
||||
if (vpninfo->stoken_pin)
|
||||
@@ -1049,6 +1050,20 @@ const char *openconnect_get_gp_os_version(struct openconnect_info *vpninfo)
|
||||
return vpninfo->gp_os_version ?: vpninfo->platname;
|
||||
}
|
||||
|
||||
+int openconnect_set_gp_host_id(struct openconnect_info *vpninfo,
|
||||
+ const char *gp_host_id)
|
||||
+{
|
||||
+ UTF8CHECK(gp_host_id);
|
||||
+
|
||||
+ STRDUP(vpninfo->gp_host_id, gp_host_id);
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+const char *openconnect_get_gp_host_id(struct openconnect_info *vpninfo)
|
||||
+{
|
||||
+ return vpninfo->gp_host_id;
|
||||
+}
|
||||
+
|
||||
int openconnect_set_urlpath(struct openconnect_info *vpninfo,
|
||||
const char *urlpath)
|
||||
{
|
||||
diff --git a/openconnect-internal.h b/openconnect-internal.h
|
||||
index a7e80659..76034fbd 100644
|
||||
--- a/openconnect-internal.h
|
||||
+++ b/openconnect-internal.h
|
||||
@@ -788,6 +788,7 @@ struct openconnect_info {
|
||||
char *version_string;
|
||||
char *gp_app_version;
|
||||
char *gp_os_version;
|
||||
+ char *gp_host_id;
|
||||
|
||||
const char *quit_reason;
|
||||
const char *delay_tunnel_reason; /* If non-null, provides a reason why protocol is not yet ready for tunnel setup */
|
||||
@@ -1684,6 +1685,9 @@ const char *openconnect_get_gp_app_version(struct openconnect_info *vpninfo);
|
||||
/* Get the OS version string for GP */
|
||||
const char *openconnect_get_gp_os_version(struct openconnect_info *vpninfo);
|
||||
|
||||
+/* Get the host ID string for GP */
|
||||
+const char *openconnect_get_gp_host_id(struct openconnect_info *vpninfo);
|
||||
+
|
||||
/* version.c */
|
||||
extern const char openconnect_version_str[];
|
||||
|
||||
diff --git a/openconnect.h b/openconnect.h
|
||||
index 40de2811..3c65c090 100644
|
||||
--- a/openconnect.h
|
||||
+++ b/openconnect.h
|
||||
@@ -472,8 +472,11 @@ int openconnect_set_useragent(struct openconnect_info *vpninfo,
|
||||
int openconnect_set_gp_app_version(struct openconnect_info *vpninfo,
|
||||
const char *gp_app_version);
|
||||
int openconnect_set_gp_os_version(struct openconnect_info *vpninfo,
|
||||
const char *gp_os_version);
|
||||
+int openconnect_set_gp_host_id(struct openconnect_info *vpninfo,
|
||||
+ const char *gp_host_id);
|
||||
+
|
||||
|
||||
int openconnect_passphrase_from_fsid(struct openconnect_info *vpninfo);
|
||||
int openconnect_obtain_cookie(struct openconnect_info *vpninfo);
|
||||
int openconnect_init_ssl(void);
|
||||
--
|
||||
2.50.1 (Apple Git-155)
|
||||
@@ -15,6 +15,7 @@ pub(crate) struct ConnectOptions {
|
||||
pub os: *const c_char,
|
||||
pub os_version: *const c_char,
|
||||
pub client_version: *const c_char,
|
||||
pub host_id: *const c_char,
|
||||
pub local_hostname: *const c_char,
|
||||
|
||||
pub script: *const c_char,
|
||||
|
||||
@@ -80,6 +80,7 @@ int vpn_connect(const vpn_options *options, vpn_connected_callback callback)
|
||||
INFO("USER_AGENT: %s", options->user_agent);
|
||||
INFO("OS: %s", options->os);
|
||||
INFO("CLIENT_VERSION: %s", options->client_version);
|
||||
INFO("HOST_ID: %s", options->host_id ? options->host_id : "(not set)");
|
||||
INFO("VPNC_SCRIPT: %s", options->script);
|
||||
INFO("SCRIPT_TUN: %d", g_script_tun);
|
||||
INFO("CSD_USER: %d", options->csd_uid);
|
||||
@@ -120,6 +121,10 @@ int vpn_connect(const vpn_options *options, vpn_connected_callback callback)
|
||||
options->client_version);
|
||||
}
|
||||
|
||||
if (options->host_id) {
|
||||
openconnect_set_gp_host_id(vpninfo, options->host_id);
|
||||
}
|
||||
|
||||
effective_local_hostname = options->local_hostname;
|
||||
if (!effective_local_hostname && !uname(&utsbuf)) {
|
||||
effective_local_hostname = utsbuf.nodename;
|
||||
|
||||
@@ -25,6 +25,7 @@ typedef struct vpn_options {
|
||||
const char *os;
|
||||
const char *os_version;
|
||||
const char *client_version;
|
||||
const char *host_id;
|
||||
const char *local_hostname;
|
||||
|
||||
const char *script;
|
||||
|
||||
@@ -64,6 +64,7 @@ pub struct Vpn {
|
||||
os: CString,
|
||||
os_version: Option<CString>,
|
||||
client_version: Option<CString>,
|
||||
host_id: Option<CString>,
|
||||
local_hostname: Option<CString>,
|
||||
|
||||
script: CString,
|
||||
@@ -124,6 +125,7 @@ impl Vpn {
|
||||
os: self.os.as_ptr(),
|
||||
os_version: Self::option_to_ptr(&self.os_version),
|
||||
client_version: Self::option_to_ptr(&self.client_version),
|
||||
host_id: Self::option_to_ptr(&self.host_id),
|
||||
local_hostname: Self::option_to_ptr(&self.local_hostname),
|
||||
|
||||
script: self.script.as_ptr(),
|
||||
@@ -185,6 +187,7 @@ pub struct VpnBuilder {
|
||||
os: Option<String>,
|
||||
os_version: Option<String>,
|
||||
client_version: Option<String>,
|
||||
host_id: Option<String>,
|
||||
local_hostname: Option<String>,
|
||||
|
||||
certificate: Option<String>,
|
||||
@@ -217,6 +220,7 @@ impl VpnBuilder {
|
||||
os: None,
|
||||
os_version: None,
|
||||
client_version: None,
|
||||
host_id: None,
|
||||
local_hostname: None,
|
||||
|
||||
certificate: None,
|
||||
@@ -271,6 +275,11 @@ impl VpnBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn host_id<T: Into<Option<String>>>(mut self, host_id: T) -> Self {
|
||||
self.host_id = host_id.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn local_hostname<T: Into<Option<String>>>(mut self, local_hostname: T) -> Self {
|
||||
self.local_hostname = local_hostname.into();
|
||||
self
|
||||
@@ -378,6 +387,7 @@ impl VpnBuilder {
|
||||
os: Self::to_cstring(&os),
|
||||
os_version: self.os_version.as_deref().map(Self::to_cstring),
|
||||
client_version: self.client_version.as_deref().map(Self::to_cstring),
|
||||
host_id: self.host_id.as_deref().map(Self::to_cstring),
|
||||
local_hostname: self.local_hostname.as_deref().map(Self::to_cstring),
|
||||
|
||||
script: Self::to_cstring(&script),
|
||||
@@ -453,4 +463,39 @@ mod tests {
|
||||
assert_eq!(info.lifetime_secs, None);
|
||||
assert_eq!(info.lifetime_warning, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn connect_options_include_host_id() {
|
||||
let vpn = Vpn {
|
||||
server: CString::new("gateway.example.com").unwrap(),
|
||||
cookie: CString::new("cookie").unwrap(),
|
||||
user_agent: CString::new("agent").unwrap(),
|
||||
os: CString::new("linux").unwrap(),
|
||||
os_version: None,
|
||||
client_version: None,
|
||||
host_id: Some(CString::new("profile-host-id").unwrap()),
|
||||
local_hostname: None,
|
||||
script: CString::new("/bin/true").unwrap(),
|
||||
interface: None,
|
||||
script_tun: false,
|
||||
certificate: None,
|
||||
sslkey: None,
|
||||
key_password: None,
|
||||
servercert: None,
|
||||
csd_uid: 0,
|
||||
csd_wrapper: None,
|
||||
reconnect_timeout: 300,
|
||||
mtu: 0,
|
||||
disable_ipv6: false,
|
||||
no_dtls: false,
|
||||
dpd_interval: 0,
|
||||
no_xmlpost: false,
|
||||
callback: Default::default(),
|
||||
};
|
||||
|
||||
let options = vpn.build_connect_options();
|
||||
|
||||
let host_id = unsafe { CStr::from_ptr(options.host_id) }.to_str().unwrap();
|
||||
assert_eq!(host_id, "profile-host-id");
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ use std::{io, path::Path};
|
||||
use is_executable::IsExecutable;
|
||||
|
||||
const VPNC_SCRIPT_LOCATIONS: &[&str] = &[
|
||||
"/usr/local/libexec/gpclient/vpnc-script",
|
||||
"/usr/libexec/gpclient/vpnc-script",
|
||||
"/usr/lib/gpclient/vpnc-script",
|
||||
"/usr/local/share/vpnc-scripts/vpnc-script",
|
||||
@@ -19,6 +20,7 @@ const VPNC_SCRIPT_LOCATIONS: &[&str] = &[
|
||||
];
|
||||
|
||||
const CSD_WRAPPER_LOCATIONS: &[&str] = &[
|
||||
"/usr/local/libexec/gpclient/hipreport.sh",
|
||||
"/usr/libexec/gpclient/hipreport.sh",
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
"/usr/lib/x86_64-linux-gnu/openconnect/hipreport.sh",
|
||||
@@ -44,11 +46,11 @@ fn find_executable(locations: &[&'static str]) -> Option<&'static str> {
|
||||
}
|
||||
|
||||
pub fn find_vpnc_script() -> Option<&'static str> {
|
||||
find_executable(&VPNC_SCRIPT_LOCATIONS)
|
||||
find_executable(VPNC_SCRIPT_LOCATIONS)
|
||||
}
|
||||
|
||||
pub fn find_csd_wrapper() -> Option<&'static str> {
|
||||
find_executable(&CSD_WRAPPER_LOCATIONS)
|
||||
find_executable(CSD_WRAPPER_LOCATIONS)
|
||||
}
|
||||
|
||||
/// If file exists, check if it is executable
|
||||
|
||||
Reference in new issue
Block a user