Set 600 perm mode to all created files
When creating a data file, set permissions to read/write for the user.jmap
parent
3e33335914
commit
af365fa8d4
|
@ -45,6 +45,7 @@ use std::fs;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
use std::io::{self, Read, Write};
|
use std::io::{self, Read, Write};
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
|
use std::os::unix::fs::PermissionsExt;
|
||||||
use std::path::{Component, Path, PathBuf};
|
use std::path::{Component, Path, PathBuf};
|
||||||
use std::result;
|
use std::result;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
@ -768,6 +769,12 @@ impl MaildirType {
|
||||||
panic!("{}", e);
|
panic!("{}", e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
let metadata = f.metadata().unwrap();
|
||||||
|
let mut permissions = metadata.permissions();
|
||||||
|
|
||||||
|
permissions.set_mode(0o600); // Read/write for owner only.
|
||||||
|
f.set_permissions(permissions).unwrap();
|
||||||
|
|
||||||
let writer = io::BufWriter::new(f);
|
let writer = io::BufWriter::new(f);
|
||||||
bincode::serialize_into(writer, &e).unwrap();
|
bincode::serialize_into(writer, &e).unwrap();
|
||||||
}
|
}
|
||||||
|
@ -860,6 +867,12 @@ impl MaildirType {
|
||||||
}
|
}
|
||||||
debug!("saving at {}", path.display());
|
debug!("saving at {}", path.display());
|
||||||
let file = fs::File::create(path).unwrap();
|
let file = fs::File::create(path).unwrap();
|
||||||
|
let metadata = file.metadata()?;
|
||||||
|
let mut permissions = metadata.permissions();
|
||||||
|
|
||||||
|
permissions.set_mode(0o600); // Read/write for owner only.
|
||||||
|
file.set_permissions(permissions)?;
|
||||||
|
|
||||||
let mut writer = io::BufWriter::new(file);
|
let mut writer = io::BufWriter::new(file);
|
||||||
writer.write_all(bytes).unwrap();
|
writer.write_all(bytes).unwrap();
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
@ -899,6 +912,11 @@ fn add_path_to_index(
|
||||||
panic!("{}", e);
|
panic!("{}", e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
let metadata = f.metadata().unwrap();
|
||||||
|
let mut permissions = metadata.permissions();
|
||||||
|
|
||||||
|
permissions.set_mode(0o600); // Read/write for owner only.
|
||||||
|
f.set_permissions(permissions).unwrap();
|
||||||
let writer = io::BufWriter::new(f);
|
let writer = io::BufWriter::new(f);
|
||||||
bincode::serialize_into(writer, &e).unwrap();
|
bincode::serialize_into(writer, &e).unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::backends::FolderHash;
|
use crate::backends::FolderHash;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::fs;
|
|
||||||
use std::io;
|
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
use std::sync::{Arc, RwLock, RwLockReadGuard, RwLockWriteGuard};
|
use std::sync::{Arc, RwLock, RwLockReadGuard, RwLockWriteGuard};
|
||||||
|
|
||||||
|
@ -52,19 +50,21 @@ pub struct Collection {
|
||||||
|
|
||||||
impl Drop for Collection {
|
impl Drop for Collection {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
let cache_dir: xdg::BaseDirectories =
|
/*
|
||||||
xdg::BaseDirectories::with_profile("meli", "threads".to_string()).unwrap();
|
let cache_dir: xdg::BaseDirectories =
|
||||||
if let Ok(cached) = cache_dir.place_cache_file("threads") {
|
xdg::BaseDirectories::with_profile("meli", "threads".to_string()).unwrap();
|
||||||
/* place result in cache directory */
|
if let Ok(cached) = cache_dir.place_cache_file("threads") {
|
||||||
let f = match fs::File::create(cached) {
|
/* place result in cache directory */
|
||||||
Ok(f) => f,
|
let f = match fs::File::create(cached) {
|
||||||
Err(e) => {
|
Ok(f) => f,
|
||||||
panic!("{}", e);
|
Err(e) => {
|
||||||
}
|
panic!("{}", e);
|
||||||
};
|
}
|
||||||
let writer = io::BufWriter::new(f);
|
};
|
||||||
bincode::serialize_into(writer, &self.threads).unwrap();
|
let writer = io::BufWriter::new(f);
|
||||||
}
|
bincode::serialize_into(writer, &self.threads).unwrap();
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
src/bin.rs
10
src/bin.rs
|
@ -28,7 +28,6 @@
|
||||||
//!
|
//!
|
||||||
|
|
||||||
use std::alloc::System;
|
use std::alloc::System;
|
||||||
use std::io::Write;
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
|
@ -209,14 +208,7 @@ fn run_app() -> Result<()> {
|
||||||
if config_path.exists() {
|
if config_path.exists() {
|
||||||
return Err(MeliError::new(format!("File `{}` already exists.\nMaybe you meant to specify another path with --create-config=PATH", config_path.display())));
|
return Err(MeliError::new(format!("File `{}` already exists.\nMaybe you meant to specify another path with --create-config=PATH", config_path.display())));
|
||||||
}
|
}
|
||||||
let mut file = std::fs::OpenOptions::new()
|
ui::conf::create_config_file(&config_path)?;
|
||||||
.write(true)
|
|
||||||
.create_new(true)
|
|
||||||
.open(config_path.as_path())
|
|
||||||
.map_err(|e| MeliError::new(format!("Could not create config file:\n{}", e)))?;
|
|
||||||
file.write_all(include_bytes!("../sample-config"))
|
|
||||||
.map_err(|e| MeliError::new(format!("Could not write to config file:\n{}", e)))?;
|
|
||||||
println!("Written example configuration to {}", config_path.display());
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1096,6 +1096,12 @@ impl Component for MailView {
|
||||||
}
|
}
|
||||||
Ok(f) => f,
|
Ok(f) => f,
|
||||||
};
|
};
|
||||||
|
use std::os::unix::fs::PermissionsExt;
|
||||||
|
let metadata = f.metadata().unwrap();
|
||||||
|
let mut permissions = metadata.permissions();
|
||||||
|
|
||||||
|
permissions.set_mode(0o600); // Read/write for owner only.
|
||||||
|
f.set_permissions(permissions).unwrap();
|
||||||
|
|
||||||
f.write_all(&decode(u, None)).unwrap();
|
f.write_all(&decode(u, None)).unwrap();
|
||||||
f.flush().unwrap();
|
f.flush().unwrap();
|
||||||
|
|
|
@ -51,7 +51,8 @@ use std::collections::HashMap;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs::{File, OpenOptions};
|
use std::fs::{File, OpenOptions};
|
||||||
use std::io::{self, BufRead, Read, Write};
|
use std::io::{self, BufRead, Read, Write};
|
||||||
use std::path::PathBuf;
|
use std::os::unix::fs::PermissionsExt;
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! split_command {
|
macro_rules! split_command {
|
||||||
|
@ -291,14 +292,7 @@ impl FileSettings {
|
||||||
|
|
||||||
match buffer.trim() {
|
match buffer.trim() {
|
||||||
"Y" | "y" | "yes" | "YES" | "Yes" => {
|
"Y" | "y" | "yes" | "YES" | "Yes" => {
|
||||||
let mut file = OpenOptions::new()
|
create_config_file(&config_path)?;
|
||||||
.write(true)
|
|
||||||
.create_new(true)
|
|
||||||
.open(config_path.as_path())
|
|
||||||
.expect("Could not create config file.");
|
|
||||||
file.write_all(include_bytes!("../../sample-config"))
|
|
||||||
.expect("Could not write to config file.");
|
|
||||||
println!("Written config to {}", config_path.display());
|
|
||||||
return Err(MeliError::new(
|
return Err(MeliError::new(
|
||||||
"Edit the sample configuration and relaunch meli.",
|
"Edit the sample configuration and relaunch meli.",
|
||||||
));
|
));
|
||||||
|
@ -559,3 +553,20 @@ pub fn usage(name: &str) -> Option<SpecialUseMailbox> {
|
||||||
Some(SpecialUseMailbox::Normal)
|
Some(SpecialUseMailbox::Normal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn create_config_file(p: &Path) -> Result<()> {
|
||||||
|
let mut file = OpenOptions::new()
|
||||||
|
.write(true)
|
||||||
|
.create_new(true)
|
||||||
|
.open(p)
|
||||||
|
.expect("Could not create config file.");
|
||||||
|
file.write_all(include_bytes!("../../sample-config"))
|
||||||
|
.expect("Could not write to config file.");
|
||||||
|
println!("Written example configuration to {}", p.display());
|
||||||
|
let metadata = file.metadata()?;
|
||||||
|
let mut permissions = metadata.permissions();
|
||||||
|
|
||||||
|
permissions.set_mode(0o600); // Read/write for owner only.
|
||||||
|
file.set_permissions(permissions)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ use std::collections::VecDeque;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::ops::{Index, IndexMut};
|
use std::ops::{Index, IndexMut};
|
||||||
|
use std::os::unix::fs::PermissionsExt;
|
||||||
use std::result;
|
use std::result;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
|
|
||||||
|
@ -177,6 +178,11 @@ impl Drop for Account {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
let metadata = f.metadata().unwrap();
|
||||||
|
let mut permissions = metadata.permissions();
|
||||||
|
|
||||||
|
permissions.set_mode(0o600); // Read/write for owner only.
|
||||||
|
f.set_permissions(permissions).unwrap();
|
||||||
let writer = io::BufWriter::new(f);
|
let writer = io::BufWriter::new(f);
|
||||||
if let Err(err) = serde_json::to_writer(writer, &self.address_book) {
|
if let Err(err) = serde_json::to_writer(writer, &self.address_book) {
|
||||||
eprintln!("{}", err);
|
eprintln!("{}", err);
|
||||||
|
@ -192,6 +198,11 @@ impl Drop for Account {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
let metadata = f.metadata().unwrap();
|
||||||
|
let mut permissions = metadata.permissions();
|
||||||
|
|
||||||
|
permissions.set_mode(0o600); // Read/write for owner only.
|
||||||
|
f.set_permissions(permissions).unwrap();
|
||||||
let writer = io::BufWriter::new(f);
|
let writer = io::BufWriter::new(f);
|
||||||
if let Err(err) = bincode::serialize_into(writer, &self.folders) {
|
if let Err(err) = bincode::serialize_into(writer, &self.folders) {
|
||||||
eprintln!("{}", err);
|
eprintln!("{}", err);
|
||||||
|
@ -254,6 +265,11 @@ impl Account {
|
||||||
let address_book = if let Ok(data) = data_dir.place_data_file("addressbook") {
|
let address_book = if let Ok(data) = data_dir.place_data_file("addressbook") {
|
||||||
if data.exists() {
|
if data.exists() {
|
||||||
let reader = io::BufReader::new(fs::File::open(data).unwrap());
|
let reader = io::BufReader::new(fs::File::open(data).unwrap());
|
||||||
|
let metadata = reader.get_ref().metadata().unwrap();
|
||||||
|
let mut permissions = metadata.permissions();
|
||||||
|
|
||||||
|
permissions.set_mode(0o600); // Read/write for owner only.
|
||||||
|
reader.get_ref().set_permissions(permissions).unwrap();
|
||||||
let result: result::Result<AddressBook, _> = serde_json::from_reader(reader);
|
let result: result::Result<AddressBook, _> = serde_json::from_reader(reader);
|
||||||
if let Ok(data_t) = result {
|
if let Ok(data_t) = result {
|
||||||
data_t
|
data_t
|
||||||
|
|
|
@ -72,13 +72,25 @@ pub fn open_db() -> Result<Connection> {
|
||||||
let db_path = data_dir
|
let db_path = data_dir
|
||||||
.place_data_file("index.db")
|
.place_data_file("index.db")
|
||||||
.map_err(|e| MeliError::new(e.to_string()))?;
|
.map_err(|e| MeliError::new(e.to_string()))?;
|
||||||
|
let mut set_mode = false;
|
||||||
if !db_path.exists() {
|
if !db_path.exists() {
|
||||||
log(
|
log(
|
||||||
format!("Creating index database in {}", db_path.display()),
|
format!("Creating index database in {}", db_path.display()),
|
||||||
melib::INFO,
|
melib::INFO,
|
||||||
);
|
);
|
||||||
|
set_mode = true;
|
||||||
}
|
}
|
||||||
let conn = Connection::open(db_path).map_err(|e| MeliError::new(e.to_string()))?;
|
let conn = Connection::open(&db_path).map_err(|e| MeliError::new(e.to_string()))?;
|
||||||
|
if set_mode {
|
||||||
|
use std::os::unix::fs::PermissionsExt;
|
||||||
|
let file = std::fs::File::open(&db_path)?;
|
||||||
|
let metadata = file.metadata()?;
|
||||||
|
let mut permissions = metadata.permissions();
|
||||||
|
|
||||||
|
permissions.set_mode(0o600); // Read/write for owner only.
|
||||||
|
file.set_permissions(permissions)?;
|
||||||
|
}
|
||||||
|
|
||||||
conn.execute_batch(
|
conn.execute_batch(
|
||||||
"CREATE TABLE IF NOT EXISTS envelopes (
|
"CREATE TABLE IF NOT EXISTS envelopes (
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
|
|
|
@ -23,6 +23,7 @@ use std;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::fs::OpenOptions;
|
use std::fs::OpenOptions;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
use std::os::unix::fs::PermissionsExt;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
@ -92,6 +93,11 @@ pub fn create_temp_file(
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut f = std::fs::File::create(path).unwrap();
|
let mut f = std::fs::File::create(path).unwrap();
|
||||||
|
let metadata = f.metadata().unwrap();
|
||||||
|
let mut permissions = metadata.permissions();
|
||||||
|
|
||||||
|
permissions.set_mode(0o600); // Read/write for owner only.
|
||||||
|
f.set_permissions(permissions).unwrap();
|
||||||
|
|
||||||
f.write_all(bytes).unwrap();
|
f.write_all(bytes).unwrap();
|
||||||
f.flush().unwrap();
|
f.flush().unwrap();
|
||||||
|
|
Loading…
Reference in New Issue