mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-30 17:56:13 -05:00
Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
341e74683f | ||
|
|
e63de466b3 | ||
|
|
5662aa16d6 | ||
|
|
d24800db4b | ||
|
|
89f6364a7b | ||
|
|
69155d04b9 | ||
|
|
2160bd82f8 | ||
|
|
2a4d23f595 | ||
|
|
1e140ca764 |
No files matched your search
@@ -0,0 +1,22 @@
|
||||
name: Windows adapter DNS check
|
||||
on:
|
||||
push:
|
||||
branches: [ci/windows-adapter-dns-native]
|
||||
permissions:
|
||||
contents: read
|
||||
jobs:
|
||||
network:
|
||||
runs-on: windows-11-arm
|
||||
timeout-minutes: 15
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: dtolnay/[email protected]
|
||||
- name: Test native Wintun adapter configuration
|
||||
shell: pwsh
|
||||
run: |
|
||||
$zip = Join-Path $env:RUNNER_TEMP 'wintun.zip'
|
||||
Invoke-WebRequest 'https://www.wintun.net/builds/wintun-0.14.1.zip' -OutFile $zip
|
||||
if ((Get-FileHash $zip).Hash -ne '07C256185D6EE3652E09FA55C0B673E2624B565E02C4B9091C79CA7D2F24EF51') { throw 'Wintun checksum mismatch' }
|
||||
Expand-Archive $zip $env:RUNNER_TEMP
|
||||
$env:GP_TEST_WINTUN_DLL = Join-Path $env:RUNNER_TEMP 'wintun/bin/arm64/wintun.dll'
|
||||
cargo +1.97.0 test --locked -p gpvpnc --test windows_network -- --ignored --nocapture --test-threads=1
|
||||
@@ -40,7 +40,7 @@ GP Connect is an independent project. It is not affiliated with or endorsed by P
|
||||
|
||||
### Windows
|
||||
|
||||
Download the Windows installer for [x64](https://github.com/yuezk/GlobalProtect-openconnect/releases/download/v3.7.0/GPConnect_3.7.0_windows-x64-setup.exe) or [ARM64](https://github.com/yuezk/GlobalProtect-openconnect/releases/download/v3.7.0/GPConnect_3.7.0_windows-arm64-setup.exe). Run it and approve the administrator prompt.
|
||||
Download the Windows installer for [x64](https://github.com/yuezk/GlobalProtect-openconnect/releases/download/v3.7.1/GPConnect_3.7.1_windows-x64-setup.exe) or [ARM64](https://github.com/yuezk/GlobalProtect-openconnect/releases/download/v3.7.1/GPConnect_3.7.1_windows-arm64-setup.exe). Run it and approve the administrator prompt.
|
||||
|
||||
### macOS
|
||||
|
||||
@@ -54,11 +54,11 @@ brew install --cask yuezk/gp-connect/gp-connect
|
||||
|
||||
#### DMG installer
|
||||
|
||||
Open the [Apple silicon DMG](https://github.com/yuezk/GlobalProtect-openconnect/releases/download/v3.7.0/GPConnect_3.7.0_arm64.dmg) and drag GP Connect into Applications.
|
||||
Open the [Apple silicon DMG](https://github.com/yuezk/GlobalProtect-openconnect/releases/download/v3.7.1/GPConnect_3.7.1_arm64.dmg) and drag GP Connect into Applications.
|
||||
|
||||
### Alpine Linux
|
||||
|
||||
Download the APK for [x86_64](https://github.com/yuezk/GlobalProtect-openconnect/releases/download/v3.7.0/globalprotect-openconnect-3.7.0-r1-x86_64.apk) or [ARM64](https://github.com/yuezk/GlobalProtect-openconnect/releases/download/v3.7.0/globalprotect-openconnect-3.7.0-r1-aarch64.apk).
|
||||
Download the APK for [x86_64](https://github.com/yuezk/GlobalProtect-openconnect/releases/download/v3.7.1/globalprotect-openconnect-3.7.1-r1-x86_64.apk) or [ARM64](https://github.com/yuezk/GlobalProtect-openconnect/releases/download/v3.7.1/globalprotect-openconnect-3.7.1-r1-aarch64.apk).
|
||||
|
||||
```bash
|
||||
sudo apk add --allow-untrusted globalprotect-openconnect-*.apk
|
||||
@@ -92,7 +92,7 @@ sudo apt-get install globalprotect-openconnect
|
||||
|
||||
#### Debian or Ubuntu release package
|
||||
|
||||
Download the DEB for [amd64](https://github.com/yuezk/GlobalProtect-openconnect/releases/download/v3.7.0/globalprotect-openconnect_3.7.0-1_amd64.deb) or [arm64](https://github.com/yuezk/GlobalProtect-openconnect/releases/download/v3.7.0/globalprotect-openconnect_3.7.0-1_arm64.deb).
|
||||
Download the DEB for [amd64](https://github.com/yuezk/GlobalProtect-openconnect/releases/download/v3.7.1/globalprotect-openconnect_3.7.1-1_amd64.deb) or [arm64](https://github.com/yuezk/GlobalProtect-openconnect/releases/download/v3.7.1/globalprotect-openconnect_3.7.1-1_arm64.deb).
|
||||
|
||||
```bash
|
||||
sudo apt install ./globalprotect-openconnect_*.deb
|
||||
@@ -160,17 +160,17 @@ Packages are available on the [openSUSE Build Service](https://build.opensuse.or
|
||||
|
||||
### Other Distributions
|
||||
|
||||
Download the archive for [x86_64](https://github.com/yuezk/GlobalProtect-openconnect/releases/download/v3.7.0/globalprotect-openconnect_3.7.0_x86_64.bin.tar.xz) or [ARM64](https://github.com/yuezk/GlobalProtect-openconnect/releases/download/v3.7.0/globalprotect-openconnect_3.7.0_aarch64.bin.tar.xz).
|
||||
Download the archive for [x86_64](https://github.com/yuezk/GlobalProtect-openconnect/releases/download/v3.7.1/globalprotect-openconnect_3.7.1_x86_64.bin.tar.xz) or [ARM64](https://github.com/yuezk/GlobalProtect-openconnect/releases/download/v3.7.1/globalprotect-openconnect_3.7.1_aarch64.bin.tar.xz).
|
||||
|
||||
```bash
|
||||
tar -xJf globalprotect-openconnect_*.bin.tar.xz
|
||||
cd globalprotect-openconnect_3.7.0
|
||||
cd globalprotect-openconnect_3.7.1
|
||||
sudo make install
|
||||
```
|
||||
|
||||
### FreeBSD
|
||||
|
||||
Download the [FreeBSD package for amd64](https://github.com/yuezk/GlobalProtect-openconnect/releases/download/v3.7.0/globalprotect-openconnect-3.7.0-freebsd-amd64.pkg).
|
||||
Download the [FreeBSD package for amd64](https://github.com/yuezk/GlobalProtect-openconnect/releases/download/v3.7.1/globalprotect-openconnect-3.7.1-freebsd-amd64.pkg).
|
||||
|
||||
```bash
|
||||
sudo pkg install ./globalprotect-openconnect-*-freebsd-*.pkg
|
||||
@@ -178,7 +178,7 @@ sudo pkg install ./globalprotect-openconnect-*-freebsd-*.pkg
|
||||
|
||||
### OpenBSD
|
||||
|
||||
Download the [OpenBSD package for amd64](https://github.com/yuezk/GlobalProtect-openconnect/releases/download/v3.7.0/globalprotect-openconnect-3.7.0-openbsd-amd64.tgz).
|
||||
Download the [OpenBSD package for amd64](https://github.com/yuezk/GlobalProtect-openconnect/releases/download/v3.7.1/globalprotect-openconnect-3.7.1-openbsd-amd64.tgz).
|
||||
|
||||
```bash
|
||||
doas pkg_add -D unsigned ./globalprotect-openconnect-*-openbsd-*.tgz
|
||||
|
||||
@@ -127,7 +127,9 @@ pub fn command_path(require_root: bool) -> io::Result<std::ffi::OsString> {
|
||||
std::env::join_paths(directories).map_err(|error| io::Error::new(io::ErrorKind::InvalidInput, error))
|
||||
}
|
||||
|
||||
fn root_owned_path(path: &Path) -> bool {
|
||||
/// Whether `path` and every ancestor are root-owned, not symlinks, and not
|
||||
/// group/world-writable (unless a root-owned sticky ancestor protects them).
|
||||
pub fn root_owned_path(path: &Path) -> bool {
|
||||
path.ancestors().all(|part| {
|
||||
fs::symlink_metadata(part).is_ok_and(|metadata| {
|
||||
let mode = metadata.permissions().mode();
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
use std::{fs, io, path::Path};
|
||||
|
||||
use gpapi::process::collection::{CollectorCommands, root_owned_path};
|
||||
use serde::Deserialize;
|
||||
|
||||
use super::BitdefenderInfo;
|
||||
|
||||
const BITDEFENDER_DIR: &str = "/opt/bitdefender-security-tools";
|
||||
const MAX_VERSION_LEN: usize = 64;
|
||||
|
||||
pub(super) fn detect(commands: &CollectorCommands<'_>) -> io::Result<Option<BitdefenderInfo>> {
|
||||
let dir = Path::new(BITDEFENDER_DIR);
|
||||
if uzers::get_effective_uid() == 0 {
|
||||
let cli = dir.join("bin/bduitool");
|
||||
let status = commands
|
||||
.run_executable(&cli, &["get", "ps"])?
|
||||
.filter(|output| output.status.success())
|
||||
.and_then(|output| String::from_utf8(output.stdout).ok())
|
||||
.as_deref()
|
||||
.and_then(parse_product_status);
|
||||
if status.is_some() {
|
||||
return Ok(status);
|
||||
}
|
||||
}
|
||||
|
||||
let Ok(manifest) = dir.join("etc/manifest.json").canonicalize() else {
|
||||
return Ok(None);
|
||||
};
|
||||
if !manifest.is_file() || !root_owned_path(&manifest) {
|
||||
return Ok(None);
|
||||
}
|
||||
let Ok(contents) = fs::read_to_string(&manifest) else {
|
||||
return Ok(None);
|
||||
};
|
||||
Ok(parse_manifest(&contents).map(|version| BitdefenderInfo {
|
||||
version,
|
||||
engine_version: None,
|
||||
real_time_protection: None,
|
||||
}))
|
||||
}
|
||||
|
||||
/// Parse `bduitool get ps`. All three fields must be present for a full entry.
|
||||
fn parse_product_status(output: &str) -> Option<BitdefenderInfo> {
|
||||
let version = product_version(value(output, "Product version:")?)?;
|
||||
let engine_version = value(output, "Engines version:")
|
||||
.filter(|version| valid_version(version))?
|
||||
.to_string();
|
||||
let real_time_protection = match value(output, "Antimalware status:")? {
|
||||
"On" => true,
|
||||
"Off" => false,
|
||||
_ => return None,
|
||||
};
|
||||
Some(BitdefenderInfo {
|
||||
version,
|
||||
engine_version: Some(engine_version),
|
||||
real_time_protection: Some(real_time_protection),
|
||||
})
|
||||
}
|
||||
|
||||
fn parse_manifest(contents: &str) -> Option<String> {
|
||||
#[derive(Deserialize)]
|
||||
struct Manifest {
|
||||
version: String,
|
||||
}
|
||||
let manifest: Manifest = serde_json::from_str(contents).ok()?;
|
||||
product_version(&manifest.version)
|
||||
}
|
||||
|
||||
/// The official client reports only the first three components, e.g. `7.10.0`.
|
||||
fn product_version(version: &str) -> Option<String> {
|
||||
if !valid_version(version) {
|
||||
return None;
|
||||
}
|
||||
let short = version.split('.').take(3).collect::<Vec<_>>().join(".");
|
||||
Some(short)
|
||||
}
|
||||
|
||||
fn valid_version(version: &str) -> bool {
|
||||
!version.is_empty()
|
||||
&& version.len() <= MAX_VERSION_LEN
|
||||
&& version.chars().all(|ch| ch.is_ascii_digit() || ch == '.')
|
||||
&& version.split('.').all(|part| !part.is_empty())
|
||||
}
|
||||
|
||||
fn value<'a>(output: &'a str, label: &str) -> Option<&'a str> {
|
||||
output.lines().find_map(|line| {
|
||||
let line = line.trim();
|
||||
let line = line.strip_prefix("- ").unwrap_or(line);
|
||||
line.strip_prefix(label).map(str::trim)
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
const OBSERVED: &str = "\nProduct version: 7.10.0.200346\nLast product update: 2026-11-21 at 14:42:06 GMT\n\
|
||||
New product update available: no\nEngines version: 7.101851\nLast security content update: 2026-11-21 at 13:42:12 GMT\n\
|
||||
Features:\n - Antimalware status: On\n - AntiExploit status: On\n - On-Access YARA status: Off\n";
|
||||
|
||||
#[test]
|
||||
fn parses_observed_product_status() {
|
||||
let info = parse_product_status(OBSERVED).expect("observed output should parse");
|
||||
assert_eq!(info.version, "7.10.0");
|
||||
assert_eq!(info.engine_version.as_deref(), Some("7.101851"));
|
||||
assert_eq!(info.real_time_protection, Some(true));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn antimalware_off_reports_no_real_time_protection() {
|
||||
let output = OBSERVED.replace("Antimalware status: On", "Antimalware status: Off");
|
||||
assert_eq!(parse_product_status(&output).unwrap().real_time_protection, Some(false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn incomplete_product_status_is_rejected() {
|
||||
assert!(parse_product_status(&OBSERVED.replace("Engines version: 7.101851\n", "")).is_none());
|
||||
assert!(parse_product_status(&OBSERVED.replace(" - Antimalware status: On\n", "")).is_none());
|
||||
assert!(parse_product_status(&OBSERVED.replace("Antimalware status: On", "Antimalware status: Unknown")).is_none());
|
||||
assert!(
|
||||
parse_product_status(&OBSERVED.replace("Engines version: 7.101851", "Engines version: 7.101851\"/>")).is_none()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn truncates_product_version_to_three_components() {
|
||||
assert_eq!(product_version("7.10.0.200346").as_deref(), Some("7.10.0"));
|
||||
assert_eq!(product_version("7.10.0").as_deref(), Some("7.10.0"));
|
||||
assert_eq!(product_version("7.10").as_deref(), Some("7.10"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_invalid_versions() {
|
||||
assert_eq!(product_version(""), None);
|
||||
assert_eq!(product_version("7.10.0\"/>"), None);
|
||||
assert_eq!(product_version(&"1".repeat(65)), None);
|
||||
assert_eq!(product_version("7..10"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_manifest_version() {
|
||||
assert_eq!(
|
||||
parse_manifest(r#"{"version":"7.10.0.200346","changeset":"e95aa9d9"}"#).as_deref(),
|
||||
Some("7.10.0")
|
||||
);
|
||||
assert_eq!(parse_manifest("not json"), None);
|
||||
assert_eq!(parse_manifest(r#"{"changeset":"e95aa9d9"}"#), None);
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,8 @@ use gpapi::collection::{CollectionBudget, CollectionControl};
|
||||
use gpapi::process::collection::CollectorCommands;
|
||||
use xmltree::Element;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
mod bitdefender_unix;
|
||||
#[cfg(target_os = "macos")]
|
||||
mod domain_macos;
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd", test))]
|
||||
@@ -355,6 +357,15 @@ struct ClamAvInfo {
|
||||
real_time_protection: bool,
|
||||
}
|
||||
|
||||
/// Bitdefender Endpoint Security Tools (GravityZone). Engine and real-time
|
||||
/// protection are only available when `bduitool` can run as root.
|
||||
#[cfg_attr(not(target_os = "linux"), allow(dead_code))]
|
||||
struct BitdefenderInfo {
|
||||
version: String,
|
||||
engine_version: Option<String>,
|
||||
real_time_protection: Option<bool>,
|
||||
}
|
||||
|
||||
struct SentinelInfo {
|
||||
version: String,
|
||||
real_time_protection: bool,
|
||||
@@ -378,6 +389,7 @@ struct HostInfo {
|
||||
defender: Option<DefenderInfo>,
|
||||
clamav: Option<ClamAvInfo>,
|
||||
sentinel: Option<SentinelInfo>,
|
||||
bitdefender: Option<BitdefenderInfo>,
|
||||
ufw: Option<UfwInfo>,
|
||||
windows_categories: Option<String>,
|
||||
windows_updates: Option<gpapi::hip::WindowsUpdateStatus>,
|
||||
@@ -503,6 +515,7 @@ impl<'p, 'a> HostInfoCollector<'p, 'a> {
|
||||
defender: None,
|
||||
clamav: None,
|
||||
sentinel: None,
|
||||
bitdefender: None,
|
||||
ufw: None,
|
||||
windows_categories: None,
|
||||
windows_updates: None,
|
||||
@@ -585,6 +598,10 @@ impl<'p, 'a> HostInfoCollector<'p, 'a> {
|
||||
if self.profile.client_os() == ClientOs::Linux && self.profile.is_native() {
|
||||
info.sentinel = sentinel_unix::detect(&commands)?;
|
||||
}
|
||||
#[cfg(target_os = "linux")]
|
||||
if self.profile.client_os() == ClientOs::Linux && self.profile.is_native() {
|
||||
info.bitdefender = bitdefender_unix::detect(&commands)?;
|
||||
}
|
||||
control.check()?;
|
||||
Ok(info)
|
||||
}
|
||||
@@ -1225,6 +1242,86 @@ mod tests {
|
||||
assert_eq!(report.matches("name=\"Sentinel Agent\"").count(), 1);
|
||||
}
|
||||
|
||||
fn render_linux_report_with_bitdefender(bitdefender: Option<BitdefenderInfo>) -> String {
|
||||
let input = make_input(make_profile(ClientOs::Linux));
|
||||
let cookie_params = HashMap::new();
|
||||
let mut host_info = HostInfoCollector::new(&input.profile, &input, &cookie_params)
|
||||
.collect_identity(&CollectionBudget::new(Duration::from_secs(10)))
|
||||
.unwrap();
|
||||
host_info.bitdefender = bitdefender;
|
||||
let (generate_time, day, month, year) = get_current_time_components();
|
||||
let report = HipReportTemplate {
|
||||
client_version: input.profile.client_version(),
|
||||
generate_time,
|
||||
day,
|
||||
month,
|
||||
year,
|
||||
user_name: "test-user",
|
||||
host_info,
|
||||
md5: "test-digest",
|
||||
}
|
||||
.render()
|
||||
.unwrap();
|
||||
let report = format_xml(&report).unwrap();
|
||||
validate_edited_report(&report).unwrap();
|
||||
report
|
||||
}
|
||||
|
||||
fn bitdefender_product_info(report: &str) -> &str {
|
||||
let start = report
|
||||
.find("name=\"Bitdefender Endpoint Security Tools\"")
|
||||
.expect("Bitdefender entry should render");
|
||||
let end = start + report[start..].find("</ProductInfo>").unwrap();
|
||||
&report[start..end]
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn linux_report_renders_full_bitdefender_entry() {
|
||||
let report = render_linux_report_with_bitdefender(Some(BitdefenderInfo {
|
||||
version: "7.10.0".to_string(),
|
||||
engine_version: Some("7.101851".to_string()),
|
||||
real_time_protection: Some(true),
|
||||
}));
|
||||
assert!(report.contains(
|
||||
"vendor=\"Bitdefender\" name=\"Bitdefender Endpoint Security Tools\" version=\"7.10.0\" defver=\"7.101851\" engver=\"7.101851\""
|
||||
));
|
||||
let entry = bitdefender_product_info(&report);
|
||||
assert!(entry.contains("prodType=\"3\" osType=\"1\""));
|
||||
assert!(entry.contains("<real-time-protection>yes</real-time-protection>"));
|
||||
assert!(entry.contains("<last-full-scan-time>n/a</last-full-scan-time>"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn linux_report_renders_bitdefender_real_time_protection_off() {
|
||||
let report = render_linux_report_with_bitdefender(Some(BitdefenderInfo {
|
||||
version: "7.10.0".to_string(),
|
||||
engine_version: Some("7.101851".to_string()),
|
||||
real_time_protection: Some(false),
|
||||
}));
|
||||
assert!(bitdefender_product_info(&report).contains("<real-time-protection>no</real-time-protection>"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn linux_report_renders_partial_bitdefender_entry() {
|
||||
let report = render_linux_report_with_bitdefender(Some(BitdefenderInfo {
|
||||
version: "7.10.0".to_string(),
|
||||
engine_version: None,
|
||||
real_time_protection: None,
|
||||
}));
|
||||
let entry = bitdefender_product_info(&report);
|
||||
assert!(entry.contains("version=\"7.10.0\""));
|
||||
assert!(!entry.contains("defver="));
|
||||
assert!(!entry.contains("engver="));
|
||||
assert!(!entry.contains("real-time-protection"));
|
||||
assert!(entry.contains("<last-full-scan-time>n/a</last-full-scan-time>"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn linux_report_omits_absent_bitdefender() {
|
||||
let report = render_linux_report_with_bitdefender(None);
|
||||
assert!(!report.contains("Bitdefender"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn preview_uses_explicit_pending_digest() {
|
||||
let input = ReportInput {
|
||||
|
||||
@@ -174,6 +174,17 @@
|
||||
</ProductInfo>
|
||||
</entry>
|
||||
{% endif -%}
|
||||
{% if let Some(bitdefender) = &host_info.bitdefender %}
|
||||
<entry>
|
||||
<ProductInfo>
|
||||
<Prod vendor="Bitdefender" name="Bitdefender Endpoint Security Tools" version="{{ bitdefender.version }}"{% if let Some(engine_version) = &bitdefender.engine_version %} defver="{{ engine_version }}" engver="{{ engine_version }}"{% endif %} datemon="{{ month }}" dateday="{{ day }}" dateyear="{{ year }}" prodType="3" osType="1"/>
|
||||
{% if let Some(real_time_protection) = bitdefender.real_time_protection -%}
|
||||
<real-time-protection>{% if real_time_protection %}yes{% else %}no{% endif %}</real-time-protection>
|
||||
{% endif -%}
|
||||
<last-full-scan-time>n/a</last-full-scan-time>
|
||||
</ProductInfo>
|
||||
</entry>
|
||||
{% endif -%}
|
||||
</list>
|
||||
</entry>
|
||||
<entry name="disk-backup">
|
||||
|
||||
@@ -19,9 +19,49 @@ struct Snapshot {
|
||||
domain: String,
|
||||
search: String,
|
||||
}
|
||||
struct AdapterServers {
|
||||
ipv6: bool,
|
||||
addresses: String,
|
||||
}
|
||||
|
||||
impl AdapterServers {
|
||||
fn capture(guid: GUID, ipv6: bool) -> io::Result<Self> {
|
||||
// Save the static override only. Restoring an effective DHCP resolver as a
|
||||
// static address would leave the adapter in manual mode after disconnect.
|
||||
let service = if ipv6 { "Tcpip6" } else { "Tcpip" };
|
||||
let id = uuid::Uuid::from_fields(guid.data1, guid.data2, guid.data3, &guid.data4);
|
||||
let path = format!(
|
||||
r"SYSTEM\CurrentControlSet\Services\{service}\Parameters\Interfaces\{}",
|
||||
id.braced()
|
||||
);
|
||||
let addresses = winreg::RegKey::predef(winreg::enums::HKEY_LOCAL_MACHINE)
|
||||
.open_subkey(path)
|
||||
.and_then(|key| key.get_value("NameServer"));
|
||||
let addresses = match addresses {
|
||||
Ok(value) => value,
|
||||
Err(error) if error.kind() == io::ErrorKind::NotFound => String::new(),
|
||||
Err(error) => return Err(error),
|
||||
};
|
||||
Ok(Self { ipv6, addresses })
|
||||
}
|
||||
|
||||
fn write(&self, guid: GUID) -> io::Result<()> {
|
||||
let mut servers = wide(&self.addresses);
|
||||
let family = if self.ipv6 { DNS_SETTING_IPV6 } else { 0 };
|
||||
let settings = DNS_INTERFACE_SETTINGS {
|
||||
Version: DNS_INTERFACE_SETTINGS_VERSION1,
|
||||
Flags: (DNS_SETTING_NAMESERVER | family) as u64,
|
||||
NameServer: servers.as_mut_ptr(),
|
||||
..Default::default()
|
||||
};
|
||||
check(unsafe { SetInterfaceDnsSettings(guid, &settings) })
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct Installed {
|
||||
guid: GUID,
|
||||
snapshot: Option<Snapshot>,
|
||||
previous_servers: Vec<AdapterServers>,
|
||||
tag: Option<String>,
|
||||
tunnel: Option<SystemTunnel>,
|
||||
}
|
||||
@@ -86,6 +126,7 @@ impl Installed {
|
||||
let mut installed = Self {
|
||||
guid,
|
||||
snapshot: Some(Snapshot::capture(guid)?),
|
||||
previous_servers: Vec::new(),
|
||||
tag: None,
|
||||
tunnel: tunnel.cloned(),
|
||||
};
|
||||
@@ -94,9 +135,28 @@ impl Installed {
|
||||
search: configuration.domains.join(","),
|
||||
}
|
||||
.write(guid)?;
|
||||
// NRPT selects both IPv4 and IPv6 VPN resolvers. Split namespaces leave
|
||||
// unrelated DNS on the physical network; "." covers full-tunnel DNS.
|
||||
// Existing static/DHCP adapter nameserver configuration stays untouched.
|
||||
// With no split namespaces the VPN resolvers also belong on the adapter.
|
||||
// Windows may accept the local NRPT rule without making it effective.
|
||||
if configuration.split_dns.is_empty() {
|
||||
for ipv6 in [false, true] {
|
||||
let servers: Vec<_> = configuration
|
||||
.servers
|
||||
.iter()
|
||||
.filter(|ip| ip.is_ipv6() == ipv6)
|
||||
.map(ToString::to_string)
|
||||
.collect();
|
||||
if servers.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let previous = AdapterServers::capture(guid, ipv6)?;
|
||||
AdapterServers {
|
||||
ipv6,
|
||||
addresses: servers.join(","),
|
||||
}
|
||||
.write(guid)?;
|
||||
installed.previous_servers.push(previous);
|
||||
}
|
||||
}
|
||||
if !configuration.servers.is_empty() {
|
||||
let namespaces: Vec<String> = if configuration.split_dns.is_empty() {
|
||||
vec![".".into()]
|
||||
@@ -127,6 +187,12 @@ impl Installed {
|
||||
failure = Some(error);
|
||||
}
|
||||
}
|
||||
for previous in self.previous_servers.drain(..) {
|
||||
if let Err(error) = previous.write(self.guid) {
|
||||
log::warn!("Could not restore VPN adapter DNS servers: {error}");
|
||||
failure.get_or_insert(error);
|
||||
}
|
||||
}
|
||||
if let Some(snapshot) = self.snapshot.take() {
|
||||
if let Err(error) = snapshot.write(self.guid) {
|
||||
log::warn!("Could not restore VPN adapter DNS: {error}");
|
||||
|
||||
@@ -275,6 +275,94 @@ fn global_search_list() -> Vec<u8> {
|
||||
output.stdout
|
||||
}
|
||||
|
||||
/// Check what DNS clients see for this adapter independently of the NRPT rule.
|
||||
fn adapter_servers(index: u32) -> Vec<String> {
|
||||
let command = format!("(Get-DnsClientServerAddress -InterfaceIndex {index} -ErrorAction Stop).ServerAddresses");
|
||||
let output = std::process::Command::new("powershell.exe")
|
||||
.args(["-NoProfile", "-NonInteractive", "-Command", &command])
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(output.status.success(), "{}", String::from_utf8_lossy(&output.stderr));
|
||||
String::from_utf8(output.stdout)
|
||||
.unwrap()
|
||||
.lines()
|
||||
.map(str::to_owned)
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "requires an isolated Windows test host and signed Wintun"]
|
||||
fn lookup_without_an_nrpt_rule() -> Result<(), Box<dyn std::error::Error>> {
|
||||
use std::net::UdpSocket;
|
||||
let adapter = Adapter::create()?;
|
||||
let index = adapter.index;
|
||||
let run = |script: &str| {
|
||||
let out = std::process::Command::new("powershell.exe")
|
||||
.args(["-NoProfile","-NonInteractive","-Command",script]).output().unwrap();
|
||||
assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr));
|
||||
String::from_utf8(out.stdout).unwrap()
|
||||
};
|
||||
run(&format!("Set-DnsClientServerAddress -ErrorAction Stop -InterfaceIndex {index} -ServerAddresses ('198.18.0.99','fd42:1235::99')"));
|
||||
let baseline = adapter_servers(index);
|
||||
assert!(baseline.iter().any(|s| s == "fd42:1235::99"));
|
||||
let mut config = environment(index);
|
||||
config.retain(|(key,_)| key != "CISCO_SPLIT_DNS");
|
||||
config.iter_mut().find(|(key,_)| key=="INTERNAL_IP4_DNS").unwrap().1 = Some("192.0.2.2 198.18.0.53 fd42:1235::53".into());
|
||||
let key = format!(r"SOFTWARE\GP Connect\Tests\Network{}", uuid::Uuid::new_v4().simple());
|
||||
let mut net = NetworkConfigurator::new(&key)?;
|
||||
net.configure("connect",&config)?;
|
||||
run(&format!("$ErrorActionPreference='Stop'; Get-DnsClientNrptRule | Where-Object Comment -eq 'GPConnectJournal:{key}' | ForEach-Object {{ Remove-DnsClientNrptRule -Name $_.Name -Force }}; if (Get-DnsClientNrptPolicy -Effective | Where-Object {{ $_.Namespace -contains '.' }}) {{ throw 'Unexpected root rule' }}"));
|
||||
let socket = UdpSocket::bind("192.0.2.2:53")?;
|
||||
socket.set_read_timeout(Some(std::time::Duration::from_secs(20)))?;
|
||||
let server = std::thread::spawn(move || -> io::Result<()> {
|
||||
let mut buf = [0u8; 2048];
|
||||
let qname = b"\x0bsupport-dns\x04test\x00\x00\x01\x00\x01";
|
||||
loop {
|
||||
let (n,from) = socket.recv_from(&mut buf)?;
|
||||
if n < 12 + qname.len() || &buf[12..12+qname.len()] != qname { continue; }
|
||||
let mut answer = buf[..2].to_vec();
|
||||
answer.extend_from_slice(&[0x81,0x80,0,1,0,1,0,0,0,0]);
|
||||
answer.extend_from_slice(qname);
|
||||
answer.extend_from_slice(&[0xc0,0x0c,0,1,0,1,0,0,0,0,0,4,198,51,100,55]);
|
||||
socket.send_to(&answer,from)?;
|
||||
return Ok(());
|
||||
}
|
||||
});
|
||||
let result = run("(Resolve-DnsName support-dns.test. -Type A -DnsOnly -NoHostsFile -ErrorAction Stop).IPAddress");
|
||||
assert_eq!(result.trim(), "198.51.100.55");
|
||||
server.join().unwrap()?;
|
||||
net.configure("disconnect",&[])?;
|
||||
assert_eq!(adapter_servers(index),baseline);
|
||||
println!("PASS: Windows resolved the fixture hostname through adapter DNS with no effective catch-all rule and restored pre-existing static IPv4 and IPv6 settings");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn check_adapter_resolvers(index: u32, key: &str) -> io::Result<()> {
|
||||
let split = environment(index);
|
||||
let mut full = split.clone();
|
||||
full.retain(|(key, _)| key != "CISCO_SPLIT_DNS");
|
||||
let initial = adapter_servers(index);
|
||||
let mut network = NetworkConfigurator::new(key)?;
|
||||
network.configure("connect", &full)?;
|
||||
let servers = adapter_servers(index);
|
||||
assert!(servers.iter().any(|address| address == "198.18.0.53"));
|
||||
assert!(servers.iter().any(|address| address == "fd42:1235::53"));
|
||||
network.configure("reconnect", &split)?;
|
||||
assert_eq!(
|
||||
adapter_servers(index),
|
||||
initial,
|
||||
"split DNS must be scoped to its namespaces"
|
||||
);
|
||||
network.configure("reconnect", &full)?;
|
||||
network.configure("disconnect", &[])?;
|
||||
assert_eq!(
|
||||
adapter_servers(index),
|
||||
initial,
|
||||
"disconnect must restore the adapter DNS settings"
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "requires administrator privileges and GP_TEST_WINTUN_DLL"]
|
||||
fn installs_and_restores_native_network_configuration() -> Result<(), Box<dyn std::error::Error>> {
|
||||
@@ -355,6 +443,7 @@ fn installs_and_restores_native_network_configuration() -> Result<(), Box<dyn st
|
||||
);
|
||||
assert_eq!(before, state(index), "Failed connection left a physical gateway route");
|
||||
println!("PASS: partial setup failure rolled back its physical gateway route");
|
||||
check_adapter_resolvers(index, &recovery_key)?;
|
||||
drop(adapter);
|
||||
assert_crash_recovery(&recovery_key)?;
|
||||
assert_eq!(global_search_list(), original_search_list);
|
||||
|
||||
Submodule crates/openconnect/deps/openconnect updated: 80b4f80926...d5094312d2.
Generated
+3
-3
@@ -63,11 +63,11 @@
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1795095985,
|
||||
"narHash": "sha256-DOTZsOOoEtOY0ysY9L6JzyDHZm4lGBr6P1bt1mFXcRw=",
|
||||
"lastModified": 1795217999,
|
||||
"narHash": "sha256-Z5mAFcY8XTAaWe+RwTchz4Fx1gwaeQ2WD8A8bKX7njY=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "19cfded70b91ca0981373973c5b1efffdd4d6647",
|
||||
"rev": "680275f0bb6afce84fbac3e75fc47c5f2272400b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
||||
@@ -29,8 +29,8 @@
|
||||
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
|
||||
pname = "globalprotect-openconnect";
|
||||
version = cargoToml.workspace.package.version;
|
||||
releaseTag = "v3.7.0";
|
||||
releaseVersion = "3.7.0";
|
||||
releaseTag = "v3.7.1";
|
||||
releaseVersion = "3.7.1";
|
||||
|
||||
toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
|
||||
|
||||
@@ -55,8 +55,8 @@
|
||||
cpu = pkgs.stdenv.hostPlatform.parsed.cpu.name;
|
||||
|
||||
gpguiHashes = {
|
||||
x86_64 = "sha256-eIvocMn4j+CiA1FMuib1/BvMEw4kcO5h4zAhbSHXFf0=";
|
||||
aarch64 = "sha256-pBH7KccAAnxLcCD5+wJxEAwpdu+QRHHncrytwoBgzh4=";
|
||||
x86_64 = "sha256-mY5w91CZp1W70Pjd8lRtxMuON3b6PRLcmWuE4AMd4/s=";
|
||||
aarch64 = "sha256-Xm6QzVFsFJ3JlrHPCiBlJMgpD/5xZT65q/qZVajw4bQ=";
|
||||
};
|
||||
|
||||
gpguiArchive = pkgs.fetchurl {
|
||||
@@ -70,8 +70,8 @@
|
||||
};
|
||||
|
||||
nshHashes = {
|
||||
x86_64 = "sha256-STlK1Wtx840a0TtIgxXJDINnVmfiedSNVcapGF154dY=";
|
||||
aarch64 = "sha256-HekBfUrlRavNzA+1g6EvxN4iiGDevEv0stsVEyL6Ejk=";
|
||||
x86_64 = "sha256-qqOtWnR20tDu0n4wRmsxPqjOVR+o8gf8fGWSwZXg/So=";
|
||||
aarch64 = "sha256-GnVauyUobwocDb6LOzdLDeurttpVB6axHracYorTk+Q=";
|
||||
};
|
||||
|
||||
nshArchive = pkgs.fetchurl {
|
||||
@@ -94,8 +94,8 @@
|
||||
'';
|
||||
|
||||
binaryHashes = {
|
||||
x86_64 = "sha256-1YFxjH6+garb/bneZRqVHAOfPQGBEvWaruAk573bZhc=";
|
||||
aarch64 = "sha256-RnXdAcS2UWKwhWtlGSLs8fM4u2iRLx0w6SR42sOX9yk=";
|
||||
x86_64 = "sha256-hP6xdkjblFDqfkHgl8u34vo75Vd0vv7L1Ua+hpqJBC4=";
|
||||
aarch64 = "sha256-czpKkEs0DPQeghSyCaZ6xayRpLBPcWxAicay4qU8PdE=";
|
||||
};
|
||||
|
||||
binaryArchive = pkgs.fetchurl {
|
||||
|
||||
Reference in new issue
Block a user