Skip to content

Commit

Permalink
manager standalone support ACL file by path, #810
Browse files Browse the repository at this point in the history
  • Loading branch information
zonyitoo committed Apr 19, 2022
1 parent 7c154d2 commit 50d2a01
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
14 changes: 12 additions & 2 deletions crates/shadowsocks-service/src/acl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
fs::File,
io::{self, BufRead, BufReader, Error, ErrorKind},
net::{IpAddr, SocketAddr},
path::Path,
path::{Path, PathBuf},
str,
};

Expand Down Expand Up @@ -321,14 +321,18 @@ pub struct AccessControl {
black_list: Rules,
white_list: Rules,
mode: Mode,
file_path: PathBuf,
}

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

let fp = File::open(p)?;
let file_path_ref = p.as_ref();
let file_path = file_path_ref.to_path_buf();

let fp = File::open(file_path_ref)?;
let r = BufReader::new(fp);

let mut mode = Mode::BlackList;
Expand Down Expand Up @@ -421,9 +425,15 @@ impl AccessControl {
black_list: bypass.into_rules()?,
white_list: proxy.into_rules()?,
mode,
file_path,
})
}

/// Get ACL file path
pub fn file_path(&self) -> &Path {
&self.file_path
}

/// Check if domain name is in proxy_list.
/// If so, it should be resolved from remote (for Android's DNS relay)
///
Expand Down
13 changes: 9 additions & 4 deletions crates/shadowsocks-service/src/manager/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,16 +366,21 @@ impl Manager {
let manager_addr = self.svr_cfg.addr.to_string();

// Start server process
let child_result = Command::new(&self.svr_cfg.server_program)
let mut child_command = Command::new(&self.svr_cfg.server_program);
child_command
.arg("-c")
.arg(&config_file_path)
.arg("--daemonize")
.arg("--daemonize-pid")
.arg(&pid_path)
.arg("--manager-addr")
.arg(&manager_addr)
.kill_on_drop(false)
.spawn();
.arg(&manager_addr);

if let Some(ref acl) = self.acl {
child_command.arg("--acl").arg(acl.file_path().to_str().expect("acl"));
}

let child_result = child_command.kill_on_drop(false).spawn();

if let Err(err) = child_result {
error!(
Expand Down

0 comments on commit 50d2a01

Please sign in to comment.