From 30ae6586b2c1b415267ab32ffc9c260e1f0c74c2 Mon Sep 17 00:00:00 2001 From: Jordan Bancino Date: Fri, 12 Aug 2022 19:32:06 -0400 Subject: [PATCH] Accept #28, with modifications. --- src/Telodendria.c | 2 ++ src/include/NonPosix.h | 59 ++++++++++++++++++++++++++++++++++++++++++ tools/bin/td | 2 +- 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/include/NonPosix.h diff --git a/src/Telodendria.c b/src/Telodendria.c index 16be3fc..efa54c8 100644 --- a/src/Telodendria.c +++ b/src/Telodendria.c @@ -37,6 +37,8 @@ #include #include +#include + HttpServer *httpServer = NULL; static void diff --git a/src/include/NonPosix.h b/src/include/NonPosix.h new file mode 100644 index 0000000..29efd27 --- /dev/null +++ b/src/include/NonPosix.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2022 Jordan Bancino <@jordan:bancino.net> + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* + * NonPosix.h: A collection of functions that I know certain operating + * systems have, but they aren't specified in POSIX. I'd like to keep + * this header really small if at all possible. + */ +#ifndef TELODENDRIA_NONPOSIX_H +#define TELODENDRIA_NONPOSIX_H + +/* + * Pretty much all Unix-like systems have a chroot() function. In fact, + * chroot() used to be POSIX, so any operating system claiming to be + * POSIX-like had to have a chroot(). But unfortunately chroot() is not + * in the standard anymore. Luckily, I don't know of a single operating + * system to get rid of chroot(). So we should be able to safely depend + * on a chroot() syscall being available. + */ +extern int chroot(const char *); + +/* + * Telodendria is primarily developed on OpenBSD; as such, you can + * expect that it will use some OpenBSD-specific features if OpenBSD + * is the target platform. + * + * It is my goal though, to make these functions entirely optional. + * I've wrapped them in a preprocessor guard, and anywhere they're used + * should also be wrapped in the same guard. So if the target platform + * is not OpenBSD, then these aren't used at all. + */ +#ifdef __OpenBSD__ +extern int pledge(const char *, const char *); +extern int unveil(const char *, const char *); + +#endif + +#endif diff --git a/tools/bin/td b/tools/bin/td index a7f3df3..ec4d233 100644 --- a/tools/bin/td +++ b/tools/bin/td @@ -22,7 +22,7 @@ : "${TELODENDRIA_VERSION:=0.0.0}" : "${CVS_TAG:=Telodendria-$(echo $TELODENDRIA_VERSION | sed 's/\./_/g')}" -: "${DEFINES:=-D_BSD_SOURCE -D_POSIX_C_SOURCE=199506L -DTELODENDRIA_VERSION=\"$TELODENDRIA_VERSION\"}" +: "${DEFINES:=-D_POSIX_C_SOURCE=200809L -DTELODENDRIA_VERSION=\"$TELODENDRIA_VERSION\"}" : "${INCLUDES:=-Isrc/include}" : "${CC:=cc}"