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
----------------
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

View file

@ -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

View file

@ -37,6 +37,8 @@ fn parse_args() -> Option<String> {
}
fn parse_config(fname: String) -> server::ServerConfig {
println!("reading configuration from: {}", fname);
let path = Path::new(&fname);
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>) {
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<T
let file = match File::open(&path) {
Ok(file) => 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),

View file

@ -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();