summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Wolff <janw@mailbox.org>2020-05-17 19:46:48 +0200
committerJan Wolff <janw@mailbox.org>2020-05-17 19:46:48 +0200
commitfaab34d44f11af3821c23d7075575f6570f984bd (patch)
tree5e534c15acc2cf9ba2567036381f547747a3f689
parent72c1e3c8132a8269833396ab955586185e7b0e58 (diff)
update readme, default configuration path
-rw-r--r--README.md23
-rw-r--r--src/main.rs16
-rw-r--r--src/mime/mod.rs1
-rw-r--r--src/server/handler.rs12
4 files changed, 35 insertions, 17 deletions
diff --git a/README.md b/README.md
index 9af8d5e..1915c85 100644
--- a/README.md
+++ b/README.md
@@ -7,29 +7,34 @@ Features
--------
This can't do much right now besides hosting some static files. In fact, the
-feature set happens to be limited to what I need to host my own gemini page.
+feature set happens to be limited to what I need to host my own Gemini page.
Coincidence?
More is to come however. Specifically I'd want to add CGI support. And maybe
reverse proxy support as well, depending on how much stuff I'll be hosting over
Gemini.
+Platform Support
+----------------
+
+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
+permissions to the private key.
+
Starting
--------
-Right now every relevant option needs to be given through command line
-parameters. Though handling of a configuration file is a feature I'll add
-later on.
+Sheldon Director look for a config file in `/etc/sheldond.conf`. If you want to
+change this, pass an alternative path on startup like so:
An example start can look like this:
```sh
-sudo ./sheldond -l "[::]:1965" -l "0.0.0.0:1965" -d "klockenschooster.de" -g /var/gemini/ --user gem-data --group gem-data
+sudo ./sheldond -c ./sheldond.conf
```
-This serves the content of the folder `/var/gemini/` over both IPv4 and IPv6
-on port 1965 on the domain `klockenschooster.de`. After opening the socket and
-reading the certificates the server sets its user and group id to the
-respective values for `gem-data`.
+An example config file can be found in this repository in `doc/sheldond.conf`.
Why "Sheldon Director"?
-----------------------
diff --git a/src/main.rs b/src/main.rs
index 5639158..7e5787a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -20,6 +20,10 @@ fn parse_args() -> Option<String> {
loop {
match args.next() {
Some(arg) => {
+ if arg == "-h" || arg == "--help" {
+ help();
+ return None;
+ }
if arg == "-c" || arg == "--config" {
let config_fname = args.next().unwrap();
return Some(config_fname);
@@ -29,7 +33,7 @@ fn parse_args() -> Option<String> {
}
}
- None
+ Some("/etc/sheldond.conf".to_string())
}
fn parse_config(fname: String) -> server::ServerConfig {
@@ -38,8 +42,8 @@ fn parse_config(fname: String) -> server::ServerConfig {
let file = match File::open(path) {
Ok(file) => BufReader::new(file),
- Err(e) => {
- panic!(e);
+ Err(_) => {
+ panic!("could not open config file: {}", fname);
}
};
@@ -77,13 +81,13 @@ fn parse_config(fname: String) -> server::ServerConfig {
}
fn main() {
- let config = match parse_args() {
- Some(config_fname) => parse_config(config_fname),
+ let config_fname = match parse_args() {
+ Some(config_fname) => config_fname,
None => {
- help();
return;
}
};
+ let config = parse_config(config_fname);
let server = server::Server::new(&config);
server.serve();
diff --git a/src/mime/mod.rs b/src/mime/mod.rs
index 6fc0f9f..156dd0d 100644
--- a/src/mime/mod.rs
+++ b/src/mime/mod.rs
@@ -14,6 +14,7 @@ pub fn get_mime_type(extension: &OsStr) -> &'static str {
match ext_str {
"gmi" => "text/gemini",
+ "gemini" => "text/gemini",
"txt" => "text/plain",
_ => default_mime_type(),
}
diff --git a/src/server/handler.rs b/src/server/handler.rs
index 84d9d17..5f77f93 100644
--- a/src/server/handler.rs
+++ b/src/server/handler.rs
@@ -5,7 +5,7 @@ use openssl::ssl::SslStream;
use std::fs::File;
use std::io::{copy, BufReader, BufWriter};
use std::net::TcpStream;
-use std::path::Path;
+use std::path::{Path, PathBuf};
use url::Url;
fn send_header(stream: &mut SslStream<TcpStream>, header: &response::Header) {
@@ -50,6 +50,13 @@ pub fn handle_request(config: &ServerConfig, mut stream: SslStream<TcpStream>) {
handle_response(config, location, &mut stream);
}
+fn gen_path_index(path: &Path) -> PathBuf {
+ match path.is_dir() {
+ true => path.join("index.gmi"),
+ false => PathBuf::from(path),
+ }
+}
+
fn handle_response(config: &ServerConfig, url: Url, mut stream: &mut SslStream<TcpStream>) {
if url.scheme() != "gemini" {
send_header(&mut stream, &response::permanent_failure());
@@ -68,7 +75,8 @@ fn handle_response(config: &ServerConfig, url: Url, mut stream: &mut SslStream<T
return;
}
};
- let path = config.gem_root.join(rel_path);
+
+ let path = gen_path_index(&config.gem_root.join(rel_path));
let file = match File::open(&path) {
Ok(file) => file,