Skip to content

Commit 553a585

Browse files
committed
Fix tempfile usage so we no longer need the world_accessible patches
- Just use a tempdir for the read-all permissions and create a file - The directory is removed when the connection is dropped
1 parent bf655ee commit 553a585

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ rcgen = { version = "^0.9", optional = true }
109109
regex = { version = "^1.5", optional = true }
110110
rustls = { version = "^0.20", optional = true, features = ["dangerous_configuration"] }
111111
sys-info = "^0.9"
112-
tempfile = { version = "3.1.0", git = "https://github.com/haata/tempfile", optional = true } # Needed for world accessible patches
112+
tempfile = { version = "3.3.0", optional = true }
113113
tokio = { version = "^1.18", features = ["net", "rt-multi-thread", "macros", "sync", "time"] }
114114
tokio-rustls = { version = "^0.23", optional = true }
115115
tokio-stream = { version = "^0.1", features = ["sync"], optional = true }

src/api/capnp.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use hid_io_protocol::{HidIoCommandId, HidIoPacketType};
3636
use rcgen::generate_simple_self_signed;
3737
use std::collections::HashMap;
3838
use std::env;
39+
use std::fs::File;
3940
use std::io::Write;
4041
use std::net::ToSocketAddrs;
4142
use std::sync::atomic::Ordering;
@@ -119,7 +120,7 @@ struct HidIoServerImpl {
119120
basic_key: String,
120121
auth_key: String,
121122

122-
basic_key_file: tempfile::NamedTempFile,
123+
basic_key_dir: tempfile::TempDir,
123124
auth_key_file: tempfile::NamedTempFile,
124125

125126
subscriptions: Arc<RwLock<Subscriptions>>,
@@ -133,15 +134,16 @@ impl HidIoServerImpl {
133134
subscriptions: Arc<RwLock<Subscriptions>>,
134135
) -> HidIoServerImpl {
135136
// Create temp file for basic key
136-
let mut basic_key_file = tempfile::Builder::new()
137-
.world_accessible(true)
138-
.tempfile()
139-
.expect("Unable to create file");
137+
let basic_key_dir = tempfile::Builder::new()
138+
.prefix("hidio")
139+
.tempdir()
140+
.expect("Unable to create dir");
141+
let mut basic_key_file =
142+
File::create(basic_key_dir.path().join("key")).expect("Unable to create file");
140143

141144
// Create temp file for auth key
142145
// Only this user can read the auth key
143146
let mut auth_key_file = tempfile::Builder::new()
144-
.world_accessible(false)
145147
.tempfile()
146148
.expect("Unable to create file");
147149

@@ -172,7 +174,7 @@ impl HidIoServerImpl {
172174
basic_key,
173175
auth_key,
174176

175-
basic_key_file,
177+
basic_key_dir,
176178
auth_key_file,
177179

178180
subscriptions,
@@ -297,7 +299,7 @@ impl hidio_capnp::hid_io_server::Server for HidIoServerImpl {
297299
) -> Promise<(), Error> {
298300
// Get and set fields
299301
let mut key = results.get().init_key();
300-
key.set_basic_key_path(&self.basic_key_file.path().display().to_string());
302+
key.set_basic_key_path(&self.basic_key_dir.path().join("key").display().to_string());
301303
key.set_auth_key_path(&self.auth_key_file.path().display().to_string());
302304
Promise::ok(())
303305
}

0 commit comments

Comments
 (0)