Skip to content

Commit 50d2a01

Browse files
committed
manager standalone support ACL file by path, #810
1 parent 7c154d2 commit 50d2a01

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

crates/shadowsocks-service/src/acl/mod.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::{
99
fs::File,
1010
io::{self, BufRead, BufReader, Error, ErrorKind},
1111
net::{IpAddr, SocketAddr},
12-
path::Path,
12+
path::{Path, PathBuf},
1313
str,
1414
};
1515

@@ -321,14 +321,18 @@ pub struct AccessControl {
321321
black_list: Rules,
322322
white_list: Rules,
323323
mode: Mode,
324+
file_path: PathBuf,
324325
}
325326

326327
impl AccessControl {
327328
/// Load ACL rules from a file
328329
pub fn load_from_file<P: AsRef<Path>>(p: P) -> io::Result<AccessControl> {
329330
trace!("ACL loading from {:?}", p.as_ref());
330331

331-
let fp = File::open(p)?;
332+
let file_path_ref = p.as_ref();
333+
let file_path = file_path_ref.to_path_buf();
334+
335+
let fp = File::open(file_path_ref)?;
332336
let r = BufReader::new(fp);
333337

334338
let mut mode = Mode::BlackList;
@@ -421,9 +425,15 @@ impl AccessControl {
421425
black_list: bypass.into_rules()?,
422426
white_list: proxy.into_rules()?,
423427
mode,
428+
file_path,
424429
})
425430
}
426431

432+
/// Get ACL file path
433+
pub fn file_path(&self) -> &Path {
434+
&self.file_path
435+
}
436+
427437
/// Check if domain name is in proxy_list.
428438
/// If so, it should be resolved from remote (for Android's DNS relay)
429439
///

crates/shadowsocks-service/src/manager/server.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,16 +366,21 @@ impl Manager {
366366
let manager_addr = self.svr_cfg.addr.to_string();
367367

368368
// Start server process
369-
let child_result = Command::new(&self.svr_cfg.server_program)
369+
let mut child_command = Command::new(&self.svr_cfg.server_program);
370+
child_command
370371
.arg("-c")
371372
.arg(&config_file_path)
372373
.arg("--daemonize")
373374
.arg("--daemonize-pid")
374375
.arg(&pid_path)
375376
.arg("--manager-addr")
376-
.arg(&manager_addr)
377-
.kill_on_drop(false)
378-
.spawn();
377+
.arg(&manager_addr);
378+
379+
if let Some(ref acl) = self.acl {
380+
child_command.arg("--acl").arg(acl.file_path().to_str().expect("acl"));
381+
}
382+
383+
let child_result = child_command.kill_on_drop(false).spawn();
379384

380385
if let Err(err) = child_result {
381386
error!(

0 commit comments

Comments
 (0)