Set Unix permissions on the state file

pull/5/head
Frank Denis 5 years ago
parent 00cab788b8
commit 93774a892f

@ -46,7 +46,7 @@ use privdrop::PrivDrop;
use rand::prelude::*;
use std::collections::vec_deque::VecDeque;
use std::convert::TryFrom;
use std::fs::File;
use std::fs::{File, OpenOptions};
use std::io::prelude::*;
use std::mem;
use std::net::{IpAddr, SocketAddr};
@ -61,6 +61,9 @@ use tokio::runtime::Runtime;
use tokio::sync::oneshot;
use tokio_net::driver::Handle;
#[cfg(unix)]
use std::os::unix::fs::OpenOptionsExt;
#[derive(Debug)]
struct UdpClientCtx {
net_udp_socket: std::net::UdpSocket,
@ -399,7 +402,13 @@ fn main() -> Result<(), Error> {
Err(_) => {
println!("No state file found... creating a new provider key");
let state = State::new();
let mut fp = File::create(state_file)?;
let mut fpb = OpenOptions::new();
let mut fpb = fpb.create(true).write(true);
#[cfg(unix)]
{
fpb = fpb.mode(0o600);
}
let mut fp = fpb.open(state_file)?;
let state_bin = toml::to_vec(&state)?;
fp.write_all(&state_bin)?;
state

Loading…
Cancel
Save