mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-17 13:46:27 -05:00
feat(gpclient): add --cookie-only to print gateway cookie without starting tunnel (#647)
Co-authored-by: Maksym Shaiev <[email protected]>
This commit is contained in:
1 parent
3882e29b0e
commit
9e4f45997e
2 files changed
+38
No files matched your search
@@ -146,6 +146,14 @@ pub(crate) struct ConnectArgs {
|
||||
num_args=0..=1
|
||||
)]
|
||||
pub(super) browser: Option<String>,
|
||||
|
||||
#[arg(
|
||||
long,
|
||||
help = "Authenticate and print the gateway cookie to stdout, then exit without starting the \
|
||||
VPN tunnel. Outputs two lines: COOKIE='<value>' and HOST='<gateway>'. Combine with \
|
||||
--cookie-cache to avoid re-authenticating when the portal session is still valid."
|
||||
)]
|
||||
pub(super) cookie_only: bool,
|
||||
}
|
||||
|
||||
pub(super) fn build_os_profile(args: &ConnectArgs) -> OsProfile {
|
||||
@@ -398,4 +406,24 @@ mod tests {
|
||||
};
|
||||
assert_eq!(err.kind(), ErrorKind::ArgumentConflict);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cookie_only_flag_parses() {
|
||||
use clap::Parser;
|
||||
|
||||
let cli = ConnectArgsTestCli::try_parse_from(["test", "portal.example.com", "--cookie-only"])
|
||||
.expect("--cookie-only should parse");
|
||||
|
||||
assert!(cli.args.cookie_only);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cookie_only_is_disabled_by_default() {
|
||||
use clap::Parser;
|
||||
|
||||
let cli = ConnectArgsTestCli::try_parse_from(["test", "portal.example.com"])
|
||||
.expect("connect args should parse");
|
||||
|
||||
assert!(!cli.args.cookie_only);
|
||||
}
|
||||
}
|
||||
@@ -341,6 +341,16 @@ impl ConnectHandler<'_> {
|
||||
allow_extend_session: bool,
|
||||
extension_auth: SessionExtensionAuth,
|
||||
) -> Result<(), GatewayConnectError> {
|
||||
// --cookie-only: print the gateway cookie and exit without opening a tunnel.
|
||||
// No tun device is allocated, no root is required, and no logout is issued
|
||||
// against the gateway — the cookie remains valid for subsequent use.
|
||||
// Output format matches openconnect --authenticate for easy shell consumption.
|
||||
if self.args.cookie_only {
|
||||
println!("COOKIE='{}'", cookie);
|
||||
println!("HOST='{}'", gateway);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mtu = self.args.mtu.unwrap_or(0);
|
||||
let (hip, csd_wrapper) = self.determine_hip_script();
|
||||
let hip_user = self.determine_hip_user();
|
||||
|
||||
Reference in new issue
Block a user