From 31d09e34fa1507833b98122b54bb929b956dcdd7 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Tue, 22 Oct 2019 22:15:55 -0400 Subject: Rename bouncer to bounce --- Makefile | 4 +-- bounce.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ bounce.h | 32 +++++++++++++++++++ bouncer.c | 108 -------------------------------------------------------------- bouncer.h | 30 ----------------- listen.c | 2 +- 6 files changed, 143 insertions(+), 141 deletions(-) create mode 100644 bounce.c create mode 100644 bounce.h delete mode 100644 bouncer.c delete mode 100644 bouncer.h diff --git a/Makefile b/Makefile index c974242..80b5261 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ LDLIBS = -ltls -include config.mk -OBJS += bouncer.o +OBJS += bounce.o OBJS += listen.o all: tags linger @@ -15,7 +15,7 @@ all: tags linger linger: ${OBJS} ${CC} ${LDFLAGS} ${OBJS} ${LDLIBS} -o $@ -${OBJS}: bouncer.h +${OBJS}: bounce.h tags: *.c *.h ctags -w *.c *.h diff --git a/bounce.c b/bounce.c new file mode 100644 index 0000000..b3d8b33 --- /dev/null +++ b/bounce.c @@ -0,0 +1,108 @@ +/* Copyright (C) 2019 C. McEnroe + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "bounce.h" + +static char *censor(char *arg) { + char *dup = strdup(arg); + if (!dup) err(EX_OSERR, "strdup"); + memset(arg, '\0', strlen(dup)); + arg[0] = '*'; + return dup; +} + +int main(int argc, char *argv[]) { + const char *localHost = "localhost"; + const char *localPort = "6697"; + const char *localPass = NULL; + char certPath[PATH_MAX] = ""; + char privPath[PATH_MAX] = ""; + + const char *host = NULL; + const char *port = "6697"; + const char *pass = NULL; + const char *auth = NULL; + const char *nick = NULL; + const char *user = NULL; + const char *real = NULL; + const char *join = NULL; + + int opt; + while (0 < (opt = getopt(argc, argv, "C:H:K:P:W:a:h:j:n:p:r:u:w:"))) { + switch (opt) { + break; case 'C': strlcpy(certPath, optarg, sizeof(certPath)); + break; case 'H': localHost = optarg; + break; case 'K': strlcpy(privPath, optarg, sizeof(privPath)); + break; case 'P': localPort = optarg; + break; case 'W': localPass = censor(optarg); + break; case 'a': auth = censor(optarg); + break; case 'h': host = optarg; + break; case 'j': join = optarg; + break; case 'n': nick = optarg; + break; case 'p': port = optarg; + break; case 'r': real = optarg; + break; case 'u': user = optarg; + break; case 'w': pass = censor(optarg); + break; default: return EX_USAGE; + } + } + + if (!certPath[0]) { + snprintf(certPath, sizeof(certPath), DEFAULT_CERT_PATH, localHost); + } + if (!privPath[0]) { + snprintf(privPath, sizeof(privPath), DEFAULT_PRIV_PATH, localHost); + } + + if (!host) errx(EX_USAGE, "no host"); + if (!nick) { + nick = getenv("USER"); + if (!nick) errx(EX_CONFIG, "USER unset"); + } + if (!user) user = nick; + if (!real) real = nick; + + listenConfig(certPath, privPath); + + enum { BindCap = 8 }; + int bind[BindCap]; + size_t bindLen = listenBind(bind, BindCap, localHost, localPort); + + // Wishing for struct-of-arrays... + struct pollfd fds[BindCap]; + for (size_t i = 0; i < bindLen; ++i) { + fds[i].fd = bind[i]; + fds[i].events = POLLIN; + } + + while (0 < poll(fds, bindLen, -1)) { + for (size_t i = 0; i < bindLen; ++i) { + if (!fds[i].revents) continue; + struct tls *client; + int fd = listenAccept(&client, fds[i].fd); + } + } +} diff --git a/bounce.h b/bounce.h new file mode 100644 index 0000000..e731ac0 --- /dev/null +++ b/bounce.h @@ -0,0 +1,32 @@ +/* Copyright (C) 2019 C. McEnroe + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include + +#ifndef DEFAULT_CERT_PATH +#define DEFAULT_CERT_PATH "/usr/local/etc/letsencrypt/live/%s/fullchain.pem" +#endif + +#ifndef DEFAULT_PRIV_PATH +#define DEFAULT_PRIV_PATH "/usr/local/etc/letsencrypt/live/%s/privkey.pem" +#endif + +void listenConfig(const char *cert, const char *priv); +size_t listenBind(int fds[], size_t cap, const char *host, const char *port); +int listenAccept(struct tls **client, int fd); + +int serverConnect(const char *host, const char *port); diff --git a/bouncer.c b/bouncer.c deleted file mode 100644 index 0d1d551..0000000 --- a/bouncer.c +++ /dev/null @@ -1,108 +0,0 @@ -/* Copyright (C) 2019 C. McEnroe - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "bouncer.h" - -static char *censor(char *arg) { - char *dup = strdup(arg); - if (!dup) err(EX_OSERR, "strdup"); - memset(arg, '\0', strlen(dup)); - arg[0] = '*'; - return dup; -} - -int main(int argc, char *argv[]) { - const char *localHost = "localhost"; - const char *localPort = "6697"; - const char *localPass = NULL; - char certPath[PATH_MAX] = ""; - char privPath[PATH_MAX] = ""; - - const char *host = NULL; - const char *port = "6697"; - const char *pass = NULL; - const char *auth = NULL; - const char *nick = NULL; - const char *user = NULL; - const char *real = NULL; - const char *join = NULL; - - int opt; - while (0 < (opt = getopt(argc, argv, "C:H:K:P:W:a:h:j:n:p:r:u:w:"))) { - switch (opt) { - break; case 'C': strlcpy(certPath, optarg, sizeof(certPath)); - break; case 'H': localHost = optarg; - break; case 'K': strlcpy(privPath, optarg, sizeof(privPath)); - break; case 'P': localPort = optarg; - break; case 'W': localPass = censor(optarg); - break; case 'a': auth = censor(optarg); - break; case 'h': host = optarg; - break; case 'j': join = optarg; - break; case 'n': nick = optarg; - break; case 'p': port = optarg; - break; case 'r': real = optarg; - break; case 'u': user = optarg; - break; case 'w': pass = censor(optarg); - break; default: return EX_USAGE; - } - } - - if (!certPath[0]) { - snprintf(certPath, sizeof(certPath), DEFAULT_CERT_PATH, localHost); - } - if (!privPath[0]) { - snprintf(privPath, sizeof(privPath), DEFAULT_PRIV_PATH, localHost); - } - - if (!host) errx(EX_USAGE, "no host"); - if (!nick) { - nick = getenv("USER"); - if (!nick) errx(EX_CONFIG, "USER unset"); - } - if (!user) user = nick; - if (!real) real = nick; - - listenConfig(certPath, privPath); - - enum { BindCap = 8 }; - int bind[BindCap]; - size_t bindLen = listenBind(bind, BindCap, localHost, localPort); - - // Wishing for struct-of-arrays... - struct pollfd fds[BindCap]; - for (size_t i = 0; i < bindLen; ++i) { - fds[i].fd = bind[i]; - fds[i].events = POLLIN; - } - - while (0 < poll(fds, bindLen, -1)) { - for (size_t i = 0; i < bindLen; ++i) { - if (!fds[i].revents) continue; - struct tls *client; - int fd = listenAccept(&client, fds[i].fd); - } - } -} diff --git a/bouncer.h b/bouncer.h deleted file mode 100644 index 13656ad..0000000 --- a/bouncer.h +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright (C) 2019 C. McEnroe - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#include -#include - -#ifndef DEFAULT_CERT_PATH -#define DEFAULT_CERT_PATH "/usr/local/etc/letsencrypt/live/%s/fullchain.pem" -#endif - -#ifndef DEFAULT_PRIV_PATH -#define DEFAULT_PRIV_PATH "/usr/local/etc/letsencrypt/live/%s/privkey.pem" -#endif - -void listenConfig(const char *cert, const char *priv); -size_t listenBind(int fds[], size_t cap, const char *host, const char *port); -int listenAccept(struct tls **client, int fd); diff --git a/listen.c b/listen.c index cb6b164..d758b9d 100644 --- a/listen.c +++ b/listen.c @@ -23,7 +23,7 @@ #include #include -#include "bouncer.h" +#include "bounce.h" static struct tls *server; -- cgit 1.4.1