summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2018-03-07 00:49:53 -0300
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2018-03-09 10:44:48 -0300
commit0416815cd6f2e33ba8626869442e6a856e5529a1 (patch)
treef1a4e6479c54d8f14ff92da8e5eb3390765eff30
parentdeefd4c50fe7e9eeab0c024bc2bfba9ae0c485b8 (diff)
downloadmullvadvpn-0416815cd6f2e33ba8626869442e6a856e5529a1.tar.xz
mullvadvpn-0416815cd6f2e33ba8626869442e6a856e5529a1.zip
Halt on failure of removal of existing RPC file
-rw-r--r--mullvad-daemon/src/rpc_info.rs17
1 files changed, 13 insertions, 4 deletions
diff --git a/mullvad-daemon/src/rpc_info.rs b/mullvad-daemon/src/rpc_info.rs
index 71c551d0db..e4df5ee184 100644
--- a/mullvad-daemon/src/rpc_info.rs
+++ b/mullvad-daemon/src/rpc_info.rs
@@ -44,8 +44,8 @@ pub fn is_another_instance_running() -> bool {
/// Writes down the RPC connection info to some API to a file.
pub fn write(rpc_address: &str, shared_secret: &str) -> Result<()> {
- // Remove any existent RPC address file first
- let _ = remove();
+ // Avoids opening an existing file owned by another user and writing sensitive data to it.
+ remove()?;
open_file(RPC_ADDRESS_FILE_PATH.as_path())
.and_then(|mut file| write!(file, "{}\n{}\n", rpc_address, shared_secret))
@@ -58,9 +58,18 @@ pub fn write(rpc_address: &str, shared_secret: &str) -> Result<()> {
Ok(())
}
+/// Removes the RPC file, if it exists.
pub fn remove() -> Result<()> {
- fs::remove_file(RPC_ADDRESS_FILE_PATH.as_path())
- .chain_err(|| ErrorKind::RemoveFailed(RPC_ADDRESS_FILE_PATH.to_owned()))
+ if let Err(error) = fs::remove_file(RPC_ADDRESS_FILE_PATH.as_path()) {
+ if error.kind() == io::ErrorKind::NotFound {
+ // No previously existing file
+ Ok(())
+ } else {
+ Err(error).chain_err(|| ErrorKind::RemoveFailed(RPC_ADDRESS_FILE_PATH.to_owned()))
+ }
+ } else {
+ Ok(())
+ }
}
fn other_daemon_responds() -> bool {