summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--bin/relay.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/bin/relay.c b/bin/relay.c
index 2ffd344b..d54f7245 100644
--- a/bin/relay.c
+++ b/bin/relay.c
@@ -87,6 +87,13 @@ static void clientHandle(struct tls *client, const char *chan, char *line) {
 	}
 }
 
+#ifdef __FreeBSD__
+static void limit(int fd, const cap_rights_t *rights) {
+	int error = cap_rights_limit(fd, rights);
+	if (error) err(EX_OSERR, "cap_rights_limit");
+}
+#endif
+
 int main(int argc, char *argv[]) {
 	int error;
 
@@ -140,25 +147,19 @@ int main(int argc, char *argv[]) {
 	if (error) errx(EX_PROTOCOL, "tls_connect: %s", tls_error(client));
 
 #ifdef __FreeBSD__
-	cap_rights_t rights;
-
 	error = cap_enter();
 	if (error) err(EX_OSERR, "cap_enter");
 
-	cap_rights_init(&rights, CAP_READ, CAP_EVENT);
-	error = cap_rights_limit(STDIN_FILENO, &rights);
-	if (error) err(EX_OSERR, "cap_rights_limit");
-
+	cap_rights_t rights;
 	cap_rights_init(&rights, CAP_WRITE);
-	error = cap_rights_limit(STDOUT_FILENO, &rights);
-	if (error) err(EX_OSERR, "cap_rights_limit");
+	limit(STDOUT_FILENO, &rights);
+	limit(STDERR_FILENO, &rights);
 
-	error = cap_rights_limit(STDERR_FILENO, &rights);
-	if (error) err(EX_OSERR, "cap_rights_limit");
+	cap_rights_init(&rights, CAP_EVENT, CAP_READ);
+	limit(STDIN_FILENO, &rights);
 
-	cap_rights_init(&rights, CAP_READ, CAP_WRITE, CAP_EVENT);
-	error = cap_rights_limit(sock, &rights);
-	if (error) err(EX_OSERR, "cap_rights_limit");
+	cap_rights_set(&rights, CAP_WRITE);
+	limit(sock, &rights);
 #endif
 
 	clientFormat(client, "NICK :%s\r\nUSER %s 0 * :%s\r\n", nick, nick, nick);
WARNINGJune McEnroe 2020-08-15Make log messages consistentJune McEnroe 2020-08-15Remove closelog callJune McEnroe 2020-08-15Implement service statusJune McEnroe 2020-08-15Parse control commandsJune McEnroe 2020-08-15Read service pipesJune McEnroe 2020-08-15Implement non-blocking line-buffered readingJune McEnroe 2020-08-15Generate tags fileJune McEnroe 2020-08-15Just use CLOCK_MONOTONIC and clean up includesJune McEnroe 2020-08-15Reap childrenJune McEnroe 2020-08-14Implement serviceSignal, serviceStop, serviceRestartJune McEnroe 2020-08-14Reset restartInterval and restartDeadline on startJune McEnroe 2020-08-14Switch to timespec for timeoutsJune McEnroe 2020-08-14Implement serviceStartJune McEnroe 2020-08-14Flesh out Service structJune McEnroe 2020-08-14Build environment for servicesJune McEnroe 2020-08-14Implement spawntab parsingJune McEnroe 2020-08-14Open syslog, daemonize, write PIDJune McEnroe 2020-08-14Implement user and group lookupJune McEnroe 2020-08-14Add install targetJune McEnroe 2020-08-14Add spawnd skeletonJune McEnroe