summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-08-28 13:01:28 -0400
committerJune McEnroe <june@causal.agency>2019-08-28 13:01:28 -0400
commitd0179695c4f2f14934c525c4881da7fff9459af5 (patch)
tree0ca11a1ef01387b23812ac68cb222b33d9f5e8e8
parentCast %lc parameter to wint_t (diff)
downloadsrc-d0179695c4f2f14934c525c4881da7fff9459af5.tar.gz
src-d0179695c4f2f14934c525c4881da7fff9459af5.zip
Factor out cap_rights_limit error handling
Diffstat (limited to '')
-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);
esJune McEnroe 2019-11-10Request all supported caps from serverJune McEnroe 2019-11-10Filter ACCOUNT, AWAY, CHGHOST for incapable clientsJune McEnroe 2019-11-10Rename listen to localJune McEnroe 2019-11-09Remove extended-join and invite-notifyJune McEnroe The remaining caps only generate new commands which can easily be filtered out when sending to clients so will be in the first pass of support. extended-join is probably safe to pass through unaltered, just causing extraneous parameters on JOIN commands, but maybe not. invite-notify reuses the INVITE command where the invited user is not self. 2019-11-09Maintain stateCaps and offer them to clientsJune McEnroe 2019-11-09Parse capabilitiesJune McEnroe The list that I've defined are the ones that I expect to be able to enable probably without any clients breaking... And of course server-time which pounce implements itself. 2019-11-09Avoid the reserved _A names with BIT macroJune McEnroe 2019-11-09Define macro for bit flag enumsJune McEnroe 2019-11-08Check that password is hashedJune McEnroe 2019-11-08Avoid calling getopt_long again after it returns -1June McEnroe On GNU, calling getopt_long again will reset optind back to the first non-option argument, which would cause an infinite loop of reading the same configurtion file forever. 2019-11-08Only change AWAY status for registered clientsJune McEnroe Turns out I did eventually fix this, because I may want to implement "passive clients" for logging or notification stuff, which wouldn't affect AWAY status either. 2019-11-07Just write the example normallyJune McEnroe 2019-11-07Include path in readlinkat errorJune McEnroe 2019-11-07Call clientConsume before clientRecvJune McEnroe This might reduce the frequency of a client getting its own message back because it was behind in the ring when it sent it. 2019-11-06Use -l:filename in Linux.mkJune McEnroe 2019-11-06Fix compat.h for #defined strlcpyJune McEnroe 2019-11-06Allow unsetting LIBRESSL_PREFIXJune McEnroe 2019-11-06Document calico service configurationJune McEnroe 2019-11-06Document SASL EXTERNAL configuration in more detailJune McEnroe 2019-11-06Document pounce service configurationJune McEnroe 2019-11-06Mention Darwin and GNU/Linux in READMEJune McEnroe 2019-11-06Assume LibreSSL from brew on DarwinJune McEnroe 2019-11-06Remove -DNO_EXPLICIT_BZERO from Darwin.mkJune McEnroe 2019-11-06Don't install rc scripts or dirs on LinuxJune McEnroe