summaryrefslogtreecommitdiffhomepage
path: root/mullvad-cli/src
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2017-10-18 17:35:00 +0200
committerLinus Färnstrand <linus@mullvad.net>2017-10-18 17:35:00 +0200
commitb92ef2951393555009fcfe4030a62979bdbcbdac (patch)
tree147190e526692251e066baecf5f3a59391b14fd8 /mullvad-cli/src
parentd7a0a68987223f994b6cb30fad79b9454d99def7 (diff)
parente1f41bb918aedb3c4af06ad505e80bf28db99462 (diff)
downloadmullvadvpn-b92ef2951393555009fcfe4030a62979bdbcbdac.tar.xz
mullvadvpn-b92ef2951393555009fcfe4030a62979bdbcbdac.zip
Merge branch 'add-shutdown-rpc-method'
Diffstat (limited to 'mullvad-cli/src')
-rw-r--r--mullvad-cli/src/cmds/mod.rs4
-rw-r--r--mullvad-cli/src/cmds/shutdown.rs20
-rw-r--r--mullvad-cli/src/rpc.rs15
3 files changed, 33 insertions, 6 deletions
diff --git a/mullvad-cli/src/cmds/mod.rs b/mullvad-cli/src/cmds/mod.rs
index 8061344b96..0104185543 100644
--- a/mullvad-cli/src/cmds/mod.rs
+++ b/mullvad-cli/src/cmds/mod.rs
@@ -16,6 +16,9 @@ pub use self::disconnect::Disconnect;
mod custom_relay;
pub use self::custom_relay::CustomRelay;
+mod shutdown;
+pub use self::shutdown::Shutdown;
+
/// Returns a map of all available subcommands with their name as key.
pub fn get_commands() -> HashMap<&'static str, Box<Command>> {
let commands: Vec<Box<Command>> = vec![
@@ -24,6 +27,7 @@ pub fn get_commands() -> HashMap<&'static str, Box<Command>> {
Box::new(Connect),
Box::new(Disconnect),
Box::new(CustomRelay),
+ Box::new(Shutdown),
];
let mut map = HashMap::new();
for cmd in commands {
diff --git a/mullvad-cli/src/cmds/shutdown.rs b/mullvad-cli/src/cmds/shutdown.rs
new file mode 100644
index 0000000000..4a334da5a5
--- /dev/null
+++ b/mullvad-cli/src/cmds/shutdown.rs
@@ -0,0 +1,20 @@
+use {Command, Result};
+use clap;
+
+use rpc;
+
+pub struct Shutdown;
+
+impl Command for Shutdown {
+ fn name(&self) -> &'static str {
+ "shutdown"
+ }
+
+ fn clap_subcommand(&self) -> clap::App<'static, 'static> {
+ clap::SubCommand::with_name(self.name()).about("Makes the backend daemon quit")
+ }
+
+ fn run(&self, _matches: &clap::ArgMatches) -> Result<()> {
+ rpc::call("shutdown", &[] as &[u8; 0])
+ }
+}
diff --git a/mullvad-cli/src/rpc.rs b/mullvad-cli/src/rpc.rs
index 16a23bda94..5e14cdf195 100644
--- a/mullvad-cli/src/rpc.rs
+++ b/mullvad-cli/src/rpc.rs
@@ -2,7 +2,7 @@ use {Result, ResultExt};
use serde;
use std::fs::{File, Metadata};
-use std::io::{self, Read};
+use std::io::{self, BufRead, BufReader};
use std::path::{Path, PathBuf};
use talpid_ipc::WsIpcClient;
@@ -20,7 +20,7 @@ where
T: serde::Serialize,
O: for<'de> serde::Deserialize<'de>,
{
- let address = read_rpc_address().chain_err(|| "Unable to read RPC address")?;
+ let (address, _shared_secret) = read_rpc_address().chain_err(|| "Unable to read RPC address")?;
info!("Using RPC address {}", address);
let mut rpc_client = WsIpcClient::new(address).chain_err(|| "Unable to create RPC client")?;
rpc_client
@@ -41,16 +41,19 @@ lazy_static! {
static ref RPC_ADDRESS_FILE_PATH: PathBuf = ::std::env::temp_dir().join(".mullvad_rpc_address");
}
-fn read_rpc_address() -> io::Result<String> {
+fn read_rpc_address() -> io::Result<(String, String)> {
debug!(
"Trying to read RPC address at {}",
RPC_ADDRESS_FILE_PATH.to_string_lossy()
);
- let mut file = File::open(&*RPC_ADDRESS_FILE_PATH)?;
+ let file = File::open(&*RPC_ADDRESS_FILE_PATH)?;
if is_rpc_file_trusted(file.metadata()?) {
+ let mut buf_file = BufReader::new(file);
let mut address = String::new();
- file.read_to_string(&mut address)?;
- Ok(address)
+ buf_file.read_line(&mut address)?;
+ let mut shared_secret = String::new();
+ buf_file.read_line(&mut shared_secret)?;
+ Ok((address, shared_secret))
} else {
Err(io::Error::new(
io::ErrorKind::Other,