some logging

This commit is contained in:
Jan Wolff 2020-05-17 20:25:59 +02:00
parent faab34d44f
commit 710e8aae56
5 changed files with 17 additions and 2 deletions

View file

@ -17,7 +17,7 @@ Gemini.
Platform Support 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 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 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 opened in user-mode, but not changing the user after startup would retain read

View file

@ -8,7 +8,7 @@ gem_root = /var/gemini/
listen = [::1]:1965 listen = [::1]:1965
listen = 127.0.0.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 user = gem-data
group = gem-data group = gem-data

View file

@ -37,6 +37,8 @@ fn parse_args() -> Option<String> {
} }
fn parse_config(fname: String) -> server::ServerConfig { fn parse_config(fname: String) -> server::ServerConfig {
println!("reading configuration from: {}", fname);
let path = Path::new(&fname); let path = Path::new(&fname);
let mut config = server::ServerConfig::new(); let mut config = server::ServerConfig::new();

View file

@ -58,6 +58,8 @@ fn gen_path_index(path: &Path) -> PathBuf {
} }
fn handle_response(config: &ServerConfig, url: Url, mut stream: &mut SslStream<TcpStream>) { fn handle_response(config: &ServerConfig, url: Url, mut stream: &mut SslStream<TcpStream>) {
println!("responding for: {}", url);
if url.scheme() != "gemini" { if url.scheme() != "gemini" {
send_header(&mut stream, &response::permanent_failure()); send_header(&mut stream, &response::permanent_failure());
return; return;
@ -81,10 +83,12 @@ fn handle_response(config: &ServerConfig, url: Url, mut stream: &mut SslStream<T
let file = match File::open(&path) { let file = match File::open(&path) {
Ok(file) => file, Ok(file) => file,
Err(_) => { Err(_) => {
println!("not found: {:?}", path);
send_header(&mut stream, &response::not_found()); send_header(&mut stream, &response::not_found());
return; return;
} }
}; };
println!("sending file: {:?}", path);
let mime_type = match path.extension() { let mime_type = match path.extension() {
Some(ext) => mime::get_mime_type(ext), Some(ext) => mime::get_mime_type(ext),

View file

@ -108,13 +108,20 @@ impl Server {
} }
pub fn serve(&self) { pub fn serve(&self) {
println!("serving...");
let acceptor = Server::build_acceptor(&self.config); 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(); let listener = TcpListener::bind(&self.config.addrs[..]).unwrap();
if self.config.user.is_root() { if self.config.user.is_root() {
panic!("refusing to run as root"); panic!("refusing to run as root");
} }
println!("set gid to: {}", self.config.group);
match unistd::setgid(self.config.group) { match unistd::setgid(self.config.group) {
Ok(_) => {} Ok(_) => {}
Err(e) => { Err(e) => {
@ -122,6 +129,7 @@ impl Server {
} }
}; };
println!("set uid to: {}", self.config.user);
match unistd::setuid(self.config.user) { match unistd::setuid(self.config.user) {
Ok(_) => {} Ok(_) => {}
Err(e) => { Err(e) => {
@ -130,6 +138,7 @@ impl Server {
}; };
for stream in listener.incoming() { for stream in listener.incoming() {
println!("new connection");
match stream { match stream {
Ok(stream) => { Ok(stream) => {
let acceptor = acceptor.clone(); let acceptor = acceptor.clone();