From 710e8aae565bd376d493ed89859c52d7f58a34f7 Mon Sep 17 00:00:00 2001 From: Jan Wolff Date: Sun, 17 May 2020 20:25:59 +0200 Subject: [PATCH] some logging --- README.md | 2 +- doc/sheldond.conf | 2 +- src/main.rs | 2 ++ src/server/handler.rs | 4 ++++ src/server/mod.rs | 9 +++++++++ 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1915c85..73023ea 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Gemini. Platform Support ---------------- -This currently only works on UNIX platforms as `setuid` and `setgid` system +This currently only works on Unix platforms as `setuid` and `setgid` system calls are used to drop the privilege level after initialization. Currently there is no way to disable this. Of course, Gemini's default port (1965) can be opened in user-mode, but not changing the user after startup would retain read diff --git a/doc/sheldond.conf b/doc/sheldond.conf index 87610d1..1af1389 100644 --- a/doc/sheldond.conf +++ b/doc/sheldond.conf @@ -8,7 +8,7 @@ gem_root = /var/gemini/ listen = [::1]:1965 listen = 127.0.0.1:1965 -# privilige level for the server to drop to after initializing +# privilege level for the server to drop to after initializing user = gem-data group = gem-data diff --git a/src/main.rs b/src/main.rs index 7e5787a..b22b626 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,6 +37,8 @@ fn parse_args() -> Option { } fn parse_config(fname: String) -> server::ServerConfig { + println!("reading configuration from: {}", fname); + let path = Path::new(&fname); let mut config = server::ServerConfig::new(); diff --git a/src/server/handler.rs b/src/server/handler.rs index 5f77f93..e122e96 100644 --- a/src/server/handler.rs +++ b/src/server/handler.rs @@ -58,6 +58,8 @@ fn gen_path_index(path: &Path) -> PathBuf { } fn handle_response(config: &ServerConfig, url: Url, mut stream: &mut SslStream) { + println!("responding for: {}", url); + if url.scheme() != "gemini" { send_header(&mut stream, &response::permanent_failure()); return; @@ -81,10 +83,12 @@ fn handle_response(config: &ServerConfig, url: Url, mut stream: &mut SslStream file, Err(_) => { + println!("not found: {:?}", path); send_header(&mut stream, &response::not_found()); return; } }; + println!("sending file: {:?}", path); let mime_type = match path.extension() { Some(ext) => mime::get_mime_type(ext), diff --git a/src/server/mod.rs b/src/server/mod.rs index 8359c32..3b01ce2 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -108,13 +108,20 @@ impl Server { } pub fn serve(&self) { + println!("serving..."); let acceptor = Server::build_acceptor(&self.config); + + for addr in &self.config.addrs { + println!("listening on: {}", addr); + } + let listener = TcpListener::bind(&self.config.addrs[..]).unwrap(); if self.config.user.is_root() { panic!("refusing to run as root"); } + println!("set gid to: {}", self.config.group); match unistd::setgid(self.config.group) { Ok(_) => {} Err(e) => { @@ -122,6 +129,7 @@ impl Server { } }; + println!("set uid to: {}", self.config.user); match unistd::setuid(self.config.user) { Ok(_) => {} Err(e) => { @@ -130,6 +138,7 @@ impl Server { }; for stream in listener.incoming() { + println!("new connection"); match stream { Ok(stream) => { let acceptor = acceptor.clone();