mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-18 22:16:18 -05:00
feat: upgrade Rust version to 1.85
This commit is contained in:
22 files changed
+865
-938
No files matched your search
@@ -31,7 +31,7 @@ pub(crate) struct ConnectOptions {
|
||||
}
|
||||
|
||||
#[link(name = "vpn")]
|
||||
extern "C" {
|
||||
unsafe extern "C" {
|
||||
#[link_name = "vpn_connect"]
|
||||
fn vpn_connect(options: *const ConnectOptions, callback: extern "C" fn(i32, *mut c_void)) -> c_int;
|
||||
|
||||
@@ -47,7 +47,7 @@ pub(crate) fn disconnect() {
|
||||
unsafe { vpn_disconnect() }
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn on_vpn_connected(pipe_fd: i32, vpn: *mut c_void) {
|
||||
let vpn = unsafe { &*(vpn as *const Vpn) };
|
||||
vpn.on_connected(pipe_fd);
|
||||
@@ -56,7 +56,7 @@ extern "C" fn on_vpn_connected(pipe_fd: i32, vpn: *mut c_void) {
|
||||
// Logger used in the C code.
|
||||
// level: 0 = error, 1 = info, 2 = debug, 3 = trace
|
||||
// map the error level log in openconnect to the warning level
|
||||
#[no_mangle]
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn vpn_log(level: i32, message: *const c_char) {
|
||||
let message = unsafe { std::ffi::CStr::from_ptr(message) };
|
||||
let message = message.to_str().unwrap_or("Invalid log message");
|
||||
|
||||
@@ -241,17 +241,17 @@ impl VpnBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
fn determine_script(&self) -> Result<String, VpnError> {
|
||||
fn determine_script(&self) -> Result<&str, VpnError> {
|
||||
match &self.script {
|
||||
Some(script) => {
|
||||
check_executable(script).map_err(|e| VpnError::new(e.to_string()))?;
|
||||
Ok(script.clone())
|
||||
Ok(script)
|
||||
}
|
||||
None => find_vpnc_script().ok_or_else(|| VpnError::new(String::from("Failed to find vpnc-script"))),
|
||||
}
|
||||
}
|
||||
|
||||
fn determine_csd_wrapper(&self) -> Result<Option<String>, VpnError> {
|
||||
fn determine_csd_wrapper(&self) -> Result<Option<&str>, VpnError> {
|
||||
if !self.hip {
|
||||
return Ok(None);
|
||||
}
|
||||
@@ -259,7 +259,7 @@ impl VpnBuilder {
|
||||
match &self.csd_wrapper {
|
||||
Some(csd_wrapper) if !csd_wrapper.is_empty() => {
|
||||
check_executable(csd_wrapper).map_err(|e| VpnError::new(e.to_string()))?;
|
||||
Ok(Some(csd_wrapper.clone()))
|
||||
Ok(Some(csd_wrapper))
|
||||
}
|
||||
_ => {
|
||||
let s = find_csd_wrapper().ok_or_else(|| VpnError::new(String::from("Failed to find csd wrapper")))?;
|
||||
@@ -269,8 +269,8 @@ impl VpnBuilder {
|
||||
}
|
||||
|
||||
pub fn build(self) -> Result<Vpn, VpnError> {
|
||||
let script = self.determine_script()?;
|
||||
let csd_wrapper = self.determine_csd_wrapper()?;
|
||||
let script = self.determine_script()?.to_owned();
|
||||
let csd_wrapper = self.determine_csd_wrapper()?.map(|s| s.to_owned());
|
||||
|
||||
let user_agent = self.user_agent.unwrap_or_default();
|
||||
let os = self.os.unwrap_or("linux".to_string());
|
||||
|
||||
@@ -25,22 +25,22 @@ const CSD_WRAPPER_LOCATIONS: &[&str] = &[
|
||||
"/opt/homebrew/opt/openconnect/libexec/openconnect/hipreport.sh",
|
||||
];
|
||||
|
||||
fn find_executable(locations: &[&str]) -> Option<String> {
|
||||
fn find_executable(locations: &[&'static str]) -> Option<&'static str> {
|
||||
for location in locations.iter() {
|
||||
let path = Path::new(location);
|
||||
if path.is_executable() {
|
||||
return Some(location.to_string());
|
||||
return Some(*location);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub fn find_vpnc_script() -> Option<String> {
|
||||
pub fn find_vpnc_script() -> Option<&'static str> {
|
||||
find_executable(&VPNC_SCRIPT_LOCATIONS)
|
||||
}
|
||||
|
||||
pub fn find_csd_wrapper() -> Option<String> {
|
||||
pub fn find_csd_wrapper() -> Option<&'static str> {
|
||||
find_executable(&CSD_WRAPPER_LOCATIONS)
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ pub fn find_csd_wrapper() -> Option<String> {
|
||||
pub fn check_executable(file: &str) -> Result<(), io::Error> {
|
||||
let path = Path::new(file);
|
||||
|
||||
if !path.is_executable() {
|
||||
if path.exists() && !path.is_executable() {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::PermissionDenied,
|
||||
format!("{} is not executable", file),
|
||||
|
||||
Reference in new issue
Block a user