mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-19 06:26:14 -05:00
refactor: align GP profile and packaging flow
Main changes: - Refactor connect/auth flows around a single OS profile and host identity model, including gateway fallback and cookie-on-stdin handling. - Align request parameters, HIP host-id propagation, SAML webview user-agent behavior, and portal default-browser handling with observed official client behavior. - Add opt-in cookie cache support and Microsoft Defender HIP reporting while keeping host-id validation explicit. - Add BSD build, packaging, release artifact, and provenance support with FreeBSD/OpenBSD path and dependency cleanup. - Update NixOS install documentation and dependency compatibility fixes.
This commit is contained in:
92 files changed
+9847
-2868
No files matched your search
@@ -3,12 +3,18 @@ use std::env;
|
||||
use anyhow::bail;
|
||||
use uzers::User;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
enum RealUserLookup {
|
||||
Uid(u32),
|
||||
Name(String),
|
||||
}
|
||||
|
||||
pub fn get_user_by_name(username: &str) -> anyhow::Result<User> {
|
||||
uzers::get_user_by_name(username).ok_or_else(|| anyhow::anyhow!("User ({}) not found", username))
|
||||
}
|
||||
|
||||
pub fn get_non_root_user() -> anyhow::Result<User> {
|
||||
let current_user = whoami::username();
|
||||
let current_user = current_username()?;
|
||||
|
||||
let user = if current_user == "root" {
|
||||
get_real_user()?
|
||||
@@ -24,16 +30,87 @@ pub fn get_non_root_user() -> anyhow::Result<User> {
|
||||
}
|
||||
|
||||
pub fn get_current_user() -> anyhow::Result<User> {
|
||||
let current_user = whoami::username();
|
||||
let current_user = current_username()?;
|
||||
get_user_by_name(¤t_user)
|
||||
}
|
||||
|
||||
fn current_username() -> anyhow::Result<String> {
|
||||
whoami::username().map_err(|err| anyhow::anyhow!("Failed to resolve current user: {err}"))
|
||||
}
|
||||
|
||||
fn get_real_user() -> anyhow::Result<User> {
|
||||
// Read the UID from SUDO_UID or PKEXEC_UID environment variable if available.
|
||||
let uid = match env::var("SUDO_UID") {
|
||||
Ok(uid) => uid.parse::<u32>()?,
|
||||
_ => env::var("PKEXEC_UID")?.parse::<u32>()?,
|
||||
};
|
||||
match real_user_lookup(|key| env::var(key).ok())? {
|
||||
RealUserLookup::Uid(uid) => uzers::get_user_by_uid(uid).ok_or_else(|| anyhow::anyhow!("User not found")),
|
||||
RealUserLookup::Name(name) => get_user_by_name(&name),
|
||||
}
|
||||
}
|
||||
|
||||
fn real_user_lookup(env_var: impl Fn(&str) -> Option<String>) -> anyhow::Result<RealUserLookup> {
|
||||
if let Some(uid) = env_var("SUDO_UID") {
|
||||
return Ok(RealUserLookup::Uid(uid.parse::<u32>()?));
|
||||
}
|
||||
|
||||
if let Some(uid) = env_var("PKEXEC_UID") {
|
||||
return Ok(RealUserLookup::Uid(uid.parse::<u32>()?));
|
||||
}
|
||||
|
||||
if let Some(user) = env_var("DOAS_USER").filter(|user| !user.trim().is_empty()) {
|
||||
return Ok(RealUserLookup::Name(user));
|
||||
}
|
||||
|
||||
bail!("User not found")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn lookup(vars: &[(&str, &str)]) -> anyhow::Result<RealUserLookup> {
|
||||
real_user_lookup(|key| {
|
||||
vars
|
||||
.iter()
|
||||
.find(|(name, _)| *name == key)
|
||||
.map(|(_, value)| value.to_string())
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn real_user_lookup_uses_sudo_uid() {
|
||||
assert_eq!(lookup(&[("SUDO_UID", "1000")]).unwrap(), RealUserLookup::Uid(1000));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn real_user_lookup_uses_pkexec_uid() {
|
||||
assert_eq!(lookup(&[("PKEXEC_UID", "1001")]).unwrap(), RealUserLookup::Uid(1001));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn real_user_lookup_uses_doas_user() {
|
||||
assert_eq!(
|
||||
lookup(&[("DOAS_USER", "alice")]).unwrap(),
|
||||
RealUserLookup::Name("alice".to_string())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn real_user_lookup_prefers_uid_over_doas_user() {
|
||||
assert_eq!(
|
||||
lookup(&[("SUDO_UID", "1000"), ("PKEXEC_UID", "1001"), ("DOAS_USER", "alice")]).unwrap(),
|
||||
RealUserLookup::Uid(1000)
|
||||
);
|
||||
assert_eq!(
|
||||
lookup(&[("PKEXEC_UID", "1001"), ("DOAS_USER", "alice")]).unwrap(),
|
||||
RealUserLookup::Uid(1001)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn real_user_lookup_ignores_blank_doas_user() {
|
||||
assert!(lookup(&[("DOAS_USER", " ")]).is_err());
|
||||
}
|
||||
|
||||
uzers::get_user_by_uid(uid).ok_or_else(|| anyhow::anyhow!("User not found"))
|
||||
#[test]
|
||||
fn real_user_lookup_errors_without_root_origin_env() {
|
||||
assert!(lookup(&[]).is_err());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user