From 7a02ffd8ec92fb3f5bebc39931b464ec08f1799e Mon Sep 17 00:00:00 2001 From: fosslinux Date: Mon, 28 Dec 2020 11:03:33 +1100 Subject: [PATCH] Allow document roots specified with relative paths Closes #71 Implements this issue by transforming all relative paths into absolute paths. --- src/gophernicus.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/gophernicus.c b/src/gophernicus.c index 412ea36..250d917 100644 --- a/src/gophernicus.c +++ b/src/gophernicus.c @@ -524,8 +524,20 @@ int main(int argc, char *argv[]) /* Handle command line arguments */ parse_args(&st, argc, argv); + /* Initalize logging */ log_init(st.opt_syslog, st.debug); + /* Convert relative gopher roots to absolute roots */ + if (st.server_root[0] != '/') { + char cwd[512]; + getcwd(cwd, sizeof(cwd)); + if (cwd == NULL) { + die(&st, NULL, "unable to get current path"); + } + snprintf(buf, sizeof(buf), "%s/%s", cwd, st.server_root); + sstrlcpy(st.server_root, buf); + } + #ifdef __OpenBSD__ /* unveil(2) support. *