diff --git a/Cargo.lock b/Cargo.lock index f42be35..14221c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -165,6 +165,7 @@ version = "2.4.6" dependencies = [ "anyhow", "block2 0.6.2", + "common", "gpapi", "html-escape", "log", @@ -584,9 +585,6 @@ dependencies = [ [[package]] name = "common" version = "2.4.6" -dependencies = [ - "is_executable", -] [[package]] name = "compile-time" @@ -1602,6 +1600,7 @@ dependencies = [ "chacha20poly1305", "clap", "clap-verbosity-flag", + "common", "dns-lookup", "env_logger", "gtk", @@ -1637,6 +1636,7 @@ dependencies = [ "anyhow", "auth", "clap", + "common", "compile-time", "env_logger", "gpapi", @@ -1696,6 +1696,7 @@ dependencies = [ "anyhow", "axum", "clap", + "common", "compile-time", "env_logger", "futures", @@ -2986,7 +2987,7 @@ name = "openconnect" version = "2.4.6" dependencies = [ "cc", - "common", + "is_executable", "log", ] diff --git a/apps/gpauth/Cargo.toml b/apps/gpauth/Cargo.toml index b81e1f5..1312059 100644 --- a/apps/gpauth/Cargo.toml +++ b/apps/gpauth/Cargo.toml @@ -10,6 +10,7 @@ license.workspace = true tauri-build = { version = "2", features = [], optional = true } [dependencies] +common = { path = "../../crates/common" } gpapi = { path = "../../crates/gpapi", features = ["clap"] } auth = { path = "../../crates/auth", features = ["browser-auth"] } diff --git a/apps/gpauth/src/cli.rs b/apps/gpauth/src/cli.rs index 014875d..006afa3 100644 --- a/apps/gpauth/src/cli.rs +++ b/apps/gpauth/src/cli.rs @@ -1,11 +1,11 @@ use auth::{auth_prelogin, BrowserAuthenticator}; use clap::Parser; +use common::constants::GP_USER_AGENT; use gpapi::{ auth::{SamlAuthData, SamlAuthResult}, clap::{args::Os, handle_error, Args, InfoLevelVerbosity}, gp_params::{ClientOs, GpParams}, utils::{normalize_server, openssl}, - GP_USER_AGENT, }; use log::info; use serde_json::json; diff --git a/apps/gpclient/src/connect.rs b/apps/gpclient/src/connect.rs index 32c6b15..3b74eaf 100644 --- a/apps/gpclient/src/connect.rs +++ b/apps/gpclient/src/connect.rs @@ -2,7 +2,7 @@ use std::{cell::RefCell, fs, sync::Arc}; use anyhow::bail; use clap::Args; -use common::vpn_utils::find_csd_wrapper; +use common::constants::GP_USER_AGENT; use gpapi::{ auth::SamlAuthResult, clap::{args::Os, ToVerboseArg}, @@ -16,7 +16,6 @@ use gpapi::{ users::{get_non_root_user, get_user_by_name}, }, utils::{request::RequestIdentityError, shutdown_signal}, - GP_USER_AGENT, }; use inquire::{Password, PasswordDisplayMode, Select, Text}; use log::{info, warn}; diff --git a/apps/gpclient/src/launch_gui.rs b/apps/gpclient/src/launch_gui.rs index fd5e8aa..6acae4f 100644 --- a/apps/gpclient/src/launch_gui.rs +++ b/apps/gpclient/src/launch_gui.rs @@ -1,11 +1,11 @@ use std::{collections::HashMap, env::temp_dir, fs, path::PathBuf}; use clap::Args; +use common::constants::GP_CALLBACK_PORT_FILENAME; use directories::ProjectDirs; use gpapi::{ process::service_launcher::ServiceLauncher, utils::{endpoint::http_endpoint, env_utils, shutdown_signal}, - GP_CALLBACK_PORT_FILENAME, }; use log::info; use tokio::io::AsyncWriteExt; diff --git a/apps/gpservice/Cargo.toml b/apps/gpservice/Cargo.toml index a990b01..f3e06c6 100644 --- a/apps/gpservice/Cargo.toml +++ b/apps/gpservice/Cargo.toml @@ -5,6 +5,7 @@ edition.workspace = true license.workspace = true [dependencies] +common = { path = "../../crates/common" } gpapi = { path = "../../crates/gpapi", features = ["clap", "logger"] } openconnect = { path = "../../crates/openconnect" } clap.workspace = true diff --git a/apps/gpservice/src/cli.rs b/apps/gpservice/src/cli.rs index fefe6ca..01fec34 100644 --- a/apps/gpservice/src/cli.rs +++ b/apps/gpservice/src/cli.rs @@ -3,13 +3,13 @@ use std::{collections::HashMap, io::Write}; use anyhow::bail; use clap::Parser; +use common::constants::GP_SERVICE_LOCK_FILE; use gpapi::clap::InfoLevelVerbosity; use gpapi::logger; use gpapi::{ process::gui_launcher::GuiLauncher, service::{request::WsRequest, vpn_state::VpnState}, utils::{crypto::generate_key, env_utils, lock_file::LockFile, redact::Redaction, shutdown_signal}, - GP_SERVICE_LOCK_FILE, }; use log::{info, warn}; use tokio::sync::{mpsc, watch}; diff --git a/apps/gpservice/src/handlers.rs b/apps/gpservice/src/handlers.rs index 700d6ab..2dd1bcf 100644 --- a/apps/gpservice/src/handlers.rs +++ b/apps/gpservice/src/handlers.rs @@ -17,11 +17,11 @@ use axum::{ http::StatusCode, response::IntoResponse, }; +use common::constants::GP_GUI_BINARY; use futures::{SinkExt, StreamExt}; use gpapi::{ service::{event::WsEvent, request::UpdateGuiRequest}, utils::checksum::verify_checksum, - GP_GUI_BINARY, }; use log::{info, warn}; use tar::Archive; diff --git a/crates/auth/Cargo.toml b/crates/auth/Cargo.toml index d1b97f4..fb65a69 100644 --- a/crates/auth/Cargo.toml +++ b/crates/auth/Cargo.toml @@ -8,6 +8,7 @@ edition.workspace = true license.workspace = true [dependencies] +common = { path = "../common" } gpapi = { path = "../gpapi" } # Shared dependencies diff --git a/crates/auth/src/browser/browser_auth.rs b/crates/auth/src/browser/browser_auth.rs index 30dc2d1..2993673 100644 --- a/crates/auth/src/browser/browser_auth.rs +++ b/crates/auth/src/browser/browser_auth.rs @@ -1,6 +1,7 @@ use std::{env::temp_dir, fs, os::unix::fs::PermissionsExt}; -use gpapi::{auth::SamlAuthData, GP_CALLBACK_PORT_FILENAME}; +use common::constants::GP_CALLBACK_PORT_FILENAME; +use gpapi::auth::SamlAuthData; use log::info; use tokio::{ io::AsyncReadExt, diff --git a/crates/common/Cargo.toml b/crates/common/Cargo.toml index 864b265..84a36d1 100644 --- a/crates/common/Cargo.toml +++ b/crates/common/Cargo.toml @@ -6,6 +6,3 @@ authors.workspace = true homepage.workspace = true edition.workspace = true license.workspace = true - -[dependencies] -is_executable.workspace = true diff --git a/crates/gpapi/build.rs b/crates/common/build.rs similarity index 89% rename from crates/gpapi/build.rs rename to crates/common/build.rs index 5cd164d..15c3e25 100644 --- a/crates/gpapi/build.rs +++ b/crates/common/build.rs @@ -14,6 +14,9 @@ fn main() { println!("cargo:rustc-env=GP_SERVICE_BINARY={}", gp_service_binary.display()); println!("cargo:rustc-env=GP_CLIENT_BINARY={}", gp_client_binary.display()); println!("cargo:rustc-env=GP_AUTH_BINARY={}", gp_auth_binary.display()); - println!("cargo:rustc-env=GP_GUI_HELPER_BINARY={}", gp_gui_helper_binary.display()); + println!( + "cargo:rustc-env=GP_GUI_HELPER_BINARY={}", + gp_gui_helper_binary.display() + ); println!("cargo:rustc-env=GP_GUI_BINARY={}", gp_gui_binary.display()); } diff --git a/crates/common/src/constants.rs b/crates/common/src/constants.rs new file mode 100644 index 0000000..48ed910 --- /dev/null +++ b/crates/common/src/constants.rs @@ -0,0 +1,27 @@ +pub const GP_USER_AGENT: &str = "PAN GlobalProtect"; +pub const GP_SERVICE_LOCK_FILE: &str = "/var/run/gpservice.lock"; +pub const GP_CALLBACK_PORT_FILENAME: &str = "gpcallback.port"; + +// Release binaries are hardcoded paths +#[cfg(not(debug_assertions))] +pub const GP_CLIENT_BINARY: &str = "/usr/bin/gpclient"; +#[cfg(not(debug_assertions))] +pub const GP_SERVICE_BINARY: &str = "/usr/bin/gpservice"; +#[cfg(not(debug_assertions))] +pub const GP_GUI_BINARY: &str = "/usr/bin/gpgui"; +#[cfg(not(debug_assertions))] +pub const GP_GUI_HELPER_BINARY: &str = "/usr/bin/gpgui-helper"; +#[cfg(not(debug_assertions))] +pub const GP_AUTH_BINARY: &str = "/usr/bin/gpauth"; + +// Debug binaries are set in build.rs via environment variables +#[cfg(debug_assertions)] +pub const GP_CLIENT_BINARY: &str = env!("GP_CLIENT_BINARY"); +#[cfg(debug_assertions)] +pub const GP_SERVICE_BINARY: &str = env!("GP_SERVICE_BINARY"); +#[cfg(debug_assertions)] +pub const GP_GUI_BINARY: &str = env!("GP_GUI_BINARY"); +#[cfg(debug_assertions)] +pub const GP_GUI_HELPER_BINARY: &str = env!("GP_GUI_HELPER_BINARY"); +#[cfg(debug_assertions)] +pub const GP_AUTH_BINARY: &str = env!("GP_AUTH_BINARY"); diff --git a/crates/common/src/lib.rs b/crates/common/src/lib.rs index f40aebc..0b6d2c4 100644 --- a/crates/common/src/lib.rs +++ b/crates/common/src/lib.rs @@ -1 +1 @@ -pub mod vpn_utils; +pub mod constants; diff --git a/crates/gpapi/Cargo.toml b/crates/gpapi/Cargo.toml index 6fb217d..87d4fc6 100644 --- a/crates/gpapi/Cargo.toml +++ b/crates/gpapi/Cargo.toml @@ -6,6 +6,7 @@ edition.workspace = true license = "MIT" [dependencies] +common = { path = "../common" } anyhow.workspace = true base64.workspace = true dns-lookup.workspace = true diff --git a/crates/gpapi/src/gp_params.rs b/crates/gpapi/src/gp_params.rs index a595b5f..d3d3ce2 100644 --- a/crates/gpapi/src/gp_params.rs +++ b/crates/gpapi/src/gp_params.rs @@ -1,11 +1,12 @@ use std::collections::HashMap; +use common::constants::GP_USER_AGENT; use log::info; use reqwest::Client; use serde::{Deserialize, Serialize}; use specta::Type; -use crate::{utils::request::create_identity, GP_USER_AGENT}; +use crate::utils::request::create_identity; #[derive(Debug, Serialize, Deserialize, Clone, Type, Default)] pub enum ClientOs { diff --git a/crates/gpapi/src/lib.rs b/crates/gpapi/src/lib.rs index 7b085eb..9549a61 100644 --- a/crates/gpapi/src/lib.rs +++ b/crates/gpapi/src/lib.rs @@ -16,29 +16,3 @@ pub mod clap; #[cfg(debug_assertions)] pub const GP_API_KEY: &[u8; 32] = &[0; 32]; - -pub const GP_USER_AGENT: &str = "PAN GlobalProtect"; -pub const GP_SERVICE_LOCK_FILE: &str = "/var/run/gpservice.lock"; -pub const GP_CALLBACK_PORT_FILENAME: &str = "gpcallback.port"; - -#[cfg(not(debug_assertions))] -pub const GP_CLIENT_BINARY: &str = "/usr/bin/gpclient"; -#[cfg(not(debug_assertions))] -pub const GP_SERVICE_BINARY: &str = "/usr/bin/gpservice"; -#[cfg(not(debug_assertions))] -pub const GP_GUI_BINARY: &str = "/usr/bin/gpgui"; -#[cfg(not(debug_assertions))] -pub const GP_GUI_HELPER_BINARY: &str = "/usr/bin/gpgui-helper"; -#[cfg(not(debug_assertions))] -pub(crate) const GP_AUTH_BINARY: &str = "/usr/bin/gpauth"; - -#[cfg(debug_assertions)] -pub const GP_CLIENT_BINARY: &str = env!("GP_CLIENT_BINARY"); -#[cfg(debug_assertions)] -pub const GP_SERVICE_BINARY: &str = env!("GP_SERVICE_BINARY"); -#[cfg(debug_assertions)] -pub const GP_GUI_BINARY: &str = env!("GP_GUI_BINARY"); -#[cfg(debug_assertions)] -pub const GP_GUI_HELPER_BINARY: &str = env!("GP_GUI_HELPER_BINARY"); -#[cfg(debug_assertions)] -pub(crate) const GP_AUTH_BINARY: &str = env!("GP_AUTH_BINARY"); diff --git a/crates/gpapi/src/process/auth_launcher.rs b/crates/gpapi/src/process/auth_launcher.rs index 11680fe..aa5514f 100644 --- a/crates/gpapi/src/process/auth_launcher.rs +++ b/crates/gpapi/src/process/auth_launcher.rs @@ -1,9 +1,10 @@ use std::process::Stdio; use anyhow::bail; +use common::constants::GP_AUTH_BINARY; use tokio::process::Command; -use crate::{auth::SamlAuthResult, credential::Credential, GP_AUTH_BINARY}; +use crate::{auth::SamlAuthResult, credential::Credential}; use super::command_traits::CommandExt; diff --git a/crates/gpapi/src/process/gui_helper_launcher.rs b/crates/gpapi/src/process/gui_helper_launcher.rs index 6fe9e34..f56a65e 100644 --- a/crates/gpapi/src/process/gui_helper_launcher.rs +++ b/crates/gpapi/src/process/gui_helper_launcher.rs @@ -1,10 +1,11 @@ use std::{collections::HashMap, path::PathBuf, process::Stdio}; use anyhow::bail; +use common::constants::GP_GUI_HELPER_BINARY; use log::info; use tokio::{io::AsyncWriteExt, process::Command}; -use crate::{process::command_traits::CommandExt, utils, GP_GUI_HELPER_BINARY}; +use crate::{process::command_traits::CommandExt, utils}; pub struct GuiHelperLauncher<'a> { program: PathBuf, diff --git a/crates/gpapi/src/process/gui_launcher.rs b/crates/gpapi/src/process/gui_launcher.rs index c7e1f87..3658874 100644 --- a/crates/gpapi/src/process/gui_launcher.rs +++ b/crates/gpapi/src/process/gui_launcher.rs @@ -5,10 +5,11 @@ use std::{ }; use anyhow::bail; +use common::constants::GP_GUI_BINARY; use log::info; use tokio::{io::AsyncWriteExt, process::Command}; -use crate::{process::gui_helper_launcher::GuiHelperLauncher, utils::base64, GP_GUI_BINARY}; +use crate::{process::gui_helper_launcher::GuiHelperLauncher, utils::base64}; use super::command_traits::CommandExt; diff --git a/crates/gpapi/src/process/service_launcher.rs b/crates/gpapi/src/process/service_launcher.rs index aada481..2fccf85 100644 --- a/crates/gpapi/src/process/service_launcher.rs +++ b/crates/gpapi/src/process/service_launcher.rs @@ -4,10 +4,9 @@ use std::{ process::{ExitStatus, Stdio}, }; +use common::constants::GP_SERVICE_BINARY; use tokio::process::Command; -use crate::GP_SERVICE_BINARY; - use super::command_traits::CommandExt; pub struct ServiceLauncher<'a> { @@ -15,7 +14,7 @@ pub struct ServiceLauncher<'a> { minimized: bool, env_file: Option, log_file: Option, - verbose: Option<&'a str> + verbose: Option<&'a str>, } impl Default for ServiceLauncher<'_> { @@ -31,7 +30,7 @@ impl<'a> ServiceLauncher<'a> { minimized: false, env_file: None, log_file: None, - verbose: None + verbose: None, } } diff --git a/crates/gpapi/src/utils/lock_file.rs b/crates/gpapi/src/utils/lock_file.rs index fa535f1..e742855 100644 --- a/crates/gpapi/src/utils/lock_file.rs +++ b/crates/gpapi/src/utils/lock_file.rs @@ -1,5 +1,6 @@ use std::path::PathBuf; +use common::constants::GP_SERVICE_LOCK_FILE; use thiserror::Error; use tokio::fs; @@ -94,7 +95,7 @@ impl LockInfo { } pub async fn gpservice_lock_info() -> Result { - LockInfo::from_file(crate::GP_SERVICE_LOCK_FILE).await + LockInfo::from_file(GP_SERVICE_LOCK_FILE).await } #[cfg(test)] diff --git a/crates/openconnect/Cargo.toml b/crates/openconnect/Cargo.toml index dc5e504..d3216a9 100644 --- a/crates/openconnect/Cargo.toml +++ b/crates/openconnect/Cargo.toml @@ -6,8 +6,8 @@ license.workspace = true links = "openconnect" [dependencies] -common = { path = "../common" } log.workspace = true +is_executable.workspace = true [build-dependencies] cc = "1" diff --git a/crates/openconnect/src/lib.rs b/crates/openconnect/src/lib.rs index ebd900d..f4bcba5 100644 --- a/crates/openconnect/src/lib.rs +++ b/crates/openconnect/src/lib.rs @@ -1,4 +1,6 @@ mod ffi; mod vpn; +mod vpn_utils; pub use vpn::*; +pub use vpn_utils::*; diff --git a/crates/openconnect/src/vpn.rs b/crates/openconnect/src/vpn.rs index 92ab34f..fdc8dce 100644 --- a/crates/openconnect/src/vpn.rs +++ b/crates/openconnect/src/vpn.rs @@ -4,10 +4,10 @@ use std::{ sync::{Arc, RwLock}, }; -use common::vpn_utils::{check_executable, find_vpnc_script}; use log::info; use crate::ffi; +use crate::vpn_utils::{check_executable, find_csd_wrapper, find_vpnc_script}; type OnConnectedCallback = Arc>>>; diff --git a/crates/common/src/vpn_utils.rs b/crates/openconnect/src/vpn_utils.rs similarity index 97% rename from crates/common/src/vpn_utils.rs rename to crates/openconnect/src/vpn_utils.rs index 146c55b..e1558d8 100644 --- a/crates/common/src/vpn_utils.rs +++ b/crates/openconnect/src/vpn_utils.rs @@ -48,7 +48,7 @@ pub fn find_csd_wrapper() -> Option { pub fn check_executable(file: &str) -> Result<(), io::Error> { let path = Path::new(file); - if path.exists() && !path.is_executable() { + if !path.is_executable() { return Err(io::Error::new( io::ErrorKind::PermissionDenied, format!("{} is not executable", file),