mirror of
				https://github.com/yuezk/GlobalProtect-openconnect.git
				synced 2025-05-20 07:26:58 -04:00 
			
		
		
		
	refactor: find the vpnc_script from predefined locations
This commit is contained in:
		| @@ -1,3 +1,4 @@ | ||||
| use crate::vpn::vpnc_script::find_default_vpnc_script; | ||||
| use log::{debug, info, warn}; | ||||
| use serde::{Deserialize, Serialize}; | ||||
| use std::ffi::{c_void, CString}; | ||||
| @@ -7,6 +8,7 @@ use tokio::sync::watch; | ||||
| use tokio::sync::{mpsc, Mutex}; | ||||
|  | ||||
| mod ffi; | ||||
| mod vpnc_script; | ||||
|  | ||||
| #[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize)] | ||||
| #[serde(rename_all = "lowercase")] | ||||
| @@ -87,11 +89,21 @@ impl Vpn { | ||||
|         server: &str, | ||||
|         cookie: &str, | ||||
|     ) -> Result<(), Box<dyn std::error::Error>> { | ||||
|         let script = match find_default_vpnc_script() { | ||||
|             Some(script) => { | ||||
|                 debug!("Using default vpnc-script: {}", script); | ||||
|                 script | ||||
|             } | ||||
|             None => { | ||||
|                 return Err("Failed to find default vpnc-script".into()); | ||||
|             } | ||||
|         }; | ||||
|  | ||||
|         // Save the VPN options so we can use them later, e.g. reconnect | ||||
|         *self.vpn_options.lock().await = Some(VpnOptions { | ||||
|             server: VpnOptions::to_cstr(server), | ||||
|             cookie: VpnOptions::to_cstr(cookie), | ||||
|             script: VpnOptions::to_cstr("/usr/share/vpnc-scripts/vpnc-script"), | ||||
|             script: VpnOptions::to_cstr(script), | ||||
|         }); | ||||
|  | ||||
|         let vpn_options = self.vpn_options.clone(); | ||||
|   | ||||
							
								
								
									
										21
									
								
								gpcommon/src/vpn/vpnc_script.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								gpcommon/src/vpn/vpnc_script.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,21 @@ | ||||
| use std::path::Path; | ||||
|  | ||||
| use is_executable::IsExecutable; | ||||
|  | ||||
| const VPNC_SCRIPT_LOCATIONS: [&str; 4] = [ | ||||
|     "/usr/local/share/vpnc-scripts/vpnc-script", | ||||
|     "/usr/local/sbin/vpnc-script", | ||||
|     "/usr/share/vpnc-scripts/vpnc-script", | ||||
|     "/usr/sbin/vpnc-script /etc/vpnc/vpnc-script", | ||||
| ]; | ||||
|  | ||||
| pub(crate) fn find_default_vpnc_script() -> Option<&'static str> { | ||||
|     for location in VPNC_SCRIPT_LOCATIONS.iter() { | ||||
|         let path = Path::new(location); | ||||
|         if path.is_executable() { | ||||
|             return Some(location); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     None | ||||
| } | ||||
		Reference in New Issue
	
	Block a user