irced

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 17f308172c5e27f47200a9524f3a6209794aab92
parent 86869eb0fb2587b6b104aa7299c4c2ae42b27516
Author: aabacchus <ben@bvnf.space>
Date:   Sun, 24 Jul 2022 01:22:56 +0100

pledge and unveil to work with ed

Diffstat:
Mirced.c | 17+++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/irced.c b/irced.c @@ -35,12 +35,12 @@ fail(char *s, ...) { void drop_privileges(char *path) { - if (chdir(path) != 0) - fail("chdir(%s) failed: %s", path, strerror(errno)); #ifdef __OpenBSD__ if (unveil(path, "rwxc") != 0) fail("unveil failed: %s", strerror(errno)); #endif + if (chdir(path) != 0) + fail("chdir(%s) failed: %s", path, strerror(errno)); } void sigchld_handler(int s) { @@ -121,11 +121,17 @@ fork_rw(char *cmd[], int *wr, int *rd) { break; case 0: /* child */ + /* exec is promised, but only $PWD and /tmp are unveiled. */ drop_privileges("."); +#ifdef __OpenBSD__ + if (unveil("/tmp/", "crw") != 0) + fail("unveil failed: %s", strerror(errno)); +#endif close(to[1]); close(from[0]); dup2(to[0], 0); dup2(from[1], 1); + dup2(from[1], 2); /* also get stderr */ execv(cmd[0], cmd); fail("exec %s failed: %s", strerror(errno)); break; @@ -248,8 +254,15 @@ main(int argc, char **argv) { return 1; } +#ifdef __OpenBSD__ + if (unveil("/bin/", "x") != 0) + fail("unveil failed: %s", strerror(errno)); path = argv[optind]; drop_privileges(path); +#ifdef __OpenBSD__ + if (pledge("exec stdio dns proc unveil rpath wpath cpath inet", "rpath wpath stdio proc tty cpath exec error") == -1) + fail("pledge failed: %s", strerror(errno)); +#endif sfd = start_listening(port); if (sfd == -1) {