summaryrefslogtreecommitdiffhomepage
path: root/mullvad-cli/src
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2022-06-07 15:16:31 +0200
committerDavid Lönnhager <david.l@mullvad.net>2022-06-14 13:59:49 +0200
commitf3acffca0c5da48c854658a19d11eed4104036b0 (patch)
tree8ca38b0a72ebc231b891c244faf52ebb11f9899f /mullvad-cli/src
parent463042e83845efd09f61cd99feb65db58240bb32 (diff)
downloadmullvadvpn-f3acffca0c5da48c854658a19d11eed4104036b0.tar.xz
mullvadvpn-f3acffca0c5da48c854658a19d11eed4104036b0.zip
Track excluded processes and add CLI command for listing them on Windows
Diffstat (limited to 'mullvad-cli/src')
-rw-r--r--mullvad-cli/src/cmds/split_tunnel/windows.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/mullvad-cli/src/cmds/split_tunnel/windows.rs b/mullvad-cli/src/cmds/split_tunnel/windows.rs
index 0bc8d468bc..9766607ce1 100644
--- a/mullvad-cli/src/cmds/split_tunnel/windows.rs
+++ b/mullvad-cli/src/cmds/split_tunnel/windows.rs
@@ -1,3 +1,5 @@
+use std::{ffi::OsStr, path::Path};
+
use crate::{new_rpc_client, Command, Result};
pub struct SplitTunnel;
@@ -23,11 +25,13 @@ impl Command for SplitTunnel {
),
)
.subcommand(clap::App::new("get").about("Display the split tunnel status"))
+ .subcommand(create_pid_subcommand())
}
async fn run(&self, matches: &clap::ArgMatches) -> Result<()> {
match matches.subcommand() {
Some(("app", matches)) => Self::handle_app_subcommand(matches).await,
+ Some(("pid", matches)) => Self::handle_pid_subcommand(matches).await,
Some(("get", _)) => self.get().await,
Some(("set", matches)) => {
let enabled = matches.value_of("policy").expect("missing policy");
@@ -50,6 +54,16 @@ fn create_app_subcommand() -> clap::App<'static> {
.subcommand(clap::App::new("clear"))
}
+fn create_pid_subcommand() -> clap::App<'static> {
+ clap::App::new("pid")
+ .about("Manages processes (PIDs) excluded from the tunnel")
+ .setting(clap::AppSettings::SubcommandRequiredElseHelp)
+ .subcommand(clap::App::new("list")
+ .about("List processes that are currently being excluded, i.e. their PIDs, as well as whether \
+ they are excluded because of their executable paths or because they're subprocesses of \
+ such processes"))
+}
+
impl SplitTunnel {
async fn handle_app_subcommand(matches: &clap::ArgMatches) -> Result<()> {
match matches.subcommand() {
@@ -91,6 +105,33 @@ impl SplitTunnel {
}
}
+ async fn handle_pid_subcommand(matches: &clap::ArgMatches) -> Result<()> {
+ match matches.subcommand() {
+ Some(("list", _)) => {
+ let processes = new_rpc_client()
+ .await?
+ .get_excluded_processes(())
+ .await?
+ .into_inner();
+
+ for process in &processes.processes {
+ let subproc = if process.inherited { "subprocess" } else { "" };
+ println!(
+ "{:<7}{subproc:<12}{}",
+ process.pid,
+ Path::new(&process.image)
+ .file_name()
+ .unwrap_or(OsStr::new("unknown"))
+ .to_string_lossy()
+ );
+ }
+
+ Ok(())
+ }
+ _ => unreachable!("unhandled subcommand"),
+ }
+ }
+
async fn set(&self, enabled: bool) -> Result<()> {
let mut rpc = new_rpc_client().await?;
rpc.set_split_tunnel_state(enabled).await?;